Rollup merge of #25873 - nham:update_E0015, r=Aatch
The E0397 explanation, as I've written it, isn't really an explanation, but I'm not sure what to put here. I will happily take suggestions. Partially addresses https://github.com/rust-lang/rust/issues/25851
This commit is contained in:
commit
c0a41b9999
4 changed files with 106 additions and 14 deletions
|
@ -196,9 +196,13 @@ const Y: i32 = A;
|
|||
"##,
|
||||
|
||||
E0015: r##"
|
||||
The only function calls allowed in static or constant expressions are enum
|
||||
variant constructors or struct constructors (for unit or tuple structs). This
|
||||
is because Rust currently does not support compile-time function execution.
|
||||
The only functions that can be called in static or constant expressions are
|
||||
`const` functions. Rust currently does not support more general compile-time
|
||||
function execution.
|
||||
|
||||
See [RFC 911] for more details on the design of `const fn`s.
|
||||
|
||||
[RFC 911]: https://github.com/rust-lang/rfcs/blob/master/text/0911-const-fn.md
|
||||
"##,
|
||||
|
||||
E0018: r##"
|
||||
|
@ -842,6 +846,53 @@ struct Foo<T: 'static> {
|
|||
foo: &'static T
|
||||
}
|
||||
```
|
||||
"##,
|
||||
|
||||
E0378: r##"
|
||||
Method calls that aren't calls to inherent `const` methods are disallowed
|
||||
in statics, constants, and constant functions.
|
||||
|
||||
For example:
|
||||
|
||||
```
|
||||
const BAZ: i32 = Foo(25).bar(); // error, `bar` isn't `const`
|
||||
|
||||
struct Foo(i32);
|
||||
|
||||
impl Foo {
|
||||
const fn foo(&self) -> i32 {
|
||||
self.bar() // error, `bar` isn't `const`
|
||||
}
|
||||
|
||||
fn bar(&self) -> i32 { self.0 }
|
||||
}
|
||||
```
|
||||
|
||||
For more information about `const fn`'s, see [RFC 911].
|
||||
|
||||
[RFC 911]: https://github.com/rust-lang/rfcs/blob/master/text/0911-const-fn.md
|
||||
"##,
|
||||
|
||||
E0394: r##"
|
||||
From [RFC 246]:
|
||||
|
||||
> It is illegal for a static to reference another static by value. It is
|
||||
> required that all references be borrowed.
|
||||
|
||||
[RFC 246]: https://github.com/rust-lang/rfcs/pull/246
|
||||
"##,
|
||||
|
||||
E0397: r##"
|
||||
It is not allowed for a mutable static to allocate or have destructors. For
|
||||
example:
|
||||
|
||||
```
|
||||
// error: mutable statics are not allowed to have boxes
|
||||
static mut FOO: Option<Box<usize>> = None;
|
||||
|
||||
// error: mutable statics are not allowed to have destructors
|
||||
static mut BAR: Option<Vec<i32>> = None;
|
||||
```
|
||||
"##
|
||||
|
||||
}
|
||||
|
@ -891,9 +942,6 @@ register_diagnostics! {
|
|||
E0315, // cannot invoke closure outside of its lifetime
|
||||
E0316, // nested quantification of lifetimes
|
||||
E0370, // discriminant overflow
|
||||
E0378, // method calls limited to constant inherent methods
|
||||
E0394, // cannot refer to other statics by value, use the address-of
|
||||
// operator or a constant instead
|
||||
E0395, // pointer comparison in const-expr
|
||||
E0396 // pointer dereference in const-expr
|
||||
}
|
||||
|
|
|
@ -273,13 +273,13 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
|
|||
let suffix = if tcontents.has_dtor() {
|
||||
"destructors"
|
||||
} else if tcontents.owns_owned() {
|
||||
"owned pointers"
|
||||
"boxes"
|
||||
} else {
|
||||
return
|
||||
};
|
||||
|
||||
self.tcx.sess.span_err(e.span, &format!("mutable statics are not allowed \
|
||||
to have {}", suffix));
|
||||
span_err!(self.tcx.sess, e.span, E0397,
|
||||
"mutable statics are not allowed to have {}", suffix);
|
||||
}
|
||||
|
||||
fn check_static_type(&self, e: &ast::Expr) {
|
||||
|
|
|
@ -170,6 +170,31 @@ Reference:
|
|||
http://doc.rust-lang.org/reference.html#trait-objects
|
||||
"##,
|
||||
|
||||
E0040: r##"
|
||||
It is not allowed to manually call destructors in Rust. It is also not
|
||||
necessary to do this since `drop` is called automatically whenever a value goes
|
||||
out of scope.
|
||||
|
||||
Here's an example of this error:
|
||||
|
||||
```
|
||||
struct Foo {
|
||||
x: i32,
|
||||
}
|
||||
|
||||
impl Drop for Foo {
|
||||
fn drop(&mut self) {
|
||||
println!("kaboom");
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut x = Foo { x: -7 };
|
||||
x.drop(); // error: explicit use of destructor method
|
||||
}
|
||||
```
|
||||
"##,
|
||||
|
||||
E0046: r##"
|
||||
When trying to make some type implement a trait `Foo`, you must, at minimum,
|
||||
provide implementations for all of `Foo`'s required methods (meaning the
|
||||
|
@ -241,7 +266,7 @@ impl Foo for Bar {
|
|||
fn foo(x: i16) { }
|
||||
|
||||
// error, values differ in mutability
|
||||
fn foo(&mut self) { }
|
||||
fn bar(&mut self) { }
|
||||
}
|
||||
```
|
||||
"##,
|
||||
|
@ -542,6 +567,21 @@ enum Empty {}
|
|||
```
|
||||
"##,
|
||||
|
||||
E0087: r##"
|
||||
Too many type parameters were supplied for a function. For example:
|
||||
|
||||
```
|
||||
fn foo<T>() {}
|
||||
|
||||
fn main() {
|
||||
foo::<f64, bool>(); // error, expected 1 parameter, found 2 parameters
|
||||
}
|
||||
```
|
||||
|
||||
The number of supplied parameters much exactly match the number of defined type
|
||||
parameters.
|
||||
"##,
|
||||
|
||||
E0089: r##"
|
||||
Not enough type parameters were supplied for a function. For example:
|
||||
|
||||
|
@ -1098,6 +1138,13 @@ Trait2 { ... }`) does not work if the trait is not object-safe. Please see the
|
|||
[RFC 255]: https://github.com/rust-lang/rfcs/pull/255
|
||||
"##,
|
||||
|
||||
E0379: r##"
|
||||
Trait methods cannot be declared `const` by design. For more information, see
|
||||
[RFC 911].
|
||||
|
||||
[RFC 911]: https://github.com/rust-lang/rfcs/pull/911
|
||||
"##,
|
||||
|
||||
E0380: r##"
|
||||
Default impls are only allowed for traits with no methods or associated items.
|
||||
For more information see the [opt-in builtin traits RFC](https://github.com/rust
|
||||
|
@ -1113,7 +1160,6 @@ register_diagnostics! {
|
|||
E0034, // multiple applicable methods in scope
|
||||
E0035, // does not take type parameters
|
||||
E0036, // incorrect number of type parameters given for this method
|
||||
E0040, // explicit use of destructor method
|
||||
E0044, // foreign items may not have type parameters
|
||||
E0045, // variadic function must have C calling convention
|
||||
E0057, // method has an incompatible type for trait
|
||||
|
@ -1128,7 +1174,6 @@ register_diagnostics! {
|
|||
E0077,
|
||||
E0085,
|
||||
E0086,
|
||||
E0087,
|
||||
E0088,
|
||||
E0090,
|
||||
E0091,
|
||||
|
@ -1235,7 +1280,6 @@ register_diagnostics! {
|
|||
// between structures
|
||||
E0377, // the trait `CoerceUnsized` may only be implemented for a coercion
|
||||
// between structures with the same definition
|
||||
E0379, // trait fns cannot be const
|
||||
E0390, // only a single inherent implementation marked with
|
||||
// `#[lang = \"{}\"]` is allowed for the `{}` primitive
|
||||
E0391, // unsupported cyclic reference between types/traits detected
|
||||
|
|
|
@ -12,6 +12,6 @@
|
|||
|
||||
static mut a: Box<isize> = box 3;
|
||||
//~^ ERROR allocations are not allowed in statics
|
||||
//~^^ ERROR mutable statics are not allowed to have owned pointers
|
||||
//~^^ ERROR mutable statics are not allowed to have boxes
|
||||
|
||||
fn main() {}
|
||||
|
|
Loading…
Add table
Reference in a new issue