-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Tweak impl signature mismatch errors involving RegionKind::ReVar
lifetimes
#67460
Conversation
CC @rust-lang/wg-diagnostics we should probably have a follow up to detect these cases in particular and explain that the |
This comment has been minimized.
This comment has been minimized.
7bcc539
to
a4967d9
Compare
src/librustc/infer/error_reporting/nice_region_error/trait_impl_difference.rs
Outdated
Show resolved
Hide resolved
src/librustc/infer/error_reporting/nice_region_error/trait_impl_difference.rs
Outdated
Show resolved
Hide resolved
src/librustc/infer/error_reporting/nice_region_error/trait_impl_difference.rs
Outdated
Show resolved
Hide resolved
src/librustc/infer/error_reporting/nice_region_error/trait_impl_difference.rs
Outdated
Show resolved
Hide resolved
src/librustc/infer/error_reporting/nice_region_error/trait_impl_difference.rs
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
7ad6d8f
to
7c00f7a
Compare
RegionKind::ReVar
lifetimes in diagnostics RegionKind::ReVar
lifetimes
This comment has been minimized.
This comment has been minimized.
RegionKind::ReVar
lifetimesRegionKind::ReVar
lifetimes
This comment has been minimized.
This comment has been minimized.
--> $DIR/trait-param-without-lifetime-constraint.rs:14:5 | ||
| | ||
LL | pub trait HaveRelationship<To> { | ||
| -- for `impl` items to implement the method, this type parameter might need a lifetime restriction like `To: 'a` |
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.
this seems sort of misleading, no?
That is, I think the proper fix here is
impl<'a> HaveRelationship<&'a ProofReader> for Article {
fn get_relation(&self) -> &'a ProofReader {
//~^ ERROR `impl` item signature doesn't match `trait` item signature
&self.proof_reader
}
}
but I'm not sure how the new error would lead me there....
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.
But that doesn't work either because HaveRelationship
needs a lifetime so that get_relation
takes a &'a self
instead of &self
. Shouldn't the correct change be?:
pub trait HaveRelationship<'a, To: 'a> {
fn get_relation(&'a self) -> To;
}
impl<'a> HaveRelationship<'a, &'a ProofReader> for Article {
fn get_relation(&'a self) -> &'a ProofReader {
&self.proof_reader
}
}
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.
Let's discuss this in the issue :)
☔ The latest upstream changes (presumably #68377) made this pull request unmergeable. Please resolve the merge conflicts. |
e2049ee
to
bcf34c7
Compare
This comment has been minimized.
This comment has been minimized.
8fb857d
to
63c56d4
Compare
📌 Commit f213acf has been approved by |
@bors r=nikomatsakis @nikomatsakis made tiny tweak to account for |
📌 Commit 1bd6970 has been approved by |
Tweak impl signature mismatch errors involving `RegionKind::ReVar` lifetimes Fix rust-lang#66406, fix rust-lang#72106. ``` error: `impl` item signature doesn't match `trait` item signature --> $DIR/trait-param-without-lifetime-constraint.rs:14:5 | LL | fn get_relation(&self) -> To; | ----------------------------- expected `fn(&Article) -> &ProofReader` ... LL | fn get_relation(&self) -> &ProofReader { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&Article) -> &ProofReader` | = note: expected `fn(&Article) -> &ProofReader` found `fn(&Article) -> &ProofReader` help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait` --> $DIR/trait-param-without-lifetime-constraint.rs:10:31 | LL | fn get_relation(&self) -> To; | ^^ consider borrowing this type parameter in the trait ``` r? @nikomatsakis
Tweak impl signature mismatch errors involving `RegionKind::ReVar` lifetimes Fix rust-lang#66406, fix rust-lang#72106. ``` error: `impl` item signature doesn't match `trait` item signature --> $DIR/trait-param-without-lifetime-constraint.rs:14:5 | LL | fn get_relation(&self) -> To; | ----------------------------- expected `fn(&Article) -> &ProofReader` ... LL | fn get_relation(&self) -> &ProofReader { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&Article) -> &ProofReader` | = note: expected `fn(&Article) -> &ProofReader` found `fn(&Article) -> &ProofReader` help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait` --> $DIR/trait-param-without-lifetime-constraint.rs:10:31 | LL | fn get_relation(&self) -> To; | ^^ consider borrowing this type parameter in the trait ``` r? @nikomatsakis
Tweak impl signature mismatch errors involving `RegionKind::ReVar` lifetimes Fix rust-lang#66406, fix rust-lang#72106. ``` error: `impl` item signature doesn't match `trait` item signature --> $DIR/trait-param-without-lifetime-constraint.rs:14:5 | LL | fn get_relation(&self) -> To; | ----------------------------- expected `fn(&Article) -> &ProofReader` ... LL | fn get_relation(&self) -> &ProofReader { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&Article) -> &ProofReader` | = note: expected `fn(&Article) -> &ProofReader` found `fn(&Article) -> &ProofReader` help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait` --> $DIR/trait-param-without-lifetime-constraint.rs:10:31 | LL | fn get_relation(&self) -> To; | ^^ consider borrowing this type parameter in the trait ``` r? @nikomatsakis
⌛ Testing commit 1bd6970 with merge 7173e7b8fe4935c4d2567a0144469d4166541af5... |
@bors retry yield |
Tweak impl signature mismatch errors involving `RegionKind::ReVar` lifetimes Fix rust-lang#66406, fix rust-lang#72106. ``` error: `impl` item signature doesn't match `trait` item signature --> $DIR/trait-param-without-lifetime-constraint.rs:14:5 | LL | fn get_relation(&self) -> To; | ----------------------------- expected `fn(&Article) -> &ProofReader` ... LL | fn get_relation(&self) -> &ProofReader { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&Article) -> &ProofReader` | = note: expected `fn(&Article) -> &ProofReader` found `fn(&Article) -> &ProofReader` help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait` --> $DIR/trait-param-without-lifetime-constraint.rs:10:31 | LL | fn get_relation(&self) -> To; | ^^ consider borrowing this type parameter in the trait ``` r? @nikomatsakis
Rollup of 9 pull requests Successful merges: - rust-lang#67460 (Tweak impl signature mismatch errors involving `RegionKind::ReVar` lifetimes) - rust-lang#71095 (impl From<[T; N]> for Box<[T]>) - rust-lang#71500 (Make pointer offset methods/intrinsics const) - rust-lang#71804 (linker: Support `-static-pie` and `-static -shared`) - rust-lang#71862 (Implement RFC 2585: unsafe blocks in unsafe fn) - rust-lang#72103 (borrowck `DefId` -> `LocalDefId`) - rust-lang#72407 (Various minor improvements to Ipv6Addr::Display) - rust-lang#72413 (impl Step for char (make Range*<char> iterable)) - rust-lang#72439 (NVPTX support for new asm!) Failed merges: r? @ghost
☔ The latest upstream changes (presumably #72756) made this pull request unmergeable. Please resolve the merge conflicts. |
Fix #66406, fix #72106.
r? @nikomatsakis