1- use crate :: { AmbiguityError , AmbiguityKind , AmbiguityErrorMisc } ;
1+ use crate :: { AmbiguityError , AmbiguityKind , AmbiguityErrorMisc , Determinacy } ;
22use crate :: { CrateLint , Resolver , ResolutionError , ScopeSet , Weak } ;
33use crate :: { Module , ModuleKind , NameBinding , NameBindingKind , PathResult , Segment , ToNameBinding } ;
44use crate :: { is_known_tool, resolve_error} ;
@@ -14,7 +14,7 @@ use rustc::{ty, lint, span_bug};
1414use syntax:: ast:: { self , Ident , ItemKind } ;
1515use syntax:: attr:: { self , StabilityLevel } ;
1616use syntax:: errors:: DiagnosticBuilder ;
17- use syntax:: ext:: base:: { self , Determinacy } ;
17+ use syntax:: ext:: base:: { self , Indeterminate } ;
1818use syntax:: ext:: base:: { MacroKind , SyntaxExtension } ;
1919use syntax:: ext:: expand:: { AstFragment , Invocation , InvocationKind } ;
2020use syntax:: ext:: hygiene:: { self , Mark } ;
@@ -216,7 +216,7 @@ impl<'a> base::Resolver for Resolver<'a> {
216216 }
217217
218218 fn resolve_macro_invocation ( & mut self , invoc : & Invocation , invoc_id : Mark , force : bool )
219- -> Result < Option < Lrc < SyntaxExtension > > , Determinacy > {
219+ -> Result < Option < Lrc < SyntaxExtension > > , Indeterminate > {
220220 let ( path, kind, derives_in_scope, after_derive) = match invoc. kind {
221221 InvocationKind :: Attr { attr : None , .. } =>
222222 return Ok ( None ) ,
@@ -229,12 +229,7 @@ impl<'a> base::Resolver for Resolver<'a> {
229229 } ;
230230
231231 let parent_scope = self . invoc_parent_scope ( invoc_id, derives_in_scope) ;
232- let ( res, ext) = match self . resolve_macro_to_res ( path, kind, & parent_scope, true , force) {
233- Ok ( ( res, ext) ) => ( res, ext) ,
234- // Return dummy syntax extensions for unresolved macros for better recovery.
235- Err ( Determinacy :: Determined ) => ( Res :: Err , self . dummy_ext ( kind) ) ,
236- Err ( Determinacy :: Undetermined ) => return Err ( Determinacy :: Undetermined ) ,
237- } ;
232+ let ( res, ext) = self . resolve_macro_to_res ( path, kind, & parent_scope, true , force) ?;
238233
239234 let span = invoc. span ( ) ;
240235 let descr = fast_print_path ( path) ;
@@ -287,7 +282,7 @@ impl<'a> Resolver<'a> {
287282 parent_scope : & ParentScope < ' a > ,
288283 trace : bool ,
289284 force : bool ,
290- ) -> Result < ( Res , Lrc < SyntaxExtension > ) , Determinacy > {
285+ ) -> Result < ( Res , Lrc < SyntaxExtension > ) , Indeterminate > {
291286 let res = self . resolve_macro_to_res_inner ( path, kind, parent_scope, trace, force) ;
292287
293288 // Report errors and enforce feature gates for the resolved macro.
@@ -313,7 +308,14 @@ impl<'a> Resolver<'a> {
313308 }
314309 }
315310
316- let res = res?;
311+ let res = match res {
312+ Err ( Determinacy :: Undetermined ) => return Err ( Indeterminate ) ,
313+ Ok ( Res :: Err ) | Err ( Determinacy :: Determined ) => {
314+ // Return dummy syntax extensions for unresolved macros for better recovery.
315+ return Ok ( ( Res :: Err , self . dummy_ext ( kind) ) ) ;
316+ }
317+ Ok ( res) => res,
318+ } ;
317319
318320 match res {
319321 Res :: Def ( DefKind :: Macro ( _) , def_id) => {
@@ -328,35 +330,23 @@ impl<'a> Resolver<'a> {
328330 }
329331 }
330332 Res :: NonMacroAttr ( attr_kind) => {
331- if kind == MacroKind :: Attr {
332- if attr_kind == NonMacroAttrKind :: Custom {
333- assert ! ( path. segments. len( ) == 1 ) ;
334- if !features. custom_attribute {
335- let msg = format ! ( "The attribute `{}` is currently unknown to the \
336- compiler and may have meaning added to it in the \
337- future", path) ;
338- self . report_unknown_attribute (
339- path. span ,
340- & path. segments [ 0 ] . ident . as_str ( ) ,
341- & msg,
342- sym:: custom_attribute,
343- ) ;
344- }
333+ if attr_kind == NonMacroAttrKind :: Custom {
334+ assert ! ( path. segments. len( ) == 1 ) ;
335+ if !features. custom_attribute {
336+ let msg = format ! ( "The attribute `{}` is currently unknown to the \
337+ compiler and may have meaning added to it in the \
338+ future", path) ;
339+ self . report_unknown_attribute (
340+ path. span ,
341+ & path. segments [ 0 ] . ident . as_str ( ) ,
342+ & msg,
343+ sym:: custom_attribute,
344+ ) ;
345345 }
346- } else {
347- // Not only attributes, but anything in macro namespace can result in
348- // `Res::NonMacroAttr` definition (e.g., `inline!()`), so we must report
349- // an error for those cases.
350- let msg = format ! ( "expected a macro, found {}" , res. descr( ) ) ;
351- self . session . span_err ( path. span , & msg) ;
352- return Err ( Determinacy :: Determined ) ;
353346 }
354347 }
355- Res :: Err => {
356- return Err ( Determinacy :: Determined ) ;
357- }
358348 _ => panic ! ( "expected `DefKind::Macro` or `Res::NonMacroAttr`" ) ,
359- }
349+ } ;
360350
361351 Ok ( ( res, self . get_macro ( res) ) )
362352 }
@@ -608,9 +598,7 @@ impl<'a> Resolver<'a> {
608598 result = Ok ( ( binding, Flags :: empty ( ) ) ) ;
609599 break ;
610600 }
611- Err ( Determinacy :: Determined ) => { }
612- Err ( Determinacy :: Undetermined ) =>
613- result = Err ( Determinacy :: Undetermined ) ,
601+ Err ( Indeterminate ) => result = Err ( Determinacy :: Undetermined ) ,
614602 }
615603 }
616604 result
0 commit comments