Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
3f0cc801
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,发现更多精彩内容 >>
提交
3f0cc801
编写于
1月 18, 2015
作者:
S
Seo Sanghyeon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make output type in ast::FnDecl optional
上级
a8333379
变更
14
隐藏空白更改
内联
并排
Showing
14 changed file
with
76 addition
and
85 deletion
+76
-85
src/librustc/middle/infer/error_reporting.rs
src/librustc/middle/infer/error_reporting.rs
+1
-0
src/librustc_trans/trans/debuginfo.rs
src/librustc_trans/trans/debuginfo.rs
+9
-12
src/librustc_trans/trans/foreign.rs
src/librustc_trans/trans/foreign.rs
+2
-3
src/librustc_typeck/astconv.rs
src/librustc_typeck/astconv.rs
+13
-5
src/librustc_typeck/collect.rs
src/librustc_typeck/collect.rs
+3
-1
src/librustdoc/clean/mod.rs
src/librustdoc/clean/mod.rs
+3
-1
src/librustdoc/html/format.rs
src/librustdoc/html/format.rs
+1
-0
src/libsyntax/ast.rs
src/libsyntax/ast.rs
+5
-0
src/libsyntax/fold.rs
src/libsyntax/fold.rs
+2
-8
src/libsyntax/parse/mod.rs
src/libsyntax/parse/mod.rs
+1
-3
src/libsyntax/parse/parser.rs
src/libsyntax/parse/parser.rs
+5
-24
src/libsyntax/print/pprust.rs
src/libsyntax/print/pprust.rs
+10
-18
src/libsyntax/test.rs
src/libsyntax/test.rs
+4
-10
src/test/pretty/fn-return.rs
src/test/pretty/fn-return.rs
+17
-0
未找到文件。
src/librustc/middle/infer/error_reporting.rs
浏览文件 @
3f0cc801
...
...
@@ -1177,6 +1177,7 @@ fn rebuild_output(&self, ty: &ast::FunctionRetTy,
ast
::
Return
(
ref
ret_ty
)
=>
ast
::
Return
(
self
.rebuild_arg_ty_or_output
(
&**
ret_ty
,
lifetime
,
anon_nums
,
region_names
)
),
ast
::
DefaultReturn
(
span
)
=>
ast
::
DefaultReturn
(
span
),
ast
::
NoReturn
(
span
)
=>
ast
::
NoReturn
(
span
)
}
}
...
...
src/librustc_trans/trans/debuginfo.rs
浏览文件 @
3f0cc801
...
...
@@ -1450,18 +1450,15 @@ fn get_function_signature<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let
mut
signature
=
Vec
::
with_capacity
(
fn_decl
.inputs
.len
()
+
1
);
// Return type -- llvm::DIBuilder wants this at index 0
match
fn_decl
.output
{
ast
::
Return
(
ref
ret_ty
)
if
ret_ty
.node
==
ast
::
TyTup
(
vec!
[])
=>
signature
.push
(
ptr
::
null_mut
()),
_
=>
{
assert_type_for_node_id
(
cx
,
fn_ast_id
,
error_reporting_span
);
let
return_type
=
ty
::
node_id_to_type
(
cx
.tcx
(),
fn_ast_id
);
let
return_type
=
monomorphize
::
apply_param_substs
(
cx
.tcx
(),
param_substs
,
&
return_type
);
signature
.push
(
type_metadata
(
cx
,
return_type
,
codemap
::
DUMMY_SP
));
}
assert_type_for_node_id
(
cx
,
fn_ast_id
,
error_reporting_span
);
let
return_type
=
ty
::
node_id_to_type
(
cx
.tcx
(),
fn_ast_id
);
let
return_type
=
monomorphize
::
apply_param_substs
(
cx
.tcx
(),
param_substs
,
&
return_type
);
if
ty
::
type_is_nil
(
return_type
)
{
signature
.push
(
ptr
::
null_mut
())
}
else
{
signature
.push
(
type_metadata
(
cx
,
return_type
,
codemap
::
DUMMY_SP
));
}
// Arguments types
...
...
src/librustc_trans/trans/foreign.rs
浏览文件 @
3f0cc801
...
...
@@ -445,9 +445,8 @@ fn gate_simd_ffi(tcx: &ty::ctxt, decl: &ast::FnDecl, ty: &ty::BareFnTy) {
for
(
input
,
ty
)
in
decl
.inputs
.iter
()
.zip
(
sig
.inputs
.iter
())
{
check
(
&*
input
.ty
,
*
ty
)
}
match
decl
.output
{
ast
::
NoReturn
(
_
)
=>
{}
ast
::
Return
(
ref
ty
)
=>
check
(
&**
ty
,
sig
.output
.unwrap
())
if
let
ast
::
Return
(
ref
ty
)
=
decl
.output
{
check
(
&**
ty
,
sig
.output
.unwrap
())
}
}
}
...
...
src/librustc_typeck/astconv.rs
浏览文件 @
3f0cc801
...
...
@@ -1359,7 +1359,8 @@ fn ty_of_method_or_bare_fn<'a, 'tcx>(this: &AstConv<'tcx>,
implied_output_region
,
lifetimes_for_params
,
&**
output
)),
ast
::
NoReturn
(
_
)
=>
ty
::
FnDiverging
ast
::
DefaultReturn
(
..
)
=>
ty
::
FnConverging
(
ty
::
mk_nil
(
this
.tcx
())),
ast
::
NoReturn
(
..
)
=>
ty
::
FnDiverging
};
(
ty
::
BareFnTy
{
...
...
@@ -1486,14 +1487,21 @@ pub fn ty_of_closure<'tcx>(
let
expected_ret_ty
=
expected_sig
.map
(|
e
|
e
.output
);
let
is_infer
=
match
decl
.output
{
ast
::
Return
(
ref
output
)
if
output
.node
==
ast
::
TyInfer
=>
true
,
ast
::
DefaultReturn
(
..
)
=>
true
,
_
=>
false
};
let
output_ty
=
match
decl
.output
{
ast
::
Return
(
ref
output
)
if
output
.node
==
ast
::
TyI
nfer
&&
expected_ret_ty
.is_some
()
=>
_
if
is_i
nfer
&&
expected_ret_ty
.is_some
()
=>
expected_ret_ty
.unwrap
(),
ast
::
Return
(
ref
output
)
if
output
.node
==
ast
::
TyI
nfer
=>
ty
::
FnConverging
(
this
.ty_infer
(
output
.span
)),
_
if
is_i
nfer
=>
ty
::
FnConverging
(
this
.ty_infer
(
decl
.output
.span
()
)),
ast
::
Return
(
ref
output
)
=>
ty
::
FnConverging
(
ast_ty_to_ty
(
this
,
&
rb
,
&**
output
)),
ast
::
NoReturn
(
_
)
=>
ty
::
FnDiverging
ast
::
DefaultReturn
(
..
)
=>
unreachable!
(),
ast
::
NoReturn
(
..
)
=>
ty
::
FnDiverging
};
debug!
(
"ty_of_closure: input_tys={}"
,
input_tys
.repr
(
this
.tcx
()));
...
...
src/librustc_typeck/collect.rs
浏览文件 @
3f0cc801
...
...
@@ -1488,7 +1488,9 @@ fn ty_of_foreign_fn_decl<'a, 'tcx>(ccx: &CollectCtxt<'a, 'tcx>,
let
output
=
match
decl
.output
{
ast
::
Return
(
ref
ty
)
=>
ty
::
FnConverging
(
ast_ty_to_ty
(
ccx
,
&
rb
,
&**
ty
)),
ast
::
NoReturn
(
_
)
=>
ast
::
DefaultReturn
(
..
)
=>
ty
::
FnConverging
(
ty
::
mk_nil
(
ccx
.tcx
)),
ast
::
NoReturn
(
..
)
=>
ty
::
FnDiverging
};
...
...
src/librustdoc/clean/mod.rs
浏览文件 @
3f0cc801
...
...
@@ -1141,6 +1141,7 @@ fn clean(&self, cx: &DocContext) -> Argument {
#[derive(Clone,
RustcEncodable,
RustcDecodable,
PartialEq,
Show)]
pub
enum
FunctionRetTy
{
Return
(
Type
),
DefaultReturn
,
NoReturn
}
...
...
@@ -1148,7 +1149,8 @@ impl Clean<FunctionRetTy> for ast::FunctionRetTy {
fn
clean
(
&
self
,
cx
:
&
DocContext
)
->
FunctionRetTy
{
match
*
self
{
ast
::
Return
(
ref
typ
)
=>
Return
(
typ
.clean
(
cx
)),
ast
::
NoReturn
(
_
)
=>
NoReturn
ast
::
DefaultReturn
(
..
)
=>
DefaultReturn
,
ast
::
NoReturn
(
..
)
=>
NoReturn
}
}
}
...
...
src/librustdoc/html/format.rs
浏览文件 @
3f0cc801
...
...
@@ -557,6 +557,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match
*
self
{
clean
::
Return
(
clean
::
Tuple
(
ref
tys
))
if
tys
.is_empty
()
=>
Ok
(()),
clean
::
Return
(
ref
ty
)
=>
write!
(
f
,
" -> {}"
,
ty
),
clean
::
DefaultReturn
=>
Ok
(()),
clean
::
NoReturn
=>
write!
(
f
,
" -> !"
)
}
}
...
...
src/libsyntax/ast.rs
浏览文件 @
3f0cc801
...
...
@@ -1390,6 +1390,10 @@ pub enum FunctionRetTy {
/// Functions with return type ! that always
/// raise an error or exit (i.e. never return to the caller)
NoReturn
(
Span
),
/// Return type is not specified. Functions default to () and
/// closures default to inference. Span points to where return
/// type would be inserted.
DefaultReturn
(
Span
),
/// Everything else
Return
(
P
<
Ty
>
),
}
...
...
@@ -1398,6 +1402,7 @@ impl FunctionRetTy {
pub
fn
span
(
&
self
)
->
Span
{
match
*
self
{
NoReturn
(
span
)
=>
span
,
DefaultReturn
(
span
)
=>
span
,
Return
(
ref
ty
)
=>
ty
.span
}
}
...
...
src/libsyntax/fold.rs
浏览文件 @
3f0cc801
...
...
@@ -726,6 +726,7 @@ pub fn noop_fold_fn_decl<T: Folder>(decl: P<FnDecl>, fld: &mut T) -> P<FnDecl> {
inputs
:
inputs
.move_map
(|
x
|
fld
.fold_arg
(
x
)),
output
:
match
output
{
Return
(
ty
)
=>
Return
(
fld
.fold_ty
(
ty
)),
DefaultReturn
(
span
)
=>
DefaultReturn
(
span
),
NoReturn
(
span
)
=>
NoReturn
(
span
)
},
variadic
:
variadic
...
...
@@ -1189,14 +1190,7 @@ pub fn noop_fold_foreign_item<T: Folder>(ni: P<ForeignItem>, folder: &mut T) ->
attrs
:
attrs
.move_map
(|
x
|
folder
.fold_attribute
(
x
)),
node
:
match
node
{
ForeignItemFn
(
fdec
,
generics
)
=>
{
ForeignItemFn
(
fdec
.map
(|
FnDecl
{
inputs
,
output
,
variadic
}|
FnDecl
{
inputs
:
inputs
.move_map
(|
a
|
folder
.fold_arg
(
a
)),
output
:
match
output
{
Return
(
ty
)
=>
Return
(
folder
.fold_ty
(
ty
)),
NoReturn
(
span
)
=>
NoReturn
(
span
)
},
variadic
:
variadic
}),
folder
.fold_generics
(
generics
))
ForeignItemFn
(
folder
.fold_fn_decl
(
fdec
),
folder
.fold_generics
(
generics
))
}
ForeignItemStatic
(
t
,
m
)
=>
{
ForeignItemStatic
(
folder
.fold_ty
(
t
),
m
)
...
...
src/libsyntax/parse/mod.rs
浏览文件 @
3f0cc801
...
...
@@ -1066,9 +1066,7 @@ fn parser_done(p: Parser){
}),
id
:
ast
::
DUMMY_NODE_ID
}),
output
:
ast
::
Return
(
P
(
ast
::
Ty
{
id
:
ast
::
DUMMY_NODE_ID
,
node
:
ast
::
TyTup
(
vec!
[]),
span
:
sp
(
15
,
15
)})),
// not sure
output
:
ast
::
DefaultReturn
(
sp
(
15
,
15
)),
variadic
:
false
}),
ast
::
Unsafety
::
Normal
,
...
...
src/libsyntax/parse/parser.rs
浏览文件 @
3f0cc801
...
...
@@ -19,7 +19,8 @@
use
ast
::{
BiBitAnd
,
BiBitOr
,
BiBitXor
,
BiRem
,
BiLt
,
BiGt
,
Block
};
use
ast
::{
BlockCheckMode
,
CaptureByRef
,
CaptureByValue
,
CaptureClause
};
use
ast
::{
Crate
,
CrateConfig
,
Decl
,
DeclItem
};
use
ast
::{
DeclLocal
,
DefaultBlock
,
UnDeref
,
BiDiv
,
EMPTY_CTXT
,
EnumDef
,
ExplicitSelf
};
use
ast
::{
DeclLocal
,
DefaultBlock
,
DefaultReturn
};
use
ast
::{
UnDeref
,
BiDiv
,
EMPTY_CTXT
,
EnumDef
,
ExplicitSelf
};
use
ast
::{
Expr
,
Expr_
,
ExprAddrOf
,
ExprMatch
,
ExprAgain
};
use
ast
::{
ExprAssign
,
ExprAssignOp
,
ExprBinary
,
ExprBlock
,
ExprBox
};
use
ast
::{
ExprBreak
,
ExprCall
,
ExprCast
};
...
...
@@ -1426,11 +1427,7 @@ pub fn parse_ret_ty(&mut self) -> FunctionRetTy {
}
}
else
{
let
pos
=
self
.span.lo
;
Return
(
P
(
Ty
{
id
:
ast
::
DUMMY_NODE_ID
,
node
:
TyTup
(
vec!
[]),
span
:
mk_sp
(
pos
,
pos
),
}))
DefaultReturn
(
mk_sp
(
pos
,
pos
))
}
}
...
...
@@ -4548,15 +4545,7 @@ fn parse_fn_block_decl(&mut self)
(
optional_unboxed_closure_kind
,
args
)
}
};
let
output
=
if
self
.check
(
&
token
::
RArrow
)
{
self
.parse_ret_ty
()
}
else
{
Return
(
P
(
Ty
{
id
:
ast
::
DUMMY_NODE_ID
,
node
:
TyInfer
,
span
:
self
.span
,
}))
};
let
output
=
self
.parse_ret_ty
();
(
P
(
FnDecl
{
inputs
:
inputs_captures
,
...
...
@@ -4573,15 +4562,7 @@ fn parse_proc_decl(&mut self) -> P<FnDecl> {
seq_sep_trailing_allowed
(
token
::
Comma
),
|
p
|
p
.parse_fn_block_arg
());
let
output
=
if
self
.check
(
&
token
::
RArrow
)
{
self
.parse_ret_ty
()
}
else
{
Return
(
P
(
Ty
{
id
:
ast
::
DUMMY_NODE_ID
,
node
:
TyInfer
,
span
:
self
.span
,
}))
};
let
output
=
self
.parse_ret_ty
();
P
(
FnDecl
{
inputs
:
inputs
,
...
...
src/libsyntax/print/pprust.rs
浏览文件 @
3f0cc801
...
...
@@ -2351,10 +2351,8 @@ pub fn print_fn_block_args(
try!
(
self
.print_fn_args
(
decl
,
None
));
try!
(
word
(
&
mut
self
.s
,
"|"
));
if
let
ast
::
Return
(
ref
ty
)
=
decl
.output
{
if
ty
.node
==
ast
::
TyInfer
{
return
self
.maybe_print_comment
(
ty
.span.lo
);
}
if
let
ast
::
DefaultReturn
(
..
)
=
decl
.output
{
return
Ok
(());
}
try!
(
self
.space_if_not_bol
());
...
...
@@ -2364,6 +2362,7 @@ pub fn print_fn_block_args(
try!
(
self
.print_type
(
&**
ty
));
self
.maybe_print_comment
(
ty
.span.lo
)
}
ast
::
DefaultReturn
(
..
)
=>
unreachable!
(),
ast
::
NoReturn
(
span
)
=>
{
try!
(
self
.word_nbsp
(
"!"
));
self
.maybe_print_comment
(
span
.lo
)
...
...
@@ -2385,10 +2384,8 @@ pub fn print_proc_args(&mut self, decl: &ast::FnDecl) -> IoResult<()> {
try!
(
self
.print_fn_args
(
decl
,
None
));
try!
(
word
(
&
mut
self
.s
,
")"
));
if
let
ast
::
Return
(
ref
ty
)
=
decl
.output
{
if
ty
.node
==
ast
::
TyInfer
{
return
self
.maybe_print_comment
(
ty
.span.lo
);
}
if
let
ast
::
DefaultReturn
(
..
)
=
decl
.output
{
return
Ok
(());
}
try!
(
self
.space_if_not_bol
());
...
...
@@ -2398,6 +2395,7 @@ pub fn print_proc_args(&mut self, decl: &ast::FnDecl) -> IoResult<()> {
try!
(
self
.print_type
(
&**
ty
));
self
.maybe_print_comment
(
ty
.span.lo
)
}
ast
::
DefaultReturn
(
..
)
=>
unreachable!
(),
ast
::
NoReturn
(
span
)
=>
{
try!
(
self
.word_nbsp
(
"!"
));
self
.maybe_print_comment
(
span
.lo
)
...
...
@@ -2684,13 +2682,8 @@ pub fn print_arg(&mut self, input: &ast::Arg) -> IoResult<()> {
}
pub
fn
print_fn_output
(
&
mut
self
,
decl
:
&
ast
::
FnDecl
)
->
IoResult
<
()
>
{
if
let
ast
::
Return
(
ref
ty
)
=
decl
.output
{
match
ty
.node
{
ast
::
TyTup
(
ref
tys
)
if
tys
.is_empty
()
=>
{
return
self
.maybe_print_comment
(
ty
.span.lo
);
}
_
=>
()
}
if
let
ast
::
DefaultReturn
(
..
)
=
decl
.output
{
return
Ok
(());
}
try!
(
self
.space_if_not_bol
());
...
...
@@ -2699,6 +2692,7 @@ pub fn print_fn_output(&mut self, decl: &ast::FnDecl) -> IoResult<()> {
match
decl
.output
{
ast
::
NoReturn
(
_
)
=>
try!
(
self
.word_nbsp
(
"!"
)),
ast
::
DefaultReturn
(
..
)
=>
unreachable!
(),
ast
::
Return
(
ref
ty
)
=>
try!
(
self
.print_type
(
&**
ty
))
}
...
...
@@ -3071,9 +3065,7 @@ fn test_fun_to_string() {
let
decl
=
ast
::
FnDecl
{
inputs
:
Vec
::
new
(),
output
:
ast
::
Return
(
P
(
ast
::
Ty
{
id
:
0
,
node
:
ast
::
TyTup
(
vec!
[]),
span
:
codemap
::
DUMMY_SP
})),
output
:
ast
::
DefaultReturn
(
codemap
::
DUMMY_SP
),
variadic
:
false
};
let
generics
=
ast_util
::
empty_generics
();
...
...
src/libsyntax/test.rs
浏览文件 @
3f0cc801
...
...
@@ -297,11 +297,8 @@ fn has_test_signature(i: &ast::Item) -> HasTestSignature {
match
&
i
.node
{
&
ast
::
ItemFn
(
ref
decl
,
_
,
_
,
ref
generics
,
_
)
=>
{
let
no_output
=
match
decl
.output
{
ast
::
Return
(
ref
ret_ty
)
=>
match
ret_ty
.node
{
ast
::
TyTup
(
ref
tys
)
if
tys
.is_empty
()
=>
true
,
_
=>
false
,
},
ast
::
NoReturn
(
_
)
=>
false
ast
::
DefaultReturn
(
..
)
=>
true
,
_
=>
false
};
if
decl
.inputs
.is_empty
()
&&
no_output
...
...
@@ -336,11 +333,8 @@ fn has_test_signature(i: &ast::Item) -> bool {
ast
::
ItemFn
(
ref
decl
,
_
,
_
,
ref
generics
,
_
)
=>
{
let
input_cnt
=
decl
.inputs
.len
();
let
no_output
=
match
decl
.output
{
ast
::
Return
(
ref
ret_ty
)
=>
match
ret_ty
.node
{
ast
::
TyTup
(
ref
tys
)
if
tys
.is_empty
()
=>
true
,
_
=>
false
,
},
ast
::
NoReturn
(
_
)
=>
false
ast
::
DefaultReturn
(
..
)
=>
true
,
_
=>
false
};
let
tparm_cnt
=
generics
.ty_params
.len
();
// NB: inadequate check, but we're running
...
...
src/test/pretty/fn-return.rs
0 → 100644
浏览文件 @
3f0cc801
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// pp-exact
// Check that `fn f() -> () { }` does not print as `fn f() { }`.
fn
f
()
->
()
{
}
fn
main
()
{
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录