-
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
Allow lifetime elision in arbitrary_self_types #60944
Allow lifetime elision in arbitrary_self_types #60944
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
f85180e
to
6eb1f35
Compare
Seems the current #![allow(dead_code)]
#![feature(arbitrary_self_types)]
struct Foo;
impl Foo {
fn b(self: &Box<Foo>, f: &Foo) -> &Foo { f }
} I expected:
or
This PR rejects (fixes) this. I feel it is right, but I don't know how far it will affect. |
@rustbot modify labels: T-compiler. |
It can reproduce even the stable: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=76eefccd7414faab0a51733c20d6b205 |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
3ae4dc9
to
19c7915
Compare
r? @Centril |
c04f346
to
8efcf41
Compare
Seems like we should do a crater run-- this is certainly a breaking change, but it's also definitely something we want to fix. cc @rust-lang/lang |
It also seems highly likely that this will affect code using futures, which is stabilized on nightly and soon-to-be-beta (1.36), so this also probably wants a beta backport. I don't know that there are significant other libraries making extensive use of this feature, so it seems like we might be able to fix this without an extra warning period. |
@bors try (for crater) |
… r=<try> Allow lifetime elision in arbitrary_self_types Currently, `self` except `&Self` and `&mut Self` is skipped. By this, other `self`s with lifetime is also ignored. This PR changes it to only skip `Self`, `&Self` and `&mut Self`, and to handle other `self`s like normal arguments. Closes #52675
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
☀️ Try build successful - checks-travis |
@craterbot run mode=check-only |
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
c799d4d
to
c0e3422
Compare
Move arbitrary self types's tests into ui/self #60944 (comment) r? @Centril
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
c0e3422
to
76ab65a
Compare
@@ -2121,6 +2121,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { | |||
_ => false, | |||
}; | |||
|
|||
// Only skip `Self`, `&Self` and `&mut Self`, | |||
// and to handle other `self`s like normal arguments. | |||
let mut should_skip = false; |
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.
Maybe rename this to skip_self_arg
?
This was intentional, in that we didn't want If you start relying on the Ideally elision would've been syntactic from the start (since it's meant to be syntactically intuitive), but we dropped the ball on that. If we do a crater run, I suggest also experimenting with this part commented out: rust/src/librustc/middle/resolve_lifetime.rs Lines 2136 to 2152 in 1cc822c
@cramertj Could we special-case |
🎉 Experiment
|
Looks like we have an ICE in the only "regression". |
@eddyb I'm sorry, I'm not sure I understand-- could you write an example or two of the kind of thing that you wanted to support, but which wouldn't be allowed under this PR? |
@eddyb from your comment it seems the concern has to do with self types containing multiple lifetimes. I notice in particular you highlight cases where users have opted for using the actual self type instead of the My naive expectation around this behavior:
|
@withoutboats It probably should've been disallowed, yeah. I'd be curious to see the results of a crater run where that is just banned (I suspect we couldn't "just do that", but it would perhaps be useful to know.) @cramertj Our testsuite might be lacking these examples, but this works on stable: struct Foo<'a>(&'a ());
impl<'a> Foo<'a> {
fn foo<'b>(self: &'b Foo<'a>) -> &() { self.0 }
}
type Alias = Foo<'static>;
impl Alias {
fn bar<'a>(self: &Alias, arg: &'a ()) -> &() { arg }
} And AFAICT, this PR changes the behavior in at least the latter case, as it relies on the (rather brittle) It otherwise uses regular rules, even for the So what I think we should do is change the special-case of |
I see that the reference says
Is that an accurate statement of the current rule? Does the |
@scottmcm Note that the rule applies to |
Closing this PR in favor of #61207. |
…2, r=<try> Allow lifetime elision in `Pin<&(mut) Self>` This replaces #60944. ~~This PR changes elision rules to apply `self: &(mut) Self` elision rules even if nested in `Pin`.~~ This PR changes `self: &(mut) S` elision rules to instead visit the type of `self` and look for `&(mut) S` (where `is_self_ty(S)`) within it Closes #52675 r? @eddyb cc @cramertj @Centril @withoutboats @scottmcm
…me-elision-2, r=Centril Allow lifetime elision in `Pin<&(mut) Self>` This PR changes `self: &(mut) S` elision rules to instead visit the type of `self` and look for `&(mut) S` (where `is_self_ty(S)`) within it Replaces rust-lang#60944 Closes rust-lang#52675 r? @eddyb cc @cramertj @Centril @withoutboats @scottmcm
…me-elision-2, r=Centril Allow lifetime elision in `Pin<&(mut) Self>` This PR changes `self: &(mut) S` elision rules to instead visit the type of `self` and look for `&(mut) S` (where `is_self_ty(S)`) within it Replaces rust-lang#60944 Closes rust-lang#52675 r? @eddyb cc @cramertj @Centril @withoutboats @scottmcm
…me-elision-2, r=Centril Allow lifetime elision in `Pin<&(mut) Self>` This PR changes `self: &(mut) S` elision rules to instead visit the type of `self` and look for `&(mut) S` (where `is_self_ty(S)`) within it Replaces rust-lang#60944 Closes rust-lang#52675 r? @eddyb cc @cramertj @Centril @withoutboats @scottmcm
…me-elision-2, r=Centril Allow lifetime elision in `Pin<&(mut) Self>` This PR changes `self: &(mut) S` elision rules to instead visit the type of `self` and look for `&(mut) S` (where `is_self_ty(S)`) within it Replaces rust-lang#60944 Closes rust-lang#52675 r? @eddyb cc @cramertj @Centril @withoutboats @scottmcm
…amertj Stabilize `async_await` in Rust 1.39.0 Here we stabilize: - free and inherent `async fn`s, - the `<expr>.await` expression form, - and the `async move? { ... }` block form. Closes rust-lang#62149. Closes rust-lang#50547. All the blockers are now closed. <details> - [x] FCP in rust-lang#62149 - [x] rust-lang#61949; PR in rust-lang#62849. - [x] rust-lang#62517; PR in rust-lang#63376. - [x] rust-lang#63225; PR in rust-lang#63501 - [x] rust-lang#63388; PR in rust-lang#63499 - [x] rust-lang#63500; PR in rust-lang#63501 - [x] rust-lang#62121 (comment) - [x] Some tests for control flow (PR rust-lang#63387): - `?` - `return` in `async` blocks - `break` - [x] rust-lang#61775 (comment), i.e. tests for rust-lang#60944 with `async fn`s instead). PR in rust-lang#63383 </details> r? @cramertj
Currently,
self
except&Self
and&mut Self
is skipped. By this, otherself
s with lifetime is also ignored.This PR changes it to only skip
Self
,&Self
and&mut Self
, and to handle otherself
s like normal arguments.Closes #52675