Skip to content

Add error explanation for E0116 #26172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/coherence/orphan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Expand Down
27 changes: 26 additions & 1 deletion src/librustc_typeck/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -1232,7 +1258,6 @@ register_diagnostics! {
E0102,
E0103,
E0104,
E0116,
E0117,
E0118,
E0119,
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/trait-or-new-type-instead.rs
Original file line number Diff line number Diff line change
@@ -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.
//
Expand All @@ -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) { }
}

Expand Down