Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Downgrade ambiguous_wide_pointer_comparisons suggestions to MaybeIncorrect #121338

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions compiler/rustc_lint/src/lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
jieyouxu marked this conversation as resolved.
Show resolved Hide resolved
)]
pub struct AmbiguousWidePointerComparisonsAddrMetadataSuggestion<'a> {
pub ne: &'a str,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
13 changes: 9 additions & 4 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.fixed
Original file line number Diff line number Diff line change
@@ -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() {}
13 changes: 13 additions & 0 deletions tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.rs
Original file line number Diff line number Diff line change
@@ -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() {}
Original file line number Diff line number Diff line change
@@ -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

Loading