Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] some mir typeck cleanup #95763

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,15 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
place_ty = self.sanitize_projection(place_ty, elem, place, location);
}

self.cx.prove_predicate(
ty::Binder::dummy(ty::PredicateKind::WellFormed(
self.body().local_decls[place.local].ty.into(),
))
.to_predicate(self.tcx()),
location.to_locations(),
ConstraintCategory::Boring,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have a known bug that is affected by this?

);

if let PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) = context {
let tcx = self.tcx();
let trait_ref = ty::TraitRef {
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/borrowck/issue-7573.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub fn remove_package_from_database() {
lines_to_use.push(installed_id);
//~^ ERROR borrowed data escapes outside of closure
//~| NOTE `installed_id` escapes the closure body here
//~| NOTE requirement occurs because of a mutable reference to `Vec<&CrateId>`
//~| NOTE mutable references are invariant over their type parameter
};
list_database(push_id);

Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/borrowck/issue-7573.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ LL | let push_id = |installed_id: &CrateId| {
LL |
LL | lines_to_use.push(installed_id);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `installed_id` escapes the closure body here
|
= note: requirement occurs because of a mutable reference to `Vec<&CrateId>`
= note: mutable references are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// compile-flags: -Zdeduplicate-diagnostics=yes
// check-pass

const fn foo<T>() -> usize {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: cannot use constants which depend on generic parameters in types
--> $DIR/function-call.rs:14:17
--> $DIR/function-call.rs:15:17
|
LL | let _ = [0; foo::<T>()];
| ^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// compile-flags: -Zdeduplicate-diagnostics=yes
// check-pass
#![allow(dead_code)]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
warning: cannot use constants which depend on generic parameters in types
--> $DIR/const-evaluatable-unchecked.rs:5:9
--> $DIR/const-evaluatable-unchecked.rs:6:9
|
LL | [0; std::mem::size_of::<*mut T>()];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -9,7 +9,7 @@ LL | [0; std::mem::size_of::<*mut T>()];
= note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200>

warning: cannot use constants which depend on generic parameters in types
--> $DIR/const-evaluatable-unchecked.rs:16:21
--> $DIR/const-evaluatable-unchecked.rs:17:21
|
LL | let _ = [0; Self::ASSOC];
| ^^^^^^^^^^^
Expand All @@ -18,7 +18,7 @@ LL | let _ = [0; Self::ASSOC];
= note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200>

warning: cannot use constants which depend on generic parameters in types
--> $DIR/const-evaluatable-unchecked.rs:28:21
--> $DIR/const-evaluatable-unchecked.rs:29:21
|
LL | let _ = [0; Self::ASSOC];
| ^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ LL | let mut closure = expect_sig(|p, y| *p = y);
| - - ^^^^^^ assignment requires that `'1` must outlive `'2`
| | |
| | has type `&'1 i32`
| has type `&'_#2r mut &'2 i32`
| has type `&'2 mut &'_#3r i32`

note: no external requirements
--> $DIR/escape-argument-callee.rs:20:1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ LL | let mut closure1 = || p = &y;
(&'_#1r mut &'_#2r i32, &'_#3r i32),
]
= note: number of external vids: 4
= note: where '_#3r: '_#1r
= note: where '_#3r: '_#2r

note: external requirements
Expand All @@ -28,6 +29,7 @@ LL | | };
(&'_#1r mut &'_#2r i32, &'_#3r i32),
]
= note: number of external vids: 4
= note: where '_#3r: '_#1r
= note: where '_#3r: '_#2r

note: no external requirements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ LL | let mut closure = || p = &y;
(&'_#1r mut &'_#2r i32, &'_#3r i32),
]
= note: number of external vids: 4
= note: where '_#3r: '_#1r
= note: where '_#3r: '_#2r

note: no external requirements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ LL | | });
= note: late-bound region is '_#4r
= note: number of external vids: 5
= note: where '_#1r: '_#2r
= note: where '_#1r: '_#2r
= note: where '_#1r: '_#2r

note: no external requirements
--> $DIR/propagate-approximated-ref.rs:42:1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ LL | | });
= note: late-bound region is '_#3r
= note: number of external vids: 4
= note: where '_#1r: '_#0r
= note: where '_#1r: '_#0r

