Skip to content

Commit

Permalink
make outlives constraints from pointer comparisons less boring
Browse files Browse the repository at this point in the history
  • Loading branch information
dianne committed Jan 7, 2025
1 parent 10061b3 commit 2c5815b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2181,7 +2181,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
ty_left,
common_ty,
location.to_locations(),
ConstraintCategory::Boring,
ConstraintCategory::CallArgument(None),
)
.unwrap_or_else(|err| {
bug!("Could not equate type variable with {:?}: {:?}", ty_left, err)
Expand All @@ -2190,7 +2190,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
ty_right,
common_ty,
location.to_locations(),
ConstraintCategory::Boring,
ConstraintCategory::CallArgument(None),
) {
span_mirbug!(
self,
Expand Down
30 changes: 15 additions & 15 deletions tests/ui/nll/type-check-pointer-comparisons.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,24 @@ LL | fn compare_const<'a, 'b>(x: *const &mut &'a i32, y: *const &mut &'b i32) {
| |
| lifetime `'a` defined here
LL | x == y;
| ^ requires that `'b` must outlive `'a`
| ^^^^^^ argument requires that `'a` must outlive `'b`
|
= help: consider adding the following bound: `'b: 'a`
= 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

error: lifetime may not live long enough
--> $DIR/type-check-pointer-comparisons.rs:4:10
--> $DIR/type-check-pointer-comparisons.rs:4: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
LL | x == y;
| ^ requires that `'a` must outlive `'b`
| ^^^^^^ argument requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'a: 'b`
= help: consider adding the following bound: `'b: 'a`
= 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
Expand All @@ -38,24 +38,24 @@ LL | fn compare_mut<'a, 'b>(x: *mut &'a i32, y: *mut &'b i32) {
| |
| lifetime `'a` defined here
LL | x == y;
| ^ requires that `'b` must outlive `'a`
| ^^^^^^ argument requires that `'a` must outlive `'b`
|
= help: consider adding the following bound: `'b: 'a`
= help: consider adding the following bound: `'a: 'b`
= 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

error: lifetime may not live long enough
--> $DIR/type-check-pointer-comparisons.rs:10:10
--> $DIR/type-check-pointer-comparisons.rs:10:5
|
LL | fn compare_mut<'a, 'b>(x: *mut &'a i32, y: *mut &'b i32) {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
LL | x == y;
| ^ requires that `'a` must outlive `'b`
| ^^^^^^ argument requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'a: '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
Expand All @@ -72,24 +72,24 @@ LL | fn compare_fn_ptr<'a, 'b, 'c>(f: fn(&'c mut &'a i32), g: fn(&'c mut &'b i32
| |
| lifetime `'a` defined here
LL | f == g;
| ^ requires that `'b` must outlive `'a`
| ^^^^^^ argument requires that `'a` must outlive `'b`
|
= help: consider adding the following bound: `'b: 'a`
= 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

error: lifetime may not live long enough
--> $DIR/type-check-pointer-comparisons.rs:16:10
--> $DIR/type-check-pointer-comparisons.rs:16:5
|
LL | fn compare_fn_ptr<'a, 'b, 'c>(f: fn(&'c mut &'a i32), g: fn(&'c mut &'b i32)) {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
LL | f == g;
| ^ requires that `'a` must outlive `'b`
| ^^^^^^ argument requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'a: 'b`
= help: consider adding the following bound: `'b: 'a`
= 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
Expand Down

0 comments on commit 2c5815b

Please sign in to comment.