Skip to content

Commit

Permalink
Auto merge of rust-lang#88946 - cuviper:beta-next, r=Mark-Simulacrum
Browse files Browse the repository at this point in the history
[beta] backports

- rustdoc: Fix ICE with `doc(hidden)` on tuple variant fields rust-lang#88639
- Fix 2021 `dyn` suggestion that used code as label rust-lang#88657
- Workaround blink/chromium grid layout limitation of 1000 rows rust-lang#88776
- Change scope of temporaries in match guards rust-lang#88678
- Add a regression test for rust-lang#88649 rust-lang#88691
- Revert anon union parsing rust-lang#88775
- Disable validate_maintainers. rust-lang#88977

Also drop stage0 rustfmt, because that's only supposed to be used on master.

r? `@Mark-Simulacrum`
  • Loading branch information
bors committed Sep 17, 2021
2 parents f9a839e + ce1c9dc commit deef866
Show file tree
Hide file tree
Showing 40 changed files with 201 additions and 649 deletions.
4 changes: 0 additions & 4 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1902,10 +1902,6 @@ pub enum TyKind {
Never,
/// A tuple (`(A, B, C, D,...)`).
Tup(Vec<P<Ty>>),
/// An anonymous struct type i.e. `struct { foo: Type }`
AnonymousStruct(Vec<FieldDef>, bool),
/// An anonymous union type i.e. `union { bar: Type }`
AnonymousUnion(Vec<FieldDef>, bool),
/// A path (`module::module::...::Type`), optionally
/// "qualified", e.g., `<Vec<T> as SomeTrait>::SomeType`.
///
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,9 +484,6 @@ pub fn noop_visit_ty<T: MutVisitor>(ty: &mut P<Ty>, vis: &mut T) {
visit_vec(bounds, |bound| vis.visit_param_bound(bound));
}
TyKind::MacCall(mac) => vis.visit_mac_call(mac),
TyKind::AnonymousStruct(fields, ..) | TyKind::AnonymousUnion(fields, ..) => {
fields.flat_map_in_place(|field| vis.flat_map_field_def(field));
}
}
vis.visit_span(span);
visit_lazy_tts(tokens, vis);
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,6 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) {
TyKind::Typeof(ref expression) => visitor.visit_anon_const(expression),
TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err => {}
TyKind::MacCall(ref mac) => visitor.visit_mac_call(mac),
TyKind::AnonymousStruct(ref fields, ..) | TyKind::AnonymousUnion(ref fields, ..) => {
walk_list!(visitor, visit_field_def, fields)
}
TyKind::Never | TyKind::CVarArgs => {}
}
}
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -749,10 +749,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
}

pub(super) fn lower_field_def(
&mut self,
(index, f): (usize, &FieldDef),
) -> hir::FieldDef<'hir> {
fn lower_field_def(&mut self, (index, f): (usize, &FieldDef)) -> hir::FieldDef<'hir> {
let ty = if let TyKind::Path(ref qself, ref path) = f.ty.kind {
let t = self.lower_path_ty(
&f.ty,
Expand Down
9 changes: 0 additions & 9 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1290,15 +1290,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
let kind = match t.kind {
TyKind::Infer => hir::TyKind::Infer,
TyKind::Err => hir::TyKind::Err,
// FIXME(unnamed_fields): IMPLEMENTATION IN PROGRESS
TyKind::AnonymousStruct(ref _fields, _recovered) => {
self.sess.struct_span_err(t.span, "anonymous structs are unimplemented").emit();
hir::TyKind::Err
}
TyKind::AnonymousUnion(ref _fields, _recovered) => {
self.sess.struct_span_err(t.span, "anonymous unions are unimplemented").emit();
hir::TyKind::Err
}
TyKind::Slice(ref ty) => hir::TyKind::Slice(self.lower_ty(ty, itctx)),
TyKind::Ptr(ref mt) => hir::TyKind::Ptr(self.lower_mt(mt, itctx)),
TyKind::Rptr(ref region, ref mt) => {
Expand Down
68 changes: 0 additions & 68 deletions compiler/rustc_ast_passes/src/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,19 +193,13 @@ impl<'a> AstValidator<'a> {
}
}
}
TyKind::AnonymousStruct(ref fields, ..) | TyKind::AnonymousUnion(ref fields, ..) => {
self.with_banned_assoc_ty_bound(|this| {
walk_list!(this, visit_struct_field_def, fields)
});
}
_ => visit::walk_ty(self, t),
}
}

