@@ -20,13 +20,12 @@ use rustc::hir::map::{self, DefCollector};
20
20
use rustc:: { ty, lint} ;
21
21
use rustc:: middle:: cstore:: CrateStore ;
22
22
use syntax:: ast:: { self , Name , Ident } ;
23
- use syntax:: attr:: { self , HasAttrs } ;
23
+ use syntax:: attr;
24
24
use syntax:: errors:: DiagnosticBuilder ;
25
- use syntax:: ext:: base:: { self , Annotatable , Determinacy , MultiModifier , MultiDecorator } ;
25
+ use syntax:: ext:: base:: { self , Determinacy , MultiModifier , MultiDecorator } ;
26
26
use syntax:: ext:: base:: { MacroKind , SyntaxExtension , Resolver as SyntaxResolver } ;
27
- use syntax:: ext:: expand:: { self , AstFragment , AstFragmentKind , Invocation , InvocationKind } ;
27
+ use syntax:: ext:: expand:: { AstFragment , Invocation , InvocationKind } ;
28
28
use syntax:: ext:: hygiene:: { self , Mark } ;
29
- use syntax:: ext:: placeholders:: placeholder;
30
29
use syntax:: ext:: tt:: macro_rules;
31
30
use syntax:: feature_gate:: { self , feature_err, emit_feature_err, is_builtin_attr_name, GateIssue } ;
32
31
use syntax:: fold:: { self , Folder } ;
@@ -320,7 +319,7 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> {
320
319
None
321
320
}
322
321
323
- fn resolve_invoc ( & mut self , invoc : & mut Invocation , scope : Mark , force : bool )
322
+ fn resolve_invoc ( & mut self , invoc : & Invocation , scope : Mark , force : bool )
324
323
-> Result < Option < Lrc < SyntaxExtension > > , Determinacy > {
325
324
let def = match invoc. kind {
326
325
InvocationKind :: Attr { attr : None , .. } => return Ok ( None ) ,
@@ -330,17 +329,22 @@ impl<'a, 'crateloader: 'a> base::Resolver for Resolver<'a, 'crateloader> {
330
329
self . report_proc_macro_stub ( invoc. span ( ) ) ;
331
330
return Err ( Determinacy :: Determined ) ;
332
331
} else if let Def :: NonMacroAttr ( attr_kind) = def {
333
- let is_attr = if let InvocationKind :: Attr { .. } = invoc. kind { true } else { false } ;
334
- if is_attr && attr_kind == NonMacroAttrKind :: Tool {
335
- if !self . session . features_untracked ( ) . tool_attributes {
336
- feature_err ( & self . session . parse_sess , "tool_attributes" ,
337
- invoc. span ( ) , GateIssue :: Language ,
338
- "tool attributes are unstable" ) . emit ( ) ;
332
+ let is_attr_invoc =
333
+ if let InvocationKind :: Attr { .. } = invoc. kind { true } else { false } ;
334
+ match attr_kind {
335
+ NonMacroAttrKind :: Tool | NonMacroAttrKind :: DeriveHelper if is_attr_invoc => {
336
+ if attr_kind == NonMacroAttrKind :: Tool &&
337
+ !self . session . features_untracked ( ) . tool_attributes {
338
+ feature_err ( & self . session . parse_sess , "tool_attributes" ,
339
+ invoc. span ( ) , GateIssue :: Language ,
340
+ "tool attributes are unstable" ) . emit ( ) ;
341
+ }
342
+ return Ok ( Some ( Lrc :: new ( SyntaxExtension :: NonMacroAttr ) ) ) ;
343
+ }
344
+ _ => {
345
+ self . report_non_macro_attr ( invoc. path_span ( ) , def) ;
346
+ return Err ( Determinacy :: Determined ) ;
339
347
}
340
- return Ok ( Some ( Lrc :: new ( SyntaxExtension :: NonMacroAttr ) ) ) ;
341
- } else {
342
- self . report_non_macro_attr ( invoc. path_span ( ) , def) ;
343
- return Err ( Determinacy :: Determined ) ;
344
348
}
345
349
}
346
350
let def_id = def. def_id ( ) ;
@@ -401,10 +405,10 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
401
405
self . session . span_err ( span, & format ! ( "expected a macro, found {}" , def. kind_name( ) ) ) ;
402
406
}
403
407
404
- fn resolve_invoc_to_def ( & mut self , invoc : & mut Invocation , scope : Mark , force : bool )
408
+ fn resolve_invoc_to_def ( & mut self , invoc : & Invocation , scope : Mark , force : bool )
405
409
-> Result < Def , Determinacy > {
406
- let ( attr, traits, item ) = match invoc. kind {
407
- InvocationKind :: Attr { ref mut attr, ref traits, ref mut item } => ( attr, traits, item ) ,
410
+ let ( attr, traits) = match invoc. kind {
411
+ InvocationKind :: Attr { ref attr, ref traits, .. } => ( attr, traits) ,
408
412
InvocationKind :: Bang { ref mac, .. } => {
409
413
return self . resolve_macro_to_def ( scope, & mac. node . path , MacroKind :: Bang , force) ;
410
414
}
@@ -413,7 +417,6 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
413
417
}
414
418
} ;
415
419
416
-
417
420
let path = attr. as_ref ( ) . unwrap ( ) . path . clone ( ) ;
418
421
let mut determinacy = Determinacy :: Determined ;
419
422
match self . resolve_macro_to_def ( scope, & path, MacroKind :: Attr , force) {
@@ -434,11 +437,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
434
437
// This loop here looks through all of the derive annotations in scope
435
438
// and tries to resolve them. If they themselves successfully resolve
436
439
// *and* the resolve mentions that this attribute's name is a registered
437
- // custom attribute then we flag this attribute as known and update
438
- // `invoc` above to point to the next invocation.
439
- //
440
- // By then returning `Undetermined` we should continue resolution to
441
- // resolve the next attribute.
440
+ // custom attribute then we return that custom attribute as the resolution result.
442
441
let attr_name = match path. segments . len ( ) {
443
442
1 => path. segments [ 0 ] . ident . name ,
444
443
_ => return Err ( determinacy) ,
@@ -447,20 +446,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
447
446
match self . resolve_macro ( scope, path, MacroKind :: Derive , force) {
448
447
Ok ( ext) => if let SyntaxExtension :: ProcMacroDerive ( _, ref inert_attrs, _) = * ext {
449
448
if inert_attrs. contains ( & attr_name) {
450
- // FIXME(jseyfried) Avoid `mem::replace` here.
451
- let dummy_item = placeholder ( AstFragmentKind :: Items , ast:: DUMMY_NODE_ID )
452
- . make_items ( ) . pop ( ) . unwrap ( ) ;
453
- let dummy_item = Annotatable :: Item ( dummy_item) ;
454
- * item = mem:: replace ( item, dummy_item) . map_attrs ( |mut attrs| {
455
- let inert_attr = attr. take ( ) . unwrap ( ) ;
456
- attr:: mark_known ( & inert_attr) ;
457
- if self . use_extern_macros {
458
- * attr = expand:: find_attr_invoc ( & mut attrs) ;
459
- }
460
- attrs. push ( inert_attr) ;
461
- attrs
462
- } ) ;
463
- return Err ( Determinacy :: Undetermined )
449
+ return Ok ( Def :: NonMacroAttr ( NonMacroAttrKind :: DeriveHelper ) ) ;
464
450
}
465
451
} ,
466
452
Err ( Determinacy :: Undetermined ) => determinacy = Determinacy :: Undetermined ,
0 commit comments