diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2023-12-18 22:21:37 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2023-12-24 08:05:28 +1100 |
| commit | 99472c7049783605444ab888a97059d0cce93a12 (patch) | |
| tree | 686e31682a9d9ae7601cf22722f1b43d3efea5db /compiler/rustc_codegen_ssa/src | |
| parent | d51db05d7ee1a12ee168f2d1ccc93ccc11b216c7 (diff) | |
| download | rust-99472c7049783605444ab888a97059d0cce93a12.tar.gz rust-99472c7049783605444ab888a97059d0cce93a12.zip | |
Remove `Session` methods that duplicate `DiagCtxt` methods.
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access.
Diffstat (limited to 'compiler/rustc_codegen_ssa/src')
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/assert_module_sources.rs | 16 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/archive.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/link.rs | 80 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/linker.rs | 22 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/back/write.rs | 15 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/base.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/codegen_attrs.rs | 51 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/mir/constant.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/mir/intrinsic.rs | 18 | ||||
| -rw-r--r-- | compiler/rustc_codegen_ssa/src/target_features.rs | 6 |
11 files changed, 111 insertions, 111 deletions
diff --git a/compiler/rustc_codegen_ssa/src/assert_module_sources.rs b/compiler/rustc_codegen_ssa/src/assert_module_sources.rs index a5bd10ecb34..094a61d6e0d 100644 --- a/compiler/rustc_codegen_ssa/src/assert_module_sources.rs +++ b/compiler/rustc_codegen_ssa/src/assert_module_sources.rs @@ -88,7 +88,7 @@ impl<'tcx> AssertModuleSource<'tcx> { sym::any => (CguReuse::PreLto, ComparisonKind::AtLeast), other => { self.tcx - .sess + .dcx() .emit_fatal(errors::UnknownReuseKind { span: attr.span, kind: other }); } } @@ -97,7 +97,7 @@ impl<'tcx> AssertModuleSource<'tcx> { }; if !self.tcx.sess.opts.unstable_opts.query_dep_graph { - self.tcx.sess.emit_fatal(errors::MissingQueryDepGraph { span: attr.span }); + self.tcx.dcx().emit_fatal(errors::MissingQueryDepGraph { span: attr.span }); } if !self.check_config(attr) { @@ -109,7 +109,7 @@ impl<'tcx> AssertModuleSource<'tcx> { let crate_name = self.tcx.crate_name(LOCAL_CRATE).to_string(); if !user_path.starts_with(&crate_name) { - self.tcx.sess.emit_fatal(errors::MalformedCguName { + self.tcx.dcx().emit_fatal(errors::MalformedCguName { span: attr.span, user_path, crate_name, @@ -139,7 +139,7 @@ impl<'tcx> AssertModuleSource<'tcx> { if !self.available_cgus.contains(&cgu_name) { let cgu_names: Vec<&str> = self.available_cgus.items().map(|cgu| cgu.as_str()).into_sorted_stable_ord(); - self.tcx.sess.emit_err(errors::NoModuleNamed { + self.tcx.dcx().emit_err(errors::NoModuleNamed { span: attr.span, user_path, cgu_name, @@ -162,7 +162,7 @@ impl<'tcx> AssertModuleSource<'tcx> { if let Some(value) = item.value_str() { return value; } else { - self.tcx.sess.emit_fatal(errors::FieldAssociatedValueExpected { + self.tcx.dcx().emit_fatal(errors::FieldAssociatedValueExpected { span: item.span(), name, }); @@ -170,7 +170,7 @@ impl<'tcx> AssertModuleSource<'tcx> { } } - self.tcx.sess.emit_fatal(errors::NoField { span: attr.span, name }); + self.tcx.dcx().emit_fatal(errors::NoField { span: attr.span, name }); } /// Scan for a `cfg="foo"` attribute and check whether we have a @@ -278,7 +278,7 @@ impl CguReuseTracker { if error { let at_least = if at_least { 1 } else { 0 }; - sess.emit_err(errors::IncorrectCguReuseType { + sess.dcx().emit_err(errors::IncorrectCguReuseType { span: *error_span, cgu_user_name, actual_reuse, @@ -287,7 +287,7 @@ impl CguReuseTracker { }); } } else { - sess.emit_fatal(errors::CguNotRecorded { cgu_user_name, cgu_name }); + sess.dcx().emit_fatal(errors::CguNotRecorded { cgu_user_name, cgu_name }); } } } diff --git a/compiler/rustc_codegen_ssa/src/back/archive.rs b/compiler/rustc_codegen_ssa/src/back/archive.rs index 4dc28adf336..8d7ad24b446 100644 --- a/compiler/rustc_codegen_ssa/src/back/archive.rs +++ b/compiler/rustc_codegen_ssa/src/back/archive.rs @@ -220,7 +220,7 @@ impl<'a> ArchiveBuilder<'a> for ArArchiveBuilder<'a> { let sess = self.sess; match self.build_inner(output) { Ok(any_members) => any_members, - Err(e) => sess.emit_fatal(ArchiveBuildFailure { error: e }), + Err(e) => sess.dcx().emit_fatal(ArchiveBuildFailure { error: e }), } } } @@ -234,7 +234,7 @@ impl<'a> ArArchiveBuilder<'a> { "coff" => ArchiveKind::Coff, "aix_big" => ArchiveKind::AixBig, kind => { - self.sess.emit_fatal(UnknownArchiveKind { kind }); + self.sess.dcx().emit_fatal(UnknownArchiveKind { kind }); } }; diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index b32865a0518..ae64b8ca588 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -98,7 +98,7 @@ pub fn link_binary<'a>( let tmpdir = TempFileBuilder::new() .prefix("rustc") .tempdir() - .unwrap_or_else(|error| sess.emit_fatal(errors::CreateTempDir { error })); + .unwrap_or_else(|error| sess.dcx().emit_fatal(errors::CreateTempDir { error })); let path = MaybeTempDir::new(tmpdir, sess.opts.cg.save_temps); let output = out_filename( sess, @@ -161,11 +161,11 @@ pub fn link_binary<'a>( if output.is_stdout() { if output.is_tty() { - sess.emit_err(errors::BinaryOutputToTty { + sess.dcx().emit_err(errors::BinaryOutputToTty { shorthand: OutputType::Exe.shorthand(), }); } else if let Err(e) = copy_to_stdout(&out_filename) { - sess.emit_err(errors::CopyPath::new(&out_filename, output.as_path(), e)); + sess.dcx().emit_err(errors::CopyPath::new(&out_filename, output.as_path(), e)); } tempfiles_for_stdout_output.push(out_filename); } @@ -380,8 +380,8 @@ fn link_rlib<'a>( && let Some(filename) = lib.filename { let path = find_native_static_library(filename.as_str(), true, &lib_search_paths, sess); - let src = - read(path).map_err(|e| sess.emit_fatal(errors::ReadFileError { message: e }))?; + let src = read(path) + .map_err(|e| sess.dcx().emit_fatal(errors::ReadFileError { message: e }))?; let (data, _) = create_wrapper_file(sess, b".bundled_lib".to_vec(), &src); let wrapper_file = emit_wrapper_file(sess, &data, tmpdir, filename.as_str()); packed_bundled_libs.push(wrapper_file); @@ -393,7 +393,7 @@ fn link_rlib<'a>( sess, ); ab.add_archive(&path, Box::new(|_| false)).unwrap_or_else(|error| { - sess.emit_fatal(errors::AddNativeLibrary { library_path: path, error }) + sess.dcx().emit_fatal(errors::AddNativeLibrary { library_path: path, error }) }); } } @@ -410,7 +410,7 @@ fn link_rlib<'a>( ); ab.add_archive(&output_path, Box::new(|_| false)).unwrap_or_else(|error| { - sess.emit_fatal(errors::AddNativeLibrary { library_path: output_path, error }); + sess.dcx().emit_fatal(errors::AddNativeLibrary { library_path: output_path, error }); }); } @@ -475,7 +475,7 @@ fn collate_raw_dylibs<'a, 'b>( // FIXME: when we add support for ordinals, figure out if we need to do anything // if we have two DllImport values with the same name but different ordinals. if import.calling_convention != old_import.calling_convention { - sess.emit_err(errors::MultipleExternalFuncDecl { + sess.dcx().emit_err(errors::MultipleExternalFuncDecl { span: import.span, function: import.name, library_name: &name, @@ -558,7 +558,7 @@ fn link_staticlib<'a>( archive_builder_builder .extract_bundled_libs(path, tempdir.as_ref(), &relevant_libs) - .unwrap_or_else(|e| sess.emit_fatal(e)); + .unwrap_or_else(|e| sess.dcx().emit_fatal(e)); for filename in relevant_libs { let joined = tempdir.as_ref().join(filename.as_str()); let path = joined.as_path(); @@ -570,7 +570,7 @@ fn link_staticlib<'a>( }, ); if let Err(e) = res { - sess.emit_fatal(e); + sess.dcx().emit_fatal(e); } ab.build(out_filename); @@ -596,9 +596,9 @@ fn link_staticlib<'a>( all_rust_dylibs.push(&**path); } else { if used_crate_source.rmeta.is_some() { - sess.emit_fatal(errors::LinkRlibError::OnlyRmetaFound { crate_name }); + sess.dcx().emit_fatal(errors::LinkRlibError::OnlyRmetaFound { crate_name }); } else { - sess.emit_fatal(errors::LinkRlibError::NotFound { crate_name }); + sess.dcx().emit_fatal(errors::LinkRlibError::NotFound { crate_name }); } } } @@ -715,7 +715,7 @@ fn link_dwarf_object<'a>( }) { Ok(()) => {} Err(e) => { - sess.emit_err(errors::ThorinErrorWrapper(e)); + sess.dcx().emit_err(errors::ThorinErrorWrapper(e)); sess.abort_if_errors(); } } @@ -955,17 +955,17 @@ fn link_natively<'a>( ) .is_some(); - sess.emit_note(errors::LinkExeUnexpectedError); + sess.dcx().emit_note(errors::LinkExeUnexpectedError); if is_vs_installed && has_linker { // the linker is broken - sess.emit_note(errors::RepairVSBuildTools); - sess.emit_note(errors::MissingCppBuildToolComponent); + sess.dcx().emit_note(errors::RepairVSBuildTools); + sess.dcx().emit_note(errors::MissingCppBuildToolComponent); } else if is_vs_installed { // the linker is not installed - sess.emit_note(errors::SelectCppBuildToolWorkload); + sess.dcx().emit_note(errors::SelectCppBuildToolWorkload); } else { // visual studio is not installed - sess.emit_note(errors::VisualStudioNotInstalled); + sess.dcx().emit_note(errors::VisualStudioNotInstalled); } } } @@ -979,9 +979,9 @@ fn link_natively<'a>( let linker_not_found = e.kind() == io::ErrorKind::NotFound; if linker_not_found { - sess.emit_err(errors::LinkerNotFound { linker_path, error: e }); + sess.dcx().emit_err(errors::LinkerNotFound { linker_path, error: e }); } else { - sess.emit_err(errors::UnableToExeLinker { + sess.dcx().emit_err(errors::UnableToExeLinker { linker_path, error: e, command_formatted: format!("{:?}", &cmd), @@ -989,9 +989,9 @@ fn link_natively<'a>( } if sess.target.is_like_msvc && linker_not_found { - sess.emit_note(errors::MsvcMissingLinker); - sess.emit_note(errors::CheckInstalledVisualStudio); - sess.emit_note(errors::InsufficientVSCodeProduct); + sess.dcx().emit_note(errors::MsvcMissingLinker); + sess.dcx().emit_note(errors::CheckInstalledVisualStudio); + sess.dcx().emit_note(errors::InsufficientVSCodeProduct); } sess.abort_if_errors(); } @@ -1016,13 +1016,13 @@ fn link_natively<'a>( if !prog.status.success() { let mut output = prog.stderr.clone(); output.extend_from_slice(&prog.stdout); - sess.emit_warning(errors::ProcessingDymutilFailed { + sess.dcx().emit_warning(errors::ProcessingDymutilFailed { status: prog.status, output: escape_string(&output), }); } } - Err(error) => sess.emit_fatal(errors::UnableToRunDsymutil { error }), + Err(error) => sess.dcx().emit_fatal(errors::UnableToRunDsymutil { error }), } } @@ -1091,14 +1091,14 @@ fn strip_symbols_with_external_utility<'a>( if !prog.status.success() { let mut output = prog.stderr.clone(); output.extend_from_slice(&prog.stdout); - sess.emit_warning(errors::StrippingDebugInfoFailed { + sess.dcx().emit_warning(errors::StrippingDebugInfoFailed { util, status: prog.status, output: escape_string(&output), }); } } - Err(error) => sess.emit_fatal(errors::UnableToRun { util, error }), + Err(error) => sess.dcx().emit_fatal(errors::UnableToRun { util, error }), } } @@ -1311,7 +1311,7 @@ pub fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) { )), (Some(linker), None) => { let stem = linker.file_stem().and_then(|stem| stem.to_str()).unwrap_or_else(|| { - sess.emit_fatal(errors::LinkerFileStem); + sess.dcx().emit_fatal(errors::LinkerFileStem); }); let flavor = sess.target.linker_flavor.with_linker_hints(stem); Some((linker, flavor)) @@ -1456,15 +1456,15 @@ fn print_native_static_libs( OutFileName::Real(path) => { out.overwrite(&lib_args.join(" "), sess); if !lib_args.is_empty() { - sess.emit_note(errors::StaticLibraryNativeArtifactsToFile { path }); + sess.dcx().emit_note(errors::StaticLibraryNativeArtifactsToFile { path }); } } OutFileName::Stdout => { if !lib_args.is_empty() { - sess.emit_note(errors::StaticLibraryNativeArtifacts); + sess.dcx().emit_note(errors::StaticLibraryNativeArtifacts); // Prefix for greppability // Note: This must not be translated as tools are allowed to depend on this exact string. - sess.note(format!("native-static-libs: {}", &lib_args.join(" "))); + sess.dcx().note(format!("native-static-libs: {}", &lib_args.join(" "))); } } } @@ -1703,7 +1703,7 @@ fn self_contained_components(sess: &Session, crate_type: CrateType) -> LinkSelfC // Emit an error if the user requested self-contained mode on the CLI but the target // explicitly refuses it. if sess.target.link_self_contained.is_disabled() { - sess.emit_err(errors::UnsupportedLinkSelfContained); + sess.dcx().emit_err(errors::UnsupportedLinkSelfContained); } self_contained } else { @@ -1790,14 +1790,14 @@ fn add_link_script(cmd: &mut dyn Linker, sess: &Session, tmpdir: &Path, crate_ty match (crate_type, &sess.target.link_script) { (CrateType::Cdylib | CrateType::Executable, Some(script)) => { if !sess.target.linker_flavor.is_gnu() { - sess.emit_fatal(errors::LinkScriptUnavailable); + sess.dcx().emit_fatal(errors::LinkScriptUnavailable); } let file_name = ["rustc", &sess.target.llvm_target, "linkfile.ld"].join("-"); let path = tmpdir.join(file_name); if let Err(error) = fs::write(&path, script.as_ref()) { - sess.emit_fatal(errors::LinkScriptWriteFailure { path, error }); + sess.dcx().emit_fatal(errors::LinkScriptWriteFailure { path, error }); } cmd.arg("--script"); @@ -1921,7 +1921,7 @@ fn add_linked_symbol_object( let path = tmpdir.join("symbols.o"); let result = std::fs::write(&path, file.write().unwrap()); if let Err(error) = result { - sess.emit_fatal(errors::FailedToWrite { path, error }); + sess.dcx().emit_fatal(errors::FailedToWrite { path, error }); } cmd.add_object(&path); } @@ -2390,7 +2390,7 @@ fn collect_natvis_visualizers( visualizer_paths.push(visualizer_out_file); } Err(error) => { - sess.emit_warning(errors::UnableToWriteDebuggerVisualizer { + sess.dcx().emit_warning(errors::UnableToWriteDebuggerVisualizer { path: visualizer_out_file, error, }); @@ -2425,7 +2425,7 @@ fn add_native_libs_from_crate( let rlib = &codegen_results.crate_info.used_crate_source[&cnum].rlib.as_ref().unwrap().0; archive_builder_builder .extract_bundled_libs(rlib, tmpdir, bundled_libs) - .unwrap_or_else(|e| sess.emit_fatal(e)); + .unwrap_or_else(|e| sess.dcx().emit_fatal(e)); } let native_libs = match cnum { @@ -2798,7 +2798,7 @@ fn add_static_crate<'a>( false }), ) { - sess.emit_fatal(errors::RlibArchiveBuildFailure { error }); + sess.dcx().emit_fatal(errors::RlibArchiveBuildFailure { error }); } if archive.build(&dst) { link_upstream(&dst); @@ -2872,14 +2872,14 @@ fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) { ("arm", "watchos") => "watchos", (_, "macos") => "macosx", _ => { - sess.emit_err(errors::UnsupportedArch { arch, os }); + sess.dcx().emit_err(errors::UnsupportedArch { arch, os }); return; } }; let sdk_root = match get_apple_sdk_root(sdk_name) { Ok(s) => s, Err(e) => { - sess.emit_err(e); + sess.dcx().emit_err(e); return; } }; diff --git a/compiler/rustc_codegen_ssa/src/back/linker.rs b/compiler/rustc_codegen_ssa/src/back/linker.rs index eeb57d4d0f4..695aeb0b2fb 100644 --- a/compiler/rustc_codegen_ssa/src/back/linker.rs +++ b/compiler/rustc_codegen_ssa/src/back/linker.rs @@ -446,11 +446,11 @@ impl<'a> Linker for GccLinker<'a> { // FIXME(81490): ld64 doesn't support these flags but macOS 11 // has -needed-l{} / -needed_library {} // but we have no way to detect that here. - self.sess.emit_warning(errors::Ld64UnimplementedModifier); + self.sess.dcx().emit_warning(errors::Ld64UnimplementedModifier); } else if self.is_gnu && !self.sess.target.is_like_windows { self.linker_arg("--no-as-needed"); } else { - self.sess.emit_warning(errors::LinkerUnsupportedModifier); + self.sess.dcx().emit_warning(errors::LinkerUnsupportedModifier); } } self.hint_dynamic(); @@ -504,7 +504,7 @@ impl<'a> Linker for GccLinker<'a> { // FIXME(81490): ld64 as of macOS 11 supports the -needed_framework // flag but we have no way to detect that here. // self.cmd.arg("-needed_framework").arg(framework); - self.sess.emit_warning(errors::Ld64UnimplementedModifier); + self.sess.dcx().emit_warning(errors::Ld64UnimplementedModifier); } self.cmd.arg("-framework").arg(framework); } @@ -693,7 +693,7 @@ impl<'a> Linker for GccLinker<'a> { } }; if let Err(error) = res { - self.sess.emit_fatal(errors::LibDefWriteFailure { error }); + self.sess.dcx().emit_fatal(errors::LibDefWriteFailure { error }); } } else if is_windows { let res: io::Result<()> = try { @@ -708,7 +708,7 @@ impl<'a> Linker for GccLinker<'a> { } }; if let Err(error) = res { - self.sess.emit_fatal(errors::LibDefWriteFailure { error }); + self.sess.dcx().emit_fatal(errors::LibDefWriteFailure { error }); } } else { // Write an LD version script @@ -725,7 +725,7 @@ impl<'a> Linker for GccLinker<'a> { writeln!(f, "\n local:\n *;\n}};")?; }; if let Err(error) = res { - self.sess.emit_fatal(errors::VersionScriptWriteFailure { error }); + self.sess.dcx().emit_fatal(errors::VersionScriptWriteFailure { error }); } } @@ -950,7 +950,7 @@ impl<'a> Linker for MsvcLinker<'a> { } } Err(error) => { - self.sess.emit_warning(errors::NoNatvisDirectory { error }); + self.sess.dcx().emit_warning(errors::NoNatvisDirectory { error }); } } } @@ -1005,7 +1005,7 @@ impl<'a> Linker for MsvcLinker<'a> { } }; if let Err(error) = res { - self.sess.emit_fatal(errors::LibDefWriteFailure { error }); + self.sess.dcx().emit_fatal(errors::LibDefWriteFailure { error }); } let mut arg = OsString::from("/DEF:"); arg.push(path); @@ -1501,7 +1501,7 @@ impl<'a> Linker for L4Bender<'a> { fn export_symbols(&mut self, _: &Path, _: CrateType, _: &[String]) { // ToDo, not implemented, copy from GCC - self.sess.emit_warning(errors::L4BenderExportingSymbolsUnimplemented); + self.sess.dcx().emit_warning(errors::L4BenderExportingSymbolsUnimplemented); return; } @@ -1688,7 +1688,7 @@ impl<'a> Linker for AixLinker<'a> { } }; if let Err(e) = res { - self.sess.fatal(format!("failed to write export file: {e}")); + self.sess.dcx().fatal(format!("failed to write export file: {e}")); } self.cmd.arg(format!("-bE:{}", path.to_str().unwrap())); } @@ -1995,7 +1995,7 @@ impl<'a> Linker for BpfLinker<'a> { } }; if let Err(error) = res { - self.sess.emit_fatal(errors::SymbolFileWriteFailure { error }); + self.sess.dcx().emit_fatal(errors::SymbolFileWriteFailure { error }); } else { self.cmd.arg("--export-symbols").arg(&path); } diff --git a/compiler/rustc_codegen_ssa/src/back/write.rs b/compiler/rustc_codegen_ssa/src/back/write.rs index 53ae085a721..f7eda81da29 100644 --- a/compiler/rustc_codegen_ssa/src/back/write.rs +++ b/compiler/rustc_codegen_ssa/src/back/write.rs @@ -534,12 +534,12 @@ fn produce_final_output_artifacts( let copy_gracefully = |from: &Path, to: &OutFileName| match to { OutFileName::Stdout => { if let Err(e) = copy_to_stdout(from) { - sess.emit_err(errors::CopyPath::new(from, to.as_path(), e)); + sess.dcx().emit_err(errors::CopyPath::new(from, to.as_path(), e)); } } OutFileName::Real(path) => { if let Err(e) = fs::copy(from, path) { - sess.emit_err(errors::CopyPath::new(from, path, e)); + sess.dcx().emit_err(errors::CopyPath::new(from, path, e)); } } }; @@ -552,7 +552,8 @@ fn produce_final_output_artifacts( let path = crate_output.temp_path(output_type, module_name); let output = crate_output.path(output_type); if !output_type.is_text_output() && output.is_tty() { - sess.emit_err(errors::BinaryOutputToTty { shorthand: output_type.shorthand() }); + sess.dcx() + .emit_err(errors::BinaryOutputToTty { shorthand: output_type.shorthand() }); } else { copy_gracefully(&path, &output); } @@ -572,11 +573,11 @@ fn produce_final_output_artifacts( if crate_output.outputs.contains_key(&output_type) { // 2) Multiple codegen units, with `--emit foo=some_name`. We have // no good solution for this case, so warn the user. - sess.emit_warning(errors::IgnoringEmitPath { extension }); + sess.dcx().emit_warning(errors::IgnoringEmitPath { extension }); } else if crate_output.single_output_file.is_some() { // 3) Multiple codegen units, with `-o some_name`. We have // no good solution for this case, so warn the user. - sess.emit_warning(errors::IgnoringOutput { extension }); + sess.dcx().emit_warning(errors::IgnoringOutput { extension }); } else { // 4) Multiple codegen units, but no explicit name. We // just leave the `foo.0.x` files in place. @@ -1079,7 +1080,7 @@ fn start_executing_work<B: ExtraBackendMethods>( let result = fs::create_dir_all(dir).and_then(|_| dir.canonicalize()); match result { Ok(dir) => Some(dir), - Err(error) => sess.emit_fatal(ErrorCreatingRemarkDir { error }), + Err(error) => sess.dcx().emit_fatal(ErrorCreatingRemarkDir { error }), } } else { None @@ -1885,7 +1886,7 @@ impl SharedEmitterMain { sess.abort_if_errors(); } Ok(SharedEmitterMessage::Fatal(msg)) => { - sess.fatal(msg); + sess.dcx().fatal(msg); } Err(_) => { break; diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index b87f4b6bf89..1367e038492 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -448,7 +448,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( let Some(llfn) = cx.declare_c_main(llfty) else { // FIXME: We should be smart and show a better diagnostic here. let span = cx.tcx().def_span(rust_main_def_id); - cx.sess().emit_err(errors::MultipleMainFunctions { span }); + cx.sess().dcx().emit_err(errors::MultipleMainFunctions { span }); cx.sess().abort_if_errors(); bug!(); }; @@ -620,7 +620,7 @@ pub fn codegen_crate<B: ExtraBackendMethods>( &exported_symbols::metadata_symbol_name(tcx), ); if let Err(error) = std::fs::write(&file_name, data) { - tcx.sess.emit_fatal(errors::MetadataObjectFileWrite { error }); + tcx.dcx().emit_fatal(errors::MetadataObjectFileWrite { error }); } CompiledModule { name: metadata_cgu_name, @@ -819,7 +819,7 @@ impl CrateInfo { let subsystem = attr::first_attr_value_str_by_name(crate_attrs, sym::windows_subsystem); let windows_subsystem = subsystem.map(|subsystem| { if subsystem != sym::windows && subsystem != sym::console { - tcx.sess.emit_fatal(errors::InvalidWindowsSubsystem { subsystem }); + tcx.dcx().emit_fatal(errors::InvalidWindowsSubsystem { subsystem }); } subsystem.to_string() }); diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index e529956b1ba..f5f2416abb6 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -44,7 +44,7 @@ fn linkage_by_name(tcx: TyCtxt<'_>, def_id: LocalDefId, name: &str) -> Linkage { "private" => Private, "weak" => WeakAny, "weak_odr" => WeakODR, - _ => tcx.sess.span_fatal(tcx.def_span(def_id), "invalid linkage specified"), + _ => tcx.dcx().span_fatal(tcx.def_span(def_id), "invalid linkage specified"), } } @@ -90,7 +90,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { if let Fn | AssocFn | Variant | Ctor(..) = def_kind { Some(tcx.fn_sig(did)) } else { - tcx.sess + tcx.dcx() .span_delayed_bug(attr.span, "this attribute can only be applied to functions"); None } @@ -119,7 +119,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { if tcx.opt_item_name(did.to_def_id()).is_some() { codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE } else { - tcx.sess + tcx.dcx() .struct_span_err( attr.span, format!( @@ -142,7 +142,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { // coverage on a smaller scope within an excluded larger scope. } Some(_) | None => { - tcx.sess.emit_err(ExpectedCoverageSymbol { span: attr.span }); + tcx.dcx().emit_err(ExpectedCoverageSymbol { span: attr.span }); } } } @@ -177,7 +177,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED; } Some(_) => { - tcx.sess.emit_err(ExpectedUsedSymbol { span: attr.span }); + tcx.dcx().emit_err(ExpectedUsedSymbol { span: attr.span }); } None => { // Unfortunately, unconditionally using `llvm.used` causes @@ -217,7 +217,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { && !matches!(fn_sig.skip_binder().abi(), abi::Abi::C { .. }) { struct_span_err!( - tcx.sess, + tcx.dcx(), attr.span, E0776, "`#[cmse_nonsecure_entry]` requires C ABI" @@ -225,7 +225,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { .emit(); } if !tcx.sess.target.llvm_target.contains("thumbv8m") { - struct_span_err!(tcx.sess, attr.span, E0775, "`#[cmse_nonsecure_entry]` is only valid for targets with the TrustZone-M extension") + struct_span_err!(tcx.dcx(), attr.span, E0775, "`#[cmse_nonsecure_entry]` is only valid for targets with the TrustZone-M extension") .emit(); } codegen_fn_attrs.flags |= CodegenFnAttrFlags::CMSE_NONSECURE_ENTRY @@ -239,7 +239,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { && fn_sig.skip_binder().abi() != abi::Abi::Rust { struct_span_err!( - tcx.sess, + tcx.dcx(), attr.span, E0737, "`#[track_caller]` requires Rust ABI" @@ -266,7 +266,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { // `#[export_name = ...]` will be converted to a null-terminated string, // so it may not contain any null characters. struct_span_err!( - tcx.sess, + tcx.dcx(), attr.span, E0648, "`export_name` may not contain null characters" @@ -336,7 +336,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { if let Some(val) = attr.value_str() { if val.as_str().bytes().any(|b| b == 0) { let msg = format!("illegal null byte in link_section value: `{}`", &val); - tcx.sess.span_err(attr.span, msg); + tcx.dcx().span_err(attr.span, msg); } else { codegen_fn_attrs.link_section = Some(val); } @@ -370,7 +370,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { codegen_fn_attrs.no_sanitize |= SanitizerSet::HWADDRESS } _ => { - tcx.sess.emit_err(errors::InvalidNoSanitize { span: item.span() }); + tcx.dcx().emit_err(errors::InvalidNoSanitize { span: item.span() }); } } } @@ -386,7 +386,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { [sym::arm, sym::a32] | [sym::arm, sym::t32] => { if !tcx.sess.target.has_thumb_interworking { struct_span_err!( - tcx.sess.dcx(), + tcx.dcx(), attr.span, E0779, "target does not support `#[instruction_set]`" @@ -403,7 +403,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { } _ => { struct_span_err!( - tcx.sess.dcx(), + tcx.dcx(), attr.span, E0779, "invalid instruction set specified", @@ -415,7 +415,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { } [] => { struct_span_err!( - tcx.sess.dcx(), + tcx.dcx(), attr.span, E0778, "`#[instruction_set]` requires an argument" @@ -425,7 +425,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { } _ => { struct_span_err!( - tcx.sess.dcx(), + tcx.dcx(), attr.span, E0779, "cannot specify more than one instruction set" @@ -443,7 +443,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { rustc_attr::parse_alignment(&literal.kind) .map_err(|msg| { struct_span_err!( - tcx.sess.dcx(), + tcx.dcx(), attr.span, E0589, "invalid `repr(align)` attribute: {}", @@ -469,15 +469,14 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { Some(MetaItemKind::List(ref items)) => { inline_span = Some(attr.span); if items.len() != 1 { - struct_span_err!(tcx.sess.dcx(), attr.span, E0534, "expected one argument") - .emit(); + struct_span_err!(tcx.dcx(), attr.span, E0534, "expected one argument").emit(); InlineAttr::None } else if list_contains_name(items, sym::always) { InlineAttr::Always } else if list_contains_name(items, sym::never) { InlineAttr::Never } else { - struct_span_err!(tcx.sess.dcx(), items[0].span(), E0535, "invalid argument") + struct_span_err!(tcx.dcx(), items[0].span(), E0535, "invalid argument") .help("valid inline arguments are `always` and `never`") .emit(); @@ -493,7 +492,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { if !attr.has_name(sym::optimize) { return ia; } - let err = |sp, s| struct_span_err!(tcx.sess.dcx(), sp, E0722, "{}", s).emit(); + let err = |sp, s| struct_span_err!(tcx.dcx(), sp, E0722, "{}", s).emit(); match attr.meta_kind() { Some(MetaItemKind::Word) => { err(attr.span, "expected one argument"); @@ -550,7 +549,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs { if !codegen_fn_attrs.target_features.is_empty() { if codegen_fn_attrs.inline == InlineAttr::Always { if let Some(span) = inline_span { - tcx.sess.span_err( + tcx.dcx().span_err( span, "cannot use `#[inline(always)]` with \ `#[target_feature]`", @@ -637,7 +636,7 @@ fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &ast::Attribute) -> Option<u16> { let sole_meta_list = match meta_item_list { Some([item]) => item.lit(), Some(_) => { - tcx.sess.emit_err(errors::InvalidLinkOrdinalNargs { span: attr.span }); + tcx.dcx().emit_err(errors::InvalidLinkOrdinalNargs { span: attr.span }); return None; } _ => None, @@ -661,14 +660,14 @@ fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &ast::Attribute) -> Option<u16> { Some(*ordinal as u16) } else { let msg = format!("ordinal value in `link_ordinal` is too large: `{}`", &ordinal); - tcx.sess + tcx.dcx() .struct_span_err(attr.span, msg) .note("the value may not exceed `u16::MAX`") .emit(); None } } else { - tcx.sess.emit_err(errors::InvalidLinkOrdinalFormat { span: attr.span }); + tcx.dcx().emit_err(errors::InvalidLinkOrdinalFormat { span: attr.span }); None } } @@ -683,9 +682,9 @@ fn check_link_name_xor_ordinal( } let msg = "cannot use `#[link_name]` with `#[link_ordinal]`"; if let Some(span) = inline_span { - tcx.sess.span_err(span, msg); + tcx.dcx().span_err(span, msg); } else { - tcx.sess.err(msg); + tcx.dcx().err(msg); } } diff --git a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs index 2ecc5ad4fe4..1b01fe03654 100644 --- a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs +++ b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs @@ -93,7 +93,7 @@ fn push_debuginfo_type_name<'tcx>( Err(e) => { // Computing the layout can still fail here, e.g. if the target architecture // cannot represent the type. See https://github.com/rust-lang/rust/issues/94961. - tcx.sess.emit_fatal(e.into_diagnostic()); + tcx.dcx().emit_fatal(e.into_diagnostic()); } } } else { diff --git a/compiler/rustc_codegen_ssa/src/mir/constant.rs b/compiler/rustc_codegen_ssa/src/mir/constant.rs index 558f64fffc2..d532bd90426 100644 --- a/compiler/rustc_codegen_ssa/src/mir/constant.rs +++ b/compiler/rustc_codegen_ssa/src/mir/constant.rs @@ -94,7 +94,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { bx.const_struct(&values, false) }) .unwrap_or_else(|| { - bx.tcx().sess.emit_err(errors::ShuffleIndicesEvaluation { span: constant.span }); + bx.tcx().dcx().emit_err(errors::ShuffleIndicesEvaluation { span: constant.span }); // We've errored, so we don't have to produce working code. let llty = bx.backend_type(bx.layout_of(ty)); bx.const_undef(llty) diff --git a/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs b/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs index a5bffc33d39..533803ea7ff 100644 --- a/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs +++ b/compiler/rustc_codegen_ssa/src/mir/intrinsic.rs @@ -220,7 +220,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } } None => { - bx.tcx().sess.emit_err(InvalidMonomorphization::BasicIntegerType { + bx.tcx().dcx().emit_err(InvalidMonomorphization::BasicIntegerType { span, name, ty, @@ -240,7 +240,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { _ => bug!(), }, None => { - bx.tcx().sess.emit_err(InvalidMonomorphization::BasicFloatType { + bx.tcx().dcx().emit_err(InvalidMonomorphization::BasicFloatType { span, name, ty: arg_tys[0], @@ -252,14 +252,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { sym::float_to_int_unchecked => { if float_type_width(arg_tys[0]).is_none() { - bx.tcx().sess.emit_err(InvalidMonomorphization::FloatToIntUnchecked { + bx.tcx().dcx().emit_err(InvalidMonomorphization::FloatToIntUnchecked { span, ty: arg_tys[0], }); return; } let Some((_width, signed)) = int_type_width_signed(ret_ty, bx.tcx()) else { - bx.tcx().sess.emit_err(InvalidMonomorphization::FloatToIntUnchecked { + bx.tcx().dcx().emit_err(InvalidMonomorphization::FloatToIntUnchecked { span, ty: ret_ty, }); @@ -297,7 +297,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { use crate::common::{AtomicRmwBinOp, SynchronizationScope}; let Some((instruction, ordering)) = atomic.split_once('_') else { - bx.sess().emit_fatal(errors::MissingMemoryOrdering); + bx.sess().dcx().emit_fatal(errors::MissingMemoryOrdering); }; let parse_ordering = |bx: &Bx, s| match s { @@ -307,11 +307,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { "release" => Release, "acqrel" => AcquireRelease, "seqcst" => SequentiallyConsistent, - _ => bx.sess().emit_fatal(errors::UnknownAtomicOrdering), + _ => bx.sess().dcx().emit_fatal(errors::UnknownAtomicOrdering), }; let invalid_monomorphization = |ty| { - bx.tcx().sess.emit_err(InvalidMonomorphization::BasicIntegerType { + bx.tcx().dcx().emit_err(InvalidMonomorphization::BasicIntegerType { span, name, ty, @@ -321,7 +321,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { match instruction { "cxchg" | "cxchgweak" => { let Some((success, failure)) = ordering.split_once('_') else { - bx.sess().emit_fatal(errors::AtomicCompareExchange); + bx.sess().dcx().emit_fatal(errors::AtomicCompareExchange); }; let ty = fn_args.type_at(0); if int_type_width_signed(ty, bx.tcx()).is_some() || ty.is_unsafe_ptr() { @@ -437,7 +437,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { "min" => AtomicRmwBinOp::AtomicMin, "umax" => AtomicRmwBinOp::AtomicUMax, "umin" => AtomicRmwBinOp::AtomicUMin, - _ => bx.sess().emit_fatal(errors::UnknownAtomicOperation), + _ => bx.sess().dcx().emit_fatal(errors::UnknownAtomicOperation), }; let ty = fn_args.type_at(0); diff --git a/compiler/rustc_codegen_ssa/src/target_features.rs b/compiler/rustc_codegen_ssa/src/target_features.rs index 0b9b08c6a24..031fcc0adb1 100644 --- a/compiler/rustc_codegen_ssa/src/target_features.rs +++ b/compiler/rustc_codegen_ssa/src/target_features.rs @@ -25,7 +25,7 @@ pub fn from_target_feature( let bad_item = |span| { let msg = "malformed `target_feature` attribute input"; let code = "enable = \"..\""; - tcx.sess + tcx.dcx() .struct_span_err(span, msg) .span_suggestion(span, "must be of the form", code, Applicability::HasPlaceholders) .emit(); @@ -48,7 +48,7 @@ pub fn from_target_feature( target_features.extend(value.as_str().split(',').filter_map(|feature| { let Some(feature_gate) = supported_target_features.get(feature) else { let msg = format!("the feature named `{feature}` is not valid for this target"); - let mut err = tcx.sess.struct_span_err(item.span(), msg); + let mut err = tcx.dcx().struct_span_err(item.span(), msg); err.span_label(item.span(), format!("`{feature}` is not valid for this target")); if let Some(stripped) = feature.strip_prefix('+') { let valid = supported_target_features.contains_key(stripped); @@ -121,7 +121,7 @@ pub fn check_target_feature_trait_unsafe(tcx: TyCtxt<'_>, id: LocalDefId, attr_s if let DefKind::AssocFn = tcx.def_kind(id) { let parent_id = tcx.local_parent(id); if let DefKind::Trait | DefKind::Impl { of_trait: true } = tcx.def_kind(parent_id) { - tcx.sess.emit_err(errors::TargetFeatureSafeTrait { + tcx.dcx().emit_err(errors::TargetFeatureSafeTrait { span: attr_span, def: tcx.def_span(id), }); |
