@@ -27,7 +27,8 @@ enum AttrError {
27
27
UnsupportedLiteral
28
28
}
29
29
30
- fn handle_errors ( diag : & Handler , span : Span , error : AttrError , is_bytestr : bool ) {
30
+ fn handle_errors ( sess : & ParseSess , span : Span , error : AttrError , is_bytestr : bool ) {
31
+ let diag = & sess. span_diagnostic ;
31
32
match error {
32
33
AttrError :: MultipleItem ( item) => span_err ! ( diag, span, E0538 ,
33
34
"multiple '{}' items" , item) ,
@@ -52,11 +53,11 @@ fn handle_errors(diag: &Handler, span: Span, error: AttrError, is_bytestr: bool)
52
53
"unsupported literal" ,
53
54
) ;
54
55
if is_bytestr {
55
- if let Ok ( lint_str) = sess. source_map . span_to_snippet ( span) {
56
+ if let Ok ( lint_str) = sess. source_map ( ) . span_to_snippet ( span) {
56
57
err. span_suggestion_with_applicability (
57
58
span,
58
59
"consider removing the prefix" ,
59
- format ! ( "{}" , lint_str[ 1 ..] ) ,
60
+ format ! ( "{}" , & lint_str[ 1 ..] ) ,
60
61
Applicability :: MaybeIncorrect ,
61
62
) ;
62
63
}
@@ -179,12 +180,12 @@ pub fn contains_feature_attr(attrs: &[Attribute], feature_name: &str) -> bool {
179
180
}
180
181
181
182
/// Find the first stability attribute. `None` if none exists.
182
- pub fn find_stability ( diagnostic : & Handler , attrs : & [ Attribute ] ,
183
+ pub fn find_stability ( sess : & ParseSess , attrs : & [ Attribute ] ,
183
184
item_sp : Span ) -> Option < Stability > {
184
- find_stability_generic ( diagnostic , attrs. iter ( ) , item_sp)
185
+ find_stability_generic ( sess , attrs. iter ( ) , item_sp)
185
186
}
186
187
187
- fn find_stability_generic < ' a , I > ( diagnostic : & Handler ,
188
+ fn find_stability_generic < ' a , I > ( sess : & ParseSess ,
188
189
attrs_iter : I ,
189
190
item_sp : Span )
190
191
-> Option < Stability >
@@ -196,6 +197,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
196
197
let mut rustc_depr: Option < RustcDeprecation > = None ;
197
198
let mut rustc_const_unstable: Option < Symbol > = None ;
198
199
let mut promotable = false ;
200
+ let diagnostic = & sess. span_diagnostic ;
199
201
200
202
' outer: for attr in attrs_iter {
201
203
if ![
@@ -220,7 +222,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
220
222
let meta = meta. as_ref ( ) . unwrap ( ) ;
221
223
let get = |meta : & MetaItem , item : & mut Option < Symbol > | {
222
224
if item. is_some ( ) {
223
- handle_errors ( diagnostic , meta. span , AttrError :: MultipleItem ( meta. name ( ) ) , false ) ;
225
+ handle_errors ( sess , meta. span , AttrError :: MultipleItem ( meta. name ( ) ) , false ) ;
224
226
return false
225
227
}
226
228
if let Some ( v) = meta. value_str ( ) {
@@ -247,16 +249,16 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
247
249
_ => {
248
250
let expected = & [ $( stringify!( $name) ) ,+ ] ;
249
251
handle_errors(
250
- diagnostic ,
252
+ sess ,
251
253
mi. span,
252
254
AttrError :: UnknownMetaItem ( mi. name( ) , expected) ,
253
- false
255
+ false ,
254
256
) ;
255
257
continue ' outer
256
258
}
257
259
}
258
260
} else {
259
- handle_errors( diagnostic , meta. span, AttrError :: UnsupportedLiteral , false ) ;
261
+ handle_errors( sess , meta. span, AttrError :: UnsupportedLiteral , false ) ;
260
262
continue ' outer
261
263
}
262
264
}
@@ -281,7 +283,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
281
283
} )
282
284
}
283
285
( None , _) => {
284
- handle_errors ( diagnostic , attr. span ( ) , AttrError :: MissingSince , false ) ;
286
+ handle_errors ( sess , attr. span ( ) , AttrError :: MissingSince , false ) ;
285
287
continue
286
288
}
287
289
_ => {
@@ -307,7 +309,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
307
309
}
308
310
"unstable" => {
309
311
if stab. is_some ( ) {
310
- handle_errors ( diagnostic , attr. span ( ) , AttrError :: MultipleStabilityLevels , false ) ;
312
+ handle_errors ( sess , attr. span ( ) , AttrError :: MultipleStabilityLevels , false ) ;
311
313
break
312
314
}
313
315
@@ -322,7 +324,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
322
324
"issue" => if !get ( mi, & mut issue) { continue ' outer } ,
323
325
_ => {
324
326
handle_errors (
325
- diagnostic ,
327
+ sess ,
326
328
meta. span ,
327
329
AttrError :: UnknownMetaItem (
328
330
mi. name ( ) ,
@@ -334,7 +336,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
334
336
}
335
337
}
336
338
} else {
337
- handle_errors ( diagnostic , meta. span , AttrError :: UnsupportedLiteral , false ) ;
339
+ handle_errors ( sess , meta. span , AttrError :: UnsupportedLiteral , false ) ;
338
340
continue ' outer
339
341
}
340
342
}
@@ -361,7 +363,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
361
363
} )
362
364
}
363
365
( None , _, _) => {
364
- handle_errors ( diagnostic , attr. span ( ) , AttrError :: MissingFeature , false ) ;
366
+ handle_errors ( sess , attr. span ( ) , AttrError :: MissingFeature , false ) ;
365
367
continue
366
368
}
367
369
_ => {
@@ -372,7 +374,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
372
374
}
373
375
"stable" => {
374
376
if stab. is_some ( ) {
375
- handle_errors ( diagnostic , attr. span ( ) , AttrError :: MultipleStabilityLevels , false ) ;
377
+ handle_errors ( sess , attr. span ( ) , AttrError :: MultipleStabilityLevels , false ) ;
376
378
break
377
379
}
378
380
@@ -386,17 +388,18 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
386
388
"since" => if !get ( mi, & mut since) { continue ' outer } ,
387
389
_ => {
388
390
handle_errors (
389
- diagnostic ,
391
+ sess ,
390
392
meta. span ,
391
393
AttrError :: UnknownMetaItem ( mi. name ( ) , & [ "since" , "note" ] ) ,
392
394
false ,
393
395
) ;
394
396
continue ' outer
395
397
}
396
398
}
399
+ } ,
397
400
NestedMetaItemKind :: Literal ( lit) => {
398
401
handle_errors (
399
- diagnostic ,
402
+ sess ,
400
403
meta. span ,
401
404
AttrError :: UnsupportedLiteral ,
402
405
lit. node . is_bytestr ( )
@@ -419,11 +422,11 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
419
422
} )
420
423
}
421
424
( None , _) => {
422
- handle_errors ( diagnostic , attr. span ( ) , AttrError :: MissingFeature , false ) ;
425
+ handle_errors ( sess , attr. span ( ) , AttrError :: MissingFeature , false ) ;
423
426
continue
424
427
}
425
428
_ => {
426
- handle_errors ( diagnostic , attr. span ( ) , AttrError :: MissingSince , false ) ;
429
+ handle_errors ( sess , attr. span ( ) , AttrError :: MissingSince , false ) ;
427
430
continue
428
431
}
429
432
}
@@ -490,9 +493,9 @@ pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Feat
490
493
MetaItemKind :: List ( ..) => {
491
494
error ( cfg. span , "unexpected parentheses after `cfg` predicate key" )
492
495
}
493
- MetaItemKind :: NameValue ( lit) => if !lit. node . is_str ( ) {
496
+ MetaItemKind :: NameValue ( lit) if !lit. node . is_str ( ) => {
494
497
handle_errors (
495
- & sess. span_diagnostic ,
498
+ sess,
496
499
lit. span , AttrError :: UnsupportedLiteral ,
497
500
lit. node . is_bytestr ( ) ,
498
501
) ;
@@ -515,7 +518,7 @@ pub fn eval_condition<F>(cfg: &ast::MetaItem, sess: &ParseSess, eval: &mut F)
515
518
ast:: MetaItemKind :: List ( ref mis) => {
516
519
for mi in mis. iter ( ) {
517
520
if !mi. is_meta_item ( ) {
518
- handle_errors ( & sess. span_diagnostic , mi. span , AttrError :: UnsupportedLiteral , false ) ;
521
+ handle_errors ( sess, mi. span , AttrError :: UnsupportedLiteral , false ) ;
519
522
return false ;
520
523
}
521
524
}
@@ -557,18 +560,19 @@ pub struct Deprecation {
557
560
}
558
561
559
562
/// Find the deprecation attribute. `None` if none exists.
560
- pub fn find_deprecation ( diagnostic : & Handler , attrs : & [ Attribute ] ,
563
+ pub fn find_deprecation ( sess : & ParseSess , attrs : & [ Attribute ] ,
561
564
item_sp : Span ) -> Option < Deprecation > {
562
- find_deprecation_generic ( diagnostic , attrs. iter ( ) , item_sp)
565
+ find_deprecation_generic ( sess , attrs. iter ( ) , item_sp)
563
566
}
564
567
565
- fn find_deprecation_generic < ' a , I > ( diagnostic : & Handler ,
568
+ fn find_deprecation_generic < ' a , I > ( sess : & ParseSess ,
566
569
attrs_iter : I ,
567
570
item_sp : Span )
568
571
-> Option < Deprecation >
569
572
where I : Iterator < Item = & ' a Attribute >
570
573
{
571
574
let mut depr: Option < Deprecation > = None ;
575
+ let diagnostic = & sess. span_diagnostic ;
572
576
573
577
' outer: for attr in attrs_iter {
574
578
if attr. path != "deprecated" {
@@ -585,7 +589,7 @@ fn find_deprecation_generic<'a, I>(diagnostic: &Handler,
585
589
depr = if let Some ( metas) = attr. meta_item_list ( ) {
586
590
let get = |meta : & MetaItem , item : & mut Option < Symbol > | {
587
591
if item. is_some ( ) {
588
- handle_errors ( diagnostic , meta. span , AttrError :: MultipleItem ( meta. name ( ) ) , false ) ;
592
+ handle_errors ( sess , meta. span , AttrError :: MultipleItem ( meta. name ( ) ) , false ) ;
589
593
return false
590
594
}
591
595
if let Some ( v) = meta. value_str ( ) {
@@ -607,7 +611,7 @@ fn find_deprecation_generic<'a, I>(diagnostic: &Handler,
607
611
"note" => if !get ( mi, & mut note) { continue ' outer } ,
608
612
_ => {
609
613
handle_errors (
610
- diagnostic ,
614
+ sess ,
611
615
meta. span ,
612
616
AttrError :: UnknownMetaItem ( mi. name ( ) , & [ "since" , "note" ] ) ,
613
617
false ,
@@ -618,7 +622,7 @@ fn find_deprecation_generic<'a, I>(diagnostic: &Handler,
618
622
}
619
623
NestedMetaItemKind :: Literal ( lit) => {
620
624
let is_bytestr = lit. node . is_bytestr ( ) ;
621
- handle_errors ( diagnostic , meta. span , AttrError :: UnsupportedLiteral , is_bytestr) ;
625
+ handle_errors ( sess , meta. span , AttrError :: UnsupportedLiteral , is_bytestr) ;
622
626
continue ' outer
623
627
}
624
628
}
@@ -668,16 +672,17 @@ impl IntType {
668
672
/// the same discriminant size that the corresponding C enum would or C
669
673
/// structure layout, `packed` to remove padding, and `transparent` to elegate representation
670
674
/// concerns to the only non-ZST field.
671
- pub fn find_repr_attrs ( diagnostic : & Handler , attr : & Attribute ) -> Vec < ReprAttr > {
675
+ pub fn find_repr_attrs ( sess : & ParseSess , attr : & Attribute ) -> Vec < ReprAttr > {
672
676
use self :: ReprAttr :: * ;
673
677
674
678
let mut acc = Vec :: new ( ) ;
679
+ let diagnostic = & sess. span_diagnostic ;
675
680
if attr. path == "repr" {
676
681
if let Some ( items) = attr. meta_item_list ( ) {
677
682
mark_used ( attr) ;
678
683
for item in items {
679
684
if !item. is_meta_item ( ) {
680
- handle_errors ( diagnostic , item. span , AttrError :: UnsupportedLiteral , false ) ;
685
+ handle_errors ( sess , item. span , AttrError :: UnsupportedLiteral , false ) ;
681
686
continue
682
687
}
683
688
0 commit comments