diff --git a/Cargo.lock b/Cargo.lock index 1631d5362612e..93422edafc4fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3799,10 +3799,8 @@ dependencies = [ "rustc_middle", "rustc_mir_build", "rustc_mir_transform", - "rustc_monomorphize", "rustc_parse", "rustc_passes", - "rustc_pattern_analysis", "rustc_privacy", "rustc_public", "rustc_resolve", @@ -3810,7 +3808,6 @@ dependencies = [ "rustc_span", "rustc_target", "rustc_trait_selection", - "rustc_ty_utils", "serde_json", "shlex", "tracing", @@ -4373,7 +4370,6 @@ dependencies = [ "rustc_abi", "rustc_data_structures", "rustc_errors", - "rustc_fluent_macro", "rustc_hir", "rustc_index", "rustc_macros", @@ -4466,7 +4462,6 @@ dependencies = [ "rustc_arena", "rustc_data_structures", "rustc_errors", - "rustc_fluent_macro", "rustc_hir", "rustc_index", "rustc_macros", @@ -4587,7 +4582,6 @@ dependencies = [ "rustc_errors", "rustc_expand", "rustc_feature", - "rustc_fluent_macro", "rustc_hir", "rustc_index", "rustc_macros", @@ -4797,7 +4791,6 @@ dependencies = [ "rustc_abi", "rustc_data_structures", "rustc_errors", - "rustc_fluent_macro", "rustc_hashes", "rustc_hir", "rustc_index", diff --git a/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs index c9da2f3b14bf9..6c52be9bd2294 100644 --- a/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs +++ b/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs @@ -12,10 +12,10 @@ use super::prelude::*; use super::util::parse_single_integer; use crate::attributes::cfg::parse_cfg_entry; use crate::session_diagnostics::{ - AsNeededCompatibility, BundleNeedsStatic, EmptyLinkName, ImportNameTypeRaw, ImportNameTypeX86, - IncompatibleWasmLink, InvalidLinkModifier, LinkFrameworkApple, LinkOrdinalOutOfRange, - LinkRequiresName, MultipleModifiers, NullOnLinkSection, RawDylibNoNul, RawDylibOnlyWindows, - WholeArchiveNeedsStatic, + AsNeededCompatibility, BundleNeedsStatic, EmptyLinkName, ExportSymbolsNeedsStatic, + ImportNameTypeRaw, ImportNameTypeX86, IncompatibleWasmLink, InvalidLinkModifier, + LinkFrameworkApple, LinkOrdinalOutOfRange, LinkRequiresName, MultipleModifiers, + NullOnLinkSection, RawDylibNoNul, RawDylibOnlyWindows, WholeArchiveNeedsStatic, }; pub(crate) struct LinkNameParser; @@ -165,6 +165,14 @@ impl CombineAttributeParser for LinkParser { cx.emit_err(BundleNeedsStatic { span }); } + (sym::export_symbols, Some(NativeLibKind::Static { export_symbols, .. })) => { + assign_modifier(export_symbols) + } + + (sym::export_symbols, _) => { + cx.emit_err(ExportSymbolsNeedsStatic { span }); + } + (sym::verbatim, _) => assign_modifier(&mut verbatim), ( @@ -190,6 +198,7 @@ impl CombineAttributeParser for LinkParser { span, &[ sym::bundle, + sym::export_symbols, sym::verbatim, sym::whole_dash_archive, sym::as_dash_needed, @@ -285,7 +294,9 @@ impl LinkParser { }; let link_kind = match link_kind { - kw::Static => NativeLibKind::Static { bundle: None, whole_archive: None }, + kw::Static => { + NativeLibKind::Static { bundle: None, whole_archive: None, export_symbols: None } + } sym::dylib => NativeLibKind::Dylib { as_needed: None }, sym::framework => { if !sess.target.is_like_darwin { diff --git a/compiler/rustc_attr_parsing/src/session_diagnostics.rs b/compiler/rustc_attr_parsing/src/session_diagnostics.rs index fb4d9c660a190..b0a334210f746 100644 --- a/compiler/rustc_attr_parsing/src/session_diagnostics.rs +++ b/compiler/rustc_attr_parsing/src/session_diagnostics.rs @@ -909,7 +909,7 @@ pub(crate) struct RawDylibOnlyWindows { #[derive(Diagnostic)] #[diag( - "invalid linking modifier syntax, expected '+' or '-' prefix before one of: bundle, verbatim, whole-archive, as-needed" + "invalid linking modifier syntax, expected '+' or '-' prefix before one of: bundle, verbatim, whole-archive, as-needed, export-symbols" )] pub(crate) struct InvalidLinkModifier { #[primary_span] @@ -938,6 +938,13 @@ pub(crate) struct BundleNeedsStatic { pub span: Span, } +#[derive(Diagnostic)] +#[diag("linking modifier `export-symbols` is only compatible with `static` linking kind")] +pub(crate) struct ExportSymbolsNeedsStatic { + #[primary_span] + pub span: Span, +} + #[derive(Diagnostic)] #[diag("linking modifier `whole-archive` is only compatible with `static` linking kind")] pub(crate) struct WholeArchiveNeedsStatic { diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index c8109db86e2f2..5a732382c9818 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -11,10 +11,11 @@ use std::{env, fmt, fs, io, mem, str}; use find_msvc_tools; use itertools::Itertools; +use object::{Object, ObjectSection, ObjectSymbol}; use regex::Regex; use rustc_arena::TypedArena; use rustc_attr_parsing::eval_config_entry; -use rustc_data_structures::fx::FxIndexSet; +use rustc_data_structures::fx::{FxHashSet, FxIndexSet}; use rustc_data_structures::memmap::Mmap; use rustc_data_structures::temp_dir::MaybeTempDir; use rustc_errors::{DiagCtxtHandle, LintDiagnostic}; @@ -2185,6 +2186,71 @@ fn add_rpath_args( } } +fn add_c_staticlib_symbols( + sess: &Session, + lib: &NativeLib, + out: &mut Vec<(String, SymbolExportKind)>, +) -> io::Result<()> { + let file_path = find_native_static_library(lib.name.as_str(), lib.verbatim, sess); + + let archive_map = unsafe { Mmap::map(File::open(&file_path)?)? }; + + let archive = object::read::archive::ArchiveFile::parse(&*archive_map) + .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?; + + for member in archive.members() { + let member = member.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?; + + let data = member + .data(&*archive_map) + .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?; + + // clang LTO: raw LLVM bitcode + if data.starts_with(b"BC\xc0\xde") { + return Err(io::Error::new( + io::ErrorKind::InvalidData, + "LLVM bitcode object in C static library (LTO not supported)", + )); + } + + let object = object::File::parse(&*data) + .map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))?; + + // gcc / clang ELF / Mach-O LTO + if object.sections().any(|s| { + s.name().map(|n| n.starts_with(".gnu.lto_") || n == ".llvm.lto").unwrap_or(false) + }) { + return Err(io::Error::new( + io::ErrorKind::InvalidData, + "LTO object in C static library is not supported", + )); + } + + for symbol in object.symbols() { + if symbol.scope() != object::SymbolScope::Dynamic { + continue; + } + + let name = match symbol.name() { + Ok(n) => n, + Err(_) => continue, + }; + + let export_kind = match symbol.kind() { + object::SymbolKind::Text => SymbolExportKind::Text, + object::SymbolKind::Data => SymbolExportKind::Data, + _ => continue, + }; + + // FIXME:The symbol mangle rules are slightly different in Windows(32-bit) and Apple. + // Need to be resolved. + out.push((name.to_string(), export_kind)); + } + } + + Ok(()) +} + /// Produce the linker command line containing linker path and arguments. /// /// When comments in the function say "order-(in)dependent" they mean order-dependence between @@ -2217,6 +2283,25 @@ fn linker_with_args( ); let link_output_kind = link_output_kind(sess, crate_type); + let mut export_symbols = codegen_results.crate_info.exported_symbols[&crate_type].clone(); + + if crate_type == CrateType::Cdylib { + let mut seen = FxHashSet::default(); + + for lib in &codegen_results.crate_info.used_libraries { + if let NativeLibKind::Static { export_symbols: Some(true), .. } = lib.kind + && seen.insert((lib.name, lib.verbatim)) + { + if let Err(err) = add_c_staticlib_symbols(&sess, lib, &mut export_symbols) { + sess.dcx().fatal(format!( + "failed to process C static library `{}`: {}", + lib.name, err + )); + } + } + } + } + // ------------ Early order-dependent options ------------ // If we're building something like a dynamic library then some platforms @@ -2224,11 +2309,7 @@ fn linker_with_args( // dynamic library. // Must be passed before any libraries to prevent the symbols to export from being thrown away, // at least on some platforms (e.g. windows-gnu). - cmd.export_symbols( - tmpdir, - crate_type, - &codegen_results.crate_info.exported_symbols[&crate_type], - ); + cmd.export_symbols(tmpdir, crate_type, &export_symbols); // Can be used for adding custom CRT objects or overriding order-dependent options above. // FIXME: In practice built-in target specs use this for arbitrary order-independent options, @@ -2678,7 +2759,7 @@ fn add_native_libs_from_crate( let name = lib.name.as_str(); let verbatim = lib.verbatim; match lib.kind { - NativeLibKind::Static { bundle, whole_archive } => { + NativeLibKind::Static { bundle, whole_archive, .. } => { if link_static { let bundle = bundle.unwrap_or(true); let whole_archive = whole_archive == Some(true); diff --git a/compiler/rustc_driver_impl/Cargo.toml b/compiler/rustc_driver_impl/Cargo.toml index d184b6c8947c6..3cba6a8507b16 100644 --- a/compiler/rustc_driver_impl/Cargo.toml +++ b/compiler/rustc_driver_impl/Cargo.toml @@ -33,10 +33,8 @@ rustc_metadata = { path = "../rustc_metadata" } rustc_middle = { path = "../rustc_middle" } rustc_mir_build = { path = "../rustc_mir_build" } rustc_mir_transform = { path = "../rustc_mir_transform" } -rustc_monomorphize = { path = "../rustc_monomorphize" } rustc_parse = { path = "../rustc_parse" } rustc_passes = { path = "../rustc_passes" } -rustc_pattern_analysis = { path = "../rustc_pattern_analysis" } rustc_privacy = { path = "../rustc_privacy" } rustc_public = { path = "../rustc_public", features = ["rustc_internal"] } rustc_resolve = { path = "../rustc_resolve" } @@ -44,7 +42,6 @@ rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } rustc_target = { path = "../rustc_target" } rustc_trait_selection = { path = "../rustc_trait_selection" } -rustc_ty_utils = { path = "../rustc_ty_utils" } serde_json = "1.0.59" shlex = "1.0" tracing = { version = "0.1.35" } diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index 3059a4fefc613..d23f53fbd38e5 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -129,15 +129,11 @@ pub static DEFAULT_LOCALE_RESOURCES: &[&str] = &[ rustc_middle::DEFAULT_LOCALE_RESOURCE, rustc_mir_build::DEFAULT_LOCALE_RESOURCE, rustc_mir_transform::DEFAULT_LOCALE_RESOURCE, - rustc_monomorphize::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE, rustc_passes::DEFAULT_LOCALE_RESOURCE, - rustc_pattern_analysis::DEFAULT_LOCALE_RESOURCE, rustc_privacy::DEFAULT_LOCALE_RESOURCE, - rustc_resolve::DEFAULT_LOCALE_RESOURCE, rustc_session::DEFAULT_LOCALE_RESOURCE, rustc_trait_selection::DEFAULT_LOCALE_RESOURCE, - rustc_ty_utils::DEFAULT_LOCALE_RESOURCE, // tidy-alphabetical-end ]; diff --git a/compiler/rustc_hir/src/attrs/data_structures.rs b/compiler/rustc_hir/src/attrs/data_structures.rs index 6138ffc8d9544..a53eff4637ff2 100644 --- a/compiler/rustc_hir/src/attrs/data_structures.rs +++ b/compiler/rustc_hir/src/attrs/data_structures.rs @@ -331,6 +331,8 @@ pub enum NativeLibKind { bundle: Option, /// Whether to link static library without throwing any object files away whole_archive: Option, + /// Whether to export c static library symbols + export_symbols: Option, }, /// Dynamic library (e.g. `libfoo.so` on Linux) /// or an import library corresponding to a dynamic library (e.g. `foo.lib` on Windows/MSVC). @@ -363,8 +365,8 @@ pub enum NativeLibKind { impl NativeLibKind { pub fn has_modifiers(&self) -> bool { match self { - NativeLibKind::Static { bundle, whole_archive } => { - bundle.is_some() || whole_archive.is_some() + NativeLibKind::Static { bundle, whole_archive, export_symbols } => { + bundle.is_some() || whole_archive.is_some() || export_symbols.is_some() } NativeLibKind::Dylib { as_needed } | NativeLibKind::Framework { as_needed } diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 0f60e86e0ca3c..b0272d726bc38 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -379,7 +379,7 @@ fn test_native_libs_tracking_hash_different_values() { NativeLib { name: String::from("a"), new_name: None, - kind: NativeLibKind::Static { bundle: None, whole_archive: None }, + kind: NativeLibKind::Static { bundle: None, whole_archive: None, export_symbols: None }, verbatim: None, }, NativeLib { @@ -401,7 +401,7 @@ fn test_native_libs_tracking_hash_different_values() { NativeLib { name: String::from("a"), new_name: None, - kind: NativeLibKind::Static { bundle: None, whole_archive: None }, + kind: NativeLibKind::Static { bundle: None, whole_archive: None, export_symbols: None }, verbatim: None, }, NativeLib { @@ -423,13 +423,13 @@ fn test_native_libs_tracking_hash_different_values() { NativeLib { name: String::from("a"), new_name: None, - kind: NativeLibKind::Static { bundle: None, whole_archive: None }, + kind: NativeLibKind::Static { bundle: None, whole_archive: None, export_symbols: None }, verbatim: None, }, NativeLib { name: String::from("b"), new_name: None, - kind: NativeLibKind::Static { bundle: None, whole_archive: None }, + kind: NativeLibKind::Static { bundle: None, whole_archive: None, export_symbols: None }, verbatim: None, }, NativeLib { @@ -445,7 +445,7 @@ fn test_native_libs_tracking_hash_different_values() { NativeLib { name: String::from("a"), new_name: None, - kind: NativeLibKind::Static { bundle: None, whole_archive: None }, + kind: NativeLibKind::Static { bundle: None, whole_archive: None, export_symbols: None }, verbatim: None, }, NativeLib { @@ -467,7 +467,7 @@ fn test_native_libs_tracking_hash_different_values() { NativeLib { name: String::from("a"), new_name: None, - kind: NativeLibKind::Static { bundle: None, whole_archive: None }, + kind: NativeLibKind::Static { bundle: None, whole_archive: None, export_symbols: None }, verbatim: None, }, NativeLib { @@ -501,7 +501,7 @@ fn test_native_libs_tracking_hash_different_order() { NativeLib { name: String::from("a"), new_name: None, - kind: NativeLibKind::Static { bundle: None, whole_archive: None }, + kind: NativeLibKind::Static { bundle: None, whole_archive: None, export_symbols: None }, verbatim: None, }, NativeLib { @@ -528,7 +528,7 @@ fn test_native_libs_tracking_hash_different_order() { NativeLib { name: String::from("a"), new_name: None, - kind: NativeLibKind::Static { bundle: None, whole_archive: None }, + kind: NativeLibKind::Static { bundle: None, whole_archive: None, export_symbols: None }, verbatim: None, }, NativeLib { @@ -549,7 +549,7 @@ fn test_native_libs_tracking_hash_different_order() { NativeLib { name: String::from("a"), new_name: None, - kind: NativeLibKind::Static { bundle: None, whole_archive: None }, + kind: NativeLibKind::Static { bundle: None, whole_archive: None, export_symbols: None }, verbatim: None, }, NativeLib { diff --git a/compiler/rustc_metadata/src/native_libs.rs b/compiler/rustc_metadata/src/native_libs.rs index b160b3fe9bb3c..0c06d1be9a3fd 100644 --- a/compiler/rustc_metadata/src/native_libs.rs +++ b/compiler/rustc_metadata/src/native_libs.rs @@ -161,7 +161,7 @@ fn find_bundled_library( tcx: TyCtxt<'_>, ) -> Option { let sess = tcx.sess; - if let NativeLibKind::Static { bundle: Some(true) | None, whole_archive } = kind + if let NativeLibKind::Static { bundle: Some(true) | None, whole_archive, .. } = kind && tcx.crate_types().iter().any(|t| matches!(t, &CrateType::Rlib | CrateType::StaticLib)) && (sess.opts.unstable_opts.packed_bundled_libs || has_cfg || whole_archive == Some(true)) { diff --git a/compiler/rustc_monomorphize/Cargo.toml b/compiler/rustc_monomorphize/Cargo.toml index 0829d52283abf..552c092ef7c46 100644 --- a/compiler/rustc_monomorphize/Cargo.toml +++ b/compiler/rustc_monomorphize/Cargo.toml @@ -8,7 +8,6 @@ edition = "2024" rustc_abi = { path = "../rustc_abi" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } -rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_hir = { path = "../rustc_hir" } rustc_index = { path = "../rustc_index" } rustc_macros = { path = "../rustc_macros" } diff --git a/compiler/rustc_monomorphize/messages.ftl b/compiler/rustc_monomorphize/messages.ftl deleted file mode 100644 index 9c791208c0935..0000000000000 --- a/compiler/rustc_monomorphize/messages.ftl +++ /dev/null @@ -1,82 +0,0 @@ -monomorphize_abi_error_disabled_vector_type = - this function {$is_call -> - [true] call - *[false] definition - } uses {$is_scalable -> - [true] scalable - *[false] SIMD - } vector type `{$ty}` which (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled{$is_call -> - [true] {" "}in the caller - *[false] {""} - } - .label = function {$is_call -> - [true] called - *[false] defined - } here - .help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`) - -monomorphize_abi_error_unsupported_unsized_parameter = - this function {$is_call -> - [true] call - *[false] definition - } uses unsized type `{$ty}` which is not supported with the chosen ABI - .label = function {$is_call -> - [true] called - *[false] defined - } here - .help = only rustic ABIs support unsized parameters - -monomorphize_abi_error_unsupported_vector_type = - this function {$is_call -> - [true] call - *[false] definition - } uses SIMD vector type `{$ty}` which is not currently supported with the chosen ABI - .label = function {$is_call -> - [true] called - *[false] defined - } here - -monomorphize_abi_required_target_feature = - this function {$is_call -> - [true] call - *[false] definition - } uses ABI "{$abi}" which requires the `{$required_feature}` target feature, which is not enabled{$is_call -> - [true] {" "}in the caller - *[false] {""} - } - .label = function {$is_call -> - [true] called - *[false] defined - } here - .help = consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable="{$required_feature}")]`) - -monomorphize_couldnt_dump_mono_stats = - unexpected error occurred while dumping monomorphization stats: {$error} - -monomorphize_encountered_error_while_instantiating = - the above error was encountered while instantiating `{$kind} {$instance}` - -monomorphize_encountered_error_while_instantiating_global_asm = - the above error was encountered while instantiating `global_asm` - -monomorphize_large_assignments = - moving {$size} bytes - .label = value moved from here - .note = the current maximum size is {$limit}, but it can be customized with the move_size_limit attribute: `#![move_size_limit = "..."]` - -monomorphize_no_optimized_mir = - missing optimized MIR for `{$instance}` in the crate `{$crate_name}` - .note = missing optimized MIR for this item (was the crate `{$crate_name}` compiled with `--emit=metadata`?) - -monomorphize_recursion_limit = - reached the recursion limit while instantiating `{$instance}` - .note = `{$def_path_str}` defined here - -monomorphize_start_not_found = using `fn main` requires the standard library - .help = use `#![no_main]` to bypass the Rust generated entrypoint and declare a platform specific entrypoint yourself, usually with `#[no_mangle]` - -monomorphize_static_initializer_cyclic = static initializer forms a cycle involving `{$head}` - .label = part of this cycle - .note = cyclic static initializers are not supported for target `{$target}` - -monomorphize_symbol_already_defined = symbol `{$symbol}` is already defined diff --git a/compiler/rustc_monomorphize/src/errors.rs b/compiler/rustc_monomorphize/src/errors.rs index 723649f22117e..d045ae0b92cba 100644 --- a/compiler/rustc_monomorphize/src/errors.rs +++ b/compiler/rustc_monomorphize/src/errors.rs @@ -3,37 +3,41 @@ use rustc_middle::ty::{Instance, Ty}; use rustc_span::{Span, Symbol}; #[derive(Diagnostic)] -#[diag(monomorphize_recursion_limit)] +#[diag("reached the recursion limit while instantiating `{$instance}`")] pub(crate) struct RecursionLimit<'tcx> { #[primary_span] pub span: Span, pub instance: Instance<'tcx>, - #[note] + #[note("`{$def_path_str}` defined here")] pub def_span: Span, pub def_path_str: String, } #[derive(Diagnostic)] -#[diag(monomorphize_no_optimized_mir)] +#[diag("missing optimized MIR for `{$instance}` in the crate `{$crate_name}`")] pub(crate) struct NoOptimizedMir { - #[note] + #[note( + "missing optimized MIR for this item (was the crate `{$crate_name}` compiled with `--emit=metadata`?)" + )] pub span: Span, pub crate_name: Symbol, pub instance: String, } #[derive(LintDiagnostic)] -#[diag(monomorphize_large_assignments)] -#[note] +#[diag("moving {$size} bytes")] +#[note( + "the current maximum size is {$limit}, but it can be customized with the move_size_limit attribute: `#![move_size_limit = \"...\"]`" +)] pub(crate) struct LargeAssignmentsLint { - #[label] + #[label("value moved from here")] pub span: Span, pub size: u64, pub limit: u64, } #[derive(Diagnostic)] -#[diag(monomorphize_symbol_already_defined)] +#[diag("symbol `{$symbol}` is already defined")] pub(crate) struct SymbolAlreadyDefined { #[primary_span] pub span: Option, @@ -41,13 +45,13 @@ pub(crate) struct SymbolAlreadyDefined { } #[derive(Diagnostic)] -#[diag(monomorphize_couldnt_dump_mono_stats)] +#[diag("unexpected error occurred while dumping monomorphization stats: {$error}")] pub(crate) struct CouldntDumpMonoStats { pub error: String, } #[derive(Diagnostic)] -#[diag(monomorphize_encountered_error_while_instantiating)] +#[diag("the above error was encountered while instantiating `{$kind} {$instance}`")] pub(crate) struct EncounteredErrorWhileInstantiating<'tcx> { #[primary_span] pub span: Span, @@ -56,23 +60,41 @@ pub(crate) struct EncounteredErrorWhileInstantiating<'tcx> { } #[derive(Diagnostic)] -#[diag(monomorphize_encountered_error_while_instantiating_global_asm)] +#[diag("the above error was encountered while instantiating `global_asm`")] pub(crate) struct EncounteredErrorWhileInstantiatingGlobalAsm { #[primary_span] pub span: Span, } #[derive(Diagnostic)] -#[diag(monomorphize_start_not_found)] -#[help] +#[diag("using `fn main` requires the standard library")] +#[help( + "use `#![no_main]` to bypass the Rust generated entrypoint and declare a platform specific entrypoint yourself, usually with `#[no_mangle]`" +)] pub(crate) struct StartNotFound; #[derive(Diagnostic)] -#[diag(monomorphize_abi_error_disabled_vector_type)] -#[help] +#[diag("this function {$is_call -> + [true] call + *[false] definition +} uses {$is_scalable -> + [true] scalable + *[false] SIMD +} vector type `{$ty}` which (with the chosen ABI) requires the `{$required_feature}` target feature, which is not enabled{$is_call -> + [true] {\" \"}in the caller + *[false] {\"\"} +}")] +#[help( + "consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable=\"{$required_feature}\")]`)" +)] pub(crate) struct AbiErrorDisabledVectorType<'a> { #[primary_span] - #[label] + #[label( + "function {$is_call -> + [true] called + *[false] defined + } here" + )] pub span: Span, pub required_feature: &'a str, pub ty: Ty<'a>, @@ -83,11 +105,21 @@ pub(crate) struct AbiErrorDisabledVectorType<'a> { } #[derive(Diagnostic)] -#[diag(monomorphize_abi_error_unsupported_unsized_parameter)] -#[help] +#[diag( + "this function {$is_call -> + [true] call + *[false] definition + } uses unsized type `{$ty}` which is not supported with the chosen ABI" +)] +#[help("only rustic ABIs support unsized parameters")] pub(crate) struct AbiErrorUnsupportedUnsizedParameter<'a> { #[primary_span] - #[label] + #[label( + "function {$is_call -> + [true] called + *[false] defined + } here" + )] pub span: Span, pub ty: Ty<'a>, /// Whether this is a problem at a call site or at a declaration. @@ -95,10 +127,20 @@ pub(crate) struct AbiErrorUnsupportedUnsizedParameter<'a> { } #[derive(Diagnostic)] -#[diag(monomorphize_abi_error_unsupported_vector_type)] +#[diag( + "this function {$is_call -> + [true] call + *[false] definition + } uses SIMD vector type `{$ty}` which is not currently supported with the chosen ABI" +)] pub(crate) struct AbiErrorUnsupportedVectorType<'a> { #[primary_span] - #[label] + #[label( + "function {$is_call -> + [true] called + *[false] defined + } here" + )] pub span: Span, pub ty: Ty<'a>, /// Whether this is a problem at a call site or at a declaration. @@ -106,11 +148,24 @@ pub(crate) struct AbiErrorUnsupportedVectorType<'a> { } #[derive(Diagnostic)] -#[diag(monomorphize_abi_required_target_feature)] -#[help] +#[diag("this function {$is_call -> + [true] call + *[false] definition +} uses ABI \"{$abi}\" which requires the `{$required_feature}` target feature, which is not enabled{$is_call -> + [true] {\" \"}in the caller + *[false] {\"\"} +}")] +#[help( + "consider enabling it globally (`-C target-feature=+{$required_feature}`) or locally (`#[target_feature(enable=\"{$required_feature}\")]`)" +)] pub(crate) struct AbiRequiredTargetFeature<'a> { #[primary_span] - #[label] + #[label( + "function {$is_call -> +[true] called +*[false] defined +} here" + )] pub span: Span, pub required_feature: &'a str, pub abi: &'a str, @@ -119,12 +174,12 @@ pub(crate) struct AbiRequiredTargetFeature<'a> { } #[derive(Diagnostic)] -#[diag(monomorphize_static_initializer_cyclic)] -#[note] +#[diag("static initializer forms a cycle involving `{$head}`")] +#[note("cyclic static initializers are not supported for target `{$target}`")] pub(crate) struct StaticInitializerCyclic<'a> { #[primary_span] pub span: Span, - #[label] + #[label("part of this cycle")] pub labels: Vec, pub head: &'a str, pub target: &'a str, diff --git a/compiler/rustc_monomorphize/src/lib.rs b/compiler/rustc_monomorphize/src/lib.rs index 30f6934bb9372..51753563b67c9 100644 --- a/compiler/rustc_monomorphize/src/lib.rs +++ b/compiler/rustc_monomorphize/src/lib.rs @@ -20,8 +20,6 @@ mod mono_checks; mod partitioning; mod util; -rustc_fluent_macro::fluent_messages! { "../messages.ftl" } - fn custom_coerce_unsize_info<'tcx>( tcx: TyCtxtAt<'tcx>, source_ty: Ty<'tcx>, diff --git a/compiler/rustc_pattern_analysis/Cargo.toml b/compiler/rustc_pattern_analysis/Cargo.toml index a59f7bbeb9e5e..a644c6a7c01a2 100644 --- a/compiler/rustc_pattern_analysis/Cargo.toml +++ b/compiler/rustc_pattern_analysis/Cargo.toml @@ -11,7 +11,6 @@ rustc_apfloat = "0.2.0" rustc_arena = { path = "../rustc_arena", optional = true } rustc_data_structures = { path = "../rustc_data_structures", optional = true } rustc_errors = { path = "../rustc_errors", optional = true } -rustc_fluent_macro = { path = "../rustc_fluent_macro", optional = true } rustc_hir = { path = "../rustc_hir", optional = true } rustc_index = { path = "../rustc_index", default-features = false } rustc_macros = { path = "../rustc_macros", optional = true } @@ -36,7 +35,6 @@ rustc = [ "dep:rustc_arena", "dep:rustc_data_structures", "dep:rustc_errors", - "dep:rustc_fluent_macro", "dep:rustc_hir", "dep:rustc_macros", "dep:rustc_middle", diff --git a/compiler/rustc_pattern_analysis/messages.ftl b/compiler/rustc_pattern_analysis/messages.ftl deleted file mode 100644 index d3a3107f8e898..0000000000000 --- a/compiler/rustc_pattern_analysis/messages.ftl +++ /dev/null @@ -1,31 +0,0 @@ -pattern_analysis_excluside_range_missing_gap = multiple ranges are one apart - .label = this range doesn't match `{$gap}` because `..` is an exclusive range - .suggestion = use an inclusive range instead - -pattern_analysis_excluside_range_missing_max = exclusive range missing `{$max}` - .label = this range doesn't match `{$max}` because `..` is an exclusive range - .suggestion = use an inclusive range instead - -pattern_analysis_mixed_deref_pattern_constructors = mix of deref patterns and normal constructors - .deref_pattern_label = matches on the result of dereferencing `{$smart_pointer_ty}` - .normal_constructor_label = matches directly on `{$smart_pointer_ty}` - -pattern_analysis_non_exhaustive_omitted_pattern = some variants are not matched explicitly - .help = ensure that all variants are matched explicitly by adding the suggested match arms - .note = the matched value is of type `{$scrut_ty}` and the `non_exhaustive_omitted_patterns` attribute was found - -pattern_analysis_non_exhaustive_omitted_pattern_lint_on_arm = the lint level must be set on the whole match - .help = it no longer has any effect to set the lint level on an individual match arm - .label = remove this attribute - .suggestion = set the lint level on the whole match - -pattern_analysis_overlapping_range_endpoints = multiple patterns overlap on their endpoints - .label = ... with this range - .note = you likely meant to write mutually exclusive ranges - -pattern_analysis_uncovered = {$count -> - [1] pattern `{$witness_1}` - [2] patterns `{$witness_1}` and `{$witness_2}` - [3] patterns `{$witness_1}`, `{$witness_2}` and `{$witness_3}` - *[other] patterns `{$witness_1}`, `{$witness_2}`, `{$witness_3}` and {$remainder} more - } not covered diff --git a/compiler/rustc_pattern_analysis/src/errors.rs b/compiler/rustc_pattern_analysis/src/errors.rs index 156ba9737673e..64d4ff4220430 100644 --- a/compiler/rustc_pattern_analysis/src/errors.rs +++ b/compiler/rustc_pattern_analysis/src/errors.rs @@ -6,7 +6,14 @@ use rustc_span::Span; use crate::rustc::{RustcPatCtxt, WitnessPat}; #[derive(Subdiagnostic)] -#[label(pattern_analysis_uncovered)] +#[label( + "{$count -> + [1] pattern `{$witness_1}` + [2] patterns `{$witness_1}` and `{$witness_2}` + [3] patterns `{$witness_1}`, `{$witness_2}` and `{$witness_3}` + *[other] patterns `{$witness_1}`, `{$witness_2}`, `{$witness_3}` and {$remainder} more + } not covered" +)] pub struct Uncovered { #[primary_span] span: Span, @@ -40,10 +47,10 @@ impl Uncovered { } #[derive(LintDiagnostic)] -#[diag(pattern_analysis_overlapping_range_endpoints)] -#[note] +#[diag("multiple patterns overlap on their endpoints")] +#[note("you likely meant to write mutually exclusive ranges")] pub struct OverlappingRangeEndpoints { - #[label] + #[label("... with this range")] pub range: Span, #[subdiagnostic] pub overlap: Vec, @@ -66,10 +73,14 @@ impl Subdiagnostic for Overlap { } #[derive(LintDiagnostic)] -#[diag(pattern_analysis_excluside_range_missing_max)] +#[diag("exclusive range missing `{$max}`")] pub struct ExclusiveRangeMissingMax { - #[label] - #[suggestion(code = "{suggestion}", applicability = "maybe-incorrect")] + #[label("this range doesn't match `{$max}` because `..` is an exclusive range")] + #[suggestion( + "use an inclusive range instead", + code = "{suggestion}", + applicability = "maybe-incorrect" + )] /// This is an exclusive range that looks like `lo..max` (i.e. doesn't match `max`). pub first_range: Span, /// Suggest `lo..=max` instead. @@ -78,10 +89,14 @@ pub struct ExclusiveRangeMissingMax { } #[derive(LintDiagnostic)] -#[diag(pattern_analysis_excluside_range_missing_gap)] +#[diag("multiple ranges are one apart")] pub struct ExclusiveRangeMissingGap { - #[label] - #[suggestion(code = "{suggestion}", applicability = "maybe-incorrect")] + #[label("this range doesn't match `{$gap}` because `..` is an exclusive range")] + #[suggestion( + "use an inclusive range instead", + code = "{suggestion}", + applicability = "maybe-incorrect" + )] /// This is an exclusive range that looks like `lo..gap` (i.e. doesn't match `gap`). pub first_range: Span, pub gap: String, // a printed pattern @@ -113,9 +128,11 @@ impl Subdiagnostic for GappedRange { } #[derive(LintDiagnostic)] -#[diag(pattern_analysis_non_exhaustive_omitted_pattern)] -#[help] -#[note] +#[diag("some variants are not matched explicitly")] +#[help("ensure that all variants are matched explicitly by adding the suggested match arms")] +#[note( + "the matched value is of type `{$scrut_ty}` and the `non_exhaustive_omitted_patterns` attribute was found" +)] pub(crate) struct NonExhaustiveOmittedPattern<'tcx> { pub scrut_ty: Ty<'tcx>, #[subdiagnostic] @@ -123,25 +140,29 @@ pub(crate) struct NonExhaustiveOmittedPattern<'tcx> { } #[derive(LintDiagnostic)] -#[diag(pattern_analysis_non_exhaustive_omitted_pattern_lint_on_arm)] -#[help] +#[diag("the lint level must be set on the whole match")] +#[help("it no longer has any effect to set the lint level on an individual match arm")] pub(crate) struct NonExhaustiveOmittedPatternLintOnArm { - #[label] + #[label("remove this attribute")] pub lint_span: Span, - #[suggestion(code = "#[{lint_level}({lint_name})]\n", applicability = "maybe-incorrect")] + #[suggestion( + "set the lint level on the whole match", + code = "#[{lint_level}({lint_name})]\n", + applicability = "maybe-incorrect" + )] pub suggest_lint_on_match: Option, pub lint_level: &'static str, pub lint_name: &'static str, } #[derive(Diagnostic)] -#[diag(pattern_analysis_mixed_deref_pattern_constructors)] +#[diag("mix of deref patterns and normal constructors")] pub(crate) struct MixedDerefPatternConstructors<'tcx> { #[primary_span] pub spans: Vec, pub smart_pointer_ty: Ty<'tcx>, - #[label(pattern_analysis_deref_pattern_label)] + #[label("matches on the result of dereferencing `{$smart_pointer_ty}`")] pub deref_pattern_label: Span, - #[label(pattern_analysis_normal_constructor_label)] + #[label("matches directly on `{$smart_pointer_ty}`")] pub normal_constructor_label: Span, } diff --git a/compiler/rustc_pattern_analysis/src/lib.rs b/compiler/rustc_pattern_analysis/src/lib.rs index 2652840863776..9ffc237c63290 100644 --- a/compiler/rustc_pattern_analysis/src/lib.rs +++ b/compiler/rustc_pattern_analysis/src/lib.rs @@ -19,9 +19,6 @@ pub mod pat_column; pub mod rustc; pub mod usefulness; -#[cfg(feature = "rustc")] -rustc_fluent_macro::fluent_messages! { "../messages.ftl" } - use std::fmt; pub use rustc_index::{Idx, IndexVec}; // re-exported to avoid rustc_index version issues diff --git a/compiler/rustc_resolve/Cargo.toml b/compiler/rustc_resolve/Cargo.toml index dd15e879c6440..01e268d911d24 100644 --- a/compiler/rustc_resolve/Cargo.toml +++ b/compiler/rustc_resolve/Cargo.toml @@ -16,7 +16,6 @@ rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_expand = { path = "../rustc_expand" } rustc_feature = { path = "../rustc_feature" } -rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_hir = { path = "../rustc_hir" } rustc_index = { path = "../rustc_index" } rustc_macros = { path = "../rustc_macros" } diff --git a/compiler/rustc_resolve/messages.ftl b/compiler/rustc_resolve/messages.ftl deleted file mode 100644 index 4a980b2bd747d..0000000000000 --- a/compiler/rustc_resolve/messages.ftl +++ /dev/null @@ -1,531 +0,0 @@ -resolve_accessible_unsure = not sure whether the path is accessible or not - .note = the type may have associated items, but we are currently not checking them - -resolve_add_as_non_derive = - add as non-Derive macro - `#[{$macro_path}]` - -resolve_added_macro_use = - have you added the `#[macro_use]` on the module/import? - -resolve_ancestor_only = - visibilities can only be restricted to ancestor modules - -resolve_anonymous_lifetime_non_gat_report_error = missing lifetime in associated type - .label = this lifetime must come from the implemented type - .note = in the trait the associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type - -resolve_arguments_macro_use_not_allowed = arguments to `macro_use` are not allowed here - -resolve_associated_const_with_similar_name_exists = - there is an associated constant with a similar name - -resolve_associated_fn_with_similar_name_exists = - there is an associated function with a similar name - -resolve_associated_type_with_similar_name_exists = - there is an associated type with a similar name - -resolve_attempt_to_use_non_constant_value_in_constant = - attempt to use a non-constant value in a constant - -resolve_attempt_to_use_non_constant_value_in_constant_label_with_suggestion = - non-constant value - -resolve_attempt_to_use_non_constant_value_in_constant_with_suggestion = - consider using `{$suggestion}` instead of `{$current}` - -resolve_attempt_to_use_non_constant_value_in_constant_without_suggestion = - this would need to be a `{$suggestion}` - -resolve_attributes_starting_with_rustc_are_reserved = - attributes starting with `rustc` are reserved for use by the `rustc` compiler - -resolve_binding_in_never_pattern = - never patterns cannot contain variable bindings - .suggestion = use a wildcard `_` instead - -resolve_binding_shadows_something_unacceptable = - {$shadowing_binding}s cannot shadow {$shadowed_binding}s - .label = cannot be named the same as {$article} {$shadowed_binding} - .label_shadowed_binding = the {$shadowed_binding} `{$name}` is {$participle} here - -resolve_binding_shadows_something_unacceptable_suggestion = - try specify the pattern arguments - -resolve_cannot_be_reexported_crate_public = - `{$ident}` is only public within the crate, and cannot be re-exported outside - -resolve_cannot_be_reexported_private = - `{$ident}` is private, and cannot be re-exported - -resolve_cannot_capture_dynamic_environment_in_fn_item = - can't capture dynamic environment in a fn item - .help = use the `|| {"{"} ... {"}"}` closure form instead - -resolve_cannot_determine_import_resolution = - cannot determine resolution for the import - .note = import resolution is stuck, try simplifying other imports - -resolve_cannot_determine_macro_resolution = - cannot determine resolution for the {$kind} `{$path}` - .note = import resolution is stuck, try simplifying macro imports - -resolve_cannot_find_builtin_macro_with_name = - cannot find a built-in macro with name `{$ident}` - -resolve_cannot_find_ident_in_this_scope = - cannot find {$expected} `{$ident}` in this scope - -resolve_cannot_glob_import_possible_crates = - cannot glob-import all possible crates - -resolve_cannot_use_through_an_import = - cannot use {$article} {$descr} through an import - .note = the {$descr} imported here - -resolve_change_import_binding = - you can use `as` to change the binding name of the import - -resolve_consider_adding_a_derive = - consider adding a derive - -resolve_consider_adding_macro_export = - consider adding a `#[macro_export]` to the macro in the imported module - -resolve_consider_declaring_with_pub = - consider declaring type or module `{$ident}` with `pub` - -resolve_consider_making_the_field_public = - { $number_of_fields -> - [one] consider making the field publicly accessible - *[other] consider making the fields publicly accessible - } - -resolve_consider_marking_as_pub = - consider marking `{$ident}` as `pub` in the imported module - -resolve_consider_marking_as_pub_crate = - in case you want to use the macro within this crate only, reduce the visibility to `pub(crate)` - -resolve_consider_move_macro_position = - consider moving the definition of `{$ident}` before this call - - -resolve_const_not_member_of_trait = - const `{$const_}` is not a member of trait `{$trait_}` - .label = not a member of trait `{$trait_}` - -resolve_const_param_in_enum_discriminant = - const parameters may not be used in enum discriminant values - -resolve_const_param_in_non_trivial_anon_const = - const parameters may only be used as standalone arguments here, i.e. `{$name}` - -resolve_constructor_private_if_any_field_private = - a constructor is private if any of the fields is private - -resolve_elided_anonymous_lifetime_report_error = - `&` without an explicit lifetime name cannot be used here - .label = explicit lifetime name needed here - -resolve_elided_anonymous_lifetime_report_error_suggestion = - consider introducing a higher-ranked lifetime here - -resolve_expected_module_found = - expected module, found {$res} `{$path_str}` - .label = not a module - -resolve_explicit_anonymous_lifetime_report_error = - `'_` cannot be used here - .label = `'_` is a reserved lifetime name - -resolve_explicit_unsafe_traits = - unsafe traits like `{$ident}` should be implemented explicitly - -resolve_extern_crate_loading_macro_not_at_crate_root = - an `extern crate` loading macros must be at the crate root - -resolve_extern_crate_not_idiomatic = `extern crate` is not idiomatic in the new edition - .suggestion = convert it to a `use` - -resolve_extern_crate_self_requires_renaming = - `extern crate self;` requires renaming - .suggestion = rename the `self` crate to be able to import it - -resolve_forward_declared_generic_in_const_param_ty = - const parameter types cannot reference parameters before they are declared - .label = const parameter type cannot reference `{$param}` before it is declared - -resolve_forward_declared_generic_param = - generic parameter defaults cannot reference parameters before they are declared - .label = cannot reference `{$param}` before it is declared - -resolve_found_an_item_configured_out = - found an item that was configured out - -resolve_generic_arguments_in_macro_path = - generic arguments in macro path - -resolve_generic_params_from_outer_item = - can't use {$is_self -> - [true] `Self` - *[false] generic parameters - } from outer item - .label = use of {$is_self -> - [true] `Self` - *[false] generic parameter - } from outer item - .refer_to_type_directly = refer to the type directly here instead - .suggestion = try introducing a local generic parameter here - .note = nested items are independent from their parent item for everything except for privacy and name resolution - -resolve_generic_params_from_outer_item_const = a `const` is a separate item from the item that contains it - -resolve_generic_params_from_outer_item_const_param = const parameter from outer item - -resolve_generic_params_from_outer_item_inner_item = {$is_self -> - [true] `Self` - *[false] generic parameter - } used in this inner {$descr} - -resolve_generic_params_from_outer_item_self_ty_alias = `Self` type implicitly declared here, by this `impl` - -resolve_generic_params_from_outer_item_self_ty_param = can't use `Self` here - -resolve_generic_params_from_outer_item_static = a `static` is a separate item from the item that contains it - -resolve_generic_params_from_outer_item_ty_param = type parameter from outer item - -resolve_ident_bound_more_than_once_in_parameter_list = - identifier `{$identifier}` is bound more than once in this parameter list - .label = used as parameter more than once - -resolve_ident_bound_more_than_once_in_same_pattern = - identifier `{$identifier}` is bound more than once in the same pattern - .label = used in a pattern more than once - -resolve_ident_imported_here_but_it_is_desc = - `{$imported_ident}` is imported here, but it is {$imported_ident_desc} - -resolve_ident_in_scope_but_it_is_desc = - `{$imported_ident}` is in scope, but it is {$imported_ident_desc} - -resolve_implicit_elided_lifetimes_not_allowed_here = implicit elided lifetime not allowed here - -resolve_imported_crate = `$crate` may not be imported - -resolve_imported_macro_not_found = imported macro not found - -resolve_imports_cannot_refer_to = - imports cannot refer to {$what} - -resolve_indeterminate = - cannot determine resolution for the visibility - -resolve_invalid_asm_sym = - invalid `sym` operand - .label = is a local variable - .help = `sym` operands must refer to either a function or a static - -resolve_is_private = - {$ident_descr} `{$ident}` is private - .label = private {$ident_descr} - -resolve_item_was_behind_feature = - the item is gated behind the `{$feature}` feature - -resolve_item_was_cfg_out = the item is gated here - -resolve_label_with_similar_name_reachable = - a label with a similar name is reachable - -resolve_legacy_derive_helpers = derive helper attribute is used before it is introduced - .label = the attribute is introduced here - -resolve_lending_iterator_report_error = - associated type `Iterator::Item` is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type - .note = you can't create an `Iterator` that borrows each `Item` from itself, but you can instead create a new type that borrows your existing type and implement `Iterator` for that new type - -resolve_lifetime_param_in_enum_discriminant = - lifetime parameters may not be used in enum discriminant values - -resolve_lifetime_param_in_non_trivial_anon_const = - lifetime parameters may not be used in const expressions - -resolve_lowercase_self = - attempt to use a non-constant value in a constant - .suggestion = try using `Self` - -resolve_macro_cannot_use_as_attr = - `{$ident}` exists, but has no `attr` rules - -resolve_macro_cannot_use_as_derive = - `{$ident}` exists, but has no `derive` rules - -resolve_macro_cannot_use_as_fn_like = - `{$ident}` exists, but has no rules for function-like invocation - -resolve_macro_defined_later = - a macro with the same name exists, but it appears later - -resolve_macro_expanded_extern_crate_cannot_shadow_extern_arguments = - macro-expanded `extern crate` items cannot shadow names passed with `--extern` - -resolve_macro_expanded_macro_exports_accessed_by_absolute_paths = macro-expanded `macro_export` macros from the current crate cannot be referred to by absolute paths - .note = the macro is defined here - -resolve_macro_expected_found = - expected {$expected}, found {$found} `{$macro_path}` - .label = not {$article} {$expected} - -resolve_macro_extern_deprecated = - `#[macro_escape]` is a deprecated synonym for `#[macro_use]` - .help = try an outer attribute: `#[macro_use]` - -resolve_macro_is_private = macro `{$ident}` is private - -resolve_macro_rule_never_used = rule #{$n} of macro `{$name}` is never used - -resolve_macro_use_deprecated = - applying the `#[macro_use]` attribute to an `extern crate` item is deprecated - .help = remove it and import macros at use sites with a `use` item instead - -resolve_macro_use_extern_crate_self = `#[macro_use]` is not supported on `extern crate self` - -resolve_macro_use_name_already_in_use = - `{$name}` is already in scope - .note = macro-expanded `#[macro_use]`s may not shadow existing macros (see RFC 1560) - -resolve_method_not_member_of_trait = - method `{$method}` is not a member of trait `{$trait_}` - .label = not a member of trait `{$trait_}` - -resolve_missing_macro_rules_name = maybe you have forgotten to define a name for this `macro_rules!` - -resolve_module_only = - visibility must resolve to a module - -resolve_name_defined_multiple_time = - the name `{$name}` is defined multiple times - .note = `{$name}` must be defined only once in the {$descr} namespace of this {$container} - -resolve_name_defined_multiple_time_old_binding_definition = - previous definition of the {$old_kind} `{$name}` here - -resolve_name_defined_multiple_time_old_binding_import = - previous import of the {$old_kind} `{$name}` here - -resolve_name_defined_multiple_time_redefined = - `{$name}` redefined here - -resolve_name_defined_multiple_time_reimported = - `{$name}` reimported here - -resolve_name_is_already_used_as_generic_parameter = - the name `{$name}` is already used for a generic parameter in this item's generic parameters - .label = already used - .first_use_of_name = first use of `{$name}` - -resolve_name_reserved_in_attribute_namespace = - name `{$ident}` is reserved in attribute namespace - -resolve_note_and_refers_to_the_item_defined_here = - {$first -> - [true] {$dots -> - [true] the {$binding_descr} `{$binding_name}` is defined here... - *[false] the {$binding_descr} `{$binding_name}` is defined here - } - *[false] {$dots -> - [true] ...and refers to the {$binding_descr} `{$binding_name}` which is defined here... - *[false] ...and refers to the {$binding_descr} `{$binding_name}` which is defined here - } - } - -resolve_out_of_scope_macro_calls = cannot find macro `{$path}` in the current scope when looking from {$location} - .label = not found from {$location} - .help = import `macro_rules` with `use` to make it callable above its definition - -resolve_outer_ident_is_not_publicly_reexported = - {$outer_ident_descr} `{$outer_ident}` is not publicly re-exported - -resolve_param_in_enum_discriminant = - generic parameters may not be used in enum discriminant values - .label = cannot perform const operation using `{$name}` - -resolve_param_in_non_trivial_anon_const = - generic parameters may not be used in const operations - .label = cannot perform const operation using `{$name}` - -resolve_param_in_non_trivial_anon_const_help = - add `#![feature(generic_const_exprs)]` to allow generic const expressions - -resolve_param_in_ty_of_const_param = - the type of const parameters must not depend on other generic parameters - .label = the type must not depend on the parameter `{$name}` - -resolve_pattern_doesnt_bind_name = pattern doesn't bind `{$name}` - -resolve_private_extern_crate_reexport = extern crate `{$ident}` is private and cannot be re-exported - .suggestion = consider making the `extern crate` item publicly accessible - -resolve_proc_macro_derive_resolution_fallback = cannot find {$ns_descr} `{$ident}` in this scope - .label = names from parent modules are not accessible without an explicit import - -resolve_proc_macro_same_crate = can't use a procedural macro from the same crate that defines it - .help = you can define integration tests in a directory named `tests` - -resolve_redundant_import_visibility = glob import doesn't reexport anything with visibility `{$import_vis}` because no imported item is public enough - .note = the most public imported item is `{$max_vis}` - .help = reduce the glob import's visibility or increase visibility of imported items - -resolve_reexport_of_crate_public = - re-export of crate public `{$ident}` - -resolve_reexport_of_private = - re-export of private `{$ident}` - -resolve_reexport_private_dependency = - {$kind} `{$name}` from private dependency '{$krate}' is re-exported - -resolve_relative_2018 = - relative paths are not supported in visibilities in 2018 edition or later - .suggestion = try - -resolve_remove_surrounding_derive = - remove from the surrounding `derive()` - -resolve_remove_unnecessary_import = remove unnecessary import - -resolve_self_import_can_only_appear_once_in_the_list = - `self` import can only appear once in an import list - .label = can only appear once in an import list - -resolve_self_import_only_in_import_list_with_non_empty_prefix = - `self` import can only appear in an import list with a non-empty prefix - .label = can only appear in an import list with a non-empty prefix - -resolve_self_imports_only_allowed_within = - `self` imports are only allowed within a {"{"} {"}"} list - -resolve_self_imports_only_allowed_within_multipart_suggestion = - alternatively, use the multi-path `use` syntax to import `self` - -resolve_self_imports_only_allowed_within_suggestion = - consider importing the module directly - -resolve_self_in_const_generic_ty = - cannot use `Self` in const parameter type - -resolve_self_in_generic_param_default = - generic parameters cannot use `Self` in their defaults - -resolve_similarly_named_defined_here = - similarly named {$candidate_descr} `{$candidate}` defined here - -resolve_single_item_defined_here = - {$candidate_descr} `{$candidate}` defined here - -resolve_static_lifetime_is_reserved = invalid lifetime parameter name: `{$lifetime}` - .label = 'static is a reserved lifetime name - -resolve_suggestion_import_ident_directly = - import `{$ident}` directly - -resolve_suggestion_import_ident_through_reexport = - import `{$ident}` through the re-export - -resolve_tool_module_imported = - cannot use a tool module through an import - .note = the tool module imported here - -resolve_tool_only_accepts_identifiers = - `{$tool}` only accepts identifiers - .label = not an identifier - -resolve_tool_was_already_registered = - tool `{$tool}` was already registered - .label = already registered here - -resolve_trait_impl_duplicate = - duplicate definitions with name `{$name}`: - .label = duplicate definition - .old_span_label = previous definition here - .trait_item_span = item in trait - -resolve_trait_impl_mismatch = - item `{$name}` is an associated {$kind}, which doesn't match its trait `{$trait_path}` - .label = does not match trait - .trait_impl_mismatch_label_item = item in trait -resolve_try_using_similarly_named_label = - try using similarly named label - -resolve_type_not_member_of_trait = - type `{$type_}` is not a member of trait `{$trait_}` - .label = not a member of trait `{$trait_}` - -resolve_type_param_in_enum_discriminant = - type parameters may not be used in enum discriminant values - -resolve_type_param_in_non_trivial_anon_const = - type parameters may not be used in const expressions - -resolve_undeclared_label = - use of undeclared label `{$name}` - .label = undeclared label `{$name}` - -resolve_underscore_lifetime_is_reserved = `'_` cannot be used here - .label = `'_` is a reserved lifetime name - .help = use another lifetime specifier - -resolve_unexpected_res_change_ty_to_const_param_sugg = - you might have meant to write a const parameter here - -resolve_unexpected_res_use_at_op_in_slice_pat_with_range_sugg = - if you meant to collect the rest of the slice in `{$ident}`, use the at operator - -resolve_unknown_diagnostic_attribute = unknown diagnostic attribute -resolve_unknown_diagnostic_attribute_typo_sugg = an attribute with a similar name exists - -resolve_unnamed_crate_root_import = - crate root imports need to be explicitly named: `use crate as name;` - -resolve_unreachable_label = - use of unreachable label `{$name}` - .label = unreachable label `{$name}` - .label_definition_span = unreachable label defined here - .note = labels are unreachable through functions, closures, async blocks and modules - -resolve_unreachable_label_similar_name_reachable = - a label with a similar name is reachable - -resolve_unreachable_label_similar_name_unreachable = - a label with a similar name exists but is also unreachable - -resolve_unreachable_label_suggestion_use_similarly_named = - try using similarly named label - -resolve_unreachable_label_with_similar_name_exists = - a label with a similar name exists but is unreachable - -resolve_unused_extern_crate = unused extern crate - .label = unused - .suggestion = remove the unused `extern crate` - -resolve_unused_label = unused label - -resolve_unused_macro_definition = unused macro definition: `{$name}` - -resolve_unused_macro_use = unused `#[macro_use]` import - -resolve_variable_bound_with_different_mode = - variable `{$variable_name}` is bound inconsistently across alternatives separated by `|` - .label = bound in different ways - .first_binding_span = first binding - -resolve_variable_is_a_typo = you might have meant to use the similarly named previously used binding `{$typo}` - -resolve_variable_is_not_bound_in_all_patterns = - variable `{$name}` is not bound in all patterns - -resolve_variable_not_in_all_patterns = variable not in all patterns diff --git a/compiler/rustc_resolve/src/errors.rs b/compiler/rustc_resolve/src/errors.rs index 3e54464030527..7afdbf6a469f8 100644 --- a/compiler/rustc_resolve/src/errors.rs +++ b/compiler/rustc_resolve/src/errors.rs @@ -1,21 +1,31 @@ use rustc_errors::codes::*; use rustc_errors::{ Applicability, Diag, DiagCtxtHandle, DiagMessage, Diagnostic, ElidedLifetimeInPathSubdiag, - EmissionGuarantee, IntoDiagArg, Level, LintDiagnostic, MultiSpan, Subdiagnostic, + EmissionGuarantee, IntoDiagArg, Level, LintDiagnostic, MultiSpan, Subdiagnostic, inline_fluent, }; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_span::source_map::Spanned; use rustc_span::{Ident, Span, Symbol}; +use crate::Res; use crate::late::PatternSource; -use crate::{Res, fluent_generated as fluent}; #[derive(Diagnostic)] -#[diag(resolve_generic_params_from_outer_item, code = E0401)] -#[note] +#[diag("can't use {$is_self -> + [true] `Self` + *[false] generic parameters + } from outer item", code = E0401)] +#[note( + "nested items are independent from their parent item for everything except for privacy and name resolution" +)] pub(crate) struct GenericParamsFromOuterItem { #[primary_span] - #[label] + #[label( + "use of {$is_self -> + [true] `Self` + *[false] generic parameter + } from outer item" + )] pub(crate) span: Span, #[subdiagnostic] pub(crate) label: Option, @@ -31,7 +41,12 @@ pub(crate) struct GenericParamsFromOuterItem { } #[derive(Subdiagnostic)] -#[label(resolve_generic_params_from_outer_item_inner_item)] +#[label( + "{$is_self -> + [true] `Self` + *[false] generic parameter + } used in this inner {$descr}" +)] pub(crate) struct GenericParamsFromOuterItemInnerItem { #[primary_span] pub(crate) span: Span, @@ -40,27 +55,27 @@ pub(crate) struct GenericParamsFromOuterItemInnerItem { #[derive(Subdiagnostic)] pub(crate) enum GenericParamsFromOuterItemStaticOrConst { - #[note(resolve_generic_params_from_outer_item_static)] + #[note("a `static` is a separate item from the item that contains it")] Static, - #[note(resolve_generic_params_from_outer_item_const)] + #[note("a `const` is a separate item from the item that contains it")] Const, } #[derive(Subdiagnostic)] pub(crate) enum GenericParamsFromOuterItemLabel { - #[label(resolve_generic_params_from_outer_item_self_ty_param)] + #[label("can't use `Self` here")] SelfTyParam(#[primary_span] Span), - #[label(resolve_generic_params_from_outer_item_self_ty_alias)] + #[label("`Self` type implicitly declared here, by this `impl`")] SelfTyAlias(#[primary_span] Span), - #[label(resolve_generic_params_from_outer_item_ty_param)] + #[label("type parameter from outer item")] TyParam(#[primary_span] Span), - #[label(resolve_generic_params_from_outer_item_const_param)] + #[label("const parameter from outer item")] ConstParam(#[primary_span] Span), } #[derive(Subdiagnostic)] #[suggestion( - resolve_suggestion, + "try introducing a local generic parameter here", code = "{snippet}", applicability = "maybe-incorrect", style = "verbose" @@ -72,7 +87,7 @@ pub(crate) struct GenericParamsFromOuterItemSugg { } #[derive(Subdiagnostic)] #[suggestion( - resolve_refer_to_type_directly, + "refer to the type directly here instead", code = "{snippet}", applicability = "maybe-incorrect", style = "verbose" @@ -84,21 +99,21 @@ pub(crate) struct UseTypeDirectly { } #[derive(Diagnostic)] -#[diag(resolve_name_is_already_used_as_generic_parameter, code = E0403)] +#[diag("the name `{$name}` is already used for a generic parameter in this item's generic parameters", code = E0403)] pub(crate) struct NameAlreadyUsedInParameterList { #[primary_span] - #[label] + #[label("already used")] pub(crate) span: Span, - #[label(resolve_first_use_of_name)] + #[label("first use of `{$name}`")] pub(crate) first_use_span: Span, pub(crate) name: Ident, } #[derive(Diagnostic)] -#[diag(resolve_method_not_member_of_trait, code = E0407)] +#[diag("method `{$method}` is not a member of trait `{$trait_}`", code = E0407)] pub(crate) struct MethodNotMemberOfTrait { #[primary_span] - #[label] + #[label("not a member of trait `{$trait_}`")] pub(crate) span: Span, pub(crate) method: Ident, pub(crate) trait_: String, @@ -108,7 +123,7 @@ pub(crate) struct MethodNotMemberOfTrait { #[derive(Subdiagnostic)] #[suggestion( - resolve_associated_fn_with_similar_name_exists, + "there is an associated function with a similar name", code = "{candidate}", applicability = "maybe-incorrect" )] @@ -119,10 +134,10 @@ pub(crate) struct AssociatedFnWithSimilarNameExists { } #[derive(Diagnostic)] -#[diag(resolve_type_not_member_of_trait, code = E0437)] +#[diag("type `{$type_}` is not a member of trait `{$trait_}`", code = E0437)] pub(crate) struct TypeNotMemberOfTrait { #[primary_span] - #[label] + #[label("not a member of trait `{$trait_}`")] pub(crate) span: Span, pub(crate) type_: Ident, pub(crate) trait_: String, @@ -132,7 +147,7 @@ pub(crate) struct TypeNotMemberOfTrait { #[derive(Subdiagnostic)] #[suggestion( - resolve_associated_type_with_similar_name_exists, + "there is an associated type with a similar name", code = "{candidate}", applicability = "maybe-incorrect" )] @@ -143,10 +158,10 @@ pub(crate) struct AssociatedTypeWithSimilarNameExists { } #[derive(Diagnostic)] -#[diag(resolve_const_not_member_of_trait, code = E0438)] +#[diag("const `{$const_}` is not a member of trait `{$trait_}`", code = E0438)] pub(crate) struct ConstNotMemberOfTrait { #[primary_span] - #[label] + #[label("not a member of trait `{$trait_}`")] pub(crate) span: Span, pub(crate) const_: Ident, pub(crate) trait_: String, @@ -156,7 +171,7 @@ pub(crate) struct ConstNotMemberOfTrait { #[derive(Subdiagnostic)] #[suggestion( - resolve_associated_const_with_similar_name_exists, + "there is an associated constant with a similar name", code = "{candidate}", applicability = "maybe-incorrect" )] @@ -167,39 +182,39 @@ pub(crate) struct AssociatedConstWithSimilarNameExists { } #[derive(Diagnostic)] -#[diag(resolve_variable_bound_with_different_mode, code = E0409)] +#[diag("variable `{$variable_name}` is bound inconsistently across alternatives separated by `|`", code = E0409)] pub(crate) struct VariableBoundWithDifferentMode { #[primary_span] - #[label] + #[label("bound in different ways")] pub(crate) span: Span, - #[label(resolve_first_binding_span)] + #[label("first binding")] pub(crate) first_binding_span: Span, pub(crate) variable_name: Ident, } #[derive(Diagnostic)] -#[diag(resolve_ident_bound_more_than_once_in_parameter_list, code = E0415)] +#[diag("identifier `{$identifier}` is bound more than once in this parameter list", code = E0415)] pub(crate) struct IdentifierBoundMoreThanOnceInParameterList { #[primary_span] - #[label] + #[label("used as parameter more than once")] pub(crate) span: Span, pub(crate) identifier: Ident, } #[derive(Diagnostic)] -#[diag(resolve_ident_bound_more_than_once_in_same_pattern, code = E0416)] +#[diag("identifier `{$identifier}` is bound more than once in the same pattern", code = E0416)] pub(crate) struct IdentifierBoundMoreThanOnceInSamePattern { #[primary_span] - #[label] + #[label("used in a pattern more than once")] pub(crate) span: Span, pub(crate) identifier: Ident, } #[derive(Diagnostic)] -#[diag(resolve_undeclared_label, code = E0426)] +#[diag("use of undeclared label `{$name}`", code = E0426)] pub(crate) struct UndeclaredLabel { #[primary_span] - #[label] + #[label("undeclared label `{$name}`")] pub(crate) span: Span, pub(crate) name: Symbol, #[subdiagnostic] @@ -211,12 +226,12 @@ pub(crate) struct UndeclaredLabel { } #[derive(Subdiagnostic)] -#[label(resolve_label_with_similar_name_reachable)] +#[label("a label with a similar name is reachable")] pub(crate) struct LabelWithSimilarNameReachable(#[primary_span] pub(crate) Span); #[derive(Subdiagnostic)] #[suggestion( - resolve_try_using_similarly_named_label, + "try using similarly named label", code = "{ident_name}", applicability = "maybe-incorrect" )] @@ -227,38 +242,38 @@ pub(crate) struct TryUsingSimilarlyNamedLabel { } #[derive(Subdiagnostic)] -#[label(resolve_unreachable_label_with_similar_name_exists)] +#[label("a label with a similar name exists but is unreachable")] pub(crate) struct UnreachableLabelWithSimilarNameExists { #[primary_span] pub(crate) ident_span: Span, } #[derive(Diagnostic)] -#[diag(resolve_self_import_can_only_appear_once_in_the_list, code = E0430)] +#[diag("`self` import can only appear once in an import list", code = E0430)] pub(crate) struct SelfImportCanOnlyAppearOnceInTheList { #[primary_span] - #[label] + #[label("can only appear once in an import list")] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(resolve_self_import_only_in_import_list_with_non_empty_prefix, code = E0431)] +#[diag("`self` import can only appear in an import list with a non-empty prefix", code = E0431)] pub(crate) struct SelfImportOnlyInImportListWithNonEmptyPrefix { #[primary_span] - #[label] + #[label("can only appear in an import list with a non-empty prefix")] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(resolve_cannot_capture_dynamic_environment_in_fn_item, code = E0434)] -#[help] +#[diag("can't capture dynamic environment in a fn item", code = E0434)] +#[help("use the `|| {\"{\"} ... {\"}\"}` closure form instead")] pub(crate) struct CannotCaptureDynamicEnvironmentInFnItem { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(resolve_attempt_to_use_non_constant_value_in_constant, code = E0435)] +#[diag("attempt to use a non-constant value in a constant", code = E0435)] pub(crate) struct AttemptToUseNonConstantValueInConstant<'a> { #[primary_span] pub(crate) span: Span, @@ -272,7 +287,7 @@ pub(crate) struct AttemptToUseNonConstantValueInConstant<'a> { #[derive(Subdiagnostic)] #[multipart_suggestion( - resolve_attempt_to_use_non_constant_value_in_constant_with_suggestion, + "consider using `{$suggestion}` instead of `{$current}`", style = "verbose", applicability = "has-placeholders" )] @@ -287,14 +302,14 @@ pub(crate) struct AttemptToUseNonConstantValueInConstantWithSuggestion<'a> { } #[derive(Subdiagnostic)] -#[label(resolve_attempt_to_use_non_constant_value_in_constant_label_with_suggestion)] +#[label("non-constant value")] pub(crate) struct AttemptToUseNonConstantValueInConstantLabelWithSuggestion { #[primary_span] pub(crate) span: Span, } #[derive(Subdiagnostic)] -#[label(resolve_attempt_to_use_non_constant_value_in_constant_without_suggestion)] +#[label("this would need to be a `{$suggestion}`")] pub(crate) struct AttemptToUseNonConstantValueInConstantWithoutSuggestion<'a> { #[primary_span] pub(crate) ident_span: Span, @@ -302,7 +317,7 @@ pub(crate) struct AttemptToUseNonConstantValueInConstantWithoutSuggestion<'a> { } #[derive(Diagnostic)] -#[diag(resolve_self_imports_only_allowed_within, code = E0429)] +#[diag("`self` imports are only allowed within a {\"{\"} {\"}\"} list", code = E0429)] pub(crate) struct SelfImportsOnlyAllowedWithin { #[primary_span] pub(crate) span: Span, @@ -314,7 +329,7 @@ pub(crate) struct SelfImportsOnlyAllowedWithin { #[derive(Subdiagnostic)] #[suggestion( - resolve_self_imports_only_allowed_within_suggestion, + "consider importing the module directly", code = "", applicability = "machine-applicable" )] @@ -325,7 +340,7 @@ pub(crate) struct SelfImportsOnlyAllowedWithinSuggestion { #[derive(Subdiagnostic)] #[multipart_suggestion( - resolve_self_imports_only_allowed_within_multipart_suggestion, + "alternatively, use the multi-path `use` syntax to import `self`", applicability = "machine-applicable" )] pub(crate) struct SelfImportsOnlyAllowedWithinMultipartSuggestion { @@ -336,17 +351,17 @@ pub(crate) struct SelfImportsOnlyAllowedWithinMultipartSuggestion { } #[derive(Diagnostic)] -#[diag(resolve_binding_shadows_something_unacceptable, code = E0530)] +#[diag("{$shadowing_binding}s cannot shadow {$shadowed_binding}s", code = E0530)] pub(crate) struct BindingShadowsSomethingUnacceptable<'a> { #[primary_span] - #[label] + #[label("cannot be named the same as {$article} {$shadowed_binding}")] pub(crate) span: Span, pub(crate) shadowing_binding: PatternSource, pub(crate) shadowed_binding: Res, pub(crate) article: &'a str, #[subdiagnostic] pub(crate) sub_suggestion: Option, - #[label(resolve_label_shadowed_binding)] + #[label("the {$shadowed_binding} `{$name}` is {$participle} here")] pub(crate) shadowed_binding_span: Span, pub(crate) participle: &'a str, pub(crate) name: Symbol, @@ -354,7 +369,7 @@ pub(crate) struct BindingShadowsSomethingUnacceptable<'a> { #[derive(Subdiagnostic)] #[suggestion( - resolve_binding_shadows_something_unacceptable_suggestion, + "try specify the pattern arguments", code = "{name}(..)", applicability = "unspecified" )] @@ -365,51 +380,51 @@ pub(crate) struct BindingShadowsSomethingUnacceptableSuggestion { } #[derive(Diagnostic)] -#[diag(resolve_forward_declared_generic_param, code = E0128)] +#[diag("generic parameter defaults cannot reference parameters before they are declared", code = E0128)] pub(crate) struct ForwardDeclaredGenericParam { #[primary_span] - #[label] + #[label("cannot reference `{$param}` before it is declared")] pub(crate) span: Span, pub(crate) param: Symbol, } #[derive(Diagnostic)] -#[diag(resolve_forward_declared_generic_in_const_param_ty)] +#[diag("const parameter types cannot reference parameters before they are declared")] pub(crate) struct ForwardDeclaredGenericInConstParamTy { #[primary_span] - #[label] + #[label("const parameter type cannot reference `{$param}` before it is declared")] pub(crate) span: Span, pub(crate) param: Symbol, } #[derive(Diagnostic)] -#[diag(resolve_param_in_ty_of_const_param, code = E0770)] +#[diag("the type of const parameters must not depend on other generic parameters", code = E0770)] pub(crate) struct ParamInTyOfConstParam { #[primary_span] - #[label] + #[label("the type must not depend on the parameter `{$name}`")] pub(crate) span: Span, pub(crate) name: Symbol, } #[derive(Diagnostic)] -#[diag(resolve_self_in_generic_param_default, code = E0735)] +#[diag("generic parameters cannot use `Self` in their defaults", code = E0735)] pub(crate) struct SelfInGenericParamDefault { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(resolve_self_in_const_generic_ty)] +#[diag("cannot use `Self` in const parameter type")] pub(crate) struct SelfInConstGenericTy { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(resolve_param_in_non_trivial_anon_const)] +#[diag("generic parameters may not be used in const operations")] pub(crate) struct ParamInNonTrivialAnonConst { #[primary_span] - #[label] + #[label("cannot perform const operation using `{$name}`")] pub(crate) span: Span, pub(crate) name: Symbol, #[subdiagnostic] @@ -419,29 +434,29 @@ pub(crate) struct ParamInNonTrivialAnonConst { } #[derive(Subdiagnostic)] -#[help(resolve_param_in_non_trivial_anon_const_help)] +#[help("add `#![feature(generic_const_exprs)]` to allow generic const expressions")] pub(crate) struct ParamInNonTrivialAnonConstHelp; #[derive(Debug)] #[derive(Subdiagnostic)] pub(crate) enum ParamKindInNonTrivialAnonConst { - #[note(resolve_type_param_in_non_trivial_anon_const)] + #[note("type parameters may not be used in const expressions")] Type, - #[help(resolve_const_param_in_non_trivial_anon_const)] + #[help("const parameters may only be used as standalone arguments here, i.e. `{$name}`")] Const { name: Symbol }, - #[note(resolve_lifetime_param_in_non_trivial_anon_const)] + #[note("lifetime parameters may not be used in const expressions")] Lifetime, } #[derive(Diagnostic)] -#[diag(resolve_unreachable_label, code = E0767)] -#[note] +#[diag("use of unreachable label `{$name}`", code = E0767)] +#[note("labels are unreachable through functions, closures, async blocks and modules")] pub(crate) struct UnreachableLabel { #[primary_span] - #[label] + #[label("unreachable label `{$name}`")] pub(crate) span: Span, pub(crate) name: Symbol, - #[label(resolve_label_definition_span)] + #[label("unreachable label defined here")] pub(crate) definition_span: Span, #[subdiagnostic] pub(crate) sub_suggestion: Option, @@ -453,7 +468,7 @@ pub(crate) struct UnreachableLabel { #[derive(Subdiagnostic)] #[suggestion( - resolve_unreachable_label_suggestion_use_similarly_named, + "try using similarly named label", code = "{ident_name}", applicability = "maybe-incorrect" )] @@ -464,104 +479,114 @@ pub(crate) struct UnreachableLabelSubSuggestion { } #[derive(Subdiagnostic)] -#[label(resolve_unreachable_label_similar_name_reachable)] +#[label("a label with a similar name is reachable")] pub(crate) struct UnreachableLabelSubLabel { #[primary_span] pub(crate) ident_span: Span, } #[derive(Subdiagnostic)] -#[label(resolve_unreachable_label_similar_name_unreachable)] +#[label("a label with a similar name exists but is also unreachable")] pub(crate) struct UnreachableLabelSubLabelUnreachable { #[primary_span] pub(crate) ident_span: Span, } #[derive(Diagnostic)] -#[diag(resolve_invalid_asm_sym)] -#[help] +#[diag("invalid `sym` operand")] +#[help("`sym` operands must refer to either a function or a static")] pub(crate) struct InvalidAsmSym { #[primary_span] - #[label] + #[label("is a local variable")] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(resolve_lowercase_self)] +#[diag("attempt to use a non-constant value in a constant")] pub(crate) struct LowercaseSelf { #[primary_span] - #[suggestion(code = "Self", applicability = "maybe-incorrect", style = "short")] + #[suggestion( + "try using `Self`", + code = "Self", + applicability = "maybe-incorrect", + style = "short" + )] pub(crate) span: Span, } #[derive(Debug)] #[derive(Diagnostic)] -#[diag(resolve_binding_in_never_pattern)] +#[diag("never patterns cannot contain variable bindings")] pub(crate) struct BindingInNeverPattern { #[primary_span] - #[suggestion(code = "_", applicability = "machine-applicable", style = "short")] + #[suggestion( + "use a wildcard `_` instead", + code = "_", + applicability = "machine-applicable", + style = "short" + )] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(resolve_trait_impl_duplicate, code = E0201)] +#[diag("duplicate definitions with name `{$name}`:", code = E0201)] pub(crate) struct TraitImplDuplicate { #[primary_span] - #[label] + #[label("duplicate definition")] pub(crate) span: Span, - #[label(resolve_old_span_label)] + #[label("previous definition here")] pub(crate) old_span: Span, - #[label(resolve_trait_item_span)] + #[label("item in trait")] pub(crate) trait_item_span: Span, pub(crate) name: Ident, } #[derive(Diagnostic)] -#[diag(resolve_relative_2018)] +#[diag("relative paths are not supported in visibilities in 2018 edition or later")] pub(crate) struct Relative2018 { #[primary_span] pub(crate) span: Span, - #[suggestion(code = "crate::{path_str}", applicability = "maybe-incorrect")] + #[suggestion("try", code = "crate::{path_str}", applicability = "maybe-incorrect")] pub(crate) path_span: Span, pub(crate) path_str: String, } #[derive(Diagnostic)] -#[diag(resolve_ancestor_only, code = E0742)] +#[diag("visibilities can only be restricted to ancestor modules", code = E0742)] pub(crate) struct AncestorOnly(#[primary_span] pub(crate) Span); #[derive(Diagnostic)] -#[diag(resolve_expected_module_found, code = E0577)] +#[diag("expected module, found {$res} `{$path_str}`", code = E0577)] pub(crate) struct ExpectedModuleFound { #[primary_span] - #[label] + #[label("not a module")] pub(crate) span: Span, pub(crate) res: Res, pub(crate) path_str: String, } #[derive(Diagnostic)] -#[diag(resolve_indeterminate, code = E0578)] +#[diag("cannot determine resolution for the visibility", code = E0578)] pub(crate) struct Indeterminate(#[primary_span] pub(crate) Span); #[derive(Diagnostic)] -#[diag(resolve_tool_module_imported)] +#[diag("cannot use a tool module through an import")] pub(crate) struct ToolModuleImported { #[primary_span] pub(crate) span: Span, - #[note] + #[note("the tool module imported here")] pub(crate) import: Span, } #[derive(Diagnostic)] -#[diag(resolve_module_only)] +#[diag("visibility must resolve to a module")] pub(crate) struct ModuleOnly(#[primary_span] pub(crate) Span); #[derive(Diagnostic)] -#[diag(resolve_macro_expected_found)] +#[diag("expected {$expected}, found {$found} `{$macro_path}`")] pub(crate) struct MacroExpectedFound<'a> { #[primary_span] - #[label] + #[label("not {$article} {$expected}")] pub(crate) span: Span, pub(crate) found: &'a str, pub(crate) article: &'static str, @@ -574,60 +599,66 @@ pub(crate) struct MacroExpectedFound<'a> { } #[derive(Subdiagnostic)] -#[help(resolve_remove_surrounding_derive)] +#[help("remove from the surrounding `derive()`")] pub(crate) struct RemoveSurroundingDerive { #[primary_span] pub(crate) span: Span, } #[derive(Subdiagnostic)] -#[help(resolve_add_as_non_derive)] +#[help( + " + add as non-Derive macro + `#[{$macro_path}]`" +)] pub(crate) struct AddAsNonDerive<'a> { pub(crate) macro_path: &'a str, } #[derive(Diagnostic)] -#[diag(resolve_proc_macro_same_crate)] +#[diag("can't use a procedural macro from the same crate that defines it")] pub(crate) struct ProcMacroSameCrate { #[primary_span] pub(crate) span: Span, - #[help] + #[help("you can define integration tests in a directory named `tests`")] pub(crate) is_test: bool, } #[derive(LintDiagnostic)] -#[diag(resolve_proc_macro_derive_resolution_fallback)] +#[diag("cannot find {$ns_descr} `{$ident}` in this scope")] pub(crate) struct ProcMacroDeriveResolutionFallback { - #[label] + #[label("names from parent modules are not accessible without an explicit import")] pub span: Span, pub ns_descr: &'static str, pub ident: Symbol, } #[derive(LintDiagnostic)] -#[diag(resolve_macro_expanded_macro_exports_accessed_by_absolute_paths)] +#[diag( + "macro-expanded `macro_export` macros from the current crate cannot be referred to by absolute paths" +)] pub(crate) struct MacroExpandedMacroExportsAccessedByAbsolutePaths { - #[note] + #[note("the macro is defined here")] pub definition: Span, } #[derive(Diagnostic)] -#[diag(resolve_imported_crate)] +#[diag("`$crate` may not be imported")] pub(crate) struct CrateImported { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(resolve_macro_use_extern_crate_self)] +#[diag("`#[macro_use]` is not supported on `extern crate self`")] pub(crate) struct MacroUseExternCrateSelf { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(resolve_accessible_unsure)] -#[note] +#[diag("not sure whether the path is accessible or not")] +#[note("the type may have associated items, but we are currently not checking them")] pub(crate) struct CfgAccessibleUnsure { #[primary_span] pub(crate) span: Span, @@ -635,10 +666,10 @@ pub(crate) struct CfgAccessibleUnsure { #[derive(Debug)] #[derive(Diagnostic)] -#[diag(resolve_param_in_enum_discriminant)] +#[diag("generic parameters may not be used in enum discriminant values")] pub(crate) struct ParamInEnumDiscriminant { #[primary_span] - #[label] + #[label("cannot perform const operation using `{$name}`")] pub(crate) span: Span, pub(crate) name: Symbol, #[subdiagnostic] @@ -648,16 +679,16 @@ pub(crate) struct ParamInEnumDiscriminant { #[derive(Debug)] #[derive(Subdiagnostic)] pub(crate) enum ParamKindInEnumDiscriminant { - #[note(resolve_type_param_in_enum_discriminant)] + #[note("type parameters may not be used in enum discriminant values")] Type, - #[note(resolve_const_param_in_enum_discriminant)] + #[note("const parameters may not be used in enum discriminant values")] Const, - #[note(resolve_lifetime_param_in_enum_discriminant)] + #[note("lifetime parameters may not be used in enum discriminant values")] Lifetime, } #[derive(Subdiagnostic)] -#[label(resolve_change_import_binding)] +#[label("you can use `as` to change the binding name of the import")] pub(crate) struct ChangeImportBinding { #[primary_span] pub(crate) span: Span, @@ -665,7 +696,7 @@ pub(crate) struct ChangeImportBinding { #[derive(Subdiagnostic)] #[suggestion( - resolve_change_import_binding, + "you can use `as` to change the binding name of the import", code = "{suggestion}", applicability = "maybe-incorrect" )] @@ -676,7 +707,7 @@ pub(crate) struct ChangeImportBindingSuggestion { } #[derive(Diagnostic)] -#[diag(resolve_imports_cannot_refer_to)] +#[diag("imports cannot refer to {$what}")] pub(crate) struct ImportsCannotReferTo<'a> { #[primary_span] pub(crate) span: Span, @@ -684,7 +715,7 @@ pub(crate) struct ImportsCannotReferTo<'a> { } #[derive(Diagnostic)] -#[diag(resolve_cannot_find_ident_in_this_scope)] +#[diag("cannot find {$expected} `{$ident}` in this scope")] pub(crate) struct CannotFindIdentInThisScope<'a> { #[primary_span] pub(crate) span: Span, @@ -693,7 +724,7 @@ pub(crate) struct CannotFindIdentInThisScope<'a> { } #[derive(Subdiagnostic)] -#[note(resolve_explicit_unsafe_traits)] +#[note("unsafe traits like `{$ident}` should be implemented explicitly")] pub(crate) struct ExplicitUnsafeTraits { #[primary_span] pub(crate) span: Span, @@ -701,14 +732,14 @@ pub(crate) struct ExplicitUnsafeTraits { } #[derive(Subdiagnostic)] -#[note(resolve_macro_defined_later)] +#[note("a macro with the same name exists, but it appears later")] pub(crate) struct MacroDefinedLater { #[primary_span] pub(crate) span: Span, } #[derive(Subdiagnostic)] -#[label(resolve_consider_move_macro_position)] +#[label("consider moving the definition of `{$ident}` before this call")] pub(crate) struct MacroSuggMovePosition { #[primary_span] pub(crate) span: Span, @@ -717,19 +748,19 @@ pub(crate) struct MacroSuggMovePosition { #[derive(Subdiagnostic)] pub(crate) enum MacroRulesNot { - #[label(resolve_macro_cannot_use_as_fn_like)] + #[label("`{$ident}` exists, but has no rules for function-like invocation")] Func { #[primary_span] span: Span, ident: Ident, }, - #[label(resolve_macro_cannot_use_as_attr)] + #[label("`{$ident}` exists, but has no `attr` rules")] Attr { #[primary_span] span: Span, ident: Ident, }, - #[label(resolve_macro_cannot_use_as_derive)] + #[label("`{$ident}` exists, but has no `derive` rules")] Derive { #[primary_span] span: Span, @@ -738,22 +769,18 @@ pub(crate) enum MacroRulesNot { } #[derive(Subdiagnostic)] -#[note(resolve_missing_macro_rules_name)] +#[note("maybe you have forgotten to define a name for this `macro_rules!`")] pub(crate) struct MaybeMissingMacroRulesName { #[primary_span] pub(crate) spans: MultiSpan, } #[derive(Subdiagnostic)] -#[help(resolve_added_macro_use)] +#[help("have you added the `#[macro_use]` on the module/import?")] pub(crate) struct AddedMacroUse; #[derive(Subdiagnostic)] -#[suggestion( - resolve_consider_adding_a_derive, - code = "{suggestion}", - applicability = "maybe-incorrect" -)] +#[suggestion("consider adding a derive", code = "{suggestion}", applicability = "maybe-incorrect")] pub(crate) struct ConsiderAddingADerive { #[primary_span] pub(crate) span: Span, @@ -761,15 +788,15 @@ pub(crate) struct ConsiderAddingADerive { } #[derive(Diagnostic)] -#[diag(resolve_cannot_determine_import_resolution)] +#[diag("cannot determine resolution for the import")] pub(crate) struct CannotDetermineImportResolution { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(resolve_cannot_determine_macro_resolution)] -#[note] +#[diag("cannot determine resolution for the {$kind} `{$path}`")] +#[note("import resolution is stuck, try simplifying macro imports")] pub(crate) struct CannotDetermineMacroResolution { #[primary_span] pub(crate) span: Span, @@ -778,7 +805,7 @@ pub(crate) struct CannotDetermineMacroResolution { } #[derive(Diagnostic)] -#[diag(resolve_cannot_be_reexported_private, code = E0364)] +#[diag("`{$ident}` is private, and cannot be re-exported", code = E0364)] pub(crate) struct CannotBeReexportedPrivate { #[primary_span] pub(crate) span: Span, @@ -786,7 +813,7 @@ pub(crate) struct CannotBeReexportedPrivate { } #[derive(Diagnostic)] -#[diag(resolve_cannot_be_reexported_crate_public, code = E0364)] +#[diag("`{$ident}` is only public within the crate, and cannot be re-exported outside", code = E0364)] pub(crate) struct CannotBeReexportedCratePublic { #[primary_span] pub(crate) span: Span, @@ -794,35 +821,40 @@ pub(crate) struct CannotBeReexportedCratePublic { } #[derive(Diagnostic)] -#[diag(resolve_cannot_be_reexported_private, code = E0365)] -#[note(resolve_consider_declaring_with_pub)] +#[diag("`{$ident}` is private, and cannot be re-exported", code = E0365)] +#[note("consider declaring type or module `{$ident}` with `pub`")] pub(crate) struct CannotBeReexportedPrivateNS { #[primary_span] - #[label(resolve_reexport_of_private)] + #[label("re-export of private `{$ident}`")] pub(crate) span: Span, pub(crate) ident: Ident, } #[derive(Diagnostic)] -#[diag(resolve_cannot_be_reexported_crate_public, code = E0365)] -#[note(resolve_consider_declaring_with_pub)] +#[diag("`{$ident}` is only public within the crate, and cannot be re-exported outside", code = E0365)] +#[note("consider declaring type or module `{$ident}` with `pub`")] pub(crate) struct CannotBeReexportedCratePublicNS { #[primary_span] - #[label(resolve_reexport_of_crate_public)] + #[label("re-export of crate public `{$ident}`")] pub(crate) span: Span, pub(crate) ident: Ident, } #[derive(LintDiagnostic)] -#[diag(resolve_private_extern_crate_reexport, code = E0365)] +#[diag("extern crate `{$ident}` is private and cannot be re-exported", code = E0365)] pub(crate) struct PrivateExternCrateReexport { pub ident: Ident, - #[suggestion(code = "pub ", style = "verbose", applicability = "maybe-incorrect")] + #[suggestion( + "consider making the `extern crate` item publicly accessible", + code = "pub ", + style = "verbose", + applicability = "maybe-incorrect" + )] pub sugg: Span, } #[derive(Subdiagnostic)] -#[help(resolve_consider_adding_macro_export)] +#[help("consider adding a `#[macro_export]` to the macro in the imported module")] pub(crate) struct ConsiderAddingMacroExport { #[primary_span] pub(crate) span: Span, @@ -830,7 +862,7 @@ pub(crate) struct ConsiderAddingMacroExport { #[derive(Subdiagnostic)] #[suggestion( - resolve_consider_marking_as_pub_crate, + "in case you want to use the macro within this crate only, reduce the visibility to `pub(crate)`", code = "pub(crate)", applicability = "maybe-incorrect" )] @@ -840,7 +872,7 @@ pub(crate) struct ConsiderMarkingAsPubCrate { } #[derive(Subdiagnostic)] -#[note(resolve_consider_marking_as_pub)] +#[note("consider marking `{$ident}` as `pub` in the imported module")] pub(crate) struct ConsiderMarkingAsPub { #[primary_span] pub(crate) span: Span, @@ -848,7 +880,7 @@ pub(crate) struct ConsiderMarkingAsPub { } #[derive(Diagnostic)] -#[diag(resolve_cannot_glob_import_possible_crates)] +#[diag("cannot glob-import all possible crates")] pub(crate) struct CannotGlobImportAllCrates { #[primary_span] pub(crate) span: Span, @@ -856,7 +888,7 @@ pub(crate) struct CannotGlobImportAllCrates { #[derive(Subdiagnostic)] #[suggestion( - resolve_unexpected_res_change_ty_to_const_param_sugg, + "you might have meant to write a const parameter here", code = "const ", style = "verbose" )] @@ -869,7 +901,7 @@ pub(crate) struct UnexpectedResChangeTyToConstParamSugg { #[derive(Subdiagnostic)] #[multipart_suggestion( - resolve_unexpected_res_change_ty_to_const_param_sugg, + "you might have meant to write a const parameter here", applicability = "has-placeholders", style = "verbose" )] @@ -882,7 +914,7 @@ pub(crate) struct UnexpectedResChangeTyParamToConstParamSugg { #[derive(Subdiagnostic)] #[suggestion( - resolve_unexpected_res_use_at_op_in_slice_pat_with_range_sugg, + "if you meant to collect the rest of the slice in `{$ident}`, use the at operator", code = "{snippet}", applicability = "maybe-incorrect", style = "verbose" @@ -895,23 +927,27 @@ pub(crate) struct UnexpectedResUseAtOpInSlicePatWithRangeSugg { } #[derive(Diagnostic)] -#[diag(resolve_extern_crate_loading_macro_not_at_crate_root, code = E0468)] +#[diag("an `extern crate` loading macros must be at the crate root", code = E0468)] pub(crate) struct ExternCrateLoadingMacroNotAtCrateRoot { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(resolve_extern_crate_self_requires_renaming)] +#[diag("`extern crate self;` requires renaming")] pub(crate) struct ExternCrateSelfRequiresRenaming { #[primary_span] - #[suggestion(code = "extern crate self as name;", applicability = "has-placeholders")] + #[suggestion( + "rename the `self` crate to be able to import it", + code = "extern crate self as name;", + applicability = "has-placeholders" + )] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(resolve_macro_use_name_already_in_use)] -#[note] +#[diag("`{$name}` is already in scope")] +#[note("macro-expanded `#[macro_use]`s may not shadow existing macros (see RFC 1560)")] pub(crate) struct MacroUseNameAlreadyInUse { #[primary_span] pub(crate) span: Span, @@ -919,74 +955,80 @@ pub(crate) struct MacroUseNameAlreadyInUse { } #[derive(Diagnostic)] -#[diag(resolve_imported_macro_not_found, code = E0469)] +#[diag("imported macro not found", code = E0469)] pub(crate) struct ImportedMacroNotFound { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(resolve_macro_extern_deprecated)] +#[diag("`#[macro_escape]` is a deprecated synonym for `#[macro_use]`")] pub(crate) struct MacroExternDeprecated { #[primary_span] pub(crate) span: Span, - #[help] + #[help("try an outer attribute: `#[macro_use]`")] pub inner_attribute: bool, } #[derive(Diagnostic)] -#[diag(resolve_arguments_macro_use_not_allowed)] +#[diag("arguments to `macro_use` are not allowed here")] pub(crate) struct ArgumentsMacroUseNotAllowed { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(resolve_unnamed_crate_root_import)] +#[diag("crate root imports need to be explicitly named: `use crate as name;`")] pub(crate) struct UnnamedCrateRootImport { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(resolve_macro_expanded_extern_crate_cannot_shadow_extern_arguments)] +#[diag("macro-expanded `extern crate` items cannot shadow names passed with `--extern`")] pub(crate) struct MacroExpandedExternCrateCannotShadowExternArguments { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(resolve_elided_anonymous_lifetime_report_error, code = E0637)] +#[diag("`&` without an explicit lifetime name cannot be used here", code = E0637)] pub(crate) struct ElidedAnonymousLifetimeReportError { #[primary_span] - #[label] + #[label("explicit lifetime name needed here")] pub(crate) span: Span, #[subdiagnostic] pub(crate) suggestion: Option, } #[derive(Diagnostic)] -#[diag(resolve_lending_iterator_report_error)] +#[diag( + "associated type `Iterator::Item` is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type" +)] pub(crate) struct LendingIteratorReportError { #[primary_span] pub(crate) lifetime: Span, - #[note] + #[note( + "you can't create an `Iterator` that borrows each `Item` from itself, but you can instead create a new type that borrows your existing type and implement `Iterator` for that new type" + )] pub(crate) ty: Span, } #[derive(Diagnostic)] -#[diag(resolve_anonymous_lifetime_non_gat_report_error)] +#[diag("missing lifetime in associated type")] pub(crate) struct AnonymousLifetimeNonGatReportError { #[primary_span] - #[label] + #[label("this lifetime must come from the implemented type")] pub(crate) lifetime: Span, - #[note] + #[note( + "in the trait the associated type is declared without lifetime parameters, so using a borrowed type for them requires that lifetime to come from the implemented type" + )] pub(crate) decl: MultiSpan, } #[derive(Subdiagnostic)] #[multipart_suggestion( - resolve_elided_anonymous_lifetime_report_error_suggestion, + "consider introducing a higher-ranked lifetime here", applicability = "machine-applicable" )] pub(crate) struct ElidedAnonymousLifetimeReportErrorSuggestion { @@ -997,15 +1039,15 @@ pub(crate) struct ElidedAnonymousLifetimeReportErrorSuggestion { } #[derive(Diagnostic)] -#[diag(resolve_explicit_anonymous_lifetime_report_error, code = E0637)] +#[diag("`'_` cannot be used here", code = E0637)] pub(crate) struct ExplicitAnonymousLifetimeReportError { #[primary_span] - #[label] + #[label("`'_` is a reserved lifetime name")] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(resolve_implicit_elided_lifetimes_not_allowed_here, code = E0726)] +#[diag("implicit elided lifetime not allowed here", code = E0726)] pub(crate) struct ImplicitElidedLifetimeNotAllowedHere { #[primary_span] pub(crate) span: Span, @@ -1014,25 +1056,25 @@ pub(crate) struct ImplicitElidedLifetimeNotAllowedHere { } #[derive(Diagnostic)] -#[diag(resolve_underscore_lifetime_is_reserved, code = E0637)] -#[help] +#[diag("`'_` cannot be used here", code = E0637)] +#[help("use another lifetime specifier")] pub(crate) struct UnderscoreLifetimeIsReserved { #[primary_span] - #[label] + #[label("`'_` is a reserved lifetime name")] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(resolve_static_lifetime_is_reserved, code = E0262)] +#[diag("invalid lifetime parameter name: `{$lifetime}`", code = E0262)] pub(crate) struct StaticLifetimeIsReserved { #[primary_span] - #[label] + #[label("'static is a reserved lifetime name")] pub(crate) span: Span, pub(crate) lifetime: Ident, } #[derive(Diagnostic)] -#[diag(resolve_variable_is_not_bound_in_all_patterns, code = E0408)] +#[diag("variable `{$name}` is not bound in all patterns", code = E0408)] pub(crate) struct VariableIsNotBoundInAllPatterns { #[primary_span] pub(crate) multispan: MultiSpan, @@ -1040,7 +1082,7 @@ pub(crate) struct VariableIsNotBoundInAllPatterns { } #[derive(Subdiagnostic, Debug, Clone)] -#[label(resolve_pattern_doesnt_bind_name)] +#[label("pattern doesn't bind `{$name}`")] pub(crate) struct PatternDoesntBindName { #[primary_span] pub(crate) span: Span, @@ -1048,7 +1090,7 @@ pub(crate) struct PatternDoesntBindName { } #[derive(Subdiagnostic, Debug, Clone)] -#[label(resolve_variable_not_in_all_patterns)] +#[label("variable not in all patterns")] pub(crate) struct VariableNotInAllPatterns { #[primary_span] pub(crate) span: Span, @@ -1056,7 +1098,7 @@ pub(crate) struct VariableNotInAllPatterns { #[derive(Subdiagnostic)] #[multipart_suggestion( - resolve_variable_is_a_typo, + "you might have meant to use the similarly named previously used binding `{$typo}`", applicability = "maybe-incorrect", style = "verbose" )] @@ -1067,8 +1109,8 @@ pub(crate) struct PatternBindingTypo { } #[derive(Diagnostic)] -#[diag(resolve_name_defined_multiple_time)] -#[note] +#[diag("the name `{$name}` is defined multiple times")] +#[note("`{$name}` must be defined only once in the {$descr} namespace of this {$container}")] pub(crate) struct NameDefinedMultipleTime { #[primary_span] pub(crate) span: Span, @@ -1083,12 +1125,12 @@ pub(crate) struct NameDefinedMultipleTime { #[derive(Subdiagnostic)] pub(crate) enum NameDefinedMultipleTimeLabel { - #[label(resolve_name_defined_multiple_time_reimported)] + #[label("`{$name}` reimported here")] Reimported { #[primary_span] span: Span, }, - #[label(resolve_name_defined_multiple_time_redefined)] + #[label("`{$name}` redefined here")] Redefined { #[primary_span] span: Span, @@ -1097,13 +1139,13 @@ pub(crate) enum NameDefinedMultipleTimeLabel { #[derive(Subdiagnostic)] pub(crate) enum NameDefinedMultipleTimeOldBindingLabel { - #[label(resolve_name_defined_multiple_time_old_binding_import)] + #[label("previous import of the {$old_kind} `{$name}` here")] Import { #[primary_span] span: Span, old_kind: &'static str, }, - #[label(resolve_name_defined_multiple_time_old_binding_definition)] + #[label("previous definition of the {$old_kind} `{$name}` here")] Definition { #[primary_span] span: Span, @@ -1112,42 +1154,42 @@ pub(crate) enum NameDefinedMultipleTimeOldBindingLabel { } #[derive(Diagnostic)] -#[diag(resolve_is_private, code = E0603)] +#[diag("{$ident_descr} `{$ident}` is private", code = E0603)] pub(crate) struct IsPrivate<'a> { #[primary_span] - #[label] + #[label("private {$ident_descr}")] pub(crate) span: Span, pub(crate) ident_descr: &'a str, pub(crate) ident: Ident, } #[derive(Diagnostic)] -#[diag(resolve_generic_arguments_in_macro_path)] +#[diag("generic arguments in macro path")] pub(crate) struct GenericArgumentsInMacroPath { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(resolve_attributes_starting_with_rustc_are_reserved)] +#[diag("attributes starting with `rustc` are reserved for use by the `rustc` compiler")] pub(crate) struct AttributesStartingWithRustcAreReserved { #[primary_span] pub(crate) span: Span, } #[derive(Diagnostic)] -#[diag(resolve_cannot_use_through_an_import)] +#[diag("cannot use {$article} {$descr} through an import")] pub(crate) struct CannotUseThroughAnImport { #[primary_span] pub(crate) span: Span, pub(crate) article: &'static str, pub(crate) descr: &'static str, - #[note] + #[note("the {$descr} imported here")] pub(crate) binding_span: Option, } #[derive(Diagnostic)] -#[diag(resolve_name_reserved_in_attribute_namespace)] +#[diag("name `{$ident}` is reserved in attribute namespace")] pub(crate) struct NameReservedInAttributeNamespace { #[primary_span] pub(crate) span: Span, @@ -1155,7 +1197,7 @@ pub(crate) struct NameReservedInAttributeNamespace { } #[derive(Diagnostic)] -#[diag(resolve_cannot_find_builtin_macro_with_name)] +#[diag("cannot find a built-in macro with name `{$ident}`")] pub(crate) struct CannotFindBuiltinMacroWithName { #[primary_span] pub(crate) span: Span, @@ -1163,34 +1205,34 @@ pub(crate) struct CannotFindBuiltinMacroWithName { } #[derive(Diagnostic)] -#[diag(resolve_tool_was_already_registered)] +#[diag("tool `{$tool}` was already registered")] pub(crate) struct ToolWasAlreadyRegistered { #[primary_span] pub(crate) span: Span, pub(crate) tool: Ident, - #[label] + #[label("already registered here")] pub(crate) old_ident_span: Span, } #[derive(Diagnostic)] -#[diag(resolve_tool_only_accepts_identifiers)] +#[diag("`{$tool}` only accepts identifiers")] pub(crate) struct ToolOnlyAcceptsIdentifiers { #[primary_span] - #[label] + #[label("not an identifier")] pub(crate) span: Span, pub(crate) tool: Symbol, } #[derive(Subdiagnostic)] pub(crate) enum DefinedHere { - #[label(resolve_similarly_named_defined_here)] + #[label("similarly named {$candidate_descr} `{$candidate}` defined here")] SimilarlyNamed { #[primary_span] span: Span, candidate_descr: &'static str, candidate: Symbol, }, - #[label(resolve_single_item_defined_here)] + #[label("{$candidate_descr} `{$candidate}` defined here")] SingleItem { #[primary_span] span: Span, @@ -1200,7 +1242,7 @@ pub(crate) enum DefinedHere { } #[derive(Subdiagnostic)] -#[label(resolve_outer_ident_is_not_publicly_reexported)] +#[label("{$outer_ident_descr} `{$outer_ident}` is not publicly re-exported")] pub(crate) struct OuterIdentIsNotPubliclyReexported { #[primary_span] pub(crate) span: Span, @@ -1209,7 +1251,7 @@ pub(crate) struct OuterIdentIsNotPubliclyReexported { } #[derive(Subdiagnostic)] -#[label(resolve_constructor_private_if_any_field_private)] +#[label("a constructor is private if any of the fields is private")] pub(crate) struct ConstructorPrivateIfAnyFieldPrivate { #[primary_span] pub(crate) span: Span, @@ -1217,7 +1259,10 @@ pub(crate) struct ConstructorPrivateIfAnyFieldPrivate { #[derive(Subdiagnostic)] #[multipart_suggestion( - resolve_consider_making_the_field_public, + "{ $number_of_fields -> + [one] consider making the field publicly accessible + *[other] consider making the fields publicly accessible + }", applicability = "maybe-incorrect", style = "verbose" )] @@ -1230,7 +1275,7 @@ pub(crate) struct ConsiderMakingTheFieldPublic { #[derive(Subdiagnostic)] pub(crate) enum ImportIdent { #[suggestion( - resolve_suggestion_import_ident_through_reexport, + "import `{$ident}` through the re-export", code = "{path}", applicability = "machine-applicable", style = "verbose" @@ -1242,7 +1287,7 @@ pub(crate) enum ImportIdent { path: String, }, #[suggestion( - resolve_suggestion_import_ident_directly, + "import `{$ident}` directly", code = "{path}", applicability = "machine-applicable", style = "verbose" @@ -1256,7 +1301,18 @@ pub(crate) enum ImportIdent { } #[derive(Subdiagnostic)] -#[note(resolve_note_and_refers_to_the_item_defined_here)] +#[note( + "{$first -> + [true] {$dots -> + [true] the {$binding_descr} `{$binding_name}` is defined here... + *[false] the {$binding_descr} `{$binding_name}` is defined here + } + *[false] {$dots -> + [true] ...and refers to the {$binding_descr} `{$binding_name}` which is defined here... + *[false] ...and refers to the {$binding_descr} `{$binding_name}` which is defined here + } + }" +)] pub(crate) struct NoteAndRefersToTheItemDefinedHere<'a> { #[primary_span] pub(crate) span: MultiSpan, @@ -1267,7 +1323,7 @@ pub(crate) struct NoteAndRefersToTheItemDefinedHere<'a> { } #[derive(Subdiagnostic)] -#[suggestion(resolve_remove_unnecessary_import, code = "", applicability = "maybe-incorrect")] +#[suggestion("remove unnecessary import", code = "", applicability = "maybe-incorrect")] pub(crate) struct RemoveUnnecessaryImport { #[primary_span] pub(crate) span: Span, @@ -1275,7 +1331,7 @@ pub(crate) struct RemoveUnnecessaryImport { #[derive(Subdiagnostic)] #[suggestion( - resolve_remove_unnecessary_import, + "remove unnecessary import", code = "", applicability = "maybe-incorrect", style = "tool-only" @@ -1286,7 +1342,7 @@ pub(crate) struct ToolOnlyRemoveUnnecessaryImport { } #[derive(Subdiagnostic)] -#[note(resolve_ident_imported_here_but_it_is_desc)] +#[note("`{$imported_ident}` is imported here, but it is {$imported_ident_desc}")] pub(crate) struct IdentImporterHereButItIsDesc<'a> { #[primary_span] pub(crate) span: Span, @@ -1295,7 +1351,7 @@ pub(crate) struct IdentImporterHereButItIsDesc<'a> { } #[derive(Subdiagnostic)] -#[note(resolve_ident_in_scope_but_it_is_desc)] +#[note("`{$imported_ident}` is in scope, but it is {$imported_ident_desc}")] pub(crate) struct IdentInScopeButItIsDesc<'a> { pub(crate) imported_ident: Ident, pub(crate) imported_ident_desc: &'a str, @@ -1319,50 +1375,55 @@ impl Subdiagnostic for FoundItemConfigureOut { let key = "feature".into(); let value = feature.into_diag_arg(&mut None); let msg = diag.dcx.eagerly_translate_to_string( - fluent::resolve_item_was_behind_feature, + inline_fluent!("the item is gated behind the `{$feature}` feature"), [(&key, &value)].into_iter(), ); multispan.push_span_label(span, msg); } ItemWas::CfgOut { span } => { - multispan.push_span_label(span, fluent::resolve_item_was_cfg_out); + multispan.push_span_label(span, inline_fluent!("the item is gated here")); } } - diag.span_note(multispan, fluent::resolve_found_an_item_configured_out); + diag.span_note(multispan, inline_fluent!("found an item that was configured out")); } } #[derive(Diagnostic)] -#[diag(resolve_trait_impl_mismatch)] +#[diag("item `{$name}` is an associated {$kind}, which doesn't match its trait `{$trait_path}`")] pub(crate) struct TraitImplMismatch { #[primary_span] - #[label] + #[label("does not match trait")] pub(crate) span: Span, pub(crate) name: Ident, pub(crate) kind: &'static str, pub(crate) trait_path: String, - #[label(resolve_trait_impl_mismatch_label_item)] + #[label("item in trait")] pub(crate) trait_item_span: Span, } #[derive(LintDiagnostic)] -#[diag(resolve_legacy_derive_helpers)] +#[diag("derive helper attribute is used before it is introduced")] pub(crate) struct LegacyDeriveHelpers { - #[label] + #[label("the attribute is introduced here")] pub span: Span, } #[derive(LintDiagnostic)] -#[diag(resolve_unused_extern_crate)] +#[diag("unused extern crate")] pub(crate) struct UnusedExternCrate { - #[label] + #[label("unused")] pub span: Span, - #[suggestion(code = "", applicability = "machine-applicable", style = "verbose")] + #[suggestion( + "remove the unused `extern crate`", + code = "", + applicability = "machine-applicable", + style = "verbose" + )] pub removal_span: Span, } #[derive(LintDiagnostic)] -#[diag(resolve_reexport_private_dependency)] +#[diag("{$kind} `{$name}` from private dependency '{$krate}' is re-exported")] pub(crate) struct ReexportPrivateDependency { pub name: Symbol, pub kind: &'static str, @@ -1370,32 +1431,32 @@ pub(crate) struct ReexportPrivateDependency { } #[derive(LintDiagnostic)] -#[diag(resolve_unused_label)] +#[diag("unused label")] pub(crate) struct UnusedLabel; #[derive(LintDiagnostic)] -#[diag(resolve_unused_macro_use)] +#[diag("unused `#[macro_use]` import")] pub(crate) struct UnusedMacroUse; #[derive(LintDiagnostic)] -#[diag(resolve_macro_use_deprecated)] -#[help] +#[diag("applying the `#[macro_use]` attribute to an `extern crate` item is deprecated")] +#[help("remove it and import macros at use sites with a `use` item instead")] pub(crate) struct MacroUseDeprecated; #[derive(LintDiagnostic)] -#[diag(resolve_macro_is_private)] +#[diag("macro `{$ident}` is private")] pub(crate) struct MacroIsPrivate { pub ident: Ident, } #[derive(LintDiagnostic)] -#[diag(resolve_unused_macro_definition)] +#[diag("unused macro definition: `{$name}`")] pub(crate) struct UnusedMacroDefinition { pub name: Symbol, } #[derive(LintDiagnostic)] -#[diag(resolve_macro_rule_never_used)] +#[diag("rule #{$n} of macro `{$name}` is never used")] pub(crate) struct MacroRuleNeverUsed { pub n: usize, pub name: Symbol, @@ -1412,36 +1473,43 @@ impl<'a> LintDiagnostic<'a, ()> for UnstableFeature { } #[derive(LintDiagnostic)] -#[diag(resolve_extern_crate_not_idiomatic)] +#[diag("`extern crate` is not idiomatic in the new edition")] pub(crate) struct ExternCrateNotIdiomatic { - #[suggestion(style = "verbose", code = "{code}", applicability = "machine-applicable")] + #[suggestion( + "convert it to a `use`", + style = "verbose", + code = "{code}", + applicability = "machine-applicable" + )] pub span: Span, pub code: &'static str, } #[derive(LintDiagnostic)] -#[diag(resolve_out_of_scope_macro_calls)] -#[help] +#[diag("cannot find macro `{$path}` in the current scope when looking from {$location}")] +#[help("import `macro_rules` with `use` to make it callable above its definition")] pub(crate) struct OutOfScopeMacroCalls { - #[label] + #[label("not found from {$location}")] pub span: Span, pub path: String, pub location: String, } #[derive(LintDiagnostic)] -#[diag(resolve_redundant_import_visibility)] +#[diag( + "glob import doesn't reexport anything with visibility `{$import_vis}` because no imported item is public enough" +)] pub(crate) struct RedundantImportVisibility { - #[note] + #[note("the most public imported item is `{$max_vis}`")] pub span: Span, - #[help] + #[help("reduce the glob import's visibility or increase visibility of imported items")] pub help: (), pub import_vis: String, pub max_vis: String, } #[derive(LintDiagnostic)] -#[diag(resolve_unknown_diagnostic_attribute)] +#[diag("unknown diagnostic attribute")] pub(crate) struct UnknownDiagnosticAttribute { #[subdiagnostic] pub typo: Option, @@ -1449,7 +1517,7 @@ pub(crate) struct UnknownDiagnosticAttribute { #[derive(Subdiagnostic)] #[suggestion( - resolve_unknown_diagnostic_attribute_typo_sugg, + "an attribute with a similar name exists", style = "verbose", code = "{typo_name}", applicability = "machine-applicable" diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 659b74b74df77..36ec173cc571f 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -98,8 +98,6 @@ pub use macros::registered_tools_ast; use crate::ref_mut::{CmCell, CmRefCell}; -rustc_fluent_macro::fluent_messages! { "../messages.ftl" } - #[derive(Copy, Clone, PartialEq, Debug)] enum Determinacy { Determined, diff --git a/compiler/rustc_session/src/config/native_libs.rs b/compiler/rustc_session/src/config/native_libs.rs index 71d3e222c8a15..28e2d0f94104b 100644 --- a/compiler/rustc_session/src/config/native_libs.rs +++ b/compiler/rustc_session/src/config/native_libs.rs @@ -53,7 +53,9 @@ fn parse_native_lib(cx: &ParseNativeLibCx<'_>, value: &str) -> NativeLib { let NativeLibParts { kind, modifiers, name, new_name } = split_native_lib_value(value); let kind = kind.map_or(NativeLibKind::Unspecified, |kind| match kind { - "static" => NativeLibKind::Static { bundle: None, whole_archive: None }, + "static" => { + NativeLibKind::Static { bundle: None, whole_archive: None, export_symbols: None } + } "dylib" => NativeLibKind::Dylib { as_needed: None }, "framework" => NativeLibKind::Framework { as_needed: None }, "link-arg" => { @@ -105,7 +107,7 @@ fn parse_and_apply_modifier(cx: &ParseNativeLibCx<'_>, modifier: &str, native_li Some(("-", m)) => (m, false), _ => cx.early_dcx.early_fatal( "invalid linking modifier syntax, expected '+' or '-' prefix \ - before one of: bundle, verbatim, whole-archive, as-needed", + before one of: bundle, verbatim, whole-archive, as-needed, export-symbols", ), }; @@ -125,6 +127,13 @@ fn parse_and_apply_modifier(cx: &ParseNativeLibCx<'_>, modifier: &str, native_li ("bundle", _) => early_dcx .early_fatal("linking modifier `bundle` is only compatible with `static` linking kind"), + ("export-symbols", NativeLibKind::Static { export_symbols, .. }) => { + assign_modifier(export_symbols) + } + ("export-symbols", _) => early_dcx.early_fatal( + "linking modifier `export-symbols` is only compatible with `static` linking kind", + ), + ("verbatim", _) => assign_modifier(&mut native_lib.verbatim), ("whole-archive", NativeLibKind::Static { whole_archive, .. }) => { @@ -151,7 +160,7 @@ fn parse_and_apply_modifier(cx: &ParseNativeLibCx<'_>, modifier: &str, native_li _ => early_dcx.early_fatal(format!( "unknown linking modifier `{modifier}`, expected one \ - of: bundle, verbatim, whole-archive, as-needed" + of: bundle, verbatim, whole-archive, as-needed, export-symbols" )), } } diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index b0ef95d10ffa0..c88dd0948b2a9 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -1002,6 +1002,7 @@ symbols! { explicit_tail_calls, export_name, export_stable, + export_symbols: "export-symbols", expr, expr_2021, expr_fragment_specifier_2024, diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs index 14e83cf3d2de8..9799f3e50ae24 100644 --- a/compiler/rustc_target/src/spec/mod.rs +++ b/compiler/rustc_target/src/spec/mod.rs @@ -3363,6 +3363,9 @@ impl Target { Err(format!("could not find specification for target {target_tuple:?}")) } + TargetTuple::TargetJson { ref contents, .. } if !unstable_options => { + Err("custom targets are unstable and require `-Zunstable-options`".to_string()) + } TargetTuple::TargetJson { ref contents, .. } => Target::from_json(contents), } } diff --git a/compiler/rustc_ty_utils/Cargo.toml b/compiler/rustc_ty_utils/Cargo.toml index ce08b300cc800..682cf941561fc 100644 --- a/compiler/rustc_ty_utils/Cargo.toml +++ b/compiler/rustc_ty_utils/Cargo.toml @@ -9,7 +9,6 @@ itertools = "0.12" rustc_abi = { path = "../rustc_abi" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } -rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_hashes = { path = "../rustc_hashes" } rustc_hir = { path = "../rustc_hir" } rustc_index = { path = "../rustc_index" } diff --git a/compiler/rustc_ty_utils/messages.ftl b/compiler/rustc_ty_utils/messages.ftl deleted file mode 100644 index c1684bfb43b66..0000000000000 --- a/compiler/rustc_ty_utils/messages.ftl +++ /dev/null @@ -1,61 +0,0 @@ -ty_utils_address_and_deref_not_supported = dereferencing or taking the address is not supported in generic constants - -ty_utils_adt_not_supported = struct/enum construction is not supported in generic constants - -ty_utils_array_not_supported = array construction is not supported in generic constants - -ty_utils_assign_not_supported = assignment is not supported in generic constants - -ty_utils_binary_not_supported = unsupported binary operation in generic constants - -ty_utils_block_not_supported = blocks are not supported in generic constants - -ty_utils_borrow_not_supported = borrowing is not supported in generic constants - -ty_utils_box_not_supported = allocations are not allowed in generic constants - -ty_utils_by_use_not_supported = .use is not allowed in generic constants - -ty_utils_closure_and_return_not_supported = closures and function keywords are not supported in generic constants - -ty_utils_const_block_not_supported = const blocks are not supported in generic constants - -ty_utils_control_flow_not_supported = control flow is not supported in generic constants - -ty_utils_field_not_supported = field access is not supported in generic constants - -ty_utils_generic_constant_too_complex = overly complex generic constant - .help = consider moving this anonymous constant into a `const` function - .maybe_supported = this operation may be supported in the future - -ty_utils_impl_trait_duplicate_arg = non-defining opaque type use in defining scope - .label = generic argument `{$arg}` used twice - .note = for this opaque type - -ty_utils_impl_trait_not_param = non-defining opaque type use in defining scope - .label = argument `{$arg}` is not a generic parameter - .note = for this opaque type - -ty_utils_index_not_supported = indexing is not supported in generic constants - -ty_utils_inline_asm_not_supported = assembly is not supported in generic constants - -ty_utils_logical_op_not_supported = unsupported operation in generic constants, short-circuiting operations would imply control flow - -ty_utils_loop_not_supported = loops and loop control flow are not supported in generic constants - -ty_utils_needs_drop_overflow = overflow while checking whether `{$query_ty}` requires drop - -ty_utils_never_to_any_not_supported = coercing the `never` type is not supported in generic constants - -ty_utils_non_primitive_simd_type = monomorphising SIMD type `{$ty}` with a non-primitive-scalar (integer/float/pointer) element type `{$e_ty}` - -ty_utils_operation_not_supported = unsupported operation in generic constants - -ty_utils_pointer_not_supported = pointer casts are not allowed in generic constants - -ty_utils_tuple_not_supported = tuple construction is not supported in generic constants - -ty_utils_unexpected_fnptr_associated_item = `FnPtr` trait with unexpected associated item - -ty_utils_yield_not_supported = coroutine control flow is not allowed in generic constants diff --git a/compiler/rustc_ty_utils/src/errors.rs b/compiler/rustc_ty_utils/src/errors.rs index f92c405242ce9..ccea5a49bd7cf 100644 --- a/compiler/rustc_ty_utils/src/errors.rs +++ b/compiler/rustc_ty_utils/src/errors.rs @@ -6,18 +6,18 @@ use rustc_middle::ty::{GenericArg, Ty}; use rustc_span::Span; #[derive(Diagnostic)] -#[diag(ty_utils_needs_drop_overflow)] +#[diag("overflow while checking whether `{$query_ty}` requires drop")] pub(crate) struct NeedsDropOverflow<'tcx> { pub query_ty: Ty<'tcx>, } #[derive(Diagnostic)] -#[diag(ty_utils_generic_constant_too_complex)] -#[help] +#[diag("overly complex generic constant")] +#[help("consider moving this anonymous constant into a `const` function")] pub(crate) struct GenericConstantTooComplex { #[primary_span] pub span: Span, - #[note(ty_utils_maybe_supported)] + #[note("this operation may be supported in the future")] pub maybe_supported: bool, #[subdiagnostic] pub sub: GenericConstantTooComplexSub, @@ -25,84 +25,88 @@ pub(crate) struct GenericConstantTooComplex { #[derive(Subdiagnostic)] pub(crate) enum GenericConstantTooComplexSub { - #[label(ty_utils_borrow_not_supported)] + #[label("borrowing is not supported in generic constants")] BorrowNotSupported(#[primary_span] Span), - #[label(ty_utils_address_and_deref_not_supported)] + #[label("dereferencing or taking the address is not supported in generic constants")] AddressAndDerefNotSupported(#[primary_span] Span), - #[label(ty_utils_array_not_supported)] + #[label("array construction is not supported in generic constants")] ArrayNotSupported(#[primary_span] Span), - #[label(ty_utils_block_not_supported)] + #[label("blocks are not supported in generic constants")] BlockNotSupported(#[primary_span] Span), - #[label(ty_utils_never_to_any_not_supported)] + #[label("coercing the `never` type is not supported in generic constants")] NeverToAnyNotSupported(#[primary_span] Span), - #[label(ty_utils_tuple_not_supported)] + #[label("tuple construction is not supported in generic constants")] TupleNotSupported(#[primary_span] Span), - #[label(ty_utils_index_not_supported)] + #[label("indexing is not supported in generic constants")] IndexNotSupported(#[primary_span] Span), - #[label(ty_utils_field_not_supported)] + #[label("field access is not supported in generic constants")] FieldNotSupported(#[primary_span] Span), - #[label(ty_utils_const_block_not_supported)] + #[label("const blocks are not supported in generic constants")] ConstBlockNotSupported(#[primary_span] Span), - #[label(ty_utils_adt_not_supported)] + #[label("struct/enum construction is not supported in generic constants")] AdtNotSupported(#[primary_span] Span), - #[label(ty_utils_pointer_not_supported)] + #[label("pointer casts are not allowed in generic constants")] PointerNotSupported(#[primary_span] Span), - #[label(ty_utils_yield_not_supported)] + #[label("coroutine control flow is not allowed in generic constants")] YieldNotSupported(#[primary_span] Span), - #[label(ty_utils_loop_not_supported)] + #[label("loops and loop control flow are not supported in generic constants")] LoopNotSupported(#[primary_span] Span), - #[label(ty_utils_box_not_supported)] + #[label("allocations are not allowed in generic constants")] BoxNotSupported(#[primary_span] Span), - #[label(ty_utils_binary_not_supported)] + #[label("unsupported binary operation in generic constants")] BinaryNotSupported(#[primary_span] Span), - #[label(ty_utils_by_use_not_supported)] + #[label(".use is not allowed in generic constants")] ByUseNotSupported(#[primary_span] Span), - #[label(ty_utils_logical_op_not_supported)] + #[label( + "unsupported operation in generic constants, short-circuiting operations would imply control flow" + )] LogicalOpNotSupported(#[primary_span] Span), - #[label(ty_utils_assign_not_supported)] + #[label("assignment is not supported in generic constants")] AssignNotSupported(#[primary_span] Span), - #[label(ty_utils_closure_and_return_not_supported)] + #[label("closures and function keywords are not supported in generic constants")] ClosureAndReturnNotSupported(#[primary_span] Span), - #[label(ty_utils_control_flow_not_supported)] + #[label("control flow is not supported in generic constants")] ControlFlowNotSupported(#[primary_span] Span), - #[label(ty_utils_inline_asm_not_supported)] + #[label("assembly is not supported in generic constants")] InlineAsmNotSupported(#[primary_span] Span), - #[label(ty_utils_operation_not_supported)] + #[label("unsupported operation in generic constants")] OperationNotSupported(#[primary_span] Span), } #[derive(Diagnostic)] -#[diag(ty_utils_unexpected_fnptr_associated_item)] +#[diag("`FnPtr` trait with unexpected associated item")] pub(crate) struct UnexpectedFnPtrAssociatedItem { #[primary_span] pub span: Span, } #[derive(Diagnostic)] -#[diag(ty_utils_non_primitive_simd_type)] +#[diag( + "monomorphising SIMD type `{$ty}` with a non-primitive-scalar (integer/float/pointer) element type `{$e_ty}`" +)] pub(crate) struct NonPrimitiveSimdType<'tcx> { pub ty: Ty<'tcx>, pub e_ty: Ty<'tcx>, } #[derive(Diagnostic)] -#[diag(ty_utils_impl_trait_duplicate_arg)] +#[diag("non-defining opaque type use in defining scope")] pub(crate) struct DuplicateArg<'tcx> { pub arg: GenericArg<'tcx>, #[primary_span] - #[label] + #[label("generic argument `{$arg}` used twice")] pub span: Span, - #[note] + #[note("for this opaque type")] pub opaque_span: Span, } #[derive(Diagnostic)] -#[diag(ty_utils_impl_trait_not_param, code = E0792)] +#[diag("non-defining opaque type use in defining scope", code = E0792)] pub(crate) struct NotParam<'tcx> { pub arg: GenericArg<'tcx>, #[primary_span] - #[label] + #[label("argument `{$arg}` is not a generic parameter")] pub span: Span, - #[note] + #[note("for this opaque type")] pub opaque_span: Span, } diff --git a/compiler/rustc_ty_utils/src/lib.rs b/compiler/rustc_ty_utils/src/lib.rs index d8b50b2d2e42f..9f8f3b240890b 100644 --- a/compiler/rustc_ty_utils/src/lib.rs +++ b/compiler/rustc_ty_utils/src/lib.rs @@ -31,8 +31,6 @@ pub mod sig_types; mod structural_match; mod ty; -rustc_fluent_macro::fluent_messages! { "../messages.ftl" } - pub fn provide(providers: &mut Providers) { abi::provide(providers); assoc::provide(providers); diff --git a/library/std/src/fs/tests.rs b/library/std/src/fs/tests.rs index 6d0b261dcadcf..42f3ccc340b27 100644 --- a/library/std/src/fs/tests.rs +++ b/library/std/src/fs/tests.rs @@ -2301,6 +2301,57 @@ fn test_fs_set_times() { } } +#[test] +fn test_fs_set_times_on_dir() { + #[cfg(target_vendor = "apple")] + use crate::os::darwin::fs::FileTimesExt; + #[cfg(windows)] + use crate::os::windows::fs::FileTimesExt; + + let tmp = tmpdir(); + let dir_path = tmp.join("testdir"); + fs::create_dir(&dir_path).unwrap(); + + let mut times = FileTimes::new(); + let accessed = SystemTime::UNIX_EPOCH + Duration::from_secs(12345); + let modified = SystemTime::UNIX_EPOCH + Duration::from_secs(54321); + times = times.set_accessed(accessed).set_modified(modified); + + #[cfg(any(windows, target_vendor = "apple"))] + let created = SystemTime::UNIX_EPOCH + Duration::from_secs(32123); + #[cfg(any(windows, target_vendor = "apple"))] + { + times = times.set_created(created); + } + + match fs::set_times(&dir_path, times) { + // Allow unsupported errors on platforms which don't support setting times. + #[cfg(not(any( + windows, + all( + unix, + not(any( + target_os = "android", + target_os = "redox", + target_os = "espidf", + target_os = "horizon" + )) + ) + )))] + Err(e) if e.kind() == ErrorKind::Unsupported => return, + Err(e) => panic!("error setting directory times: {e:?}"), + Ok(_) => {} + } + + let metadata = fs::metadata(&dir_path).unwrap(); + assert_eq!(metadata.accessed().unwrap(), accessed); + assert_eq!(metadata.modified().unwrap(), modified); + #[cfg(any(windows, target_vendor = "apple"))] + { + assert_eq!(metadata.created().unwrap(), created); + } +} + #[test] fn test_fs_set_times_follows_symlink() { #[cfg(target_vendor = "apple")] diff --git a/library/std/src/sys/fs/windows.rs b/library/std/src/sys/fs/windows.rs index fc8aec2f3f7c4..74854cdeb498d 100644 --- a/library/std/src/sys/fs/windows.rs +++ b/library/std/src/sys/fs/windows.rs @@ -1556,7 +1556,7 @@ pub fn set_perm(p: &WCStr, perm: FilePermissions) -> io::Result<()> { pub fn set_times(p: &WCStr, times: FileTimes) -> io::Result<()> { let mut opts = OpenOptions::new(); - opts.write(true); + opts.access_mode(c::FILE_WRITE_ATTRIBUTES); opts.custom_flags(c::FILE_FLAG_BACKUP_SEMANTICS); let file = File::open_native(p, &opts)?; file.set_times(times) @@ -1564,7 +1564,7 @@ pub fn set_times(p: &WCStr, times: FileTimes) -> io::Result<()> { pub fn set_times_nofollow(p: &WCStr, times: FileTimes) -> io::Result<()> { let mut opts = OpenOptions::new(); - opts.write(true); + opts.access_mode(c::FILE_WRITE_ATTRIBUTES); // `FILE_FLAG_OPEN_REPARSE_POINT` for no_follow behavior opts.custom_flags(c::FILE_FLAG_BACKUP_SEMANTICS | c::FILE_FLAG_OPEN_REPARSE_POINT); let file = File::open_native(p, &opts)?; diff --git a/src/build_helper/src/metrics.rs b/src/build_helper/src/metrics.rs index 07157e364158d..98dd952033e5c 100644 --- a/src/build_helper/src/metrics.rs +++ b/src/build_helper/src/metrics.rs @@ -111,6 +111,29 @@ pub struct JsonStepSystemStats { pub cpu_utilization_percent: f64, } +#[derive(Eq, Hash, PartialEq, Debug)] +pub enum DebuggerKind { + Gdb, + Lldb, + Cdb, +} + +impl DebuggerKind { + pub fn debuginfo_kind(name: &str) -> Option { + let name = name.to_ascii_lowercase(); + + if name.contains("debuginfo-gdb") { + Some(DebuggerKind::Gdb) + } else if name.contains("debuginfo-lldb") { + Some(DebuggerKind::Lldb) + } else if name.contains("debuginfo-cdb") { + Some(DebuggerKind::Cdb) + } else { + None + } + } +} + fn null_as_f64_nan<'de, D: serde::Deserializer<'de>>(d: D) -> Result { use serde::Deserialize as _; Option::::deserialize(d).map(|f| f.unwrap_or(f64::NAN)) diff --git a/src/ci/citool/src/analysis.rs b/src/ci/citool/src/analysis.rs index e91d27a36092a..b8048f341ea2e 100644 --- a/src/ci/citool/src/analysis.rs +++ b/src/ci/citool/src/analysis.rs @@ -3,7 +3,7 @@ use std::fmt::Debug; use std::time::Duration; use build_helper::metrics::{ - BuildStep, JsonRoot, TestOutcome, TestSuite, TestSuiteMetadata, escape_step_name, + BuildStep, DebuggerKind, JsonRoot, TestOutcome, TestSuite, TestSuiteMetadata, escape_step_name, format_build_steps, }; @@ -139,11 +139,39 @@ fn record_test_suites(metrics: &JsonRoot) { let table = render_table(aggregated); println!("\n# Test results\n"); println!("{table}"); + report_debuginfo_statistics(&suites); } else { eprintln!("No test suites found in metrics"); } } +fn report_debuginfo_statistics(suites: &[&TestSuite]) { + let mut debugger_test_record: HashMap = HashMap::new(); + for suite in suites { + if let TestSuiteMetadata::Compiletest { .. } = suite.metadata { + for test in &suite.tests { + if let Some(kind) = DebuggerKind::debuginfo_kind(&test.name) { + let record = + debugger_test_record.entry(kind).or_insert(TestSuiteRecord::default()); + match test.outcome { + TestOutcome::Passed => record.passed += 1, + TestOutcome::Ignored { .. } => record.ignored += 1, + TestOutcome::Failed => record.failed += 1, + } + } + } + } + } + + println!("## DebugInfo Test Statistics"); + for (kind, record) in debugger_test_record { + println!( + "- {:?}: Passed ✅={}, Failed ❌={}, Ignored 🚫={}", + kind, record.passed, record.failed, record.ignored + ); + } +} + fn render_table(suites: BTreeMap) -> String { use std::fmt::Write; diff --git a/src/ci/docker/scripts/rfl-build.sh b/src/ci/docker/scripts/rfl-build.sh index e7f86e10f55a5..5352505577400 100755 --- a/src/ci/docker/scripts/rfl-build.sh +++ b/src/ci/docker/scripts/rfl-build.sh @@ -2,8 +2,8 @@ set -euo pipefail -# https://github.com/rust-lang/rust/pull/145974 -LINUX_VERSION=842cfd8e5aff3157cb25481b2900b49c188d628a +# https://github.com/rust-lang/rust/pull/151534 +LINUX_VERSION=eb268c7972f65fa0b11b051c5ef2b92747bb2b62 # Build rustc, rustdoc, cargo, clippy-driver and rustfmt ../x.py build --stage 2 library rustdoc clippy rustfmt diff --git a/src/tools/rustbook/README.md b/src/tools/rustbook/README.md index d9570c23ead17..a9fd1b75b5724 100644 --- a/src/tools/rustbook/README.md +++ b/src/tools/rustbook/README.md @@ -10,7 +10,7 @@ This is invoked automatically when building mdbook-style documentation, for exam ## Cargo workspace -This package defines a separate cargo workspace from the main Rust workspace for a few reasons (ref [#127786](https://github.com/rust-lang/rust/pull/127786): +This package defines a separate cargo workspace from the main Rust workspace for a few reasons (ref [#127786](https://github.com/rust-lang/rust/pull/127786)): - Avoids requiring checking out submodules for developers who are not working on the documentation. Otherwise, some submodules such as those that have custom preprocessors would be required for cargo to find the dependencies. - Avoids problems with updating dependencies. Unfortunately this workspace has a rather large set of dependencies, which can make coordinating updates difficult (see [#127890](https://github.com/rust-lang/rust/issues/127890)). diff --git a/tests/codegen-llvm/autodiff/abi_handling.rs b/tests/codegen-llvm/autodiff/abi_handling.rs index 5c8126898a8d7..a8bc482fc293f 100644 --- a/tests/codegen-llvm/autodiff/abi_handling.rs +++ b/tests/codegen-llvm/autodiff/abi_handling.rs @@ -38,14 +38,14 @@ fn square(x: f32) -> f32 { // CHECK-LABEL: ; abi_handling::df1 // CHECK-NEXT: Function Attrs // debug-NEXT: define internal { float, float } -// debug-SAME: (ptr align 4 %x, ptr align 4 %bx_0) +// debug-SAME: (ptr {{.*}}%x, ptr {{.*}}%bx_0) // release-NEXT: define internal fastcc float // release-SAME: (float %x.0.val, float %x.4.val) // CHECK-LABEL: ; abi_handling::f1 // CHECK-NEXT: Function Attrs // debug-NEXT: define internal float -// debug-SAME: (ptr align 4 %x) +// debug-SAME: (ptr {{.*}}%x) // release-NEXT: define internal fastcc noundef float // release-SAME: (float %x.0.val, float %x.4.val) #[autodiff_forward(df1, Dual, Dual)] @@ -58,7 +58,7 @@ fn f1(x: &[f32; 2]) -> f32 { // CHECK-NEXT: Function Attrs // debug-NEXT: define internal { float, float } // debug-SAME: (ptr %f, float %x, float %dret) -// release-NEXT: define internal fastcc float +// release-NEXT: define internal fastcc noundef float // release-SAME: (float noundef %x) // CHECK-LABEL: ; abi_handling::f2 @@ -77,13 +77,13 @@ fn f2(f: fn(f32) -> f32, x: f32) -> f32 { // CHECK-NEXT: Function Attrs // debug-NEXT: define internal { float, float } // debug-SAME: (ptr align 4 %x, ptr align 4 %bx_0, ptr align 4 %y, ptr align 4 %by_0) -// release-NEXT: define internal fastcc { float, float } +// release-NEXT: define internal fastcc float // release-SAME: (float %x.0.val) // CHECK-LABEL: ; abi_handling::f3 // CHECK-NEXT: Function Attrs // debug-NEXT: define internal float -// debug-SAME: (ptr align 4 %x, ptr align 4 %y) +// debug-SAME: (ptr {{.*}}%x, ptr {{.*}}%y) // release-NEXT: define internal fastcc noundef float // release-SAME: (float %x.0.val) #[autodiff_forward(df3, Dual, Dual, Dual)] @@ -160,7 +160,7 @@ fn f6(i: NestedInput) -> f32 { // CHECK-LABEL: ; abi_handling::f7 // CHECK-NEXT: Function Attrs // debug-NEXT: define internal float -// debug-SAME: (ptr align 4 %x.0, ptr align 4 %x.1) +// debug-SAME: (ptr {{.*}}%x.0, ptr {{.*}}%x.1) // release-NEXT: define internal fastcc noundef float // release-SAME: (float %x.0.0.val, float %x.1.0.val) #[autodiff_forward(df7, Dual, Dual)] diff --git a/tests/codegen-llvm/autodiff/batched.rs b/tests/codegen-llvm/autodiff/batched.rs index 0ff6134bc07d5..5a723ff041839 100644 --- a/tests/codegen-llvm/autodiff/batched.rs +++ b/tests/codegen-llvm/autodiff/batched.rs @@ -1,13 +1,11 @@ //@ compile-flags: -Zautodiff=Enable,NoTT,NoPostopt -C opt-level=3 -Clto=fat //@ no-prefer-dynamic //@ needs-enzyme -// -// In Enzyme, we test against a large range of LLVM versions (5+) and don't have overly many -// breakages. One benefit is that we match the IR generated by Enzyme only after running it -// through LLVM's O3 pipeline, which will remove most of the noise. -// However, our integration test could also be affected by changes in how rustc lowers MIR into -// LLVM-IR, which could cause additional noise and thus breakages. If that's the case, we should -// reduce this test to only match the first lines and the ret instructions. + +// This test combines two features of Enzyme, automatic differentiation and batching. As such, it is +// especially prone to breakages. I reduced it therefore to a minimal check matches argument/return +// types. Based on the original batching author, implementing the batching feature over MLIR instead +// of LLVM should give significantly more reliable performance. #![feature(autodiff)] @@ -22,69 +20,20 @@ fn square(x: &f32) -> f32 { x * x } +// The base ("scalar") case d_square3, without batching. +// CHECK: define internal fastcc float @fwddiffesquare(float %x.0.val, float %"x'.0.val") +// CHECK: %0 = fadd fast float %"x'.0.val", %"x'.0.val" +// CHECK-NEXT: %1 = fmul fast float %0, %x.0.val +// CHECK-NEXT: ret float %1 +// CHECK-NEXT: } + // d_square2 -// CHECK: define internal [4 x float] @fwddiffe4square(ptr noalias noundef readonly align 4 captures(none) dereferenceable(4) %x, [4 x ptr] %"x'") -// CHECK-NEXT: start: -// CHECK-NEXT: %0 = extractvalue [4 x ptr] %"x'", 0 -// CHECK-NEXT: %"_2'ipl" = load float, ptr %0, align 4 -// CHECK-NEXT: %1 = extractvalue [4 x ptr] %"x'", 1 -// CHECK-NEXT: %"_2'ipl1" = load float, ptr %1, align 4 -// CHECK-NEXT: %2 = extractvalue [4 x ptr] %"x'", 2 -// CHECK-NEXT: %"_2'ipl2" = load float, ptr %2, align 4 -// CHECK-NEXT: %3 = extractvalue [4 x ptr] %"x'", 3 -// CHECK-NEXT: %"_2'ipl3" = load float, ptr %3, align 4 -// CHECK-NEXT: %_2 = load float, ptr %x, align 4 -// CHECK-NEXT: %4 = fmul fast float %"_2'ipl", %_2 -// CHECK-NEXT: %5 = fmul fast float %"_2'ipl1", %_2 -// CHECK-NEXT: %6 = fmul fast float %"_2'ipl2", %_2 -// CHECK-NEXT: %7 = fmul fast float %"_2'ipl3", %_2 -// CHECK-NEXT: %8 = fmul fast float %"_2'ipl", %_2 -// CHECK-NEXT: %9 = fmul fast float %"_2'ipl1", %_2 -// CHECK-NEXT: %10 = fmul fast float %"_2'ipl2", %_2 -// CHECK-NEXT: %11 = fmul fast float %"_2'ipl3", %_2 -// CHECK-NEXT: %12 = fadd fast float %4, %8 -// CHECK-NEXT: %13 = insertvalue [4 x float] undef, float %12, 0 -// CHECK-NEXT: %14 = fadd fast float %5, %9 -// CHECK-NEXT: %15 = insertvalue [4 x float] %13, float %14, 1 -// CHECK-NEXT: %16 = fadd fast float %6, %10 -// CHECK-NEXT: %17 = insertvalue [4 x float] %15, float %16, 2 -// CHECK-NEXT: %18 = fadd fast float %7, %11 -// CHECK-NEXT: %19 = insertvalue [4 x float] %17, float %18, 3 -// CHECK-NEXT: ret [4 x float] %19 +// CHECK: define internal fastcc [4 x float] @fwddiffe4square(float %x.0.val, [4 x ptr] %"x'") +// CHECK: ret [4 x float] // CHECK-NEXT: } -// d_square3, the extra float is the original return value (x * x) -// CHECK: define internal { float, [4 x float] } @fwddiffe4square.1(ptr noalias noundef readonly align 4 captures(none) dereferenceable(4) %x, [4 x ptr] %"x'") -// CHECK-NEXT: start: -// CHECK-NEXT: %0 = extractvalue [4 x ptr] %"x'", 0 -// CHECK-NEXT: %"_2'ipl" = load float, ptr %0, align 4 -// CHECK-NEXT: %1 = extractvalue [4 x ptr] %"x'", 1 -// CHECK-NEXT: %"_2'ipl1" = load float, ptr %1, align 4 -// CHECK-NEXT: %2 = extractvalue [4 x ptr] %"x'", 2 -// CHECK-NEXT: %"_2'ipl2" = load float, ptr %2, align 4 -// CHECK-NEXT: %3 = extractvalue [4 x ptr] %"x'", 3 -// CHECK-NEXT: %"_2'ipl3" = load float, ptr %3, align 4 -// CHECK-NEXT: %_2 = load float, ptr %x, align 4 -// CHECK-NEXT: %_0 = fmul float %_2, %_2 -// CHECK-NEXT: %4 = fmul fast float %"_2'ipl", %_2 -// CHECK-NEXT: %5 = fmul fast float %"_2'ipl1", %_2 -// CHECK-NEXT: %6 = fmul fast float %"_2'ipl2", %_2 -// CHECK-NEXT: %7 = fmul fast float %"_2'ipl3", %_2 -// CHECK-NEXT: %8 = fmul fast float %"_2'ipl", %_2 -// CHECK-NEXT: %9 = fmul fast float %"_2'ipl1", %_2 -// CHECK-NEXT: %10 = fmul fast float %"_2'ipl2", %_2 -// CHECK-NEXT: %11 = fmul fast float %"_2'ipl3", %_2 -// CHECK-NEXT: %12 = fadd fast float %4, %8 -// CHECK-NEXT: %13 = insertvalue [4 x float] undef, float %12, 0 -// CHECK-NEXT: %14 = fadd fast float %5, %9 -// CHECK-NEXT: %15 = insertvalue [4 x float] %13, float %14, 1 -// CHECK-NEXT: %16 = fadd fast float %6, %10 -// CHECK-NEXT: %17 = insertvalue [4 x float] %15, float %16, 2 -// CHECK-NEXT: %18 = fadd fast float %7, %11 -// CHECK-NEXT: %19 = insertvalue [4 x float] %17, float %18, 3 -// CHECK-NEXT: %20 = insertvalue { float, [4 x float] } undef, float %_0, 0 -// CHECK-NEXT: %21 = insertvalue { float, [4 x float] } %20, [4 x float] %19, 1 -// CHECK-NEXT: ret { float, [4 x float] } %21 +// CHECK: define internal fastcc { float, [4 x float] } @fwddiffe4square.{{.*}}(float %x.0.val, [4 x ptr] %"x'") +// CHECK: ret { float, [4 x float] } // CHECK-NEXT: } fn main() { diff --git a/tests/codegen-llvm/autodiff/generic.rs b/tests/codegen-llvm/autodiff/generic.rs index 6f56460a2b6d1..b31468c91c9c2 100644 --- a/tests/codegen-llvm/autodiff/generic.rs +++ b/tests/codegen-llvm/autodiff/generic.rs @@ -1,6 +1,14 @@ //@ compile-flags: -Zautodiff=Enable -Zautodiff=NoPostopt -C opt-level=3 -Clto=fat //@ no-prefer-dynamic //@ needs-enzyme +//@ revisions: F32 F64 Main + +// Here we verify that the function `square` can be differentiated over f64. +// This is interesting to test, since the user never calls `square` with f64, so on it's own rustc +// would have no reason to monomorphize it that way. However, Enzyme needs the f64 version of +// `square` in order to be able to differentiate it, so we have logic to enforce the +// monomorphization. Here, we test this logic. + #![feature(autodiff)] use std::autodiff::autodiff_reverse; @@ -12,32 +20,37 @@ fn square + Copy>(x: &T) -> T { } // Ensure that `d_square::` code is generated -// -// CHECK: ; generic::square -// CHECK-NEXT: ; Function Attrs: {{.*}} -// CHECK-NEXT: define internal {{.*}} float -// CHECK-NEXT: start: -// CHECK-NOT: ret -// CHECK: fmul float + +// F32-LABEL: ; generic::square:: +// F32-NEXT: ; Function Attrs: {{.*}} +// F32-NEXT: define internal {{.*}} float +// F32-NEXT: start: +// F32-NOT: ret +// F32: fmul float // Ensure that `d_square::` code is generated even if `square::` was never called -// -// CHECK: ; generic::square -// CHECK-NEXT: ; Function Attrs: -// CHECK-NEXT: define internal {{.*}} double -// CHECK-NEXT: start: -// CHECK-NOT: ret -// CHECK: fmul double + +// F64-LABEL: ; generic::d_square:: +// F64-NEXT: ; Function Attrs: {{.*}} +// F64-NEXT: define internal {{.*}} void +// F64-NEXT: start: +// F64-NEXT: {{(tail )?}}call {{(fastcc )?}}void @diffe_{{.*}}(double {{.*}}, ptr {{.*}}) +// F64-NEXT: ret void + +// Main-LABEL: ; generic::main +// Main: ; call generic::square:: +// Main: ; call generic::d_square:: fn main() { let xf32: f32 = std::hint::black_box(3.0); let xf64: f64 = std::hint::black_box(3.0); + let seed: f64 = std::hint::black_box(1.0); let outputf32 = square::(&xf32); assert_eq!(9.0, outputf32); let mut df_dxf64: f64 = std::hint::black_box(0.0); - let output_f64 = d_square::(&xf64, &mut df_dxf64, 1.0); + let output_f64 = d_square::(&xf64, &mut df_dxf64, seed); assert_eq!(6.0, df_dxf64); } diff --git a/tests/codegen-llvm/autodiff/identical_fnc.rs b/tests/codegen-llvm/autodiff/identical_fnc.rs index 1c18e7acc4b63..a8b186c302ea1 100644 --- a/tests/codegen-llvm/autodiff/identical_fnc.rs +++ b/tests/codegen-llvm/autodiff/identical_fnc.rs @@ -8,7 +8,7 @@ // merged placeholder function anymore, and compilation would fail. We prevent this by disabling // LLVM's merge_function pass before AD. Here we implicetely test that our solution keeps working. // We also explicetly test that we keep running merge_function after AD, by checking for two -// identical function calls in the LLVM-IR, while having two different calls in the Rust code. +// identical function calls in the LLVM-IR, despite having two different calls in the Rust code. #![feature(autodiff)] use std::autodiff::autodiff_reverse; @@ -27,14 +27,14 @@ fn square2(x: &f64) -> f64 { // CHECK:; identical_fnc::main // CHECK-NEXT:; Function Attrs: -// CHECK-NEXT:define internal void @_ZN13identical_fnc4main17h6009e4f751bf9407E() +// CHECK-NEXT:define internal void // CHECK-NEXT:start: // CHECK-NOT:br // CHECK-NOT:ret // CHECK:; call identical_fnc::d_square -// CHECK-NEXT:call fastcc void @_ZN13identical_fnc8d_square[[HASH:.+]](double %x.val, ptr noalias noundef align 8 dereferenceable(8) %dx1) +// CHECK-NEXT:call fastcc void @[[HASH:.+]](double %x.val, ptr noalias noundef align 8 dereferenceable(8) %dx1) // CHECK:; call identical_fnc::d_square -// CHECK-NEXT:call fastcc void @_ZN13identical_fnc8d_square[[HASH]](double %x.val, ptr noalias noundef align 8 dereferenceable(8) %dx2) +// CHECK-NEXT:call fastcc void @[[HASH]](double %x.val, ptr noalias noundef align 8 dereferenceable(8) %dx2) fn main() { let x = std::hint::black_box(3.0); diff --git a/tests/run-make/cdylib-export-c-library-symbols/foo.c b/tests/run-make/cdylib-export-c-library-symbols/foo.c new file mode 100644 index 0000000000000..a062aca03b315 --- /dev/null +++ b/tests/run-make/cdylib-export-c-library-symbols/foo.c @@ -0,0 +1 @@ +void my_function() {} diff --git a/tests/run-make/cdylib-export-c-library-symbols/foo.rs b/tests/run-make/cdylib-export-c-library-symbols/foo.rs new file mode 100644 index 0000000000000..ac641aaed00f8 --- /dev/null +++ b/tests/run-make/cdylib-export-c-library-symbols/foo.rs @@ -0,0 +1,10 @@ +extern "C" { + pub fn my_function(); +} + +#[no_mangle] +pub extern "C" fn rust_entry() { + unsafe { + my_function(); + } +} diff --git a/tests/run-make/cdylib-export-c-library-symbols/foo_export.rs b/tests/run-make/cdylib-export-c-library-symbols/foo_export.rs new file mode 100644 index 0000000000000..1eda294ef41c3 --- /dev/null +++ b/tests/run-make/cdylib-export-c-library-symbols/foo_export.rs @@ -0,0 +1,10 @@ +extern "C" { + fn my_function(); +} + +#[no_mangle] +pub extern "C" fn rust_entry() { + unsafe { + my_function(); + } +} diff --git a/tests/run-make/cdylib-export-c-library-symbols/rmake.rs b/tests/run-make/cdylib-export-c-library-symbols/rmake.rs new file mode 100644 index 0000000000000..cb237eceedadf --- /dev/null +++ b/tests/run-make/cdylib-export-c-library-symbols/rmake.rs @@ -0,0 +1,36 @@ +//@ ignore-nvptx64 +//@ ignore-wasm +//@ ignore-cross-compile +// FIXME:The symbol mangle rules are slightly different in Windows(32-bit) and Apple. +// Need to be resolved. +//@ ignore-windows +//@ ignore-apple +// Reason: the compiled binary is executed + +use run_make_support::{build_native_static_lib, cc, dynamic_lib_name, is_darwin, llvm_nm, rustc}; + +fn main() { + cc().input("foo.c").arg("-c").out_exe("foo.o").run(); + build_native_static_lib("foo"); + + rustc().input("foo.rs").arg("-lstatic=foo").crate_type("cdylib").run(); + + let out = llvm_nm() + .input(dynamic_lib_name("foo")) + .run() + .assert_stdout_not_contains_regex("T *my_function"); + + rustc().input("foo_export.rs").arg("-lstatic:+export-symbols=foo").crate_type("cdylib").run(); + + if is_darwin() { + let out = llvm_nm() + .input(dynamic_lib_name("foo_export")) + .run() + .assert_stdout_contains("T _my_function"); + } else { + let out = llvm_nm() + .input(dynamic_lib_name("foo_export")) + .run() + .assert_stdout_contains("T my_function"); + } +} diff --git a/tests/run-make/rust-lld-custom-target/rmake.rs b/tests/run-make/rust-lld-custom-target/rmake.rs index 90ba424ffe940..d281d820f47b4 100644 --- a/tests/run-make/rust-lld-custom-target/rmake.rs +++ b/tests/run-make/rust-lld-custom-target/rmake.rs @@ -15,7 +15,11 @@ fn main() { // Compile to a custom target spec with rust-lld enabled by default. We'll check that by asking // the linker to display its version number with a link-arg. assert_rustc_uses_lld( - rustc().crate_type("cdylib").target("custom-target.json").input("lib.rs"), + rustc() + .crate_type("cdylib") + .target("custom-target.json") + .arg("-Zunstable-options") + .input("lib.rs"), ); // But it can also be disabled via linker features. diff --git a/tests/run-make/rustdoc-target-spec-json-path/rmake.rs b/tests/run-make/rustdoc-target-spec-json-path/rmake.rs index d43aa9b90ac72..8660556564f1e 100644 --- a/tests/run-make/rustdoc-target-spec-json-path/rmake.rs +++ b/tests/run-make/rustdoc-target-spec-json-path/rmake.rs @@ -5,8 +5,14 @@ use run_make_support::{cwd, rustc, rustdoc}; fn main() { let out_dir = "rustdoc-target-spec-json-path"; - rustc().crate_type("lib").input("dummy_core.rs").target("target.json").run(); + rustc() + .arg("-Zunstable-options") + .crate_type("lib") + .input("dummy_core.rs") + .target("target.json") + .run(); rustdoc() + .arg("-Zunstable-options") .input("my_crate.rs") .out_dir(out_dir) .library_search_path(cwd()) diff --git a/tests/run-make/target-specs/rmake.rs b/tests/run-make/target-specs/rmake.rs index 69292af5fd69c..6c88f3164e9e4 100644 --- a/tests/run-make/target-specs/rmake.rs +++ b/tests/run-make/target-specs/rmake.rs @@ -20,13 +20,20 @@ fn main() { .target("my-incomplete-platform.json") .run_fail() .assert_stderr_contains("missing field `llvm-target`"); - let test_platform = rustc() + let _ = rustc() .input("foo.rs") .target("my-x86_64-unknown-linux-gnu-platform") .crate_type("lib") .emit("asm") .run_fail() .assert_stderr_contains("custom targets are unstable and require `-Zunstable-options`"); + let _ = rustc() + .input("foo.rs") + .target("my-awesome-platform.json") + .crate_type("lib") + .emit("asm") + .run_fail() + .assert_stderr_contains("custom targets are unstable and require `-Zunstable-options`"); rustc() .arg("-Zunstable-options") .env("RUST_TARGET_PATH", ".") diff --git a/tests/ui/check-cfg/values-target-json.rs b/tests/ui/check-cfg/values-target-json.rs index defb286ed19be..21b6af9b55605 100644 --- a/tests/ui/check-cfg/values-target-json.rs +++ b/tests/ui/check-cfg/values-target-json.rs @@ -4,7 +4,8 @@ //@ check-pass //@ no-auto-check-cfg //@ needs-llvm-components: x86 -//@ compile-flags: --crate-type=lib --check-cfg=cfg() --target={{src-base}}/check-cfg/my-awesome-platform.json +//@ compile-flags: --crate-type=lib --check-cfg=cfg() +//@ compile-flags: -Zunstable-options --target={{src-base}}/check-cfg/my-awesome-platform.json //@ ignore-backends: gcc #![feature(lang_items, no_core, auto_traits, rustc_attrs)] diff --git a/tests/ui/feature-gates/feature-gate-link-arg-attribute.in_flag.stderr b/tests/ui/feature-gates/feature-gate-link-arg-attribute.in_flag.stderr index 4d65db3c66d0b..218a4769d9542 100644 --- a/tests/ui/feature-gates/feature-gate-link-arg-attribute.in_flag.stderr +++ b/tests/ui/feature-gates/feature-gate-link-arg-attribute.in_flag.stderr @@ -1,2 +1,2 @@ -error: unknown linking modifier `link-arg`, expected one of: bundle, verbatim, whole-archive, as-needed +error: unknown linking modifier `link-arg`, expected one of: bundle, verbatim, whole-archive, as-needed, export-symbols diff --git a/tests/ui/link-native-libs/link-arg-error2.rs b/tests/ui/link-native-libs/link-arg-error2.rs new file mode 100644 index 0000000000000..a51dec0614b5f --- /dev/null +++ b/tests/ui/link-native-libs/link-arg-error2.rs @@ -0,0 +1,5 @@ +//@ compile-flags: -l link-arg:+export-symbols=arg -Z unstable-options + +fn main() {} + +//~? ERROR linking modifier `export-symbols` is only compatible with `static` linking kind diff --git a/tests/ui/link-native-libs/link-arg-error2.stderr b/tests/ui/link-native-libs/link-arg-error2.stderr new file mode 100644 index 0000000000000..61bcf7dba2829 --- /dev/null +++ b/tests/ui/link-native-libs/link-arg-error2.stderr @@ -0,0 +1,2 @@ +error: linking modifier `export-symbols` is only compatible with `static` linking kind + diff --git a/tests/ui/link-native-libs/link-arg-from-rs2.rs b/tests/ui/link-native-libs/link-arg-from-rs2.rs new file mode 100644 index 0000000000000..3074fec6c1c8f --- /dev/null +++ b/tests/ui/link-native-libs/link-arg-from-rs2.rs @@ -0,0 +1,7 @@ +#![feature(link_arg_attribute)] + +#[link(kind = "link-arg", name = "arg", modifiers = "+export-symbols")] +//~^ ERROR linking modifier `export-symbols` is only compatible with `static` linking kind +extern "C" {} + +pub fn main() {} diff --git a/tests/ui/link-native-libs/link-arg-from-rs2.stderr b/tests/ui/link-native-libs/link-arg-from-rs2.stderr new file mode 100644 index 0000000000000..af3b25253e052 --- /dev/null +++ b/tests/ui/link-native-libs/link-arg-from-rs2.stderr @@ -0,0 +1,8 @@ +error: linking modifier `export-symbols` is only compatible with `static` linking kind + --> $DIR/link-arg-from-rs2.rs:3:53 + | +LL | #[link(kind = "link-arg", name = "arg", modifiers = "+export-symbols")] + | ^^^^^^^^^^^^^^^^^ + +error: aborting due to 1 previous error + diff --git a/tests/ui/link-native-libs/link-attr-validation-late.stderr b/tests/ui/link-native-libs/link-attr-validation-late.stderr index b09431f923aaf..4a4a193752070 100644 --- a/tests/ui/link-native-libs/link-attr-validation-late.stderr +++ b/tests/ui/link-native-libs/link-attr-validation-late.stderr @@ -178,13 +178,13 @@ LL | #[link(name = "...", wasm_import_module())] | = note: for more information, visit -error: invalid linking modifier syntax, expected '+' or '-' prefix before one of: bundle, verbatim, whole-archive, as-needed +error: invalid linking modifier syntax, expected '+' or '-' prefix before one of: bundle, verbatim, whole-archive, as-needed, export-symbols --> $DIR/link-attr-validation-late.rs:31:34 | LL | #[link(name = "...", modifiers = "")] | ^^ -error: invalid linking modifier syntax, expected '+' or '-' prefix before one of: bundle, verbatim, whole-archive, as-needed +error: invalid linking modifier syntax, expected '+' or '-' prefix before one of: bundle, verbatim, whole-archive, as-needed, export-symbols --> $DIR/link-attr-validation-late.rs:32:34 | LL | #[link(name = "...", modifiers = "no-plus-minus")] @@ -196,7 +196,7 @@ error[E0539]: malformed `link` attribute input LL | #[link(name = "...", modifiers = "+unknown")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^----------^^ | | - | valid arguments are "bundle", "verbatim", "whole-archive" or "as-needed" + | valid arguments are "bundle", "export-symbols", "verbatim", "whole-archive" or "as-needed" | = note: for more information, visit diff --git a/tests/ui/link-native-libs/modifiers-bad.blank.stderr b/tests/ui/link-native-libs/modifiers-bad.blank.stderr index ea36af0b4cfa9..6a1953e008eef 100644 --- a/tests/ui/link-native-libs/modifiers-bad.blank.stderr +++ b/tests/ui/link-native-libs/modifiers-bad.blank.stderr @@ -1,2 +1,2 @@ -error: invalid linking modifier syntax, expected '+' or '-' prefix before one of: bundle, verbatim, whole-archive, as-needed +error: invalid linking modifier syntax, expected '+' or '-' prefix before one of: bundle, verbatim, whole-archive, as-needed, export-symbols diff --git a/tests/ui/link-native-libs/modifiers-bad.no-prefix.stderr b/tests/ui/link-native-libs/modifiers-bad.no-prefix.stderr index ea36af0b4cfa9..6a1953e008eef 100644 --- a/tests/ui/link-native-libs/modifiers-bad.no-prefix.stderr +++ b/tests/ui/link-native-libs/modifiers-bad.no-prefix.stderr @@ -1,2 +1,2 @@ -error: invalid linking modifier syntax, expected '+' or '-' prefix before one of: bundle, verbatim, whole-archive, as-needed +error: invalid linking modifier syntax, expected '+' or '-' prefix before one of: bundle, verbatim, whole-archive, as-needed, export-symbols diff --git a/tests/ui/link-native-libs/modifiers-bad.prefix-only.stderr b/tests/ui/link-native-libs/modifiers-bad.prefix-only.stderr index 1e701374688fe..46720cf0b15e9 100644 --- a/tests/ui/link-native-libs/modifiers-bad.prefix-only.stderr +++ b/tests/ui/link-native-libs/modifiers-bad.prefix-only.stderr @@ -1,2 +1,2 @@ -error: unknown linking modifier ``, expected one of: bundle, verbatim, whole-archive, as-needed +error: unknown linking modifier ``, expected one of: bundle, verbatim, whole-archive, as-needed, export-symbols diff --git a/tests/ui/link-native-libs/modifiers-bad.unknown.stderr b/tests/ui/link-native-libs/modifiers-bad.unknown.stderr index 75950ad9c64c7..d47694a5aeca8 100644 --- a/tests/ui/link-native-libs/modifiers-bad.unknown.stderr +++ b/tests/ui/link-native-libs/modifiers-bad.unknown.stderr @@ -1,2 +1,2 @@ -error: unknown linking modifier `ferris`, expected one of: bundle, verbatim, whole-archive, as-needed +error: unknown linking modifier `ferris`, expected one of: bundle, verbatim, whole-archive, as-needed, export-symbols