Rollup merge of #106596 - estebank:verbose-e0271, r=compiler-errors
Hide more of long types in E0271 Fix #40186.
This commit is contained in:
commit
890bc3ca90
@ -283,6 +283,8 @@ pub trait PrettyPrinter<'tcx>:
|
|||||||
/// This is typically the case for all non-`'_` regions.
|
/// This is typically the case for all non-`'_` regions.
|
||||||
fn should_print_region(&self, region: ty::Region<'tcx>) -> bool;
|
fn should_print_region(&self, region: ty::Region<'tcx>) -> bool;
|
||||||
|
|
||||||
|
fn reset_type_limit(&mut self) {}
|
||||||
|
|
||||||
// Defaults (should not be overridden):
|
// Defaults (should not be overridden):
|
||||||
|
|
||||||
/// If possible, this returns a global path resolving to `def_id` that is visible
|
/// If possible, this returns a global path resolving to `def_id` that is visible
|
||||||
@ -1981,6 +1983,10 @@ impl<'tcx> PrettyPrinter<'tcx> for FmtPrinter<'_, 'tcx> {
|
|||||||
self.0.ty_infer_name_resolver.as_ref().and_then(|func| func(id))
|
self.0.ty_infer_name_resolver.as_ref().and_then(|func| func(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn reset_type_limit(&mut self) {
|
||||||
|
self.printed_type_count = 0;
|
||||||
|
}
|
||||||
|
|
||||||
fn const_infer_name(&self, id: ty::ConstVid<'tcx>) -> Option<Symbol> {
|
fn const_infer_name(&self, id: ty::ConstVid<'tcx>) -> Option<Symbol> {
|
||||||
self.0.const_infer_name_resolver.as_ref().and_then(|func| func(id))
|
self.0.const_infer_name_resolver.as_ref().and_then(|func| func(id))
|
||||||
}
|
}
|
||||||
@ -2722,11 +2728,15 @@ define_print_and_forward_display! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ty::SubtypePredicate<'tcx> {
|
ty::SubtypePredicate<'tcx> {
|
||||||
p!(print(self.a), " <: ", print(self.b))
|
p!(print(self.a), " <: ");
|
||||||
|
cx.reset_type_limit();
|
||||||
|
p!(print(self.b))
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::CoercePredicate<'tcx> {
|
ty::CoercePredicate<'tcx> {
|
||||||
p!(print(self.a), " -> ", print(self.b))
|
p!(print(self.a), " -> ");
|
||||||
|
cx.reset_type_limit();
|
||||||
|
p!(print(self.b))
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::TraitPredicate<'tcx> {
|
ty::TraitPredicate<'tcx> {
|
||||||
@ -2738,7 +2748,9 @@ define_print_and_forward_display! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ty::ProjectionPredicate<'tcx> {
|
ty::ProjectionPredicate<'tcx> {
|
||||||
p!(print(self.projection_ty), " == ", print(self.term))
|
p!(print(self.projection_ty), " == ");
|
||||||
|
cx.reset_type_limit();
|
||||||
|
p!(print(self.term))
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::Term<'tcx> {
|
ty::Term<'tcx> {
|
||||||
|
@ -1724,7 +1724,19 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||||||
.and_then(|(predicate, _, normalized_term, expected_term)| {
|
.and_then(|(predicate, _, normalized_term, expected_term)| {
|
||||||
self.maybe_detailed_projection_msg(predicate, normalized_term, expected_term)
|
self.maybe_detailed_projection_msg(predicate, normalized_term, expected_term)
|
||||||
})
|
})
|
||||||
.unwrap_or_else(|| format!("type mismatch resolving `{}`", predicate));
|
.unwrap_or_else(|| {
|
||||||
|
with_forced_trimmed_paths!(format!(
|
||||||
|
"type mismatch resolving `{}`",
|
||||||
|
self.resolve_vars_if_possible(predicate)
|
||||||
|
.print(FmtPrinter::new_with_limit(
|
||||||
|
self.tcx,
|
||||||
|
Namespace::TypeNS,
|
||||||
|
rustc_session::Limit(10),
|
||||||
|
))
|
||||||
|
.unwrap()
|
||||||
|
.into_buffer()
|
||||||
|
))
|
||||||
|
});
|
||||||
let mut diag = struct_span_err!(self.tcx.sess, obligation.cause.span, E0271, "{msg}");
|
let mut diag = struct_span_err!(self.tcx.sess, obligation.cause.span, E0271, "{msg}");
|
||||||
|
|
||||||
let secondary_span = match predicate.kind().skip_binder() {
|
let secondary_span = match predicate.kind().skip_binder() {
|
||||||
@ -1755,7 +1767,20 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||||||
kind: hir::ImplItemKind::Type(ty),
|
kind: hir::ImplItemKind::Type(ty),
|
||||||
..
|
..
|
||||||
}),
|
}),
|
||||||
) => Some((ty.span, format!("type mismatch resolving `{}`", predicate))),
|
) => Some((
|
||||||
|
ty.span,
|
||||||
|
with_forced_trimmed_paths!(format!(
|
||||||
|
"type mismatch resolving `{}`",
|
||||||
|
self.resolve_vars_if_possible(predicate)
|
||||||
|
.print(FmtPrinter::new_with_limit(
|
||||||
|
self.tcx,
|
||||||
|
Namespace::TypeNS,
|
||||||
|
rustc_session::Limit(5),
|
||||||
|
))
|
||||||
|
.unwrap()
|
||||||
|
.into_buffer()
|
||||||
|
)),
|
||||||
|
)),
|
||||||
_ => None,
|
_ => None,
|
||||||
}),
|
}),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -2622,11 +2622,25 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ObligationCauseCode::ObjectCastObligation(concrete_ty, object_ty) => {
|
ObligationCauseCode::ObjectCastObligation(concrete_ty, object_ty) => {
|
||||||
err.note(&format!(
|
let (concrete_ty, concrete_file) =
|
||||||
"required for the cast from `{}` to the object type `{}`",
|
self.tcx.short_ty_string(self.resolve_vars_if_possible(concrete_ty));
|
||||||
self.ty_to_string(concrete_ty),
|
let (object_ty, object_file) =
|
||||||
self.ty_to_string(object_ty)
|
self.tcx.short_ty_string(self.resolve_vars_if_possible(object_ty));
|
||||||
));
|
err.note(&with_forced_trimmed_paths!(format!(
|
||||||
|
"required for the cast from `{concrete_ty}` to the object type `{object_ty}`",
|
||||||
|
)));
|
||||||
|
if let Some(file) = concrete_file {
|
||||||
|
err.note(&format!(
|
||||||
|
"the full name for the casted type has been written to '{}'",
|
||||||
|
file.display(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
if let Some(file) = object_file {
|
||||||
|
err.note(&format!(
|
||||||
|
"the full name for the object type has been written to '{}'",
|
||||||
|
file.display(),
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ObligationCauseCode::Coercion { source: _, target } => {
|
ObligationCauseCode::Coercion { source: _, target } => {
|
||||||
err.note(&format!("required by cast to type `{}`", self.ty_to_string(target)));
|
err.note(&format!("required by cast to type `{}`", self.ty_to_string(target)));
|
||||||
|
33
tests/ui/diagnostic-width/E0271.rs
Normal file
33
tests/ui/diagnostic-width/E0271.rs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
// compile-flags: --diagnostic-width=40
|
||||||
|
// normalize-stderr-test: "long-type-\d+" -> "long-type-hash"
|
||||||
|
trait Future {
|
||||||
|
type Error;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T, E> Future for Result<T, E> {
|
||||||
|
type Error = E;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> Future for Option<T> {
|
||||||
|
type Error = ();
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Foo;
|
||||||
|
|
||||||
|
fn foo() -> Box<dyn Future<Error=Foo>> {
|
||||||
|
Box::new( //~ ERROR E0271
|
||||||
|
Ok::<_, ()>(
|
||||||
|
Err::<(), _>(
|
||||||
|
Ok::<_, ()>(
|
||||||
|
Err::<(), _>(
|
||||||
|
Ok::<_, ()>(
|
||||||
|
Err::<(), _>(Some(5))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
fn main() {
|
||||||
|
}
|
23
tests/ui/diagnostic-width/E0271.stderr
Normal file
23
tests/ui/diagnostic-width/E0271.stderr
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
error[E0271]: type mismatch resolving `<Result<Result<(), Result<Result<(), Result<Result<(), Option<{integer}>>, ...>>, ...>>, ...> as Future>::Error == Foo`
|
||||||
|
--> $DIR/E0271.rs:18:5
|
||||||
|
|
|
||||||
|
LL | / Box::new(
|
||||||
|
LL | | Ok::<_, ()>(
|
||||||
|
LL | | Err::<(), _>(
|
||||||
|
LL | | Ok::<_, ()>(
|
||||||
|
... |
|
||||||
|
LL | | )
|
||||||
|
LL | | )
|
||||||
|
| |_____^ type mismatch resolving `<Result<Result<(), Result<Result<(), ...>, ...>>, ...> as Future>::Error == Foo`
|
||||||
|
|
|
||||||
|
note: expected this to be `Foo`
|
||||||
|
--> $DIR/E0271.rs:8:18
|
||||||
|
|
|
||||||
|
LL | type Error = E;
|
||||||
|
| ^
|
||||||
|
= note: required for the cast from `Result<Result<..., ...>, ...>` to the object type `dyn Future<Error = Foo>`
|
||||||
|
= note: the full name for the casted type has been written to '$TEST_BUILD_DIR/diagnostic-width/E0271/E0271.long-type-hash.txt'
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0271`.
|
@ -1,4 +1,4 @@
|
|||||||
error[E0271]: type mismatch resolving `for<'r> <L<[closure@$DIR/issue-62203-hrtb-ice.rs:42:16: 42:19]> as T0<'r, (&'r u8,)>>::O == <_ as Ty<'r>>::V`
|
error[E0271]: type mismatch resolving `for<'r> <L<[closure@issue-62203-hrtb-ice.rs:42:16]> as T0<'r, (&'r u8,)>>::O == <_ as Ty<'r>>::V`
|
||||||
--> $DIR/issue-62203-hrtb-ice.rs:39:9
|
--> $DIR/issue-62203-hrtb-ice.rs:39:9
|
||||||
|
|
|
|
||||||
LL | let v = Unit2.m(
|
LL | let v = Unit2.m(
|
||||||
@ -10,7 +10,7 @@ LL | | f: |x| {
|
|||||||
... |
|
... |
|
||||||
LL | | },
|
LL | | },
|
||||||
LL | | },
|
LL | | },
|
||||||
| |_________^ type mismatch resolving `for<'r> <L<[closure@$DIR/issue-62203-hrtb-ice.rs:42:16: 42:19]> as T0<'r, (&'r u8,)>>::O == <_ as Ty<'r>>::V`
|
| |_________^ type mismatch resolving `for<'r> <L<[closure@issue-62203-hrtb-ice.rs:42:16]> as T0<'r, (&'r u8,)>>::O == <_ as Ty<'r>>::V`
|
||||||
|
|
|
|
||||||
note: expected this to be `<_ as Ty<'_>>::V`
|
note: expected this to be `<_ as Ty<'_>>::V`
|
||||||
--> $DIR/issue-62203-hrtb-ice.rs:21:14
|
--> $DIR/issue-62203-hrtb-ice.rs:21:14
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
error[E0271]: type mismatch resolving `<Foo<()> as FooLike>::Output == <T as impl_trait::Trait>::Assoc`
|
error[E0271]: type mismatch resolving `<Foo<()> as FooLike>::Output == <T as Trait>::Assoc`
|
||||||
--> $DIR/bound-normalization-fail.rs:25:32
|
--> $DIR/bound-normalization-fail.rs:25:32
|
||||||
|
|
|
|
||||||
LL | fn foo_fail<T: Trait>() -> impl FooLike<Output = T::Assoc> {
|
LL | fn foo_fail<T: Trait>() -> impl FooLike<Output = T::Assoc> {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<Foo<()> as FooLike>::Output == <T as impl_trait::Trait>::Assoc`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<Foo<()> as FooLike>::Output == <T as Trait>::Assoc`
|
||||||
LL |
|
LL |
|
||||||
LL | Foo(())
|
LL | Foo(())
|
||||||
| ------- return type was inferred to be `Foo<()>` here
|
| ------- return type was inferred to be `Foo<()>` here
|
||||||
@ -28,11 +28,11 @@ LL | fn foo2_fail<'a, T: Trait<'a>>() -> impl FooLike<Output = T::Assoc> {
|
|||||||
= note: see issue #103532 <https://github.com/rust-lang/rust/issues/103532> for more information
|
= note: see issue #103532 <https://github.com/rust-lang/rust/issues/103532> for more information
|
||||||
= help: add `#![feature(impl_trait_projections)]` to the crate attributes to enable
|
= help: add `#![feature(impl_trait_projections)]` to the crate attributes to enable
|
||||||
|
|
||||||
error[E0271]: type mismatch resolving `<Foo<()> as FooLike>::Output == <T as lifetimes::Trait<'a>>::Assoc`
|
error[E0271]: type mismatch resolving `<Foo<()> as FooLike>::Output == <T as Trait<'a>>::Assoc`
|
||||||
--> $DIR/bound-normalization-fail.rs:41:41
|
--> $DIR/bound-normalization-fail.rs:41:41
|
||||||
|
|
|
|
||||||
LL | fn foo2_fail<'a, T: Trait<'a>>() -> impl FooLike<Output = T::Assoc> {
|
LL | fn foo2_fail<'a, T: Trait<'a>>() -> impl FooLike<Output = T::Assoc> {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<Foo<()> as FooLike>::Output == <T as lifetimes::Trait<'a>>::Assoc`
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<Foo<()> as FooLike>::Output == <T as Trait<'a>>::Assoc`
|
||||||
...
|
...
|
||||||
LL | Foo(())
|
LL | Foo(())
|
||||||
| ------- return type was inferred to be `Foo<()>` here
|
| ------- return type was inferred to be `Foo<()>` here
|
||||||
|
Loading…
x
Reference in New Issue
Block a user