From 48291cf1d73c72523c70df009422cadc6d9e07af Mon Sep 17 00:00:00 2001 From: Nicholas-Baron Date: Sun, 11 Oct 2020 15:59:41 -0700 Subject: [PATCH] Moved some short functions back into fn_ctxt.rs --- compiler/rustc_typeck/src/check/fn_ctxt.rs | 17 +++++++++++++++-- compiler/rustc_typeck/src/check/fn_ctxt_impl.rs | 11 ----------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/compiler/rustc_typeck/src/check/fn_ctxt.rs b/compiler/rustc_typeck/src/check/fn_ctxt.rs index 48c17170c96..dff54cae4df 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt.rs @@ -11,7 +11,9 @@ use rustc_middle::hir::map::blocks::FnLikeNode; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::subst::GenericArgKind; use rustc_middle::ty::{self, Const, Ty, TyCtxt}; +use rustc_session::Session; use rustc_span::{self, Span}; +use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode}; use std::cell::{Cell, RefCell}; use std::ops::Deref; @@ -104,8 +106,6 @@ pub struct FnCtxt<'a, 'tcx> { pub(super) inh: &'a Inherited<'a, 'tcx>, } -// FIXME: This impl is for functions which access the (private) `err_count_on_creation` field. -// It looks like that field will be changed soon and so this solution may end up being temporary. impl<'a, 'tcx> FnCtxt<'a, 'tcx> { pub fn new( inh: &'a Inherited<'a, 'tcx>, @@ -132,6 +132,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { inh, } } + + pub fn cause(&self, span: Span, code: ObligationCauseCode<'tcx>) -> ObligationCause<'tcx> { + ObligationCause::new(span, self.body_id, code) + } + + pub fn misc(&self, span: Span) -> ObligationCause<'tcx> { + self.cause(span, ObligationCauseCode::MiscObligation) + } + + pub fn sess(&self) -> &Session { + &self.tcx.sess + } + pub fn errors_reported_since_creation(&self) -> bool { self.tcx.sess.err_count() > self.err_count_on_creation } diff --git a/compiler/rustc_typeck/src/check/fn_ctxt_impl.rs b/compiler/rustc_typeck/src/check/fn_ctxt_impl.rs index 4a9172a0e25..17ced624e4b 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt_impl.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt_impl.rs @@ -54,9 +54,6 @@ use std::mem::replace; use std::slice; impl<'a, 'tcx> FnCtxt<'a, 'tcx> { - pub fn sess(&self) -> &Session { - &self.tcx.sess - } /// Produces warning on the given node, if the current point in the /// function is unreachable, and there hasn't been another warning. @@ -90,14 +87,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - pub fn cause(&self, span: Span, code: ObligationCauseCode<'tcx>) -> ObligationCause<'tcx> { - ObligationCause::new(span, self.body_id, code) - } - - pub fn misc(&self, span: Span) -> ObligationCause<'tcx> { - self.cause(span, ObligationCauseCode::MiscObligation) - } - /// Resolves type and const variables in `ty` if possible. Unlike the infcx /// version (resolve_vars_if_possible), this version will /// also select obligations if it seems useful, in an effort