Fix default_method_body_is_const when used across crates
This commit is contained in:
parent
df89fd2063
commit
4bb65e1c79
3 changed files with 24 additions and 2 deletions
|
@ -869,8 +869,9 @@ fn should_encode_mir(tcx: TyCtxt<'_>, def_id: LocalDefId) -> (bool, bool) {
|
||||||
let needs_inline = (generics.requires_monomorphization(tcx)
|
let needs_inline = (generics.requires_monomorphization(tcx)
|
||||||
|| tcx.codegen_fn_attrs(def_id).requests_inline())
|
|| tcx.codegen_fn_attrs(def_id).requests_inline())
|
||||||
&& tcx.sess.opts.output_types.should_codegen();
|
&& tcx.sess.opts.output_types.should_codegen();
|
||||||
// Only check the presence of the `const` modifier.
|
// The function has a `const` modifier or is annotated with `default_method_body_is_const`.
|
||||||
let is_const_fn = tcx.is_const_fn_raw(def_id.to_def_id());
|
let is_const_fn = tcx.is_const_fn_raw(def_id.to_def_id())
|
||||||
|
|| tcx.has_attr(def_id.to_def_id(), sym::default_method_body_is_const);
|
||||||
let always_encode_mir = tcx.sess.opts.debugging_opts.always_encode_mir;
|
let always_encode_mir = tcx.sess.opts.debugging_opts.always_encode_mir;
|
||||||
(is_const_fn, needs_inline || always_encode_mir)
|
(is_const_fn, needs_inline || always_encode_mir)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
|
#![feature(const_fn_trait_bound)]
|
||||||
#![feature(const_trait_impl)]
|
#![feature(const_trait_impl)]
|
||||||
|
|
||||||
pub trait MyTrait {
|
pub trait MyTrait {
|
||||||
|
#[default_method_body_is_const]
|
||||||
|
fn defaulted_func(&self) {}
|
||||||
fn func(self);
|
fn func(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
// This tests that `default_method_body_is_const` methods can
|
||||||
|
// be called from a const context when used across crates.
|
||||||
|
//
|
||||||
|
// check-pass
|
||||||
|
|
||||||
|
#![feature(const_trait_impl)]
|
||||||
|
|
||||||
|
// aux-build: cross-crate.rs
|
||||||
|
extern crate cross_crate;
|
||||||
|
|
||||||
|
use cross_crate::*;
|
||||||
|
|
||||||
|
const _: () = {
|
||||||
|
Const.func();
|
||||||
|
Const.defaulted_func();
|
||||||
|
};
|
||||||
|
|
||||||
|
fn main() {}
|
Loading…
Reference in a new issue