Skip to content

Commit 739dc86

Browse files
Merge branch 'master' into issue14150
2 parents 7acc850 + 88bcf1c commit 739dc86

Some content is hidden

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

44 files changed

+441
-359
lines changed

.github/driver.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ unset CARGO_MANIFEST_DIR
4747

4848
# Run a lint and make sure it produces the expected output. It's also expected to exit with code 1
4949
# FIXME: How to match the clippy invocation in compile-test.rs?
50-
./target/debug/clippy-driver -Dwarnings -Aunused -Zui-testing --emit metadata --crate-type bin tests/ui/string_to_string.rs 2>string_to_string.stderr && exit 1
51-
sed -e "/= help: for/d" string_to_string.stderr > normalized.stderr
52-
diff -u normalized.stderr tests/ui/string_to_string.stderr
50+
./target/debug/clippy-driver -Dwarnings -Aunused -Zui-testing --emit metadata --crate-type bin tests/ui/char_lit_as_u8.rs 2>char_lit_as_u8.stderr && exit 1
51+
sed -e "/= help: for/d" char_lit_as_u8.stderr > normalized.stderr
52+
diff -u normalized.stderr tests/ui/char_lit_as_u8.stderr
5353

5454
# make sure "clippy-driver --rustc --arg" and "rustc --arg" behave the same
5555
SYSROOT=$(rustc --print sysroot)

clippy_lints/src/blocks_in_conditions.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ impl<'tcx> LateLintPass<'tcx> for BlocksInConditions {
100100
cond.span,
101101
BRACED_EXPR_MESSAGE,
102102
"try",
103-
snippet_block_with_applicability(cx, ex.span, "..", Some(expr.span), &mut applicability)
104-
.to_string(),
103+
snippet_block_with_applicability(cx, ex.span, "..", Some(expr.span), &mut applicability),
105104
applicability,
106105
);
107106
}

clippy_lints/src/copies.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,9 @@ fn lint_branches_sharing_code<'tcx>(
235235
let cond_snippet = reindent_multiline(&snippet(cx, cond_span, "_"), false, None);
236236
let cond_indent = indent_of(cx, cond_span);
237237
let moved_snippet = reindent_multiline(&snippet(cx, span, "_"), true, None);
238-
let suggestion = moved_snippet.to_string() + "\n" + &cond_snippet + "{";
238+
let suggestion = moved_snippet + "\n" + &cond_snippet + "{";
239239
let suggestion = reindent_multiline(&suggestion, true, cond_indent);
240-
(replace_span, suggestion.to_string())
240+
(replace_span, suggestion)
241241
});
242242
let end_suggestion = res.end_span(last_block, sm).map(|span| {
243243
let moved_snipped = reindent_multiline(&snippet(cx, span, "_"), true, None);
@@ -253,7 +253,7 @@ fn lint_branches_sharing_code<'tcx>(
253253
.then_some(range.start - 4..range.end)
254254
})
255255
.map_or(span, |range| range.with_ctxt(span.ctxt()));
256-
(span, suggestion.to_string())
256+
(span, suggestion.clone())
257257
});
258258

