@@ -27,7 +27,8 @@ enum AttrError {
2727 UnsupportedLiteral
2828}
2929
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 ;
3132 match error {
3233 AttrError :: MultipleItem ( item) => span_err ! ( diag, span, E0538 ,
3334 "multiple '{}' items" , item) ,
@@ -52,11 +53,11 @@ fn handle_errors(diag: &Handler, span: Span, error: AttrError, is_bytestr: bool)
5253 "unsupported literal" ,
5354 ) ;
5455 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) {
5657 err. span_suggestion_with_applicability (
5758 span,
5859 "consider removing the prefix" ,
59- format ! ( "{}" , lint_str[ 1 ..] ) ,
60+ format ! ( "{}" , & lint_str[ 1 ..] ) ,
6061 Applicability :: MaybeIncorrect ,
6162 ) ;
6263 }
@@ -179,12 +180,12 @@ pub fn contains_feature_attr(attrs: &[Attribute], feature_name: &str) -> bool {
179180}
180181
181182/// 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 ] ,
183184 item_sp : Span ) -> Option < Stability > {
184- find_stability_generic ( diagnostic , attrs. iter ( ) , item_sp)
185+ find_stability_generic ( sess , attrs. iter ( ) , item_sp)
185186}
186187
187- fn find_stability_generic < ' a , I > ( diagnostic : & Handler ,
188+ fn find_stability_generic < ' a , I > ( sess : & ParseSess ,
188189 attrs_iter : I ,
189190 item_sp : Span )
190191 -> Option < Stability >
@@ -196,6 +197,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
196197 let mut rustc_depr: Option < RustcDeprecation > = None ;
197198 let mut rustc_const_unstable: Option < Symbol > = None ;
198199 let mut promotable = false ;
200+ let diagnostic = & sess. span_diagnostic ;
199201
200202 ' outer: for attr in attrs_iter {
201203 if ![
@@ -220,7 +222,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
220222 let meta = meta. as_ref ( ) . unwrap ( ) ;
221223 let get = |meta : & MetaItem , item : & mut Option < Symbol > | {
222224 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 ) ;
224226 return false
225227 }
226228 if let Some ( v) = meta. value_str ( ) {
@@ -247,16 +249,16 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
247249 _ => {
248250 let expected = & [ $( stringify!( $name) ) ,+ ] ;
249251 handle_errors(
250- diagnostic ,
252+ sess ,
251253 mi. span,
252254 AttrError :: UnknownMetaItem ( mi. name( ) , expected) ,
253- false
255+ false ,
254256 ) ;
255257 continue ' outer
256258 }
257259 }
258260 } else {
259- handle_errors( diagnostic , meta. span, AttrError :: UnsupportedLiteral , false ) ;
261+ handle_errors( sess , meta. span, AttrError :: UnsupportedLiteral , false ) ;
260262 continue ' outer
261263 }
262264 }
@@ -281,7 +283,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
281283 } )
282284 }
283285 ( None , _) => {
284- handle_errors ( diagnostic , attr. span ( ) , AttrError :: MissingSince , false ) ;
286+ handle_errors ( sess , attr. span ( ) , AttrError :: MissingSince , false ) ;
285287 continue
286288 }
287289 _ => {
@@ -307,7 +309,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
307309 }
308310 "unstable" => {
309311 if stab. is_some ( ) {
310- handle_errors ( diagnostic , attr. span ( ) , AttrError :: MultipleStabilityLevels , false ) ;
312+ handle_errors ( sess , attr. span ( ) , AttrError :: MultipleStabilityLevels , false ) ;
311313 break
312314 }
313315
@@ -322,7 +324,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
322324 "issue" => if !get ( mi, & mut issue) { continue ' outer } ,
323325 _ => {
324326 handle_errors (
325- diagnostic ,
327+ sess ,
326328 meta. span ,
327329 AttrError :: UnknownMetaItem (
328330 mi. name ( ) ,
@@ -334,7 +336,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
334336 }
335337 }
336338 } else {
337- handle_errors ( diagnostic , meta. span , AttrError :: UnsupportedLiteral , false ) ;
339+ handle_errors ( sess , meta. span , AttrError :: UnsupportedLiteral , false ) ;
338340 continue ' outer
339341 }
340342 }
@@ -361,7 +363,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
361363 } )
362364 }
363365 ( None , _, _) => {
364- handle_errors ( diagnostic , attr. span ( ) , AttrError :: MissingFeature , false ) ;
366+ handle_errors ( sess , attr. span ( ) , AttrError :: MissingFeature , false ) ;
365367 continue
366368 }
367369 _ => {
@@ -372,7 +374,7 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
372374 }
373375 "stable" => {
374376 if stab. is_some ( ) {
375- handle_errors ( diagnostic , attr. span ( ) , AttrError :: MultipleStabilityLevels , false ) ;
377+ handle_errors ( sess , attr. span ( ) , AttrError :: MultipleStabilityLevels , false ) ;
376378 break
377379 }
378380
@@ -386,17 +388,18 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
386388 "since" => if !get ( mi, & mut since) { continue ' outer } ,
387389 _ => {
388390 handle_errors (
389- diagnostic ,
391+ sess ,
390392 meta. span ,
391393 AttrError :: UnknownMetaItem ( mi. name ( ) , & [ "since" , "note" ] ) ,
392394 false ,
393395 ) ;
394396 continue ' outer
395397 }
396398 }
399+ } ,
397400 NestedMetaItemKind :: Literal ( lit) => {
398401 handle_errors (
399- diagnostic ,
402+ sess ,
400403 meta. span ,
401404 AttrError :: UnsupportedLiteral ,
402405 lit. node . is_bytestr ( )
@@ -419,11 +422,11 @@ fn find_stability_generic<'a, I>(diagnostic: &Handler,
419422 } )
420423 }
421424 ( None , _) => {
422- handle_errors ( diagnostic , attr. span ( ) , AttrError :: MissingFeature , false ) ;
425+ handle_errors ( sess , attr. span ( ) , AttrError :: MissingFeature , false ) ;
423426 continue
424427 }
425428 _ => {
426- handle_errors ( diagnostic , attr. span ( ) , AttrError :: MissingSince , false ) ;
429+ handle_errors ( sess , attr. span ( ) , AttrError :: MissingSince , false ) ;
427430 continue
428431 }
429432 }
@@ -490,9 +493,9 @@ pub fn cfg_matches(cfg: &ast::MetaItem, sess: &ParseSess, features: Option<&Feat
490493 MetaItemKind :: List ( ..) => {
491494 error ( cfg. span , "unexpected parentheses after `cfg` predicate key" )
492495 }
493- MetaItemKind :: NameValue ( lit) => if !lit. node . is_str ( ) {
496+ MetaItemKind :: NameValue ( lit) if !lit. node . is_str ( ) => {
494497 handle_errors (
495- & sess. span_diagnostic ,
498+ sess,
496499 lit. span , AttrError :: UnsupportedLiteral ,
497500 lit. node . is_bytestr ( ) ,
498501 ) ;
@@ -515,7 +518,7 @@ pub fn eval_condition<F>(cfg: &ast::MetaItem, sess: &ParseSess, eval: &mut F)
515518 ast:: MetaItemKind :: List ( ref mis) => {
516519 for mi in mis. iter ( ) {
517520 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 ) ;
519522 return false ;
520523 }
521524 }
@@ -557,18 +560,19 @@ pub struct Deprecation {
557560}
558561
559562/// 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 ] ,
561564 item_sp : Span ) -> Option < Deprecation > {
562- find_deprecation_generic ( diagnostic , attrs. iter ( ) , item_sp)
565+ find_deprecation_generic ( sess , attrs. iter ( ) , item_sp)
563566}
564567
565- fn find_deprecation_generic < ' a , I > ( diagnostic : & Handler ,
568+ fn find_deprecation_generic < ' a , I > ( sess : & ParseSess ,
566569 attrs_iter : I ,
567570 item_sp : Span )
568571 -> Option < Deprecation >
569572 where I : Iterator < Item = & ' a Attribute >
570573{
571574 let mut depr: Option < Deprecation > = None ;
575+ let diagnostic = & sess. span_diagnostic ;
572576
573577 ' outer: for attr in attrs_iter {
574578 if attr. path != "deprecated" {
@@ -585,7 +589,7 @@ fn find_deprecation_generic<'a, I>(diagnostic: &Handler,
585589 depr = if let Some ( metas) = attr. meta_item_list ( ) {
586590 let get = |meta : & MetaItem , item : & mut Option < Symbol > | {
587591 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 ) ;
589593 return false
590594 }
591595 if let Some ( v) = meta. value_str ( ) {
@@ -607,7 +611,7 @@ fn find_deprecation_generic<'a, I>(diagnostic: &Handler,
607611 "note" => if !get ( mi, & mut note) { continue ' outer } ,
608612 _ => {
609613 handle_errors (
610- diagnostic ,
614+ sess ,
611615 meta. span ,
612616 AttrError :: UnknownMetaItem ( mi. name ( ) , & [ "since" , "note" ] ) ,
613617 false ,
@@ -618,7 +622,7 @@ fn find_deprecation_generic<'a, I>(diagnostic: &Handler,
618622 }
619623 NestedMetaItemKind :: Literal ( lit) => {
620624 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) ;
622626 continue ' outer
623627 }
624628 }
@@ -668,16 +672,17 @@ impl IntType {
668672/// the same discriminant size that the corresponding C enum would or C
669673/// structure layout, `packed` to remove padding, and `transparent` to elegate representation
670674/// 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 > {
672676 use self :: ReprAttr :: * ;
673677
674678 let mut acc = Vec :: new ( ) ;
679+ let diagnostic = & sess. span_diagnostic ;
675680 if attr. path == "repr" {
676681 if let Some ( items) = attr. meta_item_list ( ) {
677682 mark_used ( attr) ;
678683 for item in items {
679684 if !item. is_meta_item ( ) {
680- handle_errors ( diagnostic , item. span , AttrError :: UnsupportedLiteral , false ) ;
685+ handle_errors ( sess , item. span , AttrError :: UnsupportedLiteral , false ) ;
681686 continue
682687 }
683688
0 commit comments