Skip to content

Commit 5883b87

Browse files
committed
Auto merge of #92560 - matthiaskrgr:rollup-jeli7ip, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #91587 (core::ops::unsize: improve docs for DispatchFromDyn) - #91907 (Allow `_` as the length of array types and repeat expressions) - #92515 (RustWrapper: adapt for an LLVM API change) - #92516 (Do not use deprecated -Zsymbol-mangling-version in bootstrap) - #92530 (Move `contains` method of Option and Result lower in docs) - #92546 (Update books) - #92551 (rename StackPopClean::None to Root) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7d6f948 + e525e6a commit 5883b87

File tree

41 files changed

+432
-198
lines changed

Some content is hidden

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

41 files changed

+432
-198
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
3434
}
3535
ExprKind::Repeat(ref expr, ref count) => {
3636
let expr = self.lower_expr(expr);
37-
let count = self.lower_anon_const(count);
37+
let count = self.lower_array_length(count);
3838
hir::ExprKind::Repeat(expr, count)
3939
}
4040
ExprKind::Tup(ref elts) => hir::ExprKind::Tup(self.lower_exprs(elts)),

compiler/rustc_ast_lowering/src/lib.rs

+22-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ use rustc_hir::{ConstArg, GenericArg, ParamName};
5656
use rustc_index::vec::{Idx, IndexVec};
5757
use rustc_query_system::ich::StableHashingContext;
5858
use rustc_session::lint::LintBuffer;
59+
use rustc_session::parse::feature_err;
5960
use rustc_session::utils::{FlattenNonterminals, NtToTokenstream};
6061
use rustc_session::Session;
6162
use rustc_span::hygiene::ExpnId;
@@ -1248,7 +1249,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12481249
))
12491250
}
12501251
TyKind::Array(ref ty, ref length) => {
1251-
hir::TyKind::Array(self.lower_ty(ty, itctx), self.lower_anon_const(length))
1252+
hir::TyKind::Array(self.lower_ty(ty, itctx), self.lower_array_length(length))
12521253
}
12531254
TyKind::Typeof(ref expr) => hir::TyKind::Typeof(self.lower_anon_const(expr)),
12541255
TyKind::TraitObject(ref bounds, kind) => {
@@ -2039,6 +2040,26 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20392040
self.expr_block(block, AttrVec::new())
20402041
}
20412042

