Skip to content

Commit

Permalink
fixed suggestion, check edition, ran tests/ui/update-all-references.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
DevinR528 committed Feb 27, 2020
1 parent fc1d167 commit eaeaf74
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 295 deletions.
51 changes: 27 additions & 24 deletions clippy_lints/src/macro_use.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::utils::span_lint_and_help;
use rustc_lint::{EarlyContext, EarlyLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::edition::Edition;
use syntax::ast;

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

impl EarlyLintPass for MacroUseImport {
fn check_item(&mut self, ecx: &EarlyContext<'_>, item: &ast::Item) {
if let ast::ItemKind::Use(use_tree) = &item.kind {
let macro_use_attr = item
.attrs
.iter()
.find(|attr| attr.ident().map(|s| s.to_string()) == Some("macro_use".to_string()));
if let Some(mac_attr) = macro_use_attr {
let msg = "`macro_use` attribute's are no longer needed in the Rust 2018 edition";
let help = format!(
"remove the attribute and import the macro directly `use {}::macro_name`",
use_tree
.clone()
.into_inner()
.prefix
.segments
.iter()
.enumerate()
.map(|(i, s)| if i == 0 {
s.ident.to_string()
} else {
format!("::{}", s.ident)
})
.collect::<String>(),
);
span_lint_and_help(ecx, MACRO_USE_IMPORT, mac_attr.span, msg, &help);
if ecx.sess.opts.edition == Edition::Edition2018 {
if let ast::ItemKind::Use(use_tree) = &item.kind {
let macro_use_attr = item
.attrs
.iter()
.find(|attr| attr.ident().map(|s| s.to_string()) == Some("macro_use".to_string()));
if let Some(mac_attr) = macro_use_attr {
let msg = "`macro_use` attribute's are no longer needed in the Rust 2018 edition";
let help = format!(
"remove the attribute and import the macro directly `use {}::<macro name>`",
use_tree
.clone()
.into_inner()
.prefix
.segments
.iter()
.enumerate()
.map(|(i, s)| if i == 0 {
s.ident.to_string()
} else {
format!("::{}", s.ident)
})
.collect::<String>(),
);
span_lint_and_help(ecx, MACRO_USE_IMPORT, mac_attr.span, msg, &help);
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/macro_use_import.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// compile-flags: --edition 2018
#![warn(clippy::macro_use_import)]

use std::collections::HashMap;
Expand All @@ -6,4 +7,5 @@ use std::prelude;

fn main() {
let _ = HashMap::<u8, u8>::new();
println!();
}
4 changes: 2 additions & 2 deletions tests/ui/macro_use_import.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error: `macro_use` attribute's are no longer needed in the Rust 2018 edition
--> $DIR/macro_use_import.rs:4:1
--> $DIR/macro_use_import.rs:5:1
|
LL | #[macro_use]
| ^^^^^^^^^^^^
|
= note: `-D clippy::macro-use-import` implied by `-D warnings`
= help: remove the attribute and import the macro directly `use std::prelude::macro_name`
= help: remove the attribute and import the macro directly `use std::prelude::<macro name>`

error: aborting due to previous error

106 changes: 9 additions & 97 deletions tests/ui/missing-doc-impl.stderr
Original file line number Diff line number Diff line change
@@ -1,103 +1,15 @@
error: missing documentation for a struct
--> $DIR/missing-doc-impl.rs:8:1
|
LL | / struct Foo {
LL | | a: isize,
LL | | b: isize,
LL | | }
| |_^
|
= note: `-D clippy::missing-docs-in-private-items` implied by `-D warnings`

error: missing documentation for a struct field
--> $DIR/missing-doc-impl.rs:9:5
|
LL | a: isize,
| ^^^^^^^^

error: missing documentation for a struct field
--> $DIR/missing-doc-impl.rs:10:5
|
LL | b: isize,
| ^^^^^^^^

error: missing documentation for a struct
--> $DIR/missing-doc-impl.rs:13:1
|
LL | / pub struct PubFoo {
LL | | pub a: isize,
LL | | b: isize,
LL | | }
| |_^

error: missing documentation for a struct field
--> $DIR/missing-doc-impl.rs:14:5
|
LL | pub a: isize,
| ^^^^^^^^^^^^

error: missing documentation for a struct field
--> $DIR/missing-doc-impl.rs:15:5
|
LL | b: isize,
| ^^^^^^^^

error: missing documentation for a trait
--> $DIR/missing-doc-impl.rs:38:1
|
LL | / pub trait C {
LL | | fn foo(&self);
LL | | fn foo_with_impl(&self) {}
LL | | }
| |_^

error: missing documentation for a trait method
--> $DIR/missing-doc-impl.rs:39:5
|
LL | fn foo(&self);
| ^^^^^^^^^^^^^^

error: missing documentation for a trait method
--> $DIR/missing-doc-impl.rs:40:5
|
LL | fn foo_with_impl(&self) {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: missing documentation for an associated type
--> $DIR/missing-doc-impl.rs:50:5
|
LL | type AssociatedType;
| ^^^^^^^^^^^^^^^^^^^^

error: missing documentation for an associated type
error[E0277]: the size for values of type `Self` cannot be known at compilation time
--> $DIR/missing-doc-impl.rs:51:5
|
LL | pub trait E {
| ----------- required by `E`
LL | type AssociatedType;
LL | type AssociatedTypeDef = Self;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: missing documentation for a method
--> $DIR/missing-doc-impl.rs:62:5
|
LL | pub fn foo() {}
| ^^^^^^^^^^^^^^^

error: missing documentation for a method
--> $DIR/missing-doc-impl.rs:63:5
|
LL | fn bar() {}
| ^^^^^^^^^^^

error: missing documentation for a method
--> $DIR/missing-doc-impl.rs:67:5
|
LL | pub fn foo() {}
| ^^^^^^^^^^^^^^^

error: missing documentation for a method
--> $DIR/missing-doc-impl.rs:70:5
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
LL | fn foo2() {}
| ^^^^^^^^^^^^
= help: the trait `std::marker::Sized` is not implemented for `Self`
= note: to learn more, visit <https://doc.rust-lang.org/book/ch19-04-advanced-types.html#dynamically-sized-types-and-the-sized-trait>

error: aborting due to 15 previous errors
error: aborting due to previous error

For more information about this error, try `rustc --explain E0277`.
175 changes: 8 additions & 167 deletions tests/ui/regex.stderr
Original file line number Diff line number Diff line change
@@ -1,171 +1,12 @@
error: trivial regex
--> $DIR/regex.rs:13:45
error[E0514]: found crate `regex` compiled by an incompatible version of rustc
--> $DIR/regex.rs:4:1
|
LL | let pipe_in_wrong_position = Regex::new("|");
| ^^^
LL | extern crate regex;
| ^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::trivial-regex` implied by `-D warnings`
= help: the regex is unlikely to be useful as it is
= help: please recompile that crate using this compiler (rustc 1.43.0-nightly (a8437cf21 2020-02-27))
= note: the following crate versions were found:
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

error: trivial regex
--> $DIR/regex.rs:14:60
|
LL | let pipe_in_wrong_position_builder = RegexBuilder::new("|");
| ^^^
|
= help: the regex is unlikely to be useful as it is

error: regex syntax error: invalid character class range, the start must be <= the end
--> $DIR/regex.rs:15:42
|
LL | let wrong_char_ranice = Regex::new("[z-a]");
| ^^^
|
= note: `-D clippy::invalid-regex` implied by `-D warnings`

error: regex syntax error: invalid character class range, the start must be <= the end
--> $DIR/regex.rs:16:37
|
LL | let some_unicode = Regex::new("[é-è]");
| ^^^

error: regex syntax error on position 0: unclosed group
--> $DIR/regex.rs:18:33
|
LL | let some_regex = Regex::new(OPENING_PAREN);
| ^^^^^^^^^^^^^

error: trivial regex
--> $DIR/regex.rs:20:53
|
LL | let binary_pipe_in_wrong_position = BRegex::new("|");
| ^^^
|
= help: the regex is unlikely to be useful as it is

error: regex syntax error on position 0: unclosed group
--> $DIR/regex.rs:21:41
|
LL | let some_binary_regex = BRegex::new(OPENING_PAREN);
| ^^^^^^^^^^^^^

error: regex syntax error on position 0: unclosed group
--> $DIR/regex.rs:22:56
|
LL | let some_binary_regex_builder = BRegexBuilder::new(OPENING_PAREN);
| ^^^^^^^^^^^^^

error: regex syntax error on position 0: unclosed group
--> $DIR/regex.rs:34:37
|
LL | let set_error = RegexSet::new(&[OPENING_PAREN, r"[a-z]+/.(com|org|net)"]);
| ^^^^^^^^^^^^^

error: regex syntax error on position 0: unclosed group
--> $DIR/regex.rs:35:39
|
LL | let bset_error = BRegexSet::new(&[OPENING_PAREN, r"[a-z]+/.(com|org|net)"]);
| ^^^^^^^^^^^^^

error: regex syntax error: unrecognized escape sequence
--> $DIR/regex.rs:37:45
|
LL | let raw_string_error = Regex::new(r"[...//...]");
| ^^

error: regex syntax error: unrecognized escape sequence
--> $DIR/regex.rs:38:46
|
LL | let raw_string_error = Regex::new(r#"[...//...]"#);
| ^^

error: trivial regex
--> $DIR/regex.rs:42:33
|
LL | let trivial_eq = Regex::new("^foobar$");
| ^^^^^^^^^^
|
= help: consider using `==` on `str`s

error: trivial regex
--> $DIR/regex.rs:44:48
|
LL | let trivial_eq_builder = RegexBuilder::new("^foobar$");
| ^^^^^^^^^^
|
= help: consider using `==` on `str`s

error: trivial regex
--> $DIR/regex.rs:46:42
|
LL | let trivial_starts_with = Regex::new("^foobar");
| ^^^^^^^^^
|
= help: consider using `str::starts_with`

error: trivial regex
--> $DIR/regex.rs:48:40
|
LL | let trivial_ends_with = Regex::new("foobar$");
| ^^^^^^^^^
|
= help: consider using `str::ends_with`

error: trivial regex
--> $DIR/regex.rs:50:39
|
LL | let trivial_contains = Regex::new("foobar");
| ^^^^^^^^
|
= help: consider using `str::contains`

error: trivial regex
--> $DIR/regex.rs:52:39
|
LL | let trivial_contains = Regex::new(NOT_A_REAL_REGEX);
| ^^^^^^^^^^^^^^^^
|
= help: consider using `str::contains`

error: trivial regex
--> $DIR/regex.rs:54:40
|
LL | let trivial_backslash = Regex::new("a/.b");
| ^^^^^^^
|
= help: consider using `str::contains`

error: trivial regex
--> $DIR/regex.rs:57:36
|
LL | let trivial_empty = Regex::new("");
| ^^
|
= help: the regex is unlikely to be useful as it is

error: trivial regex
--> $DIR/regex.rs:59:36
|
LL | let trivial_empty = Regex::new("^");
| ^^^
|
= help: the regex is unlikely to be useful as it is

error: trivial regex
--> $DIR/regex.rs:61:36
|
LL | let trivial_empty = Regex::new("^$");
| ^^^^
|
= help: consider using `str::is_empty`

error: trivial regex
--> $DIR/regex.rs:63:44
|
LL | let binary_trivial_empty = BRegex::new("^$");
| ^^^^
|
= help: consider using `str::is_empty`

error: aborting due to 23 previous errors
error: aborting due to previous error

2 changes: 1 addition & 1 deletion tests/ui/single_component_path_imports.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#![warn(clippy::single_component_path_imports)]
#![allow(unused_imports)]


use regex;
use serde as edres;
pub use serde;

Expand Down
Loading

0 comments on commit eaeaf74

Please sign in to comment.