Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
5841c687
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,发现更多精彩内容 >>
提交
5841c687
编写于
4月 13, 2018
作者:
J
John Kåre Alsaker
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improve query cycle error message
上级
21f6e55c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
32 addition
and
18 deletion
+32
-18
src/librustc/ty/maps/job.rs
src/librustc/ty/maps/job.rs
+12
-2
src/librustc/ty/maps/plumbing.rs
src/librustc/ty/maps/plumbing.rs
+20
-16
未找到文件。
src/librustc/ty/maps/job.rs
浏览文件 @
5841c687
...
...
@@ -31,6 +31,7 @@ pub(super) enum QueryResult<'tcx, T> {
/// A span and a query key
#[derive(Clone,
Debug)]
pub
struct
QueryInfo
<
'tcx
>
{
/// The span for a reason this query was required
pub
span
:
Span
,
pub
query
:
Query
<
'tcx
>
,
}
...
...
@@ -73,13 +74,22 @@ pub(super) fn await<'lcx>(
cycle
.insert
(
0
,
job
.info
.clone
());
if
&*
job
as
*
const
_
==
self
as
*
const
_
{
break
;
// This is the end of the cycle
// The span entry we included was for the usage
// of the cycle itself, and not part of the cycle
// Replace it with the span which caused the cycle to form
cycle
[
0
]
.span
=
span
;
// Find out why the cycle itself was used
let
usage
=
job
.parent
.as_ref
()
.map
(|
parent
|
{
(
job
.info.span
,
parent
.info.query
.clone
())
});
return
Err
(
CycleError
{
usage
,
cycle
});
}
current_job
=
job
.parent
.clone
();
}
Err
(
CycleError
{
span
,
cycle
}
)
panic!
(
"did not find a cycle"
)
}
/// Signals to waiters that the query is complete.
...
...
src/librustc/ty/maps/plumbing.rs
浏览文件 @
5841c687
...
...
@@ -64,8 +64,8 @@ fn get_cache_internal<'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>)
#[derive(Clone)]
pub
(
super
)
struct
CycleError
<
'tcx
>
{
/// The
span of the reason the first query in `cycle` ran the last query in `cycle`
pub
(
super
)
span
:
Span
,
/// The
query and related span which uses the cycle
pub
(
super
)
usage
:
Option
<
(
Span
,
Query
<
'tcx
>
)
>
,
pub
(
super
)
cycle
:
Vec
<
QueryInfo
<
'tcx
>>
,
}
...
...
@@ -81,7 +81,7 @@ pub(super) enum TryGetLock<'a, 'tcx: 'a, T, D: QueryDescription<'tcx> + 'a> {
}
impl
<
'a
,
'gcx
,
'tcx
>
TyCtxt
<
'a
,
'gcx
,
'tcx
>
{
pub
(
super
)
fn
report_cycle
(
self
,
CycleError
{
span
,
cycle
:
stack
}:
CycleError
<
'gcx
>
)
pub
(
super
)
fn
report_cycle
(
self
,
CycleError
{
usage
,
cycle
:
stack
}:
CycleError
<
'gcx
>
)
->
DiagnosticBuilder
<
'a
>
{
assert
!
(
!
stack
.is_empty
());
...
...
@@ -95,23 +95,27 @@ pub(super) fn report_cycle(self, CycleError { span, cycle: stack }: CycleError<'
// (And cycle errors around impls tend to occur during the
// collect/coherence phases anyhow.)
item_path
::
with_forced_impl_filename_line
(||
{
let
span
=
fix_span
(
span
,
&
stack
.first
()
.unwrap
()
.query
);
let
mut
err
=
struct_span_err!
(
self
.sess
,
span
,
E0391
,
"cyclic dependency detected"
);
err
.span_label
(
span
,
"cyclic reference"
);
err
.span_note
(
fix_span
(
stack
[
0
]
.span
,
&
stack
[
0
]
.query
),
&
format!
(
"the cycle begins when {}..."
,
stack
[
0
]
.query
.describe
(
self
)));
for
&
QueryInfo
{
span
,
ref
query
,
..
}
in
&
stack
[
1
..
]
{
err
.span_note
(
fix_span
(
span
,
query
),
&
format!
(
"...which then requires {}..."
,
query
.describe
(
self
)));
let
span
=
fix_span
(
stack
[
1
%
stack
.len
()]
.span
,
&
stack
[
0
]
.query
);
let
mut
err
=
struct_span_err!
(
self
.sess
,
span
,
E0391
,
"cycle detected when {}"
,
stack
[
0
]
.query
.describe
(
self
));
for
i
in
1
..
stack
.len
()
{
let
query
=
&
stack
[
i
]
.query
;
let
span
=
fix_span
(
stack
[(
i
+
1
)
%
stack
.len
()]
.span
,
query
);
err
.span_note
(
span
,
&
format!
(
"...which requires {}..."
,
query
.describe
(
self
)));
}
err
.note
(
&
format!
(
"...which
then again requires {}, completing the cycle.
"
,
err
.note
(
&
format!
(
"...which
again requires {}, completing the cycle
"
,
stack
[
0
]
.query
.describe
(
self
)));
if
let
Some
((
span
,
query
))
=
usage
{
err
.span_note
(
fix_span
(
span
,
&
query
),
&
format!
(
"cycle used when {}"
,
query
.describe
(
self
)));
}
return
err
})
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录