Fix #40186.
/// This is typically the case for all non-`'_` regions.
fn should_print_region(&self, region: ty::Region<'tcx>) -> bool;
+ fn reset_type_limit(&mut self) {}
+
// Defaults (should not be overridden):
/// If possible, this returns a global path resolving to `def_id` that is visible
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> {
self.0.const_infer_name_resolver.as_ref().and_then(|func| func(id))
}
}
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> {
- p!(print(self.a), " -> ", print(self.b))
+ p!(print(self.a), " -> ");
+ cx.reset_type_limit();
+ p!(print(self.b))
}
ty::TraitPredicate<'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> {
.and_then(|(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 secondary_span = match predicate.kind().skip_binder() {
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,
}
}
ObligationCauseCode::ObjectCastObligation(concrete_ty, object_ty) => {
- err.note(&format!(
- "required for the cast from `{}` to the object type `{}`",
- self.ty_to_string(concrete_ty),
- self.ty_to_string(object_ty)
- ));
+ let (concrete_ty, concrete_file) =
+ self.tcx.short_ty_string(self.resolve_vars_if_possible(concrete_ty));
+ let (object_ty, object_file) =
+ 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 } => {
err.note(&format!("required by cast to type `{}`", self.ty_to_string(target)));
--- /dev/null
+// 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() {
+}
--- /dev/null
+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`.
-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
|
LL | let v = Unit2.m(
... |
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`
--> $DIR/issue-62203-hrtb-ice.rs:21:14
-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
|
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 | Foo(())
| ------- return type was inferred to be `Foo<()>` here
= 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
-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
|
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(())
| ------- return type was inferred to be `Foo<()>` here