1
Fork 0

Display short types for unimplemented trait

This commit is contained in:
许杰友 Jieyou Xu (Joe) 2024-02-28 14:13:42 +00:00
parent ef324565d0
commit c0ce0f3c3f
No known key found for this signature in database
GPG key ID: 95DDEBD74A1DC2C0
5 changed files with 47 additions and 2 deletions

View file

@ -669,6 +669,7 @@ impl<'tcx> OnUnimplementedDirective {
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 @@ impl<'tcx> OnUnimplementedFormatString {
.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,
};

View file

@ -3507,7 +3507,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
}
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!(

View file

@ -389,6 +389,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
kind: _,
} = *obligation.cause.code()
{
debug!("ObligationCauseCode::CompareImplItemObligation");
return self.report_extra_impl_obligation(
span,
impl_item_def_id,