Skip to content

Commit b01e901

Browse files
committed
Merge commit 'ff4a26d442bead94a4c96fb1de967374bc4fbd8e' into clippy-subtree-update
2 parents 9b4d7c6 + ff4a26d commit b01e901

File tree

195 files changed

+1958
-647
lines changed

Some content is hidden

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

195 files changed

+1958
-647
lines changed

src/tools/clippy/CHANGELOG.md

+48-2
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,56 @@ document.
66

77
## Unreleased / Beta / In Rust Nightly
88

9-
[0f8eabd6...master](https://github.com/rust-lang/rust-clippy/compare/0f8eabd6...master)
9+
[aa0d5513...master](https://github.com/rust-lang/rust-clippy/compare/aa0d5513...master)
10+
11+
## Rust 1.83
12+
13+
Current stable, released 2024-11-28
14+
15+
[View all 64 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2024-08-25T09%3A59%3A01Z..2024-10-03T13%3A42%3A56Z+base%3Amaster)
16+
17+
### Important Change
18+
19+
* Removed the implicit `cargo-clippy` feature set by Clippy as announced here:
20+
<https://blog.rust-lang.org/2024/02/28/Clippy-deprecating-feature-cargo-clippy.html>
21+
[#13246](https://github.com/rust-lang/rust-clippy/pull/13246)
22+
23+
### New Lints
24+
25+
* Added [`unused_trait_names`] to `restriction`
26+
[#13322](https://github.com/rust-lang/rust-clippy/pull/13322)
27+
* Added [`unnecessary_first_then_check`] to `complexity`
28+
[#13421](https://github.com/rust-lang/rust-clippy/pull/13421)
29+
* Added [`non_zero_suggestions`] to `restriction`
30+
[#13167](https://github.com/rust-lang/rust-clippy/pull/13167)
31+
* Added [`manual_is_power_of_two`] to `pedantic`
32+
[#13327](https://github.com/rust-lang/rust-clippy/pull/13327)
33+
* Added [`manual_div_ceil`] to `complexity`
34+
[#12987](https://github.com/rust-lang/rust-clippy/pull/12987)
35+
* Added [`zombie_processes`] to `suspicious`
36+
[#11476](https://github.com/rust-lang/rust-clippy/pull/11476)
37+
* Added [`used_underscore_items`] to `pedantic`
38+
[#13294](https://github.com/rust-lang/rust-clippy/pull/13294)
39+
40+
### Moves and Deprecations
41+
42+
* Moved [`ref_option`] to `pedantic` (From `nursery`)
43+
[#13469](https://github.com/rust-lang/rust-clippy/pull/13469)
44+
* Moved [`manual_c_str_literals`] to `complexity` (From `pedantic`, now warn-by-default)
45+
[#13263](https://github.com/rust-lang/rust-clippy/pull/13263)
46+
* Moved [`empty_line_after_doc_comments`] to `suspicious` (From `nursery`, now warn-by-default)
47+
[#13091](https://github.com/rust-lang/rust-clippy/pull/13091)
48+
* Moved [`empty_line_after_outer_attr`] to `suspicious` (From `nursery`, now warn-by-default)
49+
[#13091](https://github.com/rust-lang/rust-clippy/pull/13091)
50+
51+
### Enhancements
52+
53+
* [`missing_panics_doc`]: No longer lints in const environments
54+
[#13382](https://github.com/rust-lang/rust-clippy/pull/13382)
1055

1156
## Rust 1.82
1257

13-
Current stable, released 2024-10-17
58+
Released 2024-10-17
1459

1560
[View all 108 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2024-07-11T20%3A12%3A07Z..2024-08-24T20%3A55%3A35Z+base%3Amaster)
1661

@@ -5441,6 +5486,7 @@ Released 2018-09-13
54415486
[`disallowed_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_type
54425487
[`disallowed_types`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_types
54435488
[`diverging_sub_expression`]: https://rust-lang.github.io/rust-clippy/master/index.html#diverging_sub_expression
5489+
[`doc_include_without_cfg`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_include_without_cfg
54445490
[`doc_lazy_continuation`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation
54455491
[`doc_link_with_quotes`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_link_with_quotes
54465492
[`doc_markdown`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_markdown

src/tools/clippy/Cargo.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[package]
22
name = "clippy"
3-
version = "0.1.84"
3+
# begin autogenerated version
4+
version = "0.1.85"
5+
# end autogenerated version
46
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
57
repository = "https://github.com/rust-lang/rust-clippy"
68
readme = "README.md"
@@ -27,7 +29,7 @@ rustc_tools_util = "0.4.0"
2729
tempfile = { version = "3.3", optional = true }
2830
termize = "0.1"
2931
color-print = "0.3.4"
30-
anstream = "0.6.0"
32+
anstream = "0.6.18"
3133

3234
[dev-dependencies]
3335
cargo_metadata = "0.18.1"

src/tools/clippy/book/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [Configuration](configuration.md)
88
- [Lint Configuration](lint_configuration.md)
99
- [Clippy's Lints](lints.md)
10+
- [Attributes for Crate Authors](attribs.md)
1011
- [Continuous Integration](continuous_integration/README.md)
1112
- [GitHub Actions](continuous_integration/github_actions.md)
1213
- [GitLab CI](continuous_integration/gitlab.md)

src/tools/clippy/book/src/attribs.md

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Attributes for Crate Authors
2+
3+
In some cases it is possible to extend Clippy coverage to 3rd party libraries.
4+
To do this, Clippy provides attributes that can be applied to items in the 3rd party crate.
5+
6+
## `#[clippy::format_args]`
7+
8+
_Available since Clippy v1.84_
9+
10+
This attribute can be added to a macro that supports `format!`, `println!`, or similar syntax.
11+
It tells Clippy that the macro is a formatting macro, and that the arguments to the macro
12+
should be linted as if they were arguments to `format!`. Any lint that would apply to a
13+
`format!` call will also apply to the macro call. The macro may have additional arguments
14+
before the format string, and these will be ignored.
15+
16+
### Example
17+
18+
```rust
19+
/// A macro that prints a message if a condition is true.
20+
#[macro_export]
21+
#[clippy::format_args]
22+
macro_rules! print_if {
23+
($condition:expr, $($args:tt)+) => {{
24+
if $condition {
25+
println!($($args)+)
26+
}
27+
}};
28+
}
29+
```
30+
31+
## `#[clippy::has_significant_drop]`
32+
33+
_Available since Clippy v1.60_
34+
35+
The `clippy::has_significant_drop` attribute can be added to types whose Drop impls have an important side effect,
36+
such as unlocking a mutex, making it important for users to be able to accurately understand their lifetimes.
37+
When a temporary is returned in a function call in a match scrutinee, its lifetime lasts until the end of the match
38+
block, which may be surprising.
39+
40+
### Example
41+
42+
```rust
43+
#[clippy::has_significant_drop]
44+
struct CounterWrapper<'a> {
45+
counter: &'a Counter,
46+
}
47+
48+
impl<'a> Drop for CounterWrapper<'a> {
49+
fn drop(&mut self) {
50+
self.counter.i.fetch_sub(1, Ordering::Relaxed);
51+
}
52+
}
53+
```

src/tools/clippy/book/src/development/adding_lints.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ need to ensure that the MSRV configured for the project is >= the MSRV of the
438438
required Rust feature. If multiple features are required, just use the one with
439439
a lower MSRV.
440440

441-
First, add an MSRV alias for the required feature in [`clippy_config::msrvs`].
441+
First, add an MSRV alias for the required feature in [`clippy_utils::msrvs`].
442442
This can be accessed later as `msrvs::STR_STRIP_PREFIX`, for example.
443443

444444
```rust
@@ -517,7 +517,7 @@ define_Conf! {
517517
}
518518
```
519519

520-
[`clippy_config::msrvs`]: https://doc.rust-lang.org/nightly/nightly-rustc/clippy_config/msrvs/index.html
520+
[`clippy_utils::msrvs`]: https://doc.rust-lang.org/nightly/nightly-rustc/clippy_config/msrvs/index.html
521521

522522
Afterwards update the documentation for the book as described in [Adding configuration to a lint](#adding-configuration-to-a-lint).
523523

src/tools/clippy/book/src/lint_configuration.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ The order of associated items in traits.
895895

896896
## `trivial-copy-size-limit`
897897
The maximum size (in bytes) to consider a `Copy` type for passing by value instead of by
898-
reference. By default there is no limit
898+
reference.
899899

900900
**Default Value:** `target_pointer_width * 2`
901901

src/tools/clippy/clippy_config/Cargo.toml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
[package]
22
name = "clippy_config"
3-
version = "0.1.84"
3+
# begin autogenerated version
4+
version = "0.1.85"
5+
# end autogenerated version
46
edition = "2021"
7+
publish = false
58

69
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
710

811
[dependencies]
12+
clippy_utils = { path = "../clippy_utils" }
913
itertools = "0.12"
1014
serde = { version = "1.0", features = ["derive"] }
1115
toml = "0.7.3"

src/tools/clippy/clippy_config/src/conf.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use crate::ClippyConfiguration;
2-
use crate::msrvs::Msrv;
32
use crate::types::{
43
DisallowedPath, MacroMatcher, MatchLintBehaviour, PubUnderscoreFieldsBehaviour, Rename, SourceItemOrdering,
54
SourceItemOrderingCategory, SourceItemOrderingModuleItemGroupings, SourceItemOrderingModuleItemKind,
65
SourceItemOrderingTraitAssocItemKind, SourceItemOrderingTraitAssocItemKinds,
76
};
7+
use clippy_utils::msrvs::Msrv;
88
use rustc_errors::Applicability;
99
use rustc_session::Session;
1010
use rustc_span::edit_distance::edit_distance;
@@ -181,7 +181,7 @@ macro_rules! define_Conf {
181181
)*) => {
182182
/// Clippy lint configuration
183183
pub struct Conf {
184-
$($(#[doc = $doc])+ pub $name: $ty,)*
184+
$($(#[cfg_attr(doc, doc = $doc)])+ pub $name: $ty,)*
185185
}
186186

187187
mod defaults {
@@ -678,7 +678,7 @@ define_Conf! {
678678
#[lints(arbitrary_source_item_ordering)]
679679
trait_assoc_item_kinds_order: SourceItemOrderingTraitAssocItemKinds = DEFAULT_TRAIT_ASSOC_ITEM_KINDS_ORDER.into(),
680680
/// The maximum size (in bytes) to consider a `Copy` type for passing by value instead of by
681-
/// reference. By default there is no limit
681+
/// reference.
682682
#[default_text = "target_pointer_width * 2"]
683683
#[lints(trivially_copy_pass_by_ref)]
684684
trivial_copy_size_limit: Option<u64> = None,

src/tools/clippy/clippy_config/src/lib.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,14 @@
1313
rustc::untranslatable_diagnostic
1414
)]
1515

16-
extern crate rustc_ast;
17-
extern crate rustc_attr;
18-
#[allow(unused_extern_crates)]
19-
extern crate rustc_driver;
2016
extern crate rustc_errors;
17+
extern crate rustc_hir;
18+
extern crate rustc_middle;
2119
extern crate rustc_session;
2220
extern crate rustc_span;
23-
extern crate smallvec;
2421

2522
mod conf;
2623
mod metadata;
27-
pub mod msrvs;
2824
pub mod types;
2925

3026
pub use conf::{Conf, get_configuration_metadata, lookup_conf_file, sanitize_explanation};

src/tools/clippy/clippy_config/src/types.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
use clippy_utils::def_path_def_ids;
2+
use rustc_hir::def_id::DefIdMap;
3+
use rustc_middle::ty::TyCtxt;
14
use serde::de::{self, Deserializer, Visitor};
25
use serde::{Deserialize, Serialize, ser};
36
use std::collections::HashMap;
@@ -31,6 +34,18 @@ impl DisallowedPath {
3134
}
3235
}
3336

37+
/// Creates a map of disallowed items to the reason they were disallowed.
38+
pub fn create_disallowed_map(
39+
tcx: TyCtxt<'_>,
40+
disallowed: &'static [DisallowedPath],
41+
) -> DefIdMap<(&'static str, Option<&'static str>)> {
42+
disallowed
43+
.iter()
44+
.map(|x| (x.path(), x.path().split("::").collect::<Vec<_>>(), x.reason()))
45+
.flat_map(|(name, path, reason)| def_path_def_ids(tcx, &path).map(move |id| (id, (name, reason))))
46+
.collect()
47+
}
48+
3449
#[derive(Clone, Copy, Debug, PartialEq, Eq, Deserialize, Serialize)]
3550
pub enum MatchLintBehaviour {
3651
AllTypes,

src/tools/clippy/clippy_dev/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2021"
66

77
[dependencies]
88
aho-corasick = "1.0"
9+
chrono = { version = "0.4.38", default-features = false, features = ["clock"] }
910
clap = { version = "4.4", features = ["derive"] }
1011
indoc = "1.0"
1112
itertools = "0.12"

src/tools/clippy/clippy_dev/src/dogfood.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{clippy_project_root, exit_if_err};
1+
use crate::utils::{clippy_project_root, exit_if_err};
22
use std::process::Command;
33

44
/// # Panics

src/tools/clippy/clippy_dev/src/fmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::clippy_project_root;
1+
use crate::utils::clippy_project_root;
22
use itertools::Itertools;
33
use rustc_lexer::{TokenKind, tokenize};
44
use shell_escape::escape;

src/tools/clippy/clippy_dev/src/lib.rs

+3-59
Original file line numberDiff line numberDiff line change
@@ -14,69 +14,13 @@
1414
extern crate rustc_driver;
1515
extern crate rustc_lexer;
1616

17-
use std::io;
18-
use std::path::PathBuf;
19-
use std::process::{self, ExitStatus};
20-
2117
pub mod dogfood;
2218
pub mod fmt;
2319
pub mod lint;
2420
pub mod new_lint;
21+
pub mod release;
2522
pub mod serve;
2623
pub mod setup;
24+
pub mod sync;
2725
pub mod update_lints;
28-
29-
#[cfg(not(windows))]
30-
static CARGO_CLIPPY_EXE: &str = "cargo-clippy";
31-
#[cfg(windows)]
32-
static CARGO_CLIPPY_EXE: &str = "cargo-clippy.exe";
33-
34-
/// Returns the path to the `cargo-clippy` binary
35-
///
36-
/// # Panics
37-
///
38-
/// Panics if the path of current executable could not be retrieved.
39-
#[must_use]
40-
pub fn cargo_clippy_path() -> PathBuf {
41-
let mut path = std::env::current_exe().expect("failed to get current executable name");
42-
path.set_file_name(CARGO_CLIPPY_EXE);
43-
path
44-
}
45-
46-
/// Returns the path to the Clippy project directory
47-
///
48-
/// # Panics
49-
///
50-
/// Panics if the current directory could not be retrieved, there was an error reading any of the
51-
/// Cargo.toml files or ancestor directory is the clippy root directory
52-
#[must_use]
53-
pub fn clippy_project_root() -> PathBuf {
54-
let current_dir = std::env::current_dir().unwrap();
55-
for path in current_dir.ancestors() {
56-
let result = std::fs::read_to_string(path.join("Cargo.toml"));
57-
if let Err(err) = &result {
58-
if err.kind() == io::ErrorKind::NotFound {
59-
continue;
60-
}
61-
}
62-
63-
let content = result.unwrap();
64-
if content.contains("[package]\nname = \"clippy\"") {
65-
return path.to_path_buf();
66-
}
67-
}
68-
panic!("error: Can't determine root of project. Please run inside a Clippy working dir.");
69-
}
70-
71-
/// # Panics
72-
/// Panics if given command result was failed.
73-
pub fn exit_if_err(status: io::Result<ExitStatus>) {
74-
match status.expect("failed to run command").code() {
75-
Some(0) => {},
76-
Some(n) => process::exit(n),
77-
None => {
78-
eprintln!("Killed by signal");
79-
process::exit(1);
80-
},
81-
}
82-
}
26+
pub mod utils;

src/tools/clippy/clippy_dev/src/lint.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::{cargo_clippy_path, exit_if_err};
1+
use crate::utils::{cargo_clippy_path, exit_if_err};
22
use std::process::{self, Command};
33
use std::{env, fs};
44

0 commit comments

Comments
 (0)