Skip to content

Commit edff4c8

Browse files
committed
Auto merge of #67298 - Mark-Simulacrum:beta-backports, r=Mark-Simulacrum
[beta] Beta backports Backporting the following pull requests: * resolve: Always resolve visibilities on impl items #67236 * resolve: Resolve visibilities on fields with non-builtin attributes #67106 * E0023: handle expected != tuple pattern type #67044 * Fix `unused_parens` triggers on macro by example code #66983 * Fix some issues with attributes on unnamed fields #66669 * Ensure that we get a hard error on generic ZST constants if their bodies #67134 (via #67297) Some of these conflicted on merge, I resolved where possible, sometimes by cherry-picking a commit or two more from the relevant PRs. Since those changes are necessary though for backport to proceed (otherwise not even std/core compile), seems fine -- they're fairly minor cleanups anyway.
2 parents b509d9b + c403f62 commit edff4c8

26 files changed

+416
-155
lines changed

src/librustc/hir/map/def_collector.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,16 @@ impl<'a> DefCollector<'a> {
7575
}
7676

7777
fn collect_field(&mut self, field: &'a StructField, index: Option<usize>) {
78+
let index = |this: &Self| index.unwrap_or_else(|| {
79+
let node_id = NodeId::placeholder_from_expn_id(this.expansion);
80+
this.definitions.placeholder_field_index(node_id)
81+
});
82+
7883
if field.is_placeholder {
84+
self.definitions.set_placeholder_field_index(field.id, index(self));
7985
self.visit_macro_invoc(field.id);
8086
} else {
81-
let name = field.ident.map(|ident| ident.name)
82-
.or_else(|| index.map(sym::integer))
83-
.unwrap_or_else(|| {
84-
let node_id = NodeId::placeholder_from_expn_id(self.expansion);
85-
sym::integer(self.definitions.placeholder_field_indices[&node_id])
86-
});
87+
let name = field.ident.map_or_else(|| sym::integer(index(self)), |ident| ident.name);
8788
let def = self.create_def(field.id, DefPathData::ValueNs(name), field.span);
8889
self.with_parent(def, |this| visit::walk_struct_field(this, field));
8990
}
@@ -190,9 +191,6 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
190191
// and every such attribute expands into a single field after it's resolved.
191192
for (index, field) in data.fields().iter().enumerate() {
192193
self.collect_field(field, Some(index));
193-
if field.is_placeholder && field.ident.is_none() {
194-
self.definitions.placeholder_field_indices.insert(field.id, index);
195-
}
196194
}
197195
}
198196

src/librustc/hir/map/definitions.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub struct Definitions {
105105
/// we know what parent node that fragment should be attached to thanks to this table.
106106
invocation_parents: FxHashMap<ExpnId, DefIndex>,
107107
/// Indices of unnamed struct or variant fields with unresolved attributes.
108-
pub(super) placeholder_field_indices: NodeMap<usize>,
108+
pub placeholder_field_indices: NodeMap<usize>,
109109
}
110110

111111
/// A unique identifier that we can use to lookup a definition
@@ -544,6 +544,15 @@ impl Definitions {
544544
let old_parent = self.invocation_parents.insert(invoc_id, parent);
545545
assert!(old_parent.is_none(), "parent `DefIndex` is reset for an invocation");
546546
}
547+
548+
pub fn placeholder_field_index(&self, node_id: ast::NodeId) -> usize {
549+
self.placeholder_field_indices[&node_id]
550+
}
551+
552+
pub fn set_placeholder_field_index(&mut self, node_id: ast::NodeId, index: usize) {
553+
let old_index = self.placeholder_field_indices.insert(node_id, index);
554+
assert!(old_index.is_none(), "placeholder field index is reset for a node ID");
555+
}
547556
}
548557

549558
impl DefPathData {

src/librustc_codegen_ssa/mir/constant.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
2323
instance,
2424
promoted: None,
2525
};
26-
self.cx.tcx().const_eval(ty::ParamEnv::reveal_all().and(cid))
26+
self.cx.tcx().const_eval(ty::ParamEnv::reveal_all().and(cid)).map_err(|err| {
27+
self.cx.tcx().sess.span_err(constant.span, "erroneous constant encountered");
28+
err
29+
})
2730
},
2831
_ => Ok(self.monomorphize(&constant.literal)),
2932
}

src/librustc_lint/unused.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,9 @@ impl UnusedParens {
374374
match value.kind {
375375
ast::ExprKind::Paren(ref inner) => {
376376
if !Self::is_expr_parens_necessary(inner, followed_by_block) &&
377-
value.attrs.is_empty() {
377+
value.attrs.is_empty() &&
378+
!value.span.from_expansion()
379+
{
378380
let expr_text = if let Ok(snippet) = cx.sess().source_map()
379381
.span_to_snippet(value.span) {
380382
snippet

src/librustc_mir/transform/simplify.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,14 @@ impl<'a, 'tcx> Visitor<'tcx> for DeclMarker<'a, 'tcx> {
363363
let stmt =
364364
&self.body.basic_blocks()[location.block].statements[location.statement_index];
365365
if let StatementKind::Assign(box (p, Rvalue::Use(Operand::Constant(c)))) = &stmt.kind {
366-
if p.as_local().is_some() {
367-
trace!("skipping store of const value {:?} to {:?}", c, local);
368-
return;
366+
match c.literal.val {
367+
// Keep assignments from unevaluated constants around, since the evaluation
368+
// may report errors, even if the use of the constant is dead code.
369+
interpret::ConstValue::Unevaluated(..) => {}
370+
_ => if p.as_local().is_some() {
371+
trace!("skipping store of const value {:?} to {:?}", c, p);
372+
return;
373+
},
369374
}
370375
}
371376
}

0 commit comments

Comments
 (0)