From d4b514f982e4214e0f9237c905670b1207ae0c95 Mon Sep 17 00:00:00 2001 From: Urgau Date: Sun, 18 Feb 2024 15:23:03 +0100 Subject: [PATCH] Add detection of [Partial]Ord methods to the ambiguous wide ptr cmp lint --- compiler/rustc_lint/src/lints.rs | 14 +- compiler/rustc_lint/src/types.rs | 58 +++-- library/core/src/ptr/const_ptr.rs | 1 + library/core/src/ptr/metadata.rs | 1 + library/core/src/ptr/mut_ptr.rs | 1 + library/core/src/ptr/non_null.rs | 2 + tests/ui/lint/wide_pointer_comparisons.rs | 24 ++ tests/ui/lint/wide_pointer_comparisons.stderr | 238 ++++++++++++++---- 8 files changed, 257 insertions(+), 82 deletions(-) diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 1dac2d89c6b..cf3890dc61c 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -1668,14 +1668,16 @@ pub enum AmbiguousWidePointerComparisonsAddrSuggestion<'a> { Cast { deref_left: &'a str, deref_right: &'a str, - #[suggestion_part(code = "{deref_left}")] + paren_left: &'a str, + paren_right: &'a str, + #[suggestion_part(code = "({deref_left}")] left_before: Option, - #[suggestion_part(code = " as *const ()")] - left: Span, - #[suggestion_part(code = "{deref_right}")] + #[suggestion_part(code = "{paren_left}.cast::<()>()")] + left_after: Span, + #[suggestion_part(code = "({deref_right}")] right_before: Option, - #[suggestion_part(code = " as *const ()")] - right: Span, + #[suggestion_part(code = "{paren_right}.cast::<()>()")] + right_after: Span, }, } diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 5331d2fb752..68cc024d9c7 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -657,10 +657,16 @@ fn eq_ne( cx.emit_span_lint(INVALID_NAN_COMPARISONS, e.span, lint); } +#[derive(Debug, PartialEq)] +enum ComparisonOp { + BinOp(hir::BinOpKind), + Other, +} + fn lint_wide_pointer<'tcx>( cx: &LateContext<'tcx>, e: &'tcx hir::Expr<'tcx>, - binop: hir::BinOpKind, + cmpop: ComparisonOp, l: &'tcx hir::Expr<'tcx>, r: &'tcx hir::Expr<'tcx>, ) { @@ -679,7 +685,7 @@ fn lint_wide_pointer<'tcx>( } }; - // PartialEq::{eq,ne} takes references, remove any explicit references + // the left and right operands can have references, remove any explicit references let l = l.peel_borrows(); let r = r.peel_borrows(); @@ -707,8 +713,8 @@ fn lint_wide_pointer<'tcx>( ); }; - let ne = if binop == hir::BinOpKind::Ne { "!" } else { "" }; - let is_eq_ne = matches!(binop, hir::BinOpKind::Eq | hir::BinOpKind::Ne); + let ne = if cmpop == ComparisonOp::BinOp(hir::BinOpKind::Ne) { "!" } else { "" }; + let is_eq_ne = matches!(cmpop, ComparisonOp::BinOp(hir::BinOpKind::Eq | hir::BinOpKind::Ne)); let is_dyn_comparison = l_inner_ty_is_dyn && r_inner_ty_is_dyn; let left = e.span.shrink_to_lo().until(l_span.shrink_to_lo()); @@ -745,12 +751,12 @@ fn lint_wide_pointer<'tcx>( AmbiguousWidePointerComparisonsAddrSuggestion::Cast { deref_left, deref_right, - // those two Options are required for correctness as having - // an empty span and an empty suggestion is not permitted - left_before: (l_ty_refs != 0).then_some(left), - right_before: (r_ty_refs != 0).then(|| r_span.shrink_to_lo()), - left: l_span.shrink_to_hi(), - right, + paren_left: if l_ty_refs != 0 { ")" } else { "" }, + paren_right: if r_ty_refs != 0 { ")" } else { "" }, + left_before: (l_ty_refs != 0).then_some(l_span.shrink_to_lo()), + left_after: l_span.shrink_to_hi(), + right_before: (r_ty_refs != 0).then_some(r_span.shrink_to_lo()), + right_after: r_span.shrink_to_hi(), } }, }, @@ -773,7 +779,7 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx hir::Expr<'tcx>) { cx.emit_span_lint(UNUSED_COMPARISONS, e.span, UnusedComparisons); } else { lint_nan(cx, e, binop, l, r); - lint_wide_pointer(cx, e, binop.node, l, r); + lint_wide_pointer(cx, e, ComparisonOp::BinOp(binop.node), l, r); } } } @@ -782,16 +788,16 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx hir::Expr<'tcx>) { if let ExprKind::Path(ref qpath) = path.kind && let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id() && let Some(diag_item) = cx.tcx.get_diagnostic_name(def_id) - && let Some(binop) = partialeq_binop(diag_item) => + && let Some(cmpop) = diag_item_cmpop(diag_item) => { - lint_wide_pointer(cx, e, binop, l, r); + lint_wide_pointer(cx, e, cmpop, l, r); } hir::ExprKind::MethodCall(_, l, [r], _) if let Some(def_id) = cx.typeck_results().type_dependent_def_id(e.hir_id) && let Some(diag_item) = cx.tcx.get_diagnostic_name(def_id) - && let Some(binop) = partialeq_binop(diag_item) => + && let Some(cmpop) = diag_item_cmpop(diag_item) => { - lint_wide_pointer(cx, e, binop, l, r); + lint_wide_pointer(cx, e, cmpop, l, r); } _ => {} }; @@ -876,14 +882,20 @@ fn is_comparison(binop: hir::BinOp) -> bool { ) } - fn partialeq_binop(diag_item: Symbol) -> Option { - if diag_item == sym::cmp_partialeq_eq { - Some(hir::BinOpKind::Eq) - } else if diag_item == sym::cmp_partialeq_ne { - Some(hir::BinOpKind::Ne) - } else { - None - } + fn diag_item_cmpop(diag_item: Symbol) -> Option { + Some(match diag_item { + sym::cmp_ord_max => ComparisonOp::Other, + sym::cmp_ord_min => ComparisonOp::Other, + sym::ord_cmp_method => ComparisonOp::Other, + sym::cmp_partialeq_eq => ComparisonOp::BinOp(hir::BinOpKind::Eq), + sym::cmp_partialeq_ne => ComparisonOp::BinOp(hir::BinOpKind::Ne), + sym::cmp_partialord_cmp => ComparisonOp::Other, + sym::cmp_partialord_ge => ComparisonOp::BinOp(hir::BinOpKind::Ge), + sym::cmp_partialord_gt => ComparisonOp::BinOp(hir::BinOpKind::Gt), + sym::cmp_partialord_le => ComparisonOp::BinOp(hir::BinOpKind::Le), + sym::cmp_partialord_lt => ComparisonOp::BinOp(hir::BinOpKind::Lt), + _ => return None, + }) } } } diff --git a/library/core/src/ptr/const_ptr.rs b/library/core/src/ptr/const_ptr.rs index a6c00ff28d4..4081ad124d3 100644 --- a/library/core/src/ptr/const_ptr.rs +++ b/library/core/src/ptr/const_ptr.rs @@ -1857,6 +1857,7 @@ fn cmp(&self, other: &*const T) -> Ordering { #[stable(feature = "rust1", since = "1.0.0")] impl PartialOrd for *const T { #[inline] + #[allow(ambiguous_wide_pointer_comparisons)] fn partial_cmp(&self, other: &*const T) -> Option { Some(self.cmp(other)) } diff --git a/library/core/src/ptr/metadata.rs b/library/core/src/ptr/metadata.rs index fe19f66a31a..7f9d8e677d2 100644 --- a/library/core/src/ptr/metadata.rs +++ b/library/core/src/ptr/metadata.rs @@ -258,6 +258,7 @@ fn eq(&self, other: &Self) -> bool { impl Ord for DynMetadata { #[inline] + #[allow(ambiguous_wide_pointer_comparisons)] fn cmp(&self, other: &Self) -> crate::cmp::Ordering { (self.vtable_ptr as *const VTable).cmp(&(other.vtable_ptr as *const VTable)) } diff --git a/library/core/src/ptr/mut_ptr.rs b/library/core/src/ptr/mut_ptr.rs index 1add9ca2311..2ff7d829918 100644 --- a/library/core/src/ptr/mut_ptr.rs +++ b/library/core/src/ptr/mut_ptr.rs @@ -2275,6 +2275,7 @@ fn cmp(&self, other: &*mut T) -> Ordering { #[stable(feature = "rust1", since = "1.0.0")] impl PartialOrd for *mut T { #[inline(always)] + #[allow(ambiguous_wide_pointer_comparisons)] fn partial_cmp(&self, other: &*mut T) -> Option { Some(self.cmp(other)) } diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index e9488917acc..70e6f3f9e79 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -1821,6 +1821,7 @@ fn eq(&self, other: &Self) -> bool { #[stable(feature = "nonnull", since = "1.25.0")] impl Ord for NonNull { #[inline] + #[allow(ambiguous_wide_pointer_comparisons)] fn cmp(&self, other: &Self) -> Ordering { self.as_ptr().cmp(&other.as_ptr()) } @@ -1829,6 +1830,7 @@ fn cmp(&self, other: &Self) -> Ordering { #[stable(feature = "nonnull", since = "1.25.0")] impl PartialOrd for NonNull { #[inline] + #[allow(ambiguous_wide_pointer_comparisons)] fn partial_cmp(&self, other: &Self) -> Option { self.as_ptr().partial_cmp(&other.as_ptr()) } diff --git a/tests/ui/lint/wide_pointer_comparisons.rs b/tests/ui/lint/wide_pointer_comparisons.rs index 31369001075..bc4b3cecabc 100644 --- a/tests/ui/lint/wide_pointer_comparisons.rs +++ b/tests/ui/lint/wide_pointer_comparisons.rs @@ -37,6 +37,18 @@ fn main() { //~^ WARN ambiguous wide pointer comparison let _ = a.ne(&b); //~^ WARN ambiguous wide pointer comparison + let _ = a.cmp(&b); + //~^ WARN ambiguous wide pointer comparison + let _ = a.partial_cmp(&b); + //~^ WARN ambiguous wide pointer comparison + let _ = a.le(&b); + //~^ WARN ambiguous wide pointer comparison + let _ = a.lt(&b); + //~^ WARN ambiguous wide pointer comparison + let _ = a.ge(&b); + //~^ WARN ambiguous wide pointer comparison + let _ = a.gt(&b); + //~^ WARN ambiguous wide pointer comparison { // &*const ?Sized @@ -68,6 +80,18 @@ fn main() { //~^ WARN ambiguous wide pointer comparison let _ = a.ne(b); //~^ WARN ambiguous wide pointer comparison + let _ = a.cmp(&b); + //~^ WARN ambiguous wide pointer comparison + let _ = a.partial_cmp(&b); + //~^ WARN ambiguous wide pointer comparison + let _ = a.le(&b); + //~^ WARN ambiguous wide pointer comparison + let _ = a.lt(&b); + //~^ WARN ambiguous wide pointer comparison + let _ = a.ge(&b); + //~^ WARN ambiguous wide pointer comparison + let _ = a.gt(&b); + //~^ WARN ambiguous wide pointer comparison } let s = "" as *const str; diff --git a/tests/ui/lint/wide_pointer_comparisons.stderr b/tests/ui/lint/wide_pointer_comparisons.stderr index 6ef117c63c5..8140f9fa5aa 100644 --- a/tests/ui/lint/wide_pointer_comparisons.stderr +++ b/tests/ui/lint/wide_pointer_comparisons.stderr @@ -29,8 +29,8 @@ LL | let _ = a < b; | help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses | -LL | let _ = a as *const () < b as *const (); - | ++++++++++++ ++++++++++++ +LL | let _ = a.cast::<()>() < b.cast::<()>(); + | +++++++++++++ +++++++++++++ warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected --> $DIR/wide_pointer_comparisons.rs:25:13 @@ -40,8 +40,8 @@ LL | let _ = a <= b; | help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses | -LL | let _ = a as *const () <= b as *const (); - | ++++++++++++ ++++++++++++ +LL | let _ = a.cast::<()>() <= b.cast::<()>(); + | +++++++++++++ +++++++++++++ warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected --> $DIR/wide_pointer_comparisons.rs:27:13 @@ -51,8 +51,8 @@ LL | let _ = a > b; | help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses | -LL | let _ = a as *const () > b as *const (); - | ++++++++++++ ++++++++++++ +LL | let _ = a.cast::<()>() > b.cast::<()>(); + | +++++++++++++ +++++++++++++ warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected --> $DIR/wide_pointer_comparisons.rs:29:13 @@ -62,8 +62,8 @@ LL | let _ = a >= b; | help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses | -LL | let _ = a as *const () >= b as *const (); - | ++++++++++++ ++++++++++++ +LL | let _ = a.cast::<()>() >= b.cast::<()>(); + | +++++++++++++ +++++++++++++ warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected --> $DIR/wide_pointer_comparisons.rs:32:13 @@ -110,7 +110,73 @@ LL | let _ = !std::ptr::addr_eq(a, b); | +++++++++++++++++++ ~ ~ warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:46:17 + --> $DIR/wide_pointer_comparisons.rs:40:13 + | +LL | let _ = a.cmp(&b); + | ^^^^^^^^^ + | +help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses + | +LL | let _ = a.cast::<()>().cmp(&b.cast::<()>()); + | +++++++++++++ +++++++++++++ + +warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected + --> $DIR/wide_pointer_comparisons.rs:42:13 + | +LL | let _ = a.partial_cmp(&b); + | ^^^^^^^^^^^^^^^^^ + | +help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses + | +LL | let _ = a.cast::<()>().partial_cmp(&b.cast::<()>()); + | +++++++++++++ +++++++++++++ + +warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected + --> $DIR/wide_pointer_comparisons.rs:44:13 + | +LL | let _ = a.le(&b); + | ^^^^^^^^ + | +help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses + | +LL | let _ = a.cast::<()>().le(&b.cast::<()>()); + | +++++++++++++ +++++++++++++ + +warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected + --> $DIR/wide_pointer_comparisons.rs:46:13 + | +LL | let _ = a.lt(&b); + | ^^^^^^^^ + | +help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses + | +LL | let _ = a.cast::<()>().lt(&b.cast::<()>()); + | +++++++++++++ +++++++++++++ + +warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected + --> $DIR/wide_pointer_comparisons.rs:48:13 + | +LL | let _ = a.ge(&b); + | ^^^^^^^^ + | +help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses + | +LL | let _ = a.cast::<()>().ge(&b.cast::<()>()); + | +++++++++++++ +++++++++++++ + +warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected + --> $DIR/wide_pointer_comparisons.rs:50:13 + | +LL | let _ = a.gt(&b); + | ^^^^^^^^ + | +help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses + | +LL | let _ = a.cast::<()>().gt(&b.cast::<()>()); + | +++++++++++++ +++++++++++++ + +warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected + --> $DIR/wide_pointer_comparisons.rs:58:17 | LL | let _ = a == b; | ^^^^^^ @@ -121,7 +187,7 @@ LL | let _ = std::ptr::addr_eq(*a, *b); | +++++++++++++++++++ ~~~ + warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:48:17 + --> $DIR/wide_pointer_comparisons.rs:60:17 | LL | let _ = a != b; | ^^^^^^ @@ -132,51 +198,51 @@ LL | let _ = !std::ptr::addr_eq(*a, *b); | ++++++++++++++++++++ ~~~ + warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:50:17 + --> $DIR/wide_pointer_comparisons.rs:62:17 | LL | let _ = a < b; | ^^^^^ | help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses | -LL | let _ = *a as *const () < *b as *const (); - | + ++++++++++++ + ++++++++++++ +LL | let _ = (*a).cast::<()>() < (*b).cast::<()>(); + | ++ ++++++++++++++ ++ ++++++++++++++ warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:52:17 + --> $DIR/wide_pointer_comparisons.rs:64:17 | LL | let _ = a <= b; | ^^^^^^ | help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses | -LL | let _ = *a as *const () <= *b as *const (); - | + ++++++++++++ + ++++++++++++ +LL | let _ = (*a).cast::<()>() <= (*b).cast::<()>(); + | ++ ++++++++++++++ ++ ++++++++++++++ warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:54:17 + --> $DIR/wide_pointer_comparisons.rs:66:17 | LL | let _ = a > b; | ^^^^^ | help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses | -LL | let _ = *a as *const () > *b as *const (); - | + ++++++++++++ + ++++++++++++ +LL | let _ = (*a).cast::<()>() > (*b).cast::<()>(); + | ++ ++++++++++++++ ++ ++++++++++++++ warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:56:17 + --> $DIR/wide_pointer_comparisons.rs:68:17 | LL | let _ = a >= b; | ^^^^^^ | help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses | -LL | let _ = *a as *const () >= *b as *const (); - | + ++++++++++++ + ++++++++++++ +LL | let _ = (*a).cast::<()>() >= (*b).cast::<()>(); + | ++ ++++++++++++++ ++ ++++++++++++++ warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:59:17 + --> $DIR/wide_pointer_comparisons.rs:71:17 | LL | let _ = PartialEq::eq(a, b); | ^^^^^^^^^^^^^^^^^^^ @@ -187,7 +253,7 @@ LL | let _ = std::ptr::addr_eq(*a, *b); | ~~~~~~~~~~~~~~~~~~~ ~~~ ~ warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:61:17 + --> $DIR/wide_pointer_comparisons.rs:73:17 | LL | let _ = PartialEq::ne(a, b); | ^^^^^^^^^^^^^^^^^^^ @@ -198,7 +264,7 @@ LL | let _ = !std::ptr::addr_eq(*a, *b); | ~~~~~~~~~~~~~~~~~~~~ ~~~ ~ warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:63:17 + --> $DIR/wide_pointer_comparisons.rs:75:17 | LL | let _ = PartialEq::eq(&a, &b); | ^^^^^^^^^^^^^^^^^^^^^ @@ -209,7 +275,7 @@ LL | let _ = std::ptr::addr_eq(*a, *b); | ~~~~~~~~~~~~~~~~~~~ ~~~ ~ warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:65:17 + --> $DIR/wide_pointer_comparisons.rs:77:17 | LL | let _ = PartialEq::ne(&a, &b); | ^^^^^^^^^^^^^^^^^^^^^ @@ -220,7 +286,7 @@ LL | let _ = !std::ptr::addr_eq(*a, *b); | ~~~~~~~~~~~~~~~~~~~~ ~~~ ~ warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:67:17 + --> $DIR/wide_pointer_comparisons.rs:79:17 | LL | let _ = a.eq(b); | ^^^^^^^ @@ -231,7 +297,7 @@ LL | let _ = std::ptr::addr_eq(*a, *b); | +++++++++++++++++++ ~~~ ~ warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:69:17 + --> $DIR/wide_pointer_comparisons.rs:81:17 | LL | let _ = a.ne(b); | ^^^^^^^ @@ -242,7 +308,73 @@ LL | let _ = !std::ptr::addr_eq(*a, *b); | ++++++++++++++++++++ ~~~ ~ warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:74:13 + --> $DIR/wide_pointer_comparisons.rs:83:17 + | +LL | let _ = a.cmp(&b); + | ^^^^^^^^^ + | +help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses + | +LL | let _ = (*a).cast::<()>().cmp(&(*b).cast::<()>()); + | ++ ++++++++++++++ ++ ++++++++++++++ + +warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected + --> $DIR/wide_pointer_comparisons.rs:85:17 + | +LL | let _ = a.partial_cmp(&b); + | ^^^^^^^^^^^^^^^^^ + | +help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses + | +LL | let _ = (*a).cast::<()>().partial_cmp(&(*b).cast::<()>()); + | ++ ++++++++++++++ ++ ++++++++++++++ + +warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected + --> $DIR/wide_pointer_comparisons.rs:87:17 + | +LL | let _ = a.le(&b); + | ^^^^^^^^ + | +help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses + | +LL | let _ = (*a).cast::<()>().le(&(*b).cast::<()>()); + | ++ ++++++++++++++ ++ ++++++++++++++ + +warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected + --> $DIR/wide_pointer_comparisons.rs:89:17 + | +LL | let _ = a.lt(&b); + | ^^^^^^^^ + | +help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses + | +LL | let _ = (*a).cast::<()>().lt(&(*b).cast::<()>()); + | ++ ++++++++++++++ ++ ++++++++++++++ + +warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected + --> $DIR/wide_pointer_comparisons.rs:91:17 + | +LL | let _ = a.ge(&b); + | ^^^^^^^^ + | +help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses + | +LL | let _ = (*a).cast::<()>().ge(&(*b).cast::<()>()); + | ++ ++++++++++++++ ++ ++++++++++++++ + +warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected + --> $DIR/wide_pointer_comparisons.rs:93:17 + | +LL | let _ = a.gt(&b); + | ^^^^^^^^ + | +help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses + | +LL | let _ = (*a).cast::<()>().gt(&(*b).cast::<()>()); + | ++ ++++++++++++++ ++ ++++++++++++++ + +warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected + --> $DIR/wide_pointer_comparisons.rs:98:13 | LL | let _ = s == s; | ^^^^^^ @@ -257,7 +389,7 @@ LL | let _ = std::ptr::eq(s, s); | +++++++++++++ ~ + warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:78:13 + --> $DIR/wide_pointer_comparisons.rs:102:13 | LL | let _ = s == s; | ^^^^^^ @@ -272,7 +404,7 @@ LL | let _ = std::ptr::eq(s, s); | +++++++++++++ ~ + warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:82:17 + --> $DIR/wide_pointer_comparisons.rs:106:17 | LL | let _ = a == b; | ^^^^^^ @@ -287,7 +419,7 @@ LL | let _ = std::ptr::eq(a, b); | +++++++++++++ ~ + warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:84:17 + --> $DIR/wide_pointer_comparisons.rs:108:17 | LL | let _ = a != b; | ^^^^^^ @@ -302,51 +434,51 @@ LL | let _ = !std::ptr::eq(a, b); | ++++++++++++++ ~ + warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:86:17 + --> $DIR/wide_pointer_comparisons.rs:110:17 | LL | let _ = a < b; | ^^^^^ | help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses | -LL | let _ = a as *const () < b as *const (); - | ++++++++++++ ++++++++++++ +LL | let _ = a.cast::<()>() < b.cast::<()>(); + | +++++++++++++ +++++++++++++ warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:88:17 + --> $DIR/wide_pointer_comparisons.rs:112:17 | LL | let _ = a <= b; | ^^^^^^ | help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses | -LL | let _ = a as *const () <= b as *const (); - | ++++++++++++ ++++++++++++ +LL | let _ = a.cast::<()>() <= b.cast::<()>(); + | +++++++++++++ +++++++++++++ warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:90:17 + --> $DIR/wide_pointer_comparisons.rs:114:17 | LL | let _ = a > b; | ^^^^^ | help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses | -LL | let _ = a as *const () > b as *const (); - | ++++++++++++ ++++++++++++ +LL | let _ = a.cast::<()>() > b.cast::<()>(); + | +++++++++++++ +++++++++++++ warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:92:17 + --> $DIR/wide_pointer_comparisons.rs:116:17 | LL | let _ = a >= b; | ^^^^^^ | help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses | -LL | let _ = a as *const () >= b as *const (); - | ++++++++++++ ++++++++++++ +LL | let _ = a.cast::<()>() >= b.cast::<()>(); + | +++++++++++++ +++++++++++++ warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:95:17 + --> $DIR/wide_pointer_comparisons.rs:119:17 | LL | let _ = PartialEq::eq(&a, &b); | ^^^^^^^^^^^^^^^^^^^^^ @@ -361,7 +493,7 @@ LL | let _ = std::ptr::eq(a, b); | ~~~~~~~~~~~~~ ~ ~ warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:97:17 + --> $DIR/wide_pointer_comparisons.rs:121:17 | LL | let _ = PartialEq::ne(&a, &b); | ^^^^^^^^^^^^^^^^^^^^^ @@ -376,7 +508,7 @@ LL | let _ = !std::ptr::eq(a, b); | ~~~~~~~~~~~~~~ ~ ~ warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:99:17 + --> $DIR/wide_pointer_comparisons.rs:123:17 | LL | let _ = a.eq(&b); | ^^^^^^^^ @@ -391,7 +523,7 @@ LL | let _ = std::ptr::eq(a, b); | +++++++++++++ ~ ~ warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:101:17 + --> $DIR/wide_pointer_comparisons.rs:125:17 | LL | let _ = a.ne(&b); | ^^^^^^^^ @@ -406,7 +538,7 @@ LL | let _ = !std::ptr::eq(a, b); | ++++++++++++++ ~ ~ warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:106:9 + --> $DIR/wide_pointer_comparisons.rs:130:9 | LL | &*a == &*b | ^^^^^^^^^^ @@ -421,7 +553,7 @@ LL | std::ptr::eq(*a, *b) | ~~~~~~~~~~~~~ ~ + warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:117:14 + --> $DIR/wide_pointer_comparisons.rs:141:14 | LL | cmp!(a, b); | ^^^^ @@ -432,7 +564,7 @@ LL | cmp!(std::ptr::addr_eq(a, b)); | ++++++++++++++++++ ~ + warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:123:39 + --> $DIR/wide_pointer_comparisons.rs:147:39 | LL | ($a:ident, $b:ident) => { $a == $b } | ^^^^^^^^ @@ -447,7 +579,7 @@ LL | ($a:ident, $b:ident) => { std::ptr::addr_eq($a, $b) } | ++++++++++++++++++ ~ + warning: ambiguous wide pointer comparison, the comparison includes metadata which may not be expected - --> $DIR/wide_pointer_comparisons.rs:133:37 + --> $DIR/wide_pointer_comparisons.rs:157:37 | LL | ($a:expr, $b:expr) => { $a == $b } | ^^ @@ -459,5 +591,5 @@ LL | cmp!(&a, &b); = help: use `std::ptr::addr_eq` or untyped pointers to only compare their addresses = note: this warning originates in the macro `cmp` (in Nightly builds, run with -Z macro-backtrace for more info) -warning: 38 warnings emitted +warning: 50 warnings emitted