Skip to content

Commit 83995f3

Browse files
committed
Auto merge of #115354 - matthiaskrgr:rollup-4cotcxz, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #111580 (Don't ICE on layout computation failure) - #114923 (doc: update lld-flavor ref) - #115174 (tests: add test for #67992) - #115187 (Add new interface to smir) - #115300 (Tweaks and improvements on SMIR around generics_of and predicates_of) - #115340 (some more is_zst that should be is_1zst) r? `@ghost` `@rustbot` modify labels: rollup
2 parents b2515fa + a644f37 commit 83995f3

File tree

21 files changed

+203
-117
lines changed

21 files changed

+203
-117
lines changed

Cargo.lock

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4335,8 +4335,11 @@ dependencies = [
43354335
name = "rustc_smir"
43364336
version = "0.0.0"
43374337
dependencies = [
4338+
"rustc_driver",
43384339
"rustc_hir",
4340+
"rustc_interface",
43394341
"rustc_middle",
4342+
"rustc_session",
43404343
"rustc_span",
43414344
"rustc_target",
43424345
"scoped-tls",

compiler/rustc_codegen_cranelift/src/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ impl<'tcx> LayoutOfHelpers<'tcx> for RevealAllLayoutCx<'tcx> {
480480
if let LayoutError::SizeOverflow(_) | LayoutError::ReferencesError(_) = err {
481481
self.0.sess.span_fatal(span, err.to_string())
482482
} else {
483-
span_bug!(span, "failed to get layout for `{}`: {}", ty, err)
483+
self.0.sess.span_fatal(span, format!("failed to get layout for `{}`: {}", ty, err))
484484
}
485485
}
486486
}

compiler/rustc_codegen_gcc/src/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_codegen_ssa::traits::{
77
BaseTypeMethods,
88
MiscMethods,
99
};
10+
use rustc_codegen_ssa::errors as ssa_errors;
1011
use rustc_data_structures::base_n;
1112
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1213
use rustc_middle::span_bug;
@@ -479,7 +480,7 @@ impl<'gcc, 'tcx> LayoutOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> {
479480
if let LayoutError::SizeOverflow(_) | LayoutError::ReferencesError(_) = err {
480481
self.sess().emit_fatal(respan(span, err.into_diagnostic()))
481482
} else {
482-
span_bug!(span, "failed to get layout for `{}`: {}", ty, err)
483+
self.tcx.sess.emit_fatal(ssa_errors::FailedToGetLayout { span, ty, err })
483484
}
484485
}
485486
}

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use crate::value::Value;
1010

1111
use cstr::cstr;
1212
use rustc_codegen_ssa::base::{wants_msvc_seh, wants_wasm_eh};
13+
use rustc_codegen_ssa::errors as ssa_errors;
1314
use rustc_codegen_ssa::traits::*;
1415
use rustc_data_structures::base_n;
1516
use rustc_data_structures::fx::FxHashMap;
@@ -1000,7 +1001,7 @@ impl<'tcx> LayoutOfHelpers<'tcx> for CodegenCx<'_, 'tcx> {
10001001
if let LayoutError::SizeOverflow(_) | LayoutError::ReferencesError(_) = err {
10011002
self.sess().emit_fatal(Spanned { span, node: err.into_diagnostic() })
10021003
} else {
1003-
span_bug!(span, "failed to get layout for `{ty}`: {err:?}")
1004+
self.tcx.sess.emit_fatal(ssa_errors::FailedToGetLayout { span, ty, err })
10041005
}
10051006
}
10061007
}

compiler/rustc_codegen_ssa/messages.ftl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ codegen_ssa_extract_bundled_libs_parse_archive = failed to parse archive '{$rlib
3535
codegen_ssa_extract_bundled_libs_read_entry = failed to read entry '{$rlib}': {$error}
3636
codegen_ssa_extract_bundled_libs_write_file = failed to write file '{$rlib}': {$error}
3737
38+
codegen_ssa_failed_to_get_layout = failed to get layout for {$ty}: {$err}
39+
3840
codegen_ssa_failed_to_write = failed to write {$path}: {$error}
3941
4042
codegen_ssa_ignoring_emit_path = ignoring emit path because multiple .{$extension} files were produced

compiler/rustc_codegen_ssa/src/errors.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_errors::{
77
IntoDiagnosticArg,
88
};
99
use rustc_macros::Diagnostic;
10+
use rustc_middle::ty::layout::LayoutError;
1011
use rustc_middle::ty::Ty;
1112
use rustc_span::{Span, Symbol};
1213
use rustc_type_ir::FloatTy;
@@ -1030,6 +1031,15 @@ pub struct TargetFeatureSafeTrait {
10301031
pub def: Span,
10311032
}
10321033

