Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
f3d96e93
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
未验证
提交
f3d96e93
编写于
8月 27, 2021
作者:
D
Deadbeef
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fmt
上级
580ca930
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
42 addition
and
30 deletion
+42
-30
compiler/rustc_mir/src/transform/check_consts/check.rs
compiler/rustc_mir/src/transform/check_consts/check.rs
+9
-4
compiler/rustc_trait_selection/src/traits/mod.rs
compiler/rustc_trait_selection/src/traits/mod.rs
+4
-1
compiler/rustc_trait_selection/src/traits/select/mod.rs
compiler/rustc_trait_selection/src/traits/select/mod.rs
+26
-24
compiler/rustc_typeck/src/collect.rs
compiler/rustc_typeck/src/collect.rs
+3
-1
未找到文件。
compiler/rustc_mir/src/transform/check_consts/check.rs
浏览文件 @
f3d96e93
...
...
@@ -826,7 +826,8 @@ fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location
);
let
implsrc
=
tcx
.infer_ctxt
()
.enter
(|
infcx
|
{
let
mut
selcx
=
SelectionContext
::
with_constness
(
&
infcx
,
hir
::
Constness
::
Const
);
let
mut
selcx
=
SelectionContext
::
with_constness
(
&
infcx
,
hir
::
Constness
::
Const
);
selcx
.select
(
&
obligation
)
});
...
...
@@ -834,13 +835,17 @@ fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location
Ok
(
Some
(
ImplSource
::
Param
(
_
,
ty
::
BoundConstness
::
ConstIfConst
)))
=>
{
debug!
(
"const_trait_impl: provided {:?} via where-clause in {:?}"
,
trait_ref
,
param_env
trait_ref
,
param_env
);
return
;
}
Ok
(
Some
(
ImplSource
::
UserDefined
(
data
)))
=>
{
let
callee_name
=
tcx
.item_name
(
callee
);
if
let
Some
(
&
did
)
=
tcx
.associated_item_def_ids
(
data
.impl_def_id
)
.iter
()
.find
(|
did
|
tcx
.item_name
(
**
did
)
==
callee_name
)
{
if
let
Some
(
&
did
)
=
tcx
.associated_item_def_ids
(
data
.impl_def_id
)
.iter
()
.find
(|
did
|
tcx
.item_name
(
**
did
)
==
callee_name
)
{
callee
=
did
;
}
}
...
...
@@ -909,7 +914,7 @@ fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location
// trait, but for it to still be non-const can be that the impl is
// using default method bodies.
nonconst_call_permission
=
true
;
}
}
}
if
!
nonconst_call_permission
{
...
...
compiler/rustc_trait_selection/src/traits/mod.rs
浏览文件 @
f3d96e93
...
...
@@ -778,7 +778,10 @@ pub fn vtable_trait_upcasting_coercion_new_vptr_slot(
let
obligation
=
Obligation
::
new
(
ObligationCause
::
dummy
(),
ty
::
ParamEnv
::
reveal_all
(),
ty
::
Binder
::
dummy
(
ty
::
TraitPredicate
{
trait_ref
,
constness
:
ty
::
BoundConstness
::
NotConst
}),
ty
::
Binder
::
dummy
(
ty
::
TraitPredicate
{
trait_ref
,
constness
:
ty
::
BoundConstness
::
NotConst
,
}),
);
let
implsrc
=
tcx
.infer_ctxt
()
.enter
(|
infcx
|
{
...
...
compiler/rustc_trait_selection/src/traits/select/mod.rs
浏览文件 @
f3d96e93
...
...
@@ -319,7 +319,7 @@ pub fn tcx(&self) -> TyCtxt<'tcx> {
pub
fn
is_trait_predicate_const
(
&
self
,
pred
:
ty
::
TraitPredicate
<
'_
>
)
->
bool
{
match
pred
.constness
{
ty
::
BoundConstness
::
ConstIfConst
if
self
.is_in_const_context
=>
true
,
_
=>
false
_
=>
false
,
}
}
...
...
@@ -1079,30 +1079,30 @@ fn filter_impls(
let
tcx
=
self
.tcx
();
// Respect const trait obligations
if
self
.is_trait_predicate_const
(
obligation
.predicate
.skip_binder
())
{
if
Some
(
obligation
.predicate
.skip_binder
()
.trait_ref.def_id
)
!=
tcx
.lang_items
()
.sized_trait
()
// const Sized bounds are skipped
{
match
candidate
{
// const impl
ImplCandidate
(
def_id
)
if
tcx
.impl_constness
(
def_id
)
==
hir
::
Constness
::
Const
=>
{}
// const param
ParamCandidate
(
ty
::
ConstnessAnd
{
constness
:
ty
::
BoundConstness
::
ConstIfConst
,
..
})
=>
{}
// auto trait impl
AutoImplCandidate
(
..
)
=>
{}
// generator, this will raise error in other places
// or ignore error with const_async_blocks feature
GeneratorCandidate
=>
{}
_
=>
{
// reject all other types of candidates
return
Err
(
Unimplemented
);
}
if
Some
(
obligation
.predicate
.skip_binder
()
.trait_ref.def_id
)
!=
tcx
.lang_items
()
.sized_trait
()
// const Sized bounds are skipped
{
match
candidate
{
// const impl
ImplCandidate
(
def_id
)
if
tcx
.impl_constness
(
def_id
)
==
hir
::
Constness
::
Const
=>
{}
// const param
ParamCandidate
(
ty
::
ConstnessAnd
{
constness
:
ty
::
BoundConstness
::
ConstIfConst
,
..
})
=>
{}
// auto trait impl
AutoImplCandidate
(
..
)
=>
{}
// generator, this will raise error in other places
// or ignore error with const_async_blocks feature
GeneratorCandidate
=>
{}
_
=>
{
// reject all other types of candidates
return
Err
(
Unimplemented
);
}
}
}
}
// Treat negative impls as unimplemented, and reservation impls as ambiguity.
if
let
ImplCandidate
(
def_id
)
=
candidate
{
...
...
@@ -1497,7 +1497,9 @@ fn candidate_should_be_dropped_in_favor_of(
// probably best characterized as a "hack", since we might prefer to just do our
// best to *not* create essentially duplicate candidates in the first place.
other
.value
.bound_vars
()
.len
()
<=
victim
.value
.bound_vars
()
.len
()
}
else
if
other
.value
==
victim
.value
&&
victim
.constness
==
ty
::
BoundConstness
::
NotConst
{
}
else
if
other
.value
==
victim
.value
&&
victim
.constness
==
ty
::
BoundConstness
::
NotConst
{
// Drop otherwise equivalent non-const candidates in favor of const candidates.
true
}
else
{
...
...
compiler/rustc_typeck/src/collect.rs
浏览文件 @
f3d96e93
...
...
@@ -2222,7 +2222,9 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: DefId) -> ty::GenericP
hir
::
GenericBound
::
Trait
(
poly_trait_ref
,
modifier
)
=>
{
let
constness
=
match
modifier
{
hir
::
TraitBoundModifier
::
None
=>
ty
::
BoundConstness
::
NotConst
,
hir
::
TraitBoundModifier
::
MaybeConst
=>
ty
::
BoundConstness
::
ConstIfConst
,
hir
::
TraitBoundModifier
::
MaybeConst
=>
{
ty
::
BoundConstness
::
ConstIfConst
}
// We ignore `where T: ?Sized`, it is already part of
// type parameter `T`.
hir
::
TraitBoundModifier
::
Maybe
=>
continue
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录