]> git.lizzy.rs Git - rust.git/blob - src/libsyntax/feature_gate.rs
rustc: Remove support for old_impl_check
[rust.git] / src / libsyntax / feature_gate.rs
1 // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 //! Feature gating
12 //!
13 //! This modules implements the gating necessary for preventing certain compiler
14 //! features from being used by default. This module will crawl a pre-expanded
15 //! AST to ensure that there are no features which are used that are not
16 //! enabled.
17 //!
18 //! Features are enabled in programs via the crate-level attributes of
19 //! `#![feature(...)]` with a comma-separated list of features.
20 //!
21 //! For the purpose of future feature-tracking, once code for detection of feature
22 //! gate usage is added, *do not remove it again* even once the feature
23 //! becomes stable.
24
25 use self::Status::*;
26 use self::AttributeType::*;
27
28 use abi::RustIntrinsic;
29 use ast::NodeId;
30 use ast;
31 use attr;
32 use attr::AttrMetaMethods;
33 use codemap::{CodeMap, Span};
34 use diagnostic::SpanHandler;
35 use visit;
36 use visit::Visitor;
37 use parse::token::{self, InternedString};
38
39 use std::ascii::AsciiExt;
40
41 // If you change this list without updating src/doc/reference.md, @cmr will be sad
42 // Don't ever remove anything from this list; set them to 'Removed'.
43 // The version numbers here correspond to the version in which the current status
44 // was set. This is most important for knowing when a particular feature became
45 // stable (active).
46 // NB: The featureck.py script parses this information directly out of the source
47 // so take care when modifying it.
48 const KNOWN_FEATURES: &'static [(&'static str, &'static str, Status)] = &[
49     ("globs", "1.0.0", Accepted),
50     ("macro_rules", "1.0.0", Accepted),
51     ("struct_variant", "1.0.0", Accepted),
52     ("asm", "1.0.0", Active),
53     ("managed_boxes", "1.0.0", Removed),
54     ("non_ascii_idents", "1.0.0", Active),
55     ("thread_local", "1.0.0", Active),
56     ("link_args", "1.0.0", Active),
57     ("phase", "1.0.0", Removed),
58     ("plugin_registrar", "1.0.0", Active),
59     ("log_syntax", "1.0.0", Active),
60     ("trace_macros", "1.0.0", Active),
61     ("concat_idents", "1.0.0", Active),
62     ("unsafe_destructor", "1.0.0", Active),
63     ("intrinsics", "1.0.0", Active),
64     ("lang_items", "1.0.0", Active),
65
66     ("simd", "1.0.0", Active),
67     ("default_type_params", "1.0.0", Accepted),
68     ("quote", "1.0.0", Active),
69     ("link_llvm_intrinsics", "1.0.0", Active),
70     ("linkage", "1.0.0", Active),
71     ("struct_inherit", "1.0.0", Removed),
72
73     ("quad_precision_float", "1.0.0", Removed),
74
75     ("rustc_diagnostic_macros", "1.0.0", Active),
76     ("unboxed_closures", "1.0.0", Active),
77     ("import_shadowing", "1.0.0", Removed),
78     ("advanced_slice_patterns", "1.0.0", Active),
79     ("tuple_indexing", "1.0.0", Accepted),
80     ("associated_types", "1.0.0", Accepted),
81     ("visible_private_types", "1.0.0", Active),
82     ("slicing_syntax", "1.0.0", Accepted),
83     ("box_syntax", "1.0.0", Active),
84     ("on_unimplemented", "1.0.0", Active),
85     ("simd_ffi", "1.0.0", Active),
86     ("allocator", "1.0.0", Active),
87
88     ("if_let", "1.0.0", Accepted),
89     ("while_let", "1.0.0", Accepted),
90
91     ("plugin", "1.0.0", Active),
92     ("start", "1.0.0", Active),
93     ("main", "1.0.0", Active),
94
95     // A temporary feature gate used to enable parser extensions needed
96     // to bootstrap fix for #5723.
97     ("issue_5723_bootstrap", "1.0.0", Accepted),
98
99     // A way to temporarily opt out of opt in copy. This will *never* be accepted.
100     ("opt_out_copy", "1.0.0", Removed),
101
102     // A way to temporarily opt out of the new orphan rules. This will *never* be accepted.
103     ("old_orphan_check", "1.0.0", Deprecated),
104
105     // OIBIT specific features
106     ("optin_builtin_traits", "1.0.0", Active),
107
108     // int and uint are now deprecated
109     ("int_uint", "1.0.0", Active),
110
111     // macro reexport needs more discussion and stabilization
112     ("macro_reexport", "1.0.0", Active),
113
114     // These are used to test this portion of the compiler, they don't actually
115     // mean anything
116     ("test_accepted_feature", "1.0.0", Accepted),
117     ("test_removed_feature", "1.0.0", Removed),
118
119     // Allows use of #[staged_api]
120     ("staged_api", "1.0.0", Active),
121
122     // Allows using items which are missing stability attributes
123     ("unmarked_api", "1.0.0", Active),
124
125     // Allows using #![no_std]
126     ("no_std", "1.0.0", Active),
127
128     // Allows using `box` in patterns; RFC 469
129     ("box_patterns", "1.0.0", Active),
130
131     // Allows using the unsafe_no_drop_flag attribute (unlikely to
132     // switch to Accepted; see RFC 320)
133     ("unsafe_no_drop_flag", "1.0.0", Active),
134
135     // Allows the use of custom attributes; RFC 572
136     ("custom_attribute", "1.0.0", Active),
137
138     // Allows the use of #[derive(Anything)] as sugar for
139     // #[derive_Anything].
140     ("custom_derive", "1.0.0", Active),
141
142     // Allows the use of rustc_* attributes; RFC 572
143     ("rustc_attrs", "1.0.0", Active),
144
145     // Allows the use of `static_assert`
146     ("static_assert", "1.0.0", Active),
147
148     // Allows the use of #[allow_internal_unstable]. This is an
149     // attribute on macro_rules! and can't use the attribute handling
150     // below (it has to be checked before expansion possibly makes
151     // macros disappear).
152     ("allow_internal_unstable", "1.0.0", Active),
153 ];
154 // (changing above list without updating src/doc/reference.md makes @cmr sad)
155
156 enum Status {
157     /// Represents an active feature that is currently being implemented or
158     /// currently being considered for addition/removal.
159     Active,
160
161     /// Represents a feature gate that is temporarily enabling deprecated behavior.
162     /// This gate will never be accepted.
163     Deprecated,
164
165     /// Represents a feature which has since been removed (it was once Active)
166     Removed,
167
168     /// This language feature has since been Accepted (it was once Active)
169     Accepted,
170 }
171
172 // Attributes that have a special meaning to rustc or rustdoc
173 pub const KNOWN_ATTRIBUTES: &'static [(&'static str, AttributeType)] = &[
174     // Normal attributes
175
176     ("warn", Normal),
177     ("allow", Normal),
178     ("forbid", Normal),
179     ("deny", Normal),
180
181     ("macro_reexport", Normal),
182     ("macro_use", Normal),
183     ("macro_export", Normal),
184     ("plugin_registrar", Normal),
185
186     ("cfg", Normal),
187     ("cfg_attr", Normal),
188     ("main", Normal),
189     ("start", Normal),
190     ("test", Normal),
191     ("bench", Normal),
192     ("simd", Normal),
193     ("repr", Normal),
194     ("path", Normal),
195     ("abi", Normal),
196     ("unsafe_destructor", Normal),
197     ("automatically_derived", Normal),
198     ("no_mangle", Normal),
199     ("no_link", Normal),
200     ("derive", Normal),
201     ("should_fail", Normal),
202     ("should_panic", Normal),
203     ("ignore", Normal),
204     ("no_implicit_prelude", Normal),
205     ("reexport_test_harness_main", Normal),
206     ("link_args", Normal),
207     ("macro_escape", Normal),
208
209
210     ("staged_api", Gated("staged_api",
211                          "staged_api is for use by rustc only")),
212     ("plugin", Gated("plugin",
213                      "compiler plugins are experimental \
214                       and possibly buggy")),
215     ("no_std", Gated("no_std",
216                      "no_std is experimental")),
217     ("lang", Gated("lang_items",
218                      "language items are subject to change")),
219     ("linkage", Gated("linkage",
220                       "the `linkage` attribute is experimental \
221                        and not portable across platforms")),
222     ("thread_local", Gated("thread_local",
223                             "`#[thread_local]` is an experimental feature, and does not \
224                              currently handle destructors. There is no corresponding \
225                              `#[task_local]` mapping to the task model")),
226
227     ("rustc_on_unimplemented", Gated("on_unimplemented",
228                                      "the `#[rustc_on_unimplemented]` attribute \
229                                       is an experimental feature")),
230     ("allocator", Gated("allocator",
231                         "the `#[allocator]` attribute is an experimental feature")),
232     ("rustc_variance", Gated("rustc_attrs",
233                              "the `#[rustc_variance]` attribute \
234                               is an experimental feature")),
235     ("rustc_error", Gated("rustc_attrs",
236                           "the `#[rustc_error]` attribute \
237                            is an experimental feature")),
238     ("rustc_move_fragments", Gated("rustc_attrs",
239                                    "the `#[rustc_move_fragments]` attribute \
240                                     is an experimental feature")),
241
242     ("allow_internal_unstable", Gated("allow_internal_unstable",
243                                       EXPLAIN_ALLOW_INTERNAL_UNSTABLE)),
244
245     // FIXME: #14408 whitelist docs since rustdoc looks at them
246     ("doc", Whitelisted),
247
248     // FIXME: #14406 these are processed in trans, which happens after the
249     // lint pass
250     ("cold", Whitelisted),
251     ("export_name", Whitelisted),
252     ("inline", Whitelisted),
253     ("link", Whitelisted),
254     ("link_name", Whitelisted),
255     ("link_section", Whitelisted),
256     ("no_builtins", Whitelisted),
257     ("no_mangle", Whitelisted),
258     ("no_stack_check", Whitelisted),
259     ("packed", Whitelisted),
260     ("static_assert", Gated("static_assert",
261                             "`#[static_assert]` is an experimental feature, and has a poor API")),
262     ("no_debug", Whitelisted),
263     ("omit_gdb_pretty_printer_section", Whitelisted),
264     ("unsafe_no_drop_flag", Gated("unsafe_no_drop_flag",
265                                   "unsafe_no_drop_flag has unstable semantics \
266                                    and may be removed in the future")),
267
268     // used in resolve
269     ("prelude_import", Whitelisted),
270
271     // FIXME: #14407 these are only looked at on-demand so we can't
272     // guarantee they'll have already been checked
273     ("deprecated", Whitelisted),
274     ("must_use", Whitelisted),
275     ("stable", Whitelisted),
276     ("unstable", Whitelisted),
277
278     // FIXME: #19470 this shouldn't be needed forever
279     ("old_orphan_check", Whitelisted),
280     ("rustc_paren_sugar", Whitelisted), // FIXME: #18101 temporary unboxed closure hack
281
282     // Crate level attributes
283     ("crate_name", CrateLevel),
284     ("crate_type", CrateLevel),
285     ("crate_id", CrateLevel),
286     ("feature", CrateLevel),
287     ("no_start", CrateLevel),
288     ("no_main", CrateLevel),
289     ("no_builtins", CrateLevel),
290     ("recursion_limit", CrateLevel),
291 ];
292
293 #[derive(PartialEq, Copy, Debug)]
294 pub enum AttributeType {
295     /// Normal, builtin attribute that is consumed
296     /// by the compiler before the unused_attribute check
297     Normal,
298
299     /// Builtin attribute that may not be consumed by the compiler
300     /// before the unused_attribute check. These attributes
301     /// will be ignored by the unused_attribute lint
302     Whitelisted,
303
304     /// Is gated by a given feature gate and reason
305     /// These get whitelisted too
306     Gated(&'static str, &'static str),
307
308     /// Builtin attribute that is only allowed at the crate level
309     CrateLevel,
310 }
311
312 /// A set of features to be used by later passes.
313 pub struct Features {
314     pub unboxed_closures: bool,
315     pub rustc_diagnostic_macros: bool,
316     pub visible_private_types: bool,
317     pub allow_quote: bool,
318     pub allow_asm: bool,
319     pub allow_log_syntax: bool,
320     pub allow_concat_idents: bool,
321     pub allow_trace_macros: bool,
322     pub allow_internal_unstable: bool,
323     pub allow_custom_derive: bool,
324     pub old_orphan_check: bool,
325     pub simd_ffi: bool,
326     pub unmarked_api: bool,
327     /// spans of #![feature] attrs for stable language features. for error reporting
328     pub declared_stable_lang_features: Vec<Span>,
329     /// #![feature] attrs for non-language (library) features
330     pub declared_lib_features: Vec<(InternedString, Span)>
331 }
332
333 impl Features {
334     pub fn new() -> Features {
335         Features {
336             unboxed_closures: false,
337             rustc_diagnostic_macros: false,
338             visible_private_types: false,
339             allow_quote: false,
340             allow_asm: false,
341             allow_log_syntax: false,
342             allow_concat_idents: false,
343             allow_trace_macros: false,
344             allow_internal_unstable: false,
345             allow_custom_derive: false,
346             old_orphan_check: false,
347             simd_ffi: false,
348             unmarked_api: false,
349             declared_stable_lang_features: Vec::new(),
350             declared_lib_features: Vec::new()
351         }
352     }
353 }
354
355 struct Context<'a> {
356     features: Vec<&'static str>,
357     span_handler: &'a SpanHandler,
358     cm: &'a CodeMap,
359     do_warnings: bool,
360 }
361
362 impl<'a> Context<'a> {
363     fn gate_feature(&self, feature: &str, span: Span, explain: &str) {
364         let has_feature = self.has_feature(feature);
365         debug!("gate_feature(feature = {:?}, span = {:?}); has? {}", feature, span, has_feature);
366         if !has_feature {
367             emit_feature_err(self.span_handler, feature, span, explain);
368         }
369     }
370
371     fn warn_feature(&self, feature: &str, span: Span, explain: &str) {
372         if !self.has_feature(feature) && self.do_warnings {
373             emit_feature_warn(self.span_handler, feature, span, explain);
374         }
375     }
376     fn has_feature(&self, feature: &str) -> bool {
377         self.features.iter().any(|&n| n == feature)
378     }
379
380     fn check_attribute(&self, attr: &ast::Attribute) {
381         debug!("check_attribute(attr = {:?})", attr);
382         let name = &*attr.name();
383         for &(n, ty) in KNOWN_ATTRIBUTES {
384             if n == name {
385                 if let Gated(gate, desc) = ty {
386                     self.gate_feature(gate, attr.span, desc);
387                 }
388                 debug!("check_attribute: {:?} is known, {:?}", name, ty);
389                 return;
390             }
391         }
392         if name.starts_with("rustc_") {
393             self.gate_feature("rustc_attrs", attr.span,
394                               "unless otherwise specified, attributes \
395                                with the prefix `rustc_` \
396                                are reserved for internal compiler diagnostics");
397         } else if name.starts_with("derive_") {
398             self.gate_feature("custom_derive", attr.span,
399                               "attributes of the form `#[derive_*]` are reserved
400                                for the compiler");
401         } else {
402             self.gate_feature("custom_attribute", attr.span,
403                        &format!("The attribute `{}` is currently \
404                                 unknown to the the compiler and \
405                                 may have meaning \
406                                 added to it in the future",
407                                 name));
408         }
409     }
410 }
411
412 pub fn emit_feature_err(diag: &SpanHandler, feature: &str, span: Span, explain: &str) {
413     diag.span_err(span, explain);
414     diag.fileline_help(span, &format!("add #![feature({})] to the \
415                                    crate attributes to enable",
416                                   feature));
417 }
418
419 pub fn emit_feature_warn(diag: &SpanHandler, feature: &str, span: Span, explain: &str) {
420     diag.span_warn(span, explain);
421     if diag.handler.can_emit_warnings {
422         diag.fileline_help(span, &format!("add #![feature({})] to the \
423                                        crate attributes to silence this warning",
424                                       feature));
425     }
426 }
427
428 pub const EXPLAIN_ASM: &'static str =
429     "inline assembly is not stable enough for use and is subject to change";
430
431 pub const EXPLAIN_LOG_SYNTAX: &'static str =
432     "`log_syntax!` is not stable enough for use and is subject to change";
433
434 pub const EXPLAIN_CONCAT_IDENTS: &'static str =
435     "`concat_idents` is not stable enough for use and is subject to change";
436
437 pub const EXPLAIN_TRACE_MACROS: &'static str =
438     "`trace_macros` is not stable enough for use and is subject to change";
439 pub const EXPLAIN_ALLOW_INTERNAL_UNSTABLE: &'static str =
440     "allow_internal_unstable side-steps feature gating and stability checks";
441
442 pub const EXPLAIN_CUSTOM_DERIVE: &'static str =
443     "`#[derive]` for custom traits is not stable enough for use and is subject to change";
444
445 struct MacroVisitor<'a> {
446     context: &'a Context<'a>
447 }
448
449 impl<'a, 'v> Visitor<'v> for MacroVisitor<'a> {
450     fn visit_mac(&mut self, mac: &ast::Mac) {
451         let ast::MacInvocTT(ref path, _, _) = mac.node;
452         let id = path.segments.last().unwrap().identifier;
453
454         // Issue 22234: If you add a new case here, make sure to also
455         // add code to catch the macro during or after expansion.
456         //
457         // We still keep this MacroVisitor (rather than *solely*
458         // relying on catching cases during or after expansion) to
459         // catch uses of these macros within conditionally-compiled
460         // code, e.g. `#[cfg]`-guarded functions.
461
462         if id == token::str_to_ident("asm") {
463             self.context.gate_feature("asm", path.span, EXPLAIN_ASM);
464         }
465
466         else if id == token::str_to_ident("log_syntax") {
467             self.context.gate_feature("log_syntax", path.span, EXPLAIN_LOG_SYNTAX);
468         }
469
470         else if id == token::str_to_ident("trace_macros") {
471             self.context.gate_feature("trace_macros", path.span, EXPLAIN_TRACE_MACROS);
472         }
473
474         else if id == token::str_to_ident("concat_idents") {
475             self.context.gate_feature("concat_idents", path.span, EXPLAIN_CONCAT_IDENTS);
476         }
477     }
478
479     fn visit_attribute(&mut self, attr: &'v ast::Attribute) {
480         self.context.check_attribute(attr);
481     }
482 }
483
484 struct PostExpansionVisitor<'a> {
485     context: &'a Context<'a>
486 }
487
488 impl<'a> PostExpansionVisitor<'a> {
489     fn gate_feature(&self, feature: &str, span: Span, explain: &str) {
490         if !self.context.cm.span_allows_unstable(span) {
491             self.context.gate_feature(feature, span, explain)
492         }
493     }
494 }
495
496 impl<'a, 'v> Visitor<'v> for PostExpansionVisitor<'a> {
497     fn visit_attribute(&mut self, attr: &ast::Attribute) {
498         if !self.context.cm.span_allows_unstable(attr.span) {
499             self.context.check_attribute(attr);
500         }
501     }
502
503     fn visit_name(&mut self, sp: Span, name: ast::Name) {
504         if !token::get_name(name).is_ascii() {
505             self.gate_feature("non_ascii_idents", sp,
506                               "non-ascii idents are not fully supported.");
507         }
508     }
509
510     fn visit_item(&mut self, i: &ast::Item) {
511         match i.node {
512             ast::ItemExternCrate(_) => {
513                 if attr::contains_name(&i.attrs[..], "macro_reexport") {
514                     self.gate_feature("macro_reexport", i.span,
515                                       "macros reexports are experimental \
516                                        and possibly buggy");
517                 }
518             }
519
520             ast::ItemForeignMod(ref foreign_module) => {
521                 if attr::contains_name(&i.attrs[..], "link_args") {
522                     self.gate_feature("link_args", i.span,
523                                       "the `link_args` attribute is not portable \
524                                        across platforms, it is recommended to \
525                                        use `#[link(name = \"foo\")]` instead")
526                 }
527                 if foreign_module.abi == RustIntrinsic {
528                     self.gate_feature("intrinsics",
529                                       i.span,
530                                       "intrinsics are subject to change")
531                 }
532             }
533
534             ast::ItemFn(..) => {
535                 if attr::contains_name(&i.attrs[..], "plugin_registrar") {
536                     self.gate_feature("plugin_registrar", i.span,
537                                       "compiler plugins are experimental and possibly buggy");
538                 }
539                 if attr::contains_name(&i.attrs[..], "start") {
540                     self.gate_feature("start", i.span,
541                                       "a #[start] function is an experimental \
542                                        feature whose signature may change \
543                                        over time");
544                 }
545                 if attr::contains_name(&i.attrs[..], "main") {
546                     self.gate_feature("main", i.span,
547                                       "declaration of a nonstandard #[main] \
548                                        function may change over time, for now \
549                                        a top-level `fn main()` is required");
550                 }
551             }
552
553             ast::ItemStruct(..) => {
554                 if attr::contains_name(&i.attrs[..], "simd") {
555                     self.gate_feature("simd", i.span,
556                                       "SIMD types are experimental and possibly buggy");
557                 }
558             }
559
560             ast::ItemDefaultImpl(..) => {
561                 self.gate_feature("optin_builtin_traits",
562                                   i.span,
563                                   "default trait implementations are experimental \
564                                    and possibly buggy");
565             }
566
567             ast::ItemImpl(_, polarity, _, _, _, _) => {
568                 match polarity {
569                     ast::ImplPolarity::Negative => {
570                         self.gate_feature("optin_builtin_traits",
571                                           i.span,
572                                           "negative trait bounds are not yet fully implemented; \
573                                           use marker types for now");
574                     },
575                     _ => {}
576                 }
577
578                 if attr::contains_name(&i.attrs,
579                                        "unsafe_destructor") {
580                     self.gate_feature("unsafe_destructor",
581                                       i.span,
582                                       "`#[unsafe_destructor]` allows too \
583                                        many unsafe patterns and may be \
584                                        removed in the future");
585                 }
586
587                 if attr::contains_name(&i.attrs[..],
588                                        "old_orphan_check") {
589                     self.gate_feature(
590                         "old_orphan_check",
591                         i.span,
592                         "the new orphan check rules will eventually be strictly enforced");
593                 }
594             }
595
596             _ => {}
597         }
598
599         visit::walk_item(self, i);
600     }
601
602     fn visit_foreign_item(&mut self, i: &ast::ForeignItem) {
603         let links_to_llvm = match attr::first_attr_value_str_by_name(&i.attrs,
604                                                                      "link_name") {
605             Some(val) => val.starts_with("llvm."),
606             _ => false
607         };
608         if links_to_llvm {
609             self.gate_feature("link_llvm_intrinsics", i.span,
610                               "linking to LLVM intrinsics is experimental");
611         }
612
613         visit::walk_foreign_item(self, i)
614     }
615
616     fn visit_ty(&mut self, t: &ast::Ty) {
617         match t.node {
618             ast::TyPath(None, ref p) => {
619                 match &*p.segments {
620
621                     [ast::PathSegment { identifier, .. }] => {
622                         let name = token::get_ident(identifier);
623                         let msg = if name == "int" {
624                             Some("the `int` type is deprecated; \
625                                   use `isize` or a fixed-sized integer")
626                         } else if name == "uint" {
627                             Some("the `uint` type is deprecated; \
628                                   use `usize` or a fixed-sized integer")
629                         } else {
630                             None
631                         };
632
633                         if let Some(msg) = msg {
634                             self.context.warn_feature("int_uint", t.span, msg)
635                         }
636                     }
637                     _ => {}
638                 }
639             }
640             _ => {}
641         }
642         visit::walk_ty(self, t);
643     }
644
645     fn visit_expr(&mut self, e: &ast::Expr) {
646         match e.node {
647             ast::ExprBox(..) | ast::ExprUnary(ast::UnOp::UnUniq, _) => {
648                 self.gate_feature("box_syntax",
649                                   e.span,
650                                   "box expression syntax is experimental; \
651                                    you can call `Box::new` instead.");
652             }
653             ast::ExprLit(ref lit) => {
654                 match lit.node {
655                     ast::LitInt(_, ty) => {
656                         let msg = if let ast::SignedIntLit(ast::TyIs(true), _) = ty {
657                             Some("the `i` and `is` suffixes on integers are deprecated; \
658                                   use `isize` or one of the fixed-sized suffixes")
659                         } else if let ast::UnsignedIntLit(ast::TyUs(true)) = ty {
660                             Some("the `u` and `us` suffixes on integers are deprecated; \
661                                   use `usize` or one of the fixed-sized suffixes")
662                         } else {
663                             None
664                         };
665                         if let Some(msg) = msg {
666                             self.context.warn_feature("int_uint", e.span, msg);
667                         }
668                     }
669                     _ => {}
670                 }
671             }
672             _ => {}
673         }
674         visit::walk_expr(self, e);
675     }
676
677     fn visit_pat(&mut self, pattern: &ast::Pat) {
678         match pattern.node {
679             ast::PatVec(_, Some(_), ref last) if !last.is_empty() => {
680                 self.gate_feature("advanced_slice_patterns",
681                                   pattern.span,
682                                   "multiple-element slice matches anywhere \
683                                    but at the end of a slice (e.g. \
684                                    `[0, ..xs, 0]` are experimental")
685             }
686             ast::PatBox(..) => {
687                 self.gate_feature("box_patterns",
688                                   pattern.span,
689                                   "box pattern syntax is experimental");
690             }
691             _ => {}
692         }
693         visit::walk_pat(self, pattern)
694     }
695
696     fn visit_fn(&mut self,
697                 fn_kind: visit::FnKind<'v>,
698                 fn_decl: &'v ast::FnDecl,
699                 block: &'v ast::Block,
700                 span: Span,
701                 _node_id: NodeId) {
702         match fn_kind {
703             visit::FkItemFn(_, _, _, abi) if abi == RustIntrinsic => {
704                 self.gate_feature("intrinsics",
705                                   span,
706                                   "intrinsics are subject to change")
707             }
708             _ => {}
709         }
710         visit::walk_fn(self, fn_kind, fn_decl, block, span);
711     }
712 }
713
714 fn check_crate_inner<F>(cm: &CodeMap, span_handler: &SpanHandler, krate: &ast::Crate,
715                         do_warnings: bool,
716                         check: F)
717                        -> Features
718     where F: FnOnce(&mut Context, &ast::Crate)
719 {
720     let mut cx = Context {
721         features: Vec::new(),
722         span_handler: span_handler,
723         do_warnings: do_warnings,
724         cm: cm,
725     };
726
727     let mut accepted_features = Vec::new();
728     let mut unknown_features = Vec::new();
729
730     for attr in &krate.attrs {
731         if !attr.check_name("feature") {
732             continue
733         }
734
735         match attr.meta_item_list() {
736             None => {
737                 span_handler.span_err(attr.span, "malformed feature attribute, \
738                                                   expected #![feature(...)]");
739             }
740             Some(list) => {
741                 for mi in list {
742                     let name = match mi.node {
743                         ast::MetaWord(ref word) => (*word).clone(),
744                         _ => {
745                             span_handler.span_err(mi.span,
746                                                   "malformed feature, expected just \
747                                                    one word");
748                             continue
749                         }
750                     };
751                     match KNOWN_FEATURES.iter()
752                                         .find(|& &(n, _, _)| name == n) {
753                         Some(&(name, _, Active)) => {
754                             cx.features.push(name);
755                         }
756                         Some(&(name, _, Deprecated)) => {
757                             cx.features.push(name);
758                             span_handler.span_warn(
759                                 mi.span,
760                                 "feature is deprecated and will only be available \
761                                  for a limited time, please rewrite code that relies on it");
762                         }
763                         Some(&(_, _, Removed)) => {
764                             span_handler.span_err(mi.span, "feature has been removed");
765                         }
766                         Some(&(_, _, Accepted)) => {
767                             accepted_features.push(mi.span);
768                         }
769                         None => {
770                             unknown_features.push((name, mi.span));
771                         }
772                     }
773                 }
774             }
775         }
776     }
777
778     check(&mut cx, krate);
779
780     // FIXME (pnkfelix): Before adding the 99th entry below, change it
781     // to a single-pass (instead of N calls to `.has_feature`).
782
783     Features {
784         unboxed_closures: cx.has_feature("unboxed_closures"),
785         rustc_diagnostic_macros: cx.has_feature("rustc_diagnostic_macros"),
786         visible_private_types: cx.has_feature("visible_private_types"),
787         allow_quote: cx.has_feature("quote"),
788         allow_asm: cx.has_feature("asm"),
789         allow_log_syntax: cx.has_feature("log_syntax"),
790         allow_concat_idents: cx.has_feature("concat_idents"),
791         allow_trace_macros: cx.has_feature("trace_macros"),
792         allow_internal_unstable: cx.has_feature("allow_internal_unstable"),
793         allow_custom_derive: cx.has_feature("custom_derive"),
794         old_orphan_check: cx.has_feature("old_orphan_check"),
795         simd_ffi: cx.has_feature("simd_ffi"),
796         unmarked_api: cx.has_feature("unmarked_api"),
797         declared_stable_lang_features: accepted_features,
798         declared_lib_features: unknown_features
799     }
800 }
801
802 pub fn check_crate_macros(cm: &CodeMap, span_handler: &SpanHandler, krate: &ast::Crate)
803 -> Features {
804     check_crate_inner(cm, span_handler, krate, true,
805                       |ctx, krate| visit::walk_crate(&mut MacroVisitor { context: ctx }, krate))
806 }
807
808 pub fn check_crate(cm: &CodeMap, span_handler: &SpanHandler, krate: &ast::Crate,
809                    do_warnings: bool) -> Features
810 {
811     check_crate_inner(cm, span_handler, krate, do_warnings,
812                       |ctx, krate| visit::walk_crate(&mut PostExpansionVisitor { context: ctx },
813                                                      krate))
814 }