Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
64acb7d9
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
64acb7d9
编写于
5月 16, 2021
作者:
J
jedel1043
1
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow formatting `Anonymous{Struct, Union}` declarations
上级
8a1dd691
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
64 addition
and
11 deletion
+64
-11
src/tools/rustfmt/src/items.rs
src/tools/rustfmt/src/items.rs
+3
-8
src/tools/rustfmt/src/lib.rs
src/tools/rustfmt/src/lib.rs
+6
-1
src/tools/rustfmt/src/types.rs
src/tools/rustfmt/src/types.rs
+55
-2
未找到文件。
src/tools/rustfmt/src/items.rs
浏览文件 @
64acb7d9
...
...
@@ -6,7 +6,7 @@
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
::{
...
...
@@ -31,12 +31,7 @@
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
)
...
...
@@ -976,7 +971,7 @@ fn format_header(&self, context: &RewriteContext<'_>, offset: Indent) -> String
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
,
...
...
src/tools/rustfmt/src/lib.rs
浏览文件 @
64acb7d9
...
...
@@ -31,7 +31,7 @@
use
ignore
;
use
rustc_ast
::
ast
;
use
rustc_span
::
symbol
;
use
rustc_span
::
{
symbol
,
DUMMY_SP
}
;
use
thiserror
::
Error
;
use
crate
::
comment
::
LineClasses
;
...
...
@@ -95,6 +95,11 @@
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)]
...
...
src/tools/rustfmt/src/types.rs
浏览文件 @
64acb7d9
...
...
@@ -2,14 +2,14 @@
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
,
};
...
...
@@ -24,6 +24,11 @@
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
{
...
...
@@ -764,6 +769,54 @@ fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String>
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
)
}
...
...
yitter
@yitter
mentioned in commit
2691a399
·
9月 17, 2021
mentioned in commit
2691a399
mentioned in commit 2691a399762149f2c8dd5c3ffc44244b98c37099
开关提交列表
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录