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:: {
5- self , AddAsNonDerive , CannotDetermineMacroResolution , CannotFindIdentInThisScope ,
6- MacroExpectedFound , RemoveSurroundingDerive ,
7- } ;
4+ use crate :: errors:: CannotDetermineMacroResolution ;
5+ use crate :: errors:: { self , AddAsNonDerive , CannotFindIdentInThisScope } ;
6+ use crate :: errors:: { MacroExpectedFound , RemoveSurroundingDerive } ;
87use crate :: Namespace :: * ;
98use crate :: { BuiltinMacroState , Determinacy , MacroData } ;
109use crate :: { DeriveData , Finalize , ParentScope , ResolutionError , Resolver , ScopeSet } ;
@@ -15,7 +14,7 @@ use rustc_ast_pretty::pprust;
1514use rustc_attr:: StabilityLevel ;
1615use rustc_data_structures:: intern:: Interned ;
1716use rustc_data_structures:: sync:: Lrc ;
18- use rustc_errors:: { codes:: * , struct_span_code_err, Applicability } ;
17+ use rustc_errors:: { codes:: * , struct_span_code_err, Applicability , StashKey } ;
1918use rustc_expand:: base:: { Annotatable , DeriveResolutions , Indeterminate , ResolverExpand } ;
2019use rustc_expand:: base:: { SyntaxExtension , SyntaxExtensionKind } ;
2120use rustc_expand:: compile_declarative_macro;
@@ -25,9 +24,8 @@ use rustc_hir::def_id::{CrateNum, DefId, LocalDefId};
2524use rustc_middle:: middle:: stability;
2625use rustc_middle:: ty:: RegisteredTools ;
2726use rustc_middle:: ty:: { TyCtxt , Visibility } ;
28- use rustc_session:: lint:: builtin:: {
29- LEGACY_DERIVE_HELPERS , SOFT_UNSTABLE , UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
30- } ;
27+ use rustc_session:: lint:: builtin:: UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ;
28+ use rustc_session:: lint:: builtin:: { LEGACY_DERIVE_HELPERS , SOFT_UNSTABLE } ;
3129use rustc_session:: lint:: builtin:: { UNUSED_MACROS , UNUSED_MACRO_RULES } ;
3230use rustc_session:: lint:: BuiltinLintDiagnostics ;
3331use rustc_session:: parse:: feature_err;
@@ -703,21 +701,21 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
703701 // situations should be reported as errors, so this is a bug.
704702 this. dcx ( ) . span_delayed_bug ( span, "inconsistent resolution for a macro" ) ;
705703 }
706- } else {
704+ } else if this . tcx . dcx ( ) . has_errors ( ) . is_none ( ) && this . privacy_errors . is_empty ( ) {
707705 // It's possible that the macro was unresolved (indeterminate) and silently
708706 // expanded into a dummy fragment for recovery during expansion.
709707 // Now, post-expansion, the resolution may succeed, but we can't change the
710708 // past and need to report an error.
711709 // However, non-speculative `resolve_path` can successfully return private items
712710 // 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- }
711+ // less informative error if no other error is reported elsewhere.
712+
713+ let err = this. dcx ( ) . create_err ( CannotDetermineMacroResolution {
714+ span,
715+ kind : kind. descr ( ) ,
716+ path : Segment :: names_to_string ( path) ,
717+ } ) ;
718+ err . stash ( span , StashKey :: UndeterminedMacroResolution ) ;
721719 }
722720 } ;
723721
0 commit comments