Skip to content

Commit

Permalink
review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Nov 18, 2022
1 parent 3debf50 commit bcb2655
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
10 changes: 5 additions & 5 deletions compiler/rustc_middle/src/ty/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -990,15 +990,15 @@ fn foo(&self) -> Self::T { String::new() }
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 type_limit = 4;
let regular = FmtPrinter::new(self, hir::def::Namespace::TypeNS)
.pretty_print_type(ty)
.expect("could not write to `String`")
.into_buffer();
if regular.len() <= length_limit {
return Ok(regular);
return (regular, None);
}
let short = FmtPrinter::new_with_limit(
self,
Expand All @@ -1009,16 +1009,16 @@ fn foo(&self) -> Self::T { String::new() }
.expect("could not write to `String`")
.into_buffer();
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.
let mut s = DefaultHasher::new();
ty.hash(&mut s);
let hash = s.finish();
let path = self.output_filenames(()).temp_path_ext(&format!("long-type-{hash}.txt"), None);
match std::fs::write(&path, &regular) {
Ok(_) => Err((short, path)),
Err(_) => Ok(regular),
Ok(_) => (short, Some(path)),
Err(_) => (regular, None),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2734,10 +2734,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
parent_trait_pred.remap_constness_diag(param_env);
let parent_def_id = parent_trait_pred.def_id();
let (self_ty, file) =
match 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)),
};
self.tcx.short_ty_string(parent_trait_pred.skip_binder().self_ty());
let msg = format!(
"required for `{self_ty}` to implement `{}`",
parent_trait_pred.print_modifiers_and_trait_path()
Expand Down Expand Up @@ -2815,10 +2812,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
pluralize!(count)
));
let (self_ty, file) =
match 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)),
};
self.tcx.short_ty_string(parent_trait_pred.skip_binder().self_ty());
err.note(&format!(
"required for `{self_ty}` to implement `{}`",
parent_trait_pred.print_modifiers_and_trait_path()
Expand Down

0 comments on commit bcb2655

Please sign in to comment.