summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhlosioneer <mattmdrr2@gmail.com>2018-03-26 00:34:58 -0400
committerPhlosioneer <mattmdrr2@gmail.com>2018-03-26 00:34:58 -0400
commitf76eaece4e6d1c516564fe1d9677aa6a58fe53e4 (patch)
tree363be9feee67bf63db5e3249bc4eb9ea14e62d93
parent482a913fb337855072a53c0d602cd19947f45285 (diff)
downloadrust-f76eaece4e6d1c516564fe1d9677aa6a58fe53e4.tar.gz
Better error message when trying to write default impls
Previously, if you tried to write this (using the specialization feature flag): default impl PartialEq<MyType> { ... } The compiler would give you the mysterious warning "inherent impls cannot be default". What it really means is that you're trying to write an impl for a Structure or *Trait Object*, and that cannot be "default". However, one of the ways to encounter this error (as shown by the above example) is when you forget to write "for MyType". This PR adds a help message that reads "maybe missing a `for` keyword?" This is useful, actionable advice that will help any user identify their mistake, and doesn't get in the way or mislead any user that really meant to use the "default" keyword for this weird purpose. In particular, this help message will be useful for any users who don't know the "inherent impl" terminology, and/or users who forget that inherent impls CAN be written for traits (they apply to the trait objects). Both of these are somewhat confusing, seldom- used concepts; a one-line error message without any error number for longer explanation is NOT the place to introduce these ideas.
-rw-r--r--src/librustc_passes/ast_validation.rs4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/librustc_passes/ast_validation.rs b/src/librustc_passes/ast_validation.rs
index 37274d1fc44..1c73ced806e 100644
--- a/src/librustc_passes/ast_validation.rs
+++ b/src/librustc_passes/ast_validation.rs
@@ -272,7 +272,9 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
self.err_handler().span_err(item.span, "inherent impls cannot be negative");
}
if defaultness == Defaultness::Default {
- self.err_handler().span_err(item.span, "inherent impls cannot be default");
+ self.err_handler()
+ .struct_span_err(item.span, "inherent impls cannot be default")
+ .help("maybe a missing `for` keyword?");
}
}
ItemKind::ForeignMod(..) => {