Display short types for unimplemented trait
This commit is contained in:
parent
ef324565d0
commit
c0ce0f3c3f
@ -669,6 +669,7 @@ pub fn evaluate(
|
||||
options.iter().filter_map(|(k, v)| v.clone().map(|v| (*k, v))).collect();
|
||||
|
||||
for command in self.subcommands.iter().chain(Some(self)).rev() {
|
||||
debug!(?command);
|
||||
if let Some(ref condition) = command.condition
|
||||
&& !attr::eval_condition(condition, &tcx.sess, Some(tcx.features()), &mut |cfg| {
|
||||
let value = cfg.value.map(|v| {
|
||||
@ -824,7 +825,11 @@ pub fn format(
|
||||
.filter_map(|param| {
|
||||
let value = match param.kind {
|
||||
GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => {
|
||||
trait_ref.args[param.index as usize].to_string()
|
||||
if let Some(ty) = trait_ref.args[param.index as usize].as_type() {
|
||||
tcx.short_ty_string(ty, &mut None)
|
||||
} else {
|
||||
trait_ref.args[param.index as usize].to_string()
|
||||
}
|
||||
}
|
||||
GenericParamDefKind::Lifetime => return None,
|
||||
};
|
||||
|
@ -3507,7 +3507,8 @@ fn note_obligation_cause_code<G: EmissionGuarantee, T>(
|
||||
}
|
||||
ObligationCauseCode::OpaqueReturnType(expr_info) => {
|
||||
if let Some((expr_ty, expr_span)) = expr_info {
|
||||
let expr_ty = with_forced_trimmed_paths!(self.ty_to_string(expr_ty));
|
||||
let expr_ty =
|
||||
with_forced_trimmed_paths!(self.tcx.short_ty_string(expr_ty, &mut None));
|
||||
err.span_label(
|
||||
expr_span,
|
||||
with_forced_trimmed_paths!(format!(
|
||||
|
@ -389,6 +389,7 @@ fn report_selection_error(
|
||||
kind: _,
|
||||
} = *obligation.cause.code()
|
||||
{
|
||||
debug!("ObligationCauseCode::CompareImplItemObligation");
|
||||
return self.report_extra_impl_obligation(
|
||||
span,
|
||||
impl_item_def_id,
|
||||
|
17
tests/ui/traits/on_unimplemented_long_types.rs
Normal file
17
tests/ui/traits/on_unimplemented_long_types.rs
Normal file
@ -0,0 +1,17 @@
|
||||
//@ compile-flags: --diagnostic-width=60 -Z write-long-types-to-disk=yes
|
||||
//@ normalize-stderr-test: "long-type-\d+" -> "long-type-hash"
|
||||
|
||||
pub fn foo() -> impl std::fmt::Display {
|
||||
//~^ ERROR doesn't implement `std::fmt::Display`
|
||||
Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(
|
||||
Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(
|
||||
Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(
|
||||
Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(
|
||||
Some(Some(Some(Some(Some(Some(Some(Some(())))))))),
|
||||
))))))))))),
|
||||
))))))))))),
|
||||
))))))))))),
|
||||
)))))))))))
|
||||
}
|
||||
|
||||
fn main() {}
|
21
tests/ui/traits/on_unimplemented_long_types.stderr
Normal file
21
tests/ui/traits/on_unimplemented_long_types.stderr
Normal file
@ -0,0 +1,21 @@
|
||||
error[E0277]: `Option<Option<Option<...>>>` doesn't implement `std::fmt::Display`
|
||||
--> $DIR/on_unimplemented_long_types.rs:4:17
|
||||
|
|
||||
LL | pub fn foo() -> impl std::fmt::Display {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ `Option<Option<Option<...>>>` cannot be formatted with the default formatter
|
||||
LL |
|
||||
LL | / Some(Some(Some(Some(Some(Some(Some(Some(Some(S...
|
||||
LL | | Some(Some(Some(Some(Some(Some(Some(Some(So...
|
||||
LL | | Some(Some(Some(Some(Some(Some(Some(Som...
|
||||
LL | | Some(Some(Some(Some(Some(Some(Some...
|
||||
... |
|
||||
LL | | ))))))))))),
|
||||
LL | | )))))))))))
|
||||
| |_______________- return type was inferred to be `Option<Option<Option<...>>>` here
|
||||
|
|
||||
= help: the trait `std::fmt::Display` is not implemented for `Option<Option<Option<...>>>`
|
||||
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
Loading…
Reference in New Issue
Block a user