Skip check for calling functions in same trait
This commit is contained in:
parent
d8d4cc3b98
commit
56d79adf3b
2 changed files with 15 additions and 5 deletions
|
@ -885,9 +885,17 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if !tcx.is_const_fn_raw(callee) {
|
let caller_has_attr = tcx.has_attr(caller, sym::default_method_body_is_const);
|
||||||
self.check_op(ops::FnCallNonConst);
|
let in_same_trait = match (tcx.trait_of_item(caller), tcx.trait_of_item(callee)) {
|
||||||
return;
|
(Some(t1), Some(t2)) => t1 == t2,
|
||||||
|
_ => false
|
||||||
|
};
|
||||||
|
|
||||||
|
if !(caller_has_attr && in_same_trait) {
|
||||||
|
if !tcx.is_const_fn_raw(callee) {
|
||||||
|
self.check_op(ops::FnCallNonConst);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the `const fn` we are trying to call is not const-stable, ensure that we have
|
// If the `const fn` we are trying to call is not const-stable, ensure that we have
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
// TODO fix this test
|
// check-pass
|
||||||
|
// TODO remove this^
|
||||||
|
|
||||||
#![feature(const_trait_impl)]
|
#![feature(const_trait_impl)]
|
||||||
|
#![feature(const_fn_trait_bound)] // FIXME is this needed?
|
||||||
#![allow(incomplete_features)]
|
#![allow(incomplete_features)]
|
||||||
|
|
||||||
trait ConstDefaultFn: Sized {
|
trait ConstDefaultFn: Sized {
|
||||||
|
@ -25,7 +27,7 @@ impl const ConstDefaultFn for ConstImpl {
|
||||||
|
|
||||||
const fn test() {
|
const fn test() {
|
||||||
NonConstImpl.a();
|
NonConstImpl.a();
|
||||||
//~^ ERROR calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
// TODO ~^ ERROR calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
||||||
ConstImpl.a();
|
ConstImpl.a();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue