-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
inherent associated types: better type inference
- Loading branch information
Showing
12 changed files
with
155 additions
and
62 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
23 changes: 0 additions & 23 deletions
23
tests/ui/associated-inherent-types/bugs/ice-substitution.rs
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
tests/ui/associated-inherent-types/bugs/ice-substitution.stderr
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,16 @@ | ||
// check-pass | ||
|
||
#![feature(inherent_associated_types)] | ||
#![allow(incomplete_features)] | ||
|
||
struct Cont<T>(T); | ||
|
||
impl<T: Copy> Cont<T> { | ||
type Out = Vec<T>; | ||
} | ||
|
||
pub fn weird<T: Copy>(x: T) { | ||
let _: Cont<_>::Out = vec![true]; | ||
} | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#![feature(inherent_associated_types)] | ||
#![allow(incomplete_features)] | ||
|
||
struct S<T>(T); | ||
|
||
impl<T> S<T> { type P = (); } | ||
|
||
fn main() { | ||
// There is no way to infer this type. | ||
let _: S<_>::P = (); //~ ERROR type annotations needed | ||
} |
6 changes: 3 additions & 3 deletions
6
...inherent-types/bugs/inference-fail.stderr → ...ated-inherent-types/inference-fail.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
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,39 @@ | ||
// Testing inference capabilities. | ||
// check-pass | ||
|
||
#![feature(inherent_associated_types)] | ||
#![allow(incomplete_features)] | ||
|
||
use std::convert::identity; | ||
|
||
struct Container<T>(T); | ||
|
||
impl Container<u32> { | ||
type Sink = (); | ||
} | ||
|
||
impl<Any> Container<Any> { | ||
type Thing = Any; | ||
} | ||
|
||
impl<T> Container<(T, ())> { | ||
type Output = ((), Wrapped<T>); | ||
} | ||
|
||
fn main() { | ||
// Inferred via the Self type of the impl. | ||
let _: Container<_>::Sink; | ||
|
||
// Inferred via the RHS: | ||
|
||
let _: Container<_>::Thing = 0; | ||
|
||
let _: Container<Wrapped<_>>::Thing = Wrapped(false); | ||
|
||
let _: Container<_>::Output = (drop(1), Wrapped("...")); | ||
|
||
let binding: Container<_>::Thing = Default::default(); // unsolved at this point | ||
identity::<String>(binding); // constrained and solved here | ||
} | ||
|
||
struct Wrapped<T>(T); |
12 changes: 12 additions & 0 deletions
12
tests/ui/associated-inherent-types/unsatisfied-bounds-inferred-type.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,12 @@ | ||
#![feature(inherent_associated_types)] | ||
#![allow(incomplete_features)] | ||
|
||
struct S<T>(T); | ||
|
||
impl<T: Copy> S<T> { | ||
type T = T; | ||
} | ||
|
||
fn main() { | ||
let _: S<_>::T = String::new(); //~ ERROR the trait bound `String: Copy` is not satisfied | ||
} |
9 changes: 9 additions & 0 deletions
9
tests/ui/associated-inherent-types/unsatisfied-bounds-inferred-type.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,9 @@ | ||
error[E0277]: the trait bound `String: Copy` is not satisfied | ||
--> $DIR/unsatisfied-bounds-inferred-type.rs:11:12 | ||
| | ||
LL | let _: S<_>::T = String::new(); | ||
| ^^^^^^^ the trait `Copy` is not implemented for `String` | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |