Skip to content

Commit be2d0dc

Browse files
---
yaml --- r: 235035 b: refs/heads/stable c: be38926 h: refs/heads/master i: 235033: bbef502 235031: 3a8eb0a v: v3
1 parent 18b5d31 commit be2d0dc

File tree

2 files changed

+78
-9
lines changed

2 files changed

+78
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/heads/tmp: afae2ff723393b3ab4ccffef6ac7c6d1809e2da0
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: f859507de8c410b648d934d8f5ec1c52daac971d
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: 2881e83c96c6f35fdc6741bbb3f951507ef74ca5
32+
refs/heads/stable: be38926b6941f13b1f03c2e3523b98dd256b3c7b
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b
3535
refs/tags/1.2.0: f557861f822c34f07270347b94b5280de20a597e

branches/stable/src/librustc_typeck/diagnostics.rs

Lines changed: 77 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,22 +1245,92 @@ impl Bytes { ... } // error, same as above
12451245
"##,
12461246

12471247
E0117: r##"
1248-
You tried to implement a trait on a type which isn't defined in your crate.
1249-
Erroneous code example:
1248+
You got this error because because you tried to implement a foreign
1249+
trait for a foreign type (with maybe a foreign type parameter). Erroneous
1250+
code example:
12501251
12511252
```
12521253
impl Drop for u32 {}
12531254
```
12541255
1255-
The type on which you want to implement the trait has to be defined in
1256-
your crate. Example:
1256+
The type, trait or the type parameter (or all of them) has to be defined
1257+
in your crate. Example:
12571258
12581259
```
12591260
pub struct Foo; // you define your type in your crate
12601261
12611262
impl Drop for Foo { // and you can implement the trait on it!
12621263
// code of trait implementation here
12631264
}
1265+
1266+
trait Bar { // or define your trait in your crate
1267+
fn get(&self) -> usize;
1268+
}
1269+
1270+
impl Bar for u32 { // and then you implement it on a foreign type
1271+
fn get(&self) -> usize { 0 }
1272+
}
1273+
1274+
impl From<Foo> for i32 { // or you use a type from your crate as
1275+
// a type parameter
1276+
fn from(i: Foo) -> i32 {
1277+
0
1278+
}
1279+
}
1280+
```
1281+
"##,
1282+
1283+
E0119: r##"
1284+
There are conflicting trait implementations for the same type.
1285+
Erroneous code example:
1286+
1287+
```
1288+
trait MyTrait {
1289+
fn get(&self) -> usize;
1290+
}
1291+
1292+
impl<T> MyTrait for T {
1293+
fn get(&self) -> usize { 0 }
1294+
}
1295+
1296+
struct Foo {
1297+
value: usize
1298+
}
1299+
1300+
impl MyTrait for Foo { // error: conflicting implementations for trait
1301+
// `MyTrait`
1302+
fn get(&self) -> usize { self.value }
1303+
}
1304+
```
1305+
1306+
When you write:
1307+
1308+
```
1309+
impl<T> MyTrait for T {
1310+
fn get(&self) -> usize { 0 }
1311+
}
1312+
```
1313+
1314+
This makes the trait implemented on all types in the scope. So if you
1315+
try to implement it on another one after that, the implementations will
1316+
conflict. Example:
1317+
1318+
```
1319+
trait MyTrait {
1320+
fn get(&self) -> usize;
1321+
}
1322+
1323+
impl<T> MyTrait for T {
1324+
fn get(&self) -> usize { 0 }
1325+
}
1326+
1327+
struct Foo;
1328+
1329+
fn main() {
1330+
let f = Foo;
1331+
1332+
f.get(); // the trait is implemented so we can use it
1333+
}
12641334
```
12651335
"##,
12661336

@@ -1403,7 +1473,7 @@ impl Trait for Foo {
14031473
}
14041474
```
14051475
1406-
The `'b` lifetime constraint for bar() implementation does not match the
1476+
The lifetime constraint `'b` for bar() implementation does not match the
14071477
trait declaration. Ensure lifetime declarations match exactly in both trait
14081478
declaration and implementation. Example:
14091479
@@ -1601,8 +1671,8 @@ impl Copy for &'static Bar { } // error
16011671
"##,
16021672

16031673
E0207: r##"
1604-
You passed an unused type parameter when implementing a trait
1605-
on an object. Erroneous code example:
1674+
You declared an unused type parameter when implementing a trait on an object.
1675+
Erroneous code example:
16061676
16071677
```
16081678
trait MyTrait {
@@ -1883,7 +1953,6 @@ register_diagnostics! {
18831953
E0103,
18841954
E0104,
18851955
E0118,
1886-
E0119,
18871956
E0120,
18881957
E0122,
18891958
E0123,

0 commit comments

Comments
 (0)