Skip to content

Commit a9bdb2c

Browse files
committed
fix(hir_analysis/wfcheck): don't leak {type error}
Closes #118179
1 parent fb5d364 commit a9bdb2c

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -961,13 +961,22 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(),
961961
hir_ty.span,
962962
"using raw pointers as const generic parameters is forbidden",
963963
),
964-
_ => tcx.dcx().struct_span_err(
965-
hir_ty.span,
966-
format!("`{}` is forbidden as the type of a const generic parameter", ty),
967-
),
964+
_ => {
965+
// Avoid showing a weird error message to the user. See #118179.
966+
if ty.contains_error() {
967+
return Ok(());
968+
}
969+
970+
tcx.dcx().struct_span_err(
971+
hir_ty.span,
972+
format!(
973+
"`{ty}` is forbidden as the type of a const generic parameter",
974+
),
975+
)
976+
}
968977
};
969978

970-
diag.note("the only supported types are integers, `bool` and `char`");
979+
diag.note("the only supported types are integers, `bool`, and `char`");
971980

972981
let cause = ObligationCause::misc(hir_ty.span, param.def_id);
973982
let adt_const_params_feature_string =

0 commit comments

Comments
 (0)