about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2022-04-02 15:27:14 -0700
committerMichael Goulet <michael@errs.io>2022-04-04 19:37:14 -0700
commita8877cf73823351cee2a871bd5387628054fabea (patch)
tree83f87c01226c4040870994f603a8db0a802bd8eb /compiler
parent60e50fc1cfe0bb693a5f4f93eb83ef70854531e3 (diff)
downloadrust-a8877cf73823351cee2a871bd5387628054fabea.tar.gz
rust-a8877cf73823351cee2a871bd5387628054fabea.zip
Handle reporting invariance of fn pointer
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_borrowck/src/diagnostics/region_errors.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs
index e63450a1f58..3e7999b43ab 100644
--- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs
+++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs
@@ -358,6 +358,17 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
                         );
                         (desc, note)
                     }
+                    ty::FnDef(def_id, _) => {
+                        let name = self.infcx.tcx.item_name(*def_id);
+                        let identity_substs =
+                            InternalSubsts::identity_for_item(self.infcx.tcx, *def_id);
+                        let desc = format!("a function pointer to `{name}`");
+                        let note = format!(
+                            "the function `{name}` is invariant over the parameter `{}`",
+                            identity_substs[param_index as usize]
+                        );
+                        (desc, note)
+                    }
                     _ => panic!("Unexpected type {:?}", ty),
                 };
                 diag.note(&format!("requirement occurs because of {desc}",));