Auto merge of #26172 - nham:add_E0116, r=alexcrichton
Also improves the wording of the E0133 description. cc #24407
This commit is contained in:
commit
fc9e424550
@ -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}
|
||||
|
@ -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; }
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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) { }
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user