#[instrument(level = "debug", skip(self))]
pub(super) fn const_to_pat(
&self,
- cv: &'tcx ty::Const<'tcx>,
+ cv: ty::Const<'tcx>,
id: hir::HirId,
span: Span,
mir_structural_match_violation: bool,
fn search_for_structural_match_violation(&self, ty: Ty<'tcx>) -> Option<String> {
traits::search_for_structural_match_violation(self.span, self.tcx(), ty).map(|non_sm_ty| {
- with_no_trimmed_paths(|| match non_sm_ty {
+ with_no_trimmed_paths!(match non_sm_ty {
traits::NonStructuralMatchTy::Adt(adt) => self.adt_derive_msg(adt),
traits::NonStructuralMatchTy::Dynamic => {
"trait objects cannot be used in patterns".to_string()
ty.is_structural_eq_shallow(self.infcx.tcx)
}
- fn to_pat(
- &mut self,
- cv: &'tcx ty::Const<'tcx>,
- mir_structural_match_violation: bool,
- ) -> Pat<'tcx> {
+ fn to_pat(&mut self, cv: ty::Const<'tcx>, mir_structural_match_violation: bool) -> Pat<'tcx> {
trace!(self.treat_byte_string_as_slice);
// This method is just a wrapper handling a validity check; the heavy lifting is
// performed by the recursive `recur` method, which is not meant to be
// If we were able to successfully convert the const to some pat,
// double-check that all types in the const implement `Structural`.
- let structural = self.search_for_structural_match_violation(cv.ty);
+ let structural = self.search_for_structural_match_violation(cv.ty());
debug!(
"search_for_structural_match_violation cv.ty: {:?} returned: {:?}",
- cv.ty, structural
+ cv.ty(),
+ structural
);
// This can occur because const qualification treats all associated constants as
}
if let Some(msg) = structural {
- if !self.type_may_have_partial_eq_impl(cv.ty) {
+ if !self.type_may_have_partial_eq_impl(cv.ty()) {
// span_fatal avoids ICE from resolution of non-existent method (rare case).
self.tcx().sess.span_fatal(self.span, &msg);
} else if mir_structural_match_violation && !self.saw_const_match_lint.get() {
fn field_pats(
&self,
- vals: impl Iterator<Item = &'tcx ty::Const<'tcx>>,
+ vals: impl Iterator<Item = ty::Const<'tcx>>,
) -> Result<Vec<FieldPat<'tcx>>, FallbackToConstRef> {
vals.enumerate()
.map(|(idx, val)| {
// Recursive helper for `to_pat`; invoke that (instead of calling this directly).
fn recur(
&self,
- cv: &'tcx ty::Const<'tcx>,
+ cv: ty::Const<'tcx>,
mir_structural_match_violation: bool,
) -> Result<Pat<'tcx>, FallbackToConstRef> {
let id = self.id;
let tcx = self.tcx();
let param_env = self.param_env;
- let kind = match cv.ty.kind() {
+ let kind = match cv.ty().kind() {
ty::Float(_) => {
if self.include_lint_checks {
tcx.struct_span_lint_hir(
PatKind::Wild
}
ty::Adt(..)
- if !self.type_may_have_partial_eq_impl(cv.ty)
+ if !self.type_may_have_partial_eq_impl(cv.ty())
// FIXME(#73448): Find a way to bring const qualification into parity with
// `search_for_structural_match_violation` and then remove this condition.
- && self.search_for_structural_match_violation(cv.ty).is_some() =>
+ && self.search_for_structural_match_violation(cv.ty()).is_some() =>
{
// Obtain the actual type that isn't annotated. If we just looked at `cv.ty` we
// could get `Option<NonStructEq>`, even though `Option` is annotated with derive.
- let msg = self.search_for_structural_match_violation(cv.ty).unwrap();
+ let msg = self.search_for_structural_match_violation(cv.ty()).unwrap();
self.saw_const_match_error.set(true);
if self.include_lint_checks {
tcx.sess.span_err(self.span, &msg);
// details.
// Backwards compatibility hack because we can't cause hard errors on these
// types, so we compare them via `PartialEq::eq` at runtime.
- ty::Adt(..) if !self.type_marked_structural(cv.ty) && self.behind_reference.get() => {
+ ty::Adt(..) if !self.type_marked_structural(cv.ty()) && self.behind_reference.get() => {
if self.include_lint_checks
&& !self.saw_const_match_error.get()
&& !self.saw_const_match_lint.get()
let msg = format!(
"to use a constant of type `{}` in a pattern, \
`{}` must be annotated with `#[derive(PartialEq, Eq)]`",
- cv.ty, cv.ty,
+ cv.ty(),
+ cv.ty(),
);
lint.build(&msg).emit()
},
// `PartialEq::eq` on it.
return Err(fallback_to_const_ref(self));
}
- ty::Adt(adt_def, _) if !self.type_marked_structural(cv.ty) => {
- debug!("adt_def {:?} has !type_marked_structural for cv.ty: {:?}", adt_def, cv.ty);
+ ty::Adt(adt_def, _) if !self.type_marked_structural(cv.ty()) => {
+ debug!(
+ "adt_def {:?} has !type_marked_structural for cv.ty: {:?}",
+ adt_def,
+ cv.ty()
+ );
let path = tcx.def_path_str(adt_def.did);
let msg = format!(
"to use a constant of type `{}` in a pattern, \
.destructure_const(param_env.and(cv))
.fields
.iter()
- .map(|val| self.recur(val, false))
+ .map(|val| self.recur(*val, false))
.collect::<Result<_, _>>()?,
slice: None,
suffix: Vec::new(),
// These are not allowed and will error elsewhere anyway.
ty::Dynamic(..) => {
self.saw_const_match_error.set(true);
- let msg = format!("`{}` cannot be used in patterns", cv.ty);
+ let msg = format!("`{}` cannot be used in patterns", cv.ty());
if self.include_lint_checks {
tcx.sess.span_err(span, &msg);
} else {
.destructure_const(param_env.and(array))
.fields
.iter()
- .map(|val| self.recur(val, false))
+ .map(|val| self.recur(*val, false))
.collect::<Result<_, _>>()?,
slice: None,
suffix: vec![],
}),
span,
- ty: pointee_ty,
+ ty: *pointee_ty,
},
};
self.behind_reference.set(old);
.destructure_const(param_env.and(array))
.fields
.iter()
- .map(|val| self.recur(val, false))
+ .map(|val| self.recur(*val, false))
.collect::<Result<_, _>>()?,
slice: None,
suffix: vec![],
// this pattern to a `PartialEq::eq` comparison and `PartialEq::eq` takes a
// reference. This makes the rest of the matching logic simpler as it doesn't have
// to figure out how to get a reference again.
- ty::Adt(adt_def, _) if !self.type_marked_structural(pointee_ty) => {
+ ty::Adt(adt_def, _) if !self.type_marked_structural(*pointee_ty) => {
if self.behind_reference.get() {
if self.include_lint_checks
&& !self.saw_const_match_error.get()
}
_ => {
self.saw_const_match_error.set(true);
- let msg = format!("`{}` cannot be used in patterns", cv.ty);
+ let msg = format!("`{}` cannot be used in patterns", cv.ty());
if self.include_lint_checks {
tcx.sess.span_err(span, &msg);
} else {
&& mir_structural_match_violation
// FIXME(#73448): Find a way to bring const qualification into parity with
// `search_for_structural_match_violation` and then remove this condition.
- && self.search_for_structural_match_violation(cv.ty).is_some()
+ && self.search_for_structural_match_violation(cv.ty()).is_some()
{
self.saw_const_match_lint.set(true);
// Obtain the actual type that isn't annotated. If we just looked at `cv.ty` we
// could get `Option<NonStructEq>`, even though `Option` is annotated with derive.
- let msg = self.search_for_structural_match_violation(cv.ty).unwrap().replace(
+ let msg = self.search_for_structural_match_violation(cv.ty()).unwrap().replace(
"in a pattern,",
"in a pattern, the constant's initializer must be trivial or",
);
);
}
- Ok(Pat { span, ty: cv.ty, kind: Box::new(kind) })
+ Ok(Pat { span, ty: cv.ty(), kind: Box::new(kind) })
}
}