Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
b8eaa160
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,发现更多精彩内容 >>
提交
b8eaa160
编写于
11月 11, 2015
作者:
B
bors
浏览文件
操作
浏览文件
下载
差异文件
Auto merge of #29778 - Manishearth:rollup, r=Manishearth
- Successful merges: #29677, #29772, #29775, #29777 - Failed merges:
上级
f1f5c04c
26705657
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
113 addition
and
56 deletion
+113
-56
src/libcore/macros.rs
src/libcore/macros.rs
+6
-6
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+19
-7
src/librustc_typeck/diagnostics.rs
src/librustc_typeck/diagnostics.rs
+22
-1
src/libstd/ffi/c_str.rs
src/libstd/ffi/c_str.rs
+32
-40
src/libstd/os/raw.rs
src/libstd/os/raw.rs
+6
-2
src/test/compile-fail/const-pattern-irrefutable.rs
src/test/compile-fail/const-pattern-irrefutable.rs
+28
-0
未找到文件。
src/libcore/macros.rs
浏览文件 @
b8eaa160
...
...
@@ -308,27 +308,27 @@
///
/// ```
/// # trait Foo {
/// # fn foo(&self);
/// # fn bar(&self);
/// # fn baz(&self);
/// # }
/// struct MyStruct;
///
/// impl Foo for MyStruct {
/// fn
foo
(&self) {
/// fn
bar
(&self) {
/// // implementation goes here
/// }
///
/// fn ba
r
(&self) {
/// // let's not worry about implementing ba
r
() for now
/// fn ba
z
(&self) {
/// // let's not worry about implementing ba
z
() for now
/// unimplemented!();
/// }
/// }
///
/// fn main() {
/// let s = MyStruct;
/// s.
foo
();
/// s.
bar
();
///
/// // we aren't even using ba
r
() yet, so this is fine.
/// // we aren't even using ba
z
() yet, so this is fine.
/// }
/// ```
#[macro_export]
...
...
src/librustc_resolve/lib.rs
浏览文件 @
b8eaa160
...
...
@@ -153,7 +153,7 @@ pub enum ResolutionError<'a> {
/// error E0413: declaration shadows an enum variant or unit-like struct in scope
DeclarationShadowsEnumVariantOrUnitLikeStruct
(
Name
),
/// error E0414: only irrefutable patterns allowed here
OnlyIrrefutablePatternsAllowedHere
,
OnlyIrrefutablePatternsAllowedHere
(
DefId
,
Name
)
,
/// error E0415: identifier is bound more than once in this parameter list
IdentifierBoundMoreThanOnceInParameterList
(
&
'a
str
),
/// error E0416: identifier is bound more than once in the same pattern
...
...
@@ -283,8 +283,19 @@ fn resolve_error<'b, 'a:'b, 'tcx:'a>(resolver: &'b Resolver<'a, 'tcx>, span: syn
scope"
,
name
);
},
ResolutionError
::
OnlyIrrefutablePatternsAllowedHere
=>
{
ResolutionError
::
OnlyIrrefutablePatternsAllowedHere
(
did
,
name
)
=>
{
span_err!
(
resolver
.session
,
span
,
E0414
,
"only irrefutable patterns allowed here"
);
resolver
.session
.span_note
(
span
,
"there already is a constant in scope
\
sharing the same name as this pattern"
);
if
let
Some
(
sp
)
=
resolver
.ast_map
.span_if_local
(
did
)
{
resolver
.session
.span_note
(
sp
,
"constant defined here"
);
}
if
let
Some
(
directive
)
=
resolver
.current_module
.import_resolutions
.borrow
()
.get
(
&
name
)
{
let
item
=
resolver
.ast_map
.expect_item
(
directive
.value_id
);
resolver
.session
.span_note
(
item
.span
,
"constant imported here"
);
}
},
ResolutionError
::
IdentifierBoundMoreThanOnceInParameterList
(
identifier
)
=>
{
span_err!
(
resolver
.session
,
span
,
E0415
,
...
...
@@ -632,7 +643,7 @@ enum NameSearchType {
#[derive(Copy,
Clone)]
enum
BareIdentifierPatternResolution
{
FoundStructOrEnumVariant
(
Def
,
LastPrivate
),
FoundConst
(
Def
,
LastPrivate
),
FoundConst
(
Def
,
LastPrivate
,
Name
),
BareIdentifierPatternUnresolved
}
...
...
@@ -2685,7 +2696,7 @@ struct or enum variant",
renamed
)
);
}
FoundConst
(
def
,
lp
)
if
const_ok
=>
{
FoundConst
(
def
,
lp
,
_
)
if
const_ok
=>
{
debug!
(
"(resolving pattern) resolving `{}` to
\
constant"
,
renamed
);
...
...
@@ -2700,11 +2711,12 @@ struct or enum variant",
depth
:
0
});
}
FoundConst
(
..
)
=>
{
FoundConst
(
def
,
_
,
name
)
=>
{
resolve_error
(
self
,
pattern
.span
,
ResolutionError
::
OnlyIrrefutablePatternsAllowedHere
ResolutionError
::
OnlyIrrefutablePatternsAllowedHere
(
def
.def_id
(),
name
)
);
}
BareIdentifierPatternUnresolved
=>
{
...
...
@@ -2929,7 +2941,7 @@ fn resolve_bare_identifier_pattern(&mut self, name: Name, span: Span)
return
FoundStructOrEnumVariant
(
def
,
LastMod
(
AllPublic
));
}
def
@
DefConst
(
..
)
|
def
@
DefAssociatedConst
(
..
)
=>
{
return
FoundConst
(
def
,
LastMod
(
AllPublic
));
return
FoundConst
(
def
,
LastMod
(
AllPublic
)
,
name
);
}
DefStatic
(
..
)
=>
{
resolve_error
(
self
,
...
...
src/librustc_typeck/diagnostics.rs
浏览文件 @
b8eaa160
...
...
@@ -2677,6 +2677,28 @@ fn foo() -> usize { 12 }
.com/rust-lang/rfcs/blob/master/text/0019-opt-in-builtin-traits.md).
"##
,
E0321
:
r##"
A cross-crate opt-out trait was implemented on something which wasn't a struct
or enum type. Erroneous code example:
```
#![feature(optin_builtin_traits)]
struct Foo;
impl !Sync for Foo {}
unsafe impl Send for &'static Foo {
// error: cross-crate traits with a default impl, like `core::marker::Send`,
// can only be implemented for a struct/enum type, not
// `&'static Foo`
```
Only structs and enums are permitted to impl Send, Sync, and other opt-out
trait, and the struct or enum must be local to the current crate. So, for
example, `unsafe impl Send for Rc<Foo>` is not allowed.
"##
,
E0322
:
r##"
The `Sized` trait is a special trait built-in to the compiler for types with a
constant size known at compile-time. This trait is automatically implemented
...
...
@@ -3463,7 +3485,6 @@ fn main() {
// E0246, // invalid recursive type
// E0319, // trait impls for defaulted traits allowed just for structs/enums
E0320
,
// recursive overflow during dropck
E0321
,
// extended coherence rules for defaulted traits violated
E0328
,
// cannot implement Unsize explicitly
E0374
,
// the trait `CoerceUnsized` may only be implemented for a coercion
// between structures with one field being coerced, none found
...
...
src/libstd/ffi/c_str.rs
浏览文件 @
b8eaa160
...
...
@@ -21,6 +21,7 @@
use
mem
;
use
ops
::
Deref
;
use
option
::
Option
::{
self
,
Some
,
None
};
use
os
::
raw
::
c_char
;
use
result
::
Result
::{
self
,
Ok
,
Err
};
use
slice
;
use
str
::{
self
,
Utf8Error
};
...
...
@@ -36,23 +37,20 @@
///
/// A `CString` is created from either a byte slice or a byte vector. After
/// being created, a `CString` predominately inherits all of its methods from
/// the `Deref` implementation to `[libc::c_char]`. Note that the underlying
/// array is represented as an array of `libc::c_char` as opposed to `u8`. A
/// `u8` slice can be obtained with the `as_bytes` method. Slices produced from
/// a `CString` do *not* contain the trailing nul terminator unless otherwise
/// specified.
/// the `Deref` implementation to `[c_char]`. Note that the underlying array
/// is represented as an array of `c_char` as opposed to `u8`. A `u8` slice
/// can be obtained with the `as_bytes` method. Slices produced from a `CString`
/// do *not* contain the trailing nul terminator unless otherwise specified.
///
/// # Examples
///
/// ```no_run
/// # #![feature(libc)]
/// # extern crate libc;
/// # fn main() {
/// use std::ffi::CString;
/// use
libc
;
/// use
std::os::raw::c_char
;
///
/// extern {
/// fn my_printer(s: *const
libc::
c_char);
/// fn my_printer(s: *const c_char);
/// }
///
/// let c_to_print = CString::new("Hello, world!").unwrap();
...
...
@@ -83,11 +81,10 @@ pub struct CString {
/// Inspecting a foreign C string
///
/// ```no_run
/// # #![feature(libc)]
/// extern crate libc;
/// use std::ffi::CStr;
/// use std::os::raw::c_char;
///
/// extern { fn my_string() -> *const
libc::
c_char; }
/// extern { fn my_string() -> *const c_char; }
///
/// fn main() {
/// unsafe {
...
...
@@ -100,12 +97,11 @@ pub struct CString {
/// Passing a Rust-originating C string
///
/// ```no_run
/// # #![feature(libc)]
/// extern crate libc;
/// use std::ffi::{CString, CStr};
/// use std::os::raw::c_char;
///
/// fn work(data: &CStr) {
/// extern { fn work_with(data: *const
libc::
c_char); }
/// extern { fn work_with(data: *const c_char); }
///
/// unsafe { work_with(data.as_ptr()) }
/// }
...
...
@@ -119,11 +115,10 @@ pub struct CString {
/// Converting a foreign C string into a Rust `String`
///
/// ```no_run
/// # #![feature(libc)]
/// extern crate libc;
/// use std::ffi::CStr;
/// use std::os::raw::c_char;
///
/// extern { fn my_string() -> *const
libc::
c_char; }
/// extern { fn my_string() -> *const c_char; }
///
/// fn my_string_safe() -> String {
/// unsafe {
...
...
@@ -139,10 +134,10 @@ pub struct CString {
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
pub
struct
CStr
{
// FIXME: this should not be represented with a DST slice but rather with
// just a raw `
libc::
c_char` along with some form of marker to make
// just a raw `c_char` along with some form of marker to make
// this an unsized type. Essentially `sizeof(&CStr)` should be the
// same as `sizeof(&c_char)` but `CStr` should be an unsized type.
inner
:
[
libc
::
c_char
]
inner
:
[
c_char
]
}
/// An error returned from `CString::new` to indicate that a nul byte was found
...
...
@@ -169,11 +164,10 @@ impl CString {
/// # Examples
///
/// ```no_run
/// # #![feature(libc)]
/// extern crate libc;
/// use std::ffi::CString;
/// use std::os::raw::c_char;
///
/// extern { fn puts(s: *const
libc::
c_char); }
/// extern { fn puts(s: *const c_char); }
///
/// fn main() {
/// let to_print = CString::new("Hello!").unwrap();
...
...
@@ -220,7 +214,7 @@ pub unsafe fn from_vec_unchecked(mut v: Vec<u8>) -> CString {
#[unstable(feature
=
"cstr_memory2"
,
reason
=
"recently added"
,
issue
=
"27769"
)]
#[deprecated(since
=
"1.4.0"
,
reason
=
"renamed to from_raw"
)]
pub
unsafe
fn
from_ptr
(
ptr
:
*
const
libc
::
c_char
)
->
CString
{
pub
unsafe
fn
from_ptr
(
ptr
:
*
const
c_char
)
->
CString
{
CString
::
from_raw
(
ptr
as
*
mut
_
)
}
...
...
@@ -230,7 +224,7 @@ pub unsafe fn from_ptr(ptr: *const libc::c_char) -> CString {
/// `into_raw`. The length of the string will be recalculated
/// using the pointer.
#[stable(feature
=
"cstr_memory"
,
since
=
"1.4.0"
)]
pub
unsafe
fn
from_raw
(
ptr
:
*
mut
libc
::
c_char
)
->
CString
{
pub
unsafe
fn
from_raw
(
ptr
:
*
mut
c_char
)
->
CString
{
let
len
=
libc
::
strlen
(
ptr
)
+
1
;
// Including the NUL byte
let
slice
=
slice
::
from_raw_parts
(
ptr
,
len
as
usize
);
CString
{
inner
:
mem
::
transmute
(
slice
)
}
...
...
@@ -247,7 +241,7 @@ pub unsafe fn from_raw(ptr: *mut libc::c_char) -> CString {
#[unstable(feature
=
"cstr_memory2"
,
reason
=
"recently added"
,
issue
=
"27769"
)]
#[deprecated(since
=
"1.4.0"
,
reason
=
"renamed to into_raw"
)]
pub
fn
into_ptr
(
self
)
->
*
const
libc
::
c_char
{
pub
fn
into_ptr
(
self
)
->
*
const
c_char
{
self
.into_raw
()
as
*
const
_
}
...
...
@@ -260,8 +254,8 @@ pub fn into_ptr(self) -> *const libc::c_char {
///
/// Failure to call `from_raw` will lead to a memory leak.
#[stable(feature
=
"cstr_memory"
,
since
=
"1.4.0"
)]
pub
fn
into_raw
(
self
)
->
*
mut
libc
::
c_char
{
Box
::
into_raw
(
self
.inner
)
as
*
mut
libc
::
c_char
pub
fn
into_raw
(
self
)
->
*
mut
c_char
{
Box
::
into_raw
(
self
.inner
)
as
*
mut
c_char
}
/// Converts the `CString` into a `String` if it contains valid Unicode data.
...
...
@@ -426,15 +420,13 @@ impl CStr {
/// # Examples
///
/// ```no_run
/// # #![feature(libc)]
/// # extern crate libc;
/// # fn main() {
/// use std::ffi::CStr;
/// use std::os::raw::c_char;
/// use std::str;
/// use libc;
///
/// extern {
/// fn my_string() -> *const
libc::
c_char;
/// fn my_string() -> *const c_char;
/// }
///
/// unsafe {
...
...
@@ -445,7 +437,7 @@ impl CStr {
/// # }
/// ```
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
pub
unsafe
fn
from_ptr
<
'a
>
(
ptr
:
*
const
libc
::
c_char
)
->
&
'a
CStr
{
pub
unsafe
fn
from_ptr
<
'a
>
(
ptr
:
*
const
c_char
)
->
&
'a
CStr
{
let
len
=
libc
::
strlen
(
ptr
);
mem
::
transmute
(
slice
::
from_raw_parts
(
ptr
,
len
as
usize
+
1
))
}
...
...
@@ -456,7 +448,7 @@ pub unsafe fn from_ptr<'a>(ptr: *const libc::c_char) -> &'a CStr {
/// to a contiguous region of memory terminated with a 0 byte to represent
/// the end of the string.
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
pub
fn
as_ptr
(
&
self
)
->
*
const
libc
::
c_char
{
pub
fn
as_ptr
(
&
self
)
->
*
const
c_char
{
self
.inner
.as_ptr
()
}
...
...
@@ -560,14 +552,14 @@ fn to_owned(&self) -> CString {
mod
tests
{
use
prelude
::
v1
::
*
;
use
super
::
*
;
use
libc
;
use
os
::
raw
::
c_char
;
use
borrow
::
Cow
::{
Borrowed
,
Owned
};
use
hash
::{
SipHasher
,
Hash
,
Hasher
};
#[test]
fn
c_to_rust
()
{
let
data
=
b
"123
\0
"
;
let
ptr
=
data
.as_ptr
()
as
*
const
libc
::
c_char
;
let
ptr
=
data
.as_ptr
()
as
*
const
c_char
;
unsafe
{
assert_eq!
(
CStr
::
from_ptr
(
ptr
)
.to_bytes
(),
b
"123"
);
assert_eq!
(
CStr
::
from_ptr
(
ptr
)
.to_bytes_with_nul
(),
b
"123
\0
"
);
...
...
@@ -616,13 +608,13 @@ fn borrowed() {
#[test]
fn
to_str
()
{
let
data
=
b
"123
\xE2\x80\xA6\0
"
;
let
ptr
=
data
.as_ptr
()
as
*
const
libc
::
c_char
;
let
ptr
=
data
.as_ptr
()
as
*
const
c_char
;
unsafe
{
assert_eq!
(
CStr
::
from_ptr
(
ptr
)
.to_str
(),
Ok
(
"123…"
));
assert_eq!
(
CStr
::
from_ptr
(
ptr
)
.to_string_lossy
(),
Borrowed
(
"123…"
));
}
let
data
=
b
"123
\xE2\0
"
;
let
ptr
=
data
.as_ptr
()
as
*
const
libc
::
c_char
;
let
ptr
=
data
.as_ptr
()
as
*
const
c_char
;
unsafe
{
assert
!
(
CStr
::
from_ptr
(
ptr
)
.to_str
()
.is_err
());
assert_eq!
(
CStr
::
from_ptr
(
ptr
)
.to_string_lossy
(),
Owned
::
<
str
>
(
format!
(
"123
\
u{FFFD}"
)));
...
...
@@ -632,7 +624,7 @@ fn to_str() {
#[test]
fn
to_owned
()
{
let
data
=
b
"123
\0
"
;
let
ptr
=
data
.as_ptr
()
as
*
const
libc
::
c_char
;
let
ptr
=
data
.as_ptr
()
as
*
const
c_char
;
let
owned
=
unsafe
{
CStr
::
from_ptr
(
ptr
)
.to_owned
()
};
assert_eq!
(
owned
.as_bytes_with_nul
(),
data
);
...
...
@@ -641,7 +633,7 @@ fn to_owned() {
#[test]
fn
equal_hash
()
{
let
data
=
b
"123
\xE2\xFA\xA6\0
"
;
let
ptr
=
data
.as_ptr
()
as
*
const
libc
::
c_char
;
let
ptr
=
data
.as_ptr
()
as
*
const
c_char
;
let
cstr
:
&
'static
CStr
=
unsafe
{
CStr
::
from_ptr
(
ptr
)
};
let
mut
s
=
SipHasher
::
new_with_keys
(
0
,
0
);
...
...
src/libstd/os/raw.rs
浏览文件 @
b8eaa160
...
...
@@ -12,9 +12,13 @@
#![stable(feature
=
"raw_os"
,
since
=
"1.1.0"
)]
#[cfg(any(target_arch
=
"aarch64"
,
target_os
=
"android"
))]
#[cfg(any(target_os
=
"android"
,
all(target_os
=
"linux"
,
any(target_arch
=
"aarch64"
,
target_arch
=
"arm"
))))]
#[stable(feature
=
"raw_os"
,
since
=
"1.1.0"
)]
pub
type
c_char
=
u8
;
#[cfg(not(any(target_arch
=
"aarch64"
,
target_os
=
"android"
)))]
#[cfg(not(any(target_os
=
"android"
,
all(target_os
=
"linux"
,
any(target_arch
=
"aarch64"
,
target_arch
=
"arm"
)))))]
#[stable(feature
=
"raw_os"
,
since
=
"1.1.0"
)]
pub
type
c_char
=
i8
;
#[stable(feature
=
"raw_os"
,
since
=
"1.1.0"
)]
pub
type
c_schar
=
i8
;
#[stable(feature
=
"raw_os"
,
since
=
"1.1.0"
)]
pub
type
c_uchar
=
u8
;
...
...
src/test/compile-fail/const-pattern-irrefutable.rs
0 → 100644
浏览文件 @
b8eaa160
// 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.
mod
foo
{
const
b
:
u8
=
2
;
//~ NOTE constant defined here
const
d
:
u8
=
2
;
//~ NOTE constant defined here
}
use
foo
::
b
as
c
;
//~ NOTE constant imported here
use
foo
::
d
;
//~ NOTE constant imported here
const
a
:
u8
=
2
;
//~ NOTE constant defined here
fn
main
()
{
let
a
=
4
;
//~ ERROR only irrefutable
//~^ NOTE there already is a constant in scope
let
c
=
4
;
//~ ERROR only irrefutable
//~^ NOTE there already is a constant in scope
let
d
=
4
;
//~ ERROR only irrefutable
//~^ NOTE there already is a constant in scope
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录