Skip to content

Commit 4f3d06f

Browse files
Don't elaborate effects predicates into bounds list unless we're actually collecting implied bounds, not super bounds
1 parent a846d55 commit 4f3d06f

File tree

4 files changed

+9
-15
lines changed

4 files changed

+9
-15
lines changed

compiler/rustc_hir_analysis/src/bounds.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use rustc_middle::ty::{self, Ty, TyCtxt, Upcast};
99
use rustc_span::def_id::DefId;
1010
use rustc_span::Span;
1111

12+
use crate::hir_ty_lowering::OnlySelfBounds;
13+
1214
/// Collects together a list of type bounds. These lists of bounds occur in many places
1315
/// in Rust's syntax:
1416
///
@@ -50,6 +52,7 @@ impl<'tcx> Bounds<'tcx> {
5052
span: Span,
5153
polarity: ty::PredicatePolarity,
5254
constness: ty::BoundConstness,
55+
only_self_bounds: OnlySelfBounds,
5356
) {
5457
let clause = (
5558
bound_trait_ref
@@ -66,7 +69,10 @@ impl<'tcx> Bounds<'tcx> {
6669
self.clauses.push(clause);
6770
}
6871

69-
if !tcx.features().effects {
72+
// FIXME(effects): Lift this out of `push_trait_bound`, and move it somewhere else.
73+
// Perhaps moving this into `lower_poly_trait_ref`, just like we lower associated
74+
// type bounds.
75+
if !tcx.features().effects || only_self_bounds.0 {
7076
return;
7177
}
7278
// For `T: ~const Tr` or `T: const Tr`, we need to add an additional bound on the

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
719719
span,
720720
polarity,
721721
constness,
722+
only_self_bounds,
722723
);
723724

724725
let mut dup_constraints = FxIndexMap::default();

tests/ui/rfcs/rfc-2632-const-trait-impl/assoc-type.rs

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ impl const Foo for NonConstAdd {
3939
#[const_trait]
4040
trait Baz {
4141
type Qux: Add;
42-
//~^ ERROR the trait bound
4342
}
4443

4544
impl const Baz for NonConstAdd {

tests/ui/rfcs/rfc-2632-const-trait-impl/assoc-type.stderr

+1-13
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,5 @@ error: using `#![feature(effects)]` without enabling next trait solver globally
1212
= note: the next trait solver must be enabled globally for the effects feature to work correctly
1313
= help: use `-Znext-solver` to enable
1414

15-
error[E0277]: the trait bound `Add::{synthetic#0}: Compat` is not satisfied
16-
--> $DIR/assoc-type.rs:41:15
17-
|
18-
LL | type Qux: Add;
19-
| ^^^ the trait `Compat` is not implemented for `Add::{synthetic#0}`
20-
|
21-
help: consider further restricting the associated type
22-
|
23-
LL | trait Baz where Add::{synthetic#0}: Compat {
24-
| ++++++++++++++++++++++++++++++++
25-
26-
error: aborting due to 2 previous errors; 1 warning emitted
15+
error: aborting due to 1 previous error; 1 warning emitted
2716

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

0 commit comments

Comments
 (0)