Skip to content

Commit 7f08d04

Browse files
committed
Auto merge of rust-lang#98591 - matthiaskrgr:rollup-7dok1wq, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#98331 (Fix rustdoc argument error) - rust-lang#98506 (Fix span issues in object safety suggestions) - rust-lang#98563 (interpret: refactor allocation info query) - rust-lang#98576 (small regions refactoring) - rust-lang#98577 (Fix "kind" for associated types in trait implementations in rustdoc JSON) - rust-lang#98578 (Remove eddyb from miri failure pings) - rust-lang#98579 (liballoc tests: avoid int2ptr cast) - rust-lang#98581 (Add triagebot mentions.) - rust-lang#98587 (libcore tests: avoid int2ptr casts) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2f3ddd9 + f266821 commit 7f08d04

File tree

51 files changed

+968
-235
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+968
-235
lines changed

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
879879
}
880880

881881
let mut found = false;
882-
tcx.fold_regions(tcx.type_of(body_parent_did), &mut true, |r: ty::Region<'tcx>, _| {
882+
tcx.fold_regions(tcx.type_of(body_parent_did), |r: ty::Region<'tcx>, _| {
883883
if *r == ty::ReEarlyBound(region) {
884884
found = true;
885885
}

compiler/rustc_borrowck/src/region_infer/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
10091009

10101010
debug!("try_promote_type_test_subject(ty = {:?})", ty);
10111011

1012-
let ty = tcx.fold_regions(ty, &mut false, |r, _depth| {
1012+
let ty = tcx.fold_regions(ty, |r, _depth| {
10131013
let region_vid = self.to_region_vid(r);
10141014

10151015
// The challenge if this. We have some region variable `r`
@@ -1289,7 +1289,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
12891289
where
12901290
T: TypeFoldable<'tcx>,
12911291
{
1292-
tcx.fold_regions(value, &mut false, |r, _db| {
1292+
tcx.fold_regions(value, |r, _db| {
12931293
let vid = self.to_region_vid(r);
12941294
let scc = self.constraint_sccs.scc(vid);
12951295
let repr = self.scc_representatives[scc];

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
5959
debug!(?concrete_type, ?substs);
6060

6161
let mut subst_regions = vec![self.universal_regions.fr_static];
62-
let universal_substs = infcx.tcx.fold_regions(substs, &mut false, |region, _| {
62+
let universal_substs = infcx.tcx.fold_regions(substs, |region, _| {
6363
if let ty::RePlaceholder(..) = region.kind() {
6464
// Higher kinded regions don't need remapping, they don't refer to anything outside of this the substs.
6565
return region;
@@ -91,7 +91,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
9191
subst_regions.dedup();
9292

9393
let universal_concrete_type =
94-
infcx.tcx.fold_regions(concrete_type, &mut false, |region, _| match *region {
94+
infcx.tcx.fold_regions(concrete_type, |region, _| match *region {
9595
ty::ReVar(vid) => subst_regions
9696
.iter()
9797
.find(|ur_vid| self.eval_equal(vid, **ur_vid))
@@ -146,7 +146,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
146146
where
147147
T: TypeFoldable<'tcx>,
148148
{
149-
tcx.fold_regions(ty, &mut false, |region, _| match *region {
149+
tcx.fold_regions(ty, |region, _| match *region {
150150
ty::ReVar(vid) => {
151151
// Find something that we can name
152152
let upper_bound = self.approx_universal_upper_bound(vid);

compiler/rustc_borrowck/src/renumber.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub fn renumber_regions<'tcx, T>(infcx: &InferCtxt<'_, 'tcx>, value: T) -> T
3131
where
3232
T: TypeFoldable<'tcx>,
3333
{
34-
infcx.tcx.fold_regions(value, &mut false, |_region, _depth| {
34+
infcx.tcx.fold_regions(value, |_region, _depth| {
3535
let origin = NllRegionVariableOrigin::Existential { from_forall: false };
3636
infcx.next_nll_region_var(origin)
3737
})

compiler/rustc_borrowck/src/type_check/constraint_conversion.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub(crate) struct ConstraintConversion<'a, 'tcx> {
2323
tcx: TyCtxt<'tcx>,
2424
universal_regions: &'a UniversalRegions<'tcx>,
2525
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
26-
implicit_region_bound: Option<ty::Region<'tcx>>,
26+
implicit_region_bound: ty::Region<'tcx>,
2727
param_env: ty::ParamEnv<'tcx>,
2828
locations: Locations,
2929
span: Span,
@@ -36,7 +36,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
3636
infcx: &'a InferCtxt<'a, 'tcx>,
3737
universal_regions: &'a UniversalRegions<'tcx>,
3838
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
39-
implicit_region_bound: Option<ty::Region<'tcx>>,
39+
implicit_region_bound: ty::Region<'tcx>,
4040
param_env: ty::ParamEnv<'tcx>,
4141
locations: Locations,
4242
span: Span,
@@ -108,7 +108,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
108108
// create new region variables, which can't be done later when
109109
// verifying these bounds.
110110
if t1.has_placeholders() {
111-
t1 = tcx.fold_regions(t1, &mut false, |r, _| match *r {
111+
t1 = tcx.fold_regions(t1, |r, _| match *r {
112112
ty::RePlaceholder(placeholder) => {
113113
self.constraints.placeholder_region(self.infcx, placeholder)
114114
}
@@ -120,7 +120,7 @@ impl<'a, 'tcx> ConstraintConversion<'a, 'tcx> {
120120
&mut *self,
121121
tcx,
122122
region_bound_pairs,
123-
implicit_region_bound,
123+
Some(implicit_region_bound),
124124
param_env,
125125
)
126126
.type_must_outlive(origin, t1, r2);

compiler/rustc_borrowck/src/type_check/free_region_relations.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub(crate) struct CreateResult<'tcx> {
6161
pub(crate) fn create<'tcx>(
6262
infcx: &InferCtxt<'_, 'tcx>,
6363
param_env: ty::ParamEnv<'tcx>,
64-
implicit_region_bound: Option<ty::Region<'tcx>>,
64+
implicit_region_bound: ty::Region<'tcx>,
6565
universal_regions: &Rc<UniversalRegions<'tcx>>,
6666
constraints: &mut MirTypeckRegionConstraints<'tcx>,
6767
) -> CreateResult<'tcx> {
@@ -223,7 +223,7 @@ struct UniversalRegionRelationsBuilder<'this, 'tcx> {
223223
infcx: &'this InferCtxt<'this, 'tcx>,
224224
param_env: ty::ParamEnv<'tcx>,
225225
universal_regions: Rc<UniversalRegions<'tcx>>,
226-
implicit_region_bound: Option<ty::Region<'tcx>>,
226+
implicit_region_bound: ty::Region<'tcx>,
227227
constraints: &'this mut MirTypeckRegionConstraints<'tcx>,
228228

229229
// outputs:

compiler/rustc_borrowck/src/type_check/input_output.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
230230
self.infcx,
231231
&self.borrowck_context.universal_regions,
232232
&self.region_bound_pairs,
233-
Some(self.implicit_region_bound),
233+
self.implicit_region_bound,
234234
self.param_env,
235235
Locations::All(DUMMY_SP),
236236
DUMMY_SP,

compiler/rustc_borrowck/src/type_check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ pub(crate) fn type_check<'mir, 'tcx>(
157157
} = free_region_relations::create(
158158
infcx,
159159
param_env,
160-
Some(implicit_region_bound),
160+
implicit_region_bound,
161161
universal_regions,
162162
&mut constraints,
163163
);
@@ -1142,7 +1142,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
11421142
self.infcx,
11431143
self.borrowck_context.universal_regions,
11441144
self.region_bound_pairs,
1145-
Some(self.implicit_region_bound),
1145+
self.implicit_region_bound,
11461146
self.param_env,
11471147
locations,
11481148
locations.span(self.body),

compiler/rustc_borrowck/src/universal_regions.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'cx, 'tcx> {
725725
where
726726
T: TypeFoldable<'tcx>,
727727
{
728-
self.tcx.fold_regions(value, &mut false, |_region, _depth| self.next_nll_region_var(origin))
728+
self.tcx.fold_regions(value, |_region, _depth| self.next_nll_region_var(origin))
729729
}
730730

731731
#[instrument(level = "debug", skip(self, indices))]
@@ -817,9 +817,7 @@ impl<'tcx> UniversalRegionIndices<'tcx> {
817817
where
818818
T: TypeFoldable<'tcx>,
819819
{
820-
tcx.fold_regions(value, &mut false, |region, _| {
821-
tcx.mk_region(ty::ReVar(self.to_region_vid(region)))
822-
})
820+
tcx.fold_regions(value, |region, _| tcx.mk_region(ty::ReVar(self.to_region_vid(region))))
823821
}
824822
}
825823

compiler/rustc_const_eval/src/interpret/memory.rs

+33-50
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,14 @@ impl<T: fmt::Display> fmt::Display for MemoryKind<T> {
5656
}
5757
}
5858

59-
/// Used by `get_size_and_align` to indicate whether the allocation needs to be live.
60-
#[derive(Debug, Copy, Clone)]
61-
pub enum AllocCheck {
62-
/// Allocation must be live and not a function pointer.
63-
Dereferenceable,
64-
/// Allocations needs to be live, but may be a function pointer.
65-
Live,
66-
/// Allocation may be dead.
67-
MaybeDead,
59+
/// The return value of `get_alloc_info` indicates the "kind" of the allocation.
60+
pub enum AllocKind {
61+
/// A regular live data allocation.
62+
LiveData,
63+
/// A function allocation (that fn ptrs point to).
64+
Function,
65+
/// A dead allocation.
66+
Dead,
6867
}
6968

7069
/// The value of a function pointer.
@@ -360,8 +359,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
360359
align,
361360
CheckInAllocMsg::MemoryAccessTest,
362361
|alloc_id, offset, tag| {
363-
let (size, align) =
364-
self.get_alloc_size_and_align(alloc_id, AllocCheck::Dereferenceable)?;
362+
let (size, align) = self.get_live_alloc_size_and_align(alloc_id)?;
365363
Ok((size, align, (alloc_id, offset, tag)))
366364
},
367365
)
@@ -379,15 +377,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
379377
msg: CheckInAllocMsg,
380378
) -> InterpResult<'tcx> {
381379
self.check_and_deref_ptr(ptr, size, Some(align), msg, |alloc_id, _, _| {
382-
let check = match msg {
383-
CheckInAllocMsg::DerefTest | CheckInAllocMsg::MemoryAccessTest => {
384-
AllocCheck::Dereferenceable
385-
}
386-
CheckInAllocMsg::PointerArithmeticTest
387-
| CheckInAllocMsg::OffsetFromTest
388-
| CheckInAllocMsg::InboundsTest => AllocCheck::Live,
389-
};
390-
let (size, align) = self.get_alloc_size_and_align(alloc_id, check)?;
380+
let (size, align) = self.get_live_alloc_size_and_align(alloc_id)?;
391381
Ok((size, align, ()))
392382
})?;
393383
Ok(())
@@ -655,30 +645,19 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
655645

656646
/// Obtain the size and alignment of an allocation, even if that allocation has
657647
/// been deallocated.
658-
///
659-
/// If `liveness` is `AllocCheck::MaybeDead`, this function always returns `Ok`.
660-
pub fn get_alloc_size_and_align(
661-
&self,
662-
id: AllocId,
663-
liveness: AllocCheck,
664-
) -> InterpResult<'tcx, (Size, Align)> {
648+
pub fn get_alloc_info(&self, id: AllocId) -> (Size, Align, AllocKind) {
665649
// # Regular allocations
666650
// Don't use `self.get_raw` here as that will
667651
// a) cause cycles in case `id` refers to a static
668652
// b) duplicate a global's allocation in miri
669653
if let Some((_, alloc)) = self.memory.alloc_map.get(id) {
670-
return Ok((alloc.size(), alloc.align));
654+
return (alloc.size(), alloc.align, AllocKind::LiveData);
671655
}
672656

673657
// # Function pointers
674658
// (both global from `alloc_map` and local from `extra_fn_ptr_map`)
675659
if self.get_fn_alloc(id).is_some() {
676-
return if let AllocCheck::Dereferenceable = liveness {
677-
// The caller requested no function pointers.
678-
throw_ub!(DerefFunctionPointer(id))
679-
} else {
680-
Ok((Size::ZERO, Align::ONE))
681-
};
660+
return (Size::ZERO, Align::ONE, AllocKind::Function);
682661
}
683662

684663
// # Statics
@@ -690,32 +669,38 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
690669
// Use size and align of the type.
691670
let ty = self.tcx.type_of(did);
692671
let layout = self.tcx.layout_of(ParamEnv::empty().and(ty)).unwrap();
693-
Ok((layout.size, layout.align.abi))
672+
(layout.size, layout.align.abi, AllocKind::LiveData)
694673
}
695674
Some(GlobalAlloc::Memory(alloc)) => {
696675
// Need to duplicate the logic here, because the global allocations have
697676
// different associated types than the interpreter-local ones.
698677
let alloc = alloc.inner();
699-
Ok((alloc.size(), alloc.align))
678+
(alloc.size(), alloc.align, AllocKind::LiveData)
700679
}
701680
Some(GlobalAlloc::Function(_)) => bug!("We already checked function pointers above"),
702681
// The rest must be dead.
703682
None => {
704-
if let AllocCheck::MaybeDead = liveness {
705-
// Deallocated pointers are allowed, we should be able to find
706-
// them in the map.
707-
Ok(*self
708-
.memory
709-
.dead_alloc_map
710-
.get(&id)
711-
.expect("deallocated pointers should all be recorded in `dead_alloc_map`"))
712-
} else {
713-
throw_ub!(PointerUseAfterFree(id))
714-
}
683+
// Deallocated pointers are allowed, we should be able to find
684+
// them in the map.
685+
let (size, align) = *self
686+
.memory
687+
.dead_alloc_map
688+
.get(&id)
689+
.expect("deallocated pointers should all be recorded in `dead_alloc_map`");
690+
(size, align, AllocKind::Dead)
715691
}
716692
}
717693
}
718694

695+
/// Obtain the size and alignment of a live allocation.
696+
pub fn get_live_alloc_size_and_align(&self, id: AllocId) -> InterpResult<'tcx, (Size, Align)> {
697+
let (size, align, kind) = self.get_alloc_info(id);
698+
if matches!(kind, AllocKind::Dead) {
699+
throw_ub!(PointerUseAfterFree(id))
700+
}
701+
Ok((size, align))
702+
}
703+
719704
fn get_fn_alloc(&self, id: AllocId) -> Option<FnVal<'tcx, M::ExtraFnVal>> {
720705
if let Some(extra) = self.memory.extra_fn_ptr_map.get(&id) {
721706
Some(FnVal::Other(*extra))
@@ -1187,9 +1172,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
11871172
let ptr = self.scalar_to_ptr(scalar)?;
11881173
match self.ptr_try_get_alloc_id(ptr) {
11891174
Ok((alloc_id, offset, _)) => {
1190-
let (size, _align) = self
1191-
.get_alloc_size_and_align(alloc_id, AllocCheck::MaybeDead)
1192-
.expect("alloc info with MaybeDead cannot fail");
1175+
let (size, _align, _kind) = self.get_alloc_info(alloc_id);
11931176
// If the pointer is out-of-bounds, it may be null.
11941177
// Note that one-past-the-end (offset == size) is still inbounds, and never null.
11951178
offset > size

compiler/rustc_const_eval/src/interpret/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub use self::eval_context::{
2323
};
2424
pub use self::intern::{intern_const_alloc_recursive, InternKind};
2525
pub use self::machine::{compile_time_machine, AllocMap, Machine, MayLeak, StackPopJump};
26-
pub use self::memory::{AllocCheck, AllocRef, AllocRefMut, FnVal, Memory, MemoryKind};
26+
pub use self::memory::{AllocKind, AllocRef, AllocRefMut, FnVal, Memory, MemoryKind};
2727
pub use self::operand::{ImmTy, Immediate, OpTy, Operand};
2828
pub use self::place::{MPlaceTy, MemPlace, MemPlaceMeta, Place, PlaceTy};
2929
pub use self::validity::{CtfeValidationMode, RefTracking};

compiler/rustc_driver/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ fn describe_codegen_flags() {
932932
print_flag_list("-C", config::CG_OPTIONS);
933933
}
934934

935-
fn print_flag_list<T>(
935+
pub fn print_flag_list<T>(
936936
cmdline_opt: &str,
937937
flag_list: &[(&'static str, T, &'static str, &'static str)],
938938
) {

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub fn find_param_with_region<'tcx>(
7979
// May return None; sometimes the tables are not yet populated.
8080
let ty = fn_sig.inputs()[index];
8181
let mut found_anon_region = false;
82-
let new_param_ty = tcx.fold_regions(ty, &mut false, |r, _| {
82+
let new_param_ty = tcx.fold_regions(ty, |r, _| {
8383
if r == anon_region {
8484
found_anon_region = true;
8585
replace_region

compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ impl<'tcx> LexicalRegionResolutions<'tcx> {
868868
where
869869
T: TypeFoldable<'tcx>,
870870
{
871-
tcx.fold_regions(value, &mut false, |r, _db| match *r {
871+
tcx.fold_regions(value, |r, _db| match *r {
872872
ty::ReVar(rid) => self.resolve_var(rid),
873873
_ => r,
874874
})

compiler/rustc_infer/src/infer/outlives/obligations.rs

+2-11
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,13 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
141141
/// `('a, K)` in this list tells us that the bounds in scope
142142
/// indicate that `K: 'a`, where `K` is either a generic
143143
/// parameter like `T` or a projection like `T::Item`.
144-
/// - `implicit_region_bound`: if some, this is a region bound
145-
/// that is considered to hold for all type parameters (the
146-
/// function body).
147144
/// - `param_env` is the parameter environment for the enclosing function.
148145
/// - `body_id` is the body-id whose region obligations are being
149146
/// processed.
150147
#[instrument(level = "debug", skip(self, region_bound_pairs_map))]
151148
pub fn process_registered_region_obligations(
152149
&self,
153150
region_bound_pairs_map: &FxHashMap<hir::HirId, RegionBoundPairs<'tcx>>,
154-
implicit_region_bound: Option<ty::Region<'tcx>>,
155151
param_env: ty::ParamEnv<'tcx>,
156152
) {
157153
assert!(
@@ -170,13 +166,8 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
170166
let sup_type = self.resolve_vars_if_possible(sup_type);
171167

172168
if let Some(region_bound_pairs) = region_bound_pairs_map.get(&body_id) {
173-
let outlives = &mut TypeOutlives::new(
174-
self,
175-
self.tcx,
176-
&region_bound_pairs,
177-
implicit_region_bound,
178-
param_env,
179-
);
169+
let outlives =
170+
&mut TypeOutlives::new(self, self.tcx, &region_bound_pairs, None, param_env);
180171
outlives.type_must_outlive(origin, sup_type, sub_region);
181172
} else {
182173
self.tcx.sess.delay_span_bug(

0 commit comments

Comments
 (0)