Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
fe9635f7
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,发现更多精彩内容 >>
未验证
提交
fe9635f7
编写于
6月 16, 2022
作者:
D
David Tolnay
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix pretty printing of empty type bound lists in where-clause
上级
1b8ca540
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
76 addition
and
50 deletion
+76
-50
compiler/rustc_ast_pretty/src/pprust/state.rs
compiler/rustc_ast_pretty/src/pprust/state.rs
+49
-44
compiler/rustc_ast_pretty/src/pprust/state/item.rs
compiler/rustc_ast_pretty/src/pprust/state/item.rs
+23
-5
compiler/rustc_parse/src/parser/diagnostics.rs
compiler/rustc_parse/src/parser/diagnostics.rs
+4
-1
未找到文件。
compiler/rustc_ast_pretty/src/pprust/state.rs
浏览文件 @
fe9635f7
...
...
@@ -814,7 +814,7 @@ fn ty_to_string(&self, ty: &ast::Ty) -> String {
}
fn
bounds_to_string
(
&
self
,
bounds
:
&
[
ast
::
GenericBound
])
->
String
{
Self
::
to_string
(|
s
|
s
.print_type_bounds
(
""
,
bounds
))
Self
::
to_string
(|
s
|
s
.print_type_bounds
(
bounds
))
}
fn
pat_to_string
(
&
self
,
pat
:
&
ast
::
Pat
)
->
String
{
...
...
@@ -991,7 +991,12 @@ pub fn print_assoc_constraint(&mut self, constraint: &ast::AssocConstraint) {
Term
::
Const
(
c
)
=>
self
.print_expr_anon_const
(
c
,
&
[]),
}
}
ast
::
AssocConstraintKind
::
Bound
{
bounds
}
=>
self
.print_type_bounds
(
":"
,
&*
bounds
),
ast
::
AssocConstraintKind
::
Bound
{
bounds
}
=>
{
if
!
bounds
.is_empty
()
{
self
.word_nbsp
(
":"
);
self
.print_type_bounds
(
&
bounds
);
}
}
}
}
...
...
@@ -1045,11 +1050,14 @@ pub fn print_type(&mut self, ty: &ast::Ty) {
}
ast
::
TyKind
::
Path
(
Some
(
ref
qself
),
ref
path
)
=>
self
.print_qpath
(
path
,
qself
,
false
),
ast
::
TyKind
::
TraitObject
(
ref
bounds
,
syntax
)
=>
{
let
prefix
=
if
syntax
==
ast
::
TraitObjectSyntax
::
Dyn
{
"dyn"
}
else
{
""
};
self
.print_type_bounds
(
prefix
,
&
bounds
);
if
syntax
==
ast
::
TraitObjectSyntax
::
Dyn
{
self
.word_nbsp
(
"dyn"
);
}
self
.print_type_bounds
(
bounds
);
}
ast
::
TyKind
::
ImplTrait
(
_
,
ref
bounds
)
=>
{
self
.print_type_bounds
(
"impl"
,
&
bounds
);
self
.word_nbsp
(
"impl"
);
self
.print_type_bounds
(
bounds
);
}
ast
::
TyKind
::
Array
(
ref
ty
,
ref
length
)
=>
{
self
.word
(
"["
);
...
...
@@ -1549,29 +1557,24 @@ pub(crate) fn print_asyncness(&mut self, asyncness: ast::Async) {
}
}
pub
fn
print_type_bounds
(
&
mut
self
,
prefix
:
&
'static
str
,
bounds
:
&
[
ast
::
GenericBound
])
{
if
!
bounds
.is_empty
()
{
self
.word
(
prefix
);
let
mut
first
=
true
;
for
bound
in
bounds
{
if
!
(
first
&&
prefix
.is_empty
())
{
self
.nbsp
();
}
if
first
{
first
=
false
;
}
else
{
self
.word_space
(
"+"
);
}
pub
fn
print_type_bounds
(
&
mut
self
,
bounds
:
&
[
ast
::
GenericBound
])
{
let
mut
first
=
true
;
for
bound
in
bounds
{
if
first
{
first
=
false
;
}
else
{
self
.nbsp
();
self
.word_space
(
"+"
);
}
match
bound
{
GenericBound
::
Trait
(
tref
,
modifier
)
=>
{
if
modifier
==
&
TraitBoundModifier
::
Maybe
{
self
.word
(
"?"
);
}
self
.print_poly_trait_ref
(
tref
);
match
bound
{
GenericBound
::
Trait
(
tref
,
modifier
)
=>
{
if
modifier
==
&
TraitBoundModifier
::
Maybe
{
self
.word
(
"?"
);
}
GenericBound
::
Outlives
(
lt
)
=>
self
.print_lifetime
(
*
lt
),
self
.print_poly_trait_ref
(
tref
);
}
GenericBound
::
Outlives
(
lt
)
=>
self
.print_lifetime
(
*
lt
),
}
}
}
...
...
@@ -1580,22 +1583,14 @@ pub(crate) fn print_lifetime(&mut self, lifetime: ast::Lifetime) {
self
.print_name
(
lifetime
.ident.name
)
}
pub
(
crate
)
fn
print_lifetime_bounds
(
&
mut
self
,
lifetime
:
ast
::
Lifetime
,
bounds
:
&
ast
::
GenericBounds
,
)
{
self
.print_lifetime
(
lifetime
);
if
!
bounds
.is_empty
()
{
self
.word
(
": "
);
for
(
i
,
bound
)
in
bounds
.iter
()
.enumerate
()
{
if
i
!=
0
{
self
.word
(
" + "
);
}
match
bound
{
ast
::
GenericBound
::
Outlives
(
lt
)
=>
self
.print_lifetime
(
*
lt
),
_
=>
panic!
(),
}
pub
(
crate
)
fn
print_lifetime_bounds
(
&
mut
self
,
bounds
:
&
ast
::
GenericBounds
)
{
for
(
i
,
bound
)
in
bounds
.iter
()
.enumerate
()
{
if
i
!=
0
{
self
.word
(
" + "
);
}
match
bound
{
ast
::
GenericBound
::
Outlives
(
lt
)
=>
self
.print_lifetime
(
*
lt
),
_
=>
panic!
(),
}
}
}
...
...
@@ -1613,11 +1608,18 @@ pub(crate) fn print_generic_params(&mut self, generic_params: &[ast::GenericPara
match
param
.kind
{
ast
::
GenericParamKind
::
Lifetime
=>
{
let
lt
=
ast
::
Lifetime
{
id
:
param
.id
,
ident
:
param
.ident
};
s
.print_lifetime_bounds
(
lt
,
&
param
.bounds
)
s
.print_lifetime
(
lt
);
if
!
param
.bounds
.is_empty
()
{
s
.word_nbsp
(
":"
);
s
.print_lifetime_bounds
(
&
param
.bounds
)
}
}
ast
::
GenericParamKind
::
Type
{
ref
default
}
=>
{
s
.print_ident
(
param
.ident
);
s
.print_type_bounds
(
":"
,
&
param
.bounds
);
if
!
param
.bounds
.is_empty
()
{
s
.word_nbsp
(
":"
);
s
.print_type_bounds
(
&
param
.bounds
);
}
if
let
Some
(
ref
default
)
=
default
{
s
.space
();
s
.word_space
(
"="
);
...
...
@@ -1630,7 +1632,10 @@ pub(crate) fn print_generic_params(&mut self, generic_params: &[ast::GenericPara
s
.space
();
s
.word_space
(
":"
);
s
.print_type
(
ty
);
s
.print_type_bounds
(
":"
,
&
param
.bounds
);
if
!
param
.bounds
.is_empty
()
{
s
.word_nbsp
(
":"
);
s
.print_type_bounds
(
&
param
.bounds
);
}
if
let
Some
(
ref
default
)
=
default
{
s
.space
();
s
.word_space
(
"="
);
...
...
compiler/rustc_ast_pretty/src/pprust/state/item.rs
浏览文件 @
fe9635f7
...
...
@@ -114,7 +114,10 @@ fn print_associated_type(
self
.word_space
(
"type"
);
self
.print_ident
(
ident
);
self
.print_generic_params
(
&
generics
.params
);
self
.print_type_bounds
(
":"
,
bounds
);
if
!
bounds
.is_empty
()
{
self
.word_nbsp
(
":"
);
self
.print_type_bounds
(
bounds
);
}
self
.print_where_clause_parts
(
where_clauses
.0.0
,
before_predicates
);
if
let
Some
(
ty
)
=
ty
{
self
.space
();
...
...
@@ -320,7 +323,10 @@ pub(crate) fn print_item(&mut self, item: &ast::Item) {
real_bounds
.push
(
b
.clone
());
}
}
self
.print_type_bounds
(
":"
,
&
real_bounds
);
if
!
real_bounds
.is_empty
()
{
self
.word_nbsp
(
":"
);
self
.print_type_bounds
(
&
real_bounds
);
}
self
.print_where_clause
(
&
generics
.where_clause
);
self
.word
(
" "
);
self
.bopen
();
...
...
@@ -347,7 +353,10 @@ pub(crate) fn print_item(&mut self, item: &ast::Item) {
}
}
self
.nbsp
();
self
.print_type_bounds
(
"="
,
&
real_bounds
);
if
!
real_bounds
.is_empty
()
{
self
.word_nbsp
(
"="
);
self
.print_type_bounds
(
&
real_bounds
);
}
self
.print_where_clause
(
&
generics
.where_clause
);
self
.word
(
";"
);
self
.end
();
// end inner head-block
...
...
@@ -618,14 +627,23 @@ pub fn print_where_predicate(&mut self, predicate: &ast::WherePredicate) {
})
=>
{
self
.print_formal_generic_params
(
bound_generic_params
);
self
.print_type
(
bounded_ty
);
self
.print_type_bounds
(
":"
,
bounds
);
self
.word
(
":"
);
if
!
bounds
.is_empty
()
{
self
.nbsp
();
self
.print_type_bounds
(
bounds
);
}
}
ast
::
WherePredicate
::
RegionPredicate
(
ast
::
WhereRegionPredicate
{
lifetime
,
bounds
,
..
})
=>
{
self
.print_lifetime_bounds
(
*
lifetime
,
bounds
);
self
.print_lifetime
(
*
lifetime
);
self
.word
(
":"
);
if
!
bounds
.is_empty
()
{
self
.nbsp
();
self
.print_lifetime_bounds
(
bounds
);
}
}
ast
::
WherePredicate
::
EqPredicate
(
ast
::
WhereEqPredicate
{
lhs_ty
,
rhs_ty
,
..
})
=>
{
self
.print_type
(
lhs_ty
);
...
...
compiler/rustc_parse/src/parser/diagnostics.rs
浏览文件 @
fe9635f7
...
...
@@ -1355,7 +1355,10 @@ pub(super) fn maybe_recover_from_bad_type_plus(&mut self, ty: &Ty) -> PResult<'a
s
.print_mutability
(
mut_ty
.mutbl
,
false
);
s
.popen
();
s
.print_type
(
&
mut_ty
.ty
);
s
.print_type_bounds
(
" +"
,
&
bounds
);
if
!
bounds
.is_empty
()
{
s
.word
(
" + "
);
s
.print_type_bounds
(
&
bounds
);
}
s
.pclose
()
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录