note: no external requirements
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:31:1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ LL | | });
= note: late-bound region is '_#3r
= note: late-bound region is '_#4r
= note: number of external vids: 5
= note: where '_#1r: '_#2r
= note: where '_#1r: '_#2r
= note: where '_#1r: '_#0r
= note: where '_#1r: '_#0r

note: no external requirements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ error: lifetime may not live long enough
LL | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
| --------- - has type `&'_#7r Cell<&'1 u32>`
| |
| has type `&'_#5r Cell<&'2 &'_#1r u32>`
| has type `&'2 Cell<&'_#6r &'_#1r u32>`
LL | // Only works if 'x: 'y:
LL | demand_y(x, y, x.get())
| ^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'1` must outlive `'2`
|
= note: requirement occurs because of the type `Cell<&'_#38r u32>`, which makes the generic argument `&'_#38r u32` invariant
= note: the struct `Cell<T>` is invariant over the parameter `T`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance

note: no external requirements
--> $DIR/propagate-fail-to-approximate-longer-no-bounds.rs:34:1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
// Only works if 'x: 'y:
demand_y(x, y, x.get())
//~^ ERROR
//~| ERROR
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
note: no external requirements
note: external requirements
--> $DIR/propagate-fail-to-approximate-longer-wrong-bounds.rs:39:47
|
LL | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
| _______________________________________________^
LL | | // Only works if 'x: 'y:
LL | | demand_y(x, y, x.get())
LL | |
LL | |
LL | | });
| |_____^
|
Expand All @@ -16,17 +17,25 @@ LL | | });
]
= note: late-bound region is '_#3r
= note: late-bound region is '_#4r
= note: number of external vids: 5
= note: where '_#1r: '_#2r
= note: where '_#1r: '_#2r
= note: where '_#1r: '_#2r

error: lifetime may not live long enough
--> $DIR/propagate-fail-to-approximate-longer-wrong-bounds.rs:41:9
|
LL | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
| ---------- ---------- has type `&'_#8r Cell<&'2 &'_#2r u32>`
| ---------- ---------- has type `&'2 Cell<&'_#9r &'_#2r u32>`
| |
| has type `&'_#6r Cell<&'1 &'_#1r u32>`
LL | // Only works if 'x: 'y:
LL | demand_y(x, y, x.get())
| ^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'1` must outlive `'2`
|
= note: requirement occurs because of the type `Cell<&'_#44r u32>`, which makes the generic argument `&'_#44r u32` invariant
= note: the struct `Cell<T>` is invariant over the parameter `T`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance

note: no external requirements
--> $DIR/propagate-fail-to-approximate-longer-wrong-bounds.rs:38:1
Expand All @@ -35,12 +44,25 @@ LL | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
LL | | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
LL | | // Only works if 'x: 'y:
LL | | demand_y(x, y, x.get())
LL | |
... |
LL | | });
LL | | }
| |_^
|
= note: defining type: supply

error: aborting due to previous error
error: lifetime may not live long enough
--> $DIR/propagate-fail-to-approximate-longer-wrong-bounds.rs:41:9
|
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
...
LL | demand_y(x, y, x.get())
| ^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'a` must outlive `'b`
|
= help: consider adding the following bound: `'a: 'b`

error: aborting due to 2 previous errors

3 changes: 1 addition & 2 deletions src/test/ui/nll/issue-95272.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ where

fn test<'a, 'b>(x: Cell<&'a ()>, y: Cell<&'b ()>) {
let f = check;
//~^ ERROR lifetime may not live long enough
f(x, y);
f(x, y); //~ ERROR lifetime may not live long enough
}

fn main() {}
9 changes: 5 additions & 4 deletions src/test/ui/nll/issue-95272.stderr
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
error: lifetime may not live long enough
--> $DIR/issue-95272.rs:12:13
--> $DIR/issue-95272.rs:13:5
|
LL | fn test<'a, 'b>(x: Cell<&'a ()>, y: Cell<&'b ()>) {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
LL | let f = check;
| ^^^^^ assignment requires that `'a` must outlive `'b`
LL | f(x, y);
| ^^^^^^^ argument requires that `'a` must outlive `'b`
|
= help: consider adding the following bound: `'a: 'b`
= note: requirement occurs because of a function pointer to `check`
= note: the function `check` is invariant over the parameter `'a`
= note: requirement occurs because of the type `Cell<&()>`, which makes the generic argument `&()` invariant
= note: the struct `Cell<T>` is invariant over the parameter `T`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance

