Skip to content

Commit 42f4643

Browse files
authored
Rollup merge of rust-lang#135902 - compiler-errors:item-non-self-bound-in-new-solver, r=lcnr
Do not consider child bound assumptions for rigid alias r? lcnr See first commit for the important details. For second commit, I also stacked a somewhat opinionated name change, though I can separate that if needed. Fixes rust-lang/trait-system-refactor-initiative#149
2 parents 53f343f + 009d687 commit 42f4643

File tree

25 files changed

+195
-117
lines changed

25 files changed

+195
-117
lines changed

Diff for: compiler/rustc_hir_analysis/src/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ fn fn_sig_suggestion<'tcx>(
457457

458458
let asyncness = if tcx.asyncness(assoc.def_id).is_async() {
459459
output = if let ty::Alias(_, alias_ty) = *output.kind() {
460-
tcx.explicit_item_super_predicates(alias_ty.def_id)
460+
tcx.explicit_item_self_bounds(alias_ty.def_id)
461461
.iter_instantiated_copied(tcx, alias_ty.args)
462462
.find_map(|(bound, _)| {
463463
bound.as_projection_clause()?.no_bound_vars()?.term.as_type()

Diff for: compiler/rustc_hir_analysis/src/collect.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ pub fn provide(providers: &mut Providers) {
6565
type_alias_is_lazy: type_of::type_alias_is_lazy,
6666
item_bounds: item_bounds::item_bounds,
6767
explicit_item_bounds: item_bounds::explicit_item_bounds,
68-
item_super_predicates: item_bounds::item_super_predicates,
69-
explicit_item_super_predicates: item_bounds::explicit_item_super_predicates,
70-
item_non_self_assumptions: item_bounds::item_non_self_assumptions,
68+
item_self_bounds: item_bounds::item_self_bounds,
69+
explicit_item_self_bounds: item_bounds::explicit_item_self_bounds,
70+
item_non_self_bounds: item_bounds::item_non_self_bounds,
7171
impl_super_outlives: item_bounds::impl_super_outlives,
7272
generics_of: generics_of::generics_of,
7373
predicates_of: predicates_of::predicates_of,
@@ -328,9 +328,9 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
328328
self.tcx.ensure().generics_of(def_id);
329329
self.tcx.ensure().predicates_of(def_id);
330330
self.tcx.ensure().explicit_item_bounds(def_id);
331-
self.tcx.ensure().explicit_item_super_predicates(def_id);
331+
self.tcx.ensure().explicit_item_self_bounds(def_id);
332332
self.tcx.ensure().item_bounds(def_id);
333-
self.tcx.ensure().item_super_predicates(def_id);
333+
self.tcx.ensure().item_self_bounds(def_id);
334334
if self.tcx.is_conditionally_const(def_id) {
335335
self.tcx.ensure().explicit_implied_const_bounds(def_id);
336336
self.tcx.ensure().const_conditions(def_id);
@@ -822,7 +822,7 @@ fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
822822

823823
hir::TraitItemKind::Type(_, Some(_)) => {
824824
tcx.ensure().item_bounds(def_id);
825-
tcx.ensure().item_super_predicates(def_id);
825+
tcx.ensure().item_self_bounds(def_id);
826826
tcx.ensure().type_of(def_id);
827827
// Account for `type T = _;`.
828828
let mut visitor = HirPlaceholderCollector::default();
@@ -839,7 +839,7 @@ fn lower_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
839839

840840
hir::TraitItemKind::Type(_, None) => {
841841
tcx.ensure().item_bounds(def_id);
842-
tcx.ensure().item_super_predicates(def_id);
842+
tcx.ensure().item_self_bounds(def_id);
843843
// #74612: Visit and try to find bad placeholders
844844
// even if there is no concrete type.
845845
let mut visitor = HirPlaceholderCollector::default();

Diff for: compiler/rustc_hir_analysis/src/collect/item_bounds.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ pub(super) fn explicit_item_bounds(
350350
explicit_item_bounds_with_filter(tcx, def_id, PredicateFilter::All)
351351
}
352352

353-
pub(super) fn explicit_item_super_predicates(
353+
pub(super) fn explicit_item_self_bounds(
354354
tcx: TyCtxt<'_>,
355355
def_id: LocalDefId,
356356
) -> ty::EarlyBinder<'_, &'_ [(ty::Clause<'_>, Span)]> {
@@ -434,11 +434,11 @@ pub(super) fn item_bounds(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<'_,
434434
})
435435
}
436436

437-
pub(super) fn item_super_predicates(
437+
pub(super) fn item_self_bounds(
438438
tcx: TyCtxt<'_>,
439439
def_id: DefId,
440440
) -> ty::EarlyBinder<'_, ty::Clauses<'_>> {
441-
tcx.explicit_item_super_predicates(def_id).map_bound(|bounds| {
441+
tcx.explicit_item_self_bounds(def_id).map_bound(|bounds| {
442442
tcx.mk_clauses_from_iter(
443443
util::elaborate(tcx, bounds.iter().map(|&(bound, _span)| bound)).filter_only_self(),
444444
)
@@ -447,13 +447,12 @@ pub(super) fn item_super_predicates(
447447

448448
/// This exists as an optimization to compute only the item bounds of the item
449449
/// that are not `Self` bounds.
450-
pub(super) fn item_non_self_assumptions(
450+
pub(super) fn item_non_self_bounds(
451451
tcx: TyCtxt<'_>,
452452
def_id: DefId,
453453
) -> ty::EarlyBinder<'_, ty::Clauses<'_>> {
454454
let all_bounds: FxIndexSet<_> = tcx.item_bounds(def_id).skip_binder().iter().collect();
455-
let own_bounds: FxIndexSet<_> =
456-
tcx.item_super_predicates(def_id).skip_binder().iter().collect();
455+
let own_bounds: FxIndexSet<_> = tcx.item_self_bounds(def_id).skip_binder().iter().collect();
457456
if all_bounds.len() == own_bounds.len() {
458457
ty::EarlyBinder::bind(ty::ListWithCachedTypeInfo::empty())
459458
} else {

Diff for: compiler/rustc_hir_typeck/src/closure.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
308308
expected_ty,
309309
closure_kind,
310310
self.tcx
311-
.explicit_item_super_predicates(def_id)
311+
.explicit_item_self_bounds(def_id)
312312
.iter_instantiated_copied(self.tcx, args)
313313
.map(|(c, s)| (c.as_predicate(), s)),
314314
),
@@ -1019,7 +1019,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10191019
}
10201020
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => self
10211021
.tcx
1022-
.explicit_item_super_predicates(def_id)
1022+
.explicit_item_self_bounds(def_id)
10231023
.iter_instantiated_copied(self.tcx, args)
10241024
.find_map(|(p, s)| get_future_output(p.as_predicate(), s))?,
10251025
ty::Error(_) => return Some(ret_ty),

Diff for: compiler/rustc_hir_typeck/src/coercion.rs

+20-24
Original file line numberDiff line numberDiff line change
@@ -1847,30 +1847,26 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
18471847
fcx.probe(|_| {
18481848
let ocx = ObligationCtxt::new(fcx);
18491849
ocx.register_obligations(
1850-
fcx.tcx.item_super_predicates(rpit_def_id).iter_identity().filter_map(
1851-
|clause| {
1852-
let predicate = clause
1853-
.kind()
1854-
.map_bound(|clause| match clause {
1855-
ty::ClauseKind::Trait(trait_pred) => Some(
1856-
ty::ClauseKind::Trait(trait_pred.with_self_ty(fcx.tcx, ty)),
1857-
),
1858-
ty::ClauseKind::Projection(proj_pred) => {
1859-
Some(ty::ClauseKind::Projection(
1860-
proj_pred.with_self_ty(fcx.tcx, ty),
1861-
))
1862-
}
1863-
_ => None,
1864-
})
1865-
.transpose()?;
1866-
Some(Obligation::new(
1867-
fcx.tcx,
1868-
ObligationCause::dummy(),
1869-
fcx.param_env,
1870-
predicate,
1871-
))
1872-
},
1873-
),
1850+
fcx.tcx.item_self_bounds(rpit_def_id).iter_identity().filter_map(|clause| {
1851+
let predicate = clause
1852+
.kind()
1853+
.map_bound(|clause| match clause {
1854+
ty::ClauseKind::Trait(trait_pred) => Some(ty::ClauseKind::Trait(
1855+
trait_pred.with_self_ty(fcx.tcx, ty),
1856+
)),
1857+
ty::ClauseKind::Projection(proj_pred) => Some(
1858+
ty::ClauseKind::Projection(proj_pred.with_self_ty(fcx.tcx, ty)),
1859+
),
1860+
_ => None,
1861+
})
1862+
.transpose()?;
1863+
Some(Obligation::new(
1864+
fcx.tcx,
1865+
ObligationCause::dummy(),
1866+
fcx.param_env,
1867+
predicate,
1868+
))
1869+
}),
18741870
);
18751871
ocx.select_where_possible().is_empty()
18761872
})

Diff for: compiler/rustc_infer/src/infer/outlives/verify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
281281
alias_ty: ty::AliasTy<'tcx>,
282282
) -> impl Iterator<Item = ty::Region<'tcx>> {
283283
let tcx = self.tcx;
284-
let bounds = tcx.item_super_predicates(alias_ty.def_id);
284+
let bounds = tcx.item_self_bounds(alias_ty.def_id);
285285
trace!("{:#?}", bounds.skip_binder());
286286
bounds
287287
.iter_instantiated(tcx, alias_ty.args)

Diff for: compiler/rustc_lint/src/unused.rs

+16-19
Original file line numberDiff line numberDiff line change
@@ -289,25 +289,22 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
289289
}
290290
ty::Adt(def, _) => is_def_must_use(cx, def.did(), span),
291291
ty::Alias(ty::Opaque | ty::Projection, ty::AliasTy { def_id: def, .. }) => {
292-
elaborate(
293-
cx.tcx,
294-
cx.tcx.explicit_item_super_predicates(def).iter_identity_copied(),
295-
)
296-
// We only care about self bounds for the impl-trait
297-
.filter_only_self()
298-
.find_map(|(pred, _span)| {
299-
// We only look at the `DefId`, so it is safe to skip the binder here.
300-
if let ty::ClauseKind::Trait(ref poly_trait_predicate) =
301-
pred.kind().skip_binder()
302-
{
303-
let def_id = poly_trait_predicate.trait_ref.def_id;
304-
305-
is_def_must_use(cx, def_id, span)
306-
} else {
307-
None
308-
}
309-
})
310-
.map(|inner| MustUsePath::Opaque(Box::new(inner)))
292+
elaborate(cx.tcx, cx.tcx.explicit_item_self_bounds(def).iter_identity_copied())
293+
// We only care about self bounds for the impl-trait
294+
.filter_only_self()
295+
.find_map(|(pred, _span)| {
296+
// We only look at the `DefId`, so it is safe to skip the binder here.
297+
if let ty::ClauseKind::Trait(ref poly_trait_predicate) =
298+
pred.kind().skip_binder()
299+
{
300+
let def_id = poly_trait_predicate.trait_ref.def_id;
301+
302+
is_def_must_use(cx, def_id, span)
303+
} else {
304+
None
305+
}
306+
})
307+
.map(|inner| MustUsePath::Opaque(Box::new(inner)))
311308
}
312309
ty::Dynamic(binders, _, _) => binders.iter().find_map(|predicate| {
313310
if let ty::ExistentialPredicate::Trait(ref trait_ref) = predicate.skip_binder()

Diff for: compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl IntoArgs for (CrateNum, SimplifiedType) {
241241

242242
provide! { tcx, def_id, other, cdata,
243243
explicit_item_bounds => { table_defaulted_array }
244-
explicit_item_super_predicates => { table_defaulted_array }
244+
explicit_item_self_bounds => { table_defaulted_array }
245245
explicit_predicates_of => { table }
246246
generics_of => { table }
247247
inferred_outlives_of => { table_defaulted_array }

Diff for: compiler/rustc_metadata/src/rmeta/encoder.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1554,7 +1554,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
15541554
}
15551555
if let DefKind::OpaqueTy = def_kind {
15561556
self.encode_explicit_item_bounds(def_id);
1557-
self.encode_explicit_item_super_predicates(def_id);
1557+
self.encode_explicit_item_self_bounds(def_id);
15581558
record!(self.tables.opaque_ty_origin[def_id] <- self.tcx.opaque_ty_origin(def_id));
15591559
self.encode_precise_capturing_args(def_id);
15601560
if tcx.is_conditionally_const(def_id) {
@@ -1667,10 +1667,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
16671667
record_defaulted_array!(self.tables.explicit_item_bounds[def_id] <- bounds);
16681668
}
16691669

1670-
fn encode_explicit_item_super_predicates(&mut self, def_id: DefId) {
1671-
debug!("EncodeContext::encode_explicit_item_super_predicates({:?})", def_id);
1672-
let bounds = self.tcx.explicit_item_super_predicates(def_id).skip_binder();
1673-
record_defaulted_array!(self.tables.explicit_item_super_predicates[def_id] <- bounds);
1670+
fn encode_explicit_item_self_bounds(&mut self, def_id: DefId) {
1671+
debug!("EncodeContext::encode_explicit_item_self_bounds({:?})", def_id);
1672+
let bounds = self.tcx.explicit_item_self_bounds(def_id).skip_binder();
1673+
record_defaulted_array!(self.tables.explicit_item_self_bounds[def_id] <- bounds);
16741674
}
16751675

16761676
#[instrument(level = "debug", skip(self))]
@@ -1685,7 +1685,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
16851685
AssocItemContainer::Trait => {
16861686
if let ty::AssocKind::Type = item.kind {
16871687
self.encode_explicit_item_bounds(def_id);
1688-
self.encode_explicit_item_super_predicates(def_id);
1688+
self.encode_explicit_item_self_bounds(def_id);
16891689
if tcx.is_conditionally_const(def_id) {
16901690
record_defaulted_array!(self.tables.explicit_implied_const_bounds[def_id]
16911691
<- self.tcx.explicit_implied_const_bounds(def_id).skip_binder());

Diff for: compiler/rustc_metadata/src/rmeta/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ define_tables! {
386386
// corresponding DefPathHash.
387387
def_path_hashes: Table<DefIndex, u64>,
388388
explicit_item_bounds: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>,
389-
explicit_item_super_predicates: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>,
389+
explicit_item_self_bounds: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>,
390390
inferred_outlives_of: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>,
391391
explicit_super_predicates_of: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>,
392392
explicit_implied_predicates_of: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>,

Diff for: compiler/rustc_middle/src/query/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ rustc_queries! {
393393
/// like closure signature deduction.
394394
///
395395
/// [explicit item bounds]: Self::explicit_item_bounds
396-
query explicit_item_super_predicates(key: DefId) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
396+
query explicit_item_self_bounds(key: DefId) -> ty::EarlyBinder<'tcx, &'tcx [(ty::Clause<'tcx>, Span)]> {
397397
desc { |tcx| "finding item bounds for `{}`", tcx.def_path_str(key) }
398398
cache_on_disk_if { key.is_local() }
399399
separate_provide_extern
@@ -427,11 +427,11 @@ rustc_queries! {
427427
desc { |tcx| "elaborating item bounds for `{}`", tcx.def_path_str(key) }
428428
}
429429

430-
query item_super_predicates(key: DefId) -> ty::EarlyBinder<'tcx, ty::Clauses<'tcx>> {
430+
query item_self_bounds(key: DefId) -> ty::EarlyBinder<'tcx, ty::Clauses<'tcx>> {
431431
desc { |tcx| "elaborating item assumptions for `{}`", tcx.def_path_str(key) }
432432
}
433433

434-
query item_non_self_assumptions(key: DefId) -> ty::EarlyBinder<'tcx, ty::Clauses<'tcx>> {
434+
query item_non_self_bounds(key: DefId) -> ty::EarlyBinder<'tcx, ty::Clauses<'tcx>> {
435435
desc { |tcx| "elaborating item assumptions for `{}`", tcx.def_path_str(key) }
436436
}
437437

Diff for: compiler/rustc_middle/src/ty/context.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,20 @@ impl<'tcx> Interner for TyCtxt<'tcx> {
345345
self.item_bounds(def_id).map_bound(IntoIterator::into_iter)
346346
}
347347

348+
fn item_self_bounds(
349+
self,
350+
def_id: DefId,
351+
) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Clause<'tcx>>> {
352+
self.item_self_bounds(def_id).map_bound(IntoIterator::into_iter)
353+
}
354+
355+
fn item_non_self_bounds(
356+
self,
357+
def_id: DefId,
358+
) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Clause<'tcx>>> {
359+
self.item_non_self_bounds(def_id).map_bound(IntoIterator::into_iter)
360+
}
361+
348362
fn predicates_of(
349363
self,
350364
def_id: DefId,
@@ -2577,7 +2591,7 @@ impl<'tcx> TyCtxt<'tcx> {
25772591
let ty::Alias(ty::Opaque, ty::AliasTy { def_id, .. }) = ty.kind() else { return false };
25782592
let future_trait = self.require_lang_item(LangItem::Future, None);
25792593

2580-
self.explicit_item_super_predicates(def_id).skip_binder().iter().any(|&(predicate, _)| {
2594+
self.explicit_item_self_bounds(def_id).skip_binder().iter().any(|&(predicate, _)| {
25812595
let ty::ClauseKind::Trait(trait_predicate) = predicate.kind().skip_binder() else {
25822596
return false;
25832597
};

Diff for: compiler/rustc_middle/src/ty/return_position_impl_trait_in_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<'tcx> TyCtxt<'tcx> {
6464
args: ty::GenericArgsRef<'tcx>,
6565
) -> &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>> {
6666
let mut bounds: Vec<_> = self
67-
.item_super_predicates(def_id)
67+
.item_self_bounds(def_id)
6868
.iter_instantiated(self, args)
6969
.filter_map(|clause| {
7070
clause

0 commit comments

Comments
 (0)