about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMaybe Waffle <waffle.lapkin@gmail.com>2023-04-25 15:34:21 +0000
committerMaybe Waffle <waffle.lapkin@gmail.com>2023-04-25 15:34:21 +0000
commit14f832733d89a968b347ced1a82f84abfeda13b0 (patch)
tree83461f76fc7338bacdcab2f864f7872cbead058b
parent91b61a4ad618c1abc2af43a58695de185ef1e513 (diff)
downloadrust-14f832733d89a968b347ced1a82f84abfeda13b0.tar.gz
rust-14f832733d89a968b347ced1a82f84abfeda13b0.zip
Add `ty::TraitRef::{new, from_lang_item}`
-rw-r--r--compiler/rustc_middle/src/ty/context.rs2
-rw-r--r--compiler/rustc_middle/src/ty/sty.rs19
2 files changed, 20 insertions, 1 deletions
diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs
index 4a4f6770fc4..03cd978be92 100644
--- a/compiler/rustc_middle/src/ty/context.rs
+++ b/compiler/rustc_middle/src/ty/context.rs
@@ -1861,7 +1861,7 @@ impl<'tcx> TyCtxt<'tcx> {
     }
 
     #[inline(always)]
-    fn check_and_mk_substs(
+    pub(crate) fn check_and_mk_substs(
         self,
         _def_id: DefId,
         substs: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs
index 29ae42be096..8002e0cb95f 100644
--- a/compiler/rustc_middle/src/ty/sty.rs
+++ b/compiler/rustc_middle/src/ty/sty.rs
@@ -3,6 +3,7 @@
 #![allow(rustc::usage_of_ty_tykind)]
 
 use crate::infer::canonical::Canonical;
+use crate::ty::query::TyCtxtAt;
 use crate::ty::subst::{GenericArg, InternalSubsts, SubstsRef};
 use crate::ty::visit::ValidateBoundVars;
 use crate::ty::InferTy::*;
@@ -825,6 +826,24 @@ pub struct TraitRef<'tcx> {
 }
 
 impl<'tcx> TraitRef<'tcx> {
+    pub fn new(
+        tcx: TyCtxt<'tcx>,
+        trait_def_id: DefId,
+        substs: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
+    ) -> Self {
+        let substs = tcx.check_and_mk_substs(trait_def_id, substs);
+        Self { def_id: trait_def_id, substs, _use_mk_trait_ref_instead: () }
+    }
+
+    pub fn from_lang_item(
+        tcx: TyCtxtAt<'tcx>,
+        trait_lang_item: LangItem,
+        substs: impl IntoIterator<Item: Into<ty::GenericArg<'tcx>>>,
+    ) -> Self {
+        let trait_def_id = tcx.require_lang_item(trait_lang_item, Some(tcx.span));
+        Self::new(tcx.tcx, trait_def_id, substs)
+    }
+
     pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
         tcx.mk_trait_ref(
             self.def_id,