Rollup merge of #131931 - compiler-errors:constness-valid, r=fmease

Remove unnecessary constness from `lower_generic_args_of_path`

We pass `NotConst` to all callsites of `lower_generic_args_of_path` except for `lower_poly_trait_ref`, so let's not do that.
This commit is contained in:
Matthias Krüger 2024-10-19 22:00:59 +02:00 committed by GitHub
commit 426e90682e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 45 deletions

View File

@ -516,7 +516,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
self_ty,
trait_segment,
false,
ty::BoundConstness::NotConst,
);
// SUBTLE: As noted at the end of `try_append_return_type_notation_params`

View File

@ -336,14 +336,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
def_id: DefId,
item_segment: &hir::PathSegment<'tcx>,
) -> GenericArgsRef<'tcx> {
let (args, _) = self.lower_generic_args_of_path(
span,
def_id,
&[],
item_segment,
None,
ty::BoundConstness::NotConst,
);
let (args, _) = self.lower_generic_args_of_path(span, def_id, &[], item_segment, None);
if let Some(c) = item_segment.args().constraints.first() {
prohibit_assoc_item_constraint(self, c, Some((def_id, item_segment, span)));
}
@ -392,7 +385,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
parent_args: &[ty::GenericArg<'tcx>],
segment: &hir::PathSegment<'tcx>,
self_ty: Option<Ty<'tcx>>,
constness: ty::BoundConstness,
) -> (GenericArgsRef<'tcx>, GenericArgCountResult) {
// If the type is parameterized by this region, then replace this
// region with the current anon region binding (in other words,
@ -415,7 +407,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
assert!(self_ty.is_none());
}
let mut arg_count = check_generic_arg_count(
let arg_count = check_generic_arg_count(
self,
def_id,
segment,
@ -573,16 +565,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
}
}
}
if let ty::BoundConstness::Const | ty::BoundConstness::ConstIfConst = constness
&& generics.has_self
&& !tcx.is_const_trait(def_id)
{
let reported = self.dcx().emit_err(crate::errors::ConstBoundForNonConstTrait {
span,
modifier: constness.as_str(),
});
arg_count.correct = Err(GenericArgCountMismatch { reported, invalid_args: vec![] });
}
let mut args_ctx = GenericArgsCtxt {
lowerer: self,
@ -614,14 +596,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
parent_args: GenericArgsRef<'tcx>,
) -> GenericArgsRef<'tcx> {
debug!(?span, ?item_def_id, ?item_segment);
let (args, _) = self.lower_generic_args_of_path(
span,
item_def_id,
parent_args,
item_segment,
None,
ty::BoundConstness::NotConst,
);
let (args, _) =
self.lower_generic_args_of_path(span, item_def_id, parent_args, item_segment, None);
if let Some(c) = item_segment.args().constraints.first() {
prohibit_assoc_item_constraint(self, c, Some((item_def_id, item_segment, span)));
}
@ -647,7 +623,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
self_ty,
trait_ref.path.segments.last().unwrap(),
true,
ty::BoundConstness::NotConst,
)
}
@ -700,9 +675,17 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
&[],
trait_segment,
Some(self_ty),
constness,
);
if let ty::BoundConstness::Const | ty::BoundConstness::ConstIfConst = constness
&& !self.tcx().is_const_trait(trait_def_id)
{
self.dcx().emit_err(crate::errors::ConstBoundForNonConstTrait {
span: trait_ref.path.span,
modifier: constness.as_str(),
});
}
let tcx = self.tcx();
let bound_vars = tcx.late_bound_vars(trait_ref.hir_ref_id);
debug!(?bound_vars);
@ -762,19 +745,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
self_ty: Ty<'tcx>,
trait_segment: &hir::PathSegment<'tcx>,
is_impl: bool,
// FIXME(effects): Move all host param things in HIR ty lowering to AST lowering.
constness: ty::BoundConstness,
) -> ty::TraitRef<'tcx> {
self.complain_about_internal_fn_trait(span, trait_def_id, trait_segment, is_impl);
let (generic_args, _) = self.lower_generic_args_of_path(
span,
trait_def_id,
&[],
trait_segment,
Some(self_ty),
constness,
);
let (generic_args, _) =
self.lower_generic_args_of_path(span, trait_def_id, &[], trait_segment, Some(self_ty));
if let Some(c) = trait_segment.args().constraints.first() {
prohibit_assoc_item_constraint(self, c, Some((trait_def_id, trait_segment, span)));
}
@ -1542,7 +1517,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
item_def_id: DefId,
trait_segment: &hir::PathSegment<'tcx>,
item_segment: &hir::PathSegment<'tcx>,
constness: ty::BoundConstness,
) -> Ty<'tcx> {
let tcx = self.tcx();
@ -1555,7 +1529,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
debug!(?self_ty);
let trait_ref =
self.lower_mono_trait_ref(span, trait_def_id, self_ty, trait_segment, false, constness);
self.lower_mono_trait_ref(span, trait_def_id, self_ty, trait_segment, false);
debug!(?trait_ref);
let item_args =
@ -1918,7 +1892,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
def_id,
&path.segments[path.segments.len() - 2],
path.segments.last().unwrap(),
ty::BoundConstness::NotConst,
)
}
Res::PrimTy(prim_ty) => {
@ -2151,7 +2124,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
&[],
&hir::PathSegment::invalid(),
None,
ty::BoundConstness::NotConst,
);
tcx.at(span).type_of(def_id).instantiate(tcx, args)
}