@@ -1489,22 +1489,46 @@ For information on the design of the orphan rules, see [RFC 1023].
14891489"## ,
14901490
14911491E0118 : r##"
1492- Rust can't find a base type for an implementation you are providing, or the type
1493- cannot have an implementation. For example, only a named type or a trait can
1494- have an implementation:
1492+ You're trying to write an inherent implementation for something which isn't a
1493+ struct nor an enum. Erroneous code example:
14951494
14961495```
1497- type NineString = [char, ..9] // This isn't a named type (struct, enum or trait)
1498- impl NineString {
1499- // Some code here
1496+ impl (u8, u8) { // error: no base type found for inherent implementation
1497+ fn get_state(&self) -> String {
1498+ // ...
1499+ }
1500+ }
1501+ ```
1502+
1503+ To fix this error, please implement a trait on the type or wrap it in a struct.
1504+ Example:
1505+
1506+ ```
1507+ // we create a trait here
1508+ trait LiveLongAndProsper {
1509+ fn get_state(&self) -> String;
1510+ }
1511+
1512+ // and now you can implement it on (u8, u8)
1513+ impl LiveLongAndProsper for (u8, u8) {
1514+ fn get_state(&self) -> String {
1515+ "He's dead, Jim!".to_owned()
1516+ }
15001517}
15011518```
15021519
1503- In the other, simpler case, Rust just can't find the type you are providing an
1504- impelementation for:
1520+ Alternatively, you can create a newtype. A newtype is a wrapping tuple-struct.
1521+ For example, `NewType` is a newtype over `Foo` in `struct NewType(Foo)`.
1522+ Example:
15051523
15061524```
1507- impl SomeTypeThatDoesntExist { }
1525+ struct TypeWrapper((u8, u8));
1526+
1527+ impl TypeWrapper {
1528+ fn get_state(&self) -> String {
1529+ "Fascinating!".to_owned()
1530+ }
1531+ }
15081532```
15091533"## ,
15101534
0 commit comments