Skip to content

Commit 18fcf64

Browse files
committed
address review comments
1 parent e947964 commit 18fcf64

File tree

3 files changed

+38
-29
lines changed

3 files changed

+38
-29
lines changed

compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,12 +1622,14 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
16221622
let f = self.tcx.erase_regions(f);
16231623
let mut expected = with_forced_trimmed_paths!(e.sort_string(self.tcx));
16241624
let mut found = with_forced_trimmed_paths!(f.sort_string(self.tcx));
1625-
if let Some(def_id) = cause.span.ctxt().outer_expn_data().macro_def_id
1626-
&& self.tcx.is_diagnostic_item(sym::assert_macro, def_id)
1625+
if let ObligationCauseCode::Pattern { span, .. } = cause.code()
1626+
&& let Some(span) = span
1627+
&& !span.from_expansion()
1628+
&& cause.span.from_expansion()
16271629
{
1628-
// When the type error comes from `assert!()`, the cause and effect are reversed
1629-
// because that macro expands to `match val { false => {panic!()}, _ => {} }`, which
1630-
// would say something like "expected `Type`, found `bool`", confusing the user.
1630+
// When the type error comes from a macro like `assert!()`, and we are pointing at
1631+
// code the user wrote the cause and effect are reversed as the expected value is
1632+
// what the macro expanded to.
16311633
(found, expected) = (expected, found);
16321634
}
16331635
if expected == found {
@@ -2202,14 +2204,22 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
22022204
return None;
22032205
}
22042206
let (mut expected, mut found) = (exp_found.expected, exp_found.found);
2205-
if let Some(def_id) = cause.span.ctxt().outer_expn_data().macro_def_id
2206-
&& self.tcx.is_diagnostic_item(sym::assert_macro, def_id)
2207+
2208+
if let ObligationCauseCode::Pattern { span, .. } = cause.code()
2209+
&& let Some(span) = span
2210+
&& !span.from_expansion()
2211+
&& cause.span.from_expansion()
22072212
{
2208-
// When the type error comes from `assert!()`, the cause and effect are reversed
2209-
// because that macro expands to `match val { false => {panic!()}, _ => {} }`, which
2210-
// would say something like
2213+
// When the type error comes from a macro like `assert!()`, and we are pointing at
2214+
// code the user wrote, the cause and effect are reversed as the expected value is
2215+
// what the macro expanded to. So if the user provided a `Type` when the macro is
2216+
// written in such a way that a `bool` was expected, we want to print:
2217+
// = note: expected `bool`
2218+
// found `Type`"
2219+
// but as far as the compiler is concerned, after expansion what was expected was `Type`
22112220
// = note: expected `Type`
22122221
// found `bool`"
2222+
// so we reverse them here to match user expectation.
22132223
(expected, found) = (found, expected);
22142224
}
22152225

src/tools/clippy/tests/ui/incompatible_msrv.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#![warn(clippy::incompatible_msrv)]
2-
#![allow(clippy::diverging_sub_expression)]
32
#![feature(custom_inner_attributes)]
4-
#![allow(stable_features)]
3+
#![allow(stable_features, clippy::diverging_sub_expression)]
54
#![feature(strict_provenance)] // For use in test
65
#![clippy::msrv = "1.3.0"]
76

src/tools/clippy/tests/ui/incompatible_msrv.stderr

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.10.0`
2-
--> tests/ui/incompatible_msrv.rs:17:39
2+
--> tests/ui/incompatible_msrv.rs:16:39
33
|
44
LL | assert_eq!(map.entry("poneyland").key(), &"poneyland");
55
| ^^^^^
@@ -8,37 +8,37 @@ LL | assert_eq!(map.entry("poneyland").key(), &"poneyland");
88
= help: to override `-D warnings` add `#[allow(clippy::incompatible_msrv)]`
99

1010
error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.12.0`
11-
--> tests/ui/incompatible_msrv.rs:23:11
11+
--> tests/ui/incompatible_msrv.rs:22:11
1212
|
1313
LL | v.into_key();
1414
| ^^^^^^^^^^
1515

1616
error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.4.0`
17-
--> tests/ui/incompatible_msrv.rs:27:5
17+
--> tests/ui/incompatible_msrv.rs:26:5
1818
|
1919
LL | sleep(Duration::new(1, 0));
2020
| ^^^^^
2121

2222
error: current MSRV (Minimum Supported Rust Version) is `1.2.0` but this item is stable since `1.3.0`
23-
--> tests/ui/incompatible_msrv.rs:32:33
23+
--> tests/ui/incompatible_msrv.rs:31:33
2424
|
2525
LL | static NO_BODY_BAD_MSRV: Option<Duration> = None;
2626
| ^^^^^^^^
2727

