diff options
| author | 许杰友 Jieyou Xu (Joe) <jieyouxu@outlook.com> | 2024-02-20 11:35:13 +0000 |
|---|---|---|
| committer | 许杰友 Jieyou Xu (Joe) <jieyouxu@outlook.com> | 2024-02-20 17:21:01 +0000 |
| commit | 4d386d9f049da498b5f072b6c358a6fbbe0baf59 (patch) | |
| tree | 7a6c0bc24e3942f51313e1ea2a527c1bebbdd705 | |
| parent | ad14a226c04c4b15a229bb1fba771ba8fd2f5b46 (diff) | |
| download | rust-4d386d9f049da498b5f072b6c358a6fbbe0baf59.tar.gz rust-4d386d9f049da498b5f072b6c358a6fbbe0baf59.zip | |
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>.
4 files changed, 50 insertions, 3 deletions
diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index c204c67fc1f..71107be206b 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -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, diff --git a/tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.fixed b/tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.fixed new file mode 100644 index 00000000000..6ce68ff9640 --- /dev/null +++ b/tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.fixed @@ -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() {} diff --git a/tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.rs b/tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.rs new file mode 100644 index 00000000000..6ce68ff9640 --- /dev/null +++ b/tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.rs @@ -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() {} diff --git a/tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.stderr b/tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.stderr new file mode 100644 index 00000000000..d9190dbb813 --- /dev/null +++ b/tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.stderr @@ -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 + |
