Skip to content

Commit

Permalink
Fix note on macro outside current crate. Changed group to restricted
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael A. Plikk committed May 24, 2018
1 parent dc8d29b commit 1f10dd2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 8 deletions.
3 changes: 1 addition & 2 deletions clippy_lints/src/lib.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 16 additions & 2 deletions clippy_lints/src/panic_unimplemented.rs
Expand Up @@ -2,6 +2,7 @@ use rustc::hir::*;
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!`.
Expand Down Expand Up @@ -35,7 +36,7 @@ declare_clippy_lint! {
/// ```
declare_clippy_lint! {
pub UNIMPLEMENTED,
style,
restriction,
"`unimplemented!` should not be present in production code"
}

Expand All @@ -60,7 +61,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
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);
Expand All @@ -70,6 +72,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
}
}

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;
Expand Down
1 change: 0 additions & 1 deletion tests/run-pass/ice_exacte_size.rs
Expand Up @@ -6,7 +6,6 @@ struct Foo;
impl Iterator for Foo {
type Item = ();

#[allow(unimplemented)]
fn next(&mut self) -> Option<()> {
let _ = self.len() == 0;
unimplemented!()
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/panic_unimplemented.rs
Expand Up @@ -54,7 +54,9 @@ fn ok_escaped() {
}

fn unimplemented() {
let a = 2;
unimplemented!();
let b = a + 2;
}

fn main() {
Expand Down
5 changes: 2 additions & 3 deletions tests/ui/panic_unimplemented.stderr
Expand Up @@ -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

0 comments on commit 1f10dd2

Please sign in to comment.