Skip to content

Commit a97384d

Browse files
authored
Rollup merge of rust-lang#92001 - fee1-dead:dmbic-xcrate-fix, r=oli-obk
Fix default_method_body_is_const when used across crates r? `@oli-obk` unblocks rust-lang#91439.
2 parents 176fb18 + 4bb65e1 commit a97384d

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -870,8 +870,9 @@ fn should_encode_mir(tcx: TyCtxt<'_>, def_id: LocalDefId) -> (bool, bool) {
870870
let needs_inline = (generics.requires_monomorphization(tcx)
871871
|| tcx.codegen_fn_attrs(def_id).requests_inline())
872872
&& tcx.sess.opts.output_types.should_codegen();
873-
// Only check the presence of the `const` modifier.
874-
let is_const_fn = tcx.is_const_fn_raw(def_id.to_def_id());
873+
// The function has a `const` modifier or is annotated with `default_method_body_is_const`.
874+
let is_const_fn = tcx.is_const_fn_raw(def_id.to_def_id())
875+
|| tcx.has_attr(def_id.to_def_id(), sym::default_method_body_is_const);
875876
let always_encode_mir = tcx.sess.opts.debugging_opts.always_encode_mir;
876877
(is_const_fn, needs_inline || always_encode_mir)
877878
}

src/test/ui/rfc-2632-const-trait-impl/auxiliary/cross-crate.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
#![feature(const_fn_trait_bound)]
12
#![feature(const_trait_impl)]
23

34
pub trait MyTrait {
5+
#[default_method_body_is_const]
6+
fn defaulted_func(&self) {}
47
fn func(self);
58
}
69

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// This tests that `default_method_body_is_const` methods can
2+
// be called from a const context when used across crates.
3+
//
4+
// check-pass
5+
6+
#![feature(const_trait_impl)]
7+
8+
// aux-build: cross-crate.rs
9+
extern crate cross_crate;
10+
11+
use cross_crate::*;
12+
13+
const _: () = {
14+
Const.func();
15+
Const.defaulted_func();
16+
};
17+
18+
fn main() {}

0 commit comments

Comments
 (0)