Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger use_self lint in local macros #3627

Merged
merged 1 commit into from
Jan 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions clippy_lints/src/use_self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use crate::utils::{in_macro, span_lint_and_sugg};
use crate::utils::span_lint_and_sugg;
use if_chain::if_chain;
use rustc::hir::def::{CtorKind, Def};
use rustc::hir::intravisit::{walk_path, walk_ty, NestedVisitorMap, Visitor};
use rustc::hir::*;
use rustc::lint::{LateContext, LateLintPass, LintArray, LintPass};
use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass};
use rustc::ty;
use rustc::{declare_tool_lint, lint_array};
use rustc_errors::Applicability;
Expand Down Expand Up @@ -172,7 +172,7 @@ fn check_trait_method_impl_decl<'a, 'tcx: 'a>(

impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UseSelf {
fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
if in_macro(item.span) {
if in_external_macro(cx.sess(), item.span) {
return;
}
if_chain! {
Expand Down
16 changes: 16 additions & 0 deletions tests/ui/use_self.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,22 @@ mod tuple_structs {
}
}

mod macros {
macro_rules! use_self_expand {
() => {
fn new() -> Foo {
Foo {}
}
};
}

struct Foo {}

impl Foo {
use_self_expand!(); // Should lint in local macros
}
}

mod issue3410 {

struct A;
Expand Down
20 changes: 19 additions & 1 deletion tests/ui/use_self.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,23 @@ error: unnecessary structure name repetition
LL | TS(0)
| ^^ help: use the applicable keyword: `Self`

error: aborting due to 22 previous errors
error: unnecessary structure name repetition
--> $DIR/use_self.rs:232:25
|
LL | fn new() -> Foo {
| ^^^ help: use the applicable keyword: `Self`
...
LL | use_self_expand!(); // Should lint in local macros
| ------------------- in this macro invocation

error: unnecessary structure name repetition
--> $DIR/use_self.rs:233:17
|
LL | Foo {}
| ^^^ help: use the applicable keyword: `Self`
...
LL | use_self_expand!(); // Should lint in local macros
| ------------------- in this macro invocation

error: aborting due to 24 previous errors