Skip to content

Commit

Permalink
use structured macro and path resolve suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
euclio committed Jan 15, 2019
1 parent 9201924 commit 93b5536
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 20 deletions.
24 changes: 19 additions & 5 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3321,7 +3321,12 @@ impl<'a> Resolver<'a> {
if let Some(def) = def {
match (def, source) {
(Def::Macro(..), _) => {
err.span_label(span, format!("did you mean `{}!(...)`?", path_str));
err.span_suggestion_with_applicability(
span,
"use `!` to invoke the macro",
format!("{}!", path_str),
Applicability::MaybeIncorrect,
);
return (err, candidates);
}
(Def::TyAlias(..), PathSource::Trait(_)) => {
Expand All @@ -3333,13 +3338,22 @@ impl<'a> Resolver<'a> {
}
(Def::Mod(..), PathSource::Expr(Some(parent))) => match parent.node {
ExprKind::Field(_, ident) => {
err.span_label(parent.span, format!("did you mean `{}::{}`?",
path_str, ident));
err.span_suggestion_with_applicability(
parent.span,
"use the path separator to refer to an item",
format!("{}::{}", path_str, ident),
Applicability::MaybeIncorrect,
);
return (err, candidates);
}
ExprKind::MethodCall(ref segment, ..) => {
err.span_label(parent.span, format!("did you mean `{}::{}(...)`?",
path_str, segment.ident));
let span = parent.span.with_hi(segment.ident.span.hi());
err.span_suggestion_with_applicability(
span,
"use the path separator to refer to an item",
format!("{}::{}", path_str, segment.ident),
Applicability::MaybeIncorrect,
);
return (err, candidates);
}
_ => {}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/resolve/resolve-hint-macro.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0423]: expected function, found macro `assert`
--> $DIR/resolve-hint-macro.rs:2:5
|
LL | assert(true);
| ^^^^^^ did you mean `assert!(...)`?
| ^^^^^^ help: use `!` to invoke the macro: `assert!`

error: aborting due to previous error

Expand Down
36 changes: 23 additions & 13 deletions src/test/ui/resolve/suggest-path-instead-of-mod-dot-item.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,45 @@ error[E0423]: expected value, found module `a`
LL | a.I
| ^--
| |
| did you mean `a::I`?
| help: use the path separator to refer to an item: `a::I`

error[E0423]: expected value, found module `a`
--> $DIR/suggest-path-instead-of-mod-dot-item.rs:22:5
|
LL | a.g()
| ^----
| ^--
| |
| did you mean `a::g(...)`?
| help: use the path separator to refer to an item: `a::g`

error[E0423]: expected value, found module `a`
--> $DIR/suggest-path-instead-of-mod-dot-item.rs:27:5
|
LL | a.b.J
| ^--
| |
| did you mean `a::b`?
| help: use the path separator to refer to an item: `a::b`

error[E0423]: expected value, found module `a::b`
--> $DIR/suggest-path-instead-of-mod-dot-item.rs:32:5
|
LL | a::b.J
| ^^^---
| | |
| | help: a constant with a similar name exists: `I`
| did you mean `a::b::J`?
| ^^^^
help: a constant with a similar name exists
|
LL | a::I.J
| ^
help: use the path separator to refer to an item
|
LL | a::b::J
|

error[E0423]: expected value, found module `a`
--> $DIR/suggest-path-instead-of-mod-dot-item.rs:37:5
|
LL | a.b.f();
| ^--
| |
| did you mean `a::b`?
| help: use the path separator to refer to an item: `a::b`

error[E0423]: expected value, found module `a::b`
--> $DIR/suggest-path-instead-of-mod-dot-item.rs:40:12
Expand All @@ -51,10 +56,15 @@ error[E0423]: expected value, found module `a::b`
--> $DIR/suggest-path-instead-of-mod-dot-item.rs:45:5
|
LL | a::b.f()
| ^^^-----
| | |
| | help: a constant with a similar name exists: `I`
| did you mean `a::b::f(...)`?
| ^^^^
help: a constant with a similar name exists
|
LL | a::I.f()
| ^
help: use the path separator to refer to an item
|
LL | a::b::f()
| ^^^^^^^

error[E0423]: expected value, found module `a::b`
--> $DIR/suggest-path-instead-of-mod-dot-item.rs:50:5
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/try-block/try-block-in-edition2015.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ error[E0574]: expected struct, variant or union type, found macro `try`
--> $DIR/try-block-in-edition2015.rs:4:33
|
LL | let try_result: Option<_> = try {
| ^^^ did you mean `try!(...)`?
| ^^^ help: use `!` to invoke the macro: `try!`

error: aborting due to 2 previous errors

Expand Down

0 comments on commit 93b5536

Please sign in to comment.