@@ -182,7 +182,14 @@ impl<'a> base::Resolver for Resolver<'a> {
182182 } ;
183183
184184 let parent_scope = self . invoc_parent_scope ( invoc_id, derives_in_scope) ;
185- let ( def, ext) = self . resolve_macro_to_def ( path, kind, & parent_scope, true , force) ?;
185+ let ( def, ext) = match self . resolve_macro_to_def ( path, kind, & parent_scope, true , force) {
186+ Ok ( ( def, ext) ) => ( def, ext) ,
187+ Err ( Determinacy :: Determined ) if kind == MacroKind :: Attr => {
188+ // Replace unresolved attributes with used inert attributes for better recovery.
189+ return Ok ( Some ( self . get_macro ( Def :: NonMacroAttr ( NonMacroAttrKind :: Tool ) ) ) ) ;
190+ }
191+ Err ( determinacy) => return Err ( determinacy) ,
192+ } ;
186193
187194 if let Def :: Macro ( def_id, _) = def {
188195 if after_derive {
@@ -337,7 +344,6 @@ impl<'a> Resolver<'a> {
337344 }
338345 PathResult :: Indeterminate if !force => return Err ( Determinacy :: Undetermined ) ,
339346 PathResult :: NonModule ( ..) | PathResult :: Indeterminate | PathResult :: Failed ( ..) => {
340- self . found_unresolved_macro = true ;
341347 Err ( Determinacy :: Determined )
342348 }
343349 PathResult :: Module ( ..) => unreachable ! ( ) ,
@@ -353,10 +359,8 @@ impl<'a> Resolver<'a> {
353359 let binding = self . early_resolve_ident_in_lexical_scope (
354360 path[ 0 ] . ident , ScopeSet :: Macro ( kind) , parent_scope, false , force, path_span
355361 ) ;
356- match binding {
357- Ok ( ..) => { }
358- Err ( Determinacy :: Determined ) => self . found_unresolved_macro = true ,
359- Err ( Determinacy :: Undetermined ) => return Err ( Determinacy :: Undetermined ) ,
362+ if let Err ( Determinacy :: Undetermined ) = binding {
363+ return Err ( Determinacy :: Undetermined ) ;
360364 }
361365
362366 if trace {
@@ -858,14 +862,23 @@ impl<'a> Resolver<'a> {
858862 pub fn finalize_current_module_macro_resolutions ( & mut self ) {
859863 let module = self . current_module ;
860864
861- let check_consistency = |this : & mut Self , path : & [ Segment ] , span,
862- kind : MacroKind , initial_def , def| {
865+ let check_consistency = |this : & mut Self , path : & [ Segment ] , span, kind : MacroKind ,
866+ initial_def : Option < Def > , def : Def | {
863867 if let Some ( initial_def) = initial_def {
864868 if def != initial_def && def != Def :: Err && this. ambiguity_errors . is_empty ( ) {
865869 // Make sure compilation does not succeed if preferred macro resolution
866870 // has changed after the macro had been expanded. In theory all such
867871 // situations should be reported as ambiguity errors, so this is a bug.
868- span_bug ! ( span, "inconsistent resolution for a macro" ) ;
872+ if initial_def == Def :: NonMacroAttr ( NonMacroAttrKind :: Custom ) {
873+ // Yeah, legacy custom attributes are implemented using forced resolution
874+ // (which is a best effort error recovery tool, basically), so we can't
875+ // promise their resolution won't change later.
876+ let msg = format ! ( "inconsistent resolution for a macro: first {}, then {}" ,
877+ initial_def. kind_name( ) , def. kind_name( ) ) ;
878+ this. session . span_err ( span, & msg) ;
879+ } else {
880+ span_bug ! ( span, "inconsistent resolution for a macro" ) ;
881+ }
869882 }
870883 } else {
871884 // It's possible that the macro was unresolved (indeterminate) and silently
0 commit comments