Rollup merge of #92432 - fee1-dead:constck-impl-constness, r=oli-obk
Error when selected impl is not const in constck Catches bad things when checking a `default_method_body_is_const` body, such as: ```rust self.map(/* .. */).is_sorted(); ``` When `Map` does not yet have a `const` `impl` for `Iterator`. r? ```@oli-obk```
This commit is contained in:
commit
6726f1e013
3 changed files with 31 additions and 1 deletions
|
@ -810,7 +810,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
|
||||||
param_env,
|
param_env,
|
||||||
Binder::dummy(TraitPredicate {
|
Binder::dummy(TraitPredicate {
|
||||||
trait_ref,
|
trait_ref,
|
||||||
constness: ty::BoundConstness::ConstIfConst,
|
constness: ty::BoundConstness::NotConst,
|
||||||
polarity: ty::ImplPolarity::Positive,
|
polarity: ty::ImplPolarity::Positive,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
@ -829,6 +829,10 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Ok(Some(ImplSource::UserDefined(data))) => {
|
Ok(Some(ImplSource::UserDefined(data))) => {
|
||||||
|
if let hir::Constness::NotConst = tcx.impl_constness(data.impl_def_id) {
|
||||||
|
self.check_op(ops::FnCallNonConst(None));
|
||||||
|
return;
|
||||||
|
}
|
||||||
let callee_name = tcx.item_name(callee);
|
let callee_name = tcx.item_name(callee);
|
||||||
if let Some(&did) = tcx
|
if let Some(&did) = tcx
|
||||||
.associated_item_def_ids(data.impl_def_id)
|
.associated_item_def_ids(data.impl_def_id)
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
#![feature(const_fn_trait_bound)]
|
||||||
|
#![feature(const_trait_impl)]
|
||||||
|
|
||||||
|
pub trait Tr {
|
||||||
|
#[default_method_body_is_const]
|
||||||
|
fn a(&self) {}
|
||||||
|
|
||||||
|
#[default_method_body_is_const]
|
||||||
|
fn b(&self) {
|
||||||
|
().a()
|
||||||
|
//~^ ERROR calls in constant functions are limited
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Tr for () {}
|
||||||
|
|
||||||
|
fn main() {}
|
|
@ -0,0 +1,9 @@
|
||||||
|
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
|
||||||
|
--> $DIR/default-method-body-is-const-same-trait-ck.rs:10:9
|
||||||
|
|
|
||||||
|
LL | ().a()
|
||||||
|
| ^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0015`.
|
Loading…
Add table
Add a link
Reference in a new issue