1034+
#[derive(Diagnostic)]
1035+
#[diag(codegen_ssa_failed_to_get_layout)]
1036+
pub struct FailedToGetLayout<'tcx> {
1037+
#[primary_span]
1038+
pub span: Span,
1039+
pub ty: Ty<'tcx>,
1040+
pub err: LayoutError<'tcx>,
1041+
}
1042+
10331043
#[derive(Diagnostic)]
10341044
#[diag(codegen_ssa_error_creating_remark_dir)]
10351045
pub struct ErrorCreatingRemarkDir {

compiler/rustc_hir_analysis/src/coherence/builtin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef
195195
let ty_b = field.ty(tcx, args_b);
196196

197197
if let Ok(layout) = tcx.layout_of(param_env.and(ty_a)) {
198-
if layout.is_zst() && layout.align.abi.bytes() == 1 {
199-
// ignore ZST fields with alignment of 1 byte
198+
if layout.is_1zst() {
199+
// ignore 1-ZST fields
200200
return false;
201201
}
202202
}

compiler/rustc_lint/src/types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ pub(crate) fn nonnull_optimization_guaranteed<'tcx>(
804804
tcx.has_attr(def.did(), sym::rustc_nonnull_optimization_guaranteed)
805805
}
806806

807-
/// `repr(transparent)` structs can have a single non-ZST field, this function returns that
807+
/// `repr(transparent)` structs can have a single non-1-ZST field, this function returns that
808808
/// field.
809809
pub fn transparent_newtype_field<'a, 'tcx>(
810810
tcx: TyCtxt<'tcx>,
@@ -813,8 +813,8 @@ pub fn transparent_newtype_field<'a, 'tcx>(
813813
let param_env = tcx.param_env(variant.def_id);
814814
variant.fields.iter().find(|field| {
815815
let field_ty = tcx.type_of(field.did).instantiate_identity();
816-
let is_zst = tcx.layout_of(param_env.and(field_ty)).is_ok_and(|layout| layout.is_zst());
817-
!is_zst
816+
let is_1zst = tcx.layout_of(param_env.and(field_ty)).is_ok_and(|layout| layout.is_1zst());
817+
!is_1zst
818818
})
819819
}
820820

compiler/rustc_middle/src/ty/layout.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use crate::query::TyCtxtAt;
44
use crate::ty::normalize_erasing_regions::NormalizationError;
55
use crate::ty::{self, ConstKind, ReprOptions, Ty, TyCtxt, TypeVisitableExt};
66
use rustc_error_messages::DiagnosticMessage;
7-
use rustc_errors::{DiagnosticBuilder, Handler, IntoDiagnostic};
7+
use rustc_errors::{
8+
DiagnosticArgValue, DiagnosticBuilder, Handler, IntoDiagnostic, IntoDiagnosticArg,
9+
};
810
use rustc_hir as hir;
911
use rustc_hir::def_id::DefId;
1012
use rustc_index::IndexVec;
@@ -265,6 +267,12 @@ impl<'tcx> fmt::Display for LayoutError<'tcx> {
265267
}
266268
}
267269

270+
impl<'tcx> IntoDiagnosticArg for LayoutError<'tcx> {
271+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
272+
self.to_string().into_diagnostic_arg()
273+
}
274+
}
275+
268276
#[derive(Clone, Copy)]
269277
pub struct LayoutCx<'tcx, C> {
270278
pub tcx: C,

compiler/rustc_smir/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ rustc_hir = { path = "../rustc_hir", optional = true }
99
rustc_middle = { path = "../rustc_middle", optional = true }
1010
rustc_span = { path = "../rustc_span", optional = true }
1111
rustc_target = { path = "../rustc_target", optional = true }
12+
rustc_driver = { path = "../rustc_driver", optional = true }
13+
rustc_interface = { path = "../rustc_interface", optional = true}
14+
rustc_session = {path = "../rustc_session", optional = true}
1215
tracing = "0.1"
1316
scoped-tls = "1.0"
1417

@@ -18,4 +21,7 @@ default = [
1821
"rustc_middle",
1922
"rustc_span",
2023
"rustc_target",
24+
"rustc_driver",
25+
"rustc_interface",
26+
"rustc_session",
2127
]

0 commit comments

Comments
 (0)