]> git.lizzy.rs Git - rust.git/commitdiff
Fix note on macro outside current crate. Changed group to restricted
authorMichael A. Plikk <michael@aptoma.com>
Thu, 24 May 2018 17:26:04 +0000 (19:26 +0200)
committerMichael A. Plikk <michael@aptoma.com>
Thu, 24 May 2018 17:38:40 +0000 (19:38 +0200)
clippy_lints/src/lib.rs
clippy_lints/src/panic_unimplemented.rs
tests/run-pass/ice_exacte_size.rs
tests/ui/panic_unimplemented.rs
tests/ui/panic_unimplemented.stderr

index 1f9b2512d3be51e1691ee8e71659e06573565a9f..aaf2ef5738c34f45baf0423af60efd32ea746d66 100644 (file)
@@ -434,6 +434,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
         methods::WRONG_PUB_SELF_CONVENTION,
         misc::FLOAT_CMP_CONST,
         missing_doc::MISSING_DOCS_IN_PRIVATE_ITEMS,
+        panic_unimplemented::UNIMPLEMENTED,
         shadow::SHADOW_REUSE,
         shadow::SHADOW_SAME,
         shadow::SHADOW_UNRELATED,
@@ -627,7 +628,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
         open_options::NONSENSICAL_OPEN_OPTIONS,
         overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL,
         panic_unimplemented::PANIC_PARAMS,
-        panic_unimplemented::UNIMPLEMENTED,
         partialeq_ne_impl::PARTIALEQ_NE_IMPL,
         precedence::PRECEDENCE,
         ptr::CMP_NULL,
@@ -750,7 +750,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
         non_expressive_names::MANY_SINGLE_CHAR_NAMES,
         ok_if_let::IF_LET_SOME_RESULT,
         panic_unimplemented::PANIC_PARAMS,
-        panic_unimplemented::UNIMPLEMENTED,
         ptr::CMP_NULL,
         ptr::PTR_ARG,
         question_mark::QUESTION_MARK,
index 7f1b6775bab92f6db5ae9c5eb45d3d3bd7e48040..b257f5b3b940f9f34c2c988261661142e806d9f5 100644 (file)
@@ -2,6 +2,7 @@
 use rustc::lint::*;
 use syntax::ast::LitKind;
 use syntax::ptr::P;
+use syntax::ext::quote::rt::Span;
 use utils::{is_direct_expn_of, is_expn_of, match_def_path, opt_def_id, paths, resolve_node, span_lint};
 
 /// **What it does:** Checks for missing parameters in `panic!`.
@@ -35,7 +36,7 @@
 /// ```
 declare_clippy_lint! {
     pub UNIMPLEMENTED,
-    style,
+    restriction,
     "`unimplemented!` should not be present in production code"
 }
 
@@ -60,7 +61,8 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
             if params.len() == 2;
             then {
                 if is_expn_of(expr.span, "unimplemented").is_some() {
-                    span_lint(cx, UNIMPLEMENTED, expr.span,
+                    let span = get_outer_span(expr);
+                    span_lint(cx, UNIMPLEMENTED, span,
                               "`unimplemented` should not be present in production code");
                 } else {
                     match_panic(params, expr, cx);
@@ -70,6 +72,18 @@ fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr) {
     }
 }
 
+fn get_outer_span(expr: &Expr) -> Span {
+    if_chain! {
+        if let Some(first) = expr.span.ctxt().outer().expn_info();
+        if let Some(second) = first.call_site.ctxt().outer().expn_info();
+        then {
+            second.call_site
+        } else {
+            expr.span
+        }
+    }
+}
+
 fn match_panic(params: &P<[Expr]>, expr: &Expr, cx: &LateContext) {
     if_chain! {
         if let ExprLit(ref lit) = params[0].node;
index d99734810f533790d563bc883bbe2b9a583f1d71..914153c64fff9364720ff4643ed5ae5888d66ddf 100644 (file)
@@ -6,7 +6,6 @@
 impl Iterator for Foo {
     type Item = ();
 
-    #[allow(unimplemented)]
     fn next(&mut self) -> Option<()> {
         let _ = self.len() == 0;
         unimplemented!()
index 56d06f23904b52dc41719ca106eba8781205cf62..33050633f7fbae22e7564daa37673da9d3604a43 100644 (file)
@@ -54,7 +54,9 @@ fn ok_escaped() {
 }
 
 fn unimplemented() {
+    let a = 2;
     unimplemented!();
+    let b = a + 2;
 }
 
 fn main() {
index 534bfbae89b09d67f7797b526494b243a6965d15..3bf5589c46825675eb94839b3c55faa1bb84774e 100644 (file)
@@ -25,13 +25,12 @@ error: you probably are missing some parameter in your format string
    |            ^^^^^^^^^^^^
 
 error: `unimplemented` should not be present in production code
-  --> $DIR/panic_unimplemented.rs:57:5
+  --> $DIR/panic_unimplemented.rs:58:5
    |
-57 |     unimplemented!();
+58 |     unimplemented!();
    |     ^^^^^^^^^^^^^^^^^
    |
    = note: `-D unimplemented` implied by `-D warnings`
-   = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
 
 error: aborting due to 5 previous errors