1
Fork 0

Address more review comments

- Add back various diagnostic methods on `Session`.

  It seems unfortunate to duplicate these in so many places, but in the
  meantime, making the API inconsistent between `Session` and `Diagnostic`
  also seems unfortunate.

- Add back TyCtxtAt methods

  These will hopefully be used in the near future.

- Add back `with_const`, it would need to be added soon after anyway.
- Add back `split()` and `get_mut()`, they're useful.
This commit is contained in:
Joshua Nelson 2021-03-27 22:16:17 -04:00
parent 230e396a76
commit f3523544f1
5 changed files with 81 additions and 1 deletions

View file

@ -14,7 +14,7 @@ use crate::middle::stability;
use crate::mir::interpret::{self, Allocation, ConstValue, Scalar};
use crate::mir::{Body, Field, Local, Place, PlaceElem, ProjectionKind, Promoted};
use crate::traits;
use crate::ty::query::{self, OnDiskCache};
use crate::ty::query::{self, OnDiskCache, TyCtxtAt};
use crate::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst, SubstsRef, UserSubsts};
use crate::ty::TyKind::*;
use crate::ty::{
@ -2650,6 +2650,21 @@ impl<'tcx> TyCtxt<'tcx> {
}
}
impl TyCtxtAt<'tcx> {
/// Constructs a `TyKind::Error` type and registers a `delay_span_bug` to ensure it gets used.
#[track_caller]
pub fn ty_error(self) -> Ty<'tcx> {
self.tcx.ty_error_with_message(self.span, "TyKind::Error constructed but no error reported")
}
/// Constructs a `TyKind::Error` type and registers a `delay_span_bug` with the given `msg to
/// ensure it gets used.
#[track_caller]
pub fn ty_error_with_message(self, msg: &str) -> Ty<'tcx> {
self.tcx.ty_error_with_message(self.span, msg)
}
}
pub trait InternAs<T: ?Sized, R> {
type Output;
fn intern_with<F>(self, f: F) -> Self::Output

View file

@ -1208,6 +1208,11 @@ pub trait WithConstness: Sized {
ConstnessAnd { constness, value: self }
}
#[inline]
fn with_const(self) -> ConstnessAnd<Self> {
self.with_constness(Constness::Const)
}
#[inline]
fn without_const(self) -> ConstnessAnd<Self> {
self.with_constness(Constness::NotConst)

View file

@ -1058,6 +1058,20 @@ impl<T> Binder<T> {
{
Binder(f(self.0, u.0))
}
/// Splits the contents into two things that share the same binder
/// level as the original, returning two distinct binders.
///
/// `f` should consider bound regions at depth 1 to be free, and
/// anything it produces with bound regions at depth 1 will be
/// bound in the resulting return values.
pub fn split<U, V, F>(self, f: F) -> (Binder<U>, Binder<V>)
where
F: FnOnce(T) -> (U, V),
{
let (u, v) = f(self.0);
(Binder(u), Binder(v))
}
}
impl<T> Binder<Option<T>> {