1use core::ops::ControlFlow;
2
3use rustc_abi::{FieldIdx, VariantIdx};
4use rustc_apfloat::Float;
5use rustc_data_structures::fx::FxHashSet;
6use rustc_errors::{Diag, msg};
7use rustc_hir as hir;
8use rustc_hir::attrs::lang_items::LangItem;
9use rustc_hir::find_attr;
10use rustc_index::Idx;
11use rustc_infer::infer::TyCtxtInferExt;
12use rustc_infer::traits::Obligation;
13use rustc_middle::mir::interpret::ErrorHandled;
14use rustc_middle::thir::{FieldPat, Pat, PatKind};
15use rustc_middle::ty::{
16 self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitableExt, TypeVisitor, Unnormalized,
17};
18use rustc_span::def_id::DefId;
19use rustc_span::{DUMMY_SP, Span, span_bug};
20use rustc_trait_selection::error_reporting::traits::ambiguity::{
21 CandidateSource, compute_applicable_impls_for_diagnostics,
22};
23use rustc_trait_selection::traits::ObligationCause;
24use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
25use tracing::{debug, instrument, trace};
26
27use super::PatCtxt;
28use crate::diagnostics::{
29 ConstPatternDependsOnGenericParameter, CouldNotEvalConstPattern, InvalidPattern, NaNPattern,
30 PointerPattern, SuggestEq, TypeNotPartialEq, TypeNotStructural, UnionPattern, UnsizedPattern,
31};
32
33impl<'tcx, 'ptcx> PatCtxt<'tcx, 'ptcx> {
34 {}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() || { false }
{
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("const_to_pat",
"rustc_mir_build::thir::pattern::const_to_pat",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs"),
::tracing_core::__macro_support::Option::Some(41u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::pattern::const_to_pat"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("c")
}> =
::tracing::__macro_support::FieldName::new("c");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("ty")
}> =
::tracing::__macro_support::FieldName::new("ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("id")
}> =
::tracing::__macro_support::FieldName::new("id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("span")
}> =
::tracing::__macro_support::FieldName::new("span");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&c)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy
:: needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: Box<Pat<'tcx>> = loop {};
return __tracing_attr_fake_return;
}
{
let mut convert = ConstToPat::new(self, id, span, c);
match c.kind() {
ty::ConstKind::Alias(_, alias_const) =>
convert.alias_to_pat(alias_const, ty),
ty::ConstKind::Value(value) =>
convert.valtree_to_pat(value),
_ =>
bug_impl(Some(span),
format_args!("Invalid `ConstKind` for `const_to_pat`: {0:?}",
c), Location::caller()),
}
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs:41",
"rustc_mir_build::thir::pattern::const_to_pat",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs"),
::tracing_core::__macro_support::Option::Some(41u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::pattern::const_to_pat"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "debug", skip(self), ret)]
42 pub(super) fn const_to_pat(
43 &self,
44 c: ty::Const<'tcx>,
45 ty: Ty<'tcx>,
46 id: hir::HirId,
47 span: Span,
48 ) -> Box<Pat<'tcx>> {
49 let mut convert = ConstToPat::new(self, id, span, c);
50
51 match c.kind() {
52 ty::ConstKind::Alias(_, alias_const) => convert.alias_to_pat(alias_const, ty),
53 ty::ConstKind::Value(value) => convert.valtree_to_pat(value),
54 _ => span_bug!(span, "Invalid `ConstKind` for `const_to_pat`: {:?}", c),
55 }
56 }
57}
58
59struct ConstToPat<'tcx> {
60 tcx: TyCtxt<'tcx>,
61 typing_env: ty::TypingEnv<'tcx>,
62 span: Span,
63 id: hir::HirId,
64
65 c: ty::Const<'tcx>,
66}
67
68impl<'tcx> ConstToPat<'tcx> {
69 fn new(pat_ctxt: &PatCtxt<'tcx, '_>, id: hir::HirId, span: Span, c: ty::Const<'tcx>) -> Self {
70 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs:70",
"rustc_mir_build::thir::pattern::const_to_pat",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs"),
::tracing_core::__macro_support::Option::Some(70u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::pattern::const_to_pat"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("pat_ctxt.typeck_results.hir_owner")
}> =
::tracing::__macro_support::FieldName::new("pat_ctxt.typeck_results.hir_owner");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&pat_ctxt.typeck_results.hir_owner)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};trace!(?pat_ctxt.typeck_results.hir_owner);
71 ConstToPat { tcx: pat_ctxt.tcx, typing_env: pat_ctxt.typing_env, span, id, c }
72 }
73
74 fn type_marked_structural(&self, ty: Ty<'tcx>) -> bool {
75 ty.is_structural_eq_shallow(self.tcx)
76 }
77
78 fn mk_err(&self, mut err: Diag<'_>, ty: Ty<'tcx>) -> Box<Pat<'tcx>> {
80 if let ty::ConstKind::Alias(_, alias_const) = self.c.kind() {
81 if let ty::AliasConstKind::Projection { def_id }
82 | ty::AliasConstKind::InherentSelf { def_id }
83 | ty::AliasConstKind::InherentImpl { def_id } = alias_const.kind
84 && let Some(def_id) = def_id.as_local()
85 {
86 err.span_label(self.tcx.def_span(self.tcx.local_parent(def_id)), "");
88 }
89 if let ty::AliasConstKind::Projection { def_id }
90 | ty::AliasConstKind::InherentSelf { def_id }
91 | ty::AliasConstKind::InherentImpl { def_id }
92 | ty::AliasConstKind::Free { def_id } = alias_const.kind
93 {
94 err.span_label(self.tcx.def_span(def_id), rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("constant defined here"))msg!("constant defined here"));
95 }
96 }
97 Box::new(Pat { span: self.span, ty, kind: PatKind::Error(err.emit()), extra: None })
98 }
99
100 fn alias_to_pat(&mut self, alias_const: ty::AliasConst<'tcx>, ty: Ty<'tcx>) -> Box<Pat<'tcx>> {
101 let typing_env =
109 self.tcx.erase_and_anonymize_regions(self.typing_env).with_codegen_normalized(self.tcx);
110 let alias_const = self.tcx.erase_and_anonymize_regions(alias_const);
111
112 let mk_too_generic_err = || {
113 let mut err = self
114 .tcx
115 .dcx()
116 .create_err(ConstPatternDependsOnGenericParameter { span: self.span });
117 for arg in alias_const.args {
118 if let ty::GenericArgKind::Type(ty) = arg.kind()
119 && let ty::Param(param_ty) = ty.kind()
120 {
121 let def_id = self.tcx.hir_enclosing_body_owner(self.id);
122 let generics = self.tcx.generics_of(def_id);
123 let param = generics.type_param(*param_ty, self.tcx);
124 let span = self.tcx.def_span(param.def_id);
125 err.span_label(span, "constant depends on this generic parameter");
126 if let Some(ident) = self.tcx.def_ident_span(def_id)
127 && self.tcx.sess.source_map().is_multiline(ident.between(span))
128 {
129 err.span_label(ident, "");
132 }
133 }
134 }
135 return self.mk_err(err, ty);
136 };
137
138 let const_value = if self.tcx.features().generic_const_args()
148 || alias_const.kind.is_direct_const(self.tcx)
149 {
150 let Ok(normalize) = self
151 .tcx
152 .try_normalize_erasing_regions(self.typing_env, Unnormalized::new_wip(self.c))
153 else {
154 let err = self.tcx.dcx().create_err(CouldNotEvalConstPattern { span: self.span });
155 return self.mk_err(err, ty);
156 };
157
158 let ty::ConstKind::Value(value) = normalize.kind() else {
159 let err = self.tcx.dcx().create_err(CouldNotEvalConstPattern { span: self.span });
160 return self.mk_err(err, ty);
161 };
162 value
163 } else {
164 let valtree =
167 match self.tcx.const_eval_resolve_for_typeck(typing_env, alias_const, self.span) {
168 Ok(Ok(c)) => c,
169 Err(ErrorHandled::Reported(_, _)) => {
170 let mut err =
172 self.tcx.dcx().create_err(CouldNotEvalConstPattern { span: self.span });
173 if let ty::ConstKind::Alias(_, alias_const) = self.c.kind()
176 && let ty::AliasConstKind::Projection { .. }
177 | ty::AliasConstKind::InherentSelf { .. }
178 | ty::AliasConstKind::InherentImpl { .. }
179 | ty::AliasConstKind::Free { .. } = alias_const.kind
180 {
181 err.downgrade_to_delayed_bug();
182 }
183 return self.mk_err(err, ty);
184 }
185 Err(ErrorHandled::TooGeneric(_)) => {
186 return mk_too_generic_err();
187 }
188 Ok(Err(bad_ty)) => {
189 let e = match bad_ty.kind() {
191 ty::Adt(def, ..) => {
192 if !def.is_union() {
::core::panicking::panic("assertion failed: def.is_union()")
};assert!(def.is_union());
193 self.tcx.dcx().create_err(UnionPattern { span: self.span })
194 }
195 ty::FnPtr(..) | ty::RawPtr(..) => {
196 self.tcx.dcx().create_err(PointerPattern { span: self.span })
197 }
198 _ => self.tcx.dcx().create_err(InvalidPattern {
199 span: self.span,
200 non_sm_ty: bad_ty,
201 prefix: bad_ty.prefix_string(self.tcx).to_string(),
202 }),
203 };
204 return self.mk_err(e, ty);
205 }
206 };
207
208 ty::Value { ty, valtree }
210 };
211 if const_value.ty.has_param() {
212 return mk_too_generic_err();
213 }
214 let mut thir_pat = self.valtree_to_pat(const_value);
215
216 if !thir_pat.references_error() {
217 if !type_has_partial_eq_impl(self.tcx, typing_env, ty).has_impl {
219 let mut err = self.tcx.dcx().create_err(TypeNotPartialEq { span: self.span, ty });
220 extend_type_not_partial_eq(self.tcx, typing_env, ty, &mut err);
221 return self.mk_err(err, ty);
222 }
223 }
224
225 thir_pat.extra.get_or_insert_default().expanded_const = alias_const.kind.opt_def_id();
228 thir_pat
229 }
230
231 fn lower_field_values_to_fieldpats(
232 &self,
233 values: impl Iterator<Item = ty::Value<'tcx>>,
234 ) -> Vec<FieldPat<'tcx>> {
235 values
236 .enumerate()
237 .map(|(index, value)| FieldPat {
238 field: FieldIdx::new(index),
239 pattern: *self.valtree_to_pat(value),
240 })
241 .collect()
242 }
243
244 {}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("valtree_to_pat",
"rustc_mir_build::thir::pattern::const_to_pat",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs"),
::tracing_core::__macro_support::Option::Some(245u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::pattern::const_to_pat"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("value")
}> =
::tracing::__macro_support::FieldName::new("value");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&value)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: Box<Pat<'tcx>> = loop {};
return __tracing_attr_fake_return;
}
{
let span = self.span;
let tcx = self.tcx;
let ty::Value { ty, valtree } = value;
let kind =
match ty.kind() {
ty::Adt(adt_def, _) if !self.type_marked_structural(ty) => {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs:257",
"rustc_mir_build::thir::pattern::const_to_pat",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs"),
::tracing_core::__macro_support::Option::Some(257u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::pattern::const_to_pat"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("adt_def")
}> =
::tracing::__macro_support::FieldName::new("adt_def");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("value.ty")
}> =
::tracing::__macro_support::FieldName::new("value.ty");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("ADT type in pattern is not `type_marked_structural`")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&adt_def)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&value.ty)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let PartialEqImplStatus {
is_derived,
possibly_inapplicable_structural_partial_eq,
non_blanket_impl,
possibly_inapplicable_derived_partial_eq,
has_impl, .. } =
type_has_partial_eq_impl(self.tcx, self.typing_env, ty);
if possibly_inapplicable_derived_partial_eq && !has_impl {
let mut err =
self.tcx.dcx().create_err(TypeNotPartialEq {
span: self.span,
ty,
});
extend_type_not_partial_eq(self.tcx, self.typing_env, ty,
&mut err);
return self.mk_err(err, ty);
}
let (manual_partialeq_impl_span,
manual_partialeq_impl_note) =
match (possibly_inapplicable_structural_partial_eq,
non_blanket_impl) {
(true, _) => (None, false),
(_, Some(def_id)) if def_id.is_local() && !is_derived => {
(Some(tcx.def_span(def_id)), false)
}
_ => (None, true),
};
let manual_partialeq_impl =
manual_partialeq_impl_note ||
manual_partialeq_impl_span.is_some();
let is_local = adt_def.did().is_local();
let ty_def_span = tcx.def_span(adt_def.did());
let suggestion =
if let Ok(name) =
tcx.sess.source_map().span_to_snippet(self.span) &&
(is_local || manual_partialeq_impl) {
let mut hir_id = self.id;
while let hir::Node::Pat(pat) = tcx.parent_hir_node(hir_id)
{
hir_id = pat.hir_id;
}
match tcx.parent_hir_node(hir_id) {
hir::Node::Arm(hir::Arm { pat, guard: None, .. }) => {
Some(SuggestEq::AddIf {
if_span: pat.span.shrink_to_hi(),
pat_span: self.span,
name,
ty,
manual_partialeq_impl,
})
}
hir::Node::Arm(hir::Arm { guard: Some(guard), .. }) => {
Some(SuggestEq::AddToIf {
span: guard.span.shrink_to_hi(),
pat_span: self.span,
name,
ty,
manual_partialeq_impl,
})
}
hir::Node::Expr(hir::Expr {
kind: hir::ExprKind::Let(let_expr), span, .. }) => {
if let_expr.pat.span == self.span {
Some(SuggestEq::ReplaceWithEq {
removal: span.until(self.span),
eq: self.span.between(let_expr.init.span),
ty,
manual_partialeq_impl,
})
} else if tcx.sess.edition().at_least_rust_2024() {
Some(SuggestEq::AddToLetChain {
span: span.shrink_to_hi(),
pat_span: self.span,
name,
ty,
manual_partialeq_impl,
})
} else { None }
}
hir::Node::LetStmt(let_stmt) if
let Some(init) = let_stmt.init &&
let Some(els) = let_stmt.els && init.span.ctxt().is_root()
&& els.span.ctxt().is_root() => {
Some(SuggestEq::ReplaceLetElseWithIf {
if_span: let_stmt.span.until(let_stmt.pat.span),
eq: let_stmt.pat.span.between(init.span),
else_span: init.span.between(els.span),
ty,
manual_partialeq_impl,
})
}
_ => None,
}
} else { None };
let err =
TypeNotStructural {
span,
ty,
ty_def_span,
manual_partialeq_impl_span,
manual_partialeq_impl_note,
is_local,
suggestion,
};
return self.mk_err(tcx.dcx().create_err(err), ty);
}
ty::Adt(adt_def, args) if adt_def.is_enum() => {
let (&variant_index, fields) =
valtree.to_branch().split_first().unwrap();
let variant_index =
VariantIdx::from_u32(variant_index.to_leaf().to_u32());
PatKind::Variant {
adt_def: *adt_def,
args,
variant_index,
subpatterns: self.lower_field_values_to_fieldpats(fields.iter().map(|ct|
ct.to_value())),
}
}
ty::Adt(def, _) => {
if !!def.is_union() {
::core::panicking::panic("assertion failed: !def.is_union()")
};
PatKind::Leaf {
subpatterns: self.lower_field_values_to_fieldpats(valtree.to_branch().iter().map(|ct|
ct.to_value())),
}
}
ty::Tuple(_) =>
PatKind::Leaf {
subpatterns: self.lower_field_values_to_fieldpats(valtree.to_branch().iter().map(|ct|
ct.to_value())),
},
ty::Slice(_) =>
PatKind::Slice {
prefix: valtree.to_branch().iter().map(|val|
*self.valtree_to_pat(val.to_value())).collect(),
slice: None,
suffix: Box::new([]),
},
ty::Array(_, _) =>
PatKind::Array {
prefix: valtree.to_branch().iter().map(|val|
*self.valtree_to_pat(val.to_value())).collect(),
slice: None,
suffix: Box::new([]),
},
ty::Str => { PatKind::Constant { value } }
ty::Ref(_, pointee_ty, ..) => {
if pointee_ty.is_str() || pointee_ty.is_slice() ||
pointee_ty.is_sized(tcx, self.typing_env) {
PatKind::Deref {
pin: hir::Pinnedness::Not,
subpattern: self.valtree_to_pat(ty::Value {
ty: *pointee_ty,
valtree,
}),
}
} else {
return self.mk_err(tcx.dcx().create_err(UnsizedPattern {
span,
non_sm_ty: *pointee_ty,
}), ty);
}
}
ty::Float(flt) => {
let v = valtree.to_leaf();
let is_nan =
match flt {
ty::FloatTy::F16 => v.to_f16().is_nan(),
ty::FloatTy::F32 => v.to_f32().is_nan(),
ty::FloatTy::F64 => v.to_f64().is_nan(),
ty::FloatTy::F128 => v.to_f128().is_nan(),
};
if is_nan {
return self.mk_err(tcx.dcx().create_err(NaNPattern {
span,
}), ty);
} else { PatKind::Constant { value } }
}
ty::Pat(..) | ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_)
| ty::RawPtr(..) => {
PatKind::Constant { value }
}
ty::FnPtr(..) => {
{
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("Valtree construction would never succeed for FnPtr, so this is unreachable.")));
}
}
_ => {
let err =
InvalidPattern {
span,
non_sm_ty: ty,
prefix: ty.prefix_string(tcx).to_string(),
};
return self.mk_err(tcx.dcx().create_err(err), ty);
}
};
Box::new(Pat { span, ty, kind, extra: None })
}
}
}#[instrument(skip(self), level = "debug")]
246 fn valtree_to_pat(&self, value: ty::Value<'tcx>) -> Box<Pat<'tcx>> {
247 let span = self.span;
248 let tcx = self.tcx;
249 let ty::Value { ty, valtree } = value;
250
251 let kind = match ty.kind() {
252 ty::Adt(adt_def, _) if !self.type_marked_structural(ty) => {
256 debug!(?adt_def, ?value.ty, "ADT type in pattern is not `type_marked_structural`");
258 let PartialEqImplStatus {
259 is_derived,
260 possibly_inapplicable_structural_partial_eq,
261 non_blanket_impl,
262 possibly_inapplicable_derived_partial_eq,
263 has_impl,
264 ..
265 } = type_has_partial_eq_impl(self.tcx, self.typing_env, ty);
266
267 if possibly_inapplicable_derived_partial_eq && !has_impl {
274 let mut err =
275 self.tcx.dcx().create_err(TypeNotPartialEq { span: self.span, ty });
276 extend_type_not_partial_eq(self.tcx, self.typing_env, ty, &mut err);
277 return self.mk_err(err, ty);
278 }
279
280 let (manual_partialeq_impl_span, manual_partialeq_impl_note) =
281 match (possibly_inapplicable_structural_partial_eq, non_blanket_impl) {
282 (true, _) => (None, false),
283 (_, Some(def_id)) if def_id.is_local() && !is_derived => {
284 (Some(tcx.def_span(def_id)), false)
285 }
286 _ => (None, true),
287 };
288 let manual_partialeq_impl =
289 manual_partialeq_impl_note || manual_partialeq_impl_span.is_some();
290 let is_local = adt_def.did().is_local();
291 let ty_def_span = tcx.def_span(adt_def.did());
292 let suggestion = if let Ok(name) = tcx.sess.source_map().span_to_snippet(self.span)
293 && (is_local || manual_partialeq_impl)
294 {
295 let mut hir_id = self.id;
296 while let hir::Node::Pat(pat) = tcx.parent_hir_node(hir_id) {
297 hir_id = pat.hir_id;
298 }
299 match tcx.parent_hir_node(hir_id) {
300 hir::Node::Arm(hir::Arm { pat, guard: None, .. }) => {
301 Some(SuggestEq::AddIf {
303 if_span: pat.span.shrink_to_hi(),
304 pat_span: self.span,
305 name,
306 ty,
307 manual_partialeq_impl,
308 })
309 }
310 hir::Node::Arm(hir::Arm { guard: Some(guard), .. }) => {
311 Some(SuggestEq::AddToIf {
313 span: guard.span.shrink_to_hi(),
314 pat_span: self.span,
315 name,
316 ty,
317 manual_partialeq_impl,
318 })
319 }
320 hir::Node::Expr(hir::Expr {
321 kind: hir::ExprKind::Let(let_expr),
322 span,
323 ..
324 }) => {
325 if let_expr.pat.span == self.span {
326 Some(SuggestEq::ReplaceWithEq {
328 removal: span.until(self.span),
329 eq: self.span.between(let_expr.init.span),
330 ty,
331 manual_partialeq_impl,
332 })
333 } else if tcx.sess.edition().at_least_rust_2024() {
334 Some(SuggestEq::AddToLetChain {
337 span: span.shrink_to_hi(),
338 pat_span: self.span,
339 name,
340 ty,
341 manual_partialeq_impl,
342 })
343 } else {
344 None
345 }
346 }
347 hir::Node::LetStmt(let_stmt)
348 if let Some(init) = let_stmt.init
349 && let Some(els) = let_stmt.els
350 && init.span.ctxt().is_root()
351 && els.span.ctxt().is_root() =>
352 {
353 Some(SuggestEq::ReplaceLetElseWithIf {
355 if_span: let_stmt.span.until(let_stmt.pat.span),
356 eq: let_stmt.pat.span.between(init.span),
357 else_span: init.span.between(els.span),
358 ty,
359 manual_partialeq_impl,
360 })
361 }
362 _ => None,
363 }
364 } else {
365 None
366 };
367 let err = TypeNotStructural {
368 span,
369 ty,
370 ty_def_span,
371 manual_partialeq_impl_span,
372 manual_partialeq_impl_note,
373 is_local,
374 suggestion,
375 };
376 return self.mk_err(tcx.dcx().create_err(err), ty);
377 }
378 ty::Adt(adt_def, args) if adt_def.is_enum() => {
379 let (&variant_index, fields) = valtree.to_branch().split_first().unwrap();
380 let variant_index = VariantIdx::from_u32(variant_index.to_leaf().to_u32());
381 PatKind::Variant {
382 adt_def: *adt_def,
383 args,
384 variant_index,
385 subpatterns: self
386 .lower_field_values_to_fieldpats(fields.iter().map(|ct| ct.to_value())),
387 }
388 }
389 ty::Adt(def, _) => {
390 assert!(!def.is_union()); PatKind::Leaf {
392 subpatterns: self.lower_field_values_to_fieldpats(
393 valtree.to_branch().iter().map(|ct| ct.to_value()),
394 ),
395 }
396 }
397 ty::Tuple(_) => PatKind::Leaf {
398 subpatterns: self.lower_field_values_to_fieldpats(
399 valtree.to_branch().iter().map(|ct| ct.to_value()),
400 ),
401 },
402 ty::Slice(_) => PatKind::Slice {
403 prefix: valtree
404 .to_branch()
405 .iter()
406 .map(|val| *self.valtree_to_pat(val.to_value()))
407 .collect(),
408 slice: None,
409 suffix: Box::new([]),
410 },
411 ty::Array(_, _) => PatKind::Array {
412 prefix: valtree
413 .to_branch()
414 .iter()
415 .map(|val| *self.valtree_to_pat(val.to_value()))
416 .collect(),
417 slice: None,
418 suffix: Box::new([]),
419 },
420 ty::Str => {
421 PatKind::Constant { value }
429 }
430 ty::Ref(_, pointee_ty, ..) => {
431 if pointee_ty.is_str()
432 || pointee_ty.is_slice()
433 || pointee_ty.is_sized(tcx, self.typing_env)
434 {
435 PatKind::Deref {
436 pin: hir::Pinnedness::Not,
438 subpattern: self.valtree_to_pat(ty::Value { ty: *pointee_ty, valtree }),
442 }
443 } else {
444 return self.mk_err(
445 tcx.dcx().create_err(UnsizedPattern { span, non_sm_ty: *pointee_ty }),
446 ty,
447 );
448 }
449 }
450 ty::Float(flt) => {
451 let v = valtree.to_leaf();
452 let is_nan = match flt {
453 ty::FloatTy::F16 => v.to_f16().is_nan(),
454 ty::FloatTy::F32 => v.to_f32().is_nan(),
455 ty::FloatTy::F64 => v.to_f64().is_nan(),
456 ty::FloatTy::F128 => v.to_f128().is_nan(),
457 };
458 if is_nan {
459 return self.mk_err(tcx.dcx().create_err(NaNPattern { span }), ty);
462 } else {
463 PatKind::Constant { value }
464 }
465 }
466 ty::Pat(..) | ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::RawPtr(..) => {
467 PatKind::Constant { value }
470 }
471 ty::FnPtr(..) => {
472 unreachable!(
473 "Valtree construction would never succeed for FnPtr, so this is unreachable."
474 )
475 }
476 _ => {
477 let err = InvalidPattern {
478 span,
479 non_sm_ty: ty,
480 prefix: ty.prefix_string(tcx).to_string(),
481 };
482 return self.mk_err(tcx.dcx().create_err(err), ty);
483 }
484 };
485
486 Box::new(Pat { span, ty, kind, extra: None })
487 }
488}
489
490fn extend_type_not_partial_eq<'tcx>(
493 tcx: TyCtxt<'tcx>,
494 typing_env: ty::TypingEnv<'tcx>,
495 ty: Ty<'tcx>,
496 err: &mut Diag<'_>,
497) {
498 struct UsedParamsNeedInstantiationVisitor<'tcx> {
500 tcx: TyCtxt<'tcx>,
501 typing_env: ty::TypingEnv<'tcx>,
502 adts_with_manual_partialeq: FxHashSet<Span>,
504 adts_without_partialeq: FxHashSet<Span>,
506 manual: FxHashSet<Ty<'tcx>>,
509 without: FxHashSet<Ty<'tcx>>,
512 }
513
514 impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for UsedParamsNeedInstantiationVisitor<'tcx> {
515 type Result = ControlFlow<()>;
516 fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result {
517 match ty.kind() {
518 ty::Dynamic(..) => return ControlFlow::Break(()),
519 ty::UnsafeBinder(..) => return ControlFlow::Break(()),
522 ty::FnPtr(..) => return ControlFlow::Continue(()),
523 ty::Adt(def, _args) => {
524 let ty_def_id = def.did();
525 let ty_def_span = self.tcx.def_span(ty_def_id);
526 let PartialEqImplStatus {
527 has_impl,
528 is_derived,
529 possibly_inapplicable_structural_partial_eq: structural_partial_eq,
530 non_blanket_impl,
531 possibly_inapplicable_derived_partial_eq: _,
532 } = type_has_partial_eq_impl(self.tcx, self.typing_env, ty);
533 match (has_impl, is_derived, structural_partial_eq, non_blanket_impl) {
534 (_, _, true, _) => {}
535 (true, false, _, Some(def_id)) if def_id.is_local() => {
536 self.adts_with_manual_partialeq.insert(self.tcx.def_span(def_id));
537 }
538 (true, false, _, _) if ty_def_id.is_local() => {
539 self.adts_with_manual_partialeq.insert(ty_def_span);
540 }
541 (false, _, _, _) if ty_def_id.is_local() => {
542 self.adts_without_partialeq.insert(ty_def_span);
543 }
544 (true, false, _, _) => {
545 self.manual.insert(ty);
546 }
547 (false, _, _, _) => {
548 self.without.insert(ty);
549 }
550 _ => {}
551 };
552 ty.super_visit_with(self)
553 }
554 _ => ty.super_visit_with(self),
555 }
556 }
557 }
558 let mut v = UsedParamsNeedInstantiationVisitor {
559 tcx,
560 typing_env,
561 adts_with_manual_partialeq: FxHashSet::default(),
562 adts_without_partialeq: FxHashSet::default(),
563 manual: FxHashSet::default(),
564 without: FxHashSet::default(),
565 };
566 if v.visit_ty(ty).is_break() {
567 return;
568 }
569 #[allow(rustc::potential_query_instability)] for span in v.adts_with_manual_partialeq {
571 err.span_note(span, "the `PartialEq` trait must be derived, manual `impl`s are not sufficient; see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details");
572 }
573 #[allow(rustc::potential_query_instability)] for span in v.adts_without_partialeq {
575 err.span_label(
576 span,
577 "must be annotated with `#[derive(PartialEq)]` to be usable in patterns",
578 );
579 }
580 #[allow(rustc::potential_query_instability)]
581 let mut manual: Vec<_> = v.manual.into_iter().map(|t| t.to_string()).collect();
582 manual.sort();
583 for ty in manual {
584 err.note(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{0}` must be annotated with `#[derive(PartialEq)]` to be usable in patterns, manual `impl`s are not sufficient; see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details",
ty))
})format!(
585 "`{ty}` must be annotated with `#[derive(PartialEq)]` to be usable in patterns, manual `impl`s are not sufficient; see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details"
586 ));
587 }
588 #[allow(rustc::potential_query_instability)]
589 let mut without: Vec<_> = v.without.into_iter().map(|t| t.to_string()).collect();
590 without.sort();
591 for ty in without {
592 err.note(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("`{0}` must be annotated with `#[derive(PartialEq)]` to be usable in patterns",
ty))
})format!(
593 "`{ty}` must be annotated with `#[derive(PartialEq)]` to be usable in patterns"
594 ));
595 }
596}
597
598#[derive(#[automatically_derived]
impl ::core::fmt::Debug for PartialEqImplStatus {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field5_finish(f,
"PartialEqImplStatus", "has_impl", &self.has_impl, "is_derived",
&self.is_derived, "non_blanket_impl", &self.non_blanket_impl,
"possibly_inapplicable_structural_partial_eq",
&self.possibly_inapplicable_structural_partial_eq,
"possibly_inapplicable_derived_partial_eq",
&&self.possibly_inapplicable_derived_partial_eq)
}
}Debug)]
599struct PartialEqImplStatus {
600 has_impl: bool,
602
603 is_derived: bool,
605 non_blanket_impl: Option<DefId>,
607
608 possibly_inapplicable_structural_partial_eq: bool,
611 possibly_inapplicable_derived_partial_eq: bool,
614}
615
616{}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() || { false }
{
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("type_has_partial_eq_impl",
"rustc_mir_build::thir::pattern::const_to_pat",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs"),
::tracing_core::__macro_support::Option::Some(616u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::pattern::const_to_pat"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("typing_env")
}> =
::tracing::__macro_support::FieldName::new("typing_env");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("ty")
}> =
::tracing::__macro_support::FieldName::new("ty");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&typing_env)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ty)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy
:: needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: PartialEqImplStatus =
loop {};
return __tracing_attr_fake_return;
}
{
let (infcx, param_env) =
tcx.infer_ctxt().build_with_typing_env(typing_env);
let partial_eq_trait_id =
tcx.require_lang_item(LangItem::PartialEq, DUMMY_SP);
let structural_partial_eq_trait_id =
tcx.require_lang_item(LangItem::StructuralPeq, DUMMY_SP);
let has_impl =
{
let obligation =
Obligation::new(tcx, ObligationCause::dummy(), param_env,
ty::TraitRef::new(tcx, partial_eq_trait_id, [ty, ty]));
infcx.predicate_must_hold_modulo_regions(&obligation)
};
let possibly_inapplicable_derived_partial_eq =
{
let obligation =
Obligation::new(tcx, ObligationCause::dummy(), param_env,
ty::Binder::dummy(ty::TraitRef::new(tcx,
partial_eq_trait_id, [ty, ty])));
compute_applicable_impls_for_diagnostics(&infcx,
&obligation,
true).iter().any(|candidate_source|
{
#[allow(non_exhaustive_omitted_patterns)]
match candidate_source {
&CandidateSource::DefId(def_id) if
{
{
'done:
{
for i in ::rustc_attr_ir::HasAttrs::get_attrs(def_id, &tcx)
{
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(AutomaticallyDerived) =>
{
break 'done Some(());
}
::rustc_attr_ir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}.is_some() => true,
_ => false,
}
})
};
let possibly_inapplicable_structural_partial_eq =
{
let obligation =
Obligation::new(tcx, ObligationCause::dummy(), param_env,
ty::Binder::dummy(ty::TraitRef::new(tcx,
structural_partial_eq_trait_id, [ty])));
compute_applicable_impls_for_diagnostics(&infcx,
&obligation,
true).iter().any(|candidate_source|
#[allow(non_exhaustive_omitted_patterns)] match candidate_source
{
CandidateSource::DefId(_) => true,
_ => false,
})
};
let mut automatically_derived = false;
let mut impl_def_id = None;
for def_id in
tcx.non_blanket_impls_for_ty(partial_eq_trait_id, ty) {
automatically_derived =
{
{
'done:
{
for i in ::rustc_attr_ir::HasAttrs::get_attrs(def_id, &tcx)
{
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(AutomaticallyDerived) =>
{
break 'done Some(());
}
::rustc_attr_ir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}.is_some();
impl_def_id = Some(def_id);
}
PartialEqImplStatus {
has_impl,
is_derived: automatically_derived,
possibly_inapplicable_structural_partial_eq,
non_blanket_impl: impl_def_id,
possibly_inapplicable_derived_partial_eq,
}
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs:616",
"rustc_mir_build::thir::pattern::const_to_pat",
::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs"),
::tracing_core::__macro_support::Option::Some(616u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::pattern::const_to_pat"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "trace", skip(tcx), ret)]
617fn type_has_partial_eq_impl<'tcx>(
618 tcx: TyCtxt<'tcx>,
619 typing_env: ty::TypingEnv<'tcx>,
620 ty: Ty<'tcx>,
621) -> PartialEqImplStatus {
622 let (infcx, param_env) = tcx.infer_ctxt().build_with_typing_env(typing_env);
623 let partial_eq_trait_id = tcx.require_lang_item(LangItem::PartialEq, DUMMY_SP);
629 let structural_partial_eq_trait_id = tcx.require_lang_item(LangItem::StructuralPeq, DUMMY_SP);
630
631 let has_impl = {
642 let obligation = Obligation::new(
643 tcx,
644 ObligationCause::dummy(),
645 param_env,
646 ty::TraitRef::new(tcx, partial_eq_trait_id, [ty, ty]),
647 );
648 infcx.predicate_must_hold_modulo_regions(&obligation)
649 };
650
651 let possibly_inapplicable_derived_partial_eq = {
654 let obligation = Obligation::new(
655 tcx,
656 ObligationCause::dummy(),
657 param_env,
658 ty::Binder::dummy(ty::TraitRef::new(tcx, partial_eq_trait_id, [ty, ty])),
659 );
660 compute_applicable_impls_for_diagnostics(&infcx, &obligation, true).iter().any(
661 |candidate_source| {
662 matches!(
663 candidate_source,
664 &CandidateSource::DefId(def_id)
665 if find_attr!(tcx, def_id, AutomaticallyDerived)
666 )
667 },
668 )
669 };
670
671 let possibly_inapplicable_structural_partial_eq = {
672 let obligation = Obligation::new(
673 tcx,
674 ObligationCause::dummy(),
675 param_env,
676 ty::Binder::dummy(ty::TraitRef::new(tcx, structural_partial_eq_trait_id, [ty])),
677 );
678 compute_applicable_impls_for_diagnostics(&infcx, &obligation, true)
679 .iter()
680 .any(|candidate_source| matches!(candidate_source, CandidateSource::DefId(_)))
681 };
682
683 let mut automatically_derived = false;
684 let mut impl_def_id = None;
685 for def_id in tcx.non_blanket_impls_for_ty(partial_eq_trait_id, ty) {
686 automatically_derived = find_attr!(tcx, def_id, AutomaticallyDerived);
687 impl_def_id = Some(def_id);
688 }
689
690 PartialEqImplStatus {
691 has_impl,
692 is_derived: automatically_derived,
693 possibly_inapplicable_structural_partial_eq,
694 non_blanket_impl: impl_def_id,
695 possibly_inapplicable_derived_partial_eq,
696 }
697}