Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 098cdf4

Browse files
authoredJan 18, 2019
Rollup merge of rust-lang#57635 - euclio:path-separators, r=michaelwoerister
use structured macro and path resolve suggestions
2 parents f5d9721 + 93b5536 commit 098cdf4

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
@@ -3318,7 +3318,12 @@ impl<'a> Resolver<'a> {
33183318
if let Some(def) = def {
33193319
match (def, source) {
33203320
(Def::Macro(..), _) => {
3321-
err.span_label(span, format!("did you mean `{}!(...)`?", path_str));
3321+
err.span_suggestion_with_applicability(
3322+
span,
3323+
"use `!` to invoke the macro",
3324+
format!("{}!", path_str),
3325+
Applicability::MaybeIncorrect,
3326+
);
33223327
return (err, candidates);
33233328
}
33243329
(Def::TyAlias(..), PathSource::Trait(_)) => {
@@ -3330,13 +3335,22 @@ impl<'a> Resolver<'a> {
33303335
}
33313336
(Def::Mod(..), PathSource::Expr(Some(parent))) => match parent.node {
33323337
ExprKind::Field(_, ident) => {
3333-
err.span_label(parent.span, format!("did you mean `{}::{}`?",
3334-
path_str, ident));
3338+
err.span_suggestion_with_applicability(
3339+
parent.span,
3340+
"use the path separator to refer to an item",
3341+
format!("{}::{}", path_str, ident),
3342+
Applicability::MaybeIncorrect,
3343+
);
33353344
return (err, candidates);
33363345
}
33373346
ExprKind::MethodCall(ref segment, ..) => {
3338-
err.span_label(parent.span, format!("did you mean `{}::{}(...)`?",
3339-
path_str, segment.ident));
3347+
let span = parent.span.with_hi(segment.ident.span.hi());
3348+
err.span_suggestion_with_applicability(
3349+
span,
3350+
"use the path separator to refer to an item",
3351+
format!("{}::{}", path_str, segment.ident),
3352+
Applicability::MaybeIncorrect,
3353+
);
33403354
return (err, candidates);
33413355
}
33423356
_ => {}

‎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)
Please sign in to comment.