Skip to content

Commit c0f0008

Browse files
committed
Tweak ptr in pattern error
Conform to error style guide.
1 parent cc492ed commit c0f0008

File tree

8 files changed

+109
-54
lines changed

8 files changed

+109
-54
lines changed

compiler/rustc_mir_build/messages.ftl

+3-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,9 @@ mir_build_non_partial_eq_match =
274274
mir_build_pattern_not_covered = refutable pattern in {$origin}
275275
.pattern_ty = the matched value is of type `{$pattern_ty}`
276276
277-
mir_build_pointer_pattern = function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
277+
mir_build_pointer_pattern = function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon
278+
.label = can't be used in patterns
279+
.note = see https://github.com/rust-lang/rust/issues/70861 for details
278280
279281
mir_build_privately_uninhabited = pattern `{$witness_1}` is currently uninhabited, but this variant contains private fields which may become inhabited in the future
280282

compiler/rustc_mir_build/src/errors.rs

+2
Original file line numberDiff line numberDiff line change
@@ -916,8 +916,10 @@ pub(crate) struct NaNPattern {
916916

917917
#[derive(Diagnostic)]
918918
#[diag(mir_build_pointer_pattern)]
919+
#[note]
919920
pub(crate) struct PointerPattern {
920921
#[primary_span]
922+
#[label]
921923
pub(crate) span: Span,
922924
}
923925

src/tools/tidy/src/fluent_period.rs

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const ALLOWLIST: &[&str] = &[
1818
"const_eval_validation_failure_note",
1919
"driver_impl_ice",
2020
"incremental_corrupt_file",
21-
"mir_build_pointer_pattern",
2221
];
2322

2423
fn check_period(filename: &str, contents: &str, bad: &mut bool) {
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,46 @@
1-
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
1+
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon
22
--> $DIR/issue-34784-match-on-non-int-raw-ptr.rs:9:9
33
|
44
LL | const C: *const u8 = &0;
55
| ------------------ constant defined here
66
...
77
LL | C => {}
8-
| ^
8+
| ^ can't be used in patterns
9+
|
10+
= note: see https://github.com/rust-lang/rust/issues/70861 for details
911

10-
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
12+
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon
1113
--> $DIR/issue-34784-match-on-non-int-raw-ptr.rs:16:9
1214
|
1315
LL | const C_INNER: (*const u8, u8) = (C, 0);
1416
| ------------------------------ constant defined here
1517
...
1618
LL | C_INNER => {}
17-
| ^^^^^^^
19+
| ^^^^^^^ can't be used in patterns
20+
|
21+
= note: see https://github.com/rust-lang/rust/issues/70861 for details
1822

19-
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
23+
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon
2024
--> $DIR/issue-34784-match-on-non-int-raw-ptr.rs:27:9
2125
|
2226
LL | const D: *const [u8; 4] = b"abcd";
2327
| ----------------------- constant defined here
2428
...
2529
LL | D => {}
26-
| ^
30+
| ^ can't be used in patterns
31+
|
32+
= note: see https://github.com/rust-lang/rust/issues/70861 for details
2733

28-
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
34+
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon
2935
--> $DIR/issue-34784-match-on-non-int-raw-ptr.rs:32:9
3036
|
3137
LL | const STR: *const str = "abcd";
3238
| --------------------- constant defined here
3339
...
3440
LL | STR => {}
35-
| ^^^
41+
| ^^^ can't be used in patterns
42+
|
43+
= note: see https://github.com/rust-lang/rust/issues/70861 for details
3644

3745
error: aborting due to 4 previous errors
3846

Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
1+
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon
22
--> $DIR/issue-44333.rs:15:9
33
|
44
LL | const FOO: Func = foo;
55
| --------------- constant defined here
66
...
77
LL | FOO => println!("foo"),
8-
| ^^^
8+
| ^^^ can't be used in patterns
9+
|
10+
= note: see https://github.com/rust-lang/rust/issues/70861 for details
911

10-
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
12+
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon
1113
--> $DIR/issue-44333.rs:16:9
1214
|
1315
LL | const BAR: Func = bar;
1416
| --------------- constant defined here
1517
...
1618
LL | BAR => println!("bar"),
17-
| ^^^
19+
| ^^^ can't be used in patterns
20+
|
21+
= note: see https://github.com/rust-lang/rust/issues/70861 for details
1822

1923
error: aborting due to 2 previous errors
2024

tests/ui/pattern/usefulness/consts-opaque.stderr

+32-16
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,90 @@
1-
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
1+
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon
22
--> $DIR/consts-opaque.rs:96:9
33
|
44
LL | const QUUX: Quux = quux;
55
| ---------------- constant defined here
66
...
77
LL | QUUX => {}
8-
| ^^^^
8+
| ^^^^ can't be used in patterns
9+
|
10+
= note: see https://github.com/rust-lang/rust/issues/70861 for details
911

10-
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
12+
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon
1113
--> $DIR/consts-opaque.rs:97:9
1214
|
1315
LL | const QUUX: Quux = quux;
1416
| ---------------- constant defined here
1517
...
1618
LL | QUUX => {}
17-
| ^^^^
19+
| ^^^^ can't be used in patterns
20+
|
21+
= note: see https://github.com/rust-lang/rust/issues/70861 for details
1822

19-
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
23+
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon
2024
--> $DIR/consts-opaque.rs:106:9
2125
|
2226
LL | const WRAPQUUX: Wrap<Quux> = Wrap(quux);
2327
| -------------------------- constant defined here
2428
...
2529
LL | WRAPQUUX => {}
26-
| ^^^^^^^^
30+
| ^^^^^^^^ can't be used in patterns
31+
|
32+
= note: see https://github.com/rust-lang/rust/issues/70861 for details
2733

28-
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
34+
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon
2935
--> $DIR/consts-opaque.rs:107:9
3036
|
3137
LL | const WRAPQUUX: Wrap<Quux> = Wrap(quux);
3238
| -------------------------- constant defined here
3339
...
3440
LL | WRAPQUUX => {}
35-
| ^^^^^^^^
41+
| ^^^^^^^^ can't be used in patterns
42+
|
43+
= note: see https://github.com/rust-lang/rust/issues/70861 for details
3644

37-
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
45+
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon
3846
--> $DIR/consts-opaque.rs:113:9
3947
|
4048
LL | const WRAPQUUX: Wrap<Quux> = Wrap(quux);
4149
| -------------------------- constant defined here
4250
...
4351
LL | WRAPQUUX => {}
44-
| ^^^^^^^^
52+
| ^^^^^^^^ can't be used in patterns
53+
|
54+
= note: see https://github.com/rust-lang/rust/issues/70861 for details
4555

46-
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
56+
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon
4757
--> $DIR/consts-opaque.rs:121:9
4858
|
4959
LL | const WRAPQUUX: Wrap<Quux> = Wrap(quux);
5060
| -------------------------- constant defined here
5161
...
5262
LL | WRAPQUUX => {}
53-
| ^^^^^^^^
63+
| ^^^^^^^^ can't be used in patterns
64+
|
65+
= note: see https://github.com/rust-lang/rust/issues/70861 for details
5466

55-
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
67+
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon
5668
--> $DIR/consts-opaque.rs:132:9
5769
|
5870
LL | const WHOKNOWSQUUX: WhoKnows<Quux> = WhoKnows::Yay(quux);
5971
| ---------------------------------- constant defined here
6072
...
6173
LL | WHOKNOWSQUUX => {}
62-
| ^^^^^^^^^^^^
74+
| ^^^^^^^^^^^^ can't be used in patterns
75+
|
76+
= note: see https://github.com/rust-lang/rust/issues/70861 for details
6377

64-
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
78+
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon
6579
--> $DIR/consts-opaque.rs:134:9
6680
|
6781
LL | const WHOKNOWSQUUX: WhoKnows<Quux> = WhoKnows::Yay(quux);
6882
| ---------------------------------- constant defined here
6983
...
7084
LL | WHOKNOWSQUUX => {}
71-
| ^^^^^^^^^^^^
85+
| ^^^^^^^^^^^^ can't be used in patterns
86+
|
87+
= note: see https://github.com/rust-lang/rust/issues/70861 for details
7288

7389
error: unreachable pattern
7490
--> $DIR/consts-opaque.rs:48:9
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,112 @@
1-
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
1+
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon
22
--> $DIR/fn-ptr-is-not-structurally-matchable.rs:41:14
33
|
44
LL | const CFN1: Wrap<fn()> = Wrap(trivial);
55
| ---------------------- constant defined here
66
...
77
LL | Wrap(CFN1) => count += 1,
8-
| ^^^^
8+
| ^^^^ can't be used in patterns
9+
|
10+
= note: see https://github.com/rust-lang/rust/issues/70861 for details
911

10-
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
12+
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon
1113
--> $DIR/fn-ptr-is-not-structurally-matchable.rs:49:14
1214
|
1315
LL | const CFN2: Wrap<fn(SM)> = Wrap(sm_to);
1416
| ------------------------ constant defined here
1517
...
1618
LL | Wrap(CFN2) => count += 1,
17-
| ^^^^
19+
| ^^^^ can't be used in patterns
20+
|
21+
= note: see https://github.com/rust-lang/rust/issues/70861 for details
1822

19-
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
23+
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon
2024
--> $DIR/fn-ptr-is-not-structurally-matchable.rs:57:14
2125
|
2226
LL | const CFN3: Wrap<fn() -> SM> = Wrap(to_sm);
2327
| ---------------------------- constant defined here
2428
...
2529
LL | Wrap(CFN3) => count += 1,
26-
| ^^^^
30+
| ^^^^ can't be used in patterns
31+
|
32+
= note: see https://github.com/rust-lang/rust/issues/70861 for details
2733

28-
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
34+
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon
2935
--> $DIR/fn-ptr-is-not-structurally-matchable.rs:65:14
3036
|
3137
LL | const CFN4: Wrap<fn(NotSM)> = Wrap(not_sm_to);
3238
| --------------------------- constant defined here
3339
...
3440
LL | Wrap(CFN4) => count += 1,
35-
| ^^^^
41+
| ^^^^ can't be used in patterns
42+
|
43+
= note: see https://github.com/rust-lang/rust/issues/70861 for details
3644

37-
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
45+
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon
3846
--> $DIR/fn-ptr-is-not-structurally-matchable.rs:73:14
3947
|
4048
LL | const CFN5: Wrap<fn() -> NotSM> = Wrap(to_not_sm);
4149
| ------------------------------- constant defined here
4250
...
4351
LL | Wrap(CFN5) => count += 1,
44-
| ^^^^
52+
| ^^^^ can't be used in patterns
53+
|
54+
= note: see https://github.com/rust-lang/rust/issues/70861 for details
4555

46-
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
56+
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon
4757
--> $DIR/fn-ptr-is-not-structurally-matchable.rs:81:14
4858
|
4959
LL | const CFN6: Wrap<fn(&SM)> = Wrap(r_sm_to);
5060
| ------------------------- constant defined here
5161
...
5262
LL | Wrap(CFN6) => count += 1,
53-
| ^^^^
63+
| ^^^^ can't be used in patterns
64+
|
65+
= note: see https://github.com/rust-lang/rust/issues/70861 for details
5466

55-
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
67+
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon
5668
--> $DIR/fn-ptr-is-not-structurally-matchable.rs:89:14
5769
|
5870
LL | const CFN7: Wrap<fn(&()) -> &SM> = Wrap(r_to_r_sm);
5971
| -------------------------------- constant defined here
6072
...
6173
LL | Wrap(CFN7) => count += 1,
62-
| ^^^^
74+
| ^^^^ can't be used in patterns
75+
|
76+
= note: see https://github.com/rust-lang/rust/issues/70861 for details
6377

64-
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
78+
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon
6579
--> $DIR/fn-ptr-is-not-structurally-matchable.rs:97:14
6680
|
6781
LL | const CFN8: Wrap<fn(&NotSM)> = Wrap(r_not_sm_to);
6882
| ---------------------------- constant defined here
6983
...
7084
LL | Wrap(CFN8) => count += 1,
71-
| ^^^^
85+
| ^^^^ can't be used in patterns
86+
|
87+
= note: see https://github.com/rust-lang/rust/issues/70861 for details
7288

73-
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
89+
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon
7490
--> $DIR/fn-ptr-is-not-structurally-matchable.rs:105:14
7591
|
7692
LL | const CFN9: Wrap<fn(&()) -> &NotSM> = Wrap(r_to_r_not_sm);
7793
| ----------------------------------- constant defined here
7894
...
7995
LL | Wrap(CFN9) => count += 1,
80-
| ^^^^
96+
| ^^^^ can't be used in patterns
97+
|
98+
= note: see https://github.com/rust-lang/rust/issues/70861 for details
8199

82-
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
100+
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon
83101
--> $DIR/fn-ptr-is-not-structurally-matchable.rs:127:9
84102
|
85103
LL | const CFOO: Foo = Foo {
86104
| --------------- constant defined here
87105
...
88106
LL | CFOO => count += 1,
89-
| ^^^^
107+
| ^^^^ can't be used in patterns
108+
|
109+
= note: see https://github.com/rust-lang/rust/issues/70861 for details
90110

91111
error: aborting due to 10 previous errors
92112

Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
1+
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon
22
--> $DIR/issue-63479-match-fnptr.rs:32:7
33
|
44
LL | const TEST: Fn = my_fn;
55
| -------------- constant defined here
66
...
77
LL | B(TEST) => println!("matched"),
8-
| ^^^^
8+
| ^^^^ can't be used in patterns
9+
|
10+
= note: see https://github.com/rust-lang/rust/issues/70861 for details
911

10-
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon. See https://github.com/rust-lang/rust/issues/70861 for details.
12+
error: function pointers and raw pointers not derived from integers in patterns behave unpredictably and should not be relied upon
1113
--> $DIR/issue-63479-match-fnptr.rs:37:5
1214
|
1315
LL | const TEST2: (Fn, u8) = (TEST, 0);
1416
| --------------------- constant defined here
1517
...
1618
LL | TEST2 => println!("matched"),
17-
| ^^^^^
19+
| ^^^^^ can't be used in patterns
20+
|
21+
= note: see https://github.com/rust-lang/rust/issues/70861 for details
1822

1923
error: aborting due to 2 previous errors
2024

0 commit comments

Comments
 (0)