Skip to content

Commit 34115d0

Browse files
committed
Auto merge of rust-lang#104215 - Manishearth:rollup-5r957ad, r=Manishearth
Rollup of 9 pull requests Successful merges: - rust-lang#101005 (Migrate rustc_codegen_llvm to SessionDiagnostics) - rust-lang#103307 (Add context to compiler error message) - rust-lang#103464 (Add support for custom mir) - rust-lang#103929 (Cleanup Apple-related code in rustc_target) - rust-lang#104015 (Remove linuxkernel targets) - rust-lang#104020 (Limit efiapi calling convention to supported arches) - rust-lang#104156 (Cleanups in autoderef impl) - rust-lang#104171 (Update books) - rust-lang#104184 (Fix `rustdoc --version` when used with download-rustc) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents e75aab0 + 70c04a2 commit 34115d0

File tree

143 files changed

+1787
-700
lines changed

Some content is hidden

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

143 files changed

+1787
-700
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1557,7 +1557,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
15571557
}
15581558

15591559
let mut err = self.temporary_value_borrowed_for_too_long(proper_span);
1560-
err.span_label(proper_span, "creates a temporary which is freed while still in use");
1560+
err.span_label(proper_span, "creates a temporary value which is freed while still in use");
15611561
err.span_label(drop_span, "temporary value is freed at the end of this statement");
15621562

