@@ -192,7 +192,14 @@ impl<'a> base::Resolver for Resolver<'a> {
192192 } ;
193193
194194 let parent_scope = self . invoc_parent_scope ( invoc_id, derives_in_scope) ;
195- let ( def, ext) = self . resolve_macro_to_def ( path, kind, & parent_scope, true , force) ?;
195+ let ( def, ext) = match self . resolve_macro_to_def ( path, kind, & parent_scope, true , force) {
196+ Ok ( ( def, ext) ) => ( def, ext) ,
197+ Err ( Determinacy :: Determined ) if kind == MacroKind :: Attr => {
198+ // Replace unresolved attributes with used inert attributes for better recovery.
199+ return Ok ( Some ( self . get_macro ( Def :: NonMacroAttr ( NonMacroAttrKind :: Tool ) ) ) ) ;
200+ }
201+ Err ( determinacy) => return Err ( determinacy) ,
202+ } ;
196203
197204 if let Def :: Macro ( def_id, _) = def {
198205 if after_derive {
@@ -347,7 +354,6 @@ impl<'a> Resolver<'a> {
347354 }
348355 PathResult :: Indeterminate if !force => return Err ( Determinacy :: Undetermined ) ,
349356 PathResult :: NonModule ( ..) | PathResult :: Indeterminate | PathResult :: Failed ( ..) => {
350- self . found_unresolved_macro = true ;
351357 Err ( Determinacy :: Determined )
352358 }
353359 PathResult :: Module ( ..) => unreachable ! ( ) ,
@@ -363,10 +369,8 @@ impl<'a> Resolver<'a> {
363369 let binding = self . early_resolve_ident_in_lexical_scope (
364370 path[ 0 ] . ident , ScopeSet :: Macro ( kind) , parent_scope, false , force, path_span
365371 ) ;
366- match binding {
367- Ok ( ..) => { }
368- Err ( Determinacy :: Determined ) => self . found_unresolved_macro = true ,
369- Err ( Determinacy :: Undetermined ) => return Err ( Determinacy :: Undetermined ) ,
372+ if let Err ( Determinacy :: Undetermined ) = binding {
373+ return Err ( Determinacy :: Undetermined ) ;
370374 }
371375
372376 if trace {
@@ -868,14 +872,23 @@ impl<'a> Resolver<'a> {
868872 pub fn finalize_current_module_macro_resolutions ( & mut self ) {
869873 let module = self . current_module ;
870874
871- let check_consistency = |this : & mut Self , path : & [ Segment ] , span,
872- kind : MacroKind , initial_def , def| {
875+ let check_consistency = |this : & mut Self , path : & [ Segment ] , span, kind : MacroKind ,
876+ initial_def : Option < Def > , def : Def | {
873877 if let Some ( initial_def) = initial_def {
874878 if def != initial_def && def != Def :: Err && this. ambiguity_errors . is_empty ( ) {
875879 // Make sure compilation does not succeed if preferred macro resolution
876880 // has changed after the macro had been expanded. In theory all such
877881 // situations should be reported as ambiguity errors, so this is a bug.
878- span_bug ! ( span, "inconsistent resolution for a macro" ) ;
882+ if initial_def == Def :: NonMacroAttr ( NonMacroAttrKind :: Custom ) {
883+ // Yeah, legacy custom attributes are implemented using forced resolution
884+ // (which is a best effort error recovery tool, basically), so we can't
885+ // promise their resolution won't change later.
886+ let msg = format ! ( "inconsistent resolution for a macro: first {}, then {}" ,
887+ initial_def. kind_name( ) , def. kind_name( ) ) ;
888+ this. session . span_err ( span, & msg) ;
889+ } else {
890+ span_bug ! ( span, "inconsistent resolution for a macro" ) ;
891+ }
879892 }
880893 } else {
881894 // It's possible that the macro was unresolved (indeterminate) and silently
0 commit comments