session: diagnostic migration lint on more fns
Apply the diagnostic migration lint to more functions on `Session`. Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
d45004806d
commit
2575b1abc9
33 changed files with 510 additions and 162 deletions
|
@ -369,6 +369,8 @@ pub(super) fn dump_mir_results<'tcx>(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(rustc::diagnostic_outside_of_impl)]
|
||||||
|
#[allow(rustc::untranslatable_diagnostic)]
|
||||||
pub(super) fn dump_annotation<'tcx>(
|
pub(super) fn dump_annotation<'tcx>(
|
||||||
infcx: &InferCtxt<'tcx>,
|
infcx: &InferCtxt<'tcx>,
|
||||||
body: &Body<'tcx>,
|
body: &Body<'tcx>,
|
||||||
|
|
|
@ -200,6 +200,7 @@ unsafe impl Sync for GccContext {}
|
||||||
impl WriteBackendMethods for GccCodegenBackend {
|
impl WriteBackendMethods for GccCodegenBackend {
|
||||||
type Module = GccContext;
|
type Module = GccContext;
|
||||||
type TargetMachine = ();
|
type TargetMachine = ();
|
||||||
|
type TargetMachineError = ();
|
||||||
type ModuleBuffer = ModuleBuffer;
|
type ModuleBuffer = ModuleBuffer;
|
||||||
type ThinData = ();
|
type ThinData = ();
|
||||||
type ThinBuffer = ThinBuffer;
|
type ThinBuffer = ThinBuffer;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
use crate::back::write::{self, save_temp_bitcode, DiagnosticHandlers};
|
use crate::back::write::{self, save_temp_bitcode, DiagnosticHandlers};
|
||||||
use crate::errors::DynamicLinkingWithLTO;
|
use crate::errors::{
|
||||||
|
DynamicLinkingWithLTO, LlvmError, LtoBitcodeFromRlib, LtoDisallowed, LtoDylib,
|
||||||
|
};
|
||||||
use crate::llvm::{self, build_string};
|
use crate::llvm::{self, build_string};
|
||||||
use crate::{LlvmCodegenBackend, ModuleLlvm};
|
use crate::{LlvmCodegenBackend, ModuleLlvm};
|
||||||
use object::read::archive::ArchiveFile;
|
use object::read::archive::ArchiveFile;
|
||||||
|
@ -77,15 +79,12 @@ fn prepare_lto(
|
||||||
// Make sure we actually can run LTO
|
// Make sure we actually can run LTO
|
||||||
for crate_type in cgcx.crate_types.iter() {
|
for crate_type in cgcx.crate_types.iter() {
|
||||||
if !crate_type_allows_lto(*crate_type) {
|
if !crate_type_allows_lto(*crate_type) {
|
||||||
let e = diag_handler.fatal(
|
diag_handler.emit_err(LtoDisallowed);
|
||||||
"lto can only be run for executables, cdylibs and \
|
return Err(FatalError);
|
||||||
static library outputs",
|
|
||||||
);
|
|
||||||
return Err(e);
|
|
||||||
} else if *crate_type == CrateType::Dylib {
|
} else if *crate_type == CrateType::Dylib {
|
||||||
if !cgcx.opts.unstable_opts.dylib_lto {
|
if !cgcx.opts.unstable_opts.dylib_lto {
|
||||||
return Err(diag_handler
|
diag_handler.emit_err(LtoDylib);
|
||||||
.fatal("lto cannot be used for `dylib` crate type without `-Zdylib-lto`"));
|
return Err(FatalError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,7 +126,10 @@ fn prepare_lto(
|
||||||
let module = SerializedModule::FromRlib(data.to_vec());
|
let module = SerializedModule::FromRlib(data.to_vec());
|
||||||
upstream_modules.push((module, CString::new(name).unwrap()));
|
upstream_modules.push((module, CString::new(name).unwrap()));
|
||||||
}
|
}
|
||||||
Err(msg) => return Err(diag_handler.fatal(&msg)),
|
Err(e) => {
|
||||||
|
diag_handler.emit_err(e);
|
||||||
|
return Err(FatalError);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,7 +142,7 @@ fn prepare_lto(
|
||||||
Ok((symbols_below_threshold, upstream_modules))
|
Ok((symbols_below_threshold, upstream_modules))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_bitcode_slice_from_object_data(obj: &[u8]) -> Result<&[u8], String> {
|
fn get_bitcode_slice_from_object_data(obj: &[u8]) -> Result<&[u8], LtoBitcodeFromRlib> {
|
||||||
let mut len = 0;
|
let mut len = 0;
|
||||||
let data =
|
let data =
|
||||||
unsafe { llvm::LLVMRustGetBitcodeSliceFromObjectData(obj.as_ptr(), obj.len(), &mut len) };
|
unsafe { llvm::LLVMRustGetBitcodeSliceFromObjectData(obj.as_ptr(), obj.len(), &mut len) };
|
||||||
|
@ -155,8 +157,9 @@ fn get_bitcode_slice_from_object_data(obj: &[u8]) -> Result<&[u8], String> {
|
||||||
Ok(bc)
|
Ok(bc)
|
||||||
} else {
|
} else {
|
||||||
assert!(len == 0);
|
assert!(len == 0);
|
||||||
let msg = llvm::last_error().unwrap_or_else(|| "unknown LLVM error".to_string());
|
Err(LtoBitcodeFromRlib {
|
||||||
Err(format!("failed to get bitcode from object file for LTO ({})", msg))
|
llvm_err: llvm::last_error().unwrap_or_else(|| "unknown LLVM error".to_string()),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,10 +331,9 @@ fn fat_lto(
|
||||||
});
|
});
|
||||||
info!("linking {:?}", name);
|
info!("linking {:?}", name);
|
||||||
let data = bc_decoded.data();
|
let data = bc_decoded.data();
|
||||||
linker.add(data).map_err(|()| {
|
linker
|
||||||
let msg = format!("failed to load bitcode of module {:?}", name);
|
.add(data)
|
||||||
write::llvm_err(diag_handler, &msg)
|
.map_err(|()| write::llvm_err(diag_handler, LlvmError::LoadBitcode { name }))?;
|
||||||
})?;
|
|
||||||
serialized_bitcode.push(bc_decoded);
|
serialized_bitcode.push(bc_decoded);
|
||||||
}
|
}
|
||||||
drop(linker);
|
drop(linker);
|
||||||
|
@ -489,7 +491,7 @@ fn thin_lto(
|
||||||
symbols_below_threshold.as_ptr(),
|
symbols_below_threshold.as_ptr(),
|
||||||
symbols_below_threshold.len() as u32,
|
symbols_below_threshold.len() as u32,
|
||||||
)
|
)
|
||||||
.ok_or_else(|| write::llvm_err(diag_handler, "failed to prepare thin LTO context"))?;
|
.ok_or_else(|| write::llvm_err(diag_handler, LlvmError::PrepareThinLtoContext))?;
|
||||||
|
|
||||||
let data = ThinData(data);
|
let data = ThinData(data);
|
||||||
|
|
||||||
|
@ -562,8 +564,7 @@ fn thin_lto(
|
||||||
// session, overwriting the previous serialized data (if any).
|
// session, overwriting the previous serialized data (if any).
|
||||||
if let Some(path) = key_map_path {
|
if let Some(path) = key_map_path {
|
||||||
if let Err(err) = curr_key_map.save_to_file(&path) {
|
if let Err(err) = curr_key_map.save_to_file(&path) {
|
||||||
let msg = format!("Error while writing ThinLTO key data: {}", err);
|
return Err(write::llvm_err(diag_handler, LlvmError::WriteThinLtoKey { err }));
|
||||||
return Err(write::llvm_err(diag_handler, &msg));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -689,8 +690,7 @@ pub unsafe fn optimize_thin_module(
|
||||||
|
|
||||||
let module_name = &thin_module.shared.module_names[thin_module.idx];
|
let module_name = &thin_module.shared.module_names[thin_module.idx];
|
||||||
let tm_factory_config = TargetMachineFactoryConfig::new(cgcx, module_name.to_str().unwrap());
|
let tm_factory_config = TargetMachineFactoryConfig::new(cgcx, module_name.to_str().unwrap());
|
||||||
let tm =
|
let tm = (cgcx.tm_factory)(tm_factory_config).map_err(|e| write::llvm_err(&diag_handler, e))?;
|
||||||
(cgcx.tm_factory)(tm_factory_config).map_err(|e| write::llvm_err(&diag_handler, &e))?;
|
|
||||||
|
|
||||||
// Right now the implementation we've got only works over serialized
|
// Right now the implementation we've got only works over serialized
|
||||||
// modules, so we create a fresh new LLVM context and parse the module
|
// modules, so we create a fresh new LLVM context and parse the module
|
||||||
|
@ -717,8 +717,7 @@ pub unsafe fn optimize_thin_module(
|
||||||
let mut cu2 = ptr::null_mut();
|
let mut cu2 = ptr::null_mut();
|
||||||
llvm::LLVMRustThinLTOGetDICompileUnit(llmod, &mut cu1, &mut cu2);
|
llvm::LLVMRustThinLTOGetDICompileUnit(llmod, &mut cu1, &mut cu2);
|
||||||
if !cu2.is_null() {
|
if !cu2.is_null() {
|
||||||
let msg = "multiple source DICompileUnits found";
|
return Err(write::llvm_err(&diag_handler, LlvmError::MultipleSourceDiCompileUnit));
|
||||||
return Err(write::llvm_err(&diag_handler, msg));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Up next comes the per-module local analyses that we do for Thin LTO.
|
// Up next comes the per-module local analyses that we do for Thin LTO.
|
||||||
|
@ -733,8 +732,7 @@ pub unsafe fn optimize_thin_module(
|
||||||
let _timer =
|
let _timer =
|
||||||
cgcx.prof.generic_activity_with_arg("LLVM_thin_lto_rename", thin_module.name());
|
cgcx.prof.generic_activity_with_arg("LLVM_thin_lto_rename", thin_module.name());
|
||||||
if !llvm::LLVMRustPrepareThinLTORename(thin_module.shared.data.0, llmod, target) {
|
if !llvm::LLVMRustPrepareThinLTORename(thin_module.shared.data.0, llmod, target) {
|
||||||
let msg = "failed to prepare thin LTO module";
|
return Err(write::llvm_err(&diag_handler, LlvmError::PrepareThinLtoModule));
|
||||||
return Err(write::llvm_err(&diag_handler, msg));
|
|
||||||
}
|
}
|
||||||
save_temp_bitcode(cgcx, &module, "thin-lto-after-rename");
|
save_temp_bitcode(cgcx, &module, "thin-lto-after-rename");
|
||||||
}
|
}
|
||||||
|
@ -744,8 +742,7 @@ pub unsafe fn optimize_thin_module(
|
||||||
.prof
|
.prof
|
||||||
.generic_activity_with_arg("LLVM_thin_lto_resolve_weak", thin_module.name());
|
.generic_activity_with_arg("LLVM_thin_lto_resolve_weak", thin_module.name());
|
||||||
if !llvm::LLVMRustPrepareThinLTOResolveWeak(thin_module.shared.data.0, llmod) {
|
if !llvm::LLVMRustPrepareThinLTOResolveWeak(thin_module.shared.data.0, llmod) {
|
||||||
let msg = "failed to prepare thin LTO module";
|
return Err(write::llvm_err(&diag_handler, LlvmError::PrepareThinLtoModule));
|
||||||
return Err(write::llvm_err(&diag_handler, msg));
|
|
||||||
}
|
}
|
||||||
save_temp_bitcode(cgcx, &module, "thin-lto-after-resolve");
|
save_temp_bitcode(cgcx, &module, "thin-lto-after-resolve");
|
||||||
}
|
}
|
||||||
|
@ -755,8 +752,7 @@ pub unsafe fn optimize_thin_module(
|
||||||
.prof
|
.prof
|
||||||
.generic_activity_with_arg("LLVM_thin_lto_internalize", thin_module.name());
|
.generic_activity_with_arg("LLVM_thin_lto_internalize", thin_module.name());
|
||||||
if !llvm::LLVMRustPrepareThinLTOInternalize(thin_module.shared.data.0, llmod) {
|
if !llvm::LLVMRustPrepareThinLTOInternalize(thin_module.shared.data.0, llmod) {
|
||||||
let msg = "failed to prepare thin LTO module";
|
return Err(write::llvm_err(&diag_handler, LlvmError::PrepareThinLtoModule));
|
||||||
return Err(write::llvm_err(&diag_handler, msg));
|
|
||||||
}
|
}
|
||||||
save_temp_bitcode(cgcx, &module, "thin-lto-after-internalize");
|
save_temp_bitcode(cgcx, &module, "thin-lto-after-internalize");
|
||||||
}
|
}
|
||||||
|
@ -765,8 +761,7 @@ pub unsafe fn optimize_thin_module(
|
||||||
let _timer =
|
let _timer =
|
||||||
cgcx.prof.generic_activity_with_arg("LLVM_thin_lto_import", thin_module.name());
|
cgcx.prof.generic_activity_with_arg("LLVM_thin_lto_import", thin_module.name());
|
||||||
if !llvm::LLVMRustPrepareThinLTOImport(thin_module.shared.data.0, llmod, target) {
|
if !llvm::LLVMRustPrepareThinLTOImport(thin_module.shared.data.0, llmod, target) {
|
||||||
let msg = "failed to prepare thin LTO module";
|
return Err(write::llvm_err(&diag_handler, LlvmError::PrepareThinLtoModule));
|
||||||
return Err(write::llvm_err(&diag_handler, msg));
|
|
||||||
}
|
}
|
||||||
save_temp_bitcode(cgcx, &module, "thin-lto-after-import");
|
save_temp_bitcode(cgcx, &module, "thin-lto-after-import");
|
||||||
}
|
}
|
||||||
|
@ -886,11 +881,7 @@ pub fn parse_module<'a>(
|
||||||
diag_handler: &Handler,
|
diag_handler: &Handler,
|
||||||
) -> Result<&'a llvm::Module, FatalError> {
|
) -> Result<&'a llvm::Module, FatalError> {
|
||||||
unsafe {
|
unsafe {
|
||||||
llvm::LLVMRustParseBitcodeForLTO(cx, data.as_ptr(), data.len(), name.as_ptr()).ok_or_else(
|
llvm::LLVMRustParseBitcodeForLTO(cx, data.as_ptr(), data.len(), name.as_ptr())
|
||||||
|| {
|
.ok_or_else(|| write::llvm_err(diag_handler, LlvmError::ParseBitcode))
|
||||||
let msg = "failed to parse bitcode for LTO module";
|
|
||||||
write::llvm_err(diag_handler, msg)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,9 @@ use crate::back::profiling::{
|
||||||
use crate::base;
|
use crate::base;
|
||||||
use crate::common;
|
use crate::common;
|
||||||
use crate::consts;
|
use crate::consts;
|
||||||
|
use crate::errors::{
|
||||||
|
CopyBitcode, FromLlvmDiag, FromLlvmOptimizationDiag, LlvmError, WithLlvmError, WriteBytecode,
|
||||||
|
};
|
||||||
use crate::llvm::{self, DiagnosticInfo, PassManager};
|
use crate::llvm::{self, DiagnosticInfo, PassManager};
|
||||||
use crate::llvm_util;
|
use crate::llvm_util;
|
||||||
use crate::type_::Type;
|
use crate::type_::Type;
|
||||||
|
@ -37,10 +40,10 @@ use std::slice;
|
||||||
use std::str;
|
use std::str;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub fn llvm_err(handler: &rustc_errors::Handler, msg: &str) -> FatalError {
|
pub fn llvm_err<'a>(handler: &rustc_errors::Handler, err: LlvmError<'a>) -> FatalError {
|
||||||
match llvm::last_error() {
|
match llvm::last_error() {
|
||||||
Some(err) => handler.fatal(&format!("{}: {}", msg, err)),
|
Some(llvm_err) => handler.emit_almost_fatal(WithLlvmError(err, llvm_err)),
|
||||||
None => handler.fatal(msg),
|
None => handler.emit_almost_fatal(err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,10 +88,9 @@ pub fn write_output_file<'ll>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
result.into_result().map_err(|()| {
|
result
|
||||||
let msg = format!("could not write output to {}", output.display());
|
.into_result()
|
||||||
llvm_err(handler, &msg)
|
.map_err(|()| llvm_err(handler, LlvmError::WriteOutput { path: output }))
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +100,7 @@ pub fn create_informational_target_machine(sess: &Session) -> &'static mut llvm:
|
||||||
// system/tcx is set up.
|
// system/tcx is set up.
|
||||||
let features = llvm_util::global_llvm_features(sess, false);
|
let features = llvm_util::global_llvm_features(sess, false);
|
||||||
target_machine_factory(sess, config::OptLevel::No, &features)(config)
|
target_machine_factory(sess, config::OptLevel::No, &features)(config)
|
||||||
.unwrap_or_else(|err| llvm_err(sess.diagnostic(), &err).raise())
|
.unwrap_or_else(|err| llvm_err(sess.diagnostic(), err).raise())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> &'static mut llvm::TargetMachine {
|
pub fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> &'static mut llvm::TargetMachine {
|
||||||
|
@ -117,7 +119,7 @@ pub fn create_target_machine(tcx: TyCtxt<'_>, mod_name: &str) -> &'static mut ll
|
||||||
tcx.backend_optimization_level(()),
|
tcx.backend_optimization_level(()),
|
||||||
tcx.global_backend_features(()),
|
tcx.global_backend_features(()),
|
||||||
)(config)
|
)(config)
|
||||||
.unwrap_or_else(|err| llvm_err(tcx.sess.diagnostic(), &err).raise())
|
.unwrap_or_else(|err| llvm_err(tcx.sess.diagnostic(), err).raise())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_llvm_opt_settings(
|
pub fn to_llvm_opt_settings(
|
||||||
|
@ -240,9 +242,7 @@ pub fn target_machine_factory(
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
tm.ok_or_else(|| {
|
tm.ok_or_else(|| LlvmError::CreateTargetMachine { triple: triple.clone() })
|
||||||
format!("Could not create LLVM TargetMachine for triple: {}", triple.to_str().unwrap())
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,25 +355,28 @@ unsafe extern "C" fn diagnostic_handler(info: &DiagnosticInfo, user: *mut c_void
|
||||||
};
|
};
|
||||||
|
|
||||||
if enabled {
|
if enabled {
|
||||||
diag_handler.note_without_error(&format!(
|
diag_handler.emit_note(FromLlvmOptimizationDiag {
|
||||||
"{}:{}:{}: {}: {}",
|
filename: &opt.filename,
|
||||||
opt.filename, opt.line, opt.column, opt.pass_name, opt.message,
|
line: opt.line,
|
||||||
));
|
column: opt.column,
|
||||||
|
pass_name: &opt.pass_name,
|
||||||
|
message: &opt.message,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
llvm::diagnostic::PGO(diagnostic_ref) | llvm::diagnostic::Linker(diagnostic_ref) => {
|
llvm::diagnostic::PGO(diagnostic_ref) | llvm::diagnostic::Linker(diagnostic_ref) => {
|
||||||
let msg = llvm::build_string(|s| {
|
let message = llvm::build_string(|s| {
|
||||||
llvm::LLVMRustWriteDiagnosticInfoToString(diagnostic_ref, s)
|
llvm::LLVMRustWriteDiagnosticInfoToString(diagnostic_ref, s)
|
||||||
})
|
})
|
||||||
.expect("non-UTF8 diagnostic");
|
.expect("non-UTF8 diagnostic");
|
||||||
diag_handler.warn(&msg);
|
diag_handler.emit_warning(FromLlvmDiag { message });
|
||||||
}
|
}
|
||||||
llvm::diagnostic::Unsupported(diagnostic_ref) => {
|
llvm::diagnostic::Unsupported(diagnostic_ref) => {
|
||||||
let msg = llvm::build_string(|s| {
|
let message = llvm::build_string(|s| {
|
||||||
llvm::LLVMRustWriteDiagnosticInfoToString(diagnostic_ref, s)
|
llvm::LLVMRustWriteDiagnosticInfoToString(diagnostic_ref, s)
|
||||||
})
|
})
|
||||||
.expect("non-UTF8 diagnostic");
|
.expect("non-UTF8 diagnostic");
|
||||||
diag_handler.err(&msg);
|
diag_handler.emit_err(FromLlvmDiag { message });
|
||||||
}
|
}
|
||||||
llvm::diagnostic::UnknownDiagnostic(..) => {}
|
llvm::diagnostic::UnknownDiagnostic(..) => {}
|
||||||
}
|
}
|
||||||
|
@ -494,7 +497,7 @@ pub(crate) unsafe fn llvm_optimize(
|
||||||
llvm_plugins.as_ptr().cast(),
|
llvm_plugins.as_ptr().cast(),
|
||||||
llvm_plugins.len(),
|
llvm_plugins.len(),
|
||||||
);
|
);
|
||||||
result.into_result().map_err(|()| llvm_err(diag_handler, "failed to run LLVM passes"))
|
result.into_result().map_err(|()| llvm_err(diag_handler, LlvmError::RunLlvmPasses))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unsafe due to LLVM calls.
|
// Unsafe due to LLVM calls.
|
||||||
|
@ -547,8 +550,7 @@ pub(crate) fn link(
|
||||||
let _timer = cgcx.prof.generic_activity_with_arg("LLVM_link_module", &*module.name);
|
let _timer = cgcx.prof.generic_activity_with_arg("LLVM_link_module", &*module.name);
|
||||||
let buffer = ModuleBuffer::new(module.module_llvm.llmod());
|
let buffer = ModuleBuffer::new(module.module_llvm.llmod());
|
||||||
linker.add(buffer.data()).map_err(|()| {
|
linker.add(buffer.data()).map_err(|()| {
|
||||||
let msg = format!("failed to serialize module {:?}", module.name);
|
llvm_err(diag_handler, LlvmError::SerializeModule { name: &module.name })
|
||||||
llvm_err(diag_handler, &msg)
|
|
||||||
})?;
|
})?;
|
||||||
}
|
}
|
||||||
drop(linker);
|
drop(linker);
|
||||||
|
@ -626,9 +628,8 @@ pub(crate) unsafe fn codegen(
|
||||||
let _timer = cgcx
|
let _timer = cgcx
|
||||||
.prof
|
.prof
|
||||||
.generic_activity_with_arg("LLVM_module_codegen_emit_bitcode", &*module.name);
|
.generic_activity_with_arg("LLVM_module_codegen_emit_bitcode", &*module.name);
|
||||||
if let Err(e) = fs::write(&bc_out, data) {
|
if let Err(err) = fs::write(&bc_out, data) {
|
||||||
let msg = format!("failed to write bytecode to {}: {}", bc_out.display(), e);
|
diag_handler.emit_err(WriteBytecode { path: &bc_out, err });
|
||||||
diag_handler.err(&msg);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -678,10 +679,9 @@ pub(crate) unsafe fn codegen(
|
||||||
record_artifact_size(&cgcx.prof, "llvm_ir", &out);
|
record_artifact_size(&cgcx.prof, "llvm_ir", &out);
|
||||||
}
|
}
|
||||||
|
|
||||||
result.into_result().map_err(|()| {
|
result
|
||||||
let msg = format!("failed to write LLVM IR to {}", out.display());
|
.into_result()
|
||||||
llvm_err(diag_handler, &msg)
|
.map_err(|()| llvm_err(diag_handler, LlvmError::WriteIr { path: &out }))?;
|
||||||
})?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.emit_asm {
|
if config.emit_asm {
|
||||||
|
@ -749,8 +749,8 @@ pub(crate) unsafe fn codegen(
|
||||||
|
|
||||||
EmitObj::Bitcode => {
|
EmitObj::Bitcode => {
|
||||||
debug!("copying bitcode {:?} to obj {:?}", bc_out, obj_out);
|
debug!("copying bitcode {:?} to obj {:?}", bc_out, obj_out);
|
||||||
if let Err(e) = link_or_copy(&bc_out, &obj_out) {
|
if let Err(err) = link_or_copy(&bc_out, &obj_out) {
|
||||||
diag_handler.err(&format!("failed to copy bitcode to object file: {}", e));
|
diag_handler.emit_err(CopyBitcode { err });
|
||||||
}
|
}
|
||||||
|
|
||||||
if !config.emit_bc {
|
if !config.emit_bc {
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
|
use std::ffi::CString;
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
use rustc_errors::fluent;
|
use rustc_data_structures::small_c_str::SmallCStr;
|
||||||
use rustc_errors::DiagnosticBuilder;
|
use rustc_errors::{
|
||||||
use rustc_errors::ErrorGuaranteed;
|
fluent, DiagnosticBuilder, EmissionGuarantee, ErrorGuaranteed, Handler, IntoDiagnostic,
|
||||||
use rustc_errors::Handler;
|
};
|
||||||
use rustc_errors::IntoDiagnostic;
|
|
||||||
use rustc_macros::{Diagnostic, Subdiagnostic};
|
use rustc_macros::{Diagnostic, Subdiagnostic};
|
||||||
use rustc_span::Span;
|
use rustc_span::Span;
|
||||||
|
|
||||||
|
@ -81,10 +82,18 @@ pub(crate) struct DlltoolFailImportLibrary<'a> {
|
||||||
#[note]
|
#[note]
|
||||||
pub(crate) struct DynamicLinkingWithLTO;
|
pub(crate) struct DynamicLinkingWithLTO;
|
||||||
|
|
||||||
#[derive(Diagnostic)]
|
pub(crate) struct ParseTargetMachineConfig<'a>(pub LlvmError<'a>);
|
||||||
#[diag(codegen_llvm_fail_parsing_target_machine_config_to_target_machine)]
|
|
||||||
pub(crate) struct FailParsingTargetMachineConfigToTargetMachine {
|
impl<EM: EmissionGuarantee> IntoDiagnostic<'_, EM> for ParseTargetMachineConfig<'_> {
|
||||||
pub error: String,
|
fn into_diagnostic(self, sess: &'_ Handler) -> DiagnosticBuilder<'_, EM> {
|
||||||
|
let diag: DiagnosticBuilder<'_, EM> = self.0.into_diagnostic(sess);
|
||||||
|
let (message, _) = diag.styled_message().first().expect("`LlvmError` with no message");
|
||||||
|
let message = sess.eagerly_translate_to_string(message.clone(), diag.args());
|
||||||
|
|
||||||
|
let mut diag = sess.struct_diagnostic(fluent::codegen_llvm_parse_target_machine_config);
|
||||||
|
diag.set_arg("error", message);
|
||||||
|
diag
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) struct TargetFeatureDisableOrEnable<'a> {
|
pub(crate) struct TargetFeatureDisableOrEnable<'a> {
|
||||||
|
@ -110,3 +119,99 @@ impl IntoDiagnostic<'_, ErrorGuaranteed> for TargetFeatureDisableOrEnable<'_> {
|
||||||
diag
|
diag
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(codegen_llvm_lto_disallowed)]
|
||||||
|
pub(crate) struct LtoDisallowed;
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(codegen_llvm_lto_dylib)]
|
||||||
|
pub(crate) struct LtoDylib;
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(codegen_llvm_lto_bitcode_from_rlib)]
|
||||||
|
pub(crate) struct LtoBitcodeFromRlib {
|
||||||
|
pub llvm_err: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
pub enum LlvmError<'a> {
|
||||||
|
#[diag(codegen_llvm_write_output)]
|
||||||
|
WriteOutput { path: &'a Path },
|
||||||
|
#[diag(codegen_llvm_target_machine)]
|
||||||
|
CreateTargetMachine { triple: SmallCStr },
|
||||||
|
#[diag(codegen_llvm_run_passes)]
|
||||||
|
RunLlvmPasses,
|
||||||
|
#[diag(codegen_llvm_serialize_module)]
|
||||||
|
SerializeModule { name: &'a str },
|
||||||
|
#[diag(codegen_llvm_write_ir)]
|
||||||
|
WriteIr { path: &'a Path },
|
||||||
|
#[diag(codegen_llvm_prepare_thin_lto_context)]
|
||||||
|
PrepareThinLtoContext,
|
||||||
|
#[diag(codegen_llvm_load_bitcode)]
|
||||||
|
LoadBitcode { name: CString },
|
||||||
|
#[diag(codegen_llvm_write_thinlto_key)]
|
||||||
|
WriteThinLtoKey { err: std::io::Error },
|
||||||
|
#[diag(codegen_llvm_multiple_source_dicompileunit)]
|
||||||
|
MultipleSourceDiCompileUnit,
|
||||||
|
#[diag(codegen_llvm_prepare_thin_lto_module)]
|
||||||
|
PrepareThinLtoModule,
|
||||||
|
#[diag(codegen_llvm_parse_bitcode)]
|
||||||
|
ParseBitcode,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) struct WithLlvmError<'a>(pub LlvmError<'a>, pub String);
|
||||||
|
|
||||||
|
impl<EM: EmissionGuarantee> IntoDiagnostic<'_, EM> for WithLlvmError<'_> {
|
||||||
|
fn into_diagnostic(self, sess: &'_ Handler) -> DiagnosticBuilder<'_, EM> {
|
||||||
|
use LlvmError::*;
|
||||||
|
let msg_with_llvm_err = match &self.0 {
|
||||||
|
WriteOutput { .. } => fluent::codegen_llvm_write_output_with_llvm_err,
|
||||||
|
CreateTargetMachine { .. } => fluent::codegen_llvm_target_machine_with_llvm_err,
|
||||||
|
RunLlvmPasses => fluent::codegen_llvm_run_passes_with_llvm_err,
|
||||||
|
SerializeModule { .. } => fluent::codegen_llvm_serialize_module_with_llvm_err,
|
||||||
|
WriteIr { .. } => fluent::codegen_llvm_write_ir_with_llvm_err,
|
||||||
|
PrepareThinLtoContext => fluent::codegen_llvm_prepare_thin_lto_context_with_llvm_err,
|
||||||
|
LoadBitcode { .. } => fluent::codegen_llvm_load_bitcode_with_llvm_err,
|
||||||
|
WriteThinLtoKey { .. } => fluent::codegen_llvm_write_thinlto_key_with_llvm_err,
|
||||||
|
MultipleSourceDiCompileUnit => {
|
||||||
|
fluent::codegen_llvm_multiple_source_dicompileunit_with_llvm_err
|
||||||
|
}
|
||||||
|
PrepareThinLtoModule => fluent::codegen_llvm_prepare_thin_lto_module_with_llvm_err,
|
||||||
|
ParseBitcode => fluent::codegen_llvm_parse_bitcode_with_llvm_err,
|
||||||
|
};
|
||||||
|
let mut diag = self.0.into_diagnostic(sess);
|
||||||
|
diag.set_primary_message(msg_with_llvm_err);
|
||||||
|
diag.set_arg("llvm_err", self.1);
|
||||||
|
diag
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(codegen_llvm_from_llvm_optimization_diag)]
|
||||||
|
pub(crate) struct FromLlvmOptimizationDiag<'a> {
|
||||||
|
pub filename: &'a str,
|
||||||
|
pub line: std::ffi::c_uint,
|
||||||
|
pub column: std::ffi::c_uint,
|
||||||
|
pub pass_name: &'a str,
|
||||||
|
pub message: &'a str,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(codegen_llvm_from_llvm_diag)]
|
||||||
|
pub(crate) struct FromLlvmDiag {
|
||||||
|
pub message: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(codegen_llvm_write_bytecode)]
|
||||||
|
pub(crate) struct WriteBytecode<'a> {
|
||||||
|
pub path: &'a Path,
|
||||||
|
pub err: std::io::Error,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(codegen_llvm_copy_bitcode)]
|
||||||
|
pub(crate) struct CopyBitcode {
|
||||||
|
pub err: std::io::Error,
|
||||||
|
}
|
||||||
|
|
|
@ -5,11 +5,12 @@
|
||||||
//! This API is completely unstable and subject to change.
|
//! This API is completely unstable and subject to change.
|
||||||
|
|
||||||
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
|
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
|
||||||
#![feature(hash_raw_entry)]
|
|
||||||
#![feature(let_chains)]
|
|
||||||
#![feature(extern_types)]
|
#![feature(extern_types)]
|
||||||
#![feature(once_cell)]
|
#![feature(hash_raw_entry)]
|
||||||
#![feature(iter_intersperse)]
|
#![feature(iter_intersperse)]
|
||||||
|
#![feature(let_chains)]
|
||||||
|
#![feature(never_type)]
|
||||||
|
#![feature(once_cell)]
|
||||||
#![recursion_limit = "256"]
|
#![recursion_limit = "256"]
|
||||||
#![allow(rustc::potential_query_instability)]
|
#![allow(rustc::potential_query_instability)]
|
||||||
#![deny(rustc::untranslatable_diagnostic)]
|
#![deny(rustc::untranslatable_diagnostic)]
|
||||||
|
@ -22,7 +23,7 @@ extern crate tracing;
|
||||||
|
|
||||||
use back::write::{create_informational_target_machine, create_target_machine};
|
use back::write::{create_informational_target_machine, create_target_machine};
|
||||||
|
|
||||||
use errors::FailParsingTargetMachineConfigToTargetMachine;
|
use errors::ParseTargetMachineConfig;
|
||||||
pub use llvm_util::target_features;
|
pub use llvm_util::target_features;
|
||||||
use rustc_ast::expand::allocator::AllocatorKind;
|
use rustc_ast::expand::allocator::AllocatorKind;
|
||||||
use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule};
|
use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule};
|
||||||
|
@ -169,6 +170,7 @@ impl WriteBackendMethods for LlvmCodegenBackend {
|
||||||
type Module = ModuleLlvm;
|
type Module = ModuleLlvm;
|
||||||
type ModuleBuffer = back::lto::ModuleBuffer;
|
type ModuleBuffer = back::lto::ModuleBuffer;
|
||||||
type TargetMachine = &'static mut llvm::TargetMachine;
|
type TargetMachine = &'static mut llvm::TargetMachine;
|
||||||
|
type TargetMachineError = crate::errors::LlvmError<'static>;
|
||||||
type ThinData = back::lto::ThinData;
|
type ThinData = back::lto::ThinData;
|
||||||
type ThinBuffer = back::lto::ThinBuffer;
|
type ThinBuffer = back::lto::ThinBuffer;
|
||||||
fn print_pass_timings(&self) {
|
fn print_pass_timings(&self) {
|
||||||
|
@ -416,8 +418,7 @@ impl ModuleLlvm {
|
||||||
let tm = match (cgcx.tm_factory)(tm_factory_config) {
|
let tm = match (cgcx.tm_factory)(tm_factory_config) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
handler.emit_err(FailParsingTargetMachineConfigToTargetMachine { error: e });
|
return Err(handler.emit_almost_fatal(ParseTargetMachineConfig(e)));
|
||||||
return Err(FatalError);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -305,8 +305,12 @@ impl TargetMachineFactoryConfig {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type TargetMachineFactoryFn<B> = Arc<
|
pub type TargetMachineFactoryFn<B> = Arc<
|
||||||
dyn Fn(TargetMachineFactoryConfig) -> Result<<B as WriteBackendMethods>::TargetMachine, String>
|
dyn Fn(
|
||||||
+ Send
|
TargetMachineFactoryConfig,
|
||||||
|
) -> Result<
|
||||||
|
<B as WriteBackendMethods>::TargetMachine,
|
||||||
|
<B as WriteBackendMethods>::TargetMachineError,
|
||||||
|
> + Send
|
||||||
+ Sync,
|
+ Sync,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ use rustc_middle::dep_graph::WorkProduct;
|
||||||
pub trait WriteBackendMethods: 'static + Sized + Clone {
|
pub trait WriteBackendMethods: 'static + Sized + Clone {
|
||||||
type Module: Send + Sync;
|
type Module: Send + Sync;
|
||||||
type TargetMachine;
|
type TargetMachine;
|
||||||
|
type TargetMachineError;
|
||||||
type ModuleBuffer: ModuleBufferMethods;
|
type ModuleBuffer: ModuleBufferMethods;
|
||||||
type ThinData: Send + Sync;
|
type ThinData: Send + Sync;
|
||||||
type ThinBuffer: ThinBufferMethods;
|
type ThinBuffer: ThinBufferMethods;
|
||||||
|
|
|
@ -43,7 +43,6 @@ use rustc_span::source_map::{FileLoader, FileName};
|
||||||
use rustc_span::symbol::sym;
|
use rustc_span::symbol::sym;
|
||||||
use rustc_target::json::ToJson;
|
use rustc_target::json::ToJson;
|
||||||
|
|
||||||
use std::borrow::Cow;
|
|
||||||
use std::cmp::max;
|
use std::cmp::max;
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
|
@ -1205,29 +1204,20 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
|
||||||
handler.emit_diagnostic(&mut d);
|
handler.emit_diagnostic(&mut d);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut xs: Vec<Cow<'static, str>> = vec![
|
handler.emit_note(session_diagnostics::Ice);
|
||||||
"the compiler unexpectedly panicked. this is a bug.".into(),
|
handler.emit_note(session_diagnostics::IceBugReport { bug_report_url });
|
||||||
format!("we would appreciate a bug report: {bug_report_url}").into(),
|
handler.emit_note(session_diagnostics::IceVersion {
|
||||||
format!(
|
version: util::version_str!().unwrap_or("unknown_version"),
|
||||||
"rustc {} running on {}",
|
triple: config::host_triple(),
|
||||||
util::version_str!().unwrap_or("unknown_version"),
|
});
|
||||||
config::host_triple()
|
|
||||||
)
|
|
||||||
.into(),
|
|
||||||
];
|
|
||||||
|
|
||||||
if let Some((flags, excluded_cargo_defaults)) = extra_compiler_flags() {
|
if let Some((flags, excluded_cargo_defaults)) = extra_compiler_flags() {
|
||||||
xs.push(format!("compiler flags: {}", flags.join(" ")).into());
|
handler.emit_note(session_diagnostics::IceFlags { flags: flags.join(" ") });
|
||||||
|
|
||||||
if excluded_cargo_defaults {
|
if excluded_cargo_defaults {
|
||||||
xs.push("some of the compiler flags provided by cargo are hidden".into());
|
handler.emit_note(session_diagnostics::IceExcludeCargoDefaults);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for note in &xs {
|
|
||||||
handler.note_without_error(note.as_ref());
|
|
||||||
}
|
|
||||||
|
|
||||||
// If backtraces are enabled, also print the query stack
|
// If backtraces are enabled, also print the query stack
|
||||||
let backtrace = env::var_os("RUST_BACKTRACE").map_or(false, |x| &x != "0");
|
let backtrace = env::var_os("RUST_BACKTRACE").map_or(false, |x| &x != "0");
|
||||||
|
|
||||||
|
|
|
@ -38,3 +38,30 @@ pub(crate) struct UnprettyDumpFail {
|
||||||
pub path: String,
|
pub path: String,
|
||||||
pub err: String,
|
pub err: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(driver_ice)]
|
||||||
|
pub(crate) struct Ice;
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(driver_ice_bug_report)]
|
||||||
|
pub(crate) struct IceBugReport<'a> {
|
||||||
|
pub bug_report_url: &'a str,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(driver_ice_version)]
|
||||||
|
pub(crate) struct IceVersion<'a> {
|
||||||
|
pub version: &'a str,
|
||||||
|
pub triple: &'a str,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(driver_ice_flags)]
|
||||||
|
pub(crate) struct IceFlags {
|
||||||
|
pub flags: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(driver_ice_exclude_cargo_defaults)]
|
||||||
|
pub(crate) struct IceExcludeCargoDefaults;
|
||||||
|
|
|
@ -39,5 +39,51 @@ codegen_llvm_dynamic_linking_with_lto =
|
||||||
cannot prefer dynamic linking when performing LTO
|
cannot prefer dynamic linking when performing LTO
|
||||||
.note = only 'staticlib', 'bin', and 'cdylib' outputs are supported with LTO
|
.note = only 'staticlib', 'bin', and 'cdylib' outputs are supported with LTO
|
||||||
|
|
||||||
codegen_llvm_fail_parsing_target_machine_config_to_target_machine =
|
codegen_llvm_parse_target_machine_config =
|
||||||
failed to parse target machine config to target machine: {$error}
|
failed to parse target machine config to target machine: {$error}
|
||||||
|
|
||||||
|
codegen_llvm_lto_disallowed = lto can only be run for executables, cdylibs and static library outputs
|
||||||
|
|
||||||
|
codegen_llvm_lto_dylib = lto cannot be used for `dylib` crate type without `-Zdylib-lto`
|
||||||
|
|
||||||
|
codegen_llvm_lto_bitcode_from_rlib = failed to get bitcode from object file for LTO ({$llvm_err})
|
||||||
|
|
||||||
|
codegen_llvm_write_output = could not write output to {$path}
|
||||||
|
codegen_llvm_write_output_with_llvm_err = could not write output to {$path}: {$llvm_err}
|
||||||
|
|
||||||
|
codegen_llvm_target_machine = could not create LLVM TargetMachine for triple: {$triple}
|
||||||
|
codegen_llvm_target_machine_with_llvm_err = could not create LLVM TargetMachine for triple: {$triple}: {$llvm_err}
|
||||||
|
|
||||||
|
codegen_llvm_run_passes = failed to run LLVM passes
|
||||||
|
codegen_llvm_run_passes_with_llvm_err = failed to run LLVM passes: {$llvm_err}
|
||||||
|
|
||||||
|
codegen_llvm_serialize_module = failed to serialize module {$name}
|
||||||
|
codegen_llvm_serialize_module_with_llvm_err = failed to serialize module {$name}: {$llvm_err}
|
||||||
|
|
||||||
|
codegen_llvm_write_ir = failed to write LLVM IR to {$path}
|
||||||
|
codegen_llvm_write_ir_with_llvm_err = failed to write LLVM IR to {$path}: {$llvm_err}
|
||||||
|
|
||||||
|
codegen_llvm_prepare_thin_lto_context = failed to prepare thin LTO context
|
||||||
|
codegen_llvm_prepare_thin_lto_context_with_llvm_err = failed to prepare thin LTO context: {$llvm_err}
|
||||||
|
|
||||||
|
codegen_llvm_load_bitcode = failed to load bitcode of module "{$name}"
|
||||||
|
codegen_llvm_load_bitcode_with_llvm_err = failed to load bitcode of module "{$name}": {$llvm_err}
|
||||||
|
|
||||||
|
codegen_llvm_write_thinlto_key = error while writing ThinLTO key data: {$err}
|
||||||
|
codegen_llvm_write_thinlto_key_with_llvm_err = error while writing ThinLTO key data: {$err}: {$llvm_err}
|
||||||
|
|
||||||
|
codegen_llvm_multiple_source_dicompileunit = multiple source DICompileUnits found
|
||||||
|
codegen_llvm_multiple_source_dicompileunit_with_llvm_err = multiple source DICompileUnits found: {$llvm_err}
|
||||||
|
|
||||||
|
codegen_llvm_prepare_thin_lto_module = failed to prepare thin LTO module
|
||||||
|
codegen_llvm_prepare_thin_lto_module_with_llvm_err = failed to prepare thin LTO module: {$llvm_err}
|
||||||
|
|
||||||
|
codegen_llvm_parse_bitcode = failed to parse bitcode for LTO module
|
||||||
|
codegen_llvm_parse_bitcode_with_llvm_err = failed to parse bitcode for LTO module: {$llvm_err}
|
||||||
|
|
||||||
|
codegen_llvm_from_llvm_optimization_diag = {$filename}:{$line}:{$column} {$pass_name}: {$message}
|
||||||
|
codegen_llvm_from_llvm_diag = {$message}
|
||||||
|
|
||||||
|
codegen_llvm_write_bytecode = failed to write bytecode to {$path}: {$err}
|
||||||
|
|
||||||
|
codegen_llvm_copy_bitcode = failed to copy bitcode to object file: {$err}
|
||||||
|
|
|
@ -11,3 +11,9 @@ driver_rlink_rustc_version_mismatch = .rlink file was produced by rustc version
|
||||||
driver_rlink_no_a_file = rlink must be a file
|
driver_rlink_no_a_file = rlink must be a file
|
||||||
|
|
||||||
driver_unpretty_dump_fail = pretty-print failed to write `{$path}` due to error `{$err}`
|
driver_unpretty_dump_fail = pretty-print failed to write `{$path}` due to error `{$err}`
|
||||||
|
|
||||||
|
driver_ice = the compiler unexpectedly panicked. this is a bug.
|
||||||
|
driver_ice_bug_report = we would appreciate a bug report: {$bug_report_url}
|
||||||
|
driver_ice_version = rustc {$version} running on {$triple}
|
||||||
|
driver_ice_flags = compiler flags: {$flags}
|
||||||
|
driver_ice_exclude_cargo_defaults = some of the compiler flags provided by cargo are hidden
|
||||||
|
|
|
@ -127,3 +127,5 @@ expand_module_file_not_found =
|
||||||
expand_module_multiple_candidates =
|
expand_module_multiple_candidates =
|
||||||
file for module `{$name}` found at both "{$default_path}" and "{$secondary_path}"
|
file for module `{$name}` found at both "{$default_path}" and "{$secondary_path}"
|
||||||
.help = delete or rename one of them to remove the ambiguity
|
.help = delete or rename one of them to remove the ambiguity
|
||||||
|
|
||||||
|
expand_trace_macro = trace_macro
|
||||||
|
|
|
@ -44,3 +44,13 @@ interface_failed_writing_file =
|
||||||
|
|
||||||
interface_proc_macro_crate_panic_abort =
|
interface_proc_macro_crate_panic_abort =
|
||||||
building proc macro crate with `panic=abort` may crash the compiler should the proc-macro panic
|
building proc macro crate with `panic=abort` may crash the compiler should the proc-macro panic
|
||||||
|
|
||||||
|
interface_unsupported_crate_type_for_target =
|
||||||
|
dropping unsupported crate type `{$crate_type}` for target `{$target_triple}`
|
||||||
|
|
||||||
|
interface_multiple_output_types_adaption =
|
||||||
|
due to multiple output types requested, the explicitly specified output file name will be adapted for each output type
|
||||||
|
|
||||||
|
interface_ignoring_extra_filename = ignoring -C extra-filename flag due to -o flag
|
||||||
|
|
||||||
|
interface_ignoring_out_dir = ignoring --out-dir flag due to -o flag
|
||||||
|
|
|
@ -24,3 +24,9 @@ monomorphize_large_assignments =
|
||||||
|
|
||||||
monomorphize_couldnt_dump_mono_stats =
|
monomorphize_couldnt_dump_mono_stats =
|
||||||
unexpected error occurred while dumping monomorphization stats: {$error}
|
unexpected error occurred while dumping monomorphization stats: {$error}
|
||||||
|
|
||||||
|
monomorphize_encountered_error_while_instantiating =
|
||||||
|
the above error was encountered while instantiating `{$formatted_item}`
|
||||||
|
|
||||||
|
monomorphize_unknown_cgu_collection_mode =
|
||||||
|
unknown codegen-item collection mode '{$mode}', falling back to 'lazy' mode
|
||||||
|
|
|
@ -731,3 +731,5 @@ passes_proc_macro_missing_args = mismatched {$kind} signature
|
||||||
passes_proc_macro_invalid_abi = proc macro functions may not be `extern "{$abi}"`
|
passes_proc_macro_invalid_abi = proc macro functions may not be `extern "{$abi}"`
|
||||||
|
|
||||||
passes_proc_macro_unsafe = proc macro functions may not be `unsafe`
|
passes_proc_macro_unsafe = proc macro functions may not be `unsafe`
|
||||||
|
|
||||||
|
passes_skipping_const_checks = skipping const checks
|
||||||
|
|
|
@ -89,3 +89,5 @@ session_int_literal_too_large = integer literal is too large
|
||||||
|
|
||||||
session_invalid_int_literal_width = invalid width `{$width}` for integer literal
|
session_invalid_int_literal_width = invalid width `{$width}` for integer literal
|
||||||
.help = valid widths are 8, 16, 32, 64 and 128
|
.help = valid widths are 8, 16, 32, 64 and 128
|
||||||
|
|
||||||
|
session_optimization_fuel_exhausted = optimization-fuel-exhausted: {$msg}
|
||||||
|
|
|
@ -1051,6 +1051,7 @@ impl Diagnostic {
|
||||||
) -> (
|
) -> (
|
||||||
&Level,
|
&Level,
|
||||||
&[(DiagnosticMessage, Style)],
|
&[(DiagnosticMessage, Style)],
|
||||||
|
Vec<(&Cow<'static, str>, &DiagnosticArgValue<'static>)>,
|
||||||
&Option<DiagnosticId>,
|
&Option<DiagnosticId>,
|
||||||
&MultiSpan,
|
&MultiSpan,
|
||||||
&Result<Vec<CodeSuggestion>, SuggestionsDisabled>,
|
&Result<Vec<CodeSuggestion>, SuggestionsDisabled>,
|
||||||
|
@ -1059,6 +1060,7 @@ impl Diagnostic {
|
||||||
(
|
(
|
||||||
&self.level,
|
&self.level,
|
||||||
&self.message,
|
&self.message,
|
||||||
|
self.args().collect(),
|
||||||
&self.code,
|
&self.code,
|
||||||
&self.span,
|
&self.span,
|
||||||
&self.suggestions,
|
&self.suggestions,
|
||||||
|
|
|
@ -408,6 +408,59 @@ impl EmissionGuarantee for ! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a> DiagnosticBuilder<'a, rustc_span::fatal_error::FatalError> {
|
||||||
|
/// Convenience function for internal use, clients should use one of the
|
||||||
|
/// `struct_*` methods on [`Handler`].
|
||||||
|
#[track_caller]
|
||||||
|
pub(crate) fn new_almost_fatal(
|
||||||
|
handler: &'a Handler,
|
||||||
|
message: impl Into<DiagnosticMessage>,
|
||||||
|
) -> Self {
|
||||||
|
let diagnostic = Diagnostic::new_with_code(Level::Fatal, None, message);
|
||||||
|
Self::new_diagnostic_almost_fatal(handler, diagnostic)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a new `DiagnosticBuilder` with an already constructed
|
||||||
|
/// diagnostic.
|
||||||
|
pub(crate) fn new_diagnostic_almost_fatal(
|
||||||
|
handler: &'a Handler,
|
||||||
|
diagnostic: Diagnostic,
|
||||||
|
) -> Self {
|
||||||
|
debug!("Created new diagnostic");
|
||||||
|
Self {
|
||||||
|
inner: DiagnosticBuilderInner {
|
||||||
|
state: DiagnosticBuilderState::Emittable(handler),
|
||||||
|
diagnostic: Box::new(diagnostic),
|
||||||
|
},
|
||||||
|
_marker: PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl EmissionGuarantee for rustc_span::fatal_error::FatalError {
|
||||||
|
fn diagnostic_builder_emit_producing_guarantee(db: &mut DiagnosticBuilder<'_, Self>) -> Self {
|
||||||
|
match db.inner.state {
|
||||||
|
// First `.emit()` call, the `&Handler` is still available.
|
||||||
|
DiagnosticBuilderState::Emittable(handler) => {
|
||||||
|
db.inner.state = DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation;
|
||||||
|
|
||||||
|
handler.emit_diagnostic(&mut db.inner.diagnostic);
|
||||||
|
}
|
||||||
|
// `.emit()` was previously called, disallowed from repeating it.
|
||||||
|
DiagnosticBuilderState::AlreadyEmittedOrDuringCancellation => {}
|
||||||
|
}
|
||||||
|
// Then fatally error..
|
||||||
|
rustc_span::fatal_error::FatalError
|
||||||
|
}
|
||||||
|
|
||||||
|
fn make_diagnostic_builder(
|
||||||
|
handler: &Handler,
|
||||||
|
msg: impl Into<DiagnosticMessage>,
|
||||||
|
) -> DiagnosticBuilder<'_, Self> {
|
||||||
|
DiagnosticBuilder::new_almost_fatal(handler, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// In general, the `DiagnosticBuilder` uses deref to allow access to
|
/// In general, the `DiagnosticBuilder` uses deref to allow access to
|
||||||
/// the fields and methods of the embedded `diagnostic` in a
|
/// the fields and methods of the embedded `diagnostic` in a
|
||||||
/// transparent way. *However,* many of the methods are intended to
|
/// transparent way. *However,* many of the methods are intended to
|
||||||
|
|
|
@ -159,12 +159,6 @@ impl IntoDiagnosticArg for ast::Path {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl IntoDiagnosticArg for &ast::Path {
|
|
||||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
|
||||||
DiagnosticArgValue::Str(Cow::Owned(pprust::path_to_string(self)))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IntoDiagnosticArg for ast::token::Token {
|
impl IntoDiagnosticArg for ast::token::Token {
|
||||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||||
DiagnosticArgValue::Str(pprust::token_to_string(&self))
|
DiagnosticArgValue::Str(pprust::token_to_string(&self))
|
||||||
|
@ -183,6 +177,18 @@ impl IntoDiagnosticArg for type_ir::FloatTy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl IntoDiagnosticArg for std::ffi::CString {
|
||||||
|
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||||
|
DiagnosticArgValue::Str(Cow::Owned(self.to_string_lossy().into_owned()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntoDiagnosticArg for rustc_data_structures::small_c_str::SmallCStr {
|
||||||
|
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||||
|
DiagnosticArgValue::Str(Cow::Owned(self.to_string_lossy().into_owned()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl IntoDiagnosticArg for Level {
|
impl IntoDiagnosticArg for Level {
|
||||||
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
fn into_diagnostic_arg(self) -> DiagnosticArgValue<'static> {
|
||||||
DiagnosticArgValue::Str(Cow::Borrowed(self.to_cmd_flag()))
|
DiagnosticArgValue::Str(Cow::Borrowed(self.to_cmd_flag()))
|
||||||
|
|
|
@ -617,22 +617,24 @@ impl Handler {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Translate `message` eagerly with `args`.
|
/// Translate `message` eagerly with `args` to `SubdiagnosticMessage::Eager`.
|
||||||
pub fn eagerly_translate<'a>(
|
pub fn eagerly_translate<'a>(
|
||||||
&self,
|
&self,
|
||||||
message: DiagnosticMessage,
|
message: DiagnosticMessage,
|
||||||
args: impl Iterator<Item = DiagnosticArg<'a, 'static>>,
|
args: impl Iterator<Item = DiagnosticArg<'a, 'static>>,
|
||||||
) -> SubdiagnosticMessage {
|
) -> SubdiagnosticMessage {
|
||||||
|
SubdiagnosticMessage::Eager(self.eagerly_translate_to_string(message, args))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Translate `message` eagerly with `args` to `String`.
|
||||||
|
pub fn eagerly_translate_to_string<'a>(
|
||||||
|
&self,
|
||||||
|
message: DiagnosticMessage,
|
||||||
|
args: impl Iterator<Item = DiagnosticArg<'a, 'static>>,
|
||||||
|
) -> String {
|
||||||
let inner = self.inner.borrow();
|
let inner = self.inner.borrow();
|
||||||
let args = crate::translation::to_fluent_args(args);
|
let args = crate::translation::to_fluent_args(args);
|
||||||
SubdiagnosticMessage::Eager(
|
inner.emitter.translate_message(&message, &args).map_err(Report::new).unwrap().to_string()
|
||||||
inner
|
|
||||||
.emitter
|
|
||||||
.translate_message(&message, &args)
|
|
||||||
.map_err(Report::new)
|
|
||||||
.unwrap()
|
|
||||||
.to_string(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This is here to not allow mutation of flags;
|
// This is here to not allow mutation of flags;
|
||||||
|
@ -1010,6 +1012,7 @@ impl Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
|
#[rustc_lint_diagnostics]
|
||||||
pub fn span_note_without_error(
|
pub fn span_note_without_error(
|
||||||
&self,
|
&self,
|
||||||
span: impl Into<MultiSpan>,
|
span: impl Into<MultiSpan>,
|
||||||
|
@ -1019,6 +1022,7 @@ impl Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
|
#[rustc_lint_diagnostics]
|
||||||
pub fn span_note_diag(
|
pub fn span_note_diag(
|
||||||
&self,
|
&self,
|
||||||
span: Span,
|
span: Span,
|
||||||
|
@ -1030,19 +1034,23 @@ impl Handler {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: intentionally doesn't raise an error so rustc_codegen_ssa only reports fatal errors in the main thread
|
// NOTE: intentionally doesn't raise an error so rustc_codegen_ssa only reports fatal errors in the main thread
|
||||||
|
#[rustc_lint_diagnostics]
|
||||||
pub fn fatal(&self, msg: impl Into<DiagnosticMessage>) -> FatalError {
|
pub fn fatal(&self, msg: impl Into<DiagnosticMessage>) -> FatalError {
|
||||||
self.inner.borrow_mut().fatal(msg)
|
self.inner.borrow_mut().fatal(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[rustc_lint_diagnostics]
|
||||||
pub fn err(&self, msg: impl Into<DiagnosticMessage>) -> ErrorGuaranteed {
|
pub fn err(&self, msg: impl Into<DiagnosticMessage>) -> ErrorGuaranteed {
|
||||||
self.inner.borrow_mut().err(msg)
|
self.inner.borrow_mut().err(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[rustc_lint_diagnostics]
|
||||||
pub fn warn(&self, msg: impl Into<DiagnosticMessage>) {
|
pub fn warn(&self, msg: impl Into<DiagnosticMessage>) {
|
||||||
let mut db = DiagnosticBuilder::new(self, Warning(None), msg);
|
let mut db = DiagnosticBuilder::new(self, Warning(None), msg);
|
||||||
db.emit();
|
db.emit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[rustc_lint_diagnostics]
|
||||||
pub fn note_without_error(&self, msg: impl Into<DiagnosticMessage>) {
|
pub fn note_without_error(&self, msg: impl Into<DiagnosticMessage>) {
|
||||||
DiagnosticBuilder::new(self, Note, msg).emit();
|
DiagnosticBuilder::new(self, Note, msg).emit();
|
||||||
}
|
}
|
||||||
|
@ -1059,6 +1067,7 @@ impl Handler {
|
||||||
pub fn has_errors(&self) -> Option<ErrorGuaranteed> {
|
pub fn has_errors(&self) -> Option<ErrorGuaranteed> {
|
||||||
if self.inner.borrow().has_errors() { Some(ErrorGuaranteed(())) } else { None }
|
if self.inner.borrow().has_errors() { Some(ErrorGuaranteed(())) } else { None }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn has_errors_or_lint_errors(&self) -> Option<ErrorGuaranteed> {
|
pub fn has_errors_or_lint_errors(&self) -> Option<ErrorGuaranteed> {
|
||||||
if self.inner.borrow().has_errors_or_lint_errors() {
|
if self.inner.borrow().has_errors_or_lint_errors() {
|
||||||
Some(ErrorGuaranteed::unchecked_claim_error_was_emitted())
|
Some(ErrorGuaranteed::unchecked_claim_error_was_emitted())
|
||||||
|
@ -1132,6 +1141,20 @@ impl Handler {
|
||||||
self.create_warning(warning).emit()
|
self.create_warning(warning).emit()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn create_almost_fatal<'a>(
|
||||||
|
&'a self,
|
||||||
|
fatal: impl IntoDiagnostic<'a, FatalError>,
|
||||||
|
) -> DiagnosticBuilder<'a, FatalError> {
|
||||||
|
fatal.into_diagnostic(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn emit_almost_fatal<'a>(
|
||||||
|
&'a self,
|
||||||
|
fatal: impl IntoDiagnostic<'a, FatalError>,
|
||||||
|
) -> FatalError {
|
||||||
|
self.create_almost_fatal(fatal).emit()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn create_fatal<'a>(
|
pub fn create_fatal<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
fatal: impl IntoDiagnostic<'a, !>,
|
fatal: impl IntoDiagnostic<'a, !>,
|
||||||
|
|
|
@ -4,7 +4,7 @@ use crate::errors::{
|
||||||
ArgumentNotAttributes, AttrNoArguments, AttributeMetaItem, AttributeSingleWord,
|
ArgumentNotAttributes, AttrNoArguments, AttributeMetaItem, AttributeSingleWord,
|
||||||
AttributesWrongForm, CannotBeNameOfMacro, ExpectedCommaInList, HelperAttributeNameInvalid,
|
AttributesWrongForm, CannotBeNameOfMacro, ExpectedCommaInList, HelperAttributeNameInvalid,
|
||||||
MacroBodyStability, MacroConstStability, NotAMetaItem, OnlyOneArgument, OnlyOneWord,
|
MacroBodyStability, MacroConstStability, NotAMetaItem, OnlyOneArgument, OnlyOneWord,
|
||||||
ResolveRelativePath, TakesNoArguments,
|
ResolveRelativePath, TakesNoArguments, TraceMacro,
|
||||||
};
|
};
|
||||||
use crate::expand::{self, AstFragment, Invocation};
|
use crate::expand::{self, AstFragment, Invocation};
|
||||||
use crate::module::DirOwnership;
|
use crate::module::DirOwnership;
|
||||||
|
@ -1142,8 +1142,8 @@ impl<'a> ExtCtxt<'a> {
|
||||||
self.sess.parse_sess.span_diagnostic.span_bug(sp, msg);
|
self.sess.parse_sess.span_diagnostic.span_bug(sp, msg);
|
||||||
}
|
}
|
||||||
pub fn trace_macros_diag(&mut self) {
|
pub fn trace_macros_diag(&mut self) {
|
||||||
for (sp, notes) in self.expansions.iter() {
|
for (span, notes) in self.expansions.iter() {
|
||||||
let mut db = self.sess.parse_sess.span_diagnostic.span_note_diag(*sp, "trace_macro");
|
let mut db = self.sess.parse_sess.create_note(TraceMacro { span: *span });
|
||||||
for note in notes {
|
for note in notes {
|
||||||
db.note(note);
|
db.note(note);
|
||||||
}
|
}
|
||||||
|
|
|
@ -368,3 +368,10 @@ pub(crate) struct ModuleMultipleCandidates {
|
||||||
pub default_path: String,
|
pub default_path: String,
|
||||||
pub secondary_path: String,
|
pub secondary_path: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(expand_trace_macro)]
|
||||||
|
pub struct TraceMacro {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
}
|
||||||
|
|
|
@ -49,9 +49,6 @@ rustc_target = { path = "../rustc_target" }
|
||||||
rustc_trait_selection = { path = "../rustc_trait_selection" }
|
rustc_trait_selection = { path = "../rustc_trait_selection" }
|
||||||
rustc_ty_utils = { path = "../rustc_ty_utils" }
|
rustc_ty_utils = { path = "../rustc_ty_utils" }
|
||||||
|
|
||||||
[dev-dependencies]
|
|
||||||
rustc_target = { path = "../rustc_target" }
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
llvm = ['rustc_codegen_llvm']
|
llvm = ['rustc_codegen_llvm']
|
||||||
rustc_use_parallel_compiler = ['rayon', 'rustc-rayon-core', 'rustc_query_impl/rustc_use_parallel_compiler', 'rustc_errors/rustc_use_parallel_compiler']
|
rustc_use_parallel_compiler = ['rayon', 'rustc-rayon-core', 'rustc_query_impl/rustc_use_parallel_compiler', 'rustc_errors/rustc_use_parallel_compiler']
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
use rustc_macros::Diagnostic;
|
use rustc_macros::Diagnostic;
|
||||||
|
use rustc_session::config::CrateType;
|
||||||
use rustc_span::{Span, Symbol};
|
use rustc_span::{Span, Symbol};
|
||||||
|
use rustc_target::spec::TargetTriple;
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
@ -91,3 +93,22 @@ pub struct FailedWritingFile<'a> {
|
||||||
#[derive(Diagnostic)]
|
#[derive(Diagnostic)]
|
||||||
#[diag(interface_proc_macro_crate_panic_abort)]
|
#[diag(interface_proc_macro_crate_panic_abort)]
|
||||||
pub struct ProcMacroCratePanicAbort;
|
pub struct ProcMacroCratePanicAbort;
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(interface_unsupported_crate_type_for_target)]
|
||||||
|
pub struct UnsupportedCrateTypeForTarget<'a> {
|
||||||
|
pub crate_type: CrateType,
|
||||||
|
pub target_triple: &'a TargetTriple,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(interface_multiple_output_types_adaption)]
|
||||||
|
pub struct MultipleOutputTypesAdaption;
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(interface_ignoring_extra_filename)]
|
||||||
|
pub struct IgnoringExtraFilename;
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(interface_ignoring_out_dir)]
|
||||||
|
pub struct IgnoringOutDir;
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::errors;
|
||||||
use info;
|
use info;
|
||||||
use libloading::Library;
|
use libloading::Library;
|
||||||
use rustc_ast as ast;
|
use rustc_ast as ast;
|
||||||
|
@ -472,16 +473,15 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<C
|
||||||
}
|
}
|
||||||
|
|
||||||
base.retain(|crate_type| {
|
base.retain(|crate_type| {
|
||||||
let res = !output::invalid_output_for_target(session, *crate_type);
|
if output::invalid_output_for_target(session, *crate_type) {
|
||||||
|
session.emit_warning(errors::UnsupportedCrateTypeForTarget {
|
||||||
if !res {
|
crate_type: *crate_type,
|
||||||
session.warn(&format!(
|
target_triple: &session.opts.target_triple,
|
||||||
"dropping unsupported crate type `{}` for target `{}`",
|
});
|
||||||
*crate_type, session.opts.target_triple
|
false
|
||||||
));
|
} else {
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
res
|
|
||||||
});
|
});
|
||||||
|
|
||||||
base
|
base
|
||||||
|
@ -517,19 +517,16 @@ pub fn build_output_filenames(attrs: &[ast::Attribute], sess: &Session) -> Outpu
|
||||||
let unnamed_output_types =
|
let unnamed_output_types =
|
||||||
sess.opts.output_types.values().filter(|a| a.is_none()).count();
|
sess.opts.output_types.values().filter(|a| a.is_none()).count();
|
||||||
let ofile = if unnamed_output_types > 1 {
|
let ofile = if unnamed_output_types > 1 {
|
||||||
sess.warn(
|
sess.emit_warning(errors::MultipleOutputTypesAdaption);
|
||||||
"due to multiple output types requested, the explicitly specified \
|
|
||||||
output file name will be adapted for each output type",
|
|
||||||
);
|
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
if !sess.opts.cg.extra_filename.is_empty() {
|
if !sess.opts.cg.extra_filename.is_empty() {
|
||||||
sess.warn("ignoring -C extra-filename flag due to -o flag");
|
sess.emit_warning(errors::IgnoringExtraFilename);
|
||||||
}
|
}
|
||||||
Some(out_file.clone())
|
Some(out_file.clone())
|
||||||
};
|
};
|
||||||
if sess.io.output_dir != None {
|
if sess.io.output_dir != None {
|
||||||
sess.warn("ignoring --out-dir flag due to -o flag");
|
sess.emit_warning(errors::IgnoringOutDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
OutputFilenames::new(
|
OutputFilenames::new(
|
||||||
|
|
|
@ -201,7 +201,9 @@ use rustc_target::abi::Size;
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use crate::errors::{LargeAssignmentsLint, RecursionLimit, TypeLengthLimit};
|
use crate::errors::{
|
||||||
|
EncounteredErrorWhileInstantiating, LargeAssignmentsLint, RecursionLimit, TypeLengthLimit,
|
||||||
|
};
|
||||||
|
|
||||||
#[derive(PartialEq)]
|
#[derive(PartialEq)]
|
||||||
pub enum MonoItemCollectionMode {
|
pub enum MonoItemCollectionMode {
|
||||||
|
@ -524,10 +526,10 @@ fn collect_items_rec<'tcx>(
|
||||||
&& starting_point.node.is_user_defined()
|
&& starting_point.node.is_user_defined()
|
||||||
{
|
{
|
||||||
let formatted_item = with_no_trimmed_paths!(starting_point.node.to_string());
|
let formatted_item = with_no_trimmed_paths!(starting_point.node.to_string());
|
||||||
tcx.sess.span_note_without_error(
|
tcx.sess.emit_note(EncounteredErrorWhileInstantiating {
|
||||||
starting_point.span,
|
span: starting_point.span,
|
||||||
&format!("the above error was encountered while instantiating `{formatted_item}`"),
|
formatted_item,
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
inlining_map.lock_mut().record_accesses(starting_point.node, &neighbors.items);
|
inlining_map.lock_mut().record_accesses(starting_point.node, &neighbors.items);
|
||||||
|
|
||||||
|
|
|
@ -83,3 +83,17 @@ pub struct SymbolAlreadyDefined {
|
||||||
pub struct CouldntDumpMonoStats {
|
pub struct CouldntDumpMonoStats {
|
||||||
pub error: String,
|
pub error: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(monomorphize_encountered_error_while_instantiating)]
|
||||||
|
pub struct EncounteredErrorWhileInstantiating {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
pub formatted_item: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(monomorphize_unknown_cgu_collection_mode)]
|
||||||
|
pub struct UnknownCguCollectionMode<'a> {
|
||||||
|
pub mode: &'a str,
|
||||||
|
}
|
||||||
|
|
|
@ -114,7 +114,9 @@ use rustc_span::symbol::Symbol;
|
||||||
|
|
||||||
use crate::collector::InliningMap;
|
use crate::collector::InliningMap;
|
||||||
use crate::collector::{self, MonoItemCollectionMode};
|
use crate::collector::{self, MonoItemCollectionMode};
|
||||||
use crate::errors::{CouldntDumpMonoStats, SymbolAlreadyDefined, UnknownPartitionStrategy};
|
use crate::errors::{
|
||||||
|
CouldntDumpMonoStats, SymbolAlreadyDefined, UnknownCguCollectionMode, UnknownPartitionStrategy,
|
||||||
|
};
|
||||||
|
|
||||||
pub struct PartitioningCx<'a, 'tcx> {
|
pub struct PartitioningCx<'a, 'tcx> {
|
||||||
tcx: TyCtxt<'tcx>,
|
tcx: TyCtxt<'tcx>,
|
||||||
|
@ -348,17 +350,13 @@ where
|
||||||
fn collect_and_partition_mono_items(tcx: TyCtxt<'_>, (): ()) -> (&DefIdSet, &[CodegenUnit<'_>]) {
|
fn collect_and_partition_mono_items(tcx: TyCtxt<'_>, (): ()) -> (&DefIdSet, &[CodegenUnit<'_>]) {
|
||||||
let collection_mode = match tcx.sess.opts.unstable_opts.print_mono_items {
|
let collection_mode = match tcx.sess.opts.unstable_opts.print_mono_items {
|
||||||
Some(ref s) => {
|
Some(ref s) => {
|
||||||
let mode_string = s.to_lowercase();
|
let mode = s.to_lowercase();
|
||||||
let mode_string = mode_string.trim();
|
let mode = mode.trim();
|
||||||
if mode_string == "eager" {
|
if mode == "eager" {
|
||||||
MonoItemCollectionMode::Eager
|
MonoItemCollectionMode::Eager
|
||||||
} else {
|
} else {
|
||||||
if mode_string != "lazy" {
|
if mode != "lazy" {
|
||||||
let message = format!(
|
tcx.sess.emit_warning(UnknownCguCollectionMode { mode });
|
||||||
"Unknown codegen-item collection mode '{mode_string}'. \
|
|
||||||
Falling back to 'lazy' mode."
|
|
||||||
);
|
|
||||||
tcx.sess.warn(&message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MonoItemCollectionMode::Lazy
|
MonoItemCollectionMode::Lazy
|
||||||
|
|
|
@ -17,7 +17,7 @@ use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_session::parse::feature_err;
|
use rustc_session::parse::feature_err;
|
||||||
use rustc_span::{sym, Span, Symbol};
|
use rustc_span::{sym, Span, Symbol};
|
||||||
|
|
||||||
use crate::errors::ExprNotAllowedInContext;
|
use crate::errors::{ExprNotAllowedInContext, SkippingConstChecks};
|
||||||
|
|
||||||
/// An expression that is not *always* legal in a const context.
|
/// An expression that is not *always* legal in a const context.
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
|
@ -124,7 +124,7 @@ impl<'tcx> CheckConstVisitor<'tcx> {
|
||||||
// corresponding feature gate. This encourages nightly users to use feature gates when
|
// corresponding feature gate. This encourages nightly users to use feature gates when
|
||||||
// possible.
|
// possible.
|
||||||
None if tcx.sess.opts.unstable_opts.unleash_the_miri_inside_of_you => {
|
None if tcx.sess.opts.unstable_opts.unleash_the_miri_inside_of_you => {
|
||||||
tcx.sess.span_warn(span, "skipping const checks");
|
tcx.sess.emit_warning(SkippingConstChecks { span });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1565,3 +1565,10 @@ pub(crate) struct ProcMacroUnsafe {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(passes_skipping_const_checks)]
|
||||||
|
pub struct SkippingConstChecks {
|
||||||
|
#[primary_span]
|
||||||
|
pub span: Span,
|
||||||
|
}
|
||||||
|
|
|
@ -375,3 +375,9 @@ pub fn report_lit_error(sess: &ParseSess, err: LitError, lit: token::Lit, span:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
#[diag(session_optimization_fuel_exhausted)]
|
||||||
|
pub struct OptimisationFuelExhausted {
|
||||||
|
pub msg: String,
|
||||||
|
}
|
||||||
|
|
|
@ -5,9 +5,10 @@ use crate::config::Input;
|
||||||
use crate::config::{self, CrateType, InstrumentCoverage, OptLevel, OutputType, SwitchWithOptPath};
|
use crate::config::{self, CrateType, InstrumentCoverage, OptLevel, OutputType, SwitchWithOptPath};
|
||||||
use crate::errors::{
|
use crate::errors::{
|
||||||
BranchProtectionRequiresAArch64, CannotEnableCrtStaticLinux, CannotMixAndMatchSanitizers,
|
BranchProtectionRequiresAArch64, CannotEnableCrtStaticLinux, CannotMixAndMatchSanitizers,
|
||||||
LinkerPluginToWindowsNotSupported, NotCircumventFeature, ProfileSampleUseFileDoesNotExist,
|
LinkerPluginToWindowsNotSupported, NotCircumventFeature, OptimisationFuelExhausted,
|
||||||
ProfileUseFileDoesNotExist, SanitizerCfiEnabled, SanitizerNotSupported, SanitizersNotSupported,
|
ProfileSampleUseFileDoesNotExist, ProfileUseFileDoesNotExist, SanitizerCfiEnabled,
|
||||||
SkippingConstChecks, SplitDebugInfoUnstablePlatform, StackProtectorNotSupportedForTarget,
|
SanitizerNotSupported, SanitizersNotSupported, SkippingConstChecks,
|
||||||
|
SplitDebugInfoUnstablePlatform, StackProtectorNotSupportedForTarget,
|
||||||
TargetRequiresUnwindTables, UnleashedFeatureHelp, UnstableVirtualFunctionElimination,
|
TargetRequiresUnwindTables, UnleashedFeatureHelp, UnstableVirtualFunctionElimination,
|
||||||
UnsupportedDwarfVersion,
|
UnsupportedDwarfVersion,
|
||||||
};
|
};
|
||||||
|
@ -483,6 +484,8 @@ impl Session {
|
||||||
self.diagnostic().span_err_with_code(sp, msg, code)
|
self.diagnostic().span_err_with_code(sp, msg, code)
|
||||||
}
|
}
|
||||||
#[rustc_lint_diagnostics]
|
#[rustc_lint_diagnostics]
|
||||||
|
#[allow(rustc::untranslatable_diagnostic)]
|
||||||
|
#[allow(rustc::diagnostic_outside_of_impl)]
|
||||||
pub fn err(&self, msg: impl Into<DiagnosticMessage>) -> ErrorGuaranteed {
|
pub fn err(&self, msg: impl Into<DiagnosticMessage>) -> ErrorGuaranteed {
|
||||||
self.diagnostic().err(msg)
|
self.diagnostic().err(msg)
|
||||||
}
|
}
|
||||||
|
@ -583,12 +586,16 @@ impl Session {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[rustc_lint_diagnostics]
|
||||||
#[allow(rustc::untranslatable_diagnostic)]
|
#[allow(rustc::untranslatable_diagnostic)]
|
||||||
#[allow(rustc::diagnostic_outside_of_impl)]
|
#[allow(rustc::diagnostic_outside_of_impl)]
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: impl Into<DiagnosticMessage>) {
|
pub fn span_warn<S: Into<MultiSpan>>(&self, sp: S, msg: impl Into<DiagnosticMessage>) {
|
||||||
self.diagnostic().span_warn(sp, msg)
|
self.diagnostic().span_warn(sp, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[rustc_lint_diagnostics]
|
||||||
#[allow(rustc::untranslatable_diagnostic)]
|
#[allow(rustc::untranslatable_diagnostic)]
|
||||||
#[allow(rustc::diagnostic_outside_of_impl)]
|
#[allow(rustc::diagnostic_outside_of_impl)]
|
||||||
pub fn span_warn_with_code<S: Into<MultiSpan>>(
|
pub fn span_warn_with_code<S: Into<MultiSpan>>(
|
||||||
|
@ -599,6 +606,10 @@ impl Session {
|
||||||
) {
|
) {
|
||||||
self.diagnostic().span_warn_with_code(sp, msg, code)
|
self.diagnostic().span_warn_with_code(sp, msg, code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[rustc_lint_diagnostics]
|
||||||
|
#[allow(rustc::untranslatable_diagnostic)]
|
||||||
|
#[allow(rustc::diagnostic_outside_of_impl)]
|
||||||
pub fn warn(&self, msg: impl Into<DiagnosticMessage>) {
|
pub fn warn(&self, msg: impl Into<DiagnosticMessage>) {
|
||||||
self.diagnostic().warn(msg)
|
self.diagnostic().warn(msg)
|
||||||
}
|
}
|
||||||
|
@ -641,11 +652,17 @@ impl Session {
|
||||||
self.diagnostic().delay_good_path_bug(msg)
|
self.diagnostic().delay_good_path_bug(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[rustc_lint_diagnostics]
|
||||||
|
#[allow(rustc::untranslatable_diagnostic)]
|
||||||
|
#[allow(rustc::diagnostic_outside_of_impl)]
|
||||||
pub fn note_without_error(&self, msg: impl Into<DiagnosticMessage>) {
|
pub fn note_without_error(&self, msg: impl Into<DiagnosticMessage>) {
|
||||||
self.diagnostic().note_without_error(msg)
|
self.diagnostic().note_without_error(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
|
#[rustc_lint_diagnostics]
|
||||||
|
#[allow(rustc::untranslatable_diagnostic)]
|
||||||
|
#[allow(rustc::diagnostic_outside_of_impl)]
|
||||||
pub fn span_note_without_error<S: Into<MultiSpan>>(
|
pub fn span_note_without_error<S: Into<MultiSpan>>(
|
||||||
&self,
|
&self,
|
||||||
sp: S,
|
sp: S,
|
||||||
|
@ -653,6 +670,8 @@ impl Session {
|
||||||
) {
|
) {
|
||||||
self.diagnostic().span_note_without_error(sp, msg)
|
self.diagnostic().span_note_without_error(sp, msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[rustc_lint_diagnostics]
|
||||||
#[allow(rustc::untranslatable_diagnostic)]
|
#[allow(rustc::untranslatable_diagnostic)]
|
||||||
#[allow(rustc::diagnostic_outside_of_impl)]
|
#[allow(rustc::diagnostic_outside_of_impl)]
|
||||||
pub fn struct_note_without_error(
|
pub fn struct_note_without_error(
|
||||||
|
@ -882,7 +901,7 @@ impl Session {
|
||||||
// We only call `msg` in case we can actually emit warnings.
|
// We only call `msg` in case we can actually emit warnings.
|
||||||
// Otherwise, this could cause a `delay_good_path_bug` to
|
// Otherwise, this could cause a `delay_good_path_bug` to
|
||||||
// trigger (issue #79546).
|
// trigger (issue #79546).
|
||||||
self.warn(&format!("optimization-fuel-exhausted: {}", msg()));
|
self.emit_warning(OptimisationFuelExhausted { msg: msg() });
|
||||||
}
|
}
|
||||||
fuel.out_of_fuel = true;
|
fuel.out_of_fuel = true;
|
||||||
} else if fuel.remaining > 0 {
|
} else if fuel.remaining > 0 {
|
||||||
|
|
Loading…
Add table
Reference in a new issue