Skip to content

Commit

Permalink
Tweak spans for "adt defined here" note
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Oct 29, 2023
1 parent 196bc04 commit c96611e
Show file tree
Hide file tree
Showing 25 changed files with 177 additions and 168 deletions.
7 changes: 1 addition & 6 deletions compiler/rustc_mir_build/src/thir/pattern/check_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -829,12 +829,7 @@ fn report_non_exhaustive_match<'p, 'tcx>(
if let Some(AdtDefinedHere { adt_def_span, ty, variants }) =
report_adt_defined_here(cx.tcx, scrut_ty, &witnesses, true)
{
let mut multi_span = if variants.is_empty() {
MultiSpan::from_span(adt_def_span)
} else {
MultiSpan::from_spans(variants.iter().map(|Variant { span }| *span).collect())
};

let mut multi_span = MultiSpan::from_span(adt_def_span);
multi_span.push_span_label(adt_def_span, "");
for Variant { span } in variants {
multi_span.push_span_label(span, "not covered");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ LL | let _b = || { match l1 { L1::A => () } };
| ^^ pattern `L1::B` not covered
|
note: `L1` defined here
--> $DIR/non-exhaustive-match.rs:12:14
--> $DIR/non-exhaustive-match.rs:12:6
|
LL | enum L1 { A, B }
| -- ^ not covered
| ^^ - not covered
= note: the matched value is of type `L1`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/error-codes/E0004.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ LL | match x {
| ^ pattern `Terminator::HastaLaVistaBaby` not covered
|
note: `Terminator` defined here
--> $DIR/E0004.rs:2:5
--> $DIR/E0004.rs:1:6
|
LL | enum Terminator {
| ----------
| ^^^^^^^^^^
LL | HastaLaVistaBaby,
| ^^^^^^^^^^^^^^^^ not covered
| ---------------- not covered
= note: the matched value is of type `Terminator`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ LL | match Foo::A {
| ^^^^^^ pattern `Foo::C` not covered
|
note: `Foo` defined here
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:16:9
--> $DIR/feature-gate-non_exhaustive_omitted_patterns_lint.rs:13:10
|
LL | enum Foo {
| ---
| ^^^
...
LL | C,
| ^ not covered
| - not covered
= note: the matched value is of type `Foo`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/match/match_non_exhaustive.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ LL | match l { L::A => () };
| ^ pattern `L::B` not covered
|
note: `L` defined here
--> $DIR/match_non_exhaustive.rs:10:13
--> $DIR/match_non_exhaustive.rs:10:6
|
LL | enum L { A, B }
| - ^ not covered
| ^ - not covered
= note: the matched value is of type `L`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/pattern/issue-94866.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ LL | match Enum::A {
| ^^^^^^^ pattern `Enum::B` not covered
|
note: `Enum` defined here
--> $DIR/issue-94866.rs:7:16
--> $DIR/issue-94866.rs:7:6
|
LL | enum Enum { A, B }
| ---- ^ not covered
| ^^^^ - not covered
= note: the matched value is of type `Enum`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
Expand Down
18 changes: 9 additions & 9 deletions tests/ui/pattern/usefulness/doc-hidden-non-exhaustive.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ LL | match HiddenEnum::A {
| ^^^^^^^^^^^^^ pattern `HiddenEnum::B` not covered
|
note: `HiddenEnum` defined here
--> $DIR/auxiliary/hidden.rs:3:5
--> $DIR/auxiliary/hidden.rs:1:1
|
LL | pub enum HiddenEnum {
| -------------------
| ^^^^^^^^^^^^^^^^^^^
LL | A,
LL | B,
| ^ not covered
| - not covered
= note: the matched value is of type `HiddenEnum`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
Expand All @@ -44,13 +44,13 @@ LL | match HiddenEnum::A {
| ^^^^^^^^^^^^^ patterns `HiddenEnum::B` and `_` not covered
|
note: `HiddenEnum` defined here
--> $DIR/auxiliary/hidden.rs:3:5
--> $DIR/auxiliary/hidden.rs:1:1
|
LL | pub enum HiddenEnum {
| -------------------
| ^^^^^^^^^^^^^^^^^^^
LL | A,
LL | B,
| ^ not covered
| - not covered
= note: the matched value is of type `HiddenEnum`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
|
Expand Down Expand Up @@ -83,13 +83,13 @@ LL | match InCrate::A {
| ^^^^^^^^^^ pattern `InCrate::C` not covered
|
note: `InCrate` defined here
--> $DIR/doc-hidden-non-exhaustive.rs:11:5
--> $DIR/doc-hidden-non-exhaustive.rs:7:6
|
LL | enum InCrate {
| -------
| ^^^^^^^
...
LL | C,
| ^ not covered
| - not covered
= note: the matched value is of type `InCrate`
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
Expand Down
46 changes: 26 additions & 20 deletions tests/ui/pattern/usefulness/empty-match.exhaustive_patterns.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,13 @@ LL | match_no_arms!(NonEmptyEnum1::Foo(true));
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyEnum1::Foo(_)` not covered
|
note: `NonEmptyEnum1` defined here
--> $DIR/empty-match.rs:33:5
--> $DIR/empty-match.rs:32:6
|
LL | enum NonEmptyEnum1 {
| -------------
| ^^^^^^^^^^^^^
...
LL | Foo(bool),
| ^^^ not covered
| --- not covered
= note: the matched value is of type `NonEmptyEnum1`
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern

Expand All @@ -143,15 +144,16 @@ LL | match_no_arms!(NonEmptyEnum2::Foo(true));
| ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
|
note: `NonEmptyEnum2` defined here
--> $DIR/empty-match.rs:40:5
--> $DIR/empty-match.rs:39:6
|
LL | enum NonEmptyEnum2 {
| -------------
| ^^^^^^^^^^^^^
...
LL | Foo(bool),
| ^^^ not covered
| --- not covered
...
LL | Bar,
| ^^^ not covered
| --- not covered
= note: the matched value is of type `NonEmptyEnum2`
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or multiple match arms

Expand All @@ -162,12 +164,13 @@ LL | match_no_arms!(NonEmptyEnum5::V1);
| ^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
|
note: `NonEmptyEnum5` defined here
--> $DIR/empty-match.rs:50:5
--> $DIR/empty-match.rs:49:6
|
LL | enum NonEmptyEnum5 {
| -------------
| ^^^^^^^^^^^^^
...
LL | V1, V2, V3, V4, V5,
| ^^ ^^ ^^ ^^ ^^ not covered
| -- -- -- -- -- not covered
| | | | |
| | | | not covered
| | | not covered
Expand Down Expand Up @@ -273,12 +276,13 @@ LL | match_guarded_arm!(NonEmptyEnum1::Foo(true));
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyEnum1::Foo(_)` not covered
|
note: `NonEmptyEnum1` defined here
--> $DIR/empty-match.rs:33:5
--> $DIR/empty-match.rs:32:6
|
LL | enum NonEmptyEnum1 {
| -------------
| ^^^^^^^^^^^^^
...
LL | Foo(bool),
| ^^^ not covered
| --- not covered
= note: the matched value is of type `NonEmptyEnum1`
= note: match arms with guards don't count towards exhaustivity
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
Expand All @@ -294,15 +298,16 @@ LL | match_guarded_arm!(NonEmptyEnum2::Foo(true));
| ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
|
note: `NonEmptyEnum2` defined here
--> $DIR/empty-match.rs:40:5
--> $DIR/empty-match.rs:39:6
|
LL | enum NonEmptyEnum2 {
| -------------
| ^^^^^^^^^^^^^
...
LL | Foo(bool),
| ^^^ not covered
| --- not covered
...
LL | Bar,
| ^^^ not covered
| --- not covered
= note: the matched value is of type `NonEmptyEnum2`
= note: match arms with guards don't count towards exhaustivity
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
Expand All @@ -318,12 +323,13 @@ LL | match_guarded_arm!(NonEmptyEnum5::V1);
| ^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
|
note: `NonEmptyEnum5` defined here
--> $DIR/empty-match.rs:50:5
--> $DIR/empty-match.rs:49:6
|
LL | enum NonEmptyEnum5 {
| -------------
| ^^^^^^^^^^^^^
...
LL | V1, V2, V3, V4, V5,
| ^^ ^^ ^^ ^^ ^^ not covered
| -- -- -- -- -- not covered
| | | | |
| | | | not covered
| | | not covered
Expand Down
46 changes: 26 additions & 20 deletions tests/ui/pattern/usefulness/empty-match.normal.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,13 @@ LL | match_no_arms!(NonEmptyEnum1::Foo(true));
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyEnum1::Foo(_)` not covered
|
note: `NonEmptyEnum1` defined here
--> $DIR/empty-match.rs:33:5
--> $DIR/empty-match.rs:32:6
|
LL | enum NonEmptyEnum1 {
| -------------
| ^^^^^^^^^^^^^
...
LL | Foo(bool),
| ^^^ not covered
| --- not covered
= note: the matched value is of type `NonEmptyEnum1`
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern

Expand All @@ -142,15 +143,16 @@ LL | match_no_arms!(NonEmptyEnum2::Foo(true));
| ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
|
note: `NonEmptyEnum2` defined here
--> $DIR/empty-match.rs:40:5
--> $DIR/empty-match.rs:39:6
|
LL | enum NonEmptyEnum2 {
| -------------
| ^^^^^^^^^^^^^
...
LL | Foo(bool),
| ^^^ not covered
| --- not covered
...
LL | Bar,
| ^^^ not covered
| --- not covered
= note: the matched value is of type `NonEmptyEnum2`
= help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or multiple match arms

Expand All @@ -161,12 +163,13 @@ LL | match_no_arms!(NonEmptyEnum5::V1);
| ^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
|
note: `NonEmptyEnum5` defined here
--> $DIR/empty-match.rs:50:5
--> $DIR/empty-match.rs:49:6
|
LL | enum NonEmptyEnum5 {
| -------------
| ^^^^^^^^^^^^^
...
LL | V1, V2, V3, V4, V5,
| ^^ ^^ ^^ ^^ ^^ not covered
| -- -- -- -- -- not covered
| | | | |
| | | | not covered
| | | not covered
Expand Down Expand Up @@ -272,12 +275,13 @@ LL | match_guarded_arm!(NonEmptyEnum1::Foo(true));
| ^^^^^^^^^^^^^^^^^^^^^^^^ pattern `NonEmptyEnum1::Foo(_)` not covered
|
note: `NonEmptyEnum1` defined here
--> $DIR/empty-match.rs:33:5
--> $DIR/empty-match.rs:32:6
|
LL | enum NonEmptyEnum1 {
| -------------
| ^^^^^^^^^^^^^
...
LL | Foo(bool),
| ^^^ not covered
| --- not covered
= note: the matched value is of type `NonEmptyEnum1`
= note: match arms with guards don't count towards exhaustivity
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
Expand All @@ -293,15 +297,16 @@ LL | match_guarded_arm!(NonEmptyEnum2::Foo(true));
| ^^^^^^^^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum2::Foo(_)` and `NonEmptyEnum2::Bar` not covered
|
note: `NonEmptyEnum2` defined here
--> $DIR/empty-match.rs:40:5
--> $DIR/empty-match.rs:39:6
|
LL | enum NonEmptyEnum2 {
| -------------
| ^^^^^^^^^^^^^
...
LL | Foo(bool),
| ^^^ not covered
| --- not covered
...
LL | Bar,
| ^^^ not covered
| --- not covered
= note: the matched value is of type `NonEmptyEnum2`
= note: match arms with guards don't count towards exhaustivity
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern, a match arm with multiple or-patterns as shown, or multiple match arms
Expand All @@ -317,12 +322,13 @@ LL | match_guarded_arm!(NonEmptyEnum5::V1);
| ^^^^^^^^^^^^^^^^^ patterns `NonEmptyEnum5::V1`, `NonEmptyEnum5::V2`, `NonEmptyEnum5::V3` and 2 more not covered
|
note: `NonEmptyEnum5` defined here
--> $DIR/empty-match.rs:50:5
--> $DIR/empty-match.rs:49:6
|
LL | enum NonEmptyEnum5 {
| -------------
| ^^^^^^^^^^^^^
...
LL | V1, V2, V3, V4, V5,
| ^^ ^^ ^^ ^^ ^^ not covered
| -- -- -- -- -- not covered
| | | | |
| | | | not covered
| | | not covered
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/pattern/usefulness/empty-match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,27 @@ union NonEmptyUnion2 {
bar: (),
}
enum NonEmptyEnum1 {
Foo(bool),
//~^ NOTE `NonEmptyEnum1` defined here
//~| NOTE `NonEmptyEnum1` defined here
//~| NOTE not covered
Foo(bool),
//~^ NOTE not covered
//~| NOTE not covered
}
enum NonEmptyEnum2 {
Foo(bool),
//~^ NOTE `NonEmptyEnum2` defined here
//~| NOTE `NonEmptyEnum2` defined here
//~| NOTE not covered
Foo(bool),
//~^ NOTE not covered
//~| NOTE not covered
Bar,
//~^ NOTE not covered
//~| NOTE not covered
}
enum NonEmptyEnum5 {
V1, V2, V3, V4, V5,
//~^ NOTE `NonEmptyEnum5` defined here
//~| NOTE `NonEmptyEnum5` defined here
//~| NOTE not covered
V1, V2, V3, V4, V5,
//~^ NOTE not covered
//~| NOTE not covered
//~| NOTE not covered
//~| NOTE not covered
Expand Down
Loading

0 comments on commit c96611e

Please sign in to comment.