Skip to content

Commit

Permalink
fix the new unsoundness
Browse files Browse the repository at this point in the history
  • Loading branch information
aliemjay committed Mar 5, 2023
1 parent eea5604 commit bfd3501
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
9 changes: 8 additions & 1 deletion compiler/rustc_infer/src/infer/region_constraints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,14 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
) -> ty::Region<'tcx> {
let mut ut = self.unification_table_mut(); // FIXME(rust-lang/ena#42): unnecessary mut
let root_vid = ut.find(vid).vid;
ut.probe_value(root_vid).0.unwrap_or_else(|| tcx.mk_re_var(root_vid))
let resolved = ut.probe_value(root_vid).0.unwrap_or_else(|| tcx.mk_re_var(root_vid));

// Don't resolve a variable to a region that it cannot name.
if self.var_universe(vid).can_name(self.universe(resolved)) {
resolved
} else {
tcx.mk_re_var(vid)
}
}

fn combine_map(&mut self, t: CombineMapType) -> &mut CombineMap<'tcx> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
//
// In particular, we test this pattern in trait solving, where it is not connected
// to any part of the source code.
//
// check-pass
// Oops!

use std::cell::Cell;

Expand All @@ -28,5 +25,5 @@ fn main() {
// yielding `fn(&!b u32)`, in a fresh universe U1
// - So we get `?a = !b` but the universe U0 assigned to `?a` cannot name `!b`.

foo::<()>();
foo::<()>(); //~ ERROR implementation of `Trait` is not general enough
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: implementation of `Trait` is not general enough
--> $DIR/hrtb-exists-forall-trait-invariant.rs:28:5
|
LL | foo::<()>();
| ^^^^^^^^^^^ implementation of `Trait` is not general enough
|
= note: `()` must implement `Trait<for<'b> fn(Cell<&'b u32>)>`
= note: ...but it actually implements `Trait<fn(Cell<&'0 u32>)>`, for some specific lifetime `'0`

error: aborting due to previous error

6 changes: 6 additions & 0 deletions tests/ui/higher-rank-trait-bounds/hrtb-just-for-static.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ LL | fn give_some<'a>() {
| -- lifetime `'a` defined here
LL | want_hrtb::<&'a u32>()
| ^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'static`
|
note: due to current limitations in the borrow checker, this implies a `'static` lifetime
--> $DIR/hrtb-just-for-static.rs:9:15
|
LL | where T : for<'a> Foo<&'a isize>
| ^^^^^^^^^^^^^^^^^^^^^^

error: implementation of `Foo` is not general enough
--> $DIR/hrtb-just-for-static.rs:30:5
Expand Down

0 comments on commit bfd3501

Please sign in to comment.