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