Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
051eb7ca
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
未验证
提交
051eb7ca
编写于
8月 09, 2023
作者:
L
León Orell Valerian Liehr
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Unlock trailing where-clauses for lazy type aliases
上级
617821ab
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
175 addition
and
49 deletion
+175
-49
compiler/rustc_ast_passes/messages.ftl
compiler/rustc_ast_passes/messages.ftl
+6
-1
compiler/rustc_ast_passes/src/ast_validation.rs
compiler/rustc_ast_passes/src/ast_validation.rs
+55
-44
compiler/rustc_ast_passes/src/errors.rs
compiler/rustc_ast_passes/src/errors.rs
+28
-2
tests/ui/lazy-type-alias/leading-where-clause.fixed
tests/ui/lazy-type-alias/leading-where-clause.fixed
+15
-0
tests/ui/lazy-type-alias/leading-where-clause.rs
tests/ui/lazy-type-alias/leading-where-clause.rs
+16
-0
tests/ui/lazy-type-alias/leading-where-clause.stderr
tests/ui/lazy-type-alias/leading-where-clause.stderr
+16
-0
tests/ui/lazy-type-alias/trailing-where-clause.rs
tests/ui/lazy-type-alias/trailing-where-clause.rs
+13
-0
tests/ui/lazy-type-alias/trailing-where-clause.stderr
tests/ui/lazy-type-alias/trailing-where-clause.stderr
+22
-0
tests/ui/where-clauses/where-clause-placement-type-alias.stderr
...ui/where-clauses/where-clause-placement-type-alias.stderr
+4
-2
未找到文件。
compiler/rustc_ast_passes/messages.ftl
浏览文件 @
051eb7ca
...
...
@@ -239,5 +239,10 @@ ast_passes_visibility_not_permitted =
.individual_impl_items = place qualifiers on individual impl items instead
.individual_foreign_items = place qualifiers on individual foreign items instead
ast_passes_where_after_type_alias = where clauses are not allowed after the type for type aliases
ast_passes_where_clause_after_type_alias = where clauses are not allowed after the type for type aliases
.note = see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information
.help = add `#![feature(lazy_type_alias)]` to the crate attributes to enable
ast_passes_where_clause_before_type_alias = where clauses are not allowed before the type for type aliases
.note = see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
.suggestion = move it to the end of the type declaration
compiler/rustc_ast_passes/src/ast_validation.rs
浏览文件 @
051eb7ca
...
...
@@ -136,40 +136,42 @@ fn ban_let_expr(&self, expr: &'a Expr, forbidden_let_reason: ForbiddenLetReason)
}
}
fn
check_
gat_where
(
fn
check_
type_alias_where_clause_location
(
&
mut
self
,
id
:
NodeId
,
before_predicates
:
&
[
WherePredicate
],
where_clauses
:
(
ast
::
TyAliasWhereClause
,
ast
::
TyAliasWhereClause
),
)
{
if
!
before_predicates
.is_empty
()
{
let
mut
state
=
State
::
new
();
if
!
where_clauses
.1.0
{
state
.space
();
state
.word_space
(
"where"
);
}
else
{
ty_alias
:
&
TyAlias
,
)
->
Result
<
(),
errors
::
WhereClauseBeforeTypeAlias
>
{
let
before_predicates
=
ty_alias
.generics.where_clause.predicates
.split_at
(
ty_alias
.where_predicates_split
)
.0
;
if
ty_alias
.ty
.is_none
()
||
before_predicates
.is_empty
()
{
return
Ok
(());
}
let
mut
state
=
State
::
new
();
if
!
ty_alias
.where_clauses
.1.0
{
state
.space
();
state
.word_space
(
"where"
);
}
else
{
state
.word_space
(
","
);
}
let
mut
first
=
true
;
for
p
in
before_predicates
{
if
!
first
{
state
.word_space
(
","
);
}
let
mut
first
=
true
;
for
p
in
before_predicates
.iter
()
{
if
!
first
{
state
.word_space
(
","
);
}
first
=
false
;
state
.print_where_predicate
(
p
);
}
let
suggestion
=
state
.s
.eof
();
self
.lint_buffer
.buffer_lint_with_diagnostic
(
DEPRECATED_WHERE_CLAUSE_LOCATION
,
id
,
where_clauses
.0.1
,
fluent
::
ast_passes_deprecated_where_clause_location
,
BuiltinLintDiagnostics
::
DeprecatedWhereclauseLocation
(
where_clauses
.1.1
.shrink_to_hi
(),
suggestion
,
),
);
first
=
false
;
state
.print_where_predicate
(
p
);
}
let
span
=
ty_alias
.where_clauses
.0.1
;
Err
(
errors
::
WhereClauseBeforeTypeAlias
{
span
,
sugg
:
errors
::
WhereClauseBeforeTypeAliasSugg
{
left
:
span
,
snippet
:
state
.s
.eof
(),
right
:
ty_alias
.where_clauses
.1.1
.shrink_to_hi
(),
},
})
}
fn
with_impl_trait
(
&
mut
self
,
outer
:
Option
<
Span
>
,
f
:
impl
FnOnce
(
&
mut
Self
))
{
...
...
@@ -1009,7 +1011,9 @@ fn visit_item(&mut self, item: &'a Item) {
replace_span
:
self
.ending_semi_or_hi
(
item
.span
),
});
}
ItemKind
::
TyAlias
(
box
TyAlias
{
defaultness
,
where_clauses
,
bounds
,
ty
,
..
})
=>
{
ItemKind
::
TyAlias
(
ty_alias
@
box
TyAlias
{
defaultness
,
bounds
,
where_clauses
,
ty
,
..
},
)
=>
{
self
.check_defaultness
(
item
.span
,
*
defaultness
);
if
ty
.is_none
()
{
self
.session
.emit_err
(
errors
::
TyAliasWithoutBody
{
...
...
@@ -1018,9 +1022,16 @@ fn visit_item(&mut self, item: &'a Item) {
});
}
self
.check_type_no_bounds
(
bounds
,
"this context"
);
if
where_clauses
.1.0
{
self
.err_handler
()
.emit_err
(
errors
::
WhereAfterTypeAlias
{
span
:
where_clauses
.1.1
});
if
self
.session
.features_untracked
()
.lazy_type_alias
{
if
let
Err
(
err
)
=
self
.check_type_alias_where_clause_location
(
ty_alias
)
{
self
.err_handler
()
.emit_err
(
err
);
}
}
else
if
where_clauses
.1.0
{
self
.err_handler
()
.emit_err
(
errors
::
WhereClauseAfterTypeAlias
{
span
:
where_clauses
.1.1
,
help
:
self
.session
.is_nightly_build
()
.then_some
(()),
});
}
}
_
=>
{}
...
...
@@ -1313,18 +1324,18 @@ fn visit_assoc_item(&mut self, item: &'a AssocItem, ctxt: AssocCtxt) {
}
}
if
let
AssocItemKind
::
Type
(
box
TyAlias
{
generics
,
where_clauses
,
where_predicates_split
,
ty
:
Some
(
_
),
..
})
=
&
item
.kind
if
let
AssocItemKind
::
Type
(
ty_alias
)
=
&
item
.kind
&&
let
Err
(
err
)
=
self
.check_type_alias_where_clause_location
(
ty_alias
)
{
self
.check_gat_where
(
self
.lint_buffer
.buffer_lint_with_diagnostic
(
DEPRECATED_WHERE_CLAUSE_LOCATION
,
item
.id
,
generics
.where_clause.predicates
.split_at
(
*
where_predicates_split
)
.0
,
*
where_clauses
,
err
.span
,
fluent
::
ast_passes_deprecated_where_clause_location
,
BuiltinLintDiagnostics
::
DeprecatedWhereclauseLocation
(
err
.sugg.right
,
err
.sugg.snippet
,
),
);
}
...
...
compiler/rustc_ast_passes/src/errors.rs
浏览文件 @
051eb7ca
...
...
@@ -496,11 +496,37 @@ pub struct FieldlessUnion {
}
#[derive(Diagnostic)]
#[diag(ast_passes_where_after_type_alias)]
#[diag(ast_passes_where_
clause_
after_type_alias)]
#[note]
pub
struct
WhereAfterTypeAlias
{
pub
struct
Where
Clause
AfterTypeAlias
{
#[primary_span]
pub
span
:
Span
,
#[help]
pub
help
:
Option
<
()
>
,
}
#[derive(Diagnostic)]
#[diag(ast_passes_where_clause_before_type_alias)]
#[note]
pub
struct
WhereClauseBeforeTypeAlias
{
#[primary_span]
pub
span
:
Span
,
#[subdiagnostic]
pub
sugg
:
WhereClauseBeforeTypeAliasSugg
,
}
#[derive(Subdiagnostic)]
#[multipart_suggestion(
ast_passes_suggestion,
applicability
=
"machine-applicable"
,
style
=
"verbose"
)]
pub
struct
WhereClauseBeforeTypeAliasSugg
{
#[suggestion_part(code
=
""
)]
pub
left
:
Span
,
pub
snippet
:
String
,
#[suggestion_part(code
=
"{snippet}"
)]
pub
right
:
Span
,
}
#[derive(Diagnostic)]
...
...
tests/ui/lazy-type-alias/leading-where-clause.fixed
0 → 100644
浏览文件 @
051eb7ca
// run-rustfix
#![feature(lazy_type_alias)]
#![allow(incomplete_features)]
// Check that we *reject* leading where-clauses on lazy type aliases.
type Alias<T>
= T where String: From<T>;
//~^^^ ERROR where clauses are not allowed before the type for type aliases
fn main() {
let _: Alias<&str>;
}
tests/ui/lazy-type-alias/leading-where-clause.rs
0 → 100644
浏览文件 @
051eb7ca
// run-rustfix
#![feature(lazy_type_alias)]
#![allow(incomplete_features)]
// Check that we *reject* leading where-clauses on lazy type aliases.
type
Alias
<
T
>
where
String
:
From
<
T
>
,
=
T
;
//~^^^ ERROR where clauses are not allowed before the type for type aliases
fn
main
()
{
let
_
:
Alias
<&
str
>
;
}
tests/ui/lazy-type-alias/leading-where-clause.stderr
0 → 100644
浏览文件 @
051eb7ca
error: where clauses are not allowed before the type for type aliases
--> $DIR/leading-where-clause.rs:9:1
|
LL | / where
LL | | String: From<T>,
| |____________________^
|
= note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
help: move it to the end of the type declaration
|
LL +
LL ~ = T where String: From<T>;
|
error: aborting due to previous error
tests/ui/lazy-type-alias/trailing-where-clause.rs
0 → 100644
浏览文件 @
051eb7ca
#![feature(lazy_type_alias)]
#![allow(incomplete_features)]
// Check that we allow & respect trailing where-clauses on lazy type aliases.
type
Alias
<
T
>
=
T
where
String
:
From
<
T
>
;
fn
main
()
{
let
_
:
Alias
<&
str
>
;
let
_
:
Alias
<
()
>
;
//~ ERROR the trait bound `String: From<()>` is not satisfied
}
tests/ui/lazy-type-alias/trailing-where-clause.stderr
0 → 100644
浏览文件 @
051eb7ca
error[E0277]: the trait bound `String: From<()>` is not satisfied
--> $DIR/trailing-where-clause.rs:12:12
|
LL | let _: Alias<()>;
| ^^^^^^^^^ the trait `From<()>` is not implemented for `String`
|
= help: the following other types implement trait `From<T>`:
<String as From<char>>
<String as From<Box<str>>>
<String as From<Cow<'a, str>>>
<String as From<&str>>
<String as From<&mut str>>
<String as From<&String>>
note: required by a bound on the type alias `Alias`
--> $DIR/trailing-where-clause.rs:8:13
|
LL | String: From<T>;
| ^^^^^^^ required by this bound
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
tests/ui/where-clauses/where-clause-placement-type-alias.stderr
浏览文件 @
051eb7ca
...
...
@@ -4,7 +4,8 @@ error: where clauses are not allowed after the type for type aliases
LL | type Bar = () where u32: Copy;
| ^^^^^^^^^^^^^^^
|
= note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
= note: see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information
= help: add `#![feature(lazy_type_alias)]` to the crate attributes to enable
error: where clauses are not allowed after the type for type aliases
--> $DIR/where-clause-placement-type-alias.rs:8:15
...
...
@@ -12,7 +13,8 @@ error: where clauses are not allowed after the type for type aliases
LL | type Baz = () where;
| ^^^^^
|
= note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
= note: see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information
= help: add `#![feature(lazy_type_alias)]` to the crate attributes to enable
error: aborting due to 2 previous errors
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录