Skip to content

Rollup of 7 pull requests #69606

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
Mar 1, 2020
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion src/bootstrap/dist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,14 @@ fn make_win_dist(
}
}

let target_tools = ["gcc.exe", "ld.exe", "dlltool.exe", "libwinpthread-1.dll"];
let compiler = if target_triple == "i686-pc-windows-gnu" {
"i686-w64-mingw32-gcc.exe"
} else if target_triple == "x86_64-pc-windows-gnu" {
"x86_64-w64-mingw32-gcc.exe"
} else {
"gcc.exe"
};
let target_tools = [compiler, "ld.exe", "dlltool.exe", "libwinpthread-1.dll"];
let mut rustc_dlls = vec!["libwinpthread-1.dll"];
if target_triple.starts_with("i686-") {
rustc_dlls.push("libgcc_s_dw2-1.dll");
Expand Down
8 changes: 2 additions & 6 deletions src/bootstrap/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,8 @@ impl Step for Llvm {
cfg.define("LLVM_VERSION_SUFFIX", suffix);
}
} else {
let mut default_suffix =
format!("-rust-{}-{}", channel::CFG_RELEASE_NUM, builder.config.channel,);
if let Some(sha) = llvm_info.sha_short() {
default_suffix.push_str("-");
default_suffix.push_str(sha);
}
let default_suffix =
format!("-rust-{}-{}", channel::CFG_RELEASE_NUM, builder.config.channel);
cfg.define("LLVM_VERSION_SUFFIX", default_suffix);
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ich/hcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::cmp::Ord;

fn compute_ignored_attr_names() -> FxHashSet<Symbol> {
debug_assert!(!ich::IGNORED_ATTRIBUTES.is_empty());
ich::IGNORED_ATTRIBUTES.iter().map(|&s| s).collect()
ich::IGNORED_ATTRIBUTES.iter().copied().collect()
}

/// This is the context state available during incr. comp. hashing. It contains
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ impl<'tcx> ScopeTree {
/// Used to sanity check visit_expr call count when
/// calculating generator interiors.
pub fn body_expr_count(&self, body_id: hir::BodyId) -> Option<usize> {
self.body_expr_count.get(&body_id).map(|r| *r)
self.body_expr_count.get(&body_id).copied()
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_ast_lowering/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let from_err_expr =
self.wrap_in_try_constructor(sym::from_error, unstable_span, from_expr, try_span);
let thin_attrs = ThinVec::from(attrs);
let catch_scope = self.catch_scopes.last().map(|x| *x);
let catch_scope = self.catch_scopes.last().copied();
let ret_expr = if let Some(catch_node) = catch_scope {
let target_id = Ok(self.lower_node_id(catch_node));
self.arena.alloc(self.expr(
Expand Down
12 changes: 6 additions & 6 deletions src/librustc_builtin_macros/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ fn parse_inline_asm<'a>(

let constraint = parse_asm_str(&mut p)?;

let span = p.prev_span;
let span = p.prev_token.span;

p.expect(&token::OpenDelim(token::Paren))?;
let expr = p.parse_expr()?;
Expand Down Expand Up @@ -202,15 +202,15 @@ fn parse_inline_asm<'a>(
if constraint.as_str().starts_with('=') {
struct_span_err!(
cx.parse_sess.span_diagnostic,
p.prev_span,
p.prev_token.span,
E0662,
"input operand constraint contains '='"
)
.emit();
} else if constraint.as_str().starts_with('+') {
struct_span_err!(
cx.parse_sess.span_diagnostic,
p.prev_span,
p.prev_token.span,
E0663,
"input operand constraint contains '+'"
)
Expand All @@ -233,11 +233,11 @@ fn parse_inline_asm<'a>(
let s = parse_asm_str(&mut p)?;

if OPTIONS.iter().any(|&opt| s == opt) {
cx.span_warn(p.prev_span, "expected a clobber, found an option");
cx.span_warn(p.prev_token.span, "expected a clobber, found an option");
} else if s.as_str().starts_with('{') || s.as_str().ends_with('}') {
struct_span_err!(
cx.parse_sess.span_diagnostic,
p.prev_span,
p.prev_token.span,
E0664,
"clobber should not be surrounded by braces"
)
Expand All @@ -259,7 +259,7 @@ fn parse_inline_asm<'a>(
} else if option == sym::intel {
dialect = AsmDialect::Intel;
} else {
cx.span_warn(p.prev_span, "unrecognized option");
cx.span_warn(p.prev_token.span, "unrecognized option");
}

if p.token == token::Comma {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_builtin_macros/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ fn parse_assert<'a>(
let custom_message =
if let token::Literal(token::Lit { kind: token::Str, .. }) = parser.token.kind {
let mut err = cx.struct_span_warn(parser.token.span, "unexpected string literal");
let comma_span = parser.prev_span.shrink_to_hi();
let comma_span = parser.prev_token.span.shrink_to_hi();
err.span_suggestion_short(
comma_span,
"try adding a comma",
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_builtin_macros/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ impl<'a, 'b> Context<'a, 'b> {
refs.sort();
refs.dedup();
let (arg_list, mut sp) = if refs.len() == 1 {
let spans: Vec<_> = spans.into_iter().filter_map(|sp| sp.map(|sp| *sp)).collect();
let spans: Vec<_> = spans.into_iter().filter_map(|sp| sp.copied()).collect();
(
format!("argument {}", refs[0]),
if spans.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_expand/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ fn check_matcher_core(
msg,
ts[..ts.len() - 1]
.iter()
.map(|s| *s)
.copied()
.collect::<Vec<_>>()
.join(", "),
ts[ts.len() - 1],
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_metadata/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ impl<'tcx> EncodeContext<'tcx> {
},
proc_macro_data,
proc_macro_stability: if is_proc_macro {
tcx.lookup_stability(DefId::local(CRATE_DEF_INDEX)).map(|stab| *stab)
tcx.lookup_stability(DefId::local(CRATE_DEF_INDEX)).copied()
} else {
None
},
Expand Down
126 changes: 72 additions & 54 deletions src/librustc_mir/dataflow/generic/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,24 @@ where
}

SwitchInt { ref targets, ref values, ref discr, .. } => {
self.propagate_bits_into_switch_int_successors(
in_out,
(bb, bb_data),
dirty_list,
discr,
&*values,
&*targets,
);
// If this is a switch on an enum discriminant, a custom effect may be applied
// along each outgoing edge.
if let Some(place) = discr.place() {
let enum_def = switch_on_enum_discriminant(self.tcx, self.body, bb_data, place);
if let Some(enum_def) = enum_def {
self.propagate_bits_into_enum_discriminant_switch_successors(
in_out, bb, enum_def, place, dirty_list, &*values, &*targets,
);

return;
}
}

// Otherwise, it's just a normal `SwitchInt`, and every successor sees the same
// exit state.
for target in targets.iter().copied() {
self.propagate_bits_into_entry_set_for(&in_out, target, dirty_list);
}
}

Call { cleanup, ref destination, ref func, ref args, .. } => {
Expand Down Expand Up @@ -293,64 +303,72 @@ where
}
}

fn propagate_bits_into_switch_int_successors(
fn propagate_bits_into_enum_discriminant_switch_successors(
&mut self,
in_out: &mut BitSet<A::Idx>,
(bb, bb_data): (BasicBlock, &mir::BasicBlockData<'tcx>),
bb: BasicBlock,
enum_def: &'tcx ty::AdtDef,
enum_place: &mir::Place<'tcx>,
dirty_list: &mut WorkQueue<BasicBlock>,
switch_on: &mir::Operand<'tcx>,
values: &[u128],
targets: &[BasicBlock],
) {
match bb_data.statements.last().map(|stmt| &stmt.kind) {
// Look at the last statement to see if it is an assignment of an enum discriminant to
// the local that determines the target of a `SwitchInt` like so:
// _42 = discriminant(..)
// SwitchInt(_42, ..)
Some(mir::StatementKind::Assign(box (lhs, mir::Rvalue::Discriminant(enum_))))
if Some(lhs) == switch_on.place() =>
{
let adt = match enum_.ty(self.body, self.tcx).ty.kind {
ty::Adt(def, _) => def,
_ => bug!("Switch on discriminant of non-ADT"),
};

// MIR building adds discriminants to the `values` array in the same order as they
// are yielded by `AdtDef::discriminants`. We rely on this to match each
// discriminant in `values` to its corresponding variant in linear time.
let mut tmp = BitSet::new_empty(in_out.domain_size());
let mut discriminants = adt.discriminants(self.tcx);
for (value, target) in values.iter().zip(targets.iter().copied()) {
let (variant_idx, _) =
discriminants.find(|&(_, discr)| discr.val == *value).expect(
"Order of `AdtDef::discriminants` differed \
from that of `SwitchInt::values`",
);
// MIR building adds discriminants to the `values` array in the same order as they
// are yielded by `AdtDef::discriminants`. We rely on this to match each
// discriminant in `values` to its corresponding variant in linear time.
let mut tmp = BitSet::new_empty(in_out.domain_size());
let mut discriminants = enum_def.discriminants(self.tcx);
for (value, target) in values.iter().zip(targets.iter().copied()) {
let (variant_idx, _) = discriminants.find(|&(_, discr)| discr.val == *value).expect(
"Order of `AdtDef::discriminants` differed from that of `SwitchInt::values`",
);

tmp.overwrite(in_out);
self.analysis.apply_discriminant_switch_effect(
&mut tmp,
bb,
enum_,
adt,
variant_idx,
);
self.propagate_bits_into_entry_set_for(&tmp, target, dirty_list);
}
tmp.overwrite(in_out);
self.analysis.apply_discriminant_switch_effect(
&mut tmp,
bb,
enum_place,
enum_def,
variant_idx,
);
self.propagate_bits_into_entry_set_for(&tmp, target, dirty_list);
}

std::mem::drop(tmp);
std::mem::drop(tmp);

// Propagate dataflow state along the "otherwise" edge.
let otherwise = targets.last().copied().unwrap();
self.propagate_bits_into_entry_set_for(&in_out, otherwise, dirty_list);
}
// Propagate dataflow state along the "otherwise" edge.
let otherwise = targets.last().copied().unwrap();
self.propagate_bits_into_entry_set_for(&in_out, otherwise, dirty_list);
}
}

_ => {
for target in targets.iter().copied() {
self.propagate_bits_into_entry_set_for(&in_out, target, dirty_list);
}
/// Look at the last statement of a block that ends with to see if it is an assignment of an enum
/// discriminant to the local that determines the target of a `SwitchInt` like so:
/// _42 = discriminant(..)
/// SwitchInt(_42, ..)
fn switch_on_enum_discriminant(
tcx: TyCtxt<'tcx>,
body: &mir::Body<'tcx>,
block: &mir::BasicBlockData<'tcx>,
switch_on: &mir::Place<'tcx>,
) -> Option<&'tcx ty::AdtDef> {
match block.statements.last().map(|stmt| &stmt.kind) {
Some(mir::StatementKind::Assign(box (lhs, mir::Rvalue::Discriminant(discriminated))))
if lhs == switch_on =>
{
match &discriminated.ty(body, tcx).ty.kind {
ty::Adt(def, _) => Some(def),

// `Rvalue::Discriminant` is also used to get the active yield point for a
// generator, but we do not need edge-specific effects in that case. This may
// change in the future.
ty::Generator(..) => None,

t => bug!("`discriminant` called on unexpected type {:?}", t),
}
}

_ => None,
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/interpret/terminator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
let mut caller_iter = caller_args
.iter()
.filter(|op| !rust_abi || !op.layout.is_zst())
.map(|op| *op);
.copied();

// Now we have to spread them out across the callee's locals,
// taking into account the `spread_arg`. If we could write
Expand Down
23 changes: 11 additions & 12 deletions src/librustc_mir_build/hair/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,12 @@ fn make_mirror_unadjusted<'a, 'tcx>(
if let Some((adt_def, index)) = adt_data {
let substs = cx.tables().node_substs(fun.hir_id);
let user_provided_types = cx.tables().user_provided_types();
let user_ty =
user_provided_types.get(fun.hir_id).map(|u_ty| *u_ty).map(|mut u_ty| {
if let UserType::TypeOf(ref mut did, _) = &mut u_ty.value {
*did = adt_def.did;
}
u_ty
});
let user_ty = user_provided_types.get(fun.hir_id).copied().map(|mut u_ty| {
if let UserType::TypeOf(ref mut did, _) = &mut u_ty.value {
*did = adt_def.did;
}
u_ty
});
debug!("make_mirror_unadjusted: (call) user_ty={:?}", user_ty);

let field_refs = args
Expand Down Expand Up @@ -329,7 +328,7 @@ fn make_mirror_unadjusted<'a, 'tcx>(
ty::Adt(adt, substs) => match adt.adt_kind() {
AdtKind::Struct | AdtKind::Union => {
let user_provided_types = cx.tables().user_provided_types();
let user_ty = user_provided_types.get(expr.hir_id).map(|u_ty| *u_ty);
let user_ty = user_provided_types.get(expr.hir_id).copied();
debug!("make_mirror_unadjusted: (struct/union) user_ty={:?}", user_ty);
ExprKind::Adt {
adt_def: adt,
Expand All @@ -351,7 +350,7 @@ fn make_mirror_unadjusted<'a, 'tcx>(

let index = adt.variant_index_with_id(variant_id);
let user_provided_types = cx.tables().user_provided_types();
let user_ty = user_provided_types.get(expr.hir_id).map(|u_ty| *u_ty);
let user_ty = user_provided_types.get(expr.hir_id).copied();
debug!("make_mirror_unadjusted: (variant) user_ty={:?}", user_ty);
ExprKind::Adt {
adt_def: adt,
Expand Down Expand Up @@ -570,7 +569,7 @@ fn make_mirror_unadjusted<'a, 'tcx>(
}
hir::ExprKind::Type(ref source, ref ty) => {
let user_provided_types = cx.tables.user_provided_types();
let user_ty = user_provided_types.get(ty.hir_id).map(|u_ty| *u_ty);
let user_ty = user_provided_types.get(ty.hir_id).copied();
debug!("make_mirror_unadjusted: (type) user_ty={:?}", user_ty);
if source.is_syntactic_place_expr() {
ExprKind::PlaceTypeAscription { source: source.to_ref(), user_ty }
Expand Down Expand Up @@ -605,7 +604,7 @@ fn user_substs_applied_to_res<'tcx>(
| Res::Def(DefKind::Ctor(_, CtorKind::Fn), _)
| Res::Def(DefKind::Const, _)
| Res::Def(DefKind::AssocConst, _) => {
cx.tables().user_provided_types().get(hir_id).map(|u_ty| *u_ty)
cx.tables().user_provided_types().get(hir_id).copied()
}

// A unit struct/variant which is used as a value (e.g.,
Expand Down Expand Up @@ -744,7 +743,7 @@ fn convert_path_expr<'a, 'tcx>(

Res::Def(DefKind::Ctor(_, CtorKind::Const), def_id) => {
let user_provided_types = cx.tables.user_provided_types();
let user_provided_type = user_provided_types.get(expr.hir_id).map(|u_ty| *u_ty);
let user_provided_type = user_provided_types.get(expr.hir_id).copied();
debug!("convert_path_expr: user_provided_type={:?}", user_provided_type);
let ty = cx.tables().node_type(expr.hir_id);
match ty.kind {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir_build/hair/pattern/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ impl<'p, 'tcx> PatStack<'p, 'tcx> {
}

fn iter(&self) -> impl Iterator<Item = &Pat<'tcx>> {
self.0.iter().map(|p| *p)
self.0.iter().copied()
}

// If the first pattern is an or-pattern, expand this pattern. Otherwise, return `None`.
Expand Down
Loading