Skip to content

Commit bcb2655

Browse files
committed
review comment
1 parent 3debf50 commit bcb2655

File tree

2 files changed

+7
-13
lines changed

2 files changed

+7
-13
lines changed

compiler/rustc_middle/src/ty/error.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -990,15 +990,15 @@ fn foo(&self) -> Self::T { String::new() }
990990
false
991991
}
992992

993-
pub fn short_ty_string(self, ty: Ty<'tcx>) -> Result<String, (String, PathBuf)> {
993+
pub fn short_ty_string(self, ty: Ty<'tcx>) -> (String, Option<PathBuf>) {
994994
let length_limit = 50;
995995
let type_limit = 4;
996996
let regular = FmtPrinter::new(self, hir::def::Namespace::TypeNS)
997997
.pretty_print_type(ty)
998998
.expect("could not write to `String`")
999999
.into_buffer();
10001000
if regular.len() <= length_limit {
1001-
return Ok(regular);
1001+
return (regular, None);
10021002
}
10031003
let short = FmtPrinter::new_with_limit(
10041004
self,
@@ -1009,16 +1009,16 @@ fn foo(&self) -> Self::T { String::new() }
10091009
.expect("could not write to `String`")
10101010
.into_buffer();
10111011
if regular == short {
1012-
return Ok(regular);
1012+
return (regular, None);
10131013
}
10141014
// Multiple types might be shortened in a single error, ensure we create a file for each.
10151015
let mut s = DefaultHasher::new();
10161016
ty.hash(&mut s);
10171017
let hash = s.finish();
10181018
let path = self.output_filenames(()).temp_path_ext(&format!("long-type-{hash}.txt"), None);
10191019
match std::fs::write(&path, &regular) {
1020-
Ok(_) => Err((short, path)),
1021-
Err(_) => Ok(regular),
1020+
Ok(_) => (short, Some(path)),
1021+
Err(_) => (regular, None),
10221022
}
10231023
}
10241024

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -2734,10 +2734,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
27342734
parent_trait_pred.remap_constness_diag(param_env);
27352735
let parent_def_id = parent_trait_pred.def_id();
27362736
let (self_ty, file) =
2737-
match self.tcx.short_ty_string(parent_trait_pred.skip_binder().self_ty()) {
2738-
Ok(self_ty) => (self_ty, None),
2739-
Err((self_ty, file)) => (self_ty, Some(file)),
2740-
};
2737+
self.tcx.short_ty_string(parent_trait_pred.skip_binder().self_ty());
27412738
let msg = format!(
27422739
"required for `{self_ty}` to implement `{}`",
27432740
parent_trait_pred.print_modifiers_and_trait_path()
@@ -2815,10 +2812,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
28152812
pluralize!(count)
28162813
));
28172814
let (self_ty, file) =
2818-
match self.tcx.short_ty_string(parent_trait_pred.skip_binder().self_ty()) {
2819-
Ok(self_ty) => (self_ty, None),
2820-
Err((self_ty, file)) => (self_ty, Some(file)),
2821-
};
2815+
self.tcx.short_ty_string(parent_trait_pred.skip_binder().self_ty());
28222816
err.note(&format!(
28232817
"required for `{self_ty}` to implement `{}`",
28242818
parent_trait_pred.print_modifiers_and_trait_path()

0 commit comments

Comments
 (0)