Skip to content

Commit 8d9f4a1

Browse files
committed
rustc: rename all occurences of "freevar" to "upvar".
1 parent 125dc60 commit 8d9f4a1

File tree

20 files changed

+94
-94
lines changed

20 files changed

+94
-94
lines changed

src/librustc/hir/def.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ pub enum Res<Id = hir::HirId> {
140140
SelfCtor(DefId /* impl */), // `DefId` refers to the impl
141141
Local(Id),
142142
Upvar(Id, // `HirId` of closed over local
143-
usize, // index in the `freevars` list of the closure
143+
usize, // index in the `upvars` list of the closure
144144
ast::NodeId), // expr node that creates the closure
145145

146146
// Macro namespace

src/librustc/hir/mod.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -2476,19 +2476,19 @@ impl ForeignItemKind {
24762476
}
24772477
}
24782478

2479-
/// A free variable referred to in a function.
2479+
/// A variable captured by a closure.
24802480
#[derive(Debug, Copy, Clone, RustcEncodable, RustcDecodable, HashStable)]
2481-
pub struct Freevar<Id = HirId> {
2482-
/// The variable being accessed free.
2481+
pub struct Upvar<Id = HirId> {
2482+
/// The variable being captured.
24832483
pub res: Res<Id>,
24842484

24852485
// First span where it is accessed (there can be multiple).
24862486
pub span: Span
24872487
}
24882488

2489-
impl<Id: fmt::Debug + Copy> Freevar<Id> {
2490-
pub fn map_id<R>(self, map: impl FnMut(Id) -> R) -> Freevar<R> {
2491-
Freevar {
2489+
impl<Id: fmt::Debug + Copy> Upvar<Id> {
2490+
pub fn map_id<R>(self, map: impl FnMut(Id) -> R) -> Upvar<R> {
2491+
Upvar {
24922492
res: self.res.map_id(map),
24932493
span: self.span,
24942494
}
@@ -2497,12 +2497,12 @@ impl<Id: fmt::Debug + Copy> Freevar<Id> {
24972497
pub fn var_id(&self) -> Id {
24982498
match self.res {
24992499
Res::Local(id) | Res::Upvar(id, ..) => id,
2500-
_ => bug!("Freevar::var_id: bad res ({:?})", self.res)
2500+
_ => bug!("Upvar::var_id: bad res ({:?})", self.res)
25012501
}
25022502
}
25032503
}
25042504

2505-
pub type FreevarMap = NodeMap<Vec<Freevar<ast::NodeId>>>;
2505+
pub type UpvarMap = NodeMap<Vec<Upvar<ast::NodeId>>>;
25062506

25072507
pub type CaptureModeMap = NodeMap<CaptureClause>;
25082508

src/librustc/infer/error_reporting/note.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
4646
err.span_note(span,
4747
"...so that pointer is not dereferenced outside its lifetime");
4848
}
49-
infer::FreeVariable(span, id) => {
49+
infer::ClosureCapture(span, id) => {
5050
err.span_note(span,
5151
&format!("...so that captured variable `{}` does not outlive the \
5252
enclosing closure",
@@ -214,7 +214,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
214214
"the reference is only valid for ", sup, "");
215215
err
216216
}
217-
infer::FreeVariable(span, id) => {
217+
infer::ClosureCapture(span, id) => {
218218
let mut err = struct_span_err!(self.tcx.sess,
219219
span,
220220
E0474,

src/librustc/infer/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,8 @@ pub enum SubregionOrigin<'tcx> {
264264
/// Dereference of reference must be within its lifetime
265265
DerefPointer(Span),
266266

267-
/// Closure bound must not outlive captured free variables
268-
FreeVariable(Span, ast::NodeId),
267+
/// Closure bound must not outlive captured variables
268+
ClosureCapture(Span, ast::NodeId),
269269

270270
/// Index into slice must be within its lifetime
271271
IndexSlice(Span),
@@ -1660,7 +1660,7 @@ impl<'tcx> SubregionOrigin<'tcx> {
16601660
InfStackClosure(a) => a,
16611661
InvokeClosure(a) => a,
16621662
DerefPointer(a) => a,
1663-
FreeVariable(a, _) => a,
1663+
ClosureCapture(a, _) => a,
16641664
IndexSlice(a) => a,
16651665
RelateObjectBound(a) => a,
16661666
RelateParamBound(a, _) => a,

src/librustc/middle/expr_use_visitor.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -931,32 +931,32 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
931931
debug!("walk_captures({:?})", closure_expr);
932932

933933
let closure_def_id = self.tcx().hir().local_def_id_from_hir_id(closure_expr.hir_id);
934-
if let Some(freevars) = self.tcx().freevars(closure_def_id) {
935-
for freevar in freevars.iter() {
936-
let var_hir_id = freevar.var_id();
934+
if let Some(upvars) = self.tcx().upvars(closure_def_id) {
935+
for upvar in upvars.iter() {
936+
let var_hir_id = upvar.var_id();
937937
let upvar_id = ty::UpvarId {
938938
var_path: ty::UpvarPath { hir_id: var_hir_id },
939939
closure_expr_id: closure_def_id.to_local(),
940940
};
941941
let upvar_capture = self.mc.tables.upvar_capture(upvar_id);
942942
let cmt_var = return_if_err!(self.cat_captured_var(closure_expr.hir_id,
943943
fn_decl_span,
944-
freevar));
944+
upvar));
945945
match upvar_capture {
946946
ty::UpvarCapture::ByValue => {
947947
let mode = copy_or_move(&self.mc,
948948
self.param_env,
949949
&cmt_var,
950950
CaptureMove);
951-
self.delegate.consume(closure_expr.hir_id, freevar.span, &cmt_var, mode);
951+
self.delegate.consume(closure_expr.hir_id, upvar.span, &cmt_var, mode);
952952
}
953953
ty::UpvarCapture::ByRef(upvar_borrow) => {
954954
self.delegate.borrow(closure_expr.hir_id,
955955
fn_decl_span,
956956
&cmt_var,
957957
upvar_borrow.region,
958958
upvar_borrow.kind,
959-
ClosureCapture(freevar.span));
959+
ClosureCapture(upvar.span));
960960
}
961961
}
962962
}
@@ -966,7 +966,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
966966
fn cat_captured_var(&mut self,
967967
closure_hir_id: hir::HirId,
968968
closure_span: Span,
969-
upvar: &hir::Freevar)
969+
upvar: &hir::Upvar)
970970
-> mc::McResult<mc::cmt_<'tcx>> {
971971
// Create the cmt for the variable being borrowed, from the
972972
// caller's perspective

src/librustc/middle/liveness.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl LiveNode {
144144

145145
#[derive(Copy, Clone, PartialEq, Debug)]
146146
enum LiveNodeKind {
147-
FreeVarNode(Span),
147+
UpvarNode(Span),
148148
ExprNode(Span),
149149
VarDefNode(Span),
150150
ExitNode
@@ -153,8 +153,8 @@ enum LiveNodeKind {
153153
fn live_node_kind_to_string(lnk: LiveNodeKind, tcx: TyCtxt<'_, '_, '_>) -> String {
154154
let cm = tcx.sess.source_map();
155155
match lnk {
156-
FreeVarNode(s) => {
157-
format!("Free var node [{}]", cm.span_to_string(s))
156+
UpvarNode(s) => {
157+
format!("Upvar node [{}]", cm.span_to_string(s))
158158
}
159159
ExprNode(s) => {
160160
format!("Expr node [{}]", cm.span_to_string(s))
@@ -484,11 +484,11 @@ fn visit_expr<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, expr: &'tcx Expr) {
484484
// construction site.
485485
let mut call_caps = Vec::new();
486486
let closure_def_id = ir.tcx.hir().local_def_id_from_hir_id(expr.hir_id);
487-
if let Some(freevars) = ir.tcx.freevars(closure_def_id) {
488-
call_caps.extend(freevars.iter().filter_map(|freevar| {
489-
if let Res::Local(rv) = freevar.res {
490-
let freevar_ln = ir.add_live_node(FreeVarNode(freevar.span));
491-
Some(CaptureInfo { ln: freevar_ln, var_hid: rv })
487+
if let Some(upvars) = ir.tcx.upvars(closure_def_id) {
488+
call_caps.extend(upvars.iter().filter_map(|upvar| {
489+
if let Res::Local(rv) = upvar.res {
490+
let upvar_ln = ir.add_live_node(UpvarNode(upvar.span));
491+
Some(CaptureInfo { ln: upvar_ln, var_hid: rv })
492492
} else {
493493
None
494494
}

src/librustc/mir/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2572,9 +2572,9 @@ impl<'tcx> Debug for Rvalue<'tcx> {
25722572
};
25732573
let mut struct_fmt = fmt.debug_struct(&name);
25742574

2575-
if let Some(freevars) = tcx.freevars(def_id) {
2576-
for (freevar, place) in freevars.iter().zip(places) {
2577-
let var_name = tcx.hir().name_by_hir_id(freevar.var_id());
2575+
if let Some(upvars) = tcx.upvars(def_id) {
2576+
for (upvar, place) in upvars.iter().zip(places) {
2577+
let var_name = tcx.hir().name_by_hir_id(upvar.var_id());
25782578
struct_fmt.field(&var_name.as_str(), place);
25792579
}
25802580
}
@@ -2591,9 +2591,9 @@ impl<'tcx> Debug for Rvalue<'tcx> {
25912591
tcx.hir().span_by_hir_id(hir_id));
25922592
let mut struct_fmt = fmt.debug_struct(&name);
25932593

2594-
if let Some(freevars) = tcx.freevars(def_id) {
2595-
for (freevar, place) in freevars.iter().zip(places) {
2596-
let var_name = tcx.hir().name_by_hir_id(freevar.var_id());
2594+
if let Some(upvars) = tcx.upvars(def_id) {
2595+
for (upvar, place) in upvars.iter().zip(places) {
2596+
let var_name = tcx.hir().name_by_hir_id(upvar.var_id());
25972597
struct_fmt.field(&var_name.as_str(), place);
25982598
}
25992599
}

src/librustc/query/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ rustc_queries! {
824824
desc { "generating a postorder list of CrateNums" }
825825
}
826826

827-
query freevars(_: DefId) -> Option<Lrc<Vec<hir::Freevar>>> {
827+
query upvars(_: DefId) -> Option<Lrc<Vec<hir::Upvar>>> {
828828
eval_always
829829
}
830830
query maybe_unused_trait_import(_: DefId) -> bool {

src/librustc/ty/context.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1071,10 +1071,10 @@ pub struct GlobalCtxt<'tcx> {
10711071

10721072
pub queries: query::Queries<'tcx>,
10731073

1074-
// Records the free variables referenced by every closure
1074+
// Records the captured variables referenced by every closure
10751075
// expression. Do not track deps for this, just recompute it from
10761076
// scratch every time.
1077-
freevars: FxHashMap<DefId, Lrc<Vec<hir::Freevar>>>,
1077+
upvars: FxHashMap<DefId, Lrc<Vec<hir::Upvar>>>,
10781078

10791079
maybe_unused_trait_imports: FxHashSet<DefId>,
10801080
maybe_unused_extern_crates: Vec<(DefId, Span)>,
@@ -1317,7 +1317,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
13171317
}).collect();
13181318
(k, Lrc::new(exports))
13191319
}).collect(),
1320-
freevars: resolutions.freevars.into_iter().map(|(k, v)| {
1320+
upvars: resolutions.upvars.into_iter().map(|(k, v)| {
13211321
let vars: Vec<_> = v.into_iter().map(|e| {
13221322
e.map_id(|id| hir.node_to_hir_id(id))
13231323
}).collect();
@@ -3055,7 +3055,7 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
30553055
assert_eq!(id, LOCAL_CRATE);
30563056
Lrc::new(middle::lang_items::collect(tcx))
30573057
};
3058-
providers.freevars = |tcx, id| tcx.gcx.freevars.get(&id).cloned();
3058+
providers.upvars = |tcx, id| tcx.gcx.upvars.get(&id).cloned();
30593059
providers.maybe_unused_trait_import = |tcx, id| {
30603060
tcx.maybe_unused_trait_imports.contains(&id)
30613061
};

src/librustc/ty/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub use self::BorrowKind::*;
88
pub use self::IntVarValue::*;
99
pub use self::fold::TypeFoldable;
1010

11-
use crate::hir::{map as hir_map, FreevarMap, GlobMap, TraitMap};
11+
use crate::hir::{map as hir_map, UpvarMap, GlobMap, TraitMap};
1212
use crate::hir::Node;
1313
use crate::hir::def::{Res, DefKind, CtorOf, CtorKind, ExportMap};
1414
use crate::hir::def_id::{CrateNum, DefId, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
@@ -122,7 +122,7 @@ mod sty;
122122

123123
#[derive(Clone)]
124124
pub struct Resolutions {
125-
pub freevars: FreevarMap,
125+
pub upvars: UpvarMap,
126126
pub trait_map: TraitMap,
127127
pub maybe_unused_trait_imports: NodeSet,
128128
pub maybe_unused_extern_crates: Vec<(NodeId, Span)>,

src/librustc/ty/print/pretty.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
582582
if let Some(hir_id) = self.tcx().hir().as_local_hir_id(did) {
583583
p!(write("@{:?}", self.tcx().hir().span_by_hir_id(hir_id)));
584584
let mut sep = " ";
585-
for (freevar, upvar_ty) in self.tcx().freevars(did)
585+
for (upvar, upvar_ty) in self.tcx().upvars(did)
586586
.as_ref()
587587
.map_or(&[][..], |v| &v[..])
588588
.iter()
@@ -591,7 +591,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
591591
p!(
592592
write("{}{}:",
593593
sep,
594-
self.tcx().hir().name_by_hir_id(freevar.var_id())),
594+
self.tcx().hir().name_by_hir_id(upvar.var_id())),
595595
print(upvar_ty));
596596
sep = ", ";
597597
}
@@ -625,7 +625,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
625625
p!(write("@{:?}", self.tcx().hir().span_by_hir_id(hir_id)));
626626
}
627627
let mut sep = " ";
628-
for (freevar, upvar_ty) in self.tcx().freevars(did)
628+
for (upvar, upvar_ty) in self.tcx().upvars(did)
629629
.as_ref()
630630
.map_or(&[][..], |v| &v[..])
631631
.iter()
@@ -634,7 +634,7 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>:
634634
p!(
635635
write("{}{}:",
636636
sep,
637-
self.tcx().hir().name_by_hir_id(freevar.var_id())),
637+
self.tcx().hir().name_by_hir_id(upvar.var_id())),
638638
print(upvar_ty));
639639
sep = ", ";
640640
}

src/librustc_interface/passes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ impl ExpansionResult {
180180
ExpansionResult {
181181
defs: Steal::new(resolver.definitions),
182182
resolutions: Steal::new(Resolutions {
183-
freevars: resolver.freevars,
183+
upvars: resolver.upvars,
184184
export_map: resolver.export_map,
185185
trait_map: resolver.trait_map,
186186
glob_map: resolver.glob_map,
@@ -199,7 +199,7 @@ impl ExpansionResult {
199199
ExpansionResult {
200200
defs: Steal::new(resolver.definitions.clone()),
201201
resolutions: Steal::new(Resolutions {
202-
freevars: resolver.freevars.clone(),
202+
upvars: resolver.upvars.clone(),
203203
export_map: resolver.export_map.clone(),
204204
trait_map: resolver.trait_map.clone(),
205205
glob_map: resolver.glob_map.clone(),

src/librustc_mir/borrow_check/error_reporting.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1814,12 +1814,12 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
18141814
ty::Array(ty, _) | ty::Slice(ty) =>
18151815
self.describe_field_from_ty(&ty, field, variant_index),
18161816
ty::Closure(def_id, _) | ty::Generator(def_id, _, _) => {
1817-
// `tcx.freevars(def_id)` returns an `Option`, which is `None` in case
1817+
// `tcx.upvars(def_id)` returns an `Option`, which is `None` in case
18181818
// the closure comes from another crate. But in that case we wouldn't
18191819
// be borrowck'ing it, so we can just unwrap:
1820-
let freevar = self.infcx.tcx.freevars(def_id).unwrap()[field.index()];
1820+
let upvar = self.infcx.tcx.upvars(def_id).unwrap()[field.index()];
18211821

1822-
self.infcx.tcx.hir().name_by_hir_id(freevar.var_id()).to_string()
1822+
self.infcx.tcx.hir().name_by_hir_id(upvar.var_id()).to_string()
18231823
}
18241824
_ => {
18251825
// Might need a revision when the fields in trait RFC is implemented
@@ -2609,7 +2609,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
26092609
if let hir::ExprKind::Closure(
26102610
.., args_span, _
26112611
) = expr {
2612-
for (v, place) in self.infcx.tcx.freevars(def_id)?.iter().zip(places) {
2612+
for (v, place) in self.infcx.tcx.upvars(def_id)?.iter().zip(places) {
26132613
match place {
26142614
Operand::Copy(place) |
26152615
Operand::Move(place) if target_place == place => {

src/librustc_mir/hair/cx/expr.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -516,10 +516,10 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
516516
span_bug!(expr.span, "closure expr w/o closure type: {:?}", closure_ty);
517517
}
518518
};
519-
let upvars = cx.tcx.freevars(def_id).iter()
520-
.flat_map(|freevars| freevars.iter())
519+
let upvars = cx.tcx.upvars(def_id).iter()
520+
.flat_map(|upvars| upvars.iter())
521521
.zip(substs.upvar_tys(def_id, cx.tcx))
522-
.map(|(freevar, ty)| capture_freevar(cx, expr, freevar, ty))
522+
.map(|(upvar, ty)| capture_upvar(cx, expr, upvar, ty))
523523
.collect();
524524
ExprKind::Closure {
525525
closure_id: def_id,
@@ -1184,12 +1184,12 @@ fn overloaded_place<'a, 'gcx, 'tcx>(
11841184
ExprKind::Deref { arg: ref_expr.to_ref() }
11851185
}
11861186

1187-
fn capture_freevar<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
1187+
fn capture_upvar<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
11881188
closure_expr: &'tcx hir::Expr,
1189-
freevar: &hir::Freevar,
1190-
freevar_ty: Ty<'tcx>)
1189+
upvar: &hir::Upvar,
1190+
upvar_ty: Ty<'tcx>)
11911191
-> ExprRef<'tcx> {
1192-
let var_hir_id = freevar.var_id();
1192+
let var_hir_id = upvar.var_id();
11931193
let upvar_id = ty::UpvarId {
11941194
var_path: ty::UpvarPath { hir_id: var_hir_id },
11951195
closure_expr_id: cx.tcx.hir().local_def_id_from_hir_id(closure_expr.hir_id).to_local(),
@@ -1201,7 +1201,7 @@ fn capture_freevar<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
12011201
temp_lifetime,
12021202
ty: var_ty,
12031203
span: closure_expr.span,
1204-
kind: convert_var(cx, closure_expr, freevar.res),
1204+
kind: convert_var(cx, closure_expr, upvar.res),
12051205
};
12061206
match upvar_capture {
12071207
ty::UpvarCapture::ByValue => captured_var.to_ref(),
@@ -1213,7 +1213,7 @@ fn capture_freevar<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
12131213
};
12141214
Expr {
12151215
temp_lifetime,
1216-
ty: freevar_ty,
1216+
ty: upvar_ty,
12171217
span: closure_expr.span,
12181218
kind: ExprKind::Borrow {
12191219
borrow_kind,

src/librustc_mir/interpret/validity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl<'rt, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> ValidityVisitor<'rt, 'a, '
170170
if def_id.is_local() {
171171
let tables = self.ecx.tcx.typeck_tables_of(def_id);
172172
if let Some(upvars) = tables.upvar_list.get(&def_id) {
173-
// Sometimes the index is beyond the number of freevars (seen
173+
// Sometimes the index is beyond the number of upvars (seen
174174
// for a generator).
175175
if let Some(upvar_id) = upvars.get(field) {
176176
let var_hir_id = upvar_id.var_path.hir_id;

0 commit comments

Comments
 (0)