Display short types for unimplemented trait
This commit is contained in:
parent
ef324565d0
commit
c0ce0f3c3f
5 changed files with 47 additions and 2 deletions
|
@ -669,6 +669,7 @@ impl<'tcx> OnUnimplementedDirective {
|
||||||
options.iter().filter_map(|(k, v)| v.clone().map(|v| (*k, v))).collect();
|
options.iter().filter_map(|(k, v)| v.clone().map(|v| (*k, v))).collect();
|
||||||
|
|
||||||
for command in self.subcommands.iter().chain(Some(self)).rev() {
|
for command in self.subcommands.iter().chain(Some(self)).rev() {
|
||||||
|
debug!(?command);
|
||||||
if let Some(ref condition) = command.condition
|
if let Some(ref condition) = command.condition
|
||||||
&& !attr::eval_condition(condition, &tcx.sess, Some(tcx.features()), &mut |cfg| {
|
&& !attr::eval_condition(condition, &tcx.sess, Some(tcx.features()), &mut |cfg| {
|
||||||
let value = cfg.value.map(|v| {
|
let value = cfg.value.map(|v| {
|
||||||
|
@ -824,8 +825,12 @@ impl<'tcx> OnUnimplementedFormatString {
|
||||||
.filter_map(|param| {
|
.filter_map(|param| {
|
||||||
let value = match param.kind {
|
let value = match param.kind {
|
||||||
GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => {
|
GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => {
|
||||||
|
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()
|
trait_ref.args[param.index as usize].to_string()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
GenericParamDefKind::Lifetime => return None,
|
GenericParamDefKind::Lifetime => return None,
|
||||||
};
|
};
|
||||||
let name = param.name;
|
let name = param.name;
|
||||||
|
|
|
@ -3507,7 +3507,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
}
|
}
|
||||||
ObligationCauseCode::OpaqueReturnType(expr_info) => {
|
ObligationCauseCode::OpaqueReturnType(expr_info) => {
|
||||||
if let Some((expr_ty, expr_span)) = 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(
|
err.span_label(
|
||||||
expr_span,
|
expr_span,
|
||||||
with_forced_trimmed_paths!(format!(
|
with_forced_trimmed_paths!(format!(
|
||||||
|
|
|
@ -389,6 +389,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
||||||
kind: _,
|
kind: _,
|
||||||
} = *obligation.cause.code()
|
} = *obligation.cause.code()
|
||||||
{
|
{
|
||||||
|
debug!("ObligationCauseCode::CompareImplItemObligation");
|
||||||
return self.report_extra_impl_obligation(
|
return self.report_extra_impl_obligation(
|
||||||
span,
|
span,
|
||||||
impl_item_def_id,
|
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…
Add table
Add a link
Reference in a new issue