@@ -11,6 +11,7 @@ use rustc_hir::attrs::AttributeKind;
11
11
use rustc_hir:: lints:: { AttributeLint , AttributeLintKind } ;
12
12
use rustc_hir:: { AttrArgs , AttrItem , AttrPath , Attribute , HashIgnoredAttrId , HirId } ;
13
13
use rustc_session:: Session ;
14
+ use rustc_session:: lint:: BuiltinLintDiag ;
14
15
use rustc_span:: { DUMMY_SP , ErrorGuaranteed , Span , Symbol , sym} ;
15
16
16
17
use crate :: attributes:: allow_unstable:: {
@@ -22,6 +23,7 @@ use crate::attributes::codegen_attrs::{
22
23
TargetFeatureParser , TrackCallerParser , UsedParser ,
23
24
} ;
24
25
use crate :: attributes:: confusables:: ConfusablesParser ;
26
+ use crate :: attributes:: crate_level:: CrateNameParser ;
25
27
use crate :: attributes:: deprecation:: DeprecationParser ;
26
28
use crate :: attributes:: dummy:: DummyParser ;
27
29
use crate :: attributes:: inline:: { InlineParser , RustcForceInlineParser } ;
@@ -59,6 +61,7 @@ use crate::attributes::traits::{
59
61
} ;
60
62
use crate :: attributes:: transparency:: TransparencyParser ;
61
63
use crate :: attributes:: { AttributeParser as _, Combine , Single , WithoutArgs } ;
64
+ use crate :: lints:: lint_name;
62
65
use crate :: parser:: { ArgParser , MetaItemParser , PathParser } ;
63
66
use crate :: session_diagnostics:: { AttributeParseError , AttributeParseErrorReason , UnknownMetaItem } ;
64
67
@@ -157,6 +160,7 @@ attribute_parsers!(
157
160
158
161
// tidy-alphabetical-start
159
162
Single <CoverageParser >,
163
+ Single <CrateNameParser >,
160
164
Single <DeprecationParser >,
161
165
Single <DummyParser >,
162
166
Single <ExportNameParser >,
@@ -301,7 +305,9 @@ pub struct AcceptContext<'f, 'sess, S: Stage> {
301
305
/// The span of the attribute currently being parsed
302
306
pub ( crate ) attr_span : Span ,
303
307
308
+ /// Whether it is an inner or outer attribute
304
309
pub ( crate ) attr_style : AttrStyle ,
310
+
305
311
/// The expected structure of the attribute.
306
312
///
307
313
/// Used in reporting errors to give a hint to users what the attribute *should* look like.
@@ -689,22 +695,48 @@ impl<'sess> AttributeParser<'sess, Early> {
689
695
target_span : Span ,
690
696
target_node_id : NodeId ,
691
697
features : Option < & ' sess Features > ,
698
+ ) -> Option < Attribute > {
699
+ Self :: parse_limited_should_emit (
700
+ sess,
701
+ attrs,
702
+ sym,
703
+ target_span,
704
+ target_node_id,
705
+ features,
706
+ ShouldEmit :: Nothing ,
707
+ )
708
+ }
709
+
710
+ /// Usually you want `parse_limited`, which defaults to no errors.
711
+ pub fn parse_limited_should_emit (
712
+ sess : & ' sess Session ,
713
+ attrs : & [ ast:: Attribute ] ,
714
+ sym : Symbol ,
715
+ target_span : Span ,
716
+ target_node_id : NodeId ,
717
+ features : Option < & ' sess Features > ,
718
+ should_emit : ShouldEmit ,
692
719
) -> Option < Attribute > {
693
720
let mut p = Self {
694
721
features,
695
722
tools : Vec :: new ( ) ,
696
723
parse_only : Some ( sym) ,
697
724
sess,
698
- stage : Early { emit_errors : ShouldEmit :: Nothing } ,
725
+ stage : Early { emit_errors : should_emit } ,
699
726
} ;
700
727
let mut parsed = p. parse_attribute_list (
701
728
attrs,
702
729
target_span,
703
730
target_node_id,
704
731
OmitDoc :: Skip ,
705
732
std:: convert:: identity,
706
- |_lint| {
707
- panic ! ( "can't emit lints here for now (nothing uses this atm)" ) ;
733
+ |AttributeLint { id, span, kind } | {
734
+ sess. psess . buffer_lint (
735
+ lint_name ( & kind) ,
736
+ span,
737
+ id,
738
+ BuiltinLintDiag :: AttributeLint ( kind) ,
739
+ ) ;
708
740
} ,
709
741
) ;
710
742
assert ! ( parsed. len( ) <= 1 ) ;
0 commit comments