Skip to content

Commit d945496

Browse files
yeet
1 parent 0995f8a commit d945496

File tree

4 files changed

+33
-32
lines changed

4 files changed

+33
-32
lines changed

compiler/rustc_hir_analysis/src/bounds.rs

+17-22
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//! `ty` form from the HIR.
33
44
use rustc_hir::LangItem;
5-
use rustc_middle::ty::Binder;
65
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt};
76
use rustc_span::Span;
87

@@ -24,62 +23,58 @@ use rustc_span::Span;
2423
/// include the self type (e.g., `trait_bounds`) but in others we do not
2524
#[derive(Default, PartialEq, Eq, Clone, Debug)]
2625
pub struct Bounds<'tcx> {
27-
pub predicates: Vec<(Binder<'tcx, ty::Clause<'tcx>>, Span)>,
26+
pub predicates: Vec<(ty::Clause<'tcx>, Span)>,
2827
}
2928

3029
impl<'tcx> Bounds<'tcx> {
3130
pub fn push_region_bound(
3231
&mut self,
33-
_tcx: TyCtxt<'tcx>,
32+
tcx: TyCtxt<'tcx>,
3433
region: ty::PolyTypeOutlivesPredicate<'tcx>,
3534
span: Span,
3635
) {
37-
self.predicates.push((region.map_bound(|p| ty::Clause::TypeOutlives(p)), span));
36+
self.predicates
37+
.push((region.map_bound(|p| ty::ClauseKind::TypeOutlives(p)).to_predicate(tcx), span));
3838
}
3939

4040
pub fn push_trait_bound(
4141
&mut self,
42-
_tcx: TyCtxt<'tcx>,
42+
tcx: TyCtxt<'tcx>,
4343
trait_ref: ty::PolyTraitRef<'tcx>,
4444
span: Span,
4545
constness: ty::BoundConstness,
4646
polarity: ty::ImplPolarity,
4747
) {
4848
self.predicates.push((
49-
trait_ref.map_bound(|trait_ref| {
50-
ty::Clause::Trait(ty::TraitPredicate { trait_ref, constness, polarity })
51-
}),
49+
trait_ref
50+
.map_bound(|trait_ref| {
51+
ty::ClauseKind::Trait(ty::TraitPredicate { trait_ref, constness, polarity })
52+
})
53+
.to_predicate(tcx),
5254
span,
5355
));
5456
}
5557

5658
pub fn push_projection_bound(
5759
&mut self,
58-
_tcx: TyCtxt<'tcx>,
60+
tcx: TyCtxt<'tcx>,
5961
projection: ty::PolyProjectionPredicate<'tcx>,
6062
span: Span,
6163
) {
62-
self.predicates.push((projection.map_bound(|proj| ty::Clause::Projection(proj)), span));
64+
self.predicates.push((
65+
projection.map_bound(|proj| ty::ClauseKind::Projection(proj)).to_predicate(tcx),
66+
span,
67+
));
6368
}
6469

6570
pub fn push_sized(&mut self, tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, span: Span) {
6671
let sized_def_id = tcx.require_lang_item(LangItem::Sized, Some(span));
6772
let trait_ref = ty::TraitRef::new(tcx, sized_def_id, [ty]);
6873
// Preferable to put this obligation first, since we report better errors for sized ambiguity.
69-
self.predicates.insert(
70-
0,
71-
(
72-
ty::Binder::dummy(ty::Clause::Trait(trait_ref.without_const().to_predicate(tcx))),
73-
span,
74-
),
75-
);
76-
}
77-
78-
pub fn predicates(&self) -> impl Iterator<Item = (Binder<'tcx, ty::Clause<'tcx>>, Span)> + '_ {
79-
self.predicates.iter().cloned()
74+
self.predicates.insert(0, (trait_ref.to_predicate(tcx), span));
8075
}
8176

8277
pub fn clauses(&self) -> impl Iterator<Item = (ty::Clause<'tcx>, Span)> + '_ {
83-
self.predicates.iter().cloned().map(|(pred, span)| (pred.as_clause().unwrap(), span))
78+
self.predicates.iter().cloned()
8479
}
8580
}

compiler/rustc_hir_analysis/src/collect/item_bounds.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::astconv::{AstConv, OnlySelfBounds};
33
use rustc_hir as hir;
44
use rustc_infer::traits::util;
55
use rustc_middle::ty::subst::InternalSubsts;
6-
use rustc_middle::ty::ToPredicate;
76
use rustc_middle::ty::{self, Ty, TyCtxt};
87
use rustc_span::def_id::{DefId, LocalDefId};
98
use rustc_span::Span;

compiler/rustc_privacy/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1259,8 +1259,8 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
12591259
self.tcx.types.never,
12601260
);
12611261

1262-
for (pred, _) in bounds.predicates() {
1263-
match pred.skip_binder() {
1262+
for (pred, _) in bounds.clauses() {
1263+
match pred.kind().skip_binder() {
12641264
ty::ClauseKind::Trait(trait_predicate) => {
12651265
if self.visit_trait(trait_predicate.trait_ref).is_break() {
12661266
return;
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
1-
error: the type `S` is not well-formed
2-
--> $DIR/recursive_where_clause_on_type.rs:28:11
1+
error[E0277]: the trait bound `S: Bar` is not satisfied
2+
--> $DIR/recursive_where_clause_on_type.rs:14:14
3+
|
4+
LL | impl Foo for S {
5+
| ^ the trait `Bar` is not implemented for `S`
6+
|
7+
note: required by a bound in `Foo`
8+
--> $DIR/recursive_where_clause_on_type.rs:10:12
39
|
4-
LL | foo::<S>()
5-
| ^
10+
LL | trait Foo: Bar { }
11+
| ^^^ required by this bound in `Foo`
612

713
error: the type `S` is not well-formed
8-
--> $DIR/recursive_where_clause_on_type.rs:28:5
14+
--> $DIR/recursive_where_clause_on_type.rs:14:14
915
|
10-
LL | foo::<S>()
11-
| ^^^^^^^^
16+
LL | impl Foo for S {
17+
| ^
1218

1319
error: aborting due to 2 previous errors
1420

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

0 commit comments

Comments
 (0)