Skip to content

Commit d77b022

Browse files
authored
Rollup merge of rust-lang#108115 - eggyal:unmet_trait_alias_bound, r=compiler-errors
Do not ICE on unmet trait alias bounds Rework of rust-lang#108093 following feedback on that PR. Fixes rust-lang#108072 r? `@compiler-errors`
2 parents 09a2267 + 540bd98 commit d77b022

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/adjust_fulfillment_errors.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -477,12 +477,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
477477
// This is the "trait" (meaning, the predicate "proved" by this `impl`) which provides the `Self` type we care about.
478478
// For the purposes of this function, we hope that it is a `struct` type, and that our current `expr` is a literal of
479479
// that struct type.
480-
let impl_trait_self_ref: Option<ty::TraitRef<'tcx>> =
481-
self.tcx.impl_trait_ref(obligation.impl_def_id).map(|impl_def| impl_def.skip_binder());
482-
483-
let Some(impl_trait_self_ref) = impl_trait_self_ref else {
484-
// It is possible that this is absent. In this case, we make no progress.
485-
return Err(expr);
480+
let impl_trait_self_ref = if self.tcx.is_trait_alias(obligation.impl_def_id) {
481+
self.tcx.mk_trait_ref(
482+
obligation.impl_def_id,
483+
ty::InternalSubsts::identity_for_item(self.tcx, obligation.impl_def_id),
484+
)
485+
} else {
486+
self.tcx
487+
.impl_trait_ref(obligation.impl_def_id)
488+
.map(|impl_def| impl_def.skip_binder())
489+
// It is possible that this is absent. In this case, we make no progress.
490+
.ok_or(expr)?
486491
};
487492

488493
// We only really care about the `Self` type itself, which we extract from the ref.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Regression test for #108072: do not ICE upon unmet trait alias constraint
2+
3+
#![feature(trait_alias)]
4+
5+
trait IteratorAlias = Iterator;
6+
7+
fn f(_: impl IteratorAlias) {}
8+
9+
fn main() {
10+
f(()) //~ `()` is not an iterator
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0277]: `()` is not an iterator
2+
--> $DIR/issue-108072-unmet-trait-alias-bound.rs:10:7
3+
|
4+
LL | f(())
5+
| - ^^ `()` is not an iterator
6+
| |
7+
| required by a bound introduced by this call
8+
|
9+
= help: the trait `Iterator` is not implemented for `()`
10+
= note: required for `()` to implement `IteratorAlias`
11+
note: required by a bound in `f`
12+
--> $DIR/issue-108072-unmet-trait-alias-bound.rs:7:14
13+
|
14+
LL | fn f(_: impl IteratorAlias) {}
15+
| ^^^^^^^^^^^^^ required by this bound in `f`
16+
17+
error: aborting due to previous error
18+
19+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)