Skip to content

Pass constness with span into lower_poly_trait_ref #132227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -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(),
});
}
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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 => {}
},
}

Expand Down
8 changes: 4 additions & 4 deletions tests/ui/consts/const-block-const-bound.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/const-block-const-bound.rs:8:22
--> $DIR/const-block-const-bound.rs:8:15
|
LL | const fn f<T: ~const Destruct>(x: T) {}
| ^^^^^^^^
| ^^^^^^

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/const-block-const-bound.rs:8:22
--> $DIR/const-block-const-bound.rs:8:15
|
LL | const fn f<T: ~const Destruct>(x: T) {}
| ^^^^^^^^
| ^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

Expand Down
92 changes: 46 additions & 46 deletions tests/ui/consts/fn_trait_refs.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,168 +11,168 @@ LL | #![feature(const_cmp)]
| ^^^^^^^^^

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:13:15
--> $DIR/fn_trait_refs.rs:13:8
|
LL | T: ~const Fn<()> + ~const Destruct,
| ^^^^^^
| ^^^^^^

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:13:31
--> $DIR/fn_trait_refs.rs:13:24
|
LL | T: ~const Fn<()> + ~const Destruct,
| ^^^^^^^^
| ^^^^^^

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:13:15
--> $DIR/fn_trait_refs.rs:13:8
|
LL | T: ~const Fn<()> + ~const Destruct,
| ^^^^^^
| ^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:13:15
--> $DIR/fn_trait_refs.rs:13:8
|
LL | T: ~const Fn<()> + ~const Destruct,
| ^^^^^^
| ^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:13:31
--> $DIR/fn_trait_refs.rs:13:24
|
LL | T: ~const Fn<()> + ~const Destruct,
| ^^^^^^^^
| ^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:20:15
--> $DIR/fn_trait_refs.rs:20:8
|
LL | T: ~const FnMut<()> + ~const Destruct,
| ^^^^^^^^^
| ^^^^^^

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:20:34
--> $DIR/fn_trait_refs.rs:20:27
|
LL | T: ~const FnMut<()> + ~const Destruct,
| ^^^^^^^^
| ^^^^^^

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:20:15
--> $DIR/fn_trait_refs.rs:20:8
|
LL | T: ~const FnMut<()> + ~const Destruct,
| ^^^^^^^^^
| ^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:20:15
--> $DIR/fn_trait_refs.rs:20:8
|
LL | T: ~const FnMut<()> + ~const Destruct,
| ^^^^^^^^^
| ^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:20:34
--> $DIR/fn_trait_refs.rs:20:27
|
LL | T: ~const FnMut<()> + ~const Destruct,
| ^^^^^^^^
| ^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:27:15
--> $DIR/fn_trait_refs.rs:27:8
|
LL | T: ~const FnOnce<()>,
| ^^^^^^^^^^
| ^^^^^^

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:27:15
--> $DIR/fn_trait_refs.rs:27:8
|
LL | T: ~const FnOnce<()>,
| ^^^^^^^^^^
| ^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:27:15
--> $DIR/fn_trait_refs.rs:27:8
|
LL | T: ~const FnOnce<()>,
| ^^^^^^^^^^
| ^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:34:15
--> $DIR/fn_trait_refs.rs:34:8
|
LL | T: ~const Fn<()> + ~const Destruct,
| ^^^^^^
| ^^^^^^

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:34:31
--> $DIR/fn_trait_refs.rs:34:24
|
LL | T: ~const Fn<()> + ~const Destruct,
| ^^^^^^^^
| ^^^^^^

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:34:15
--> $DIR/fn_trait_refs.rs:34:8
|
LL | T: ~const Fn<()> + ~const Destruct,
| ^^^^^^
| ^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:34:15
--> $DIR/fn_trait_refs.rs:34:8
|
LL | T: ~const Fn<()> + ~const Destruct,
| ^^^^^^
| ^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:34:31
--> $DIR/fn_trait_refs.rs:34:24
|
LL | T: ~const Fn<()> + ~const Destruct,
| ^^^^^^^^
| ^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:48:15
--> $DIR/fn_trait_refs.rs:48:8
|
LL | T: ~const FnMut<()> + ~const Destruct,
| ^^^^^^^^^
| ^^^^^^

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:48:34
--> $DIR/fn_trait_refs.rs:48:27
|
LL | T: ~const FnMut<()> + ~const Destruct,
| ^^^^^^^^
| ^^^^^^

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:48:15
--> $DIR/fn_trait_refs.rs:48:8
|
LL | T: ~const FnMut<()> + ~const Destruct,
| ^^^^^^^^^
| ^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:48:15
--> $DIR/fn_trait_refs.rs:48:8
|
LL | T: ~const FnMut<()> + ~const Destruct,
| ^^^^^^^^^
| ^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/fn_trait_refs.rs:48:34
--> $DIR/fn_trait_refs.rs:48:27
|
LL | T: ~const FnMut<()> + ~const Destruct,
| ^^^^^^^^
| ^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

Expand Down
8 changes: 4 additions & 4 deletions tests/ui/consts/unstable-const-fn-in-libcore.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/unstable-const-fn-in-libcore.rs:19:39
--> $DIR/unstable-const-fn-in-libcore.rs:19:32
|
LL | const fn unwrap_or_else<F: ~const FnOnce() -> T>(self, f: F) -> T {
| ^^^^^^^^^^^^^
| ^^^^^^

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/unstable-const-fn-in-libcore.rs:19:39
--> $DIR/unstable-const-fn-in-libcore.rs:19:32
|
LL | const fn unwrap_or_else<F: ~const FnOnce() -> T>(self, f: F) -> T {
| ^^^^^^^^^^^^^
| ^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

Expand Down
16 changes: 8 additions & 8 deletions tests/ui/impl-trait/normalize-tait-in-const.stderr
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/normalize-tait-in-const.rs:26:42
--> $DIR/normalize-tait-in-const.rs:26:35
|
LL | const fn with_positive<F: for<'a> ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) {
| ^^^^^^^^^^^^^^^^^
| ^^^^^^

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/normalize-tait-in-const.rs:26:69
--> $DIR/normalize-tait-in-const.rs:26:62
|
LL | const fn with_positive<F: for<'a> ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) {
| ^^^^^^^^
| ^^^^^^

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/normalize-tait-in-const.rs:26:42
--> $DIR/normalize-tait-in-const.rs:26:35
|
LL | const fn with_positive<F: for<'a> ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) {
| ^^^^^^^^^^^^^^^^^
| ^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

error: `~const` can only be applied to `#[const_trait]` traits
--> $DIR/normalize-tait-in-const.rs:26:69
--> $DIR/normalize-tait-in-const.rs:26:62
|
LL | const fn with_positive<F: for<'a> ~const Fn(&'a Alias<'a>) + ~const Destruct>(fun: F) {
| ^^^^^^^^
| ^^^^^^
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`

Expand Down
Loading
Loading