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
This commit is contained in:
commit
a9ee1d025b
38 changed files with 241 additions and 254 deletions
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 => {}
|
||||
},
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue