Skip to content

Commit 86b8a21

Browse files
committed
Turn pointer_structural_match forward compat lint into normal lint
This commit removes the pointer_structural_match forward compat lint from the forward compatibility warning mechanism, as there is no concrete plan for removal of matching on function pointers. It also turns the lint from allow-by-default to warn-by-default, as the behaviour might be surprising to users and they should specifically opt into the dangers. As the lint is recognized on older compilers, users can easily allow it after having made the descision on whether they want to keep it in their code or not.
1 parent 4b94c23 commit 86b8a21

13 files changed

+22
-44
lines changed

compiler/rustc_lint_defs/src/builtin.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -2277,19 +2277,16 @@ declare_lint! {
22772277
///
22782278
/// ### Explanation
22792279
///
2280-
/// Previous versions of Rust allowed function pointers and wide raw pointers in patterns.
2281-
/// While these work in many cases as expected by users, it is possible that due to
2282-
/// optimizations pointers are "not equal to themselves" or pointers to different functions
2283-
/// compare as equal during runtime. This is because LLVM optimizations can deduplicate
2284-
/// functions if their bodies are the same, thus also making pointers to these functions point
2285-
/// to the same location. Additionally functions may get duplicated if they are instantiated
2280+
/// Use of function pointers and wide raw pointers in patterns works in many cases as
2281+
/// expected by users. However, it is possible that due to optimizations pointers are "not equal
2282+
/// to themselves" or pointers to different functions compare as equal during runtime.
2283+
/// This is because LLVM optimizations can deduplicate functions if their bodies are the same,
2284+
/// thus also making pointers to these functions point to the same location.
2285+
/// Additionally, functions may get duplicated if they are instantiated
22862286
/// in different crates and not deduplicated again via LTO.
22872287
pub POINTER_STRUCTURAL_MATCH,
2288-
Allow,
2289-
"pointers are not structural-match",
2290-
@future_incompatible = FutureIncompatibleInfo {
2291-
reference: "issue #62411 <https://github.com/rust-lang/rust/issues/70861>",
2292-
};
2288+
Warn,
2289+
"pointers are not structural-match"
22932290
}
22942291

22952292
declare_lint! {

library/core/src/marker.rs

+1
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ pub trait StructuralPartialEq {
243243
///
244244
/// const CFN: Wrap<fn(&())> = Wrap(higher_order);
245245
///
246+
/// # #[allow(pointer_structural_match)]
246247
/// fn main() {
247248
/// match CFN {
248249
/// CFN => {}

tests/ui/consts/const_in_pattern/issue-44333.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// run-pass
22

3-
#![warn(pointer_structural_match)]
4-
53
type Func = fn(usize, usize) -> usize;
64

75
fn foo(a: usize, b: usize) -> usize { a + b }
@@ -17,9 +15,7 @@ const BAR: Func = bar;
1715
fn main() {
1816
match test(std::env::consts::ARCH.len()) {
1917
FOO => println!("foo"), //~ WARN pointers in patterns behave unpredictably
20-
//~^ WARN will become a hard error
2118
BAR => println!("bar"), //~ WARN pointers in patterns behave unpredictably
22-
//~^ WARN will become a hard error
2319
_ => unreachable!(),
2420
}
2521
}
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
11
warning: function pointers and unsized pointers 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
2+
--> $DIR/issue-44333.rs:17:9
33
|
44
LL | FOO => println!("foo"),
55
| ^^^
66
|
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 #62411 <https://github.com/rust-lang/rust/issues/70861>
9-
note: the lint level is defined here
10-
--> $DIR/issue-44333.rs:3:9
11-
|
12-
LL | #![warn(pointer_structural_match)]
13-
| ^^^^^^^^^^^^^^^^^^^^^^^^
7+
= note: `#[warn(pointer_structural_match)]` on by default
148

159
warning: function pointers and unsized pointers 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
10+
--> $DIR/issue-44333.rs:18:9
1711
|
1812
LL | BAR => println!("bar"),
1913
| ^^^
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 #62411 <https://github.com/rust-lang/rust/issues/70861>
2314

2415
warning: 2 warnings emitted
2516

tests/ui/consts/issue-34784.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-pass
22

3-
#![warn(pointer_structural_match)]
3+
44
#![allow(dead_code)]
55
const C: *const u8 = &0;
66

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// unnecessary warnings because const_to_pat.rs converts a constant pattern to a wildcard when the
33
// constant is not allowed as a pattern. This is an edge case so we may not care to fix it.
44
// See also https://github.com/rust-lang/rust/issues/78057
5-
5+
#![allow(pointer_structural_match)]
66
#![deny(unreachable_patterns)]
77

88
#[derive(PartialEq)]

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// run-pass
55

6-
#![warn(pointer_structural_match)]
6+
#![deny(pointer_structural_match)]
77

88
struct NoDerive(#[allow(unused_tuple_struct_fields)] i32);
99

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// run-pass
55

6-
#![warn(pointer_structural_match)]
6+
#![deny(pointer_structural_match)]
77

88
struct NoDerive(#[allow(unused_tuple_struct_fields)] i32);
99

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// run-pass
55

6-
#![warn(pointer_structural_match)]
6+
#![deny(pointer_structural_match)]
77

88
struct NoDerive(#[allow(unused_tuple_struct_fields)] i32);
99

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// run-pass
55

6-
#![warn(pointer_structural_match)]
6+
#![deny(pointer_structural_match)]
77

88
struct NoDerive(#[allow(unused_tuple_struct_fields)] i32);
99

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

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
// This file checks that fn ptrs are considered structurally matchable.
44
// See also rust-lang/rust#63479.
55

6+
#![allow(pointer_structural_match)]
7+
68
fn main() {
79
let mut count = 0;
810

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

-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
// cover the case this hit; I've since expanded it accordingly, but the
66
// experience left me wary of leaving this regression test out.)
77

8-
#![warn(pointer_structural_match)]
9-
108
#[derive(Eq)]
119
struct A {
1210
a: i64
@@ -34,7 +32,6 @@ fn main() {
3432
match s {
3533
B(TEST) => println!("matched"),
3634
//~^ WARN pointers in patterns behave unpredictably
37-
//~| WARN this was previously accepted by the compiler but is being phased out
3835
_ => panic!("didn't match")
3936
};
4037
}
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
warning: function pointers and unsized pointers 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:35:7
2+
--> $DIR/issue-63479-match-fnptr.rs:33:7
33
|
44
LL | B(TEST) => println!("matched"),
55
| ^^^^
66
|
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 #62411 <https://github.com/rust-lang/rust/issues/70861>
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-
| ^^^^^^^^^^^^^^^^^^^^^^^^
7+
= note: `#[warn(pointer_structural_match)]` on by default
148

159
warning: 1 warning emitted
1610

0 commit comments

Comments
 (0)