-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #126884 - estebank:issue-125634, r=Nadrieril
Do not ICE when suggesting dereferencing closure arg Account for `for` lifetimes when constructing closure to see if dereferencing the return value would be valid. Fix #125634, fix #124563.
- Loading branch information
Showing
8 changed files
with
119 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
tests/ui/regions/account-for-lifetimes-in-closure-suggestion.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// #125634 | ||
struct Thing; | ||
|
||
// Invariant in 'a, Covariant in 'b | ||
struct TwoThings<'a, 'b>(*mut &'a (), &'b mut ()); | ||
|
||
impl Thing { | ||
fn enter_scope<'a>(self, _scope: impl for<'b> FnOnce(TwoThings<'a, 'b>)) {} | ||
} | ||
|
||
fn foo() { | ||
Thing.enter_scope(|ctx| { | ||
SameLifetime(ctx); //~ ERROR lifetime may not live long enough | ||
}); | ||
} | ||
|
||
struct SameLifetime<'a>(TwoThings<'a, 'a>); | ||
|
||
fn main() {} |
17 changes: 17 additions & 0 deletions
17
tests/ui/regions/account-for-lifetimes-in-closure-suggestion.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
error: lifetime may not live long enough | ||
--> $DIR/account-for-lifetimes-in-closure-suggestion.rs:13:22 | ||
| | ||
LL | Thing.enter_scope(|ctx| { | ||
| --- | ||
| | | ||
| has type `TwoThings<'_, '1>` | ||
| has type `TwoThings<'2, '_>` | ||
LL | SameLifetime(ctx); | ||
| ^^^ this usage requires that `'1` must outlive `'2` | ||
| | ||
= note: requirement occurs because of the type `TwoThings<'_, '_>`, which makes the generic argument `'_` invariant | ||
= note: the struct `TwoThings<'a, 'b>` is invariant over the parameter `'a` | ||
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance | ||
|
||
error: aborting due to 1 previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
tests/ui/regions/lifetime-not-long-enough-suggestion-regression-test-124563.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
error[E0478]: lifetime bound not satisfied | ||
--> $DIR/lifetime-not-long-enough-suggestion-regression-test-124563.rs:19:16 | ||
| | ||
LL | type Bar = BarImpl<'a, 'b, T>; | ||
| ^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: lifetime parameter instantiated with the lifetime `'a` as defined here | ||
--> $DIR/lifetime-not-long-enough-suggestion-regression-test-124563.rs:14:6 | ||
| | ||
LL | impl<'a, 'b, T> Foo for FooImpl<'a, 'b, T> | ||
| ^^ | ||
note: but lifetime parameter must outlive the lifetime `'b` as defined here | ||
--> $DIR/lifetime-not-long-enough-suggestion-regression-test-124563.rs:14:10 | ||
| | ||
LL | impl<'a, 'b, T> Foo for FooImpl<'a, 'b, T> | ||
| ^^ | ||
|
||
error: lifetime may not live long enough | ||
--> $DIR/lifetime-not-long-enough-suggestion-regression-test-124563.rs:23:21 | ||
| | ||
LL | self.enter_scope(|ctx| { | ||
| --- | ||
| | | ||
| has type `&'1 mut FooImpl<'_, '_, T>` | ||
| has type `&mut FooImpl<'2, '_, T>` | ||
LL | BarImpl(ctx); | ||
| ^^^ this usage requires that `'1` must outlive `'2` | ||
|
||
error: lifetime may not live long enough | ||
--> $DIR/lifetime-not-long-enough-suggestion-regression-test-124563.rs:22:9 | ||
| | ||
LL | impl<'a, 'b, T> Foo for FooImpl<'a, 'b, T> | ||
| -- -- lifetime `'b` defined here | ||
| | | ||
| lifetime `'a` defined here | ||
... | ||
LL | / self.enter_scope(|ctx| { | ||
LL | | BarImpl(ctx); | ||
LL | | }); | ||
| |__________^ argument requires that `'a` must outlive `'b` | ||
| | ||
= help: consider adding the following bound: `'a: 'b` | ||
= note: requirement occurs because of a mutable reference to `FooImpl<'_, '_, T>` | ||
= 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 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0478`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Test a method call where the parameter `B` would (illegally) be | ||
// inferred to a region bound in the method argument. If this program | ||
// were accepted, then the closure passed to `s.f` could escape its | ||
// argument. | ||
//@ run-rustfix | ||
|
||
struct S; | ||
|
||
impl S { | ||
fn f<B, F>(&self, _: F) where F: FnOnce(&i32) -> B { | ||
} | ||
} | ||
|
||
fn main() { | ||
let s = S; | ||
s.f(|p| *p) //~ ERROR lifetime may not live long enough | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
error: lifetime may not live long enough | ||
--> $DIR/regions-escape-method.rs:15:13 | ||
--> $DIR/regions-escape-method.rs:16:13 | ||
| | ||
LL | s.f(|p| p) | ||
| -- ^ returning this value requires that `'1` must outlive `'2` | ||
| || | ||
| |return type of closure is &'2 i32 | ||
| has type `&'1 i32` | ||
| | ||
help: dereference the return value | ||
| | ||
LL | s.f(|p| *p) | ||
| + | ||
|
||
error: aborting due to 1 previous error | ||
|