-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add more detail to type inference error #61361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8bb094d
65c2a7b
74fb3bb
ebbe725
9616b33
e420f44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -483,7 +483,17 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>: | |
ty::FnPtr(ref bare_fn) => { | ||
p!(print(bare_fn)) | ||
} | ||
ty::Infer(infer_ty) => p!(write("{}", infer_ty)), | ||
ty::Infer(infer_ty) => { | ||
if let ty::TyVar(ty_vid) = infer_ty { | ||
if let Some(name) = self.infer_ty_name(ty_vid) { | ||
p!(write("{}", name)) | ||
} else { | ||
p!(write("{}", infer_ty)) | ||
} | ||
} else { | ||
estebank marked this conversation as resolved.
Show resolved
Hide resolved
|
||
p!(write("{}", infer_ty)) | ||
} | ||
}, | ||
ty::Error => p!(write("[type error]")), | ||
ty::Param(ref param_ty) => p!(write("{}", param_ty)), | ||
ty::Bound(debruijn, bound_ty) => { | ||
|
@@ -681,6 +691,10 @@ pub trait PrettyPrinter<'gcx: 'tcx, 'tcx>: | |
Ok(self) | ||
} | ||
|
||
fn infer_ty_name(&self, _: ty::TyVid) -> Option<String> { | ||
None | ||
} | ||
|
||
fn pretty_print_dyn_existential( | ||
mut self, | ||
predicates: &'tcx ty::List<ty::ExistentialPredicate<'tcx>>, | ||
|
@@ -931,6 +945,8 @@ pub struct FmtPrinterData<'a, 'gcx, 'tcx, F> { | |
binder_depth: usize, | ||
|
||
pub region_highlight_mode: RegionHighlightMode, | ||
|
||
pub name_resolver: Option<Box<&'a dyn Fn(ty::sty::TyVid) -> Option<String>>>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please cc me on |
||
} | ||
|
||
impl<F> Deref for FmtPrinter<'a, 'gcx, 'tcx, F> { | ||
|
@@ -957,6 +973,7 @@ impl<F> FmtPrinter<'a, 'gcx, 'tcx, F> { | |
region_index: 0, | ||
binder_depth: 0, | ||
region_highlight_mode: RegionHighlightMode::default(), | ||
name_resolver: None, | ||
})) | ||
} | ||
} | ||
|
@@ -1206,6 +1223,10 @@ impl<F: fmt::Write> Printer<'gcx, 'tcx> for FmtPrinter<'_, 'gcx, 'tcx, F> { | |
} | ||
|
||
impl<F: fmt::Write> PrettyPrinter<'gcx, 'tcx> for FmtPrinter<'_, 'gcx, 'tcx, F> { | ||
fn infer_ty_name(&self, id: ty::TyVid) -> Option<String> { | ||
self.0.name_resolver.as_ref().and_then(|func| func(id)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a |
||
} | ||
|
||
fn print_value_path( | ||
mut self, | ||
def_id: DefId, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd probably override this in
FmtPrinter
'sprint_ty
tbh, instead of addinginfer_ty_name
.