diff options
| author | Alisdair Owens <awo101@zepler.net> | 2015-07-22 13:52:48 +0100 |
|---|---|---|
| committer | Alisdair Owens <awo101@zepler.net> | 2015-07-22 13:52:48 +0100 |
| commit | dd3ac9058aa9684179415d0a6d36d23fba0d9bd1 (patch) | |
| tree | bce494604c6017f46283289e977104183abc9f49 | |
| parent | 90904204d6218ecb4bdfb36015759ade77b10f4b (diff) | |
| download | rust-dd3ac9058aa9684179415d0a6d36d23fba0d9bd1.tar.gz rust-dd3ac9058aa9684179415d0a6d36d23fba0d9bd1.zip | |
Add long diagnostics for E0223 and E0225
| -rw-r--r-- | src/librustc_typeck/diagnostics.rs | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index a002ed311e8..aa3219e589a 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -1886,6 +1886,62 @@ type Foo = Trait<Bar=i32>; // ok! ``` "##, +E0223: r##" +An attempt was made to retrieve an associated type, but the type was ambiguous. +For example: + +``` +trait MyTrait {type X; } + +fn main() { + let foo: MyTrait::X; +} +``` + +The problem here is that we're attempting to take the type of X from MyTrait. +Unfortunately, the type of X is not defined, because it's only made concrete in +implementations of the trait. A working version of this code might look like: + +``` +trait MyTrait {type X; } +struct MyStruct; + +impl MyTrait for MyStruct { + type X = u32; +} + +fn main() { + let foo: <MyStruct as MyTrait>::X; +} +``` + +This syntax specifies that we want the X type from MyTrait, as made concrete in +MyStruct. The reason that we cannot simply use `MyStruct::X` is that MyStruct +might implement two different traits with identically-named associated types. +This syntax allows disambiguation between the two. +"##, + +E0225: r##" +You attempted to use multiple types as bounds for a closure or trait object. +Rust does not currently support this. A simple example that causes this error: + +``` +fn main() { + let _: Box<std::io::Read+std::io::Write>; +} +``` + +Builtin traits are an exception to this rule: it's possible to have bounds of +one non-builtin type, plus any number of builtin types. For example, the +following compiles correctly: + +``` +fn main() { + let _: Box<std::io::Read+Copy+Sync>; +} +``` +"##, + E0232: r##" The attribute must have a value. Erroneous code example: @@ -2225,9 +2281,7 @@ register_diagnostics! { E0221, // ambiguous associated type in bounds //E0222, // Error code E0045 (variadic function must have C calling // convention) duplicate - E0223, // ambiguous associated type E0224, // at least one non-builtin train is required for an object type - E0225, // only the builtin traits can be used as closure or object bounds E0226, // only a single explicit lifetime bound is permitted E0227, // ambiguous lifetime bound, explicit lifetime bound required E0228, // explicit lifetime bound required |
