Skip to content

Commit 40bd145

Browse files
committed
Auto merge of #60567 - Manishearth:rollup-rjagqnw, r=Manishearth
Rollup of 5 pull requests Successful merges: - #60131 (Fix broken link in rustc_plugin doc) - #60426 (Stop `-O`/`-C opt-level` and `-g`/`-C debuginfo` conflicting) - #60515 (use span instead of div for since version) - #60530 (rustc: rename all occurences of "freevar" to "upvar".) - #60536 (Correct code points to match their textual description) Failed merges: r? @ghost
2 parents d628c2e + ff7ef11 commit 40bd145

File tree

31 files changed

+188
-171
lines changed

31 files changed

+188
-171
lines changed

Cargo.lock

+10-10
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ dependencies = [
169169
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
170170
"cmake 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
171171
"filetime 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
172-
"getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
172+
"getopts 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)",
173173
"lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
174174
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
175175
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -463,7 +463,7 @@ dependencies = [
463463
"diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
464464
"env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)",
465465
"filetime 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
466-
"getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
466+
"getopts 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)",
467467
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
468468
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
469469
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -484,7 +484,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
484484
dependencies = [
485485
"diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
486486
"filetime 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
487-
"getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
487+
"getopts 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)",
488488
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
489489
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
490490
"miow 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -974,7 +974,7 @@ dependencies = [
974974

975975
[[package]]
976976
name = "getopts"
977-
version = "0.2.18"
977+
version = "0.2.19"
978978
source = "registry+https://github.com/rust-lang/crates.io-index"
979979
dependencies = [
980980
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1989,7 +1989,7 @@ version = "0.1.2"
19891989
source = "registry+https://github.com/rust-lang/crates.io-index"
19901990
dependencies = [
19911991
"bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
1992-
"getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
1992+
"getopts 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)",
19931993
]
19941994

19951995
[[package]]
@@ -2008,7 +2008,7 @@ version = "0.5.0"
20082008
source = "registry+https://github.com/rust-lang/crates.io-index"
20092009
dependencies = [
20102010
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
2011-
"getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
2011+
"getopts 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)",
20122012
"memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
20132013
"unicase 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
20142014
]
@@ -3095,7 +3095,7 @@ dependencies = [
30953095
"dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
30963096
"env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
30973097
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
3098-
"getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
3098+
"getopts 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)",
30993099
"ignore 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
31003100
"itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
31013101
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3522,7 +3522,7 @@ dependencies = [
35223522
name = "test"
35233523
version = "0.0.0"
35243524
dependencies = [
3525-
"getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
3525+
"getopts 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)",
35263526
"proc_macro 0.0.0",
35273527
"term 0.0.0",
35283528
]
@@ -3532,7 +3532,7 @@ name = "tester"
35323532
version = "0.5.0"
35333533
source = "registry+https://github.com/rust-lang/crates.io-index"
35343534
dependencies = [
3535-
"getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
3535+
"getopts 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)",
35363536
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
35373537
"term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
35383538
]
@@ -4132,7 +4132,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
41324132
"checksum futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)" = "1a70b146671de62ec8c8ed572219ca5d594d9b06c0b364d5e67b722fc559b48c"
41334133
"checksum fwdansi 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "34dd4c507af68d37ffef962063dfa1944ce0dd4d5b82043dbab1dabe088610c3"
41344134
"checksum generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d"
4135-
"checksum getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "0a7292d30132fb5424b354f5dc02512a86e4c516fe544bb7a25e7f266951b797"
4135+
"checksum getopts 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)" = "72327b15c228bfe31f1390f93dd5e9279587f0463836393c9df719ce62a3e450"
41364136
"checksum git2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7339329bfa14a00223244311560d11f8f489b453fb90092af97f267a6090ab0"
41374137
"checksum git2-curl 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d58551e903ed7e2d6fe3a2f3c7efa3a784ec29b19d0fbb035aaf0497c183fbdd"
41384138
"checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"

src/bootstrap/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ build_helper = { path = "../build_helper" }
3939
cmake = "0.1.38"
4040
filetime = "0.2"
4141
num_cpus = "1.0"
42-
getopts = "0.2.18"
42+
getopts = "0.2.19"
4343
cc = "1.0.35"
4444
libc = "0.2"
4545
serde = "1.0.8"

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -931,42 +931,42 @@ 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-
self.tcx().with_freevars(closure_expr.hir_id, |freevars| {
935-
for freevar in freevars {
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
}
963-
});
963+
}
964964
}
965965

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

+10-9
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))
@@ -483,16 +483,17 @@ fn visit_expr<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, expr: &'tcx Expr) {
483483
// in better error messages than just pointing at the closure
484484
// construction site.
485485
let mut call_caps = Vec::new();
486-
ir.tcx.with_freevars(expr.hir_id, |freevars| {
487-
call_caps.extend(freevars.iter().filter_map(|fv| {
488-
if let Res::Local(rv) = fv.res {
489-
let fv_ln = ir.add_live_node(FreeVarNode(fv.span));
490-
Some(CaptureInfo { ln: fv_ln, var_hid: rv })
486+
let closure_def_id = ir.tcx.hir().local_def_id_from_hir_id(expr.hir_id);
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 })
491492
} else {
492493
None
493494
}
494495
}));
495-
});
496+
}
496497
ir.set_captures(expr.hir_id, call_caps);
497498

