-
Notifications
You must be signed in to change notification settings - Fork 13.7k
add member constraints tests #145050
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
Merged
+101
−1
Merged
add member constraints tests #145050
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
tests/ui/impl-trait/member-constraints/apply_member_constraint-no-req-eq.rs
This file contains hidden or 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,24 @@ | ||
//@ check-pass | ||
// FIXME(-Znext-solver): enable this test | ||
|
||
trait Id { | ||
type This; | ||
} | ||
impl<T> Id for T { | ||
type This = T; | ||
} | ||
|
||
// We have two member constraints here: | ||
// | ||
// - 'unconstrained member ['a, 'static] | ||
// - 'unconstrained member ['static] | ||
// | ||
// Applying the first constraint results in `'unconstrained: 'a` | ||
// while the second then adds `'unconstrained: 'static`. If applying | ||
// member constraints were to require the member region equal to the | ||
// choice region, applying the first constraint first and then the | ||
// second would result in a `'a: 'static` requirement. | ||
fn test<'a>() -> impl Id<This = impl Sized + use<>> + use<'a> { | ||
&() | ||
} | ||
fn main() {} |
21 changes: 21 additions & 0 deletions
21
tests/ui/impl-trait/member-constraints/incomplete-constraint.rs
This file contains hidden or 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,21 @@ | ||
//@ check-pass | ||
// FIXME(-Znext-solver): enable this test | ||
|
||
// These functions currently does not normalize the opaque type but will do | ||
// so in the future. At this point we've got a new use of the opaque will fully | ||
lcnr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// universal arguments but for which lifetimes in the hidden type are unconstrained. | ||
// | ||
// Applying the member constraints would then incompletely infer `'unconstrained` to `'static`. | ||
fn new_defining_use<F: FnOnce(T) -> R, T, R>(_: F) {} | ||
|
||
fn rpit1<'a, 'b: 'b>(x: &'b ()) -> impl Sized + use<'a, 'b> { | ||
new_defining_use(rpit1::<'a, 'b>); | ||
x | ||
} | ||
|
||
struct Inv<'a, 'b>(*mut (&'a (), &'b ())); | ||
fn rpit2<'a>(_: ()) -> impl Sized + use<'a> { | ||
new_defining_use(rpit2::<'a>); | ||
Inv::<'a, 'static>(std::ptr::null_mut()) | ||
} | ||
fn main() {} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 4 additions & 1 deletion
5
...ber-constraints/nested-impl-trait-pass.rs → ...ber-constraints/nested-impl-trait-pass.rs
This file contains hidden or 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
34 changes: 34 additions & 0 deletions
34
tests/ui/impl-trait/member-constraints/reject-choice-due-to-prev-constraint.rs
This file contains hidden or 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,34 @@ | ||
//@ revisions: current next | ||
//@[next] compile-flags: -Znext-solver | ||
//@ ignore-compare-mode-next-solver (explicit revisions) | ||
//@ check-pass | ||
|
||
// We've got `'0 member ['a, 'b, 'static]` and `'1 member ['a, 'b, 'static]`. | ||
// | ||
// As '0 gets outlived by 'a - its "upper bound" - the only applicable choice | ||
// region is 'a. | ||
// | ||
// '1 has to outlive 'b so the only applicabel choice regions are 'b and 'static. | ||
lcnr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Considering this member constraint by itself would choose 'b as it is the | ||
// smaller of the two regions. | ||
// | ||
// However, this is only the case when ignoring the member constraint on '0. | ||
// After applying this constraint and requiring '0 to outlive 'a. As '1 outlives | ||
// '0, the region 'b is no longer an applicable choice region for '1 as 'b does | ||
// does not outlive 'a. We would therefore choose 'static. | ||
// | ||
// This means applying member constraints is order dependent. We handle this by | ||
// first applying member constraints for regions 'x and then consider the resulting | ||
// constraints when applying member constraints for regions 'y with 'y: 'x. | ||
fn with_constraints<'r0, 'r1, 'a, 'b>() -> *mut (&'r0 (), &'r1 ()) | ||
where | ||
'r1: 'r0, | ||
'a: 'r0, | ||
'r1: 'b, | ||
{ | ||
loop {} | ||
} | ||
fn foo<'a, 'b>() -> impl Sized + use<'a, 'b> { | ||
with_constraints::<'_, '_, 'a, 'b>() | ||
} | ||
fn main() {} |
This file contains hidden or 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,18 @@ | ||
//@ check-pass | ||
// FIXME(-Znext-solver): enable this test | ||
|
||
// A regression test for an error in `redis` while working on #139587. | ||
// | ||
// We check for structural equality when adding defining uses of opaques. | ||
// In this test one defining use had anonymized regions while the other | ||
// one did not, causing an error. | ||
struct W<T>(T); | ||
fn constrain<F: FnOnce(T) -> R, T, R>(f: F) -> R { | ||
loop {} | ||
} | ||
fn foo<'a>(x: for<'b> fn(&'b ())) -> impl Sized + use<'a> { | ||
let mut r = constrain(foo::<'_>); | ||
r = W(x); | ||
r | ||
} | ||
fn main() {} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.