Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustup #7853

Merged
merged 15 commits into from
Oct 21, 2021
Merged

Rustup #7853

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1873,10 +1873,10 @@ Released 2019-01-17

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

* New lints: [`slow_vector_initialization`], [`mem_discriminant_non_enum`],
* New lints: [`slow_vector_initialization`], `mem_discriminant_non_enum`,
[`redundant_clone`], [`wildcard_dependencies`],
[`into_iter_on_ref`], `into_iter_on_array`, [`deprecated_cfg_attr`],
[`mem_discriminant_non_enum`], [`cargo_common_metadata`]
[`cargo_common_metadata`]
* Add support for `u128` and `i128` to integer related lints
* Add float support to `mistyped_literal_suffixes`
* Fix false positives in `use_self`
Expand Down Expand Up @@ -2842,7 +2842,6 @@ Released 2018-09-13
[`match_wild_err_arm`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_wild_err_arm
[`match_wildcard_for_single_variants`]: https://rust-lang.github.io/rust-clippy/master/index.html#match_wildcard_for_single_variants
[`maybe_infinite_iter`]: https://rust-lang.github.io/rust-clippy/master/index.html#maybe_infinite_iter
[`mem_discriminant_non_enum`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_discriminant_non_enum
[`mem_forget`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_forget
[`mem_replace_option_with_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_option_with_none
[`mem_replace_with_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#mem_replace_with_default
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clippy"
version = "0.1.57"
version = "0.1.58"
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
repository = "https://github.com/rust-lang/rust-clippy"
readme = "README.md"
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clippy_lints"
version = "0.1.57"
version = "0.1.58"
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
repository = "https://github.com/rust-lang/rust-clippy"
readme = "README.md"
Expand Down
20 changes: 10 additions & 10 deletions clippy_lints/src/copies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_data_structures::fx::FxHashSet;
use rustc_errors::{Applicability, DiagnosticBuilder};
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
use rustc_hir::{Block, Expr, ExprKind, HirId};
use rustc_lint::{LateContext, LateLintPass};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::hir::map::Map;
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::{source_map::Span, symbol::Symbol, BytePos};
Expand Down Expand Up @@ -432,10 +432,11 @@ fn emit_branches_sharing_code_lint(
let mut add_expr_note = false;

// Construct suggestions
let sm = cx.sess().source_map();
if start_stmts > 0 {
let block = blocks[0];
let span_start = first_line_of_span(cx, if_expr.span).shrink_to_lo();
let span_end = block.stmts[start_stmts - 1].span.source_callsite();
let span_end = sm.stmt_span(block.stmts[start_stmts - 1].span, block.span);

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

let moved_start = if end_stmts == 0 && block.expr.is_some() {
block.expr.unwrap().span
block.expr.unwrap().span.source_callsite()
} else {
block.stmts[block.stmts.len() - end_stmts].span
}
.source_callsite();
let moved_end = block
.expr
.map_or_else(|| block.stmts[block.stmts.len() - 1].span, |expr| expr.span)
.source_callsite();
sm.stmt_span(block.stmts[block.stmts.len() - end_stmts].span, block.span)
};
let moved_end = block.expr.map_or_else(
|| sm.stmt_span(block.stmts[block.stmts.len() - 1].span, block.span),
|expr| expr.span.source_callsite(),
);

let moved_span = moved_start.to(moved_end);
let moved_snipped = reindent_multiline(snippet(cx, moved_span, "_"), true, None);
Expand Down
7 changes: 1 addition & 6 deletions clippy_lints/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessFormat {
}
}

fn span_useless_format(cx: &LateContext<'_>, span: Span, mut sugg: String, mut applicability: Applicability) {
// The callsite span contains the statement semicolon for some reason.
if snippet_with_applicability(cx, span, "..", &mut applicability).ends_with(';') {
sugg.push(';');
}

fn span_useless_format(cx: &LateContext<'_>, span: Span, sugg: String, applicability: Applicability) {
span_lint_and_sugg(
cx,
USELESS_FORMAT,
Expand Down
1 change: 0 additions & 1 deletion clippy_lints/src/lib.register_all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ store.register_group(true, "clippy::all", Some("clippy_all"), vec![
LintId::of(matches::REDUNDANT_PATTERN_MATCHING),
LintId::of(matches::SINGLE_MATCH),
LintId::of(matches::WILDCARD_IN_OR_PATTERNS),
LintId::of(mem_discriminant::MEM_DISCRIMINANT_NON_ENUM),
LintId::of(mem_replace::MEM_REPLACE_OPTION_WITH_NONE),
LintId::of(mem_replace::MEM_REPLACE_WITH_DEFAULT),
LintId::of(mem_replace::MEM_REPLACE_WITH_UNINIT),
Expand Down
1 change: 0 additions & 1 deletion clippy_lints/src/lib.register_correctness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ store.register_group(true, "clippy::correctness", Some("clippy_correctness"), ve
LintId::of(loops::NEVER_LOOP),
LintId::of(loops::WHILE_IMMUTABLE_CONDITION),
LintId::of(match_str_case_mismatch::MATCH_STR_CASE_MISMATCH),
LintId::of(mem_discriminant::MEM_DISCRIMINANT_NON_ENUM),
LintId::of(mem_replace::MEM_REPLACE_WITH_UNINIT),
LintId::of(methods::CLONE_DOUBLE_REF),
LintId::of(methods::ITERATOR_STEP_BY_ZERO),
Expand Down
1 change: 0 additions & 1 deletion clippy_lints/src/lib.register_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,6 @@ store.register_lints(&[
matches::SINGLE_MATCH_ELSE,
matches::WILDCARD_ENUM_MATCH_ARM,
matches::WILDCARD_IN_OR_PATTERNS,
mem_discriminant::MEM_DISCRIMINANT_NON_ENUM,
mem_forget::MEM_FORGET,
mem_replace::MEM_REPLACE_OPTION_WITH_NONE,
mem_replace::MEM_REPLACE_WITH_DEFAULT,
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ mod match_on_vec_items;
mod match_result_ok;
mod match_str_case_mismatch;
mod matches;
mod mem_discriminant;
mod mem_forget;
mod mem_replace;
mod methods;
Expand Down Expand Up @@ -606,7 +605,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
let doc_valid_idents = conf.doc_valid_idents.iter().cloned().collect::<FxHashSet<_>>();
store.register_late_pass(move || Box::new(doc::DocMarkdown::new(doc_valid_idents.clone())));
store.register_late_pass(|| Box::new(neg_multiply::NegMultiply));
store.register_late_pass(|| Box::new(mem_discriminant::MemDiscriminant));
store.register_late_pass(|| Box::new(mem_forget::MemForget));
store.register_late_pass(|| Box::new(arithmetic::Arithmetic::default()));
store.register_late_pass(|| Box::new(assign_ops::AssignOps));
Expand Down Expand Up @@ -861,6 +859,7 @@ pub fn register_renamed(ls: &mut rustc_lint::LintStore) {
ls.register_renamed("clippy::panic_params", "non_fmt_panics");
ls.register_renamed("clippy::unknown_clippy_lints", "unknown_lints");
ls.register_renamed("clippy::invalid_atomic_ordering", "invalid_atomic_ordering");
ls.register_renamed("clippy::mem_discriminant_non_enum", "enum_intrinsics_non_enums");
}

// only exists to let the dogfood integration test works.
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/manual_unwrap_or.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ fn lint_manual_unwrap_or<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
reindent_multiline(or_body_snippet.into(), true, Some(indent));

let suggestion = if scrutinee.span.from_expansion() {
// we don't want parenthesis around macro, e.g. `(some_macro!()).unwrap_or(0)`
// we don't want parentheses around macro, e.g. `(some_macro!()).unwrap_or(0)`
sugg::Sugg::hir_with_macro_callsite(cx, scrutinee, "..")
}
else {
Expand Down
82 changes: 0 additions & 82 deletions clippy_lints/src/mem_discriminant.rs

This file was deleted.

13 changes: 6 additions & 7 deletions clippy_lints/src/needless_continue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@
use clippy_utils::diagnostics::span_lint_and_help;
use clippy_utils::source::{indent_of, snippet, snippet_block};
use rustc_ast::ast;
use rustc_lint::{EarlyContext, EarlyLintPass};
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::source_map::{original_sp, DUMMY_SP};
use rustc_span::Span;

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

const MSG_REDUNDANT_CONTINUE_EXPRESSION: &str = "this `continue` expression is redundant";
Expand Down Expand Up @@ -343,10 +342,10 @@ fn suggestion_snippet_for_continue_inside_else<'a>(cx: &EarlyContext<'_>, data:
let indent = span_of_first_expr_in_block(data.if_block)
.and_then(|span| indent_of(cx, span))
.unwrap_or(0);
let to_annex = data.block_stmts[data.stmt_idx + 1..]
let to_annex = data.loop_block.stmts[data.stmt_idx + 1..]
.iter()
.map(|stmt| original_sp(stmt.span, DUMMY_SP))
.map(|span| {
.map(|stmt| {
let span = cx.sess().source_map().stmt_span(stmt.span, data.loop_block.span);
let snip = snippet_block(cx, span, "..", None).into_owned();
snip.lines()
.map(|line| format!("{}{}", " ".repeat(indent), line))
Expand Down Expand Up @@ -393,7 +392,7 @@ fn check_and_warn<'a>(cx: &EarlyContext<'_>, expr: &'a ast::Expr) {
if_cond: cond,
if_block: then_block,
else_expr,
block_stmts: &loop_block.stmts,
loop_block,
};
if needless_continue_in_else(else_expr, label) {
emit_warning(
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/utils/internal_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,8 +770,7 @@ impl<'tcx> LateLintPass<'tcx> for MatchTypeOnDiagItem {
let segments: Vec<&str> = segments.iter().map(|sym| &**sym).collect();
if let Some(ty_did) = path_to_res(cx, &segments[..]).opt_def_id();
// Check if the matched type is a diagnostic item
let diag_items = cx.tcx.diagnostic_items(ty_did.krate);
if let Some(item_name) = diag_items.iter().find_map(|(k, v)| if *v == ty_did { Some(k) } else { None });
if let Some(item_name) = cx.tcx.get_diagnostic_name(ty_did);
then {
// TODO: check paths constants from external crates.
let cx_snippet = snippet(cx, context.span, "_");
Expand Down
2 changes: 1 addition & 1 deletion clippy_utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clippy_utils"
version = "0.1.57"
version = "0.1.58"
edition = "2021"
publish = false

Expand Down
1 change: 0 additions & 1 deletion clippy_utils/src/higher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,6 @@ impl PanicExpn<'tcx> {
if let Some(init) = block.expr;
if let ExprKind::Call(_, [format_args]) = init.kind;
let expn_data = expr.span.ctxt().outer_expn_data();
if let ExprKind::AddrOf(_, _, format_args) = format_args.kind;
if let Some(format_args) = FormatArgsExpn::parse(format_args);
then {
Some(PanicExpn {
Expand Down
1 change: 0 additions & 1 deletion clippy_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,6 @@ pub fn match_panic_def_id(cx: &LateContext<'_>, did: DefId) -> bool {
did,
&[
&paths::BEGIN_PANIC,
&paths::BEGIN_PANIC_FMT,
&paths::PANIC_ANY,
&paths::PANICKING_PANIC,
&paths::PANICKING_PANIC_FMT,
Expand Down
1 change: 0 additions & 1 deletion clippy_utils/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub const ASSERT_NE_MACRO: [&str; 3] = ["core", "macros", "assert_ne"];
pub const ASMUT_TRAIT: [&str; 3] = ["core", "convert", "AsMut"];
pub const ASREF_TRAIT: [&str; 3] = ["core", "convert", "AsRef"];
pub(super) const BEGIN_PANIC: [&str; 3] = ["std", "panicking", "begin_panic"];
pub(super) const BEGIN_PANIC_FMT: [&str; 3] = ["std", "panicking", "begin_panic_fmt"];
/// Preferably use the diagnostic item `sym::Borrow` where possible
pub const BORROW_TRAIT: [&str; 3] = ["core", "borrow", "Borrow"];
pub const BTREEMAP_CONTAINS_KEY: [&str; 6] = ["alloc", "collections", "btree", "map", "BTreeMap", "contains_key"];
Expand Down
6 changes: 3 additions & 3 deletions clippy_utils/src/sugg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ use std::convert::TryInto;
use std::fmt::Display;
use std::ops::{Add, Neg, Not, Sub};

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

/// Adds parenthesis to any expression that might need them. Suitable to the
/// Adds parentheses to any expression that might need them. Suitable to the
/// `self` argument of a method call
/// (e.g., to build `bar.foo()` or `(1 + 2).foo()`).
pub fn maybe_par(self) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2021-10-07"
channel = "nightly-2021-10-21"
components = ["llvm-tools-preview", "rustc-dev", "rust-src"]
4 changes: 2 additions & 2 deletions tests/ui-internal/unnecessary_symbol_str.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ fn main() {
Symbol::intern("foo") == rustc_span::sym::clippy;
Symbol::intern("foo") == rustc_span::symbol::kw::SelfLower;
Symbol::intern("foo") != rustc_span::symbol::kw::SelfUpper;
Ident::invalid().name == rustc_span::sym::clippy;
rustc_span::sym::clippy == Ident::invalid().name;
Ident::empty().name == rustc_span::sym::clippy;
rustc_span::sym::clippy == Ident::empty().name;
}
4 changes: 2 additions & 2 deletions tests/ui-internal/unnecessary_symbol_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ fn main() {
Symbol::intern("foo").as_str() == "clippy";
Symbol::intern("foo").to_string() == "self";
Symbol::intern("foo").to_ident_string() != "Self";
&*Ident::invalid().as_str() == "clippy";
"clippy" == Ident::invalid().to_string();
&*Ident::empty().as_str() == "clippy";
"clippy" == Ident::empty().to_string();
}
8 changes: 4 additions & 4 deletions tests/ui-internal/unnecessary_symbol_str.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ LL | Symbol::intern("foo").to_ident_string() != "Self";
error: unnecessary `Symbol` to string conversion
--> $DIR/unnecessary_symbol_str.rs:14:5
|
LL | &*Ident::invalid().as_str() == "clippy";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Ident::invalid().name == rustc_span::sym::clippy`
LL | &*Ident::empty().as_str() == "clippy";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `Ident::empty().name == rustc_span::sym::clippy`

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

error: aborting due to 5 previous errors

Loading