]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc/lint/context.rs
rollup merge of #20482: kmcallister/macro-reform
[rust.git] / src / librustc / lint / context.rs
index d8d9d653e62f78b811ad10737aa8e70d5faa7407..5c0fd8944368f60da86abc2a3a85b2860e3de174 100644 (file)
@@ -26,7 +26,7 @@
 use self::TargetLint::*;
 
 use middle::privacy::ExportedItems;
-use middle::ty::{mod, Ty};
+use middle::ty::{self, Ty};
 use session::{early_error, Session};
 use lint::{Level, LevelSource, Lint, LintId, LintArray, LintPass, LintPassObject};
 use lint::{Default, CommandLine, Node, Allow, Warn, Deny, Forbid};
@@ -104,7 +104,7 @@ pub fn new() -> LintStore {
     }
 
     pub fn get_lints<'t>(&'t self) -> &'t [(&'static Lint, bool)] {
-        self.lints.as_slice()
+        self.lints[]
     }
 
     pub fn get_lint_groups<'t>(&'t self) -> Vec<(&'static str, Vec<LintId>, bool)> {
@@ -124,11 +124,11 @@ pub fn register_pass(&mut self, sess: Option<&Session>,
                 match (sess, from_plugin) {
                     // We load builtin lints first, so a duplicate is a compiler bug.
                     // Use early_error when handling -W help with no crate.
-                    (None, _) => early_error(msg.as_slice()),
-                    (Some(sess), false) => sess.bug(msg.as_slice()),
+                    (None, _) => early_error(msg[]),
+                    (Some(sess), false) => sess.bug(msg[]),
 
                     // A duplicate name from a plugin is a user error.
-                    (Some(sess), true)  => sess.err(msg.as_slice()),
+                    (Some(sess), true)  => sess.err(msg[]),
                 }
             }
 
@@ -149,11 +149,11 @@ pub fn register_group(&mut self, sess: Option<&Session>,
             match (sess, from_plugin) {
                 // We load builtin lints first, so a duplicate is a compiler bug.
                 // Use early_error when handling -W help with no crate.
-                (None, _) => early_error(msg.as_slice()),
-                (Some(sess), false) => sess.bug(msg.as_slice()),
+                (None, _) => early_error(msg[]),
+                (Some(sess), false) => sess.bug(msg[]),
 
                 // A duplicate name from a plugin is a user error.
-                (Some(sess), true)  => sess.err(msg.as_slice()),
+                (Some(sess), true)  => sess.err(msg[]),
             }
         }
     }
