Skip to content

Commit 7474be0

Browse files
committed
Make ty::ParameterEnvironment, not ty::ctxt, implement Typer and
`UnboxedClosureTyper`. This requires adding a `tcx` field to `ParameterEnvironment` but generally simplifies everything since we only need to pass along an `UnboxedClosureTyper` or `Typer`.
1 parent 83ef304 commit 7474be0

File tree

24 files changed

+288
-259
lines changed

24 files changed

+288
-259
lines changed

src/librustc/middle/check_match.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl<'a> FromIterator<Vec<&'a Pat>> for Matrix<'a> {
9999

100100
pub struct MatchCheckCtxt<'a, 'tcx: 'a> {
101101
pub tcx: &'a ty::ctxt<'tcx>,
102-
pub param_env: ParameterEnvironment<'tcx>,
102+
pub param_env: ParameterEnvironment<'a, 'tcx>,
103103
}
104104

105105
#[deriving(Clone, PartialEq)]
@@ -148,7 +148,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for MatchCheckCtxt<'a, 'tcx> {
148148
pub fn check_crate(tcx: &ty::ctxt) {
149149
visit::walk_crate(&mut MatchCheckCtxt {
150150
tcx: tcx,
151-
param_env: ty::empty_parameter_environment(),
151+
param_env: ty::empty_parameter_environment(tcx),
152152
}, tcx.map.krate());
153153
tcx.sess.abort_if_errors();
154154
}
@@ -1061,8 +1061,7 @@ fn check_for_mutation_in_guard<'a, 'tcx>(cx: &'a MatchCheckCtxt<'a, 'tcx>,
10611061
cx: cx,
10621062
};
10631063
let mut visitor = ExprUseVisitor::new(&mut checker,
1064-
checker.cx.tcx,
1065-
&cx.param_env);
1064+
&checker.cx.param_env);
10661065
visitor.walk_expr(guard);
10671066
}
10681067

src/librustc/middle/check_rvalues.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl<'a, 'tcx, 'v> visit::Visitor<'v> for RvalueContext<'a, 'tcx> {
4141
{
4242
let param_env = ParameterEnvironment::for_item(self.tcx, fn_id);
4343
let mut delegate = RvalueContextDelegate { tcx: self.tcx, param_env: &param_env };
44-
let mut euv = euv::ExprUseVisitor::new(&mut delegate, self.tcx, &param_env);
44+
let mut euv = euv::ExprUseVisitor::new(&mut delegate, &param_env);
4545
euv.walk_fn(fd, b);
4646
}
4747
visit::walk_fn(self, fk, fd, b, s)
@@ -50,7 +50,7 @@ impl<'a, 'tcx, 'v> visit::Visitor<'v> for RvalueContext<'a, 'tcx> {
5050

5151
struct RvalueContextDelegate<'a, 'tcx: 'a> {
5252
tcx: &'a ty::ctxt<'tcx>,
53-
param_env: &'a ty::ParameterEnvironment<'tcx>,
53+
param_env: &'a ty::ParameterEnvironment<'a,'tcx>,
5454
}
5555

5656
impl<'a, 'tcx> euv::Delegate<'tcx> for RvalueContextDelegate<'a, 'tcx> {

src/librustc/middle/check_static.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct CheckStaticVisitor<'a, 'tcx: 'a> {
5454
}
5555

