Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
59481823
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,发现更多精彩内容 >>
提交
59481823
编写于
8月 10, 2016
作者:
G
Guillaume Gomez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add Span field for Generics structs
上级
7ac11cad
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
37 addition
and
52 deletion
+37
-52
src/librustc/hir/fold.rs
src/librustc/hir/fold.rs
+2
-1
src/librustc/hir/lowering.rs
src/librustc/hir/lowering.rs
+1
-0
src/librustc/hir/mod.rs
src/librustc/hir/mod.rs
+3
-33
src/librustc/hir/print.rs
src/librustc/hir/print.rs
+2
-0
src/librustc/infer/error_reporting.rs
src/librustc/infer/error_reporting.rs
+1
-0
src/librustc_typeck/lib.rs
src/librustc_typeck/lib.rs
+5
-6
src/libsyntax/ast.rs
src/libsyntax/ast.rs
+4
-2
src/libsyntax/fold.rs
src/libsyntax/fold.rs
+2
-1
src/libsyntax/parse/mod.rs
src/libsyntax/parse/mod.rs
+3
-2
src/libsyntax/parse/parser.rs
src/libsyntax/parse/parser.rs
+5
-3
src/libsyntax/print/pprust.rs
src/libsyntax/print/pprust.rs
+2
-0
src/libsyntax_ext/deriving/generic/mod.rs
src/libsyntax_ext/deriving/generic/mod.rs
+2
-1
src/libsyntax_ext/deriving/generic/ty.rs
src/libsyntax_ext/deriving/generic/ty.rs
+4
-2
src/test/compile-fail/E0132.rs
src/test/compile-fail/E0132.rs
+1
-1
未找到文件。
src/librustc/hir/fold.rs
浏览文件 @
59481823
...
...
@@ -577,13 +577,14 @@ pub fn noop_fold_opt_lifetime<T: Folder>(o_lt: Option<Lifetime>, fld: &mut T) ->
o_lt
.map
(|
lt
|
fld
.fold_lifetime
(
lt
))
}
pub
fn
noop_fold_generics
<
T
:
Folder
>
(
Generics
{
ty_params
,
lifetimes
,
where_clause
}:
Generics
,
pub
fn
noop_fold_generics
<
T
:
Folder
>
(
Generics
{
ty_params
,
lifetimes
,
where_clause
,
span
}:
Generics
,
fld
:
&
mut
T
)
->
Generics
{
Generics
{
ty_params
:
fld
.fold_ty_params
(
ty_params
),
lifetimes
:
fld
.fold_lifetime_defs
(
lifetimes
),
where_clause
:
fld
.fold_where_clause
(
where_clause
),
span
:
fld
.new_span
(
span
),
}
}
...
...
src/librustc/hir/lowering.rs
浏览文件 @
59481823
...
...
@@ -466,6 +466,7 @@ fn lower_generics(&mut self, g: &Generics) -> hir::Generics {
ty_params
:
self
.lower_ty_params
(
&
g
.ty_params
),
lifetimes
:
self
.lower_lifetime_defs
(
&
g
.lifetimes
),
where_clause
:
self
.lower_where_clause
(
&
g
.where_clause
),
span
:
g
.span
,
}
}
...
...
src/librustc/hir/mod.rs
浏览文件 @
59481823
...
...
@@ -36,7 +36,7 @@
use
hir
::
def_id
::
DefId
;
use
util
::
nodemap
::{
NodeMap
,
FnvHashSet
};
use
syntax_pos
::{
BytePos
,
mk_sp
,
Span
,
ExpnId
};
use
syntax_pos
::{
mk_sp
,
Span
,
ExpnId
,
DUMMY_SP
};
use
syntax
::
codemap
::{
self
,
respan
,
Spanned
};
use
syntax
::
abi
::
Abi
;
use
syntax
::
ast
::{
Name
,
NodeId
,
DUMMY_NODE_ID
,
AsmDialect
};
...
...
@@ -301,6 +301,7 @@ pub struct Generics {
pub
lifetimes
:
HirVec
<
LifetimeDef
>
,
pub
ty_params
:
HirVec
<
TyParam
>
,
pub
where_clause
:
WhereClause
,
pub
span
:
Span
,
}
impl
Generics
{
...
...
@@ -312,6 +313,7 @@ pub fn empty() -> Generics {
id
:
DUMMY_NODE_ID
,
predicates
:
HirVec
::
new
(),
},
span
:
DUMMY_SP
,
}
}
...
...
@@ -326,38 +328,6 @@ pub fn is_type_parameterized(&self) -> bool {
pub
fn
is_parameterized
(
&
self
)
->
bool
{
self
.is_lt_parameterized
()
||
self
.is_type_parameterized
()
}
// Does return a span which includes lifetimes and type parameters,
// not where clause.
pub
fn
span
(
&
self
)
->
Option
<
Span
>
{
if
!
self
.is_parameterized
()
{
None
}
else
{
let
mut
span
:
Option
<
Span
>
=
None
;
for
lifetime
in
self
.lifetimes
.iter
()
{
if
let
Some
(
ref
mut
span
)
=
span
{
let
life_span
=
lifetime
.lifetime.span
;
span
.hi
=
if
span
.hi
>
life_span
.hi
{
span
.hi
}
else
{
life_span
.hi
};
span
.lo
=
if
span
.lo
<
life_span
.lo
{
span
.lo
}
else
{
life_span
.lo
};
}
else
{
span
=
Some
(
lifetime
.lifetime.span
.clone
());
}
}
for
ty_param
in
self
.ty_params
.iter
()
{
if
let
Some
(
ref
mut
span
)
=
span
{
span
.lo
=
if
span
.lo
<
ty_param
.span.lo
{
span
.lo
}
else
{
ty_param
.span.lo
};
span
.hi
=
if
span
.hi
>
ty_param
.span.hi
{
span
.hi
}
else
{
ty_param
.span.hi
};
}
else
{
span
=
Some
(
ty_param
.span
.clone
());
}
}
if
let
Some
(
ref
mut
span
)
=
span
{
span
.lo
=
span
.lo
-
BytePos
(
1
);
span
.hi
=
span
.hi
+
BytePos
(
1
);
}
span
}
}
}
/// A `where` clause in a definition
...
...
src/librustc/hir/print.rs
浏览文件 @
59481823
...
...
@@ -523,6 +523,7 @@ pub fn print_type(&mut self, ty: &hir::Ty) -> io::Result<()> {
id
:
ast
::
DUMMY_NODE_ID
,
predicates
:
hir
::
HirVec
::
new
(),
},
span
:
syntax_pos
::
DUMMY_SP
,
};
self
.print_ty_fn
(
f
.abi
,
f
.unsafety
,
&
f
.decl
,
None
,
&
generics
)
?
;
}
...
...
@@ -2224,6 +2225,7 @@ pub fn print_ty_fn(&mut self,
id
:
ast
::
DUMMY_NODE_ID
,
predicates
:
hir
::
HirVec
::
new
(),
},
span
:
syntax_pos
::
DUMMY_SP
,
};
self
.print_fn
(
decl
,
unsafety
,
...
...
src/librustc/infer/error_reporting.rs
浏览文件 @
59481823
...
...
@@ -1293,6 +1293,7 @@ fn rebuild_generics(&self,
lifetimes
:
lifetimes
.into
(),
ty_params
:
ty_params
,
where_clause
:
where_clause
,
span
:
generics
.span
,
}
}
...
...
src/librustc_typeck/lib.rs
浏览文件 @
59481823
...
...
@@ -216,10 +216,10 @@ fn check_main_fn_ty(ccx: &CrateCtxt,
Some
(
hir_map
::
NodeItem
(
it
))
=>
{
match
it
.node
{
hir
::
ItemFn
(
_
,
_
,
_
,
_
,
ref
generics
,
_
)
=>
{
if
let
Some
(
gen_span
)
=
generics
.span
()
{
struct_span_err!
(
ccx
.tcx.sess
,
gen
_
span
,
E0131
,
if
generics
.is_parameterized
()
{
struct_span_err!
(
ccx
.tcx.sess
,
gen
erics
.
span
,
E0131
,
"main function is not allowed to have type parameters"
)
.span_label
(
gen
_
span
,
.span_label
(
gen
erics
.
span
,
&
format!
(
"main cannot have type parameters"
))
.emit
();
return
;
...
...
@@ -269,10 +269,9 @@ fn check_start_fn_ty(ccx: &CrateCtxt,
match
it
.node
{
hir
::
ItemFn
(
_
,
_
,
_
,
_
,
ref
ps
,
_
)
if
ps
.is_parameterized
()
=>
{
let
sp
=
if
let
Some
(
sp
)
=
ps
.span
()
{
sp
}
else
{
start_span
};
struct_span_err!
(
tcx
.sess
,
sp
,
E0132
,
struct_span_err!
(
tcx
.sess
,
ps
.span
,
E0132
,
"start function is not allowed to have type parameters"
)
.span_label
(
sp
,
.span_label
(
ps
.span
,
&
format!
(
"start function cannot have type parameters"
))
.emit
();
return
;
...
...
src/libsyntax/ast.rs
浏览文件 @
59481823
...
...
@@ -336,7 +336,7 @@ pub struct TyParam {
pub
id
:
NodeId
,
pub
bounds
:
TyParamBounds
,
pub
default
:
Option
<
P
<
Ty
>>
,
pub
span
:
Span
pub
span
:
Span
,
}
/// Represents lifetimes and type parameters attached to a declaration
...
...
@@ -346,6 +346,7 @@ pub struct Generics {
pub
lifetimes
:
Vec
<
LifetimeDef
>
,
pub
ty_params
:
P
<
[
TyParam
]
>
,
pub
where_clause
:
WhereClause
,
pub
span
:
Span
,
}
impl
Generics
{
...
...
@@ -368,7 +369,8 @@ fn default() -> Generics {
where_clause
:
WhereClause
{
id
:
DUMMY_NODE_ID
,
predicates
:
Vec
::
new
(),
}
},
span
:
DUMMY_SP
,
}
}
}
...
...
src/libsyntax/fold.rs
浏览文件 @
59481823
...
...
@@ -698,12 +698,13 @@ pub fn noop_fold_opt_lifetime<T: Folder>(o_lt: Option<Lifetime>, fld: &mut T)
o_lt
.map
(|
lt
|
fld
.fold_lifetime
(
lt
))
}
pub
fn
noop_fold_generics
<
T
:
Folder
>
(
Generics
{
ty_params
,
lifetimes
,
where_clause
}:
Generics
,
pub
fn
noop_fold_generics
<
T
:
Folder
>
(
Generics
{
ty_params
,
lifetimes
,
where_clause
,
span
}:
Generics
,
fld
:
&
mut
T
)
->
Generics
{
Generics
{
ty_params
:
fld
.fold_ty_params
(
ty_params
),
lifetimes
:
fld
.fold_lifetime_defs
(
lifetimes
),
where_clause
:
fld
.fold_where_clause
(
where_clause
),
span
:
fld
.new_span
(
span
),
}
}
...
...
src/libsyntax/parse/mod.rs
浏览文件 @
59481823
...
...
@@ -674,7 +674,7 @@ pub fn integer_lit(s: &str,
mod
tests
{
use
super
::
*
;
use
std
::
rc
::
Rc
;
use
syntax_pos
::{
Span
,
BytePos
,
Pos
,
NO_EXPANSION
};
use
syntax_pos
::{
self
,
Span
,
BytePos
,
Pos
,
NO_EXPANSION
};
use
codemap
::
Spanned
;
use
ast
::{
self
,
PatKind
};
use
abi
::
Abi
;
...
...
@@ -945,7 +945,8 @@ fn parser_done(p: Parser){
where_clause
:
ast
::
WhereClause
{
id
:
ast
::
DUMMY_NODE_ID
,
predicates
:
Vec
::
new
(),
}
},
span
:
syntax_pos
::
DUMMY_SP
,
},
P
(
ast
::
Block
{
stmts
:
vec!
(
ast
::
Stmt
{
...
...
src/libsyntax/parse/parser.rs
浏览文件 @
59481823
...
...
@@ -716,8 +716,8 @@ pub fn expect_gt(&mut self) -> PResult<'a, ()> {
let
gt_str
=
Parser
::
token_to_string
(
&
token
::
Gt
);
let
this_token_str
=
self
.this_token_to_string
();
Err
(
self
.fatal
(
&
format!
(
"expected `{}`, found `{}`"
,
gt_str
,
this_token_str
)))
gt_str
,
this_token_str
)))
}
}
}
...
...
@@ -4251,6 +4251,7 @@ fn parse_ty_param(&mut self) -> PResult<'a, TyParam> {
/// where typaramseq = ( typaram ) | ( typaram , typaramseq )
pub
fn
parse_generics
(
&
mut
self
)
->
PResult
<
'a
,
ast
::
Generics
>
{
maybe_whole!
(
self
,
NtGenerics
);
let
span_lo
=
self
.span.lo
;
if
self
.eat
(
&
token
::
Lt
)
{
let
lifetime_defs
=
self
.parse_lifetime_defs
()
?
;
...
...
@@ -4273,7 +4274,8 @@ pub fn parse_generics(&mut self) -> PResult<'a, ast::Generics> {
where_clause
:
WhereClause
{
id
:
ast
::
DUMMY_NODE_ID
,
predicates
:
Vec
::
new
(),
}
},
span
:
mk_sp
(
span_lo
,
self
.last_span.hi
),
})
}
else
{
Ok
(
ast
::
Generics
::
default
())
...
...
src/libsyntax/print/pprust.rs
浏览文件 @
59481823
...
...
@@ -1001,6 +1001,7 @@ pub fn print_type(&mut self, ty: &ast::Ty) -> io::Result<()> {
id
:
ast
::
DUMMY_NODE_ID
,
predicates
:
Vec
::
new
(),
},
span
:
syntax_pos
::
DUMMY_SP
,
};
try!
(
self
.print_ty_fn
(
f
.abi
,
f
.unsafety
,
...
...
@@ -2982,6 +2983,7 @@ pub fn print_ty_fn(&mut self,
id
:
ast
::
DUMMY_NODE_ID
,
predicates
:
Vec
::
new
(),
},
span
:
syntax_pos
::
DUMMY_SP
,
};
try!
(
self
.print_fn
(
decl
,
unsafety
,
...
...
src/libsyntax_ext/deriving/generic/mod.rs
浏览文件 @
59481823
...
...
@@ -488,7 +488,7 @@ fn create_derived_impl(&self,
}
});
let
Generics
{
mut
lifetimes
,
ty_params
,
mut
where_clause
}
=
self
.generics
let
Generics
{
mut
lifetimes
,
ty_params
,
mut
where_clause
,
span
}
=
self
.generics
.to_generics
(
cx
,
self
.span
,
type_ident
,
generics
);
let
mut
ty_params
=
ty_params
.into_vec
();
...
...
@@ -590,6 +590,7 @@ fn create_derived_impl(&self,
lifetimes
:
lifetimes
,
ty_params
:
P
::
from_vec
(
ty_params
),
where_clause
:
where_clause
,
span
:
span
,
};
// Create the reference to the trait.
...
...
src/libsyntax_ext/deriving/generic/ty.rs
浏览文件 @
59481823
...
...
@@ -207,7 +207,8 @@ fn mk_ty_param(cx: &ExtCtxt,
cx
.typaram
(
span
,
cx
.ident_of
(
name
),
bounds
,
None
)
}
fn
mk_generics
(
lifetimes
:
Vec
<
ast
::
LifetimeDef
>
,
ty_params
:
Vec
<
ast
::
TyParam
>
)
->
Generics
{
fn
mk_generics
(
lifetimes
:
Vec
<
ast
::
LifetimeDef
>
,
ty_params
:
Vec
<
ast
::
TyParam
>
,
span
:
Span
)
->
Generics
{
Generics
{
lifetimes
:
lifetimes
,
ty_params
:
P
::
from_vec
(
ty_params
),
...
...
@@ -215,6 +216,7 @@ fn mk_generics(lifetimes: Vec<ast::LifetimeDef>, ty_params: Vec<ast::TyParam>) -
id
:
ast
::
DUMMY_NODE_ID
,
predicates
:
Vec
::
new
(),
},
span
:
span
,
}
}
...
...
@@ -257,7 +259,7 @@ pub fn to_generics(&self,
}
})
.collect
();
mk_generics
(
lifetimes
,
ty_params
)
mk_generics
(
lifetimes
,
ty_params
,
span
)
}
}
...
...
src/test/compile-fail/E0132.rs
浏览文件 @
59481823
...
...
@@ -11,7 +11,7 @@
#![feature(start)]
#[start]
fn
f
<
T
>
()
{}
//~ ERROR E0132
fn
f
<
T
>
()
{}
//~ ERROR E0132
//~| NOTE start function cannot have type parameters
fn
main
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录