@@ -167,21 +167,27 @@ fn register_renamed(&mut self, old_name: &str, new_name: &str) {
     }
 
     pub fn register_builtin(&mut self, sess: Option<&Session>) {
-        macro_rules! add_builtin ( ( $sess:ident, $($name:ident),*, ) => (
-            {$(
-                self.register_pass($sess, false, box builtin::$name as LintPassObject);
-            )*}
-        ));
-
-        macro_rules! add_builtin_with_new ( ( $sess:ident, $($name:ident),*, ) => (
-            {$(
-                self.register_pass($sess, false, box builtin::$name::new() as LintPassObject);
-            )*}
-        ));
-
-        macro_rules! add_lint_group ( ( $sess:ident, $name:expr, $($lint:ident),* ) => (
-            self.register_group($sess, false, $name, vec![$(LintId::of(builtin::$lint)),*]);
-        ));
+        macro_rules! add_builtin {
+            ($sess:ident, $($name:ident),*,) => (
+                {$(
+                    self.register_pass($sess, false, box builtin::$name as LintPassObject);
+                )*}
+            )
+        }
+
+        macro_rules! add_builtin_with_new {
+            ($sess:ident, $($name:ident),*,) => (
+                {$(
+                    self.register_pass($sess, false, box builtin::$name::new() as LintPassObject);
+                )*}
+            )
+        }
+
+        macro_rules! add_lint_group {
+            ($sess:ident, $name:expr, $($lint:ident),*) => (
+                self.register_group($sess, false, $name, vec![$(LintId::of(builtin::$lint)),*]);
+            )
+        }
 
         add_builtin!(sess,
                      HardwiredLints,
@@ -208,7 +214,7 @@ macro_rules! add_lint_group ( ( $sess:ident, $name:expr, $($lint:ident),* ) => (
 
         add_builtin_with_new!(sess,
                               TypeLimits,
-                              RawPointerDeriving,
+                              RawPointerDerive,
                               MissingDoc,
         );
 
@@ -247,6 +253,7 @@ macro_rules! add_lint_group ( ( $sess:ident, $name:expr, $($lint:ident),* ) => (
         self.register_renamed("unknown_crate_type", "unknown_crate_types");
         self.register_renamed("variant_size_difference", "variant_size_differences");
         self.register_renamed("transmute_fat_ptr", "fat_ptr_transmutes");
+        self.register_renamed("raw_pointer_deriving", "raw_pointer_derive");
 
     }
 
@@ -260,8 +267,8 @@ fn find_lint(&self, lint_name: &str, sess: &Session, span: Option<Span>)
                 let warning = format!("lint {} has been renamed to {}",
                                       lint_name, new_name);
                 match span {
-                    Some(span) => sess.span_warn(span, warning.as_slice()),
-                    None => sess.warn(warning.as_slice()),
+                    Some(span) => sess.span_warn(span, warning[]),
+                    None => sess.warn(warning[]),
                 };
                 Some(lint_id)
             }
@@ -271,13 +278,13 @@ fn find_lint(&self, lint_name: &str, sess: &Session, span: Option<Span>)
 
     pub fn process_command_line(&mut self, sess: &Session) {
         for &(ref lint_name, level) in sess.opts.lint_opts.iter() {
-            match self.find_lint(lint_name.as_slice(), sess, None) {
+            match self.find_lint(lint_name[], sess, None) {
                 Some(lint_id) => self.set_level(lint_id, (level, CommandLine)),
                 None => {
                     match self.lint_groups.iter().map(|(&x, pair)| (x, pair.0.clone()))
                                                  .collect::<FnvHashMap<&'static str,
                                                                        Vec<LintId>>>()
-                                                 .get(lint_name.as_slice()) {
+                                                 .get(lint_name[]) {
                         Some(v) => {
                             v.iter()
                              .map(|lint_id: &LintId|
@@ -285,7 +292,7 @@ pub fn process_command_line(&mut self, sess: &Session) {
                              .collect::<Vec<()>>();
                         }
                         None => sess.err(format!("unknown {} flag: {}",
-                                                 level.as_str(), lint_name).as_slice()),
+                                                 level.as_str(), lint_name)[]),
                     }
                 }
             }
@@ -396,10 +403,10 @@ pub fn raw_emit_lint(sess: &Session, lint: &'static Lint,
     if level == Forbid { level = Deny; }
 
     match (level, span) {
-        (Warn, Some(sp)) => sess.span_warn(sp, msg.as_slice()),
-        (Warn, None)     => sess.warn(msg.as_slice()),
-        (Deny, Some(sp)) => sess.span_err(sp, msg.as_slice()),
-        (Deny, None)     => sess.err(msg.as_slice()),
+        (Warn, Some(sp)) => sess.span_warn(sp, msg[]),
+        (Warn, None)     => sess.warn(msg[]),
+        (Deny, Some(sp)) => sess.span_err(sp, msg[]),
+        (Deny, None)     => sess.err(msg[]),
         _ => sess.bug("impossible level in raw_emit_lint"),
     }
 
@@ -492,7 +499,7 @@ fn with_lint_attrs<F>(&mut self,
                                 None => {
                                     self.span_lint(builtin::UNKNOWN_LINTS, span,
                                                format!("unknown `{}` attribute: `{}`",
-                                                       level.as_str(), lint_name).as_slice());
+                                                       level.as_str(), lint_name)[]);
                                     continue;
                                 }
                             }
@@ -508,7 +515,7 @@ fn with_lint_attrs<F>(&mut self,
                     self.tcx.sess.span_err(span,
                                            format!("{}({}) overruled by outer forbid({})",
                                                    level.as_str(), lint_name,
-                                                   lint_name).as_slice());
+                                                   lint_name)[]);
                 } else if now != level {
                     let src = self.lints.get_level_source(lint_id).1;
                     self.level_stack.push((lint_id, (now, src)));
@@ -543,7 +550,7 @@ fn visit_ids<F>(&mut self, f: F) where
 
 impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
     fn visit_item(&mut self, it: &ast::Item) {
-        self.with_lint_attrs(it.attrs.as_slice(), |cx| {
+        self.with_lint_attrs(it.attrs[], |cx| {
             run_lints!(cx, check_item, it);
             cx.visit_ids(|v| v.visit_item(it));
             visit::walk_item(cx, it);
@@ -551,14 +558,14 @@ fn visit_item(&mut self, it: &ast::Item) {
     }
 
     fn visit_foreign_item(&mut self, it: &ast::ForeignItem) {
-        self.with_lint_attrs(it.attrs.as_slice(), |cx| {
+        self.with_lint_attrs(it.attrs[], |cx| {
             run_lints!(cx, check_foreign_item, it);
             visit::walk_foreign_item(cx, it);
         })
     }
 
     fn visit_view_item(&mut self, i: &ast::ViewItem) {
-        self.with_lint_attrs(i.attrs.as_slice(), |cx| {
+        self.with_lint_attrs(i.attrs[], |cx| {
             run_lints!(cx, check_view_item, i);
             cx.visit_ids(|v| v.visit_view_item(i));
             visit::walk_view_item(cx, i);
@@ -584,7 +591,7 @@ fn visit_fn(&mut self, fk: FnKind<'v>, decl: &'v ast::FnDecl,
                 body: &'v ast::Block, span: Span, id: ast::NodeId) {
         match fk {
             visit::FkMethod(_, _, m) => {
-                self.with_lint_attrs(m.attrs.as_slice(), |cx| {
+                self.with_lint_attrs(m.attrs[], |cx| {
                     run_lints!(cx, check_fn, fk, decl, body, span, id);
                     cx.visit_ids(|v| {
                         v.visit_fn(fk, decl, body, span, id);
@@ -600,7 +607,7 @@ fn visit_fn(&mut self, fk: FnKind<'v>, decl: &'v ast::FnDecl,
     }
 
     fn visit_ty_method(&mut self, t: &ast::TypeMethod) {
-        self.with_lint_attrs(t.attrs.as_slice(), |cx| {
+        self.with_lint_attrs(t.attrs[], |cx| {
             run_lints!(cx, check_ty_method, t);
             visit::walk_ty_method(cx, t);
         })
@@ -617,14 +624,14 @@ fn visit_struct_def(&mut self,
     }
 
     fn visit_struct_field(&mut self, s: &ast::StructField) {
-        self.with_lint_attrs(s.node.attrs.as_slice(), |cx| {
+        self.with_lint_attrs(s.node.attrs[], |cx| {
             run_lints!(cx, check_struct_field, s);
             visit::walk_struct_field(cx, s);
         })
     }
 
     fn visit_variant(&mut self, v: &ast::Variant, g: &ast::Generics) {
-        self.with_lint_attrs(v.node.attrs.as_slice(), |cx| {
+        self.with_lint_attrs(v.node.attrs[], |cx| {
             run_lints!(cx, check_variant, v, g);
             visit::walk_variant(cx, v, g);
             run_lints!(cx, check_variant_post, v, g);
@@ -718,7 +725,7 @@ fn visit_id(&mut self, id: ast::NodeId) {
             None => {}
             Some(lints) => {
                 for (lint_id, span, msg) in lints.into_iter() {
-                    self.span_lint(lint_id.lint, span, msg.as_slice())
+                    self.span_lint(lint_id.lint, span, msg[])
                 }
             }
         }
@@ -764,7 +771,7 @@ pub fn check_crate(tcx: &ty::ctxt,
     let mut cx = Context::new(tcx, krate, exported_items);
 
     // Visit the whole crate.
-    cx.with_lint_attrs(krate.attrs.as_slice(), |cx| {
+    cx.with_lint_attrs(krate.attrs[], |cx| {
         cx.visit_id(ast::CRATE_NODE_ID);
         cx.visit_ids(|v| {
             v.visited_outermost = true;
@@ -784,7 +791,7 @@ pub fn check_crate(tcx: &ty::ctxt,
         for &(lint, span, ref msg) in v.iter() {
             tcx.sess.span_bug(span,
                               format!("unprocessed lint {} at {}: {}",
-                                      lint.as_str(), tcx.map.node_to_string(*id), *msg).as_slice())
+                                      lint.as_str(), tcx.map.node_to_string(*id), *msg)[])
         }
     }