1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
use middle::expr_use_visitor as euv;
use middle::mem_categorization as mc;
use middle::ty::ParameterEnvironment;
use middle::ty;
use util::ppaux::ty_to_string;
use syntax::ast;
use syntax::codemap::Span;
use syntax::visit;
pub fn check_crate(tcx: &ty::ctxt,
krate: &ast::Crate) {
let mut rvcx = RvalueContext { tcx: tcx };
visit::walk_crate(&mut rvcx, krate);
}
struct RvalueContext<'a, 'tcx: 'a> {
tcx: &'a ty::ctxt<'tcx>,
}
impl<'a, 'tcx, 'v> visit::Visitor<'v> for RvalueContext<'a, 'tcx> {
fn visit_fn(&mut self,
fk: visit::FnKind<'v>,
fd: &'v ast::FnDecl,
b: &'v ast::Block,
s: Span,
fn_id: ast::NodeId) {
{
let param_env = ParameterEnvironment::for_item(self.tcx, fn_id);
let mut delegate = RvalueContextDelegate { tcx: self.tcx, param_env: ¶m_env };
let mut euv = euv::ExprUseVisitor::new(&mut delegate, ¶m_env);
euv.walk_fn(fd, b);
}
visit::walk_fn(self, fk, fd, b, s)
}
}
struct RvalueContextDelegate<'a, 'tcx: 'a> {
tcx: &'a ty::ctxt<'tcx>,
param_env: &'a ty::ParameterEnvironment<'a,'tcx>,
}
impl<'a, 'tcx> euv::Delegate<'tcx> for RvalueContextDelegate<'a, 'tcx> {
fn consume(&mut self,
_: ast::NodeId,
span: Span,
cmt: mc::cmt<'tcx>,
_: euv::ConsumeMode) {
debug!("consume; cmt: {:?}; type: {}", *cmt, ty_to_string(self.tcx, cmt.ty));
if !ty::type_is_sized(self.param_env, span, cmt.ty) {
span_err!(self.tcx.sess, span, E0161,
"cannot move a value of type {0}: the size of {0} cannot be statically determined",
ty_to_string(self.tcx, cmt.ty));
}
}
fn matched_pat(&mut self,
_matched_pat: &ast::Pat,
_cmt: mc::cmt,
_mode: euv::MatchMode) {}
fn consume_pat(&mut self,
_consume_pat: &ast::Pat,
_cmt: mc::cmt,
_mode: euv::ConsumeMode) {
}
fn borrow(&mut self,
_borrow_id: ast::NodeId,
_borrow_span: Span,
_cmt: mc::cmt,
_loan_region: ty::Region,
_bk: ty::BorrowKind,
_loan_cause: euv::LoanCause) {
}
fn decl_without_init(&mut self,
_id: ast::NodeId,
_span: Span) {
}
fn mutate(&mut self,
_assignment_id: ast::NodeId,
_assignment_span: Span,
_assignee_cmt: mc::cmt,
_mode: euv::MutateMode) {
}
}