File tree 7 files changed +71
-21
lines changed
rustc_error_codes/src/error_codes
rustc_typeck/src/coherence
7 files changed +71
-21
lines changed Original file line number Diff line number Diff line change 1
- An inherent implementation was defined for something which isn't a struct nor
2
- an enum.
1
+ An inherent implementation was defined for something which isn't a struct,
2
+ enum, union, or trait object .
3
3
4
4
Erroneous code example:
5
5
6
6
``` compile_fail,E0118
7
- impl (u8, u8) { // error: no base type found for inherent implementation
7
+ impl (u8, u8) { // error: no nominal type found for inherent implementation
8
8
fn get_state(&self) -> String {
9
9
// ...
10
10
}
@@ -41,3 +41,24 @@ impl TypeWrapper {
41
41
}
42
42
}
43
43
```
44
+
45
+ Instead of defining an inherent implementation on a reference, you could also
46
+ move the reference inside the implementation:
47
+
48
+ ``` compile_fail,E0118
49
+ struct Foo;
50
+
51
+ impl &Foo { // error: no nominal type found for inherent implementation
52
+ fn bar(self, other: Self) {}
53
+ }
54
+ ```
55
+
56
+ becomes
57
+
58
+ ```
59
+ struct Foo;
60
+
61
+ impl Foo {
62
+ fn bar(&self, other: &Self) {}
63
+ }
64
+ ```
Original file line number Diff line number Diff line change @@ -308,18 +308,25 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
308
308
}
309
309
ty:: Error ( _) => { }
310
310
_ => {
311
- struct_span_err ! (
311
+ let mut err = struct_span_err ! (
312
312
self . tcx. sess,
313
313
ty. span,
314
314
E0118 ,
315
- "no base type found for inherent implementation"
316
- )
317
- . span_label ( ty. span , "impl requires a base type" )
318
- . note (
319
- "either implement a trait on it or create a newtype \
320
- to wrap it instead",
321
- )
322
- . emit ( ) ;
315
+ "no nominal type found for inherent implementation"
316
+ ) ;
317
+
318
+ err. span_label ( ty. span , "impl requires a nominal type" )
319
+ . note ( "either implement a trait on it or create a newtype to wrap it instead" ) ;
320
+
321
+ if let ty:: Ref ( _, subty, _) = self_ty. kind ( ) {
322
+ err. note ( & format ! (
323
+ "you could also try moving the reference to \
324
+ uses of `{}` (such as `self`) within the implementation",
325
+ subty
326
+ ) ) ;
327
+ }
328
+
329
+ err. emit ( ) ;
323
330
}
324
331
}
325
332
}
Original file line number Diff line number Diff line change
1
+ struct Foo ;
2
+
3
+ impl & mut Foo {
4
+ //~^ ERROR E0118
5
+ fn bar ( self ) { }
6
+ }
7
+
8
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error[E0118]: no nominal type found for inherent implementation
2
+ --> $DIR/E0118-2.rs:3:6
3
+ |
4
+ LL | impl &mut Foo {
5
+ | ^^^^^^^^ impl requires a nominal type
6
+ |
7
+ = note: either implement a trait on it or create a newtype to wrap it instead
8
+ = note: you could also try moving the reference to uses of `Foo` (such as `self`) within the implementation
9
+
10
+ error: aborting due to previous error
11
+
12
+ For more information about this error, try `rustc --explain E0118`.
Original file line number Diff line number Diff line change 1
- error[E0118]: no base type found for inherent implementation
1
+ error[E0118]: no nominal type found for inherent implementation
2
2
--> $DIR/E0118.rs:1:6
3
3
|
4
4
LL | impl (u8, u8) {
5
- | ^^^^^^^^ impl requires a base type
5
+ | ^^^^^^^^ impl requires a nominal type
6
6
|
7
7
= note: either implement a trait on it or create a newtype to wrap it instead
8
8
Original file line number Diff line number Diff line change @@ -11,7 +11,8 @@ mod aliases_pub {
11
11
type AssocAlias = m:: Pub3 ;
12
12
}
13
13
14
- impl <Priv as PrivTr >:: AssocAlias { //~ ERROR no base type found for inherent implementation
14
+ impl <Priv as PrivTr >:: AssocAlias {
15
+ //~^ ERROR no nominal type found for inherent implementation
15
16
pub fn f ( arg : Priv ) { } // private type `aliases_pub::Priv` in public interface
16
17
}
17
18
}
@@ -27,7 +28,8 @@ mod aliases_priv {
27
28
type AssocAlias = Priv3 ;
28
29
}
29
30
30
- impl <Priv as PrivTr >:: AssocAlias { //~ ERROR no base type found for inherent implementation
31
+ impl <Priv as PrivTr >:: AssocAlias {
32
+ //~^ ERROR no nominal type found for inherent implementation
31
33
pub fn f ( arg : Priv ) { } // OK
32
34
}
33
35
}
Original file line number Diff line number Diff line change 1
- error[E0118]: no base type found for inherent implementation
1
+ error[E0118]: no nominal type found for inherent implementation
2
2
--> $DIR/private-in-public-ill-formed.rs:14:10
3
3
|
4
4
LL | impl <Priv as PrivTr>::AssocAlias {
5
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl requires a base type
5
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl requires a nominal type
6
6
|
7
7
= note: either implement a trait on it or create a newtype to wrap it instead
8
8
9
- error[E0118]: no base type found for inherent implementation
10
- --> $DIR/private-in-public-ill-formed.rs:30 :10
9
+ error[E0118]: no nominal type found for inherent implementation
10
+ --> $DIR/private-in-public-ill-formed.rs:31 :10
11
11
|
12
12
LL | impl <Priv as PrivTr>::AssocAlias {
13
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl requires a base type
13
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl requires a nominal type
14
14
|
15
15
= note: either implement a trait on it or create a newtype to wrap it instead
16
16
You can’t perform that action at this time.
0 commit comments