Skip to content

Commit 60ee496

Browse files
committed
Port LinkageConstOrMutType error
1 parent 5d79d3c commit 60ee496

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::base;
22
use crate::common::{self, CodegenCx};
33
use crate::debuginfo;
4-
use crate::errors::InvalidMinimumAlignment;
4+
use crate::errors::{InvalidMinimumAlignment, LinkageConstOrMutType};
55
use crate::llvm::{self, True};
66
use crate::llvm_util;
77
use crate::type_::Type;
@@ -147,9 +147,7 @@ fn set_global_alignment<'ll>(cx: &CodegenCx<'ll, '_>, gv: &'ll Value, mut align:
147147
match Align::from_bits(min) {
148148
Ok(min) => align = align.max(min),
149149
Err(err) => {
150-
cx.sess().emit_err(InvalidMinimumAlignment {
151-
err,
152-
});
150+
cx.sess().emit_err(InvalidMinimumAlignment { err });
153151
}
154152
}
155153
}
@@ -177,10 +175,7 @@ fn check_and_apply_linkage<'ll, 'tcx>(
177175
let llty2 = if let ty::RawPtr(ref mt) = ty.kind() {
178176
cx.layout_of(mt.ty).llvm_type(cx)
179177
} else {
180-
cx.sess().span_fatal(
181-
cx.tcx.def_span(def_id),
182-
"must have type `*const T` or `*mut T` due to `#[linkage]` attribute",
183-
)
178+
cx.sess().emit_fatal(LinkageConstOrMutType { span: cx.tcx.def_span(def_id) })
184179
};
185180
unsafe {
186181
// Declare a symbol `foo` with the desired linkage.

compiler/rustc_codegen_llvm/src/errors.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,12 @@ pub(crate) struct LayoutSizeOverflow {
7171
#[derive(SessionDiagnostic)]
7272
#[diag(codegen_llvm::invalid_minimum_alignment)]
7373
pub(crate) struct InvalidMinimumAlignment {
74-
pub err: String
74+
pub err: String,
75+
}
76+
77+
#[derive(SessionDiagnostic)]
78+
#[diag(codegen_llvm::linkage_const_or_mut_type)]
79+
pub(crate) struct LinkageConstOrMutType {
80+
#[primary_span]
81+
pub span: Span,
7582
}

compiler/rustc_error_messages/locales/en-US/codegen_llvm.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,6 @@ codegen_llvm_layout_size_overflow =
3030
3131
codegen_llvm_invalid_minimum_alignment =
3232
invalid minimum global alignment: {$err}
33+
34+
codegen_llvm_linkage_const_or_mut_type =
35+
must have type `*const T` or `*mut T` due to `#[linkage]` attribute

0 commit comments

Comments
 (0)