Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
1e9bef91
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,发现更多精彩内容 >>
提交
1e9bef91
编写于
2月 26, 2015
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed-size byte string literals (RFC 339)
上级
bfac337d
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
100 addition
and
43 deletion
+100
-43
src/librustc_trans/trans/consts.rs
src/librustc_trans/trans/consts.rs
+1
-8
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/mod.rs
+5
-4
src/libstd/ffi/c_str.rs
src/libstd/ffi/c_str.rs
+17
-0
src/libstd/io/buffered.rs
src/libstd/io/buffered.rs
+2
-2
src/libstd/io/cursor.rs
src/libstd/io/cursor.rs
+17
-0
src/libstd/old_io/util.rs
src/libstd/old_io/util.rs
+2
-1
src/libstd/old_path/mod.rs
src/libstd/old_path/mod.rs
+20
-0
src/libstd/old_path/posix.rs
src/libstd/old_path/posix.rs
+15
-15
src/libstd/old_path/windows.rs
src/libstd/old_path/windows.rs
+6
-6
src/test/run-pass/byte-literals.rs
src/test/run-pass/byte-literals.rs
+15
-7
未找到文件。
src/librustc_trans/trans/consts.rs
浏览文件 @
1e9bef91
...
...
@@ -75,14 +75,7 @@ pub fn const_lit(cx: &CrateContext, e: &ast::Expr, lit: &ast::Lit)
ast
::
LitBool
(
b
)
=>
C_bool
(
cx
,
b
),
ast
::
LitStr
(
ref
s
,
_
)
=>
C_str_slice
(
cx
,
(
*
s
)
.clone
()),
ast
::
LitBinary
(
ref
data
)
=>
{
let
g
=
addr_of
(
cx
,
C_bytes
(
cx
,
&
data
[
..
]),
"binary"
,
e
.id
);
let
base
=
ptrcast
(
g
,
Type
::
i8p
(
cx
));
let
prev_const
=
cx
.const_unsized
()
.borrow_mut
()
.insert
(
base
,
g
);
assert
!
(
prev_const
.is_none
()
||
prev_const
==
Some
(
g
));
assert_eq!
(
abi
::
FAT_PTR_ADDR
,
0
);
assert_eq!
(
abi
::
FAT_PTR_EXTRA
,
1
);
C_struct
(
cx
,
&
[
base
,
C_uint
(
cx
,
data
.len
())],
false
)
addr_of
(
cx
,
C_bytes
(
cx
,
&
data
[
..
]),
"binary"
,
e
.id
)
}
}
}
...
...
src/librustc_typeck/check/mod.rs
浏览文件 @
1e9bef91
...
...
@@ -2505,10 +2505,11 @@ fn check_lit<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
match
lit
.node
{
ast
::
LitStr
(
..
)
=>
ty
::
mk_str_slice
(
tcx
,
tcx
.mk_region
(
ty
::
ReStatic
),
ast
::
MutImmutable
),
ast
::
LitBinary
(
..
)
=>
{
ty
::
mk_slice
(
tcx
,
tcx
.mk_region
(
ty
::
ReStatic
),
ty
::
mt
{
ty
:
tcx
.types.u8
,
mutbl
:
ast
::
MutImmutable
})
ast
::
LitBinary
(
ref
v
)
=>
{
ty
::
mk_rptr
(
tcx
,
tcx
.mk_region
(
ty
::
ReStatic
),
ty
::
mt
{
ty
:
ty
::
mk_vec
(
tcx
,
tcx
.types.u8
,
Some
(
v
.len
())),
mutbl
:
ast
::
MutImmutable
,
})
}
ast
::
LitByte
(
_
)
=>
tcx
.types.u8
,
ast
::
LitChar
(
_
)
=>
tcx
.types.char
,
...
...
src/libstd/ffi/c_str.rs
浏览文件 @
1e9bef91
...
...
@@ -451,6 +451,23 @@ impl IntoBytes for Vec<u8> {
fn
into_bytes
(
self
)
->
Vec
<
u8
>
{
self
}
}
macro_rules!
array_impls
{
(
$
(
$N
:
expr
)
+
)
=>
{
$
(
impl
<
'a
>
IntoBytes
for
&
'a
[
u8
;
$N
]
{
fn
into_bytes
(
self
)
->
Vec
<
u8
>
{
self
.to_vec
()
}
}
)
+
}
}
array_impls!
{
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
}
#[cfg(test)]
mod
tests
{
use
prelude
::
v1
::
*
;
...
...
src/libstd/io/buffered.rs
浏览文件 @
1e9bef91
...
...
@@ -622,7 +622,7 @@ fn test_line_buffer() {
#[test]
fn
test_read_line
()
{
let
in_buf
=
b
"a
\n
b
\n
c"
;
let
in_buf
:
&
[
u8
]
=
b
"a
\n
b
\n
c"
;
let
mut
reader
=
BufReader
::
with_capacity
(
2
,
in_buf
);
let
mut
s
=
String
::
new
();
reader
.read_line
(
&
mut
s
)
.unwrap
();
...
...
@@ -640,7 +640,7 @@ fn test_read_line() {
#[test]
fn
test_lines
()
{
let
in_buf
=
b
"a
\n
b
\n
c"
;
let
in_buf
:
&
[
u8
]
=
b
"a
\n
b
\n
c"
;
let
reader
=
BufReader
::
with_capacity
(
2
,
in_buf
);
let
mut
it
=
reader
.lines
();
assert_eq!
(
it
.next
(),
Some
(
Ok
(
"a"
.to_string
())));
...
...
src/libstd/io/cursor.rs
浏览文件 @
1e9bef91
...
...
@@ -129,6 +129,23 @@ fn fill_buf(&mut self) -> io::Result<&[u8]> {
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
impl
<
'a
>
BufRead
for
Cursor
<
Vec
<
u8
>>
{
buffer!
();
}
macro_rules!
array_impls
{
(
$
(
$N
:
expr
)
+
)
=>
{
$
(
impl
<
'a
>
io
::
Seek
for
Cursor
<&
'a
[
u8
;
$N
]
>
{
seek!
();
}
impl
<
'a
>
Read
for
Cursor
<&
'a
[
u8
;
$N
]
>
{
read!
();
}
impl
<
'a
>
BufRead
for
Cursor
<&
'a
[
u8
;
$N
]
>
{
buffer!
();
}
)
+
}
}
array_impls!
{
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
}
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
impl
<
'a
>
Write
for
Cursor
<&
'a
mut
[
u8
]
>
{
fn
write
(
&
mut
self
,
data
:
&
[
u8
])
->
io
::
Result
<
usize
>
{
...
...
src/libstd/old_io/util.rs
浏览文件 @
1e9bef91
...
...
@@ -445,7 +445,8 @@ fn test_copy() {
#[test]
fn
limit_reader_buffer
()
{
let
r
=
&
mut
b
"0123456789
\n
0123456789
\n
"
;
let
mut
r
:
&
[
u8
]
=
b
"0123456789
\n
0123456789
\n
"
;
let
r
=
&
mut
r
;
{
let
mut
r
=
LimitReader
::
new
(
r
.by_ref
(),
3
);
assert_eq!
(
r
.read_line
(),
Ok
(
"012"
.to_string
()));
...
...
src/libstd/old_path/mod.rs
浏览文件 @
1e9bef91
...
...
@@ -895,6 +895,26 @@ fn container_as_bytes(&self) -> &[u8] {
}
}
macro_rules!
array_impls
{
(
$
(
$N
:
expr
)
+
)
=>
{
$
(
impl
BytesContainer
for
[
u8
;
$N
]
{
#[inline]
fn
container_as_bytes
(
&
self
)
->
&
[
u8
]
{
&
self
[
..
]
}
}
)
+
}
}
array_impls!
{
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
}
impl
BytesContainer
for
Vec
<
u8
>
{
#[inline]
fn
container_as_bytes
(
&
self
)
->
&
[
u8
]
{
...
...
src/libstd/old_path/posix.rs
浏览文件 @
1e9bef91
...
...
@@ -632,9 +632,9 @@ fn test_components() {
);
}
t!
(
v
:
b
"a/b/c"
,
filename
,
Some
(
b
"c"
));
t!
(
v
:
b
"a/b/c
\xFF
"
,
filename
,
Some
(
b
"c
\xFF
"
));
t!
(
v
:
b
"a/b
\xFF
/c"
,
filename
,
Some
(
b
"c"
));
t!
(
v
:
b
"a/b/c"
,
filename
,
Some
(
&
b
"c"
[
..
]
));
t!
(
v
:
b
"a/b/c
\xFF
"
,
filename
,
Some
(
&
b
"c
\xFF
"
[
..
]
));
t!
(
v
:
b
"a/b
\xFF
/c"
,
filename
,
Some
(
&
b
"c"
[
..
]
));
t!
(
s
:
"a/b/c"
,
filename
,
Some
(
"c"
),
opt
);
t!
(
s
:
"/a/b/c"
,
filename
,
Some
(
"c"
),
opt
);
t!
(
s
:
"a"
,
filename
,
Some
(
"a"
),
opt
);
...
...
@@ -656,9 +656,9 @@ fn test_components() {
t!
(
s
:
".."
,
dirname
,
".."
);
t!
(
s
:
"../.."
,
dirname
,
"../.."
);
t!
(
v
:
b
"hi/there.txt"
,
filestem
,
Some
(
b
"there"
));
t!
(
v
:
b
"hi/there
\x80
.txt"
,
filestem
,
Some
(
b
"there
\x80
"
));
t!
(
v
:
b
"hi/there.t
\x80
xt"
,
filestem
,
Some
(
b
"there"
));
t!
(
v
:
b
"hi/there.txt"
,
filestem
,
Some
(
&
b
"there"
[
..
]
));
t!
(
v
:
b
"hi/there
\x80
.txt"
,
filestem
,
Some
(
&
b
"there
\x80
"
[
..
]
));
t!
(
v
:
b
"hi/there.t
\x80
xt"
,
filestem
,
Some
(
&
b
"there"
[
..
]
));
t!
(
s
:
"hi/there.txt"
,
filestem
,
Some
(
"there"
),
opt
);
t!
(
s
:
"hi/there"
,
filestem
,
Some
(
"there"
),
opt
);
t!
(
s
:
"there.txt"
,
filestem
,
Some
(
"there"
),
opt
);
...
...
@@ -672,9 +672,9 @@ fn test_components() {
t!
(
s
:
".."
,
filestem
,
None
,
opt
);
t!
(
s
:
"../.."
,
filestem
,
None
,
opt
);
t!
(
v
:
b
"hi/there.txt"
,
extension
,
Some
(
b
"txt"
));
t!
(
v
:
b
"hi/there
\x80
.txt"
,
extension
,
Some
(
b
"txt"
));
t!
(
v
:
b
"hi/there.t
\x80
xt"
,
extension
,
Some
(
b
"t
\x80
xt"
));
t!
(
v
:
b
"hi/there.txt"
,
extension
,
Some
(
&
b
"txt"
[
..
]
));
t!
(
v
:
b
"hi/there
\x80
.txt"
,
extension
,
Some
(
&
b
"txt"
[
..
]
));
t!
(
v
:
b
"hi/there.t
\x80
xt"
,
extension
,
Some
(
&
b
"t
\x80
xt"
[
..
]
));
t!
(
v
:
b
"hi/there"
,
extension
,
None
);
t!
(
v
:
b
"hi/there
\x80
"
,
extension
,
None
);
t!
(
s
:
"hi/there.txt"
,
extension
,
Some
(
"txt"
),
opt
);
...
...
@@ -756,8 +756,8 @@ fn test_push_many() {
t!
(
s
:
"a/b/c"
,
[
"d"
,
"/e"
],
"/e"
);
t!
(
s
:
"a/b/c"
,
[
"d"
,
"/e"
,
"f"
],
"/e/f"
);
t!
(
s
:
"a/b/c"
,
[
"d"
.to_string
(),
"e"
.to_string
()],
"a/b/c/d/e"
);
t!
(
v
:
b
"a/b/c"
,
[
b
"d"
,
b
"e"
],
b
"a/b/c/d/e"
);
t!
(
v
:
b
"a/b/c"
,
[
b
"d"
,
b
"/e"
,
b
"f"
],
b
"/e/f"
);
t!
(
v
:
b
"a/b/c"
,
[
&
b
"d"
[
..
],
&
b
"e"
[
..
]
],
b
"a/b/c/d/e"
);
t!
(
v
:
b
"a/b/c"
,
[
&
b
"d"
[
..
],
&
b
"/e"
[
..
],
&
b
"f"
[
..
]
],
b
"/e/f"
);
t!
(
v
:
b
"a/b/c"
,
[
b
"d"
.to_vec
(),
b
"e"
.to_vec
()],
b
"a/b/c/d/e"
);
}
...
...
@@ -983,10 +983,10 @@ fn test_getters() {
)
}
t!
(
v
:
Path
::
new
(
b
"a/b/c"
),
Some
(
b
"c"
),
b
"a/b"
,
Some
(
b
"c"
),
None
);
t!
(
v
:
Path
::
new
(
b
"a/b/
\xFF
"
),
Some
(
b
"
\xFF
"
),
b
"a/b"
,
Some
(
b
"
\xFF
"
),
None
);
t!
(
v
:
Path
::
new
(
b
"hi/there.
\xFF
"
),
Some
(
b
"there.
\xFF
"
),
b
"hi"
,
Some
(
b
"there"
),
Some
(
b
"
\xFF
"
));
t!
(
v
:
Path
::
new
(
b
"a/b/c"
),
Some
(
&
b
"c"
[
..
]),
b
"a/b"
,
Some
(
&
b
"c"
[
..
]
),
None
);
t!
(
v
:
Path
::
new
(
b
"a/b/
\xFF
"
),
Some
(
&
b
"
\xFF
"
[
..
]),
b
"a/b"
,
Some
(
&
b
"
\xFF
"
[
..
]
),
None
);
t!
(
v
:
Path
::
new
(
b
"hi/there.
\xFF
"
),
Some
(
&
b
"there.
\xFF
"
[
..
]
),
b
"hi"
,
Some
(
&
b
"there"
[
..
]),
Some
(
&
b
"
\xFF
"
[
..
]
));
t!
(
s
:
Path
::
new
(
"a/b/c"
),
Some
(
"c"
),
Some
(
"a/b"
),
Some
(
"c"
),
None
);
t!
(
s
:
Path
::
new
(
"."
),
None
,
Some
(
"."
),
None
,
None
);
t!
(
s
:
Path
::
new
(
"/"
),
None
,
Some
(
"/"
),
None
,
None
);
...
...
src/libstd/old_path/windows.rs
浏览文件 @
1e9bef91
...
...
@@ -1397,7 +1397,7 @@ fn test_components() {
)
}
t!
(
v
:
b
"a
\\
b
\\
c"
,
filename
,
Some
(
b
"c"
));
t!
(
v
:
b
"a
\\
b
\\
c"
,
filename
,
Some
(
&
b
"c"
[
..
]
));
t!
(
s
:
"a
\\
b
\\
c"
,
filename_str
,
"c"
);
t!
(
s
:
"
\\
a
\\
b
\\
c"
,
filename_str
,
"c"
);
t!
(
s
:
"a"
,
filename_str
,
"a"
);
...
...
@@ -1461,7 +1461,7 @@ fn test_components() {
t!
(
s
:
"
\\\\
.
\\
foo"
,
dirname_str
,
"
\\\\
.
\\
foo"
);
t!
(
s
:
"
\\\\
?
\\
a
\\
b
\\
"
,
dirname_str
,
"
\\\\
?
\\
a"
);
t!
(
v
:
b
"hi
\\
there.txt"
,
filestem
,
Some
(
b
"there"
));
t!
(
v
:
b
"hi
\\
there.txt"
,
filestem
,
Some
(
&
b
"there"
[
..
]
));
t!
(
s
:
"hi
\\
there.txt"
,
filestem_str
,
"there"
);
t!
(
s
:
"hi
\\
there"
,
filestem_str
,
"there"
);
t!
(
s
:
"there.txt"
,
filestem_str
,
"there"
);
...
...
@@ -1476,7 +1476,7 @@ fn test_components() {
t!
(
s
:
"..
\\
.."
,
filestem_str
,
None
,
opt
);
// filestem is based on filename, so we don't need the full set of prefix tests
t!
(
v
:
b
"hi
\\
there.txt"
,
extension
,
Some
(
b
"txt"
));
t!
(
v
:
b
"hi
\\
there.txt"
,
extension
,
Some
(
&
b
"txt"
[
..
]
));
t!
(
v
:
b
"hi
\\
there"
,
extension
,
None
);
t!
(
s
:
"hi
\\
there.txt"
,
extension_str
,
Some
(
"txt"
),
opt
);
t!
(
s
:
"hi
\\
there"
,
extension_str
,
None
,
opt
);
...
...
@@ -1603,8 +1603,8 @@ fn test_push_many() {
t!
(
s
:
"a
\\
b
\\
c"
,
[
"d"
,
"
\\
e"
],
"
\\
e"
);
t!
(
s
:
"a
\\
b
\\
c"
,
[
"d"
,
"
\\
e"
,
"f"
],
"
\\
e
\\
f"
);
t!
(
s
:
"a
\\
b
\\
c"
,
[
"d"
.to_string
(),
"e"
.to_string
()],
"a
\\
b
\\
c
\\
d
\\
e"
);
t!
(
v
:
b
"a
\\
b
\\
c"
,
[
b
"d"
,
b
"e"
],
b
"a
\\
b
\\
c
\\
d
\\
e"
);
t!
(
v
:
b
"a
\\
b
\\
c"
,
[
b
"d"
,
b
"
\\
e"
,
b
"f"
],
b
"
\\
e
\\
f"
);
t!
(
v
:
b
"a
\\
b
\\
c"
,
[
&
b
"d"
[
..
],
&
b
"e"
[
..
]
],
b
"a
\\
b
\\
c
\\
d
\\
e"
);
t!
(
v
:
b
"a
\\
b
\\
c"
,
[
&
b
"d"
[
..
],
&
b
"
\\
e"
[
..
],
&
b
"f"
[
..
]
],
b
"
\\
e
\\
f"
);
t!
(
v
:
b
"a
\\
b
\\
c"
,
[
b
"d"
.to_vec
(),
b
"e"
.to_vec
()],
b
"a
\\
b
\\
c
\\
d
\\
e"
);
}
...
...
@@ -1898,7 +1898,7 @@ fn test_getters() {
)
}
t!
(
v
:
Path
::
new
(
b
"a
\\
b
\\
c"
),
Some
(
b
"c"
),
b
"a
\\
b"
,
Some
(
b
"c"
),
None
);
t!
(
v
:
Path
::
new
(
b
"a
\\
b
\\
c"
),
Some
(
&
b
"c"
[
..
]),
b
"a
\\
b"
,
Some
(
&
b
"c"
[
..
]
),
None
);
t!
(
s
:
Path
::
new
(
"a
\\
b
\\
c"
),
Some
(
"c"
),
Some
(
"a
\\
b"
),
Some
(
"c"
),
None
);
t!
(
s
:
Path
::
new
(
"."
),
None
,
Some
(
"."
),
None
,
None
);
t!
(
s
:
Path
::
new
(
"
\\
"
),
None
,
Some
(
"
\\
"
),
None
,
None
);
...
...
src/test/run-pass/byte-literals.rs
浏览文件 @
1e9bef91
...
...
@@ -13,9 +13,13 @@
static
FOO
:
u8
=
b
'\xF0'
;
static
BAR
:
&
'static
[
u8
]
=
b
"a
\xF0\t
"
;
static
BAR_FIXED
:
&
'static
[
u8
;
3
]
=
b
"a
\xF0\t
"
;
static
BAZ
:
&
'static
[
u8
]
=
br
"a
\n
"
;
pub
fn
main
()
{
let
bar
:
&
'static
[
u8
]
=
b
"a
\xF0\t
"
;
let
bar_fixed
:
&
'static
[
u8
;
3
]
=
b
"a
\xF0\t
"
;
assert_eq!
(
b
'a'
,
97u8
);
assert_eq!
(
b
'\n'
,
10u8
);
assert_eq!
(
b
'\r'
,
13u8
);
...
...
@@ -44,19 +48,23 @@ pub fn main() {
b"
,
expected
);
let
expected
:
&
[
_
]
=
&
[
97u8
,
240u8
,
9u8
];
assert_eq!
(
BAR
,
expected
);
assert_eq!
(
BAR_FIXED
,
expected
);
assert_eq!
(
bar
,
expected
);
assert_eq!
(
bar_fixed
,
expected
);
let
val
:
&
[
_
]
=
&
[
97u8
,
10u8
];
let
val
=
&
[
97u8
,
10u8
];
match
val
{
b
"a
\n
"
=>
{},
_
=>
panic!
(),
}
let
buf
=
vec!
(
97u8
,
98
,
99
,
100
);
assert_eq!
(
match
&
buf
[
0
..
3
]
{
b
"def"
=>
1_u
size
,
b
"abc"
=>
2_u
size
,
_
=>
3_u
size
},
2
);
// FIXME: There are no DST coercions &[T; N] -> &[T] in patterns
// let buf = vec!(97u8, 98, 99, 100);
// assert_eq!(match &buf[0..3] {
// b"def" => 1_usize,
// b"abc" => 2_usize,
// _ => 3_usize
// }, 2);
let
expected
:
&
[
_
]
=
&
[
97u8
,
92u8
,
110u8
];
assert_eq!
(
BAZ
,
expected
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录