Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
0d61852c
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,发现更多精彩内容 >>
提交
0d61852c
编写于
12月 17, 2021
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
hir: Do not introduce dummy type names for `extern` blocks in def paths
Use a separate nameless `DefPathData` variant instead
上级
dde825db
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
33 addition
and
28 deletion
+33
-28
compiler/rustc_hir/src/definitions.rs
compiler/rustc_hir/src/definitions.rs
+6
-1
compiler/rustc_lint/src/context.rs
compiler/rustc_lint/src/context.rs
+2
-2
compiler/rustc_middle/src/ty/print/pretty.rs
compiler/rustc_middle/src/ty/print/pretty.rs
+12
-16
compiler/rustc_resolve/src/def_collector.rs
compiler/rustc_resolve/src/def_collector.rs
+1
-1
compiler/rustc_symbol_mangling/src/legacy.rs
compiler/rustc_symbol_mangling/src/legacy.rs
+2
-2
compiler/rustc_symbol_mangling/src/v0.rs
compiler/rustc_symbol_mangling/src/v0.rs
+4
-0
src/librustdoc/clean/inline.rs
src/librustdoc/clean/inline.rs
+3
-3
src/librustdoc/visit_ast.rs
src/librustdoc/visit_ast.rs
+3
-3
未找到文件。
compiler/rustc_hir/src/definitions.rs
浏览文件 @
0d61852c
...
...
@@ -267,6 +267,8 @@ pub enum DefPathData {
// Different kinds of items and item-like things:
/// An impl.
Impl
,
/// An `extern` block.
ForeignMod
,
/// Something in the type namespace.
TypeNs
(
Symbol
),
/// Something in the value namespace.
...
...
@@ -469,7 +471,9 @@ pub fn get_opt_name(&self) -> Option<Symbol> {
match
*
self
{
TypeNs
(
name
)
|
ValueNs
(
name
)
|
MacroNs
(
name
)
|
LifetimeNs
(
name
)
=>
Some
(
name
),
Impl
|
CrateRoot
|
Misc
|
ClosureExpr
|
Ctor
|
AnonConst
|
ImplTrait
=>
None
,
Impl
|
ForeignMod
|
CrateRoot
|
Misc
|
ClosureExpr
|
Ctor
|
AnonConst
|
ImplTrait
=>
{
None
}
}
}
...
...
@@ -482,6 +486,7 @@ pub fn name(&self) -> DefPathDataName {
// Note that this does not show up in user print-outs.
CrateRoot
=>
DefPathDataName
::
Anon
{
namespace
:
kw
::
Crate
},
Impl
=>
DefPathDataName
::
Anon
{
namespace
:
kw
::
Impl
},
ForeignMod
=>
DefPathDataName
::
Anon
{
namespace
:
kw
::
Extern
},
Misc
=>
DefPathDataName
::
Anon
{
namespace
:
sym
::
misc
},
ClosureExpr
=>
DefPathDataName
::
Anon
{
namespace
:
sym
::
closure
},
Ctor
=>
DefPathDataName
::
Anon
{
namespace
:
sym
::
constructor
},
...
...
compiler/rustc_lint/src/context.rs
浏览文件 @
0d61852c
...
...
@@ -1040,8 +1040,8 @@ fn path_append(
)
->
Result
<
Self
::
Path
,
Self
::
Error
>
{
let
mut
path
=
print_prefix
(
self
)
?
;
// Skip `::{{constructor}}` on tuple/unit structs.
if
let
DefPathData
::
Ctor
=
disambiguated_data
.data
{
// Skip `::{{
extern}}` blocks and `::{{
constructor}}` on tuple/unit structs.
if
let
DefPathData
::
ForeignMod
|
DefPathData
::
Ctor
=
disambiguated_data
.data
{
return
Ok
(
path
);
}
...
...
compiler/rustc_middle/src/ty/print/pretty.rs
浏览文件 @
0d61852c
...
...
@@ -1740,30 +1740,26 @@ fn path_append(
)
->
Result
<
Self
::
Path
,
Self
::
Error
>
{
self
=
print_prefix
(
self
)
?
;
// Skip `::{{constructor}}` on tuple/unit structs.
if
let
DefPathData
::
Ctor
=
disambiguated_data
.data
{
// Skip `::{{
extern}}` blocks and `::{{
constructor}}` on tuple/unit structs.
if
let
DefPathData
::
ForeignMod
|
DefPathData
::
Ctor
=
disambiguated_data
.data
{
return
Ok
(
self
);
}
// FIXME(eddyb) `name` should never be empty, but it
// currently is for `extern { ... }` "foreign modules".
let
name
=
disambiguated_data
.data
.name
();
if
name
!=
DefPathDataName
::
Named
(
kw
::
Empty
)
{
if
!
self
.empty_path
{
write!
(
self
,
"::"
)
?
;
}
if
!
self
.empty_path
{
write!
(
self
,
"::"
)
?
;
}
if
let
DefPathDataName
::
Named
(
name
)
=
name
{
if
Ident
::
with_dummy_span
(
name
)
.is_raw_guess
()
{
write!
(
self
,
"r#"
)
?
;
}
if
let
DefPathDataName
::
Named
(
name
)
=
name
{
if
Ident
::
with_dummy_span
(
name
)
.is_raw_guess
()
{
write!
(
self
,
"r#"
)
?
;
}
}
let
verbose
=
self
.tcx.sess
.verbose
();
disambiguated_data
.fmt_maybe_verbose
(
&
mut
self
,
verbose
)
?
;
let
verbose
=
self
.tcx.sess
.verbose
();
disambiguated_data
.fmt_maybe_verbose
(
&
mut
self
,
verbose
)
?
;
self
.empty_path
=
false
;
}
self
.empty_path
=
false
;
Ok
(
self
)
}
...
...
compiler/rustc_resolve/src/def_collector.rs
浏览文件 @
0d61852c
...
...
@@ -92,6 +92,7 @@ fn visit_item(&mut self, i: &'a Item) {
// information we encapsulate into, the better
let
def_data
=
match
&
i
.kind
{
ItemKind
::
Impl
{
..
}
=>
DefPathData
::
Impl
,
ItemKind
::
ForeignMod
(
..
)
=>
DefPathData
::
ForeignMod
,
ItemKind
::
Mod
(
..
)
|
ItemKind
::
Trait
(
..
)
|
ItemKind
::
TraitAlias
(
..
)
...
...
@@ -99,7 +100,6 @@ fn visit_item(&mut self, i: &'a Item) {
|
ItemKind
::
Struct
(
..
)
|
ItemKind
::
Union
(
..
)
|
ItemKind
::
ExternCrate
(
..
)
|
ItemKind
::
ForeignMod
(
..
)
|
ItemKind
::
TyAlias
(
..
)
=>
DefPathData
::
TypeNs
(
i
.ident.name
),
ItemKind
::
Static
(
..
)
|
ItemKind
::
Const
(
..
)
|
ItemKind
::
Fn
(
..
)
=>
{
DefPathData
::
ValueNs
(
i
.ident.name
)
...
...
compiler/rustc_symbol_mangling/src/legacy.rs
浏览文件 @
0d61852c
...
...
@@ -311,8 +311,8 @@ fn path_append(
)
->
Result
<
Self
::
Path
,
Self
::
Error
>
{
self
=
print_prefix
(
self
)
?
;
// Skip `::{{constructor}}` on tuple/unit structs.
if
let
DefPathData
::
Ctor
=
disambiguated_data
.data
{
// Skip `::{{
extern}}` blocks and `::{{
constructor}}` on tuple/unit structs.
if
let
DefPathData
::
ForeignMod
|
DefPathData
::
Ctor
=
disambiguated_data
.data
{
return
Ok
(
self
);
}
...
...
compiler/rustc_symbol_mangling/src/v0.rs
浏览文件 @
0d61852c
...
...
@@ -771,6 +771,10 @@ fn path_append(
disambiguated_data
:
&
DisambiguatedDefPathData
,
)
->
Result
<
Self
::
Path
,
Self
::
Error
>
{
let
ns
=
match
disambiguated_data
.data
{
// FIXME: It shouldn't be necessary to add anything for extern block segments,
// but we add 't' for backward compatibility.
DefPathData
::
ForeignMod
=>
't'
,
// Uppercase categories are more stable than lowercase ones.
DefPathData
::
TypeNs
(
_
)
=>
't'
,
DefPathData
::
ValueNs
(
_
)
=>
'v'
,
...
...
src/librustdoc/clean/inline.rs
浏览文件 @
0d61852c
...
...
@@ -8,6 +8,7 @@
use
rustc_hir
as
hir
;
use
rustc_hir
::
def
::{
DefKind
,
Res
};
use
rustc_hir
::
def_id
::
DefId
;
use
rustc_hir
::
definitions
::
DefPathData
;
use
rustc_hir
::
Mutability
;
use
rustc_metadata
::
creader
::{
CStore
,
LoadedMacro
};
use
rustc_middle
::
ty
::{
self
,
TyCtxt
};
...
...
@@ -165,9 +166,8 @@
let
crate_name
=
cx
.tcx
.crate_name
(
did
.krate
)
.to_string
();
let
relative
=
cx
.tcx
.def_path
(
did
)
.data
.into_iter
()
.filter_map
(|
elem
|
{
// extern blocks have an empty name
let
s
=
elem
.data
.to_string
();
if
!
s
.is_empty
()
{
Some
(
s
)
}
else
{
None
}
// Filter out extern blocks
(
elem
.data
!=
DefPathData
::
ForeignMod
)
.then
(||
elem
.data
.to_string
())
});
let
fqn
=
if
let
ItemType
::
Macro
=
kind
{
// Check to see if it is a macro 2.0 or built-in macro
...
...
src/librustdoc/visit_ast.rs
浏览文件 @
0d61852c
...
...
@@ -5,6 +5,7 @@
use
rustc_hir
as
hir
;
use
rustc_hir
::
def
::{
DefKind
,
Res
};
use
rustc_hir
::
def_id
::
DefId
;
use
rustc_hir
::
definitions
::
DefPathData
;
use
rustc_hir
::
Node
;
use
rustc_hir
::
CRATE_HIR_ID
;
use
rustc_middle
::
middle
::
privacy
::
AccessLevel
;
...
...
@@ -45,9 +46,8 @@ impl Module<'hir> {
fn
def_id_to_path
(
tcx
:
TyCtxt
<
'_
>
,
did
:
DefId
)
->
Vec
<
String
>
{
let
crate_name
=
tcx
.crate_name
(
did
.krate
)
.to_string
();
let
relative
=
tcx
.def_path
(
did
)
.data
.into_iter
()
.filter_map
(|
elem
|
{
// extern blocks have an empty name
let
s
=
elem
.data
.to_string
();
if
!
s
.is_empty
()
{
Some
(
s
)
}
else
{
None
}
// Filter out extern blocks
(
elem
.data
!=
DefPathData
::
ForeignMod
)
.then
(||
elem
.data
.to_string
())
});
std
::
iter
::
once
(
crate_name
)
.chain
(
relative
)
.collect
()
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录