Rollup merge of #91847 - BoxyUwU:generic_arg_infer_fixme, r=lcnr
Fix FIXME for `generic_arg_infer` in `create_substs_for_ast_path` Fixes a FIXME, does some general refactoring of this fn, and also fixes a bug where we would use a const params defaults instead of an inference var ([playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=19456f65ea5dc3fcaa9b696f842ab380)) (lot of stuff in one PR but it was all so close together...) r? `@lcnr` Fixes #91614
This commit is contained in:
commit
f8de2f56e8
4 changed files with 74 additions and 55 deletions
|
@ -414,34 +414,40 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
arg: &GenericArg<'_>,
|
||||
) -> subst::GenericArg<'tcx> {
|
||||
let tcx = self.astconv.tcx();
|
||||
|
||||
let mut handle_ty_args = |has_default, ty: &hir::Ty<'_>| {
|
||||
if has_default {
|
||||
tcx.check_optional_stability(
|
||||
param.def_id,
|
||||
Some(arg.id()),
|
||||
arg.span(),
|
||||
None,
|
||||
|_, _| {
|
||||
// Default generic parameters may not be marked
|
||||
// with stability attributes, i.e. when the
|
||||
// default parameter was defined at the same time
|
||||
// as the rest of the type. As such, we ignore missing
|
||||
// stability attributes.
|
||||
},
|
||||
)
|
||||
}
|
||||
if let (hir::TyKind::Infer, false) = (&ty.kind, self.astconv.allow_ty_infer()) {
|
||||
self.inferred_params.push(ty.span);
|
||||
tcx.ty_error().into()
|
||||
} else {
|
||||
self.astconv.ast_ty_to_ty(ty).into()
|
||||
}
|
||||
};
|
||||
|
||||
match (¶m.kind, arg) {
|
||||
(GenericParamDefKind::Lifetime, GenericArg::Lifetime(lt)) => {
|
||||
self.astconv.ast_region_to_region(lt, Some(param)).into()
|
||||
}
|
||||
(&GenericParamDefKind::Type { has_default, .. }, GenericArg::Type(ty)) => {
|
||||
if has_default {
|
||||
tcx.check_optional_stability(
|
||||
param.def_id,
|
||||
Some(arg.id()),
|
||||
arg.span(),
|
||||
None,
|
||||
|_, _| {
|
||||
// Default generic parameters may not be marked
|
||||
// with stability attributes, i.e. when the
|
||||
// default parameter was defined at the same time
|
||||
// as the rest of the type. As such, we ignore missing
|
||||
// stability attributes.
|
||||
},
|
||||
)
|
||||
}
|
||||
if let (hir::TyKind::Infer, false) =
|
||||
(&ty.kind, self.astconv.allow_ty_infer())
|
||||
{
|
||||
self.inferred_params.push(ty.span);
|
||||
tcx.ty_error().into()
|
||||
} else {
|
||||
self.astconv.ast_ty_to_ty(ty).into()
|
||||
}
|
||||
handle_ty_args(has_default, ty)
|
||||
}
|
||||
(&GenericParamDefKind::Type { has_default, .. }, GenericArg::Infer(inf)) => {
|
||||
handle_ty_args(has_default, &inf.to_ty())
|
||||
}
|
||||
(GenericParamDefKind::Const { .. }, GenericArg::Const(ct)) => {
|
||||
ty::Const::from_opt_const_arg_anon_const(
|
||||
|
@ -453,41 +459,13 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||
)
|
||||
.into()
|
||||
}
|
||||
(&GenericParamDefKind::Const { has_default }, hir::GenericArg::Infer(inf)) => {
|
||||
if has_default {
|
||||
tcx.const_param_default(param.def_id).into()
|
||||
} else if self.astconv.allow_ty_infer() {
|
||||
// FIXME(const_generics): Actually infer parameter here?
|
||||
todo!()
|
||||
} else {
|
||||
self.inferred_params.push(inf.span);
|
||||
tcx.ty_error().into()
|
||||
}
|
||||
}
|
||||
(
|
||||
&GenericParamDefKind::Type { has_default, .. },
|
||||
hir::GenericArg::Infer(inf),
|
||||
) => {
|
||||
if has_default {
|
||||
tcx.check_optional_stability(
|
||||
param.def_id,
|
||||
Some(arg.id()),
|
||||
arg.span(),
|
||||
None,
|
||||
|_, _| {
|
||||
// Default generic parameters may not be marked
|
||||
// with stability attributes, i.e. when the
|
||||
// default parameter was defined at the same time
|
||||
// as the rest of the type. As such, we ignore missing
|
||||
// stability attributes.
|
||||
},
|
||||
);
|
||||
}
|
||||
(&GenericParamDefKind::Const { .. }, hir::GenericArg::Infer(inf)) => {
|
||||
let ty = tcx.at(self.span).type_of(param.def_id);
|
||||
if self.astconv.allow_ty_infer() {
|
||||
self.astconv.ast_ty_to_ty(&inf.to_ty()).into()
|
||||
self.astconv.ct_infer(ty, Some(param), inf.span).into()
|
||||
} else {
|
||||
self.inferred_params.push(inf.span);
|
||||
tcx.ty_error().into()
|
||||
tcx.const_error(ty).into()
|
||||
}
|
||||
}
|
||||
_ => unreachable!(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue