Skip to content

Commit eaeaf74

Browse files
committed
fixed suggestion, check edition, ran tests/ui/update-all-references.sh
1 parent fc1d167 commit eaeaf74

File tree

7 files changed

+55
-295
lines changed

7 files changed

+55
-295
lines changed

clippy_lints/src/macro_use.rs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::utils::span_lint_and_help;
22
use rustc_lint::{EarlyContext, EarlyLintPass};
33
use rustc_session::{declare_lint_pass, declare_tool_lint};
4+
use rustc_span::edition::Edition;
45
use syntax::ast;
56

67
declare_clippy_lint! {
@@ -25,30 +26,32 @@ declare_lint_pass!(MacroUseImport => [MACRO_USE_IMPORT]);
2526

2627
impl EarlyLintPass for MacroUseImport {
2728
fn check_item(&mut self, ecx: &EarlyContext<'_>, item: &ast::Item) {
28-
if let ast::ItemKind::Use(use_tree) = &item.kind {
29-
let macro_use_attr = item
30-
.attrs
31-
.iter()
32-
.find(|attr| attr.ident().map(|s| s.to_string()) == Some("macro_use".to_string()));
33-
if let Some(mac_attr) = macro_use_attr {
34-
let msg = "`macro_use` attribute's are no longer needed in the Rust 2018 edition";
35-
let help = format!(
36-
"remove the attribute and import the macro directly `use {}::macro_name`",
37-
use_tree
38-
.clone()
39-
.into_inner()
40-
.prefix
41-
.segments
42-
.iter()
43-
.enumerate()
44-
.map(|(i, s)| if i == 0 {
45-
s.ident.to_string()
46-
} else {
47-
format!("::{}", s.ident)
48-
})
49-
.collect::<String>(),
50-
);
51-
span_lint_and_help(ecx, MACRO_USE_IMPORT, mac_attr.span, msg, &help);
29+
if ecx.sess.opts.edition == Edition::Edition2018 {
30+
if let ast::ItemKind::Use(use_tree) = &item.kind {
31+
let macro_use_attr = item
32+
.attrs
33+
.iter()
34+
.find(|attr| attr.ident().map(|s| s.to_string()) == Some("macro_use".to_string()));
35+
if let Some(mac_attr) = macro_use_attr {
36+
let msg = "`macro_use` attribute's are no longer needed in the Rust 2018 edition";
37+
let help = format!(
38+
"remove the attribute and import the macro directly `use {}::<macro name>`",
39+
use_tree
40+
.clone()
41+
.into_inner()
42+
.prefix
43+
.segments
44+
.iter()
45+
.enumerate()
46+
.map(|(i, s)| if i == 0 {
47+
s.ident.to_string()
48+
} else {
49+
format!("::{}", s.ident)
50+
})
51+
.collect::<String>(),
52+
);
53+
span_lint_and_help(ecx, MACRO_USE_IMPORT, mac_attr.span, msg, &help);
54+
}
5255
}
5356
}
5457
}

tests/ui/macro_use_import.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// compile-flags: --edition 2018
12
#![warn(clippy::macro_use_import)]
23

34
use std::collections::HashMap;
@@ -6,4 +7,5 @@ use std::prelude;
67

78
fn main() {
89
let _ = HashMap::<u8, u8>::new();
10+
println!();
911
}

tests/ui/macro_use_import.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: `macro_use` attribute's are no longer needed in the Rust 2018 edition
2-
--> $DIR/macro_use_import.rs:4:1
2+
--> $DIR/macro_use_import.rs:5:1
33
|
44
LL | #[macro_use]
55
| ^^^^^^^^^^^^
66
|
77
= note: `-D clippy::macro-use-import` implied by `-D warnings`
8-
= help: remove the attribute and import the macro directly `use std::prelude::macro_name`
8+
= help: remove the attribute and import the macro directly `use std::prelude::<macro name>`
99

1010
error: aborting due to previous error
1111

tests/ui/missing-doc-impl.stderr

Lines changed: 9 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,15 @@
1-
error: missing documentation for a struct
2-
--> $DIR/missing-doc-impl.rs:8:1
3-
|
4-
LL | / struct Foo {
5-
LL | | a: isize,
6-
LL | | b: isize,
7-
LL | | }
8-
| |_^
9-
|
10-
= note: `-D clippy::missing-docs-in-private-items` implied by `-D warnings`
11-
12-
error: missing documentation for a struct field
13-
--> $DIR/missing-doc-impl.rs:9:5
14-
|
15-
LL | a: isize,
16-
| ^^^^^^^^
17-
18-
error: missing documentation for a struct field
19-
--> $DIR/missing-doc-impl.rs:10:5
20-
|
21-
LL | b: isize,
22-
| ^^^^^^^^
23-
24-
error: missing documentation for a struct
25-
--> $DIR/missing-doc-impl.rs:13:1
26-
|
27-
LL | / pub struct PubFoo {
28-
LL | | pub a: isize,
29-
LL | | b: isize,
30-
LL | | }
31-
| |_^
32-
33-
error: missing documentation for a struct field
34-
--> $DIR/missing-doc-impl.rs:14:5
35-
|
36-
LL | pub a: isize,
37-
| ^^^^^^^^^^^^
38-
39-
error: missing documentation for a struct field
40-
--> $DIR/missing-doc-impl.rs:15:5
41-
|
42-
LL | b: isize,
43-
| ^^^^^^^^
44-
45-
error: missing documentation for a trait
46-
--> $DIR/missing-doc-impl.rs:38:1
47-
|
48-
LL | / pub trait C {
49-
LL | | fn foo(&self);
50-
LL | | fn foo_with_impl(&self) {}
51-
LL | | }
52-
| |_^
53-
54-
error: missing documentation for a trait method
55-
--> $DIR/missing-doc-impl.rs:39:5
56-
|
57-
LL | fn foo(&self);
58-
| ^^^^^^^^^^^^^^
59-
60-
error: missing documentation for a trait method
61-
--> $DIR/missing-doc-impl.rs:40:5
62-
|
63-
LL | fn foo_with_impl(&self) {}
64-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
65-
66-
error: missing documentation for an associated type
67-
--> $DIR/missing-doc-impl.rs:50:5
68-
|
69-
LL | type AssociatedType;
70-
| ^^^^^^^^^^^^^^^^^^^^
71-
72-
error: missing documentation for an associated type
1+
error[E0277]: the size for values of type `Self` cannot be known at compilation time
732
--> $DIR/missing-doc-impl.rs:51:5
743
|
4+
LL | pub trait E {
5+
| ----------- required by `E`
6+
LL | type AssociatedType;
757
LL | type AssociatedTypeDef = Self;
76-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
77-
78-
error: missing documentation for a method
79-
--> $DIR/missing-doc-impl.rs:62:5
80-
|
81-
LL | pub fn foo() {}
82-
| ^^^^^^^^^^^^^^^
83-
84-
error: missing documentation for a method
85-
--> $DIR/missing-doc-impl.rs:63:5
86-
|
87-
LL | fn bar() {}
88-
| ^^^^^^^^^^^
89-
90-
error: missing documentation for a method
91-
--> $DIR/missing-doc-impl.rs:67:5
92-
|
93-
LL | pub fn foo() {}
94-
| ^^^^^^^^^^^^^^^
95-
96-
error: missing documentation for a method
97-
--> $DIR/missing-doc-impl.rs:70:5
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
989
|
99-
LL | fn foo2() {}
100-
| ^^^^^^^^^^^^
10+
= help: the trait `std::marker::Sized` is not implemented for `Self`
11+
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>
10112

102-
error: aborting due to 15 previous errors
13+
error: aborting due to previous error
10314

15+
For more information about this error, try `rustc --explain E0277`.

tests/ui/regex.stderr

Lines changed: 8 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -1,171 +1,12 @@
1-
error: trivial regex
2-
--> $DIR/regex.rs:13:45
1+
error[E0514]: found crate `regex` compiled by an incompatible version of rustc
2+
--> $DIR/regex.rs:4:1
33
|
4-
LL | let pipe_in_wrong_position = Regex::new("|");
5-
| ^^^
4+
LL | extern crate regex;
5+
| ^^^^^^^^^^^^^^^^^^^
66
|
7-
= note: `-D clippy::trivial-regex` implied by `-D warnings`
8-
= help: the regex is unlikely to be useful as it is
7+
= help: please recompile that crate using this compiler (rustc 1.43.0-nightly (a8437cf21 2020-02-27))
8+
= note: the following crate versions were found:
9+
crate `regex` compiled by rustc 1.43.0-nightly (e3a277943 2020-02-25): /home/devinr/aprog/rust/__forks__/rust-clippy/target/debug/deps/libregex-7640b48dc23b89d0.rlib
910

10-
error: trivial regex
11-
--> $DIR/regex.rs:14:60
12-
|
13-
LL | let pipe_in_wrong_position_builder = RegexBuilder::new("|");
14-
| ^^^
15-
|
16-
= help: the regex is unlikely to be useful as it is
17-
18-
error: regex syntax error: invalid character class range, the start must be <= the end
19-
--> $DIR/regex.rs:15:42
20-
|
21-
LL | let wrong_char_ranice = Regex::new("[z-a]");
22-
| ^^^
23-
|
24-
= note: `-D clippy::invalid-regex` implied by `-D warnings`
25-
26-
error: regex syntax error: invalid character class range, the start must be <= the end
27-
--> $DIR/regex.rs:16:37
28-
|
29-
LL | let some_unicode = Regex::new("[é-è]");
30-
| ^^^
31-
32-
error: regex syntax error on position 0: unclosed group
33-
--> $DIR/regex.rs:18:33
34-
|
35-
LL | let some_regex = Regex::new(OPENING_PAREN);
36-
| ^^^^^^^^^^^^^
37-
38-
error: trivial regex
39-
--> $DIR/regex.rs:20:53
40-
|
41-
LL | let binary_pipe_in_wrong_position = BRegex::new("|");
42-
| ^^^
43-
|
44-
= help: the regex is unlikely to be useful as it is
45-
46-
error: regex syntax error on position 0: unclosed group
47-
--> $DIR/regex.rs:21:41
48-
|
49-
LL | let some_binary_regex = BRegex::new(OPENING_PAREN);
50-
| ^^^^^^^^^^^^^
51-
52-
error: regex syntax error on position 0: unclosed group
53-
--> $DIR/regex.rs:22:56
54-
|
55-
LL | let some_binary_regex_builder = BRegexBuilder::new(OPENING_PAREN);
56-
| ^^^^^^^^^^^^^
57-
58-
error: regex syntax error on position 0: unclosed group
59-
--> $DIR/regex.rs:34:37
60-
|
61-
LL | let set_error = RegexSet::new(&[OPENING_PAREN, r"[a-z]+/.(com|org|net)"]);
62-
| ^^^^^^^^^^^^^
63-
64-
error: regex syntax error on position 0: unclosed group
65-
--> $DIR/regex.rs:35:39
66-
|
67-
LL | let bset_error = BRegexSet::new(&[OPENING_PAREN, r"[a-z]+/.(com|org|net)"]);
68-
| ^^^^^^^^^^^^^
69-
70-
error: regex syntax error: unrecognized escape sequence
71-
--> $DIR/regex.rs:37:45
72-
|
73-
LL | let raw_string_error = Regex::new(r"[...//...]");
74-
| ^^
75-
76-
error: regex syntax error: unrecognized escape sequence
77-
--> $DIR/regex.rs:38:46
78-
|
79-
LL | let raw_string_error = Regex::new(r#"[...//...]"#);
80-
| ^^
81-
82-
error: trivial regex
83-
--> $DIR/regex.rs:42:33
84-
|
85-
LL | let trivial_eq = Regex::new("^foobar$");
86-
| ^^^^^^^^^^
87-
|
88-
= help: consider using `==` on `str`s
89-
90-
error: trivial regex
91-
--> $DIR/regex.rs:44:48
92-
|
93-
LL | let trivial_eq_builder = RegexBuilder::new("^foobar$");
94-
| ^^^^^^^^^^
95-
|
96-
= help: consider using `==` on `str`s
97-
98-
error: trivial regex
99-
--> $DIR/regex.rs:46:42
100-
|
101-
LL | let trivial_starts_with = Regex::new("^foobar");
102-
| ^^^^^^^^^
103-
|
104-
= help: consider using `str::starts_with`
105-
106-
error: trivial regex
107-
--> $DIR/regex.rs:48:40
108-
|
109-
LL | let trivial_ends_with = Regex::new("foobar$");
110-
| ^^^^^^^^^
111-
|
112-
= help: consider using `str::ends_with`
113-
114-
error: trivial regex
115-
--> $DIR/regex.rs:50:39
116-
|
117-
LL | let trivial_contains = Regex::new("foobar");
118-
| ^^^^^^^^
119-
|
120-
= help: consider using `str::contains`
121-
122-
error: trivial regex
123-
--> $DIR/regex.rs:52:39
124-
|
125-
LL | let trivial_contains = Regex::new(NOT_A_REAL_REGEX);
126-
| ^^^^^^^^^^^^^^^^
127-
|
128-
= help: consider using `str::contains`
129-
130-
error: trivial regex
131-
--> $DIR/regex.rs:54:40
132-
|
133-
LL | let trivial_backslash = Regex::new("a/.b");
134-
| ^^^^^^^
135-
|
136-
= help: consider using `str::contains`
137-
138-
error: trivial regex
139-
--> $DIR/regex.rs:57:36
140-
|
141-
LL | let trivial_empty = Regex::new("");
142-
| ^^
143-
|
144-
= help: the regex is unlikely to be useful as it is
145-
146-
error: trivial regex
147-
--> $DIR/regex.rs:59:36
148-
|
149-
LL | let trivial_empty = Regex::new("^");
150-
| ^^^
151-
|
152-
= help: the regex is unlikely to be useful as it is
153-
154-
error: trivial regex
155-
--> $DIR/regex.rs:61:36
156-
|
157-
LL | let trivial_empty = Regex::new("^$");
158-
| ^^^^
159-
|
160-
= help: consider using `str::is_empty`
161-
162-
error: trivial regex
163-
--> $DIR/regex.rs:63:44
164-
|
165-
LL | let binary_trivial_empty = BRegex::new("^$");
166-
| ^^^^
167-
|
168-
= help: consider using `str::is_empty`
169-
170-
error: aborting due to 23 previous errors
11+
error: aborting due to previous error
17112

tests/ui/single_component_path_imports.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![warn(clippy::single_component_path_imports)]
44
#![allow(unused_imports)]
55

6-
6+
use regex;
77
use serde as edres;
88
pub use serde;
99

0 commit comments

Comments
 (0)