Skip to content

Commit 5b09f90

Browse files
Merge branch 'rust-lang:master' into 11710
2 parents 235f45c + 4a0c36d commit 5b09f90

File tree

261 files changed

+8467
-9754
lines changed

Some content is hidden

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

261 files changed

+8467
-9754
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,10 @@ For example, the [`else_if_without_else`][else_if_without_else] lint is register
146146
pub mod else_if_without_else;
147147
// ...
148148

149-
pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: &Conf) {
149+
pub fn register_lints(store: &mut rustc_lint::LintStore, conf: &'static Conf) {
150150
// ...
151151
store.register_early_pass(|| Box::new(else_if_without_else::ElseIfWithoutElse));
152152
// ...
153-
154-
store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![
155-
// ...
156-
LintId::of(&else_if_without_else::ELSE_IF_WITHOUT_ELSE),
157-
// ...
158-
]);
159153
}
160154
```
161155

book/src/development/adding_lints.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ When using `cargo dev new_lint`, the lint is automatically registered and
270270
nothing more has to be done.
271271

272272
When declaring a new lint by hand and `cargo dev update_lints` is used, the lint
273-
pass may have to be registered manually in the `register_plugins` function in
273+
pass may have to be registered manually in the `register_lints` function in
274274
`clippy_lints/src/lib.rs`:
275275

276276
```rust,ignore

book/src/development/defining_lints.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ However, sometimes we might want to declare a new lint by hand. In this case,
186186
we'd use `cargo dev update_lints` command afterwards.
187187

188188
When a lint is manually declared, we might need to register the lint pass
189-
manually in the `register_plugins` function in `clippy_lints/src/lib.rs`:
189+
manually in the `register_lints` function in `clippy_lints/src/lib.rs`:
190190

