@@ -97,11 +97,12 @@ struct Annotator<'a, 'tcx> {
9797impl < ' a , ' tcx > Annotator < ' a , ' tcx > {
9898 // Determine the stability for a node based on its attributes and inherited
9999 // stability. The stability is recorded in the index and used as the parent.
100+ // fn_sig: Function signature linked with the current node
100101 fn annotate < F > (
101102 & mut self ,
102103 hir_id : HirId ,
103104 item_sp : Span ,
104- item_kind : Option < & ItemKind < ' _ > > ,
105+ fn_sig : Option < & hir :: FnSig < ' _ > > ,
105106 kind : AnnotationKind ,
106107 inherit_deprecation : InheritDeprecation ,
107108 inherit_const_stability : InheritConstStability ,
@@ -169,20 +170,28 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
169170
170171 let const_stab = const_stab. map ( |( const_stab, const_span) | {
171172 let const_stab = self . tcx . intern_const_stability ( const_stab) ;
172- match item_kind {
173- Some ( ItemKind :: Fn ( ref fn_sig, _, _) ) => {
174- if !( fn_sig. header . constness == Constness :: Const
175- && fn_sig. header . abi != Abi :: RustIntrinsic
176- && fn_sig. header . abi != Abi :: PlatformIntrinsic )
177- {
178- self . tcx
179- . sess
180- . struct_span_err ( fn_sig. span , "Attributes `#[rustc_const_unstable]` and `#[rustc_const_stable]` require the function to be marked `const`" )
181- . span_label ( const_span, "Const stability attribute specified here" )
182- . emit ( ) ;
183- }
173+ if let Some ( fn_sig) = fn_sig {
174+ if !( fn_sig. header . constness == hir:: Constness :: Const
175+ && fn_sig. header . abi != Abi :: RustIntrinsic
176+ && fn_sig. header . abi != Abi :: PlatformIntrinsic )
177+ {
178+ self . tcx
179+ . sess
180+ . struct_span_err (
181+ fn_sig. span ,
182+ "attributes `#[rustc_const_unstable]` \
183+ and `#[rustc_const_stable]` require \
184+ the function or method to be marked `const`",
185+ )
186+ . span_suggestion_short (
187+ fn_sig. span ,
188+ "make the function or method const" ,
189+ String :: new ( ) ,
190+ rustc_errors:: Applicability :: Unspecified ,
191+ )
192+ . span_label ( const_span, "attribute specified here" )
193+ . emit ( ) ;
184194 }
185- _ => { }
186195 }
187196
188197 self . index . const_stab_map . insert ( hir_id, const_stab) ;
@@ -386,6 +395,8 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
386395 let orig_in_trait_impl = self . in_trait_impl ;
387396 let mut kind = AnnotationKind :: Required ;
388397 let mut const_stab_inherit = InheritConstStability :: No ;
398+ let mut fn_sig = None ;
399+
389400 match i. kind {
390401 // Inherent impls and foreign modules serve only as containers for other items,
391402 // they don't have their own stability. They still can be annotated as unstable
@@ -406,7 +417,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
406417 self . annotate (
407418 ctor_hir_id,
408419 i. span ,
409- Some ( & i . kind ) ,
420+ None ,
410421 AnnotationKind :: Required ,
411422 InheritDeprecation :: Yes ,
412423 InheritConstStability :: No ,
@@ -415,13 +426,16 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
415426 )
416427 }
417428 }
429+ hir:: ItemKind :: Fn ( ref item_fn_sig, _, _) => {
430+ fn_sig = Some ( item_fn_sig) ;
431+ }
418432 _ => { }
419433 }
420434
421435 self . annotate (
422436 i. hir_id ( ) ,
423437 i. span ,
424- Some ( & i . kind ) ,
438+ fn_sig ,
425439 kind,
426440 InheritDeprecation :: Yes ,
427441 const_stab_inherit,
@@ -432,10 +446,15 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
432446 }
433447
434448 fn visit_trait_item ( & mut self , ti : & ' tcx hir:: TraitItem < ' tcx > ) {
449+ let fn_sig = match ti. kind {
450+ hir:: TraitItemKind :: Fn ( ref fn_sig, _) => Some ( fn_sig) ,
451+ _ => None ,
452+ } ;
453+
435454 self . annotate (
436455 ti. hir_id ( ) ,
437456 ti. span ,
438- None ,
457+ fn_sig ,
439458 AnnotationKind :: Required ,
440459 InheritDeprecation :: Yes ,
441460 InheritConstStability :: No ,
@@ -449,10 +468,16 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
449468 fn visit_impl_item ( & mut self , ii : & ' tcx hir:: ImplItem < ' tcx > ) {
450469 let kind =
451470 if self . in_trait_impl { AnnotationKind :: Prohibited } else { AnnotationKind :: Required } ;
471+
472+ let fn_sig = match ii. kind {
473+ hir:: ImplItemKind :: Fn ( ref fn_sig, _) => Some ( fn_sig) ,
474+ _ => None ,
475+ } ;
476+
452477 self . annotate (
453478 ii. hir_id ( ) ,
454479 ii. span ,
455- None ,
480+ fn_sig ,
456481 kind,
457482 InheritDeprecation :: Yes ,
458483 InheritConstStability :: No ,
0 commit comments