Skip to content

Commit f914b82

Browse files
committed
Auto merge of rust-lang#102509 - matthiaskrgr:rollup-gtenet8, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#101075 (Migrate rustc_codegen_gcc to SessionDiagnostics ) - rust-lang#102350 (Improve errors for incomplete functions in struct definitions) - rust-lang#102481 (rustdoc: remove unneeded CSS `.rust-example-rendered { position }`) - rust-lang#102491 (rustdoc: remove no-op source sidebar `opacity`) - rust-lang#102499 (Adjust the s390x data layout for LLVM 16) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4a0ee3c + 588a25a commit f914b82

File tree

22 files changed

+482
-205
lines changed

22 files changed

+482
-205
lines changed

Diff for: compiler/rustc_codegen_gcc/src/archive.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use std::fs::File;
22
use std::path::{Path, PathBuf};
33

4+
use crate::errors::RanlibFailure;
5+
46
use rustc_codegen_ssa::back::archive::{ArchiveBuilder, ArchiveBuilderBuilder};
57
use rustc_session::Session;
68

@@ -181,7 +183,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> {
181183
std::process::Command::new("ranlib").arg(output).status().expect("Couldn't run ranlib");
182184

183185
if !status.success() {
184-
self.config.sess.fatal(&format!("Ranlib exited with code {:?}", status.code()));
186+
self.config.sess.emit_fatal(RanlibFailure::new(status.code()));
185187
}
186188

187189
any_members

Diff for: compiler/rustc_codegen_gcc/src/asm.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::borrow::Cow;
1212

1313
use crate::builder::Builder;
1414
use crate::context::CodegenCx;
15+
use crate::errors::UnwindingInlineAsm;
1516
use crate::type_of::LayoutGccExt;
1617
use crate::callee::get_fn;
1718

@@ -109,7 +110,7 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
109110
fn codegen_inline_asm(&mut self, template: &[InlineAsmTemplatePiece], rust_operands: &[InlineAsmOperandRef<'tcx, Self>], options: InlineAsmOptions, span: &[Span], _instance: Instance<'_>, _dest_catch_funclet: Option<(Self::BasicBlock, Self::BasicBlock, Option<&Self::Funclet>)>) {
110111
if options.contains(InlineAsmOptions::MAY_UNWIND) {
111112
self.sess()
112-
.struct_span_err(span[0], "GCC backend does not support unwinding from inline asm")
113+
.create_err(UnwindingInlineAsm { span: span[0] })
113114
.emit();
114115
return;
115116
}

Diff for: compiler/rustc_codegen_gcc/src/consts.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_target::abi::{self, Align, HasDataLayout, Primitive, Size, WrappingRan
1414

1515
use crate::base;
1616
use crate::context::CodegenCx;
17+
use crate::errors::LinkageConstOrMutType;
1718
use crate::type_of::LayoutGccExt;
1819

1920
impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
@@ -368,10 +369,7 @@ fn check_and_apply_linkage<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, attrs: &Codeg
368369
cx.layout_of(mt.ty).gcc_type(cx, true)
369370
}
370371
else {
371-
cx.sess().span_fatal(
372-
span,
373-
"must have type `*const T` or `*mut T` due to `#[linkage]` attribute",
374-
)
372+
cx.sess().emit_fatal(LinkageConstOrMutType { span: span })
375373
};
376374
// Declare a symbol `foo` with the desired linkage.
377375
let global1 = cx.declare_global_with_linkage(&sym, llty2, base::global_linkage_to_gcc(linkage));

Diff for: compiler/rustc_codegen_gcc/src/context.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::mir::mono::CodegenUnit;
1313
use rustc_middle::ty::{self, Instance, ParamEnv, PolyExistentialTraitRef, Ty, TyCtxt};
1414
use rustc_middle::ty::layout::{FnAbiError, FnAbiOfHelpers, FnAbiRequest, HasParamEnv, HasTyCtxt, LayoutError, TyAndLayout, LayoutOfHelpers};
1515
use rustc_session::Session;
16-
use rustc_span::Span;
16+
use rustc_span::{Span, source_map::respan};
1717
use rustc_target::abi::{call::FnAbi, HasDataLayout, PointeeInfo, Size, TargetDataLayout, VariantIdx};
1818
use rustc_target::spec::{HasTargetSpec, Target, TlsModel};
1919

@@ -293,7 +293,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
293293
self.is_native_int_type(typ) || self.is_non_native_int_type(typ) || typ.is_compatible_with(self.bool_type)
294294
}
295295

296-
pub fn sess(&self) -> &Session {
296+
pub fn sess(&self) -> &'tcx Session {
297297
&self.tcx.sess
298298
}
299299

@@ -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().span_fatal(span, &err.to_string())
480+
self.sess().emit_fatal(respan(span, err))
481481
} else {
482482
span_bug!(span, "failed to get layout for `{}`: {}", ty, err)
483483
}
@@ -495,7 +495,7 @@ impl<'gcc, 'tcx> FnAbiOfHelpers<'tcx> for CodegenCx<'gcc, 'tcx> {
495495
fn_abi_request: FnAbiRequest<'tcx>,
496496
) -> ! {
497497
if let FnAbiError::Layout(LayoutError::SizeOverflow(_)) = err {
498-
self.sess().span_fatal(span, &err.to_string())
498+
self.sess().emit_fatal(respan(span, err))
499499
} else {
500500
match fn_abi_request {
501501
FnAbiRequest::OfFnPtr { sig, extra_args } => {

Diff for: compiler/rustc_codegen_gcc/src/errors.rs

+242
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
use rustc_errors::{DiagnosticArgValue, IntoDiagnosticArg};
2+
use rustc_macros::Diagnostic;
3+
use rustc_middle::ty::Ty;
4+
use rustc_span::{Span, Symbol};
5+
use std::borrow::Cow;
6+
7+
struct ExitCode(Option<i32>);
8+
9+
impl IntoDiagnosticArg for ExitCode {
10+
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
11+
let ExitCode(exit_code) = self;
12+
match exit_code {
13+
Some(t) => t.into_diagnostic_arg(),
14+
None => DiagnosticArgValue::Str(Cow::Borrowed("<signal>")),
15+
}
16+
}
17+
}
18+
19+
#[derive(Diagnostic)]
20+
#[diag(codegen_gcc::ranlib_failure)]
21+
pub(crate) struct RanlibFailure {
22+
exit_code: ExitCode,
23+
}
24+
25+
impl RanlibFailure {
26+
pub fn new(exit_code: Option<i32>) -> Self {
27+
RanlibFailure { exit_code: ExitCode(exit_code) }
28+
}
29+
}
30+
31+
#[derive(Diagnostic)]
32+
#[diag(codegen_gcc::invalid_monomorphization_basic_integer, code = "E0511")]
33+
pub(crate) struct InvalidMonomorphizationBasicInteger<'a> {
34+
#[primary_span]
35+
pub span: Span,
36+
pub name: Symbol,
37+
pub ty: Ty<'a>,
38+
}
39+
40+
#[derive(Diagnostic)]
41+
#[diag(codegen_gcc::invalid_monomorphization_invalid_float_vector, code = "E0511")]
42+
pub(crate) struct InvalidMonomorphizationInvalidFloatVector<'a> {
43+
#[primary_span]
44+
pub span: Span,
45+
pub name: Symbol,
46+
pub elem_ty: &'a str,
47+
pub vec_ty: Ty<'a>,
48+
}
49+
50+
#[derive(Diagnostic)]
51+
#[diag(codegen_gcc::invalid_monomorphization_not_float, code = "E0511")]
52+
pub(crate) struct InvalidMonomorphizationNotFloat<'a> {
53+
#[primary_span]
54+
pub span: Span,
55+
pub name: Symbol,
56+
pub ty: Ty<'a>,
57+
}
58+
59+
#[derive(Diagnostic)]
60+
#[diag(codegen_gcc::invalid_monomorphization_unrecognized, code = "E0511")]
61+
pub(crate) struct InvalidMonomorphizationUnrecognized {
62+
#[primary_span]
63+
pub span: Span,
64+
pub name: Symbol,
65+
}
66+
67+
#[derive(Diagnostic)]
68+
#[diag(codegen_gcc::invalid_monomorphization_expected_signed_unsigned, code = "E0511")]
69+
pub(crate) struct InvalidMonomorphizationExpectedSignedUnsigned<'a> {
70+
#[primary_span]
71+
pub span: Span,
72+
pub name: Symbol,
73+
pub elem_ty: Ty<'a>,
74+
pub vec_ty: Ty<'a>,
75+
}
76+
77+
#[derive(Diagnostic)]
78+
#[diag(codegen_gcc::invalid_monomorphization_unsupported_element, code = "E0511")]
79+
pub(crate) struct InvalidMonomorphizationUnsupportedElement<'a> {
80+
#[primary_span]
81+
pub span: Span,
82+
pub name: Symbol,
83+
pub in_ty: Ty<'a>,
84+
pub elem_ty: Ty<'a>,
85+
pub ret_ty: Ty<'a>,
86+
}
87+
88+
#[derive(Diagnostic)]
89+
#[diag(codegen_gcc::invalid_monomorphization_invalid_bitmask, code = "E0511")]
90+
pub(crate) struct InvalidMonomorphizationInvalidBitmask<'a> {
91+
#[primary_span]
92+
pub span: Span,
93+
pub name: Symbol,
94+
pub ty: Ty<'a>,
95+
pub expected_int_bits: u64,
96+
pub expected_bytes: u64,
97+
}
98+
99+
#[derive(Diagnostic)]
100+
#[diag(codegen_gcc::invalid_monomorphization_simd_shuffle, code = "E0511")]
101+
pub(crate) struct InvalidMonomorphizationSimdShuffle<'a> {
102+
#[primary_span]
103+
pub span: Span,
104+
pub name: Symbol,
105+
pub ty: Ty<'a>,
106+
}
107+
108+
#[derive(Diagnostic)]
109+
#[diag(codegen_gcc::invalid_monomorphization_expected_simd, code = "E0511")]
110+
pub(crate) struct InvalidMonomorphizationExpectedSimd<'a> {
111+
#[primary_span]
112+
pub span: Span,
113+
pub name: Symbol,
114+
pub position: &'a str,
115+
pub found_ty: Ty<'a>,
116+
}
117+
118+
#[derive(Diagnostic)]
119+
#[diag(codegen_gcc::invalid_monomorphization_mask_type, code = "E0511")]
120+
pub(crate) struct InvalidMonomorphizationMaskType<'a> {
121+
#[primary_span]
122+
pub span: Span,
123+
pub name: Symbol,
124+
pub ty: Ty<'a>,
125+
}
126+
127+
#[derive(Diagnostic)]
128+
#[diag(codegen_gcc::invalid_monomorphization_return_length, code = "E0511")]
129+
pub(crate) struct InvalidMonomorphizationReturnLength<'a> {
130+
#[primary_span]
131+
pub span: Span,
132+
pub name: Symbol,
133+
pub in_len: u64,
134+
pub ret_ty: Ty<'a>,
135+
pub out_len: u64,
136+
}
137+
138+
#[derive(Diagnostic)]
139+
#[diag(codegen_gcc::invalid_monomorphization_return_length_input_type, code = "E0511")]
140+
pub(crate) struct InvalidMonomorphizationReturnLengthInputType<'a> {
141+
#[primary_span]
142+
pub span: Span,
143+
pub name: Symbol,
144+
pub in_len: u64,
145+
pub in_ty: Ty<'a>,
146+
pub ret_ty: Ty<'a>,
147+
pub out_len: u64,
148+
}
149+
150+
#[derive(Diagnostic)]
151+
#[diag(codegen_gcc::invalid_monomorphization_return_element, code = "E0511")]
152+
pub(crate) struct InvalidMonomorphizationReturnElement<'a> {
153+
#[primary_span]
154+
pub span: Span,
155+
pub name: Symbol,
156+
pub in_elem: Ty<'a>,
157+
pub in_ty: Ty<'a>,
158+
pub ret_ty: Ty<'a>,
159+
pub out_ty: Ty<'a>,
160+
}
161+
162+
#[derive(Diagnostic)]
163+
#[diag(codegen_gcc::invalid_monomorphization_return_type, code = "E0511")]
164+
pub(crate) struct InvalidMonomorphizationReturnType<'a> {
165+
#[primary_span]
166+
pub span: Span,
167+
pub name: Symbol,
168+
pub in_elem: Ty<'a>,
169+
pub in_ty: Ty<'a>,
170+
pub ret_ty: Ty<'a>,
171+
}
172+
173+
#[derive(Diagnostic)]
174+
#[diag(codegen_gcc::invalid_monomorphization_inserted_type, code = "E0511")]
175+
pub(crate) struct InvalidMonomorphizationInsertedType<'a> {
176+
#[primary_span]
177+
pub span: Span,
178+
pub name: Symbol,
179+
pub in_elem: Ty<'a>,
180+
pub in_ty: Ty<'a>,
181+
pub out_ty: Ty<'a>,
182+
}
183+
184+
#[derive(Diagnostic)]
185+
#[diag(codegen_gcc::invalid_monomorphization_return_integer_type, code = "E0511")]
186+
pub(crate) struct InvalidMonomorphizationReturnIntegerType<'a> {
187+
#[primary_span]
188+
pub span: Span,
189+
pub name: Symbol,
190+
pub ret_ty: Ty<'a>,
191+
pub out_ty: Ty<'a>,
192+
}
193+
194+
#[derive(Diagnostic)]
195+
#[diag(codegen_gcc::invalid_monomorphization_mismatched_lengths, code = "E0511")]
196+
pub(crate) struct InvalidMonomorphizationMismatchedLengths {
197+
#[primary_span]
198+
pub span: Span,
199+
pub name: Symbol,
200+
pub m_len: u64,
201+
pub v_len: u64,
202+
}
203+
204+
#[derive(Diagnostic)]
205+
#[diag(codegen_gcc::invalid_monomorphization_unsupported_cast, code = "E0511")]
206+
pub(crate) struct InvalidMonomorphizationUnsupportedCast<'a> {
207+
#[primary_span]
208+
pub span: Span,
209+
pub name: Symbol,
210+
pub in_ty: Ty<'a>,
211+
pub in_elem: Ty<'a>,
212+
pub ret_ty: Ty<'a>,
213+
pub out_elem: Ty<'a>,
214+
}
215+
216+
#[derive(Diagnostic)]
217+
#[diag(codegen_gcc::invalid_monomorphization_unsupported_operation, code = "E0511")]
218+
pub(crate) struct InvalidMonomorphizationUnsupportedOperation<'a> {
219+
#[primary_span]
220+
pub span: Span,
221+
pub name: Symbol,
222+
pub in_ty: Ty<'a>,
223+
pub in_elem: Ty<'a>,
224+
}
225+
226+
#[derive(Diagnostic)]
227+
#[diag(codegen_gcc::linkage_const_or_mut_type)]
228+
pub(crate) struct LinkageConstOrMutType {
229+
#[primary_span]
230+
pub span: Span
231+
}
232+
233+
#[derive(Diagnostic)]
234+
#[diag(codegen_gcc::lto_not_supported)]
235+
pub(crate) struct LTONotSupported;
236+
237+
#[derive(Diagnostic)]
238+
#[diag(codegen_gcc::unwinding_inline_asm)]
239+
pub(crate) struct UnwindingInlineAsm {
240+
#[primary_span]
241+
pub span: Span
242+
}

