Skip to content

Rollup of 5 pull requests #60567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
May 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Cargo.lock
Original file line number Diff line number Diff line change
@@ -169,7 +169,7 @@ dependencies = [
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
"cmake 0.1.38 (registry+https://github.com/rust-lang/crates.io-index)",
"filetime 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -463,7 +463,7 @@ dependencies = [
"diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)",
"filetime 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
"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"
dependencies = [
"diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
"filetime 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"miow 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -974,7 +974,7 @@ dependencies = [

[[package]]
name = "getopts"
version = "0.2.18"
version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1989,7 +1989,7 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
@@ -2008,7 +2008,7 @@ version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unicase 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -3095,7 +3095,7 @@ dependencies = [
"dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)",
"ignore 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3522,7 +3522,7 @@ dependencies = [
name = "test"
version = "0.0.0"
dependencies = [
"getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)",
"proc_macro 0.0.0",
"term 0.0.0",
]
@@ -3532,7 +3532,7 @@ name = "tester"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
"getopts 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
"term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -4132,7 +4132,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)" = "1a70b146671de62ec8c8ed572219ca5d594d9b06c0b364d5e67b722fc559b48c"
"checksum fwdansi 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "34dd4c507af68d37ffef962063dfa1944ce0dd4d5b82043dbab1dabe088610c3"
"checksum generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d"
"checksum getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "0a7292d30132fb5424b354f5dc02512a86e4c516fe544bb7a25e7f266951b797"
"checksum getopts 0.2.19 (registry+https://github.com/rust-lang/crates.io-index)" = "72327b15c228bfe31f1390f93dd5e9279587f0463836393c9df719ce62a3e450"
"checksum git2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7339329bfa14a00223244311560d11f8f489b453fb90092af97f267a6090ab0"
"checksum git2-curl 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d58551e903ed7e2d6fe3a2f3c7efa3a784ec29b19d0fbb035aaf0497c183fbdd"
"checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
2 changes: 1 addition & 1 deletion src/bootstrap/Cargo.toml
Original file line number Diff line number Diff line change
@@ -39,7 +39,7 @@ build_helper = { path = "../build_helper" }
cmake = "0.1.38"
filetime = "0.2"
num_cpus = "1.0"
getopts = "0.2.18"
getopts = "0.2.19"
cc = "1.0.35"
libc = "0.2"
serde = "1.0.8"
2 changes: 1 addition & 1 deletion src/librustc/hir/def.rs
Original file line number Diff line number Diff line change
@@ -140,7 +140,7 @@ pub enum Res<Id = hir::HirId> {
SelfCtor(DefId /* impl */), // `DefId` refers to the impl
Local(Id),
Upvar(Id, // `HirId` of closed over local
usize, // index in the `freevars` list of the closure
usize, // index in the `upvars` list of the closure
ast::NodeId), // expr node that creates the closure

// Macro namespace
16 changes: 8 additions & 8 deletions src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
@@ -2476,19 +2476,19 @@ impl ForeignItemKind {
}
}

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

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

impl<Id: fmt::Debug + Copy> Freevar<Id> {
pub fn map_id<R>(self, map: impl FnMut(Id) -> R) -> Freevar<R> {
Freevar {
impl<Id: fmt::Debug + Copy> Upvar<Id> {
pub fn map_id<R>(self, map: impl FnMut(Id) -> R) -> Upvar<R> {
Upvar {
res: self.res.map_id(map),
span: self.span,
}
@@ -2497,12 +2497,12 @@ impl<Id: fmt::Debug + Copy> Freevar<Id> {
pub fn var_id(&self) -> Id {
match self.res {
Res::Local(id) | Res::Upvar(id, ..) => id,
_ => bug!("Freevar::var_id: bad res ({:?})", self.res)
_ => bug!("Upvar::var_id: bad res ({:?})", self.res)
}
}
}

pub type FreevarMap = NodeMap<Vec<Freevar<ast::NodeId>>>;
pub type UpvarMap = NodeMap<Vec<Upvar<ast::NodeId>>>;

pub type CaptureModeMap = NodeMap<CaptureClause>;

4 changes: 2 additions & 2 deletions src/librustc/infer/error_reporting/note.rs
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
err.span_note(span,
"...so that pointer is not dereferenced outside its lifetime");
}
infer::FreeVariable(span, id) => {
infer::ClosureCapture(span, id) => {
err.span_note(span,
&format!("...so that captured variable `{}` does not outlive the \
enclosing closure",
@@ -214,7 +214,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
"the reference is only valid for ", sup, "");
err
}
infer::FreeVariable(span, id) => {
infer::ClosureCapture(span, id) => {
let mut err = struct_span_err!(self.tcx.sess,
span,
E0474,
6 changes: 3 additions & 3 deletions src/librustc/infer/mod.rs
Original file line number Diff line number Diff line change
@@ -264,8 +264,8 @@ pub enum SubregionOrigin<'tcx> {
/// Dereference of reference must be within its lifetime
DerefPointer(Span),

/// Closure bound must not outlive captured free variables
FreeVariable(Span, ast::NodeId),
/// Closure bound must not outlive captured variables
ClosureCapture(Span, ast::NodeId),

/// Index into slice must be within its lifetime
IndexSlice(Span),
@@ -1660,7 +1660,7 @@ impl<'tcx> SubregionOrigin<'tcx> {
InfStackClosure(a) => a,
InvokeClosure(a) => a,
DerefPointer(a) => a,
FreeVariable(a, _) => a,
ClosureCapture(a, _) => a,
IndexSlice(a) => a,
RelateObjectBound(a) => a,
RelateParamBound(a, _) => a,
16 changes: 8 additions & 8 deletions src/librustc/middle/expr_use_visitor.rs
Original file line number Diff line number Diff line change
@@ -931,42 +931,42 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
debug!("walk_captures({:?})", closure_expr);

let closure_def_id = self.tcx().hir().local_def_id_from_hir_id(closure_expr.hir_id);
self.tcx().with_freevars(closure_expr.hir_id, |freevars| {
for freevar in freevars {
let var_hir_id = freevar.var_id();
if let Some(upvars) = self.tcx().upvars(closure_def_id) {
for upvar in upvars.iter() {
let var_hir_id = upvar.var_id();
let upvar_id = ty::UpvarId {
var_path: ty::UpvarPath { hir_id: var_hir_id },
closure_expr_id: closure_def_id.to_local(),
};
let upvar_capture = self.mc.tables.upvar_capture(upvar_id);
let cmt_var = return_if_err!(self.cat_captured_var(closure_expr.hir_id,
fn_decl_span,
freevar));
upvar));
match upvar_capture {
ty::UpvarCapture::ByValue => {
let mode = copy_or_move(&self.mc,
self.param_env,
&cmt_var,
CaptureMove);
self.delegate.consume(closure_expr.hir_id, freevar.span, &cmt_var, mode);
self.delegate.consume(closure_expr.hir_id, upvar.span, &cmt_var, mode);
}
ty::UpvarCapture::ByRef(upvar_borrow) => {
self.delegate.borrow(closure_expr.hir_id,
fn_decl_span,
&cmt_var,
upvar_borrow.region,
upvar_borrow.kind,
ClosureCapture(freevar.span));
ClosureCapture(upvar.span));
}
}
}
});
}
}

fn cat_captured_var(&mut self,
closure_hir_id: hir::HirId,
closure_span: Span,
upvar: &hir::Freevar)
upvar: &hir::Upvar)
-> mc::McResult<mc::cmt_<'tcx>> {
// Create the cmt for the variable being borrowed, from the
// caller's perspective
19 changes: 10 additions & 9 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
@@ -144,7 +144,7 @@ impl LiveNode {

#[derive(Copy, Clone, PartialEq, Debug)]
enum LiveNodeKind {
FreeVarNode(Span),
UpvarNode(Span),
ExprNode(Span),
VarDefNode(Span),
ExitNode
@@ -153,8 +153,8 @@ enum LiveNodeKind {
fn live_node_kind_to_string(lnk: LiveNodeKind, tcx: TyCtxt<'_, '_, '_>) -> String {
let cm = tcx.sess.source_map();
match lnk {
FreeVarNode(s) => {
format!("Free var node [{}]", cm.span_to_string(s))
UpvarNode(s) => {
format!("Upvar node [{}]", cm.span_to_string(s))
}
ExprNode(s) => {
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) {
// in better error messages than just pointing at the closure
// construction site.
let mut call_caps = Vec::new();
ir.tcx.with_freevars(expr.hir_id, |freevars| {
call_caps.extend(freevars.iter().filter_map(|fv| {
if let Res::Local(rv) = fv.res {
let fv_ln = ir.add_live_node(FreeVarNode(fv.span));
Some(CaptureInfo { ln: fv_ln, var_hid: rv })
let closure_def_id = ir.tcx.hir().local_def_id_from_hir_id(expr.hir_id);
if let Some(upvars) = ir.tcx.upvars(closure_def_id) {
call_caps.extend(upvars.iter().filter_map(|upvar| {
if let Res::Local(rv) = upvar.res {
let upvar_ln = ir.add_live_node(UpvarNode(upvar.span));
Some(CaptureInfo { ln: upvar_ln, var_hid: rv })
} else {
None
}
}));
});
}
ir.set_captures(expr.hir_id, call_caps);

intravisit::walk_expr(ir, expr);
16 changes: 8 additions & 8 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
@@ -2572,12 +2572,12 @@ impl<'tcx> Debug for Rvalue<'tcx> {
};
let mut struct_fmt = fmt.debug_struct(&name);

tcx.with_freevars(hir_id, |freevars| {
for (freevar, place) in freevars.iter().zip(places) {
let var_name = tcx.hir().name_by_hir_id(freevar.var_id());
if let Some(upvars) = tcx.upvars(def_id) {
for (upvar, place) in upvars.iter().zip(places) {
let var_name = tcx.hir().name_by_hir_id(upvar.var_id());
struct_fmt.field(&var_name.as_str(), place);
}
});
}

struct_fmt.finish()
} else {
@@ -2591,12 +2591,12 @@ impl<'tcx> Debug for Rvalue<'tcx> {
tcx.hir().span_by_hir_id(hir_id));
let mut struct_fmt = fmt.debug_struct(&name);

tcx.with_freevars(hir_id, |freevars| {
for (freevar, place) in freevars.iter().zip(places) {
let var_name = tcx.hir().name_by_hir_id(freevar.var_id());
if let Some(upvars) = tcx.upvars(def_id) {
for (upvar, place) in upvars.iter().zip(places) {
let var_name = tcx.hir().name_by_hir_id(upvar.var_id());
struct_fmt.field(&var_name.as_str(), place);
}
});
}

struct_fmt.finish()
} else {
2 changes: 1 addition & 1 deletion src/librustc/query/mod.rs
Original file line number Diff line number Diff line change
@@ -824,7 +824,7 @@ rustc_queries! {
desc { "generating a postorder list of CrateNums" }
}

query freevars(_: DefId) -> Option<Lrc<Vec<hir::Freevar>>> {
query upvars(_: DefId) -> Option<Lrc<Vec<hir::Upvar>>> {
eval_always
}
query maybe_unused_trait_import(_: DefId) -> bool {
31 changes: 25 additions & 6 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
@@ -2181,10 +2181,21 @@ pub fn build_session_options_and_crate_config(
TargetTriple::from_triple(host_triple())
};
let opt_level = {
if matches.opt_present("O") {
if cg.opt_level.is_some() {
early_error(error_format, "-O and -C opt-level both provided");
// The `-O` and `-C opt-level` flags specify the same setting, so we want to be able
// to use them interchangeably. However, because they're technically different flags,
// we need to work out manually which should take precedence if both are supplied (i.e.
// the rightmost flag). We do this by finding the (rightmost) position of both flags and
// comparing them. Note that if a flag is not found, its position will be `None`, which
// always compared less than `Some(_)`.
let max_o = matches.opt_positions("O").into_iter().max();
let max_c = matches.opt_strs_pos("C").into_iter().flat_map(|(i, s)| {
if let Some("opt-level") = s.splitn(2, '=').next() {
Some(i)
} else {
None
}
}).max();
if max_o > max_c {
OptLevel::Default
} else {
match cg.opt_level.as_ref().map(String::as_ref) {
@@ -2208,11 +2219,19 @@ pub fn build_session_options_and_crate_config(
}
}
};
// The `-g` and `-C debuginfo` flags specify the same setting, so we want to be able
// to use them interchangeably. See the note above (regarding `-O` and `-C opt-level`)
// for more details.
let debug_assertions = cg.debug_assertions.unwrap_or(opt_level == OptLevel::No);
let debuginfo = if matches.opt_present("g") {
if cg.debuginfo.is_some() {
early_error(error_format, "-g and -C debuginfo both provided");
let max_g = matches.opt_positions("g").into_iter().max();
let max_c = matches.opt_strs_pos("C").into_iter().flat_map(|(i, s)| {
if let Some("debuginfo") = s.splitn(2, '=').next() {
Some(i)
} else {
None
}
}).max();
let debuginfo = if max_g > max_c {
DebugInfo::Full
} else {
match cg.debuginfo {
Loading