Skip to content

Update Clippy #101609

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

Merged
merged 61 commits into from
Sep 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
e4eddc6
Replace `Body::basic_blocks()` with field access
tmiasko Jul 5, 2022
3b80e99
Use `&'hir Expr` everywhere.
nnethercote Aug 26, 2022
3ce109e
Use `&'hir Ty` everywhere.
nnethercote Aug 26, 2022
ce847be
Revert let_chains stabilization
Noratrieb Aug 20, 2022
98fe5f7
Fix tests due to stricter invalid_value
5225225 Aug 29, 2022
7ba06ec
Auto merge of #98919 - 5225225:stricter-invalid-value, r=RalfJung
bors Aug 30, 2022
28a055d
match_wild_err_arm: Fix typo in note text
softmoth Aug 31, 2022
7298de2
fix a clippy test
RalfJung Aug 31, 2022
fb41bfa
Merge commit 'f51aade56f93175dde89177a92e3669ebd8e7592' into clippyup
Jarcho Aug 31, 2022
7bd5b01
Use `CountIsStart` in clippy
Jarcho Aug 31, 2022
c782767
Auto merge of #9403 - softmoth:wild_err_expect, r=Alexendoo
bors Aug 31, 2022
5b784f8
Auto merge of #101249 - matthiaskrgr:rollup-wahnoz8, r=matthiaskrgr
bors Aug 31, 2022
d4a0785
Correctly handle unescape warnings
Jarcho Sep 1, 2022
291f75e
Auto merge of #9406 - Jarcho:unescape_ice, r=Manishearth
bors Sep 1, 2022
6e14e60
Fix {subopt,imprec}_float not lint const.*(const)
lukaslueg Aug 31, 2022
a80e278
Auto merge of #9404 - lukaslueg:issue9402, r=giraffate
bors Sep 1, 2022
b1f86a4
New lint `bool_to_int_with_if`
Jun 30, 2022
334be18
Auto merge of #9412 - xFrednet:jst-r-bool-to-int-lint, r=xFrednet
bors Sep 1, 2022
bd70ccf
Don't use `hir_ty_to_ty` in `result_large_err` as it sometimes leaves…
Jarcho Sep 2, 2022
e5f30f4
clippy: BindingAnnotation change
camsteffen Aug 30, 2022
958a9cf
Auto merge of #9417 - Jarcho:ice_9414, r=Alexendoo
bors Sep 2, 2022
ffc75af
Fix `mut_mutex_lock` for Mutex behind imm deref
lukaslueg Sep 2, 2022
c36696a
Auto merge of #9418 - lukaslueg:issue9415, r=llogiq
bors Sep 2, 2022
ad72aee
add `--explain` subcommand
llogiq Jun 5, 2022
30e4532
Auto merge of #8952 - rust-lang:explain, r=xFredNet
bors Sep 2, 2022
584000a
Use `approx_ty_size` for `large_enum_variant`
lukaslueg Aug 30, 2022
99ab5fe
Auto merge of #9400 - lukaslueg:approx_large_enum, r=llogiq
bors Sep 3, 2022
750a2d5
Fix `unnecessary_to_owned` false positive
Sep 3, 2022
46b7cb6
Auto merge of #9424 - mikerite:fix-9351-4, r=xFrednet
bors Sep 4, 2022
2cc20e3
fix wording for `derivable_impls`
kraktus Sep 4, 2022
90804d3
Auto merge of #9425 - kraktus:patch-1, r=xFrednet
bors Sep 4, 2022
f0e586c
Suggest `Entry::or_default` for `Entry::or_insert(Default::default())`
relrelb Aug 16, 2022
25f6f18
Make `hir::PathSegment::res` non-optional.
nnethercote Aug 30, 2022
b763b14
Auto merge of #9342 - relrelb:or_default, r=dswij
bors Sep 5, 2022
2d4349c
Pack `Term` in the same way as `GenericArg`.
nnethercote Sep 5, 2022
9ae3292
Rollup merge of #101142 - nnethercote:improve-hir-stats, r=davidtwco
Dylan-DPC Sep 5, 2022
4bcadde
separate the receiver from arguments in HIR under /clippy
TaKO8Ki Sep 1, 2022
097ef51
refactor: remove unnecessary variables
TaKO8Ki Sep 2, 2022
5ea9977
Auto merge of #101228 - nnethercote:simplify-hir-PathSegment, r=petro…
bors Sep 5, 2022
8931da4
use `propagate_through_exprs` instead of `propagate_through_expr`
TaKO8Ki Sep 5, 2022
2ccf843
Auto merge of #101261 - TaKO8Ki:separate-receiver-from-arguments-in-h…
bors Sep 5, 2022
ce339b2
Auto merge of #101241 - camsteffen:refactor-binding-annotations, r=cj…
bors Sep 6, 2022
b21d9d3
Suggest `unwrap_or_default` when closure returns `"".to_string`
xphoniex Sep 6, 2022
e1b3483
Lower the assume intrinsic to a MIR statement
oli-obk Jun 30, 2022
9cbbd4a
Generalize the Assume intrinsic statement to a general Intrinsic stat…
oli-obk Jul 12, 2022
7babd1b
Auto merge of #9421 - xphoniex:fix-#9420, r=giraffate
bors Sep 6, 2022
0d078c9
[Arithmetic] Consider literals
c410-f3r Sep 7, 2022
567e1bb
Auto merge of #101432 - nnethercote:shrink-PredicateS, r=lcnr
bors Sep 7, 2022
1585932
Fix hang in `vec_init_then_push`
Jarcho Sep 7, 2022
da29f89
Auto merge of #9441 - Jarcho:hang_9433, r=Alexendoo
bors Sep 7, 2022
617417e
Auto merge of #9365 - c410-f3r:arith, r=Alexendoo
bors Sep 7, 2022
51d8b6c
Rename the `arithmetic` lint
c410-f3r Sep 8, 2022
2c5524f
Update cargo in lintcheck_crates.toml
Alexendoo Sep 8, 2022
b30c5c0
Auto merge of #9444 - Alexendoo:lintcheck-cargo, r=matthiaskrgr
bors Sep 8, 2022
1f92c9d
Auto merge of #9443 - c410-f3r:arith, r=flip1995
bors Sep 8, 2022
a6d8afd
Fix `range_{plus,minus}_one` bad suggestions
Sep 8, 2022
4ee55c5
Merge remote-tracking branch 'upstream/auto' into rustup
flip1995 Sep 8, 2022
df536c9
Bump nightly version -> 2022-09-08
flip1995 Sep 8, 2022
32fa80d
Auto merge of #9447 - flip1995:rustup, r=flip1995
bors Sep 8, 2022
b52fb52
Auto merge of #9446 - mikerite:fix-9431-2, r=giraffate
bors Sep 8, 2022
ce03f15
Merge commit 'b52fb5234cd7c11ecfae51897a6f7fa52e8777fc' into clippyup
flip1995 Sep 9, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion src/tools/clippy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3583,7 +3583,7 @@ Released 2018-09-13
[`almost_complete_letter_range`]: https://rust-lang.github.io/rust-clippy/master/index.html#almost_complete_letter_range
[`almost_swapped`]: https://rust-lang.github.io/rust-clippy/master/index.html#almost_swapped
[`approx_constant`]: https://rust-lang.github.io/rust-clippy/master/index.html#approx_constant
[`arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#arithmetic
[`arithmetic_side_effects`]: https://rust-lang.github.io/rust-clippy/master/index.html#arithmetic_side_effects
[`as_conversions`]: https://rust-lang.github.io/rust-clippy/master/index.html#as_conversions
[`as_underscore`]: https://rust-lang.github.io/rust-clippy/master/index.html#as_underscore
[`assertions_on_constants`]: https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_constants
Expand All @@ -3603,6 +3603,7 @@ Released 2018-09-13
[`blocks_in_if_conditions`]: https://rust-lang.github.io/rust-clippy/master/index.html#blocks_in_if_conditions
[`bool_assert_comparison`]: https://rust-lang.github.io/rust-clippy/master/index.html#bool_assert_comparison
[`bool_comparison`]: https://rust-lang.github.io/rust-clippy/master/index.html#bool_comparison
[`bool_to_int_with_if`]: https://rust-lang.github.io/rust-clippy/master/index.html#bool_to_int_with_if
[`borrow_as_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#borrow_as_ptr
[`borrow_deref_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#borrow_deref_ref
[`borrow_interior_mutable_const`]: https://rust-lang.github.io/rust-clippy/master/index.html#borrow_interior_mutable_const
Expand Down
194 changes: 165 additions & 29 deletions src/tools/clippy/clippy_dev/src/update_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use aho_corasick::AhoCorasickBuilder;
use indoc::writedoc;
use itertools::Itertools;
use rustc_lexer::{tokenize, unescape, LiteralKind, TokenKind};
use std::collections::{HashMap, HashSet};
use std::collections::{BTreeSet, HashMap, HashSet};
use std::ffi::OsStr;
use std::fmt::Write;
use std::fs::{self, OpenOptions};
Expand Down Expand Up @@ -124,6 +124,8 @@ fn generate_lint_files(
let content = gen_lint_group_list("all", all_group_lints);
process_file("clippy_lints/src/lib.register_all.rs", update_mode, &content);

update_docs(update_mode, &usable_lints);

for (lint_group, lints) in Lint::by_lint_group(usable_lints.into_iter().chain(internal_lints)) {
let content = gen_lint_group_list(&lint_group, lints.iter());
process_file(
Expand All @@ -140,6 +142,62 @@ fn generate_lint_files(
process_file("tests/ui/rename.rs", update_mode, &content);
}

fn update_docs(update_mode: UpdateMode, usable_lints: &[Lint]) {
replace_region_in_file(update_mode, Path::new("src/docs.rs"), "docs! {\n", "\n}\n", |res| {
for name in usable_lints.iter().map(|lint| lint.name.clone()).sorted() {
writeln!(res, r#" "{name}","#).unwrap();
}
});

if update_mode == UpdateMode::Check {
let mut extra = BTreeSet::new();
let mut lint_names = usable_lints
.iter()
.map(|lint| lint.name.clone())
.collect::<BTreeSet<_>>();
for file in std::fs::read_dir("src/docs").unwrap() {
let filename = file.unwrap().file_name().into_string().unwrap();
if let Some(name) = filename.strip_suffix(".txt") {
if !lint_names.remove(name) {
extra.insert(name.to_string());
}
}
}

let failed = print_lint_names("extra lint docs:", &extra) | print_lint_names("missing lint docs:", &lint_names);

if failed {
exit_with_failure();
}
} else {
if std::fs::remove_dir_all("src/docs").is_err() {
eprintln!("could not remove src/docs directory");
}
if std::fs::create_dir("src/docs").is_err() {
eprintln!("could not recreate src/docs directory");
}
}
for lint in usable_lints {
process_file(
Path::new("src/docs").join(lint.name.clone() + ".txt"),
update_mode,
&lint.documentation,
);
}
}

fn print_lint_names(header: &str, lints: &BTreeSet<String>) -> bool {
if lints.is_empty() {
return false;
}
println!("{}", header);
for lint in lints.iter().sorted() {
println!(" {}", lint);
}
println!();
true
}

pub fn print_lints() {
let (lint_list, _, _) = gather_all();
let usable_lints = Lint::usable_lints(&lint_list);
Expand Down Expand Up @@ -589,17 +647,26 @@ struct Lint {
desc: String,
module: String,
declaration_range: Range<usize>,
documentation: String,
}

impl Lint {
#[must_use]
fn new(name: &str, group: &str, desc: &str, module: &str, declaration_range: Range<usize>) -> Self {
fn new(
name: &str,
group: &str,
desc: &str,
module: &str,
declaration_range: Range<usize>,
documentation: String,
) -> Self {
Self {
name: name.to_lowercase(),
group: group.into(),
desc: remove_line_splices(desc),
module: module.into(),
declaration_range,
documentation,
}
}

Expand Down Expand Up @@ -852,27 +919,35 @@ fn parse_contents(contents: &str, module: &str, lints: &mut Vec<Lint>) {
}| token_kind == &TokenKind::Ident && *content == "declare_clippy_lint",
) {
let start = range.start;

let mut iter = iter
.by_ref()
.filter(|t| !matches!(t.token_kind, TokenKind::Whitespace | TokenKind::LineComment { .. }));
let mut docs = String::with_capacity(128);
let mut iter = iter.by_ref().filter(|t| !matches!(t.token_kind, TokenKind::Whitespace));
// matches `!{`
match_tokens!(iter, Bang OpenBrace);
match iter.next() {
// #[clippy::version = "version"] pub
Some(LintDeclSearchResult {
token_kind: TokenKind::Pound,
..
}) => {
match_tokens!(iter, OpenBracket Ident Colon Colon Ident Eq Literal{..} CloseBracket Ident);
},
// pub
Some(LintDeclSearchResult {
token_kind: TokenKind::Ident,
..
}) => (),
_ => continue,
let mut in_code = false;
while let Some(t) = iter.next() {
match t.token_kind {
TokenKind::LineComment { .. } => {
if let Some(line) = t.content.strip_prefix("/// ").or_else(|| t.content.strip_prefix("///")) {
if line.starts_with("```") {
docs += "```\n";
in_code = !in_code;
} else if !(in_code && line.starts_with("# ")) {
docs += line;
docs.push('\n');
}
}
},
TokenKind::Pound => {
match_tokens!(iter, OpenBracket Ident Colon Colon Ident Eq Literal{..} CloseBracket Ident);
break;
},
TokenKind::Ident => {
break;
},
_ => {},
}
}
docs.pop(); // remove final newline

