From bd95695b947291b2aac349a6f4587a6cee213e25 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 26 Oct 2024 20:54:38 +0000 Subject: Pass constness with span into lower_poly_trait_ref --- .../rustc_hir_analysis/src/hir_ty_lowering/bounds.rs | 7 ------- .../src/hir_ty_lowering/dyn_compatibility.rs | 2 +- compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs | 16 ++++++++-------- 3 files changed, 9 insertions(+), 16 deletions(-) (limited to 'compiler/rustc_hir_analysis') diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs index c902e85c267..a5709089db6 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs @@ -168,13 +168,6 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { match hir_bound { hir::GenericBound::Trait(poly_trait_ref) => { let hir::TraitBoundModifiers { constness, polarity } = poly_trait_ref.modifiers; - // FIXME: We could pass these directly into `lower_poly_trait_ref` - // so that we could use these spans in diagnostics within that function... - let constness = match constness { - hir::BoundConstness::Never => None, - hir::BoundConstness::Always(_) => Some(ty::BoundConstness::Const), - hir::BoundConstness::Maybe(_) => Some(ty::BoundConstness::ConstIfConst), - }; let polarity = match polarity { rustc_ast::BoundPolarity::Positive => ty::PredicatePolarity::Positive, rustc_ast::BoundPolarity::Negative(_) => ty::PredicatePolarity::Negative, diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs index 890e8fa99e6..f2ee4b0ccd4 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs @@ -50,7 +50,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { } = self.lower_poly_trait_ref( &trait_bound.trait_ref, trait_bound.span, - None, + hir::BoundConstness::Never, ty::PredicatePolarity::Positive, dummy_self, &mut bounds, diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index 863c077a9e0..4b7eb0b00bb 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -658,7 +658,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { &self, trait_ref: &hir::TraitRef<'tcx>, span: Span, - constness: Option, + constness: hir::BoundConstness, polarity: ty::PredicatePolarity, self_ty: Ty<'tcx>, bounds: &mut Bounds<'tcx>, @@ -681,11 +681,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { Some(self_ty), ); - if let Some(constness) = constness + if let hir::BoundConstness::Always(span) | hir::BoundConstness::Maybe(span) = constness && !self.tcx().is_const_trait(trait_def_id) { self.dcx().emit_err(crate::errors::ConstBoundForNonConstTrait { - span: trait_ref.path.span, + span, modifier: constness.as_str(), }); } @@ -708,7 +708,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { bounds.push_trait_bound(tcx, poly_trait_ref, span, polarity); match constness { - Some(ty::BoundConstness::Const) => { + hir::BoundConstness::Always(span) => { if polarity == ty::PredicatePolarity::Positive { bounds.push_const_bound( tcx, @@ -718,13 +718,13 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { ); } } - Some(ty::BoundConstness::ConstIfConst) => { + hir::BoundConstness::Maybe(_) => { // We don't emit a const bound here, since that would mean that we // unconditionally need to prove a `HostEffect` predicate, even when // the predicates are being instantiated in a non-const context. This // is instead handled in the `const_conditions` query. } - None => {} + hir::BoundConstness::Never => {} } } // On the flip side, when filtering `ConstIfConst` bounds, we only need to convert @@ -734,12 +734,12 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { // here because we only call this on self bounds, and deal with the recursive case // in `lower_assoc_item_constraint`. PredicateFilter::ConstIfConst | PredicateFilter::SelfConstIfConst => match constness { - Some(ty::BoundConstness::ConstIfConst) => { + hir::BoundConstness::Maybe(span) => { if polarity == ty::PredicatePolarity::Positive { bounds.push_const_bound(tcx, poly_trait_ref, ty::HostPolarity::Maybe, span); } } - None | Some(ty::BoundConstness::Const) => {} + hir::BoundConstness::Always(_) | hir::BoundConstness::Never => {} }, } -- cgit 1.4.1-3-g733a5