about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_lint/src/lints.rs9
-rw-r--r--src/tools/compiletest/src/runtest.rs13
-rw-r--r--tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.fixed13
-rw-r--r--tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.rs13
-rw-r--r--tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.stderr18
5 files changed, 59 insertions, 7 deletions
diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs
index 5fb2ddf9199..f067c365170 100644
--- a/compiler/rustc_lint/src/lints.rs
+++ b/compiler/rustc_lint/src/lints.rs
@@ -1582,7 +1582,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,
@@ -1601,7 +1602,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,
@@ -1617,7 +1619,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/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs
index f3a0e87d43a..ed120ee877a 100644
--- a/src/tools/compiletest/src/runtest.rs
+++ b/src/tools/compiletest/src/runtest.rs
@@ -3938,10 +3938,15 @@ impl<'test> TestCx<'test> {
                 self.props.compare_output_lines_by_subset,
             );
         } else if !expected_fixed.is_empty() {
-            panic!(
-                "the `// run-rustfix` directive wasn't found but a `*.fixed` \
-                 file was found"
-            );
+            if self.config.suite == "ui" {
+                panic!(
+                    "the `//@ run-rustfix` directive wasn't found but a `*.fixed` file was found"
+                );
+            } else {
+                panic!(
+                    "the `// run-rustfix` directive wasn't found but a `*.fixed` file was found"
+                );
+            }
         }
 
         if errors > 0 {
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
+