Skip to content

Commit

Permalink
Rollup merge of #70428 - Centril:move-to-mod, r=petrochenkov
Browse files Browse the repository at this point in the history
`error_bad_item_kind`: add help text

For example, this adds:
```
    = help: consider moving the `use` import out to a nearby module scope
```
r? @petrochenkov @estebank

Fixes #37205.
  • Loading branch information
Dylan-DPC authored Mar 26, 2020
2 parents c640b95 + 91c68c5 commit ef43cde
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/librustc_parse/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -908,8 +908,10 @@ impl<'a> Parser<'a> {

fn error_bad_item_kind<T>(&self, span: Span, kind: &ItemKind, ctx: &str) -> Option<T> {
let span = self.sess.source_map().guess_head_span(span);
let msg = format!("{} is not supported in {}", kind.descr(), ctx);
self.struct_span_err(span, &msg).emit();
let descr = kind.descr();
self.struct_span_err(span, &format!("{} is not supported in {}", descr, ctx))
.help(&format!("consider moving the {} out to a nearby module scope", descr))
.emit();
None
}

Expand Down
72 changes: 72 additions & 0 deletions src/test/ui/parser/default-on-wrong-item-kind.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ error: extern crate is not supported in `extern` blocks
|
LL | default extern crate foo;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider moving the extern crate out to a nearby module scope

error: a `use` import cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:35:5
Expand All @@ -137,6 +139,8 @@ error: `use` import is not supported in `extern` blocks
|
LL | default use foo;
| ^^^^^^^^^^^^^^^^
|
= help: consider moving the `use` import out to a nearby module scope

error: a static item cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:37:5
Expand Down Expand Up @@ -169,6 +173,8 @@ error: module is not supported in `extern` blocks
|
LL | default mod foo {}
| ^^^^^^^^^^^^^^^
|
= help: consider moving the module out to a nearby module scope

error: an extern block cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:43:5
Expand All @@ -183,6 +189,8 @@ error: extern block is not supported in `extern` blocks
|
LL | default extern "C" {}
| ^^^^^^^^^^^^^^^^^^
|
= help: consider moving the extern block out to a nearby module scope

error: an enum cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:46:5
Expand All @@ -197,6 +205,8 @@ error: enum is not supported in `extern` blocks
|
LL | default enum foo {}
| ^^^^^^^^^^^^^^^^
|
= help: consider moving the enum out to a nearby module scope

error: a struct cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:48:5
Expand All @@ -211,6 +221,8 @@ error: struct is not supported in `extern` blocks
|
LL | default struct foo {}
| ^^^^^^^^^^^^^^^^^^
|
= help: consider moving the struct out to a nearby module scope

error: a union cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:50:5
Expand All @@ -225,6 +237,8 @@ error: union is not supported in `extern` blocks
|
LL | default union foo {}
| ^^^^^^^^^^^^^^^^^
|
= help: consider moving the union out to a nearby module scope

error: a trait cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:52:5
Expand All @@ -239,6 +253,8 @@ error: trait is not supported in `extern` blocks
|
LL | default trait foo {}
| ^^^^^^^^^^^^^^^^^
|
= help: consider moving the trait out to a nearby module scope

error: a trait alias cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:54:5
Expand All @@ -253,12 +269,16 @@ error: trait alias is not supported in `extern` blocks
|
LL | default trait foo = Ord;
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider moving the trait alias out to a nearby module scope

error: implementation is not supported in `extern` blocks
--> $DIR/default-on-wrong-item-kind.rs:56:5
|
LL | default impl foo {}
| ^^^^^^^^^^^^^^^^
|
= help: consider moving the implementation out to a nearby module scope

error: an item macro invocation cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:60:5
Expand Down Expand Up @@ -289,6 +309,8 @@ error: macro definition is not supported in `extern` blocks
|
LL | default macro foo {}
| ^^^^^^^^^^^^^^^^^
|
= help: consider moving the macro definition out to a nearby module scope

error: a macro definition cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:64:5
Expand All @@ -303,6 +325,8 @@ error: macro definition is not supported in `extern` blocks
|
LL | default macro_rules! foo {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider moving the macro definition out to a nearby module scope

error: an extern crate cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:70:5
Expand All @@ -317,6 +341,8 @@ error: extern crate is not supported in `trait`s or `impl`s
|
LL | default extern crate foo;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider moving the extern crate out to a nearby module scope

error: a `use` import cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:72:5
Expand All @@ -331,6 +357,8 @@ error: `use` import is not supported in `trait`s or `impl`s
|
LL | default use foo;
| ^^^^^^^^^^^^^^^^
|
= help: consider moving the `use` import out to a nearby module scope

error: a static item cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:74:5
Expand Down Expand Up @@ -359,6 +387,8 @@ error: module is not supported in `trait`s or `impl`s
|
LL | default mod foo {}
| ^^^^^^^^^^^^^^^
|
= help: consider moving the module out to a nearby module scope

error: an extern block cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:80:5
Expand All @@ -373,6 +403,8 @@ error: extern block is not supported in `trait`s or `impl`s
|
LL | default extern "C" {}
| ^^^^^^^^^^^^^^^^^^
|
= help: consider moving the extern block out to a nearby module scope

error: an enum cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:83:5
Expand All @@ -387,6 +419,8 @@ error: enum is not supported in `trait`s or `impl`s
|
LL | default enum foo {}
| ^^^^^^^^^^^^^^^^
|
= help: consider moving the enum out to a nearby module scope

error: a struct cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:85:5
Expand All @@ -401,6 +435,8 @@ error: struct is not supported in `trait`s or `impl`s
|
LL | default struct foo {}
| ^^^^^^^^^^^^^^^^^^
|
= help: consider moving the struct out to a nearby module scope

error: a union cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:87:5
Expand All @@ -415,6 +451,8 @@ error: union is not supported in `trait`s or `impl`s
|
LL | default union foo {}
| ^^^^^^^^^^^^^^^^^
|
= help: consider moving the union out to a nearby module scope

error: a trait cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:89:5
Expand All @@ -429,6 +467,8 @@ error: trait is not supported in `trait`s or `impl`s
|
LL | default trait foo {}
| ^^^^^^^^^^^^^^^^^
|
= help: consider moving the trait out to a nearby module scope

error: a trait alias cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:91:5
Expand All @@ -443,12 +483,16 @@ error: trait alias is not supported in `trait`s or `impl`s
|
LL | default trait foo = Ord;
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider moving the trait alias out to a nearby module scope

error: implementation is not supported in `trait`s or `impl`s
--> $DIR/default-on-wrong-item-kind.rs:93:5
|
LL | default impl foo {}
| ^^^^^^^^^^^^^^^^
|
= help: consider moving the implementation out to a nearby module scope

error: an item macro invocation cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:97:5
Expand Down Expand Up @@ -479,6 +523,8 @@ error: macro definition is not supported in `trait`s or `impl`s
|
LL | default macro foo {}
| ^^^^^^^^^^^^^^^^^
|
= help: consider moving the macro definition out to a nearby module scope

error: a macro definition cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:101:5
Expand All @@ -493,6 +539,8 @@ error: macro definition is not supported in `trait`s or `impl`s
|
LL | default macro_rules! foo {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider moving the macro definition out to a nearby module scope

error: an extern crate cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:107:5
Expand All @@ -507,6 +555,8 @@ error: extern crate is not supported in `trait`s or `impl`s
|
LL | default extern crate foo;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider moving the extern crate out to a nearby module scope

error: a `use` import cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:109:5
Expand All @@ -521,6 +571,8 @@ error: `use` import is not supported in `trait`s or `impl`s
|
LL | default use foo;
| ^^^^^^^^^^^^^^^^
|
= help: consider moving the `use` import out to a nearby module scope

error: a static item cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:111:5
Expand Down Expand Up @@ -549,6 +601,8 @@ error: module is not supported in `trait`s or `impl`s
|
LL | default mod foo {}
| ^^^^^^^^^^^^^^^
|
= help: consider moving the module out to a nearby module scope

error: an extern block cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:117:5
Expand All @@ -563,6 +617,8 @@ error: extern block is not supported in `trait`s or `impl`s
|
LL | default extern "C" {}
| ^^^^^^^^^^^^^^^^^^
|
= help: consider moving the extern block out to a nearby module scope

error: an enum cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:120:5
Expand All @@ -577,6 +633,8 @@ error: enum is not supported in `trait`s or `impl`s
|
LL | default enum foo {}
| ^^^^^^^^^^^^^^^^
|
= help: consider moving the enum out to a nearby module scope

error: a struct cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:122:5
Expand All @@ -591,6 +649,8 @@ error: struct is not supported in `trait`s or `impl`s
|
LL | default struct foo {}
| ^^^^^^^^^^^^^^^^^^
|
= help: consider moving the struct out to a nearby module scope

error: a union cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:124:5
Expand All @@ -605,6 +665,8 @@ error: union is not supported in `trait`s or `impl`s
|
LL | default union foo {}
| ^^^^^^^^^^^^^^^^^
|
= help: consider moving the union out to a nearby module scope

error: a trait cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:126:5
Expand All @@ -619,6 +681,8 @@ error: trait is not supported in `trait`s or `impl`s
|
LL | default trait foo {}
| ^^^^^^^^^^^^^^^^^
|
= help: consider moving the trait out to a nearby module scope

error: a trait alias cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:128:5
Expand All @@ -633,12 +697,16 @@ error: trait alias is not supported in `trait`s or `impl`s
|
LL | default trait foo = Ord;
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider moving the trait alias out to a nearby module scope

error: implementation is not supported in `trait`s or `impl`s
--> $DIR/default-on-wrong-item-kind.rs:130:5
|
LL | default impl foo {}
| ^^^^^^^^^^^^^^^^
|
= help: consider moving the implementation out to a nearby module scope

error: an item macro invocation cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:134:5
Expand Down Expand Up @@ -669,6 +737,8 @@ error: macro definition is not supported in `trait`s or `impl`s
|
LL | default macro foo {}
| ^^^^^^^^^^^^^^^^^
|
= help: consider moving the macro definition out to a nearby module scope

error: a macro definition cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:138:5
Expand All @@ -683,6 +753,8 @@ error: macro definition is not supported in `trait`s or `impl`s
|
LL | default macro_rules! foo {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider moving the macro definition out to a nearby module scope

error: aborting due to 95 previous errors

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ error: struct is not supported in `trait`s or `impl`s
|
LL | struct BadS;
| ^^^^^^^^^^^^
|
= help: consider moving the struct out to a nearby module scope

error: enum is not supported in `trait`s or `impl`s
--> $DIR/issue-48137-macros-cannot-interpolate-impl-items-bad-variants.rs:5:9
Expand All @@ -13,13 +15,16 @@ LL | enum BadE {}
LL | expand_to_enum!();
| ------------------ in this macro invocation
|
= help: consider moving the enum out to a nearby module scope
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: struct is not supported in `trait`s or `impl`s
--> $DIR/issue-48137-macros-cannot-interpolate-impl-items-bad-variants.rs:31:5
|
LL | struct BadS;
| ^^^^^^^^^^^^
|
= help: consider moving the struct out to a nearby module scope

error: enum is not supported in `trait`s or `impl`s
--> $DIR/issue-48137-macros-cannot-interpolate-impl-items-bad-variants.rs:5:9
Expand All @@ -30,13 +35,16 @@ LL | enum BadE {}
LL | expand_to_enum!();
| ------------------ in this macro invocation
|
= help: consider moving the enum out to a nearby module scope
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: struct is not supported in `extern` blocks
--> $DIR/issue-48137-macros-cannot-interpolate-impl-items-bad-variants.rs:42:5
|
LL | struct BadS;
| ^^^^^^^^^^^^
|
= help: consider moving the struct out to a nearby module scope

error: enum is not supported in `extern` blocks
--> $DIR/issue-48137-macros-cannot-interpolate-impl-items-bad-variants.rs:5:9
Expand All @@ -47,6 +55,7 @@ LL | enum BadE {}
LL | expand_to_enum!();
| ------------------ in this macro invocation
|
= help: consider moving the enum out to a nearby module scope
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 6 previous errors
Expand Down
Loading

0 comments on commit ef43cde

Please sign in to comment.