Skip to content

Commit 1f10dd2

Browse files
author
Michael A. Plikk
committed
Fix note on macro outside current crate. Changed group to restricted
1 parent dc8d29b commit 1f10dd2

File tree

5 files changed

+21
-8
lines changed

5 files changed

+21
-8
lines changed

clippy_lints/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
434434
methods::WRONG_PUB_SELF_CONVENTION,
435435
misc::FLOAT_CMP_CONST,
436436
missing_doc::MISSING_DOCS_IN_PRIVATE_ITEMS,
437+
panic_unimplemented::UNIMPLEMENTED,
437438
shadow::SHADOW_REUSE,
438439
shadow::SHADOW_SAME,
439440
shadow::SHADOW_UNRELATED,
@@ -627,7 +628,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
627628
open_options::NONSENSICAL_OPEN_OPTIONS,
628629
overflow_check_conditional::OVERFLOW_CHECK_CONDITIONAL,
629630
panic_unimplemented::PANIC_PARAMS,
630-
panic_unimplemented::UNIMPLEMENTED,
631631
partialeq_ne_impl::PARTIALEQ_NE_IMPL,
632632
precedence::PRECEDENCE,
633633
ptr::CMP_NULL,
@@ -750,7 +750,6 @@ pub fn register_plugins(reg: &mut rustc_plugin::Registry) {
750750
non_expressive_names::MANY_SINGLE_CHAR_NAMES,
751751
ok_if_let::IF_LET_SOME_RESULT,
752752
panic_unimplemented::PANIC_PARAMS,
753-
panic_unimplemented::UNIMPLEMENTED,
754753
ptr::CMP_NULL,
755754
ptr::PTR_ARG,
756755
question_mark::QUESTION_MARK,

clippy_lints/src/panic_unimplemented.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use rustc::hir::*;
22
use rustc::lint::*;
33
use syntax::ast::LitKind;
44
use syntax::ptr::P;
5+
use syntax::ext::quote::rt::Span;
56
use utils::{is_direct_expn_of, is_expn_of, match_def_path, opt_def_id, paths, resolve_node, span_lint};
67

78
/// **What it does:** Checks for missing parameters in `panic!`.
@@ -35,7 +36,7 @@ declare_clippy_lint! {
3536
/// ```
3637
declare_clippy_lint! {
3738
pub UNIMPLEMENTED,
38-
style,
39+
restriction,
3940
"`unimplemented!` should not be present in production code"
4041
}
4142

@@ -60,7 +61,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
6061
if params.len() == 2;
6162
then {
6263
if is_expn_of(expr.span, "unimplemented").is_some() {
63-
span_lint(cx, UNIMPLEMENTED, expr.span,
64+
let span = get_outer_span(expr);
65+
span_lint(cx, UNIMPLEMENTED, span,
6466
"`unimplemented` should not be present in production code");
6567
} else {
6668
match_panic(params, expr, cx);
@@ -70,6 +72,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
7072
}
7173
}
7274

75+
fn get_outer_span(expr: &Expr) -> Span {
76+
if_chain! {
77+
if let Some(first) = expr.span.ctxt().outer().expn_info();
78+
if let Some(second) = first.call_site.ctxt().outer().expn_info();
79+
then {
80+
second.call_site
81+
} else {
82+
expr.span
83+
}
84+
}
85+
}
86+
7387
fn match_panic(params: &P<[Expr]>, expr: &Expr, cx: &LateContext) {
7488
if_chain! {
7589
if let ExprLit(ref lit) = params[0].node;

tests/run-pass/ice_exacte_size.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ struct Foo;
66
impl Iterator for Foo {
77
type Item = ();
88

9-
#[allow(unimplemented)]
109
fn next(&mut self) -> Option<()> {
1110
let _ = self.len() == 0;
1211
unimplemented!()

tests/ui/panic_unimplemented.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ fn ok_escaped() {
5454
}
5555

5656
fn unimplemented() {
57+
let a = 2;
5758
unimplemented!();
59+
let b = a + 2;
5860
}
5961

6062
fn main() {

tests/ui/panic_unimplemented.stderr

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@ error: you probably are missing some parameter in your format string
2525
| ^^^^^^^^^^^^
2626

2727
error: `unimplemented` should not be present in production code
28-
--> $DIR/panic_unimplemented.rs:57:5
28+
--> $DIR/panic_unimplemented.rs:58:5
2929
|
30-
57 | unimplemented!();
30+
58 | unimplemented!();
3131
| ^^^^^^^^^^^^^^^^^
3232
|
3333
= note: `-D unimplemented` implied by `-D warnings`
34-
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
3534

3635
error: aborting due to 5 previous errors
3736

0 commit comments

Comments
 (0)