Skip to content

Commit 49025fa

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 49025fa

4 files changed

+71
-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,25 @@
1+
//@ run-rustfix
2+
//@ rustfix-only-machine-applicable
3+
//@ check-pass
4+
5+
// See <https://github.com/rust-lang/rust/issues/121330>.
6+
7+
use std::cmp::PartialEq;
8+
use std::rc::Rc;
9+
use std::sync::Arc;
10+
11+
struct A;
12+
struct B;
13+
14+
trait T {}
15+
impl T for A {}
16+
impl T for B {}
17+
18+
fn main() {
19+
fn cmp<T: ?Sized>(a: *mut T, b: *mut T) -> bool {
20+
let _ = a == b;
21+
//~^ WARN ambiguous wide pointer comparison
22+
23+
panic!();
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//@ run-rustfix
2+
//@ rustfix-only-machine-applicable
3+
//@ check-pass
4+
5+
// See <https://github.com/rust-lang/rust/issues/121330>.
6+
7+
use std::cmp::PartialEq;
8+
use std::rc::Rc;
9+
use std::sync::Arc;
10+
11+
struct A;
12+
struct B;
13+
14+
trait T {}
15+
impl T for A {}
16+
impl T for B {}
17+
18+
fn main() {
19+
fn cmp<T: ?Sized>(a: *mut T, b: *mut T) -> bool {
20+
let _ = a == b;
21+
//~^ WARN ambiguous wide pointer comparison
22+
23+
panic!();
24+
}
25+
}
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:20:17
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)