Remove unnecessary constness

This commit is contained in:
Michael Goulet 2024-10-19 10:36:56 -04:00
parent b27f33a4d9
commit ad2a649aab
2 changed files with 16 additions and 45 deletions

View File

@ -516,7 +516,6 @@ pub fn lower_ty_maybe_return_type_notation(&self, hir_ty: &hir::Ty<'tcx>) -> Ty<
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 @@ pub fn lower_generic_args_of_path_segment(
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 @@ fn lower_generic_args_of_path(
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 @@ fn lower_generic_args_of_path(
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 @@ fn inferred_kind(
}
}
}
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 @@ pub fn lower_generic_args_of_assoc_item(
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 @@ pub fn lower_impl_trait_ref(
self_ty,
trait_ref.path.segments.last().unwrap(),
true,
ty::BoundConstness::NotConst,
)
}
@ -700,9 +675,17 @@ pub(crate) fn lower_poly_trait_ref(
&[],
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 @@ fn lower_mono_trait_ref(
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 @@ fn lower_qpath(
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 @@ fn lower_qpath(
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 @@ pub fn lower_path(
def_id,
&path.segments[path.segments.len() - 2],
path.segments.last().unwrap(),
ty::BoundConstness::NotConst,
)
}
Res::PrimTy(prim_ty) => {
@ -2151,7 +2124,6 @@ pub fn lower_ty(&self, hir_ty: &hir::Ty<'tcx>) -> Ty<'tcx> {
&[],
&hir::PathSegment::invalid(),
None,
ty::BoundConstness::NotConst,
);
tcx.at(span).type_of(def_id).instantiate(tcx, args)
}