Skip to content

Commit 93b5536

Browse files
committed
use structured macro and path resolve suggestions
1 parent 9201924 commit 93b5536

File tree

4 files changed

+44
-20
lines changed

4 files changed

+44
-20
lines changed

src/librustc_resolve/lib.rs

+19-5
Original file line numberDiff line numberDiff line change
@@ -3321,7 +3321,12 @@ impl<'a> Resolver<'a> {
33213321
if let Some(def) = def {
33223322
match (def, source) {
33233323
(Def::Macro(..), _) => {
3324-
err.span_label(span, format!("did you mean `{}!(...)`?", path_str));
3324+
err.span_suggestion_with_applicability(
3325+
span,
3326+
"use `!` to invoke the macro",
3327+
format!("{}!", path_str),
3328+
Applicability::MaybeIncorrect,
3329+
);
33253330
return (err, candidates);
33263331
}
33273332
(Def::TyAlias(..), PathSource::Trait(_)) => {
@@ -3333,13 +3338,22 @@ impl<'a> Resolver<'a> {
33333338
}
33343339
(Def::Mod(..), PathSource::Expr(Some(parent))) => match parent.node {
33353340
ExprKind::Field(_, ident) => {
3336-
err.span_label(parent.span, format!("did you mean `{}::{}`?",
3337-
path_str, ident));
3341+
err.span_suggestion_with_applicability(
3342+
parent.span,
3343+
"use the path separator to refer to an item",
3344+
format!("{}::{}", path_str, ident),
3345+
Applicability::MaybeIncorrect,
3346+
);
33383347
return (err, candidates);
33393348
}
33403349
ExprKind::MethodCall(ref segment, ..) => {
3341-
err.span_label(parent.span, format!("did you mean `{}::{}(...)`?",
3342-
path_str, segment.ident));
3350+
let span = parent.span.with_hi(segment.ident.span.hi());
3351+
err.span_suggestion_with_applicability(
3352+
span,
3353+
"use the path separator to refer to an item",
3354+
format!("{}::{}", path_str, segment.ident),
3355+
Applicability::MaybeIncorrect,
3356+
);
33433357
return (err, candidates);
33443358
}
33453359
_ => {}

src/test/ui/resolve/resolve-hint-macro.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0423]: expected function, found macro `assert`
22
--> $DIR/resolve-hint-macro.rs:2:5
33
|
44
LL | assert(true);
5-
| ^^^^^^ did you mean `assert!(...)`?
5+
| ^^^^^^ help: use `!` to invoke the macro: `assert!`
66

77
error: aborting due to previous error
88

src/test/ui/resolve/suggest-path-instead-of-mod-dot-item.stderr

+23-13
Original file line numberDiff line numberDiff line change
@@ -4,40 +4,45 @@ error[E0423]: expected value, found module `a`
44
LL | a.I
55
| ^--
66
| |
7-
| did you mean `a::I`?
7+
| help: use the path separator to refer to an item: `a::I`
88

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

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

2525
error[E0423]: expected value, found module `a::b`
2626
--> $DIR/suggest-path-instead-of-mod-dot-item.rs:32:5
2727
|
2828
LL | a::b.J
29-
| ^^^---
30-
| | |
31-
| | help: a constant with a similar name exists: `I`
32-
| did you mean `a::b::J`?
29+
| ^^^^
30+
help: a constant with a similar name exists
31+
|
32+
LL | a::I.J
33+
| ^
34+
help: use the path separator to refer to an item
35+
|
36+
LL | a::b::J
37+
|
3338

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

4247
error[E0423]: expected value, found module `a::b`
4348
--> $DIR/suggest-path-instead-of-mod-dot-item.rs:40:12
@@ -51,10 +56,15 @@ error[E0423]: expected value, found module `a::b`
5156
--> $DIR/suggest-path-instead-of-mod-dot-item.rs:45:5
5257
|
5358
LL | a::b.f()
54-
| ^^^-----
55-
| | |
56-
| | help: a constant with a similar name exists: `I`
57-
| did you mean `a::b::f(...)`?
59+
| ^^^^
60+
help: a constant with a similar name exists
61+
|
62+
LL | a::I.f()
63+
| ^
64+
help: use the path separator to refer to an item
65+
|
66+
LL | a::b::f()
67+
| ^^^^^^^
5868

5969
error[E0423]: expected value, found module `a::b`
6070
--> $DIR/suggest-path-instead-of-mod-dot-item.rs:50:5

src/test/ui/try-block/try-block-in-edition2015.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ error[E0574]: expected struct, variant or union type, found macro `try`
1515
--> $DIR/try-block-in-edition2015.rs:4:33
1616
|
1717
LL | let try_result: Option<_> = try {
18-
| ^^^ did you mean `try!(...)`?
18+
| ^^^ help: use `!` to invoke the macro: `try!`
1919

2020
error: aborting due to 2 previous errors
2121

0 commit comments

Comments
 (0)