Skip to content
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

Clippy subtree update #120345

Merged
merged 112 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
112 commits
Select commit Hold shift + click to select a range
8c79f78
`read_zero_byte_vec` refactor for better heuristics
dswij Nov 7, 2023
543d569
Make `HirEqInterExpr::eq_block` take comments into account
ARandomDev99 Jan 2, 2024
c2d071c
Documentation edits for arc_with_non_send_sync
talagrand Jan 9, 2024
7c389ac
Fix error warning span for issue12045
cocodery Jan 11, 2024
fb83ef6
Stop using `DiagnosticBuilder::buffer` in the parser.
nnethercote Jan 11, 2024
aa220c7
Merge commit '26ac6aab023393c94edf42f38f6ad31196009643'
flip1995 Jan 11, 2024
82841aa
Fix suggestion for `map_clone` on types implementing `Copy`
GuillaumeGomez Jan 11, 2024
74db4b7
Add new ui tests for `map_clone` lint on types implementing `Copy`
GuillaumeGomez Jan 11, 2024
85364e5
I'm not on vacation (again)
blyxyas Jan 11, 2024
6baa129
Auto merge of #119864 - matthiaskrgr:rollup-mc2qz13, r=matthiaskrgr
bors Jan 11, 2024
c537134
Auto merge of #12132 - blyxyas:not-on-vacation-again, r=xFrednet
bors Jan 11, 2024
88b5d51
Auto merge of #12129 - GuillaumeGomez:map-clone-copy, r=llogiq
bors Jan 11, 2024
1485e5c
check rust lints when an unknown lint is detected
chenyukang Jan 10, 2024
09d0241
Delegation implementation: step 1
Bryanskiy Nov 26, 2023
153b83f
[`useless_asref`]: check that the clone receiver is the local
y21 Jan 12, 2024
e9f8713
Rollup merge of #119819 - chenyukang:yukang-fix-118183-lint, r=davidtwco
GuillaumeGomez Jan 12, 2024
c8cd09a
Fix false positive in `PartialEq` check in `unconditional_recursion` …
GuillaumeGomez Jan 12, 2024
1326672
Add regression ui test for `unconditional_recursion` lint on `PartialEq`
GuillaumeGomez Jan 12, 2024
7eca5af
Auto merge of #12137 - GuillaumeGomez:fix-unconditional_recursion-fal…
bors Jan 12, 2024
68aceee
Improve help message for `search_is_some` lint
GuillaumeGomez Jan 12, 2024
37947ff
Update ui tests for `search_is_some` lint
GuillaumeGomez Jan 12, 2024
3b7ba1d
Improve `let_underscore_lock`
Noratrieb Jan 7, 2024
a71211d
Auto merge of #12140 - GuillaumeGomez:improve-message-search_is_some,…
bors Jan 12, 2024
5a45dbe
Auto merge of #118947 - Bryanskiy:delegStep1, r=petrochenkov,lcnr
bors Jan 13, 2024
e025356
from_over_into: suggest a correct conversion to ()
samueltardieu Jan 13, 2024
be5707c
lint on `.map(|&x| x.clone())`
y21 Jan 13, 2024
2469784
Add `.` to end of lint lists in configuration
blyxyas Jan 14, 2024
44f5d96
Change `PublicallyExported` -> `PubliclyExported`
blyxyas Jan 14, 2024
5769c21
chore: negative test for multiple crate versions not working when nam…
kristof-mattei Jan 14, 2024
d975e26
fix: add fix for bug, fix test name
kristof-mattei Jan 14, 2024
0774489
find function path references early in the lint pass
y21 Jan 14, 2024
1bcaf29
Correctly suggest `std` or `core` path depending if this is a `no_std…
GuillaumeGomez Jan 14, 2024
40a45a4
Update and add ui tests for core/std suggestions
GuillaumeGomez Jan 14, 2024
5d06fbb
fix: don't allocate new string when not needed
kristof-mattei Jan 14, 2024
b1c52d5
chore: add comments to explain reasoning
kristof-mattei Jan 14, 2024
ea585ef
chore: remove unneeded into_iter
kristof-mattei Jan 14, 2024
e8ec998
fix: crates are limited to ASCII values
kristof-mattei Jan 14, 2024
a9fa2f5
Auto merge of #12074 - ARandomDev99:12044-include-comments-while-chec…
bors Jan 15, 2024
37b8ae7
Auto merge of #12114 - talagrand:patch-1, r=Jarcho
bors Jan 15, 2024
d6ff2d2
Auto merge of #12141 - samueltardieu:issue-12138, r=Jarcho
bors Jan 15, 2024
692f53f
Auto merge of #12136 - y21:issue12135, r=Jarcho
bors Jan 15, 2024
33d8e47
Try to improve wording and fix dead link in description of arc_with_n…
adamreichold Dec 10, 2023
a16a850
Add "OpenTelemetry" to default `doc_valid_idents`
edmorley Dec 4, 2023
6c201db
Add suspicious_open_options lint.
atwam Oct 4, 2023
6fb471d
More helpful text, small style changes.
atwam Oct 10, 2023
2ec8729
PR Fixes
atwam Oct 10, 2023
84588a8
Add suggestion/fix to suspicious_open_options
atwam Oct 26, 2023
515fe65
Fix conflicts
atwam Jan 11, 2024
f09cd88
fix false positive in `suspicious_open_options`, make paths work
y21 Jan 13, 2024
ad2a2ba
Ensure `callee_id`s are body owners
smoelius Jan 15, 2024
771a2a9
Auto merge of #11926 - edmorley:update-default-doc_valid_idents, r=bl…
bors Jan 15, 2024
6a74a0e
compiler: Lower fn call arg spans down to MIR
Enselic Jan 12, 2024
874f851
Use `std_or_core` instead of doing check by hand every time
GuillaumeGomez Jan 15, 2024
a198904
Don't emit `derive_partial_eq_without_eq` lint if the type has the `n…
GuillaumeGomez Jan 15, 2024
136a582
Add `non_exhaustive` checks in `derive_partial_eq_without_eq.rs` ui test
GuillaumeGomez Jan 15, 2024
ecb0311
Auto merge of #12149 - GuillaumeGomez:core-std-suggestions, r=llogiq
bors Jan 16, 2024
169e2ab
Correctly handle type relative in `trait_duplication_in_bounds` lint
GuillaumeGomez Jan 16, 2024
7217c22
Update `trait_duplication_in_bounds.rs` ui test to add regression for…
GuillaumeGomez Jan 16, 2024
f7376a0
Deal with additional wrapping of async closure body in clippy
compiler-errors Jan 15, 2024
ca7b54b
Auto merge of #11945 - adamreichold:fix-lint-comments, r=Alexendoo
bors Jan 16, 2024
5f3a060
Auto merge of #11608 - atwam:suspicious-open-options, r=y21
bors Jan 16, 2024
33e1e6f
Add `PatKind::Err`
ShE3py Jan 17, 2024
4488653
Fix clippy
oli-obk Jan 12, 2024
e27ebf2
Auto merge of #11766 - dswij:issue-9274, r=blyxyas
bors Jan 17, 2024
2067fe4
Auto merge of #12155 - GuillaumeGomez:fix-9961, r=blyxyas
bors Jan 17, 2024
bb2d497
Auto merge of #12146 - kristof-mattei:multiple-crate-versions-with-da…
bors Jan 17, 2024
cc629f0
Rollup merge of #119978 - compiler-errors:async-closure-captures, r=o…
matthiaskrgr Jan 18, 2024
9fe7c6a
finally came up with some repro code
J-ZhengLi Jan 18, 2024
0e961cd
fix suggestion error with attr macros
J-ZhengLi Jan 18, 2024
6a331e3
Apply suggestions from code review
smoelius Jan 18, 2024
7a1e7d7
Don't forget that the lifetime on hir types is `'tcx`
oli-obk Feb 1, 2023
efd8daf
[`default_numeric_fallback`]: improve const context detection
y21 Jan 18, 2024
b08ffee
Auto merge of #12168 - y21:issue12159, r=blyxyas
bors Jan 18, 2024
4b3a9c0
Auto merge of #12167 - J-ZhengLi:issue12133, r=Alexendoo
bors Jan 18, 2024
21d719d
Rollup merge of #119869 - oli-obk:track_errors2, r=matthewjasper
matthiaskrgr Jan 18, 2024
c6079a6
blocks_in_conditions: do not warn if condition comes from macro
samueltardieu Jan 19, 2024
6fd0258
Auto merge of #12173 - samueltardieu:issue-12162, r=Manishearth
bors Jan 19, 2024
9661f9b
Add new condition to avoid derived code trigger lint
cocodery Jan 19, 2024
73d7ce6
Move the new check to the end of checks
cocodery Jan 19, 2024
989ce17
Auto merge of #12125 - cocodery:issue12045, r=xFrednet
bors Jan 19, 2024
6267b6c
no_effect_underscore_binding: _ prefixed variables can be used
samueltardieu Jan 19, 2024
eb42f3e
Pack the u128 in LitKind::Int
cuviper Jan 17, 2024
70573af
Auto merge of #12147 - y21:needless_pass_by_ref_mut_rm_visitor, r=llogiq
bors Jan 20, 2024
49b0c3f
Improve wording for suggestion messages
GuillaumeGomez Jan 18, 2024
38d9585
Update ui tests
GuillaumeGomez Jan 18, 2024
fd6e752
Move `has_non_exhaustive_attr` function into `clippy_utils`
GuillaumeGomez Jan 20, 2024
8b0931a
Rollup merge of #120000 - smoelius:fix-clippy, r=fee1-dead
GuillaumeGomez Jan 20, 2024
fe3e682
Auto merge of #12144 - blyxyas:10283-postfix, r=llogiq
bors Jan 20, 2024
7386856
Auto merge of #12172 - samueltardieu:issue-12166, r=Alexendoo
bors Jan 21, 2024
833cbd6
Auto merge of #120100 - oli-obk:astconv_lifetimes, r=BoxyUwU
bors Jan 21, 2024
f73879e
`unused_io_amount` captures `Ok(_)`s
m-rph Dec 21, 2023
64d08a8
Auto merge of #12005 - PartiallyTyped:11713, r=blyxyas
bors Jan 21, 2024
95a084f
[`multiple_crate_versions`]: add a configuration option for allowed d…
y21 Jan 21, 2024
99423e8
Auto merge of #12170 - GuillaumeGomez:improve-suggestions-wording, r=…
bors Jan 21, 2024
ad4d90b
respect `#[allow]` attribute in `single_call_fn` lint
y21 Jan 21, 2024
af76e3e
Updating dependencies
michaelciraci Jan 21, 2024
a417366
Rollup merge of #119710 - Nilstrieb:let-_-=-oops, r=TaKO8Ki
matthiaskrgr Jan 22, 2024
93955e0
Auto merge of #120080 - cuviper:128-align-packed, r=nikic
bors Jan 22, 2024
a8017ae
Auto merge of #12153 - GuillaumeGomez:non-exhaustive, r=llogiq
bors Jan 22, 2024
0b6e7e2
Auto merge of #12183 - y21:issue12182, r=dswij
bors Jan 22, 2024
cf355c6
Rename `LintContext::struct_span_lint` as `LintContext::span_lint`.
nnethercote Jan 16, 2024
6b359b7
Rename `TyCtxt::struct_span_lint_hir` as `TyCtxt::node_span_lint`.
nnethercote Jan 16, 2024
76a75bf
Auto merge of #12179 - y21:issue12176, r=dswij
bors Jan 24, 2024
4780637
suggest similar config option if one is found
y21 Jan 21, 2024
900a5aa
Auto merge of #12180 - y21:conf_lev_distance, r=blyxyas
bors Jan 24, 2024
8a17125
Auto merge of #12184 - michaelciraci:merge-deps, r=llogiq
bors Jan 25, 2024
1534e08
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Jan 25, 2024
c08c756
Bump nightly version -> 2024-01-25
flip1995 Jan 25, 2024
66c29b9
Auto merge of #12200 - flip1995:rustup, r=flip1995
bors Jan 25, 2024
41e1231
Merge commit '66c29b973b3b10278bd39f4e26b08522a379c2c9' into clippy-s…
flip1995 Jan 25, 2024
d7a0182
Update Cargo.lock
flip1995 Jan 25, 2024
de8ccdb
Clippy: Fix empty suggestion in from_over_into
flip1995 Jan 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 4 additions & 14 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -587,11 +587,11 @@ dependencies = [
name = "clippy_dev"
version = "0.0.1"
dependencies = [
"aho-corasick 0.7.20",
"aho-corasick 1.0.2",
"clap",
"indoc",
"itertools",
"opener 0.5.2",
"opener",
"shell-escape",
"walkdir",
]
Expand All @@ -601,7 +601,7 @@ name = "clippy_lints"
version = "0.1.77"
dependencies = [
"arrayvec",
"cargo_metadata 0.15.4",
"cargo_metadata 0.18.0",
"clippy_config",
"clippy_utils",
"declare_clippy_lint",
Expand Down Expand Up @@ -2342,7 +2342,7 @@ dependencies = [
"log",
"memchr",
"once_cell",
"opener 0.6.1",
"opener",
"pathdiff",
"pulldown-cmark",
"regex",
Expand Down Expand Up @@ -2617,16 +2617,6 @@ version = "1.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d"

[[package]]
name = "opener"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "293c15678e37254c15bd2f092314abb4e51d7fdde05c2021279c12631b54f005"
dependencies = [
"bstr",
"winapi",
]

[[package]]
name = "opener"
version = "0.6.1"
Expand Down
2 changes: 2 additions & 0 deletions src/tools/clippy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5606,6 +5606,7 @@ Released 2018-09-13
[`suspicious_else_formatting`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_else_formatting
[`suspicious_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_map
[`suspicious_op_assign_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_op_assign_impl
[`suspicious_open_options`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_open_options
[`suspicious_operation_groupings`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_operation_groupings
[`suspicious_splitn`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_splitn
[`suspicious_to_owned`]: https://rust-lang.github.io/rust-clippy/master/index.html#suspicious_to_owned
Expand Down Expand Up @@ -5814,6 +5815,7 @@ Released 2018-09-13
[`absolute-paths-max-segments`]: https://doc.rust-lang.org/clippy/lint_configuration.html#absolute-paths-max-segments
[`absolute-paths-allowed-crates`]: https://doc.rust-lang.org/clippy/lint_configuration.html#absolute-paths-allowed-crates
[`allowed-dotfiles`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-dotfiles
[`allowed-duplicate-crates`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-duplicate-crates
[`enforce-iter-loop-reborrow`]: https://doc.rust-lang.org/clippy/lint_configuration.html#enforce-iter-loop-reborrow
[`check-private-items`]: https://doc.rust-lang.org/clippy/lint_configuration.html#check-private-items
[`pub-underscore-fields-behavior`]: https://doc.rust-lang.org/clippy/lint_configuration.html#pub-underscore-fields-behavior
Expand Down
21 changes: 17 additions & 4 deletions src/tools/clippy/book/src/lint_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ default configuration of Clippy. By default, any configuration will replace the
* `doc-valid-idents = ["ClipPy"]` would replace the default list with `["ClipPy"]`.
* `doc-valid-idents = ["ClipPy", ".."]` would append `ClipPy` to the default list.

**Default Value:** `["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "DirectX", "ECMAScript", "GPLv2", "GPLv3", "GitHub", "GitLab", "IPv4", "IPv6", "ClojureScript", "CoffeeScript", "JavaScript", "PureScript", "TypeScript", "WebAssembly", "NaN", "NaNs", "OAuth", "GraphQL", "OCaml", "OpenGL", "OpenMP", "OpenSSH", "OpenSSL", "OpenStreetMap", "OpenDNS", "WebGL", "WebGL2", "WebGPU", "TensorFlow", "TrueType", "iOS", "macOS", "FreeBSD", "TeX", "LaTeX", "BibTeX", "BibLaTeX", "MinGW", "CamelCase"]`
**Default Value:** `["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "DirectX", "ECMAScript", "GPLv2", "GPLv3", "GitHub", "GitLab", "IPv4", "IPv6", "ClojureScript", "CoffeeScript", "JavaScript", "PureScript", "TypeScript", "WebAssembly", "NaN", "NaNs", "OAuth", "GraphQL", "OCaml", "OpenDNS", "OpenGL", "OpenMP", "OpenSSH", "OpenSSL", "OpenStreetMap", "OpenTelemetry", "WebGL", "WebGL2", "WebGPU", "TensorFlow", "TrueType", "iOS", "macOS", "FreeBSD", "TeX", "LaTeX", "BibTeX", "BibLaTeX", "MinGW", "CamelCase"]`

---
**Affected lints:**
Expand Down Expand Up @@ -768,7 +768,19 @@ Additional dotfiles (files or directories starting with a dot) to allow
* [`path_ends_with_ext`](https://rust-lang.github.io/rust-clippy/master/index.html#path_ends_with_ext)


## `allowed-duplicate-crates`
A list of crate names to allow duplicates of

**Default Value:** `[]`

---
**Affected lints:**
* [`multiple_crate_versions`](https://rust-lang.github.io/rust-clippy/master/index.html#multiple_crate_versions)


## `enforce-iter-loop-reborrow`
Whether to recommend using implicit into iter for reborrowed values.

#### Example
```no_run
let mut vec = vec![1, 2, 3];
Expand All @@ -793,7 +805,7 @@ for _ in &mut *rmvec {}


## `check-private-items`

Whether to also run the listed lints on private items.

**Default Value:** `false`

Expand All @@ -806,9 +818,10 @@ for _ in &mut *rmvec {}


## `pub-underscore-fields-behavior`
Lint "public" fields in a struct that are prefixed with an underscore based on their
exported visibility, or whether they are marked as "pub".


**Default Value:** `"PublicallyExported"`
**Default Value:** `"PubliclyExported"`

---
**Affected lints:**
Expand Down
80 changes: 63 additions & 17 deletions src/tools/clippy/clippy_config/src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ use crate::msrvs::Msrv;
use crate::types::{DisallowedPath, MacroMatcher, MatchLintBehaviour, PubUnderscoreFieldsBehaviour, Rename};
use crate::ClippyConfiguration;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::Applicability;
use rustc_session::Session;
use rustc_span::edit_distance::edit_distance;
use rustc_span::{BytePos, Pos, SourceFile, Span, SyntaxContext};
use serde::de::{IgnoredAny, IntoDeserializer, MapAccess, Visitor};
use serde::{Deserialize, Deserializer, Serialize};
Expand All @@ -26,7 +28,7 @@ const DEFAULT_DOC_VALID_IDENTS: &[&str] = &[
"NaN", "NaNs",
"OAuth", "GraphQL",
"OCaml",
"OpenGL", "OpenMP", "OpenSSH", "OpenSSL", "OpenStreetMap", "OpenDNS",
"OpenDNS", "OpenGL", "OpenMP", "OpenSSH", "OpenSSL", "OpenStreetMap", "OpenTelemetry",
"WebGL", "WebGL2", "WebGPU",
"TensorFlow",
"TrueType",
Expand Down Expand Up @@ -59,18 +61,25 @@ impl TryConf {
#[derive(Debug)]
struct ConfError {
message: String,
suggestion: Option<Suggestion>,
span: Span,
}

impl ConfError {
fn from_toml(file: &SourceFile, error: &toml::de::Error) -> Self {
let span = error.span().unwrap_or(0..file.source_len.0 as usize);
Self::spanned(file, error.message(), span)
Self::spanned(file, error.message(), None, span)
}

fn spanned(file: &SourceFile, message: impl Into<String>, span: Range<usize>) -> Self {
fn spanned(
file: &SourceFile,
message: impl Into<String>,
suggestion: Option<Suggestion>,
span: Range<usize>,
) -> Self {
Self {
message: message.into(),
suggestion,
span: Span::new(
file.start_pos + BytePos::from_usize(span.start),
file.start_pos + BytePos::from_usize(span.end),
Expand Down Expand Up @@ -147,16 +156,18 @@ macro_rules! define_Conf {
match Field::deserialize(name.get_ref().as_str().into_deserializer()) {
Err(e) => {
let e: FieldError = e;
errors.push(ConfError::spanned(self.0, e.0, name.span()));
errors.push(ConfError::spanned(self.0, e.error, e.suggestion, name.span()));
}
$(Ok(Field::$name) => {
$(warnings.push(ConfError::spanned(self.0, format!("deprecated field `{}`. {}", name.get_ref(), $dep), name.span()));)?
$(warnings.push(ConfError::spanned(self.0, format!("deprecated field `{}`. {}", name.get_ref(), $dep), None, name.span()));)?
let raw_value = map.next_value::<toml::Spanned<toml::Value>>()?;
let value_span = raw_value.span();
match <$ty>::deserialize(raw_value.into_inner()) {
Err(e) => errors.push(ConfError::spanned(self.0, e.to_string().replace('\n', " ").trim(), value_span)),
Err(e) => errors.push(ConfError::spanned(self.0, e.to_string().replace('\n', " ").trim(), None, value_span)),
Ok(value) => match $name {
Some(_) => errors.push(ConfError::spanned(self.0, format!("duplicate field `{}`", name.get_ref()), name.span())),
Some(_) => {
errors.push(ConfError::spanned(self.0, format!("duplicate field `{}`", name.get_ref()), None, name.span()));
}
None => {
$name = Some(value);
// $new_conf is the same as one of the defined `$name`s, so
Expand All @@ -165,7 +176,7 @@ macro_rules! define_Conf {
Some(_) => errors.push(ConfError::spanned(self.0, concat!(
"duplicate field `", stringify!($new_conf),
"` (provided as `", stringify!($name), "`)"
), name.span())),
), None, name.span())),
None => $new_conf = $name.clone(),
})?
},
Expand Down Expand Up @@ -523,7 +534,11 @@ define_Conf! {
///
/// Additional dotfiles (files or directories starting with a dot) to allow
(allowed_dotfiles: FxHashSet<String> = FxHashSet::default()),
/// Lint: EXPLICIT_ITER_LOOP
/// Lint: MULTIPLE_CRATE_VERSIONS.
///
/// A list of crate names to allow duplicates of
(allowed_duplicate_crates: FxHashSet<String> = FxHashSet::default()),
/// Lint: EXPLICIT_ITER_LOOP.
///
/// Whether to recommend using implicit into iter for reborrowed values.
///
Expand All @@ -543,15 +558,15 @@ define_Conf! {
/// for _ in &mut *rmvec {}
/// ```
(enforce_iter_loop_reborrow: bool = false),
/// Lint: MISSING_SAFETY_DOC, UNNECESSARY_SAFETY_DOC, MISSING_PANICS_DOC, MISSING_ERRORS_DOC
/// Lint: MISSING_SAFETY_DOC, UNNECESSARY_SAFETY_DOC, MISSING_PANICS_DOC, MISSING_ERRORS_DOC.
///
/// Whether to also run the listed lints on private items.
(check_private_items: bool = false),
/// Lint: PUB_UNDERSCORE_FIELDS
/// Lint: PUB_UNDERSCORE_FIELDS.
///
/// Lint "public" fields in a struct that are prefixed with an underscore based on their
/// exported visibility, or whether they are marked as "pub".
(pub_underscore_fields_behavior: PubUnderscoreFieldsBehaviour = PubUnderscoreFieldsBehaviour::PublicallyExported),
(pub_underscore_fields_behavior: PubUnderscoreFieldsBehaviour = PubUnderscoreFieldsBehaviour::PubliclyExported),
}

/// Search for the configuration file.
Expand Down Expand Up @@ -669,10 +684,16 @@ impl Conf {

// all conf errors are non-fatal, we just use the default conf in case of error
for error in errors {
sess.dcx().span_err(
let mut diag = sess.dcx().struct_span_err(
error.span,
format!("error reading Clippy's configuration file: {}", error.message),
);

if let Some(sugg) = error.suggestion {
diag.span_suggestion(error.span, sugg.message, sugg.suggestion, Applicability::MaybeIncorrect);
}

diag.emit();
}

for warning in warnings {
Expand All @@ -689,19 +710,31 @@ impl Conf {
const SEPARATOR_WIDTH: usize = 4;

#[derive(Debug)]
struct FieldError(String);
struct FieldError {
error: String,
suggestion: Option<Suggestion>,
}

#[derive(Debug)]
struct Suggestion {
message: &'static str,
suggestion: &'static str,
}

impl std::error::Error for FieldError {}

impl Display for FieldError {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.pad(&self.0)
f.pad(&self.error)
}
}

impl serde::de::Error for FieldError {
fn custom<T: Display>(msg: T) -> Self {
Self(msg.to_string())
Self {
error: msg.to_string(),
suggestion: None,
}
}

fn unknown_field(field: &str, expected: &'static [&'static str]) -> Self {
Expand All @@ -723,7 +756,20 @@ impl serde::de::Error for FieldError {
write!(msg, "{:SEPARATOR_WIDTH$}{field:column_width$}", " ").unwrap();
}
}
Self(msg)

let suggestion = expected
.iter()
.filter_map(|expected| {
let dist = edit_distance(field, expected, 4)?;
Some((dist, expected))
})
.min_by_key(|&(dist, _)| dist)
.map(|(_, suggestion)| Suggestion {
message: "perhaps you meant",
suggestion,
});

Self { error: msg, suggestion }
}
}

Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/clippy_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extern crate rustc_ast;
extern crate rustc_data_structures;
#[allow(unused_extern_crates)]
extern crate rustc_driver;
extern crate rustc_errors;
extern crate rustc_session;
extern crate rustc_span;

Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_config/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,6 @@ unimplemented_serialize! {

#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub enum PubUnderscoreFieldsBehaviour {
PublicallyExported,
PubliclyExported,
AllPubFields,
}
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_dev/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ version = "0.0.1"
edition = "2021"

[dependencies]
aho-corasick = "0.7"
aho-corasick = "1.0"
clap = "4.1.4"
indoc = "1.0"
itertools = "0.11"
opener = "0.5"
opener = "0.6"
shell-escape = "0.1"
walkdir = "2.3"

Expand Down
3 changes: 1 addition & 2 deletions src/tools/clippy/clippy_dev/src/update_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,8 @@ fn replace_ident_like(contents: &str, replacements: &[(&str, &str)]) -> Option<S
}

let searcher = AhoCorasickBuilder::new()
.dfa(true)
.match_kind(aho_corasick::MatchKind::LeftmostLongest)
.build_with_size::<u16, _, _>(replacements.iter().map(|&(x, _)| x.as_bytes()))
.build(replacements.iter().map(|&(x, _)| x.as_bytes()))
.unwrap();

let mut result = String::with_capacity(contents.len() + 1024);
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ edition = "2021"

[dependencies]
arrayvec = { version = "0.7", default-features = false }
cargo_metadata = "0.15.3"
cargo_metadata = "0.18"
clippy_config = { path = "../clippy_config" }
clippy_utils = { path = "../clippy_utils" }
declare_clippy_lint = { path = "../declare_clippy_lint" }
Expand Down
8 changes: 4 additions & 4 deletions src/tools/clippy/clippy_lints/src/arc_with_non_send_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ declare_clippy_lint! {
/// This lint warns when you use `Arc` with a type that does not implement `Send` or `Sync`.
///
/// ### Why is this bad?
/// `Arc<T>` is an Atomic `RC<T>` and guarantees that updates to the reference counter are
/// Atomic. This is useful in multiprocessing scenarios. To send an `Arc<T>` across processes
/// 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),
/// either `T` should be made `Send + Sync` or an `Rc` should be used instead of an `Arc`
/// `Arc<T>` is a thread-safe `Rc<T>` and guarantees that updates to the reference counter
/// use atomic operations. To send an `Arc<T>` across thread boundaries and
/// share ownership between multiple threads, `T` must be [both `Send` and `Sync`](https://doc.rust-lang.org/std/sync/struct.Arc.html#thread-safety),
/// so either `T` should be made `Send + Sync` or an `Rc` should be used instead of an `Arc`
///
/// ### Example
/// ```no_run
Expand Down
5 changes: 5 additions & 0 deletions src/tools/clippy/clippy_lints/src/blocks_in_conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ impl<'tcx> LateLintPass<'tcx> for BlocksInConditions {
);

if let ExprKind::Block(block, _) = &cond.kind {
if !block.span.eq_ctxt(expr.span) {
// If the block comes from a macro, or as an argument to a macro,
// do not lint.
return;
}
if block.rules == BlockCheckMode::DefaultBlock {
if block.stmts.is_empty() {
if let Some(ex) = &block.expr {
Expand Down
Loading
Loading