]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_ast_passes/src/feature_gate.rs
Auto merge of #80565 - camelid:fix-not-has, r=GuillaumeGomez
[rust.git] / compiler / rustc_ast_passes / src / feature_gate.rs
1 use rustc_ast as ast;
2 use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor};
3 use rustc_ast::{AssocTyConstraint, AssocTyConstraintKind, NodeId};
4 use rustc_ast::{PatKind, RangeEnd, VariantData};
5 use rustc_errors::struct_span_err;
6 use rustc_feature::{AttributeGate, BUILTIN_ATTRIBUTE_MAP};
7 use rustc_feature::{Features, GateIssue};
8 use rustc_session::parse::{feature_err, feature_err_issue};
9 use rustc_session::Session;
10 use rustc_span::source_map::Spanned;
11 use rustc_span::symbol::{sym, Symbol};
12 use rustc_span::Span;
13
14 use tracing::debug;
15
16 macro_rules! gate_feature_fn {
17     ($visitor: expr, $has_feature: expr, $span: expr, $name: expr, $explain: expr) => {{
18         let (visitor, has_feature, span, name, explain) =
19             (&*$visitor, $has_feature, $span, $name, $explain);
20         let has_feature: bool = has_feature(visitor.features);
21         debug!("gate_feature(feature = {:?}, span = {:?}); has? {}", name, span, has_feature);
22         if !has_feature && !span.allows_unstable($name) {
23             feature_err_issue(&visitor.sess.parse_sess, name, span, GateIssue::Language, explain)
24                 .emit();
25         }
26     }};
27 }
28
29 macro_rules! gate_feature_post {
30     ($visitor: expr, $feature: ident, $span: expr, $explain: expr) => {
31         gate_feature_fn!($visitor, |x: &Features| x.$feature, $span, sym::$feature, $explain)
32     };
33 }
34
35 pub fn check_attribute(attr: &ast::Attribute, sess: &Session, features: &Features) {
36     PostExpansionVisitor { sess, features }.visit_attribute(attr)
37 }
38
39 struct PostExpansionVisitor<'a> {
40     sess: &'a Session,
41
42     // `sess` contains a `Features`, but this might not be that one.
43     features: &'a Features,
44 }
45
46 impl<'a> PostExpansionVisitor<'a> {
47     fn check_abi(&self, abi: ast::StrLit) {
48         let ast::StrLit { symbol_unescaped, span, .. } = abi;
49
50         match &*symbol_unescaped.as_str() {
51             // Stable
52             "Rust" | "C" | "cdecl" | "stdcall" | "fastcall" | "aapcs" | "win64" | "sysv64"
53             | "system" => {}
54             "rust-intrinsic" => {
55                 gate_feature_post!(&self, intrinsics, span, "intrinsics are subject to change");
56             }
57             "platform-intrinsic" => {
58                 gate_feature_post!(
59                     &self,
60                     platform_intrinsics,
61                     span,
62                     "platform intrinsics are experimental and possibly buggy"
63                 );
64             }
65             "vectorcall" => {
66                 gate_feature_post!(
67                     &self,
68                     abi_vectorcall,
69                     span,
70                     "vectorcall is experimental and subject to change"
71                 );
72             }
73             "thiscall" => {
74                 gate_feature_post!(
75                     &self,
76                     abi_thiscall,
77                     span,
78                     "thiscall is experimental and subject to change"
79                 );
80             }
81             "rust-call" => {
82                 gate_feature_post!(
83                     &self,
84                     unboxed_closures,
85                     span,
86                     "rust-call ABI is subject to change"
87                 );
88             }
89             "ptx-kernel" => {
90                 gate_feature_post!(
91                     &self,
92                     abi_ptx,
93                     span,
94                     "PTX ABIs are experimental and subject to change"
95                 );
96             }
97             "unadjusted" => {
98                 gate_feature_post!(
99                     &self,
100                     abi_unadjusted,
101                     span,
102                     "unadjusted ABI is an implementation detail and perma-unstable"
103                 );
104             }
105             "msp430-interrupt" => {
106                 gate_feature_post!(
107                     &self,
108                     abi_msp430_interrupt,
109                     span,
110                     "msp430-interrupt ABI is experimental and subject to change"
111                 );
112             }
113             "x86-interrupt" => {
114                 gate_feature_post!(
115                     &self,
116                     abi_x86_interrupt,
117                     span,
118                     "x86-interrupt ABI is experimental and subject to change"
119                 );
120             }
121             "amdgpu-kernel" => {
122                 gate_feature_post!(
123                     &self,
124                     abi_amdgpu_kernel,
125                     span,
126                     "amdgpu-kernel ABI is experimental and subject to change"
127                 );
128             }
129             "avr-interrupt" | "avr-non-blocking-interrupt" => {
130                 gate_feature_post!(
131                     &self,
132                     abi_avr_interrupt,
133                     span,
134                     "avr-interrupt and avr-non-blocking-interrupt ABIs are experimental and subject to change"
135                 );
136             }
137             "efiapi" => {
138                 gate_feature_post!(
139                     &self,
140                     abi_efiapi,
141                     span,
142                     "efiapi ABI is experimental and subject to change"
143                 );
144             }
145             abi => self
146                 .sess
147                 .parse_sess
148                 .span_diagnostic
149                 .delay_span_bug(span, &format!("unrecognized ABI not caught in lowering: {}", abi)),
150         }
151     }
152
153     fn check_extern(&self, ext: ast::Extern) {
154         if let ast::Extern::Explicit(abi) = ext {
155             self.check_abi(abi);
156         }
157     }
158
159     fn maybe_report_invalid_custom_discriminants(&self, variants: &[ast::Variant]) {
160         let has_fields = variants.iter().any(|variant| match variant.data {
161             VariantData::Tuple(..) | VariantData::Struct(..) => true,
162             VariantData::Unit(..) => false,
163         });
164
165         let discriminant_spans = variants
166             .iter()
167             .filter(|variant| match variant.data {
168                 VariantData::Tuple(..) | VariantData::Struct(..) => false,
169                 VariantData::Unit(..) => true,
170             })
171             .filter_map(|variant| variant.disr_expr.as_ref().map(|c| c.value.span))
172             .collect::<Vec<_>>();
173
174         if !discriminant_spans.is_empty() && has_fields {
175             let mut err = feature_err(
176                 &self.sess.parse_sess,
177                 sym::arbitrary_enum_discriminant,
178                 discriminant_spans.clone(),
179                 "custom discriminant values are not allowed in enums with tuple or struct variants",
180             );
181             for sp in discriminant_spans {
182                 err.span_label(sp, "disallowed custom discriminant");
183             }
184             for variant in variants.iter() {
185                 match &variant.data {
186                     VariantData::Struct(..) => {
187                         err.span_label(variant.span, "struct variant defined here");
188                     }
189                     VariantData::Tuple(..) => {
190                         err.span_label(variant.span, "tuple variant defined here");
191                     }
192                     VariantData::Unit(..) => {}
193                 }
194             }
195             err.emit();
196         }
197     }
198
199     fn check_gat(&self, generics: &ast::Generics, span: Span) {
200         if !generics.params.is_empty() {
201             gate_feature_post!(
202                 &self,
203                 generic_associated_types,
204                 span,
205                 "generic associated types are unstable"
206             );
207         }
208         if !generics.where_clause.predicates.is_empty() {
209             gate_feature_post!(
210                 &self,
211                 generic_associated_types,
212                 span,
213                 "where clauses on associated types are unstable"
214             );
215         }
216     }
217
218     /// Feature gate `impl Trait` inside `type Alias = $type_expr;`.
219     fn check_impl_trait(&self, ty: &ast::Ty) {
220         struct ImplTraitVisitor<'a> {
221             vis: &'a PostExpansionVisitor<'a>,
222         }
223         impl Visitor<'_> for ImplTraitVisitor<'_> {
224             fn visit_ty(&mut self, ty: &ast::Ty) {
225                 if let ast::TyKind::ImplTrait(..) = ty.kind {
226                     gate_feature_post!(
227                         &self.vis,
228                         type_alias_impl_trait,
229                         ty.span,
230                         "`impl Trait` in type aliases is unstable"
231                     );
232                 }
233                 visit::walk_ty(self, ty);
234             }
235         }
236         ImplTraitVisitor { vis: self }.visit_ty(ty);
237     }
238 }
239
240 impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
241     fn visit_attribute(&mut self, attr: &ast::Attribute) {
242         let attr_info =
243             attr.ident().and_then(|ident| BUILTIN_ATTRIBUTE_MAP.get(&ident.name)).map(|a| **a);
244         // Check feature gates for built-in attributes.
245         if let Some((.., AttributeGate::Gated(_, name, descr, has_feature))) = attr_info {
246             gate_feature_fn!(self, has_feature, attr.span, name, descr);
247         }
248         // Check unstable flavors of the `#[doc]` attribute.
249         if self.sess.check_name(attr, sym::doc) {
250             for nested_meta in attr.meta_item_list().unwrap_or_default() {
251                 macro_rules! gate_doc { ($($name:ident => $feature:ident)*) => {
252                     $(if nested_meta.has_name(sym::$name) {
253                         let msg = concat!("`#[doc(", stringify!($name), ")]` is experimental");
254                         gate_feature_post!(self, $feature, attr.span, msg);
255                     })*
256                 }}
257
258                 gate_doc!(
259                     include => external_doc
260                     cfg => doc_cfg
261                     masked => doc_masked
262                     spotlight => doc_spotlight
263                     keyword => doc_keyword
264                 );
265             }
266         }
267     }
268
269     fn visit_name(&mut self, sp: Span, name: Symbol) {
270         if !name.as_str().is_ascii() {
271             gate_feature_post!(
272                 &self,
273                 non_ascii_idents,
274                 self.sess.parse_sess.source_map().guess_head_span(sp),
275                 "non-ascii idents are not fully supported"
276             );
277         }
278     }
279
280     fn visit_item(&mut self, i: &'a ast::Item) {
281         match i.kind {
282             ast::ItemKind::ForeignMod(ref foreign_module) => {
283                 if let Some(abi) = foreign_module.abi {
284                     self.check_abi(abi);
285                 }
286             }
287
288             ast::ItemKind::Fn(..) => {
289                 if self.sess.contains_name(&i.attrs[..], sym::plugin_registrar) {
290                     gate_feature_post!(
291                         &self,
292                         plugin_registrar,
293                         i.span,
294                         "compiler plugins are experimental and possibly buggy"
295                     );
296                 }
297                 if self.sess.contains_name(&i.attrs[..], sym::start) {
298                     gate_feature_post!(
299                         &self,
300                         start,
301                         i.span,
302                         "`#[start]` functions are experimental \
303                          and their signature may change \
304                          over time"
305                     );
306                 }
307                 if self.sess.contains_name(&i.attrs[..], sym::main) {
308                     gate_feature_post!(
309                         &self,
310                         main,
311                         i.span,
312                         "declaration of a non-standard `#[main]` \
313                          function may change over time, for now \
314                          a top-level `fn main()` is required"
315                     );
316                 }
317             }
318
319             ast::ItemKind::Struct(..) => {
320                 for attr in self.sess.filter_by_name(&i.attrs[..], sym::repr) {
321                     for item in attr.meta_item_list().unwrap_or_else(Vec::new) {
322                         if item.has_name(sym::simd) {
323                             gate_feature_post!(
324                                 &self,
325                                 repr_simd,
326                                 attr.span,
327                                 "SIMD types are experimental and possibly buggy"
328                             );
329                         }
330                     }
331                 }
332             }
333
334             ast::ItemKind::Enum(ast::EnumDef { ref variants, .. }, ..) => {
335                 for variant in variants {
336                     match (&variant.data, &variant.disr_expr) {
337                         (ast::VariantData::Unit(..), _) => {}
338                         (_, Some(disr_expr)) => gate_feature_post!(
339                             &self,
340                             arbitrary_enum_discriminant,
341                             disr_expr.value.span,
342                             "discriminants on non-unit variants are experimental"
343                         ),
344                         _ => {}
345                     }
346                 }
347
348                 let has_feature = self.features.arbitrary_enum_discriminant;
349                 if !has_feature && !i.span.allows_unstable(sym::arbitrary_enum_discriminant) {
350                     self.maybe_report_invalid_custom_discriminants(&variants);
351                 }
352             }
353
354             ast::ItemKind::Impl { polarity, defaultness, ref of_trait, .. } => {
355                 if let ast::ImplPolarity::Negative(span) = polarity {
356                     gate_feature_post!(
357                         &self,
358                         negative_impls,
359                         span.to(of_trait.as_ref().map(|t| t.path.span).unwrap_or(span)),
360                         "negative trait bounds are not yet fully implemented; \
361                          use marker types for now"
362                     );
363                 }
364
365                 if let ast::Defaultness::Default(_) = defaultness {
366                     gate_feature_post!(&self, specialization, i.span, "specialization is unstable");
367                 }
368             }
369
370             ast::ItemKind::Trait(ast::IsAuto::Yes, ..) => {
371                 gate_feature_post!(
372                     &self,
373                     auto_traits,
374                     i.span,
375                     "auto traits are experimental and possibly buggy"
376                 );
377             }
378
379             ast::ItemKind::TraitAlias(..) => {
380                 gate_feature_post!(&self, trait_alias, i.span, "trait aliases are experimental");
381             }
382
383             ast::ItemKind::MacroDef(ast::MacroDef { macro_rules: false, .. }) => {
384                 let msg = "`macro` is experimental";
385                 gate_feature_post!(&self, decl_macro, i.span, msg);
386             }
387
388             ast::ItemKind::TyAlias(_, _, _, Some(ref ty)) => self.check_impl_trait(&ty),
389
390             _ => {}
391         }
392
393         visit::walk_item(self, i);
394     }
395
396     fn visit_foreign_item(&mut self, i: &'a ast::ForeignItem) {
397         match i.kind {
398             ast::ForeignItemKind::Fn(..) | ast::ForeignItemKind::Static(..) => {
399                 let link_name = self.sess.first_attr_value_str_by_name(&i.attrs, sym::link_name);
400                 let links_to_llvm =
401                     link_name.map_or(false, |val| val.as_str().starts_with("llvm."));
402                 if links_to_llvm {
403                     gate_feature_post!(
404                         &self,
405                         link_llvm_intrinsics,
406                         i.span,
407                         "linking to LLVM intrinsics is experimental"
408                     );
409                 }
410             }
411             ast::ForeignItemKind::TyAlias(..) => {
412                 gate_feature_post!(&self, extern_types, i.span, "extern types are experimental");
413             }
414             ast::ForeignItemKind::MacCall(..) => {}
415         }
416
417         visit::walk_foreign_item(self, i)
418     }
419
420     fn visit_ty(&mut self, ty: &'a ast::Ty) {
421         match ty.kind {
422             ast::TyKind::BareFn(ref bare_fn_ty) => {
423                 self.check_extern(bare_fn_ty.ext);
424             }
425             ast::TyKind::Never => {
426                 gate_feature_post!(&self, never_type, ty.span, "the `!` type is experimental");
427             }
428             _ => {}
429         }
430         visit::walk_ty(self, ty)
431     }
432
433     fn visit_fn_ret_ty(&mut self, ret_ty: &'a ast::FnRetTy) {
434         if let ast::FnRetTy::Ty(ref output_ty) = *ret_ty {
435             if let ast::TyKind::Never = output_ty.kind {
436                 // Do nothing.
437             } else {
438                 self.visit_ty(output_ty)
439             }
440         }
441     }
442
443     fn visit_expr(&mut self, e: &'a ast::Expr) {
444         match e.kind {
445             ast::ExprKind::Box(_) => {
446                 gate_feature_post!(
447                     &self,
448                     box_syntax,
449                     e.span,
450                     "box expression syntax is experimental; you can call `Box::new` instead"
451                 );
452             }
453             ast::ExprKind::Type(..) => {
454                 // To avoid noise about type ascription in common syntax errors, only emit if it
455                 // is the *only* error.
456                 if self.sess.parse_sess.span_diagnostic.err_count() == 0 {
457                     gate_feature_post!(
458                         &self,
459                         type_ascription,
460                         e.span,
461                         "type ascription is experimental"
462                     );
463                 }
464             }
465             ast::ExprKind::TryBlock(_) => {
466                 gate_feature_post!(&self, try_blocks, e.span, "`try` expression is experimental");
467             }
468             ast::ExprKind::Block(_, opt_label) => {
469                 if let Some(label) = opt_label {
470                     gate_feature_post!(
471                         &self,
472                         label_break_value,
473                         label.ident.span,
474                         "labels on blocks are unstable"
475                     );
476                 }
477             }
478             _ => {}
479         }
480         visit::walk_expr(self, e)
481     }
482
483     fn visit_pat(&mut self, pattern: &'a ast::Pat) {
484         match &pattern.kind {
485             PatKind::Box(..) => {
486                 gate_feature_post!(
487                     &self,
488                     box_patterns,
489                     pattern.span,
490                     "box pattern syntax is experimental"
491                 );
492             }
493             PatKind::Range(_, _, Spanned { node: RangeEnd::Excluded, .. }) => {
494                 gate_feature_post!(
495                     &self,
496                     exclusive_range_pattern,
497                     pattern.span,
498                     "exclusive range pattern syntax is experimental"
499                 );
500             }
501             _ => {}
502         }
503         visit::walk_pat(self, pattern)
504     }
505
506     fn visit_fn(&mut self, fn_kind: FnKind<'a>, span: Span, _: NodeId) {
507         if let Some(header) = fn_kind.header() {
508             // Stability of const fn methods are covered in `visit_assoc_item` below.
509             self.check_extern(header.ext);
510
511             if let (ast::Const::Yes(_), ast::Extern::Implicit)
512             | (ast::Const::Yes(_), ast::Extern::Explicit(_)) = (header.constness, header.ext)
513             {
514                 gate_feature_post!(
515                     &self,
516                     const_extern_fn,
517                     span,
518                     "`const extern fn` definitions are unstable"
519                 );
520             }
521         }
522
523         if fn_kind.ctxt() != Some(FnCtxt::Foreign) && fn_kind.decl().c_variadic() {
524             gate_feature_post!(&self, c_variadic, span, "C-variadic functions are unstable");
525         }
526
527         visit::walk_fn(self, fn_kind, span)
528     }
529
530     fn visit_assoc_ty_constraint(&mut self, constraint: &'a AssocTyConstraint) {
531         if let AssocTyConstraintKind::Bound { .. } = constraint.kind {
532             gate_feature_post!(
533                 &self,
534                 associated_type_bounds,
535                 constraint.span,
536                 "associated type bounds are unstable"
537             )
538         }
539         visit::walk_assoc_ty_constraint(self, constraint)
540     }
541
542     fn visit_assoc_item(&mut self, i: &'a ast::AssocItem, ctxt: AssocCtxt) {
543         let is_fn = match i.kind {
544             ast::AssocItemKind::Fn(_, ref sig, _, _) => {
545                 if let (ast::Const::Yes(_), AssocCtxt::Trait) = (sig.header.constness, ctxt) {
546                     gate_feature_post!(&self, const_fn, i.span, "const fn is unstable");
547                 }
548                 true
549             }
550             ast::AssocItemKind::TyAlias(_, ref generics, _, ref ty) => {
551                 if let (Some(_), AssocCtxt::Trait) = (ty, ctxt) {
552                     gate_feature_post!(
553                         &self,
554                         associated_type_defaults,
555                         i.span,
556                         "associated type defaults are unstable"
557                     );
558                 }
559                 if let Some(ty) = ty {
560                     self.check_impl_trait(ty);
561                 }
562                 self.check_gat(generics, i.span);
563                 false
564             }
565             _ => false,
566         };
567         if let ast::Defaultness::Default(_) = i.kind.defaultness() {
568             // Limit `min_specialization` to only specializing functions.
569             gate_feature_fn!(
570                 &self,
571                 |x: &Features| x.specialization || (is_fn && x.min_specialization),
572                 i.span,
573                 sym::specialization,
574                 "specialization is unstable"
575             );
576         }
577         visit::walk_assoc_item(self, i, ctxt)
578     }
579
580     fn visit_vis(&mut self, vis: &'a ast::Visibility) {
581         if let ast::VisibilityKind::Crate(ast::CrateSugar::JustCrate) = vis.kind {
582             gate_feature_post!(
583                 &self,
584                 crate_visibility_modifier,
585                 vis.span,
586                 "`crate` visibility modifier is experimental"
587             );
588         }
589         visit::walk_vis(self, vis)
590     }
591 }
592
593 pub fn check_crate(krate: &ast::Crate, sess: &Session) {
594     maybe_stage_features(sess, krate);
595     check_incompatible_features(sess);
596     let mut visitor = PostExpansionVisitor { sess, features: &sess.features_untracked() };
597
598     let spans = sess.parse_sess.gated_spans.spans.borrow();
599     macro_rules! gate_all {
600         ($gate:ident, $msg:literal) => {
601             if let Some(spans) = spans.get(&sym::$gate) {
602                 for span in spans {
603                     gate_feature_post!(&visitor, $gate, *span, $msg);
604                 }
605             }
606         };
607     }
608     gate_all!(if_let_guard, "`if let` guards are experimental");
609     gate_all!(let_chains, "`let` expressions in this position are experimental");
610     gate_all!(async_closure, "async closures are unstable");
611     gate_all!(generators, "yield syntax is experimental");
612     gate_all!(or_patterns, "or-patterns syntax is experimental");
613     gate_all!(raw_ref_op, "raw address of syntax is experimental");
614     gate_all!(const_trait_bound_opt_out, "`?const` on trait bounds is experimental");
615     gate_all!(const_trait_impl, "const trait impls are experimental");
616     gate_all!(half_open_range_patterns, "half-open range patterns are unstable");
617     gate_all!(inline_const, "inline-const is experimental");
618     gate_all!(
619         extended_key_value_attributes,
620         "arbitrary expressions in key-value attributes are unstable"
621     );
622     gate_all!(
623         const_generics_defaults,
624         "default values for const generic parameters are experimental"
625     );
626     if sess.parse_sess.span_diagnostic.err_count() == 0 {
627         // Errors for `destructuring_assignment` can get quite noisy, especially where `_` is
628         // involved, so we only emit errors where there are no other parsing errors.
629         gate_all!(destructuring_assignment, "destructuring assignments are unstable");
630     }
631
632     // All uses of `gate_all!` below this point were added in #65742,
633     // and subsequently disabled (with the non-early gating readded).
634     macro_rules! gate_all {
635         ($gate:ident, $msg:literal) => {
636             // FIXME(eddyb) do something more useful than always
637             // disabling these uses of early feature-gatings.
638             if false {
639                 for span in spans.get(&sym::$gate).unwrap_or(&vec![]) {
640                     gate_feature_post!(&visitor, $gate, *span, $msg);
641                 }
642             }
643         };
644     }
645
646     gate_all!(trait_alias, "trait aliases are experimental");
647     gate_all!(associated_type_bounds, "associated type bounds are unstable");
648     gate_all!(crate_visibility_modifier, "`crate` visibility modifier is experimental");
649     gate_all!(const_generics, "const generics are unstable");
650     gate_all!(decl_macro, "`macro` is experimental");
651     gate_all!(box_patterns, "box pattern syntax is experimental");
652     gate_all!(exclusive_range_pattern, "exclusive range pattern syntax is experimental");
653     gate_all!(try_blocks, "`try` blocks are unstable");
654     gate_all!(label_break_value, "labels on blocks are unstable");
655     gate_all!(box_syntax, "box expression syntax is experimental; you can call `Box::new` instead");
656     // To avoid noise about type ascription in common syntax errors,
657     // only emit if it is the *only* error. (Also check it last.)
658     if sess.parse_sess.span_diagnostic.err_count() == 0 {
659         gate_all!(type_ascription, "type ascription is experimental");
660     }
661
662     visit::walk_crate(&mut visitor, krate);
663 }
664
665 fn maybe_stage_features(sess: &Session, krate: &ast::Crate) {
666     if !sess.opts.unstable_features.is_nightly_build() {
667         for attr in krate.attrs.iter().filter(|attr| sess.check_name(attr, sym::feature)) {
668             struct_span_err!(
669                 sess.parse_sess.span_diagnostic,
670                 attr.span,
671                 E0554,
672                 "`#![feature]` may not be used on the {} release channel",
673                 option_env!("CFG_RELEASE_CHANNEL").unwrap_or("(unknown)")
674             )
675             .emit();
676         }
677     }
678 }
679
680 fn check_incompatible_features(sess: &Session) {
681     let features = sess.features_untracked();
682
683     let declared_features = features
684         .declared_lang_features
685         .iter()
686         .copied()
687         .map(|(name, span, _)| (name, span))
688         .chain(features.declared_lib_features.iter().copied());
689
690     for (f1, f2) in rustc_feature::INCOMPATIBLE_FEATURES
691         .iter()
692         .filter(|&&(f1, f2)| features.enabled(f1) && features.enabled(f2))
693     {
694         if let Some((f1_name, f1_span)) = declared_features.clone().find(|(name, _)| name == f1) {
695             if let Some((f2_name, f2_span)) = declared_features.clone().find(|(name, _)| name == f2)
696             {
697                 let spans = vec![f1_span, f2_span];
698                 sess.struct_span_err(
699                     spans.clone(),
700                     &format!(
701                         "features `{}` and `{}` are incompatible, using them at the same time \
702                         is not allowed",
703                         f1_name, f2_name
704                     ),
705                 )
706                 .help("remove one of these features")
707                 .emit();
708             }
709         }
710     }
711 }