Skip to content

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

+2-1
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

+6-6
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

-3
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

+3-14
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

+2-7
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

+1-1
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

+3
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

+4-4
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

+13-6
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

+1
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 }

compiler/rustc_metadata/src/rmeta/encoder.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,11 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
10761076
record_array!(self.tables.inferred_outlives_of[def_id] <- inferred_outlives);
10771077
}
10781078
}
1079+
if let DefKind::TyParam | DefKind::ConstParam = def_kind {
1080+
if let Some(default) = self.tcx.object_lifetime_default(def_id) {
1081+
record!(self.tables.object_lifetime_default[def_id] <- default);
1082+
}
1083+
}
10791084
if let DefKind::Trait | DefKind::TraitAlias = def_kind {
10801085
record!(self.tables.super_predicates_of[def_id] <- self.tcx.super_predicates_of(def_id));
10811086
}

compiler/rustc_metadata/src/rmeta/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use rustc_index::{bit_set::FiniteBitSet, vec::IndexVec};
1616
use rustc_middle::metadata::ModChild;
1717
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
1818
use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportInfo};
19+
use rustc_middle::middle::resolve_lifetime::ObjectLifetimeDefault;
1920
use rustc_middle::mir;
2021
use rustc_middle::ty::fast_reject::SimplifiedType;
2122
use rustc_middle::ty::query::Providers;
@@ -358,6 +359,7 @@ define_tables! {
358359
codegen_fn_attrs: Table<DefIndex, LazyValue<CodegenFnAttrs>>,
359360
impl_trait_ref: Table<DefIndex, LazyValue<ty::TraitRef<'static>>>,
360361
const_param_default: Table<DefIndex, LazyValue<rustc_middle::ty::Const<'static>>>,
362+
object_lifetime_default: Table<DefIndex, LazyValue<ObjectLifetimeDefault>>,
361363
optimized_mir: Table<DefIndex, LazyValue<mir::Body<'static>>>,
362364
mir_for_ctfe: Table<DefIndex, LazyValue<mir::Body<'static>>>,
363365
promoted_mir: Table<DefIndex, LazyValue<IndexVec<mir::Promoted, mir::Body<'static>>>>,

compiler/rustc_middle/src/hir/map/mod.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,9 @@ impl<'hir> Map<'hir> {
486486
let def_kind = self.tcx.def_kind(def_id);
487487
match def_kind {
488488
DefKind::Trait | DefKind::TraitAlias => def_id,
489-
DefKind::TyParam | DefKind::ConstParam => self.tcx.local_parent(def_id),
489+
DefKind::LifetimeParam | DefKind::TyParam | DefKind::ConstParam => {
490+
self.tcx.local_parent(def_id)
491+
}
490492
_ => bug!("ty_param_owner: {:?} is a {:?} not a type parameter", def_id, def_kind),
491493
}
492494
}
@@ -495,7 +497,9 @@ impl<'hir> Map<'hir> {
495497
let def_kind = self.tcx.def_kind(def_id);
496498
match def_kind {
497499
DefKind::Trait | DefKind::TraitAlias => kw::SelfUpper,
498-
DefKind::TyParam | DefKind::ConstParam => self.tcx.item_name(def_id.to_def_id()),
500+
DefKind::LifetimeParam | DefKind::TyParam | DefKind::ConstParam => {
501+
self.tcx.item_name(def_id.to_def_id())
502+
}
499503
_ => bug!("ty_param_name: {:?} is a {:?} not a type parameter", def_id, def_kind),
500504
}
501505
}

compiler/rustc_middle/src/middle/resolve_lifetime.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_macros::HashStable;
1010
#[derive(Clone, Copy, PartialEq, Eq, Hash, TyEncodable, TyDecodable, Debug, HashStable)]
1111
pub enum Region {
1212
Static,
13-
EarlyBound(/* index */ u32, /* lifetime decl */ DefId),
13+
EarlyBound(/* lifetime decl */ DefId),
1414
LateBound(ty::DebruijnIndex, /* late-bound index */ u32, /* lifetime decl */ DefId),
1515
Free(DefId, /* lifetime decl */ DefId),
1616
}
@@ -35,7 +35,13 @@ impl<T: PartialEq> Set1<T> {
3535
}
3636
}
3737

38-
pub type ObjectLifetimeDefault = Set1<Region>;
38+
#[derive(Copy, Clone, Debug, HashStable, Encodable, Decodable)]
39+
pub enum ObjectLifetimeDefault {
40+
Empty,
41+
Static,
42+
Ambiguous,
43+
Param(DefId),
44+
}
3945

4046
/// Maps the id of each lifetime reference to the lifetime decl
4147
/// that it corresponds to.

compiler/rustc_middle/src/query/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1597,8 +1597,9 @@ rustc_queries! {
15971597
/// for each parameter if a trait object were to be passed for that parameter.
15981598
/// For example, for `struct Foo<'a, T, U>`, this would be `['static, 'static]`.
15991599
/// For `struct Foo<'a, T: 'a, U>`, this would instead be `['a, 'static]`.
1600-
query object_lifetime_defaults(_: LocalDefId) -> Option<&'tcx [ObjectLifetimeDefault]> {
1601-
desc { "looking up lifetime defaults for a region on an item" }
1600+
query object_lifetime_default(key: DefId) -> Option<ObjectLifetimeDefault> {
1601+
desc { "looking up lifetime defaults for generic parameter `{:?}`", key }
1602+
separate_provide_extern
16021603
}
16031604
query late_bound_vars_map(_: LocalDefId)
16041605
-> Option<&'tcx FxHashMap<ItemLocalId, Vec<ty::BoundVariableKind>>> {

compiler/rustc_middle/src/ty/generics.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::middle::resolve_lifetime::ObjectLifetimeDefault;
21
use crate::ty;
32
use crate::ty::subst::{Subst, SubstsRef};
43
use crate::ty::EarlyBinder;
@@ -13,7 +12,7 @@ use super::{EarlyBoundRegion, InstantiatedPredicates, ParamConst, ParamTy, Predi
1312
#[derive(Clone, Debug, TyEncodable, TyDecodable, HashStable)]
1413
pub enum GenericParamDefKind {
1514
Lifetime,
16-
Type { has_default: bool, object_lifetime_default: ObjectLifetimeDefault, synthetic: bool },
15+
Type { has_default: bool, synthetic: bool },
1716
Const { has_default: bool },
1817
}
1918

compiler/rustc_middle/src/ty/parameterized.rs

+1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ trivially_parameterized_over_tcx! {
5353
crate::metadata::ModChild,
5454
crate::middle::codegen_fn_attrs::CodegenFnAttrs,
5555
crate::middle::exported_symbols::SymbolExportInfo,
56+
crate::middle::resolve_lifetime::ObjectLifetimeDefault,
5657
crate::mir::ConstQualifs,
5758
ty::Generics,
5859
ty::ImplPolarity,

0 commit comments

Comments
 (0)