Skip to content

Commit 52e1a52

Browse files
authored
Rollup merge of rust-lang#88775 - pnkfelix:revert-anon-union-parsing, r=davidtwco
Revert anon union parsing Revert PR rust-lang#84571 and rust-lang#85515, which implemented anonymous union parsing in a manner that broke the context-sensitivity for the `union` keyword and thus broke stable Rust code. Fix rust-lang#88583.
2 parents 8743472 + d647ebf commit 52e1a52

File tree

3 files changed

+12
-65
lines changed

3 files changed

+12
-65
lines changed

src/items.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::cmp::{max, min, Ordering};
66
use regex::Regex;
77
use rustc_ast::visit;
88
use rustc_ast::{ast, ptr};
9-
use rustc_span::{symbol, BytePos, Span};
9+
use rustc_span::{symbol, BytePos, Span, DUMMY_SP};
1010

1111
use crate::attr::filter_inline_attrs;
1212
use crate::comment::{
@@ -31,7 +31,12 @@ use crate::stmt::Stmt;
3131
use crate::utils::*;
3232
use crate::vertical::rewrite_with_alignment;
3333
use crate::visitor::FmtVisitor;
34-
use crate::DEFAULT_VISIBILITY;
34+
35+
const DEFAULT_VISIBILITY: ast::Visibility = ast::Visibility {
36+
kind: ast::VisibilityKind::Inherited,
37+
span: DUMMY_SP,
38+
tokens: None,
39+
};
3540

3641
fn type_annotation_separator(config: &Config) -> &str {
3742
colon_spaces(config)
@@ -972,7 +977,7 @@ impl<'a> StructParts<'a> {
972977
format_header(context, self.prefix, self.ident, self.vis, offset)
973978
}
974979

975-
pub(crate) fn from_variant(variant: &'a ast::Variant) -> Self {
980+
fn from_variant(variant: &'a ast::Variant) -> Self {
976981
StructParts {
977982
prefix: "",
978983
ident: variant.ident,

src/lib.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use std::path::PathBuf;
3232
use std::rc::Rc;
3333

3434
use rustc_ast::ast;
35-
use rustc_span::{symbol, DUMMY_SP};
35+
use rustc_span::symbol;
3636
use thiserror::Error;
3737

3838
use crate::comment::LineClasses;
@@ -96,11 +96,6 @@ mod types;
9696
mod vertical;
9797
pub(crate) mod visitor;
9898

99-
const DEFAULT_VISIBILITY: ast::Visibility = ast::Visibility {
100-
kind: ast::VisibilityKind::Inherited,
101-
span: DUMMY_SP,
102-
tokens: None,
103-
};
10499
/// The various errors that can occur during formatting. Note that not all of
105100
/// these can currently be propagated to clients.
106101
#[derive(Error, Debug)]

src/types.rs

+3-56
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use std::iter::ExactSizeIterator;
22
use std::ops::Deref;
33

4-
use rustc_ast::ast::{self, AttrVec, FnRetTy, Mutability};
5-
use rustc_span::{symbol::kw, symbol::Ident, BytePos, Pos, Span};
4+
use rustc_ast::ast::{self, FnRetTy, Mutability};
5+
use rustc_span::{symbol::kw, BytePos, Pos, Span};
66

7+
use crate::comment::{combine_strs_with_missing_comments, contains_comment};
78
use crate::config::lists::*;
89
use crate::config::{IndentStyle, TypeDensity, Version};
910
use crate::expr::{
1011
format_expr, rewrite_assign_rhs, rewrite_call, rewrite_tuple, rewrite_unary_prefix, ExprType,
1112
};
12-
use crate::items::StructParts;
1313
use crate::lists::{
1414
definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator,
1515
};
@@ -24,11 +24,6 @@ use crate::utils::{
2424
colon_spaces, extra_offset, first_line_width, format_extern, format_mutability,
2525
last_line_extendable, last_line_width, mk_sp, rewrite_ident,
2626
};
27-
use crate::DEFAULT_VISIBILITY;
28-
use crate::{
29-
comment::{combine_strs_with_missing_comments, contains_comment},
30-
items::format_struct_struct,
31-
};
3227

3328
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
3429
pub(crate) enum PathContext {
@@ -769,54 +764,6 @@ impl Rewrite for ast::Ty {
769764
ast::TyKind::Tup(ref items) => {
770765
rewrite_tuple(context, items.iter(), self.span, shape, items.len() == 1)
771766
}
772-
ast::TyKind::AnonymousStruct(ref fields, recovered) => {
773-
let ident = Ident::new(
774-
kw::Struct,
775-
mk_sp(self.span.lo(), self.span.lo() + BytePos(6)),
776-
);
777-
let data = ast::VariantData::Struct(fields.clone(), recovered);
778-
let variant = ast::Variant {
779-
attrs: AttrVec::new(),
780-
id: self.id,
781-
span: self.span,
782-
vis: DEFAULT_VISIBILITY,
783-
ident,
784-
data,
785-
disr_expr: None,
786-
is_placeholder: false,
787-
};
788-
format_struct_struct(
789-
&context,
790-
&StructParts::from_variant(&variant),
791-
fields,
792-
shape.indent,
793-
None,
794-
)
795-
}
796-
ast::TyKind::AnonymousUnion(ref fields, recovered) => {
797-
let ident = Ident::new(
798-
kw::Union,
799-
mk_sp(self.span.lo(), self.span.lo() + BytePos(5)),
800-
);
801-
let data = ast::VariantData::Struct(fields.clone(), recovered);
802-
let variant = ast::Variant {
803-
attrs: AttrVec::new(),
804-
id: self.id,
805-
span: self.span,
806-
vis: DEFAULT_VISIBILITY,
807-
ident,
808-
data,
809-
disr_expr: None,
810-
is_placeholder: false,
811-
};
812-
format_struct_struct(
813-
&context,
814-
&StructParts::from_variant(&variant),
815-
fields,
816-
shape.indent,
817-
None,
818-
)
819-
}
820767
ast::TyKind::Path(ref q_self, ref path) => {
821768
rewrite_path(context, PathContext::Type, q_self.as_ref(), path, shape)
822769
}

0 commit comments

Comments
 (0)