191191
```rust
192192
store.register_late_pass(|_| Box::new(foo_functions::FooFunctions));

clippy_config/src/types.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use serde::de::{self, Deserializer, Visitor};
22
use serde::{ser, Deserialize, Serialize};
33
use std::fmt;
4-
use std::hash::{Hash, Hasher};
54

65
#[derive(Clone, Debug, Deserialize)]
76
pub struct Rename {
@@ -33,32 +32,19 @@ impl DisallowedPath {
3332
}
3433
}
3534

36-
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Deserialize, Serialize)]
35+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)]
3736
pub enum MatchLintBehaviour {
3837
AllTypes,
3938
WellKnownTypes,
4039
Never,
4140
}
4241

43-
#[derive(Clone, Debug)]
42+
#[derive(Debug)]
4443
pub struct MacroMatcher {
4544
pub name: String,
46-
pub braces: (String, String),
45+
pub braces: (char, char),
4746
}
4847

49-
impl Hash for MacroMatcher {
50-
fn hash<H: Hasher>(&self, state: &mut H) {
51-
self.name.hash(state);
52-
}
53-
}
54-
55-
impl PartialEq for MacroMatcher {
56-
fn eq(&self, other: &Self) -> bool {
57-
self.name == other.name
58-
}
59-
}
60-
impl Eq for MacroMatcher {}
61-
6248
impl<'de> Deserialize<'de> for MacroMatcher {
6349
fn deserialize<D>(deser: D) -> Result<Self, D::Error>
6450
where
@@ -83,7 +69,7 @@ impl<'de> Deserialize<'de> for MacroMatcher {
8369
V: de::MapAccess<'de>,
8470
{
8571
let mut name = None;
86-
let mut brace: Option<String> = None;
72+
let mut brace: Option<char> = None;
8773
while let Some(key) = map.next_key()? {
8874
match key {
8975
Field::Name => {
@@ -104,7 +90,7 @@ impl<'de> Deserialize<'de> for MacroMatcher {
10490
let brace = brace.ok_or_else(|| de::Error::missing_field("brace"))?;
10591
Ok(MacroMatcher {
10692
name,
107-
braces: [("(", ")"), ("{", "}"), ("[", "]")]
93+
braces: [('(', ')'), ('{', '}'), ('[', ']')]
10894
.into_iter()
10995
.find(|b| b.0 == brace)
11096
.map(|(o, c)| (o.to_owned(), c.to_owned()))

clippy_lints/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ cargo_metadata = "0.15.3"
1414
clippy_config = { path = "../clippy_config" }
1515
clippy_utils = { path = "../clippy_utils" }
1616
declare_clippy_lint = { path = "../declare_clippy_lint" }
17-
if_chain = "1.0"
1817
itertools = "0.10.1"
1918
quine-mc_cluskey = "0.2"
2019
regex-syntax = "0.7"

clippy_lints/src/allow_attributes.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,24 +52,22 @@ declare_lint_pass!(AllowAttribute => [ALLOW_ATTRIBUTES]);
5252
impl LateLintPass<'_> for AllowAttribute {
5353
// Separate each crate's features.
5454
fn check_attribute<'cx>(&mut self, cx: &LateContext<'cx>, attr: &'cx Attribute) {
55-
if_chain! {
56-
if !in_external_macro(cx.sess(), attr.span);
57-
if cx.tcx.features().lint_reasons;
58-
if let AttrStyle::Outer = attr.style;
59-
if let Some(ident) = attr.ident();
60-
if ident.name == rustc_span::symbol::sym::allow;
61-
if !is_from_proc_macro(cx, &attr);
62-
then {
63-
span_lint_and_sugg(
64-
cx,
65-
ALLOW_ATTRIBUTES,
66-
ident.span,
67-
"#[allow] attribute found",
68-
"replace it with",
69-
"expect".into(),
70-
Applicability::MachineApplicable,
71-
);
72-
}
55+
if !in_external_macro(cx.sess(), attr.span)
56+
&& cx.tcx.features().lint_reasons
57+
&& let AttrStyle::Outer = attr.style
58+
&& let Some(ident) = attr.ident()
59+
&& ident.name == rustc_span::symbol::sym::allow
60+
&& !is_from_proc_macro(cx, &attr)
61+
{
62+
span_lint_and_sugg(
63+
cx,
64+
ALLOW_ATTRIBUTES,
65+
ident.span,
66+
"#[allow] attribute found",
67+
"replace it with",
68+
"expect".into(),
69+
Applicability::MachineApplicable,
70+
);
7371
}
7472
}
7573
}

clippy_lints/src/arc_with_non_send_sync.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ declare_clippy_lint! {
1414
/// This lint warns when you use `Arc` with a type that does not implement `Send` or `Sync`.
1515
///
1616
/// ### Why is this bad?
17-
/// `Arc<T>` is only `Send`/`Sync` when `T` is [both `Send` and `Sync`](https://doc.rust-lang.org/std/sync/struct.Arc.html#impl-Send-for-Arc%3CT%3E),
17+
/// `Arc<T>` is an Atomic `RC<T>` and guarantees that updates to the reference counter are
18+
/// Atomic. This is useful in multiprocessing scenarios. To send an `Arc<T>` across processes
19+
/// and make use of the atomic ref counter, `T` must be [both `Send` and `Sync`](https://doc.rust-lang.org/std/sync/struct.Arc.html#impl-Send-for-Arc%3CT%3E),
1820
/// either `T` should be made `Send + Sync` or an `Rc` should be used instead of an `Arc`
1921
///
2022
/// ### Example
@@ -34,7 +36,7 @@ declare_clippy_lint! {
3436
#[clippy::version = "1.72.0"]
3537
pub ARC_WITH_NON_SEND_SYNC,
3638
suspicious,
37-
"using `Arc` with a type that does not implement `Send` or `Sync`"
39+
"using `Arc` with a type that does not implement `Send` and `Sync`"
3840
}
3941
declare_lint_pass!(ArcWithNonSendSync => [ARC_WITH_NON_SEND_SYNC]);
4042

@@ -61,19 +63,25 @@ impl<'tcx> LateLintPass<'tcx> for ArcWithNonSendSync {
6163
cx,
6264
ARC_WITH_NON_SEND_SYNC,
6365
expr.span,
64-
"usage of an `Arc` that is not `Send` or `Sync`",
66+
"usage of an `Arc` that is not `Send` and `Sync`",
6567
|diag| {
6668
with_forced_trimmed_paths!({
69+
diag.note(format!("`Arc<{arg_ty}>` is not `Send` and `Sync` as:"));
70+
6771
if !is_send {
68-
diag.note(format!("the trait `Send` is not implemented for `{arg_ty}`"));
72+
diag.note(format!("- the trait `Send` is not implemented for `{arg_ty}`"));
6973
}
7074
if !is_sync {
71-
diag.note(format!("the trait `Sync` is not implemented for `{arg_ty}`"));
75+
diag.note(format!("- the trait `Sync` is not implemented for `{arg_ty}`"));
7276
}
7377

74-
diag.note(format!("required for `{ty}` to implement `Send` and `Sync`"));
78+
diag.help("consider using an `Rc` instead. `Arc` does not provide benefits for non `Send` and `Sync` types");
79+
80+
diag.note("if you intend to use `Arc` with `Send` and `Sync` traits");
7581

76-
diag.help("consider using an `Rc` instead or wrapping the inner type with a `Mutex`");
82+
diag.note(format!(
83+
"wrap the inner type with a `Mutex` or implement `Send` and `Sync` for `{arg_ty}`"
84+
));
7785
});
7886
},
7987
);

clippy_lints/src/attrs.rs

Lines changed: 57 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sug
55
use clippy_utils::is_from_proc_macro;
66
use clippy_utils::macros::{is_panic, macro_backtrace};
77
use clippy_utils::source::{first_line_of_span, is_present_in_source, snippet_opt, without_block_comments};
8-
use if_chain::if_chain;
98
use rustc_ast::token::{Token, TokenKind};
109
use rustc_ast::tokenstream::TokenTree;
1110
use rustc_ast::{
@@ -471,13 +470,11 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
471470
return;
472471
}
473472
for item in items {
474-
if_chain! {
475-
if let NestedMetaItem::MetaItem(mi) = &item;
476-
if let MetaItemKind::NameValue(lit) = &mi.kind;
477-
if mi.has_name(sym::since);
478-
then {
479-
check_semver(cx, item.span(), lit);
480-
}
473+
if let NestedMetaItem::MetaItem(mi) = &item
474+
&& let MetaItemKind::NameValue(lit) = &mi.kind
475+
&& mi.has_name(sym::since)
476+
{
477+
check_semver(cx, item.span(), lit);
481478
}
482479
}
483480
}
@@ -580,15 +577,13 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
580577

581578
/// Returns the lint name if it is clippy lint.
582579
fn extract_clippy_lint(lint: &NestedMetaItem) -> Option<Symbol> {
583-
if_chain! {
584-
if let Some(meta_item) = lint.meta_item();
585-
if meta_item.path.segments.len() > 1;
586-
if let tool_name = meta_item.path.segments[0].ident;
587-
if tool_name.name == sym::clippy;
588-
then {
589-
let lint_name = meta_item.path.segments.last().unwrap().ident.name;
590-
return Some(lint_name);
591-
}
580+
if let Some(meta_item) = lint.meta_item()
581+
&& meta_item.path.segments.len() > 1
582+
&& let tool_name = meta_item.path.segments[0].ident
583+
&& tool_name.name == sym::clippy
584+
{
585+
let lint_name = meta_item.path.segments.last().unwrap().ident.name;
586+
return Some(lint_name);
592587
}
593588
None
594589
}
@@ -857,40 +852,38 @@ fn check_empty_line_after_outer_attr(cx: &EarlyContext<'_>, item: &rustc_ast::It
857852
}
858853

859854
fn check_deprecated_cfg_attr(cx: &EarlyContext<'_>, attr: &Attribute, msrv: &Msrv) {
860-
if_chain! {
861-
if msrv.meets(msrvs::TOOL_ATTRIBUTES);
855+
if msrv.meets(msrvs::TOOL_ATTRIBUTES)
862856
// check cfg_attr
863-
if attr.has_name(sym::cfg_attr);
864-
if let Some(items) = attr.meta_item_list();
865-
if items.len() == 2;
857+
&& attr.has_name(sym::cfg_attr)
858+
&& let Some(items) = attr.meta_item_list()
859+
&& items.len() == 2
866860
// check for `rustfmt`
867-
if let Some(feature_item) = items[0].meta_item();
868-
if feature_item.has_name(sym::rustfmt);
861+
&& let Some(feature_item) = items[0].meta_item()
862+
&& feature_item.has_name(sym::rustfmt)
869863
// check for `rustfmt_skip` and `rustfmt::skip`
870-
if let Some(skip_item) = &items[1].meta_item();
871-
if skip_item.has_name(sym!(rustfmt_skip))
864+
&& let Some(skip_item) = &items[1].meta_item()
865+
&& (skip_item.has_name(sym!(rustfmt_skip))
872866
|| skip_item
873867
.path
874868
.segments
875869
.last()
876870
.expect("empty path in attribute")
877871
.ident
878872
.name
879-
== sym::skip;
873+
== sym::skip)
880874
// Only lint outer attributes, because custom inner attributes are unstable
881875
// Tracking issue: https://github.com/rust-lang/rust/issues/54726
882-
if attr.style == AttrStyle::Outer;
883-
then {
884-
span_lint_and_sugg(
885-
cx,
886-
DEPRECATED_CFG_ATTR,
887-
attr.span,
888-
"`cfg_attr` is deprecated for rustfmt and got replaced by tool attributes",
889-
"use",
890-
"#[rustfmt::skip]".to_string(),
891-
Applicability::MachineApplicable,
892-
);
893-
}
876+
&& attr.style == AttrStyle::Outer
877+
{
878+
span_lint_and_sugg(
879+
cx,
880+
DEPRECATED_CFG_ATTR,
881+
attr.span,
882+
"`cfg_attr` is deprecated for rustfmt and got replaced by tool attributes",
883+
"use",
884+
"#[rustfmt::skip]".to_string(),
885+
Applicability::MachineApplicable,
886+
);
894887
}
895888
}
896889

@@ -990,12 +983,10 @@ fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) {
990983
mismatched.extend(find_mismatched_target_os(list));
991984
},
992985
MetaItemKind::Word => {
993-
if_chain! {
994-
if let Some(ident) = meta.ident();
995-
if let Some(os) = find_os(ident.name.as_str());
996-
then {
997-
mismatched.push((os, ident.span));
998-
}
986+
if let Some(ident) = meta.ident()
987+
&& let Some(os) = find_os(ident.name.as_str())
988+
{
989+
mismatched.push((os, ident.span));
999990
}
1000991
},
1001992
MetaItemKind::NameValue(..) => {},
@@ -1006,30 +997,28 @@ fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) {
1006997
mismatched
1007998
}
1008999

1009-
if_chain! {
1010-
if attr.has_name(sym::cfg);
1011-
if let Some(list) = attr.meta_item_list();
1012-
let mismatched = find_mismatched_target_os(&list);
1013-
if !mismatched.is_empty();
1014-
then {
1015-
let mess = "operating system used in target family position";
1016-
1017-
span_lint_and_then(cx, MISMATCHED_TARGET_OS, attr.span, mess, |diag| {
1018-
// Avoid showing the unix suggestion multiple times in case
1019-
// we have more than one mismatch for unix-like systems
1020-
let mut unix_suggested = false;
1021-
1022-
for (os, span) in mismatched {
1023-
let sugg = format!("target_os = \"{os}\"");
1024-
diag.span_suggestion(span, "try", sugg, Applicability::MaybeIncorrect);
1025-
1026-
if !unix_suggested && is_unix(os) {
1027-
diag.help("did you mean `unix`?");
1028-
unix_suggested = true;
1029-
}
1000+
if attr.has_name(sym::cfg)
1001+
&& let Some(list) = attr.meta_item_list()
1002+
&& let mismatched = find_mismatched_target_os(&list)
1003+
&& !mismatched.is_empty()
1004+
{
1005+
let mess = "operating system used in target family position";
1006+
1007+
span_lint_and_then(cx, MISMATCHED_TARGET_OS, attr.span, mess, |diag| {
1008+
// Avoid showing the unix suggestion multiple times in case
1009+
// we have more than one mismatch for unix-like systems
1010+
let mut unix_suggested = false;
1011+
1012+
for (os, span) in mismatched {
1013+
let sugg = format!("target_os = \"{os}\"");
1014+
diag.span_suggestion(span, "try", sugg, Applicability::MaybeIncorrect);
1015+
1016+
if !unix_suggested && is_unix(os) {
1017+
diag.help("did you mean `unix`?");
1018+
unix_suggested = true;
10301019
}
1031-
});
1032-
}
1020+
}
1021+
});
10331022
}
10341023
}
10351024

0 commit comments

Comments
 (0)