Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
230 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
This directory contains the test for incorrect usage of specialization that | ||
should lead to compile failure. Those tests break down into a few categories: | ||
|
||
- Feature gating | ||
- [On use of the `default` keyword](specialization-feature-gate-default.rs) | ||
- [On overlapping impls](specialization-feature-gate-overlap.rs) | ||
|
||
- Overlap checking with specialization enabled | ||
- [Basic overlap scenarios](specialization-overlap.rs) | ||
- Includes purely structural overlap | ||
- Includes purely trait-based overlap | ||
- Includes mix | ||
- [Overlap with differing polarity](specialization-overlap-negative.rs) | ||
|
||
- [Attempt to specialize without using `default`](specialization-no-default.rs) | ||
|
||
- [Attempt to change impl polarity in a specialization](specialization-polarity.rs) | ||
|
||
- Attempt to rely on projection of a `default` type | ||
- [Rely on it externally in both generic and monomorphic contexts](specialization-default-projection.rs) | ||
- [Rely on it both within an impl and outside it](specialization-default-types.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
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,37 @@ | ||
Tests that specialization is working correctly: | ||
|
||
- Dispatch | ||
- [On methods](specialization-basics.rs), includes: | ||
- Specialization via adding a trait bound | ||
- Including both remote and local traits | ||
- Specialization via pure structure (e.g. `(T, U)` vs `(T, T)`) | ||
- Specialization via concrete types vs unknown types | ||
- In top level of the trait reference | ||
- Embedded within another type (`Vec<T>` vs `Vec<i32>`) | ||
- [Specialization based on super trait relationships](specialization-super-traits.rs) | ||
- [On assoc fns](specialization-assoc-fns.rs) | ||
- [Ensure that impl order doesn't matter](specialization-out-of-order.rs) | ||
|
||
- Item inheritance | ||
- [Correct default cascading for methods](specialization-default-methods.rs) | ||
- Inheritance works across impls with varying generics | ||
- [With projections](specialization-translate-projections.rs) | ||
- [With projections that involve input types](specialization-translate-projections-with-params.rs) | ||
|
||
- Normalization issues | ||
- [Non-default assoc types can be projected](specialization-projection.rs) | ||
- Including non-specialized cases | ||
- Including specialized cases | ||
- [Specialized Impls can happen on projections](specialization-on-projection.rs) | ||
- [Projections and aliases play well together](specialization-projection-alias.rs) | ||
- [Projections involving specialization allowed in the trait ref for impls, and overlap can still be determined](specialization-overlap-projection.rs) | ||
- Only works for the simple case where the most specialized impl directly | ||
provides a non-`default` associated type | ||
|
||
- Across crates | ||
- [For traits defined in upstream crate](specialization-allowed-cross-crate.rs) | ||
- [Full method dispatch tests, drawing from upstream crate](specialization-cross-crate.rs) | ||
- Including *additional* local specializations | ||
- [Full method dispatch tests, *without* turning on specialization in local crate](specialization-cross-crate-no-gate.rs) | ||
- [Test that defaults cascade correctly from upstream crates](specialization-cross-crate-defaults.rs) | ||
- Including *additional* local use of defaults |
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
29 changes: 29 additions & 0 deletions
29
src/test/run-pass/specialization/specialization-cross-crate-no-gate.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,29 @@ | ||
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Test that specialization works even if only the upstream crate enables it | ||
|
||
// aux-build:specialization_cross_crate.rs | ||
|
||
extern crate specialization_cross_crate; | ||
|
||
use specialization_cross_crate::*; | ||
|
||
fn main() { | ||
assert!(0u8.foo() == "generic Clone"); | ||
assert!(vec![0u8].foo() == "generic Vec"); | ||
assert!(vec![0i32].foo() == "Vec<i32>"); | ||
assert!(0i32.foo() == "i32"); | ||
assert!(String::new().foo() == "String"); | ||
assert!(((), 0).foo() == "generic pair"); | ||
assert!(((), ()).foo() == "generic uniform pair"); | ||
assert!((0u8, 0u32).foo() == "(u8, u32)"); | ||
assert!((0u8, 0u8).foo() == "(u8, u8)"); | ||
} |
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
33 changes: 33 additions & 0 deletions
33
src/test/run-pass/specialization/specialization-overlap-projection.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,33 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Test that impls on projected self types can resolve overlap, even when the | ||
// projections involve specialization, so long as the associated type is | ||
// provided by the most specialized impl. | ||
|
||
#![feature(specialization)] | ||
|
||
trait Assoc { | ||
type Output; | ||
} | ||
|
||
impl<T> Assoc for T { | ||
default type Output = bool; | ||
} | ||
|
||
impl Assoc for u8 { type Output = u8; } | ||
impl Assoc for u16 { type Output = u16; } | ||
|
||
trait Foo {} | ||
impl Foo for u32 {} | ||
impl Foo for <u8 as Assoc>::Output {} | ||
impl Foo for <u16 as Assoc>::Output {} | ||
|
||
fn main() {} |
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
Oops, something went wrong.