Skip to content

Commit 9e3cd88

Browse files
committed
Auto merge of #7252 - flip1995:rustup, r=flip1995
Rustup r? `@ghost` cc `@xFrednet` There was a change to the `rustc_span::FileName` removing the `Display` impl for it. I adapted the metadata collector to compile with that change. I'm not sure if I changed the behavior with this. The path to the string is now printed relative to the `clippy_lints` dir. So for example `src/swap.rs`. I think this should be fine, but probably something to be aware of. changelog: none
2 parents 2d597b7 + 559ce6d commit 9e3cd88

Some content is hidden

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

51 files changed

+149
-154
lines changed

clippy_lints/src/derive.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_lint::{LateContext, LateLintPass};
1212
use rustc_middle::hir::map::Map;
1313
use rustc_middle::ty::{self, Ty};
1414
use rustc_session::{declare_lint_pass, declare_tool_lint};
15-
use rustc_span::{def_id::LOCAL_CRATE, source_map::Span};
15+
use rustc_span::source_map::Span;
1616

1717
declare_clippy_lint! {
1818
/// **What it does:** Checks for deriving `Hash` but implementing `PartialEq`
@@ -310,15 +310,11 @@ fn check_copy_clone<'tcx>(cx: &LateContext<'tcx>, item: &Item<'_>, trait_ref: &T
310310
// there's a Copy impl for any instance of the adt.
311311
if !is_copy(cx, ty) {
312312
if ty_subs.non_erasable_generics().next().is_some() {
313-
let has_copy_impl = cx
314-
.tcx
315-
.all_local_trait_impls(LOCAL_CRATE)
316-
.get(&copy_id)
317-
.map_or(false, |impls| {
318-
impls
319-
.iter()
320-
.any(|&id| matches!(cx.tcx.type_of(id).kind(), ty::Adt(adt, _) if ty_adt.did == adt.did))
321-
});
313+
let has_copy_impl = cx.tcx.all_local_trait_impls(()).get(&copy_id).map_or(false, |impls| {
314+
impls
315+
.iter()
316+
.any(|&id| matches!(cx.tcx.type_of(id).kind(), ty::Adt(adt, _) if ty_adt.did == adt.did))
317+
});
322318
if !has_copy_impl {
323319
return;
324320
}

clippy_lints/src/inherent_impl.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
use clippy_utils::diagnostics::span_lint_and_note;
44
use clippy_utils::{in_macro, is_allowed};
55
use rustc_data_structures::fx::FxHashMap;
6-
use rustc_hir::{
7-
def_id::{LocalDefId, LOCAL_CRATE},
8-
Crate, Item, ItemKind, Node,
9-
};
6+
use rustc_hir::{def_id::LocalDefId, Crate, Item, ItemKind, Node};
107
use rustc_lint::{LateContext, LateLintPass};
118
use rustc_session::{declare_lint_pass, declare_tool_lint};
129
use rustc_span::Span;
@@ -56,16 +53,16 @@ impl<'tcx> LateLintPass<'tcx> for MultipleInherentImpl {
5653

5754
for (_, impl_ids) in cx
5855
.tcx
59-
.crate_inherent_impls(LOCAL_CRATE)
56+
.crate_inherent_impls(())
6057
.inherent_impls
6158
.iter()
62-
.filter(|(id, impls)| {
59+
.filter(|(&id, impls)| {
6360
impls.len() > 1
6461
// Check for `#[allow]` on the type definition
6562
&& !is_allowed(
6663
cx,
6764
MULTIPLE_INHERENT_IMPL,
68-
cx.tcx.hir().local_def_id_to_hir_id(id.expect_local()),
65+
cx.tcx.hir().local_def_id_to_hir_id(id),
6966
)
7067
})
7168
{

clippy_lints/src/macro_use.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ pub struct MacroRefData {
4747

4848
impl MacroRefData {
4949
pub fn new(name: String, callee: Span, cx: &LateContext<'_>) -> Self {
50-
let mut path = cx.sess().source_map().span_to_filename(callee).to_string();
50+
let mut path = cx
51+
.sess()
52+
.source_map()
53+
.span_to_filename(callee)
54+
.prefer_local()
55+
.to_string();
5156

5257
// std lib paths are <::std::module::file type>
5358
// so remove brackets, space and type.

clippy_lints/src/misc.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,14 @@ fn in_attributes_expansion(expr: &Expr<'_>) -> bool {
660660
use rustc_span::hygiene::MacroKind;
661661
if expr.span.from_expansion() {
662662
let data = expr.span.ctxt().outer_expn_data();
663-
matches!(data.kind, ExpnKind::Macro(MacroKind::Attr, _))
663+
matches!(
664+
data.kind,
665+
ExpnKind::Macro {
666+
kind: MacroKind::Attr,
667+
name: _,
668+
proc_macro: _
669+
}
670+
)
664671
} else {
665672
false
666673
}

clippy_lints/src/needless_question_mark.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
100100
if is_lang_ctor(cx, qpath, OptionSome) || is_lang_ctor(cx, qpath, ResultOk);
101101
if let ExprKind::Match(inner_expr_with_q, _, MatchSource::TryDesugar) = &arg.kind;
102102
if let ExprKind::Call(called, [inner_expr]) = &inner_expr_with_q.kind;
103-
if let ExprKind::Path(QPath::LangItem(LangItem::TryIntoResult, _)) = &called.kind;
103+
if let ExprKind::Path(QPath::LangItem(LangItem::TryTraitBranch, _)) = &called.kind;
104104
if expr.span.ctxt() == inner_expr.span.ctxt();
105105
let expr_ty = cx.typeck_results().expr_ty(expr);
106106
let inner_ty = cx.typeck_results().expr_ty(inner_expr);

clippy_lints/src/try_err.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for TryErr {
6464
if let ExprKind::Match(match_arg, _, MatchSource::TryDesugar) = expr.kind;
6565
if let ExprKind::Call(match_fun, try_args) = match_arg.kind;
6666
if let ExprKind::Path(ref match_fun_path) = match_fun.kind;
67-
if matches!(match_fun_path, QPath::LangItem(LangItem::TryIntoResult, _));
67+
if matches!(match_fun_path, QPath::LangItem(LangItem::TryTraitBranch, _));
6868
if let Some(try_arg) = try_args.get(0);
6969
if let ExprKind::Call(err_fun, err_args) = try_arg.kind;
7070
if let Some(err_arg) = err_args.get(0);

clippy_lints/src/unit_types/unit_cmp.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ use super::UNIT_CMP;
88
pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
99
if expr.span.from_expansion() {
1010
if let Some(callee) = expr.span.source_callee() {
11-
if let ExpnKind::Macro(MacroKind::Bang, symbol) = callee.kind {
11+
if let ExpnKind::Macro {
12+
kind: MacroKind::Bang,
13+
name: symbol,
14+
proc_macro: _,
15+
} = callee.kind
16+
{
1217
if let ExprKind::Binary(ref cmp, left, _) = expr.kind {
1318
let op = cmp.node;
1419
if op.is_comparison() && cx.typeck_results().expr_ty(left).is_unit() {

clippy_lints/src/unused_io_amount.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount {
4545
if let hir::ExprKind::Call(func, args) = res.kind {
4646
if matches!(
4747
func.kind,
48-
hir::ExprKind::Path(hir::QPath::LangItem(hir::LangItem::TryIntoResult, _))
48+
hir::ExprKind::Path(hir::QPath::LangItem(hir::LangItem::TryTraitBranch, _))
4949
) {
5050
check_map_error(cx, &args[0], expr);
5151
}

clippy_lints/src/utils/internal_lints/metadata_collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ impl SerializableSpan {
247247
let loc: Loc = cx.sess().source_map().lookup_char_pos(span.lo());
248248

249249
Self {
250-
path: format!("{}", loc.file.name),
250+
path: format!("{}", loc.file.name.prefer_remapped()),
251251
line: loc.line,
252252
}
253253
}

clippy_utils/src/lib.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ use rustc_ast::ast::{self, Attribute, BorrowKind, LitKind};
6666
use rustc_data_structures::fx::FxHashMap;
6767
use rustc_hir as hir;
6868
use rustc_hir::def::{DefKind, Res};
69-
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
69+
use rustc_hir::def_id::DefId;
7070
use rustc_hir::intravisit::{self, walk_expr, ErasedMap, FnKind, NestedVisitorMap, Visitor};
7171
use rustc_hir::LangItem::{ResultErr, ResultOk};
7272
use rustc_hir::{
@@ -683,7 +683,7 @@ pub fn method_chain_args<'a>(expr: &'a Expr<'_>, methods: &[&str]) -> Option<Vec
683683
/// Returns `true` if the provided `def_id` is an entrypoint to a program.
684684
pub fn is_entrypoint_fn(cx: &LateContext<'_>, def_id: DefId) -> bool {
685685
cx.tcx
686-
.entry_fn(LOCAL_CRATE)
686+
.entry_fn(())
687687
.map_or(false, |(entry_fn_def_id, _)| def_id == entry_fn_def_id)
688688
}
689689

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

974-
if let ExpnKind::Macro(MacroKind::Bang, mac_name) = data.kind {
974+
if let ExpnKind::Macro {
975+
kind: MacroKind::Bang,
976+
name: mac_name,
977+
proc_macro: _,
978+
} = data.kind
979+
{
975980
if mac_name.as_str() == name {
976981
return Some(new_span);
977982
}
@@ -999,7 +1004,12 @@ pub fn is_direct_expn_of(span: Span, name: &str) -> Option<Span> {
9991004
let data = span.ctxt().outer_expn_data();
10001005
let new_span = data.call_site;
10011006

1002-
if let ExpnKind::Macro(MacroKind::Bang, mac_name) = data.kind {
1007+
if let ExpnKind::Macro {
1008+
kind: MacroKind::Bang,
1009+
name: mac_name,
1010+
proc_macro: _,
1011+
} = data.kind
1012+
{
10031013
if mac_name.as_str() == name {
10041014
return Some(new_span);
10051015
}

rust-toolchain

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

tests/ui-internal/default_lint.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ note: the lint level is defined here
1515
LL | #![deny(clippy::internal)]
1616
| ^^^^^^^^^^^^^^^^
1717
= note: `#[deny(clippy::default_lint)]` implied by `#[deny(clippy::internal)]`
18-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
18+
= note: this error originates in the macro `$crate::declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)
1919

2020
error: aborting due to previous error
2121

tests/ui-internal/if_chain_style.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ LL | | }
5656
LL | | }
5757
| |_____^
5858
|
59-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
59+
= note: this error originates in the macro `__if_chain` (in Nightly builds, run with -Z macro-backtrace for more info)
6060

6161
error: `let` expression should be above the `if_chain!`
6262
--> $DIR/if_chain_style.rs:40:9

tests/ui-internal/lint_without_lint_pass.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ note: the lint level is defined here
1515
LL | #![deny(clippy::internal)]
1616
| ^^^^^^^^^^^^^^^^
1717
= note: `#[deny(clippy::lint_without_lint_pass)]` implied by `#[deny(clippy::internal)]`
18-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
18+
= note: this error originates in the macro `declare_tool_lint` (in Nightly builds, run with -Z macro-backtrace for more info)
1919

2020
error: aborting due to previous error
2121

tests/ui/assertions_on_constants.stderr

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LL | assert!(true);
66
|
77
= note: `-D clippy::assertions-on-constants` implied by `-D warnings`
88
= help: remove it
9-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
9+
= note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info)
1010

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

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

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

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

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

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

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

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

8383
error: aborting due to 9 previous errors
8484

tests/ui/checked_unwrap/simple_conditionals.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ LL | $a.unwrap(); // unnecessary
5555
LL | m!(x);
5656
| ------ in this macro invocation
5757
|
58-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
58+
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
5959

6060
error: you checked before that `unwrap()` cannot fail, instead of checking and unwrapping, it's better to use `if let` or `match`
6161
--> $DIR/simple_conditionals.rs:54:9

tests/ui/collapsible_match2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ LL | mac!(res_opt => Ok(val), val => Some(n), foo(n));
5555
| ^^^ ^^^^^^^ with this pattern
5656
| |
5757
| replace this binding
58-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
58+
= note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info)
5959

6060
error: unnecessary nested match
6161
--> $DIR/collapsible_match2.rs:51:20

tests/ui/crashes/ice-6255.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | extern crate std as core;
77
LL | define_other_core!();
88
| --------------------- in this macro invocation
99
|
10-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
10+
= note: this error originates in the macro `define_other_core` (in Nightly builds, run with -Z macro-backtrace for more info)
1111

1212
error: aborting due to previous error
1313

tests/ui/declare_interior_mutable_const/others.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ LL | const $name: $ty = $e;
3333
LL | declare_const!(_ONCE: Once = Once::new()); //~ ERROR interior mutable
3434
| ------------------------------------------ in this macro invocation
3535
|
36-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
36+
= note: this error originates in the macro `declare_const` (in Nightly builds, run with -Z macro-backtrace for more info)
3737

3838
error: aborting due to 4 previous errors
3939

tests/ui/declare_interior_mutable_const/traits.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ LL | const $name: $ty = $e;
1515
LL | declare_const!(ANOTHER_ATOMIC: AtomicUsize = Self::ATOMIC); //~ ERROR interior mutable
1616
| ----------------------------------------------------------- in this macro invocation
1717
|
18-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
18+
= note: this error originates in the macro `declare_const` (in Nightly builds, run with -Z macro-backtrace for more info)
1919

2020
error: a `const` item should never be interior mutable
2121
--> $DIR/traits.rs:43:5

tests/ui/deprecated.stderr

+1-7
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,5 @@ error: lint `clippy::filter_map` has been removed: this lint has been replaced b
8484
LL | #[warn(clippy::filter_map)]
8585
| ^^^^^^^^^^^^^^^^^^
8686

87-
error: lint `clippy::unstable_as_slice` has been removed: `Vec::as_slice` has been stabilized in 1.7
88-
--> $DIR/deprecated.rs:1:8
89-
|
90-
LL | #[warn(clippy::unstable_as_slice)]
91-
| ^^^^^^^^^^^^^^^^^^^^^^^^^
92-
93-
error: aborting due to 15 previous errors
87+
error: aborting due to 14 previous errors
9488

tests/ui/deprecated_old.stderr

+1-7
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,5 @@ error: lint `misaligned_transmute` has been removed: this lint has been split in
1818
LL | #[warn(misaligned_transmute)]
1919
| ^^^^^^^^^^^^^^^^^^^^
2020

21-
error: lint `unstable_as_slice` has been removed: `Vec::as_slice` has been stabilized in 1.7
22-
--> $DIR/deprecated_old.rs:1:8
23-
|
24-
LL | #[warn(unstable_as_slice)]
25-
| ^^^^^^^^^^^^^^^^^
26-
27-
error: aborting due to 4 previous errors
21+
error: aborting due to 3 previous errors
2822

tests/ui/deref_addrof.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ LL | *& $visitor
5757
LL | m!(self)
5858
| -------- in this macro invocation
5959
|
60-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
60+
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
6161

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

7373
error: aborting due to 10 previous errors
7474

0 commit comments

Comments
 (0)