error: aborting due to previous error
Expand Down
16 changes: 4 additions & 12 deletions src/test/ui/nll/type-check-pointer-coercions.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,14 @@ LL | x
|
= help: consider adding the following bound: `'a: 'b`

error: lifetime may not live long enough
error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/type-check-pointer-coercions.rs:13:5
|
LL | fn unique_to_mut<'a, 'b>(x: &mut &'a i32) -> *mut &'b i32 {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
| ------------ help: add explicit lifetime `'b` to the type of `x`: `&'b mut &'a i32`
LL | // Two errors because *mut is invariant
LL | x
| ^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b`
|
= help: consider adding the following bound: `'b: 'a`
= note: requirement occurs because of a mutable pointer to `&i32`
= note: mutable pointers are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
| ^ lifetime `'b` required

error: lifetime may not live long enough
--> $DIR/type-check-pointer-coercions.rs:13:5
Expand All @@ -54,8 +47,6 @@ LL | x
= note: mutable pointers are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance

help: `'b` and `'a` must be the same: replace one with the other

error: lifetime may not live long enough
--> $DIR/type-check-pointer-coercions.rs:18:5
|
Expand Down Expand Up @@ -109,3 +100,4 @@ LL | y

error: aborting due to 8 previous errors

For more information about this error, try `rustc --explain E0621`.
2 changes: 1 addition & 1 deletion src/test/ui/nll/type-check-pointer-comparisons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

fn compare_const<'a, 'b>(x: *const &mut &'a i32, y: *const &mut &'b i32) {
x == y;
//~^ ERROR lifetime may not live long enough
//~^ ERROR explicit lifetime required in the type of `y`
//~| ERROR lifetime may not live long enough
}

Expand Down
16 changes: 4 additions & 12 deletions src/test/ui/nll/type-check-pointer-comparisons.stderr
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
error: lifetime may not live long enough
error[E0621]: explicit lifetime required in the type of `y`
--> $DIR/type-check-pointer-comparisons.rs:6:5
|
LL | fn compare_const<'a, 'b>(x: *const &mut &'a i32, y: *const &mut &'b i32) {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
| ------------------- help: add explicit lifetime `'a` to the type of `y`: `*const &'a mut &'b i32`
LL | x == y;
| ^ requires that `'a` must outlive `'b`
|
= help: consider adding the following bound: `'a: 'b`
= note: requirement occurs because of a mutable reference to `&i32`
= note: mutable references are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
| ^ lifetime `'a` required

error: lifetime may not live long enough
--> $DIR/type-check-pointer-comparisons.rs:6:10
Expand All @@ -28,8 +21,6 @@ LL | x == y;
= note: mutable references are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance

help: `'a` and `'b` must be the same: replace one with the other

error: lifetime may not live long enough
--> $DIR/type-check-pointer-comparisons.rs:12:5
|
Expand Down Expand Up @@ -96,3 +87,4 @@ help: `'a` and `'b` must be the same: replace one with the other

error: aborting due to 6 previous errors

For more information about this error, try `rustc --explain E0621`.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ error: lifetime may not live long enough
LL | doit(0, &|x, y| {
| - - has type `&'1 i32`
| |
| has type `&Cell<&'2 i32>`
| has type `&'2 Cell<&i32>`
LL | x.set(y);
| ^^^^^^^^ argument requires that `'1` must outlive `'2`
|
= note: requirement occurs because of the type `Cell<&i32>`, which makes the generic argument `&i32` invariant
= note: the struct `Cell<T>` is invariant over the parameter `T`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance

error: aborting due to previous error

Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ error: lifetime may not live long enough
--> $DIR/underscore-lifetime-elison-mismatch.rs:5:42
|
LL | fn foo(x: &mut Vec<&'_ u8>, y: &'_ u8) { x.push(y); }
| - - ^^^^^^^^^ argument requires that `'1` must outlive `'2`
| | |
| | let's call the lifetime of this reference `'1`
| let's call the lifetime of this reference `'2`
| - - ^^^^^^^^^ argument requires that `'1` must outlive `'2`
| | |
| | let's call the lifetime of this reference `'1`
| let's call the lifetime of this reference `'2`
|
= note: requirement occurs because of a mutable reference to `Vec<&u8>`
= note: mutable references are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance

error: aborting due to previous error