Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
16337464
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,发现更多精彩内容 >>
提交
16337464
编写于
5月 20, 2022
作者:
U
Urgau
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Handle more cases in cfg_accessible
上级
bef2b7cd
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
55 addition
and
49 deletion
+55
-49
compiler/rustc_resolve/src/macros.rs
compiler/rustc_resolve/src/macros.rs
+13
-8
src/test/ui/conditional-compilation/cfg_accessible.rs
src/test/ui/conditional-compilation/cfg_accessible.rs
+25
-13
src/test/ui/conditional-compilation/cfg_accessible.stderr
src/test/ui/conditional-compilation/cfg_accessible.stderr
+17
-28
未找到文件。
compiler/rustc_resolve/src/macros.rs
浏览文件 @
16337464
...
...
@@ -443,11 +443,20 @@ fn cfg_accessible(
PathResult
::
NonModule
(
partial_res
)
if
partial_res
.unresolved_segments
()
==
0
=>
{
return
Ok
(
true
);
}
PathResult
::
NonModule
(
..
)
=>
{
self
.session
.struct_span_err
(
span
,
"not sure whether the path is accessible or not"
)
.note
(
"the type may have associated items, but we are currently not checking them"
)
.emit
();
// If we get a partially resolved NonModule in one namespace, we should get the
// same result in any other namespaces, so we can return early.
return
Ok
(
false
);
}
PathResult
::
Indeterminate
=>
indeterminate
=
true
,
// FIXME: `resolve_path` is not ready to report partially resolved paths
// correctly, so we just report an error if the path was reported as unresolved.
// This needs to be fixed for `cfg_accessible` to be useful.
PathResult
::
NonModule
(
..
)
|
PathResult
::
Failed
{
..
}
=>
{}
// We can only be sure that a path doesn't exist after having tested all the
// posibilities, only at that time we can return false.
PathResult
::
Failed
{
..
}
=>
{}
PathResult
::
Module
(
_
)
=>
panic!
(
"unexpected path resolution"
),
}
}
...
...
@@ -456,10 +465,6 @@ fn cfg_accessible(
return
Err
(
Indeterminate
);
}
self
.session
.struct_span_err
(
span
,
"not sure whether the path is accessible or not"
)
.span_note
(
span
,
"`cfg_accessible` is not fully implemented"
)
.emit
();
Ok
(
false
)
}
...
...
src/test/ui/conditional-compilation/cfg_accessible.rs
浏览文件 @
16337464
...
...
@@ -5,20 +5,35 @@ mod m {
struct
ExistingPrivate
;
}
trait
Trait
{
type
Assoc
;
}
enum
Enum
{
Existing
,
}
#[cfg_accessible(Enum)]
struct
ExistingResolved
;
#[cfg_accessible(Enum::Existing)]
struct
ExistingResolvedVariant
;
#[cfg_accessible(m::ExistingPublic)]
struct
ExistingPublic
;
// FIXME: Not implemented yet.
#[cfg_accessible(m::ExistingPrivate)]
//~ ERROR not sure whether the path is accessible or not
#[cfg_accessible(m::ExistingPrivate)]
struct
ExistingPrivate
;
// FIXME: Not implemented yet.
#[cfg_accessible(m::NonExistent)]
//~ ERROR not sure whether the path is accessible or not
struct
ExistingPrivate
;
#[cfg_accessible(m::NonExistent)]
struct
NonExistingPrivate
;
#[cfg_accessible(n::AccessibleExpanded)]
// OK, `cfg_accessible` can wait and retry.
struct
AccessibleExpanded
;
#[cfg_accessible(Trait::Assoc)]
struct
AccessibleTraitAssoc
;
macro_rules!
generate_accessible_expanded
{
()
=>
{
mod
n
{
...
...
@@ -29,15 +44,12 @@ mod n {
generate_accessible_expanded!
();
struct
S
{
field
:
u8
,
}
// FIXME: Not implemented yet.
#[cfg_accessible(S::field)]
//~ ERROR not sure whether the path is accessible or not
struct
Field
;
fn
main
()
{
ExistingPublic
;
AccessibleExpanded
;
AccessibleTraitAssoc
;
ExistingPrivate
;
//~ ERROR cannot find
NonExistingPrivate
;
//~ ERROR cannot find
NonExistingTraitAlias
;
//~ ERROR cannot find
}
src/test/ui/conditional-compilation/cfg_accessible.stderr
浏览文件 @
16337464
error
: not sure whether the path is accessible or not
--> $DIR/cfg_accessible.rs:
12:18
error
[E0425]: cannot find value `ExistingPrivate` in this scope
--> $DIR/cfg_accessible.rs:
52:5
|
LL |
#[cfg_accessible(m::ExistingPrivate)]
|
^^^^^^^^^^^^^^^^^^
LL |
ExistingPrivate;
|
^^^^^^^^^^^^^^^ not found in this scope
|
note:
`cfg_accessible` is not fully implemented
--> $DIR/cfg_accessible.rs:
12:18
note:
unit struct `m::ExistingPrivate` exists but is inaccessible
--> $DIR/cfg_accessible.rs:
5:5
|
LL |
#[cfg_accessible(m::ExistingPrivate)]
|
^^^^^^^^^^^^^^^^^^
LL |
struct ExistingPrivate;
|
^^^^^^^^^^^^^^^^^^^^^^^ not accessible
error
: not sure whether the path is accessible or not
--> $DIR/cfg_accessible.rs:
16:18
error
[E0425]: cannot find value `NonExistingPrivate` in this scope
--> $DIR/cfg_accessible.rs:
53:5
|
LL | #[cfg_accessible(m::NonExistent)]
| ^^^^^^^^^^^^^^
|
note: `cfg_accessible` is not fully implemented
--> $DIR/cfg_accessible.rs:16:18
|
LL | #[cfg_accessible(m::NonExistent)]
| ^^^^^^^^^^^^^^
LL | NonExistingPrivate;
| ^^^^^^^^^^^^^^^^^^ not found in this scope
error: not sure whether the path is accessible or not
--> $DIR/cfg_accessible.rs:37:18
|
LL | #[cfg_accessible(S::field)]
| ^^^^^^^^
|
note: `cfg_accessible` is not fully implemented
--> $DIR/cfg_accessible.rs:37:18
error[E0425]: cannot find value `NonExistingTraitAlias` in this scope
--> $DIR/cfg_accessible.rs:54:5
|
LL |
#[cfg_accessible(S::field)]
|
^^^^^^^^
LL |
NonExistingTraitAlias;
|
^^^^^^^^^^^^^^^^^^^^^ not found in this scope
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0425`.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录