498499
intravisit::walk_expr(ir, expr);

src/librustc/mir/mod.rs

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

2575-
tcx.with_freevars(hir_id, |freevars| {
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
}
2580-
});
2580+
}
25812581

25822582
struct_fmt.finish()
25832583
} else {
@@ -2591,12 +2591,12 @@ 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-
tcx.with_freevars(hir_id, |freevars| {
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
}
2599-
});
2599+
}
26002600

26012601
struct_fmt.finish()
26022602
} else {

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/session/config.rs

+25-6
Original file line numberDiff line numberDiff line change
@@ -2181,10 +2181,21 @@ pub fn build_session_options_and_crate_config(
21812181
TargetTriple::from_triple(host_triple())
21822182
};
21832183
let opt_level = {
2184-
if matches.opt_present("O") {
2185-
if cg.opt_level.is_some() {
2186-
early_error(error_format, "-O and -C opt-level both provided");
2184+
// The `-O` and `-C opt-level` flags specify the same setting, so we want to be able
2185+
// to use them interchangeably. However, because they're technically different flags,
2186+
// we need to work out manually which should take precedence if both are supplied (i.e.
2187+
// the rightmost flag). We do this by finding the (rightmost) position of both flags and
2188+
// comparing them. Note that if a flag is not found, its position will be `None`, which
2189+
// always compared less than `Some(_)`.
2190+
let max_o = matches.opt_positions("O").into_iter().max();
2191+
let max_c = matches.opt_strs_pos("C").into_iter().flat_map(|(i, s)| {
2192+
if let Some("opt-level") = s.splitn(2, '=').next() {
2193+
Some(i)
2194+
} else {
2195+
None
21872196
}
2197+
}).max();
2198+
if max_o > max_c {
21882199
OptLevel::Default
21892200
} else {
21902201
match cg.opt_level.as_ref().map(String::as_ref) {
@@ -2208,11 +2219,19 @@ pub fn build_session_options_and_crate_config(
22082219
}
22092220
}
22102221
};
2222+
// The `-g` and `-C debuginfo` flags specify the same setting, so we want to be able
2223+
// to use them interchangeably. See the note above (regarding `-O` and `-C opt-level`)
2224+
// for more details.
22112225
let debug_assertions = cg.debug_assertions.unwrap_or(opt_level == OptLevel::No);
2212-
let debuginfo = if matches.opt_present("g") {
2213-
if cg.debuginfo.is_some() {
2214-
early_error(error_format, "-g and -C debuginfo both provided");
2226+
let max_g = matches.opt_positions("g").into_iter().max();
2227+
let max_c = matches.opt_strs_pos("C").into_iter().flat_map(|(i, s)| {
2228+
if let Some("debuginfo") = s.splitn(2, '=').next() {
2229+
Some(i)
2230+
} else {
2231+
None
22152232
}
2233+
}).max();
2234+
let debuginfo = if max_g > max_c {
22162235
DebugInfo::Full
22172236
} else {
22182237
match cg.debuginfo {

0 commit comments

Comments
 (0)