15631563
match explanation {

compiler/rustc_borrowck/src/lib.rs

+14
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ extern crate tracing;
1818

1919
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
2020
use rustc_data_structures::graph::dominators::Dominators;
21+
use rustc_data_structures::vec_map::VecMap;
2122
use rustc_errors::{Diagnostic, DiagnosticBuilder, ErrorGuaranteed};
2223
use rustc_hir as hir;
2324
use rustc_hir::def_id::LocalDefId;
@@ -129,6 +130,19 @@ fn mir_borrowck<'tcx>(
129130
) -> &'tcx BorrowCheckResult<'tcx> {
130131
let (input_body, promoted) = tcx.mir_promoted(def);
131132
debug!("run query mir_borrowck: {}", tcx.def_path_str(def.did.to_def_id()));
133+
134+
if input_body.borrow().should_skip() {
135+
debug!("Skipping borrowck because of injected body");
136+
// Let's make up a borrowck result! Fun times!
137+
let result = BorrowCheckResult {
138+
concrete_opaque_types: VecMap::new(),
139+
closure_requirements: None,
140+
used_mut_upvars: SmallVec::new(),
141+
tainted_by_errors: None,
142+
};
143+
return tcx.arena.alloc(result);
144+
}
145+
132146
let hir_owner = tcx.hir().local_def_id_to_hir_id(def.did).owner;
133147

134148
let infcx =

compiler/rustc_codegen_cranelift/src/debuginfo/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl DebugContext {
5959

6060
let producer = format!(
6161
"cg_clif (rustc {}, cranelift {})",
62-
rustc_interface::util::version_str().unwrap_or("unknown version"),
62+
rustc_interface::util::rustc_version_str().unwrap_or("unknown version"),
6363
cranelift_codegen::VERSION,
6464
);
6565
let comp_dir = tcx

compiler/rustc_codegen_llvm/src/attributes.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rustc_target::spec::{FramePointer, SanitizerSet, StackProbeType, StackProtec
1212
use smallvec::SmallVec;
1313

1414
use crate::attributes;
15+
use crate::errors::{MissingFeatures, SanitizerMemtagRequiresMte, TargetFeatureDisableOrEnable};
1516
use crate::llvm::AttributePlace::Function;
1617
use crate::llvm::{self, AllocKindFlags, Attribute, AttributeKind, AttributePlace, MemoryEffects};
1718
use crate::llvm_util;
@@ -82,7 +83,7 @@ pub fn sanitize_attrs<'ll>(
8283
let mte_feature =
8384
features.iter().map(|s| &s[..]).rfind(|n| ["+mte", "-mte"].contains(&&n[..]));
8485
if let None | Some("-mte") = mte_feature {
85-
cx.tcx.sess.err("`-Zsanitizer=memtag` requires `-Ctarget-feature=+mte`");
86+
cx.tcx.sess.emit_err(SanitizerMemtagRequiresMte);
8687
}
8788

8889
attrs.push(llvm::AttributeKind::SanitizeMemTag.create_attr(cx.llcx));
@@ -393,13 +394,14 @@ pub fn from_fn_attrs<'ll, 'tcx>(
393394
.get_attrs(instance.def_id(), sym::target_feature)
394395
.next()
395396
.map_or_else(|| cx.tcx.def_span(instance.def_id()), |a| a.span);
396-
let msg = format!(
397-
"the target features {} must all be either enabled or disabled together",
398-
f.join(", ")
399-
);
400-
let mut err = cx.tcx.sess.struct_span_err(span, &msg);
401-
err.help("add the missing features in a `target_feature` attribute");
402-
err.emit();
397+
cx.tcx
398+
.sess
399+
.create_err(TargetFeatureDisableOrEnable {
400+
features: f,
401+
span: Some(span),
402+
missing_features: Some(MissingFeatures),
403+
})
404+
.emit();
403405
return;
404406
}
405407

compiler/rustc_codegen_llvm/src/back/archive.rs

+20-15
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ use std::str;
1212
use object::read::macho::FatArch;
1313

1414
use crate::common;
15+
use crate::errors::{
16+
ArchiveBuildFailure, DlltoolFailImportLibrary, ErrorCallingDllTool, ErrorCreatingImportLibrary,
17+
ErrorWritingDEFFile, UnknownArchiveKind,
18+
};
1519
use crate::llvm::archive_ro::{ArchiveRO, Child};
1620
use crate::llvm::{self, ArchiveKind, LLVMMachineType, LLVMRustCOFFShortExport};
1721
use rustc_codegen_ssa::back::archive::{ArchiveBuilder, ArchiveBuilderBuilder};
@@ -147,7 +151,7 @@ impl<'a> ArchiveBuilder<'a> for LlvmArchiveBuilder<'a> {
147151
fn build(mut self: Box<Self>, output: &Path) -> bool {
148152
match self.build_with_llvm(output) {
149153
Ok(any_members) => any_members,
150-
Err(e) => self.sess.fatal(&format!("failed to build archive: {}", e)),
154+
Err(e) => self.sess.emit_fatal(ArchiveBuildFailure { error: e }),
151155
}
152156
}
153157
}
@@ -217,7 +221,7 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
217221
match std::fs::write(&def_file_path, def_file_content) {
218222
Ok(_) => {}
219223
Err(e) => {
220-
sess.fatal(&format!("Error writing .DEF file: {}", e));
224+
sess.emit_fatal(ErrorWritingDEFFile { error: e });
221225
}
222226
};
223227

@@ -239,13 +243,14 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
239243

240244
match result {
241245
Err(e) => {
242-
sess.fatal(&format!("Error calling dlltool: {}", e));
246+
sess.emit_fatal(ErrorCallingDllTool { error: e });
247+
}
248+
Ok(output) if !output.status.success() => {
249+
sess.emit_fatal(DlltoolFailImportLibrary {
250+
stdout: String::from_utf8_lossy(&output.stdout),
251+
stderr: String::from_utf8_lossy(&output.stderr),
252+
})
243253
}
244-
Ok(output) if !output.status.success() => sess.fatal(&format!(
245-
"Dlltool could not create import library: {}\n{}",
246-
String::from_utf8_lossy(&output.stdout),
247-
String::from_utf8_lossy(&output.stderr)
248-
)),
249254
_ => {}
250255
}
251256
} else {
@@ -293,11 +298,10 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
293298
};
294299

295300
if result == crate::llvm::LLVMRustResult::Failure {
296-
sess.fatal(&format!(
297-
"Error creating import library for {}: {}",
301+
sess.emit_fatal(ErrorCreatingImportLibrary {
298302
lib_name,
299-
llvm::last_error().unwrap_or("unknown LLVM error".to_string())
300-
));
303+
error: llvm::last_error().unwrap_or("unknown LLVM error".to_string()),
304+
});
301305
}
302306
};
303307

