fix: skip implied bounds if unconstrained lifetime exists

This commit is contained in:
Ezra Shaw 2023-04-13 20:29:41 +12:00
parent a29dada983
commit ecf2a9b75e
No known key found for this signature in database
GPG Key ID: 67ABF16FB0ECD870
3 changed files with 46 additions and 1 deletions

View File

@ -55,7 +55,16 @@ impl<'a, 'tcx: 'a> InferCtxtExt<'a, 'tcx> for InferCtxt<'tcx> {
) -> Vec<OutlivesBound<'tcx>> {
let ty = self.resolve_vars_if_possible(ty);
let ty = OpportunisticRegionResolver::new(self).fold_ty(ty);
assert!(!ty.needs_infer());
// We must avoid processing constrained lifetime variables in implied
// bounds. See #110161 for context.
if ty.needs_infer() {
self.tcx.sess.delay_span_bug(
self.tcx.source_span_untracked(body_id),
"skipped implied_outlives_bounds due to unconstrained lifetimes",
);
return vec![];
}
let span = self.tcx.def_span(body_id);
let result = param_env

View File

@ -0,0 +1,24 @@
// ICE regression relating to unconstrained lifetimes in implied
// bounds. See #110161.
// compile-flags: --crate-type=lib
trait Trait {
type Ty;
}
// erroneous `Ty` impl
impl Trait for () {
//~^ ERROR not all trait items implemented, missing: `Ty` [E0046]
}
// `'lt` is not constrained by the erroneous `Ty`
impl<'lt, T> Trait for Box<T>
where
T: Trait<Ty = &'lt ()>,
{
type Ty = &'lt ();
}
// unconstrained lifetime appears in implied bounds
fn test(_: <Box<()> as Trait>::Ty) {}

View File

@ -0,0 +1,12 @@
error[E0046]: not all trait items implemented, missing: `Ty`
--> $DIR/issue-110161.rs:11:1
|
LL | type Ty;
| ------- `Ty` from trait
...
LL | impl Trait for () {
| ^^^^^^^^^^^^^^^^^ missing `Ty` in implementation
error: aborting due to previous error
For more information about this error, try `rustc --explain E0046`.