Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
6c8b2dcb
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,发现更多精彩内容 >>
提交
6c8b2dcb
编写于
12月 24, 2019
作者:
E
Esteban Küber
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Account for all item kinds when collecting and gateing `_` in item defs
上级
8cb193a5
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
199 addition
and
150 deletion
+199
-150
src/librustc_typeck/astconv.rs
src/librustc_typeck/astconv.rs
+16
-51
src/librustc_typeck/collect.rs
src/librustc_typeck/collect.rs
+93
-3
src/test/ui/self/self-infer.stderr
src/test/ui/self/self-infer.stderr
+2
-2
src/test/ui/typeck/typeck_type_placeholder_item.rs
src/test/ui/typeck/typeck_type_placeholder_item.rs
+0
-6
src/test/ui/typeck/typeck_type_placeholder_item.stderr
src/test/ui/typeck/typeck_type_placeholder_item.stderr
+88
-88
未找到文件。
src/librustc_typeck/astconv.rs
浏览文件 @
6c8b2dcb
...
...
@@ -7,7 +7,7 @@
use
crate
::
hir
::
print
;
use
crate
::
hir
::
ptr
::
P
;
use
crate
::
hir
::{
self
,
ExprKind
,
GenericArg
,
GenericArgs
,
HirVec
};
use
crate
::
hir
::
intravisit
::
{
NestedVisitorMap
,
Visitor
}
;
use
crate
::
hir
::
intravisit
::
Visitor
;
use
crate
::
lint
;
use
crate
::
middle
::
lang_items
::
SizedTraitLangItem
;
use
crate
::
middle
::
resolve_lifetime
as
rl
;
...
...
@@ -16,6 +16,7 @@
use
crate
::
util
::
common
::
ErrorReported
;
use
crate
::
util
::
nodemap
::
FxHashMap
;
use
errors
::{
Applicability
,
DiagnosticId
};
use
crate
::
collect
::
PlaceholderHirTyCollector
;
use
rustc
::
lint
::
builtin
::
AMBIGUOUS_ASSOCIATED_ITEMS
;
use
rustc
::
traits
;
use
rustc
::
ty
::
subst
::{
self
,
InternalSubsts
,
Subst
,
SubstsRef
};
...
...
@@ -2747,12 +2748,11 @@ pub fn impl_trait_ty_to_ty(
}
pub
fn
ty_of_arg
(
&
self
,
ty
:
&
hir
::
Ty
<
'_
>
,
expected_ty
:
Option
<
Ty
<
'tcx
>>
)
->
Ty
<
'tcx
>
{
match
ty
.kind
{
hir
::
TyKind
::
Infer
if
expected_ty
.is_some
()
=>
{
self
.record_ty
(
ty
.hir_id
,
expected_ty
.unwrap
(),
ty
.span
);
expected_ty
.unwrap
()
}
_
=>
self
.ast_ty_to_ty
(
ty
),
if
crate
::
collect
::
is_infer_ty
(
ty
)
&&
expected_ty
.is_some
()
{
self
.record_ty
(
ty
.hir_id
,
expected_ty
.unwrap
(),
ty
.span
);
expected_ty
.unwrap
()
}
else
{
self
.ast_ty_to_ty
(
ty
)
}
}
...
...
@@ -2769,23 +2769,11 @@ pub fn ty_of_fn(
let
tcx
=
self
.tcx
();
// We proactively collect all the infered type params to emit a single error per fn def.
struct
PlaceholderHirTyCollector
(
Vec
<
Span
>
);
impl
<
'v
>
Visitor
<
'v
>
for
PlaceholderHirTyCollector
{
fn
nested_visit_map
<
'this
>
(
&
'this
mut
self
)
->
NestedVisitorMap
<
'this
,
'v
>
{
NestedVisitorMap
::
None
}
fn
visit_ty
(
&
mut
self
,
t
:
&
'v
hir
::
Ty
<
'v
>
)
{
if
let
hir
::
TyKind
::
Infer
=
t
.kind
{
self
.0
.push
(
t
.span
);
}
hir
::
intravisit
::
walk_ty
(
self
,
t
)
}
}
let
mut
placeholder_types
=
vec!
[];
let
mut
output_placeholder_types
=
vec!
[];
let
input_tys
=
decl
.inputs
.iter
()
.map
(|
a
|
{
let
mut
visitor
=
PlaceholderHirTyCollector
(
vec!
[]
);
let
mut
visitor
=
PlaceholderHirTyCollector
::
new
(
);
visitor
.visit_ty
(
&
a
);
if
visitor
.0
.is_empty
()
||
self
.allow_ty_infer
()
{
self
.ty_of_arg
(
a
,
None
)
...
...
@@ -2796,7 +2784,7 @@ fn visit_ty(&mut self, t: &'v hir::Ty<'v>) {
});
let
output_ty
=
match
decl
.output
{
hir
::
Return
(
ref
output
)
=>
{
let
mut
visitor
=
PlaceholderHirTyCollector
(
vec!
[]
);
let
mut
visitor
=
PlaceholderHirTyCollector
::
new
(
);
visitor
.visit_ty
(
output
);
let
is_infer
=
if
let
hir
::
TyKind
::
Infer
=
output
.kind
{
true
...
...
@@ -2820,36 +2808,13 @@ fn visit_ty(&mut self, t: &'v hir::Ty<'v>) {
placeholder_types
.extend
(
output_placeholder_types
);
if
!
placeholder_types
.is_empty
()
{
let
mut
sugg
=
placeholder_types
.iter
()
.cloned
()
.map
(|
sp
|
(
sp
,
"T"
.to_owned
()))
.collect
::
<
Vec
<
_
>>
();
if
let
Some
(
span
)
=
ident_span
{
if
generic_params
.is_empty
()
{
sugg
.push
((
span
.shrink_to_hi
(),
"<T>"
.to_string
()));
}
else
{
sugg
.push
((
generic_params
.iter
()
.last
()
.unwrap
()
.span
.shrink_to_hi
(),
", T"
.to_string
(),
));
}
}
let
mut
err
=
struct_span_err!
(
tcx
.sess
,
placeholder_types
,
E0121
,
"the type placeholder `_` is not allowed within types on item signatures"
,
);
if
ident_span
.is_some
()
{
err
.multipart_suggestion
(
"use type parameters instead"
,
sugg
,
Applicability
::
HasPlaceholders
,
);
}
err
.emit
();
}
crate
::
collect
::
placeholder_type_error
(
tcx
,
ident_span
.unwrap_or
(
DUMMY_SP
),
generic_params
,
placeholder_types
,
ident_span
.is_some
(),
);
// Find any late-bound regions declared in return type that do
// not appear in the arguments. These are not well-formed.
...
...
src/librustc_typeck/collect.rs
浏览文件 @
6c8b2dcb
...
...
@@ -102,10 +102,88 @@ pub struct ItemCtxt<'tcx> {
///////////////////////////////////////////////////////////////////////////
crate
struct
PlaceholderHirTyCollector
(
crate
Vec
<
Span
>
);
impl
<
'v
>
Visitor
<
'v
>
for
PlaceholderHirTyCollector
{
fn
nested_visit_map
<
'this
>
(
&
'this
mut
self
)
->
NestedVisitorMap
<
'this
,
'v
>
{
NestedVisitorMap
::
None
}
fn
visit_ty
(
&
mut
self
,
t
:
&
'v
hir
::
Ty
<
'v
>
)
{
if
let
hir
::
TyKind
::
Infer
=
t
.kind
{
self
.0
.push
(
t
.span
);
}
hir
::
intravisit
::
walk_ty
(
self
,
t
)
}
}
impl
PlaceholderHirTyCollector
{
pub
fn
new
()
->
PlaceholderHirTyCollector
{
PlaceholderHirTyCollector
(
vec!
[])
}
}
struct
CollectItemTypesVisitor
<
'tcx
>
{
tcx
:
TyCtxt
<
'tcx
>
,
}
crate
fn
placeholder_type_error
(
tcx
:
TyCtxt
<
'tcx
>
,
ident_span
:
Span
,
generics
:
&
[
hir
::
GenericParam
<
'_
>
],
placeholder_types
:
Vec
<
Span
>
,
suggest
:
bool
,
)
{
if
!
placeholder_types
.is_empty
()
{
let
mut
sugg
:
Vec
<
_
>
=
placeholder_types
.iter
()
.map
(|
sp
|
(
*
sp
,
"T"
.to_string
()))
.collect
();
if
generics
.is_empty
()
{
sugg
.push
((
ident_span
.shrink_to_hi
(),
"<T>"
.to_string
()));
}
else
{
sugg
.push
((
generics
.iter
()
.last
()
.unwrap
()
.span
.shrink_to_hi
(),
", T"
.to_string
()));
}
let
mut
err
=
struct_span_err!
(
tcx
.sess
,
placeholder_types
.clone
(),
E0121
,
"the type placeholder `_` is not allowed within types on item signatures"
,
);
for
span
in
&
placeholder_types
{
err
.span_label
(
*
span
,
"not allowed in type signatures"
);
}
if
suggest
{
err
.multipart_suggestion
(
"use type parameters instead"
,
sugg
,
Applicability
::
HasPlaceholders
,
);
}
err
.emit
();
}
}
fn
reject_placeholder_type_signatures_in_item
(
tcx
:
TyCtxt
<
'tcx
>
,
item
:
&
'tcx
hir
::
Item
<
'tcx
>
)
{
let
(
generics
,
suggest
)
=
match
&
item
.kind
{
hir
::
ItemKind
::
Union
(
_
,
generics
)
|
hir
::
ItemKind
::
Enum
(
_
,
generics
)
|
hir
::
ItemKind
::
Struct
(
_
,
generics
)
=>
(
&
generics
.params
[
..
],
true
),
hir
::
ItemKind
::
Static
(
ty
,
..
)
=>
{
if
let
hir
::
TyKind
::
Infer
=
ty
.kind
{
return
;
// We handle it elsewhere to attempt to suggest an appropriate type.
}
else
{
(
&
[][
..
],
false
)
}
}
hir
::
ItemKind
::
TyAlias
(
_
,
generics
)
=>
(
&
generics
.params
[
..
],
false
),
// hir::ItemKind::Fn(..) |
// hir::ItemKind::Const(..) => {} // We handle these elsewhere to suggest appropriate type.
_
=>
return
,
};
let
mut
visitor
=
PlaceholderHirTyCollector
::
new
();
visitor
.visit_item
(
item
);
placeholder_type_error
(
tcx
,
item
.ident.span
,
generics
,
visitor
.0
,
suggest
);
}
impl
Visitor
<
'tcx
>
for
CollectItemTypesVisitor
<
'tcx
>
{
fn
nested_visit_map
<
'this
>
(
&
'this
mut
self
)
->
NestedVisitorMap
<
'this
,
'tcx
>
{
NestedVisitorMap
::
OnlyBodies
(
&
self
.tcx
.hir
())
...
...
@@ -113,6 +191,7 @@ fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'tcx> {
fn
visit_item
(
&
mut
self
,
item
:
&
'tcx
hir
::
Item
<
'tcx
>
)
{
convert_item
(
self
.tcx
,
item
.hir_id
);
reject_placeholder_type_signatures_in_item
(
self
.tcx
,
item
);
intravisit
::
walk_item
(
self
,
item
);
}
...
...
@@ -200,8 +279,7 @@ fn allow_ty_infer(&self) -> bool {
}
fn
ty_infer
(
&
self
,
_
:
Option
<&
ty
::
GenericParamDef
>
,
span
:
Span
)
->
Ty
<
'tcx
>
{
bad_placeholder_type
(
self
.tcx
(),
span
)
.emit
();
self
.tcx
()
.sess
.delay_span_bug
(
span
,
"bad placeholder type, but no error was emitted"
);
self
.tcx
()
.types.err
}
...
...
@@ -1189,6 +1267,10 @@ fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
.and_then
(|
body_id
|
{
if
let
hir
::
TyKind
::
Infer
=
ty
.kind
{
Some
(
infer_placeholder_type
(
tcx
,
def_id
,
body_id
,
ty
.span
,
item
.ident
))
}
else
if
is_infer_ty
(
ty
)
{
// Infering this would cause a cycle error.
tcx
.sess
.delay_span_bug
(
ty
.span
,
"`_` placeholder but no error emitted"
);
Some
(
tcx
.types.err
)
}
else
{
None
}
...
...
@@ -1208,6 +1290,10 @@ fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
ImplItemKind
::
Const
(
ref
ty
,
body_id
)
=>
{
if
let
hir
::
TyKind
::
Infer
=
ty
.kind
{
infer_placeholder_type
(
tcx
,
def_id
,
body_id
,
ty
.span
,
item
.ident
)
}
else
if
is_infer_ty
(
ty
)
{
// Infering this would cause a cycle error.
tcx
.sess
.delay_span_bug
(
ty
.span
,
"`_` placeholder but no error emitted"
);
tcx
.types.err
}
else
{
icx
.to_ty
(
ty
)
}
...
...
@@ -1233,6 +1319,10 @@ fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> {
ItemKind
::
Static
(
ref
ty
,
..
,
body_id
)
|
ItemKind
::
Const
(
ref
ty
,
body_id
)
=>
{
if
let
hir
::
TyKind
::
Infer
=
ty
.kind
{
infer_placeholder_type
(
tcx
,
def_id
,
body_id
,
ty
.span
,
item
.ident
)
}
else
if
is_infer_ty
(
ty
)
{
// Infering this would cause a cycle error.
tcx
.sess
.delay_span_bug
(
ty
.span
,
"`_` placeholder but no error emitted"
);
tcx
.types.err
}
else
{
icx
.to_ty
(
ty
)
}
...
...
@@ -1703,7 +1793,7 @@ fn visit_trait_item(&mut self, it: &'tcx TraitItem<'tcx>) {
}
}
fn
is_infer_ty
(
ty
:
&
hir
::
Ty
<
'_
>
)
->
bool
{
crate
fn
is_infer_ty
(
ty
:
&
hir
::
Ty
<
'_
>
)
->
bool
{
match
&
ty
.kind
{
hir
::
TyKind
::
Infer
=>
true
,
hir
::
TyKind
::
Slice
(
ty
)
|
hir
::
TyKind
::
Array
(
ty
,
_
)
=>
is_infer_ty
(
ty
),
...
...
src/test/ui/self/self-infer.stderr
浏览文件 @
6c8b2dcb
...
...
@@ -2,7 +2,7 @@ error[E0121]: the type placeholder `_` is not allowed within types on item signa
--> $DIR/self-infer.rs:4:16
|
LL | fn f(self: _) {}
| ^
| ^
not allowed in type signatures
|
help: use type parameters instead
|
...
...
@@ -13,7 +13,7 @@ error[E0121]: the type placeholder `_` is not allowed within types on item signa
--> $DIR/self-infer.rs:5:17
|
LL | fn g(self: &_) {}
| ^
| ^
not allowed in type signatures
|
help: use type parameters instead
|
...
...
src/test/ui/typeck/typeck_type_placeholder_item.rs
浏览文件 @
6c8b2dcb
...
...
@@ -15,7 +15,6 @@ fn test2() -> (_, _) { (5, 5) }
static
TEST5
:
(
_
,
_
)
=
(
1
,
2
);
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~^^ ERROR the type placeholder `_` is not allowed within types on item signatures
fn
test6
(
_
:
_
)
{
}
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
...
...
@@ -48,8 +47,6 @@ struct Test10 {
a
:
_
,
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
b
:
(
_
,
_
),
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~^^ ERROR the type placeholder `_` is not allowed within types on item signatures
}
pub
fn
main
()
{
...
...
@@ -67,7 +64,6 @@ fn fn_test2() -> (_, _) { (5, 5) }
static
FN_TEST5
:
(
_
,
_
)
=
(
1
,
2
);
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~^^ ERROR the type placeholder `_` is not allowed within types on item signatures
fn
fn_test6
(
_
:
_
)
{
}
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
...
...
@@ -100,8 +96,6 @@ struct FnTest10 {
a
:
_
,
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
b
:
(
_
,
_
),
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~^^ ERROR the type placeholder `_` is not allowed within types on item signatures
}
fn
fn_test11
(
_
:
_
)
->
(
_
,
_
)
{
panic!
()
}
...
...
src/test/ui/typeck/typeck_type_placeholder_item.stderr
浏览文件 @
6c8b2dcb
...
...
@@ -38,19 +38,15 @@ error[E0121]: the type placeholder `_` is not allowed within types on item signa
--> $DIR/typeck_type_placeholder_item.rs:16:16
|
LL | static TEST5: (_, _) = (1, 2);
| ^ not allowed in type signatures
| ^ ^ not allowed in type signatures
| |
| not allowed in type signatures
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:16:19
|
LL | static TEST5: (_, _) = (1, 2);
| ^ not allowed in type signatures
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:20:13
--> $DIR/typeck_type_placeholder_item.rs:19:13
|
LL | fn test6(_: _) { }
| ^
| ^
not allowed in type signatures
|
help: use type parameters instead
|
...
...
@@ -58,10 +54,10 @@ LL | fn test6<T>(_: T) { }
| ^^^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:2
3
:13
--> $DIR/typeck_type_placeholder_item.rs:2
2
:13
|
LL | fn test7(x: _) { let _x: usize = x; }
| ^
| ^
not allowed in type signatures
|
help: use type parameters instead
|
...
...
@@ -69,10 +65,10 @@ LL | fn test7<T>(x: T) { let _x: usize = x; }
| ^^^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:2
6
:22
--> $DIR/typeck_type_placeholder_item.rs:2
5
:22
|
LL | fn test8(_f: fn() -> _) { }
| ^
| ^
not allowed in type signatures
|
help: use type parameters instead
|
...
...
@@ -80,43 +76,26 @@ LL | fn test8<T>(_f: fn() -> T) { }
| ^^^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:4
8
:8
--> $DIR/typeck_type_placeholder_item.rs:4
7
:8
|
LL | a: _,
| ^ not allowed in type signatures
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:50:9
|
LL |
LL | b: (_, _),
| ^ not allowed in type signatures
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:50:12
| ^ ^ not allowed in type signatures
| |
| not allowed in type signatures
|
LL | b: (_, _),
| ^ not allowed in type signatures
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:100:12
|
LL | a: _,
| ^ not allowed in type signatures
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:102:13
help: use type parameters instead
|
LL | b: (_, _),
| ^ not allowed in type signatures
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:102:16
LL | struct Test10<T> {
LL | a: T,
LL |
LL | b: (T, T),
|
LL | b: (_, _),
| ^ not allowed in type signatures
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:5
6
:21
--> $DIR/typeck_type_placeholder_item.rs:5
3
:21
|
LL | fn fn_test() -> _ { 5 }
| ^
...
...
@@ -125,7 +104,7 @@ LL | fn fn_test() -> _ { 5 }
| help: replace this with the correct return type: `i32`
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:5
9
:22
--> $DIR/typeck_type_placeholder_item.rs:5
6
:22
|
LL | fn fn_test2() -> (_, _) { (5, 5) }
| ^^^^^^
...
...
@@ -134,7 +113,7 @@ LL | fn fn_test2() -> (_, _) { (5, 5) }
| help: replace this with the correct return type: `(i32, i32)`
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:
62
:22
--> $DIR/typeck_type_placeholder_item.rs:
59
:22
|
LL | static FN_TEST3: _ = "test";
| ^
...
...
@@ -143,7 +122,7 @@ LL | static FN_TEST3: _ = "test";
| help: replace `_` with the correct type: `&'static str`
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:6
5
:22
--> $DIR/typeck_type_placeholder_item.rs:6
2
:22
|
LL | static FN_TEST4: _ = 145;
| ^
...
...
@@ -152,22 +131,18 @@ LL | static FN_TEST4: _ = 145;
| help: replace `_` with the correct type: `i32`
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:68:23
|
LL | static FN_TEST5: (_, _) = (1, 2);
| ^ not allowed in type signatures
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:68:26
--> $DIR/typeck_type_placeholder_item.rs:65:23
|
LL | static FN_TEST5: (_, _) = (1, 2);
| ^ not allowed in type signatures
| ^ ^ not allowed in type signatures
| |
| not allowed in type signatures
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:
72
:20
--> $DIR/typeck_type_placeholder_item.rs:
68
:20
|
LL | fn fn_test6(_: _) { }
| ^
| ^
not allowed in type signatures
|
help: use type parameters instead
|
...
...
@@ -175,10 +150,10 @@ LL | fn fn_test6<T>(_: T) { }
| ^^^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:7
5
:20
--> $DIR/typeck_type_placeholder_item.rs:7
1
:20
|
LL | fn fn_test7(x: _) { let _x: usize = x; }
| ^
| ^
not allowed in type signatures
|
help: use type parameters instead
|
...
...
@@ -186,30 +161,49 @@ LL | fn fn_test7<T>(x: T) { let _x: usize = x; }
| ^^^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:7
8
:29
--> $DIR/typeck_type_placeholder_item.rs:7
4
:29
|
LL | fn fn_test8(_f: fn() -> _) { }
| ^
| ^
not allowed in type signatures
|
help: use type parameters instead
|
LL | fn fn_test8<T>(_f: fn() -> T) { }
| ^^^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:96:12
|
LL | a: _,
| ^ not allowed in type signatures
LL |
LL | b: (_, _),
| ^ ^ not allowed in type signatures
| |
| not allowed in type signatures
|
help: use type parameters instead
|
LL | struct FnTest10<T> {
LL | a: T,
LL |
LL | b: (T, T),
|
error[E0282]: type annotations needed
--> $DIR/typeck_type_placeholder_item.rs:10
7
:27
--> $DIR/typeck_type_placeholder_item.rs:10
1
:27
|
LL | fn fn_test11(_: _) -> (_, _) { panic!() }
| ^^^^^^ cannot infer type
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:10
7
:27
--> $DIR/typeck_type_placeholder_item.rs:10
1
:27
|
LL | fn fn_test11(_: _) -> (_, _) { panic!() }
| ^^^^^^ not allowed in type signatures
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:1
11
:29
--> $DIR/typeck_type_placeholder_item.rs:1
05
:29
|
LL | fn fn_test12(x: i32) -> (_, _) { (x, x) }
| ^^^^^^
...
...
@@ -218,10 +212,12 @@ LL | fn fn_test12(x: i32) -> (_, _) { (x, x) }
| help: replace this with the correct return type: `(i32, i32)`
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:1
14
:21
--> $DIR/typeck_type_placeholder_item.rs:1
08
:21
|
LL | fn fn_test13(x: _) -> (i32, _) { (x, x) }
| ^ ^
| ^ ^ not allowed in type signatures
| |
| not allowed in type signatures
|
help: use type parameters instead
|
...
...
@@ -229,10 +225,10 @@ LL | fn fn_test13<T>(x: T) -> (i32, T) { (x, x) }
| ^^^ ^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:11
9
:31
--> $DIR/typeck_type_placeholder_item.rs:11
3
:31
|
LL | fn method_test1(&self, x: _);
| ^
| ^
not allowed in type signatures
|
help: use type parameters instead
|
...
...
@@ -240,10 +236,12 @@ LL | fn method_test1<T>(&self, x: T);
| ^^^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:1
21
:31
--> $DIR/typeck_type_placeholder_item.rs:1
15
:31
|
LL | fn method_test2(&self, x: _) -> _;
| ^ ^
| ^ ^ not allowed in type signatures
| |
| not allowed in type signatures
|
help: use type parameters instead
|
...
...
@@ -251,10 +249,10 @@ LL | fn method_test2<T>(&self, x: T) -> T;
| ^^^ ^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:1
23
:31
--> $DIR/typeck_type_placeholder_item.rs:1
17
:31
|
LL | fn method_test3(&self) -> _;
| ^
| ^
not allowed in type signatures
|
help: use type parameters instead
|
...
...
@@ -262,10 +260,10 @@ LL | fn method_test3<T>(&self) -> T;
| ^^^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:1
25
:26
--> $DIR/typeck_type_placeholder_item.rs:1
19
:26
|
LL | fn assoc_fn_test1(x: _);
| ^
| ^
not allowed in type signatures
|
help: use type parameters instead
|
...
...
@@ -273,10 +271,12 @@ LL | fn assoc_fn_test1<T>(x: T);
| ^^^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:12
7
:26
--> $DIR/typeck_type_placeholder_item.rs:12
1
:26
|
LL | fn assoc_fn_test2(x: _) -> _;
| ^ ^
| ^ ^ not allowed in type signatures
| |
| not allowed in type signatures
|
help: use type parameters instead
|
...
...
@@ -284,10 +284,10 @@ LL | fn assoc_fn_test2<T>(x: T) -> T;
| ^^^ ^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:12
9
:28
--> $DIR/typeck_type_placeholder_item.rs:12
3
:28
|
LL | fn assoc_fn_test3() -> _;
| ^
| ^
not allowed in type signatures
|
help: use type parameters instead
|
...
...
@@ -295,7 +295,7 @@ LL | fn assoc_fn_test3<T>() -> T;
| ^^^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:3
2
:24
--> $DIR/typeck_type_placeholder_item.rs:3
1
:24
|
LL | fn test9(&self) -> _ { () }
| ^
...
...
@@ -304,10 +304,10 @@ LL | fn test9(&self) -> _ { () }
| help: replace this with the correct return type: `()`
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:3
5
:27
--> $DIR/typeck_type_placeholder_item.rs:3
4
:27
|
LL | fn test10(&self, _x : _) { }
| ^
| ^
not allowed in type signatures
|
help: use type parameters instead
|
...
...
@@ -315,7 +315,7 @@ LL | fn test10<T>(&self, _x : T) { }
| ^^^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:
40
:24
--> $DIR/typeck_type_placeholder_item.rs:
39
:24
|
LL | fn clone(&self) -> _ { Test9 }
| ^
...
...
@@ -324,10 +324,10 @@ LL | fn clone(&self) -> _ { Test9 }
| help: replace this with the correct return type: `Test9`
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:4
3
:37
--> $DIR/typeck_type_placeholder_item.rs:4
2
:37
|
LL | fn clone_from(&mut self, other: _) { *self = Test9; }
| ^
| ^
not allowed in type signatures
|
help: use type parameters instead
|
...
...
@@ -335,7 +335,7 @@ LL | fn clone_from<T>(&mut self, other: T) { *self = Test9; }
| ^^^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:8
4
:31
--> $DIR/typeck_type_placeholder_item.rs:8
0
:31
|
LL | fn fn_test9(&self) -> _ { () }
| ^
...
...
@@ -344,10 +344,10 @@ LL | fn fn_test9(&self) -> _ { () }
| help: replace this with the correct return type: `()`
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:8
7
:34
--> $DIR/typeck_type_placeholder_item.rs:8
3
:34
|
LL | fn fn_test10(&self, _x : _) { }
| ^
| ^
not allowed in type signatures
|
help: use type parameters instead
|
...
...
@@ -355,7 +355,7 @@ LL | fn fn_test10<T>(&self, _x : T) { }
| ^^^ ^
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:
92
:28
--> $DIR/typeck_type_placeholder_item.rs:
88
:28
|
LL | fn clone(&self) -> _ { FnTest9 }
| ^
...
...
@@ -364,17 +364,17 @@ LL | fn clone(&self) -> _ { FnTest9 }
| help: replace this with the correct return type: `main::FnTest9`
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
--> $DIR/typeck_type_placeholder_item.rs:9
5
:41
--> $DIR/typeck_type_placeholder_item.rs:9
1
:41
|
LL | fn clone_from(&mut self, other: _) { *self = FnTest9; }
| ^
| ^
not allowed in type signatures
|
help: use type parameters instead
|
LL | fn clone_from<T>(&mut self, other: T) { *self = FnTest9; }
| ^^^ ^
error: aborting due to
42
previous errors
error: aborting due to
36
previous errors
Some errors have detailed explanations: E0121, E0282.
For more information about an error, try `rustc --explain E0121`.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录