about summary refs log tree commit diff
path: root/compiler/rustc_hir_analysis
diff options
context:
space:
mode:
author许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com>2024-10-28 13:36:20 +0800
committerGitHub <noreply@github.com>2024-10-28 13:36:20 +0800
commita9ee1d025b93559bb0bf26a8bfbec84c290b8069 (patch)
treef63c1c941f98d99b947fd61d5ec88f7ab7a1352b /compiler/rustc_hir_analysis
parentafc93a912859cc33437d6cab8d48e32e3863d2d0 (diff)
parentbd95695b947291b2aac349a6f4587a6cee213e25 (diff)
downloadrust-a9ee1d025b93559bb0bf26a8bfbec84c290b8069.tar.gz
rust-a9ee1d025b93559bb0bf26a8bfbec84c290b8069.zip
Rollup merge of #132227 - compiler-errors:better-const-span, r=Nadrieril
Pass constness with span into lower_poly_trait_ref

Gives us a span to point at for ~const/const on non-const traits.

Split from #132209. r? Nadrieril
Diffstat (limited to 'compiler/rustc_hir_analysis')
-rw-r--r--compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs7
-rw-r--r--compiler/rustc_hir_analysis/src/hir_ty_lowering/dyn_compatibility.rs2
-rw-r--r--compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs16
3 files changed, 9 insertions, 16 deletions
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 cfd1241ad69..0891642f2c8 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<ty::BoundConstness>,
+        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 => {}
             },
         }