Skip to content

Commit 14f8327

Browse files
committed
Add ty::TraitRef::{new, from_lang_item}
1 parent 91b61a4 commit 14f8327

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1861,7 +1861,7 @@ impl<'tcx> TyCtxt<'tcx> {
18611861
}
18621862

18631863
#[inline(always)]
1864-
fn check_and_mk_substs(
1864+
pub(crate) fn check_and_mk_substs(
18651865
self,
18661866
_def_id: DefId,
18671867
substs: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#![allow(rustc::usage_of_ty_tykind)]
44

55
use crate::infer::canonical::Canonical;
6+
use crate::ty::query::TyCtxtAt;
67
use crate::ty::subst::{GenericArg, InternalSubsts, SubstsRef};
78
use crate::ty::visit::ValidateBoundVars;
89
use crate::ty::InferTy::*;
@@ -825,6 +826,24 @@ pub struct TraitRef<'tcx> {
825826
}
826827

827828
impl<'tcx> TraitRef<'tcx> {
829+
pub fn new(
830+
tcx: TyCtxt<'tcx>,
831+
trait_def_id: DefId,
832+
substs: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
833+
) -> Self {
834+
let substs = tcx.check_and_mk_substs(trait_def_id, substs);
835+
Self { def_id: trait_def_id, substs, _use_mk_trait_ref_instead: () }
836+
}
837+
838+
pub fn from_lang_item(
839+
tcx: TyCtxtAt<'tcx>,
840+
trait_lang_item: LangItem,
841+
substs: impl IntoIterator<Item: Into<ty::GenericArg<'tcx>>>,
842+
) -> Self {
843+
let trait_def_id = tcx.require_lang_item(trait_lang_item, Some(tcx.span));
844+
Self::new(tcx.tcx, trait_def_id, substs)
845+
}
846+
828847
pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
829848
tcx.mk_trait_ref(
830849
self.def_id,

0 commit comments

Comments
 (0)