Skip to content

Commit

Permalink
Rollup merge of rust-lang#110272 - Ezrashaw:fix-unconned-lt-in-implbo…
Browse files Browse the repository at this point in the history
…unds, r=aliemjay

fix: skip implied bounds if unconstrained lifetime exists

Fixes rust-lang#110161

r? ``@aliemjay``
  • Loading branch information
aliemjay committed Apr 15, 2023
2 parents cd5e6a0 + 4c80f58 commit f21f14b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
13 changes: 12 additions & 1 deletion compiler/rustc_trait_selection/src/traits/outlives_bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,18 @@ 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 do not expect existential variables in implied bounds.
// We may however encounter unconstrained lifetime variables in invalid
// code. See #110161 for context.
assert!(!ty.has_non_region_infer());
if ty.needs_infer() {
self.tcx.sess.delay_span_bug(
self.tcx.def_span(body_id),
"skipped implied_outlives_bounds due to unconstrained lifetimes",
);
return vec![];
}

let span = self.tcx.def_span(body_id);
let result = param_env
Expand Down
26 changes: 26 additions & 0 deletions tests/ui/implied-bounds/issue-110161.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// ICE regression relating to unconstrained lifetimes in implied
// bounds. See #110161.

// compile-flags: --crate-type=lib

trait LtTrait {
type Ty;
}

// erroneous `Ty` impl
impl LtTrait for () {
//~^ ERROR not all trait items implemented, missing: `Ty` [E0046]
}

// `'lt` is not constrained by the erroneous `Ty`
impl<'lt, T> LtTrait for Box<T>
where
T: LtTrait<Ty = &'lt ()>,
{
type Ty = &'lt ();
}

// unconstrained lifetime appears in implied bounds
fn test(_: <Box<()> as LtTrait>::Ty) {}

fn test2<'x>(_: &'x <Box<()> as LtTrait>::Ty) {}
12 changes: 12 additions & 0 deletions tests/ui/implied-bounds/issue-110161.stderr
Original file line number Diff line number Diff line change
@@ -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 LtTrait for () {
| ^^^^^^^^^^^^^^^^^^^ missing `Ty` in implementation

error: aborting due to previous error

For more information about this error, try `rustc --explain E0046`.

0 comments on commit f21f14b

Please sign in to comment.