let (name, group, desc) = match_tokens!(
iter,
Expand All @@ -890,7 +965,7 @@ fn parse_contents(contents: &str, module: &str, lints: &mut Vec<Lint>) {
..
}) = iter.next()
{
lints.push(Lint::new(name, group, desc, module, start..range.end));
lints.push(Lint::new(name, group, desc, module, start..range.end, docs));
}
}
}
Expand Down Expand Up @@ -977,7 +1052,11 @@ fn remove_line_splices(s: &str) -> String {
.and_then(|s| s.strip_suffix('"'))
.unwrap_or_else(|| panic!("expected quoted string, found `{}`", s));
let mut res = String::with_capacity(s.len());
unescape::unescape_literal(s, unescape::Mode::Str, &mut |range, _| res.push_str(&s[range]));
unescape::unescape_literal(s, unescape::Mode::Str, &mut |range, ch| {
if ch.is_ok() {
res.push_str(&s[range]);
}
});
res
}

Expand Down Expand Up @@ -1116,13 +1195,15 @@ mod tests {
"\"really long text\"",
"module_name",
Range::default(),
String::new(),
),
Lint::new(
"doc_markdown",
"pedantic",
"\"single line\"",
"module_name",
Range::default(),
String::new(),
),
];
assert_eq!(expected, result);
Expand Down Expand Up @@ -1162,20 +1243,23 @@ mod tests {
"\"abc\"",
"module_name",
Range::default(),
String::new(),
),
Lint::new(
"should_assert_eq2",
"internal",
"\"abc\"",
"module_name",
Range::default(),
String::new(),
),
Lint::new(
"should_assert_eq2",
"internal_style",
"\"abc\"",
"module_name",
Range::default(),
String::new(),
),
];
let expected = vec![Lint::new(
Expand All @@ -1184,29 +1268,59 @@ mod tests {
"\"abc\"",
"module_name",
Range::default(),
String::new(),
)];
assert_eq!(expected, Lint::usable_lints(&lints));
}

