Rollup merge of #108115 - eggyal:unmet_trait_alias_bound, r=compiler-errors
Do not ICE on unmet trait alias bounds Rework of #108093 following feedback on that PR. Fixes #108072 r? `@compiler-errors`
This commit is contained in:
commit
d77b0221f8
@ -477,12 +477,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
// This is the "trait" (meaning, the predicate "proved" by this `impl`) which provides the `Self` type we care about.
|
// This is the "trait" (meaning, the predicate "proved" by this `impl`) which provides the `Self` type we care about.
|
||||||
// For the purposes of this function, we hope that it is a `struct` type, and that our current `expr` is a literal of
|
// For the purposes of this function, we hope that it is a `struct` type, and that our current `expr` is a literal of
|
||||||
// that struct type.
|
// that struct type.
|
||||||
let impl_trait_self_ref: Option<ty::TraitRef<'tcx>> =
|
let impl_trait_self_ref = if self.tcx.is_trait_alias(obligation.impl_def_id) {
|
||||||
self.tcx.impl_trait_ref(obligation.impl_def_id).map(|impl_def| impl_def.skip_binder());
|
self.tcx.mk_trait_ref(
|
||||||
|
obligation.impl_def_id,
|
||||||
let Some(impl_trait_self_ref) = impl_trait_self_ref else {
|
ty::InternalSubsts::identity_for_item(self.tcx, obligation.impl_def_id),
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
self.tcx
|
||||||
|
.impl_trait_ref(obligation.impl_def_id)
|
||||||
|
.map(|impl_def| impl_def.skip_binder())
|
||||||
// It is possible that this is absent. In this case, we make no progress.
|
// It is possible that this is absent. In this case, we make no progress.
|
||||||
return Err(expr);
|
.ok_or(expr)?
|
||||||
};
|
};
|
||||||
|
|
||||||
// We only really care about the `Self` type itself, which we extract from the ref.
|
// We only really care about the `Self` type itself, which we extract from the ref.
|
||||||
|
@ -0,0 +1,11 @@
|
|||||||
|
// Regression test for #108072: do not ICE upon unmet trait alias constraint
|
||||||
|
|
||||||
|
#![feature(trait_alias)]
|
||||||
|
|
||||||
|
trait IteratorAlias = Iterator;
|
||||||
|
|
||||||
|
fn f(_: impl IteratorAlias) {}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
f(()) //~ `()` is not an iterator
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
error[E0277]: `()` is not an iterator
|
||||||
|
--> $DIR/issue-108072-unmet-trait-alias-bound.rs:10:7
|
||||||
|
|
|
||||||
|
LL | f(())
|
||||||
|
| - ^^ `()` is not an iterator
|
||||||
|
| |
|
||||||
|
| required by a bound introduced by this call
|
||||||
|
|
|
||||||
|
= help: the trait `Iterator` is not implemented for `()`
|
||||||
|
= note: required for `()` to implement `IteratorAlias`
|
||||||
|
note: required by a bound in `f`
|
||||||
|
--> $DIR/issue-108072-unmet-trait-alias-bound.rs:7:14
|
||||||
|
|
|
||||||
|
LL | fn f(_: impl IteratorAlias) {}
|
||||||
|
| ^^^^^^^^^^^^^ required by this bound in `f`
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0277`.
|
Loading…
x
Reference in New Issue
Block a user