Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
2b151fd5
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,发现更多精彩内容 >>
提交
2b151fd5
编写于
2月 14, 2022
作者:
J
Jack Huey
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Review changes
上级
c920eb88
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
130 addition
and
50 deletion
+130
-50
compiler/rustc_ast/src/ast.rs
compiler/rustc_ast/src/ast.rs
+12
-0
compiler/rustc_ast_passes/src/ast_validation.rs
compiler/rustc_ast_passes/src/ast_validation.rs
+6
-2
compiler/rustc_lint/src/context.rs
compiler/rustc_lint/src/context.rs
+6
-4
src/test/ui/parser/type-alias-where-fixable.fixed
src/test/ui/parser/type-alias-where-fixable.fixed
+30
-0
src/test/ui/parser/type-alias-where-fixable.rs
src/test/ui/parser/type-alias-where-fixable.rs
+30
-0
src/test/ui/parser/type-alias-where-fixable.stderr
src/test/ui/parser/type-alias-where-fixable.stderr
+42
-0
src/test/ui/parser/type-alias-where.rs
src/test/ui/parser/type-alias-where.rs
+0
-24
src/test/ui/parser/type-alias-where.stderr
src/test/ui/parser/type-alias-where.stderr
+4
-20
未找到文件。
compiler/rustc_ast/src/ast.rs
浏览文件 @
2b151fd5
...
...
@@ -2666,6 +2666,18 @@ pub struct Trait {
/// a `where` keyword (`bool`). This is split out from `WhereClause`, since there
/// are two locations for where clause on type aliases, but their predicates
/// are concatenated together.
///
/// Take this example:
/// ```rust, ignore
/// trait Foo {
/// type Assoc<'a, 'b> where Self: 'a, Self: 'b;
/// }
/// impl Foo for () {
/// type Assoc<'a, 'b> where Self: 'a = () where Self: 'b;
/// // ^^^^^^^^^^^^^^ first where clause
/// // ^^^^^^^^^^^^^^ second where clause
/// }
/// ```
#[derive(Copy,
Clone,
Encodable,
Decodable,
Debug,
Default)]
pub
struct
TyAliasWhereClause
(
pub
bool
,
pub
Span
);
...
...
compiler/rustc_ast_passes/src/ast_validation.rs
浏览文件 @
2b151fd5
...
...
@@ -1275,10 +1275,14 @@ fn visit_item(&mut self, item: &'a Item) {
}
self
.check_type_no_bounds
(
bounds
,
"this context"
);
if
where_clauses
.1.0
{
self
.err_handler
()
.
span_err
(
let
mut
err
=
self
.err_handler
()
.struct_
span_err
(
where_clauses
.1.1
,
"where clauses are not allowed after the type for type aliases"
,
)
);
err
.note
(
"see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information"
,
);
err
.emit
();
}
}
_
=>
{}
...
...
compiler/rustc_lint/src/context.rs
浏览文件 @
2b151fd5
...
...
@@ -819,12 +819,14 @@ fn lookup_with_diagnostics(
}
},
BuiltinLintDiagnostics
::
DeprecatedWhereclauseLocation
(
new_span
,
suggestion
)
=>
{
db
.span_suggestion
(
new_span
,
"move it here"
,
suggestion
,
db
.multipart_suggestion
(
"move it to the end of the type declaration"
,
vec!
[(
db
.span
.primary_span
()
.unwrap
(),
""
.to_string
()),
(
new_span
,
suggestion
)],
Applicability
::
MachineApplicable
,
);
db
.note
(
"see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information"
,
);
},
}
// Rewrap `db`, and pass control to the user.
...
...
src/test/ui/parser/type-alias-where-fixable.fixed
0 → 100644
浏览文件 @
2b151fd5
// check-pass
// run-rustfix
#![feature(generic_associated_types)]
trait Trait {
// Fine.
type Assoc where u32: Copy;
// Fine.
type Assoc2 where u32: Copy, i32: Copy;
}
impl Trait for u32 {
// Not fine, suggests moving.
type Assoc = () where u32: Copy;
//~^ WARNING where clause not allowed here
// Not fine, suggests moving `u32: Copy`
type Assoc2 = () where i32: Copy, u32: Copy;
//~^ WARNING where clause not allowed here
}
impl Trait for i32 {
// Fine.
type Assoc = () where u32: Copy;
// Not fine, suggests moving both.
type Assoc2 = () where u32: Copy, i32: Copy;
//~^ WARNING where clause not allowed here
}
fn main() {}
src/test/ui/parser/type-alias-where-fixable.rs
0 → 100644
浏览文件 @
2b151fd5
// check-pass
// run-rustfix
#![feature(generic_associated_types)]
trait
Trait
{
// Fine.
type
Assoc
where
u32
:
Copy
;
// Fine.
type
Assoc2
where
u32
:
Copy
,
i32
:
Copy
;
}
impl
Trait
for
u32
{
// Not fine, suggests moving.
type
Assoc
where
u32
:
Copy
=
();
//~^ WARNING where clause not allowed here
// Not fine, suggests moving `u32: Copy`
type
Assoc2
where
u32
:
Copy
=
()
where
i32
:
Copy
;
//~^ WARNING where clause not allowed here
}
impl
Trait
for
i32
{
// Fine.
type
Assoc
=
()
where
u32
:
Copy
;
// Not fine, suggests moving both.
type
Assoc2
where
u32
:
Copy
,
i32
:
Copy
=
();
//~^ WARNING where clause not allowed here
}
fn
main
()
{}
src/test/ui/parser/type-alias-where-fixable.stderr
0 → 100644
浏览文件 @
2b151fd5
warning: where clause not allowed here
--> $DIR/type-alias-where-fixable.rs:15:16
|
LL | type Assoc where u32: Copy = ();
| ^^^^^^^^^^^^^^^
|
= note: `#[warn(deprecated_where_clause_location)]` on by default
= 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 - type Assoc where u32: Copy = ();
LL + type Assoc = () where u32: Copy;
|
warning: where clause not allowed here
--> $DIR/type-alias-where-fixable.rs:18:17
|
LL | type Assoc2 where u32: Copy = () where i32: Copy;
| ^^^^^^^^^^^^^^^
|
= 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 - type Assoc2 where u32: Copy = () where i32: Copy;
LL + type Assoc2 = () where i32: Copy, u32: Copy;
|
warning: where clause not allowed here
--> $DIR/type-alias-where-fixable.rs:26:17
|
LL | type Assoc2 where u32: Copy, i32: Copy = ();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= 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 - type Assoc2 where u32: Copy, i32: Copy = ();
LL + type Assoc2 = () where u32: Copy, i32: Copy;
|
warning: 3 warnings emitted
src/test/ui/parser/type-alias-where.rs
浏览文件 @
2b151fd5
...
...
@@ -10,28 +10,4 @@
type
Baz
=
()
where
;
//~^ ERROR where clauses are not allowed
trait
Trait
{
// Fine.
type
Assoc
where
u32
:
Copy
;
// Fine.
type
Assoc2
where
u32
:
Copy
,
i32
:
Copy
;
}
impl
Trait
for
u32
{
// Not fine, suggests moving.
type
Assoc
where
u32
:
Copy
=
();
//~^ WARNING where clause not allowed here
// Not fine, suggests moving `u32: Copy`
type
Assoc2
where
u32
:
Copy
=
()
where
i32
:
Copy
;
//~^ WARNING where clause not allowed here
}
impl
Trait
for
i32
{
// Fine.
type
Assoc
=
()
where
u32
:
Copy
;
// Not fine, suggests moving both.
type
Assoc2
where
u32
:
Copy
,
i32
:
Copy
=
();
//~^ WARNING where clause not allowed here
}
fn
main
()
{}
src/test/ui/parser/type-alias-where.stderr
浏览文件 @
2b151fd5
...
...
@@ -3,32 +3,16 @@ 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
error: where clauses are not allowed after the type for type aliases
--> $DIR/type-alias-where.rs:10:15
|
LL | type Baz = () where;
| ^^^^^
warning: where clause not allowed here
--> $DIR/type-alias-where.rs:22:16
|
LL | type Assoc where u32: Copy = ();
| ^^^^^^^^^^^^^^^ - help: move it here: `where u32: Copy`
|
= note: `#[warn(deprecated_where_clause_location)]` on by default
warning: where clause not allowed here
--> $DIR/type-alias-where.rs:25:17
|
LL | type Assoc2 where u32: Copy = () where i32: Copy;
| ^^^^^^^^^^^^^^^ - help: move it here: `, u32: Copy`
warning: where clause not allowed here
--> $DIR/type-alias-where.rs:33:17
|
LL | type Assoc2 where u32: Copy, i32: Copy = ();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ - help: move it here: `where u32: Copy, i32: Copy`
= note: see issue #89122 <https://github.com/rust-lang/rust/issues/89122> for more information
error: aborting due to 2 previous errors
; 3 warnings emitted
error: aborting due to 2 previous errors
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录