2043+
fn lower_array_length(&mut self, c: &AnonConst) -> hir::ArrayLen {
2044+
match c.value.kind {
2045+
ExprKind::Underscore => {
2046+
if self.sess.features_untracked().generic_arg_infer {
2047+
hir::ArrayLen::Infer(self.lower_node_id(c.id), c.value.span)
2048+
} else {
2049+
feature_err(
2050+
&self.sess.parse_sess,
2051+
sym::generic_arg_infer,
2052+
c.value.span,
2053+
"using `_` for array lengths is unstable",
2054+
)
2055+
.emit();
2056+
hir::ArrayLen::Body(self.lower_anon_const(c))
2057+
}
2058+
}
2059+
_ => hir::ArrayLen::Body(self.lower_anon_const(c)),
2060+
}
2061+
}
2062+
20422063
fn lower_anon_const(&mut self, c: &AnonConst) -> hir::AnonConst {
20432064
self.with_new_scopes(|this| hir::AnonConst {
20442065
hir_id: this.lower_node_id(c.id),

compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,17 @@ impl<'ll> DebugInfoBuilderMethods for Builder<'_, 'll, '_> {
160160
// the values should match the ones in the DWARF standard anyway.
161161
let op_deref = || unsafe { llvm::LLVMRustDIBuilderCreateOpDeref() };
162162
let op_plus_uconst = || unsafe { llvm::LLVMRustDIBuilderCreateOpPlusUconst() };
163-
let mut addr_ops = SmallVec::<[_; 8]>::new();
163+
let mut addr_ops = SmallVec::<[u64; 8]>::new();
164164

165165
if direct_offset.bytes() > 0 {
166166
addr_ops.push(op_plus_uconst());
167-
addr_ops.push(direct_offset.bytes() as i64);
167+
addr_ops.push(direct_offset.bytes() as u64);
168168
}
169169
for &offset in indirect_offsets {
170170
addr_ops.push(op_deref());
171171
if offset.bytes() > 0 {
172172
addr_ops.push(op_plus_uconst());
173-
addr_ops.push(offset.bytes() as i64);
173+
addr_ops.push(offset.bytes() as u64);
174174
}
175175
}
176176

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2108,7 +2108,7 @@ extern "C" {
21082108
Builder: &DIBuilder<'a>,
21092109
Val: &'a Value,
21102110
VarInfo: &'a DIVariable,
2111-
AddrOps: *const i64,
2111+
AddrOps: *const u64,
21122112
AddrOpsCount: c_uint,
21132113
DL: &'a DILocation,
21142114
InsertAtEnd: &'a BasicBlock,
@@ -2199,8 +2199,8 @@ extern "C" {
21992199
Scope: &'a DIScope,
22002200
InlinedAt: Option<&'a DILocation>,
22012201
) -> &'a DILocation;
2202-
pub fn LLVMRustDIBuilderCreateOpDeref() -> i64;
2203-
pub fn LLVMRustDIBuilderCreateOpPlusUconst() -> i64;
2202+
pub fn LLVMRustDIBuilderCreateOpDeref() -> u64;
2203+
pub fn LLVMRustDIBuilderCreateOpPlusUconst() -> u64;
22042204

22052205
#[allow(improper_ctypes)]
22062206
pub fn LLVMRustWriteTypeToString(Type: &Type, s: &RustString);

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
6363
cid.instance,
6464
body,
6565
Some(&ret.into()),
66-
StackPopCleanup::None { cleanup: false },
66+
StackPopCleanup::Root { cleanup: false },
6767
)?;
6868

6969
// The main interpreter loop.

compiler/rustc_const_eval/src/interpret/eval_context.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ pub enum StackPopCleanup {
156156
/// `ret` stores the block we jump to on a normal return, while `unwind`
157157
/// stores the block used for cleanup during unwinding.
158158
Goto { ret: Option<mir::BasicBlock>, unwind: StackPopUnwind },
159-
/// Just do nothing: Used by Main and for TLS hooks in miri.
159+
/// The root frame of the stack: nowhere else to jump to.
160160
/// `cleanup` says whether locals are deallocated. Static computation
161161
/// wants them leaked to intern what they need (and just throw away
162162
/// the entire `ecx` when it is done).
163-
None { cleanup: bool },
163+
Root { cleanup: bool },
164164
}
165165

166166
/// State of a local variable including a memoized layout
@@ -849,7 +849,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
849849
// because this is CTFE and the final value will be thoroughly validated anyway.
850850
let cleanup = match return_to_block {
851851
StackPopCleanup::Goto { .. } => true,
852-
StackPopCleanup::None { cleanup, .. } => cleanup,
852+
StackPopCleanup::Root { cleanup, .. } => cleanup,
853853
};
854854

855855
if !cleanup {
@@ -874,16 +874,22 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
874874
// Follow the unwind edge.
875875
let unwind = match return_to_block {
876876
StackPopCleanup::Goto { unwind, .. } => unwind,
877-
StackPopCleanup::None { .. } => {
878-
panic!("Encountered StackPopCleanup::None when unwinding!")
877+
StackPopCleanup::Root { .. } => {
878+
panic!("encountered StackPopCleanup::Root when unwinding!")
879879
}
880880
};
881881
self.unwind_to_block(unwind)
882882
} else {
883883
// Follow the normal return edge.
884884
match return_to_block {
885885
StackPopCleanup::Goto { ret, .. } => self.return_to_block(ret),
886-
StackPopCleanup::None { .. } => Ok(()),
886+
StackPopCleanup::Root { .. } => {
887+
assert!(
888+
self.stack().is_empty(),
889+
"only the topmost frame can have StackPopCleanup::Root"
890+
);
891+
Ok(())
892+
}
887893
}
888894
}
889895
}

compiler/rustc_hir/src/hir.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -1407,6 +1407,20 @@ impl fmt::Display for ConstContext {
14071407
/// A literal.
14081408
pub type Lit = Spanned<LitKind>;
14091409

1410+
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Debug, HashStable_Generic)]
1411+
pub enum ArrayLen {
1412+
Infer(HirId, Span),
1413+
Body(AnonConst),
1414+
}
1415+
1416+
impl ArrayLen {
1417+
pub fn hir_id(&self) -> HirId {
1418+
match self {
1419+
&ArrayLen::Infer(hir_id, _) | &ArrayLen::Body(AnonConst { hir_id, body: _ }) => hir_id,
1420+
}
1421+
}
1422+
}
1423+
14101424
/// A constant (expression) that's not an item or associated item,
14111425
/// but needs its own `DefId` for type-checking, const-eval, etc.
14121426
/// These are usually found nested inside types (e.g., array lengths)
@@ -1756,7 +1770,7 @@ pub enum ExprKind<'hir> {
17561770
///
17571771
/// E.g., `[1; 5]`. The first expression is the element
17581772
/// to be repeated; the second is the number of times to repeat it.
1759-
Repeat(&'hir Expr<'hir>, AnonConst),
1773+
Repeat(&'hir Expr<'hir>, ArrayLen),
17601774

17611775
/// A suspension point for generators (i.e., `yield <expr>`).
17621776
Yield(&'hir Expr<'hir>, YieldSource),
@@ -2266,7 +2280,7 @@ pub enum TyKind<'hir> {
22662280
/// A variable length slice (i.e., `[T]`).
22672281
Slice(&'hir Ty<'hir>),
22682282
/// A fixed length array (i.e., `[T; n]`).
2269-
Array(&'hir Ty<'hir>, AnonConst),
2283+
Array(&'hir Ty<'hir>, ArrayLen),
22702284
/// A raw pointer (i.e., `*const T` or `*mut T`).
22712285
Ptr(MutTy<'hir>),
22722286
/// A reference (i.e., `&'a T` or `&'a mut T`).

compiler/rustc_hir/src/intravisit.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,9 @@ pub trait Visitor<'v>: Sized {
383383
fn visit_pat(&mut self, p: &'v Pat<'v>) {
384384
walk_pat(self, p)
385385
}
386+
fn visit_array_length(&mut self, len: &'v ArrayLen) {
387+
walk_array_len(self, len)
388+
}
386389
fn visit_anon_const(&mut self, c: &'v AnonConst) {
387390
walk_anon_const(self, c)
388391
}
@@ -753,7 +756,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v>) {
753756
}
754757
TyKind::Array(ref ty, ref length) => {
755758
visitor.visit_ty(ty);
756-
visitor.visit_anon_const(length)
759+
visitor.visit_array_length(length)
757760
}
758761
TyKind::TraitObject(bounds, ref lifetime, _syntax) => {
759762
for bound in bounds {
@@ -1124,6 +1127,13 @@ pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt<'v>) {
11241127
}
11251128
}
11261129

1130+
pub fn walk_array_len<'v, V: Visitor<'v>>(visitor: &mut V, len: &'v ArrayLen) {
1131+
match len {
1132+
&ArrayLen::Infer(hir_id, _span) => visitor.visit_id(hir_id),
1133+
ArrayLen::Body(c) => visitor.visit_anon_const(c),
1134+
}
1135+
}
1136+
11271137
pub fn walk_anon_const<'v, V: Visitor<'v>>(visitor: &mut V, constant: &'v AnonConst) {
11281138
visitor.visit_id(constant.hir_id);
11291139
visitor.visit_nested_body(constant.body);
@@ -1147,7 +1157,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr<'v>)
11471157
ExprKind::ConstBlock(ref anon_const) => visitor.visit_anon_const(anon_const),
11481158
ExprKind::Repeat(ref element, ref count) => {
11491159
visitor.visit_expr(element);
1150-
visitor.visit_anon_const(count)
1160+
visitor.visit_array_length(count)
11511161
}
11521162
ExprKind::Struct(ref qpath, fields, ref optional_base) => {
11531163
visitor.visit_qpath(qpath, expression.hir_id, expression.span);

compiler/rustc_hir_pretty/src/lib.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ impl<'a> State<'a> {
358358
self.word("[");
359359
self.print_type(&ty);
360360
self.word("; ");
361-
self.print_anon_const(length);
361+
self.print_array_length(length);
362362
self.word("]");
363363
}
364364
hir::TyKind::Typeof(ref e) => {
@@ -1065,6 +1065,13 @@ impl<'a> State<'a> {
10651065
self.print_else(elseopt)
10661066
}
10671067

1068+
pub fn print_array_length(&mut self, len: &hir::ArrayLen) {
1069+
match len {
1070+
hir::ArrayLen::Infer(_, _) => self.word("_"),
1071+
hir::ArrayLen::Body(ct) => self.print_anon_const(ct),
1072+
}
1073+
}
1074+
10681075
pub fn print_anon_const(&mut self, constant: &hir::AnonConst) {
10691076
self.ann.nested(self, Nested::Body(constant.body))
10701077
}
@@ -1140,12 +1147,12 @@ impl<'a> State<'a> {
11401147
self.end()
11411148
}
11421149

1143-
fn print_expr_repeat(&mut self, element: &hir::Expr<'_>, count: &hir::AnonConst) {
1150+
fn print_expr_repeat(&mut self, element: &hir::Expr<'_>, count: &hir::ArrayLen) {
11441151
self.ibox(INDENT_UNIT);
11451152
self.word("[");
11461153
self.print_expr(element);
11471154
self.word_space(";");
1148-
self.print_anon_const(count);
1155+
self.print_array_length(count);
11491156
self.word("]");
11501157
self.end()
11511158
}

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -979,11 +979,11 @@ LLVMRustDIBuilderGetOrCreateArray(LLVMRustDIBuilderRef Builder,
979979

980980
extern "C" LLVMValueRef LLVMRustDIBuilderInsertDeclareAtEnd(
981981
LLVMRustDIBuilderRef Builder, LLVMValueRef V, LLVMMetadataRef VarInfo,
982-
int64_t *AddrOps, unsigned AddrOpsCount, LLVMMetadataRef DL,
982+
uint64_t *AddrOps, unsigned AddrOpsCount, LLVMMetadataRef DL,
983983
LLVMBasicBlockRef InsertAtEnd) {
984984
return wrap(Builder->insertDeclare(
985985
unwrap(V), unwrap<DILocalVariable>(VarInfo),
986-
Builder->createExpression(llvm::ArrayRef<int64_t>(AddrOps, AddrOpsCount)),
986+
Builder->createExpression(llvm::ArrayRef<uint64_t>(AddrOps, AddrOpsCount)),
987987
DebugLoc(cast<MDNode>(unwrap(DL))),
988988
unwrap(InsertAtEnd)));
989989
}
@@ -1057,11 +1057,11 @@ LLVMRustDIBuilderCreateDebugLocation(unsigned Line, unsigned Column,
10571057
return wrap(Loc);
10581058
}
10591059

1060-
extern "C" int64_t LLVMRustDIBuilderCreateOpDeref() {
1060+
extern "C" uint64_t LLVMRustDIBuilderCreateOpDeref() {
10611061
return dwarf::DW_OP_deref;
10621062
}
10631063

1064-
extern "C" int64_t LLVMRustDIBuilderCreateOpPlusUconst() {
1064+
extern "C" uint64_t LLVMRustDIBuilderCreateOpPlusUconst() {
10651065
return dwarf::DW_OP_plus_uconst;
10661066
}
10671067

compiler/rustc_mir_build/src/thir/cx/expr.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -583,9 +583,12 @@ impl<'tcx> Cx<'tcx> {
583583
ExprKind::ConstBlock { value }
584584
}
585585
// Now comes the rote stuff:
586-
hir::ExprKind::Repeat(ref v, ref count) => {
587-
let count_def_id = self.tcx.hir().local_def_id(count.hir_id);
588-
let count = ty::Const::from_anon_const(self.tcx, count_def_id);
586+
hir::ExprKind::Repeat(ref v, _) => {
587+
let ty = self.typeck_results().expr_ty(expr);
588+
let count = match ty.kind() {
589+
ty::Array(_, ct) => ct,
590+
_ => span_bug!(expr.span, "unexpected repeat expr ty: {:?}", ty),
591+
};
589592

590593
ExprKind::Repeat { value: self.mirror_expr(v), count }
591594
}

compiler/rustc_mir_transform/src/const_prop.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
406406
Instance::new(def_id, substs),
407407
dummy_body,
408408
ret.as_ref(),
409-
StackPopCleanup::None { cleanup: false },
409+
StackPopCleanup::Root { cleanup: false },
410410
)
411411
.expect("failed to push initial stack frame");
412412

compiler/rustc_save_analysis/src/dump_visitor.rs

+20-8
Original file line numberDiff line numberDiff line change
@@ -1326,12 +1326,18 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
13261326
}
13271327
intravisit::walk_qpath(self, path, t.hir_id, t.span);
13281328
}
1329-
hir::TyKind::Array(ref ty, ref anon_const) => {
1329+
hir::TyKind::Array(ref ty, ref length) => {
13301330
self.visit_ty(ty);
13311331
let map = self.tcx.hir();
1332-
self.nest_typeck_results(self.tcx.hir().local_def_id(anon_const.hir_id), |v| {
1333-
v.visit_expr(&map.body(anon_const.body).value)
1334-
});
1332+
match length {
1333+
// FIXME(generic_arg_infer): We probably want to
1334+
// output the inferred type here? :shrug:
1335+
hir::ArrayLen::Infer(..) => {}
1336+
hir::ArrayLen::Body(anon_const) => self
1337+
.nest_typeck_results(self.tcx.hir().local_def_id(anon_const.hir_id), |v| {
1338+
v.visit_expr(&map.body(anon_const.body).value)
1339+
}),
1340+
}
13351341
}
13361342
hir::TyKind::OpaqueDef(item_id, _) => {
13371343
let item = self.tcx.hir().item(item_id);
@@ -1390,12 +1396,18 @@ impl<'tcx> Visitor<'tcx> for DumpVisitor<'tcx> {
13901396
v.visit_expr(&body.value)
13911397
});
13921398
}
1393-
hir::ExprKind::Repeat(ref expr, ref anon_const) => {
1399+
hir::ExprKind::Repeat(ref expr, ref length) => {
13941400
self.visit_expr(expr);
13951401
let map = self.tcx.hir();
1396-
self.nest_typeck_results(self.tcx.hir().local_def_id(anon_const.hir_id), |v| {
1397-
v.visit_expr(&map.body(anon_const.body).value)
1398-
});
1402+
match length {
1403+
// FIXME(generic_arg_infer): We probably want to
1404+
// output the inferred type here? :shrug:
1405+
hir::ArrayLen::Infer(..) => {}
1406+
hir::ArrayLen::Body(anon_const) => self
1407+
.nest_typeck_results(self.tcx.hir().local_def_id(anon_const.hir_id), |v| {
1408+
v.visit_expr(&map.body(anon_const.body).value)
1409+
}),
1410+
}
13991411
}
14001412
// In particular, we take this branch for call and path expressions,
14011413
// where we'll index the idents involved just by continuing to walk.

compiler/rustc_save_analysis/src/sig.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,9 @@ impl<'hir> Sig for hir::Ty<'hir> {
310310
let nested = bounds_to_string(&bounds);
311311
Ok(text_sig(nested))
312312
}
313-
hir::TyKind::Array(ref ty, ref anon_const) => {
313+
hir::TyKind::Array(ref ty, ref length) => {
314314
let nested_ty = ty.make(offset + 1, id, scx)?;
315-
let expr = id_to_string(&scx.tcx.hir(), anon_const.body.hir_id).replace('\n', " ");
315+
let expr = id_to_string(&scx.tcx.hir(), length.hir_id()).replace('\n', " ");
316316
let text = format!("[{}; {}]", nested_ty.text, expr);
317317
Ok(replace_text(nested_ty, text))
318318
}

compiler/rustc_typeck/src/astconv/generics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
104104
GenericArg::Type(hir::Ty { kind: hir::TyKind::Array(_, len), .. }),
105105
GenericParamDefKind::Const { .. },
106106
) if tcx.type_of(param.def_id) == tcx.types.usize => {
107-
let snippet = sess.source_map().span_to_snippet(tcx.hir().span(len.hir_id));
107+
let snippet = sess.source_map().span_to_snippet(tcx.hir().span(len.hir_id()));
108108
if let Ok(snippet) = snippet {
109109
err.span_suggestion(
110110
arg.span(),

0 commit comments

Comments
 (0)