From aba5ea1430df393eddc90068e838de6b1707c0d8 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Sun, 20 Sep 2020 17:11:00 +0200 Subject: Lint on function pointers used in patterns --- compiler/rustc_session/src/lint/builtin.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'compiler/rustc_session/src') diff --git a/compiler/rustc_session/src/lint/builtin.rs b/compiler/rustc_session/src/lint/builtin.rs index 562df176b14..c72b97fa1ca 100644 --- a/compiler/rustc_session/src/lint/builtin.rs +++ b/compiler/rustc_session/src/lint/builtin.rs @@ -2197,6 +2197,32 @@ declare_lint! { report_in_external_macro } +declare_lint! { + /// The `pointer_structural_match` lint detects pointers used in patterns that do not + /// behave deterministically across optimizations. + /// + /// ### Example + /// + /// ```rust,compile_fail + /// #![deny(pointer_structural_match)] + /// fn foo(a: usize, b: usize) -> usize { a + b } + /// const FOO: fn(usize, usize) -> usize = foo; + /// fn main() { + /// match FOO { + /// FOO => {}, + /// _ => {}, + /// } + /// } + /// ``` + pub POINTER_STRUCTURAL_MATCH, + Allow, + "pointers are not structural-match", + @future_incompatible = FutureIncompatibleInfo { + reference: "issue #62411 ", + edition: None, + }; +} + declare_lint! { /// The `ambiguous_associated_items` lint detects ambiguity between /// [associated items] and [enum variants]. @@ -2630,6 +2656,7 @@ declare_lint_pass! { AMBIGUOUS_ASSOCIATED_ITEMS, MUTABLE_BORROW_RESERVATION_CONFLICT, INDIRECT_STRUCTURAL_MATCH, + POINTER_STRUCTURAL_MATCH, SOFT_UNSTABLE, INLINE_NO_SANITIZE, ASM_SUB_REGISTER, -- cgit 1.4.1-3-g733a5