Skip to content

Commit c52ce4e

Browse files
authored
Rollup merge of #122449 - compiler-errors:stranded-opaque, r=oli-obk
Delay a bug for stranded opaques r? oli-obk Fixes #122445
2 parents 8d2f79c + 026eb3d commit c52ce4e

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -381,11 +381,17 @@ fn check_opaque_meets_bounds<'tcx>(
381381
match ocx.eq(&misc_cause, param_env, opaque_ty, hidden_ty) {
382382
Ok(()) => {}
383383
Err(ty_err) => {
384+
// Some types may be left "stranded" if they can't be reached
385+
// from an astconv'd bound but they're mentioned in the HIR. This
386+
// will happen, e.g., when a nested opaque is inside of a non-
387+
// existent associated type, like `impl Trait<Missing = impl Trait>`.
388+
// See <tests/ui/impl-trait/stranded-opaque.rs>.
384389
let ty_err = ty_err.to_string(tcx);
385-
tcx.dcx().span_bug(
390+
let guar = tcx.dcx().span_delayed_bug(
386391
span,
387392
format!("could not unify `{hidden_ty}` with revealed type:\n{ty_err}"),
388393
);
394+
return Err(guar);
389395
}
390396
}
391397

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
trait Trait {}
2+
3+
impl Trait for i32 {}
4+
5+
// Since `Assoc` doesn't actually exist, it's "stranded", and won't show up in
6+
// the list of opaques that may be defined by the function. Make sure we don't
7+
// ICE in this case.
8+
fn produce<T>() -> impl Trait<Assoc = impl Trait> {
9+
//~^ ERROR associated type `Assoc` not found for `Trait`
10+
16
11+
}
12+
13+
fn main () {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0220]: associated type `Assoc` not found for `Trait`
2+
--> $DIR/stranded-opaque.rs:8:31
3+
|
4+
LL | fn produce<T>() -> impl Trait<Assoc = impl Trait> {
5+
| ^^^^^ associated type `Assoc` not found
6+
7+
error: aborting due to 1 previous error
8+
9+
For more information about this error, try `rustc --explain E0220`.

0 commit comments

Comments
 (0)