3 //! The job of the categorization module is to analyze an expression to
4 //! determine what kind of memory is used in evaluating it (for example,
5 //! where dereferences occur and what kind of pointer is dereferenced;
6 //! whether the memory is mutable, etc.).
8 //! Categorization effectively transforms all of our expressions into
9 //! expressions of the following forms (the actual enum has many more
10 //! possibilities, naturally, but they are all variants of these base
13 //! E = rvalue // some computed rvalue
14 //! | x // address of a local variable or argument
15 //! | *E // deref of a ptr
16 //! | E.comp // access to an interior component
18 //! Imagine a routine ToAddr(Expr) that evaluates an expression and returns an
19 //! address where the result is to be found. If Expr is a place, then this
20 //! is the address of the place. If `Expr` is an rvalue, this is the address of
21 //! some temporary spot in memory where the result is stored.
23 //! Now, `cat_expr()` classifies the expression `Expr` and the address `A = ToAddr(Expr)`
26 //! - `cat`: what kind of expression was this? This is a subset of the
27 //! full expression forms which only includes those that we care about
28 //! for the purpose of the analysis.
29 //! - `mutbl`: mutability of the address `A`.
30 //! - `ty`: the type of data found at the address `A`.
32 //! The resulting categorization tree differs somewhat from the expressions
33 //! themselves. For example, auto-derefs are explicit. Also, an index `a[b]` is
34 //! decomposed into two operations: a dereference to reach the array data and
35 //! then an index to jump forward to the relevant item.
37 //! ## By-reference upvars
39 //! One part of the codegen which may be non-obvious is that we translate
40 //! closure upvars into the dereference of a borrowed pointer; this more closely
41 //! resembles the runtime codegen. So, for example, if we had:
45 //! let inc = || x += y;
47 //! Then when we categorize `x` (*within* the closure) we would yield a
48 //! result of `*x'`, effectively, where `x'` is a `Categorization::Upvar` reference
49 //! tied to `x`. The type of `x'` will be a borrowed pointer.
51 use rustc_middle::hir::place::*;
52 use rustc_middle::ty::adjustment;
53 use rustc_middle::ty::fold::TypeFoldable;
54 use rustc_middle::ty::{self, Ty, TyCtxt};
56 use rustc_data_structures::fx::FxIndexMap;
58 use rustc_hir::def::{CtorOf, DefKind, Res};
59 use rustc_hir::def_id::LocalDefId;
60 use rustc_hir::pat_util::EnumerateAndAdjustIterator;
61 use rustc_hir::PatKind;
62 use rustc_index::vec::Idx;
63 use rustc_infer::infer::InferCtxt;
65 use rustc_target::abi::VariantIdx;
66 use rustc_trait_selection::infer::InferCtxtExt;
69 fn hir_id(&self) -> hir::HirId;
70 fn span(&self) -> Span;
73 impl HirNode for hir::Expr<'_> {
74 fn hir_id(&self) -> hir::HirId {
77 fn span(&self) -> Span {
82 impl HirNode for hir::Pat<'_> {
83 fn hir_id(&self) -> hir::HirId {
86 fn span(&self) -> Span {
92 crate struct MemCategorizationContext<'a, 'tcx> {
93 crate typeck_results: &'a ty::TypeckResults<'tcx>,
94 infcx: &'a InferCtxt<'a, 'tcx>,
95 param_env: ty::ParamEnv<'tcx>,
96 body_owner: LocalDefId,
97 upvars: Option<&'tcx FxIndexMap<hir::HirId, hir::Upvar>>,
100 crate type McResult<T> = Result<T, ()>;
102 impl<'a, 'tcx> MemCategorizationContext<'a, 'tcx> {
103 /// Creates a `MemCategorizationContext`.
105 infcx: &'a InferCtxt<'a, 'tcx>,
106 param_env: ty::ParamEnv<'tcx>,
107 body_owner: LocalDefId,
108 typeck_results: &'a ty::TypeckResults<'tcx>,
109 ) -> MemCategorizationContext<'a, 'tcx> {
110 MemCategorizationContext {
115 upvars: infcx.tcx.upvars_mentioned(body_owner),
119 crate fn tcx(&self) -> TyCtxt<'tcx> {
123 crate fn type_is_copy_modulo_regions(&self, ty: Ty<'tcx>, span: Span) -> bool {
124 self.infcx.type_is_copy_modulo_regions(self.param_env, ty, span)
127 fn resolve_vars_if_possible<T>(&self, value: &T) -> T
129 T: TypeFoldable<'tcx>,
131 self.infcx.resolve_vars_if_possible(value)
134 fn is_tainted_by_errors(&self) -> bool {
135 self.infcx.is_tainted_by_errors()
138 fn resolve_type_vars_or_error(
141 ty: Option<Ty<'tcx>>,
142 ) -> McResult<Ty<'tcx>> {
145 let ty = self.resolve_vars_if_possible(&ty);
146 if ty.references_error() || ty.is_ty_var() {
147 debug!("resolve_type_vars_or_error: error from {:?}", ty);
154 None if self.is_tainted_by_errors() => Err(()),
157 "no type for node {}: {} in mem_categorization",
159 self.tcx().hir().node_to_string(id)
165 crate fn node_ty(&self, hir_id: hir::HirId) -> McResult<Ty<'tcx>> {
166 self.resolve_type_vars_or_error(hir_id, self.typeck_results.node_type_opt(hir_id))
169 fn expr_ty(&self, expr: &hir::Expr<'_>) -> McResult<Ty<'tcx>> {
170 self.resolve_type_vars_or_error(expr.hir_id, self.typeck_results.expr_ty_opt(expr))
173 crate fn expr_ty_adjusted(&self, expr: &hir::Expr<'_>) -> McResult<Ty<'tcx>> {
174 self.resolve_type_vars_or_error(expr.hir_id, self.typeck_results.expr_ty_adjusted_opt(expr))
177 /// Returns the type of value that this pattern matches against.
178 /// Some non-obvious cases:
180 /// - a `ref x` binding matches against a value of type `T` and gives
181 /// `x` the type `&T`; we return `T`.
182 /// - a pattern with implicit derefs (thanks to default binding
183 /// modes #42640) may look like `Some(x)` but in fact have
184 /// implicit deref patterns attached (e.g., it is really
185 /// `&Some(x)`). In that case, we return the "outermost" type
186 /// (e.g., `&Option<T>).
187 crate fn pat_ty_adjusted(&self, pat: &hir::Pat<'_>) -> McResult<Ty<'tcx>> {
188 // Check for implicit `&` types wrapping the pattern; note
189 // that these are never attached to binding patterns, so
190 // actually this is somewhat "disjoint" from the code below
191 // that aims to account for `ref x`.
192 if let Some(vec) = self.typeck_results.pat_adjustments().get(pat.hir_id) {
193 if let Some(first_ty) = vec.first() {
194 debug!("pat_ty(pat={:?}) found adjusted ty `{:?}`", pat, first_ty);
199 self.pat_ty_unadjusted(pat)
202 /// Like `pat_ty`, but ignores implicit `&` patterns.
203 fn pat_ty_unadjusted(&self, pat: &hir::Pat<'_>) -> McResult<Ty<'tcx>> {
204 let base_ty = self.node_ty(pat.hir_id)?;
205 debug!("pat_ty(pat={:?}) base_ty={:?}", pat, base_ty);
207 // This code detects whether we are looking at a `ref x`,
208 // and if so, figures out what the type *being borrowed* is.
209 let ret_ty = match pat.kind {
210 PatKind::Binding(..) => {
215 .expect("missing binding mode");
217 if let ty::BindByReference(_) = bm {
218 // a bind-by-ref means that the base_ty will be the type of the ident itself,
219 // but what we want here is the type of the underlying value being borrowed.
220 // So peel off one-level, turning the &T into T.
221 match base_ty.builtin_deref(false) {
224 debug!("By-ref binding of non-derefable type {:?}", base_ty);
234 debug!("pat_ty(pat={:?}) ret_ty={:?}", pat, ret_ty);
239 crate fn cat_expr(&self, expr: &hir::Expr<'_>) -> McResult<PlaceWithHirId<'tcx>> {
240 // This recursion helper avoids going through *too many*
241 // adjustments, since *only* non-overloaded deref recurses.
243 mc: &MemCategorizationContext<'a, 'tcx>,
244 expr: &hir::Expr<'_>,
245 adjustments: &[adjustment::Adjustment<'tcx>],
246 ) -> McResult<PlaceWithHirId<'tcx>> {
247 match adjustments.split_last() {
248 None => mc.cat_expr_unadjusted(expr),
249 Some((adjustment, previous)) => {
250 mc.cat_expr_adjusted_with(expr, || helper(mc, expr, previous), adjustment)
255 helper(self, expr, self.typeck_results.expr_adjustments(expr))
258 crate fn cat_expr_adjusted(
260 expr: &hir::Expr<'_>,
261 previous: PlaceWithHirId<'tcx>,
262 adjustment: &adjustment::Adjustment<'tcx>,
263 ) -> McResult<PlaceWithHirId<'tcx>> {
264 self.cat_expr_adjusted_with(expr, || Ok(previous), adjustment)
267 fn cat_expr_adjusted_with<F>(
269 expr: &hir::Expr<'_>,
271 adjustment: &adjustment::Adjustment<'tcx>,
272 ) -> McResult<PlaceWithHirId<'tcx>>
274 F: FnOnce() -> McResult<PlaceWithHirId<'tcx>>,
276 debug!("cat_expr_adjusted_with({:?}): {:?}", adjustment, expr);
277 let target = self.resolve_vars_if_possible(&adjustment.target);
278 match adjustment.kind {
279 adjustment::Adjust::Deref(overloaded) => {
280 // Equivalent to *expr or something similar.
281 let base = if let Some(deref) = overloaded {
284 .mk_ref(deref.region, ty::TypeAndMut { ty: target, mutbl: deref.mutbl });
285 self.cat_rvalue(expr.hir_id, expr.span, ref_ty)
289 self.cat_deref(expr, base)
292 adjustment::Adjust::NeverToAny
293 | adjustment::Adjust::Pointer(_)
294 | adjustment::Adjust::Borrow(_) => {
295 // Result is an rvalue.
296 Ok(self.cat_rvalue(expr.hir_id, expr.span, target))
301 crate fn cat_expr_unadjusted(&self, expr: &hir::Expr<'_>) -> McResult<PlaceWithHirId<'tcx>> {
302 debug!("cat_expr: id={} expr={:?}", expr.hir_id, expr);
304 let expr_ty = self.expr_ty(expr)?;
306 hir::ExprKind::Unary(hir::UnOp::UnDeref, ref e_base) => {
307 if self.typeck_results.is_method_call(expr) {
308 self.cat_overloaded_place(expr, e_base)
310 let base = self.cat_expr(&e_base)?;
311 self.cat_deref(expr, base)
315 hir::ExprKind::Field(ref base, _) => {
316 let base = self.cat_expr(&base)?;
317 debug!("cat_expr(cat_field): id={} expr={:?} base={:?}", expr.hir_id, expr, base);
324 .expect("Field index not found");
326 Ok(self.cat_projection(
330 ProjectionKind::Field(field_idx as u32, VariantIdx::new(0)),
334 hir::ExprKind::Index(ref base, _) => {
335 if self.typeck_results.is_method_call(expr) {
336 // If this is an index implemented by a method call, then it
337 // will include an implicit deref of the result.
338 // The call to index() returns a `&T` value, which
339 // is an rvalue. That is what we will be
341 self.cat_overloaded_place(expr, base)
343 let base = self.cat_expr(&base)?;
344 Ok(self.cat_projection(expr, base, expr_ty, ProjectionKind::Index))
348 hir::ExprKind::Path(ref qpath) => {
349 let res = self.typeck_results.qpath_res(qpath, expr.hir_id);
350 self.cat_res(expr.hir_id, expr.span, expr_ty, res)
353 hir::ExprKind::Type(ref e, _) => self.cat_expr(&e),
355 hir::ExprKind::AddrOf(..)
356 | hir::ExprKind::Call(..)
357 | hir::ExprKind::Assign(..)
358 | hir::ExprKind::AssignOp(..)
359 | hir::ExprKind::Closure(..)
360 | hir::ExprKind::Ret(..)
361 | hir::ExprKind::Unary(..)
362 | hir::ExprKind::Yield(..)
363 | hir::ExprKind::MethodCall(..)
364 | hir::ExprKind::Cast(..)
365 | hir::ExprKind::DropTemps(..)
366 | hir::ExprKind::Array(..)
367 | hir::ExprKind::Tup(..)
368 | hir::ExprKind::Binary(..)
369 | hir::ExprKind::Block(..)
370 | hir::ExprKind::Loop(..)
371 | hir::ExprKind::Match(..)
372 | hir::ExprKind::Lit(..)
373 | hir::ExprKind::Break(..)
374 | hir::ExprKind::Continue(..)
375 | hir::ExprKind::Struct(..)
376 | hir::ExprKind::Repeat(..)
377 | hir::ExprKind::InlineAsm(..)
378 | hir::ExprKind::LlvmInlineAsm(..)
379 | hir::ExprKind::Box(..)
380 | hir::ExprKind::Err => Ok(self.cat_rvalue(expr.hir_id, expr.span, expr_ty)),
390 ) -> McResult<PlaceWithHirId<'tcx>> {
391 debug!("cat_res: id={:?} expr={:?} def={:?}", hir_id, expr_ty, res);
397 | DefKind::ConstParam
398 | DefKind::AssocConst
403 | Res::SelfCtor(..) => Ok(self.cat_rvalue(hir_id, span, expr_ty)),
405 Res::Def(DefKind::Static, _) => {
406 Ok(PlaceWithHirId::new(hir_id, expr_ty, PlaceBase::StaticItem, Vec::new()))
409 Res::Local(var_id) => {
410 if self.upvars.map_or(false, |upvars| upvars.contains_key(&var_id)) {
411 self.cat_upvar(hir_id, var_id)
413 Ok(PlaceWithHirId::new(hir_id, expr_ty, PlaceBase::Local(var_id), Vec::new()))
417 def => span_bug!(span, "unexpected definition in memory categorization: {:?}", def),
421 /// Categorize an upvar.
423 /// Note: the actual upvar access contains invisible derefs of closure
424 /// environment and upvar reference as appropriate. Only regionck cares
425 /// about these dereferences, so we let it compute them as needed.
426 fn cat_upvar(&self, hir_id: hir::HirId, var_id: hir::HirId) -> McResult<PlaceWithHirId<'tcx>> {
427 let closure_expr_def_id = self.body_owner;
429 let upvar_id = ty::UpvarId {
430 var_path: ty::UpvarPath { hir_id: var_id },
431 closure_expr_id: closure_expr_def_id,
433 let var_ty = self.node_ty(var_id)?;
435 let ret = PlaceWithHirId::new(hir_id, var_ty, PlaceBase::Upvar(upvar_id), Vec::new());
437 debug!("cat_upvar ret={:?}", ret);
446 ) -> PlaceWithHirId<'tcx> {
447 debug!("cat_rvalue hir_id={:?}, expr_ty={:?}, span={:?}", hir_id, expr_ty, span);
448 let ret = PlaceWithHirId::new(hir_id, expr_ty, PlaceBase::Rvalue, Vec::new());
449 debug!("cat_rvalue ret={:?}", ret);
453 crate fn cat_projection<N: HirNode>(
456 base_place: PlaceWithHirId<'tcx>,
458 kind: ProjectionKind,
459 ) -> PlaceWithHirId<'tcx> {
460 let mut projections = base_place.place.projections;
461 projections.push(Projection { kind: kind, ty: ty });
462 let ret = PlaceWithHirId::new(
464 base_place.place.base_ty,
465 base_place.place.base,
468 debug!("cat_field ret {:?}", ret);
472 fn cat_overloaded_place(
474 expr: &hir::Expr<'_>,
475 base: &hir::Expr<'_>,
476 ) -> McResult<PlaceWithHirId<'tcx>> {
477 debug!("cat_overloaded_place(expr={:?}, base={:?})", expr, base);
479 // Reconstruct the output assuming it's a reference with the
480 // same region and mutability as the receiver. This holds for
481 // `Deref(Mut)::Deref(_mut)` and `Index(Mut)::index(_mut)`.
482 let place_ty = self.expr_ty(expr)?;
483 let base_ty = self.expr_ty_adjusted(base)?;
485 let (region, mutbl) = match base_ty.kind {
486 ty::Ref(region, _, mutbl) => (region, mutbl),
487 _ => span_bug!(expr.span, "cat_overloaded_place: base is not a reference"),
489 let ref_ty = self.tcx().mk_ref(region, ty::TypeAndMut { ty: place_ty, mutbl });
491 let base = self.cat_rvalue(expr.hir_id, expr.span, ref_ty);
492 self.cat_deref(expr, base)
498 base_place: PlaceWithHirId<'tcx>,
499 ) -> McResult<PlaceWithHirId<'tcx>> {
500 debug!("cat_deref: base_place={:?}", base_place);
502 let base_curr_ty = base_place.place.ty();
503 let deref_ty = match base_curr_ty.builtin_deref(true) {
506 debug!("explicit deref of non-derefable type: {:?}", base_curr_ty);
510 let mut projections = base_place.place.projections;
511 projections.push(Projection { kind: ProjectionKind::Deref, ty: deref_ty });
513 let ret = PlaceWithHirId::new(
515 base_place.place.base_ty,
516 base_place.place.base,
519 debug!("cat_deref ret {:?}", ret);
523 crate fn cat_pattern<F>(
525 place: PlaceWithHirId<'tcx>,
530 F: FnMut(&PlaceWithHirId<'tcx>, &hir::Pat<'_>),
532 self.cat_pattern_(place, pat, &mut op)
535 /// Returns the variant index for an ADT used within a Struct or TupleStruct pattern
536 /// Here `pat_hir_id` is the HirId of the pattern itself.
537 fn variant_index_for_adt(
539 qpath: &hir::QPath<'_>,
540 pat_hir_id: hir::HirId,
542 ) -> McResult<VariantIdx> {
543 let res = self.typeck_results.qpath_res(qpath, pat_hir_id);
544 let ty = self.typeck_results.node_type(pat_hir_id);
545 let adt_def = match ty.kind {
546 ty::Adt(adt_def, _) => adt_def,
550 .delay_span_bug(span, "struct or tuple struct pattern not applied to an ADT");
556 Res::Def(DefKind::Variant, variant_id) => Ok(adt_def.variant_index_with_id(variant_id)),
557 Res::Def(DefKind::Ctor(CtorOf::Variant, ..), variant_ctor_id) => {
558 Ok(adt_def.variant_index_with_ctor_id(variant_ctor_id))
560 Res::Def(DefKind::Ctor(CtorOf::Struct, ..), _)
561 | Res::Def(DefKind::Struct | DefKind::Union | DefKind::TyAlias | DefKind::AssocTy, _)
563 | Res::SelfTy(..) => {
564 // Structs and Unions have only have one variant.
565 Ok(VariantIdx::new(0))
567 _ => bug!("expected ADT path, found={:?}", res),
571 /// Returns the total number of fields in an ADT variant used within a pattern.
572 /// Here `pat_hir_id` is the HirId of the pattern itself.
573 fn total_fields_in_adt_variant(
575 pat_hir_id: hir::HirId,
576 variant_index: VariantIdx,
578 ) -> McResult<usize> {
579 let ty = self.typeck_results.node_type(pat_hir_id);
581 ty::Adt(adt_def, _) => Ok(adt_def.variants[variant_index].fields.len()),
585 .delay_span_bug(span, "struct or tuple struct pattern not applied to an ADT");
591 /// Returns the total number of fields in a tuple used within a Tuple pattern.
592 /// Here `pat_hir_id` is the HirId of the pattern itself.
593 fn total_fields_in_tuple(&self, pat_hir_id: hir::HirId, span: Span) -> McResult<usize> {
594 let ty = self.typeck_results.node_type(pat_hir_id);
596 ty::Tuple(substs) => Ok(substs.len()),
598 self.tcx().sess.delay_span_bug(span, "tuple pattern not applied to a tuple");
604 // FIXME(#19596) This is a workaround, but there should be a better way to do this
607 mut place_with_id: PlaceWithHirId<'tcx>,
612 F: FnMut(&PlaceWithHirId<'tcx>, &hir::Pat<'_>),
614 // Here, `place` is the `PlaceWithHirId` being matched and pat is the pattern it
615 // is being matched against.
617 // In general, the way that this works is that we walk down the pattern,
618 // constructing a `PlaceWithHirId` that represents the path that will be taken
619 // to reach the value being matched.
621 debug!("cat_pattern(pat={:?}, place_with_id={:?})", pat, place_with_id);
623 // If (pattern) adjustments are active for this pattern, adjust the `PlaceWithHirId` correspondingly.
624 // `PlaceWithHirId`s are constructed differently from patterns. For example, in
628 // &&Some(x, ) => { ... },
633 // the pattern `&&Some(x,)` is represented as `Ref { Ref { TupleStruct }}`. To build the
634 // corresponding `PlaceWithHirId` we start with the `PlaceWithHirId` for `foo`, and then, by traversing the
635 // pattern, try to answer the question: given the address of `foo`, how is `x` reached?
637 // `&&Some(x,)` `place_foo`
638 // `&Some(x,)` `deref { place_foo}`
639 // `Some(x,)` `deref { deref { place_foo }}`
640 // (x,)` `field0 { deref { deref { place_foo }}}` <- resulting place
642 // The above example has no adjustments. If the code were instead the (after adjustments,
643 // equivalent) version
647 // Some(x, ) => { ... },
652 // Then we see that to get the same result, we must start with
653 // `deref { deref { place_foo }}` instead of `place_foo` since the pattern is now `Some(x,)`
654 // and not `&&Some(x,)`, even though its assigned type is that of `&&Some(x,)`.
656 0..self.typeck_results.pat_adjustments().get(pat.hir_id).map(|v| v.len()).unwrap_or(0)
658 debug!("cat_pattern: applying adjustment to place_with_id={:?}", place_with_id);
659 place_with_id = self.cat_deref(pat, place_with_id)?;
661 let place_with_id = place_with_id; // lose mutability
662 debug!("cat_pattern: applied adjustment derefs to get place_with_id={:?}", place_with_id);
664 // Invoke the callback, but only now, after the `place_with_id` has adjusted.
666 // To see that this makes sense, consider `match &Some(3) { Some(x) => { ... }}`. In that
667 // case, the initial `place_with_id` will be that for `&Some(3)` and the pattern is `Some(x)`. We
668 // don't want to call `op` with these incompatible values. As written, what happens instead
669 // is that `op` is called with the adjusted place (that for `*&Some(3)`) and the pattern
670 // `Some(x)` (which matches). Recursing once more, `*&Some(3)` and the pattern `Some(x)`
671 // result in the place `Downcast<Some>(*&Some(3)).0` associated to `x` and invoke `op` with
672 // that (where the `ref` on `x` is implied).
673 op(&place_with_id, pat);
676 PatKind::Tuple(ref subpats, dots_pos) => {
678 let total_fields = self.total_fields_in_tuple(pat.hir_id, pat.span)?;
680 for (i, subpat) in subpats.iter().enumerate_and_adjust(total_fields, dots_pos) {
681 let subpat_ty = self.pat_ty_adjusted(&subpat)?;
682 let projection_kind = ProjectionKind::Field(i as u32, VariantIdx::new(0));
684 self.cat_projection(pat, place_with_id.clone(), subpat_ty, projection_kind);
685 self.cat_pattern_(sub_place, &subpat, op)?;
689 PatKind::TupleStruct(ref qpath, ref subpats, dots_pos) => {
691 let variant_index = self.variant_index_for_adt(qpath, pat.hir_id, pat.span)?;
693 self.total_fields_in_adt_variant(pat.hir_id, variant_index, pat.span)?;
695 for (i, subpat) in subpats.iter().enumerate_and_adjust(total_fields, dots_pos) {
696 let subpat_ty = self.pat_ty_adjusted(&subpat)?;
697 let projection_kind = ProjectionKind::Field(i as u32, variant_index);
699 self.cat_projection(pat, place_with_id.clone(), subpat_ty, projection_kind);
700 self.cat_pattern_(sub_place, &subpat, op)?;
704 PatKind::Struct(ref qpath, field_pats, _) => {
705 // S { f1: p1, ..., fN: pN }
707 let variant_index = self.variant_index_for_adt(qpath, pat.hir_id, pat.span)?;
709 for fp in field_pats {
710 let field_ty = self.pat_ty_adjusted(&fp.pat)?;
711 let field_index = self
716 .expect("no index for a field");
718 let field_place = self.cat_projection(
720 place_with_id.clone(),
722 ProjectionKind::Field(field_index as u32, variant_index),
724 self.cat_pattern_(field_place, &fp.pat, op)?;
728 PatKind::Or(pats) => {
730 self.cat_pattern_(place_with_id.clone(), &pat, op)?;
734 PatKind::Binding(.., Some(ref subpat)) => {
735 self.cat_pattern_(place_with_id, &subpat, op)?;
738 PatKind::Box(ref subpat) | PatKind::Ref(ref subpat, _) => {
739 // box p1, &p1, &mut p1. we can ignore the mutability of
740 // PatKind::Ref since that information is already contained
742 let subplace = self.cat_deref(pat, place_with_id)?;
743 self.cat_pattern_(subplace, &subpat, op)?;
746 PatKind::Slice(before, ref slice, after) => {
747 let element_ty = match place_with_id.place.ty().builtin_index() {
750 debug!("explicit index of non-indexable type {:?}", place_with_id);
754 let elt_place = self.cat_projection(
756 place_with_id.clone(),
758 ProjectionKind::Index,
760 for before_pat in before {
761 self.cat_pattern_(elt_place.clone(), &before_pat, op)?;
763 if let Some(ref slice_pat) = *slice {
764 let slice_pat_ty = self.pat_ty_adjusted(&slice_pat)?;
765 let slice_place = self.cat_projection(
769 ProjectionKind::Subslice,
771 self.cat_pattern_(slice_place, &slice_pat, op)?;
773 for after_pat in after {
774 self.cat_pattern_(elt_place.clone(), &after_pat, op)?;
779 | PatKind::Binding(.., None)