Skip to content

Commit db241bb

Browse files
committed
Auto merge of rust-lang#78458 - Dylan-DPC:rollup-tan044s, r=Dylan-DPC
Rollup of 10 pull requests Successful merges: - rust-lang#78152 (Separate unsized locals) - rust-lang#78297 (Suggest calling await on method call and field access) - rust-lang#78351 (Move "mutable thing in const" check from interning to validity) - rust-lang#78365 (check object safety of generic constants) - rust-lang#78379 (Tweak invalid `fn` header and body parsing) - rust-lang#78391 (Add const_fn in generics test) - rust-lang#78401 (resolve: private fields in tuple struct ctor diag) - rust-lang#78408 (Remove tokens from foreign items in `TokenStripper`) - rust-lang#78447 (Fix typo in comment) - rust-lang#78453 (Fix typo in comments) Failed merges: r? `@ghost`
2 parents 90e6d0d + 6967005 commit db241bb

File tree

123 files changed

+1059
-549
lines changed

Some content is hidden

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

123 files changed

+1059
-549
lines changed

compiler/rustc_arena/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ impl DropArena {
533533
ptr::write(mem, object);
534534
let result = &mut *mem;
535535
// Record the destructor after doing the allocation as that may panic
536-
// and would cause `object`'s destuctor to run twice if it was recorded before
536+
// and would cause `object`'s destructor to run twice if it was recorded before
537537
self.destructors
538538
.borrow_mut()
539539
.push(DropType { drop_fn: drop_for_type::<T>, obj: result as *mut T as *mut u8 });
@@ -560,7 +560,7 @@ impl DropArena {
560560
mem::forget(vec.drain(..));
561561

562562
// Record the destructors after doing the allocation as that may panic
563-
// and would cause `object`'s destuctor to run twice if it was recorded before
563+
// and would cause `object`'s destructor to run twice if it was recorded before
564564
for i in 0..len {
565565
destructors.push(DropType {
566566
drop_fn: drop_for_type::<T>,

compiler/rustc_data_structures/src/graph/vec_graph/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl<N: Idx> VecGraph<N> {
2929

3030
// Create the *edge starts* array. We are iterating over over
3131
// the (sorted) edge pairs. We maintain the invariant that the
32-
// length of the `node_starts` arary is enough to store the
32+
// length of the `node_starts` array is enough to store the
3333
// current source node -- so when we see that the source node
3434
// for an edge is greater than the current length, we grow the
3535
// edge-starts array by just enough.

compiler/rustc_feature/src/active.rs

+4
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,9 @@ declare_features! (
607607
/// Allow anonymous constants from an inline `const` block
608608
(active, inline_const, "1.49.0", Some(76001), None),
609609

610+
/// Allows unsized fn parameters.
611+
(active, unsized_fn_params, "1.49.0", Some(48055), None),
612+
610613
// -------------------------------------------------------------------------
611614
// feature-group-end: actual feature gates
612615
// -------------------------------------------------------------------------
@@ -629,6 +632,7 @@ pub const INCOMPLETE_FEATURES: &[Symbol] = &[
629632
sym::specialization,
630633
sym::inline_const,
631634
sym::repr128,
635+
sym::unsized_locals,
632636
];
633637

634638
/// Some features are not allowed to be used together at the same time, if

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1669,7 +1669,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
16691669
self.note_error_origin(diag, cause, exp_found);
16701670
}
16711671

1672-
fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
1672+
pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
16731673
if let ty::Opaque(def_id, substs) = ty.kind() {
16741674
let future_trait = self.tcx.require_lang_item(LangItem::Future, None);
16751675
// Future::Output

compiler/rustc_interface/src/passes.rs

+7
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ impl mut_visit::MutVisitor for TokenStripper {
6363
i.tokens = None;
6464
mut_visit::noop_flat_map_item(i, self)
6565
}
66+
fn flat_map_foreign_item(
67+
&mut self,
68+
mut i: P<ast::ForeignItem>,
69+
) -> SmallVec<[P<ast::ForeignItem>; 1]> {
70+
i.tokens = None;
71+
mut_visit::noop_flat_map_foreign_item(i, self)
72+
}
6673
fn visit_block(&mut self, b: &mut P<ast::Block>) {
6774
b.tokens = None;
6875
mut_visit::noop_visit_block(b, self);

compiler/rustc_middle/src/mir/mod.rs

-12
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,6 @@ pub struct Body<'tcx> {
210210
/// We hold in this field all the constants we are not able to evaluate yet.
211211
pub required_consts: Vec<Constant<'tcx>>,
212212

213-
/// The user may be writing e.g. `&[(SOME_CELL, 42)][i].1` and this would get promoted, because
214-
/// we'd statically know that no thing with interior mutability will ever be available to the
215-
/// user without some serious unsafe code. Now this means that our promoted is actually
216-
/// `&[(SOME_CELL, 42)]` and the MIR using it will do the `&promoted[i].1` projection because
217-
/// the index may be a runtime value. Such a promoted value is illegal because it has reachable
218-
/// interior mutability. This flag just makes this situation very obvious where the previous
219-
/// implementation without the flag hid this situation silently.
220-
/// FIXME(oli-obk): rewrite the promoted during promotion to eliminate the cell components.
221-
pub ignore_interior_mut_in_const_validation: bool,
222-
223213
/// Does this body use generic parameters. This is used for the `ConstEvaluatable` check.
224214
///
225215
/// Note that this does not actually mean that this body is not computable right now.
@@ -276,7 +266,6 @@ impl<'tcx> Body<'tcx> {
276266
var_debug_info,
277267
span,
278268
required_consts: Vec::new(),
279-
ignore_interior_mut_in_const_validation: false,
280269
is_polymorphic: false,
281270
predecessor_cache: PredecessorCache::new(),
282271
};
@@ -306,7 +295,6 @@ impl<'tcx> Body<'tcx> {
306295
required_consts: Vec::new(),
307296
generator_kind: None,
308297
var_debug_info: Vec::new(),
309-
ignore_interior_mut_in_const_validation: false,
310298
is_polymorphic: false,
311299
predecessor_cache: PredecessorCache::new(),
312300
};

compiler/rustc_mir/src/borrow_check/type_check/mod.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,11 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
974974
checker
975975
}
976976

977+
fn unsized_feature_enabled(&self) -> bool {
978+
let features = self.tcx().features();
979+
features.unsized_locals || features.unsized_fn_params
980+
}
981+
977982
/// Equate the inferred type and the annotated type for user type annotations
978983
fn check_user_type_annotations(&mut self) {
979984
debug!(
@@ -1456,7 +1461,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
14561461
}
14571462

14581463
self.check_rvalue(body, rv, location);
1459-
if !self.tcx().features().unsized_locals {
1464+
if !self.unsized_feature_enabled() {
14601465
let trait_ref = ty::TraitRef {
14611466
def_id: tcx.require_lang_item(LangItem::Sized, Some(self.last_span)),
14621467
substs: tcx.mk_substs_trait(place_ty, &[]),
@@ -1717,9 +1722,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
17171722
);
17181723
}
17191724

1720-
// When `#![feature(unsized_locals)]` is not enabled,
1725+
// When `unsized_fn_params` and `unsized_locals` are both not enabled,
17211726
// this check is done at `check_local`.
1722-
if self.tcx().features().unsized_locals {
1727+
if self.unsized_feature_enabled() {
17231728
let span = term.source_info.span;
17241729
self.ensure_place_sized(dest_ty, span);
17251730
}
@@ -1880,9 +1885,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18801885
LocalKind::Var | LocalKind::Temp => {}
18811886
}
18821887

1883-
// When `#![feature(unsized_locals)]` is enabled, only function calls
1888+
// When `unsized_fn_params` or `unsized_locals` is enabled, only function calls
18841889
// and nullary ops are checked in `check_call_dest`.
1885-
if !self.tcx().features().unsized_locals {
1890+
if !self.unsized_feature_enabled() {
18861891
let span = local_decl.source_info.span;
18871892
let ty = local_decl.ty;
18881893
self.ensure_place_sized(ty, span);
@@ -2024,7 +2029,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
20242029

20252030
Rvalue::NullaryOp(_, ty) => {
20262031
// Even with unsized locals cannot box an unsized value.
2027-
if self.tcx().features().unsized_locals {
2032+
if self.unsized_feature_enabled() {
20282033
let span = body.source_info(location).span;
20292034
self.ensure_place_sized(ty, span);
20302035
}

compiler/rustc_mir/src/const_eval/eval_queries.rs

+24-25
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use super::{CompileTimeEvalContext, CompileTimeInterpreter, ConstEvalErr, MemoryExtra};
22
use crate::interpret::eval_nullary_intrinsic;
33
use crate::interpret::{
4-
intern_const_alloc_recursive, Allocation, ConstAlloc, ConstValue, GlobalId, Immediate,
5-
InternKind, InterpCx, InterpResult, MPlaceTy, MemoryKind, OpTy, RefTracking, Scalar,
4+
intern_const_alloc_recursive, Allocation, ConstAlloc, ConstValue, CtfeValidationMode, GlobalId,
5+
Immediate, InternKind, InterpCx, InterpResult, MPlaceTy, MemoryKind, OpTy, RefTracking, Scalar,
66
ScalarMaybeUninit, StackPopCleanup,
77
};
88

@@ -59,23 +59,15 @@ fn eval_body_using_ecx<'mir, 'tcx>(
5959
ecx.run()?;
6060

6161
// Intern the result
62-
// FIXME: since the DefId of a promoted is the DefId of its owner, this
63-
// means that promoteds in statics are actually interned like statics!
64-
// However, this is also currently crucial because we promote mutable
65-
// non-empty slices in statics to extend their lifetime, and this
66-
// ensures that they are put into a mutable allocation.
67-
// For other kinds of promoteds in statics (like array initializers), this is rather silly.
68-
let intern_kind = match tcx.static_mutability(cid.instance.def_id()) {
69-
Some(m) => InternKind::Static(m),
70-
None if cid.promoted.is_some() => InternKind::Promoted,
71-
_ => InternKind::Constant,
62+
let intern_kind = if cid.promoted.is_some() {
63+
InternKind::Promoted
64+
} else {
65+
match tcx.static_mutability(cid.instance.def_id()) {
66+
Some(m) => InternKind::Static(m),
67+
None => InternKind::Constant,
68+
}
7269
};
73-
intern_const_alloc_recursive(
74-
ecx,
75-
intern_kind,
76-
ret,
77-
body.ignore_interior_mut_in_const_validation,
78-
);
70+
intern_const_alloc_recursive(ecx, intern_kind, ret);
7971

8072
debug!("eval_body_using_ecx done: {:?}", *ret);
8173
Ok(ret)
@@ -376,16 +368,23 @@ pub fn eval_to_allocation_raw_provider<'tcx>(
376368
// Since evaluation had no errors, valiate the resulting constant:
377369
let validation = try {
378370
// FIXME do not validate promoteds until a decision on
379-
// https://github.com/rust-lang/rust/issues/67465 is made
371+
// https://github.com/rust-lang/rust/issues/67465 and
372+
// https://github.com/rust-lang/rust/issues/67534 is made.
373+
// Promoteds can contain unexpected `UnsafeCell` and reference `static`s, but their
374+
// otherwise restricted form ensures that this is still sound. We just lose the
375+
// extra safety net of some of the dynamic checks. They can also contain invalid
376+
// values, but since we do not usually check intermediate results of a computation
377+
// for validity, it might be surprising to do that here.
380378
if cid.promoted.is_none() {
381379
let mut ref_tracking = RefTracking::new(mplace);
380+
let mut inner = false;
382381
while let Some((mplace, path)) = ref_tracking.todo.pop() {
383-
ecx.const_validate_operand(
384-
mplace.into(),
385-
path,
386-
&mut ref_tracking,
387-
/*may_ref_to_static*/ ecx.memory.extra.can_access_statics,
388-
)?;
382+
let mode = match tcx.static_mutability(cid.instance.def_id()) {
383+
Some(_) => CtfeValidationMode::Regular, // a `static`
384+
None => CtfeValidationMode::Const { inner },
385+
};
386+
ecx.const_validate_operand(mplace.into(), path, &mut ref_tracking, mode)?;
387+
inner = true;
389388
}
390389
}
391390
};

compiler/rustc_mir/src/const_eval/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(crate) fn const_caller_location(
2929
let mut ecx = mk_eval_cx(tcx, DUMMY_SP, ty::ParamEnv::reveal_all(), false);
3030

3131
let loc_place = ecx.alloc_caller_location(file, line, col);
32-
intern_const_alloc_recursive(&mut ecx, InternKind::Constant, loc_place, false);
32+
intern_const_alloc_recursive(&mut ecx, InternKind::Constant, loc_place);
3333
ConstValue::Scalar(loc_place.ptr)
3434
}
3535

0 commit comments

Comments
 (0)