-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Remove self: Self
methods from vtables
#114260
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
890a506
Make non-zero check more obvious
WaffleLapkin 716c5de
Add a comment explaining some weird `is_vtable_safe_method` behavior
WaffleLapkin 9eb35a2
Don't allow dead code
WaffleLapkin 5fc0233
Return multiple object-safety violation errors
WaffleLapkin e543524
Add a test for vtable layout of traits with `self: Self` methods
WaffleLapkin 7a4d253
Don't include `fn f(self)`-like methods in vtables
WaffleLapkin 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 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
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
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
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,50 @@ | ||
// Make sure we don't include vtable entries for methods that take self by-value, | ||
// see <https://github.com/rust-lang/rust/issues/114007>. | ||
// | ||
// build-fail | ||
#![crate_type = "lib"] | ||
#![feature(rustc_attrs)] | ||
|
||
use std::ops::*; | ||
|
||
#[rustc_dump_vtable] | ||
pub trait Simple { | ||
//~^ error: vtable entries for `<() as Simple>`: [ | ||
fn f(self); | ||
fn g(self: Self); | ||
} | ||
|
||
impl Simple for () { | ||
fn f(self) {} | ||
fn g(self: Self) {} | ||
} | ||
|
||
#[rustc_dump_vtable] | ||
pub trait RefNum<Base>: NumOps<Base, Base> + for<'r> NumOps<&'r Base, Base> {} | ||
//~^ error: vtable entries for `<u32 as RefNum<u32>>`: [ | ||
|
||
impl<T, Base> RefNum<Base> for T where T: NumOps<Base, Base> + for<'r> NumOps<&'r Base, Base> {} | ||
|
||
pub trait NumOps<Rhs = Self, Output = Self>: | ||
Add<Rhs, Output = Output> | ||
+ Sub<Rhs, Output = Output> | ||
+ Mul<Rhs, Output = Output> | ||
+ Div<Rhs, Output = Output> | ||
+ Rem<Rhs, Output = Output> | ||
{ | ||
} | ||
|
||
impl<T, Rhs, Output> NumOps<Rhs, Output> for T where | ||
T: Add<Rhs, Output = Output> | ||
+ Sub<Rhs, Output = Output> | ||
+ Mul<Rhs, Output = Output> | ||
+ Div<Rhs, Output = Output> | ||
+ Rem<Rhs, Output = Output> | ||
{ | ||
} | ||
|
||
pub fn require_vtables() { | ||
fn require_vtables(_: &dyn RefNum<u32>, _: &dyn Simple) {} | ||
|
||
require_vtables(&1u32, &()) | ||
} |
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,22 @@ | ||
error: vtable entries for `<u32 as RefNum<u32>>`: [ | ||
MetadataDropInPlace, | ||
MetadataSize, | ||
MetadataAlign, | ||
] | ||
--> $DIR/plain-self.rs:23:1 | ||
| | ||
LL | pub trait RefNum<Base>: NumOps<Base, Base> + for<'r> NumOps<&'r Base, Base> {} | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: vtable entries for `<() as Simple>`: [ | ||
MetadataDropInPlace, | ||
MetadataSize, | ||
MetadataAlign, | ||
] | ||
--> $DIR/plain-self.rs:11:1 | ||
| | ||
LL | pub trait Simple { | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
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.
I don't think users need that much help when getting the error
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.
You see, this is tricky, because those lines are triggered by different errors:
rust/compiler/rustc_middle/src/traits/mod.rs
Lines 866 to 869 in a17c796
I couldn't find an easy way to fix this...