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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 8 additions & 8 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 7 additions & 7 deletions
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

Lines changed: 8 additions & 8 deletions
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

Lines changed: 6 additions & 6 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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)>,

0 commit comments

Comments
 (0)