259259
let (span, msg, end_span) = match (&start_suggestion, &end_suggestion) {

clippy_lints/src/declared_lints.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,6 @@ pub static LINTS: &[&::declare_clippy_lint::LintInfo] = &[
690690
crate::strings::STRING_FROM_UTF8_AS_BYTES_INFO,
691691
crate::strings::STRING_LIT_AS_BYTES_INFO,
692692
crate::strings::STRING_SLICE_INFO,
693-
crate::strings::STRING_TO_STRING_INFO,
694693
crate::strings::STR_TO_STRING_INFO,
695694
crate::strings::TRIM_SPLIT_WHITESPACE_INFO,
696695
crate::strlen_on_c_strings::STRLEN_ON_C_STRINGS_INFO,

clippy_lints/src/deprecated_lints.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ declare_with_version! { DEPRECATED(DEPRECATED_VERSION) = [
3434
("clippy::replace_consts", "`min_value` and `max_value` are now deprecated"),
3535
#[clippy::version = "pre 1.29.0"]
3636
("clippy::should_assert_eq", "`assert!(a == b)` can now print the values the same way `assert_eq!(a, b) can"),
37+
#[clippy::version = "1.90.0"]
38+
("clippy::string_to_string", "`clippy:implicit_clone` covers those cases"),
3739
#[clippy::version = "pre 1.29.0"]
3840
("clippy::unsafe_vector_initialization", "the suggested alternative could be substantially slower"),
3941
#[clippy::version = "pre 1.29.0"]

clippy_lints/src/doc/broken_link.rs

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -19,52 +19,52 @@ pub fn check(cx: &LateContext<'_>, bl: &PullDownBrokenLink<'_>, doc: &str, fragm
1919
}
2020

2121
fn warn_if_broken_link(cx: &LateContext<'_>, bl: &PullDownBrokenLink<'_>, doc: &str, fragments: &[DocFragment]) {
22-
if let Some((span, _)) = source_span_for_markdown_range(cx.tcx, doc, &bl.span, fragments) {
23-
let mut len = 0;
22+
let mut len = 0;
2423

25-
// grab raw link data
26-
let (_, raw_link) = doc.split_at(bl.span.start);
24+
// grab raw link data
25+
let (_, raw_link) = doc.split_at(bl.span.start);
2726

28-
// strip off link text part
29-
let raw_link = match raw_link.split_once(']') {
30-
None => return,
31-
Some((prefix, suffix)) => {
32-
len += prefix.len() + 1;
33-
suffix
34-
},
35-
};
27+
// strip off link text part
28+
let raw_link = match raw_link.split_once(']') {
29+
None => return,
30+
Some((prefix, suffix)) => {
31+
len += prefix.len() + 1;
32+
suffix
33+
},
34+
};
3635

37-
let raw_link = match raw_link.split_once('(') {
38-
None => return,
39-
Some((prefix, suffix)) => {
40-
if !prefix.is_empty() {
41-
// there is text between ']' and '(' chars, so it is not a valid link
42-
return;
43-
}
44-
len += prefix.len() + 1;
45-
suffix
46-
},
47-
};
48-
49-
if raw_link.starts_with("(http") {
50-
// reduce chances of false positive reports
51-
// by limiting this checking only to http/https links.
52-
return;
53-
}
54-
55-
for c in raw_link.chars() {
56-
if c == ')' {
57-
// it is a valid link
36+
let raw_link = match raw_link.split_once('(') {
37+
None => return,
38+
Some((prefix, suffix)) => {
39+
if !prefix.is_empty() {
40+
// there is text between ']' and '(' chars, so it is not a valid link
5841
return;
5942
}
43+
len += prefix.len() + 1;
44+
suffix
45+
},
46+
};
6047

61-
if c == '\n' {
62-
report_broken_link(cx, span, len);
63-
break;
64-
}
48+
if raw_link.starts_with("(http") {
49+
// reduce chances of false positive reports
50+
// by limiting this checking only to http/https links.
51+
return;
52+
}
6553

66-
len += 1;
54+
for c in raw_link.chars() {
55+
if c == ')' {
56+
// it is a valid link
57+
return;
6758
}
59+
60+
if c == '\n'
61+
&& let Some((span, _)) = source_span_for_markdown_range(cx.tcx, doc, &bl.span, fragments)
62+
{
63+
report_broken_link(cx, span, len);
64+
break;
65+
}
66+
67+
len += 1;
6868
}
6969
}
7070

clippy_lints/src/if_not_else.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl LateLintPass<'_> for IfNotElse {
8181
e.span,
8282
msg,
8383
"try",
84-
make_sugg(cx, &cond.kind, cond_inner.span, els.span, "..", Some(e.span)).to_string(),
84+
make_sugg(cx, &cond.kind, cond_inner.span, els.span, "..", Some(e.span)),
8585
Applicability::MachineApplicable,
8686
),
8787
_ => span_lint_and_help(cx, IF_NOT_ELSE, e.span, msg, None, help),

clippy_lints/src/let_with_type_underscore.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::is_from_proc_macro;
3+
use clippy_utils::source::{IntoSpan, SpanRangeExt};
34
use rustc_errors::Applicability;
45
use rustc_hir::{LetStmt, TyKind};
56
use rustc_lint::{LateContext, LateLintPass};
@@ -30,17 +31,23 @@ impl<'tcx> LateLintPass<'tcx> for UnderscoreTyped {
3031
if let Some(ty) = local.ty // Ensure that it has a type defined
3132
&& let TyKind::Infer(()) = &ty.kind // that type is '_'
3233
&& local.span.eq_ctxt(ty.span)
33-
&& !local.span.in_external_macro(cx.tcx.sess.source_map())
34+
&& let sm = cx.tcx.sess.source_map()
35+
&& !local.span.in_external_macro(sm)
3436
&& !is_from_proc_macro(cx, ty)
3537
{
38+
let span_to_remove = sm
39+
.span_extend_to_prev_char_before(ty.span, ':', true)
40+
.with_leading_whitespace(cx)
41+
.into_span();
42+
3643
span_lint_and_then(
3744
cx,
3845
LET_WITH_TYPE_UNDERSCORE,
3946
local.span,
4047
"variable declared with type underscore",
4148
|diag| {
4249
diag.span_suggestion_verbose(
43-
ty.span.with_lo(local.pat.span.hi()),
50+
span_to_remove,
4451
"remove the explicit type `_` declaration",
4552
"",
4653
Applicability::MachineApplicable,

clippy_lints/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,6 @@ pub fn register_lint_passes(store: &mut rustc_lint::LintStore, conf: &'static Co
665665
store.register_early_pass(|| Box::new(asm_syntax::InlineAsmX86IntelSyntax));
666666
store.register_late_pass(|_| Box::new(empty_drop::EmptyDrop));
667667
store.register_late_pass(|_| Box::new(strings::StrToString));
668-
store.register_late_pass(|_| Box::new(strings::StringToString));
669668
store.register_late_pass(|_| Box::new(zero_sized_map_values::ZeroSizedMapValues));
670669
store.register_late_pass(|_| Box::<vec_init_then_push::VecInitThenPush>::default());
671670
store.register_late_pass(|_| Box::new(redundant_slicing::RedundantSlicing));

clippy_lints/src/manual_assert.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::macros::{is_panic, root_macro_call};
3-
use clippy_utils::{is_else_clause, is_parent_stmt, peel_blocks_with_stmt, span_extract_comment, sugg};
3+
use clippy_utils::{higher, is_else_clause, is_parent_stmt, peel_blocks_with_stmt, span_extract_comment, sugg};
44
use rustc_errors::Applicability;
5-
use rustc_hir::{Expr, ExprKind, UnOp};
5+
use rustc_hir::{Expr, ExprKind};
66
use rustc_lint::{LateContext, LateLintPass, LintContext};
77
use rustc_session::declare_lint_pass;
88

@@ -35,7 +35,7 @@ declare_lint_pass!(ManualAssert => [MANUAL_ASSERT]);
3535

3636
impl<'tcx> LateLintPass<'tcx> for ManualAssert {
3737
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &Expr<'tcx>) {
38-
if let ExprKind::If(cond, then, None) = expr.kind
38+
if let Some(higher::If { cond, then, r#else: None }) = higher::If::hir(expr)
3939
&& !matches!(cond.kind, ExprKind::Let(_))
4040
&& !expr.span.from_expansion()
4141
&& let then = peel_blocks_with_stmt(then)
@@ -51,19 +51,13 @@ impl<'tcx> LateLintPass<'tcx> for ManualAssert {
5151
&& !is_else_clause(cx.tcx, expr)
5252
{
5353
let mut applicability = Applicability::MachineApplicable;
54-
let cond = cond.peel_drop_temps();
5554
let mut comments = span_extract_comment(cx.sess().source_map(), expr.span);
5655
if !comments.is_empty() {
5756
comments += "\n";
5857
}
59-
let (cond, not) = match cond.kind {
60-
ExprKind::Unary(UnOp::Not, e) => (e, ""),
61-
_ => (cond, "!"),
62-
};
63-
let cond_sugg =
64-
sugg::Sugg::hir_with_context(cx, cond, expr.span.ctxt(), "..", &mut applicability).maybe_paren();
58+
let cond_sugg = !sugg::Sugg::hir_with_context(cx, cond, expr.span.ctxt(), "..", &mut applicability);
6559
let semicolon = if is_parent_stmt(cx, expr.hir_id) { ";" } else { "" };
66-
let sugg = format!("assert!({not}{cond_sugg}, {format_args_snip}){semicolon}");
60+
let sugg = format!("assert!({cond_sugg}, {format_args_snip}){semicolon}");
6761
// we show to the user the suggestion without the comments, but when applying the fix, include the
6862
// comments in the block
6963
span_lint_and_then(

0 commit comments

Comments
 (0)