Rollup merge of #112506 - compiler-errors:const-infer-ice, r=b-naber
Properly check associated consts for infer placeholders We only reported an error if it was in a "suggestable" position (according to `is_suggestable_infer_ty`) -- this isn't correct for infer tys that can show up in other places in the constant's type, like behind a dyn trait. fixes #112491
This commit is contained in:
commit
c1b4d075a2
12 changed files with 77 additions and 34 deletions
|
@ -666,17 +666,15 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
|
|||
tcx.ensure().fn_sig(def_id);
|
||||
}
|
||||
|
||||
hir::TraitItemKind::Const(.., Some(_)) => {
|
||||
hir::TraitItemKind::Const(ty, body_id) => {
|
||||
tcx.ensure().type_of(def_id);
|
||||
}
|
||||
|
||||
hir::TraitItemKind::Const(hir_ty, _) => {
|
||||
tcx.ensure().type_of(def_id);
|
||||
// Account for `const C: _;`.
|
||||
let mut visitor = HirPlaceholderCollector::default();
|
||||
visitor.visit_trait_item(trait_item);
|
||||
if !tcx.sess.diagnostic().has_stashed_diagnostic(hir_ty.span, StashKey::ItemNoType) {
|
||||
placeholder_type_error(tcx, None, visitor.0, false, None, "constant");
|
||||
if !tcx.sess.diagnostic().has_stashed_diagnostic(ty.span, StashKey::ItemNoType)
|
||||
&& !(is_suggestable_infer_ty(ty) && body_id.is_some())
|
||||
{
|
||||
// Account for `const C: _;`.
|
||||
let mut visitor = HirPlaceholderCollector::default();
|
||||
visitor.visit_trait_item(trait_item);
|
||||
placeholder_type_error(tcx, None, visitor.0, false, None, "associated constant");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -721,7 +719,14 @@ fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
|
|||
|
||||
placeholder_type_error(tcx, None, visitor.0, false, None, "associated type");
|
||||
}
|
||||
hir::ImplItemKind::Const(..) => {}
|
||||
hir::ImplItemKind::Const(ty, _) => {
|
||||
// Account for `const T: _ = ..;`
|
||||
if !is_suggestable_infer_ty(ty) {
|
||||
let mut visitor = HirPlaceholderCollector::default();
|
||||
visitor.visit_impl_item(impl_item);
|
||||
placeholder_type_error(tcx, None, visitor.0, false, None, "associated constant");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -341,7 +341,12 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
|
|||
.and_then(|body_id| {
|
||||
is_suggestable_infer_ty(ty).then(|| {
|
||||
infer_placeholder_type(
|
||||
tcx, def_id, body_id, ty.span, item.ident, "constant",
|
||||
tcx,
|
||||
def_id,
|
||||
body_id,
|
||||
ty.span,
|
||||
item.ident,
|
||||
"associated constant",
|
||||
)
|
||||
})
|
||||
})
|
||||
|
@ -359,7 +364,14 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
|
|||
}
|
||||
ImplItemKind::Const(ty, body_id) => {
|
||||
if is_suggestable_infer_ty(ty) {
|
||||
infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident, "constant")
|
||||
infer_placeholder_type(
|
||||
tcx,
|
||||
def_id,
|
||||
body_id,
|
||||
ty.span,
|
||||
item.ident,
|
||||
"associated constant",
|
||||
)
|
||||
} else {
|
||||
icx.to_ty(ty)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue