Skip to content

Commit 6b2983a

Browse files
committed
Auto merge of #69606 - JohnTitor:rollup-i3nrrcf, r=JohnTitor
Rollup of 7 pull requests Successful merges: - #69397 (bootstrap: Remove commit hash from LLVM version suffix to avoid rebuilds) - #69549 (Improve MinGW detection when cross compiling ) - #69562 (Don't `bug` when taking discriminant of generator during dataflow) - #69579 (parser: Remove `Parser::prev_span`) - #69580 (use .copied() instead of .map(|x| *x) on iterators) - #69583 (Do not ICE on invalid type node after parse recovery) - #69605 (Use `opt_def_id()` over `def_id()`) Failed merges: r? @ghost
2 parents ee50590 + 47d87d7 commit 6b2983a

File tree

40 files changed

+368
-309
lines changed

40 files changed

+368
-309
lines changed

src/bootstrap/dist.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,14 @@ fn make_win_dist(
234234
}
235235
}
236236

237-
let target_tools = ["gcc.exe", "ld.exe", "dlltool.exe", "libwinpthread-1.dll"];
237+
let compiler = if target_triple == "i686-pc-windows-gnu" {
238+
"i686-w64-mingw32-gcc.exe"
239+
} else if target_triple == "x86_64-pc-windows-gnu" {
240+
"x86_64-w64-mingw32-gcc.exe"
241+
} else {
242+
"gcc.exe"
243+
};
244+
let target_tools = [compiler, "ld.exe", "dlltool.exe", "libwinpthread-1.dll"];
238245
let mut rustc_dlls = vec!["libwinpthread-1.dll"];
239246
if target_triple.starts_with("i686-") {
240247
rustc_dlls.push("libgcc_s_dw2-1.dll");

src/bootstrap/native.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,8 @@ impl Step for Llvm {
241241
cfg.define("LLVM_VERSION_SUFFIX", suffix);
242242
}
243243
} else {
244-
let mut default_suffix =
245-
format!("-rust-{}-{}", channel::CFG_RELEASE_NUM, builder.config.channel,);
246-
if let Some(sha) = llvm_info.sha_short() {
247-
default_suffix.push_str("-");
248-
default_suffix.push_str(sha);
249-
}
244+
let default_suffix =
245+
format!("-rust-{}-{}", channel::CFG_RELEASE_NUM, builder.config.channel);
250246
cfg.define("LLVM_VERSION_SUFFIX", default_suffix);
251247
}
252248

src/librustc/ich/hcx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::cmp::Ord;
2020

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

2626
/// This is the context state available during incr. comp. hashing. It contains

src/librustc/middle/region.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ impl<'tcx> ScopeTree {
635635
/// Used to sanity check visit_expr call count when
636636
/// calculating generator interiors.
637637
pub fn body_expr_count(&self, body_id: hir::BodyId) -> Option<usize> {
638-
self.body_expr_count.get(&body_id).map(|r| *r)
638+
self.body_expr_count.get(&body_id).copied()
639639
}
640640
}
641641