fn visit_struct_field_def(&mut self, field: &'a FieldDef) {
if let Some(ident) = field.ident {
if ident.name == kw::Underscore {
self.check_anonymous_field(field);
self.visit_vis(&field.vis);
self.visit_ident(ident);
self.visit_ty_common(&field.ty);
Expand Down Expand Up @@ -251,66 +245,6 @@ impl<'a> AstValidator<'a> {
err.emit();
}

fn check_anonymous_field(&self, field: &FieldDef) {
let FieldDef { ty, .. } = field;
match &ty.kind {
TyKind::AnonymousStruct(..) | TyKind::AnonymousUnion(..) => {
// We already checked for `kw::Underscore` before calling this function,
// so skip the check
}
TyKind::Path(..) => {
// If the anonymous field contains a Path as type, we can't determine
// if the path is a valid struct or union, so skip the check
}
_ => {
let msg = "unnamed fields can only have struct or union types";
let label = "not a struct or union";
self.err_handler()
.struct_span_err(field.span, msg)
.span_label(ty.span, label)
.emit();
}
}
}

fn deny_anonymous_struct(&self, ty: &Ty) {
match &ty.kind {
TyKind::AnonymousStruct(..) => {
self.err_handler()
.struct_span_err(
ty.span,
"anonymous structs are not allowed outside of unnamed struct or union fields",
)
.span_label(ty.span, "anonymous struct declared here")
.emit();
}
TyKind::AnonymousUnion(..) => {
self.err_handler()
.struct_span_err(
ty.span,
"anonymous unions are not allowed outside of unnamed struct or union fields",
)
.span_label(ty.span, "anonymous union declared here")
.emit();
}
_ => {}
}
}

fn deny_anonymous_field(&self, field: &FieldDef) {
if let Some(ident) = field.ident {
if ident.name == kw::Underscore {
self.err_handler()
.struct_span_err(
field.span,
"anonymous fields are not allowed outside of structs or unions",
)
.span_label(ident.span, "anonymous field declared here")
.emit()
}
}
}

fn check_decl_no_pat(decl: &FnDecl, mut report_err: impl FnMut(Span, Option<Ident>, bool)) {
for Param { pat, .. } in &decl.inputs {
match pat.kind {
Expand Down Expand Up @@ -1067,7 +1001,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {

fn visit_ty(&mut self, ty: &'a Ty) {
self.visit_ty_common(ty);
self.deny_anonymous_struct(ty);
self.walk_ty(ty)
}

Expand All @@ -1082,7 +1015,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
}

fn visit_field_def(&mut self, s: &'a FieldDef) {
self.deny_anonymous_field(s);
visit::walk_field_def(self, s)
}

Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
// involved, so we only emit errors where there are no other parsing errors.
gate_all!(destructuring_assignment, "destructuring assignments are unstable");
}
gate_all!(unnamed_fields, "unnamed fields are not yet fully implemented");

// All uses of `gate_all!` below this point were added in #65742,
// and subsequently disabled (with the non-early gating readded).
Expand Down
16 changes: 6 additions & 10 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -985,14 +985,6 @@ impl<'a> State<'a> {
}
self.pclose();
}
ast::TyKind::AnonymousStruct(ref fields, ..) => {
self.head("struct");
self.print_record_struct_body(&fields, ty.span);
}
ast::TyKind::AnonymousUnion(ref fields, ..) => {
self.head("union");
self.print_record_struct_body(&fields, ty.span);
}
ast::TyKind::Paren(ref typ) => {
self.popen();
self.print_type(typ);
Expand Down Expand Up @@ -1413,7 +1405,12 @@ impl<'a> State<'a> {
}
}

crate fn print_record_struct_body(&mut self, fields: &[ast::FieldDef], span: rustc_span::Span) {
crate fn print_record_struct_body(
&mut self,
fields: &Vec<ast::FieldDef>,
span: rustc_span::Span,
) {
self.nbsp();
self.bopen();
self.hardbreak_if_not_bol();

Expand Down Expand Up @@ -1462,7 +1459,6 @@ impl<'a> State<'a> {
}
ast::VariantData::Struct(ref fields, ..) => {
self.print_where_clause(&generics.where_clause);
self.nbsp();
self.print_record_struct_body(fields, span);
}
}
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,9 +639,6 @@ declare_features! (
/// Allows specifying the as-needed link modifier
(active, native_link_modifiers_as_needed, "1.53.0", Some(81490), None),

/// Allows unnamed fields of struct and union type
(incomplete, unnamed_fields, "1.53.0", Some(49804), None),

/// Allows qualified paths in struct expressions, struct patterns and tuple struct patterns.
(active, more_qualified_paths, "1.54.0", Some(86935), None),

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/build/expr/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let then_blk = unpack!(this.then_else_break(
block,
&this.thir[cond],
condition_scope,
Some(condition_scope),
condition_scope,
then_expr.span,
));
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_mir_build/src/build/matches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
&mut self,
mut block: BasicBlock,
expr: &Expr<'tcx>,
temp_scope: region::Scope,
temp_scope_override: Option<region::Scope>,
break_scope: region::Scope,
variable_scope_span: Span,
) -> BlockAnd<()> {
Expand All @@ -53,7 +53,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
this.then_else_break(
block,
&this.thir[value],
temp_scope,
temp_scope_override,
break_scope,
variable_scope_span,
)
Expand All @@ -63,6 +63,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
this.lower_let_expr(block, &this.thir[expr], pat, break_scope, variable_scope_span)
}
_ => {
let temp_scope = temp_scope_override.unwrap_or_else(|| this.local_scope());
let mutability = Mutability::Mut;
let place =
unpack!(block = this.as_temp(block, Some(temp_scope), expr, mutability));
Expand Down Expand Up @@ -1948,7 +1949,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
}

let arm_span = arm_span.unwrap();
let arm_scope = self.local_scope();
let match_scope = match_scope.unwrap();
let mut guard_span = rustc_span::DUMMY_SP;

Expand All @@ -1957,7 +1957,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
Guard::If(e) => {
let e = &this.thir[e];
guard_span = e.span;
this.then_else_break(block, e, arm_scope, match_scope, arm_span)
this.then_else_break(block, e, None, match_scope, arm_span)
}
Guard::IfLet(ref pat, scrutinee) => {
let s = &this.thir[scrutinee];
Expand Down
38 changes: 16 additions & 22 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ impl<'a> Parser<'a> {
Ok((class_name, ItemKind::Union(vdata, generics)))
}

pub(super) fn parse_record_struct_body(
fn parse_record_struct_body(
&mut self,
adt_ty: &str,
) -> PResult<'a, (Vec<FieldDef>, /* recovered */ bool)> {
Expand Down Expand Up @@ -1468,28 +1468,22 @@ impl<'a> Parser<'a> {
fn parse_field_ident(&mut self, adt_ty: &str, lo: Span) -> PResult<'a, Ident> {
let (ident, is_raw) = self.ident_or_err()?;
if !is_raw && ident.is_reserved() {
if ident.name == kw::Underscore {
self.sess.gated_spans.gate(sym::unnamed_fields, lo);
let err = if self.check_fn_front_matter(false) {
// We use `parse_fn` to get a span for the function
if let Err(mut db) = self.parse_fn(&mut Vec::new(), |_| true, lo) {
db.delay_as_bug();
}
let mut err = self.struct_span_err(
lo.to(self.prev_token.span),
&format!("functions are not allowed in {} definitions", adt_ty),
);
err.help("unlike in C++, Java, and C#, functions are declared in `impl` blocks");
err.help("see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information");
err
} else {
let err = if self.check_fn_front_matter(false) {
// We use `parse_fn` to get a span for the function
if let Err(mut db) = self.parse_fn(&mut Vec::new(), |_| true, lo) {
db.delay_as_bug();
}
let mut err = self.struct_span_err(
lo.to(self.prev_token.span),
&format!("functions are not allowed in {} definitions", adt_ty),
);
err.help(
"unlike in C++, Java, and C#, functions are declared in `impl` blocks",
);
err.help("see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information");
err
} else {
self.expected_ident_found()
};
return Err(err);
}
self.expected_ident_found()
};
return Err(err);
}
self.bump();
Ok(ident)
Expand Down
13 changes: 0 additions & 13 deletions compiler/rustc_parse/src/parser/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,19 +226,6 @@ impl<'a> Parser<'a> {
}
} else if self.eat_keyword(kw::Impl) {
self.parse_impl_ty(&mut impl_dyn_multi)?
} else if self.token.is_keyword(kw::Union)
&& self.look_ahead(1, |t| t == &token::OpenDelim(token::Brace))
{
self.bump();
let (fields, recovered) = self.parse_record_struct_body("union")?;
let span = lo.to(self.prev_token.span);
self.sess.gated_spans.gate(sym::unnamed_fields, span);
TyKind::AnonymousUnion(fields, recovered)
} else if self.eat_keyword(kw::Struct) {
let (fields, recovered) = self.parse_record_struct_body("struct")?;
let span = lo.to(self.prev_token.span);
self.sess.gated_spans.gate(sym::unnamed_fields, span);
TyKind::AnonymousStruct(fields, recovered)
} else if self.is_explicit_dyn_type() {
self.parse_dyn_ty(&mut impl_dyn_multi)?
} else if self.eat_lt() {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,6 @@ symbols! {
unix,
unlikely,
unmarked_api,
unnamed_fields,
unpin,
unreachable,
unreachable_code,
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,7 +945,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
Ok(s) if s.starts_with('<') => sugg,
_ => format!("<{}>", sugg),
};
let replace = String::from("use `dyn`");
let sugg_label = "use `dyn`";
if self.sess().edition() >= Edition::Edition2021 {
let mut err = rustc_errors::struct_span_err!(
self.sess(),
Expand All @@ -956,8 +956,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
);
err.span_suggestion(
self_ty.span,
&sugg,
replace,
sugg_label,
sugg,
Applicability::MachineApplicable,
)
.emit();
Expand All @@ -968,7 +968,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self_ty.span,
|lint| {
let mut db = lint.build(msg);
db.span_suggestion(self_ty.span, &replace, sugg, app);
db.span_suggestion(self_ty.span, sugg_label, sugg, app);
db.emit()
},
);
Expand Down
Loading

0 comments on commit deef866

Please sign in to comment.