Skip to content

Commit 813862f

Browse files
committed
trait_sel: extend fast path with constness
Extends the fast path for `Sized` traits to include `const {Meta,}Sized`.
1 parent 9fe7ae5 commit 813862f

File tree

1 file changed

+17
-0
lines changed
  • compiler/rustc_trait_selection/src/traits

1 file changed

+17
-0
lines changed

compiler/rustc_trait_selection/src/traits/util.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,23 @@ pub fn sizedness_fast_path<'tcx>(
548548
}
549549
}
550550

551+
// Likewise, determining if a sizedness trait is implemented const-ly is a trivial
552+
// determination that can happen in the fast path.
553+
//
554+
// NOTE: Keep this in sync with `evaluate_host_effect_for_sizedness_goal` in the old solver,
555+
// `const_conditions_for_sizedness` in the new solver.
556+
if let ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(host_pred)) =
557+
predicate.kind().skip_binder()
558+
{
559+
let is_sizedness = tcx.is_lang_item(host_pred.def_id(), LangItem::Sized)
560+
|| tcx.is_lang_item(host_pred.def_id(), LangItem::MetaSized);
561+
562+
if is_sizedness && !host_pred.self_ty().has_non_const_sizedness() {
563+
debug!("fast path -- host effect");
564+
return true;
565+
}
566+
}
567+
551568
false
552569
}
553570

0 commit comments

Comments
 (0)