Delay a bug for stranded opaques
This commit is contained in:
parent
3cbb93223f
commit
026eb3dd64
@ -381,11 +381,17 @@ fn check_opaque_meets_bounds<'tcx>(
|
|||||||
match ocx.eq(&misc_cause, param_env, opaque_ty, hidden_ty) {
|
match ocx.eq(&misc_cause, param_env, opaque_ty, hidden_ty) {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(ty_err) => {
|
Err(ty_err) => {
|
||||||
|
// Some types may be left "stranded" if they can't be reached
|
||||||
|
// from an astconv'd bound but they're mentioned in the HIR. This
|
||||||
|
// will happen, e.g., when a nested opaque is inside of a non-
|
||||||
|
// existent associated type, like `impl Trait<Missing = impl Trait>`.
|
||||||
|
// See <tests/ui/impl-trait/stranded-opaque.rs>.
|
||||||
let ty_err = ty_err.to_string(tcx);
|
let ty_err = ty_err.to_string(tcx);
|
||||||
tcx.dcx().span_bug(
|
let guar = tcx.dcx().span_delayed_bug(
|
||||||
span,
|
span,
|
||||||
format!("could not unify `{hidden_ty}` with revealed type:\n{ty_err}"),
|
format!("could not unify `{hidden_ty}` with revealed type:\n{ty_err}"),
|
||||||
);
|
);
|
||||||
|
return Err(guar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
tests/ui/impl-trait/stranded-opaque.rs
Normal file
13
tests/ui/impl-trait/stranded-opaque.rs
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
trait Trait {}
|
||||||
|
|
||||||
|
impl Trait for i32 {}
|
||||||
|
|
||||||
|
// Since `Assoc` doesn't actually exist, it's "stranded", and won't show up in
|
||||||
|
// the list of opaques that may be defined by the function. Make sure we don't
|
||||||
|
// ICE in this case.
|
||||||
|
fn produce<T>() -> impl Trait<Assoc = impl Trait> {
|
||||||
|
//~^ ERROR associated type `Assoc` not found for `Trait`
|
||||||
|
16
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main () {}
|
9
tests/ui/impl-trait/stranded-opaque.stderr
Normal file
9
tests/ui/impl-trait/stranded-opaque.stderr
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
error[E0220]: associated type `Assoc` not found for `Trait`
|
||||||
|
--> $DIR/stranded-opaque.rs:8:31
|
||||||
|
|
|
||||||
|
LL | fn produce<T>() -> impl Trait<Assoc = impl Trait> {
|
||||||
|
| ^^^^^ associated type `Assoc` not found
|
||||||
|
|
||||||
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0220`.
|
Loading…
x
Reference in New Issue
Block a user