Skip to content

Commit 86a22fb

Browse files
estebankMark-Simulacrum
authored andcommitted
Backport only: avoid ICE on bad placeholder type
This change avoids the ICE by actually emitting an appropriate error. The output will be duplicated in some cases, but that's better than the avoidable ICE.
1 parent 8ffc110 commit 86a22fb

File tree

7 files changed

+34
-750
lines changed

7 files changed

+34
-750
lines changed

src/librustc_typeck/collect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> {
316316
}
317317

318318
fn ty_infer(&self, _: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx> {
319-
self.tcx().sess.delay_span_bug(span, "bad placeholder type");
319+
placeholder_type_error(self.tcx(), span, &[], vec![span], false);
320320
self.tcx().types.err
321321
}
322322

src/test/ui/did_you_mean/bad-assoc-ty.rs

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type D = (u8, u8)::AssocTy;
1717
type E = _::AssocTy;
1818
//~^ ERROR missing angle brackets in associated item path
1919
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
20+
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
2021

2122
type F = &'static (u8)::AssocTy;
2223
//~^ ERROR missing angle brackets in associated item path

src/test/ui/did_you_mean/bad-assoc-ty.stderr

+16-10
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,25 @@ LL | type E = _::AssocTy;
2929
| ^^^^^^^^^^ help: try: `<_>::AssocTy`
3030

3131
error: missing angle brackets in associated item path
32-
--> $DIR/bad-assoc-ty.rs:21:19
32+
--> $DIR/bad-assoc-ty.rs:22:19
3333
|
3434
LL | type F = &'static (u8)::AssocTy;
3535
| ^^^^^^^^^^^^^ help: try: `<(u8)>::AssocTy`
3636

3737
error: missing angle brackets in associated item path
38-
--> $DIR/bad-assoc-ty.rs:27:10
38+
--> $DIR/bad-assoc-ty.rs:28:10
3939
|
4040
LL | type G = dyn 'static + (Send)::AssocTy;
4141
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `<dyn 'static + (Send)>::AssocTy`
4242

4343
error: missing angle brackets in associated item path
44-
--> $DIR/bad-assoc-ty.rs:44:10
44+
--> $DIR/bad-assoc-ty.rs:45:10
4545
|
4646
LL | type I = ty!()::AssocTy;
4747
| ^^^^^^^^^^^^^^ help: try: `<ty!()>::AssocTy`
4848

4949
error: missing angle brackets in associated item path
50-
--> $DIR/bad-assoc-ty.rs:37:19
50+
--> $DIR/bad-assoc-ty.rs:38:19
5151
|
5252
LL | ($ty: ty) => ($ty::AssocTy);
5353
| ^^^^^^^^^^^^ help: try: `<$ty>::AssocTy`
@@ -85,26 +85,32 @@ error[E0121]: the type placeholder `_` is not allowed within types on item signa
8585
LL | type E = _::AssocTy;
8686
| ^ not allowed in type signatures
8787

88+
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
89+
--> $DIR/bad-assoc-ty.rs:17:10
90+
|
91+
LL | type E = _::AssocTy;
92+
| ^ not allowed in type signatures
93+
8894
error[E0223]: ambiguous associated type
89-
--> $DIR/bad-assoc-ty.rs:21:19
95+
--> $DIR/bad-assoc-ty.rs:22:19
9096
|
9197
LL | type F = &'static (u8)::AssocTy;
9298
| ^^^^^^^^^^^^^ help: use fully-qualified syntax: `<u8 as Trait>::AssocTy`
9399

94100
error[E0223]: ambiguous associated type
95-
--> $DIR/bad-assoc-ty.rs:27:10
101+
--> $DIR/bad-assoc-ty.rs:28:10
96102
|
97103
LL | type G = dyn 'static + (Send)::AssocTy;
98104
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<(dyn std::marker::Send + 'static) as Trait>::AssocTy`
99105

100106
error[E0223]: ambiguous associated type
101-
--> $DIR/bad-assoc-ty.rs:33:10
107+
--> $DIR/bad-assoc-ty.rs:34:10
102108
|
103109
LL | type H = Fn(u8) -> (u8)::Output;
104110
| ^^^^^^^^^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<(dyn std::ops::Fn(u8) -> u8 + 'static) as Trait>::Output`
105111

106112
error[E0223]: ambiguous associated type
107-
--> $DIR/bad-assoc-ty.rs:37:19
113+
--> $DIR/bad-assoc-ty.rs:38:19
108114
|
109115
LL | ($ty: ty) => ($ty::AssocTy);
110116
| ^^^^^^^^^^^^ help: use fully-qualified syntax: `<u8 as Trait>::AssocTy`
@@ -113,12 +119,12 @@ LL | type J = ty!(u8);
113119
| ------- in this macro invocation
114120

115121
error[E0223]: ambiguous associated type
116-
--> $DIR/bad-assoc-ty.rs:44:10
122+
--> $DIR/bad-assoc-ty.rs:45:10
117123
|
118124
LL | type I = ty!()::AssocTy;
119125
| ^^^^^^^^^^^^^^ help: use fully-qualified syntax: `<u8 as Trait>::AssocTy`
120126

121-
error: aborting due to 19 previous errors
127+
error: aborting due to 20 previous errors
122128

123129
Some errors have detailed explanations: E0121, E0223.
124130
For more information about an error, try `rustc --explain E0121`.

src/test/ui/self/self-infer.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ struct S;
22

33
impl S {
44
fn f(self: _) {} //~ERROR the type placeholder `_` is not allowed within types on item sig
5+
//~^ ERROR the type placeholder `_` is not allowed within types on item sig
56
fn g(self: &_) {} //~ERROR the type placeholder `_` is not allowed within types on item sig
7+
//~^ ERROR the type placeholder `_` is not allowed within types on item sig
68
}
79

810
fn main() {}

src/test/ui/self/self-infer.stderr

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
2+
--> $DIR/self-infer.rs:4:16
3+
|
4+
LL | fn f(self: _) {}
5+
| ^ not allowed in type signatures
6+
17
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
28
--> $DIR/self-infer.rs:4:16
39
|
@@ -10,7 +16,13 @@ LL | fn f<T>(self: T) {}
1016
| ^^^ ^
1117

1218
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
13-
--> $DIR/self-infer.rs:5:17
19+
--> $DIR/self-infer.rs:6:17
20+
|
21+
LL | fn g(self: &_) {}
22+
| ^ not allowed in type signatures
23+
24+
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
25+
--> $DIR/self-infer.rs:6:17
1426
|
1527
LL | fn g(self: &_) {}
1628
| ^ not allowed in type signatures
@@ -20,6 +32,6 @@ help: use type parameters instead
2032
LL | fn g<T>(self: &T) {}
2133
| ^^^ ^
2234

23-
error: aborting due to 2 previous errors
35+
error: aborting due to 4 previous errors
2436

2537
For more information about this error, try `rustc --explain E0121`.

src/test/ui/typeck/typeck_type_placeholder_item.rs

-185
This file was deleted.

0 commit comments

Comments
 (0)