Skip to content

Commit

Permalink
Rollup merge of rust-lang#69324 - estebank:ice-break-backport-bad-pla…
Browse files Browse the repository at this point in the history
…ceholder-type, r=Centril

Backport only: avoid ICE on bad placeholder type

 rust-lang#69148 has a proper fix, but it is too big to backport.
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.

r? @Centril
  • Loading branch information
JohnTitor authored Feb 27, 2020
2 parents 0c15adc + 1cb555a commit add9338
Show file tree
Hide file tree
Showing 7 changed files with 329 additions and 68 deletions.
2 changes: 1 addition & 1 deletion src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ impl AstConv<'tcx> for ItemCtxt<'tcx> {
}

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

Expand Down
1 change: 1 addition & 0 deletions src/test/ui/did_you_mean/bad-assoc-ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type D = (u8, u8)::AssocTy;
type E = _::AssocTy;
//~^ ERROR missing angle brackets in associated item path
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures

type F = &'static (u8)::AssocTy;
//~^ ERROR missing angle brackets in associated item path
Expand Down
26 changes: 16 additions & 10 deletions src/test/ui/did_you_mean/bad-assoc-ty.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,25 @@ LL | type E = _::AssocTy;
| ^^^^^^^^^^ help: try: `<_>::AssocTy`

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

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

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

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

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/bad-assoc-ty.rs:17:10
|
LL | type E = _::AssocTy;
| ^ not allowed in type signatures

error[E0223]: ambiguous associated type
--> $DIR/bad-assoc-ty.rs:21:19
--> $DIR/bad-assoc-ty.rs:22:19
|
LL | type F = &'static (u8)::AssocTy;
| ^^^^^^^^^^^^^ help: use fully-qualified syntax: `<u8 as Trait>::AssocTy`

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

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

error[E0223]: ambiguous associated type
--> $DIR/bad-assoc-ty.rs:37:19
--> $DIR/bad-assoc-ty.rs:38:19
|
LL | ($ty: ty) => ($ty::AssocTy);
| ^^^^^^^^^^^^ help: use fully-qualified syntax: `<u8 as Trait>::AssocTy`
Expand All @@ -117,12 +123,12 @@ LL | type J = ty!(u8);
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

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

error: aborting due to 19 previous errors
error: aborting due to 20 previous errors

Some errors have detailed explanations: E0121, E0223.
For more information about an error, try `rustc --explain E0121`.
2 changes: 2 additions & 0 deletions src/test/ui/self/self-infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ struct S;

impl S {
fn f(self: _) {} //~ERROR the type placeholder `_` is not allowed within types on item sig
//~^ ERROR the type placeholder `_` is not allowed within types on item sig
fn g(self: &_) {} //~ERROR the type placeholder `_` is not allowed within types on item sig
//~^ ERROR the type placeholder `_` is not allowed within types on item sig
}

fn main() {}
16 changes: 14 additions & 2 deletions src/test/ui/self/self-infer.stderr
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/self-infer.rs:4:16
|
LL | fn f(self: _) {}
| ^ not allowed in type signatures

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/self-infer.rs:4:16
|
Expand All @@ -10,7 +16,13 @@ LL | fn f<T>(self: T) {}
| ^^^ ^

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/self-infer.rs:5:17
--> $DIR/self-infer.rs:6:17
|
LL | fn g(self: &_) {}
| ^ not allowed in type signatures

error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/self-infer.rs:6:17
|
LL | fn g(self: &_) {}
| ^ not allowed in type signatures
Expand All @@ -20,6 +32,6 @@ help: use type parameters instead
LL | fn g<T>(self: &T) {}
| ^^^ ^

error: aborting due to 2 previous errors
error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0121`.
34 changes: 34 additions & 0 deletions src/test/ui/typeck/typeck_type_placeholder_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,24 @@ static TEST5: (_, _) = (1, 2);

fn test6(_: _) { }
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures

fn test6_b<T>(_: _, _: T) { }
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures

fn test6_c<T, K, L, A, B>(_: _, _: (T, K, L, A, B)) { }
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures

fn test7(x: _) { let _x: usize = x; }
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures

fn test8(_f: fn() -> _) { }
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures

struct Test9;

Expand All @@ -41,6 +46,7 @@ impl Test9 {

fn test10(&self, _x : _) { }
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
}

fn test11(x: &usize) -> &_ {
Expand All @@ -59,12 +65,16 @@ impl Clone for Test9 {

fn clone_from(&mut self, other: _) { *self = Test9; }
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
}

struct Test10 {
a: _,
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
b: (_, _),
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
}

pub fn main() {
Expand Down Expand Up @@ -92,13 +102,16 @@ pub fn main() {

fn fn_test6(_: _) { }
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures

fn fn_test7(x: _) { let _x: usize = x; }
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures

fn fn_test8(_f: fn() -> _) { }
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures

struct FnTest9;

Expand All @@ -108,6 +121,7 @@ pub fn main() {

fn fn_test10(&self, _x : _) { }
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
}

impl Clone for FnTest9 {
Expand All @@ -116,12 +130,16 @@ pub fn main() {

fn clone_from(&mut self, other: _) { *self = FnTest9; }
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
}

struct FnTest10 {
a: _,
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
b: (_, _),
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
}

fn fn_test11(_: _) -> (_, _) { panic!() }
Expand All @@ -138,28 +156,40 @@ pub fn main() {
trait T {
fn method_test1(&self, x: _);
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
fn method_test2(&self, x: _) -> _;
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
fn method_test3(&self) -> _;
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
fn assoc_fn_test1(x: _);
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
fn assoc_fn_test2(x: _) -> _;
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
fn assoc_fn_test3() -> _;
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
}

struct BadStruct<_>(_);
//~^ ERROR expected identifier, found reserved identifier `_`
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
trait BadTrait<_> {}
//~^ ERROR expected identifier, found reserved identifier `_`
impl BadTrait<_> for BadStruct<_> {}
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures

fn impl_trait() -> impl BadTrait<_> {
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
unimplemented!()
}

Expand All @@ -168,18 +198,22 @@ struct BadStruct1<_, _>(_);
//~| ERROR expected identifier, found reserved identifier `_`
//~| ERROR the name `_` is already used
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
struct BadStruct2<_, T>(_, T);
//~^ ERROR expected identifier, found reserved identifier `_`
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures

type X = Box<_>;
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures

struct Struct;
trait Trait<T> {}
impl Trait<usize> for Struct {}
type Y = impl Trait<_>;
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR the type placeholder `_` is not allowed within types on item signatures
fn foo() -> Y {
Struct
}
Loading

0 comments on commit add9338

Please sign in to comment.