From eb15030dc18933c189daa0f9e0dfc780691a217b Mon Sep 17 00:00:00 2001 From: Nick Hamann Date: Wed, 27 May 2015 14:07:20 -0500 Subject: [PATCH] Add error explanations for E0040, E0087, E0378, E0379, E0394. --- src/librustc/diagnostics.rs | 37 ++++++++++++++++++++-- src/librustc_typeck/diagnostics.rs | 50 ++++++++++++++++++++++++++++-- 2 files changed, 81 insertions(+), 6 deletions(-) diff --git a/src/librustc/diagnostics.rs b/src/librustc/diagnostics.rs index 499973715269..cc0ea621a49a 100644 --- a/src/librustc/diagnostics.rs +++ b/src/librustc/diagnostics.rs @@ -846,6 +846,40 @@ struct Foo { 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/pull/911 +"##, + +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 "## } @@ -895,9 +929,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 } diff --git a/src/librustc_typeck/diagnostics.rs b/src/librustc_typeck/diagnostics.rs index a3d77bb351df..c822a7faa19b 100644 --- a/src/librustc_typeck/diagnostics.rs +++ b/src/librustc_typeck/diagnostics.rs @@ -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 @@ -542,6 +567,21 @@ enum Empty {} ``` "##, +E0087: r##" +Too many type parameters were supplied for a function. For example: + +``` +fn foo() {} + +fn main() { + foo::(); // 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