Rollup merge of #95607 - compiler-errors:issue-95272, r=Aaron1011
Note invariance reason for FnDef types Fixes #95272. Is it worthwhile even printing a variance explanation here? Or should I try to track down which function parameter is responsible for the invariance? r? ``@Aaron1011`` since you wrote #89336
This commit is contained in:
commit
2a7e7bd0e0
31 changed files with 158 additions and 113 deletions
|
@ -330,14 +330,14 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||
ty::RawPtr(ty_mut) => {
|
||||
assert_eq!(ty_mut.mutbl, rustc_hir::Mutability::Mut);
|
||||
(
|
||||
format!("a mutable pointer to {}", ty_mut.ty),
|
||||
format!("a mutable pointer to `{}`", ty_mut.ty),
|
||||
"mutable pointers are invariant over their type parameter".to_string(),
|
||||
)
|
||||
}
|
||||
ty::Ref(_, inner_ty, mutbl) => {
|
||||
assert_eq!(*mutbl, rustc_hir::Mutability::Mut);
|
||||
(
|
||||
format!("a mutable reference to {}", inner_ty),
|
||||
format!("a mutable reference to `{}`", inner_ty),
|
||||
"mutable references are invariant over their type parameter"
|
||||
.to_string(),
|
||||
)
|
||||
|
@ -351,10 +351,21 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
|
|||
let adt_desc = adt.descr();
|
||||
|
||||
let desc = format!(
|
||||
"the type {ty}, which makes the generic argument {generic_arg} invariant"
|
||||
"the type `{ty}`, which makes the generic argument `{generic_arg}` invariant"
|
||||
);
|
||||
let note = format!(
|
||||
"the {adt_desc} {base_ty} is invariant over the parameter {base_generic_arg}"
|
||||
"the {adt_desc} `{base_ty}` is invariant over the parameter `{base_generic_arg}`"
|
||||
);
|
||||
(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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue