-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Fix capturing duplicated lifetimes via parent in precise_captures
(impl use<'...>
)
#124104
Merged
Merged
Changes from all commits
Commits
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
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
38 changes: 38 additions & 0 deletions
38
tests/ui/impl-trait/precise-capturing/capture-parent-arg.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,38 @@ | ||
#![feature(precise_capturing)] | ||
//~^ WARN the feature `precise_capturing` is incomplete | ||
|
||
trait Tr { | ||
type Assoc; | ||
} | ||
|
||
struct W<'a>(&'a ()); | ||
|
||
impl Tr for W<'_> { | ||
type Assoc = (); | ||
} | ||
|
||
// The normal way of capturing `'a`... | ||
impl<'a> W<'a> { | ||
fn good1() -> impl use<'a> Into<<W<'a> as Tr>::Assoc> {} | ||
} | ||
|
||
// This ensures that we don't error when we capture the *parent* copy of `'a`, | ||
// since the opaque captures that rather than the duplicated `'a` lifetime | ||
// synthesized from mentioning `'a` directly in the bounds. | ||
impl<'a> W<'a> { | ||
fn good2() -> impl use<'a> Into<<Self as Tr>::Assoc> {} | ||
} | ||
|
||
// The normal way of capturing `'a`... but not mentioned in the bounds. | ||
impl<'a> W<'a> { | ||
fn bad1() -> impl use<> Into<<W<'a> as Tr>::Assoc> {} | ||
//~^ ERROR `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list | ||
} | ||
|
||
// But also make sure that we error here... | ||
impl<'a> W<'a> { | ||
//~^ ERROR `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list | ||
fn bad2() -> impl use<> Into<<Self as Tr>::Assoc> {} | ||
} | ||
|
||
fn main() {} |
28 changes: 28 additions & 0 deletions
28
tests/ui/impl-trait/precise-capturing/capture-parent-arg.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,28 @@ | ||
warning: the feature `precise_capturing` is incomplete and may not be safe to use and/or cause compiler crashes | ||
--> $DIR/capture-parent-arg.rs:1:12 | ||
| | ||
LL | #![feature(precise_capturing)] | ||
| ^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #123432 <https://github.com/rust-lang/rust/issues/123432> for more information | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
error: `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list | ||
--> $DIR/capture-parent-arg.rs:28:37 | ||
| | ||
LL | impl<'a> W<'a> { | ||
| -- this lifetime parameter is captured | ||
LL | fn bad1() -> impl use<> Into<<W<'a> as Tr>::Assoc> {} | ||
| -------------------^^---------------- lifetime captured due to being mentioned in the bounds of the `impl Trait` | ||
|
||
error: `impl Trait` captures lifetime parameter, but it is not mentioned in `use<...>` precise captures list | ||
--> $DIR/capture-parent-arg.rs:33:6 | ||
| | ||
LL | impl<'a> W<'a> { | ||
| ^^ | ||
LL | | ||
LL | fn bad2() -> impl use<> Into<<Self as Tr>::Assoc> {} | ||
| ------------------------------------ lifetime captured due to being mentioned in the bounds of the `impl Trait` | ||
|
||
error: aborting due to 2 previous errors; 1 warning emitted | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document that this test is ensuring that
Self
captures work, even though they refer to the parent's'a
instead of the opaque type's copy