forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#121338 - jieyouxu:ambiguous_wide_pointer_co…
…mparisons_suggestion, r=Nadrieril Downgrade ambiguous_wide_pointer_comparisons suggestions to MaybeIncorrect In certain cases like rust-lang#121330, it is possible to have more than one suggestion from the `ambiguous_wide_pointer_comparisons` lint (which before this PR are `MachineApplicable`). When this gets passed to rustfix, rustfix makes *multiple* changes according to the suggestions which result in incorrect code. This is a temporary workaround. The real long term solution to problems like these is to address <rust-lang#53934>. This PR also includes a drive-by edit to the panic message emitted by compiletest because "ui" test suite now uses `//`@`` directives. Fixes rust-lang#121330.
- Loading branch information
Showing
5 changed files
with
59 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
18 changes: 18 additions & 0 deletions
18
tests/ui/lint/ambiguous_wide_pointer_comparisons_suggestions.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|