5656
struct GlobalVisitor<'a,'b,'tcx:'a+'b>(
57-
euv::ExprUseVisitor<'a,'b,'tcx,ty::ctxt<'tcx>>);
57+
euv::ExprUseVisitor<'a,'b,'tcx,ty::ParameterEnvironment<'b,'tcx>>);
5858
struct GlobalChecker {
5959
static_consumptions: NodeSet,
6060
const_borrows: NodeSet,
@@ -70,8 +70,8 @@ pub fn check_crate(tcx: &ty::ctxt) {
7070
static_local_borrows: NodeSet::new(),
7171
};
7272
{
73-
let param_env = ty::empty_parameter_environment();
74-
let visitor = euv::ExprUseVisitor::new(&mut checker, tcx, &param_env);
73+
let param_env = ty::empty_parameter_environment(tcx);
74+
let visitor = euv::ExprUseVisitor::new(&mut checker, &param_env);
7575
visit::walk_crate(&mut GlobalVisitor(visitor), tcx.map.krate());
7676
}
7777
visit::walk_crate(&mut CheckStaticVisitor {
@@ -121,8 +121,8 @@ impl<'a, 'tcx> CheckStaticVisitor<'a, 'tcx> {
121121
let mut fulfill_cx = traits::FulfillmentContext::new();
122122
let cause = traits::ObligationCause::new(e.span, e.id, traits::SharedStatic);
123123
fulfill_cx.register_builtin_bound(&infcx, ty, ty::BoundSync, cause);
124-
let env = ty::empty_parameter_environment();
125-
match fulfill_cx.select_all_or_error(&infcx, &env, self.tcx) {
124+
let env = ty::empty_parameter_environment(self.tcx);
125+
match fulfill_cx.select_all_or_error(&infcx, &env) {
126126
Ok(()) => { },
127127
Err(ref errors) => {
128128
traits::report_fulfillment_errors(&infcx, errors);

src/librustc/middle/expr_use_visitor.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use self::OverloadedCallType::*;
2323
use middle::{def, region, pat_util};
2424
use middle::mem_categorization as mc;
2525
use middle::mem_categorization::Typer;
26-
use middle::ty::{mod, ParameterEnvironment, Ty};
26+
use middle::ty::{mod};
2727
use middle::ty::{MethodCall, MethodObject, MethodTraitObject};
2828
use middle::ty::{MethodOrigin, MethodParam, MethodTypeParam};
2929
use middle::ty::{MethodStatic, MethodStaticUnboxedClosure};
@@ -299,7 +299,8 @@ pub struct ExprUseVisitor<'d,'t,'tcx:'t,TYPER:'t> {
299299
typer: &'t TYPER,
300300
mc: mc::MemCategorizationContext<'t,TYPER>,
301301
delegate: &'d mut (Delegate<'tcx>+'d),
302-
param_env: &'t ParameterEnvironment<'tcx>,
302+
}
303+
303304
// If the TYPER results in an error, it's because the type check
304305
// failed (or will fail, when the error is uncovered and reported
305306
// during writeback). In this case, we just ignore this part of the
@@ -324,14 +325,12 @@ enum PassArgs {
324325

325326
impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
326327
pub fn new(delegate: &'d mut Delegate<'tcx>,
327-
typer: &'t TYPER,
328-
param_env: &'t ParameterEnvironment<'tcx>)
328+
typer: &'t TYPER)
329329
-> ExprUseVisitor<'d,'t,'tcx,TYPER> {
330330
ExprUseVisitor {
331331
typer: typer,
332332
mc: mc::MemCategorizationContext::new(typer),
333333
delegate: delegate,
334-
param_env: param_env,
335334
}
336335
}
337336

src/librustc/middle/intrinsicck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ struct IntrinsicCheckingVisitor<'a, 'tcx: 'a> {
4141
// environments for each function we encounter. When we find a
4242
// call to `transmute`, we can check it in the context of the top
4343
// of the stack (which ought not to be empty).
44-
param_envs: Vec<ty::ParameterEnvironment<'tcx>>,
44+
param_envs: Vec<ty::ParameterEnvironment<'a,'tcx>>,
4545

4646
// Dummy sized/unsized types that use to substitute for type
4747
// parameters in order to estimate how big a type will be for any

src/librustc/middle/mem_categorization.rs

Lines changed: 73 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ pub type McResult<T> = Result<T, ()>;
272272
/// can be sure that only `Ok` results will occur.
273273
pub trait Typer<'tcx> : ty::UnboxedClosureTyper<'tcx> {
274274
fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx>;
275-
fn param_env<'a>(&'a self) -> &'a ty::ParameterEnvironment<'a, 'tcx>;
276275
fn node_ty(&self, id: ast::NodeId) -> McResult<Ty<'tcx>>;
277276
fn expr_ty_adjusted(&self, expr: &ast::Expr) -> McResult<Ty<'tcx>>;
278277
fn type_moves_by_default(&self, span: Span, ty: Ty<'tcx>) -> bool;
@@ -1292,77 +1291,8 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
12921291
self.tcx().sess.span_bug(pat.span, "unexpanded macro");
12931292
}
12941293
}
1295-
}
12961294

1297-
pub fn cmt_to_string(&self, cmt: &cmt_<'tcx>) -> String {
1298-
fn upvar_to_string(upvar: &Upvar, is_copy: bool) -> String {
1299-
if upvar.is_unboxed {
1300-
let kind = match upvar.kind {
1301-
ty::FnUnboxedClosureKind => "Fn",
1302-
ty::FnMutUnboxedClosureKind => "FnMut",
1303-
ty::FnOnceUnboxedClosureKind => "FnOnce"
1304-
};
1305-
format!("captured outer variable in an `{}` closure", kind)
1306-
} else {
1307-
(match (upvar.kind, is_copy) {
1308-
(ty::FnOnceUnboxedClosureKind, true) => "captured outer variable in a proc",
1309-
_ => "captured outer variable"
1310-
}).to_string()
1311-
}
1312-
}
1313-
1314-
match cmt.cat {
1315-
cat_static_item => {
1316-
"static item".to_string()
1317-
}
1318-
cat_rvalue(..) => {
1319-
"non-lvalue".to_string()
1320-
}
1321-
cat_local(vid) => {
1322-
match self.tcx().map.find(vid) {
1323-
Some(ast_map::NodeArg(_)) => {
1324-
"argument".to_string()
1325-
}
1326-
_ => "local variable".to_string()
1327-
}
1328-
}
1329-
cat_deref(_, _, pk) => {
1330-
let upvar = cmt.upvar();
1331-
match upvar.as_ref().map(|i| &i.cat) {
1332-
Some(&cat_upvar(ref var)) => {
1333-
upvar_to_string(var, false)
1334-
}
1335-
Some(_) => unreachable!(),
1336-
None => {
1337-
match pk {
1338-
Implicit(..) => {
1339-
"dereference (dereference is implicit, due to indexing)".to_string()
1340-
}
1341-
Unique => format!("dereference of `{}`", ptr_sigil(pk)),
1342-
_ => format!("dereference of `{}`-pointer", ptr_sigil(pk))
1343-
}
1344-
}
1345-
}
1346-
}
1347-
cat_interior(_, InteriorField(NamedField(_))) => {
1348-
"field".to_string()
1349-
}
1350-
cat_interior(_, InteriorField(PositionalField(_))) => {
1351-
"anonymous field".to_string()
1352-
}
1353-
cat_interior(_, InteriorElement(VecElement)) => {
1354-
"vec content".to_string()
1355-
}
1356-
cat_interior(_, InteriorElement(OtherElement)) => {
1357-
"indexed content".to_string()
1358-
}
1359-
cat_upvar(ref var) => {
1360-
upvar_to_string(var, true)
1361-
}
1362-
cat_downcast(ref cmt, _) => {
1363-
self.cmt_to_string(&**cmt)
1364-
}
1365-
}
1295+
Ok(())
13661296
}
13671297
}
13681298

@@ -1474,6 +1404,78 @@ impl<'tcx> cmt_<'tcx> {
14741404
NoteNone => None
14751405
}
14761406
}
1407+
1408+
1409+
pub fn descriptive_string(&self, tcx: &ty::ctxt) -> String {
1410+
fn upvar_to_string(upvar: &Upvar, is_copy: bool) -> String {
1411+
if upvar.is_unboxed {
1412+
let kind = match upvar.kind {
1413+
ty::FnUnboxedClosureKind => "Fn",
1414+
ty::FnMutUnboxedClosureKind => "FnMut",
1415+
ty::FnOnceUnboxedClosureKind => "FnOnce"
1416+
};
1417+
format!("captured outer variable in an `{}` closure", kind)
1418+
} else {
1419+
(match (upvar.kind, is_copy) {
1420+
(ty::FnOnceUnboxedClosureKind, true) => "captured outer variable in a proc",
1421+
_ => "captured outer variable"
1422+
}).to_string()
1423+
}
1424+
}
1425+
1426+
match self.cat {
1427+
cat_static_item => {
1428+
"static item".to_string()
1429+
}
1430+
cat_rvalue(..) => {
1431+
"non-lvalue".to_string()
1432+
}
1433+
cat_local(vid) => {
1434+
match tcx.map.find(vid) {
1435+
Some(ast_map::NodeArg(_)) => {
1436+
"argument".to_string()
1437+
}
1438+
_ => "local variable".to_string()
1439+
}
1440+
}
1441+
cat_deref(_, _, pk) => {
1442+
let upvar = self.upvar();
1443+
match upvar.as_ref().map(|i| &i.cat) {
1444+
Some(&cat_upvar(ref var)) => {
1445+
upvar_to_string(var, false)
1446+
}
1447+
Some(_) => unreachable!(),
1448+
None => {
1449+
match pk {
1450+
Implicit(..) => {
1451+
"dereference (dereference is implicit, due to indexing)".to_string()
1452+
}
1453+
Unique => format!("dereference of `{}`", ptr_sigil(pk)),
1454+
_ => format!("dereference of `{}`-pointer", ptr_sigil(pk))
1455+
}
1456+
}
1457+
}
1458+
}
1459+
cat_interior(_, InteriorField(NamedField(_))) => {
1460+
"field".to_string()
1461+
}
1462+
cat_interior(_, InteriorField(PositionalField(_))) => {
1463+
"anonymous field".to_string()
1464+
}
1465+
cat_interior(_, InteriorElement(VecElement)) => {
1466+
"vec content".to_string()
1467+
}
1468+
cat_interior(_, InteriorElement(OtherElement)) => {
1469+
"indexed content".to_string()
1470+
}
1471+
cat_upvar(ref var) => {
1472+
upvar_to_string(var, true)
1473+
}
1474+
cat_downcast(ref cmt, _) => {
1475+
cmt.descriptive_string(tcx)
1476+
}
1477+
}
1478+
}
14771479
}
14781480

14791481
impl<'tcx> Repr<'tcx> for cmt_<'tcx> {

src/librustc/middle/traits/coherence.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ pub fn impl_can_satisfy(infcx: &InferCtxt,
4242

4343
// Determine whether `impl2` can provide an implementation for those
4444
// same types.
45-
let param_env = ty::empty_parameter_environment();
46-
let mut selcx = SelectionContext::intercrate(infcx, &param_env, infcx.tcx);
45+
let param_env = ty::empty_parameter_environment(infcx.tcx);
46+
let mut selcx = SelectionContext::intercrate(infcx, &param_env);
4747
let obligation = Obligation::new(ObligationCause::dummy(),
4848
ty::Binder(ty::TraitPredicate {
4949
trait_ref: Rc::new(impl1_trait_ref),

src/librustc/middle/traits/fulfill.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ impl<'tcx> FulfillmentContext<'tcx> {
109109
/// `projection_ty` again.
110110
pub fn normalize_projection_type<'a>(&mut self,
111111
infcx: &InferCtxt<'a,'tcx>,
112-
param_env: &ty::ParameterEnvironment<'tcx>,
113112
typer: &ty::UnboxedClosureTyper<'tcx>,
114113
projection_ty: ty::ProjectionTy<'tcx>,
115114
cause: ObligationCause<'tcx>)
@@ -122,7 +121,7 @@ impl<'tcx> FulfillmentContext<'tcx> {
122121

123122
// FIXME(#20304) -- cache
124123

125-
let mut selcx = SelectionContext::new(infcx, param_env, typer);
124+
let mut selcx = SelectionContext::new(infcx, typer);
126125
let normalized = project::normalize_projection_type(&mut selcx, projection_ty, cause, 0);
127126

128127
for obligation in normalized.obligations.into_iter() {
@@ -186,11 +185,10 @@ impl<'tcx> FulfillmentContext<'tcx> {
186185

187186
pub fn select_all_or_error<'a>(&mut self,
188187
infcx: &InferCtxt<'a,'tcx>,
189-
param_env: &ty::ParameterEnvironment<'tcx>,
190188
typer: &ty::UnboxedClosureTyper<'tcx>)
191189
-> Result<(),Vec<FulfillmentError<'tcx>>>
192190
{
193-
try!(self.select_where_possible(infcx, param_env, typer));
191+
try!(self.select_where_possible(infcx, typer));
194192

195193
// Anything left is ambiguous.
196194
let errors: Vec<FulfillmentError> =
@@ -212,21 +210,19 @@ impl<'tcx> FulfillmentContext<'tcx> {
212210
/// results in `O(n^2)` performance (#18208).
213211
pub fn select_new_obligations<'a>(&mut self,
214212
infcx: &InferCtxt<'a,'tcx>,
215-
param_env: &ty::ParameterEnvironment<'tcx>,
216213
typer: &ty::UnboxedClosureTyper<'tcx>)
217214
-> Result<(),Vec<FulfillmentError<'tcx>>>
218215
{
219-
let mut selcx = SelectionContext::new(infcx, param_env, typer);
216+
let mut selcx = SelectionContext::new(infcx, typer);
220217
self.select(&mut selcx, true)
221218
}
222219

223220
pub fn select_where_possible<'a>(&mut self,
224221
infcx: &InferCtxt<'a,'tcx>,
225-
param_env: &ty::ParameterEnvironment<'tcx>,
226222
typer: &ty::UnboxedClosureTyper<'tcx>)
227223
-> Result<(),Vec<FulfillmentError<'tcx>>>
228224
{
229-
let mut selcx = SelectionContext::new(infcx, param_env, typer);
225+
let mut selcx = SelectionContext::new(infcx, typer);
230226
self.select(&mut selcx, false)
231227
}
232228

0 commit comments

Comments
 (0)