Skip to content

Commit 9af8e37

Browse files
committed
Merge commit '91496c2ac6abf6454c413bb23e8becf6b6dc20ea' into clippyup
2 parents 40ebd07 + 91496c2 commit 9af8e37

File tree

127 files changed

+4334
-628
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

127 files changed

+4334
-628
lines changed

src/tools/clippy/CHANGELOG.md

+9
Original file line numberDiff line numberDiff line change
@@ -2730,11 +2730,13 @@ Released 2018-09-13
27302730
[`fn_address_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#fn_address_comparisons
27312731
[`fn_params_excessive_bools`]: https://rust-lang.github.io/rust-clippy/master/index.html#fn_params_excessive_bools
27322732
[`fn_to_numeric_cast`]: https://rust-lang.github.io/rust-clippy/master/index.html#fn_to_numeric_cast
2733+
[`fn_to_numeric_cast_any`]: https://rust-lang.github.io/rust-clippy/master/index.html#fn_to_numeric_cast_any
27332734
[`fn_to_numeric_cast_with_truncation`]: https://rust-lang.github.io/rust-clippy/master/index.html#fn_to_numeric_cast_with_truncation
27342735
[`for_kv_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#for_kv_map
27352736
[`for_loops_over_fallibles`]: https://rust-lang.github.io/rust-clippy/master/index.html#for_loops_over_fallibles
27362737
[`forget_copy`]: https://rust-lang.github.io/rust-clippy/master/index.html#forget_copy
27372738
[`forget_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#forget_ref
2739+
[`format_in_format_args`]: https://rust-lang.github.io/rust-clippy/master/index.html#format_in_format_args
27382740
[`from_iter_instead_of_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#from_iter_instead_of_collect
27392741
[`from_over_into`]: https://rust-lang.github.io/rust-clippy/master/index.html#from_over_into
27402742
[`from_str_radix_10`]: https://rust-lang.github.io/rust-clippy/master/index.html#from_str_radix_10
@@ -2836,6 +2838,7 @@ Released 2018-09-13
28362838
[`match_result_ok`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_result_ok
28372839
[`match_same_arms`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms
28382840
[`match_single_binding`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_single_binding
2841+
[`match_str_case_mismatch`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_str_case_mismatch
28392842
[`match_wild_err_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_wild_err_arm
28402843
[`match_wildcard_for_single_variants`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_wildcard_for_single_variants
28412844
[`maybe_infinite_iter`]: https://rust-lang.github.io/rust-clippy/master/index.html#maybe_infinite_iter
@@ -2896,6 +2899,7 @@ Released 2018-09-13
28962899
[`new_ret_no_self`]: https://rust-lang.github.io/rust-clippy/master/index.html#new_ret_no_self
28972900
[`new_without_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default
28982901
[`no_effect`]: https://rust-lang.github.io/rust-clippy/master/index.html#no_effect
2902+
[`no_effect_underscore_binding`]: https://rust-lang.github.io/rust-clippy/master/index.html#no_effect_underscore_binding
28992903
[`non_ascii_literal`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_ascii_literal
29002904
[`non_octal_unix_permissions`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_octal_unix_permissions
29012905
[`non_send_fields_in_send_ty`]: https://rust-lang.github.io/rust-clippy/master/index.html#non_send_fields_in_send_ty
@@ -3012,16 +3016,19 @@ Released 2018-09-13
30123016
[`temporary_assignment`]: https://rust-lang.github.io/rust-clippy/master/index.html#temporary_assignment
30133017
[`to_digit_is_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#to_digit_is_some
30143018
[`to_string_in_display`]: https://rust-lang.github.io/rust-clippy/master/index.html#to_string_in_display
3019+
[`to_string_in_format_args`]: https://rust-lang.github.io/rust-clippy/master/index.html#to_string_in_format_args
30153020
[`todo`]: https://rust-lang.github.io/rust-clippy/master/index.html#todo
30163021
[`too_many_arguments`]: https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments
30173022
[`too_many_lines`]: https://rust-lang.github.io/rust-clippy/master/index.html#too_many_lines
30183023
[`toplevel_ref_arg`]: https://rust-lang.github.io/rust-clippy/master/index.html#toplevel_ref_arg
3024+
[`trailing_empty_array`]: https://rust-lang.github.io/rust-clippy/master/index.html#trailing_empty_array
30193025
[`trait_duplication_in_bounds`]: https://rust-lang.github.io/rust-clippy/master/index.html#trait_duplication_in_bounds
30203026
[`transmute_bytes_to_str`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_bytes_to_str
30213027
[`transmute_float_to_int`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_float_to_int
30223028
[`transmute_int_to_bool`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_int_to_bool
30233029
[`transmute_int_to_char`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_int_to_char
30243030
[`transmute_int_to_float`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_int_to_float
3031+
[`transmute_num_to_bytes`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_num_to_bytes
30253032
[`transmute_ptr_to_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_ptr_to_ptr
30263033
[`transmute_ptr_to_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmute_ptr_to_ref
30273034
[`transmutes_expressible_as_ptr_casts`]: https://rust-lang.github.io/rust-clippy/master/index.html#transmutes_expressible_as_ptr_casts
@@ -3031,10 +3038,12 @@ Released 2018-09-13
30313038
[`try_err`]: https://rust-lang.github.io/rust-clippy/master/index.html#try_err
30323039
[`type_complexity`]: https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity
30333040
[`type_repetition_in_bounds`]: https://rust-lang.github.io/rust-clippy/master/index.html#type_repetition_in_bounds
3041+
[`undocumented_unsafe_blocks`]: https://rust-lang.github.io/rust-clippy/master/index.html#undocumented_unsafe_blocks
30343042
[`undropped_manually_drops`]: https://rust-lang.github.io/rust-clippy/master/index.html#undropped_manually_drops
30353043
[`unicode_not_nfc`]: https://rust-lang.github.io/rust-clippy/master/index.html#unicode_not_nfc
30363044
[`unimplemented`]: https://rust-lang.github.io/rust-clippy/master/index.html#unimplemented
30373045
[`uninit_assumed_init`]: https://rust-lang.github.io/rust-clippy/master/index.html#uninit_assumed_init
3046+
[`uninit_vec`]: https://rust-lang.github.io/rust-clippy/master/index.html#uninit_vec
30383047
[`unit_arg`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_arg
30393048
[`unit_cmp`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_cmp
30403049
[`unit_return_expecting_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#unit_return_expecting_ord

src/tools/clippy/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.1.57"
3+
version = "0.1.58"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"

src/tools/clippy/clippy_dev/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2021"
66
[dependencies]
77
bytecount = "0.6"
88
clap = "2.33"
9+
indoc = "1.0"
910
itertools = "0.10"
1011
opener = "0.5"
1112
regex = "1.5"

src/tools/clippy/clippy_dev/src/main.rs

+6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ fn main() {
2828
matches.value_of("pass"),
2929
matches.value_of("name"),
3030
matches.value_of("category"),
31+
matches.is_present("msrv"),
3132
) {
3233
Ok(_) => update_lints::run(update_lints::UpdateMode::Change),
3334
Err(e) => eprintln!("Unable to create lint: {}", e),
@@ -147,6 +148,11 @@ fn get_clap_config<'a>() -> ArgMatches<'a> {
147148
"internal_warn",
148149
])
149150
.takes_value(true),
151+
)
152+
.arg(
153+
Arg::with_name("msrv")
154+
.long("msrv")
155+
.help("Add MSRV config code to the lint"),
150156
),
151157
)
152158
.subcommand(

src/tools/clippy/clippy_dev/src/new_lint.rs

+142-78
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::clippy_project_root;
2+
use indoc::indoc;
23
use std::fs::{self, OpenOptions};
34
use std::io::prelude::*;
45
use std::io::{self, ErrorKind};
@@ -32,37 +33,20 @@ impl<T> Context for io::Result<T> {
3233
/// # Errors
3334
///
3435
/// This function errors out if the files couldn't be created or written to.
35-
pub fn create(pass: Option<&str>, lint_name: Option<&str>, category: Option<&str>) -> io::Result<()> {
36+
pub fn create(pass: Option<&str>, lint_name: Option<&str>, category: Option<&str>, msrv: bool) -> io::Result<()> {
3637
let lint = LintData {
3738
pass: pass.expect("`pass` argument is validated by clap"),
3839
name: lint_name.expect("`name` argument is validated by clap"),
3940
category: category.expect("`category` argument is validated by clap"),
4041
project_root: clippy_project_root(),
4142
};
4243

43-
create_lint(&lint).context("Unable to create lint implementation")?;
44+
create_lint(&lint, msrv).context("Unable to create lint implementation")?;
4445
create_test(&lint).context("Unable to create a test for the new lint")
4546
}
4647

47-
fn create_lint(lint: &LintData<'_>) -> io::Result<()> {
48-
let (pass_type, pass_lifetimes, pass_import, context_import) = match lint.pass {
49-
"early" => ("EarlyLintPass", "", "use rustc_ast::ast::*;", "EarlyContext"),
50-
"late" => ("LateLintPass", "<'_>", "use rustc_hir::*;", "LateContext"),
51-
_ => {
52-
unreachable!("`pass_type` should only ever be `early` or `late`!");
53-
},
54-
};
55-
56-
let camel_case_name = to_camel_case(lint.name);
57-
let lint_contents = get_lint_file_contents(
58-
pass_type,
59-
pass_lifetimes,
60-
lint.name,
61-
&camel_case_name,
62-
lint.category,
63-
pass_import,
64-
context_import,
65-
);
48+
fn create_lint(lint: &LintData<'_>, enable_msrv: bool) -> io::Result<()> {
49+
let lint_contents = get_lint_file_contents(lint, enable_msrv);
6650

6751
let lint_path = format!("clippy_lints/src/{}.rs", lint.name);
6852
write_file(lint.project_root.join(&lint_path), lint_contents.as_bytes())
@@ -122,12 +106,13 @@ fn to_camel_case(name: &str) -> String {
122106

123107
fn get_test_file_contents(lint_name: &str, header_commands: Option<&str>) -> String {
124108
let mut contents = format!(
125-
"#![warn(clippy::{})]
109+
indoc! {"
110+
#![warn(clippy::{})]
126111
127-
fn main() {{
128-
// test code goes here
129-
}}
130-
",
112+
fn main() {{
113+
// test code goes here
114+
}}
115+
"},
131116
lint_name
132117
);
133118

@@ -140,64 +125,143 @@ fn main() {{
140125

141126
fn get_manifest_contents(lint_name: &str, hint: &str) -> String {
142127
format!(
143-
r#"
144-
# {}
128+
indoc! {r#"
129+
# {}
145130
146-
[package]
147-
name = "{}"
148-
version = "0.1.0"
149-
publish = false
131+
[package]
132+
name = "{}"
133+
version = "0.1.0"
134+
publish = false
150135
151-
[workspace]
152-
"#,
136+
[workspace]
137+
"#},
153138
hint, lint_name
154139
)
155140
}
156141

157-
fn get_lint_file_contents(
158-
pass_type: &str,
159-
pass_lifetimes: &str,
160-
lint_name: &str,
161-
camel_case_name: &str,
162-
category: &str,
163-
pass_import: &str,
164-
context_import: &str,
165-
) -> String {
166-
format!(
167-
"use rustc_lint::{{{type}, {context_import}}};
168-
use rustc_session::{{declare_lint_pass, declare_tool_lint}};
169-
{pass_import}
170-
171-
declare_clippy_lint! {{
172-
/// ### What it does
173-
///
174-
/// ### Why is this bad?
175-
///
176-
/// ### Example
177-
/// ```rust
178-
/// // example code where clippy issues a warning
179-
/// ```
180-
/// Use instead:
181-
/// ```rust
182-
/// // example code which does not raise clippy warning
183-
/// ```
184-
pub {name_upper},
185-
{category},
186-
\"default lint description\"
187-
}}
188-
189-
declare_lint_pass!({name_camel} => [{name_upper}]);
190-
191-
impl {type}{lifetimes} for {name_camel} {{}}
192-
",
193-
type=pass_type,
194-
lifetimes=pass_lifetimes,
195-
name_upper=lint_name.to_uppercase(),
196-
name_camel=camel_case_name,
197-
category=category,
198-
pass_import=pass_import,
199-
context_import=context_import
200-
)
142+
fn get_lint_file_contents(lint: &LintData<'_>, enable_msrv: bool) -> String {
143+
let mut result = String::new();
144+
145+
let (pass_type, pass_lifetimes, pass_import, context_import) = match lint.pass {
146+
"early" => ("EarlyLintPass", "", "use rustc_ast::ast::*;", "EarlyContext"),
147+
"late" => ("LateLintPass", "<'_>", "use rustc_hir::*;", "LateContext"),
148+
_ => {
149+
unreachable!("`pass_type` should only ever be `early` or `late`!");
150+
},
151+
};
152+
153+
let lint_name = lint.name;
154+
let pass_name = lint.pass;
155+
let category = lint.category;
156+
let name_camel = to_camel_case(lint.name);
157+
let name_upper = lint_name.to_uppercase();
158+
159+
result.push_str(&if enable_msrv {
160+
format!(
161+
indoc! {"
162+
use clippy_utils::msrvs;
163+
{pass_import}
164+
use rustc_lint::{{{context_import}, {pass_type}, LintContext}};
165+
use rustc_semver::RustcVersion;
166+
use rustc_session::{{declare_tool_lint, impl_lint_pass}};
167+
168+
"},
169+
pass_type = pass_type,
170+
pass_import = pass_import,
171+
context_import = context_import,
172+
)
173+
} else {
174+
format!(
175+
indoc! {"
176+
{pass_import}
177+
use rustc_lint::{{{context_import}, {pass_type}}};
178+
use rustc_session::{{declare_lint_pass, declare_tool_lint}};
179+
180+
"},
181+
pass_import = pass_import,
182+
pass_type = pass_type,
183+
context_import = context_import
184+
)
185+
});
186+
187+
result.push_str(&format!(
188+
indoc! {"
189+
declare_clippy_lint! {{
190+
/// ### What it does
191+
///
192+
/// ### Why is this bad?
193+
///
194+
/// ### Example
195+
/// ```rust
196+
/// // example code where clippy issues a warning
197+
/// ```
198+
/// Use instead:
199+
/// ```rust
200+
/// // example code which does not raise clippy warning
201+
/// ```
202+
pub {name_upper},
203+
{category},
204+
\"default lint description\"
205+
}}
206+
"},
207+
name_upper = name_upper,
208+
category = category,
209+
));
210+
211+
result.push_str(&if enable_msrv {
212+
format!(
213+
indoc! {"
214+
pub struct {name_camel} {{
215+
msrv: Option<RustcVersion>,
216+
}}
217+
218+
impl {name_camel} {{
219+
#[must_use]
220+
pub fn new(msrv: Option<RustcVersion>) -> Self {{
221+
Self {{ msrv }}
222+
}}
223+
}}
224+
225+
impl_lint_pass!({name_camel} => [{name_upper}]);
226+
227+
impl {pass_type}{pass_lifetimes} for {name_camel} {{
228+
extract_msrv_attr!({context_import});
229+
}}
230+
231+
// TODO: Register the lint pass in `clippy_lints/src/lib.rs`,
232+
// e.g. store.register_{pass_name}_pass(move || Box::new({module_name}::{name_camel}::new(msrv)));
233+
// TODO: Add MSRV level to `clippy_utils/src/msrvs.rs` if needed.
234+
// TODO: Add MSRV test to `tests/ui/min_rust_version_attr.rs`.
235+
// TODO: Update msrv config comment in `clippy_lints/src/utils/conf.rs`
236+
"},
237+
pass_type = pass_type,
238+
pass_lifetimes = pass_lifetimes,
239+
pass_name = pass_name,
240+
name_upper = name_upper,
241+
name_camel = name_camel,
242+
module_name = lint_name,
243+
context_import = context_import,
244+
)
245+
} else {
246+
format!(
247+
indoc! {"
248+
declare_lint_pass!({name_camel} => [{name_upper}]);
249+
250+
impl {pass_type}{pass_lifetimes} for {name_camel} {{}}
251+
//
252+
// TODO: Register the lint pass in `clippy_lints/src/lib.rs`,
253+
// e.g. store.register_{pass_name}_pass(|| Box::new({module_name}::{name_camel}));
254+
"},
255+
pass_type = pass_type,
256+
pass_lifetimes = pass_lifetimes,
257+
pass_name = pass_name,
258+
name_upper = name_upper,
259+
name_camel = name_camel,
260+
module_name = lint_name,
261+
)
262+
});
263+
264+
result
201265
}
202266

203267
#[test]

src/tools/clippy/clippy_dev/src/update_lints.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -619,8 +619,8 @@ mod tests {
619619
Lint::new("should_assert_eq2", "group2", "abc", None, "module_name"),
620620
];
621621
let expected = vec![
622-
format!("[`should_assert_eq`]: {}#should_assert_eq", DOCS_LINK.to_string()),
623-
format!("[`should_assert_eq2`]: {}#should_assert_eq2", DOCS_LINK.to_string()),
622+
format!("[`should_assert_eq`]: {}#should_assert_eq", DOCS_LINK),
623+
format!("[`should_assert_eq2`]: {}#should_assert_eq2", DOCS_LINK),
624624
];
625625
assert_eq!(expected, gen_changelog_lint_list(lints.iter()));
626626
}

src/tools/clippy/clippy_lints/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_lints"
3-
version = "0.1.57"
3+
version = "0.1.58"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"

0 commit comments

Comments
 (0)