Skip to content

Commit

Permalink
Auto merge of #67298 - Mark-Simulacrum:beta-backports, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
[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.
  • Loading branch information
bors committed Dec 14, 2019
2 parents b509d9b + c403f62 commit edff4c8
Show file tree
Hide file tree
Showing 26 changed files with 416 additions and 155 deletions.
16 changes: 7 additions & 9 deletions src/librustc/hir/map/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,16 @@ impl<'a> DefCollector<'a> {
}

fn collect_field(&mut self, field: &'a StructField, index: Option<usize>) {
let index = |this: &Self| index.unwrap_or_else(|| {
let node_id = NodeId::placeholder_from_expn_id(this.expansion);
this.definitions.placeholder_field_index(node_id)
});

if field.is_placeholder {
self.definitions.set_placeholder_field_index(field.id, index(self));
self.visit_macro_invoc(field.id);
} else {
let name = field.ident.map(|ident| ident.name)
.or_else(|| index.map(sym::integer))
.unwrap_or_else(|| {
let node_id = NodeId::placeholder_from_expn_id(self.expansion);
sym::integer(self.definitions.placeholder_field_indices[&node_id])
});
let name = field.ident.map_or_else(|| sym::integer(index(self)), |ident| ident.name);
let def = self.create_def(field.id, DefPathData::ValueNs(name), field.span);
self.with_parent(def, |this| visit::walk_struct_field(this, field));
}
Expand Down Expand Up @@ -190,9 +191,6 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
// and every such attribute expands into a single field after it's resolved.
for (index, field) in data.fields().iter().enumerate() {
self.collect_field(field, Some(index));
if field.is_placeholder && field.ident.is_none() {
self.definitions.placeholder_field_indices.insert(field.id, index);
}
}
}

Expand Down
11 changes: 10 additions & 1 deletion src/librustc/hir/map/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pub struct Definitions {
/// we know what parent node that fragment should be attached to thanks to this table.
invocation_parents: FxHashMap<ExpnId, DefIndex>,
/// Indices of unnamed struct or variant fields with unresolved attributes.
pub(super) placeholder_field_indices: NodeMap<usize>,
pub placeholder_field_indices: NodeMap<usize>,
}

/// A unique identifier that we can use to lookup a definition
Expand Down Expand Up @@ -544,6 +544,15 @@ impl Definitions {
let old_parent = self.invocation_parents.insert(invoc_id, parent);
assert!(old_parent.is_none(), "parent `DefIndex` is reset for an invocation");
}

pub fn placeholder_field_index(&self, node_id: ast::NodeId) -> usize {
self.placeholder_field_indices[&node_id]
}

pub fn set_placeholder_field_index(&mut self, node_id: ast::NodeId, index: usize) {
let old_index = self.placeholder_field_indices.insert(node_id, index);
assert!(old_index.is_none(), "placeholder field index is reset for a node ID");
}
}

impl DefPathData {
Expand Down
5 changes: 4 additions & 1 deletion src/librustc_codegen_ssa/mir/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
instance,
promoted: None,
};
self.cx.tcx().const_eval(ty::ParamEnv::reveal_all().and(cid))
self.cx.tcx().const_eval(ty::ParamEnv::reveal_all().and(cid)).map_err(|err| {
self.cx.tcx().sess.span_err(constant.span, "erroneous constant encountered");
err
})
},
_ => Ok(self.monomorphize(&constant.literal)),
}
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,9 @@ impl UnusedParens {
match value.kind {
ast::ExprKind::Paren(ref inner) => {
if !Self::is_expr_parens_necessary(inner, followed_by_block) &&
value.attrs.is_empty() {
value.attrs.is_empty() &&
!value.span.from_expansion()
{
let expr_text = if let Ok(snippet) = cx.sess().source_map()
.span_to_snippet(value.span) {
snippet
Expand Down
11 changes: 8 additions & 3 deletions src/librustc_mir/transform/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,14 @@ impl<'a, 'tcx> Visitor<'tcx> for DeclMarker<'a, 'tcx> {
let stmt =
&self.body.basic_blocks()[location.block].statements[location.statement_index];
if let StatementKind::Assign(box (p, Rvalue::Use(Operand::Constant(c)))) = &stmt.kind {
if p.as_local().is_some() {
trace!("skipping store of const value {:?} to {:?}", c, local);
return;
match c.literal.val {
// Keep assignments from unevaluated constants around, since the evaluation
// may report errors, even if the use of the constant is dead code.
interpret::ConstValue::Unevaluated(..) => {}
_ => if p.as_local().is_some() {
trace!("skipping store of const value {:?} to {:?}", c, p);
return;
},
}
}
}
Expand Down
Loading

0 comments on commit edff4c8

Please sign in to comment.