mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
Auto merge of #121268 - Urgau:improve_ambi_wide_ptr_cmps, r=Nadrieril
Add detection of [Partial]Ord methods in the `ambiguous_wide_pointer_comparisons` lint Partially addresses https://github.com/rust-lang/rust/issues/121264 by adding diagnostics items for PartialOrd and Ord methods, detecting such diagnostics items as "binary operation" and suggesting the correct replacement. I also took the opportunity to change the suggestion to use new methods `.cast()` on `*mut T` an d `*const T`.
This commit is contained in:
commit
af4a5a13a1
@ -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<Span>,
|
||||
#[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<Span>,
|
||||
#[suggestion_part(code = " as *const ()")]
|
||||
right: Span,
|
||||
#[suggestion_part(code = "{paren_right}.cast::<()>()")]
|
||||
right_after: Span,
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -657,10 +657,16 @@ fn lint_nan<'tcx>(
|
||||
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 @@ impl<'tcx> LateLintPass<'tcx> for TypeLimits {
|
||||
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 @@ impl<'tcx> LateLintPass<'tcx> for TypeLimits {
|
||||
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 @@ impl<'tcx> LateLintPass<'tcx> for TypeLimits {
|
||||
)
|
||||
}
|
||||
|
||||
fn partialeq_binop(diag_item: Symbol) -> Option<hir::BinOpKind> {
|
||||
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<ComparisonOp> {
|
||||
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,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -531,8 +531,15 @@ symbols! {
|
||||
cmp,
|
||||
cmp_max,
|
||||
cmp_min,
|
||||
cmp_ord_max,
|
||||
cmp_ord_min,
|
||||
cmp_partialeq_eq,
|
||||
cmp_partialeq_ne,
|
||||
cmp_partialord_cmp,
|
||||
cmp_partialord_ge,
|
||||
cmp_partialord_gt,
|
||||
cmp_partialord_le,
|
||||
cmp_partialord_lt,
|
||||
cmpxchg16b_target_feature,
|
||||
cmse_nonsecure_entry,
|
||||
coerce_unsized,
|
||||
|
@ -848,6 +848,7 @@ pub trait Ord: Eq + PartialOrd<Self> {
|
||||
#[stable(feature = "ord_max_min", since = "1.21.0")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "cmp_ord_max")]
|
||||
fn max(self, other: Self) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
@ -868,6 +869,7 @@ pub trait Ord: Eq + PartialOrd<Self> {
|
||||
#[stable(feature = "ord_max_min", since = "1.21.0")]
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "cmp_ord_min")]
|
||||
fn min(self, other: Self) -> Self
|
||||
where
|
||||
Self: Sized,
|
||||
@ -1154,6 +1156,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
|
||||
/// ```
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "cmp_partialord_cmp")]
|
||||
fn partial_cmp(&self, other: &Rhs) -> Option<Ordering>;
|
||||
|
||||
/// This method tests less than (for `self` and `other`) and is used by the `<` operator.
|
||||
@ -1168,6 +1171,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "cmp_partialord_lt")]
|
||||
fn lt(&self, other: &Rhs) -> bool {
|
||||
matches!(self.partial_cmp(other), Some(Less))
|
||||
}
|
||||
@ -1185,6 +1189,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "cmp_partialord_le")]
|
||||
fn le(&self, other: &Rhs) -> bool {
|
||||
matches!(self.partial_cmp(other), Some(Less | Equal))
|
||||
}
|
||||
@ -1201,6 +1206,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "cmp_partialord_gt")]
|
||||
fn gt(&self, other: &Rhs) -> bool {
|
||||
matches!(self.partial_cmp(other), Some(Greater))
|
||||
}
|
||||
@ -1218,6 +1224,7 @@ pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
|
||||
#[inline]
|
||||
#[must_use]
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
#[cfg_attr(not(bootstrap), rustc_diagnostic_item = "cmp_partialord_ge")]
|
||||
fn ge(&self, other: &Rhs) -> bool {
|
||||
matches!(self.partial_cmp(other), Some(Greater | Equal))
|
||||
}
|
||||
|
@ -1857,6 +1857,7 @@ impl<T: ?Sized> Ord for *const T {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T: ?Sized> PartialOrd for *const T {
|
||||
#[inline]
|
||||
#[allow(ambiguous_wide_pointer_comparisons)]
|
||||
fn partial_cmp(&self, other: &*const T) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
|
@ -258,6 +258,7 @@ impl<Dyn: ?Sized> PartialEq for DynMetadata<Dyn> {
|
||||
|
||||
impl<Dyn: ?Sized> Ord for DynMetadata<Dyn> {
|
||||
#[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))
|
||||
}
|
||||
|
@ -2275,6 +2275,7 @@ impl<T: ?Sized> Ord for *mut T {
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<T: ?Sized> PartialOrd for *mut T {
|
||||
#[inline(always)]
|
||||
#[allow(ambiguous_wide_pointer_comparisons)]
|
||||
fn partial_cmp(&self, other: &*mut T) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
|
@ -1821,6 +1821,7 @@ impl<T: ?Sized> PartialEq for NonNull<T> {
|
||||
#[stable(feature = "nonnull", since = "1.25.0")]
|
||||
impl<T: ?Sized> Ord for NonNull<T> {
|
||||
#[inline]
|
||||
#[allow(ambiguous_wide_pointer_comparisons)]
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.as_ptr().cmp(&other.as_ptr())
|
||||
}
|
||||
@ -1829,6 +1830,7 @@ impl<T: ?Sized> Ord for NonNull<T> {
|
||||
#[stable(feature = "nonnull", since = "1.25.0")]
|
||||
impl<T: ?Sized> PartialOrd for NonNull<T> {
|
||||
#[inline]
|
||||
#[allow(ambiguous_wide_pointer_comparisons)]
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
self.as_ptr().partial_cmp(&other.as_ptr())
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user