-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Deny specializing items not in the parent impl #64564
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2cd5030
Deny specializing items not in the parent impl
jonas-schievink 55277d4
Add comment to `Type` and `OpaqueTy` match
jonas-schievink 02f36e5
Hide the `Iterator` specialization behind a trait
jonas-schievink 9aaef06
Fix the bootstrap
jonas-schievink a0cf531
Test that we get the proper errors
jonas-schievink 98f02b2
Pacify tidy
jonas-schievink 33d23cd
Extend test and fix nits
jonas-schievink 47f89e7
Rename the test
jonas-schievink 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
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
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,53 @@ | ||
#![feature(specialization, associated_type_defaults)] | ||
|
||
// Test that attempting to override a non-default method or one not in the | ||
// parent impl causes an error. | ||
|
||
trait Foo { | ||
type Ty = (); | ||
const CONST: u8 = 123; | ||
fn foo(&self) -> bool { true } | ||
} | ||
|
||
// Specialization tree for Foo: | ||
// | ||
// Box<T> Vec<T> | ||
// / \ / \ | ||
// Box<i32> Box<i64> Vec<()> Vec<bool> | ||
|
||
impl<T> Foo for Box<T> { | ||
type Ty = bool; | ||
const CONST: u8 = 0; | ||
fn foo(&self) -> bool { false } | ||
} | ||
|
||
// Allowed | ||
impl Foo for Box<i32> {} | ||
|
||
// Can't override a non-`default` fn | ||
impl Foo for Box<i64> { | ||
type Ty = Vec<()>; | ||
//~^ error: `Ty` specializes an item from a parent `impl`, but that item is not marked `default` | ||
const CONST: u8 = 42; | ||
//~^ error: `CONST` specializes an item from a parent `impl`, but that item is not marked `default` | ||
fn foo(&self) -> bool { true } | ||
//~^ error: `foo` specializes an item from a parent `impl`, but that item is not marked `default` | ||
} | ||
|
||
|
||
// Doesn't mention the item = provided body/value is used and the method is final. | ||
impl<T> Foo for Vec<T> {} | ||
|
||
// Allowed | ||
impl Foo for Vec<()> {} | ||
|
||
impl Foo for Vec<bool> { | ||
type Ty = Vec<()>; | ||
//~^ error: `Ty` specializes an item from a parent `impl`, but that item is not marked `default` | ||
const CONST: u8 = 42; | ||
//~^ error: `CONST` specializes an item from a parent `impl`, but that item is not marked `default` | ||
fn foo(&self) -> bool { true } | ||
//~^ error: `foo` specializes an item from a parent `impl`, but that item is not marked `default` | ||
} | ||
|
||
fn main() {} |
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.
Uh oh!
There was an error while loading. Please reload this page.