Skip to content

Commit 856d335

Browse files
authored
Unrolled build for rust-lang#121338
Rollup merge of rust-lang#121338 - jieyouxu:ambiguous_wide_pointer_comparisons_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.
2 parents bb8b11e + 4d386d9 commit 856d335

File tree

5 files changed

+59
-7
lines changed

5 files changed

+59
-7
lines changed

compiler/rustc_lint/src/lints.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1582,7 +1582,8 @@ pub enum AmbiguousWidePointerComparisons<'a> {
15821582
#[multipart_suggestion(
15831583
lint_addr_metadata_suggestion,
15841584
style = "verbose",
1585-
applicability = "machine-applicable"
1585+
// FIXME(#53934): make machine-applicable again
1586+
applicability = "maybe-incorrect"
15861587
)]
15871588
pub struct AmbiguousWidePointerComparisonsAddrMetadataSuggestion<'a> {
15881589
pub ne: &'a str,
@@ -1601,7 +1602,8 @@ pub enum AmbiguousWidePointerComparisonsAddrSuggestion<'a> {
16011602
#[multipart_suggestion(
16021603
lint_addr_suggestion,
16031604
style = "verbose",
1604-
applicability = "machine-applicable"
1605+
// FIXME(#53934): make machine-applicable again
1606+
applicability = "maybe-incorrect"
16051607
)]
16061608
AddrEq {
16071609
ne: &'a str,
@@ -1617,7 +1619,8 @@ pub enum AmbiguousWidePointerComparisonsAddrSuggestion<'a> {
16171619
#[multipart_suggestion(
16181620
lint_addr_suggestion,
16191621
style = "verbose",
1620-
applicability = "machine-applicable"
1622+
// FIXME(#53934): make machine-applicable again
1623+
applicability = "maybe-incorrect"
16211624
)]
16221625
Cast {
16231626
deref_left: &'a str,

src/tools/compiletest/src/runtest.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -3938,10 +3938,15 @@ impl<'test> TestCx<'test> {
39383938
self.props.compare_output_lines_by_subset,
39393939
);
39403940
} else if !expected_fixed.is_empty() {
3941-
panic!(
3942-
"the `// run-rustfix` directive wasn't found but a `*.fixed` \
3943-
file was found"
3944-
);
3941+
if self.config.suite == "ui" {
3942+
panic!(
3943+
"the `//@ run-rustfix` directive wasn't found but a `*.fixed` file was found"
3944+
);
3945+
} else {
3946+
panic!(
3947+
"the `// run-rustfix` directive wasn't found but a `*.fixed` file was found"
3948+
);
3949+
}
39453950
}
39463951

39473952
if errors > 0 {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ run-rustfix
2+
//@ rustfix-only-machine-applicable
3+
//@ check-pass
4+
5+
// See <https://github.com/rust-lang/rust/issues/121330>.
6+
7+
fn cmp<T: ?Sized>(a: *mut T, b: *mut T) -> bool {
8+
let _ = a == b;
9+
//~^ WARN ambiguous wide pointer comparison
10+
panic!();
11+
}
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ run-rustfix
2+
//@ rustfix-only-machine-applicable
3+
//@ check-pass
4+
5+
// See <https://github.com/rust-lang/rust/issues/121330>.
6+
7+
fn cmp<T: ?Sized>(a: *mut T, b: *mut T) -> bool {
8+
let _ = a == b;
9+
//~^ WARN ambiguous wide pointer comparison
10+
panic!();
11+
}
12+
13+
fn main() {}
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:8:13
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)