make pointer_structural_match warn-by-default
This commit is contained in:
parent
af6c7e0ca1
commit
70a8e157ab
@ -2226,7 +2226,7 @@
|
||||
/// in different crates and not deduplicated again via LTO. Pointer identity for memory
|
||||
/// created by `const` is similarly unreliable.
|
||||
pub POINTER_STRUCTURAL_MATCH,
|
||||
Allow,
|
||||
Warn,
|
||||
"pointers are not structural-match",
|
||||
@future_incompatible = FutureIncompatibleInfo {
|
||||
reason: FutureIncompatibilityReason::FutureReleaseErrorDontReportInDeps,
|
||||
|
@ -247,6 +247,7 @@ pub trait StructuralPartialEq {
|
||||
///
|
||||
/// const CFN: Wrap<fn(&())> = Wrap(higher_order);
|
||||
///
|
||||
/// #[allow(pointer_structural_match)]
|
||||
/// fn main() {
|
||||
/// match CFN {
|
||||
/// CFN => {}
|
||||
|
@ -26,7 +26,8 @@ pub fn edge_case_str(event: String) {
|
||||
pub fn edge_case_raw_ptr(event: *const i32) {
|
||||
let _ = || {
|
||||
match event {
|
||||
NUMBER_POINTER => (),
|
||||
NUMBER_POINTER => (), //~WARN behave unpredictably
|
||||
//~| previously accepted
|
||||
_ => (),
|
||||
};
|
||||
};
|
||||
|
@ -0,0 +1,12 @@
|
||||
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.
|
||||
--> $DIR/match-edge-cases_1.rs:29:13
|
||||
|
|
||||
LL | NUMBER_POINTER => (),
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/70861>
|
||||
= note: `#[warn(pointer_structural_match)]` on by default
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
@ -95,8 +95,10 @@ fn quux(a: usize, b: usize) -> usize { a + b }
|
||||
const QUUX: Quux = quux;
|
||||
|
||||
match QUUX {
|
||||
QUUX => {}
|
||||
QUUX => {}
|
||||
QUUX => {} //~WARN behave unpredictably
|
||||
//~| previously accepted
|
||||
QUUX => {} //~WARN behave unpredictably
|
||||
//~| previously accepted
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@ -105,14 +107,17 @@ fn quux(a: usize, b: usize) -> usize { a + b }
|
||||
const WRAPQUUX: Wrap<Quux> = Wrap(quux);
|
||||
|
||||
match WRAPQUUX {
|
||||
WRAPQUUX => {}
|
||||
WRAPQUUX => {}
|
||||
WRAPQUUX => {} //~WARN behave unpredictably
|
||||
//~| previously accepted
|
||||
WRAPQUUX => {} //~WARN behave unpredictably
|
||||
//~| previously accepted
|
||||
Wrap(_) => {}
|
||||
}
|
||||
|
||||
match WRAPQUUX {
|
||||
Wrap(_) => {}
|
||||
WRAPQUUX => {}
|
||||
WRAPQUUX => {} //~WARN behave unpredictably
|
||||
//~| previously accepted
|
||||
}
|
||||
|
||||
match WRAPQUUX {
|
||||
@ -121,7 +126,8 @@ fn quux(a: usize, b: usize) -> usize { a + b }
|
||||
|
||||
match WRAPQUUX {
|
||||
//~^ ERROR: non-exhaustive patterns: `Wrap(_)` not covered
|
||||
WRAPQUUX => {}
|
||||
WRAPQUUX => {} //~WARN behave unpredictably
|
||||
//~| previously accepted
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
@ -132,9 +138,11 @@ enum WhoKnows<T> {
|
||||
const WHOKNOWSQUUX: WhoKnows<Quux> = WhoKnows::Yay(quux);
|
||||
|
||||
match WHOKNOWSQUUX {
|
||||
WHOKNOWSQUUX => {}
|
||||
WHOKNOWSQUUX => {} //~WARN behave unpredictably
|
||||
//~| previously accepted
|
||||
WhoKnows::Yay(_) => {}
|
||||
WHOKNOWSQUUX => {}
|
||||
WHOKNOWSQUUX => {} //~WARN behave unpredictably
|
||||
//~| previously accepted
|
||||
WhoKnows::Nope => {}
|
||||
}
|
||||
}
|
||||
|
@ -91,24 +91,96 @@ LL | BAZ => {}
|
||||
= note: the traits must be derived, manual `impl`s are not sufficient
|
||||
= note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
|
||||
|
||||
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.
|
||||
--> $DIR/consts-opaque.rs:98:9
|
||||
|
|
||||
LL | QUUX => {}
|
||||
| ^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/70861>
|
||||
= note: `#[warn(pointer_structural_match)]` on by default
|
||||
|
||||
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.
|
||||
--> $DIR/consts-opaque.rs:100:9
|
||||
|
|
||||
LL | QUUX => {}
|
||||
| ^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/70861>
|
||||
|
||||
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.
|
||||
--> $DIR/consts-opaque.rs:110:9
|
||||
|
|
||||
LL | WRAPQUUX => {}
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/70861>
|
||||
|
||||
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.
|
||||
--> $DIR/consts-opaque.rs:112:9
|
||||
|
|
||||
LL | WRAPQUUX => {}
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/70861>
|
||||
|
||||
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.
|
||||
--> $DIR/consts-opaque.rs:119:9
|
||||
|
|
||||
LL | WRAPQUUX => {}
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/70861>
|
||||
|
||||
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.
|
||||
--> $DIR/consts-opaque.rs:129:9
|
||||
|
|
||||
LL | WRAPQUUX => {}
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/70861>
|
||||
|
||||
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.
|
||||
--> $DIR/consts-opaque.rs:141:9
|
||||
|
|
||||
LL | WHOKNOWSQUUX => {}
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/70861>
|
||||
|
||||
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.
|
||||
--> $DIR/consts-opaque.rs:144:9
|
||||
|
|
||||
LL | WHOKNOWSQUUX => {}
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/70861>
|
||||
|
||||
error[E0004]: non-exhaustive patterns: `Wrap(_)` not covered
|
||||
--> $DIR/consts-opaque.rs:122:11
|
||||
--> $DIR/consts-opaque.rs:127:11
|
||||
|
|
||||
LL | match WRAPQUUX {
|
||||
| ^^^^^^^^ pattern `Wrap(_)` not covered
|
||||
|
|
||||
note: `Wrap<fn(usize, usize) -> usize>` defined here
|
||||
--> $DIR/consts-opaque.rs:104:12
|
||||
--> $DIR/consts-opaque.rs:106:12
|
||||
|
|
||||
LL | struct Wrap<T>(T);
|
||||
| ^^^^
|
||||
= note: the matched value is of type `Wrap<fn(usize, usize) -> usize>`
|
||||
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
|
||||
|
|
||||
LL ~ WRAPQUUX => {},
|
||||
LL + Wrap(_) => todo!()
|
||||
|
|
||||
LL | WRAPQUUX => {}, Wrap(_) => todo!()
|
||||
| ++++++++++++++++++++
|
||||
|
||||
error: aborting due to 10 previous errors; 1 warning emitted
|
||||
error: aborting due to 10 previous errors; 9 warnings emitted
|
||||
|
||||
For more information about this error, try `rustc --explain E0004`.
|
||||
|
@ -40,7 +40,8 @@ fn r_to_r_not_sm(_: &()) -> &NotSM { &NotSM }
|
||||
const CFN1: Wrap<fn()> = Wrap(trivial);
|
||||
let input: Wrap<fn()> = Wrap(trivial);
|
||||
match Wrap(input) {
|
||||
Wrap(CFN1) => count += 1,
|
||||
Wrap(CFN1) => count += 1, //~WARN behave unpredictably
|
||||
//~| previously accepted
|
||||
Wrap(_) => {}
|
||||
};
|
||||
|
||||
@ -48,7 +49,8 @@ fn r_to_r_not_sm(_: &()) -> &NotSM { &NotSM }
|
||||
const CFN2: Wrap<fn(SM)> = Wrap(sm_to);
|
||||
let input: Wrap<fn(SM)> = Wrap(sm_to);
|
||||
match Wrap(input) {
|
||||
Wrap(CFN2) => count += 1,
|
||||
Wrap(CFN2) => count += 1, //~WARN behave unpredictably
|
||||
//~| previously accepted
|
||||
Wrap(_) => {}
|
||||
};
|
||||
|
||||
@ -56,7 +58,8 @@ fn r_to_r_not_sm(_: &()) -> &NotSM { &NotSM }
|
||||
const CFN3: Wrap<fn() -> SM> = Wrap(to_sm);
|
||||
let input: Wrap<fn() -> SM> = Wrap(to_sm);
|
||||
match Wrap(input) {
|
||||
Wrap(CFN3) => count += 1,
|
||||
Wrap(CFN3) => count += 1, //~WARN behave unpredictably
|
||||
//~| previously accepted
|
||||
Wrap(_) => {}
|
||||
};
|
||||
|
||||
@ -64,7 +67,8 @@ fn r_to_r_not_sm(_: &()) -> &NotSM { &NotSM }
|
||||
const CFN4: Wrap<fn(NotSM)> = Wrap(not_sm_to);
|
||||
let input: Wrap<fn(NotSM)> = Wrap(not_sm_to);
|
||||
match Wrap(input) {
|
||||
Wrap(CFN4) => count += 1,
|
||||
Wrap(CFN4) => count += 1, //~WARN behave unpredictably
|
||||
//~| previously accepted
|
||||
Wrap(_) => {}
|
||||
};
|
||||
|
||||
@ -72,7 +76,8 @@ fn r_to_r_not_sm(_: &()) -> &NotSM { &NotSM }
|
||||
const CFN5: Wrap<fn() -> NotSM> = Wrap(to_not_sm);
|
||||
let input: Wrap<fn() -> NotSM> = Wrap(to_not_sm);
|
||||
match Wrap(input) {
|
||||
Wrap(CFN5) => count += 1,
|
||||
Wrap(CFN5) => count += 1, //~WARN behave unpredictably
|
||||
//~| previously accepted
|
||||
Wrap(_) => {}
|
||||
};
|
||||
|
||||
@ -80,7 +85,8 @@ fn r_to_r_not_sm(_: &()) -> &NotSM { &NotSM }
|
||||
const CFN6: Wrap<fn(&SM)> = Wrap(r_sm_to);
|
||||
let input: Wrap<fn(&SM)> = Wrap(r_sm_to);
|
||||
match Wrap(input) {
|
||||
Wrap(CFN6) => count += 1,
|
||||
Wrap(CFN6) => count += 1, //~WARN behave unpredictably
|
||||
//~| previously accepted
|
||||
Wrap(_) => {}
|
||||
};
|
||||
|
||||
@ -88,7 +94,8 @@ fn r_to_r_not_sm(_: &()) -> &NotSM { &NotSM }
|
||||
const CFN7: Wrap<fn(&()) -> &SM> = Wrap(r_to_r_sm);
|
||||
let input: Wrap<fn(&()) -> &SM> = Wrap(r_to_r_sm);
|
||||
match Wrap(input) {
|
||||
Wrap(CFN7) => count += 1,
|
||||
Wrap(CFN7) => count += 1, //~WARN behave unpredictably
|
||||
//~| previously accepted
|
||||
Wrap(_) => {}
|
||||
};
|
||||
|
||||
@ -96,7 +103,8 @@ fn r_to_r_not_sm(_: &()) -> &NotSM { &NotSM }
|
||||
const CFN8: Wrap<fn(&NotSM)> = Wrap(r_not_sm_to);
|
||||
let input: Wrap<fn(&NotSM)> = Wrap(r_not_sm_to);
|
||||
match Wrap(input) {
|
||||
Wrap(CFN8) => count += 1,
|
||||
Wrap(CFN8) => count += 1, //~WARN behave unpredictably
|
||||
//~| previously accepted
|
||||
Wrap(_) => {}
|
||||
};
|
||||
|
||||
@ -104,7 +112,8 @@ fn r_to_r_not_sm(_: &()) -> &NotSM { &NotSM }
|
||||
const CFN9: Wrap<fn(&()) -> &NotSM> = Wrap(r_to_r_not_sm);
|
||||
let input: Wrap<fn(&()) -> &NotSM> = Wrap(r_to_r_not_sm);
|
||||
match Wrap(input) {
|
||||
Wrap(CFN9) => count += 1,
|
||||
Wrap(CFN9) => count += 1, //~WARN behave unpredictably
|
||||
//~| previously accepted
|
||||
Wrap(_) => {}
|
||||
};
|
||||
|
||||
@ -126,7 +135,8 @@ struct Foo {
|
||||
|
||||
let input = Foo { alpha: not_sm_to, beta: to_not_sm, gamma: sm_to, delta: to_sm };
|
||||
match input {
|
||||
CFOO => count += 1,
|
||||
CFOO => count += 1, //~WARN behave unpredictably
|
||||
//~| previously accepted
|
||||
Foo { .. } => {}
|
||||
};
|
||||
|
||||
|
@ -0,0 +1,93 @@
|
||||
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.
|
||||
--> $DIR/fn-ptr-is-structurally-matchable.rs:43:14
|
||||
|
|
||||
LL | Wrap(CFN1) => count += 1,
|
||||
| ^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/70861>
|
||||
= note: `#[warn(pointer_structural_match)]` on by default
|
||||
|
||||
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.
|
||||
--> $DIR/fn-ptr-is-structurally-matchable.rs:52:14
|
||||
|
|
||||
LL | Wrap(CFN2) => count += 1,
|
||||
| ^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/70861>
|
||||
|
||||
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.
|
||||
--> $DIR/fn-ptr-is-structurally-matchable.rs:61:14
|
||||
|
|
||||
LL | Wrap(CFN3) => count += 1,
|
||||
| ^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/70861>
|
||||
|
||||
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.
|
||||
--> $DIR/fn-ptr-is-structurally-matchable.rs:70:14
|
||||
|
|
||||
LL | Wrap(CFN4) => count += 1,
|
||||
| ^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/70861>
|
||||
|
||||
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.
|
||||
--> $DIR/fn-ptr-is-structurally-matchable.rs:79:14
|
||||
|
|
||||
LL | Wrap(CFN5) => count += 1,
|
||||
| ^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/70861>
|
||||
|
||||
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.
|
||||
--> $DIR/fn-ptr-is-structurally-matchable.rs:88:14
|
||||
|
|
||||
LL | Wrap(CFN6) => count += 1,
|
||||
| ^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/70861>
|
||||
|
||||
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.
|
||||
--> $DIR/fn-ptr-is-structurally-matchable.rs:97:14
|
||||
|
|
||||
LL | Wrap(CFN7) => count += 1,
|
||||
| ^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/70861>
|
||||
|
||||
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.
|
||||
--> $DIR/fn-ptr-is-structurally-matchable.rs:106:14
|
||||
|
|
||||
LL | Wrap(CFN8) => count += 1,
|
||||
| ^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/70861>
|
||||
|
||||
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.
|
||||
--> $DIR/fn-ptr-is-structurally-matchable.rs:115:14
|
||||
|
|
||||
LL | Wrap(CFN9) => count += 1,
|
||||
| ^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/70861>
|
||||
|
||||
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.
|
||||
--> $DIR/fn-ptr-is-structurally-matchable.rs:138:9
|
||||
|
|
||||
LL | CFOO => count += 1,
|
||||
| ^^^^
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/70861>
|
||||
|
||||
warning: 10 warnings emitted
|
||||
|
Loading…
Reference in New Issue
Block a user