Skip to content

Commit 0cb0f76

Browse files
committed
Auto merge of #9069 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents ff3964a + 9de1f9f commit 0cb0f76

Some content is hidden

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

43 files changed

+267
-289
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.1.63"
3+
version = "0.1.64"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"

clippy_dev/src/bless.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
use crate::cargo_clippy_path;
55
use std::ffi::OsStr;
66
use std::fs;
7-
use std::lazy::SyncLazy;
87
use std::path::{Path, PathBuf};
8+
use std::sync::LazyLock;
99
use walkdir::{DirEntry, WalkDir};
1010

11-
static CLIPPY_BUILD_TIME: SyncLazy<Option<std::time::SystemTime>> =
12-
SyncLazy::new(|| cargo_clippy_path().metadata().ok()?.modified().ok());
11+
static CLIPPY_BUILD_TIME: LazyLock<Option<std::time::SystemTime>> =
12+
LazyLock::new(|| cargo_clippy_path().metadata().ok()?.modified().ok());
1313

1414
/// # Panics
1515
///

clippy_lints/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_lints"
3-
version = "0.1.63"
3+
version = "0.1.64"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"

clippy_lints/src/methods/map_flatten.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_utils::diagnostics::span_lint_and_sugg_for_edges;
1+
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::is_trait_method;
33
use clippy_utils::source::snippet_with_applicability;
44
use clippy_utils::ty::is_type_diagnostic_item;
@@ -14,17 +14,17 @@ use super::MAP_FLATTEN;
1414
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, map_arg: &Expr<'_>, map_span: Span) {
1515
if let Some((caller_ty_name, method_to_use)) = try_get_caller_ty_name_and_method_name(cx, expr, recv, map_arg) {
1616
let mut applicability = Applicability::MachineApplicable;
17-
let help_msgs = [
18-
&format!("try replacing `map` with `{}`", method_to_use),
19-
"and remove the `.flatten()`",
20-
];
17+
2118
let closure_snippet = snippet_with_applicability(cx, map_arg.span, "..", &mut applicability);
22-
span_lint_and_sugg_for_edges(
19+
span_lint_and_sugg(
2320
cx,
2421
MAP_FLATTEN,
2522
expr.span.with_lo(map_span.lo()),
2623
&format!("called `map(..).flatten()` on `{}`", caller_ty_name),
27-
&help_msgs,
24+
&format!(
25+
"try replacing `map` with `{}` and remove the `.flatten()`",
26+
method_to_use
27+
),
2828
format!("{}({})", method_to_use, closure_snippet),
2929
applicability,
3030
);

clippy_lints/src/methods/or_fun_call.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use clippy_utils::source::{snippet, snippet_with_applicability, snippet_with_mac
44
use clippy_utils::ty::{implements_trait, match_type};
55
use clippy_utils::{contains_return, is_trait_item, last_path_segment, paths};
66
use if_chain::if_chain;
7-
use rustc_errors::emitter::MAX_SUGGESTION_HIGHLIGHT_LINES;
87
use rustc_errors::Applicability;
98
use rustc_hir as hir;
109
use rustc_lint::LateContext;
@@ -33,7 +32,6 @@ pub(super) fn check<'tcx>(
3332
arg: &hir::Expr<'_>,
3433
or_has_args: bool,
3534
span: Span,
36-
method_span: Span,
3735
) -> bool {
3836
let is_default_default = || is_trait_item(cx, fun, sym::Default);
3937

@@ -56,19 +54,14 @@ pub(super) fn check<'tcx>(
5654
then {
5755
let mut applicability = Applicability::MachineApplicable;
5856
let hint = "unwrap_or_default()";
59-
let mut sugg_span = span;
57+
let sugg_span = span;
6058

61-
let mut sugg: String = format!(
59+
let sugg: String = format!(
6260
"{}.{}",
6361
snippet_with_applicability(cx, self_expr.span, "..", &mut applicability),
6462
hint
6563
);
6664

67-
if sugg.lines().count() > MAX_SUGGESTION_HIGHLIGHT_LINES {
68-
sugg_span = method_span.with_hi(span.hi());
69-
sugg = hint.to_string();
70-
}
71-
7265
span_lint_and_sugg(
7366
cx,
7467
OR_FUN_CALL,
@@ -178,7 +171,7 @@ pub(super) fn check<'tcx>(
178171
match inner_arg.kind {
179172
hir::ExprKind::Call(fun, or_args) => {
180173
let or_has_args = !or_args.is_empty();
181-
if !check_unwrap_or_default(cx, name, fun, self_arg, arg, or_has_args, expr.span, method_span) {
174+
if !check_unwrap_or_default(cx, name, fun, self_arg, arg, or_has_args, expr.span) {
182175
let fun_span = if or_has_args { None } else { Some(fun.span) };
183176
check_general_case(cx, name, method_span, self_arg, arg, expr.span, fun_span);
184177
}

clippy_lints/src/utils/internal_lints/metadata_collector.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,14 @@ macro_rules! RENAME_VALUE_TEMPLATE {
104104
};
105105
}
106106

107-
const LINT_EMISSION_FUNCTIONS: [&[&str]; 8] = [
107+
const LINT_EMISSION_FUNCTIONS: [&[&str]; 7] = [
108108
&["clippy_utils", "diagnostics", "span_lint"],
109109
&["clippy_utils", "diagnostics", "span_lint_and_help"],
110110
&["clippy_utils", "diagnostics", "span_lint_and_note"],
111111
&["clippy_utils", "diagnostics", "span_lint_hir"],
112112
&["clippy_utils", "diagnostics", "span_lint_and_sugg"],
113113
&["clippy_utils", "diagnostics", "span_lint_and_then"],
114114
&["clippy_utils", "diagnostics", "span_lint_hir_and_then"],
115-
&["clippy_utils", "diagnostics", "span_lint_and_sugg_for_edges"],
116115
];
117116
const SUGGESTION_DIAGNOSTIC_BUILDER_METHODS: [(&str, bool); 9] = [
118117
("span_suggestion", false),

clippy_utils/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_utils"
3-
version = "0.1.63"
3+
version = "0.1.64"
44
edition = "2021"
55
publish = false
66

clippy_utils/src/diagnostics.rs

+1-88
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//! Thank you!
99
//! ~The `INTERNAL_METADATA_COLLECTOR` lint
1010
11-
use rustc_errors::{emitter::MAX_SUGGESTION_HIGHLIGHT_LINES, Applicability, Diagnostic, MultiSpan};
11+
use rustc_errors::{Applicability, Diagnostic, MultiSpan};
1212
use rustc_hir::HirId;
1313
use rustc_lint::{LateContext, Lint, LintContext};
1414
use rustc_span::source_map::Span;
@@ -213,93 +213,6 @@ pub fn span_lint_and_sugg<'a, T: LintContext>(
213213
});
214214
}
215215

216-
/// Like [`span_lint_and_sugg`] with a focus on the edges. The output will either
217-
/// emit single span or multispan suggestion depending on the number of its lines.
218-
///
219-
/// If the given suggestion string has more lines than the maximum display length defined by
220-
/// [`MAX_SUGGESTION_HIGHLIGHT_LINES`][`rustc_errors::emitter::MAX_SUGGESTION_HIGHLIGHT_LINES`],
221-
/// this function will split the suggestion and span to showcase the change for the top and
222-
/// bottom edge of the code. For normal suggestions, in one display window, the help message
223-
/// will be combined with a colon.
224-
///
225-
/// Multipart suggestions like the one being created here currently cannot be
226-
/// applied by rustfix (See [rustfix#141](https://github.com/rust-lang/rustfix/issues/141)).
227-
/// Testing rustfix with this lint emission function might require a file with
228-
/// suggestions that can be fixed and those that can't. See
229-
/// [clippy#8520](https://github.com/rust-lang/rust-clippy/pull/8520/files) for
230-
/// an example and of this.
231-
///
232-
/// # Example for a long suggestion
233-
///
234-
/// ```text
235-
/// error: called `map(..).flatten()` on `Option`
236-
/// --> $DIR/map_flatten.rs:8:10
237-
/// |
238-
/// LL | .map(|x| {
239-
/// | __________^
240-
/// LL | | if x <= 5 {
241-
/// LL | | Some(x)
242-
/// LL | | } else {
243-
/// ... |
244-
/// LL | | })
245-
/// LL | | .flatten();
246-
/// | |__________________^
247-
/// |
248-
/// = note: `-D clippy::map-flatten` implied by `-D warnings`
249-
/// help: try replacing `map` with `and_then`
250-
/// |
251-
/// LL ~ .and_then(|x| {
252-
/// LL + if x <= 5 {
253-
/// LL + Some(x)
254-
/// |
255-
/// help: and remove the `.flatten()`
256-
/// |
257-
/// LL + None
258-
/// LL + }
259-
/// LL ~ });
260-
/// |
261-
/// ```
262-
pub fn span_lint_and_sugg_for_edges(
263-
cx: &LateContext<'_>,
264-
lint: &'static Lint,
265-
sp: Span,
266-
msg: &str,
267-
helps: &[&str; 2],
268-
sugg: String,
269-
applicability: Applicability,
270-
) {
271-
span_lint_and_then(cx, lint, sp, msg, |diag| {
272-
let sugg_lines_count = sugg.lines().count();
273-
if sugg_lines_count > MAX_SUGGESTION_HIGHLIGHT_LINES {
274-
let sm = cx.sess().source_map();
275-
if let (Ok(line_upper), Ok(line_bottom)) = (sm.lookup_line(sp.lo()), sm.lookup_line(sp.hi())) {
276-
let split_idx = MAX_SUGGESTION_HIGHLIGHT_LINES / 2;
277-
let span_upper = sm.span_until_char(
278-
sp.with_hi(line_upper.sf.lines(|lines| lines[line_upper.line + split_idx])),
279-
'\n',
280-
);
281-
let span_bottom = sp.with_lo(line_bottom.sf.lines(|lines| lines[line_bottom.line - split_idx]));
282-
283-
let sugg_lines_vec = sugg.lines().collect::<Vec<&str>>();
284-
let sugg_upper = sugg_lines_vec[..split_idx].join("\n");
285-
let sugg_bottom = sugg_lines_vec[sugg_lines_count - split_idx..].join("\n");
286-
287-
diag.span_suggestion(span_upper, helps[0], sugg_upper, applicability);
288-
diag.span_suggestion(span_bottom, helps[1], sugg_bottom, applicability);
289-
290-
return;
291-
}
292-
}
293-
diag.span_suggestion_with_style(
294-
sp,
295-
&helps.join(", "),
296-
sugg,
297-
applicability,
298-
rustc_errors::SuggestionStyle::ShowAlways,
299-
);
300-
});
301-
}
302-
303216
/// Create a suggestion made from several `span → replacement`.
304217
///
305218
/// Note: in the JSON format (used by `compiletest_rs`), the help message will

clippy_utils/src/hir_utils.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ use rustc_middle::ty::TypeckResults;
1616
use rustc_span::{sym, Symbol};
1717
use std::hash::{Hash, Hasher};
1818

19+
/// Callback that is called when two expressions are not equal in the sense of `SpanlessEq`, but
20+
/// other conditions would make them equal.
21+
type SpanlessEqCallback<'a> = dyn FnMut(&Expr<'_>, &Expr<'_>) -> bool + 'a;
22+
1923
/// Type used to check whether two ast are the same. This is different from the
2024
/// operator `==` on ast types as this operator would compare true equality with
2125
/// ID and span.
@@ -26,7 +30,7 @@ pub struct SpanlessEq<'a, 'tcx> {
2630
cx: &'a LateContext<'tcx>,
2731
maybe_typeck_results: Option<(&'tcx TypeckResults<'tcx>, &'tcx TypeckResults<'tcx>)>,
2832
allow_side_effects: bool,
29-
expr_fallback: Option<Box<dyn FnMut(&Expr<'_>, &Expr<'_>) -> bool + 'a>>,
33+
expr_fallback: Option<Box<SpanlessEqCallback<'a>>>,
3034
}
3135

3236
impl<'a, 'tcx> SpanlessEq<'a, 'tcx> {

clippy_utils/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub use self::hir_utils::{
6464

6565
use std::collections::hash_map::Entry;
6666
use std::hash::BuildHasherDefault;
67-
use std::lazy::SyncOnceCell;
67+
use std::sync::OnceLock;
6868
use std::sync::{Mutex, MutexGuard};
6969

7070
use if_chain::if_chain;
@@ -2099,7 +2099,7 @@ pub fn is_hir_ty_cfg_dependant(cx: &LateContext<'_>, ty: &hir::Ty<'_>) -> bool {
20992099
false
21002100
}
21012101

2102-
static TEST_ITEM_NAMES_CACHE: SyncOnceCell<Mutex<FxHashMap<LocalDefId, Vec<Symbol>>>> = SyncOnceCell::new();
2102+
static TEST_ITEM_NAMES_CACHE: OnceLock<Mutex<FxHashMap<LocalDefId, Vec<Symbol>>>> = OnceLock::new();
21032103

21042104
fn with_test_item_names<'tcx>(tcx: TyCtxt<'tcx>, module: LocalDefId, f: impl Fn(&[Symbol]) -> bool) -> bool {
21052105
let cache = TEST_ITEM_NAMES_CACHE.get_or_init(|| Mutex::new(FxHashMap::default()));

clippy_utils/src/sugg.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ impl<T: LintContext> DiagnosticExt<T> for rustc_errors::Diagnostic {
771771
}
772772
}
773773

774-
self.span_suggestion(remove_span, msg, String::new(), applicability);
774+
self.span_suggestion(remove_span, msg, "", applicability);
775775
}
776776
}
777777

rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2022-06-16"
2+
channel = "nightly-2022-06-30"
33
components = ["cargo", "llvm-tools-preview", "rust-src", "rust-std", "rustc", "rustc-dev", "rustfmt"]

src/driver.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ use rustc_tools_util::VersionInfo;
2121

2222
use std::borrow::Cow;
2323
use std::env;
24-
use std::lazy::SyncLazy;
2524
use std::ops::Deref;
2625
use std::panic;
2726
use std::path::{Path, PathBuf};
2827
use std::process::{exit, Command};
28+
use std::sync::LazyLock;
2929

3030
/// If a command-line option matches `find_arg`, then apply the predicate `pred` on its value. If
3131
/// true, then return it. The parameter is assumed to be either `--arg=value` or `--arg value`.
@@ -153,7 +153,8 @@ You can use tool lints to allow or deny lints from your code, eg.:
153153

154154
const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rust-clippy/issues/new";
155155

156-
static ICE_HOOK: SyncLazy<Box<dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static>> = SyncLazy::new(|| {
156+
type PanicCallback = dyn Fn(&panic::PanicInfo<'_>) + Sync + Send + 'static;
157+
static ICE_HOOK: LazyLock<Box<PanicCallback>> = LazyLock::new(|| {
157158
let hook = panic::take_hook();
158159
panic::set_hook(Box::new(|info| report_clippy_ice(info, BUG_REPORT_URL)));
159160
hook
@@ -220,7 +221,7 @@ fn toolchain_path(home: Option<String>, toolchain: Option<String>) -> Option<Pat
220221
#[allow(clippy::too_many_lines)]
221222
pub fn main() {
222223
rustc_driver::init_rustc_env_logger();
223-
SyncLazy::force(&ICE_HOOK);
224+
LazyLock::force(&ICE_HOOK);
224225
exit(rustc_driver::catch_with_exit_code(move || {
225226
let mut orig_args: Vec<String> = env::args().collect();
226227

tests/compile-test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use std::env::{self, remove_var, set_var, var_os};
1212
use std::ffi::{OsStr, OsString};
1313
use std::fs;
1414
use std::io;
15-
use std::lazy::SyncLazy;
1615
use std::path::{Path, PathBuf};
16+
use std::sync::LazyLock;
1717
use test_utils::IS_RUSTC_TEST_SUITE;
1818

1919
mod test_utils;
@@ -75,7 +75,7 @@ extern crate tokio;
7575
/// dependencies must be added to Cargo.toml at the project root. Test
7676
/// dependencies that are not *directly* used by this test module require an
7777
/// `extern crate` declaration.
78-
static EXTERN_FLAGS: SyncLazy<String> = SyncLazy::new(|| {
78+
static EXTERN_FLAGS: LazyLock<String> = LazyLock::new(|| {
7979
let current_exe_depinfo = {
8080
let mut path = env::current_exe().unwrap();
8181
path.set_extension("d");

tests/test_utils/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#![allow(dead_code)] // see https://github.com/rust-lang/rust/issues/46379
22

3-
use std::lazy::SyncLazy;
43
use std::path::PathBuf;
4+
use std::sync::LazyLock;
55

6-
pub static CARGO_CLIPPY_PATH: SyncLazy<PathBuf> = SyncLazy::new(|| {
6+
pub static CARGO_CLIPPY_PATH: LazyLock<PathBuf> = LazyLock::new(|| {
77
let mut path = std::env::current_exe().unwrap();
88
assert!(path.pop()); // deps
99
path.set_file_name("cargo-clippy");

tests/ui/bind_instead_of_map_multipart.stderr

+18
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,25 @@ LL | if s == "43" {
5656
LL ~ return 43;
5757
LL | }
5858
LL | s == "42"
59+
LL | } {
60+
LL ~ return 45;
61+
LL | }
62+
LL | match s.len() {
63+
LL ~ 10 => 2,
64+
LL | 20 => {
5965
...
66+
LL | if foo() {
67+
LL ~ return 20;
68+
LL | }
69+
LL | println!("foo");
70+
LL ~ 3
71+
LL | };
72+
LL | }
73+
LL ~ 20
74+
LL | },
75+
LL ~ 40 => 30,
76+
LL ~ _ => 1,
77+
|
6078

6179
error: using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)`
6280
--> $DIR/bind_instead_of_map_multipart.rs:61:13

tests/ui/branches_sharing_code/shared_at_top_and_bottom.stderr

+2-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ LL + id: e_id,
9898
LL + name: "Player 1".to_string(),
9999
LL + some_data: vec![0x12, 0x34, 0x56, 0x78, 0x90],
100100
LL + };
101-
...
101+
LL + process_data(pack);
102+
|
102103

103104
error: all if blocks contain the same code at both the start and the end
104105
--> $DIR/shared_at_top_and_bottom.rs:94:5

0 commit comments

Comments
 (0)