#[test]
fn test_by_lint_group() {
let lints = vec![
Lint::new("should_assert_eq", "group1", "\"abc\"", "module_name", Range::default()),
Lint::new(
"should_assert_eq",
"group1",
"\"abc\"",
"module_name",
Range::default(),
String::new(),
),
Lint::new(
"should_assert_eq2",
"group2",
"\"abc\"",
"module_name",
Range::default(),
String::new(),
),
Lint::new(
"incorrect_match",
"group1",
"\"abc\"",
"module_name",
Range::default(),
String::new(),
),
Lint::new("incorrect_match", "group1", "\"abc\"", "module_name", Range::default()),
];
let mut expected: HashMap<String, Vec<Lint>> = HashMap::new();
expected.insert(
"group1".to_string(),
vec![
Lint::new("should_assert_eq", "group1", "\"abc\"", "module_name", Range::default()),
Lint::new("incorrect_match", "group1", "\"abc\"", "module_name", Range::default()),
Lint::new(
"should_assert_eq",
"group1",
"\"abc\"",
"module_name",
Range::default(),
String::new(),
),
Lint::new(
"incorrect_match",
"group1",
"\"abc\"",
"module_name",
Range::default(),
String::new(),
),
],
);
expected.insert(
Expand All @@ -1217,6 +1331,7 @@ mod tests {
"\"abc\"",
"module_name",
Range::default(),
String::new(),
)],
);
assert_eq!(expected, Lint::by_lint_group(lints.into_iter()));
Expand Down Expand Up @@ -1255,9 +1370,30 @@ mod tests {
#[test]
fn test_gen_lint_group_list() {
let lints = vec![
Lint::new("abc", "group1", "\"abc\"", "module_name", Range::default()),
Lint::new("should_assert_eq", "group1", "\"abc\"", "module_name", Range::default()),
Lint::new("internal", "internal_style", "\"abc\"", "module_name", Range::default()),
Lint::new(
"abc",
"group1",
"\"abc\"",
"module_name",
Range::default(),
String::new(),
),
Lint::new(
"should_assert_eq",
"group1",
"\"abc\"",
"module_name",
Range::default(),
String::new(),
),
Lint::new(
"internal",
"internal_style",
"\"abc\"",
"module_name",
Range::default(),
String::new(),
),
];
let expected = GENERATED_FILE_COMMENT.to_string()
+ &[
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/async_yields_async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl<'tcx> LateLintPass<'tcx> for AsyncYieldsAsync {
hir_id: body.value.hir_id,
};
let typeck_results = cx.tcx.typeck_body(body_id);
let expr_ty = typeck_results.expr_ty(&body.value);
let expr_ty = typeck_results.expr_ty(body.value);

if implements_trait(cx, expr_ty, future_trait_def_id, &[]) {
let return_expr_span = match &body.value.kind {
Expand Down
6 changes: 3 additions & 3 deletions src/tools/clippy/clippy_lints/src/attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,15 +475,15 @@ fn check_lint_reason(cx: &LateContext<'_>, name: Symbol, items: &[NestedMetaItem

fn is_relevant_item(cx: &LateContext<'_>, item: &Item<'_>) -> bool {
if let ItemKind::Fn(_, _, eid) = item.kind {
is_relevant_expr(cx, cx.tcx.typeck_body(eid), &cx.tcx.hir().body(eid).value)
is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir().body(eid).value)
} else {
true
}
}

fn is_relevant_impl(cx: &LateContext<'_>, item: &ImplItem<'_>) -> bool {
match item.kind {
ImplItemKind::Fn(_, eid) => is_relevant_expr(cx, cx.tcx.typeck_body(eid), &cx.tcx.hir().body(eid).value),
ImplItemKind::Fn(_, eid) => is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir().body(eid).value),
_ => false,
}
}
Expand All @@ -492,7 +492,7 @@ fn is_relevant_trait(cx: &LateContext<'_>, item: &TraitItem<'_>) -> bool {
match item.kind {
TraitItemKind::Fn(_, TraitFn::Required(_)) => true,
TraitItemKind::Fn(_, TraitFn::Provided(eid)) => {
is_relevant_expr(cx, cx.tcx.typeck_body(eid), &cx.tcx.hir().body(eid).value)
is_relevant_expr(cx, cx.tcx.typeck_body(eid), cx.tcx.hir().body(eid).value)
},
_ => false,
}
Expand Down
Loading