Skip to content

Commit 62baa67

Browse files
committed
Avoid silently writing to a file when the involved ty is long
1 parent a1dbb61 commit 62baa67

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -1054,6 +1054,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10541054
bound_list.into_iter().map(|(_, path)| path).collect::<Vec<_>>().join("\n");
10551055
let actual_prefix = rcvr_ty.prefix_string(self.tcx);
10561056
info!("unimplemented_traits.len() == {}", unimplemented_traits.len());
1057+
let mut long_ty_file = None;
10571058
let (primary_message, label) = if unimplemented_traits.len() == 1
10581059
&& unimplemented_traits_only
10591060
{
@@ -1066,8 +1067,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10661067
// Avoid crashing.
10671068
return (None, None);
10681069
}
1069-
let OnUnimplementedNote { message, label, .. } =
1070-
self.err_ctxt().on_unimplemented_note(trait_ref, &obligation);
1070+
let OnUnimplementedNote { message, label, .. } = self
1071+
.err_ctxt()
1072+
.on_unimplemented_note(trait_ref, &obligation, &mut long_ty_file);
10711073
(message, label)
10721074
})
10731075
.unwrap()
@@ -1081,6 +1083,15 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10811083
)
10821084
});
10831085
err.primary_message(primary_message);
1086+
if let Some(file) = long_ty_file {
1087+
err.note(format!(
1088+
"the full name for the type has been written to '{}'",
1089+
file.display(),
1090+
));
1091+
err.note(
1092+
"consider using `--verbose` to print the full type name to the console",
1093+
);
1094+
}
10841095
if let Some(label) = label {
10851096
custom_span_label = true;
10861097
err.span_label(span, label);

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
111111
&self,
112112
trait_ref: ty::PolyTraitRef<'tcx>,
113113
obligation: &PredicateObligation<'tcx>,
114+
long_ty_file: &mut Option<PathBuf>,
114115
) -> OnUnimplementedNote {
115-
let mut long_ty_file = None;
116-
117116
let (def_id, args) = self
118117
.impl_similar_to(trait_ref, obligation)
119118
.unwrap_or_else(|| (trait_ref.def_id(), trait_ref.skip_binder().args));
@@ -268,7 +267,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
268267
}));
269268

270269
if let Ok(Some(command)) = OnUnimplementedDirective::of_item(self.tcx, def_id) {
271-
command.evaluate(self.tcx, trait_ref, &flags, &mut long_ty_file)
270+
command.evaluate(self.tcx, trait_ref, &flags, long_ty_file)
272271
} else {
273272
OnUnimplementedNote::default()
274273
}

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

+13-1
Original file line numberDiff line numberDiff line change
@@ -445,13 +445,16 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
445445
file.display(),
446446
));
447447

448+
let mut long_ty_file = None;
449+
448450
let OnUnimplementedNote {
449451
message,
450452
label,
451453
notes,
452454
parent_label,
453455
append_const_msg,
454-
} = self.on_unimplemented_note(trait_ref, &obligation);
456+
} = self.on_unimplemented_note(trait_ref, &obligation, &mut long_ty_file);
457+
455458
let have_alt_message = message.is_some() || label.is_some();
456459
let is_try_conversion = self.is_try_conversion(span, trait_ref.def_id());
457460
let is_unsize =
@@ -506,6 +509,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
506509

507510
let mut err = struct_span_code_err!(self.dcx(), span, E0277, "{}", err_msg);
508511

512+
if let Some(long_ty_file) = long_ty_file {
513+
err.note(format!(
514+
"the full name for the type has been written to '{}'",
515+
long_ty_file.display(),
516+
));
517+
err.note("consider using `--verbose` to print the full type name to the console");
518+
}
509519
let mut suggested = false;
510520
if is_try_conversion {
511521
suggested = self.try_conversion_context(&obligation, trait_ref.skip_binder(), &mut err);
@@ -753,6 +763,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
753763
return err.emit();
754764
}
755765

766+
767+
756768
err
757769
}
758770

tests/ui/traits/on_unimplemented_long_types.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ LL | | ))))))))))),
1313
LL | | )))))))))))
1414
| |_______________- return type was inferred to be `Option<Option<Option<...>>>` here
1515
|
16+
= note: the full name for the type has been written to '$TEST_BUILD_DIR/traits/on_unimplemented_long_types/on_unimplemented_long_types.long-type-hash.txt'
17+
= note: consider using `--verbose` to print the full type name to the console
1618
= help: the trait `std::fmt::Display` is not implemented for `Option<Option<Option<...>>>`
1719
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead
1820
= note: the full name for the type has been written to '$TEST_BUILD_DIR/traits/on_unimplemented_long_types/on_unimplemented_long_types.long-type-hash.txt'

0 commit comments

Comments
 (0)