Diff for: compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ mod simd;
44
use gccjit::{ComparisonOp, Function, RValue, ToRValue, Type, UnaryOp, FunctionType};
55
use rustc_codegen_ssa::MemFlags;
66
use rustc_codegen_ssa::base::wants_msvc_seh;
7-
use rustc_codegen_ssa::common::{IntPredicate, span_invalid_monomorphization_error};
7+
use rustc_codegen_ssa::common::IntPredicate;
88
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
99
use rustc_codegen_ssa::mir::place::PlaceRef;
1010
use rustc_codegen_ssa::traits::{ArgAbiMethods, BaseTypeMethods, BuilderMethods, ConstMethods, IntrinsicCallMethods};
@@ -20,6 +20,7 @@ use crate::abi::GccType;
2020
use crate::builder::Builder;
2121
use crate::common::{SignType, TypeReflection};
2222
use crate::context::CodegenCx;
23+
use crate::errors::InvalidMonomorphizationBasicInteger;
2324
use crate::type_of::LayoutGccExt;
2425
use crate::intrinsic::simd::generic_simd_intrinsic;
2526

@@ -242,15 +243,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
242243
_ => bug!(),
243244
},
244245
None => {
245-
span_invalid_monomorphization_error(
246-
tcx.sess,
247-
span,
248-
&format!(
249-
"invalid monomorphization of `{}` intrinsic: \
250-
expected basic integer type, found `{}`",
251-
name, ty
252-
),
253-
);
246+
tcx.sess.emit_err(InvalidMonomorphizationBasicInteger { span, name, ty });
254247
return;
255248
}
256249
}

0 commit comments

Comments
 (0)