-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #64564 - jonas-schievink:cowardly-default, r=<try>
Deny specializing items not in the parent impl Part of #29661 (rust-lang/rfcs#2532). At least sort of? This was discussed in #61812 (comment) and is needed for that PR to make progress (fixing an unsoundness). One annoyance with doing this is that it sometimes requires users to copy-paste a provided trait method into an impl just to mark it `default` (ie. there is no syntax to forward this impl method to the provided trait method). cc @Centril and @arielb1
- Loading branch information
Showing
12 changed files
with
268 additions
and
45 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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.