2828
error: current MSRV (Minimum Supported Rust Version) is `1.2.0` but this item is stable since `1.3.0`
29-
--> tests/ui/incompatible_msrv.rs:39:19
29+
--> tests/ui/incompatible_msrv.rs:38:19
3030
|
3131
LL | let _: Option<Duration> = None;
3232
| ^^^^^^^^
3333

3434
error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.43.0`
35-
--> tests/ui/incompatible_msrv.rs:63:17
35+
--> tests/ui/incompatible_msrv.rs:62:17
3636
|
3737
LL | let _ = core::iter::once_with(|| 0);
3838
| ^^^^^^^^^^^^^^^^^^^^^
3939

4040
error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.43.0`
41-
--> tests/ui/incompatible_msrv.rs:70:21
41+
--> tests/ui/incompatible_msrv.rs:69:21
4242
|
4343
LL | let _ = core::iter::once_with(|| $msg);
4444
| ^^^^^^^^^^^^^^^^^^^^^
@@ -49,63 +49,63 @@ LL | my_panic!("foo");
4949
= note: this error originates in the macro `my_panic` (in Nightly builds, run with -Z macro-backtrace for more info)
5050

5151
error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.43.0`
52-
--> tests/ui/incompatible_msrv.rs:77:13
52+
--> tests/ui/incompatible_msrv.rs:76:13
5353
|
5454
LL | assert!(core::iter::once_with(|| 0).next().is_some());
5555
| ^^^^^^^^^^^^^^^^^^^^^
5656

5757
error: current MSRV (Minimum Supported Rust Version) is `1.80.0` but this item is stable since `1.82.0`
58-
--> tests/ui/incompatible_msrv.rs:90:13
58+
--> tests/ui/incompatible_msrv.rs:89:13
5959
|
6060
LL | let _ = std::iter::repeat_n((), 5);
6161
| ^^^^^^^^^^^^^^^^^^^
6262

6363
error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.82.0`
64-
--> tests/ui/incompatible_msrv.rs:101:13
64+
--> tests/ui/incompatible_msrv.rs:100:13
6565
|
6666
LL | let _ = std::iter::repeat_n((), 5);
6767
| ^^^^^^^^^^^^^^^^^^^
6868

6969
error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.82.0`
70-
--> tests/ui/incompatible_msrv.rs:106:17
70+
--> tests/ui/incompatible_msrv.rs:105:17
7171
|
7272
LL | let _ = std::iter::repeat_n((), 5);
7373
| ^^^^^^^^^^^^^^^^^^^
7474
|
7575
= note: you may want to conditionally increase the MSRV considered by Clippy using the `clippy::msrv` attribute
7676

7777
error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.82.0`
78-
--> tests/ui/incompatible_msrv.rs:111:17
78+
--> tests/ui/incompatible_msrv.rs:110:17
7979
|
8080
LL | let _ = std::iter::repeat_n((), 5);
8181
| ^^^^^^^^^^^^^^^^^^^
8282

8383
error: current MSRV (Minimum Supported Rust Version) is `1.78.0` but this item is stable since `1.84.0`
84-
--> tests/ui/incompatible_msrv.rs:124:7
84+
--> tests/ui/incompatible_msrv.rs:123:7
8585
|
8686
LL | r.isqrt()
8787
| ^^^^^^^
8888

8989
error: current MSRV (Minimum Supported Rust Version) is `1.3.0` but this item is stable since `1.85.0`
90-
--> tests/ui/incompatible_msrv.rs:129:13
90+
--> tests/ui/incompatible_msrv.rs:128:13
9191
|
9292
LL | let _ = std::io::ErrorKind::CrossesDevices;
9393
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9494

9595
error: current MSRV (Minimum Supported Rust Version) is `1.87.0` but this item is stable in a `const` context since `1.88.0`
96-
--> tests/ui/incompatible_msrv.rs:141:15
96+
--> tests/ui/incompatible_msrv.rs:140:15
9797
|
9898
LL | _ = c.get();
9999
| ^^^^^
100100

101101
error: current MSRV (Minimum Supported Rust Version) is `1.86.0` but this item is stable since `1.87.0`
102-
--> tests/ui/incompatible_msrv.rs:160:13
102+
--> tests/ui/incompatible_msrv.rs:159:13
103103
|
104104
LL | let _ = std::io::ErrorKind::InvalidFilename;
105105
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
106106

107107
error: current MSRV (Minimum Supported Rust Version) is `1.86.0` but this item is stable since `1.87.0`
108-
--> tests/ui/incompatible_msrv.rs:162:21
108+
--> tests/ui/incompatible_msrv.rs:161:21
109109
|
110110
LL | let _ = const { std::io::ErrorKind::InvalidFilename };
111111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)