Skip to content

Commit 0ded305

Browse files
authored
Rollup merge of rust-lang#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.
2 parents cfe5389 + ad2a649 commit 0ded305

File tree

2 files changed

+16
-45
lines changed

2 files changed

+16
-45
lines changed

compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs

-1
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
516516
self_ty,
517517
trait_segment,
518518
false,
519-
ty::BoundConstness::NotConst,
520519
);
521520

522521
// SUBTLE: As noted at the end of `try_append_return_type_notation_params`

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+16-44
Original file line numberDiff line numberDiff line change
@@ -336,14 +336,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
336336
def_id: DefId,
337337
item_segment: &hir::PathSegment<'tcx>,
338338
) -> GenericArgsRef<'tcx> {
339-
let (args, _) = self.lower_generic_args_of_path(
340-
span,
341-
def_id,
342-
&[],
343-
item_segment,
344-
None,
345-
ty::BoundConstness::NotConst,
346-
);
339+
let (args, _) = self.lower_generic_args_of_path(span, def_id, &[], item_segment, None);
347340
if let Some(c) = item_segment.args().constraints.first() {
348341
prohibit_assoc_item_constraint(self, c, Some((def_id, item_segment, span)));
349342
}
@@ -392,7 +385,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
392385
parent_args: &[ty::GenericArg<'tcx>],
393386
segment: &hir::PathSegment<'tcx>,
394387
self_ty: Option<Ty<'tcx>>,
395-
constness: ty::BoundConstness,
396388
) -> (GenericArgsRef<'tcx>, GenericArgCountResult) {
397389
// If the type is parameterized by this region, then replace this
398390
// region with the current anon region binding (in other words,
@@ -415,7 +407,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
415407
assert!(self_ty.is_none());
416408
}
417409

418-
let mut arg_count = check_generic_arg_count(
410+
let arg_count = check_generic_arg_count(
419411
self,
420412
def_id,
421413
segment,
@@ -573,16 +565,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
573565
}
574566
}
575567
}
576-
if let ty::BoundConstness::Const | ty::BoundConstness::ConstIfConst = constness
577-
&& generics.has_self
578-
&& !tcx.is_const_trait(def_id)
579-
{
580-
let reported = self.dcx().emit_err(crate::errors::ConstBoundForNonConstTrait {
581-
span,
582-
modifier: constness.as_str(),
583-
});
584-
arg_count.correct = Err(GenericArgCountMismatch { reported, invalid_args: vec![] });
585-
}
586568

587569
let mut args_ctx = GenericArgsCtxt {
588570
lowerer: self,
@@ -614,14 +596,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
614596
parent_args: GenericArgsRef<'tcx>,
615597
) -> GenericArgsRef<'tcx> {
616598
debug!(?span, ?item_def_id, ?item_segment);
617-
let (args, _) = self.lower_generic_args_of_path(
618-
span,
619-
item_def_id,
620-
parent_args,
621-
item_segment,
622-
None,
623-
ty::BoundConstness::NotConst,
624-
);
599+
let (args, _) =
600+
self.lower_generic_args_of_path(span, item_def_id, parent_args, item_segment, None);
625601
if let Some(c) = item_segment.args().constraints.first() {
626602
prohibit_assoc_item_constraint(self, c, Some((item_def_id, item_segment, span)));
627603
}
@@ -647,7 +623,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
647623
self_ty,
648624
trait_ref.path.segments.last().unwrap(),
649625
true,
650-
ty::BoundConstness::NotConst,
651626
)
652627
}
653628

@@ -700,9 +675,17 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
700675
&[],
701676
trait_segment,
702677
Some(self_ty),
703-
constness,
704678
);
705679

680+
if let ty::BoundConstness::Const | ty::BoundConstness::ConstIfConst = constness
681+
&& !self.tcx().is_const_trait(trait_def_id)
682+
{
683+
self.dcx().emit_err(crate::errors::ConstBoundForNonConstTrait {
684+
span: trait_ref.path.span,
685+
modifier: constness.as_str(),
686+
});
687+
}
688+
706689
let tcx = self.tcx();
707690
let bound_vars = tcx.late_bound_vars(trait_ref.hir_ref_id);
708691
debug!(?bound_vars);
@@ -762,19 +745,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
762745
self_ty: Ty<'tcx>,
763746
trait_segment: &hir::PathSegment<'tcx>,
764747
is_impl: bool,
765-
// FIXME(effects): Move all host param things in HIR ty lowering to AST lowering.
766-
constness: ty::BoundConstness,
767748
) -> ty::TraitRef<'tcx> {
768749
self.complain_about_internal_fn_trait(span, trait_def_id, trait_segment, is_impl);
769750

770-
let (generic_args, _) = self.lower_generic_args_of_path(
771-
span,
772-
trait_def_id,
773-
&[],
774-
trait_segment,
775-
Some(self_ty),
776-
constness,
777-
);
751+
let (generic_args, _) =
752+
self.lower_generic_args_of_path(span, trait_def_id, &[], trait_segment, Some(self_ty));
778753
if let Some(c) = trait_segment.args().constraints.first() {
779754
prohibit_assoc_item_constraint(self, c, Some((trait_def_id, trait_segment, span)));
780755
}
@@ -1542,7 +1517,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
15421517
item_def_id: DefId,
15431518
trait_segment: &hir::PathSegment<'tcx>,
15441519
item_segment: &hir::PathSegment<'tcx>,
1545-
constness: ty::BoundConstness,
15461520
) -> Ty<'tcx> {
15471521
let tcx = self.tcx();
15481522

@@ -1555,7 +1529,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
15551529
debug!(?self_ty);
15561530

15571531
let trait_ref =
1558-
self.lower_mono_trait_ref(span, trait_def_id, self_ty, trait_segment, false, constness);
1532+
self.lower_mono_trait_ref(span, trait_def_id, self_ty, trait_segment, false);
15591533
debug!(?trait_ref);
15601534

15611535
let item_args =
@@ -1918,7 +1892,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
19181892
def_id,
19191893
&path.segments[path.segments.len() - 2],
19201894
path.segments.last().unwrap(),
1921-
ty::BoundConstness::NotConst,
19221895
)
19231896
}
19241897
Res::PrimTy(prim_ty) => {
@@ -2151,7 +2124,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
21512124
&[],
21522125
&hir::PathSegment::invalid(),
21532126
None,
2154-
ty::BoundConstness::NotConst,
21552127
);
21562128
tcx.at(span).type_of(def_id).instantiate(tcx, args)
21572129
}

0 commit comments

Comments
 (0)