Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
f3a3fc90
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,发现更多精彩内容 >>
未验证
提交
f3a3fc90
编写于
12月 10, 2020
作者:
T
Tyler Mandry
提交者:
GitHub
12月 10, 2020
浏览文件
操作
浏览文件
下载
差异文件
Rollup merge of #79639 - sasurau4:feature/add-long-explanation-E0212, r=GuillaumeGomez
Add long explanation for E0212 Helps with #61137
上级
a8c19e1b
87c62169
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
58 addition
and
20 deletion
+58
-20
compiler/rustc_error_codes/src/error_codes.rs
compiler/rustc_error_codes/src/error_codes.rs
+1
-1
compiler/rustc_error_codes/src/error_codes/E0212.md
compiler/rustc_error_codes/src/error_codes/E0212.md
+35
-0
compiler/rustc_typeck/src/collect.rs
compiler/rustc_typeck/src/collect.rs
+2
-2
src/test/ui/associated-types/associated-types-project-from-hrtb-in-fn.fixed
...ated-types/associated-types-project-from-hrtb-in-fn.fixed
+1
-1
src/test/ui/associated-types/associated-types-project-from-hrtb-in-fn.rs
...ociated-types/associated-types-project-from-hrtb-in-fn.rs
+1
-1
src/test/ui/associated-types/associated-types-project-from-hrtb-in-fn.stderr
...ted-types/associated-types-project-from-hrtb-in-fn.stderr
+2
-1
src/test/ui/associated-types/associated-types-project-from-hrtb-in-struct.rs
...ted-types/associated-types-project-from-hrtb-in-struct.rs
+4
-4
src/test/ui/associated-types/associated-types-project-from-hrtb-in-struct.stderr
...types/associated-types-project-from-hrtb-in-struct.stderr
+5
-4
src/test/ui/associated-types/associated-types-project-from-hrtb-in-trait-method.fixed
.../associated-types-project-from-hrtb-in-trait-method.fixed
+2
-2
src/test/ui/associated-types/associated-types-project-from-hrtb-in-trait-method.rs
...pes/associated-types-project-from-hrtb-in-trait-method.rs
+2
-2
src/test/ui/associated-types/associated-types-project-from-hrtb-in-trait-method.stderr
...associated-types-project-from-hrtb-in-trait-method.stderr
+3
-2
未找到文件。
compiler/rustc_error_codes/src/error_codes.rs
浏览文件 @
f3a3fc90
...
...
@@ -111,6 +111,7 @@
E0207
:
include_str!
(
"./error_codes/E0207.md"
),
E0210
:
include_str!
(
"./error_codes/E0210.md"
),
E0211
:
include_str!
(
"./error_codes/E0211.md"
),
E0212
:
include_str!
(
"./error_codes/E0212.md"
),
E0214
:
include_str!
(
"./error_codes/E0214.md"
),
E0220
:
include_str!
(
"./error_codes/E0220.md"
),
E0221
:
include_str!
(
"./error_codes/E0221.md"
),
...
...
@@ -503,7 +504,6 @@
// E0196, // cannot determine a type for this closure
E0208
,
// E0209, // builtin traits can only be implemented on structs or enums
E0212
,
// cannot extract an associated type from a higher-ranked trait bound
// E0213, // associated types are not accepted in this context
// E0215, // angle-bracket notation is not stable with `Fn`
// E0216, // parenthetical notation is only stable with `Fn`
...
...
compiler/rustc_error_codes/src/error_codes/E0212.md
0 → 100644
浏览文件 @
f3a3fc90
Cannot use the associated type of
a trait with uninferred generic parameters.
Erroneous code example:
```
compile_fail,E0212
pub trait Foo<T> {
type A;
fn get(&self, t: T) -> Self::A;
}
fn foo2<I : for<'x> Foo<&'x isize>>(
field: I::A) {} // error!
```
In this example, we have to instantiate
`'x`
, and
we don't know what lifetime to instantiate it with.
To fix this, spell out the precise lifetimes involved.
Example:
```
pub trait Foo<T> {
type A;
fn get(&self, t: T) -> Self::A;
}
fn foo3<I : for<'x> Foo<&'x isize>>(
x: <I as Foo<&isize>>::A) {} // ok!
fn foo4<'a, I : for<'x> Foo<&'x isize>>(
x: <I as Foo<&'a isize>>::A) {} // ok!
```
compiler/rustc_typeck/src/collect.rs
浏览文件 @
f3a3fc90
...
...
@@ -359,8 +359,8 @@ fn projected_ty_from_poly_trait_ref(
self
.tcx
()
.sess
,
span
,
E0212
,
"cannot
extract an associated type from a higher-ranked trait bound
\
in this context
"
"cannot
use the associated type of a trait
\
with uninferred generic parameters
"
);
match
self
.node
()
{
...
...
src/test/ui/associated-types/associated-types-project-from-hrtb-in-fn.fixed
浏览文件 @
f3a3fc90
...
...
@@ -11,7 +11,7 @@ pub trait Foo<T> {
fn foo2<I : for<'x> Foo<&'x isize>>(
x: <I as Foo<&isize>>::A)
//~^ ERROR cannot
extract an associated type from a higher-ranked trait bound in this context
//~^ ERROR cannot
use the associated type of a trait with uninferred generic parameters
{
// This case is illegal because we have to instantiate `'x`, and
// we don't know what region to instantiate it with.
...
...
src/test/ui/associated-types/associated-types-project-from-hrtb-in-fn.rs
浏览文件 @
f3a3fc90
...
...
@@ -11,7 +11,7 @@ pub trait Foo<T> {
fn
foo2
<
I
:
for
<
'x
>
Foo
<&
'x
isize
>>
(
x
:
I
::
A
)
//~^ ERROR cannot
extract an associated type from a higher-ranked trait bound in this context
//~^ ERROR cannot
use the associated type of a trait with uninferred generic parameters
{
// This case is illegal because we have to instantiate `'x`, and
// we don't know what region to instantiate it with.
...
...
src/test/ui/associated-types/associated-types-project-from-hrtb-in-fn.stderr
浏览文件 @
f3a3fc90
error[E0212]: cannot
extract an associated type from a higher-ranked trait bound in this context
error[E0212]: cannot
use the associated type of a trait with uninferred generic parameters
--> $DIR/associated-types-project-from-hrtb-in-fn.rs:13:8
|
LL | x: I::A)
...
...
@@ -6,3 +6,4 @@ LL | x: I::A)
error: aborting due to previous error
For more information about this error, try `rustc --explain E0212`.
src/test/ui/associated-types/associated-types-project-from-hrtb-in-struct.rs
浏览文件 @
f3a3fc90
...
...
@@ -9,14 +9,14 @@ pub trait Foo<T> {
struct
SomeStruct
<
I
:
for
<
'x
>
Foo
<&
'x
isize
>>
{
field
:
I
::
A
//~^ ERROR cannot
extract an associated type from a higher-ranked trait bound in this context
//~^ ERROR cannot
use the associated type of a trait with uninferred generic parameters
}
enum
SomeEnum
<
'b
,
I
:
for
<
'a
>
Foo
<&
'a
isize
>>
{
TupleVariant
(
I
::
A
),
//~^ ERROR cannot
extract an associated type from a higher-ranked trait bound in this context
//~^ ERROR cannot
use the associated type of a trait with uninferred generic parameters
StructVariant
{
field
:
I
::
A
},
//~^ ERROR cannot
extract an associated type from a higher-ranked trait bound in this context
//~^ ERROR cannot
use the associated type of a trait with uninferred generic parameters
OkVariant
(
&
'b
usize
),
}
...
...
@@ -33,7 +33,7 @@ struct YetAnotherStruct<'a, I: for<'x> Foo<&'x isize>> {
struct
Why
<
'a
,
'b
,
'c
,
'd
,
'e
,
'f
,
'g
,
'h
,
'i
,
'j
,
'k
,
'n
,
'o
,
'p
,
'q
,
'r
,
's
,
't
,
'u
,
'v
,
'w
,
'x
,
'y
,
'z
,
'aa
,
I
:
for
<
'l
,
'm
>
Foo
<&
'l
&
'm
isize
>>
{
field
:
I
::
A
,
//~^ ERROR cannot
extract an associated type from a higher-ranked trait bound in this context
//~^ ERROR cannot
use the associated type of a trait with uninferred generic parameters
}
pub
fn
main
()
{}
src/test/ui/associated-types/associated-types-project-from-hrtb-in-struct.stderr
浏览文件 @
f3a3fc90
error[E0212]: cannot
extract an associated type from a higher-ranked trait bound in this context
error[E0212]: cannot
use the associated type of a trait with uninferred generic parameters
--> $DIR/associated-types-project-from-hrtb-in-struct.rs:11:12
|
LL | field: I::A
...
...
@@ -10,7 +10,7 @@ LL | struct SomeStruct<'a, I: for<'x> Foo<&'x isize>> {
LL | field: <I as Foo<&'a isize>>::A
|
error[E0212]: cannot
extract an associated type from a higher-ranked trait bound in this context
error[E0212]: cannot
use the associated type of a trait with uninferred generic parameters
--> $DIR/associated-types-project-from-hrtb-in-struct.rs:16:18
|
LL | TupleVariant(I::A),
...
...
@@ -22,7 +22,7 @@ LL | enum SomeEnum<'c, 'b, I: for<'a> Foo<&'a isize>> {
LL | TupleVariant(<I as Foo<&'c isize>>::A),
|
error[E0212]: cannot
extract an associated type from a higher-ranked trait bound in this context
error[E0212]: cannot
use the associated type of a trait with uninferred generic parameters
--> $DIR/associated-types-project-from-hrtb-in-struct.rs:18:28
|
LL | StructVariant { field: I::A },
...
...
@@ -36,7 +36,7 @@ LL |
LL | StructVariant { field: <I as Foo<&'c isize>>::A },
|
error[E0212]: cannot
extract an associated type from a higher-ranked trait bound in this context
error[E0212]: cannot
use the associated type of a trait with uninferred generic parameters
--> $DIR/associated-types-project-from-hrtb-in-struct.rs:35:12
|
LL | field: I::A,
...
...
@@ -51,3 +51,4 @@ LL | field: <I as Foo<&'bb &'bb isize>>::A,
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0212`.
src/test/ui/associated-types/associated-types-project-from-hrtb-in-trait-method.fixed
浏览文件 @
f3a3fc90
...
...
@@ -11,7 +11,7 @@ pub trait Foo<T> {
trait SomeTrait<I : for<'x> Foo<&'x isize>> {
fn some_method(&self, arg: <I as Foo<&isize>>::A);
//~^ ERROR cannot
extract an associated type from a higher-ranked trait bound in this context
//~^ ERROR cannot
use the associated type of a trait with uninferred generic parameters
}
trait AnotherTrait<I : for<'x> Foo<&'x isize>> {
...
...
@@ -30,7 +30,7 @@ struct Peach<X>(std::marker::PhantomData<X>);
impl<X: for<'a> Banana<'a>> Peach<X> {
fn mango(&self) -> <X as Banana<'_>>::Assoc {
//~^ ERROR cannot
extract an associated type from a higher-ranked trait bound in this context
//~^ ERROR cannot
use the associated type of a trait with uninferred generic parameters
Default::default()
}
}
...
...
src/test/ui/associated-types/associated-types-project-from-hrtb-in-trait-method.rs
浏览文件 @
f3a3fc90
...
...
@@ -11,7 +11,7 @@ pub trait Foo<T> {
trait
SomeTrait
<
I
:
for
<
'x
>
Foo
<&
'x
isize
>>
{
fn
some_method
(
&
self
,
arg
:
I
::
A
);
//~^ ERROR cannot
extract an associated type from a higher-ranked trait bound in this context
//~^ ERROR cannot
use the associated type of a trait with uninferred generic parameters
}
trait
AnotherTrait
<
I
:
for
<
'x
>
Foo
<&
'x
isize
>>
{
...
...
@@ -30,7 +30,7 @@ trait Banana<'a> {
impl
<
X
:
for
<
'a
>
Banana
<
'a
>>
Peach
<
X
>
{
fn
mango
(
&
self
)
->
X
::
Assoc
{
//~^ ERROR cannot
extract an associated type from a higher-ranked trait bound in this context
//~^ ERROR cannot
use the associated type of a trait with uninferred generic parameters
Default
::
default
()
}
}
...
...
src/test/ui/associated-types/associated-types-project-from-hrtb-in-trait-method.stderr
浏览文件 @
f3a3fc90
error[E0212]: cannot
extract an associated type from a higher-ranked trait bound in this context
error[E0212]: cannot
use the associated type of a trait with uninferred generic parameters
--> $DIR/associated-types-project-from-hrtb-in-trait-method.rs:13:32
|
LL | fn some_method(&self, arg: I::A);
| ^^^^ help: use a fully qualified path with inferred lifetimes: `<I as Foo<&isize>>::A`
error[E0212]: cannot
extract an associated type from a higher-ranked trait bound in this context
error[E0212]: cannot
use the associated type of a trait with uninferred generic parameters
--> $DIR/associated-types-project-from-hrtb-in-trait-method.rs:32:24
|
LL | fn mango(&self) -> X::Assoc {
...
...
@@ -12,3 +12,4 @@ LL | fn mango(&self) -> X::Assoc {
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0212`.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录