Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
aa5c4bb0
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
aa5c4bb0
编写于
8月 10, 2016
作者:
K
Keith Yeung
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Change Constness to Spanned<Constness>
上级
1e9e798c
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
61 addition
and
38 deletion
+61
-38
src/librustc/hir/lowering.rs
src/librustc/hir/lowering.rs
+2
-2
src/librustc/hir/map/blocks.rs
src/librustc/hir/map/blocks.rs
+3
-3
src/librustc/infer/error_reporting.rs
src/librustc/infer/error_reporting.rs
+2
-1
src/librustc_passes/ast_validation.rs
src/librustc_passes/ast_validation.rs
+8
-6
src/librustc_passes/consts.rs
src/librustc_passes/consts.rs
+2
-1
src/libsyntax/ast.rs
src/libsyntax/ast.rs
+2
-2
src/libsyntax/ext/build.rs
src/libsyntax/ext/build.rs
+2
-2
src/libsyntax/feature_gate.rs
src/libsyntax/feature_gate.rs
+4
-4
src/libsyntax/parse/mod.rs
src/libsyntax/parse/mod.rs
+4
-1
src/libsyntax/parse/parser.rs
src/libsyntax/parse/parser.rs
+24
-9
src/libsyntax/print/pprust.rs
src/libsyntax/print/pprust.rs
+2
-2
src/libsyntax/test.rs
src/libsyntax/test.rs
+2
-2
src/libsyntax/visit.rs
src/libsyntax/visit.rs
+1
-1
src/libsyntax_ext/deriving/generic/mod.rs
src/libsyntax_ext/deriving/generic/mod.rs
+3
-2
未找到文件。
src/librustc/hir/lowering.rs
浏览文件 @
aa5c4bb0
...
...
@@ -809,8 +809,8 @@ fn lower_unsafety(&mut self, u: Unsafety) -> hir::Unsafety {
}
}
fn
lower_constness
(
&
mut
self
,
c
:
Constness
)
->
hir
::
Constness
{
match
c
{
fn
lower_constness
(
&
mut
self
,
c
:
Spanned
<
Constness
>
)
->
hir
::
Constness
{
match
c
.node
{
Constness
::
Const
=>
hir
::
Constness
::
Const
,
Constness
::
NotConst
=>
hir
::
Constness
::
NotConst
,
}
...
...
src/librustc/hir/map/blocks.rs
浏览文件 @
aa5c4bb0
...
...
@@ -23,13 +23,13 @@
pub
use
self
::
Code
::
*
;
use
hir
as
ast
;
use
hir
::
map
::{
self
,
Node
};
use
syntax
::
abi
;
use
hir
::{
Block
,
FnDecl
};
use
hir
::
intravisit
::
FnKind
;
use
syntax
::
abi
;
use
syntax
::
ast
::{
Attribute
,
Name
,
NodeId
};
use
hir
as
ast
;
use
syntax_pos
::
Span
;
use
hir
::
intravisit
::
FnKind
;
/// An FnLikeNode is a Node that is like a fn, in that it has a decl
/// and a body (as well as a NodeId, a span, etc).
...
...
src/librustc/infer/error_reporting.rs
浏览文件 @
aa5c4bb0
...
...
@@ -1030,7 +1030,8 @@ fn give_suggestion(&self, err: &mut DiagnosticBuilder, same_regions: &[SameRegio
=
node_inner
.expect
(
"expect item fn"
);
let
rebuilder
=
Rebuilder
::
new
(
self
.tcx
,
fn_decl
,
generics
,
same_regions
,
&
life_giver
);
let
(
fn_decl
,
generics
)
=
rebuilder
.rebuild
();
self
.give_expl_lifetime_param
(
err
,
&
fn_decl
,
unsafety
,
constness
,
name
,
&
generics
,
span
);
self
.give_expl_lifetime_param
(
err
,
&
fn_decl
,
unsafety
,
constness
,
name
,
&
generics
,
span
);
}
pub
fn
issue_32330_warnings
(
&
self
,
span
:
Span
,
issue32330s
:
&
[
ty
::
Issue32330
])
{
...
...
src/librustc_passes/ast_validation.rs
浏览文件 @
aa5c4bb0
...
...
@@ -20,6 +20,7 @@
use
rustc
::
session
::
Session
;
use
syntax
::
ast
::
*
;
use
syntax
::
attr
;
use
syntax
::
codemap
::
Spanned
;
use
syntax
::
parse
::
token
::{
self
,
keywords
};
use
syntax
::
visit
::{
self
,
Visitor
};
use
syntax_pos
::
Span
;
...
...
@@ -70,11 +71,12 @@ fn check_decl_no_pat<ReportFn: Fn(Span, bool)>(&self, decl: &FnDecl, report_err:
}
}
fn
check_trait_fn_not_const
(
&
self
,
span
:
Span
,
constness
:
Constness
)
{
match
constness
{
fn
check_trait_fn_not_const
(
&
self
,
constness
:
Spanned
<
Constness
>
)
{
match
constness
.node
{
Constness
::
Const
=>
{
struct_span_err!
(
self
.session
,
span
,
E0379
,
"trait fns cannot be declared const"
)
.span_label
(
span
,
&
format!
(
"trait fns cannot be const"
))
struct_span_err!
(
self
.session
,
constness
.span
,
E0379
,
"trait fns cannot be declared const"
)
.span_label
(
constness
.span
,
&
format!
(
"trait fns cannot be const"
))
.emit
();
}
_
=>
{}
...
...
@@ -158,7 +160,7 @@ fn visit_item(&mut self, item: &Item) {
for
impl_item
in
impl_items
{
self
.invalid_visibility
(
&
impl_item
.vis
,
impl_item
.span
,
None
);
if
let
ImplItemKind
::
Method
(
ref
sig
,
_
)
=
impl_item
.node
{
self
.check_trait_fn_not_const
(
impl_item
.span
,
sig
.constness
);
self
.check_trait_fn_not_const
(
sig
.constness
);
}
}
}
...
...
@@ -186,7 +188,7 @@ fn visit_item(&mut self, item: &Item) {
ItemKind
::
Trait
(
_
,
_
,
_
,
ref
trait_items
)
=>
{
for
trait_item
in
trait_items
{
if
let
TraitItemKind
::
Method
(
ref
sig
,
_
)
=
trait_item
.node
{
self
.check_trait_fn_not_const
(
trait_item
.span
,
sig
.constness
);
self
.check_trait_fn_not_const
(
sig
.constness
);
}
}
}
...
...
src/librustc_passes/consts.rs
浏览文件 @
aa5c4bb0
...
...
@@ -147,7 +147,8 @@ fn fn_like(&mut self,
}
let
mode
=
match
fk
{
FnKind
::
ItemFn
(
_
,
_
,
_
,
hir
::
Constness
::
Const
,
_
,
_
,
_
)
=>
Mode
::
ConstFn
,
FnKind
::
ItemFn
(
_
,
_
,
_
,
hir
::
Constness
::
Const
,
_
,
_
,
_
)
=>
Mode
::
ConstFn
,
FnKind
::
Method
(
_
,
m
,
_
,
_
)
=>
{
if
m
.constness
==
hir
::
Constness
::
Const
{
Mode
::
ConstFn
...
...
src/libsyntax/ast.rs
浏览文件 @
aa5c4bb0
...
...
@@ -1120,7 +1120,7 @@ pub struct MutTy {
#[derive(Clone,
PartialEq,
Eq,
RustcEncodable,
RustcDecodable,
Hash,
Debug)]
pub
struct
MethodSig
{
pub
unsafety
:
Unsafety
,
pub
constness
:
Constness
,
pub
constness
:
Spanned
<
Constness
>
,
pub
abi
:
Abi
,
pub
decl
:
P
<
FnDecl
>
,
pub
generics
:
Generics
,
...
...
@@ -1846,7 +1846,7 @@ pub enum ItemKind {
/// A function declaration (`fn` or `pub fn`).
///
/// E.g. `fn foo(bar: usize) -> usize { .. }`
Fn
(
P
<
FnDecl
>
,
Unsafety
,
Constness
,
Abi
,
Generics
,
P
<
Block
>
),
Fn
(
P
<
FnDecl
>
,
Unsafety
,
Spanned
<
Constness
>
,
Abi
,
Generics
,
P
<
Block
>
),
/// A module declaration (`mod` or `pub mod`).
///
/// E.g. `mod foo;` or `mod foo { .. }`
...
...
src/libsyntax/ext/build.rs
浏览文件 @
aa5c4bb0
...
...
@@ -12,7 +12,7 @@
use
ast
::{
self
,
Ident
,
Generics
,
Expr
,
BlockCheckMode
,
UnOp
,
PatKind
};
use
attr
;
use
syntax_pos
::{
Span
,
DUMMY_SP
,
Pos
};
use
codemap
::{
respan
,
Spanned
};
use
codemap
::{
dummy_spanned
,
respan
,
Spanned
};
use
ext
::
base
::
ExtCtxt
;
use
parse
::
token
::{
self
,
keywords
,
InternedString
};
use
ptr
::
P
;
...
...
@@ -1016,7 +1016,7 @@ fn item_fn_poly(&self,
Vec
::
new
(),
ast
::
ItemKind
::
Fn
(
self
.fn_decl
(
inputs
,
output
),
ast
::
Unsafety
::
Normal
,
ast
::
Constness
::
NotConst
,
dummy_spanned
(
ast
::
Constness
::
NotConst
)
,
Abi
::
Rust
,
generics
,
body
))
...
...
src/libsyntax/feature_gate.rs
浏览文件 @
aa5c4bb0
...
...
@@ -30,7 +30,7 @@
use
ast
;
use
attr
;
use
attr
::
AttrMetaMethods
;
use
codemap
::
CodeMap
;
use
codemap
::
{
CodeMap
,
Spanned
}
;
use
syntax_pos
::
Span
;
use
errors
::
Handler
;
use
visit
::{
self
,
FnKind
,
Visitor
};
...
...
@@ -1046,7 +1046,7 @@ fn visit_fn(&mut self,
_
node_id
:
NodeId
)
{
// check for const fn declarations
match
fn_kind
{
FnKind
::
ItemFn
(
_
,
_
,
_
,
ast
::
Constness
::
Const
,
_
,
_
)
=>
{
FnKind
::
ItemFn
(
_
,
_
,
_
,
Spanned
{
node
:
ast
::
Constness
::
Const
,
..
}
,
_
,
_
)
=>
{
gate_feature_post!
(
&
self
,
const_fn
,
span
,
"const fn is unstable"
);
}
_
=>
{
...
...
@@ -1078,7 +1078,7 @@ fn visit_trait_item(&mut self, ti: &ast::TraitItem) {
if
block
.is_none
()
{
self
.check_abi
(
sig
.abi
,
ti
.span
);
}
if
sig
.constness
==
ast
::
Constness
::
Const
{
if
sig
.constness
.node
==
ast
::
Constness
::
Const
{
gate_feature_post!
(
&
self
,
const_fn
,
ti
.span
,
"const fn is unstable"
);
}
}
...
...
@@ -1105,7 +1105,7 @@ fn visit_impl_item(&mut self, ii: &ast::ImplItem) {
"associated constants are experimental"
)
}
ast
::
ImplItemKind
::
Method
(
ref
sig
,
_
)
=>
{
if
sig
.constness
==
ast
::
Constness
::
Const
{
if
sig
.constness
.node
==
ast
::
Constness
::
Const
{
gate_feature_post!
(
&
self
,
const_fn
,
ii
.span
,
"const fn is unstable"
);
}
}
...
...
src/libsyntax/parse/mod.rs
浏览文件 @
aa5c4bb0
...
...
@@ -937,7 +937,10 @@ fn parser_done(p: Parser){
variadic
:
false
}),
ast
::
Unsafety
::
Normal
,
ast
::
Constness
::
NotConst
,
Spanned
{
span
:
sp
(
0
,
2
),
node
:
ast
::
Constness
::
NotConst
,
},
Abi
::
Rust
,
ast
::
Generics
{
// no idea on either of these:
lifetimes
:
Vec
::
new
(),
...
...
src/libsyntax/parse/parser.rs
浏览文件 @
aa5c4bb0
...
...
@@ -39,7 +39,7 @@
use
ast
::{
Visibility
,
WhereClause
};
use
ast
::{
BinOpKind
,
UnOp
};
use
ast
;
use
codemap
::{
self
,
CodeMap
,
Spanned
,
spanned
};
use
codemap
::{
self
,
CodeMap
,
Spanned
,
spanned
,
respan
};
use
syntax_pos
::{
self
,
Span
,
BytePos
,
mk_sp
};
use
errors
::{
self
,
DiagnosticBuilder
};
use
ext
::
tt
::
macro_parser
;
...
...
@@ -4768,7 +4768,7 @@ fn mk_item(&mut self, lo: BytePos, hi: BytePos, ident: Ident,
/// Parse an item-position function declaration.
fn
parse_item_fn
(
&
mut
self
,
unsafety
:
Unsafety
,
constness
:
Constness
,
constness
:
Spanned
<
Constness
>
,
abi
:
abi
::
Abi
)
->
PResult
<
'a
,
ItemInfo
>
{
let
(
ident
,
mut
generics
)
=
self
.parse_fn_header
()
?
;
...
...
@@ -4794,18 +4794,21 @@ pub fn is_const_item(&mut self) -> bool {
/// - `extern fn`
/// - etc
pub
fn
parse_fn_front_matter
(
&
mut
self
)
->
PResult
<
'a
,
(
ast
::
Constness
,
ast
::
Unsafety
,
abi
::
Abi
)
>
{
->
PResult
<
'a
,
(
Spanned
<
ast
::
Constness
>
,
ast
::
Unsafety
,
abi
::
Abi
)
>
{
let
is_const_fn
=
self
.eat_keyword
(
keywords
::
Const
);
let
const_span
=
self
.last_span
;
let
unsafety
=
self
.parse_unsafety
()
?
;
let
(
constness
,
unsafety
,
abi
)
=
if
is_const_fn
{
(
Constness
::
Const
,
unsafety
,
Abi
::
Rust
)
(
respan
(
const_span
,
Constness
::
Const
)
,
unsafety
,
Abi
::
Rust
)
}
else
{
let
abi
=
if
self
.eat_keyword
(
keywords
::
Extern
)
{
self
.parse_opt_abi
()
?
.unwrap_or
(
Abi
::
C
)
}
else
{
Abi
::
Rust
};
(
Constness
::
NotConst
,
unsafety
,
abi
)
(
respan
(
self
.last_span
,
Constness
::
NotConst
)
,
unsafety
,
abi
)
};
self
.expect_keyword
(
keywords
::
Fn
)
?
;
Ok
((
constness
,
unsafety
,
abi
))
...
...
@@ -5704,9 +5707,12 @@ fn parse_item_(&mut self, attrs: Vec<Attribute>,
if
self
.eat_keyword
(
keywords
::
Fn
)
{
// EXTERN FUNCTION ITEM
let
fn_span
=
self
.last_span
;
let
abi
=
opt_abi
.unwrap_or
(
Abi
::
C
);
let
(
ident
,
item_
,
extra_attrs
)
=
self
.parse_item_fn
(
Unsafety
::
Normal
,
Constness
::
NotConst
,
abi
)
?
;
self
.parse_item_fn
(
Unsafety
::
Normal
,
respan
(
fn_span
,
Constness
::
NotConst
),
abi
)
?
;
let
last_span
=
self
.last_span
;
let
item
=
self
.mk_item
(
lo
,
last_span
.hi
,
...
...
@@ -5740,6 +5746,7 @@ fn parse_item_(&mut self, attrs: Vec<Attribute>,
return
Ok
(
Some
(
item
));
}
if
self
.eat_keyword
(
keywords
::
Const
)
{
let
const_span
=
self
.last_span
;
if
self
.check_keyword
(
keywords
::
Fn
)
||
(
self
.check_keyword
(
keywords
::
Unsafe
)
&&
self
.look_ahead
(
1
,
|
t
|
t
.is_keyword
(
keywords
::
Fn
)))
{
...
...
@@ -5751,7 +5758,9 @@ fn parse_item_(&mut self, attrs: Vec<Attribute>,
};
self
.bump
();
let
(
ident
,
item_
,
extra_attrs
)
=
self
.parse_item_fn
(
unsafety
,
Constness
::
Const
,
Abi
::
Rust
)
?
;
self
.parse_item_fn
(
unsafety
,
respan
(
const_span
,
Constness
::
Const
),
Abi
::
Rust
)
?
;
let
last_span
=
self
.last_span
;
let
item
=
self
.mk_item
(
lo
,
last_span
.hi
,
...
...
@@ -5815,8 +5824,11 @@ fn parse_item_(&mut self, attrs: Vec<Attribute>,
if
self
.check_keyword
(
keywords
::
Fn
)
{
// FUNCTION ITEM
self
.bump
();
let
fn_span
=
self
.last_span
;
let
(
ident
,
item_
,
extra_attrs
)
=
self
.parse_item_fn
(
Unsafety
::
Normal
,
Constness
::
NotConst
,
Abi
::
Rust
)
?
;
self
.parse_item_fn
(
Unsafety
::
Normal
,
respan
(
fn_span
,
Constness
::
NotConst
),
Abi
::
Rust
)
?
;
let
last_span
=
self
.last_span
;
let
item
=
self
.mk_item
(
lo
,
last_span
.hi
,
...
...
@@ -5836,8 +5848,11 @@ fn parse_item_(&mut self, attrs: Vec<Attribute>,
Abi
::
Rust
};
self
.expect_keyword
(
keywords
::
Fn
)
?
;
let
fn_span
=
self
.last_span
;
let
(
ident
,
item_
,
extra_attrs
)
=
self
.parse_item_fn
(
Unsafety
::
Unsafe
,
Constness
::
NotConst
,
abi
)
?
;
self
.parse_item_fn
(
Unsafety
::
Unsafe
,
respan
(
fn_span
,
Constness
::
NotConst
),
abi
)
?
;
let
last_span
=
self
.last_span
;
let
item
=
self
.mk_item
(
lo
,
last_span
.hi
,
...
...
src/libsyntax/print/pprust.rs
浏览文件 @
aa5c4bb0
...
...
@@ -1184,7 +1184,7 @@ pub fn print_item(&mut self, item: &ast::Item) -> io::Result<()> {
try!
(
self
.print_fn
(
decl
,
unsafety
,
constness
,
constness
.node
,
abi
,
Some
(
item
.ident
),
typarams
,
...
...
@@ -1518,7 +1518,7 @@ pub fn print_method_sig(&mut self,
->
io
::
Result
<
()
>
{
self
.print_fn
(
&
m
.decl
,
m
.unsafety
,
m
.constness
,
m
.constness
.node
,
m
.abi
,
Some
(
ident
),
&
m
.generics
,
...
...
src/libsyntax/test.rs
浏览文件 @
aa5c4bb0
...
...
@@ -24,7 +24,7 @@
use
syntax_pos
::{
self
,
DUMMY_SP
,
NO_EXPANSION
,
Span
,
FileMap
,
BytePos
};
use
std
::
rc
::
Rc
;
use
codemap
::{
self
,
CodeMap
,
ExpnInfo
,
NameAndSpan
,
MacroAttribute
};
use
codemap
::{
self
,
CodeMap
,
ExpnInfo
,
NameAndSpan
,
MacroAttribute
,
dummy_spanned
};
use
errors
;
use
errors
::
snippet
::{
SnippetData
};
use
config
;
...
...
@@ -485,7 +485,7 @@ fn mk_main(cx: &mut TestCtxt) -> P<ast::Item> {
let
main_body
=
ecx
.block
(
sp
,
vec!
[
call_test_main
]);
let
main
=
ast
::
ItemKind
::
Fn
(
ecx
.fn_decl
(
vec!
[],
main_ret_ty
),
ast
::
Unsafety
::
Normal
,
ast
::
Constness
::
NotConst
,
dummy_spanned
(
ast
::
Constness
::
NotConst
)
,
::
abi
::
Abi
::
Rust
,
ast
::
Generics
::
default
(),
main_body
);
let
main
=
P
(
ast
::
Item
{
ident
:
token
::
str_to_ident
(
"main"
),
...
...
src/libsyntax/visit.rs
浏览文件 @
aa5c4bb0
...
...
@@ -31,7 +31,7 @@
#[derive(Copy,
Clone,
PartialEq,
Eq)]
pub
enum
FnKind
<
'a
>
{
/// fn foo() or extern "Abi" fn foo()
ItemFn
(
Ident
,
&
'a
Generics
,
Unsafety
,
Constness
,
Abi
,
&
'a
Visibility
),
ItemFn
(
Ident
,
&
'a
Generics
,
Unsafety
,
Spanned
<
Constness
>
,
Abi
,
&
'a
Visibility
),
/// fn foo(&self)
Method
(
Ident
,
&
'a
MethodSig
,
Option
<&
'a
Visibility
>
),
...
...
src/libsyntax_ext/deriving/generic/mod.rs
浏览文件 @
aa5c4bb0
...
...
@@ -197,7 +197,7 @@
use
syntax
::
attr
::
AttrMetaMethods
;
use
syntax
::
ext
::
base
::{
Annotatable
,
ExtCtxt
};
use
syntax
::
ext
::
build
::
AstBuilder
;
use
syntax
::
codemap
::{
self
,
respan
};
use
syntax
::
codemap
::{
self
,
dummy_spanned
,
respan
};
use
syntax
::
util
::
move_map
::
MoveMap
;
use
syntax
::
parse
::
token
::{
InternedString
,
keywords
};
use
syntax
::
ptr
::
P
;
...
...
@@ -901,7 +901,8 @@ fn create_method(&self,
generics
:
fn_generics
,
abi
:
abi
,
unsafety
:
unsafety
,
constness
:
ast
::
Constness
::
NotConst
,
constness
:
dummy_spanned
(
ast
::
Constness
::
NotConst
),
decl
:
fn_decl
,
},
body_block
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录