Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
d67f1a4
Update log to 0.4.14
jyn514 May 2, 2021
e243be6
Allow formatting `Anonymous{Struct, Union}` declarations
jedel1043 May 17, 2021
58c63cf
Add support for using qualified paths with structs in expression and …
rylev Dec 10, 2020
1e2258f
Use `AttrVec` for `Arm`, `FieldDef`, and `Variant`
JohnTitor Jun 16, 2021
2608f2c
fix(rustfmt): load nested out-of-line mods correctly
calebcartwright Jun 18, 2021
71f01d1
Delete spaces
Jun 21, 2021
d13020c
Rollup merge of #86274 - alexander-melentyev:spaces, r=bjorn3
JohnTitor Jun 21, 2021
0b8a26f
Rollup merge of #86424 - calebcartwright:rustfmt-mod-resolution, r=Ma…
JohnTitor Jun 21, 2021
33acc96
Document rustfmt on nightly-rustc
jyn514 Jun 30, 2021
abf449f
Rework SESSION_GLOBALS API to prevent overwriting it
GuillaumeGomez May 5, 2021
277feac
Use LocalExpnId where possible.
cjgillot Jun 25, 2021
bfd479d
Merge pull request #4920 from calebcartwright/subtree-sync
calebcartwright Jul 26, 2021
75765f6
Allow `--edition 2021` to be passed to rustfmt
PatchMixolydic May 22, 2021
1ca3798
Improve pasta copyability of `merge_imports` deprecation message
casey May 10, 2021
486e774
Adjusting help message (#4865)
murchu27 Jun 11, 2021
e634a6f
Updating outdated links (#4869)
murchu27 Jun 16, 2021
b305d62
fix: correct arm leading pipe check (#4880)
calebcartwright Jun 24, 2021
19733f1
Change line endings from CRLF to LF
Jun 25, 2021
2cf280e
docs: clarify match_arm_blocks config documentation
calebcartwright Jul 5, 2021
4c2959f
fix a bunch of clippy warnings
matthiaskrgr Jul 18, 2021
d42be80
chore: disable clippy::matches_like_macro lint
calebcartwright Jul 18, 2021
0832137
fix link in Contributing.md
ebobrow Jul 19, 2021
4236289
chore: bump toolchain
calebcartwright Jul 26, 2021
102a06b
Merge commit '4236289b75ee55c78538c749512cdbeea5e1c332' into update-r…
calebcartwright Jul 26, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Allow formatting Anonymous{Struct, Union} declarations
  • Loading branch information
jedel1043 committed May 17, 2021
commit e243be6adad16ad65c3349e476d528d1f416ed59
11 changes: 3 additions & 8 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::cmp::{max, min, Ordering};
use regex::Regex;
use rustc_ast::visit;
use rustc_ast::{ast, ptr};
use rustc_span::{symbol, BytePos, Span, DUMMY_SP};
use rustc_span::{symbol, BytePos, Span};

use crate::attr::filter_inline_attrs;
use crate::comment::{
Expand All @@ -31,12 +31,7 @@ use crate::stmt::Stmt;
use crate::utils::*;
use crate::vertical::rewrite_with_alignment;
use crate::visitor::FmtVisitor;

const DEFAULT_VISIBILITY: ast::Visibility = ast::Visibility {
kind: ast::VisibilityKind::Inherited,
span: DUMMY_SP,
tokens: None,
};
use crate::DEFAULT_VISIBILITY;

fn type_annotation_separator(config: &Config) -> &str {
colon_spaces(config)
Expand Down Expand Up @@ -976,7 +971,7 @@ impl<'a> StructParts<'a> {
format_header(context, self.prefix, self.ident, self.vis, offset)
}

fn from_variant(variant: &'a ast::Variant) -> Self {
pub(crate) fn from_variant(variant: &'a ast::Variant) -> Self {
StructParts {
prefix: "",
ident: variant.ident,
Expand Down
7 changes: 6 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use std::rc::Rc;

use ignore;
use rustc_ast::ast;
use rustc_span::symbol;
use rustc_span::{symbol, DUMMY_SP};
use thiserror::Error;

use crate::comment::LineClasses;
Expand Down Expand Up @@ -95,6 +95,11 @@ mod types;
mod vertical;
pub(crate) mod visitor;

const DEFAULT_VISIBILITY: ast::Visibility = ast::Visibility {
kind: ast::VisibilityKind::Inherited,
span: DUMMY_SP,
tokens: None,
};
/// The various errors that can occur during formatting. Note that not all of
/// these can currently be propagated to clients.
#[derive(Error, Debug)]
Expand Down
57 changes: 55 additions & 2 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ use std::iter::ExactSizeIterator;
use std::ops::Deref;

use rustc_ast::ast::{self, FnRetTy, Mutability};
use rustc_span::{symbol::kw, BytePos, Pos, Span};
use rustc_span::{symbol::kw, symbol::Ident, BytePos, Pos, Span};

use crate::comment::{combine_strs_with_missing_comments, contains_comment};
use crate::config::lists::*;
use crate::config::{IndentStyle, TypeDensity, Version};
use crate::expr::{
format_expr, rewrite_assign_rhs, rewrite_call, rewrite_tuple, rewrite_unary_prefix, ExprType,
};
use crate::items::StructParts;
use crate::lists::{
definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator,
};
Expand All @@ -24,6 +24,11 @@ use crate::utils::{
colon_spaces, extra_offset, first_line_width, format_extern, format_mutability,
last_line_extendable, last_line_width, mk_sp, rewrite_ident,
};
use crate::DEFAULT_VISIBILITY;
use crate::{
comment::{combine_strs_with_missing_comments, contains_comment},
items::format_struct_struct,
};

#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub(crate) enum PathContext {
Expand Down Expand Up @@ -764,6 +769,54 @@ impl Rewrite for ast::Ty {
ast::TyKind::Tup(ref items) => {
rewrite_tuple(context, items.iter(), self.span, shape, items.len() == 1)
}
ast::TyKind::AnonymousStruct(ref fields, recovered) => {
let ident = Ident::new(
kw::Struct,
mk_sp(self.span.lo(), self.span.lo() + BytePos(6)),
);
let data = ast::VariantData::Struct(fields.clone(), recovered);
let variant = ast::Variant {
attrs: vec![],
id: self.id,
span: self.span,
vis: DEFAULT_VISIBILITY,
ident,
data,
disr_expr: None,
is_placeholder: false,
};
format_struct_struct(
&context,
&StructParts::from_variant(&variant),
fields,
shape.indent,
None,
)
}
ast::TyKind::AnonymousUnion(ref fields, recovered) => {
let ident = Ident::new(
kw::Union,
mk_sp(self.span.lo(), self.span.lo() + BytePos(5)),
);
let data = ast::VariantData::Struct(fields.clone(), recovered);
let variant = ast::Variant {
attrs: vec![],
id: self.id,
span: self.span,
vis: DEFAULT_VISIBILITY,
ident,
data,
disr_expr: None,
is_placeholder: false,
};
format_struct_struct(
&context,
&StructParts::from_variant(&variant),
fields,
shape.indent,
None,
)
}
ast::TyKind::Path(ref q_self, ref path) => {
rewrite_path(context, PathContext::Type, q_self.as_ref(), path, shape)
}
Expand Down