Downgrade ambiguous_wide_pointer_comparisons suggestions to MaybeIncorrect

It is possible to have more than one valid suggestion, which when
applied together via rustfix causes the code to no longer compile.

This is a temporary workaround; the real long term solution to these
issues is to solve <https://github.com/rust-lang/rust/issues/53934>.
This commit is contained in:
许杰友 Jieyou Xu (Joe) 2024-02-20 11:35:13 +00:00
parent ad14a226c0
commit 4d386d9f04
No known key found for this signature in database
GPG Key ID: 95DDEBD74A1DC2C0
4 changed files with 50 additions and 3 deletions

View File

@ -1543,7 +1543,8 @@ pub enum AmbiguousWidePointerComparisons<'a> {
#[multipart_suggestion(
lint_addr_metadata_suggestion,
style = "verbose",
applicability = "machine-applicable"
// FIXME(#53934): make machine-applicable again
applicability = "maybe-incorrect"
)]
pub struct AmbiguousWidePointerComparisonsAddrMetadataSuggestion<'a> {
pub ne: &'a str,
@ -1562,7 +1563,8 @@ pub enum AmbiguousWidePointerComparisonsAddrSuggestion<'a> {
#[multipart_suggestion(
lint_addr_suggestion,
style = "verbose",
applicability = "machine-applicable"
// FIXME(#53934): make machine-applicable again
applicability = "maybe-incorrect"
)]
AddrEq {
ne: &'a str,
@ -1578,7 +1580,8 @@ pub enum AmbiguousWidePointerComparisonsAddrSuggestion<'a> {
#[multipart_suggestion(
lint_addr_suggestion,
style = "verbose",
applicability = "machine-applicable"
// FIXME(#53934): make machine-applicable again
applicability = "maybe-incorrect"
)]
Cast {
deref_left: &'a str,

View File

@ -0,0 +1,13 @@
//@ run-rustfix
//@ rustfix-only-machine-applicable
//@ check-pass
// See <https://github.com/rust-lang/rust/issues/121330>.
fn cmp<T: ?Sized>(a: *mut T, b: *mut T) -> bool {
let _ = a == b;
//~^ WARN ambiguous wide pointer comparison
panic!();
}
fn main() {}

View File

@ -0,0 +1,13 @@
//@ run-rustfix
//@ rustfix-only-machine-applicable
//@ check-pass
// See <https://github.com/rust-lang/rust/issues/121330>.
fn cmp<T: ?Sized>(a: *mut T, b: *mut T) -> bool {
let _ = a == b;
//~^ WARN ambiguous wide pointer comparison
panic!();
}
fn main() {}

View File

@ -0,0 +1,18 @@
warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
--> $DIR/ambiguous_wide_pointer_comparisons_suggestions.rs:8:13
|
LL | let _ = a == b;
| ^^^^^^
|
= note: `#[warn(ambiguous_wide_pointer_comparisons)]` on by default
help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses
|
LL | let _ = std::ptr::addr_eq(a, b);
| ++++++++++++++++++ ~ +
help: use explicit `std::ptr::eq` method to compare metadata and addresses
|
LL | let _ = std::ptr::eq(a, b);
| +++++++++++++ ~ +
warning: 1 warning emitted