Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit bc4b39c

Browse files
committed
Auto merge of rust-lang#101152 - Dylan-DPC:rollup-v4iw8ux, r=Dylan-DPC
Rollup of 8 pull requests Successful merges: - rust-lang#98304 (Add MaybeUninit memset test) - rust-lang#98801 (Add a `File::create_new` constructor) - rust-lang#99821 (Remove separate indexing of early-bound regions) - rust-lang#100239 (remove an ineffective check in const_prop) - rust-lang#100337 (Stabilize `std::io::read_to_string`) - rust-lang#100819 (Make use of `[wrapping_]byte_{add,sub}`) - rust-lang#100934 (Remove a panicking branch from `fmt::builders::PadAdapter`) - rust-lang#101000 (Separate CountIsStar from CountIsParam in rustc_parse_format.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents fcc2bdd + 0b6faca commit bc4b39c

File tree

44 files changed

+330
-534
lines changed

Some content is hidden

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

44 files changed

+330
-534
lines changed

compiler/rustc_arena/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#![feature(maybe_uninit_slice)]
1717
#![feature(min_specialization)]
1818
#![feature(decl_macro)]
19+
#![feature(pointer_byte_offsets)]
1920
#![feature(rustc_attrs)]
2021
#![cfg_attr(test, feature(test))]
2122
#![feature(strict_provenance)]
@@ -211,7 +212,7 @@ impl<T> TypedArena<T> {
211212

212213
unsafe {
213214
if mem::size_of::<T>() == 0 {
214-
self.ptr.set((self.ptr.get() as *mut u8).wrapping_offset(1) as *mut T);
215+
self.ptr.set(self.ptr.get().wrapping_byte_add(1));
215216
let ptr = ptr::NonNull::<T>::dangling().as_ptr();
216217
// Don't drop the object. This `write` is equivalent to `forget`.
217218
ptr::write(ptr, object);

compiler/rustc_builtin_macros/src/format.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ impl<'a, 'b> Context<'a, 'b> {
541541
) {
542542
match c {
543543
parse::CountImplied | parse::CountIs(..) => {}
544-
parse::CountIsParam(i) => {
544+
parse::CountIsParam(i) | parse::CountIsStar(i) => {
545545
self.unused_names_lint.maybe_add_positional_named_arg(
546546
self.args.get(i),
547547
named_arg_type,
@@ -589,7 +589,7 @@ impl<'a, 'b> Context<'a, 'b> {
589589
+ self
590590
.arg_with_formatting
591591
.iter()
592-
.filter(|fmt| matches!(fmt.precision, parse::CountIsParam(_)))
592+
.filter(|fmt| matches!(fmt.precision, parse::CountIsStar(_)))
593593
.count();
594594
if self.names.is_empty() && !numbered_position_args && count != self.num_args() {
595595
e = self.ecx.struct_span_err(
@@ -639,7 +639,7 @@ impl<'a, 'b> Context<'a, 'b> {
639639
if let Some(span) = fmt.precision_span {
640640
let span = self.fmtsp.from_inner(InnerSpan::new(span.start, span.end));
641641
match fmt.precision {
642-
parse::CountIsParam(pos) if pos > self.num_args() => {
642+
parse::CountIsParam(pos) if pos >= self.num_args() => {
643643
e.span_label(
644644
span,
645645
&format!(
@@ -651,12 +651,12 @@ impl<'a, 'b> Context<'a, 'b> {
651651
);
652652
zero_based_note = true;
653653
}
654-
parse::CountIsParam(pos) => {
654+
parse::CountIsStar(pos) => {
655655
let count = self.pieces.len()
656656
+ self
657657
.arg_with_formatting
658658
.iter()
659-
.filter(|fmt| matches!(fmt.precision, parse::CountIsParam(_)))
659+
.filter(|fmt| matches!(fmt.precision, parse::CountIsStar(_)))
660660
.count();
661661
e.span_label(
662662
span,
@@ -837,7 +837,7 @@ impl<'a, 'b> Context<'a, 'b> {
837837
};
838838
match c {
839839
parse::CountIs(i) => count(sym::Is, Some(self.ecx.expr_usize(sp, i))),
840-
parse::CountIsParam(i) => {
840+
parse::CountIsParam(i) | parse::CountIsStar(i) => {
841841
// This needs mapping too, as `i` is referring to a macro
842842
// argument. If `i` is not found in `count_positions` then
843843
// the error had already been emitted elsewhere.

compiler/rustc_const_eval/src/interpret/eval_context.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,6 @@ pub enum LocalValue<Prov: Provenance = AllocId> {
187187

188188
impl<'tcx, Prov: Provenance + 'static> LocalState<'tcx, Prov> {
189189
/// Read the local's value or error if the local is not yet live or not live anymore.
190-
///
191-
/// Note: This may only be invoked from the `Machine::access_local` hook and not from
192-
/// anywhere else. You may be invalidating machine invariants if you do!
193190
#[inline]
194191
pub fn access(&self) -> InterpResult<'tcx, &Operand<Prov>> {
195192
match &self.value {

compiler/rustc_const_eval/src/interpret/machine.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -215,23 +215,12 @@ pub trait Machine<'mir, 'tcx>: Sized {
215215
right: &ImmTy<'tcx, Self::Provenance>,
216216
) -> InterpResult<'tcx, (Scalar<Self::Provenance>, bool, Ty<'tcx>)>;
217217

218-
/// Called to read the specified `local` from the `frame`.
219-
/// Since reading a ZST is not actually accessing memory or locals, this is never invoked
220-
/// for ZST reads.
221-
#[inline]
222-
fn access_local<'a>(
223-
frame: &'a Frame<'mir, 'tcx, Self::Provenance, Self::FrameExtra>,
224-
local: mir::Local,
225-
) -> InterpResult<'tcx, &'a Operand<Self::Provenance>>
226-
where
227-
'tcx: 'mir,
228-
{
229-
frame.locals[local].access()
230-
}
231-
232218
/// Called to write the specified `local` from the `frame`.
233219
/// Since writing a ZST is not actually accessing memory or locals, this is never invoked
234220
/// for ZST reads.
221+
///
222+
/// Due to borrow checker trouble, we indicate the `frame` as an index rather than an `&mut
223+
/// Frame`.
235224
#[inline]
236225
fn access_local_mut<'a>(
237226
ecx: &'a mut InterpCx<'mir, 'tcx, Self>,

compiler/rustc_const_eval/src/interpret/operand.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
444444
}
445445
}
446446

447-
/// Read from a local. Will not actually access the local if reading from a ZST.
447+
/// Read from a local.
448448
/// Will not access memory, instead an indirect `Operand` is returned.
449449
///
450450
/// This is public because it is used by [priroda](https://github.com/oli-obk/priroda) to get an
@@ -456,12 +456,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
456456
layout: Option<TyAndLayout<'tcx>>,
457457
) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> {
458458
let layout = self.layout_of_local(frame, local, layout)?;
459-
let op = if layout.is_zst() {
460-
// Bypass `access_local` (helps in ConstProp)
461-
Operand::Immediate(Immediate::Uninit)
462-
} else {
463-
*M::access_local(frame, local)?
464-
};
459+
let op = *frame.locals[local].access()?;
465460
Ok(OpTy { op, layout, align: Some(layout.align.abi) })
466461
}
467462

compiler/rustc_const_eval/src/interpret/place.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ where
642642
// avoid force_allocation.
643643
let src = match self.read_immediate_raw(src)? {
644644
Ok(src_val) => {
645-
assert!(!src.layout.is_unsized(), "cannot have unsized immediates");
645+
assert!(!src.layout.is_unsized(), "cannot copy unsized immediates");
646646
assert!(
647647
!dest.layout.is_unsized(),
648648
"the src is sized, so the dest must also be sized"

compiler/rustc_const_eval/src/interpret/projection.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ where
100100
// This makes several assumptions about what layouts we will encounter; we match what
101101
// codegen does as good as we can (see `extract_field` in `rustc_codegen_ssa/src/mir/operand.rs`).
102102
let field_val: Immediate<_> = match (*base, base.layout.abi) {
103+
// if the entire value is uninit, then so is the field (can happen in ConstProp)
104+
(Immediate::Uninit, _) => Immediate::Uninit,
103105
// the field contains no information, can be left uninit
104106
_ if field_layout.is_zst() => Immediate::Uninit,
105107
// the field covers the entire type
@@ -124,6 +126,7 @@ where
124126
b_val
125127
})
126128
}
129+
// everything else is a bug
127130
_ => span_bug!(
128131
self.cur_span(),
129132
"invalid field access on immediate {}, layout {:#?}",

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
103103
// Find the index of the named region that was part of the
104104
// error. We will then search the function parameters for a bound
105105
// region at the right depth with the same index
106-
(Some(rl::Region::EarlyBound(_, id)), ty::BrNamed(def_id, _)) => {
106+
(Some(rl::Region::EarlyBound(id)), ty::BrNamed(def_id, _)) => {
107107
debug!("EarlyBound id={:?} def_id={:?}", id, def_id);
108108
if id == def_id {
109109
self.found_type = Some(arg);
@@ -133,7 +133,7 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
133133
Some(
134134
rl::Region::Static
135135
| rl::Region::Free(_, _)
136-
| rl::Region::EarlyBound(_, _)
136+
| rl::Region::EarlyBound(_)
137137
| rl::Region::LateBound(_, _, _),
138138
)
139139
| None,
@@ -188,7 +188,7 @@ impl<'tcx> Visitor<'tcx> for TyPathVisitor<'tcx> {
188188
fn visit_lifetime(&mut self, lifetime: &hir::Lifetime) {
189189
match (self.tcx.named_region(lifetime.hir_id), self.bound_region) {
190190
// the lifetime of the TyPath!
191-
(Some(rl::Region::EarlyBound(_, id)), ty::BrNamed(def_id, _)) => {
191+
(Some(rl::Region::EarlyBound(id)), ty::BrNamed(def_id, _)) => {
192192
debug!("EarlyBound id={:?} def_id={:?}", id, def_id);
193193
if id == def_id {
194194
self.found_it = true;
@@ -209,7 +209,7 @@ impl<'tcx> Visitor<'tcx> for TyPathVisitor<'tcx> {
209209
(
210210
Some(
211211
rl::Region::Static
212-
| rl::Region::EarlyBound(_, _)
212+
| rl::Region::EarlyBound(_)
213213
| rl::Region::LateBound(_, _, _)
214214
| rl::Region::Free(_, _),
215215
)

compiler/rustc_lint/src/builtin.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,13 +2026,13 @@ declare_lint_pass!(ExplicitOutlivesRequirements => [EXPLICIT_OUTLIVES_REQUIREMEN
20262026
impl ExplicitOutlivesRequirements {
20272027
fn lifetimes_outliving_lifetime<'tcx>(
20282028
inferred_outlives: &'tcx [(ty::Predicate<'tcx>, Span)],
2029-
index: u32,
2029+
def_id: DefId,
20302030
) -> Vec<ty::Region<'tcx>> {
20312031
inferred_outlives
20322032
.iter()
20332033
.filter_map(|(pred, _)| match pred.kind().skip_binder() {
20342034
ty::PredicateKind::RegionOutlives(ty::OutlivesPredicate(a, b)) => match *a {
2035-
ty::ReEarlyBound(ebr) if ebr.index == index => Some(b),
2035+
ty::ReEarlyBound(ebr) if ebr.def_id == def_id => Some(b),
20362036
_ => None,
20372037
},
20382038
_ => None,
@@ -2069,8 +2069,12 @@ impl ExplicitOutlivesRequirements {
20692069
.filter_map(|(i, bound)| {
20702070
if let hir::GenericBound::Outlives(lifetime) = bound {
20712071
let is_inferred = match tcx.named_region(lifetime.hir_id) {
2072-
Some(Region::EarlyBound(index, ..)) => inferred_outlives.iter().any(|r| {
2073-
if let ty::ReEarlyBound(ebr) = **r { ebr.index == index } else { false }
2072+
Some(Region::EarlyBound(def_id)) => inferred_outlives.iter().any(|r| {
2073+
if let ty::ReEarlyBound(ebr) = **r {
2074+
ebr.def_id == def_id
2075+
} else {
2076+
false
2077+
}
20742078
}),
20752079
_ => false,
20762080
};
@@ -2164,11 +2168,14 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitOutlivesRequirements {
21642168
for (i, where_predicate) in hir_generics.predicates.iter().enumerate() {
21652169
let (relevant_lifetimes, bounds, span, in_where_clause) = match where_predicate {
21662170
hir::WherePredicate::RegionPredicate(predicate) => {
2167-
if let Some(Region::EarlyBound(index, ..)) =
2171+
if let Some(Region::EarlyBound(region_def_id)) =
21682172
cx.tcx.named_region(predicate.lifetime.hir_id)
21692173
{
21702174
(
2171-
Self::lifetimes_outliving_lifetime(inferred_outlives, index),
2175+
Self::lifetimes_outliving_lifetime(
2176+
inferred_outlives,
2177+
region_def_id,
2178+
),
21722179
&predicate.bounds,
21732180
predicate.span,
21742181
predicate.in_where_clause,

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ provide! { tcx, def_id, other, cdata,
199199
codegen_fn_attrs => { table }
200200
impl_trait_ref => { table }
201201
const_param_default => { table }
202+
object_lifetime_default => { table }
202203
thir_abstract_const => { table }
203204
optimized_mir => { table }
204205
mir_for_ctfe => { table }

0 commit comments

Comments
 (0)