Skip to content

Commit eb15030

Browse files
author
Nick Hamann
committed
Add error explanations for E0040, E0087, E0378, E0379, E0394.
1 parent f607440 commit eb15030

File tree

2 files changed

+81
-6
lines changed

2 files changed

+81
-6
lines changed

src/librustc/diagnostics.rs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,40 @@ struct Foo<T: 'static> {
846846
foo: &'static T
847847
}
848848
```
849+
"##,
850+
851+
E0378: r##"
852+
Method calls that aren't calls to inherent `const` methods are disallowed
853+
in statics, constants, and constant functions.
854+
855+
For example:
856+
857+
```
858+
const BAZ: i32 = Foo(25).bar(); // error, `bar` isn't `const`
859+
860+
struct Foo(i32);
861+
862+
impl Foo {
863+
const fn foo(&self) -> i32 {
864+
self.bar() // error, `bar` isn't `const`
865+
}
866+
867+
fn bar(&self) -> i32 { self.0 }
868+
}
869+
```
870+
871+
For more information about `const fn`'s, see [RFC 911].
872+
873+
[RFC 911]: https://github.com/rust-lang/rfcs/pull/911
874+
"##,
875+
876+
E0394: r##"
877+
From [RFC 246]:
878+
879+
> It is illegal for a static to reference another static by value. It is
880+
> required that all references be borrowed.
881+
882+
[RFC 246]: https://github.com/rust-lang/rfcs/pull/246
849883
"##
850884

851885
}
@@ -895,9 +929,6 @@ register_diagnostics! {
895929
E0315, // cannot invoke closure outside of its lifetime
896930
E0316, // nested quantification of lifetimes
897931
E0370, // discriminant overflow
898-
E0378, // method calls limited to constant inherent methods
899-
E0394, // cannot refer to other statics by value, use the address-of
900-
// operator or a constant instead
901932
E0395, // pointer comparison in const-expr
902933
E0396 // pointer dereference in const-expr
903934
}

src/librustc_typeck/diagnostics.rs

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,31 @@ Reference:
170170
http://doc.rust-lang.org/reference.html#trait-objects
171171
"##,
172172

173+
E0040: r##"
174+
It is not allowed to manually call destructors in Rust. It is also not
175+
necessary to do this since `drop` is called automatically whenever a value goes
176+
out of scope.
177+
178+
Here's an example of this error:
179+
180+
```
181+
struct Foo {
182+
x: i32,
183+
}
184+
185+
impl Drop for Foo {
186+
fn drop(&mut self) {
187+
println!("kaboom");
188+
}
189+
}
190+
191+
fn main() {
192+
let mut x = Foo { x: -7 };
193+
x.drop(); // error: explicit use of destructor method
194+
}
195+
```
196+
"##,
197+
173198
E0046: r##"
174199
When trying to make some type implement a trait `Foo`, you must, at minimum,
175200
provide implementations for all of `Foo`'s required methods (meaning the
@@ -542,6 +567,21 @@ enum Empty {}
542567
```
543568
"##,
544569

570+
E0087: r##"
571+
Too many type parameters were supplied for a function. For example:
572+
573+
```
574+
fn foo<T>() {}
575+
576+
fn main() {
577+
foo::<f64, bool>(); // error, expected 1 parameter, found 2 parameters
578+
}
579+
```
580+
581+
The number of supplied parameters much exactly match the number of defined type
582+
parameters.
583+
"##,
584+
545585
E0089: r##"
546586
Not enough type parameters were supplied for a function. For example:
547587
@@ -1098,6 +1138,13 @@ Trait2 { ... }`) does not work if the trait is not object-safe. Please see the
10981138
[RFC 255]: https://github.com/rust-lang/rfcs/pull/255
10991139
"##,
11001140

1141+
E0379: r##"
1142+
Trait methods cannot be declared `const` by design. For more information, see
1143+
[RFC 911].
1144+
1145+
[RFC 911]: https://github.com/rust-lang/rfcs/pull/911
1146+
"##,
1147+
11011148
E0380: r##"
11021149
Default impls are only allowed for traits with no methods or associated items.
11031150
For more information see the [opt-in builtin traits RFC](https://github.com/rust
@@ -1113,7 +1160,6 @@ register_diagnostics! {
11131160
E0034, // multiple applicable methods in scope
11141161
E0035, // does not take type parameters
11151162
E0036, // incorrect number of type parameters given for this method
1116-
E0040, // explicit use of destructor method
11171163
E0044, // foreign items may not have type parameters
11181164
E0045, // variadic function must have C calling convention
11191165
E0057, // method has an incompatible type for trait
@@ -1128,7 +1174,6 @@ register_diagnostics! {
11281174
E0077,
11291175
E0085,
11301176
E0086,
1131-
E0087,
11321177
E0088,
11331178
E0090,
11341179
E0091,
@@ -1235,7 +1280,6 @@ register_diagnostics! {
12351280
// between structures
12361281
E0377, // the trait `CoerceUnsized` may only be implemented for a coercion
12371282
// between structures with the same definition
1238-
E0379, // trait fns cannot be const
12391283
E0390, // only a single inherent implementation marked with
12401284
// `#[lang = \"{}\"]` is allowed for the `{}` primitive
12411285
E0391, // unsupported cyclic reference between types/traits detected

0 commit comments

Comments
 (0)