提交 4e21942b 编写于 作者: C Camelid

Clarify the 'default is only allowed on...' error

Code like

    impl Foo {
        default fn foo() {}
    }

will trigger the error

    error: `default` is only allowed on items in `impl` definitions
     --> src/lib.rs:5:5
      |
    5 |     default fn foo() {}
      |     -------^^^^^^^^^
      |     |
      |     `default` because of this

but that's very confusing! I *did* put it on an item in an impl!

So this commit changes the message to

    error: `default` is only allowed on items in trait impls
     --> src/lib.rs:5:5
      |
    5 |     default fn foo() {}
      |     -------^^^^^^^^^
      |     |
      |     `default` because of this
上级 5bb68c31
......@@ -400,7 +400,7 @@ fn check_defaultness(&self, span: Span, defaultness: Defaultness) {
if let Defaultness::Default(def_span) = defaultness {
let span = self.session.source_map().guess_head_span(span);
self.err_handler()
.struct_span_err(span, "`default` is only allowed on items in `impl` definitions")
.struct_span_err(span, "`default` is only allowed on items in trait impls")
.span_label(def_span, "`default` because of this")
.emit();
}
......
......@@ -3,10 +3,10 @@
fn main() {}
trait X {
default const A: u8; //~ ERROR `default` is only allowed on items in `impl` definitions
default const B: u8 = 0; //~ ERROR `default` is only allowed on items in `impl` definitions
default type D; //~ ERROR `default` is only allowed on items in `impl` definitions
default type C: Ord; //~ ERROR `default` is only allowed on items in `impl` definitions
default fn f1(); //~ ERROR `default` is only allowed on items in `impl` definitions
default fn f2() {} //~ ERROR `default` is only allowed on items in `impl` definitions
default const A: u8; //~ ERROR `default` is only allowed on items in trait impls
default const B: u8 = 0; //~ ERROR `default` is only allowed on items in trait impls
default type D; //~ ERROR `default` is only allowed on items in trait impls
default type C: Ord; //~ ERROR `default` is only allowed on items in trait impls
default fn f1(); //~ ERROR `default` is only allowed on items in trait impls
default fn f2() {} //~ ERROR `default` is only allowed on items in trait impls
}
error: `default` is only allowed on items in `impl` definitions
error: `default` is only allowed on items in trait impls
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:6:5
|
LL | default const A: u8;
......@@ -6,7 +6,7 @@ LL | default const A: u8;
| |
| `default` because of this
error: `default` is only allowed on items in `impl` definitions
error: `default` is only allowed on items in trait impls
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:7:5
|
LL | default const B: u8 = 0;
......@@ -14,7 +14,7 @@ LL | default const B: u8 = 0;
| |
| `default` because of this
error: `default` is only allowed on items in `impl` definitions
error: `default` is only allowed on items in trait impls
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:8:5
|
LL | default type D;
......@@ -22,7 +22,7 @@ LL | default type D;
| |
| `default` because of this
error: `default` is only allowed on items in `impl` definitions
error: `default` is only allowed on items in trait impls
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:9:5
|
LL | default type C: Ord;
......@@ -30,7 +30,7 @@ LL | default type C: Ord;
| |
| `default` because of this
error: `default` is only allowed on items in `impl` definitions
error: `default` is only allowed on items in trait impls
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:10:5
|
LL | default fn f1();
......@@ -38,7 +38,7 @@ LL | default fn f1();
| |
| `default` because of this
error: `default` is only allowed on items in `impl` definitions
error: `default` is only allowed on items in trait impls
--> $DIR/trait-item-with-defaultness-fail-semantic.rs:11:5
|
LL | default fn f2() {}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册