-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Don't require method impls for methods with Self:Sized
bounds for impls for unsized types
#135480
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
As per #112319 (comment) I am not adding @rust-lang/lang to the FCP, but just pinging them and nominating so they'll see it and can raise concerns. @rfcbot merge |
Team member @oli-obk has proposed to merge this. The next step is review by the rest of the tagged team members: No concerns currently listed. Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
This comment has been minimized.
This comment has been minimized.
fa00d7b
to
f049c41
Compare
f403d53
to
d1c9c54
Compare
@rfcbot reviewed |
This seems at least plausible, but I wonder if there's anything that would make it more complex if we did Hierarchy of Sized traits by @davidtwco (or similar)? Is there anything about what's happening here with |
@rustbot labels -I-lang-nominated We discussed this in the lang call today, and we're OK with this going forward according to our earlier guidance for this in #112319 (comment). This did actually generate substantial discussion, though. We thought through the compatibility with this and the ongoing work on the hierarchy of |
This is special-cased specifically for just |
I very much think we can and should do this for trait objects. The check currently looks at the struct tail, so it would even allow such impls for a foreign type |
r? lcnr since you were reviewing this |
|
||
//@ error-pattern: reached the recursion limit finding the struct tail for `<[Hello] as Normalize>::Assoc` | ||
|
||
trait Bound {} |
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.
why add this test?
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 was just necessary before I added the normalization.
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.
two nits, then r=me
d6549e6
to
fec0385
Compare
@bors r=lcnr |
This comment has been minimized.
This comment has been minimized.
…mpls for unsized types
fec0385
to
ffc955b
Compare
@bors r=lcnr |
…pl, r=lcnr Don't require method impls for methods with `Self:Sized` bounds for impls for unsized types Similarly to how rust-lang#112319 doesn't require specifying associated types with `Self: Sized` bounds on `dyn Trait`, we now don't require assoc items with `Self: Sized` bounds to be in impls of for unsized types. Additionally we lint assoc items with `Self: Sized` bounds that are in such impls: ```rust trait Foo { fn foo() where Self: Sized; } impl Foo for () { fn foo() {} } impl Foo for i32 {} //~^ ERROR: not all trait items implemented, missing: `foo` impl Foo for dyn std::fmt::Debug {} #[deny(dead_code)] impl Foo for dyn std::fmt::Display { fn foo() {} //~^ ERROR this item cannot be used as its where bounds are not satisfied } ``` Note that this works with the same `Self: Sized` specific logic we already have for `dyn Trait`, so no new capabilities like avoiding assoc items with `Self: Copy` bounds on impls for `String` or such are added here. Specifying `where ConcreteType: Sized` in a trait and implementing the trait for `ConcreteType` also does not work, it *must* be exactly `Self: Sized`.
Rollup of 6 pull requests Successful merges: - rust-lang#135480 (Don't require method impls for methods with `Self:Sized` bounds for impls for unsized types) - rust-lang#137360 (Use `as_chunks` in `analyze_source_file_sse2`) - rust-lang#137460 (downgrade bootstrap `cc`) - rust-lang#137515 (Update `compiler-builtins` to 0.1.148) - rust-lang#137522 (use stage 2 on cargo and clippy tests when possible) - rust-lang#137597 (Revert accidental cargo submodule update) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#135480 - oli-obk:sized-method-on-unsized-impl, r=lcnr Don't require method impls for methods with `Self:Sized` bounds for impls for unsized types Similarly to how rust-lang#112319 doesn't require specifying associated types with `Self: Sized` bounds on `dyn Trait`, we now don't require assoc items with `Self: Sized` bounds to be in impls of for unsized types. Additionally we lint assoc items with `Self: Sized` bounds that are in such impls: ```rust trait Foo { fn foo() where Self: Sized; } impl Foo for () { fn foo() {} } impl Foo for i32 {} //~^ ERROR: not all trait items implemented, missing: `foo` impl Foo for dyn std::fmt::Debug {} #[deny(dead_code)] impl Foo for dyn std::fmt::Display { fn foo() {} //~^ ERROR this item cannot be used as its where bounds are not satisfied } ``` Note that this works with the same `Self: Sized` specific logic we already have for `dyn Trait`, so no new capabilities like avoiding assoc items with `Self: Copy` bounds on impls for `String` or such are added here. Specifying `where ConcreteType: Sized` in a trait and implementing the trait for `ConcreteType` also does not work, it *must* be exactly `Self: Sized`.
This PR lead to perf regressions: #137611 (comment)
|
It looks like they exactly revert the instruction count reduction from #133832 weird. |
Similarly to how #112319 doesn't require specifying associated types with
Self: Sized
bounds ondyn Trait
, we now don't require assoc items withSelf: Sized
bounds to be in impls of for unsized types.Additionally we lint assoc items with
Self: Sized
bounds that are in such impls:Note that this works with the same
Self: Sized
specific logic we already have fordyn Trait
, so no new capabilities like avoiding assoc items withSelf: Copy
bounds on impls forString
or such are added here. Specifyingwhere ConcreteType: Sized
in a trait and implementing the trait forConcreteType
also does not work, it must be exactlySelf: Sized
.