1
Fork 0

Auto merge of #96964 - oli-obk:const_trait_mvp, r=compiler-errors

Replace `#[default_method_body_is_const]` with `#[const_trait]`

pulled out of #96077

related issues:  #67792 and #92158

cc `@fee1-dead`

This is groundwork to only allowing `impl const Trait` for traits that are marked with `#[const_trait]`. This is necessary to prevent adding a new default method from becoming a breaking change (as it could be a non-const fn).
This commit is contained in:
bors 2022-05-30 09:19:03 +00:00
commit 5c780b98d1
32 changed files with 82 additions and 260 deletions

View file

@ -5,7 +5,7 @@ use rustc_middle::ty::subst::Subst;
use rustc_middle::ty::{
self, Binder, EarlyBinder, Predicate, PredicateKind, ToPredicate, Ty, TyCtxt,
};
use rustc_span::{sym, Span};
use rustc_span::Span;
use rustc_trait_selection::traits;
fn sized_constraint_for_ty<'tcx>(
@ -153,7 +153,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
let constness = match hir_id {
Some(hir_id) => match tcx.hir().get(hir_id) {
hir::Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Fn(..), .. })
if tcx.has_attr(def_id, sym::default_method_body_is_const) =>
if tcx.is_const_default_method(def_id) =>
{
hir::Constness::Const
}