Don't elaborate effects predicates into bounds list unless we're actually collecting implied bounds, not super bounds

This commit is contained in:
Michael Goulet 2024-09-21 11:36:44 -04:00
parent a846d55d46
commit 4f3d06f5aa
4 changed files with 9 additions and 15 deletions

View File

@ -9,6 +9,8 @@ use rustc_middle::ty::{self, Ty, TyCtxt, Upcast};
use rustc_span::def_id::DefId; use rustc_span::def_id::DefId;
use rustc_span::Span; 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 /// Collects together a list of type bounds. These lists of bounds occur in many places
/// in Rust's syntax: /// in Rust's syntax:
/// ///
@ -50,6 +52,7 @@ impl<'tcx> Bounds<'tcx> {
span: Span, span: Span,
polarity: ty::PredicatePolarity, polarity: ty::PredicatePolarity,
constness: ty::BoundConstness, constness: ty::BoundConstness,
only_self_bounds: OnlySelfBounds,
) { ) {
let clause = ( let clause = (
bound_trait_ref bound_trait_ref
@ -66,7 +69,10 @@ impl<'tcx> Bounds<'tcx> {
self.clauses.push(clause); 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; return;
} }
// For `T: ~const Tr` or `T: const Tr`, we need to add an additional bound on the // For `T: ~const Tr` or `T: const Tr`, we need to add an additional bound on the

View File

@ -719,6 +719,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
span, span,
polarity, polarity,
constness, constness,
only_self_bounds,
); );
let mut dup_constraints = FxIndexMap::default(); let mut dup_constraints = FxIndexMap::default();

View File

@ -39,7 +39,6 @@ impl const Foo for NonConstAdd {
#[const_trait] #[const_trait]
trait Baz { trait Baz {
type Qux: Add; type Qux: Add;
//~^ ERROR the trait bound
} }
impl const Baz for NonConstAdd { impl const Baz for NonConstAdd {

View File

@ -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 = note: the next trait solver must be enabled globally for the effects feature to work correctly
= help: use `-Znext-solver` to enable = help: use `-Znext-solver` to enable
error[E0277]: the trait bound `Add::{synthetic#0}: Compat` is not satisfied error: aborting due to 1 previous error; 1 warning emitted
--> $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
For more information about this error, try `rustc --explain E0277`.