-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #134586 - Urgau:fn-ptr-lint-option, r=compiler-errors
Also lint on option of function pointer comparisons This PR is the first part of #134536, ie. the linting on `Option<{fn ptr}>` in the `unpredictable_function_pointer_comparisons` lint, which isn't part of the lang nomination that the second part is going trough, and so should be able to be approved independently. Related to #134527 r? `@compiler-errors`
- Loading branch information
Showing
3 changed files
with
50 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// This test checks that we lint on Option of fn ptr. | ||
// | ||
// https://github.com/rust-lang/rust/issues/134527. | ||
// | ||
//@ check-pass | ||
|
||
unsafe extern "C" fn func() {} | ||
|
||
type FnPtr = unsafe extern "C" fn(); | ||
|
||
fn main() { | ||
let _ = Some::<FnPtr>(func) == Some(func as unsafe extern "C" fn()); | ||
//~^ WARN function pointer comparisons | ||
|
||
// Undecided as of https://github.com/rust-lang/rust/pull/134536 | ||
assert_eq!(Some::<FnPtr>(func), Some(func as unsafe extern "C" fn())); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
warning: function pointer comparisons do not produce meaningful results since their addresses are not guaranteed to be unique | ||
--> $DIR/fn-ptr-comparisons-some.rs:12:13 | ||
| | ||
LL | let _ = Some::<FnPtr>(func) == Some(func as unsafe extern "C" fn()); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: the address of the same function can vary between different codegen units | ||
= note: furthermore, different functions could have the same address after being merged together | ||
= note: for more information visit <https://doc.rust-lang.org/nightly/core/ptr/fn.fn_addr_eq.html> | ||
= note: `#[warn(unpredictable_function_pointer_comparisons)]` on by default | ||
|
||
warning: 1 warning emitted | ||
|