Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cbd682b

Browse files
committedMay 3, 2024·
turn pointer_structural_match into a hard error
1 parent 179a6a0 commit cbd682b

23 files changed

+131
-811
lines changed
 

‎compiler/rustc_lint/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,11 @@ fn register_builtins(store: &mut LintStore) {
544544
"converted into hard error, see RFC #3535 \
545545
<https://rust-lang.github.io/rfcs/3535-constants-in-patterns.html> for more information",
546546
);
547+
store.register_removed(
548+
"pointer_structural_match",
549+
"converted into hard error, see RFC #3535 \
550+
<https://rust-lang.github.io/rfcs/3535-constants-in-patterns.html> for more information",
551+
);
547552
}
548553

549554
fn register_internals(store: &mut LintStore) {

‎compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ declare_lint_pass! {
7474
ORDER_DEPENDENT_TRAIT_OBJECTS,
7575
OVERLAPPING_RANGE_ENDPOINTS,
7676
PATTERNS_IN_FNS_WITHOUT_BODY,
77-
POINTER_STRUCTURAL_MATCH,
7877
PRIVATE_BOUNDS,
7978
PRIVATE_INTERFACES,
8079
PROC_MACRO_BACK_COMPAT,
@@ -2371,45 +2370,6 @@ declare_lint! {
23712370
report_in_external_macro
23722371
}
23732372

2374-
declare_lint! {
2375-
/// The `pointer_structural_match` lint detects pointers used in patterns whose behaviour
2376-
/// cannot be relied upon across compiler versions and optimization levels.
2377-
///
2378-
/// ### Example
2379-
///
2380-
/// ```rust,compile_fail
2381-
/// #![deny(pointer_structural_match)]
2382-
/// fn foo(a: usize, b: usize) -> usize { a + b }
2383-
/// const FOO: fn(usize, usize) -> usize = foo;
2384-
/// fn main() {
2385-
/// match FOO {
2386-
/// FOO => {},
2387-
/// _ => {},
2388-
/// }
2389-
/// }
2390-
/// ```
2391-
///
2392-
/// {{produces}}
2393-
///
2394-
/// ### Explanation
2395-
///
2396-
/// Previous versions of Rust allowed function pointers and all raw pointers in patterns.
2397-
/// While these work in many cases as expected by users, it is possible that due to
2398-
/// optimizations pointers are "not equal to themselves" or pointers to different functions
2399-
/// compare as equal during runtime. This is because LLVM optimizations can deduplicate
2400-
/// functions if their bodies are the same, thus also making pointers to these functions point
2401-
/// to the same location. Additionally functions may get duplicated if they are instantiated
2402-
/// in different crates and not deduplicated again via LTO. Pointer identity for memory
2403-
/// created by `const` is similarly unreliable.
2404-
pub POINTER_STRUCTURAL_MATCH,
2405-
Warn,
2406-
"pointers are not structural-match",
2407-
@future_incompatible = FutureIncompatibleInfo {
2408-
reason: FutureIncompatibilityReason::FutureReleaseErrorReportInDeps,
2409-
reference: "issue #120362 <https://github.com/rust-lang/rust/issues/120362>",
2410-
};
2411-
}
2412-
24132373
declare_lint! {
24142374
/// The `ambiguous_associated_items` lint detects ambiguity between
24152375
/// [associated items] and [enum variants].

‎compiler/rustc_mir_build/src/errors.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -788,9 +788,12 @@ pub struct NaNPattern {
788788
pub span: Span,
789789
}
790790

791-
#[derive(LintDiagnostic)]
791+
#[derive(Diagnostic)]
792792
#[diag(mir_build_pointer_pattern)]
793-
pub struct PointerPattern;
793+
pub struct PointerPattern {
794+
#[primary_span]
795+
pub span: Span,
796+
}
794797

795798
#[derive(Diagnostic)]
796799
#[diag(mir_build_non_empty_never_pattern)]

‎compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use rustc_infer::traits::Obligation;
66
use rustc_middle::mir;
77
use rustc_middle::thir::{FieldPat, Pat, PatKind};
88
use rustc_middle::ty::{self, Ty, TyCtxt, ValTree};
9-
use rustc_session::lint;
109
use rustc_span::{ErrorGuaranteed, Span};
1110
use rustc_target::abi::{FieldIdx, VariantIdx};
1211
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
@@ -189,12 +188,9 @@ impl<'tcx> ConstToPat<'tcx> {
189188
} else if !have_valtree {
190189
// The only way valtree construction can fail without the structural match
191190
// checker finding a violation is if there is a pointer somewhere.
192-
self.tcx().emit_node_span_lint(
193-
lint::builtin::POINTER_STRUCTURAL_MATCH,
194-
self.id,
195-
self.span,
196-
PointerPattern,
197-
);
191+
let e = self.tcx().dcx().emit_err(PointerPattern { span: self.span });
192+
let kind = PatKind::Error(e);
193+
return Box::new(Pat { span: self.span, ty: cv.ty(), kind });
198194
}
199195

200196
// Always check for `PartialEq` if we had no other errors yet.

‎tests/ui/closures/2229_closure_analysis/match/match-edge-cases_1.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
//@ edition:2021
33

44
const PATTERN_REF: &str = "Hello World";
5-
const NUMBER: i32 = 30;
6-
const NUMBER_POINTER: *const i32 = &NUMBER;
5+
const NUMBER_POINTER: *const i32 = 30 as *const i32;
76

87
pub fn edge_case_ref(event: &str) {
98
let _ = || {
@@ -26,8 +25,7 @@ pub fn edge_case_str(event: String) {
2625
pub fn edge_case_raw_ptr(event: *const i32) {
2726
let _ = || {
2827
match event {
29-
NUMBER_POINTER => (), //~WARN behave unpredictably
30-
//~| previously accepted
28+
NUMBER_POINTER => (),
3129
_ => (),
3230
};
3331
};

‎tests/ui/closures/2229_closure_analysis/match/match-edge-cases_1.stderr

Lines changed: 0 additions & 23 deletions
This file was deleted.

‎tests/ui/consts/const_in_pattern/issue-34784-match-on-non-int-raw-ptr.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![deny(pointer_structural_match)]
21
#![allow(dead_code)]
32

43
const C: *const u8 = &0;
@@ -8,15 +7,13 @@ const C_INNER: (*const u8, u8) = (C, 0);
87
fn foo(x: *const u8) {
98
match x {
109
C => {} //~ERROR: behave unpredictably
11-
//~| previously accepted
1210
_ => {}
1311
}
1412
}
1513

1614
fn foo2(x: *const u8) {
1715
match (x, 1) {
1816
C_INNER => {} //~ERROR: behave unpredictably
19-
//~| previously accepted
2017
_ => {}
2118
}
2219
}
@@ -28,13 +25,11 @@ const STR: *const str = "abcd";
2825
fn main() {
2926
match D {
3027
D => {} //~ERROR: behave unpredictably
31-
//~| previously accepted
3228
_ => {}
3329
}
3430

3531
match STR {
3632
STR => {} //~ERROR: behave unpredictably
37-
//~| previously accepted
3833
_ => {}
3934
}
4035
}
Lines changed: 4 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,26 @@
11
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.
2-
--> $DIR/issue-34784-match-on-non-int-raw-ptr.rs:10:9
2+
--> $DIR/issue-34784-match-on-non-int-raw-ptr.rs:9:9
33
|
44
LL | C => {}
55
| ^
6-
|
7-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
9-
note: the lint level is defined here
10-
--> $DIR/issue-34784-match-on-non-int-raw-ptr.rs:1:9
11-
|
12-
LL | #![deny(pointer_structural_match)]
13-
| ^^^^^^^^^^^^^^^^^^^^^^^^
146

157
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.
16-
--> $DIR/issue-34784-match-on-non-int-raw-ptr.rs:18:9
8+
--> $DIR/issue-34784-match-on-non-int-raw-ptr.rs:16:9
179
|
1810
LL | C_INNER => {}
1911
| ^^^^^^^
20-
|
21-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
22-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
2312

2413
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.
25-
--> $DIR/issue-34784-match-on-non-int-raw-ptr.rs:30:9
14+
--> $DIR/issue-34784-match-on-non-int-raw-ptr.rs:27:9
2615
|
2716
LL | D => {}
2817
| ^
29-
|
30-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
31-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
3218

3319
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-
--> $DIR/issue-34784-match-on-non-int-raw-ptr.rs:36:9
20+
--> $DIR/issue-34784-match-on-non-int-raw-ptr.rs:32:9
3521
|
3622
LL | STR => {}
3723
| ^^^
38-
|
39-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
40-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
4124

4225
error: aborting due to 4 previous errors
4326

44-
Future incompatibility report: Future breakage diagnostic:
45-
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.
46-
--> $DIR/issue-34784-match-on-non-int-raw-ptr.rs:10:9
47-
|
48-
LL | C => {}
49-
| ^
50-
|
51-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
52-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
53-
note: the lint level is defined here
54-
--> $DIR/issue-34784-match-on-non-int-raw-ptr.rs:1:9
55-
|
56-
LL | #![deny(pointer_structural_match)]
57-
| ^^^^^^^^^^^^^^^^^^^^^^^^
58-
59-
Future breakage diagnostic:
60-
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.
61-
--> $DIR/issue-34784-match-on-non-int-raw-ptr.rs:18:9
62-
|
63-
LL | C_INNER => {}
64-
| ^^^^^^^
65-
|
66-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
67-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
68-
note: the lint level is defined here
69-
--> $DIR/issue-34784-match-on-non-int-raw-ptr.rs:1:9
70-
|
71-
LL | #![deny(pointer_structural_match)]
72-
| ^^^^^^^^^^^^^^^^^^^^^^^^
73-
74-
Future breakage diagnostic:
75-
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.
76-
--> $DIR/issue-34784-match-on-non-int-raw-ptr.rs:30:9
77-
|
78-
LL | D => {}
79-
| ^
80-
|
81-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
82-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
83-
note: the lint level is defined here
84-
--> $DIR/issue-34784-match-on-non-int-raw-ptr.rs:1:9
85-
|
86-
LL | #![deny(pointer_structural_match)]
87-
| ^^^^^^^^^^^^^^^^^^^^^^^^
88-
89-
Future breakage diagnostic:
90-
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.
91-
--> $DIR/issue-34784-match-on-non-int-raw-ptr.rs:36:9
92-
|
93-
LL | STR => {}
94-
| ^^^
95-
|
96-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
97-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
98-
note: the lint level is defined here
99-
--> $DIR/issue-34784-match-on-non-int-raw-ptr.rs:1:9
100-
|
101-
LL | #![deny(pointer_structural_match)]
102-
| ^^^^^^^^^^^^^^^^^^^^^^^^
103-
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
//@ run-pass
2-
3-
#![warn(pointer_structural_match)]
4-
51
type Func = fn(usize, usize) -> usize;
62

73
fn foo(a: usize, b: usize) -> usize { a + b }
@@ -16,10 +12,8 @@ const BAR: Func = bar;
1612

1713
fn main() {
1814
match test(std::env::consts::ARCH.len()) {
19-
FOO => println!("foo"), //~ WARN behave unpredictably
20-
//~^ WARN will become a hard error
21-
BAR => println!("bar"), //~ WARN behave unpredictably
22-
//~^ WARN will become a hard error
15+
FOO => println!("foo"), //~ ERROR behave unpredictably
16+
BAR => println!("bar"), //~ ERROR behave unpredictably
2317
_ => unreachable!(),
2418
}
2519
}
Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,14 @@
1-
warning: 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.
2-
--> $DIR/issue-44333.rs:19:9
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.
2+
--> $DIR/issue-44333.rs:15:9
33
|
44
LL | FOO => println!("foo"),
55
| ^^^
6-
|
7-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
9-
note: the lint level is defined here
10-
--> $DIR/issue-44333.rs:3:9
11-
|
12-
LL | #![warn(pointer_structural_match)]
13-
| ^^^^^^^^^^^^^^^^^^^^^^^^
146

15-
warning: 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.
16-
--> $DIR/issue-44333.rs:21:9
7+
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.
8+
--> $DIR/issue-44333.rs:16:9
179
|
1810
LL | BAR => println!("bar"),
1911
| ^^^
20-
|
21-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
22-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
23-
24-
warning: 2 warnings emitted
2512

26-
Future incompatibility report: Future breakage diagnostic:
27-
warning: 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.
28-
--> $DIR/issue-44333.rs:19:9
29-
|
30-
LL | FOO => println!("foo"),
31-
| ^^^
32-
|
33-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
34-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
35-
note: the lint level is defined here
36-
--> $DIR/issue-44333.rs:3:9
37-
|
38-
LL | #![warn(pointer_structural_match)]
39-
| ^^^^^^^^^^^^^^^^^^^^^^^^
40-
41-
Future breakage diagnostic:
42-
warning: 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.
43-
--> $DIR/issue-44333.rs:21:9
44-
|
45-
LL | BAR => println!("bar"),
46-
| ^^^
47-
|
48-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
49-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
50-
note: the lint level is defined here
51-
--> $DIR/issue-44333.rs:3:9
52-
|
53-
LL | #![warn(pointer_structural_match)]
54-
| ^^^^^^^^^^^^^^^^^^^^^^^^
13+
error: aborting due to 2 previous errors
5514

‎tests/ui/pattern/usefulness/consts-opaque.rs

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,8 @@ fn main() {
9393
const QUUX: Quux = quux;
9494

9595
match QUUX {
96-
QUUX => {} //~WARN behave unpredictably
97-
//~| previously accepted
98-
QUUX => {} //~WARN behave unpredictably
99-
//~| previously accepted
96+
QUUX => {} //~ERROR behave unpredictably
97+
QUUX => {} //~ERROR behave unpredictably
10098
_ => {}
10199
}
102100

@@ -105,27 +103,22 @@ fn main() {
105103
const WRAPQUUX: Wrap<Quux> = Wrap(quux);
106104

107105
match WRAPQUUX {
108-
WRAPQUUX => {} //~WARN behave unpredictably
109-
//~| previously accepted
110-
WRAPQUUX => {} //~WARN behave unpredictably
111-
//~| previously accepted
106+
WRAPQUUX => {} //~ERROR behave unpredictably
107+
WRAPQUUX => {} //~ERROR behave unpredictably
112108
Wrap(_) => {}
113109
}
114110

115111
match WRAPQUUX {
116112
Wrap(_) => {}
117-
WRAPQUUX => {} //~WARN behave unpredictably
118-
//~| previously accepted
113+
WRAPQUUX => {} //~ERROR behave unpredictably
119114
}
120115

121116
match WRAPQUUX {
122117
Wrap(_) => {}
123118
}
124119

125120
match WRAPQUUX {
126-
//~^ ERROR: non-exhaustive patterns: `Wrap(_)` not covered
127-
WRAPQUUX => {} //~WARN behave unpredictably
128-
//~| previously accepted
121+
WRAPQUUX => {} //~ERROR behave unpredictably
129122
}
130123

131124
#[derive(PartialEq, Eq)]
@@ -136,11 +129,9 @@ fn main() {
136129
const WHOKNOWSQUUX: WhoKnows<Quux> = WhoKnows::Yay(quux);
137130

138131
match WHOKNOWSQUUX {
139-
WHOKNOWSQUUX => {} //~WARN behave unpredictably
140-
//~| previously accepted
132+
WHOKNOWSQUUX => {} //~ERROR behave unpredictably
141133
WhoKnows::Yay(_) => {}
142-
WHOKNOWSQUUX => {} //~WARN behave unpredictably
143-
//~| previously accepted
134+
WHOKNOWSQUUX => {} //~ERROR behave unpredictably
144135
WhoKnows::Nope => {}
145136
}
146137
}
Lines changed: 16 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,50 @@
1-
warning: 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. See https://github.com/rust-lang/rust/issues/70861 for details.
22
--> $DIR/consts-opaque.rs:96:9
33
|
44
LL | QUUX => {}
55
| ^^^^
6-
|
7-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
9-
= note: `#[warn(pointer_structural_match)]` on by default
106

11-
warning: 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-
--> $DIR/consts-opaque.rs:98:9
7+
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.
8+
--> $DIR/consts-opaque.rs:97:9
139
|
1410
LL | QUUX => {}
1511
| ^^^^
16-
|
17-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
18-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
1912

20-
warning: 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.
21-
--> $DIR/consts-opaque.rs:108:9
13+
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.
14+
--> $DIR/consts-opaque.rs:106:9
2215
|
2316
LL | WRAPQUUX => {}
2417
| ^^^^^^^^
25-
|
26-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
27-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
2818

29-
warning: 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.
30-
--> $DIR/consts-opaque.rs:110:9
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.
20+
--> $DIR/consts-opaque.rs:107:9
3121
|
3222
LL | WRAPQUUX => {}
3323
| ^^^^^^^^
34-
|
35-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
36-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
3724

38-
warning: 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.
39-
--> $DIR/consts-opaque.rs:117:9
25+
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.
26+
--> $DIR/consts-opaque.rs:113:9
4027
|
4128
LL | WRAPQUUX => {}
4229
| ^^^^^^^^
43-
|
44-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
45-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
4630

47-
warning: 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.
48-
--> $DIR/consts-opaque.rs:127:9
31+
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.
32+
--> $DIR/consts-opaque.rs:121:9
4933
|
5034
LL | WRAPQUUX => {}
5135
| ^^^^^^^^
52-
|
53-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
54-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
5536

56-
warning: 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.
57-
--> $DIR/consts-opaque.rs:139:9
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.
38+
--> $DIR/consts-opaque.rs:132:9
5839
|
5940
LL | WHOKNOWSQUUX => {}
6041
| ^^^^^^^^^^^^
61-
|
62-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
63-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
6442

65-
warning: 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.
66-
--> $DIR/consts-opaque.rs:142:9
43+
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.
44+
--> $DIR/consts-opaque.rs:134:9
6745
|
6846
LL | WHOKNOWSQUUX => {}
6947
| ^^^^^^^^^^^^
70-
|
71-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
72-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
7348

7449
error: unreachable pattern
7550
--> $DIR/consts-opaque.rs:48:9
@@ -146,111 +121,5 @@ error: unreachable pattern
146121
LL | _ => {} // should not be emitting unreachable warning
147122
| ^
148123

149-
error[E0004]: non-exhaustive patterns: `Wrap(_)` not covered
150-
--> $DIR/consts-opaque.rs:125:11
151-
|
152-
LL | match WRAPQUUX {
153-
| ^^^^^^^^ pattern `Wrap(_)` not covered
154-
|
155-
note: `Wrap<fn(usize, usize) -> usize>` defined here
156-
--> $DIR/consts-opaque.rs:104:12
157-
|
158-
LL | struct Wrap<T>(T);
159-
| ^^^^
160-
= note: the matched value is of type `Wrap<fn(usize, usize) -> usize>`
161-
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
162-
|
163-
LL | WRAPQUUX => {}, Wrap(_) => todo!()
164-
| ++++++++++++++++++++
165-
166-
error: aborting due to 10 previous errors; 8 warnings emitted
167-
168-
For more information about this error, try `rustc --explain E0004`.
169-
Future incompatibility report: Future breakage diagnostic:
170-
warning: 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.
171-
--> $DIR/consts-opaque.rs:96:9
172-
|
173-
LL | QUUX => {}
174-
| ^^^^
175-
|
176-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
177-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
178-
= note: `#[warn(pointer_structural_match)]` on by default
179-
180-
Future breakage diagnostic:
181-
warning: 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.
182-
--> $DIR/consts-opaque.rs:98:9
183-
|
184-
LL | QUUX => {}
185-
| ^^^^
186-
|
187-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
188-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
189-
= note: `#[warn(pointer_structural_match)]` on by default
190-
191-
Future breakage diagnostic:
192-
warning: 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.
193-
--> $DIR/consts-opaque.rs:108:9
194-
|
195-
LL | WRAPQUUX => {}
196-
| ^^^^^^^^
197-
|
198-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
199-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
200-
= note: `#[warn(pointer_structural_match)]` on by default
201-
202-
Future breakage diagnostic:
203-
warning: 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.
204-
--> $DIR/consts-opaque.rs:110:9
205-
|
206-
LL | WRAPQUUX => {}
207-
| ^^^^^^^^
208-
|
209-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
210-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
211-
= note: `#[warn(pointer_structural_match)]` on by default
212-
213-
Future breakage diagnostic:
214-
warning: 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.
215-
--> $DIR/consts-opaque.rs:117:9
216-
|
217-
LL | WRAPQUUX => {}
218-
| ^^^^^^^^
219-
|
220-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
221-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
222-
= note: `#[warn(pointer_structural_match)]` on by default
223-
224-
Future breakage diagnostic:
225-
warning: 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.
226-
--> $DIR/consts-opaque.rs:127:9
227-
|
228-
LL | WRAPQUUX => {}
229-
| ^^^^^^^^
230-
|
231-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
232-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
233-
= note: `#[warn(pointer_structural_match)]` on by default
234-
235-
Future breakage diagnostic:
236-
warning: 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.
237-
--> $DIR/consts-opaque.rs:139:9
238-
|
239-
LL | WHOKNOWSQUUX => {}
240-
| ^^^^^^^^^^^^
241-
|
242-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
243-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
244-
= note: `#[warn(pointer_structural_match)]` on by default
245-
246-
Future breakage diagnostic:
247-
warning: 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.
248-
--> $DIR/consts-opaque.rs:142:9
249-
|
250-
LL | WHOKNOWSQUUX => {}
251-
| ^^^^^^^^^^^^
252-
|
253-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
254-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
255-
= note: `#[warn(pointer_structural_match)]` on by default
124+
error: aborting due to 17 previous errors
256125

‎tests/ui/raw-ref-op/const-eval-compare-ice-105047.rs

Lines changed: 0 additions & 15 deletions
This file was deleted.

‎tests/ui/raw-ref-op/const-eval-compare-ice-105047.stderr

Lines changed: 0 additions & 31 deletions
This file was deleted.

‎tests/ui/rfcs/rfc-1445-restrict-constants-in-patterns/allow-hide-behind-direct-unsafe-ptr-embedded.rs

Lines changed: 0 additions & 26 deletions
This file was deleted.

‎tests/ui/rfcs/rfc-1445-restrict-constants-in-patterns/allow-hide-behind-direct-unsafe-ptr-param.rs

Lines changed: 0 additions & 26 deletions
This file was deleted.

‎tests/ui/rfcs/rfc-1445-restrict-constants-in-patterns/allow-hide-behind-indirect-unsafe-ptr-embedded.rs

Lines changed: 0 additions & 26 deletions
This file was deleted.

‎tests/ui/rfcs/rfc-1445-restrict-constants-in-patterns/allow-hide-behind-indirect-unsafe-ptr-param.rs

Lines changed: 0 additions & 26 deletions
This file was deleted.

‎tests/ui/rfcs/rfc-1445-restrict-constants-in-patterns/fn-ptr-is-structurally-matchable.rs renamed to ‎tests/ui/rfcs/rfc-1445-restrict-constants-in-patterns/fn-ptr-is-not-structurally-matchable.rs

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
//@ run-pass
2-
3-
// This file checks that fn ptrs are considered structurally matchable.
4-
// See also rust-lang/rust#63479.
1+
// This file checks that fn ptrs are *not* considered structurally matchable.
2+
// See also rust-lang/rust#63479 and RFC 3535.
53

64
fn main() {
75
let mut count = 0;
@@ -40,80 +38,71 @@ fn main() {
4038
const CFN1: Wrap<fn()> = Wrap(trivial);
4139
let input: Wrap<fn()> = Wrap(trivial);
4240
match Wrap(input) {
43-
Wrap(CFN1) => count += 1, //~WARN behave unpredictably
44-
//~| previously accepted
41+
Wrap(CFN1) => count += 1, //~ERROR behave unpredictably
4542
Wrap(_) => {}
4643
};
4744

4845
// Check that fn(T) is structural-match when T is too.
4946
const CFN2: Wrap<fn(SM)> = Wrap(sm_to);
5047
let input: Wrap<fn(SM)> = Wrap(sm_to);
5148
match Wrap(input) {
52-
Wrap(CFN2) => count += 1, //~WARN behave unpredictably
53-
//~| previously accepted
49+
Wrap(CFN2) => count += 1, //~ERROR behave unpredictably
5450
Wrap(_) => {}
5551
};
5652

5753
// Check that fn() -> T is structural-match when T is too.
5854
const CFN3: Wrap<fn() -> SM> = Wrap(to_sm);
5955
let input: Wrap<fn() -> SM> = Wrap(to_sm);
6056
match Wrap(input) {
61-
Wrap(CFN3) => count += 1, //~WARN behave unpredictably
62-
//~| previously accepted
57+
Wrap(CFN3) => count += 1, //~ERROR behave unpredictably
6358
Wrap(_) => {}
6459
};
6560

6661
// Check that fn(T) is structural-match even if T is not.
6762
const CFN4: Wrap<fn(NotSM)> = Wrap(not_sm_to);
6863
let input: Wrap<fn(NotSM)> = Wrap(not_sm_to);
6964
match Wrap(input) {
70-
Wrap(CFN4) => count += 1, //~WARN behave unpredictably
71-
//~| previously accepted
65+
Wrap(CFN4) => count += 1, //~ERROR behave unpredictably
7266
Wrap(_) => {}
7367
};
7468

7569
// Check that fn() -> T is structural-match even if T is not.
7670
const CFN5: Wrap<fn() -> NotSM> = Wrap(to_not_sm);
7771
let input: Wrap<fn() -> NotSM> = Wrap(to_not_sm);
7872
match Wrap(input) {
79-
Wrap(CFN5) => count += 1, //~WARN behave unpredictably
80-
//~| previously accepted
73+
Wrap(CFN5) => count += 1, //~ERROR behave unpredictably
8174
Wrap(_) => {}
8275
};
8376

8477
// Check that fn(&T) is structural-match when T is too.
8578
const CFN6: Wrap<fn(&SM)> = Wrap(r_sm_to);
8679
let input: Wrap<fn(&SM)> = Wrap(r_sm_to);
8780
match Wrap(input) {
88-
Wrap(CFN6) => count += 1, //~WARN behave unpredictably
89-
//~| previously accepted
81+
Wrap(CFN6) => count += 1, //~ERROR behave unpredictably
9082
Wrap(_) => {}
9183
};
9284

9385
// Check that fn() -> &T is structural-match when T is too.
9486
const CFN7: Wrap<fn(&()) -> &SM> = Wrap(r_to_r_sm);
9587
let input: Wrap<fn(&()) -> &SM> = Wrap(r_to_r_sm);
9688
match Wrap(input) {
97-
Wrap(CFN7) => count += 1, //~WARN behave unpredictably
98-
//~| previously accepted
89+
Wrap(CFN7) => count += 1, //~ERROR behave unpredictably
9990
Wrap(_) => {}
10091
};
10192

10293
// Check that fn(T) is structural-match even if T is not.
10394
const CFN8: Wrap<fn(&NotSM)> = Wrap(r_not_sm_to);
10495
let input: Wrap<fn(&NotSM)> = Wrap(r_not_sm_to);
10596
match Wrap(input) {
106-
Wrap(CFN8) => count += 1, //~WARN behave unpredictably
107-
//~| previously accepted
97+
Wrap(CFN8) => count += 1, //~ERROR behave unpredictably
10898
Wrap(_) => {}
10999
};
110100

111101
// Check that fn() -> T is structural-match even if T is not.
112102
const CFN9: Wrap<fn(&()) -> &NotSM> = Wrap(r_to_r_not_sm);
113103
let input: Wrap<fn(&()) -> &NotSM> = Wrap(r_to_r_not_sm);
114104
match Wrap(input) {
115-
Wrap(CFN9) => count += 1, //~WARN behave unpredictably
116-
//~| previously accepted
105+
Wrap(CFN9) => count += 1, //~ERROR behave unpredictably
117106
Wrap(_) => {}
118107
};
119108

@@ -135,8 +124,7 @@ fn main() {
135124

136125
let input = Foo { alpha: not_sm_to, beta: to_not_sm, gamma: sm_to, delta: to_sm };
137126
match input {
138-
CFOO => count += 1, //~WARN behave unpredictably
139-
//~| previously accepted
127+
CFOO => count += 1, //~ERROR behave unpredictably
140128
Foo { .. } => {}
141129
};
142130

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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.
2+
--> $DIR/fn-ptr-is-not-structurally-matchable.rs:41:14
3+
|
4+
LL | Wrap(CFN1) => count += 1,
5+
| ^^^^
6+
7+
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.
8+
--> $DIR/fn-ptr-is-not-structurally-matchable.rs:49:14
9+
|
10+
LL | Wrap(CFN2) => count += 1,
11+
| ^^^^
12+
13+
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.
14+
--> $DIR/fn-ptr-is-not-structurally-matchable.rs:57:14
15+
|
16+
LL | Wrap(CFN3) => count += 1,
17+
| ^^^^
18+
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.
20+
--> $DIR/fn-ptr-is-not-structurally-matchable.rs:65:14
21+
|
22+
LL | Wrap(CFN4) => count += 1,
23+
| ^^^^
24+
25+
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.
26+
--> $DIR/fn-ptr-is-not-structurally-matchable.rs:73:14
27+
|
28+
LL | Wrap(CFN5) => count += 1,
29+
| ^^^^
30+
31+
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.
32+
--> $DIR/fn-ptr-is-not-structurally-matchable.rs:81:14
33+
|
34+
LL | Wrap(CFN6) => count += 1,
35+
| ^^^^
36+
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.
38+
--> $DIR/fn-ptr-is-not-structurally-matchable.rs:89:14
39+
|
40+
LL | Wrap(CFN7) => count += 1,
41+
| ^^^^
42+
43+
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.
44+
--> $DIR/fn-ptr-is-not-structurally-matchable.rs:97:14
45+
|
46+
LL | Wrap(CFN8) => count += 1,
47+
| ^^^^
48+
49+
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.
50+
--> $DIR/fn-ptr-is-not-structurally-matchable.rs:105:14
51+
|
52+
LL | Wrap(CFN9) => count += 1,
53+
| ^^^^
54+
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.
56+
--> $DIR/fn-ptr-is-not-structurally-matchable.rs:127:9
57+
|
58+
LL | CFOO => count += 1,
59+
| ^^^^
60+
61+
error: aborting due to 10 previous errors
62+

‎tests/ui/rfcs/rfc-1445-restrict-constants-in-patterns/fn-ptr-is-structurally-matchable.stderr

Lines changed: 0 additions & 203 deletions
This file was deleted.

‎tests/ui/rfcs/rfc-1445-restrict-constants-in-patterns/issue-63479-match-fnptr.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
//@ run-pass
2-
31
// The actual regression test from #63479. (Including this because my
42
// first draft at fn-ptr-is-structurally-matchable.rs failed to actually
53
// cover the case this hit; I've since expanded it accordingly, but the
64
// experience left me wary of leaving this regression test out.)
75

8-
#![warn(pointer_structural_match)]
9-
106
#[derive(Eq)]
117
struct A {
128
a: i64
@@ -34,14 +30,12 @@ fn main() {
3430
let s = B(my_fn);
3531
match s {
3632
B(TEST) => println!("matched"),
37-
//~^ WARN behave unpredictably
38-
//~| WARN this was previously accepted by the compiler but is being phased out
33+
//~^ ERROR behave unpredictably
3934
_ => panic!("didn't match")
4035
};
4136
match (s.0, 0) {
4237
TEST2 => println!("matched"),
43-
//~^ WARN behave unpredictably
44-
//~| WARN this was previously accepted by the compiler but is being phased out
38+
//~^ ERROR behave unpredictably
4539
_ => panic!("didn't match")
4640
}
4741
}
Lines changed: 5 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,14 @@
1-
warning: 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.
2-
--> $DIR/issue-63479-match-fnptr.rs:36:7
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.
2+
--> $DIR/issue-63479-match-fnptr.rs:32:7
33
|
44
LL | B(TEST) => println!("matched"),
55
| ^^^^
6-
|
7-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
8-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
9-
note: the lint level is defined here
10-
--> $DIR/issue-63479-match-fnptr.rs:8:9
11-
|
12-
LL | #![warn(pointer_structural_match)]
13-
| ^^^^^^^^^^^^^^^^^^^^^^^^
146

15-
warning: 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.
16-
--> $DIR/issue-63479-match-fnptr.rs:42:5
7+
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.
8+
--> $DIR/issue-63479-match-fnptr.rs:37:5
179
|
1810
LL | TEST2 => println!("matched"),
1911
| ^^^^^
20-
|
21-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
22-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
23-
24-
warning: 2 warnings emitted
2512

26-
Future incompatibility report: Future breakage diagnostic:
27-
warning: 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.
28-
--> $DIR/issue-63479-match-fnptr.rs:36:7
29-
|
30-
LL | B(TEST) => println!("matched"),
31-
| ^^^^
32-
|
33-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
34-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
35-
note: the lint level is defined here
36-
--> $DIR/issue-63479-match-fnptr.rs:8:9
37-
|
38-
LL | #![warn(pointer_structural_match)]
39-
| ^^^^^^^^^^^^^^^^^^^^^^^^
40-
41-
Future breakage diagnostic:
42-
warning: 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.
43-
--> $DIR/issue-63479-match-fnptr.rs:42:5
44-
|
45-
LL | TEST2 => println!("matched"),
46-
| ^^^^^
47-
|
48-
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
49-
= note: for more information, see issue #120362 <https://github.com/rust-lang/rust/issues/120362>
50-
note: the lint level is defined here
51-
--> $DIR/issue-63479-match-fnptr.rs:8:9
52-
|
53-
LL | #![warn(pointer_structural_match)]
54-
| ^^^^^^^^^^^^^^^^^^^^^^^^
13+
error: aborting due to 2 previous errors
5514

0 commit comments

Comments
 (0)
Please sign in to comment.