Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
164f0105
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,发现更多精彩内容 >>
提交
164f0105
编写于
10月 25, 2016
作者:
G
Guillaume Gomez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add safe_suggestion attribute
上级
601bbf26
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
35 addition
and
5 deletion
+35
-5
src/libcollections/lib.rs
src/libcollections/lib.rs
+1
-0
src/libcollections/string.rs
src/libcollections/string.rs
+1
-0
src/librustc/infer/error_reporting.rs
src/librustc/infer/error_reporting.rs
+24
-5
src/libsyntax/feature_gate.rs
src/libsyntax/feature_gate.rs
+9
-0
未找到文件。
src/libcollections/lib.rs
浏览文件 @
164f0105
...
...
@@ -28,6 +28,7 @@
#![cfg_attr(test,
allow(deprecated))]
// rand
#![cfg_attr(not(stage0),
deny(warnings))]
#![cfg_attr(not(stage0),
feature(safe_suggestion))]
#![feature(alloc)]
#![feature(allow_internal_unstable)]
...
...
src/libcollections/string.rs
浏览文件 @
164f0105
...
...
@@ -1231,6 +1231,7 @@ pub unsafe fn as_mut_vec(&mut self) -> &mut Vec<u8> {
/// assert_eq!(a.len(), 3);
/// ```
#[inline]
#[cfg_attr(not(stage0),
safe_suggestion)]
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
pub
fn
len
(
&
self
)
->
usize
{
self
.vec
.len
()
...
...
src/librustc/infer/error_reporting.rs
浏览文件 @
164f0105
...
...
@@ -587,19 +587,29 @@ pub fn note_type_err(&self,
// look for expected with found id
self
.tcx
.populate_inherent_implementations_for_type_if_necessary
(
found
);
if
let
Some
(
impl_infos
)
=
self
.tcx.inherent_impls
.borrow
()
.get
(
&
found
)
{
let
mut
methods
=
Vec
::
new
();
let
mut
methods
:
Vec
<
(
Option
<
ast
::
Attribute
>
,
DefId
,
ImplOrTraitItem
<
'tcx
>
)
>
=
Vec
::
new
();
for
impl_
in
impl_infos
{
methods
.append
(
&
mut
self
.tcx
.impl_or_trait_items
(
*
impl_
)
.iter
()
.map
(|
&
did
|
self
.tcx
.impl_or_trait_item
(
did
))
.filter
(|
x
|
{
.map
(|
&
did
|
(
None
,
did
,
self
.tcx
.impl_or_trait_item
(
did
)
))
.filter
(|
&
(
_
,
_
,
ref
x
)
|
{
self
.matches_return_type
(
x
,
&
expected_ty
)
})
.collect
());
}
for
method
in
methods
{
println!
(
"==> {:?}"
,
method
.name
());
let
safe_suggestions
:
Vec
<
_
>
=
methods
.iter
()
.map
(|
&
(
_
,
ref
id
,
ref
x
)|
(
self
.find_attr
(
*
id
,
"safe_suggestion"
),
id
,
x
))
.filter
(|
&
(
ref
res
,
_
,
_
)|
res
.is_some
())
.collect
();
if
safe_suggestions
.len
()
>
0
{
for
(
_
,
_
,
method
)
in
safe_suggestions
{
println!
(
"safe ==> {:?}"
,
method
.name
());
}
}
else
{
for
&
(
_
,
_
,
ref
method
)
in
methods
.iter
()
{
println!
(
"not safe ==> {:?}"
,
method
.name
());
}
}
}
}
...
...
@@ -615,6 +625,15 @@ pub fn note_type_err(&self,
self
.tcx
.note_and_explain_type_err
(
diag
,
terr
,
span
);
}
fn
find_attr
(
&
self
,
def_id
:
DefId
,
attr_name
:
&
str
)
->
Option
<
ast
::
Attribute
>
{
for
item
in
self
.tcx
.get_attrs
(
def_id
)
.iter
()
{
if
item
.check_name
(
attr_name
)
{
return
Some
(
item
.clone
());
}
}
None
}
pub
fn
report_and_explain_type_error
(
&
self
,
trace
:
TypeTrace
<
'tcx
>
,
terr
:
&
TypeError
<
'tcx
>
)
...
...
src/libsyntax/feature_gate.rs
浏览文件 @
164f0105
...
...
@@ -304,6 +304,7 @@ pub fn new() -> Features {
// Allows using `Self` and associated types in struct expressions and patterns.
(
active
,
more_struct_aliases
,
"1.14.0"
,
Some
(
37544
)),
// Allows #[link(..., cfg(..))]
(
active
,
link_cfg
,
"1.14.0"
,
Some
(
37406
)),
...
...
@@ -314,6 +315,9 @@ pub fn new() -> Features {
// Allows #[target_feature(...)]
(
active
,
target_feature
,
"1.15.0"
,
None
),
// Allow safe suggestions for potential type conversions.
(
active
,
safe_suggestion
,
"1.0.0"
,
Some
(
37384
)),
);
declare_features!
(
...
...
@@ -648,6 +652,11 @@ pub fn deprecated_attributes() -> Vec<&'static (&'static str, AttributeType, Att
"internal implementation detail"
,
cfg_fn!
(
rustc_attrs
))),
(
"safe_suggestion"
,
Whitelisted
,
Gated
(
"safe_suggestion"
,
"the `#[safe_suggestion]` attribute
\
is an experimental feature"
,
cfg_fn!
(
safe_suggestion
))),
// FIXME: #14408 whitelist docs since rustdoc looks at them
(
"doc"
,
Whitelisted
,
Ungated
),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录