Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
a5328bc1
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,发现更多精彩内容 >>
提交
a5328bc1
编写于
5月 27, 2018
作者:
V
varkor
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simply joint lifetime/type iteration
上级
8bccfe7a
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
122 addition
and
217 deletion
+122
-217
src/librustc/hir/mod.rs
src/librustc/hir/mod.rs
+0
-6
src/librustc_save_analysis/lib.rs
src/librustc_save_analysis/lib.rs
+1
-4
src/librustc_typeck/astconv.rs
src/librustc_typeck/astconv.rs
+6
-7
src/librustc_typeck/check/method/confirm.rs
src/librustc_typeck/check/method/confirm.rs
+20
-34
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/mod.rs
+40
-49
src/librustc_typeck/check/wfcheck.rs
src/librustc_typeck/check/wfcheck.rs
+6
-9
src/librustc_typeck/coherence/unsafety.rs
src/librustc_typeck/coherence/unsafety.rs
+2
-7
src/librustc_typeck/collect.rs
src/librustc_typeck/collect.rs
+8
-15
src/librustc_typeck/diagnostics.rs
src/librustc_typeck/diagnostics.rs
+3
-3
src/librustc_typeck/lib.rs
src/librustc_typeck/lib.rs
+3
-10
src/librustdoc/clean/mod.rs
src/librustdoc/clean/mod.rs
+4
-8
src/libsyntax/visit.rs
src/libsyntax/visit.rs
+1
-1
src/libsyntax_ext/deriving/generic/mod.rs
src/libsyntax_ext/deriving/generic/mod.rs
+10
-27
src/libsyntax_ext/deriving/generic/ty.rs
src/libsyntax_ext/deriving/generic/ty.rs
+11
-30
src/libsyntax_ext/env.rs
src/libsyntax_ext/env.rs
+1
-1
src/test/compile-fail/issue-1900.rs
src/test/compile-fail/issue-1900.rs
+1
-1
src/test/ui/error-codes/E0131.stderr
src/test/ui/error-codes/E0131.stderr
+2
-2
src/test/ui/issue-51022.rs
src/test/ui/issue-51022.rs
+1
-1
src/test/ui/issue-51022.stderr
src/test/ui/issue-51022.stderr
+2
-2
未找到文件。
src/librustc/hir/mod.rs
浏览文件 @
a5328bc1
...
...
@@ -449,12 +449,6 @@ pub enum TraitBoundModifier {
pub
enum
GenericParamKind
{
/// A lifetime definition, eg `'a: 'b + 'c + 'd`.
Lifetime
{
/// Either "'a", referring to a named lifetime definition,
/// or "" (aka keywords::Invalid), for elision placeholders.
///
/// HIR lowering inserts these placeholders in type paths that
/// refer to type definitions needing lifetime parameters,
/// `&T` and `&mut T`, and trait objects without `... + 'a`.
name
:
LifetimeName
,
bounds
:
HirVec
<
Lifetime
>
,
// Indicates that the lifetime definition was synthetically added
...
...
src/librustc_save_analysis/lib.rs
浏览文件 @
a5328bc1
...
...
@@ -934,10 +934,7 @@ fn make_signature(decl: &ast::FnDecl, generics: &ast::Generics) -> String {
sig
.push_str
(
&
generics
.params
.iter
()
.map
(|
param
|
match
param
.kind
{
ast
::
GenericParamKind
::
Lifetime
{
..
}
=>
param
.ident.name
.to_string
(),
ast
::
GenericParamKind
::
Type
{
..
}
=>
param
.ident
.to_string
(),
})
.map
(|
param
|
param
.ident
.to_string
())
.collect
::
<
Vec
<
_
>>
()
.join
(
", "
));
sig
.push_str
(
"> "
);
...
...
src/librustc_typeck/astconv.rs
浏览文件 @
a5328bc1
...
...
@@ -996,13 +996,12 @@ fn qpath_to_ty(&self,
pub
fn
prohibit_type_params
(
&
self
,
segments
:
&
[
hir
::
PathSegment
])
{
for
segment
in
segments
{
segment
.with_generic_args
(|
generic_args
|
{
let
mut
err_for_lifetime
=
false
;
let
mut
err_for_type
=
false
;
let
(
mut
err_for_lt
,
mut
err_for_ty
)
=
(
false
,
false
);
for
arg
in
&
generic_args
.args
{
let
(
mut
span_err
,
span
,
kind
)
=
match
arg
{
hir
::
GenericArg
::
Lifetime
(
lt
)
=>
{
if
err_for_l
ifetime
{
continue
}
err_for_l
ifetime
=
true
;
if
err_for_l
t
{
continue
}
err_for_l
t
=
true
;
(
struct_span_err!
(
self
.tcx
()
.sess
,
lt
.span
,
E0110
,
"lifetime parameters are not allowed on
\
this type"
),
...
...
@@ -1010,8 +1009,8 @@ pub fn prohibit_type_params(&self, segments: &[hir::PathSegment]) {
"lifetime"
)
}
hir
::
GenericArg
::
Type
(
ty
)
=>
{
if
err_for_ty
pe
{
continue
}
err_for_ty
pe
=
true
;
if
err_for_ty
{
continue
}
err_for_ty
=
true
;
(
struct_span_err!
(
self
.tcx
()
.sess
,
ty
.span
,
E0109
,
"type parameters are not allowed on this type"
),
ty
.span
,
...
...
@@ -1020,7 +1019,7 @@ pub fn prohibit_type_params(&self, segments: &[hir::PathSegment]) {
};
span_err
.span_label
(
span
,
format!
(
"{} parameter not allowed"
,
kind
))
.emit
();
if
err_for_l
ifetime
&&
err_for_type
{
if
err_for_l
t
&&
err_for_ty
{
break
;
}
}
...
...
src/librustc_typeck/check/method/confirm.rs
浏览文件 @
a5328bc1
...
...
@@ -329,46 +329,32 @@ fn instantiate_method_substs(
if
i
<
parent_substs
.len
()
{
parent_substs
[
i
]
}
else
{
match
param
.kind
{
GenericParamDefKind
::
Lifetime
=>
{
if
let
Some
(
lifetime
)
=
provided
.as_ref
()
.and_then
(|
data
|
{
for
arg
in
&
data
.args
{
match
arg
{
GenericArg
::
Lifetime
(
lt
)
=>
{
if
i
==
parent_substs
.len
()
{
return
Some
(
lt
);
}
i
-=
1
;
}
_
=>
{}
let
(
is_lt
,
is_ty
)
=
match
param
.kind
{
GenericParamDefKind
::
Lifetime
=>
(
true
,
false
),
GenericParamDefKind
::
Type
{
..
}
=>
(
false
,
true
),
};
provided
.as_ref
()
.and_then
(|
data
|
{
for
arg
in
&
data
.args
{
match
arg
{
GenericArg
::
Lifetime
(
lt
)
if
is_lt
=>
{
if
i
==
parent_substs
.len
()
{
return
Some
(
AstConv
::
ast_region_to_region
(
self
.fcx
,
lt
,
Some
(
param
))
.into
());
}
i
-=
1
;
}
None
})
{
return
AstConv
::
ast_region_to_region
(
self
.fcx
,
lifetime
,
Some
(
param
))
.into
();
}
}
GenericParamDefKind
::
Type
{
..
}
=>
{
if
let
Some
(
ast_ty
)
=
provided
.as_ref
()
.and_then
(|
data
|
{
for
arg
in
&
data
.args
{
match
arg
{
GenericArg
::
Type
(
ty
)
=>
{
if
i
==
parent_substs
.len
()
+
own_counts
.lifetimes
{
return
Some
(
ty
);
}
i
-=
1
;
}
_
=>
{}
GenericArg
::
Lifetime
(
_
)
=>
{}
GenericArg
::
Type
(
ty
)
if
is_ty
=>
{
if
i
==
parent_substs
.len
()
+
own_counts
.lifetimes
{
return
Some
(
self
.to_ty
(
ty
)
.into
());
}
i
-=
1
;
}
None
})
{
return
self
.to_ty
(
ast_ty
)
.into
();
GenericArg
::
Type
(
_
)
=>
{}
}
}
}
self
.var_for_def
(
self
.span
,
param
)
None
})
.unwrap_or_else
(||
self
.var_for_def
(
self
.span
,
param
)
)
}
})
}
...
...
src/librustc_typeck/check/mod.rs
浏览文件 @
a5328bc1
...
...
@@ -4977,8 +4977,7 @@ fn check_generic_arg_count(&self,
s
.args
.as_ref
()
.map_or
(
(
vec!
[],
vec!
[],
s
.infer_types
,
&
[][
..
]),
|
data
|
{
let
mut
lifetimes
=
vec!
[];
let
mut
types
=
vec!
[];
let
(
mut
lifetimes
,
mut
types
)
=
(
vec!
[],
vec!
[]);
data
.args
.iter
()
.for_each
(|
arg
|
match
arg
{
GenericArg
::
Lifetime
(
lt
)
=>
lifetimes
.push
(
lt
),
GenericArg
::
Type
(
ty
)
=>
types
.push
(
ty
),
...
...
@@ -4987,14 +4986,6 @@ fn check_generic_arg_count(&self,
}
)
});
let
infer_lifetimes
=
lifetimes
.len
()
==
0
;
let
count_lifetime_params
=
|
n
|
{
format!
(
"{} lifetime parameter{}"
,
n
,
if
n
==
1
{
""
}
else
{
"s"
})
};
let
count_type_params
=
|
n
|
{
format!
(
"{} type parameter{}"
,
n
,
if
n
==
1
{
""
}
else
{
"s"
})
};
// Check provided parameters.
let
((
ty_required
,
ty_accepted
),
lt_accepted
)
=
...
...
@@ -5008,9 +4999,7 @@ struct ParamRange {
let
mut
ty_params
=
ParamRange
{
required
:
0
,
accepted
:
0
};
for
param
in
&
generics
.params
{
match
param
.kind
{
GenericParamDefKind
::
Lifetime
=>
{
lt_accepted
+=
1
;
}
GenericParamDefKind
::
Lifetime
=>
lt_accepted
+=
1
,
GenericParamDefKind
::
Type
{
has_default
,
..
}
=>
{
ty_params
.accepted
+=
1
;
if
!
has_default
{
...
...
@@ -5027,36 +5016,37 @@ struct ParamRange {
((
ty_params
.required
,
ty_params
.accepted
),
lt_accepted
)
});
if
types
.len
()
>
ty_accepted
{
let
span
=
types
[
ty_accepted
]
.span
;
let
expected_text
=
count_type_params
(
ty_accepted
);
let
actual_text
=
count_type_params
(
types
.len
());
struct_span_err!
(
self
.tcx.sess
,
span
,
E0087
,
"too many type parameters provided:
\
expected at most {}, found {}"
,
expected_text
,
actual_text
)
.span_label
(
span
,
format!
(
"expected {}"
,
expected_text
))
.emit
();
let
count_type_params
=
|
n
|
{
format!
(
"{} type parameter{}"
,
n
,
if
n
==
1
{
""
}
else
{
"s"
})
};
let
expected_text
=
count_type_params
(
ty_accepted
);
let
actual_text
=
count_type_params
(
types
.len
());
if
let
Some
((
mut
err
,
span
))
=
if
types
.len
()
>
ty_accepted
{
// To prevent derived errors to accumulate due to extra
// type parameters, we force instantiate_value_path to
// use inference variables instead of the provided types.
*
segment
=
None
;
let
span
=
types
[
ty_accepted
]
.span
;
Some
((
struct_span_err!
(
self
.tcx.sess
,
span
,
E0087
,
"too many type parameters provided:
\
expected at most {}, found {}"
,
expected_text
,
actual_text
),
span
))
}
else
if
types
.len
()
<
ty_required
&&
!
infer_types
&&
!
supress_mismatch_error
{
let
expected_text
=
count_type_params
(
ty_required
);
let
actual_text
=
count_type_params
(
types
.len
());
struct_span_err!
(
self
.tcx.sess
,
span
,
E0089
,
"too few type parameters provided:
\
expected {}, found {}"
,
expected_text
,
actual_text
)
.span_label
(
span
,
format!
(
"expected {}"
,
expected_text
))
.emit
();
Some
((
struct_span_err!
(
self
.tcx.sess
,
span
,
E0089
,
"too few type parameters provided:
\
expected {}, found {}"
,
expected_text
,
actual_text
),
span
))
}
else
{
None
}
{
err
.span_label
(
span
,
format!
(
"expected {}"
,
expected_text
))
.emit
();
}
if
!
bindings
.is_empty
()
{
AstConv
::
prohibit_projection
(
self
,
bindings
[
0
]
.span
);
}
let
infer_lifetimes
=
lifetimes
.len
()
==
0
;
// Prohibit explicit lifetime arguments if late bound lifetime parameters are present.
let
has_late_bound_lifetime_defs
=
segment
.map_or
(
None
,
|(
_
,
generics
)|
generics
.has_late_bound_regions
);
...
...
@@ -5080,25 +5070,26 @@ struct ParamRange {
return
;
}
if
lifetimes
.len
()
>
lt_accepted
{
let
count_lifetime_params
=
|
n
|
{
format!
(
"{} lifetime parameter{}"
,
n
,
if
n
==
1
{
""
}
else
{
"s"
})
};
let
expected_text
=
count_lifetime_params
(
lt_accepted
);
let
actual_text
=
count_lifetime_params
(
lifetimes
.len
());
if
let
Some
((
mut
err
,
span
))
=
if
lifetimes
.len
()
>
lt_accepted
{
let
span
=
lifetimes
[
lt_accepted
]
.span
;
let
expected_text
=
count_lifetime_params
(
lt_accepted
);
let
actual_text
=
count_lifetime_params
(
lifetimes
.len
());
struct_span_err!
(
self
.tcx.sess
,
span
,
E0088
,
"too many lifetime parameters provided:
\
expected at most {}, found {}"
,
expected_text
,
actual_text
)
.span_label
(
span
,
format!
(
"expected {}"
,
expected_text
))
.emit
();
Some
((
struct_span_err!
(
self
.tcx.sess
,
span
,
E0088
,
"too many lifetime parameters provided:
\
expected at most {}, found {}"
,
expected_text
,
actual_text
),
span
))
}
else
if
lifetimes
.len
()
<
lt_accepted
&&
!
infer_lifetimes
{
let
expected_text
=
count_lifetime_params
(
lt_accepted
);
let
actual_text
=
count_lifetime_params
(
lifetimes
.len
());
struct_span_err!
(
self
.tcx.sess
,
span
,
E0090
,
"too few lifetime parameters provided:
\
expected {}, found {}"
,
expected_text
,
actual_text
)
.span_label
(
span
,
format!
(
"expected {}"
,
expected_text
))
.emit
();
Some
((
struct_span_err!
(
self
.tcx.sess
,
span
,
E0090
,
"too few lifetime parameters provided:
\
expected {}, found {}"
,
expected_text
,
actual_text
),
span
))
}
else
{
None
}
{
err
.span_label
(
span
,
format!
(
"expected {}"
,
expected_text
))
.emit
();
}
}
...
...
src/librustc_typeck/check/wfcheck.rs
浏览文件 @
a5328bc1
...
...
@@ -660,15 +660,12 @@ fn report_bivariance<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
fn
reject_shadowing_parameters
(
tcx
:
TyCtxt
,
def_id
:
DefId
)
{
let
generics
=
tcx
.generics_of
(
def_id
);
let
parent
=
tcx
.generics_of
(
generics
.parent
.unwrap
());
let
impl_params
:
FxHashMap
<
_
,
_
>
=
parent
.params
.iter
()
.flat_map
(|
param
|
match
param
.kind
{
GenericParamDefKind
::
Lifetime
=>
None
,
GenericParamDefKind
::
Type
{
..
}
=>
Some
((
param
.name
,
param
.def_id
)),
})
.collect
();
for
method_param
in
generics
.params
.iter
()
{
let
impl_params
:
FxHashMap
<
_
,
_
>
=
parent
.params
.iter
()
.flat_map
(|
param
|
match
param
.kind
{
GenericParamDefKind
::
Lifetime
=>
None
,
GenericParamDefKind
::
Type
{
..
}
=>
Some
((
param
.name
,
param
.def_id
)),
})
.collect
();
for
method_param
in
&
generics
.params
{
match
method_param
.kind
{
// Shadowing is checked in resolve_lifetime.
GenericParamDefKind
::
Lifetime
=>
continue
,
...
...
src/librustc_typeck/coherence/unsafety.rs
浏览文件 @
a5328bc1
...
...
@@ -35,13 +35,8 @@ fn check_unsafety_coherence(&mut self,
Some
(
trait_ref
)
=>
{
let
trait_def
=
self
.tcx
.trait_def
(
trait_ref
.def_id
);
let
unsafe_attr
=
impl_generics
.and_then
(|
g
|
{
for
param
in
&
g
.params
{
if
param
.pure_wrt_drop
{
return
Some
(
"may_dangle"
);
}
}
None
let
unsafe_attr
=
impl_generics
.and_then
(|
generics
|
{
generics
.params
.iter
()
.find
(|
p
|
p
.pure_wrt_drop
)
.map
(|
_
|
"may_dangle"
)
});
match
(
trait_def
.unsafety
,
unsafe_attr
,
unsafety
,
polarity
)
{
(
Unsafety
::
Normal
,
None
,
Unsafety
::
Unsafe
,
hir
::
ImplPolarity
::
Positive
)
=>
{
...
...
src/librustc_typeck/collect.rs
浏览文件 @
a5328bc1
...
...
@@ -117,12 +117,11 @@ fn visit_generics(&mut self, generics: &'tcx hir::Generics) {
for
param
in
&
generics
.params
{
match
param
.kind
{
hir
::
GenericParamKind
::
Lifetime
{
..
}
=>
{}
hir
::
GenericParamKind
::
Type
{
ref
default
,
..
}
=>
{
if
default
.is_some
()
{
let
def_id
=
self
.tcx.hir
.local_def_id
(
param
.id
);
self
.tcx
.type_of
(
def_id
);
}
hir
::
GenericParamKind
::
Type
{
ref
default
,
..
}
if
default
.is_some
()
=>
{
let
def_id
=
self
.tcx.hir
.local_def_id
(
param
.id
);
self
.tcx
.type_of
(
def_id
);
}
hir
::
GenericParamKind
::
Type
{
..
}
=>
{}
}
}
intravisit
::
walk_generics
(
self
,
generics
);
...
...
@@ -316,11 +315,8 @@ fn type_parameter_bounds_in_generics(&self,
let
from_ty_params
=
ast_generics
.params
.iter
()
.filter_map
(|
param
|
match
param
.kind
{
GenericParamKind
::
Type
{
ref
bounds
,
..
}
=>
{
if
param
.id
==
param_id
{
return
Some
(
bounds
);
}
None
GenericParamKind
::
Type
{
ref
bounds
,
..
}
if
param
.id
==
param_id
=>
{
Some
(
bounds
)
}
_
=>
None
})
...
...
@@ -1470,11 +1466,8 @@ pub fn explicit_predicates_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
.to_ty
(
tcx
);
index
+=
1
;
let
bounds
=
compute_bounds
(
&
icx
,
param_ty
,
bounds
,
SizedByDefault
::
Yes
,
param
.span
);
let
bounds
=
compute_bounds
(
&
icx
,
param_ty
,
bounds
,
SizedByDefault
::
Yes
,
param
.span
);
predicates
.extend
(
bounds
.predicates
(
tcx
,
param_ty
));
}
_
=>
{}
...
...
src/librustc_typeck/diagnostics.rs
浏览文件 @
a5328bc1
...
...
@@ -1501,12 +1501,12 @@ struct Foo {
"##
,
E0131
:
r##"
It is not possible to define `main` with
type parameters, or even with function
parameters.
When `main` is present, it must take no arguments and return `()`.
It is not possible to define `main` with
generic parameters.
When `main` is present, it must take no arguments and return `()`.
Erroneous code example:
```compile_fail,E0131
fn main<T>() { // error: main function is not allowed to have
type
parameters
fn main<T>() { // error: main function is not allowed to have
generic
parameters
}
```
"##
,
...
...
src/librustc_typeck/lib.rs
浏览文件 @
a5328bc1
...
...
@@ -191,16 +191,9 @@ fn check_main_fn_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
hir
::
ItemFn
(
..
,
ref
generics
,
_
)
=>
{
let
mut
error
=
false
;
if
!
generics
.params
.is_empty
()
{
let
param_type
=
if
generics
.is_lt_parameterized
()
{
"lifetime"
}
else
{
"type"
};
let
msg
=
format!
(
"`main` function is not allowed to have {} parameters"
,
param_type
);
let
label
=
format!
(
"`main` cannot have {} parameters"
,
param_type
);
let
msg
=
format!
(
"`main` function is not allowed to have generic
\
parameters"
);
let
label
=
format!
(
"`main` cannot have generic parameters"
);
struct_span_err!
(
tcx
.sess
,
generics
.span
,
E0131
,
"{}"
,
msg
)
.span_label
(
generics
.span
,
label
)
.emit
();
...
...
src/librustdoc/clean/mod.rs
浏览文件 @
a5328bc1
...
...
@@ -3540,27 +3540,23 @@ fn clean(&self, cx: &DocContext) -> GenericArgs {
output
:
if
output
!=
Type
::
Tuple
(
Vec
::
new
())
{
Some
(
output
)
}
else
{
None
}
}
}
else
{
let
mut
lifetimes
=
vec!
[];
let
mut
types
=
vec!
[];
let
(
mut
lifetimes
,
mut
types
)
=
(
vec!
[],
vec!
[]);
let
mut
elided_lifetimes
=
true
;
for
arg
in
&
self
.args
{
match
arg
{
GenericArg
::
Lifetime
(
lt
)
if
elided_lifetimes
=>
{
if
lt
.is_elided
()
{
GenericArg
::
Lifetime
(
lt
)
=>
{
if
!
lt
.is_elided
()
{
elided_lifetimes
=
false
;
lifetimes
=
vec!
[];
continue
;
}
lifetimes
.push
(
lt
.clean
(
cx
));
}
GenericArg
::
Lifetime
(
_
)
=>
{}
GenericArg
::
Type
(
ty
)
=>
{
types
.push
(
ty
.clean
(
cx
));
}
}
}
GenericArgs
::
AngleBracketed
{
lifetimes
,
lifetimes
:
if
elided_lifetimes
{
vec!
[]
}
else
{
lifetimes
}
,
types
,
bindings
:
self
.bindings
.clean
(
cx
),
}
...
...
src/libsyntax/visit.rs
浏览文件 @
a5328bc1
...
...
@@ -136,7 +136,7 @@ fn visit_generic_args(&mut self, path_span: Span, generic_args: &'ast GenericArg
fn
visit_generic_arg
(
&
mut
self
,
generic_arg
:
&
'ast
GenericArg
)
{
match
generic_arg
{
GenericArg
::
Lifetime
(
lt
)
=>
self
.visit_lifetime
(
lt
),
GenericArg
::
Type
(
ty
)
=>
self
.visit_ty
(
ty
),
GenericArg
::
Type
(
ty
)
=>
self
.visit_ty
(
ty
),
}
}
fn
visit_assoc_type_binding
(
&
mut
self
,
type_binding
:
&
'ast
TypeBinding
)
{
...
...
src/libsyntax_ext/deriving/generic/mod.rs
浏览文件 @
a5328bc1
...
...
@@ -665,35 +665,18 @@ fn create_derived_impl(&self,
// Create the reference to the trait.
let
trait_ref
=
cx
.trait_ref
(
trait_path
);
// Create the type parameters on the `self` path.
let
self_ty_params
:
Vec
<
P
<
ast
::
Ty
>>
=
generics
.params
.iter
()
.filter_map
(|
param
|
match
param
.kind
{
GenericParamKind
::
Type
{
..
}
=>
Some
(
cx
.ty_ident
(
self
.span
,
param
.ident
)),
_
=>
None
,
})
.collect
();
let
self_lifetimes
:
Vec
<
ast
::
Lifetime
>
=
generics
.params
.iter
()
.filter_map
(|
param
|
match
param
.kind
{
GenericParamKind
::
Lifetime
{
ref
lifetime
,
..
}
=>
Some
(
*
lifetime
),
_
=>
None
,
})
.collect
();
let
self_params
=
self_lifetimes
.into_iter
()
.map
(|
lt
|
GenericArg
::
Lifetime
(
lt
))
.chain
(
self_ty_params
.into_iter
()
.map
(|
ty
|
GenericArg
::
Type
(
ty
)))
.collect
();
let
self_params
:
Vec
<
_
>
=
generics
.params
.iter
()
.map
(|
param
|
match
param
.kind
{
GenericParamKind
::
Lifetime
{
ref
lifetime
,
..
}
=>
{
GenericArg
::
Lifetime
(
*
lifetime
)
}
GenericParamKind
::
Type
{
..
}
=>
{
GenericArg
::
Type
(
cx
.ty_ident
(
self
.span
,
param
.ident
))
}
})
.collect
();
// Create the type of `self`.
let
self_type
=
cx
.ty_path
(
cx
.path_all
(
self
.span
,
false
,
vec!
[
type_ident
],
self_params
,
Vec
::
new
()));
let
path
=
cx
.path_all
(
self
.span
,
false
,
vec!
[
type_ident
],
self_params
,
vec!
[]);
let
self_type
=
cx
.ty_path
(
path
);
let
attr
=
cx
.attribute
(
self
.span
,
cx
.meta_word
(
self
.span
,
...
...
src/libsyntax_ext/deriving/generic/ty.rs
浏览文件 @
a5328bc1
...
...
@@ -185,41 +185,22 @@ pub fn to_path(&self,
cx
:
&
ExtCtxt
,
span
:
Span
,
self_ty
:
Ident
,
self_
generics
:
&
Generics
)
generics
:
&
Generics
)
->
ast
::
Path
{
match
*
self
{
Self_
=>
{
let
ty_params
:
Vec
<
P
<
ast
::
Ty
>>
=
self_generics
.params
.iter
()
.filter_map
(|
param
|
match
param
.kind
{
GenericParamKind
::
Type
{
..
}
=>
{
Some
(
cx
.ty_ident
(
span
,
param
.ident
))
}
_
=>
None
,
})
.collect
();
let
lifetimes
:
Vec
<
ast
::
Lifetime
>
=
self_generics
.params
.iter
()
.filter_map
(|
param
|
match
param
.kind
{
GenericParamKind
::
Lifetime
{
ref
lifetime
,
..
}
=>
Some
(
*
lifetime
),
_
=>
None
,
})
.collect
();
let
params
=
lifetimes
.into_iter
()
.map
(|
lt
|
GenericArg
::
Lifetime
(
lt
))
.chain
(
ty_params
.into_iter
()
.map
(|
ty
|
GenericArg
::
Type
(
ty
)))
.collect
();
let
params
:
Vec
<
_
>
=
generics
.params
.iter
()
.map
(|
param
|
match
param
.kind
{
GenericParamKind
::
Lifetime
{
ref
lifetime
,
..
}
=>
{
GenericArg
::
Lifetime
(
*
lifetime
)
}
GenericParamKind
::
Type
{
..
}
=>
{
GenericArg
::
Type
(
cx
.ty_ident
(
span
,
param
.ident
))
}
})
.collect
();
cx
.path_all
(
span
,
false
,
vec!
[
self_ty
],
params
,
Vec
::
new
())
cx
.path_all
(
span
,
false
,
vec!
[
self_ty
],
params
,
vec!
[])
}
Literal
(
ref
p
)
=>
p
.to_path
(
cx
,
span
,
self_ty
,
self_
generics
),
Literal
(
ref
p
)
=>
p
.to_path
(
cx
,
span
,
self_ty
,
generics
),
Ptr
(
..
)
=>
cx
.span_bug
(
span
,
"pointer in a path in generic `derive`"
),
Tuple
(
..
)
=>
cx
.span_bug
(
span
,
"tuple in a path in generic `derive`"
),
}
...
...
src/libsyntax_ext/env.rs
浏览文件 @
a5328bc1
...
...
@@ -43,7 +43,7 @@ pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt,
cx
.ty_ident
(
sp
,
Ident
::
from_str
(
"str"
)),
Some
(
lt
),
ast
::
Mutability
::
Immutable
))],
Vec
::
new
()
))
vec!
[]
))
}
Ok
(
s
)
=>
{
cx
.expr_call_global
(
sp
,
...
...
src/test/compile-fail/issue-1900.rs
浏览文件 @
a5328bc1
...
...
@@ -8,5 +8,5 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern: `main` function is not allowed to have
type
parameters
// error-pattern: `main` function is not allowed to have
generic
parameters
fn
main
<
T
>
()
{
}
src/test/ui/error-codes/E0131.stderr
浏览文件 @
a5328bc1
error[E0131]: `main` function is not allowed to have
type
parameters
error[E0131]: `main` function is not allowed to have
generic
parameters
--> $DIR/E0131.rs:11:8
|
LL | fn main<T>() {
| ^^^ `main` cannot have
type
parameters
| ^^^ `main` cannot have
generic
parameters
error: aborting due to previous error
...
...
src/test/ui/issue-51022.rs
浏览文件 @
a5328bc1
...
...
@@ -9,4 +9,4 @@
// except according to those terms.
fn
main
<
'a
>
()
{
}
//~^ ERROR `main` function is not allowed to have
lifetime
parameters [E0131]
//~^ ERROR `main` function is not allowed to have
generic
parameters [E0131]
src/test/ui/issue-51022.stderr
浏览文件 @
a5328bc1
error[E0131]: `main` function is not allowed to have
lifetime
parameters
error[E0131]: `main` function is not allowed to have
generic
parameters
--> $DIR/issue-51022.rs:11:8
|
LL | fn main<'a>() { }
| ^^^^ `main` cannot have
lifetime
parameters
| ^^^^ `main` cannot have
generic
parameters
error: aborting due to previous error
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录