//! unit-tested and separated from the Rust source and compiler data
//! structures.
-use rustc::mir::repr::{BinOp, BorrowKind, Field, Literal, Mutability, UnOp,
- TypedConstVal};
-use rustc::middle::const_val::ConstVal;
+use rustc::mir::{BinOp, BorrowKind, Field, Literal, UnOp, TypedConstVal};
use rustc::hir::def_id::DefId;
use rustc::middle::region::CodeExtent;
use rustc::ty::subst::Substs;
pub mod cx;
+pub use rustc_const_eval::pattern::{BindingMode, Pattern, PatternKind, FieldPattern};
+
#[derive(Clone, Debug)]
pub struct Block<'tcx> {
pub extent: CodeExtent,
id: DefId,
},
Borrow {
- region: Region,
+ region: &'tcx Region,
borrow_kind: BorrowKind,
arg: ExprRef<'tcx>,
},
pub body: ExprRef<'tcx>,
}
-#[derive(Clone, Debug)]
-pub struct Pattern<'tcx> {
- pub ty: Ty<'tcx>,
- pub span: Span,
- pub kind: Box<PatternKind<'tcx>>,
-}
-
#[derive(Copy, Clone, Debug)]
pub enum LogicalOp {
And,
Or,
}
-#[derive(Clone, Debug)]
-pub enum PatternKind<'tcx> {
- Wild,
-
- /// x, ref x, x @ P, etc
- Binding {
- mutability: Mutability,
- name: ast::Name,
- mode: BindingMode,
- var: ast::NodeId,
- ty: Ty<'tcx>,
- subpattern: Option<Pattern<'tcx>>,
- },
-
- /// Foo(...) or Foo{...} or Foo, where `Foo` is a variant name from an adt with >1 variants
- Variant {
- adt_def: AdtDef<'tcx>,
- variant_index: usize,
- subpatterns: Vec<FieldPattern<'tcx>>,
- },
-
- /// (...), Foo(...), Foo{...}, or Foo, where `Foo` is a variant name from an adt with 1 variant
- Leaf {
- subpatterns: Vec<FieldPattern<'tcx>>,
- },
-
- /// box P, &P, &mut P, etc
- Deref {
- subpattern: Pattern<'tcx>,
- },
-
- Constant {
- value: ConstVal,
- },
-
- Range {
- lo: Literal<'tcx>,
- hi: Literal<'tcx>,
- },
-
- /// matches against a slice, checking the length and extracting elements
- Slice {
- prefix: Vec<Pattern<'tcx>>,
- slice: Option<Pattern<'tcx>>,
- suffix: Vec<Pattern<'tcx>>,
- },
-
- /// fixed match against an array, irrefutable
- Array {
- prefix: Vec<Pattern<'tcx>>,
- slice: Option<Pattern<'tcx>>,
- suffix: Vec<Pattern<'tcx>>,
- },
-}
-
-#[derive(Copy, Clone, Debug)]
-pub enum BindingMode {
- ByValue,
- ByRef(Region, BorrowKind),
-}
-
-#[derive(Clone, Debug)]
-pub struct FieldPattern<'tcx> {
- pub field: Field,
- pub pattern: Pattern<'tcx>,
-}
-
///////////////////////////////////////////////////////////////////////////
// The Mirror trait