diff options
| author | bors <bors@rust-lang.org> | 2023-05-28 18:04:53 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-05-28 18:04:53 +0000 |
| commit | 1c53407e8c7cc922d718bde61ca34f47b6d2120f (patch) | |
| tree | cb51d4703b9467f6794bdee1a94df3909c2017b1 /compiler/rustc_hir_analysis/src/outlives/mod.rs | |
| parent | 3fae1b9fc35fc449186e2138bdf8ee75dac78dae (diff) | |
| parent | c29c212f8dc80e40f099b6dbc9da3111177ba7bf (diff) | |
| download | rust-1c53407e8c7cc922d718bde61ca34f47b6d2120f.tar.gz rust-1c53407e8c7cc922d718bde61ca34f47b6d2120f.zip | |
Auto merge of #112006 - kylematsuda:earlybinder-private, r=jackh726
Make `EarlyBinder`'s inner value private Currently, `EarlyBinder(T)`'s inner value is public, which allows implicitly skipping the binder by indexing into the tuple struct (i.e., `x.0`). `@lcnr` suggested making `EarlyBinder`'s inner value private so users are required to explicitly call `skip_binder` (https://github.com/rust-lang/rust/issues/105779#issuecomment-1549933424) . This PR makes the inner value private, adds `EarlyBinder::new` for constructing a new instance, and replaces uses of `x.0` with `x.skip_binder()` (or similar). It also adds some documentation to `EarlyBinder::skip_binder` explaining how to skip the binder of `&EarlyBinder<T>` to get `&T` now that the inner value is private (since previously we could just do `&x.0`). r? `@lcnr`
Diffstat (limited to 'compiler/rustc_hir_analysis/src/outlives/mod.rs')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/outlives/mod.rs | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/compiler/rustc_hir_analysis/src/outlives/mod.rs b/compiler/rustc_hir_analysis/src/outlives/mod.rs index a8596c707f3..2106d6ff07d 100644 --- a/compiler/rustc_hir_analysis/src/outlives/mod.rs +++ b/compiler/rustc_hir_analysis/src/outlives/mod.rs @@ -98,24 +98,27 @@ fn inferred_outlives_crate(tcx: TyCtxt<'_>, (): ()) -> CratePredicatesMap<'_> { let predicates = global_inferred_outlives .iter() .map(|(&def_id, set)| { - let predicates = &*tcx.arena.alloc_from_iter(set.0.iter().filter_map( - |(ty::OutlivesPredicate(kind1, region2), &span)| { - match kind1.unpack() { - GenericArgKind::Type(ty1) => Some(( - ty::Clause::TypeOutlives(ty::OutlivesPredicate(ty1, *region2)), - span, - )), - GenericArgKind::Lifetime(region1) => Some(( - ty::Clause::RegionOutlives(ty::OutlivesPredicate(region1, *region2)), - span, - )), - GenericArgKind::Const(_) => { - // Generic consts don't impose any constraints. - None + let predicates = + &*tcx.arena.alloc_from_iter(set.as_ref().skip_binder().iter().filter_map( + |(ty::OutlivesPredicate(kind1, region2), &span)| { + match kind1.unpack() { + GenericArgKind::Type(ty1) => Some(( + ty::Clause::TypeOutlives(ty::OutlivesPredicate(ty1, *region2)), + span, + )), + GenericArgKind::Lifetime(region1) => Some(( + ty::Clause::RegionOutlives(ty::OutlivesPredicate( + region1, *region2, + )), + span, + )), + GenericArgKind::Const(_) => { + // Generic consts don't impose any constraints. + None + } } - } - }, - )); + }, + )); (def_id, predicates) }) .collect(); |