@@ -308,9 +312,10 @@ impl ArchiveBuilderBuilder for LlvmArchiveBuilderBuilder {
308312
impl<'a> LlvmArchiveBuilder<'a> {
309313
fn build_with_llvm(&mut self, output: &Path) -> io::Result<bool> {
310314
let kind = &*self.sess.target.archive_format;
311-
let kind = kind.parse::<ArchiveKind>().map_err(|_| kind).unwrap_or_else(|kind| {
312-
self.sess.fatal(&format!("Don't know how to build archive of type: {}", kind))
313-
});
315+
let kind = kind
316+
.parse::<ArchiveKind>()
317+
.map_err(|_| kind)
318+
.unwrap_or_else(|kind| self.sess.emit_fatal(UnknownArchiveKind { kind }));
314319

315320
let mut additions = mem::take(&mut self.additions);
316321
let mut strings = Vec::new();

compiler/rustc_codegen_llvm/src/back/lto.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::back::write::{self, save_temp_bitcode, DiagnosticHandlers};
2+
use crate::errors::DynamicLinkingWithLTO;
23
use crate::llvm::{self, build_string};
34
use crate::{LlvmCodegenBackend, ModuleLlvm};
45
use object::read::archive::ArchiveFile;
@@ -90,13 +91,7 @@ fn prepare_lto(
9091
}
9192

9293
if cgcx.opts.cg.prefer_dynamic && !cgcx.opts.unstable_opts.dylib_lto {
93-
diag_handler
94-
.struct_err("cannot prefer dynamic linking when performing LTO")
95-
.note(
96-
"only 'staticlib', 'bin', and 'cdylib' outputs are \
97-
supported with LTO",
98-
)
99-
.emit();
94+
diag_handler.emit_err(DynamicLinkingWithLTO);
10095
return Err(FatalError);
10196
}
10297

compiler/rustc_codegen_llvm/src/consts.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::base;
22
use crate::common::{self, CodegenCx};
33
use crate::debuginfo;
4+
use crate::errors::{InvalidMinimumAlignment, LinkageConstOrMutType, SymbolAlreadyDefined};
45
use crate::llvm::{self, True};
56
use crate::llvm_util;
67
use crate::type_::Type;
@@ -146,7 +147,7 @@ fn set_global_alignment<'ll>(cx: &CodegenCx<'ll, '_>, gv: &'ll Value, mut align:
146147
match Align::from_bits(min) {
147148
Ok(min) => align = align.max(min),
148149
Err(err) => {
149-
cx.sess().err(&format!("invalid minimum global alignment: {}", err));
150+
cx.sess().emit_err(InvalidMinimumAlignment { err });
150151
}
151152
}
152153
}
@@ -174,10 +175,7 @@ fn check_and_apply_linkage<'ll, 'tcx>(
174175
let llty2 = if let ty::RawPtr(ref mt) = ty.kind() {
175176
cx.layout_of(mt.ty).llvm_type(cx)
176177
} else {
177-
cx.sess().span_fatal(
178-
cx.tcx.def_span(def_id),
179-
"must have type `*const T` or `*mut T` due to `#[linkage]` attribute",
180-
)
178+
cx.sess().emit_fatal(LinkageConstOrMutType { span: cx.tcx.def_span(def_id) })
181179
};
182180
unsafe {
183181
// Declare a symbol `foo` with the desired linkage.
@@ -193,10 +191,10 @@ fn check_and_apply_linkage<'ll, 'tcx>(
193191
let mut real_name = "_rust_extern_with_linkage_".to_string();
194192
real_name.push_str(sym);
195193
let g2 = cx.define_global(&real_name, llty).unwrap_or_else(|| {
196-
cx.sess().span_fatal(
197-
cx.tcx.def_span(def_id),
198-
&format!("symbol `{}` is already defined", &sym),
199-
)
194+
cx.sess().emit_fatal(SymbolAlreadyDefined {
195+
span: cx.tcx.def_span(def_id),
196+
symbol_name: sym,
197+
})
200198
});
201199
llvm::LLVMRustSetLinkage(g2, llvm::Linkage::InternalLinkage);
202200
llvm::LLVMSetInitializer(g2, g1);

compiler/rustc_codegen_llvm/src/context.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::back::write::to_llvm_code_model;
33
use crate::callee::get_fn;
44
use crate::coverageinfo;
55
use crate::debuginfo;
6+
use crate::errors::BranchProtectionRequiresAArch64;
67
use crate::llvm;
78
use crate::llvm_util;
89
use crate::type_::Type;
@@ -26,6 +27,7 @@ use rustc_session::config::{BranchProtection, CFGuard, CFProtection};
2627
use rustc_session::config::{CrateType, DebugInfo, PAuthKey, PacRet};
2728
use rustc_session::Session;
2829
use rustc_span::source_map::Span;
30+
use rustc_span::source_map::Spanned;
2931
use rustc_target::abi::{
3032
call::FnAbi, HasDataLayout, PointeeInfo, Size, TargetDataLayout, VariantIdx,
3133
};
@@ -275,7 +277,7 @@ pub unsafe fn create_module<'ll>(
275277

276278
if let Some(BranchProtection { bti, pac_ret }) = sess.opts.unstable_opts.branch_protection {
277279
if sess.target.arch != "aarch64" {
278-
sess.err("-Zbranch-protection is only supported on aarch64");
280+
sess.emit_err(BranchProtectionRequiresAArch64);
279281
} else {
280282
llvm::LLVMRustAddModuleFlag(
281283
llmod,
@@ -951,7 +953,7 @@ impl<'tcx> LayoutOfHelpers<'tcx> for CodegenCx<'_, 'tcx> {
951953
#[inline]
952954
fn handle_layout_err(&self, err: LayoutError<'tcx>, span: Span, ty: Ty<'tcx>) -> ! {
953955
if let LayoutError::SizeOverflow(_) = err {
954-
self.sess().span_fatal(span, &err.to_string())
956+
self.sess().emit_fatal(Spanned { span, node: err })
955957
} else {
956958
span_bug!(span, "failed to get layout for `{}`: {}", ty, err)
957959
}
@@ -969,7 +971,7 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for CodegenCx<'_, 'tcx> {
969971
fn_abi_request: FnAbiRequest<'tcx>,
970972
) -> ! {
971973
if let FnAbiError::Layout(LayoutError::SizeOverflow(_)) = err {
972-
self.sess().span_fatal(span, &err.to_string())
974+
self.sess().emit_fatal(Spanned { span, node: err })
973975
} else {
974976
match fn_abi_request {
975977
FnAbiRequest::OfFnPtr { sig, extra_args } => {

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::common::CodegenCx;
22
use crate::coverageinfo;
3+
use crate::errors::InstrumentCoverageRequiresLLVM12;
34
use crate::llvm;
45

56
use llvm::coverageinfo::CounterMappingRegion;
@@ -37,7 +38,7 @@ pub fn finalize<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>) {
3738
// LLVM 12.
3839
let version = coverageinfo::mapping_version();
3940
if version < 4 {
40-
tcx.sess.fatal("rustc option `-C instrument-coverage` requires LLVM 12 or higher.");
41+
tcx.sess.emit_fatal(InstrumentCoverageRequiresLLVM12);
4142
}
4243

4344
debug!("Generating coverage map for CodegenUnit: `{}`", cx.codegen_unit.name());

0 commit comments

Comments
 (0)