]> git.lizzy.rs Git - rust.git/blob - src/librustc_passes/stability.rs
Rollup merge of #67909 - varkor:obsolete-const-print, r=davidtwco
[rust.git] / src / librustc_passes / stability.rs
1 //! A pass that annotates every item and method with its stability level,
2 //! propagating default levels lexically from parent to children ast nodes.
3
4 use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor};
5 use rustc::lint;
6 use rustc::middle::privacy::AccessLevels;
7 use rustc::middle::stability::{DeprecationEntry, Index};
8 use rustc::session::Session;
9 use rustc::ty::query::Providers;
10 use rustc::ty::TyCtxt;
11 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
12 use rustc_hir as hir;
13 use rustc_hir::def::{DefKind, Res};
14 use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
15 use rustc_hir::{Generics, HirId, Item, StructField, Variant};
16 use rustc_span::symbol::{sym, Symbol};
17 use rustc_span::Span;
18 use syntax::ast::Attribute;
19 use syntax::attr::{self, Stability};
20 use syntax::feature_gate::feature_err;
21
22 use std::cmp::Ordering;
23 use std::mem::replace;
24 use std::num::NonZeroU32;
25
26 use rustc_error_codes::*;
27
28 #[derive(PartialEq)]
29 enum AnnotationKind {
30     // Annotation is required if not inherited from unstable parents
31     Required,
32     // Annotation is useless, reject it
33     Prohibited,
34     // Annotation itself is useless, but it can be propagated to children
35     Container,
36 }
37
38 // A private tree-walker for producing an Index.
39 struct Annotator<'a, 'tcx> {
40     tcx: TyCtxt<'tcx>,
41     index: &'a mut Index<'tcx>,
42     parent_stab: Option<&'tcx Stability>,
43     parent_depr: Option<DeprecationEntry>,
44     in_trait_impl: bool,
45 }
46
47 impl<'a, 'tcx> Annotator<'a, 'tcx> {
48     // Determine the stability for a node based on its attributes and inherited
49     // stability. The stability is recorded in the index and used as the parent.
50     fn annotate<F>(
51         &mut self,
52         hir_id: HirId,
53         attrs: &[Attribute],
54         item_sp: Span,
55         kind: AnnotationKind,
56         visit_children: F,
57     ) where
58         F: FnOnce(&mut Self),
59     {
60         if self.tcx.features().staged_api {
61             // This crate explicitly wants staged API.
62             debug!("annotate(id = {:?}, attrs = {:?})", hir_id, attrs);
63             if let Some(..) = attr::find_deprecation(&self.tcx.sess.parse_sess, attrs, item_sp) {
64                 self.tcx.sess.span_err(
65                     item_sp,
66                     "`#[deprecated]` cannot be used in staged API; \
67                                                  use `#[rustc_deprecated]` instead",
68                 );
69             }
70             let (stab, const_stab) =
71                 attr::find_stability(&self.tcx.sess.parse_sess, attrs, item_sp);
72             if let Some(const_stab) = const_stab {
73                 let const_stab = self.tcx.intern_const_stability(const_stab);
74                 self.index.const_stab_map.insert(hir_id, const_stab);
75             }
76             if let Some(mut stab) = stab {
77                 // Error if prohibited, or can't inherit anything from a container.
78                 if kind == AnnotationKind::Prohibited
79                     || (kind == AnnotationKind::Container
80                         && stab.level.is_stable()
81                         && stab.rustc_depr.is_none())
82                 {
83                     self.tcx.sess.span_err(item_sp, "This stability annotation is useless");
84                 }
85
86                 debug!("annotate: found {:?}", stab);
87                 // If parent is deprecated and we're not, inherit this by merging
88                 // deprecated_since and its reason.
89                 if let Some(parent_stab) = self.parent_stab {
90                     if parent_stab.rustc_depr.is_some() && stab.rustc_depr.is_none() {
91                         stab.rustc_depr = parent_stab.rustc_depr.clone()
92                     }
93                 }
94
95                 let stab = self.tcx.intern_stability(stab);
96
97                 // Check if deprecated_since < stable_since. If it is,
98                 // this is *almost surely* an accident.
99                 if let (
100                     &Some(attr::RustcDeprecation { since: dep_since, .. }),
101                     &attr::Stable { since: stab_since },
102                 ) = (&stab.rustc_depr, &stab.level)
103                 {
104                     // Explicit version of iter::order::lt to handle parse errors properly
105                     for (dep_v, stab_v) in
106                         dep_since.as_str().split('.').zip(stab_since.as_str().split('.'))
107                     {
108                         if let (Ok(dep_v), Ok(stab_v)) = (dep_v.parse::<u64>(), stab_v.parse()) {
109                             match dep_v.cmp(&stab_v) {
110                                 Ordering::Less => {
111                                     self.tcx.sess.span_err(
112                                         item_sp,
113                                         "An API can't be stabilized \
114                                                                      after it is deprecated",
115                                     );
116                                     break;
117                                 }
118                                 Ordering::Equal => continue,
119                                 Ordering::Greater => break,
120                             }
121                         } else {
122                             // Act like it isn't less because the question is now nonsensical,
123                             // and this makes us not do anything else interesting.
124                             self.tcx.sess.span_err(
125                                 item_sp,
126                                 "Invalid stability or deprecation \
127                                                              version found",
128                             );
129                             break;
130                         }
131                     }
132                 }
133
134                 self.index.stab_map.insert(hir_id, stab);
135
136                 let orig_parent_stab = replace(&mut self.parent_stab, Some(stab));
137                 visit_children(self);
138                 self.parent_stab = orig_parent_stab;
139             } else {
140                 debug!("annotate: not found, parent = {:?}", self.parent_stab);
141                 if let Some(stab) = self.parent_stab {
142                     if stab.level.is_unstable() {
143                         self.index.stab_map.insert(hir_id, stab);
144                     }
145                 }
146                 visit_children(self);
147             }
148         } else {
149             // Emit errors for non-staged-api crates.
150             let unstable_attrs = [
151                 sym::unstable,
152                 sym::stable,
153                 sym::rustc_deprecated,
154                 sym::rustc_const_unstable,
155                 sym::rustc_const_stable,
156             ];
157             for attr in attrs {
158                 let name = attr.name_or_empty();
159                 if unstable_attrs.contains(&name) {
160                     attr::mark_used(attr);
161                     struct_span_err!(
162                         self.tcx.sess,
163                         attr.span,
164                         E0734,
165                         "stability attributes may not be used outside of the standard library",
166                     )
167                     .emit();
168                 }
169             }
170
171             // Propagate unstability.  This can happen even for non-staged-api crates in case
172             // -Zforce-unstable-if-unmarked is set.
173             if let Some(stab) = self.parent_stab {
174                 if stab.level.is_unstable() {
175                     self.index.stab_map.insert(hir_id, stab);
176                 }
177             }
178
179             if let Some(depr) = attr::find_deprecation(&self.tcx.sess.parse_sess, attrs, item_sp) {
180                 if kind == AnnotationKind::Prohibited {
181                     self.tcx.sess.span_err(item_sp, "This deprecation annotation is useless");
182                 }
183
184                 // `Deprecation` is just two pointers, no need to intern it
185                 let depr_entry = DeprecationEntry::local(depr, hir_id);
186                 self.index.depr_map.insert(hir_id, depr_entry.clone());
187
188                 let orig_parent_depr = replace(&mut self.parent_depr, Some(depr_entry));
189                 visit_children(self);
190                 self.parent_depr = orig_parent_depr;
191             } else if let Some(parent_depr) = self.parent_depr.clone() {
192                 self.index.depr_map.insert(hir_id, parent_depr);
193                 visit_children(self);
194             } else {
195                 visit_children(self);
196             }
197         }
198     }
199 }
200
201 impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> {
202     /// Because stability levels are scoped lexically, we want to walk
203     /// nested items in the context of the outer item, so enable
204     /// deep-walking.
205     fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
206         NestedVisitorMap::All(&self.tcx.hir())
207     }
208
209     fn visit_item(&mut self, i: &'tcx Item<'tcx>) {
210         let orig_in_trait_impl = self.in_trait_impl;
211         let mut kind = AnnotationKind::Required;
212         match i.kind {
213             // Inherent impls and foreign modules serve only as containers for other items,
214             // they don't have their own stability. They still can be annotated as unstable
215             // and propagate this unstability to children, but this annotation is completely
216             // optional. They inherit stability from their parents when unannotated.
217             hir::ItemKind::Impl(.., None, _, _) | hir::ItemKind::ForeignMod(..) => {
218                 self.in_trait_impl = false;
219                 kind = AnnotationKind::Container;
220             }
221             hir::ItemKind::Impl(.., Some(_), _, _) => {
222                 self.in_trait_impl = true;
223             }
224             hir::ItemKind::Struct(ref sd, _) => {
225                 if let Some(ctor_hir_id) = sd.ctor_hir_id() {
226                     self.annotate(ctor_hir_id, &i.attrs, i.span, AnnotationKind::Required, |_| {})
227                 }
228             }
229             _ => {}
230         }
231
232         self.annotate(i.hir_id, &i.attrs, i.span, kind, |v| intravisit::walk_item(v, i));
233         self.in_trait_impl = orig_in_trait_impl;
234     }
235
236     fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem<'tcx>) {
237         self.annotate(ti.hir_id, &ti.attrs, ti.span, AnnotationKind::Required, |v| {
238             intravisit::walk_trait_item(v, ti);
239         });
240     }
241
242     fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem<'tcx>) {
243         let kind =
244             if self.in_trait_impl { AnnotationKind::Prohibited } else { AnnotationKind::Required };
245         self.annotate(ii.hir_id, &ii.attrs, ii.span, kind, |v| {
246             intravisit::walk_impl_item(v, ii);
247         });
248     }
249
250     fn visit_variant(&mut self, var: &'tcx Variant<'tcx>, g: &'tcx Generics<'tcx>, item_id: HirId) {
251         self.annotate(var.id, &var.attrs, var.span, AnnotationKind::Required, |v| {
252             if let Some(ctor_hir_id) = var.data.ctor_hir_id() {
253                 v.annotate(ctor_hir_id, &var.attrs, var.span, AnnotationKind::Required, |_| {});
254             }
255
256             intravisit::walk_variant(v, var, g, item_id)
257         })
258     }
259
260     fn visit_struct_field(&mut self, s: &'tcx StructField<'tcx>) {
261         self.annotate(s.hir_id, &s.attrs, s.span, AnnotationKind::Required, |v| {
262             intravisit::walk_struct_field(v, s);
263         });
264     }
265
266     fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem<'tcx>) {
267         self.annotate(i.hir_id, &i.attrs, i.span, AnnotationKind::Required, |v| {
268             intravisit::walk_foreign_item(v, i);
269         });
270     }
271
272     fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef<'tcx>) {
273         self.annotate(md.hir_id, &md.attrs, md.span, AnnotationKind::Required, |_| {});
274     }
275 }
276
277 struct MissingStabilityAnnotations<'a, 'tcx> {
278     tcx: TyCtxt<'tcx>,
279     access_levels: &'a AccessLevels,
280 }
281
282 impl<'a, 'tcx> MissingStabilityAnnotations<'a, 'tcx> {
283     fn check_missing_stability(&self, hir_id: HirId, span: Span, name: &str) {
284         let stab = self.tcx.stability().local_stability(hir_id);
285         let is_error =
286             !self.tcx.sess.opts.test && stab.is_none() && self.access_levels.is_reachable(hir_id);
287         if is_error {
288             self.tcx.sess.span_err(span, &format!("{} has missing stability attribute", name));
289         }
290     }
291 }
292
293 impl<'a, 'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'a, 'tcx> {
294     fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
295         NestedVisitorMap::OnlyBodies(&self.tcx.hir())
296     }
297
298     fn visit_item(&mut self, i: &'tcx Item<'tcx>) {
299         match i.kind {
300             // Inherent impls and foreign modules serve only as containers for other items,
301             // they don't have their own stability. They still can be annotated as unstable
302             // and propagate this unstability to children, but this annotation is completely
303             // optional. They inherit stability from their parents when unannotated.
304             hir::ItemKind::Impl(.., None, _, _) | hir::ItemKind::ForeignMod(..) => {}
305
306             _ => self.check_missing_stability(i.hir_id, i.span, i.kind.descriptive_variant()),
307         }
308
309         intravisit::walk_item(self, i)
310     }
311
312     fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem<'tcx>) {
313         self.check_missing_stability(ti.hir_id, ti.span, "item");
314         intravisit::walk_trait_item(self, ti);
315     }
316
317     fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem<'tcx>) {
318         let impl_def_id = self.tcx.hir().local_def_id(self.tcx.hir().get_parent_item(ii.hir_id));
319         if self.tcx.impl_trait_ref(impl_def_id).is_none() {
320             self.check_missing_stability(ii.hir_id, ii.span, "item");
321         }
322         intravisit::walk_impl_item(self, ii);
323     }
324
325     fn visit_variant(&mut self, var: &'tcx Variant<'tcx>, g: &'tcx Generics<'tcx>, item_id: HirId) {
326         self.check_missing_stability(var.id, var.span, "variant");
327         intravisit::walk_variant(self, var, g, item_id);
328     }
329
330     fn visit_struct_field(&mut self, s: &'tcx StructField<'tcx>) {
331         self.check_missing_stability(s.hir_id, s.span, "field");
332         intravisit::walk_struct_field(self, s);
333     }
334
335     fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem<'tcx>) {
336         self.check_missing_stability(i.hir_id, i.span, i.kind.descriptive_variant());
337         intravisit::walk_foreign_item(self, i);
338     }
339
340     fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef<'tcx>) {
341         self.check_missing_stability(md.hir_id, md.span, "macro");
342     }
343 }
344
345 fn new_index(tcx: TyCtxt<'tcx>) -> Index<'tcx> {
346     let is_staged_api =
347         tcx.sess.opts.debugging_opts.force_unstable_if_unmarked || tcx.features().staged_api;
348     let mut staged_api = FxHashMap::default();
349     staged_api.insert(LOCAL_CRATE, is_staged_api);
350     let mut index = Index {
351         staged_api,
352         stab_map: Default::default(),
353         const_stab_map: Default::default(),
354         depr_map: Default::default(),
355         active_features: Default::default(),
356     };
357
358     let active_lib_features = &tcx.features().declared_lib_features;
359     let active_lang_features = &tcx.features().declared_lang_features;
360
361     // Put the active features into a map for quick lookup.
362     index.active_features = active_lib_features
363         .iter()
364         .map(|&(ref s, ..)| s.clone())
365         .chain(active_lang_features.iter().map(|&(ref s, ..)| s.clone()))
366         .collect();
367
368     {
369         let krate = tcx.hir().krate();
370         let mut annotator = Annotator {
371             tcx,
372             index: &mut index,
373             parent_stab: None,
374             parent_depr: None,
375             in_trait_impl: false,
376         };
377
378         // If the `-Z force-unstable-if-unmarked` flag is passed then we provide
379         // a parent stability annotation which indicates that this is private
380         // with the `rustc_private` feature. This is intended for use when
381         // compiling librustc crates themselves so we can leverage crates.io
382         // while maintaining the invariant that all sysroot crates are unstable
383         // by default and are unable to be used.
384         if tcx.sess.opts.debugging_opts.force_unstable_if_unmarked {
385             let reason = "this crate is being loaded from the sysroot, an \
386                           unstable location; did you mean to load this crate \
387                           from crates.io via `Cargo.toml` instead?";
388             let stability = tcx.intern_stability(Stability {
389                 level: attr::StabilityLevel::Unstable {
390                     reason: Some(Symbol::intern(reason)),
391                     issue: NonZeroU32::new(27812),
392                     is_soft: false,
393                 },
394                 feature: sym::rustc_private,
395                 rustc_depr: None,
396             });
397             annotator.parent_stab = Some(stability);
398         }
399
400         annotator.annotate(
401             hir::CRATE_HIR_ID,
402             &krate.attrs,
403             krate.span,
404             AnnotationKind::Required,
405             |v| intravisit::walk_crate(v, krate),
406         );
407     }
408     return index;
409 }
410
411 /// Cross-references the feature names of unstable APIs with enabled
412 /// features and possibly prints errors.
413 fn check_mod_unstable_api_usage(tcx: TyCtxt<'_>, module_def_id: DefId) {
414     tcx.hir().visit_item_likes_in_module(module_def_id, &mut Checker { tcx }.as_deep_visitor());
415 }
416
417 pub(crate) fn provide(providers: &mut Providers<'_>) {
418     *providers = Providers { check_mod_unstable_api_usage, ..*providers };
419     providers.stability_index = |tcx, cnum| {
420         assert_eq!(cnum, LOCAL_CRATE);
421         tcx.arena.alloc(new_index(tcx))
422     };
423 }
424
425 struct Checker<'tcx> {
426     tcx: TyCtxt<'tcx>,
427 }
428
429 impl Visitor<'tcx> for Checker<'tcx> {
430     /// Because stability levels are scoped lexically, we want to walk
431     /// nested items in the context of the outer item, so enable
432     /// deep-walking.
433     fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
434         NestedVisitorMap::OnlyBodies(&self.tcx.hir())
435     }
436
437     fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) {
438         match item.kind {
439             hir::ItemKind::ExternCrate(_) => {
440                 // compiler-generated `extern crate` items have a dummy span.
441                 if item.span.is_dummy() {
442                     return;
443                 }
444
445                 let def_id = self.tcx.hir().local_def_id(item.hir_id);
446                 let cnum = match self.tcx.extern_mod_stmt_cnum(def_id) {
447                     Some(cnum) => cnum,
448                     None => return,
449                 };
450                 let def_id = DefId { krate: cnum, index: CRATE_DEF_INDEX };
451                 self.tcx.check_stability(def_id, Some(item.hir_id), item.span);
452             }
453
454             // For implementations of traits, check the stability of each item
455             // individually as it's possible to have a stable trait with unstable
456             // items.
457             hir::ItemKind::Impl(.., Some(ref t), _, impl_item_refs) => {
458                 if let Res::Def(DefKind::Trait, trait_did) = t.path.res {
459                     for impl_item_ref in impl_item_refs {
460                         let impl_item = self.tcx.hir().impl_item(impl_item_ref.id);
461                         let trait_item_def_id = self
462                             .tcx
463                             .associated_items(trait_did)
464                             .find(|item| item.ident.name == impl_item.ident.name)
465                             .map(|item| item.def_id);
466                         if let Some(def_id) = trait_item_def_id {
467                             // Pass `None` to skip deprecation warnings.
468                             self.tcx.check_stability(def_id, None, impl_item.span);
469                         }
470                     }
471                 }
472             }
473
474             // There's no good place to insert stability check for non-Copy unions,
475             // so semi-randomly perform it here in stability.rs
476             hir::ItemKind::Union(..) if !self.tcx.features().untagged_unions => {
477                 let def_id = self.tcx.hir().local_def_id(item.hir_id);
478                 let adt_def = self.tcx.adt_def(def_id);
479                 let ty = self.tcx.type_of(def_id);
480
481                 if adt_def.has_dtor(self.tcx) {
482                     feature_err(
483                         &self.tcx.sess.parse_sess,
484                         sym::untagged_unions,
485                         item.span,
486                         "unions with `Drop` implementations are unstable",
487                     )
488                     .emit();
489                 } else {
490                     let param_env = self.tcx.param_env(def_id);
491                     if !param_env.can_type_implement_copy(self.tcx, ty).is_ok() {
492                         feature_err(
493                             &self.tcx.sess.parse_sess,
494                             sym::untagged_unions,
495                             item.span,
496                             "unions with non-`Copy` fields are unstable",
497                         )
498                         .emit();
499                     }
500                 }
501             }
502
503             _ => (/* pass */),
504         }
505         intravisit::walk_item(self, item);
506     }
507
508     fn visit_path(&mut self, path: &'tcx hir::Path<'tcx>, id: hir::HirId) {
509         if let Some(def_id) = path.res.opt_def_id() {
510             self.tcx.check_stability(def_id, Some(id), path.span)
511         }
512         intravisit::walk_path(self, path)
513     }
514 }
515
516 /// Given the list of enabled features that were not language features (i.e., that
517 /// were expected to be library features), and the list of features used from
518 /// libraries, identify activated features that don't exist and error about them.
519 pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
520     let access_levels = &tcx.privacy_access_levels(LOCAL_CRATE);
521
522     if tcx.stability().staged_api[&LOCAL_CRATE] {
523         let krate = tcx.hir().krate();
524         let mut missing = MissingStabilityAnnotations { tcx, access_levels };
525         missing.check_missing_stability(hir::CRATE_HIR_ID, krate.span, "crate");
526         intravisit::walk_crate(&mut missing, krate);
527         krate.visit_all_item_likes(&mut missing.as_deep_visitor());
528     }
529
530     let declared_lang_features = &tcx.features().declared_lang_features;
531     let mut lang_features = FxHashSet::default();
532     for &(feature, span, since) in declared_lang_features {
533         if let Some(since) = since {
534             // Warn if the user has enabled an already-stable lang feature.
535             unnecessary_stable_feature_lint(tcx, span, feature, since);
536         }
537         if !lang_features.insert(feature) {
538             // Warn if the user enables a lang feature multiple times.
539             duplicate_feature_err(tcx.sess, span, feature);
540         }
541     }
542
543     let declared_lib_features = &tcx.features().declared_lib_features;
544     let mut remaining_lib_features = FxHashMap::default();
545     for (feature, span) in declared_lib_features {
546         if remaining_lib_features.contains_key(&feature) {
547             // Warn if the user enables a lib feature multiple times.
548             duplicate_feature_err(tcx.sess, *span, *feature);
549         }
550         remaining_lib_features.insert(feature, span.clone());
551     }
552     // `stdbuild` has special handling for `libc`, so we need to
553     // recognise the feature when building std.
554     // Likewise, libtest is handled specially, so `test` isn't
555     // available as we'd like it to be.
556     // FIXME: only remove `libc` when `stdbuild` is active.
557     // FIXME: remove special casing for `test`.
558     remaining_lib_features.remove(&Symbol::intern("libc"));
559     remaining_lib_features.remove(&sym::test);
560
561     let check_features = |remaining_lib_features: &mut FxHashMap<_, _>, defined_features: &[_]| {
562         for &(feature, since) in defined_features {
563             if let Some(since) = since {
564                 if let Some(span) = remaining_lib_features.get(&feature) {
565                     // Warn if the user has enabled an already-stable lib feature.
566                     unnecessary_stable_feature_lint(tcx, *span, feature, since);
567                 }
568             }
569             remaining_lib_features.remove(&feature);
570             if remaining_lib_features.is_empty() {
571                 break;
572             }
573         }
574     };
575
576     // We always collect the lib features declared in the current crate, even if there are
577     // no unknown features, because the collection also does feature attribute validation.
578     let local_defined_features = tcx.lib_features().to_vec();
579     if !remaining_lib_features.is_empty() {
580         check_features(&mut remaining_lib_features, &local_defined_features);
581
582         for &cnum in &*tcx.crates() {
583             if remaining_lib_features.is_empty() {
584                 break;
585             }
586             check_features(&mut remaining_lib_features, tcx.defined_lib_features(cnum));
587         }
588     }
589
590     for (feature, span) in remaining_lib_features {
591         struct_span_err!(tcx.sess, span, E0635, "unknown feature `{}`", feature).emit();
592     }
593
594     // FIXME(#44232): the `used_features` table no longer exists, so we
595     // don't lint about unused features. We should reenable this one day!
596 }
597
598 fn unnecessary_stable_feature_lint(tcx: TyCtxt<'_>, span: Span, feature: Symbol, since: Symbol) {
599     tcx.lint_hir(
600         lint::builtin::STABLE_FEATURES,
601         hir::CRATE_HIR_ID,
602         span,
603         &format!(
604             "the feature `{}` has been stable since {} and no longer requires \
605                   an attribute to enable",
606             feature, since
607         ),
608     );
609 }
610
611 fn duplicate_feature_err(sess: &Session, span: Span, feature: Symbol) {
612     struct_span_err!(sess, span, E0636, "the feature `{}` has already been declared", feature)
613         .emit();
614 }