Skip to content

Commit 0cb0f76

Browse files
committed
Auto merge of rust-lang#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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 7 additions & 7 deletions
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

Lines changed: 3 additions & 10 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 88 deletions
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

Lines changed: 5 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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()));

0 commit comments

Comments
 (0)