Add a helper function for checking whether a default function in a trait can be treated as const
This commit is contained in:
parent
257f06587c
commit
4d390de4a3
7 changed files with 20 additions and 18 deletions
|
@ -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>(
|
||||
|
@ -152,7 +152,9 @@ 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 matches!(tcx.trait_of_item(def_id), Some(trait_id) if tcx.has_attr(trait_id, sym::const_trait)) => {
|
||||
hir::Node::TraitItem(hir::TraitItem { kind: hir::TraitItemKind::Fn(..), .. })
|
||||
if tcx.is_const_default_method(def_id) =>
|
||||
{
|
||||
hir::Constness::Const
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue