Rollup merge of #104469 - estebank:long-types, r=oli-obk

Make "long type" printing type aware and trim types in E0275

Instead of simple string cutting, use a custom printer to hide parts of long printed types.

On E0275, check for type length before printing.
This commit is contained in:
Matthias Krüger 2022-11-19 15:35:21 +01:00 committed by GitHub
commit 06707c073d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 208 additions and 97 deletions

View file

@ -42,6 +42,7 @@ use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams};
use rustc_middle::ty::fold::BottomUpFolder;
use rustc_middle::ty::print::{FmtPrinter, Print};
use rustc_middle::ty::relate::TypeRelation;
use rustc_middle::ty::SubstsRef;
use rustc_middle::ty::{self, EarlyBinder, PolyProjectionPredicate, ToPolyTraitRef, ToPredicate};
@ -1081,11 +1082,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
it.for_each(|o| o.recursion_depth = cmp::max(min_depth, o.recursion_depth) + 1);
}
fn check_recursion_depth<T: Display + TypeFoldable<'tcx>>(
fn check_recursion_depth<T>(
&self,
depth: usize,
error_obligation: &Obligation<'tcx, T>,
) -> Result<(), OverflowError> {
) -> Result<(), OverflowError>
where
T: fmt::Display
+ TypeFoldable<'tcx>
+ Print<'tcx, FmtPrinter<'tcx, 'tcx>, Output = FmtPrinter<'tcx, 'tcx>>,
<T as Print<'tcx, FmtPrinter<'tcx, 'tcx>>>::Error: std::fmt::Debug,
{
if !self.infcx.tcx.recursion_limit().value_within_limit(depth) {
match self.query_mode {
TraitQueryMode::Standard => {
@ -1107,11 +1114,17 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
/// The weird return type of this function allows it to be used with the `try` (`?`)
/// operator within certain functions.
#[inline(always)]
fn check_recursion_limit<T: Display + TypeFoldable<'tcx>, V: Display + TypeFoldable<'tcx>>(
fn check_recursion_limit<T: Display + TypeFoldable<'tcx>, V>(
&self,
obligation: &Obligation<'tcx, T>,
error_obligation: &Obligation<'tcx, V>,
) -> Result<(), OverflowError> {
) -> Result<(), OverflowError>
where
V: fmt::Display
+ TypeFoldable<'tcx>
+ Print<'tcx, FmtPrinter<'tcx, 'tcx>, Output = FmtPrinter<'tcx, 'tcx>>,
<V as Print<'tcx, FmtPrinter<'tcx, 'tcx>>>::Error: std::fmt::Debug,
{
self.check_recursion_depth(obligation.recursion_depth, error_obligation)
}