Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
3dc8a369
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,发现更多精彩内容 >>
提交
3dc8a369
编写于
8月 07, 2020
作者:
N
Nicholas Nethercote
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Eliminate `librustc_hir`'s dependency on `librustc_session`.
上级
e539dd65
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
25 addition
and
13 deletion
+25
-13
Cargo.lock
Cargo.lock
+0
-1
src/librustc_hir/Cargo.toml
src/librustc_hir/Cargo.toml
+0
-1
src/librustc_hir/lang_items.rs
src/librustc_hir/lang_items.rs
+12
-5
src/librustc_hir/weak_lang_items.rs
src/librustc_hir/weak_lang_items.rs
+7
-3
src/librustc_passes/lang_items.rs
src/librustc_passes/lang_items.rs
+2
-1
src/librustc_passes/weak_lang_items.rs
src/librustc_passes/weak_lang_items.rs
+2
-1
src/librustc_typeck/collect.rs
src/librustc_typeck/collect.rs
+2
-1
未找到文件。
Cargo.lock
浏览文件 @
3dc8a369
...
...
@@ -3466,7 +3466,6 @@ dependencies = [
"rustc_index",
"rustc_macros",
"rustc_serialize",
"rustc_session",
"rustc_span",
"rustc_target",
"smallvec 1.4.0",
...
...
src/librustc_hir/Cargo.toml
浏览文件 @
3dc8a369
...
...
@@ -16,7 +16,6 @@ rustc_data_structures = { path = "../librustc_data_structures" }
rustc_index
=
{
path
=
"../librustc_index"
}
rustc_span
=
{
path
=
"../librustc_span"
}
rustc_serialize
=
{
path
=
"../librustc_serialize"
}
rustc_session
=
{
path
=
"../librustc_session"
}
rustc_ast
=
{
path
=
"../librustc_ast"
}
lazy_static
=
"1"
log
=
{
package
=
"tracing"
,
version
=
"0.1"
}
...
...
src/librustc_hir/lang_items.rs
浏览文件 @
3dc8a369
...
...
@@ -16,7 +16,6 @@
use
rustc_data_structures
::
fx
::
FxHashMap
;
use
rustc_data_structures
::
stable_hasher
::{
HashStable
,
StableHasher
};
use
rustc_macros
::
HashStable_Generic
;
use
rustc_session
::
Session
;
use
rustc_span
::
symbol
::{
kw
,
sym
,
Symbol
};
use
rustc_span
::
Span
;
...
...
@@ -142,12 +141,20 @@ fn hash_stable(&self, _: &mut CTX, hasher: &mut StableHasher) {
/// Extracts the first `lang = "$name"` out of a list of attributes.
/// The attributes `#[panic_handler]` and `#[alloc_error_handler]`
/// are also extracted out when found.
pub
fn
extract
(
sess
:
&
Session
,
attrs
:
&
[
ast
::
Attribute
])
->
Option
<
(
Symbol
,
Span
)
>
{
///
/// About the `check_name` argument: passing in a `Session` would be simpler,
/// because then we could call `Session::check_name` directly. But we want to
/// avoid the need for `librustc_hir` to depend on `librustc_session`, so we
/// use a closure instead.
pub
fn
extract
<
'a
,
F
>
(
check_name
:
F
,
attrs
:
&
'a
[
ast
::
Attribute
])
->
Option
<
(
Symbol
,
Span
)
>
where
F
:
Fn
(
&
'a
ast
::
Attribute
,
Symbol
)
->
bool
,
{
attrs
.iter
()
.find_map
(|
attr
|
{
Some
(
match
attr
{
_
if
sess
.
check_name
(
attr
,
sym
::
lang
)
=>
(
attr
.value_str
()
?
,
attr
.span
),
_
if
sess
.
check_name
(
attr
,
sym
::
panic_handler
)
=>
(
sym
::
panic_impl
,
attr
.span
),
_
if
sess
.
check_name
(
attr
,
sym
::
alloc_error_handler
)
=>
(
sym
::
oom
,
attr
.span
),
_
if
check_name
(
attr
,
sym
::
lang
)
=>
(
attr
.value_str
()
?
,
attr
.span
),
_
if
check_name
(
attr
,
sym
::
panic_handler
)
=>
(
sym
::
panic_impl
,
attr
.span
),
_
if
check_name
(
attr
,
sym
::
alloc_error_handler
)
=>
(
sym
::
oom
,
attr
.span
),
_
=>
return
None
,
})
})
...
...
src/librustc_hir/weak_lang_items.rs
浏览文件 @
3dc8a369
...
...
@@ -5,7 +5,6 @@
use
rustc_ast
::
ast
;
use
rustc_data_structures
::
fx
::
FxHashMap
;
use
rustc_session
::
Session
;
use
rustc_span
::
symbol
::{
sym
,
Symbol
};
use
lazy_static
::
lazy_static
;
...
...
@@ -21,8 +20,13 @@
};
}
pub
fn
link_name
(
sess
:
&
Session
,
attrs
:
&
[
ast
::
Attribute
])
->
Option
<
Symbol
>
{
lang_items
::
extract
(
sess
,
attrs
)
.and_then
(|(
name
,
_
)|
{
/// The `check_name` argument avoids the need for `librustc_hir` to depend on
/// `librustc_session`.
pub
fn
link_name
<
'a
,
F
>
(
check_name
:
F
,
attrs
:
&
'a
[
ast
::
Attribute
])
->
Option
<
Symbol
>
where
F
:
Fn
(
&
'a
ast
::
Attribute
,
Symbol
)
->
bool
{
lang_items
::
extract
(
check_name
,
attrs
)
.and_then
(|(
name
,
_
)|
{
$
(
if
name
==
sym
::
$name
{
Some
(
sym
::
$sym
)
}
else
)
*
{
...
...
src/librustc_passes/lang_items.rs
浏览文件 @
3dc8a369
...
...
@@ -56,7 +56,8 @@ fn new(tcx: TyCtxt<'tcx>) -> LanguageItemCollector<'tcx> {
}
fn
check_for_lang
(
&
mut
self
,
actual_target
:
Target
,
hir_id
:
HirId
,
attrs
:
&
[
Attribute
])
{
if
let
Some
((
value
,
span
))
=
extract
(
&
self
.tcx.sess
,
&
attrs
)
{
let
check_name
=
|
attr
,
sym
|
self
.tcx.sess
.check_name
(
attr
,
sym
);
if
let
Some
((
value
,
span
))
=
extract
(
check_name
,
&
attrs
)
{
match
ITEM_REFS
.get
(
&
value
)
.cloned
()
{
// Known lang item with attribute on correct target.
Some
((
item_index
,
expected_target
))
if
actual_target
==
expected_target
=>
{
...
...
src/librustc_passes/weak_lang_items.rs
浏览文件 @
3dc8a369
...
...
@@ -100,7 +100,8 @@ fn nested_visit_map(&mut self) -> NestedVisitorMap<Self::Map> {
}
fn
visit_foreign_item
(
&
mut
self
,
i
:
&
hir
::
ForeignItem
<
'_
>
)
{
if
let
Some
((
lang_item
,
_
))
=
hir
::
lang_items
::
extract
(
&
self
.tcx.sess
,
&
i
.attrs
)
{
let
check_name
=
|
attr
,
sym
|
self
.tcx.sess
.check_name
(
attr
,
sym
);
if
let
Some
((
lang_item
,
_
))
=
hir
::
lang_items
::
extract
(
check_name
,
&
i
.attrs
)
{
self
.register
(
lang_item
,
i
.span
,
i
.hir_id
);
}
intravisit
::
walk_foreign_item
(
self
,
i
)
...
...
src/librustc_typeck/collect.rs
浏览文件 @
3dc8a369
...
...
@@ -2614,7 +2614,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, id: DefId) -> CodegenFnAttrs {
if
tcx
.is_weak_lang_item
(
id
)
{
codegen_fn_attrs
.flags
|
=
CodegenFnAttrFlags
::
RUSTC_STD_INTERNAL_SYMBOL
;
}
if
let
Some
(
name
)
=
weak_lang_items
::
link_name
(
&
tcx
.sess
,
&
attrs
)
{
let
check_name
=
|
attr
,
sym
|
tcx
.sess
.check_name
(
attr
,
sym
);
if
let
Some
(
name
)
=
weak_lang_items
::
link_name
(
check_name
,
&
attrs
)
{
codegen_fn_attrs
.export_name
=
Some
(
name
);
codegen_fn_attrs
.link_name
=
Some
(
name
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录