@@ -12,7 +12,7 @@ use rustc_attr::StabilityLevel;
12
12
use rustc_data_structures:: fx:: FxHashSet ;
13
13
use rustc_data_structures:: intern:: Interned ;
14
14
use rustc_data_structures:: sync:: Lrc ;
15
- use rustc_errors:: struct_span_err;
15
+ use rustc_errors:: { struct_span_err, Applicability } ;
16
16
use rustc_expand:: base:: { Annotatable , DeriveResolutions , Indeterminate , ResolverExpand } ;
17
17
use rustc_expand:: base:: { SyntaxExtension , SyntaxExtensionKind } ;
18
18
use rustc_expand:: compile_declarative_macro;
@@ -694,7 +694,19 @@ impl<'a> Resolver<'a> {
694
694
check_consistency ( self , & path, path_span, kind, initial_res, res)
695
695
}
696
696
path_res @ PathResult :: NonModule ( ..) | path_res @ PathResult :: Failed { .. } => {
697
+ let mut suggestion = None ;
697
698
let ( span, label) = if let PathResult :: Failed { span, label, .. } = path_res {
699
+ // try to suggest if it's not a macro, maybe a function
700
+ if let PathResult :: NonModule ( partial_res) = self . maybe_resolve_path ( & path, Some ( ValueNS ) , & parent_scope)
701
+ && partial_res. unresolved_segments ( ) == 0 {
702
+ let sm = self . session . source_map ( ) ;
703
+ let exclamation_span = sm. next_point ( span) ;
704
+ suggestion = Some ( (
705
+ vec ! [ ( exclamation_span, "" . to_string( ) ) ] ,
706
+ format ! ( "{} is not a macro, but a {}, try to remove `!`" , Segment :: names_to_string( & path) , partial_res. base_res( ) . descr( ) ) ,
707
+ Applicability :: MaybeIncorrect
708
+ ) ) ;
709
+ }
698
710
( span, label)
699
711
} else {
700
712
(
@@ -708,7 +720,7 @@ impl<'a> Resolver<'a> {
708
720
} ;
709
721
self . report_error (
710
722
span,
711
- ResolutionError :: FailedToResolve { label, suggestion : None } ,
723
+ ResolutionError :: FailedToResolve { label, suggestion } ,
712
724
) ;
713
725
}
714
726
PathResult :: Module ( ..) | PathResult :: Indeterminate => unreachable ! ( ) ,
0 commit comments