From 8adf08c4373f5bdd5bbef9aa4dfd0ca5c4a2eefc Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 17 Jul 2018 10:23:03 -0700 Subject: rustc: Polish off `in_external_macro` This commit polishes off this new function to compile on newer rustc as well as update and add a suite of test cases to work with this new check for lints. --- .../ellided-lifetimes-macro-checks.rs | 15 ------------ .../ui/lint/auxiliary/lints-in-foreign-macros.rs | 24 +++++++++++++++++++ src/test/ui/lint/lints-in-foreign-macros.rs | 28 ++++++++++++++++++++++ src/test/ui/lint/lints-in-foreign-macros.stderr | 27 +++++++++++++++++++++ 4 files changed, 79 insertions(+), 15 deletions(-) delete mode 100644 src/test/ui/in-band-lifetimes/ellided-lifetimes-macro-checks.rs create mode 100644 src/test/ui/lint/auxiliary/lints-in-foreign-macros.rs create mode 100644 src/test/ui/lint/lints-in-foreign-macros.rs create mode 100644 src/test/ui/lint/lints-in-foreign-macros.stderr (limited to 'src/test/ui') diff --git a/src/test/ui/in-band-lifetimes/ellided-lifetimes-macro-checks.rs b/src/test/ui/in-band-lifetimes/ellided-lifetimes-macro-checks.rs deleted file mode 100644 index 9e53cbfb3ad..00000000000 --- a/src/test/ui/in-band-lifetimes/ellided-lifetimes-macro-checks.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2018 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. -#![feature(nll)] -#![deny(elided_lifetime_in_path)] - -fn main() { - format!("foo {}", 22) -} diff --git a/src/test/ui/lint/auxiliary/lints-in-foreign-macros.rs b/src/test/ui/lint/auxiliary/lints-in-foreign-macros.rs new file mode 100644 index 00000000000..cf8e9c18de3 --- /dev/null +++ b/src/test/ui/lint/auxiliary/lints-in-foreign-macros.rs @@ -0,0 +1,24 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[macro_export] +macro_rules! bar { + () => {use std::string::ToString;} +} + +#[macro_export] +macro_rules! baz { + ($i:item) => ($i) +} + +#[macro_export] +macro_rules! baz2 { + ($($i:tt)*) => ($($i)*) +} diff --git a/src/test/ui/lint/lints-in-foreign-macros.rs b/src/test/ui/lint/lints-in-foreign-macros.rs new file mode 100644 index 00000000000..0f9003877cc --- /dev/null +++ b/src/test/ui/lint/lints-in-foreign-macros.rs @@ -0,0 +1,28 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:lints-in-foreign-macros.rs +// compile-pass + +#![warn(unused_imports)] + +#[macro_use] +extern crate lints_in_foreign_macros; + +macro_rules! foo { + () => {use std::string::ToString;} //~ WARN: unused import +} + +mod a { foo!(); } +mod b { bar!(); } +mod c { baz!(use std::string::ToString;); } //~ WARN: unused import +mod d { baz2!(use std::string::ToString;); } //~ WARN: unused import + +fn main() {} diff --git a/src/test/ui/lint/lints-in-foreign-macros.stderr b/src/test/ui/lint/lints-in-foreign-macros.stderr new file mode 100644 index 00000000000..e9f6d3d3815 --- /dev/null +++ b/src/test/ui/lint/lints-in-foreign-macros.stderr @@ -0,0 +1,27 @@ +warning: unused import: `std::string::ToString` + --> $DIR/lints-in-foreign-macros.rs:20:16 + | +LL | () => {use std::string::ToString;} //~ WARN: unused import + | ^^^^^^^^^^^^^^^^^^^^^ +... +LL | mod a { foo!(); } + | ------- in this macro invocation + | +note: lint level defined here + --> $DIR/lints-in-foreign-macros.rs:14:9 + | +LL | #![warn(unused_imports)] + | ^^^^^^^^^^^^^^ + +warning: unused import: `std::string::ToString` + --> $DIR/lints-in-foreign-macros.rs:25:18 + | +LL | mod c { baz!(use std::string::ToString;); } //~ WARN: unused import + | ^^^^^^^^^^^^^^^^^^^^^ + +warning: unused import: `std::string::ToString` + --> $DIR/lints-in-foreign-macros.rs:26:19 + | +LL | mod d { baz2!(use std::string::ToString;); } //~ WARN: unused import + | ^^^^^^^^^^^^^^^^^^^^^ + -- cgit 1.4.1-3-g733a5