1
Fork 0

diagnostics: give a special note for unsafe fn / Fn/FnOnce/FnMut

Fixes #90073
This commit is contained in:
Michael Howell 2022-04-04 17:37:59 -07:00
parent 60e50fc1cf
commit bec8dbdb60
5 changed files with 28 additions and 0 deletions

View file

@ -208,6 +208,15 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
flags.push((sym::_Self, Some("&[]".to_owned())));
}
if self_ty.is_fn() {
let fn_sig = self_ty.fn_sig(self.tcx);
let shortname = match fn_sig.unsafety() {
hir::Unsafety::Normal => "fn",
hir::Unsafety::Unsafe => "unsafe fn",
};
flags.push((sym::_Self, Some(shortname.to_owned())));
}
if let ty::Array(aty, len) = self_ty.kind() {
flags.push((sym::_Self, Some("[]".to_owned())));
flags.push((sym::_Self, Some(format!("[{}]", aty))));