Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
a256a663
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,发现更多精彩内容 >>
提交
a256a663
编写于
10月 02, 2018
作者:
L
ljedrz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustc/middle: use Cow<'static, str> where applicable
上级
c2b3aa99
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
41 addition
and
38 deletion
+41
-38
src/librustc/middle/mem_categorization.rs
src/librustc/middle/mem_categorization.rs
+18
-17
src/librustc/middle/resolve_lifetime.rs
src/librustc/middle/resolve_lifetime.rs
+8
-7
src/librustc_borrowck/borrowck/mod.rs
src/librustc_borrowck/borrowck/mod.rs
+15
-14
未找到文件。
src/librustc/middle/mem_categorization.rs
浏览文件 @
a256a663
...
@@ -83,6 +83,7 @@
...
@@ -83,6 +83,7 @@
use
syntax
::
ast
::{
self
,
Name
};
use
syntax
::
ast
::{
self
,
Name
};
use
syntax_pos
::
Span
;
use
syntax_pos
::
Span
;
use
std
::
borrow
::
Cow
;
use
std
::
fmt
;
use
std
::
fmt
;
use
std
::
hash
::{
Hash
,
Hasher
};
use
std
::
hash
::{
Hash
,
Hasher
};
use
rustc_data_structures
::
sync
::
Lrc
;
use
rustc_data_structures
::
sync
::
Lrc
;
...
@@ -1489,59 +1490,59 @@ pub fn upvar_cat(&self) -> Option<&Categorization<'tcx>> {
...
@@ -1489,59 +1490,59 @@ pub fn upvar_cat(&self) -> Option<&Categorization<'tcx>> {
}
}
}
}
pub
fn
descriptive_string
(
&
self
,
tcx
:
TyCtxt
<
'_
,
'_
,
'_
>
)
->
String
{
pub
fn
descriptive_string
(
&
self
,
tcx
:
TyCtxt
<
'_
,
'_
,
'_
>
)
->
Cow
<
'static
,
str
>
{
match
self
.cat
{
match
self
.cat
{
Categorization
::
StaticItem
=>
{
Categorization
::
StaticItem
=>
{
"static item"
.
to_string
()
"static item"
.
into
()
}
}
Categorization
::
Rvalue
(
..
)
=>
{
Categorization
::
Rvalue
(
..
)
=>
{
"non-place"
.
to_string
()
"non-place"
.
into
()
}
}
Categorization
::
Local
(
vid
)
=>
{
Categorization
::
Local
(
vid
)
=>
{
if
tcx
.hir
.is_argument
(
vid
)
{
if
tcx
.hir
.is_argument
(
vid
)
{
"argument"
.to_string
()
"argument"
}
else
{
}
else
{
"local variable"
.to_string
()
"local variable"
}
}
.into
()
}
}
Categorization
::
Deref
(
_
,
pk
)
=>
{
Categorization
::
Deref
(
_
,
pk
)
=>
{
match
self
.upvar_cat
()
{
match
self
.upvar_cat
()
{
Some
(
&
Categorization
::
Upvar
(
ref
var
))
=>
{
Some
(
&
Categorization
::
Upvar
(
ref
var
))
=>
{
var
.to_string
()
var
.to_string
()
.into
()
}
}
Some
(
_
)
=>
bug!
(),
Some
(
_
)
=>
bug!
(),
None
=>
{
None
=>
{
match
pk
{
match
pk
{
Unique
=>
{
Unique
=>
{
"`Box` content"
.to_string
()
"`Box` content"
}
}
UnsafePtr
(
..
)
=>
{
UnsafePtr
(
..
)
=>
{
"dereference of raw pointer"
.to_string
()
"dereference of raw pointer"
}
}
BorrowedPtr
(
..
)
=>
{
BorrowedPtr
(
..
)
=>
{
match
self
.note
{
match
self
.note
{
NoteIndex
=>
"indexed content"
.to_string
()
,
NoteIndex
=>
"indexed content"
,
_
=>
"borrowed content"
.to_string
(),
_
=>
"borrowed content"
}
}
}
}
}
}
.into
()
}
}
}
}
}
}
Categorization
::
Interior
(
_
,
InteriorField
(
..
))
=>
{
Categorization
::
Interior
(
_
,
InteriorField
(
..
))
=>
{
"field"
.
to_string
()
"field"
.
into
()
}
}
Categorization
::
Interior
(
_
,
InteriorElement
(
InteriorOffsetKind
::
Index
))
=>
{
Categorization
::
Interior
(
_
,
InteriorElement
(
InteriorOffsetKind
::
Index
))
=>
{
"indexed content"
.
to_string
()
"indexed content"
.
into
()
}
}
Categorization
::
Interior
(
_
,
InteriorElement
(
InteriorOffsetKind
::
Pattern
))
=>
{
Categorization
::
Interior
(
_
,
InteriorElement
(
InteriorOffsetKind
::
Pattern
))
=>
{
"pattern-bound indexed content"
.
to_string
()
"pattern-bound indexed content"
.
into
()
}
}
Categorization
::
Upvar
(
ref
var
)
=>
{
Categorization
::
Upvar
(
ref
var
)
=>
{
var
.to_string
()
var
.to_string
()
.into
()
}
}
Categorization
::
Downcast
(
ref
cmt
,
_
)
=>
{
Categorization
::
Downcast
(
ref
cmt
,
_
)
=>
{
cmt
.descriptive_string
(
tcx
)
cmt
.descriptive_string
(
tcx
)
.into
()
}
}
}
}
}
}
...
...
src/librustc/middle/resolve_lifetime.rs
浏览文件 @
a256a663
...
@@ -25,6 +25,7 @@
...
@@ -25,6 +25,7 @@
use
rustc
::
lint
;
use
rustc
::
lint
;
use
rustc_data_structures
::
sync
::
Lrc
;
use
rustc_data_structures
::
sync
::
Lrc
;
use
session
::
Session
;
use
session
::
Session
;
use
std
::
borrow
::
Cow
;
use
std
::
cell
::
Cell
;
use
std
::
cell
::
Cell
;
use
std
::
mem
::
replace
;
use
std
::
mem
::
replace
;
use
syntax
::
ast
;
use
syntax
::
ast
;
...
@@ -1250,8 +1251,8 @@ fn compute_object_lifetime_defaults(
...
@@ -1250,8 +1251,8 @@ fn compute_object_lifetime_defaults(
let
object_lifetime_default_reprs
:
String
=
result
let
object_lifetime_default_reprs
:
String
=
result
.iter
()
.iter
()
.map
(|
set
|
match
*
set
{
.map
(|
set
|
match
*
set
{
Set1
::
Empty
=>
"BaseDefault"
.
to_string
(),
Set1
::
Empty
=>
"BaseDefault"
.
into
(),
Set1
::
One
(
Region
::
Static
)
=>
"'static"
.
to_string
(),
Set1
::
One
(
Region
::
Static
)
=>
"'static"
.
into
(),
Set1
::
One
(
Region
::
EarlyBound
(
mut
i
,
_
,
_
))
=>
{
Set1
::
One
(
Region
::
EarlyBound
(
mut
i
,
_
,
_
))
=>
{
generics
.params
.iter
()
.find_map
(|
param
|
match
param
.kind
{
generics
.params
.iter
()
.find_map
(|
param
|
match
param
.kind
{
GenericParamKind
::
Lifetime
{
..
}
=>
{
GenericParamKind
::
Lifetime
{
..
}
=>
{
...
@@ -1265,9 +1266,9 @@ fn compute_object_lifetime_defaults(
...
@@ -1265,9 +1266,9 @@ fn compute_object_lifetime_defaults(
})
.unwrap
()
})
.unwrap
()
}
}
Set1
::
One
(
_
)
=>
bug!
(),
Set1
::
One
(
_
)
=>
bug!
(),
Set1
::
Many
=>
"Ambiguous"
.
to_string
(),
Set1
::
Many
=>
"Ambiguous"
.
into
(),
})
})
.collect
::
<
Vec
<
String
>>
()
.collect
::
<
Vec
<
Cow
<
'static
,
str
>
>>
()
.join
(
","
);
.join
(
","
);
tcx
.sess
.span_err
(
item
.span
,
&
object_lifetime_default_reprs
);
tcx
.sess
.span_err
(
item
.span
,
&
object_lifetime_default_reprs
);
}
}
...
@@ -2652,10 +2653,10 @@ pub fn report_missing_lifetime_specifiers(
...
@@ -2652,10 +2653,10 @@ pub fn report_missing_lifetime_specifiers(
if
count
>
1
{
"s"
}
else
{
""
}
if
count
>
1
{
"s"
}
else
{
""
}
);
);
let
msg
=
if
count
>
1
{
let
msg
:
Cow
<
'static
,
str
>
=
if
count
>
1
{
format!
(
"expected {} lifetime parameters"
,
count
)
format!
(
"expected {} lifetime parameters"
,
count
)
.into
()
}
else
{
}
else
{
"expected lifetime parameter"
.
to_string
()
"expected lifetime parameter"
.
into
()
};
};
err
.span_label
(
span
,
msg
);
err
.span_label
(
span
,
msg
);
...
...
src/librustc_borrowck/borrowck/mod.rs
浏览文件 @
a256a663
...
@@ -38,6 +38,7 @@
...
@@ -38,6 +38,7 @@
use
rustc_mir
::
util
::
suggest_ref_mut
;
use
rustc_mir
::
util
::
suggest_ref_mut
;
use
rustc
::
util
::
nodemap
::
FxHashSet
;
use
rustc
::
util
::
nodemap
::
FxHashSet
;
use
std
::
borrow
::
Cow
;
use
std
::
cell
::{
Cell
,
RefCell
};
use
std
::
cell
::{
Cell
,
RefCell
};
use
std
::
fmt
;
use
std
::
fmt
;
use
std
::
rc
::
Rc
;
use
std
::
rc
::
Rc
;
...
@@ -808,34 +809,34 @@ fn report_bckerr(&self, err: &BckError<'a, 'tcx>) {
...
@@ -808,34 +809,34 @@ fn report_bckerr(&self, err: &BckError<'a, 'tcx>) {
match
err
.code
{
match
err
.code
{
err_mutbl
=>
{
err_mutbl
=>
{
let
descr
=
match
err
.cmt.note
{
let
descr
:
Cow
<
'static
,
str
>
=
match
err
.cmt.note
{
mc
::
NoteClosureEnv
(
_
)
|
mc
::
NoteUpvarRef
(
_
)
=>
{
mc
::
NoteClosureEnv
(
_
)
|
mc
::
NoteUpvarRef
(
_
)
=>
{
self
.cmt_to_
string
(
&
err
.cmt
)
self
.cmt_to_
cow_str
(
&
err
.cmt
)
}
}
_
=>
match
opt_loan_path_is_field
(
&
err
.cmt
)
{
_
=>
match
opt_loan_path_is_field
(
&
err
.cmt
)
{
(
None
,
true
)
=>
{
(
None
,
true
)
=>
{
format!
(
"{} of {} binding"
,
format!
(
"{} of {} binding"
,
self
.cmt_to_
string
(
&
err
.cmt
),
self
.cmt_to_
cow_str
(
&
err
.cmt
),
err
.cmt.mutbl
.to_user_str
())
err
.cmt.mutbl
.to_user_str
())
.into
()
}
}
(
None
,
false
)
=>
{
(
None
,
false
)
=>
{
format!
(
"{} {}"
,
format!
(
"{} {}"
,
err
.cmt.mutbl
.to_user_str
(),
err
.cmt.mutbl
.to_user_str
(),
self
.cmt_to_
string
(
&
err
.cmt
)
)
self
.cmt_to_
cow_str
(
&
err
.cmt
))
.into
(
)
}
}
(
Some
(
lp
),
true
)
=>
{
(
Some
(
lp
),
true
)
=>
{
format!
(
"{} `{}` of {} binding"
,
format!
(
"{} `{}` of {} binding"
,
self
.cmt_to_
string
(
&
err
.cmt
),
self
.cmt_to_
cow_str
(
&
err
.cmt
),
self
.loan_path_to_string
(
&
lp
),
self
.loan_path_to_string
(
&
lp
),
err
.cmt.mutbl
.to_user_str
())
err
.cmt.mutbl
.to_user_str
())
.into
()
}
}
(
Some
(
lp
),
false
)
=>
{
(
Some
(
lp
),
false
)
=>
{
format!
(
"{} {} `{}`"
,
format!
(
"{} {} `{}`"
,
err
.cmt.mutbl
.to_user_str
(),
err
.cmt.mutbl
.to_user_str
(),
self
.cmt_to_
string
(
&
err
.cmt
),
self
.cmt_to_
cow_str
(
&
err
.cmt
),
self
.loan_path_to_string
(
&
lp
))
self
.loan_path_to_string
(
&
lp
))
.into
()
}
}
}
}
};
};
...
@@ -1058,11 +1059,11 @@ fn report_bckerr(&self, err: &BckError<'a, 'tcx>) {
...
@@ -1058,11 +1059,11 @@ fn report_bckerr(&self, err: &BckError<'a, 'tcx>) {
err_borrowed_pointer_too_short
(
loan_scope
,
ptr_scope
)
=>
{
err_borrowed_pointer_too_short
(
loan_scope
,
ptr_scope
)
=>
{
let
descr
=
self
.cmt_to_path_or_string
(
err
.cmt
);
let
descr
=
self
.cmt_to_path_or_string
(
err
.cmt
);
let
mut
db
=
self
.lifetime_too_short_for_reborrow
(
error_span
,
&
descr
,
Origin
::
Ast
);
let
mut
db
=
self
.lifetime_too_short_for_reborrow
(
error_span
,
&
descr
,
Origin
::
Ast
);
let
descr
=
match
opt_loan_path
(
&
err
.cmt
)
{
let
descr
:
Cow
<
'static
,
str
>
=
match
opt_loan_path
(
&
err
.cmt
)
{
Some
(
lp
)
=>
{
Some
(
lp
)
=>
{
format!
(
"`{}`"
,
self
.loan_path_to_string
(
&
lp
))
format!
(
"`{}`"
,
self
.loan_path_to_string
(
&
lp
))
.into
()
}
}
None
=>
self
.cmt_to_
string
(
&
err
.cmt
),
None
=>
self
.cmt_to_
cow_str
(
&
err
.cmt
)
};
};
self
.tcx
.note_and_explain_region
(
self
.tcx
.note_and_explain_region
(
&
self
.region_scope_tree
,
&
self
.region_scope_tree
,
...
@@ -1477,14 +1478,14 @@ pub fn loan_path_to_string(&self, loan_path: &LoanPath<'tcx>) -> String {
...
@@ -1477,14 +1478,14 @@ pub fn loan_path_to_string(&self, loan_path: &LoanPath<'tcx>) -> String {
result
result
}
}
pub
fn
cmt_to_
string
(
&
self
,
cmt
:
&
mc
::
cmt_
<
'tcx
>
)
->
String
{
pub
fn
cmt_to_
cow_str
(
&
self
,
cmt
:
&
mc
::
cmt_
<
'tcx
>
)
->
Cow
<
'static
,
str
>
{
cmt
.descriptive_string
(
self
.tcx
)
cmt
.descriptive_string
(
self
.tcx
)
}
}
pub
fn
cmt_to_path_or_string
(
&
self
,
cmt
:
&
mc
::
cmt_
<
'tcx
>
)
->
String
{
pub
fn
cmt_to_path_or_string
(
&
self
,
cmt
:
&
mc
::
cmt_
<
'tcx
>
)
->
String
{
match
opt_loan_path
(
cmt
)
{
match
opt_loan_path
(
cmt
)
{
Some
(
lp
)
=>
format!
(
"`{}`"
,
self
.loan_path_to_string
(
&
lp
)),
Some
(
lp
)
=>
format!
(
"`{}`"
,
self
.loan_path_to_string
(
&
lp
)),
None
=>
self
.cmt_to_
string
(
cmt
),
None
=>
self
.cmt_to_
cow_str
(
cmt
)
.into_owned
(
),
}
}
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录