Skip to content

Commit c158be0

Browse files
Add E0195 error explanation
1 parent 40db46c commit c158be0

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

src/librustc_typeck/diagnostics.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,44 @@ information see the [opt-in builtin traits RFC](https://github.com/rust-lang/
12501250
rfcs/blob/master/text/0019-opt-in-builtin-traits.md).
12511251
"##,
12521252

1253+
E0195: r##"
1254+
Your method's lifetime parameters do not match the trait declaration.
1255+
Erroneous code example:
1256+
1257+
```
1258+
trait Trait {
1259+
fn t<'a,'b:'a>(x: &'a str, y: &'b str);
1260+
}
1261+
1262+
struct Foo;
1263+
1264+
impl Trait for Foo {
1265+
fn t<'a,'b>(x: &'a str, y: &'b str) { // error: lifetime parameters
1266+
// or bounds on method `t`
1267+
// do not match the trait
1268+
// declaration
1269+
}
1270+
}
1271+
```
1272+
1273+
The 'b lifetime constraints for `t` implementation does not match the
1274+
trait declaration. Ensure lifetime declarations match exactly in both trait
1275+
declaration and implementation. Example:
1276+
1277+
```
1278+
trait Trait {
1279+
fn t<'a,'b:'a>(x: &'a str, y: &'b str);
1280+
}
1281+
1282+
struct Foo;
1283+
1284+
impl Trait for Foo {
1285+
fn t<'a,'b:'a>(x: &'a str, y: &'b str) { // ok!
1286+
}
1287+
}
1288+
```
1289+
"##,
1290+
12531291
E0197: r##"
12541292
Inherent implementations (one that do not implement a trait but provide
12551293
methods associated with a type) are always safe because they are not
@@ -1686,7 +1724,6 @@ register_diagnostics! {
16861724
E0193, // cannot bound type where clause bounds may only be attached to types
16871725
// involving type parameters
16881726
E0194,
1689-
E0195, // lifetime parameters or bounds on method do not match the trait declaration
16901727
E0196, // cannot determine a type for this closure
16911728
E0203, // type parameter has more than one relaxed default bound,
16921729
// and only one is supported

0 commit comments

Comments
 (0)