Skip to content

Commit 91496c2

Browse files
committed
Auto merge of #7853 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` changelog: none
2 parents 535262c + 8e48333 commit 91496c2

File tree

69 files changed

+316
-625
lines changed

Some content is hidden

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

69 files changed

+316
-625
lines changed

CHANGELOG.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -1873,10 +1873,10 @@ Released 2019-01-17
18731873

18741874
[2e26fdc2...b2601be](https://github.com/rust-lang/rust-clippy/compare/2e26fdc2...b2601be)
18751875

1876-
* New lints: [`slow_vector_initialization`], [`mem_discriminant_non_enum`],
1876+
* New lints: [`slow_vector_initialization`], `mem_discriminant_non_enum`,
18771877
[`redundant_clone`], [`wildcard_dependencies`],
18781878
[`into_iter_on_ref`], `into_iter_on_array`, [`deprecated_cfg_attr`],
1879-
[`mem_discriminant_non_enum`], [`cargo_common_metadata`]
1879+
[`cargo_common_metadata`]
18801880
* Add support for `u128` and `i128` to integer related lints
18811881
* Add float support to `mistyped_literal_suffixes`
18821882
* Fix false positives in `use_self`
@@ -2842,7 +2842,6 @@ Released 2018-09-13
28422842
[`match_wild_err_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_wild_err_arm
28432843
[`match_wildcard_for_single_variants`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_wildcard_for_single_variants
28442844
[`maybe_infinite_iter`]: https://rust-lang.github.io/rust-clippy/master/index.html#maybe_infinite_iter
2845-
[`mem_discriminant_non_enum`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_discriminant_non_enum
28462845
[`mem_forget`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_forget
28472846
[`mem_replace_option_with_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_option_with_none
28482847
[`mem_replace_with_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default

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.57"
3+
version = "0.1.58"
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/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.57"
3+
version = "0.1.58"
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/copies.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_data_structures::fx::FxHashSet;
99
use rustc_errors::{Applicability, DiagnosticBuilder};
1010
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
1111
use rustc_hir::{Block, Expr, ExprKind, HirId};
12-
use rustc_lint::{LateContext, LateLintPass};
12+
use rustc_lint::{LateContext, LateLintPass, LintContext};
1313
use rustc_middle::hir::map::Map;
1414
use rustc_session::{declare_lint_pass, declare_tool_lint};
1515
use rustc_span::{source_map::Span, symbol::Symbol, BytePos};
@@ -432,10 +432,11 @@ fn emit_branches_sharing_code_lint(
432432
let mut add_expr_note = false;
433433

434434
// Construct suggestions
435+
let sm = cx.sess().source_map();
435436
if start_stmts > 0 {
436437
let block = blocks[0];
437438
let span_start = first_line_of_span(cx, if_expr.span).shrink_to_lo();
438-
let span_end = block.stmts[start_stmts - 1].span.source_callsite();
439+
let span_end = sm.stmt_span(block.stmts[start_stmts - 1].span, block.span);
439440

440441
let cond_span = first_line_of_span(cx, if_expr.span).until(block.span);
441442
let cond_snippet = reindent_multiline(snippet(cx, cond_span, "_"), false, None);
@@ -454,15 +455,14 @@ fn emit_branches_sharing_code_lint(
454455
let span_end = block.span.shrink_to_hi();
455456

456457
let moved_start = if end_stmts == 0 && block.expr.is_some() {
457-
block.expr.unwrap().span
458+
block.expr.unwrap().span.source_callsite()
458459
} else {
459-
block.stmts[block.stmts.len() - end_stmts].span
460-
}
461-
.source_callsite();
462-
let moved_end = block
463-
.expr
464-
.map_or_else(|| block.stmts[block.stmts.len() - 1].span, |expr| expr.span)
465-
.source_callsite();
460+
sm.stmt_span(block.stmts[block.stmts.len() - end_stmts].span, block.span)
461+
};
462+
let moved_end = block.expr.map_or_else(
463+
|| sm.stmt_span(block.stmts[block.stmts.len() - 1].span, block.span),
464+
|expr| expr.span.source_callsite(),
465+
);
466466

467467
let moved_span = moved_start.to(moved_end);
468468
let moved_snipped = reindent_multiline(snippet(cx, moved_span, "_"), true, None);

clippy_lints/src/format.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessFormat {
8989
}
9090
}
9191

92-
fn span_useless_format(cx: &LateContext<'_>, span: Span, mut sugg: String, mut applicability: Applicability) {
93-
// The callsite span contains the statement semicolon for some reason.
94-
if snippet_with_applicability(cx, span, "..", &mut applicability).ends_with(';') {
95-
sugg.push(';');
96-
}
97-
92+
fn span_useless_format(cx: &LateContext<'_>, span: Span, sugg: String, applicability: Applicability) {
9893
span_lint_and_sugg(
9994
cx,
10095
USELESS_FORMAT,

clippy_lints/src/lib.register_all.rs

-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
130130
LintId::of(matches::REDUNDANT_PATTERN_MATCHING),
131131
LintId::of(matches::SINGLE_MATCH),
132132
LintId::of(matches::WILDCARD_IN_OR_PATTERNS),
133-
LintId::of(mem_discriminant::MEM_DISCRIMINANT_NON_ENUM),
134133
LintId::of(mem_replace::MEM_REPLACE_OPTION_WITH_NONE),
135134
LintId::of(mem_replace::MEM_REPLACE_WITH_DEFAULT),
136135
LintId::of(mem_replace::MEM_REPLACE_WITH_UNINIT),

clippy_lints/src/lib.register_correctness.rs

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ store.register_group(true, "clippy::correctness", Some("clippy_correctness"), ve
3737
LintId::of(loops::NEVER_LOOP),
3838
LintId::of(loops::WHILE_IMMUTABLE_CONDITION),
3939
LintId::of(match_str_case_mismatch::MATCH_STR_CASE_MISMATCH),
40-
LintId::of(mem_discriminant::MEM_DISCRIMINANT_NON_ENUM),
4140
LintId::of(mem_replace::MEM_REPLACE_WITH_UNINIT),
4241
LintId::of(methods::CLONE_DOUBLE_REF),
4342
LintId::of(methods::ITERATOR_STEP_BY_ZERO),

clippy_lints/src/lib.register_lints.rs

-1
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ store.register_lints(&[
245245
matches::SINGLE_MATCH_ELSE,
246246
matches::WILDCARD_ENUM_MATCH_ARM,
247247
matches::WILDCARD_IN_OR_PATTERNS,
248-
mem_discriminant::MEM_DISCRIMINANT_NON_ENUM,
249248
mem_forget::MEM_FORGET,
250249
mem_replace::MEM_REPLACE_OPTION_WITH_NONE,
251250
mem_replace::MEM_REPLACE_WITH_DEFAULT,

clippy_lints/src/lib.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,6 @@ mod match_on_vec_items;
268268
mod match_result_ok;
269269
mod match_str_case_mismatch;
270270
mod matches;
271-
mod mem_discriminant;
272271
mod mem_forget;
273272
mod mem_replace;
274273
mod methods;
@@ -606,7 +605,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
606605
let doc_valid_idents = conf.doc_valid_idents.iter().cloned().collect::<FxHashSet<_>>();
607606
store.register_late_pass(move || Box::new(doc::DocMarkdown::new(doc_valid_idents.clone())));
608607
store.register_late_pass(|| Box::new(neg_multiply::NegMultiply));
609-
store.register_late_pass(|| Box::new(mem_discriminant::MemDiscriminant));
610608
store.register_late_pass(|| Box::new(mem_forget::MemForget));
611609
store.register_late_pass(|| Box::new(arithmetic::Arithmetic::default()));
612610
store.register_late_pass(|| Box::new(assign_ops::AssignOps));
@@ -861,6 +859,7 @@ pub fn register_renamed(ls: &mut rustc_lint::LintStore) {
861859
ls.register_renamed("clippy::panic_params", "non_fmt_panics");
862860
ls.register_renamed("clippy::unknown_clippy_lints", "unknown_lints");
863861
ls.register_renamed("clippy::invalid_atomic_ordering", "invalid_atomic_ordering");
862+
ls.register_renamed("clippy::mem_discriminant_non_enum", "enum_intrinsics_non_enums");
864863
}
865864

866865
// only exists to let the dogfood integration test works.

clippy_lints/src/manual_unwrap_or.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ fn lint_manual_unwrap_or<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
9898
reindent_multiline(or_body_snippet.into(), true, Some(indent));
9999

100100
let suggestion = if scrutinee.span.from_expansion() {
101-
// we don't want parenthesis around macro, e.g. `(some_macro!()).unwrap_or(0)`
101+
// we don't want parentheses around macro, e.g. `(some_macro!()).unwrap_or(0)`
102102
sugg::Sugg::hir_with_macro_callsite(cx, scrutinee, "..")
103103
}
104104
else {

clippy_lints/src/mem_discriminant.rs

-82
This file was deleted.

clippy_lints/src/needless_continue.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@
3636
use clippy_utils::diagnostics::span_lint_and_help;
3737
use clippy_utils::source::{indent_of, snippet, snippet_block};
3838
use rustc_ast::ast;
39-
use rustc_lint::{EarlyContext, EarlyLintPass};
39+
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
4040
use rustc_session::{declare_lint_pass, declare_tool_lint};
41-
use rustc_span::source_map::{original_sp, DUMMY_SP};
4241
use rustc_span::Span;
4342

4443
declare_clippy_lint! {
@@ -270,7 +269,7 @@ struct LintData<'a> {
270269
/// The 0-based index of the `if` statement in the containing loop block.
271270
stmt_idx: usize,
272271
/// The statements of the loop block.
273-
block_stmts: &'a [ast::Stmt],
272+
loop_block: &'a ast::Block,
274273
}
275274

276275
const MSG_REDUNDANT_CONTINUE_EXPRESSION: &str = "this `continue` expression is redundant";
@@ -343,10 +342,10 @@ fn suggestion_snippet_for_continue_inside_else<'a>(cx: &EarlyContext<'_>, data:
343342
let indent = span_of_first_expr_in_block(data.if_block)
344343
.and_then(|span| indent_of(cx, span))
345344
.unwrap_or(0);
346-
let to_annex = data.block_stmts[data.stmt_idx + 1..]
345+
let to_annex = data.loop_block.stmts[data.stmt_idx + 1..]
347346
.iter()
348-
.map(|stmt| original_sp(stmt.span, DUMMY_SP))
349-
.map(|span| {
347+
.map(|stmt| {
348+
let span = cx.sess().source_map().stmt_span(stmt.span, data.loop_block.span);
350349
let snip = snippet_block(cx, span, "..", None).into_owned();
351350
snip.lines()
352351
.map(|line| format!("{}{}", " ".repeat(indent), line))
@@ -393,7 +392,7 @@ fn check_and_warn<'a>(cx: &EarlyContext<'_>, expr: &'a ast::Expr) {
393392
if_cond: cond,
394393
if_block: then_block,
395394
else_expr,
396-
block_stmts: &loop_block.stmts,
395+
loop_block,
397396
};
398397
if needless_continue_in_else(else_expr, label) {
399398
emit_warning(

clippy_lints/src/utils/internal_lints.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -770,8 +770,7 @@ impl<'tcx> LateLintPass<'tcx> for MatchTypeOnDiagItem {
770770
let segments: Vec<&str> = segments.iter().map(|sym| &**sym).collect();
771771
if let Some(ty_did) = path_to_res(cx, &segments[..]).opt_def_id();
772772
// Check if the matched type is a diagnostic item
773-
let diag_items = cx.tcx.diagnostic_items(ty_did.krate);
774-
if let Some(item_name) = diag_items.iter().find_map(|(k, v)| if *v == ty_did { Some(k) } else { None });
773+
if let Some(item_name) = cx.tcx.get_diagnostic_name(ty_did);
775774
then {
776775
// TODO: check paths constants from external crates.
777776
let cx_snippet = snippet(cx, context.span, "_");

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.57"
3+
version = "0.1.58"
44
edition = "2021"
55
publish = false
66

clippy_utils/src/higher.rs

-1
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,6 @@ impl PanicExpn<'tcx> {
722722
if let Some(init) = block.expr;
723723
if let ExprKind::Call(_, [format_args]) = init.kind;
724724
let expn_data = expr.span.ctxt().outer_expn_data();
725-
if let ExprKind::AddrOf(_, _, format_args) = format_args.kind;
726725
if let Some(format_args) = FormatArgsExpn::parse(format_args);
727726
then {
728727
Some(PanicExpn {

clippy_utils/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,6 @@ pub fn match_panic_def_id(cx: &LateContext<'_>, did: DefId) -> bool {
16411641
did,
16421642
&[
16431643
&paths::BEGIN_PANIC,
1644-
&paths::BEGIN_PANIC_FMT,
16451644
&paths::PANIC_ANY,
16461645
&paths::PANICKING_PANIC,
16471646
&paths::PANICKING_PANIC_FMT,

clippy_utils/src/paths.rs

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ pub const ASSERT_NE_MACRO: [&str; 3] = ["core", "macros", "assert_ne"];
2626
pub const ASMUT_TRAIT: [&str; 3] = ["core", "convert", "AsMut"];
2727
pub const ASREF_TRAIT: [&str; 3] = ["core", "convert", "AsRef"];
2828
pub(super) const BEGIN_PANIC: [&str; 3] = ["std", "panicking", "begin_panic"];
29-
pub(super) const BEGIN_PANIC_FMT: [&str; 3] = ["std", "panicking", "begin_panic_fmt"];
3029
/// Preferably use the diagnostic item `sym::Borrow` where possible
3130
pub const BORROW_TRAIT: [&str; 3] = ["core", "borrow", "Borrow"];
3231
pub const BTREEMAP_CONTAINS_KEY: [&str; 6] = ["alloc", "collections", "btree", "map", "BTreeMap", "contains_key"];

clippy_utils/src/sugg.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ use std::convert::TryInto;
1616
use std::fmt::Display;
1717
use std::ops::{Add, Neg, Not, Sub};
1818

19-
/// A helper type to build suggestion correctly handling parenthesis.
19+
/// A helper type to build suggestion correctly handling parentheses.
2020
#[derive(Clone, PartialEq)]
2121
pub enum Sugg<'a> {
22-
/// An expression that never needs parenthesis such as `1337` or `[0; 42]`.
22+
/// An expression that never needs parentheses such as `1337` or `[0; 42]`.
2323
NonParen(Cow<'a, str>),
2424
/// An expression that does not fit in other variants.
2525
MaybeParen(Cow<'a, str>),
@@ -283,7 +283,7 @@ impl<'a> Sugg<'a> {
283283
}
284284
}
285285

286-
/// Adds parenthesis to any expression that might need them. Suitable to the
286+
/// Adds parentheses to any expression that might need them. Suitable to the
287287
/// `self` argument of a method call
288288
/// (e.g., to build `bar.foo()` or `(1 + 2).foo()`).
289289
pub fn maybe_par(self) -> Self {

rust-toolchain

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2021-10-07"
2+
channel = "nightly-2021-10-21"
33
components = ["llvm-tools-preview", "rustc-dev", "rust-src"]

tests/ui-internal/unnecessary_symbol_str.fixed

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ fn main() {
1111
Symbol::intern("foo") == rustc_span::sym::clippy;
1212
Symbol::intern("foo") == rustc_span::symbol::kw::SelfLower;
1313
Symbol::intern("foo") != rustc_span::symbol::kw::SelfUpper;
14-
Ident::invalid().name == rustc_span::sym::clippy;
15-
rustc_span::sym::clippy == Ident::invalid().name;
14+
Ident::empty().name == rustc_span::sym::clippy;
15+
rustc_span::sym::clippy == Ident::empty().name;
1616
}

tests/ui-internal/unnecessary_symbol_str.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ fn main() {
1111
Symbol::intern("foo").as_str() == "clippy";
1212
Symbol::intern("foo").to_string() == "self";
1313
Symbol::intern("foo").to_ident_string() != "Self";
14-
&*Ident::invalid().as_str() == "clippy";
15-
"clippy" == Ident::invalid().to_string();
14+
&*Ident::empty().as_str() == "clippy";
15+
"clippy" == Ident::empty().to_string();
1616
}

tests/ui-internal/unnecessary_symbol_str.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ LL | Symbol::intern("foo").to_ident_string() != "Self";
2626
error: unnecessary `Symbol` to string conversion
2727
--> $DIR/unnecessary_symbol_str.rs:14:5
2828
|
29-
LL | &*Ident::invalid().as_str() == "clippy";
30-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Ident::invalid().name == rustc_span::sym::clippy`
29+
LL | &*Ident::empty().as_str() == "clippy";
30+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Ident::empty().name == rustc_span::sym::clippy`
3131

3232
error: unnecessary `Symbol` to string conversion
3333
--> $DIR/unnecessary_symbol_str.rs:15:5
3434
|
35-
LL | "clippy" == Ident::invalid().to_string();
36-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `rustc_span::sym::clippy == Ident::invalid().name`
35+
LL | "clippy" == Ident::empty().to_string();
36+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `rustc_span::sym::clippy == Ident::empty().name`
3737

3838
error: aborting due to 5 previous errors
3939

0 commit comments

Comments
 (0)