Skip to content

Commit

Permalink
Don't elaborate effects predicates into bounds list unless we're actu…
Browse files Browse the repository at this point in the history
…ally collecting implied bounds, not super bounds
  • Loading branch information
compiler-errors committed Sep 21, 2024
1 parent a846d55 commit 4f3d06f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 15 deletions.
8 changes: 7 additions & 1 deletion compiler/rustc_hir_analysis/src/bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use rustc_middle::ty::{self, Ty, TyCtxt, Upcast};
use rustc_span::def_id::DefId;
use rustc_span::Span;

use crate::hir_ty_lowering::OnlySelfBounds;

/// Collects together a list of type bounds. These lists of bounds occur in many places
/// in Rust's syntax:
///
Expand Down Expand Up @@ -50,6 +52,7 @@ impl<'tcx> Bounds<'tcx> {
span: Span,
polarity: ty::PredicatePolarity,
constness: ty::BoundConstness,
only_self_bounds: OnlySelfBounds,
) {
let clause = (
bound_trait_ref
Expand All @@ -66,7 +69,10 @@ impl<'tcx> Bounds<'tcx> {
self.clauses.push(clause);
}

if !tcx.features().effects {
// FIXME(effects): Lift this out of `push_trait_bound`, and move it somewhere else.
// Perhaps moving this into `lower_poly_trait_ref`, just like we lower associated
// type bounds.
if !tcx.features().effects || only_self_bounds.0 {
return;
}
// For `T: ~const Tr` or `T: const Tr`, we need to add an additional bound on the
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
span,
polarity,
constness,
only_self_bounds,
);

let mut dup_constraints = FxIndexMap::default();
Expand Down
1 change: 0 additions & 1 deletion tests/ui/rfcs/rfc-2632-const-trait-impl/assoc-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ impl const Foo for NonConstAdd {
#[const_trait]
trait Baz {
type Qux: Add;
//~^ ERROR the trait bound
}

impl const Baz for NonConstAdd {
Expand Down
14 changes: 1 addition & 13 deletions tests/ui/rfcs/rfc-2632-const-trait-impl/assoc-type.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,5 @@ error: using `#![feature(effects)]` without enabling next trait solver globally
= note: the next trait solver must be enabled globally for the effects feature to work correctly
= help: use `-Znext-solver` to enable

error[E0277]: the trait bound `Add::{synthetic#0}: Compat` is not satisfied
--> $DIR/assoc-type.rs:41:15
|
LL | type Qux: Add;
| ^^^ the trait `Compat` is not implemented for `Add::{synthetic#0}`
|
help: consider further restricting the associated type
|
LL | trait Baz where Add::{synthetic#0}: Compat {
| ++++++++++++++++++++++++++++++++

error: aborting due to 2 previous errors; 1 warning emitted
error: aborting due to 1 previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0277`.

0 comments on commit 4f3d06f

Please sign in to comment.