@@ -11,7 +11,9 @@ use rustc_middle::hir::map::blocks::FnLikeNode;
1111use rustc_middle::ty::fold::TypeFoldable;
1212use rustc_middle::ty::subst::GenericArgKind;
1313use rustc_middle::ty::{self, Const, Ty, TyCtxt};
14+ use rustc_session::Session;
1415use rustc_span::{self, Span};
16+ use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode};
1517
1618use std::cell::{Cell, RefCell};
1719use std::ops::Deref;
@@ -104,8 +106,6 @@ pub struct FnCtxt<'a, 'tcx> {
104106 pub(super) inh: &'a Inherited<'a, 'tcx>,
105107}
106108
107- // FIXME: This impl is for functions which access the (private) `err_count_on_creation` field.
108- // It looks like that field will be changed soon and so this solution may end up being temporary.
109109impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
110110 pub fn new(
111111 inh: &'a Inherited<'a, 'tcx>,
@@ -132,6 +132,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
132132 inh,
133133 }
134134 }
135+
136+ pub fn cause(&self, span: Span, code: ObligationCauseCode<'tcx>) -> ObligationCause<'tcx> {
137+ ObligationCause::new(span, self.body_id, code)
138+ }
139+
140+ pub fn misc(&self, span: Span) -> ObligationCause<'tcx> {
141+ self.cause(span, ObligationCauseCode::MiscObligation)
142+ }
143+
144+ pub fn sess(&self) -> &Session {
145+ &self.tcx.sess
146+ }
147+
135148 pub fn errors_reported_since_creation(&self) -> bool {
136149 self.tcx.sess.err_count() > self.err_count_on_creation
137150 }
0 commit comments