When giving a suggestion to use :: instead of . where the rhs is a macro giving a type,
make it also work when the rhs is a type alias, not just a struct.
This commit is contained in:
parent
bfde43c84b
commit
ae7b45a6d4
3 changed files with 137 additions and 4 deletions
|
@ -1529,7 +1529,7 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
true
|
true
|
||||||
} else if kind == DefKind::Struct
|
} else if matches!(kind, DefKind::Struct | DefKind::TyAlias)
|
||||||
&& let Some(lhs_source_span) = lhs_span.find_ancestor_inside(expr.span)
|
&& let Some(lhs_source_span) = lhs_span.find_ancestor_inside(expr.span)
|
||||||
&& let Ok(snippet) = this.r.tcx.sess.source_map().span_to_snippet(lhs_source_span)
|
&& let Ok(snippet) = this.r.tcx.sess.source_map().span_to_snippet(lhs_source_span)
|
||||||
{
|
{
|
||||||
|
|
|
@ -39,6 +39,12 @@ macro_rules! Type {
|
||||||
//~| ERROR expected value, found struct `std::cell::Cell`
|
//~| ERROR expected value, found struct `std::cell::Cell`
|
||||||
//~| ERROR expected value, found struct `std::cell::Cell`
|
//~| ERROR expected value, found struct `std::cell::Cell`
|
||||||
};
|
};
|
||||||
|
(alias) => {
|
||||||
|
Alias
|
||||||
|
//~^ ERROR expected value, found type alias `Alias`
|
||||||
|
//~| ERROR expected value, found type alias `Alias`
|
||||||
|
//~| ERROR expected value, found type alias `Alias`
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! create {
|
macro_rules! create {
|
||||||
|
@ -56,6 +62,32 @@ macro_rules! create {
|
||||||
Type!().new(0)
|
Type!().new(0)
|
||||||
//~^ HELP use the path separator
|
//~^ HELP use the path separator
|
||||||
};
|
};
|
||||||
|
(macro method alias) => {
|
||||||
|
Type!(alias).new(0)
|
||||||
|
//~^ HELP use the path separator
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! check_ty {
|
||||||
|
($Ty:ident) => {
|
||||||
|
$Ty.foo
|
||||||
|
//~^ ERROR expected value, found type alias `Alias`
|
||||||
|
//~| HELP use the path separator
|
||||||
|
};
|
||||||
|
}
|
||||||
|
macro_rules! check_ident {
|
||||||
|
($Ident:ident) => {
|
||||||
|
Alias.$Ident
|
||||||
|
//~^ ERROR expected value, found type alias `Alias`
|
||||||
|
//~| HELP use the path separator
|
||||||
|
};
|
||||||
|
}
|
||||||
|
macro_rules! check_ty_ident {
|
||||||
|
($Ty:ident, $Ident:ident) => {
|
||||||
|
$Ty.$Ident
|
||||||
|
//~^ ERROR expected value, found type alias `Alias`
|
||||||
|
//~| HELP use the path separator
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interaction_with_macros() {
|
fn interaction_with_macros() {
|
||||||
|
@ -70,6 +102,12 @@ fn interaction_with_macros() {
|
||||||
Type! {}.get;
|
Type! {}.get;
|
||||||
//~^ HELP use the path separator
|
//~^ HELP use the path separator
|
||||||
|
|
||||||
|
Type!(alias).get();
|
||||||
|
//~^ HELP use the path separator
|
||||||
|
|
||||||
|
Type! {alias}.get;
|
||||||
|
//~^ HELP use the path separator
|
||||||
|
|
||||||
//
|
//
|
||||||
// Ensure that the suggestion is shown for expressions inside of macro definitions.
|
// Ensure that the suggestion is shown for expressions inside of macro definitions.
|
||||||
//
|
//
|
||||||
|
@ -77,4 +115,9 @@ fn interaction_with_macros() {
|
||||||
let _ = create!(type method);
|
let _ = create!(type method);
|
||||||
let _ = create!(type field);
|
let _ = create!(type field);
|
||||||
let _ = create!(macro method);
|
let _ = create!(macro method);
|
||||||
|
let _ = create!(macro method alias);
|
||||||
|
|
||||||
|
let _ = check_ty!(Alias);
|
||||||
|
let _ = check_ident!(foo);
|
||||||
|
let _ = check_ty_ident!(Alias, foo);
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,8 +99,38 @@ LL - Type! {}.get;
|
||||||
LL + <Type! {}>::get;
|
LL + <Type! {}>::get;
|
||||||
|
|
|
|
||||||
|
|
||||||
|
error[E0423]: expected value, found type alias `Alias`
|
||||||
|
--> $DIR/dot-notation-type-namespace-suggest-path-sep.rs:43:9
|
||||||
|
|
|
||||||
|
LL | Alias
|
||||||
|
| ^^^^^
|
||||||
|
...
|
||||||
|
LL | Type!(alias).get();
|
||||||
|
| ------------ in this macro invocation
|
||||||
|
|
|
||||||
|
= note: this error originates in the macro `Type` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
help: use the path separator to refer to an item
|
||||||
|
|
|
||||||
|
LL | <Type!(alias)>::get();
|
||||||
|
| ~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
error[E0423]: expected value, found type alias `Alias`
|
||||||
|
--> $DIR/dot-notation-type-namespace-suggest-path-sep.rs:43:9
|
||||||
|
|
|
||||||
|
LL | Alias
|
||||||
|
| ^^^^^
|
||||||
|
...
|
||||||
|
LL | Type! {alias}.get;
|
||||||
|
| ------------- in this macro invocation
|
||||||
|
|
|
||||||
|
= note: this error originates in the macro `Type` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
help: use the path separator to refer to an item
|
||||||
|
|
|
||||||
|
LL | <Type! {alias}>::get;
|
||||||
|
| ~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
error[E0423]: expected value, found struct `Vec`
|
error[E0423]: expected value, found struct `Vec`
|
||||||
--> $DIR/dot-notation-type-namespace-suggest-path-sep.rs:46:9
|
--> $DIR/dot-notation-type-namespace-suggest-path-sep.rs:52:9
|
||||||
|
|
|
|
||||||
LL | Vec.new()
|
LL | Vec.new()
|
||||||
| ^^^
|
| ^^^
|
||||||
|
@ -116,7 +146,7 @@ LL + Vec::new()
|
||||||
|
|
|
|
||||||
|
|
||||||
error[E0423]: expected value, found struct `Vec`
|
error[E0423]: expected value, found struct `Vec`
|
||||||
--> $DIR/dot-notation-type-namespace-suggest-path-sep.rs:51:9
|
--> $DIR/dot-notation-type-namespace-suggest-path-sep.rs:57:9
|
||||||
|
|
|
|
||||||
LL | Vec.new
|
LL | Vec.new
|
||||||
| ^^^
|
| ^^^
|
||||||
|
@ -147,6 +177,66 @@ LL - Type!().new(0)
|
||||||
LL + <Type!()>::new(0)
|
LL + <Type!()>::new(0)
|
||||||
|
|
|
|
||||||
|
|
||||||
error: aborting due to 11 previous errors
|
error[E0423]: expected value, found type alias `Alias`
|
||||||
|
--> $DIR/dot-notation-type-namespace-suggest-path-sep.rs:43:9
|
||||||
|
|
|
||||||
|
LL | Alias
|
||||||
|
| ^^^^^
|
||||||
|
...
|
||||||
|
LL | let _ = create!(macro method alias);
|
||||||
|
| --------------------------- in this macro invocation
|
||||||
|
|
|
||||||
|
= note: this error originates in the macro `Type` which comes from the expansion of the macro `create` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
help: use the path separator to refer to an item
|
||||||
|
|
|
||||||
|
LL | <Type!(alias)>::new(0)
|
||||||
|
| ~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
error[E0423]: expected value, found type alias `Alias`
|
||||||
|
--> $DIR/dot-notation-type-namespace-suggest-path-sep.rs:73:9
|
||||||
|
|
|
||||||
|
LL | $Ty.foo
|
||||||
|
| ^^^
|
||||||
|
...
|
||||||
|
LL | let _ = check_ty!(Alias);
|
||||||
|
| ---------------- in this macro invocation
|
||||||
|
|
|
||||||
|
= note: this error originates in the macro `check_ty` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
help: use the path separator to refer to an item
|
||||||
|
|
|
||||||
|
LL | $Ty::foo
|
||||||
|
| ~~
|
||||||
|
|
||||||
|
error[E0423]: expected value, found type alias `Alias`
|
||||||
|
--> $DIR/dot-notation-type-namespace-suggest-path-sep.rs:80:9
|
||||||
|
|
|
||||||
|
LL | Alias.$Ident
|
||||||
|
| ^^^^^
|
||||||
|
...
|
||||||
|
LL | let _ = check_ident!(foo);
|
||||||
|
| ----------------- in this macro invocation
|
||||||
|
|
|
||||||
|
= note: this error originates in the macro `check_ident` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
help: use the path separator to refer to an item
|
||||||
|
|
|
||||||
|
LL | <Alias>::$Ident
|
||||||
|
| ~~~~~~~~~
|
||||||
|
|
||||||
|
error[E0423]: expected value, found type alias `Alias`
|
||||||
|
--> $DIR/dot-notation-type-namespace-suggest-path-sep.rs:87:9
|
||||||
|
|
|
||||||
|
LL | $Ty.$Ident
|
||||||
|
| ^^^
|
||||||
|
...
|
||||||
|
LL | let _ = check_ty_ident!(Alias, foo);
|
||||||
|
| --------------------------- in this macro invocation
|
||||||
|
|
|
||||||
|
= note: this error originates in the macro `check_ty_ident` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||||
|
help: use the path separator to refer to an item
|
||||||
|
|
|
||||||
|
LL | <$Ty>::$Ident
|
||||||
|
| ~~~~~~~
|
||||||
|
|
||||||
|
error: aborting due to 17 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0423`.
|
For more information about this error, try `rustc --explain E0423`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue