-
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 #116960 - lqd:applied-member-constraints-scope, r=mat…
…thewjasper Location-insensitive polonius: consider a loan escaping if an SCC has member constraints applied only The location-insensitive analysis considered loans to escape if there were member constraints, which makes *some* sense for scopes and matches the scopes that NLL computes on all the tests. However, polonius and NLLs differ on the fuzzed case #116657, where an SCC has member constraints but no applied ones (and is kinda surprising). The existing UI tests with member constraints impacting scopes all have some constraint applied. This PR changes the location-insensitive analysis to consider a loan to escape if there are applied member constraints, and for extra paranoia/insurance via fuzzing and crater: actually checks the constraint's min choice is indeed a universal region as we expect. (This could be turned into a `debug_assert` and early return as a slight optimization after these periods of verification) The 4 UI tests where member constraints are meaningful for computing scopes still pass obviously, and this also fixes #116657. r? `@matthewjasper`
- Loading branch information
Showing
6 changed files
with
128 additions
and
25 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
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
36 changes: 36 additions & 0 deletions
36
tests/ui/nll/polonius/location-insensitive-scopes-issue-116657.nll.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,36 @@ | ||
error[E0046]: not all trait items implemented, missing: `call` | ||
--> $DIR/location-insensitive-scopes-issue-116657.rs:18:1 | ||
| | ||
LL | fn call(x: Self) -> Self::Output; | ||
| --------------------------------- `call` from trait | ||
... | ||
LL | impl<T: PlusOne> Callable for T { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `call` in implementation | ||
|
||
error: unconstrained opaque type | ||
--> $DIR/location-insensitive-scopes-issue-116657.rs:22:19 | ||
| | ||
LL | type Output = impl PlusOne; | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: `Output` must be used in combination with a concrete type within the same impl | ||
|
||
error[E0700]: hidden type for `impl PlusOne` captures lifetime that does not appear in bounds | ||
--> $DIR/location-insensitive-scopes-issue-116657.rs:28:5 | ||
| | ||
LL | fn test<'a>(y: &'a mut i32) -> impl PlusOne { | ||
| -- ------------ opaque type defined here | ||
| | | ||
| hidden type `<&'a mut i32 as Callable>::Output` captures the lifetime `'a` as defined here | ||
LL | <&mut i32 as Callable>::call(y) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: to declare that `impl PlusOne` captures `'a`, you can add an explicit `'a` lifetime bound | ||
| | ||
LL | fn test<'a>(y: &'a mut i32) -> impl PlusOne + 'a { | ||
| ++++ | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
Some errors have detailed explanations: E0046, E0700. | ||
For more information about an error, try `rustc --explain E0046`. |
36 changes: 36 additions & 0 deletions
36
tests/ui/nll/polonius/location-insensitive-scopes-issue-116657.polonius.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,36 @@ | ||
error[E0046]: not all trait items implemented, missing: `call` | ||
--> $DIR/location-insensitive-scopes-issue-116657.rs:18:1 | ||
| | ||
LL | fn call(x: Self) -> Self::Output; | ||
| --------------------------------- `call` from trait | ||
... | ||
LL | impl<T: PlusOne> Callable for T { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `call` in implementation | ||
|
||
error: unconstrained opaque type | ||
--> $DIR/location-insensitive-scopes-issue-116657.rs:22:19 | ||
| | ||
LL | type Output = impl PlusOne; | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: `Output` must be used in combination with a concrete type within the same impl | ||
|
||
error[E0700]: hidden type for `impl PlusOne` captures lifetime that does not appear in bounds | ||
--> $DIR/location-insensitive-scopes-issue-116657.rs:28:5 | ||
| | ||
LL | fn test<'a>(y: &'a mut i32) -> impl PlusOne { | ||
| -- ------------ opaque type defined here | ||
| | | ||
| hidden type `<&'a mut i32 as Callable>::Output` captures the lifetime `'a` as defined here | ||
LL | <&mut i32 as Callable>::call(y) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: to declare that `impl PlusOne` captures `'a`, you can add an explicit `'a` lifetime bound | ||
| | ||
LL | fn test<'a>(y: &'a mut i32) -> impl PlusOne + 'a { | ||
| ++++ | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
Some errors have detailed explanations: E0046, E0700. | ||
For more information about an error, try `rustc --explain E0046`. |
33 changes: 33 additions & 0 deletions
33
tests/ui/nll/polonius/location-insensitive-scopes-issue-116657.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,33 @@ | ||
// This is a non-regression test for issue #116657, where NLL and `-Zpolonius=next` computed | ||
// different loan scopes when a member constraint was not ultimately applied. | ||
|
||
// revisions: nll polonius | ||
// [polonius] compile-flags: -Zpolonius=next | ||
|
||
#![feature(impl_trait_in_assoc_type)] | ||
|
||
trait Callable { | ||
type Output; | ||
fn call(x: Self) -> Self::Output; | ||
} | ||
|
||
trait PlusOne {} | ||
|
||
impl<'a> PlusOne for &'a mut i32 {} | ||
|
||
impl<T: PlusOne> Callable for T { | ||
//[nll]~^ ERROR not all trait items implemented | ||
//[polonius]~^^ ERROR not all trait items implemented | ||
|
||
type Output = impl PlusOne; | ||
//[nll]~^ ERROR unconstrained opaque type | ||
//[polonius]~^^ ERROR unconstrained opaque type | ||
} | ||
|
||
fn test<'a>(y: &'a mut i32) -> impl PlusOne { | ||
<&mut i32 as Callable>::call(y) | ||
//[nll]~^ ERROR hidden type for `impl PlusOne` captures lifetime | ||
//[polonius]~^^ ERROR hidden type for `impl PlusOne` captures lifetime | ||
} | ||
|
||
fn main() {} |