Skip to content

use structured macro and path resolve suggestions #57635

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 19 additions & 5 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
@@ -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(_)) => {
@@ -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);
}
_ => {}
2 changes: 1 addition & 1 deletion src/test/ui/resolve/resolve-hint-macro.stderr
Original file line number Diff line number Diff line change
@@ -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

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
@@ -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
@@ -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
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
@@ -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