src/librustc_ast_lowering/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1179,7 +1179,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
11791179
let from_err_expr =
11801180
self.wrap_in_try_constructor(sym::from_error, unstable_span, from_expr, try_span);
11811181
let thin_attrs = ThinVec::from(attrs);
1182-
let catch_scope = self.catch_scopes.last().map(|x| *x);
1182+
let catch_scope = self.catch_scopes.last().copied();
11831183
let ret_expr = if let Some(catch_node) = catch_scope {
11841184
let target_id = Ok(self.lower_node_id(catch_node));
11851185
self.arena.alloc(self.expr(

src/librustc_builtin_macros/asm.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fn parse_inline_asm<'a>(
151151

152152
let constraint = parse_asm_str(&mut p)?;
153153

154-
let span = p.prev_span;
154+
let span = p.prev_token.span;
155155

156156
p.expect(&token::OpenDelim(token::Paren))?;
157157
let expr = p.parse_expr()?;
@@ -202,15 +202,15 @@ fn parse_inline_asm<'a>(
202202
if constraint.as_str().starts_with('=') {
203203
struct_span_err!(
204204
cx.parse_sess.span_diagnostic,
205-
p.prev_span,
205+
p.prev_token.span,
206206
E0662,
207207
"input operand constraint contains '='"
208208
)
209209
.emit();
210210
} else if constraint.as_str().starts_with('+') {
211211
struct_span_err!(
212212
cx.parse_sess.span_diagnostic,
213-
p.prev_span,
213+
p.prev_token.span,
214214
E0663,
215215
"input operand constraint contains '+'"
216216
)
@@ -233,11 +233,11 @@ fn parse_inline_asm<'a>(
233233
let s = parse_asm_str(&mut p)?;
234234

235235
if OPTIONS.iter().any(|&opt| s == opt) {
236-
cx.span_warn(p.prev_span, "expected a clobber, found an option");
236+
cx.span_warn(p.prev_token.span, "expected a clobber, found an option");
237237
} else if s.as_str().starts_with('{') || s.as_str().ends_with('}') {
238238
struct_span_err!(
239239
cx.parse_sess.span_diagnostic,
240-
p.prev_span,
240+
p.prev_token.span,
241241
E0664,
242242
"clobber should not be surrounded by braces"
243243
)
@@ -259,7 +259,7 @@ fn parse_inline_asm<'a>(
259259
} else if option == sym::intel {
260260
dialect = AsmDialect::Intel;
261261
} else {
262-
cx.span_warn(p.prev_span, "unrecognized option");
262+
cx.span_warn(p.prev_token.span, "unrecognized option");
263263
}
264264

265265
if p.token == token::Comma {

src/librustc_builtin_macros/assert.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fn parse_assert<'a>(
106106
let custom_message =
107107
if let token::Literal(token::Lit { kind: token::Str, .. }) = parser.token.kind {
108108
let mut err = cx.struct_span_warn(parser.token.span, "unexpected string literal");
109-
let comma_span = parser.prev_span.shrink_to_hi();
109+
let comma_span = parser.prev_token.span.shrink_to_hi();
110110
err.span_suggestion_short(
111111
comma_span,
112112
"try adding a comma",

src/librustc_builtin_macros/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ impl<'a, 'b> Context<'a, 'b> {
359359
refs.sort();
360360
refs.dedup();
361361
let (arg_list, mut sp) = if refs.len() == 1 {
362-
let spans: Vec<_> = spans.into_iter().filter_map(|sp| sp.map(|sp| *sp)).collect();
362+
let spans: Vec<_> = spans.into_iter().filter_map(|sp| sp.copied()).collect();
363363
(
364364
format!("argument {}", refs[0]),
365365
if spans.is_empty() {

src/librustc_expand/mbe/macro_rules.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ fn check_matcher_core(
970970
msg,
971971
ts[..ts.len() - 1]
972972
.iter()
973-
.map(|s| *s)
973+
.copied()
974974
.collect::<Vec<_>>()
975975
.join(", "),
976976
ts[ts.len() - 1],

src/librustc_metadata/rmeta/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ impl<'tcx> EncodeContext<'tcx> {
503503
},
504504
proc_macro_data,
505505
proc_macro_stability: if is_proc_macro {
506-
tcx.lookup_stability(DefId::local(CRATE_DEF_INDEX)).map(|stab| *stab)
506+
tcx.lookup_stability(DefId::local(CRATE_DEF_INDEX)).copied()
507507
} else {
508508
None
509509
},

src/librustc_mir/dataflow/generic/engine.rs

+72-54
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,24 @@ where
239239
}
240240

241241
SwitchInt { ref targets, ref values, ref discr, .. } => {
242-
self.propagate_bits_into_switch_int_successors(
243-
in_out,
244-
(bb, bb_data),
245-
dirty_list,
246-
discr,
247-
&*values,
248-
&*targets,
249-
);
242+
// If this is a switch on an enum discriminant, a custom effect may be applied
243+
// along each outgoing edge.
244+
if let Some(place) = discr.place() {
245+
let enum_def = switch_on_enum_discriminant(self.tcx, self.body, bb_data, place);
246+
if let Some(enum_def) = enum_def {
247+
self.propagate_bits_into_enum_discriminant_switch_successors(
248+
in_out, bb, enum_def, place, dirty_list, &*values, &*targets,
249+
);
250+
251+
return;
252+
}
253+
}
254+
255+
// Otherwise, it's just a normal `SwitchInt`, and every successor sees the same
256+
// exit state.
257+
for target in targets.iter().copied() {
258+
self.propagate_bits_into_entry_set_for(&in_out, target, dirty_list);
259+
}
250260
}
251261

252262
Call { cleanup, ref destination, ref func, ref args, .. } => {
@@ -293,64 +303,72 @@ where
293303
}
294304
}
295305

296-
fn propagate_bits_into_switch_int_successors(
306+
fn propagate_bits_into_enum_discriminant_switch_successors(
297307
&mut self,
298308
in_out: &mut BitSet<A::Idx>,
299-
(bb, bb_data): (BasicBlock, &mir::BasicBlockData<'tcx>),
309+
bb: BasicBlock,
310+
enum_def: &'tcx ty::AdtDef,
311+
enum_place: &mir::Place<'tcx>,
300312
dirty_list: &mut WorkQueue<BasicBlock>,
301-
switch_on: &mir::Operand<'tcx>,
302313
values: &[u128],
303314
targets: &[BasicBlock],
304315
) {
305-
match bb_data.statements.last().map(|stmt| &stmt.kind) {
306-
// Look at the last statement to see if it is an assignment of an enum discriminant to
307-
// the local that determines the target of a `SwitchInt` like so:
308-
// _42 = discriminant(..)
309-
// SwitchInt(_42, ..)
310-
Some(mir::StatementKind::Assign(box (lhs, mir::Rvalue::Discriminant(enum_))))
311-
if Some(lhs) == switch_on.place() =>
312-
{
313-
let adt = match enum_.ty(self.body, self.tcx).ty.kind {
314-
ty::Adt(def, _) => def,
315-
_ => bug!("Switch on discriminant of non-ADT"),
316-
};
317-
318-
// MIR building adds discriminants to the `values` array in the same order as they
319-
// are yielded by `AdtDef::discriminants`. We rely on this to match each
320-
// discriminant in `values` to its corresponding variant in linear time.
321-
let mut tmp = BitSet::new_empty(in_out.domain_size());
322-
let mut discriminants = adt.discriminants(self.tcx);
323-
for (value, target) in values.iter().zip(targets.iter().copied()) {
324-
let (variant_idx, _) =
325-
discriminants.find(|&(_, discr)| discr.val == *value).expect(
326-
"Order of `AdtDef::discriminants` differed \
327-
from that of `SwitchInt::values`",
328-
);
316+
// MIR building adds discriminants to the `values` array in the same order as they
317+
// are yielded by `AdtDef::discriminants`. We rely on this to match each
318+
// discriminant in `values` to its corresponding variant in linear time.
319+
let mut tmp = BitSet::new_empty(in_out.domain_size());
320+
let mut discriminants = enum_def.discriminants(self.tcx);
321+
for (value, target) in values.iter().zip(targets.iter().copied()) {
322+
let (variant_idx, _) = discriminants.find(|&(_, discr)| discr.val == *value).expect(
323+
"Order of `AdtDef::discriminants` differed from that of `SwitchInt::values`",
324+
);
329325

330-
tmp.overwrite(in_out);
331-
self.analysis.apply_discriminant_switch_effect(
332-
&mut tmp,
333-
bb,
334-
enum_,
335-
adt,
336-
variant_idx,
337-
);
338-
self.propagate_bits_into_entry_set_for(&tmp, target, dirty_list);
339-
}
326+
tmp.overwrite(in_out);
327+
self.analysis.apply_discriminant_switch_effect(
328+
&mut tmp,
329+
bb,
330+
enum_place,
331+
enum_def,
332+
variant_idx,
333+
);
334+
self.propagate_bits_into_entry_set_for(&tmp, target, dirty_list);
335+
}
340336

341-
std::mem::drop(tmp);
337+
std::mem::drop(tmp);
342338

343-
// Propagate dataflow state along the "otherwise" edge.
344-
let otherwise = targets.last().copied().unwrap();
345-
self.propagate_bits_into_entry_set_for(&in_out, otherwise, dirty_list);
346-
}
339+
// Propagate dataflow state along the "otherwise" edge.
340+
let otherwise = targets.last().copied().unwrap();
341+
self.propagate_bits_into_entry_set_for(&in_out, otherwise, dirty_list);
342+
}
343+
}
347344

348-
_ => {
349-
for target in targets.iter().copied() {
350-
self.propagate_bits_into_entry_set_for(&in_out, target, dirty_list);
351-
}
345+
/// Look at the last statement of a block that ends with to see if it is an assignment of an enum
346+
/// discriminant to the local that determines the target of a `SwitchInt` like so:
347+
/// _42 = discriminant(..)
348+
/// SwitchInt(_42, ..)
349+
fn switch_on_enum_discriminant(
350+
tcx: TyCtxt<'tcx>,
351+
body: &mir::Body<'tcx>,
352+
block: &mir::BasicBlockData<'tcx>,
353+
switch_on: &mir::Place<'tcx>,
354+
) -> Option<&'tcx ty::AdtDef> {
355+
match block.statements.last().map(|stmt| &stmt.kind) {
356+
Some(mir::StatementKind::Assign(box (lhs, mir::Rvalue::Discriminant(discriminated))))
357+
if lhs == switch_on =>
358+
{
359+
match &discriminated.ty(body, tcx).ty.kind {
360+
ty::Adt(def, _) => Some(def),
361+
362+
// `Rvalue::Discriminant` is also used to get the active yield point for a
363+
// generator, but we do not need edge-specific effects in that case. This may
364+
// change in the future.
365+
ty::Generator(..) => None,
366+
367+
t => bug!("`discriminant` called on unexpected type {:?}", t),
352368
}
353369
}
370+
371+
_ => None,
354372
}
355373
}
356374

src/librustc_mir/interpret/terminator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
305305
let mut caller_iter = caller_args
306306
.iter()
307307
.filter(|op| !rust_abi || !op.layout.is_zst())
308-
.map(|op| *op);
308+
.copied();
309309

310310
// Now we have to spread them out across the callee's locals,
311311
// taking into account the `spread_arg`. If we could write

src/librustc_mir_build/hair/cx/expr.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,12 @@ fn make_mirror_unadjusted<'a, 'tcx>(
187187
if let Some((adt_def, index)) = adt_data {
188188
let substs = cx.tables().node_substs(fun.hir_id);
189189
let user_provided_types = cx.tables().user_provided_types();
190-
let user_ty =
191-
user_provided_types.get(fun.hir_id).map(|u_ty| *u_ty).map(|mut u_ty| {
192-
if let UserType::TypeOf(ref mut did, _) = &mut u_ty.value {
193-
*did = adt_def.did;
194-
}
195-
u_ty
196-
});
190+
let user_ty = user_provided_types.get(fun.hir_id).copied().map(|mut u_ty| {
191+
if let UserType::TypeOf(ref mut did, _) = &mut u_ty.value {
192+
*did = adt_def.did;
193+
}
194+
u_ty
195+
});
197196
debug!("make_mirror_unadjusted: (call) user_ty={:?}", user_ty);
198197

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

352351
let index = adt.variant_index_with_id(variant_id);
353352
let user_provided_types = cx.tables().user_provided_types();
354-
let user_ty = user_provided_types.get(expr.hir_id).map(|u_ty| *u_ty);
353+
let user_ty = user_provided_types.get(expr.hir_id).copied();
355354
debug!("make_mirror_unadjusted: (variant) user_ty={:?}", user_ty);
356355
ExprKind::Adt {
357356
adt_def: adt,
@@ -570,7 +569,7 @@ fn make_mirror_unadjusted<'a, 'tcx>(
570569
}
571570
hir::ExprKind::Type(ref source, ref ty) => {
572571
let user_provided_types = cx.tables.user_provided_types();
573-
let user_ty = user_provided_types.get(ty.hir_id).map(|u_ty| *u_ty);
572+
let user_ty = user_provided_types.get(ty.hir_id).copied();
574573
debug!("make_mirror_unadjusted: (type) user_ty={:?}", user_ty);
575574
if source.is_syntactic_place_expr() {
576575
ExprKind::PlaceTypeAscription { source: source.to_ref(), user_ty }
@@ -605,7 +604,7 @@ fn user_substs_applied_to_res<'tcx>(
605604
| Res::Def(DefKind::Ctor(_, CtorKind::Fn), _)
606605
| Res::Def(DefKind::Const, _)
607606
| Res::Def(DefKind::AssocConst, _) => {
608-
cx.tables().user_provided_types().get(hir_id).map(|u_ty| *u_ty)
607+
cx.tables().user_provided_types().get(hir_id).copied()
609608
}
610609

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

745744
Res::Def(DefKind::Ctor(_, CtorKind::Const), def_id) => {
746745
let user_provided_types = cx.tables.user_provided_types();
747-
let user_provided_type = user_provided_types.get(expr.hir_id).map(|u_ty| *u_ty);
746+
let user_provided_type = user_provided_types.get(expr.hir_id).copied();
748747
debug!("convert_path_expr: user_provided_type={:?}", user_provided_type);
749748
let ty = cx.tables().node_type(expr.hir_id);
750749
match ty.kind {

src/librustc_mir_build/hair/pattern/_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ impl<'p, 'tcx> PatStack<'p, 'tcx> {
411411
}
412412

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

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

0 commit comments

Comments
 (0)