diff options
| -rw-r--r-- | src/doc/reference.md | 2 | ||||
| -rw-r--r-- | src/librustc/diagnostics.rs | 4 | ||||
| -rw-r--r-- | src/librustc_typeck/coherence/orphan.rs | 4 | ||||
| -rw-r--r-- | src/librustc_typeck/diagnostics.rs | 27 | ||||
| -rw-r--r-- | src/test/compile-fail/trait-or-new-type-instead.rs | 4 |
5 files changed, 33 insertions, 8 deletions
diff --git a/src/doc/reference.md b/src/doc/reference.md index 8d57238dc17..2a0f7b659d1 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -1550,7 +1550,7 @@ methods in such an implementation can only be used as direct calls on the values of the type that the implementation targets. In such an implementation, the trait type and `for` after `impl` are omitted. Such implementations are limited to nominal types (enums, structs), and the implementation must appear -in the same module or a sub-module as the `self` type: +in the same crate as the `self` type: ``` struct Point {x: i32, y: i32} diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 9a60e2378cc..0857fb3258e 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -312,8 +312,8 @@ http://doc.rust-lang.org/reference.html#ffi-attributes E0133: r##" Using unsafe functionality, such as dereferencing raw pointers and calling functions via FFI or marked as unsafe, is potentially dangerous and disallowed -by safety checks. As such, those safety checks can be temporarily relaxed by -wrapping the unsafe instructions inside an `unsafe` block. For instance: +by safety checks. These safety checks can be relaxed for a section of the code +by wrapping the unsafe instructions with an `unsafe` block. For instance: ``` unsafe fn f() { return; } diff --git a/src/librustc_typeck/coherence/orphan.rs b/src/librustc_typeck/coherence/orphan.rs index 7dc865ef885..cc03dffe3a0 100644 --- a/src/librustc_typeck/coherence/orphan.rs +++ b/src/librustc_typeck/coherence/orphan.rs @@ -33,8 +33,8 @@ impl<'cx, 'tcx> OrphanChecker<'cx, 'tcx> { fn check_def_id(&self, item: &ast::Item, def_id: ast::DefId) { if def_id.krate != ast::LOCAL_CRATE { span_err!(self.tcx.sess, item.span, E0116, - "cannot associate methods with a type outside the \ - crate the type is defined in; define and implement \ + "cannot define inherent `impl` for a type outside of the \ + crate where the type is defined; define and implement \ a trait or new type instead"); } } diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index 10bae6f63d0..c2cb55bb1f5 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -730,6 +730,32 @@ RFC. It is, however, [currently unimplemented][iss15872]. [iss15872]: https://github.com/rust-lang/rust/issues/15872 "##, +E0116: r##" +You can only define an inherent implementation for a type in the same crate +where the type was defined. For example, an `impl` block as below is not allowed +since `Vec` is defined in the standard library: + +``` +impl Vec<u8> { ... } // error +``` + +To fix this problem, you can do either of these things: + + - define a trait that has the desired associated functions/types/constants and + implement the trait for the type in question + - define a new type wrapping the type and define an implementation on the new + type + +Note that using the `type` keyword does not work here because `type` only +introduces a type alias: + +``` +type Bytes = Vec<u8>; + +impl Bytes { ... } // error, same as above +``` +"##, + E0121: r##" In order to be consistent with Rust's lack of global type inference, type placeholders are disallowed by design in item signatures. @@ -1232,7 +1258,6 @@ register_diagnostics! { E0102, E0103, E0104, - E0116, E0117, E0118, E0119, diff --git a/src/test/compile-fail/trait-or-new-type-instead.rs b/src/test/compile-fail/trait-or-new-type-instead.rs index 3aec23a55b8..b1e4d06affe 100644 --- a/src/test/compile-fail/trait-or-new-type-instead.rs +++ b/src/test/compile-fail/trait-or-new-type-instead.rs @@ -1,4 +1,4 @@ -// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT +// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT // file at the top-level directory of this distribution and at // http://rust-lang.org/COPYRIGHT. // @@ -9,7 +9,7 @@ // except according to those terms. impl<T> Option<T> { -//~^ ERROR cannot associate methods with a type outside the crate the type is defined in +//~^ ERROR cannot define inherent `impl` for a type outside of the crate where the type is defined pub fn foo(&self) { } } |
