use hair::constant::*;
use rustc::mir::{fmt_const_val, Field, BorrowKind, Mutability};
-use rustc::mir::{ProjectionElem, UserTypeProjection};
+use rustc::mir::{UserTypeProjection};
use rustc::mir::interpret::{Scalar, GlobalId, ConstValue, sign_extend};
-use rustc::ty::{self, Region, TyCtxt, AdtDef, Ty, Lift};
-use rustc::ty::{CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, UserTypeAnnotation};
+use rustc::ty::{self, Region, TyCtxt, AdtDef, Ty, Lift, UserType};
+use rustc::ty::{CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations};
use rustc::ty::subst::{Substs, Kind};
use rustc::ty::layout::VariantIdx;
use rustc::hir::{self, PatKind, RangeEnd};
}
#[derive(Copy, Clone, Debug)]
-pub enum BindingMode<'tcx> {
+pub enum BindingMode {
ByValue,
- ByRef(Region<'tcx>, BorrowKind),
+ ByRef(BorrowKind),
}
#[derive(Clone, Debug)]
#[derive(Clone, Debug)]
pub struct PatternTypeProjection<'tcx> {
- pub base: CanonicalUserTypeAnnotation<'tcx>,
- pub projs: Vec<ProjectionElem<'tcx, (), ()>>,
+ pub user_ty: CanonicalUserType<'tcx>,
}
impl<'tcx> PatternTypeProjection<'tcx> {
- pub(crate) fn from_user_type(user_annotation: CanonicalUserTypeAnnotation<'tcx>) -> Self {
+ pub(crate) fn from_user_type(user_annotation: CanonicalUserType<'tcx>) -> Self {
Self {
- base: user_annotation,
- projs: Vec::new(),
+ user_ty: user_annotation,
}
}
pub(crate) fn user_ty(
self,
annotations: &mut CanonicalUserTypeAnnotations<'tcx>,
+ inferred_ty: Ty<'tcx>,
span: Span,
) -> UserTypeProjection<'tcx> {
UserTypeProjection {
- base: annotations.push((span, self.base)),
- projs: self.projs
+ base: annotations.push(CanonicalUserTypeAnnotation {
+ span,
+ user_ty: self.user_ty,
+ inferred_ty,
+ }),
+ projs: Vec::new(),
}
}
}
Binding {
mutability: Mutability,
name: ast::Name,
- mode: BindingMode<'tcx>,
+ mode: BindingMode,
var: ast::NodeId,
ty: Ty<'tcx>,
subpattern: Option<Pattern<'tcx>>,
PatternKind::Binding { mutability, name, mode, ref subpattern, .. } => {
let is_mut = match mode {
BindingMode::ByValue => mutability == Mutability::Mut,
- BindingMode::ByRef(_, bk) => {
+ BindingMode::ByRef(bk) => {
write!(f, "ref ")?;
match bk { BorrowKind::Mut { .. } => true, _ => false }
}
PatKind::Binding(_, id, ident, ref sub) => {
let var_ty = self.tables.node_id_to_type(pat.hir_id);
- let region = match var_ty.sty {
- ty::Ref(r, _, _) => Some(r),
- ty::Error => { // Avoid ICE
- return Pattern { span: pat.span, ty, kind: Box::new(PatternKind::Wild) };
- }
- _ => None,
+ if let ty::Error = var_ty.sty {
+ // Avoid ICE
+ return Pattern { span: pat.span, ty, kind: Box::new(PatternKind::Wild) };
};
let bm = *self.tables.pat_binding_modes().get(pat.hir_id)
.expect("missing binding mode");
(Mutability::Not, BindingMode::ByValue),
ty::BindByReference(hir::MutMutable) =>
(Mutability::Not, BindingMode::ByRef(
- region.unwrap(), BorrowKind::Mut { allow_two_phase_borrow: false })),
+ BorrowKind::Mut { allow_two_phase_borrow: false })),
ty::BindByReference(hir::MutImmutable) =>
(Mutability::Not, BindingMode::ByRef(
- region.unwrap(), BorrowKind::Shared)),
+ BorrowKind::Shared)),
};
// A ref x pattern is the same node used for x, and as such it has
let adt_subpattern = |i, variant_opt| {
let field = Field::new(i);
let val = const_field(
- self.tcx, self.param_env, instance,
+ self.tcx, self.param_env,
variant_opt, field, cv,
).expect("field access failed");
self.const_to_pat(instance, val, id, span)
},
ty::Adt(adt_def, substs) if adt_def.is_enum() => {
let variant_index = const_variant_index(
- self.tcx, self.param_env, instance, cv
+ self.tcx, self.param_env, cv
).expect("const_variant_index failed");
let subpatterns = adt_subpatterns(
adt_def.variants[variant_index].fields.len(),
CloneImpls!{ <'tcx>
Span, Field, Mutability, ast::Name, ast::NodeId, usize, ty::Const<'tcx>,
- Region<'tcx>, Ty<'tcx>, BindingMode<'tcx>, &'tcx AdtDef,
- &'tcx Substs<'tcx>, &'tcx Kind<'tcx>, UserTypeAnnotation<'tcx>,
+ Region<'tcx>, Ty<'tcx>, BindingMode, &'tcx AdtDef,
+ &'tcx Substs<'tcx>, &'tcx Kind<'tcx>, UserType<'tcx>,
UserTypeProjection<'tcx>, PatternTypeProjection<'tcx>
}