11//! A bunch of methods and structures more or less related to resolving macros and
22//! interface provided by `Resolver` to macro expander.
33
4+ use crate :: errors:: CannotDetermineMacroResolution ;
45use crate :: errors:: {
5- self , AddAsNonDerive , CannotDetermineMacroResolution , CannotFindIdentInThisScope ,
6- MacroExpectedFound , RemoveSurroundingDerive ,
6+ self , AddAsNonDerive , CannotFindIdentInThisScope , MacroExpectedFound , RemoveSurroundingDerive ,
77} ;
88use crate :: Namespace :: * ;
99use crate :: { BuiltinMacroState , Determinacy , MacroData } ;
@@ -15,6 +15,7 @@ use rustc_ast_pretty::pprust;
1515use rustc_attr:: StabilityLevel ;
1616use rustc_data_structures:: intern:: Interned ;
1717use rustc_data_structures:: sync:: Lrc ;
18+ use rustc_errors:: StashKey :: MacroResolutionError ;
1819use rustc_errors:: { struct_span_code_err, Applicability } ;
1920use rustc_expand:: base:: { Annotatable , DeriveResolutions , Indeterminate , ResolverExpand } ;
2021use rustc_expand:: base:: { SyntaxExtension , SyntaxExtensionKind } ;
@@ -703,21 +704,21 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
703704 // situations should be reported as errors, so this is a bug.
704705 this. dcx ( ) . span_delayed_bug ( span, "inconsistent resolution for a macro" ) ;
705706 }
706- } else {
707+ } else if this . tcx . dcx ( ) . has_errors ( ) . is_none ( ) && this . privacy_errors . is_empty ( ) {
707708 // It's possible that the macro was unresolved (indeterminate) and silently
708709 // expanded into a dummy fragment for recovery during expansion.
709710 // Now, post-expansion, the resolution may succeed, but we can't change the
710711 // past and need to report an error.
711712 // However, non-speculative `resolve_path` can successfully return private items
712713 // even if speculative `resolve_path` returned nothing previously, so we skip this
713- // less informative error if the privacy error is reported elsewhere.
714- if this . privacy_errors . is_empty ( ) {
715- this. dcx ( ) . emit_err ( CannotDetermineMacroResolution {
716- span,
717- kind : kind. descr ( ) ,
718- path : Segment :: names_to_string ( path) ,
719- } ) ;
720- }
714+ // less informative error if no other error is reported elsewhere.
715+
716+ let err = this. dcx ( ) . create_err ( CannotDetermineMacroResolution {
717+ span,
718+ kind : kind. descr ( ) ,
719+ path : Segment :: names_to_string ( path) ,
720+ } ) ;
721+ err . stash ( span , MacroResolutionError ) ;
721722 }
722723 } ;
723724
0 commit comments