Skip to content

Commit 507055b

Browse files
committed
Auto merge of #2911 - RalfJung:rustup, r=RalfJung
Rustup
2 parents 47bf8e7 + be4e05a commit 507055b

File tree

307 files changed

+6772
-4342
lines changed

Some content is hidden

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

307 files changed

+6772
-4342
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,7 @@ jobs:
578578
actions: write
579579
name: "try - ${{ matrix.name }}"
580580
env:
581+
DIST_TRY_BUILD: 1
581582
CI_JOB_NAME: "${{ matrix.name }}"
582583
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
583584
SCCACHE_BUCKET: rust-lang-ci-sccache2

compiler/rustc_abi/src/lib.rs

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ pub enum TargetDataLayoutErrors<'a> {
209209
InvalidAddressSpace { addr_space: &'a str, cause: &'a str, err: ParseIntError },
210210
InvalidBits { kind: &'a str, bit: &'a str, cause: &'a str, err: ParseIntError },
211211
MissingAlignment { cause: &'a str },
212-
InvalidAlignment { cause: &'a str, err: String },
212+
InvalidAlignment { cause: &'a str, err: AlignFromBytesError },
213213
InconsistentTargetArchitecture { dl: &'a str, target: &'a str },
214214
InconsistentTargetPointerWidth { pointer_size: u64, target: u32 },
215215
InvalidBitsSize { err: String },
@@ -640,30 +640,65 @@ impl fmt::Debug for Align {
640640
}
641641
}
642642

643+
#[derive(Clone, Copy)]
644+
pub enum AlignFromBytesError {
645+
NotPowerOfTwo(u64),
646+
TooLarge(u64),
647+
}
648+
649+
impl AlignFromBytesError {
650+
pub fn diag_ident(self) -> &'static str {
651+
match self {
652+
Self::NotPowerOfTwo(_) => "not_power_of_two",
653+
Self::TooLarge(_) => "too_large",
654+
}
655+
}
656+
657+
pub fn align(self) -> u64 {
658+
let (Self::NotPowerOfTwo(align) | Self::TooLarge(align)) = self;
659+
align
660+
}
661+
}
662+
663+
impl fmt::Debug for AlignFromBytesError {
664+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
665+
fmt::Display::fmt(self, f)
666+
}
667+
}
668+
669+
impl fmt::Display for AlignFromBytesError {
670+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
671+
match self {
672+
AlignFromBytesError::NotPowerOfTwo(align) => write!(f, "`{align}` is not a power of 2"),
673+
AlignFromBytesError::TooLarge(align) => write!(f, "`{align}` is too large"),
674+
}
675+
}
676+
}
677+
643678
impl Align {
644679
pub const ONE: Align = Align { pow2: 0 };
645680
pub const MAX: Align = Align { pow2: 29 };
646681

647682
#[inline]
648-
pub fn from_bits(bits: u64) -> Result<Align, String> {
683+
pub fn from_bits(bits: u64) -> Result<Align, AlignFromBytesError> {
649684
Align::from_bytes(Size::from_bits(bits).bytes())
650685
}
651686

652687
#[inline]
653-
pub fn from_bytes(align: u64) -> Result<Align, String> {
688+
pub fn from_bytes(align: u64) -> Result<Align, AlignFromBytesError> {
654689
// Treat an alignment of 0 bytes like 1-byte alignment.
655690
if align == 0 {
656691
return Ok(Align::ONE);
657692
}
658693

659694
#[cold]
660-
fn not_power_of_2(align: u64) -> String {
661-
format!("`{}` is not a power of 2", align)
695+
fn not_power_of_2(align: u64) -> AlignFromBytesError {
696+
AlignFromBytesError::NotPowerOfTwo(align)
662697
}
663698

664699
#[cold]
665-
fn too_large(align: u64) -> String {
666-
format!("`{}` is too large", align)
700+
fn too_large(align: u64) -> AlignFromBytesError {
701+
AlignFromBytesError::TooLarge(align)
667702
}
668703

669704
let tz = align.trailing_zeros();

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,18 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
279279
// HACK This bubble is required for this tests to pass:
280280
// nested-return-type2-tait2.rs
281281
// nested-return-type2-tait3.rs
282-
let infcx =
283-
self.tcx.infer_ctxt().with_opaque_type_inference(DefiningAnchor::Bubble).build();
282+
// FIXME(-Ztrait-solver=next): We probably should use `DefiningAnchor::Error`
283+
// and prepopulate this `InferCtxt` with known opaque values, rather than
284+
// using the `Bind` anchor here. For now it's fine.
285+
let infcx = self
286+
.tcx
287+
.infer_ctxt()
288+
.with_opaque_type_inference(if self.tcx.trait_solver_next() {
289+
DefiningAnchor::Bind(def_id)
290+
} else {
291+
DefiningAnchor::Bubble
292+
})
293+
.build();
284294
let ocx = ObligationCtxt::new(&infcx);
285295
// Require the hidden type to be well-formed with only the generics of the opaque type.
286296
// Defining use functions may have more bounds than the opaque type, which is ok, as long as the

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,6 @@ pub(crate) fn type_check<'mir, 'tcx>(
188188

189189
// FIXME(-Ztrait-solver=next): A bit dubious that we're only registering
190190
// predefined opaques in the typeck root.
191-
// FIXME(-Ztrait-solver=next): This is also totally wrong for TAITs, since
192-
// the HIR typeck map defining usages back to their definition params,
193-
// they won't actually match up with the usages in this body...
194191
if infcx.tcx.trait_solver_next() && !infcx.tcx.is_typeck_child(body.source.def_id()) {
195192
checker.register_predefined_opaques_in_new_solver();
196193
}
@@ -1042,10 +1039,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
10421039
.typeck(self.body.source.def_id().expect_local())
10431040
.concrete_opaque_types
10441041
.iter()
1045-
.map(|(&def_id, &hidden_ty)| {
1046-
let substs = ty::InternalSubsts::identity_for_item(self.infcx.tcx, def_id);
1047-
(ty::OpaqueTypeKey { def_id, substs }, hidden_ty)
1048-
})
1042+
.map(|(k, v)| (*k, *v))
10491043
.collect();
10501044

10511045
let renumbered_opaques = self.infcx.tcx.fold_regions(opaques, |_, _| {

compiler/rustc_codegen_cranelift/src/common.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use rustc_index::IndexVec;
66
use rustc_middle::ty::layout::{
77
FnAbiError, FnAbiOfHelpers, FnAbiRequest, LayoutError, LayoutOfHelpers,
88
};
9+
use rustc_span::source_map::Spanned;
910
use rustc_span::SourceFile;
1011
use rustc_target::abi::call::FnAbi;
1112
use rustc_target::abi::{Integer, Primitive};
@@ -495,25 +496,16 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> {
495496
fn_abi_request: FnAbiRequest<'tcx>,
496497
) -> ! {
497498
if let FnAbiError::Layout(LayoutError::SizeOverflow(_)) = err {
498-
self.0.sess.span_fatal(span, err.to_string())
499+
self.0.sess.emit_fatal(Spanned { span, node: err })
499500
} else {
500501
match fn_abi_request {
501502
FnAbiRequest::OfFnPtr { sig, extra_args } => {
502-
span_bug!(
503-
span,
504-
"`fn_abi_of_fn_ptr({}, {:?})` failed: {}",
505-
sig,
506-
extra_args,
507-
err
508-
);
503+
span_bug!(span, "`fn_abi_of_fn_ptr({sig}, {extra_args:?})` failed: {err:?}");
509504
}
510505
FnAbiRequest::OfInstance { instance, extra_args } => {
511506
span_bug!(
512507
span,
513-
"`fn_abi_of_instance({}, {:?})` failed: {}",
514-
instance,
515-
extra_args,
516-
err
508+
"`fn_abi_of_instance({instance}, {extra_args:?})` failed: {err:?}"
517509
);
518510
}
519511
}

compiler/rustc_codegen_gcc/src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
758758
assert_eq!(place.llextra.is_some(), place.layout.is_unsized());
759759

760760
if place.layout.is_zst() {
761-
return OperandRef::new_zst(self, place.layout);
761+
return OperandRef::zero_sized(place.layout);
762762
}
763763

764764
fn scalar_load_metadata<'a, 'gcc, 'tcx>(bx: &mut Builder<'a, 'gcc, 'tcx>, load: RValue<'gcc>, scalar: &abi::Scalar) {

compiler/rustc_codegen_gcc/src/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn set_global_alignment<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, gv: LValue<'gcc>
2424
match Align::from_bits(min) {
2525
Ok(min) => align = align.max(min),
2626
Err(err) => {
27-
cx.sess().emit_err(InvalidMinimumAlignment { err });
27+
cx.sess().emit_err(InvalidMinimumAlignment { err: err.to_string() });
2828
}
2929
}
3030
}

compiler/rustc_codegen_gcc/src/context.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ impl<'gcc, 'tcx> LayoutOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> {
477477
#[inline]
478478
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
479479
if let LayoutError::SizeOverflow(_) = err {
480-
self.sess().emit_fatal(respan(span, err))
480+
self.sess().emit_fatal(respan(span, err.into_diagnostic()))
481481
} else {
482482
span_bug!(span, "failed to get layout for `{}`: {}", ty, err)
483483
}
@@ -499,21 +499,12 @@ impl<'gcc, 'tcx> FnAbiOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> {
499499
} else {
500500
match fn_abi_request {
501501
FnAbiRequest::OfFnPtr { sig, extra_args } => {
502-
span_bug!(
503-
span,
504-
"`fn_abi_of_fn_ptr({}, {:?})` failed: {}",
505-
sig,
506-
extra_args,
507-
err
508-
);
502+
span_bug!(span, "`fn_abi_of_fn_ptr({sig}, {extra_args:?})` failed: {err:?}");
509503
}
510504
FnAbiRequest::OfInstance { instance, extra_args } => {
511505
span_bug!(
512506
span,
513-
"`fn_abi_of_instance({}, {:?})` failed: {}",
514-
instance,
515-
extra_args,
516-
err
507+
"`fn_abi_of_instance({instance}, {extra_args:?})` failed: {err:?}"
517508
);
518509
}
519510
}

compiler/rustc_codegen_gcc/src/type_of.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
159159
fn is_gcc_immediate(&self) -> bool {
160160
match self.abi {
161161
Abi::Scalar(_) | Abi::Vector { .. } => true,
162-
Abi::ScalarPair(..) => false,
163-
Abi::Uninhabited | Abi::Aggregate { .. } => self.is_zst(),
162+
Abi::ScalarPair(..) | Abi::Uninhabited | Abi::Aggregate { .. } => false,
164163
}
165164
}
166165

compiler/rustc_codegen_llvm/messages.ftl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ codegen_llvm_error_writing_def_file =
2020
codegen_llvm_from_llvm_diag = {$message}
2121
2222
codegen_llvm_from_llvm_optimization_diag = {$filename}:{$line}:{$column} {$pass_name} ({$kind}): {$message}
23-
codegen_llvm_invalid_minimum_alignment =
24-
invalid minimum global alignment: {$err}
23+
24+
codegen_llvm_invalid_minimum_alignment_not_power_of_two =
25+
invalid minimum global alignment: {$align} is not power of 2
26+
27+
codegen_llvm_invalid_minimum_alignment_too_large =
28+
invalid minimum global alignment: {$align} is too large
2529
2630
codegen_llvm_load_bitcode = failed to load bitcode of module "{$name}"
2731
codegen_llvm_load_bitcode_with_llvm_err = failed to load bitcode of module "{$name}": {$llvm_err}

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
486486
assert_eq!(place.llextra.is_some(), place.layout.is_unsized());
487487

488488
if place.layout.is_zst() {
489-
return OperandRef::new_zst(self, place.layout);
489+
return OperandRef::zero_sized(place.layout);
490490
}
491491

492492
#[instrument(level = "trace", skip(bx))]

compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use crate::base;
22
use crate::common::{self, CodegenCx};
33
use crate::debuginfo;
4-
use crate::errors::{InvalidMinimumAlignment, SymbolAlreadyDefined};
4+
use crate::errors::{
5+
InvalidMinimumAlignmentNotPowerOfTwo, InvalidMinimumAlignmentTooLarge, SymbolAlreadyDefined,
6+
};
57
use crate::llvm::{self, True};
68
use crate::type_::Type;
79
use crate::type_of::LayoutLlvmExt;
@@ -19,7 +21,9 @@ use rustc_middle::ty::layout::LayoutOf;
1921
use rustc_middle::ty::{self, Instance, Ty};
2022
use rustc_middle::{bug, span_bug};
2123
use rustc_session::config::Lto;
22-
use rustc_target::abi::{Align, HasDataLayout, Primitive, Scalar, Size, WrappingRange};
24+
use rustc_target::abi::{
25+
Align, AlignFromBytesError, HasDataLayout, Primitive, Scalar, Size, WrappingRange,
26+
};
2327
use std::ops::Range;
2428

2529
pub fn const_alloc_to_llvm<'ll>(cx: &CodegenCx<'ll, '_>, alloc: ConstAllocation<'_>) -> &'ll Value {
@@ -129,9 +133,14 @@ fn set_global_alignment<'ll>(cx: &CodegenCx<'ll, '_>, gv: &'ll Value, mut align:
129133
if let Some(min) = cx.sess().target.min_global_align {
130134
match Align::from_bits(min) {
131135
Ok(min) => align = align.max(min),
132-
Err(err) => {
133-
cx.sess().emit_err(InvalidMinimumAlignment { err });
134-
}
136+
Err(err) => match err {
137+
AlignFromBytesError::NotPowerOfTwo(align) => {
138+
cx.sess().emit_err(InvalidMinimumAlignmentNotPowerOfTwo { align });
139+
}
140+
AlignFromBytesError::TooLarge(align) => {
141+
cx.sess().emit_err(InvalidMinimumAlignmentTooLarge { align });
142+
}
143+
},
135144
}
136145
}
137146
unsafe {

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -969,9 +969,9 @@ impl<'tcx> LayoutOfHelpers<'tcx> for CodegenCx<'_, 'tcx> {
969969
#[inline]
970970
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
971971
if let LayoutError::SizeOverflow(_) = err {
972-
self.sess().emit_fatal(Spanned { span, node: err })
972+
self.sess().emit_fatal(Spanned { span, node: err.into_diagnostic() })
973973
} else {
974-
span_bug!(span, "failed to get layout for `{}`: {}", ty, err)
974+
span_bug!(span, "failed to get layout for `{ty}`: {err:?}")
975975
}
976976
}
977977
}
@@ -991,21 +991,12 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for CodegenCx<'_, 'tcx> {
991991
} else {
992992
match fn_abi_request {
993993
FnAbiRequest::OfFnPtr { sig, extra_args } => {
994-
span_bug!(
995-
span,
996-
"`fn_abi_of_fn_ptr({}, {:?})` failed: {}",
997-
sig,
998-
extra_args,
999-
err
1000-
);
994+
span_bug!(span, "`fn_abi_of_fn_ptr({sig}, {extra_args:?})` failed: {err:?}",);
1001995
}
1002996
FnAbiRequest::OfInstance { instance, extra_args } => {
1003997
span_bug!(
1004998
span,
1005-
"`fn_abi_of_instance({}, {:?})` failed: {}",
1006-
instance,
1007-
extra_args,
1008-
err
999+
"`fn_abi_of_instance({instance}, {extra_args:?})` failed: {err:?}",
10091000
);
10101001
}
10111002
}

compiler/rustc_codegen_llvm/src/errors.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,15 @@ pub(crate) struct SymbolAlreadyDefined<'a> {
5050
}
5151

5252
#[derive(Diagnostic)]
53-
#[diag(codegen_llvm_invalid_minimum_alignment)]
54-
pub(crate) struct InvalidMinimumAlignment {
55-
pub err: String,
53+
#[diag(codegen_llvm_invalid_minimum_alignment_not_power_of_two)]
54+
pub(crate) struct InvalidMinimumAlignmentNotPowerOfTwo {
55+
pub align: u64,
56+
}
57+
58+
#[derive(Diagnostic)]
59+
#[diag(codegen_llvm_invalid_minimum_alignment_too_large)]
60+
pub(crate) struct InvalidMinimumAlignmentTooLarge {
61+
pub align: u64,
5662
}
5763

5864
#[derive(Diagnostic)]

compiler/rustc_codegen_llvm/src/type_of.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
198198
fn is_llvm_immediate(&self) -> bool {
199199
match self.abi {
200200
Abi::Scalar(_) | Abi::Vector { .. } => true,
201-
Abi::ScalarPair(..) => false,
202-
Abi::Uninhabited | Abi::Aggregate { .. } => self.is_zst(),
201+
Abi::ScalarPair(..) | Abi::Uninhabited | Abi::Aggregate { .. } => false,
203202
}
204203
}
205204

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ pub fn coerce_unsized_into<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
295295
let (base, info) = match bx.load_operand(src).val {
296296
OperandValue::Pair(base, info) => unsize_ptr(bx, base, src_ty, dst_ty, Some(info)),
297297
OperandValue::Immediate(base) => unsize_ptr(bx, base, src_ty, dst_ty, None),
298-
OperandValue::Ref(..) => bug!(),
298+
OperandValue::Ref(..) | OperandValue::ZeroSized => bug!(),
299299
};
300300
OperandValue::Pair(base, info).store(bx, dst);
301301
}

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ fn push_debuginfo_type_name<'tcx>(
9393
Err(e) => {
9494
// Computing the layout can still fail here, e.g. if the target architecture
9595
// cannot represent the type. See https://github.com/rust-lang/rust/issues/94961.
96-
// FIXME: migrate once `rustc_middle::mir::interpret::InterpError` is translatable.
97-
tcx.sess.fatal(format!("{}", e));
96+
tcx.sess.emit_fatal(e.into_diagnostic());
9897
}
9998
}
10099
} else {

0 commit comments

Comments
 (0)