Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
4c8fd2e8
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,发现更多精彩内容 >>
提交
4c8fd2e8
编写于
11月 20, 2018
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
try to detect affected code and direct people to #56105
上级
2c17af0b
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
48 addition
and
7 deletion
+48
-7
src/librustc/traits/coherence.rs
src/librustc/traits/coherence.rs
+33
-6
src/librustc/traits/mod.rs
src/librustc/traits/mod.rs
+2
-1
src/librustc/traits/specialize/mod.rs
src/librustc/traits/specialize/mod.rs
+6
-0
src/librustc/traits/specialize/specialization_graph.rs
src/librustc/traits/specialize/specialization_graph.rs
+1
-0
src/librustc_typeck/coherence/inherent_impls_overlap.rs
src/librustc_typeck/coherence/inherent_impls_overlap.rs
+4
-0
src/test/ui/coherence/coherence-subtyping.stderr
src/test/ui/coherence/coherence-subtyping.stderr
+2
-0
未找到文件。
src/librustc/traits/coherence.rs
浏览文件 @
4c8fd2e8
...
...
@@ -4,6 +4,7 @@
//! [trait-resolution]: https://rust-lang.github.io/rustc-guide/traits/resolution.html
//! [trait-specialization]: https://rust-lang.github.io/rustc-guide/traits/specialization.html
use
infer
::
CombinedSnapshot
;
use
hir
::
def_id
::{
DefId
,
LOCAL_CRATE
};
use
syntax_pos
::
DUMMY_SP
;
use
traits
::{
self
,
Normalized
,
SelectionContext
,
Obligation
,
ObligationCause
};
...
...
@@ -33,6 +34,17 @@ pub enum Conflict {
pub
struct
OverlapResult
<
'tcx
>
{
pub
impl_header
:
ty
::
ImplHeader
<
'tcx
>
,
pub
intercrate_ambiguity_causes
:
Vec
<
IntercrateAmbiguityCause
>
,
/// True if the overlap might've been permitted before the shift
/// to universes.
pub
involves_placeholder
:
bool
,
}
pub
fn
add_placeholder_note
(
err
:
&
mut
::
errors
::
DiagnosticBuilder
<
'_
>
)
{
err
.note
(
&
format!
(
"this behavior recently changed as a result of a bug fix;
\
see rust-lang/rust#56105 for details"
));
}
/// If there are types that satisfy both impls, invokes `on_overlap`
...
...
@@ -104,13 +116,22 @@ fn with_fresh_ty_vars<'cx, 'gcx, 'tcx>(selcx: &mut SelectionContext<'cx, 'gcx, '
/// Can both impl `a` and impl `b` be satisfied by a common type (including
/// `where` clauses)? If so, returns an `ImplHeader` that unifies the two impls.
fn
overlap
<
'cx
,
'gcx
,
'tcx
>
(
selcx
:
&
mut
SelectionContext
<
'cx
,
'gcx
,
'tcx
>
,
a_def_id
:
DefId
,
b_def_id
:
DefId
)
->
Option
<
OverlapResult
<
'tcx
>>
{
fn
overlap
<
'cx
,
'gcx
,
'tcx
>
(
selcx
:
&
mut
SelectionContext
<
'cx
,
'gcx
,
'tcx
>
,
a_def_id
:
DefId
,
b_def_id
:
DefId
,
)
->
Option
<
OverlapResult
<
'tcx
>>
{
debug!
(
"overlap(a_def_id={:?}, b_def_id={:?})"
,
a_def_id
,
b_def_id
);
selcx
.infcx
()
.probe
(|
snapshot
|
overlap_within_probe
(
selcx
,
a_def_id
,
b_def_id
,
snapshot
))
}
fn
overlap_within_probe
(
selcx
:
&
mut
SelectionContext
<
'cx
,
'gcx
,
'tcx
>
,
a_def_id
:
DefId
,
b_def_id
:
DefId
,
snapshot
:
&
CombinedSnapshot
<
'_
,
'tcx
>
,
)
->
Option
<
OverlapResult
<
'tcx
>>
{
// For the purposes of this check, we don't bring any placeholder
// types into scope; instead, we replace the generic types with
// fresh type variables, and hence we do our evaluations in an
...
...
@@ -158,7 +179,13 @@ fn overlap<'cx, 'gcx, 'tcx>(selcx: &mut SelectionContext<'cx, 'gcx, 'tcx>,
let
impl_header
=
selcx
.infcx
()
.resolve_type_vars_if_possible
(
&
a_impl_header
);
let
intercrate_ambiguity_causes
=
selcx
.take_intercrate_ambiguity_causes
();
debug!
(
"overlap: intercrate_ambiguity_causes={:#?}"
,
intercrate_ambiguity_causes
);
Some
(
OverlapResult
{
impl_header
,
intercrate_ambiguity_causes
})
let
involves_placeholder
=
match
selcx
.infcx
()
.region_constraints_added_in_snapshot
(
snapshot
)
{
Some
(
true
)
=>
true
,
_
=>
false
,
};
Some
(
OverlapResult
{
impl_header
,
intercrate_ambiguity_causes
,
involves_placeholder
})
}
pub
fn
trait_ref_is_knowable
<
'a
,
'gcx
,
'tcx
>
(
tcx
:
TyCtxt
<
'a
,
'gcx
,
'tcx
>
,
...
...
src/librustc/traits/mod.rs
浏览文件 @
4c8fd2e8
...
...
@@ -43,7 +43,8 @@
pub
use
self
::
Vtable
::
*
;
pub
use
self
::
ObligationCauseCode
::
*
;
pub
use
self
::
coherence
::{
orphan_check
,
overlapping_impls
,
OrphanCheckErr
,
OverlapResult
};
pub
use
self
::
coherence
::{
add_placeholder_note
,
orphan_check
,
overlapping_impls
};
pub
use
self
::
coherence
::{
OrphanCheckErr
,
OverlapResult
};
pub
use
self
::
fulfill
::{
FulfillmentContext
,
PendingPredicateObligation
};
pub
use
self
::
project
::
MismatchedProjectionTypes
;
pub
use
self
::
project
::{
normalize
,
normalize_projection_type
,
poly_project_and_unify_type
};
...
...
src/librustc/traits/specialize/mod.rs
浏览文件 @
4c8fd2e8
...
...
@@ -15,6 +15,7 @@
use
infer
::{
InferCtxt
,
InferOk
};
use
lint
;
use
traits
::{
self
,
FutureCompatOverlapErrorKind
,
ObligationCause
,
TraitEngine
};
use
traits
::
coherence
;
use
rustc_data_structures
::
fx
::
FxHashSet
;
use
rustc_data_structures
::
sync
::
Lrc
;
use
syntax_pos
::
DUMMY_SP
;
...
...
@@ -32,6 +33,7 @@ pub struct OverlapError {
pub
trait_desc
:
String
,
pub
self_desc
:
Option
<
String
>
,
pub
intercrate_ambiguity_causes
:
Vec
<
IntercrateAmbiguityCause
>
,
pub
involves_placeholder
:
bool
,
}
/// Given a subst for the requested impl, translate it to a subst
...
...
@@ -370,6 +372,10 @@ pub(super) fn specialization_graph_provider<'a, 'tcx>(
cause
.add_intercrate_ambiguity_hint
(
&
mut
err
);
}
if
overlap
.involves_placeholder
{
coherence
::
add_placeholder_note
(
&
mut
err
);
}
err
.emit
();
}
}
else
{
...
...
src/librustc/traits/specialize/specialization_graph.rs
浏览文件 @
4c8fd2e8
...
...
@@ -164,6 +164,7 @@ fn insert(&mut self,
None
},
intercrate_ambiguity_causes
:
overlap
.intercrate_ambiguity_causes
,
involves_placeholder
:
overlap
.involves_placeholder
,
}
};
...
...
src/librustc_typeck/coherence/inherent_impls_overlap.rs
浏览文件 @
4c8fd2e8
...
...
@@ -73,6 +73,10 @@ fn check_for_common_items_in_impls(
cause
.add_intercrate_ambiguity_hint
(
&
mut
err
);
}
if
overlap
.involves_placeholder
{
traits
::
add_placeholder_note
(
&
mut
err
);
}
err
.emit
();
}
}
...
...
src/test/ui/coherence/coherence-subtyping.stderr
浏览文件 @
4c8fd2e8
...
...
@@ -6,6 +6,8 @@ LL | impl TheTrait for for<'a,'b> fn(&'a u8, &'b u8) -> &'a u8 {
...
LL | impl TheTrait for for<'a> fn(&'a u8, &'a u8) -> &'a u8 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `for<'a, 'b> fn(&'a u8, &'b u8) -> &'a u8`
|
= note: this behavior recently changed as a result of a bug fix; see #XXX for details
error: aborting due to previous error
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录