Skip to content

Rustup #7252

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

Merged
merged 19 commits into from
May 20, 2021
Merged

Rustup #7252

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
16 changes: 6 additions & 10 deletions clippy_lints/src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::hir::map::Map;
use rustc_middle::ty::{self, Ty};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::{def_id::LOCAL_CRATE, source_map::Span};
use rustc_span::source_map::Span;

declare_clippy_lint! {
/// **What it does:** Checks for deriving `Hash` but implementing `PartialEq`
Expand Down Expand Up @@ -310,15 +310,11 @@ fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &T
// there's a Copy impl for any instance of the adt.
if !is_copy(cx, ty) {
if ty_subs.non_erasable_generics().next().is_some() {
let has_copy_impl = cx
.tcx
.all_local_trait_impls(LOCAL_CRATE)
.get(&copy_id)
.map_or(false, |impls| {
impls
.iter()
.any(|&id| matches!(cx.tcx.type_of(id).kind(), ty::Adt(adt, _) if ty_adt.did == adt.did))
});
let has_copy_impl = cx.tcx.all_local_trait_impls(()).get(&copy_id).map_or(false, |impls| {
impls
.iter()
.any(|&id| matches!(cx.tcx.type_of(id).kind(), ty::Adt(adt, _) if ty_adt.did == adt.did))
});
if !has_copy_impl {
return;
}
Expand Down
11 changes: 4 additions & 7 deletions clippy_lints/src/inherent_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
use clippy_utils::diagnostics::span_lint_and_note;
use clippy_utils::{in_macro, is_allowed};
use rustc_data_structures::fx::FxHashMap;
use rustc_hir::{
def_id::{LocalDefId, LOCAL_CRATE},
Crate, Item, ItemKind, Node,
};
use rustc_hir::{def_id::LocalDefId, Crate, Item, ItemKind, Node};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::Span;
Expand Down Expand Up @@ -56,16 +53,16 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl {

for (_, impl_ids) in cx
.tcx
.crate_inherent_impls(LOCAL_CRATE)
.crate_inherent_impls(())
.inherent_impls
.iter()
.filter(|(id, impls)| {
.filter(|(&id, impls)| {
impls.len() > 1
// Check for `#[allow]` on the type definition
&& !is_allowed(
cx,
MULTIPLE_INHERENT_IMPL,
cx.tcx.hir().local_def_id_to_hir_id(id.expect_local()),
cx.tcx.hir().local_def_id_to_hir_id(id),
)
})
{
Expand Down
7 changes: 6 additions & 1 deletion clippy_lints/src/macro_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ pub struct MacroRefData {

impl MacroRefData {
pub fn new(name: String, callee: Span, cx: &LateContext<'_>) -> Self {
let mut path = cx.sess().source_map().span_to_filename(callee).to_string();
let mut path = cx
.sess()
.source_map()
.span_to_filename(callee)
.prefer_local()
.to_string();

// std lib paths are <::std::module::file type>
// so remove brackets, space and type.
Expand Down
9 changes: 8 additions & 1 deletion clippy_lints/src/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,14 @@ fn in_attributes_expansion(expr: &Expr<'_>) -> bool {
use rustc_span::hygiene::MacroKind;
if expr.span.from_expansion() {
let data = expr.span.ctxt().outer_expn_data();
matches!(data.kind, ExpnKind::Macro(MacroKind::Attr, _))
matches!(
data.kind,
ExpnKind::Macro {
kind: MacroKind::Attr,
name: _,
proc_macro: _
}
)
} else {
false
}
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/needless_question_mark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
if is_lang_ctor(cx, qpath, OptionSome) || is_lang_ctor(cx, qpath, ResultOk);
if let ExprKind::Match(inner_expr_with_q, _, MatchSource::TryDesugar) = &arg.kind;
if let ExprKind::Call(called, [inner_expr]) = &inner_expr_with_q.kind;
if let ExprKind::Path(QPath::LangItem(LangItem::TryIntoResult, _)) = &called.kind;
if let ExprKind::Path(QPath::LangItem(LangItem::TryTraitBranch, _)) = &called.kind;
if expr.span.ctxt() == inner_expr.span.ctxt();
let expr_ty = cx.typeck_results().expr_ty(expr);
let inner_ty = cx.typeck_results().expr_ty(inner_expr);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/try_err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for TryErr {
if let ExprKind::Match(match_arg, _, MatchSource::TryDesugar) = expr.kind;
if let ExprKind::Call(match_fun, try_args) = match_arg.kind;
if let ExprKind::Path(ref match_fun_path) = match_fun.kind;
if matches!(match_fun_path, QPath::LangItem(LangItem::TryIntoResult, _));
if matches!(match_fun_path, QPath::LangItem(LangItem::TryTraitBranch, _));
if let Some(try_arg) = try_args.get(0);
if let ExprKind::Call(err_fun, err_args) = try_arg.kind;
if let Some(err_arg) = err_args.get(0);
Expand Down
7 changes: 6 additions & 1 deletion clippy_lints/src/unit_types/unit_cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ use super::UNIT_CMP;
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
if expr.span.from_expansion() {
if let Some(callee) = expr.span.source_callee() {
if let ExpnKind::Macro(MacroKind::Bang, symbol) = callee.kind {
if let ExpnKind::Macro {
kind: MacroKind::Bang,
name: symbol,
proc_macro: _,
} = callee.kind
{
if let ExprKind::Binary(ref cmp, left, _) = expr.kind {
let op = cmp.node;
if op.is_comparison() && cx.typeck_results().expr_ty(left).is_unit() {
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/unused_io_amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount {
if let hir::ExprKind::Call(func, args) = res.kind {
if matches!(
func.kind,
hir::ExprKind::Path(hir::QPath::LangItem(hir::LangItem::TryIntoResult, _))
hir::ExprKind::Path(hir::QPath::LangItem(hir::LangItem::TryTraitBranch, _))
) {
check_map_error(cx, &args[0], expr);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ impl SerializableSpan {
let loc: Loc = cx.sess().source_map().lookup_char_pos(span.lo());

Self {
path: format!("{}", loc.file.name),
path: format!("{}", loc.file.name.prefer_remapped()),
line: loc.line,
}
}
Expand Down
18 changes: 14 additions & 4 deletions clippy_utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ use rustc_ast::ast::{self, Attribute, BorrowKind, LitKind};
use rustc_data_structures::fx::FxHashMap;
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
use rustc_hir::def_id::DefId;
use rustc_hir::intravisit::{self, walk_expr, ErasedMap, FnKind, NestedVisitorMap, Visitor};
use rustc_hir::LangItem::{ResultErr, ResultOk};
use rustc_hir::{
Expand Down Expand Up @@ -683,7 +683,7 @@ pub fn method_chain_args<'a>(expr: &'a Expr<'_>, methods: &[&str]) -> Option<Vec
/// Returns `true` if the provided `def_id` is an entrypoint to a program.
pub fn is_entrypoint_fn(cx: &LateContext<'_>, def_id: DefId) -> bool {
cx.tcx
.entry_fn(LOCAL_CRATE)
.entry_fn(())
.map_or(false, |(entry_fn_def_id, _)| def_id == entry_fn_def_id)
}

Expand Down Expand Up @@ -971,7 +971,12 @@ pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
let data = span.ctxt().outer_expn_data();
let new_span = data.call_site;

if let ExpnKind::Macro(MacroKind::Bang, mac_name) = data.kind {
if let ExpnKind::Macro {
kind: MacroKind::Bang,
name: mac_name,
proc_macro: _,
} = data.kind
{
if mac_name.as_str() == name {
return Some(new_span);
}
Expand Down Expand Up @@ -999,7 +1004,12 @@ pub fn is_direct_expn_of(span: Span, name: &str) -> Option<Span> {
let data = span.ctxt().outer_expn_data();
let new_span = data.call_site;

if let ExpnKind::Macro(MacroKind::Bang, mac_name) = data.kind {
if let ExpnKind::Macro {
kind: MacroKind::Bang,
name: mac_name,
proc_macro: _,
} = data.kind
{
if mac_name.as_str() == name {
return Some(new_span);
}
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-05-06"
channel = "nightly-2021-05-20"
components = ["llvm-tools-preview", "rustc-dev", "rust-src"]
2 changes: 1 addition & 1 deletion tests/ui-internal/default_lint.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ note: the lint level is defined here
LL | #![deny(clippy::internal)]
| ^^^^^^^^^^^^^^^^
= note: `#[deny(clippy::default_lint)]` implied by `#[deny(clippy::internal)]`
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `$crate::declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

2 changes: 1 addition & 1 deletion tests/ui-internal/if_chain_style.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ LL | | }
LL | | }
| |_____^
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `__if_chain` (in Nightly builds, run with -Z macro-backtrace for more info)

error: `let` expression should be above the `if_chain!`
--> $DIR/if_chain_style.rs:40:9
Expand Down
2 changes: 1 addition & 1 deletion tests/ui-internal/lint_without_lint_pass.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ note: the lint level is defined here
LL | #![deny(clippy::internal)]
| ^^^^^^^^^^^^^^^^
= note: `#[deny(clippy::lint_without_lint_pass)]` implied by `#[deny(clippy::internal)]`
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

18 changes: 9 additions & 9 deletions tests/ui/assertions_on_constants.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ LL | assert!(true);
|
= note: `-D clippy::assertions-on-constants` implied by `-D warnings`
= help: remove it
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)

error: `assert!(false)` should probably be replaced
--> $DIR/assertions_on_constants.rs:12:5
Expand All @@ -15,7 +15,7 @@ LL | assert!(false);
| ^^^^^^^^^^^^^^^
|
= help: use `panic!()` or `unreachable!()`
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)

error: `assert!(true)` will be optimized out by the compiler
--> $DIR/assertions_on_constants.rs:13:5
Expand All @@ -24,7 +24,7 @@ LL | assert!(true, "true message");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: remove it
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)

error: `assert!(false, "false message")` should probably be replaced
--> $DIR/assertions_on_constants.rs:14:5
Expand All @@ -33,7 +33,7 @@ LL | assert!(false, "false message");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: use `panic!("false message")` or `unreachable!("false message")`
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)

error: `assert!(false, msg.to_uppercase())` should probably be replaced
--> $DIR/assertions_on_constants.rs:17:5
Expand All @@ -42,7 +42,7 @@ LL | assert!(false, msg.to_uppercase());
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: use `panic!(msg.to_uppercase())` or `unreachable!(msg.to_uppercase())`
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)

error: `assert!(true)` will be optimized out by the compiler
--> $DIR/assertions_on_constants.rs:20:5
Expand All @@ -51,7 +51,7 @@ LL | assert!(B);
| ^^^^^^^^^^^
|
= help: remove it
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)

error: `assert!(false)` should probably be replaced
--> $DIR/assertions_on_constants.rs:23:5
Expand All @@ -60,7 +60,7 @@ LL | assert!(C);
| ^^^^^^^^^^^
|
= help: use `panic!()` or `unreachable!()`
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)

error: `assert!(false, "C message")` should probably be replaced
--> $DIR/assertions_on_constants.rs:24:5
Expand All @@ -69,7 +69,7 @@ LL | assert!(C, "C message");
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: use `panic!("C message")` or `unreachable!("C message")`
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)

error: `debug_assert!(true)` will be optimized out by the compiler
--> $DIR/assertions_on_constants.rs:26:5
Expand All @@ -78,7 +78,7 @@ LL | debug_assert!(true);
| ^^^^^^^^^^^^^^^^^^^^
|
= help: remove it
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `$crate::assert` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 9 previous errors

2 changes: 1 addition & 1 deletion tests/ui/checked_unwrap/simple_conditionals.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ LL | $a.unwrap(); // unnecessary
LL | m!(x);
| ------ in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)

error: you checked before that `unwrap()` cannot fail, instead of checking and unwrapping, it's better to use `if let` or `match`
--> $DIR/simple_conditionals.rs:54:9
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/collapsible_match2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ LL | mac!(res_opt => Ok(val), val => Some(n), foo(n));
| ^^^ ^^^^^^^ with this pattern
| |
| replace this binding
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)

error: unnecessary nested match
--> $DIR/collapsible_match2.rs:51:20
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/crashes/ice-6255.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LL | extern crate std as core;
LL | define_other_core!();
| --------------------- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `define_other_core` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

2 changes: 1 addition & 1 deletion tests/ui/declare_interior_mutable_const/others.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ LL | const $name: $ty = $e;
LL | declare_const!(_ONCE: Once = Once::new()); //~ ERROR interior mutable
| ------------------------------------------ in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `declare_const` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 4 previous errors

2 changes: 1 addition & 1 deletion tests/ui/declare_interior_mutable_const/traits.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ LL | const $name: $ty = $e;
LL | declare_const!(ANOTHER_ATOMIC: AtomicUsize = Self::ATOMIC); //~ ERROR interior mutable
| ----------------------------------------------------------- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `declare_const` (in Nightly builds, run with -Z macro-backtrace for more info)

error: a `const` item should never be interior mutable
--> $DIR/traits.rs:43:5
Expand Down
8 changes: 1 addition & 7 deletions tests/ui/deprecated.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,5 @@ error: lint `clippy::filter_map` has been removed: this lint has been replaced b
LL | #[warn(clippy::filter_map)]
| ^^^^^^^^^^^^^^^^^^

error: lint `clippy::unstable_as_slice` has been removed: `Vec::as_slice` has been stabilized in 1.7
--> $DIR/deprecated.rs:1:8
|
LL | #[warn(clippy::unstable_as_slice)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 15 previous errors
error: aborting due to 14 previous errors

8 changes: 1 addition & 7 deletions tests/ui/deprecated_old.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,5 @@ error: lint `misaligned_transmute` has been removed: this lint has been split in
LL | #[warn(misaligned_transmute)]
| ^^^^^^^^^^^^^^^^^^^^

error: lint `unstable_as_slice` has been removed: `Vec::as_slice` has been stabilized in 1.7
--> $DIR/deprecated_old.rs:1:8
|
LL | #[warn(unstable_as_slice)]
| ^^^^^^^^^^^^^^^^^

error: aborting due to 4 previous errors
error: aborting due to 3 previous errors

4 changes: 2 additions & 2 deletions tests/ui/deref_addrof.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ LL | *& $visitor
LL | m!(self)
| -------- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)

error: immediately dereferencing a reference
--> $DIR/deref_addrof.rs:51:9
Expand All @@ -68,7 +68,7 @@ LL | *& mut $visitor
LL | m_mut!(self)
| ------------ in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
= note: this error originates in the macro `m_mut` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to 10 previous errors

Loading