forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Consider well-formed predicates in min-specialization
- Loading branch information
1 parent
4377ac3
commit 39ee66a
Showing
4 changed files
with
82 additions
and
4 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
30 changes: 30 additions & 0 deletions
30
src/test/ui/specialization/min_specialization/implcit-well-formed-bounds.rs
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,30 @@ | ||
// Test that specializing on the well-formed predicates of the trait and | ||
// self-type of an impl is allowed. | ||
|
||
// check-pass | ||
|
||
#![feature(min_specialization)] | ||
|
||
struct OrdOnly<T: Ord>(T); | ||
|
||
trait SpecTrait<U> { | ||
fn f(); | ||
} | ||
|
||
impl<T, U> SpecTrait<U> for T { | ||
default fn f() {} | ||
} | ||
|
||
impl<T: Ord> SpecTrait<()> for OrdOnly<T> { | ||
fn f() {} | ||
} | ||
|
||
impl<T: Ord> SpecTrait<OrdOnly<T>> for () { | ||
fn f() {} | ||
} | ||
|
||
impl<T: Ord, U: Ord, V: Ord> SpecTrait<(OrdOnly<T>, OrdOnly<U>)> for &[OrdOnly<V>] { | ||
fn f() {} | ||
} | ||
|
||
fn main() {} |
18 changes: 18 additions & 0 deletions
18
src/test/ui/specialization/min_specialization/specialization_super_trait.rs
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,18 @@ | ||
// Test that supertraits can't be assumed in impls of | ||
// `rustc_specialization_trait`, as such impls would | ||
// allow specializing on the supertrait. | ||
|
||
#![feature(min_specialization)] | ||
#![feature(rustc_attrs)] | ||
|
||
#[rustc_specialization_trait] | ||
trait SpecMarker: Default { | ||
fn f(); | ||
} | ||
|
||
impl<T: Default> SpecMarker for T { | ||
//~^ ERROR cannot specialize | ||
fn f() {} | ||
} | ||
|
||
fn main() {} |
11 changes: 11 additions & 0 deletions
11
src/test/ui/specialization/min_specialization/specialization_super_trait.stderr
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,11 @@ | ||
error: cannot specialize on trait `std::default::Default` | ||
--> $DIR/specialization_super_trait.rs:13:1 | ||
| | ||
LL | / impl<T: Default> SpecMarker for T { | ||
LL | | | ||
LL | | fn f() {} | ||
LL | | } | ||
| |_^ | ||
|
||
error: aborting due to previous error | ||
|