Skip to content

Commit 0e58333

Browse files
committed
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 <#53934>.
1 parent ad14a22 commit 0e58333

4 files changed

+47
-3
lines changed

compiler/rustc_lint/src/lints.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1543,7 +1543,7 @@ pub enum AmbiguousWidePointerComparisons<'a> {
15431543
#[multipart_suggestion(
15441544
lint_addr_metadata_suggestion,
15451545
style = "verbose",
1546-
applicability = "machine-applicable"
1546+
applicability = "maybe-incorrect"
15471547
)]
15481548
pub struct AmbiguousWidePointerComparisonsAddrMetadataSuggestion<'a> {
15491549
pub ne: &'a str,
@@ -1562,7 +1562,7 @@ pub enum AmbiguousWidePointerComparisonsAddrSuggestion<'a> {
15621562
#[multipart_suggestion(
15631563
lint_addr_suggestion,
15641564
style = "verbose",
1565-
applicability = "machine-applicable"
1565+
applicability = "maybe-incorrect"
15661566
)]
15671567
AddrEq {
15681568
ne: &'a str,
@@ -1578,7 +1578,7 @@ pub enum AmbiguousWidePointerComparisonsAddrSuggestion<'a> {
15781578
#[multipart_suggestion(
15791579
lint_addr_suggestion,
15801580
style = "verbose",
1581-
applicability = "machine-applicable"
1581+
applicability = "maybe-incorrect"
15821582
)]
15831583
Cast {
15841584
deref_left: &'a str,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ run-rustfix
2+
//@ rustfix-only-machine-applicable
3+
//@ check-pass
4+
5+
// See <https://github.com/rust-lang/rust/issues/121330>.
6+
7+
fn cmp<T: ?Sized>(a: *mut T, b: *mut T) -> bool {
8+
let _ = a == b;
9+
//~^ WARN ambiguous wide pointer comparison
10+
panic!();
11+
}
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ run-rustfix
2+
//@ rustfix-only-machine-applicable
3+
//@ check-pass
4+
5+
// See <https://github.com/rust-lang/rust/issues/121330>.
6+
7+
fn cmp<T: ?Sized>(a: *mut T, b: *mut T) -> bool {
8+
let _ = a == b;
9+
//~^ WARN ambiguous wide pointer comparison
10+
panic!();
11+
}
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected
2+
--> $DIR/ambiguous_wide_pointer_comparisons_suggestions.rs:8:13
3+
|
4+
LL | let _ = a == b;
5+
| ^^^^^^
6+
|
7+
= note: `#[warn(ambiguous_wide_pointer_comparisons)]` on by default
8+
help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses
9+
|
10+
LL | let _ = std::ptr::addr_eq(a, b);
11+
| ++++++++++++++++++ ~ +
12+
help: use explicit `std::ptr::eq` method to compare metadata and addresses
13+
|
14+
LL | let _ = std::ptr::eq(a, b);
15+
| +++++++++++++ ~ +
16+
17+
warning: 1 warning emitted
18+

0 commit comments

Comments
 (0)