review comment
This commit is contained in:
parent
3debf5006a
commit
bcb2655a9a
@ -990,7 +990,7 @@ fn foo(&self) -> Self::T { String::new() }
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn short_ty_string(self, ty: Ty<'tcx>) -> Result<String, (String, PathBuf)> {
|
pub fn short_ty_string(self, ty: Ty<'tcx>) -> (String, Option<PathBuf>) {
|
||||||
let length_limit = 50;
|
let length_limit = 50;
|
||||||
let type_limit = 4;
|
let type_limit = 4;
|
||||||
let regular = FmtPrinter::new(self, hir::def::Namespace::TypeNS)
|
let regular = FmtPrinter::new(self, hir::def::Namespace::TypeNS)
|
||||||
@ -998,7 +998,7 @@ fn foo(&self) -> Self::T { String::new() }
|
|||||||
.expect("could not write to `String`")
|
.expect("could not write to `String`")
|
||||||
.into_buffer();
|
.into_buffer();
|
||||||
if regular.len() <= length_limit {
|
if regular.len() <= length_limit {
|
||||||
return Ok(regular);
|
return (regular, None);
|
||||||
}
|
}
|
||||||
let short = FmtPrinter::new_with_limit(
|
let short = FmtPrinter::new_with_limit(
|
||||||
self,
|
self,
|
||||||
@ -1009,7 +1009,7 @@ fn foo(&self) -> Self::T { String::new() }
|
|||||||
.expect("could not write to `String`")
|
.expect("could not write to `String`")
|
||||||
.into_buffer();
|
.into_buffer();
|
||||||
if regular == short {
|
if regular == short {
|
||||||
return Ok(regular);
|
return (regular, None);
|
||||||
}
|
}
|
||||||
// Multiple types might be shortened in a single error, ensure we create a file for each.
|
// Multiple types might be shortened in a single error, ensure we create a file for each.
|
||||||
let mut s = DefaultHasher::new();
|
let mut s = DefaultHasher::new();
|
||||||
@ -1017,8 +1017,8 @@ fn foo(&self) -> Self::T { String::new() }
|
|||||||
let hash = s.finish();
|
let hash = s.finish();
|
||||||
let path = self.output_filenames(()).temp_path_ext(&format!("long-type-{hash}.txt"), None);
|
let path = self.output_filenames(()).temp_path_ext(&format!("long-type-{hash}.txt"), None);
|
||||||
match std::fs::write(&path, ®ular) {
|
match std::fs::write(&path, ®ular) {
|
||||||
Ok(_) => Err((short, path)),
|
Ok(_) => (short, Some(path)),
|
||||||
Err(_) => Ok(regular),
|
Err(_) => (regular, None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2734,10 +2734,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||||||
parent_trait_pred.remap_constness_diag(param_env);
|
parent_trait_pred.remap_constness_diag(param_env);
|
||||||
let parent_def_id = parent_trait_pred.def_id();
|
let parent_def_id = parent_trait_pred.def_id();
|
||||||
let (self_ty, file) =
|
let (self_ty, file) =
|
||||||
match self.tcx.short_ty_string(parent_trait_pred.skip_binder().self_ty()) {
|
self.tcx.short_ty_string(parent_trait_pred.skip_binder().self_ty());
|
||||||
Ok(self_ty) => (self_ty, None),
|
|
||||||
Err((self_ty, file)) => (self_ty, Some(file)),
|
|
||||||
};
|
|
||||||
let msg = format!(
|
let msg = format!(
|
||||||
"required for `{self_ty}` to implement `{}`",
|
"required for `{self_ty}` to implement `{}`",
|
||||||
parent_trait_pred.print_modifiers_and_trait_path()
|
parent_trait_pred.print_modifiers_and_trait_path()
|
||||||
@ -2815,10 +2812,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||||||
pluralize!(count)
|
pluralize!(count)
|
||||||
));
|
));
|
||||||
let (self_ty, file) =
|
let (self_ty, file) =
|
||||||
match self.tcx.short_ty_string(parent_trait_pred.skip_binder().self_ty()) {
|
self.tcx.short_ty_string(parent_trait_pred.skip_binder().self_ty());
|
||||||
Ok(self_ty) => (self_ty, None),
|
|
||||||
Err((self_ty, file)) => (self_ty, Some(file)),
|
|
||||||
};
|
|
||||||
err.note(&format!(
|
err.note(&format!(
|
||||||
"required for `{self_ty}` to implement `{}`",
|
"required for `{self_ty}` to implement `{}`",
|
||||||
parent_trait_pred.print_modifiers_and_trait_path()
|
parent_trait_pred.print_modifiers_and_trait_path()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user