Skip to content

Commit ce33ca0

Browse files
committed
Auto merge of #3074 - rust-lang:rustup-2023-09-22, r=RalfJung
Automatic sync from rustc
2 parents aea1eff + 896065f commit ce33ca0

File tree

255 files changed

+3176
-2191
lines changed

Some content is hidden

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

255 files changed

+3176
-2191
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13081308

13091309
fn lower_asyncness(&mut self, a: Async) -> hir::IsAsync {
13101310
match a {
1311-
Async::Yes { .. } => hir::IsAsync::Async,
1311+
Async::Yes { span, .. } => hir::IsAsync::Async(span),
13121312
Async::No => hir::IsAsync::NotAsync,
13131313
}
13141314
}

compiler/rustc_borrowck/src/diagnostics/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_index::IndexSlice;
1313
use rustc_infer::infer::LateBoundRegionConversionTime;
1414
use rustc_middle::mir::tcx::PlaceTy;
1515
use rustc_middle::mir::{
16-
AggregateKind, CallSource, Constant, FakeReadCause, Local, LocalInfo, LocalKind, Location,
16+
AggregateKind, CallSource, ConstOperand, FakeReadCause, Local, LocalInfo, LocalKind, Location,
1717
Operand, Place, PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Terminator,
1818
TerminatorKind,
1919
};
@@ -101,12 +101,12 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
101101
let terminator = self.body[location.block].terminator();
102102
debug!("add_moved_or_invoked_closure_note: terminator={:?}", terminator);
103103
if let TerminatorKind::Call {
104-
func: Operand::Constant(box Constant { literal, .. }),
104+
func: Operand::Constant(box ConstOperand { const_, .. }),
105105
args,
106106
..
107107
} = &terminator.kind
108108
{
109-
if let ty::FnDef(id, _) = *literal.ty().kind() {
109+
if let ty::FnDef(id, _) = *const_.ty().kind() {
110110
debug!("add_moved_or_invoked_closure_note: id={:?}", id);
111111
if Some(self.infcx.tcx.parent(id)) == self.infcx.tcx.lang_items().fn_once_trait() {
112112
let closure = match args.first() {

compiler/rustc_borrowck/src/diagnostics/region_name.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
302302
if free_region.bound_region.is_named() {
303303
// A named region that is actually named.
304304
Some(RegionName { name, source: RegionNameSource::NamedFreeRegion(span) })
305-
} else if let hir::IsAsync::Async = tcx.asyncness(self.mir_hir_id().owner) {
305+
} else if tcx.asyncness(self.mir_hir_id().owner).is_async() {
306306
// If we spuriously thought that the region is named, we should let the
307307
// system generate a true name for error messages. Currently this can
308308
// happen if we have an elided name in an async fn for example: the

compiler/rustc_borrowck/src/renumber.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ use crate::BorrowckInferCtxt;
44
use rustc_index::IndexSlice;
55
use rustc_infer::infer::NllRegionVariableOrigin;
66
use rustc_middle::mir::visit::{MutVisitor, TyContext};
7-
use rustc_middle::mir::Constant;
8-
use rustc_middle::mir::{Body, Location, Promoted};
7+
use rustc_middle::mir::{Body, ConstOperand, Location, Promoted};
98
use rustc_middle::ty::GenericArgsRef;
109
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
1110
use rustc_span::{Span, Symbol};
@@ -117,9 +116,9 @@ impl<'a, 'tcx> MutVisitor<'tcx> for RegionRenumberer<'a, 'tcx> {
117116
}
118117

119118
#[instrument(skip(self), level = "debug")]
120-
fn visit_constant(&mut self, constant: &mut Constant<'tcx>, location: Location) {
121-
let literal = constant.literal;
122-
constant.literal = self.renumber_regions(literal, || RegionCtxt::Location(location));
119+
fn visit_constant(&mut self, constant: &mut ConstOperand<'tcx>, location: Location) {
120+
let const_ = constant.const_;
121+
constant.const_ = self.renumber_regions(const_, || RegionCtxt::Location(location));
123122
debug!("constant: {:#?}", constant);
124123
}
125124
}

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,11 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
302302
self.sanitize_place(place, location, context);
303303
}
304304

305-
fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) {
305+
fn visit_constant(&mut self, constant: &ConstOperand<'tcx>, location: Location) {
306306
debug!(?constant, ?location, "visit_constant");
307307

308308
self.super_constant(constant, location);
309-
let ty = self.sanitize_type(constant, constant.literal.ty());
309+
let ty = self.sanitize_type(constant, constant.const_.ty());
310310

311311
self.cx.infcx.tcx.for_each_free_region(&ty, |live_region| {
312312
let live_region_vid =
@@ -328,7 +328,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
328328

329329
if let Some(annotation_index) = constant.user_ty {
330330
if let Err(terr) = self.cx.relate_type_and_user_type(
331-
constant.literal.ty(),
331+
constant.const_.ty(),
332332
ty::Variance::Invariant,
333333
&UserTypeProjection { base: annotation_index, projs: vec![] },
334334
locations,
@@ -340,20 +340,20 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
340340
constant,
341341
"bad constant user type {:?} vs {:?}: {:?}",
342342
annotation,
343-
constant.literal.ty(),
343+
constant.const_.ty(),
344344
terr,
345345
);
346346
}
347347
} else {
348348
let tcx = self.tcx();
349-
let maybe_uneval = match constant.literal {
350-
ConstantKind::Ty(ct) => match ct.kind() {
349+
let maybe_uneval = match constant.const_ {
350+
Const::Ty(ct) => match ct.kind() {
351351
ty::ConstKind::Unevaluated(_) => {
352-
bug!("should not encounter unevaluated ConstantKind::Ty here, got {:?}", ct)
352+
bug!("should not encounter unevaluated Const::Ty here, got {:?}", ct)
353353
}
354354
_ => None,
355355
},
356-
ConstantKind::Unevaluated(uv, _) => Some(uv),
356+
Const::Unevaluated(uv, _) => Some(uv),
357357
_ => None,
358358
};
359359

@@ -384,15 +384,15 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
384384
check_err(self, promoted_body, ty, promoted_ty);
385385
} else {
386386
self.cx.ascribe_user_type(
387-
constant.literal.ty(),
387+
constant.const_.ty(),
388388
UserType::TypeOf(uv.def, UserArgs { args: uv.args, user_self_ty: None }),
389389
locations.span(&self.cx.body),
390390
);
391391
}
392392
} else if let Some(static_def_id) = constant.check_static_ptr(tcx) {
393393
let unnormalized_ty = tcx.type_of(static_def_id).instantiate_identity();
394394
let normalized_ty = self.cx.normalize(unnormalized_ty, locations);
395-
let literal_ty = constant.literal.ty().builtin_deref(true).unwrap().ty;
395+
let literal_ty = constant.const_.ty().builtin_deref(true).unwrap().ty;
396396

397397
if let Err(terr) = self.cx.eq_types(
398398
literal_ty,
@@ -404,7 +404,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
404404
}
405405
}
406406

407-
if let ty::FnDef(def_id, args) = *constant.literal.ty().kind() {
407+
if let ty::FnDef(def_id, args) = *constant.const_.ty().kind() {
408408
let instantiated_predicates = tcx.predicates_of(def_id).instantiate(tcx, args);
409409
self.cx.normalize_and_prove_instantiated_predicates(
410410
def_id,
@@ -1801,9 +1801,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
18011801
debug!(?op, ?location, "check_operand");
18021802

18031803
if let Operand::Constant(constant) = op {
1804-
let maybe_uneval = match constant.literal {
1805-
ConstantKind::Val(..) | ConstantKind::Ty(_) => None,
1806-
ConstantKind::Unevaluated(uv, _) => Some(uv),
1804+
let maybe_uneval = match constant.const_ {
1805+
Const::Val(..) | Const::Ty(_) => None,
1806+
Const::Unevaluated(uv, _) => Some(uv),
18071807
};
18081808

18091809
if let Some(uv) = maybe_uneval {

compiler/rustc_borrowck/src/universal_regions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
580580
}
581581
}
582582

583-
BodyOwnerKind::Const | BodyOwnerKind::Static(..) => {
583+
BodyOwnerKind::Const { .. } | BodyOwnerKind::Static(..) => {
584584
let identity_args = GenericArgs::identity_for_item(tcx, typeck_root_def_id);
585585
if self.mir_def.to_def_id() == typeck_root_def_id {
586586
let args =

compiler/rustc_codegen_cranelift/src/constant.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ pub(crate) fn codegen_tls_ref<'tcx>(
6464

6565
pub(crate) fn eval_mir_constant<'tcx>(
6666
fx: &FunctionCx<'_, '_, 'tcx>,
67-
constant: &Constant<'tcx>,
67+
constant: &ConstOperand<'tcx>,
6868
) -> (ConstValue<'tcx>, Ty<'tcx>) {
69-
let cv = fx.monomorphize(constant.literal);
69+
let cv = fx.monomorphize(constant.const_);
7070
// This cannot fail because we checked all required_consts in advance.
7171
let val = cv
7272
.eval(fx.tcx, ty::ParamEnv::reveal_all(), Some(constant.span))
@@ -76,7 +76,7 @@ pub(crate) fn eval_mir_constant<'tcx>(
7676

7777
pub(crate) fn codegen_constant_operand<'tcx>(
7878
fx: &mut FunctionCx<'_, '_, 'tcx>,
79-
constant: &Constant<'tcx>,
79+
constant: &ConstOperand<'tcx>,
8080
) -> CValue<'tcx> {
8181
let (const_val, ty) = eval_mir_constant(fx, constant);
8282
codegen_const_value(fx, const_val, ty)

compiler/rustc_codegen_cranelift/src/inline_asm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ pub(crate) fn codegen_inline_asm<'tcx>(
252252
CInlineAsmOperand::Const { value }
253253
}
254254
InlineAsmOperand::SymFn { ref value } => {
255-
let literal = fx.monomorphize(value.literal);
256-
if let ty::FnDef(def_id, args) = *literal.ty().kind() {
255+
let const_ = fx.monomorphize(value.const_);
256+
if let ty::FnDef(def_id, args) = *const_.ty().kind() {
257257
let instance = ty::Instance::resolve_for_fn_ptr(
258258
fx.tcx,
259259
ty::ParamEnv::reveal_all(),

compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_middle::mir::coverage::{CounterId, MappedExpressionIndex};
1+
use rustc_middle::mir::coverage::{CounterId, ExpressionId, Operand};
22

33
/// Must match the layout of `LLVMRustCounterKind`.
44
#[derive(Copy, Clone, Debug)]
@@ -30,32 +30,25 @@ pub struct Counter {
3030
}
3131

3232
impl Counter {
33-
/// Constructs a new `Counter` of kind `Zero`. For this `CounterKind`, the
34-
/// `id` is not used.
35-
pub fn zero() -> Self {
36-
Self { kind: CounterKind::Zero, id: 0 }
37-
}
33+
/// A `Counter` of kind `Zero`. For this counter kind, the `id` is not used.
34+
pub(crate) const ZERO: Self = Self { kind: CounterKind::Zero, id: 0 };
3835

3936
/// Constructs a new `Counter` of kind `CounterValueReference`.
4037
pub fn counter_value_reference(counter_id: CounterId) -> Self {
4138
Self { kind: CounterKind::CounterValueReference, id: counter_id.as_u32() }
4239
}
4340

4441
/// Constructs a new `Counter` of kind `Expression`.
45-
pub fn expression(mapped_expression_index: MappedExpressionIndex) -> Self {
46-
Self { kind: CounterKind::Expression, id: mapped_expression_index.into() }
47-
}
48-
49-
/// Returns true if the `Counter` kind is `Zero`.
50-
pub fn is_zero(&self) -> bool {
51-
matches!(self.kind, CounterKind::Zero)
42+
pub(crate) fn expression(expression_id: ExpressionId) -> Self {
43+
Self { kind: CounterKind::Expression, id: expression_id.as_u32() }
5244
}
5345

54-
/// An explicitly-named function to get the ID value, making it more obvious
55-
/// that the stored value is now 0-based.
56-
pub fn zero_based_id(&self) -> u32 {
57-
debug_assert!(!self.is_zero(), "`id` is undefined for CounterKind::Zero");
58-
self.id
46+
pub(crate) fn from_operand(operand: Operand) -> Self {
47+
match operand {
48+
Operand::Zero => Self::ZERO,
49+
Operand::Counter(id) => Self::counter_value_reference(id),
50+
Operand::Expression(id) => Self::expression(id),
51+
}
5952
}
6053
}
6154

@@ -81,6 +74,11 @@ pub struct CounterExpression {
8174
}
8275

8376
impl CounterExpression {
77+
/// The dummy expression `(0 - 0)` has a representation of all zeroes,
78+
/// making it marginally more efficient to initialize than `(0 + 0)`.
79+
pub(crate) const DUMMY: Self =
80+
Self { lhs: Counter::ZERO, kind: ExprKind::Subtract, rhs: Counter::ZERO };
81+
8482
pub fn new(lhs: Counter, kind: ExprKind, rhs: Counter) -> Self {
8583
Self { kind, lhs, rhs }
8684
}
@@ -172,7 +170,7 @@ impl CounterMappingRegion {
172170
) -> Self {
173171
Self {
174172
counter,
175-
false_counter: Counter::zero(),
173+
false_counter: Counter::ZERO,
176174
file_id,
177175
expanded_file_id: 0,
178176
start_line,
@@ -220,8 +218,8 @@ impl CounterMappingRegion {
220218
end_col: u32,
221219
) -> Self {
222220
Self {
223-
counter: Counter::zero(),
224-
false_counter: Counter::zero(),
221+
counter: Counter::ZERO,
222+
false_counter: Counter::ZERO,
225223
file_id,
226224
expanded_file_id,
227225
start_line,
@@ -243,8 +241,8 @@ impl CounterMappingRegion {
243241
end_col: u32,
244242
) -> Self {
245243
Self {
246-
counter: Counter::zero(),
247-
false_counter: Counter::zero(),
244+
counter: Counter::ZERO,
245+
false_counter: Counter::ZERO,
248246
file_id,
249247
expanded_file_id: 0,
250248
start_line,
@@ -268,7 +266,7 @@ impl CounterMappingRegion {
268266
) -> Self {
269267
Self {
270268
counter,
271-
false_counter: Counter::zero(),
269+
false_counter: Counter::ZERO,
272270
file_id,
273271
expanded_file_id: 0,
274272
start_line,

0 commit comments

Comments
 (0)