Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 1d168b3

Browse files
authored
Merge branch 'rust-lang:master' into clear-with-drain
2 parents d56c941 + 5ed64d4 commit 1d168b3

File tree

67 files changed

+715
-321
lines changed

Some content is hidden

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

67 files changed

+715
-321
lines changed

.cargo/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@ target-dir = "target"
1111

1212
[unstable]
1313
binary-dep-depinfo = true
14+
15+
[profile.dev]
16+
split-debuginfo = "unpacked"

.github/workflows/clippy_bors.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ jobs:
180180

181181
# Run
182182
- name: Build Integration Test
183+
env:
184+
CARGO_PROFILE_DEV_SPLIT_DEBUGINFO: off
183185
run: cargo test --test integration --features integration --no-run
184186

185187
# Upload

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4988,6 +4988,7 @@ Released 2018-09-13
49884988
[`unnecessary_safety_doc`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_safety_doc
49894989
[`unnecessary_self_imports`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_self_imports
49904990
[`unnecessary_sort_by`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_sort_by
4991+
[`unnecessary_struct_initialization`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_struct_initialization
49914992
[`unnecessary_to_owned`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_to_owned
49924993
[`unnecessary_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_unwrap
49934994
[`unnecessary_wraps`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_wraps

COPYRIGHT

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
// REUSE-IgnoreStart
2+
13
Copyright 2014-2022 The Rust Project Developers
24

35
Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
46
http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
57
<LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
68
option. All files in the project carrying such notice may not be
79
copied, modified, or distributed except according to those terms.
10+
11+
// REUSE-IgnoreEnd

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,14 @@ If you want to contribute to Clippy, you can find more information in [CONTRIBUT
275275

276276
## License
277277

278+
<!-- REUSE-IgnoreStart -->
279+
278280
Copyright 2014-2022 The Rust Project Developers
279281

280282
Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
281283
[https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)> or the MIT license
282284
<LICENSE-MIT or [https://opensource.org/licenses/MIT](https://opensource.org/licenses/MIT)>, at your
283285
option. Files in the project may not be
284286
copied, modified, or distributed except according to those terms.
287+
288+
<!-- REUSE-IgnoreEnd -->

book/src/development/adding_lints.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ because that's clearly a non-descriptive name.
1818
- [Cargo lints](#cargo-lints)
1919
- [Rustfix tests](#rustfix-tests)
2020
- [Testing manually](#testing-manually)
21+
- [Running directly](#running-directly)
2122
- [Lint declaration](#lint-declaration)
2223
- [Lint registration](#lint-registration)
2324
- [Lint passes](#lint-passes)
@@ -186,6 +187,15 @@ cargo dev lint input.rs
186187
from the working copy root. With tests in place, let's have a look at
187188
implementing our lint now.
188189

190+
## Running directly
191+
192+
While it's easier to just use `cargo dev lint`, it might be desirable to get
193+
`target/release/cargo-clippy` and `target/release/clippy-driver` to work as well in some cases.
194+
By default, they don't work because clippy dynamically links rustc. To help them find rustc,
195+
add the path printed by`rustc --print target-libdir` (ran inside this workspace so that the rustc version matches)
196+
to your library search path.
197+
On linux, this can be done by setting the `LD_LIBRARY_PATH` environment variable to that path.
198+
189199
## Lint declaration
190200

191201
Let's start by opening the new file created in the `clippy_lints` crate at

clippy_lints/src/booleans.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -495,18 +495,19 @@ struct NotSimplificationVisitor<'a, 'tcx> {
495495

496496
impl<'a, 'tcx> Visitor<'tcx> for NotSimplificationVisitor<'a, 'tcx> {
497497
fn visit_expr(&mut self, expr: &'tcx Expr<'_>) {
498-
if let ExprKind::Unary(UnOp::Not, inner) = &expr.kind {
499-
if let Some(suggestion) = simplify_not(self.cx, inner) {
500-
span_lint_and_sugg(
501-
self.cx,
502-
NONMINIMAL_BOOL,
503-
expr.span,
504-
"this boolean expression can be simplified",
505-
"try",
506-
suggestion,
507-
Applicability::MachineApplicable,
508-
);
509-
}
498+
if let ExprKind::Unary(UnOp::Not, inner) = &expr.kind &&
499+
!inner.span.from_expansion() &&
500+
let Some(suggestion) = simplify_not(self.cx, inner)
501+
{
502+
span_lint_and_sugg(
503+
self.cx,
504+
NONMINIMAL_BOOL,
505+
expr.span,
506+
"this boolean expression can be simplified",
507+
"try",
508+
suggestion,
509+
Applicability::MachineApplicable,
510+
);
510511
}
511512

512513
walk_expr(self, expr);

clippy_lints/src/casts/cast_possible_truncation.rs

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ use clippy_utils::consts::{constant, Constant};
22
use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
33
use clippy_utils::expr_or_init;
44
use clippy_utils::source::snippet;
5+
use clippy_utils::sugg::Sugg;
56
use clippy_utils::ty::{get_discriminant_value, is_isize_or_usize};
6-
use rustc_errors::{Applicability, SuggestionStyle};
7+
use rustc_errors::{Applicability, Diagnostic, SuggestionStyle};
78
use rustc_hir::def::{DefKind, Res};
89
use rustc_hir::{BinOpKind, Expr, ExprKind};
910
use rustc_lint::LateContext;
@@ -163,19 +164,34 @@ pub(super) fn check(
163164
_ => return,
164165
};
165166

166-
let name_of_cast_from = snippet(cx, cast_expr.span, "..");
167-
let cast_to_snip = snippet(cx, cast_to_span, "..");
168-
let suggestion = format!("{cast_to_snip}::try_from({name_of_cast_from})");
169-
170167
span_lint_and_then(cx, CAST_POSSIBLE_TRUNCATION, expr.span, &msg, |diag| {
171168
diag.help("if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ...");
172-
diag.span_suggestion_with_style(
173-
expr.span,
174-
"... or use `try_from` and handle the error accordingly",
175-
suggestion,
176-
Applicability::Unspecified,
177-
// always show the suggestion in a separate line
178-
SuggestionStyle::ShowAlways,
179-
);
169+
if !cast_from.is_floating_point() {
170+
offer_suggestion(cx, expr, cast_expr, cast_to_span, diag);
171+
}
180172
});
181173
}
174+
175+
fn offer_suggestion(
176+
cx: &LateContext<'_>,
177+
expr: &Expr<'_>,
178+
cast_expr: &Expr<'_>,
179+
cast_to_span: Span,
180+
diag: &mut Diagnostic,
181+
) {
182+
let cast_to_snip = snippet(cx, cast_to_span, "..");
183+
let suggestion = if cast_to_snip == "_" {
184+
format!("{}.try_into()", Sugg::hir(cx, cast_expr, "..").maybe_par())
185+
} else {
186+
format!("{cast_to_snip}::try_from({})", Sugg::hir(cx, cast_expr, ".."))
187+
};
188+
189+
diag.span_suggestion_with_style(
190+
expr.span,
191+
"... or use `try_from` and handle the error accordingly",
192+
suggestion,
193+
Applicability::Unspecified,
194+
// always show the suggestion in a separate line
195+
SuggestionStyle::ShowAlways,
196+
);
197+
}

clippy_lints/src/cognitive_complexity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ impl<'tcx> LateLintPass<'tcx> for CognitiveComplexity {
143143
span: Span,
144144
def_id: LocalDefId,
145145
) {
146-
if !cx.tcx.has_attr(def_id.to_def_id(), sym::test) {
146+
if !cx.tcx.has_attr(def_id, sym::test) {
147147
let expr = if is_async_fn(kind) {
148148
match get_async_fn_body(cx.tcx, body) {
149149
Some(b) => b,

clippy_lints/src/declared_lints.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[
619619
crate::unnamed_address::VTABLE_ADDRESS_COMPARISONS_INFO,
620620
crate::unnecessary_owned_empty_strings::UNNECESSARY_OWNED_EMPTY_STRINGS_INFO,
621621
crate::unnecessary_self_imports::UNNECESSARY_SELF_IMPORTS_INFO,
622+
crate::unnecessary_struct_initialization::UNNECESSARY_STRUCT_INITIALIZATION_INFO,
622623
crate::unnecessary_wraps::UNNECESSARY_WRAPS_INFO,
623624
crate::unnested_or_patterns::UNNESTED_OR_PATTERNS_INFO,
624625
crate::unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME_INFO,

0 commit comments

Comments
 (0)