Skip to content

RFC #1733 (Trait Aliases): compilation crash when putting "diagnostic::on_unimplemented" on alias #130627

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

Closed
andrzejressel opened this issue Sep 20, 2024 · 0 comments · Fixed by #139091
Labels
C-bug Category: This is a bug. F-on_unimplemented Error messages that can be tackled with `#[rustc_on_unimplemented]` F-trait_alias `#![feature(trait_alias)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@andrzejressel
Copy link

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=7b59ad99144e849738f87583bb664c44

Code

#![feature(trait_alias)]

trait Test {
    
}

#[diagnostic::on_unimplemented(
    message="message",
    label="label",
    note="note"
)]
trait Alias = Test;

// Use trait alias as bound on type parameter.
fn foo<T: Alias>(v: &T) {
}

pub fn main() {
    foo(&1);
}

Meta

rustc --version --verbose:

nightly 2024-09-19 506f22b4663f3e756e1e

Error output

thread 'rustc' panicked at compiler/rustc_hir_analysis/src/collect.rs:1689:22:
$ident: found Item { ident: Alias#0, owner_id: DefId(0:7 ~ playground[b3b9]::Alias), kind: TraitAlias(Generics { params: [], predicates: [], has_where_clause_predicates: false, where_clause_span: src/main.rs:13:19: 13:19 (#0), span: src/main.rs:13:12: 13:12 (#0) }, [Trait(PolyTraitRef { bound_generic_params: [], trait_ref: TraitRef { path: Path { span: src/main.rs:13:15: 13:19 (#0), res: Def(Trait, DefId(0:3 ~ playground[b3b9]::Test)), segments: [PathSegment { ident: Test#0, hir_id: HirId(DefId(0:7 ~ playground[b3b9]::Alias).1), res: Def(Trait, DefId(0:3 ~ playground[b3b9]::Test)), args: None, infer_args: false }] }, hir_ref_id: HirId(DefId(0:7 ~ playground[b3b9]::Alias).2) }, span: src/main.rs:13:15: 13:19 (#0) }, None)]), span: src/main.rs:13:1: 13:20 (#0), vis_span: src/main.rs:13:1: 13:1 (#0) }
stack backtrace:
   0:     0x7ffb9d1c3c9a - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h931fa8a693ee76bf
   1:     0x7ffb9d9577d7 - core::fmt::write::ha344a87a3011b8f5
   2:     0x7ffb9e8608b3 - std::io::Write::write_fmt::ha4f1ac9a9087f93c
   3:     0x7ffb9d1c3af2 - std::sys::backtrace::BacktraceLock::print::h2930c514ae5653cd
   4:     0x7ffb9d1c6271 - std::panicking::default_hook::{{closure}}::hc7a5b0b766fd5663
   5:     0x7ffb9d1c60a4 - std::panicking::default_hook::h9d542ef7bbd51eed
   6:     0x7ffb9c2c3a4f - std[ee7033f0ed262c3b]::panicking::update_hook::<alloc[3af4d0b46ca260e8]::boxed::Box<rustc_driver_impl[2bd8fe8419d4e53d]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x7ffb9d1c6988 - std::panicking::rust_panic_with_hook::h426e85c59c56abd7
   8:     0x7ffb9d1c675a - std::panicking::begin_panic_handler::{{closure}}::hdbed8eca2a1d0322
   9:     0x7ffb9d1c4149 - std::sys::backtrace::__rust_end_short_backtrace::hfaec60235a9405e1
  10:     0x7ffb9d1c641c - rust_begin_unwind
  11:     0x7ffb99fe10b0 - core::panicking::panic_fmt::he0c447514557f5eb
  12:     0x7ffb9c37b861 - rustc_hir[9aec883c6500dd0e]::hir::expect_failed::<&rustc_hir[9aec883c6500dd0e]::hir::Item>
  13:     0x7ffb9e05b3af - rustc_hir_analysis[6076d6bf04e2ff00]::collect::impl_trait_header
  14:     0x7ffb9dbbb08e - rustc_query_impl[3b3b44733218f5bc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3b3b44733218f5bc]::query_impl::impl_trait_header::dynamic_query::{closure#2}::{closure#0}, rustc_middle[99c6bed041f57f4c]::query::erase::Erased<[u8; 24usize]>>
  15:     0x7ffb9dbba4b6 - rustc_query_system[52f0d79d68908be]::query::plumbing::try_execute_query::<rustc_query_impl[3b3b44733218f5bc]::DynamicConfig<rustc_query_system[52f0d79d68908be]::query::caches::DefIdCache<rustc_middle[99c6bed041f57f4c]::query::erase::Erased<[u8; 24usize]>>, false, false, false>, rustc_query_impl[3b3b44733218f5bc]::plumbing::QueryCtxt, false>
  16:     0x7ffb9dbba1a8 - rustc_query_impl[3b3b44733218f5bc]::query_impl::impl_trait_header::get_query_non_incr::__rust_end_short_backtrace
  17:     0x7ffb9dba8d31 - <rustc_middle[99c6bed041f57f4c]::ty::context::TyCtxt>::trait_id_of_impl
  18:     0x7ffb9d017f3d - <rustc_trait_selection[921af4f56dbc3556]::error_reporting::traits::on_unimplemented::OnUnimplementedFormatString>::try_parse
  19:     0x7ffb9d016c8c - <rustc_trait_selection[921af4f56dbc3556]::error_reporting::traits::on_unimplemented::OnUnimplementedDirective>::parse
  20:     0x7ffb9bc3ddc2 - <rustc_trait_selection[921af4f56dbc3556]::error_reporting::traits::on_unimplemented::OnUnimplementedDirective>::parse_attribute
  21:     0x7ffb9dc66e9e - <rustc_trait_selection[921af4f56dbc3556]::error_reporting::traits::on_unimplemented::OnUnimplementedDirective>::of_item
  22:     0x7ffb9d0153af - <rustc_trait_selection[921af4f56dbc3556]::error_reporting::TypeErrCtxt>::on_unimplemented_note
  23:     0x7ffb9cffe812 - <rustc_trait_selection[921af4f56dbc3556]::error_reporting::TypeErrCtxt>::report_selection_error
  24:     0x7ffb9d07c0cb - <rustc_trait_selection[921af4f56dbc3556]::error_reporting::TypeErrCtxt>::report_fulfillment_error
  25:     0x7ffb9d0444c7 - <rustc_trait_selection[921af4f56dbc3556]::error_reporting::TypeErrCtxt>::report_fulfillment_errors
  26:     0x7ffb9a56e063 - <rustc_hir_typeck[30566531c8d8333f]::fn_ctxt::FnCtxt>::confirm_builtin_call
  27:     0x7ffb9e4ae7b9 - <rustc_hir_typeck[30566531c8d8333f]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  28:     0x7ffb9e4a81fe - <rustc_hir_typeck[30566531c8d8333f]::fn_ctxt::FnCtxt>::check_block_with_expected
  29:     0x7ffb9e4af01d - <rustc_hir_typeck[30566531c8d8333f]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  30:     0x7ffb9d9f4b15 - rustc_hir_typeck[30566531c8d8333f]::check::check_fn
  31:     0x7ffb9dcef2fe - rustc_hir_typeck[30566531c8d8333f]::typeck
  32:     0x7ffb9dceed49 - rustc_query_impl[3b3b44733218f5bc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3b3b44733218f5bc]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[99c6bed041f57f4c]::query::erase::Erased<[u8; 8usize]>>
  33:     0x7ffb9dce16fd - rustc_query_system[52f0d79d68908be]::query::plumbing::try_execute_query::<rustc_query_impl[3b3b44733218f5bc]::DynamicConfig<rustc_query_system[52f0d79d68908be]::query::caches::VecCache<rustc_span[d9e8be537ef50d77]::def_id::LocalDefId, rustc_middle[99c6bed041f57f4c]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[3b3b44733218f5bc]::plumbing::QueryCtxt, false>
  34:     0x7ffb9dce044d - rustc_query_impl[3b3b44733218f5bc]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  35:     0x7ffb9dce00c7 - <rustc_middle[99c6bed041f57f4c]::hir::map::Map>::par_body_owners::<rustc_hir_analysis[6076d6bf04e2ff00]::check_crate::{closure#4}>::{closure#0}
  36:     0x7ffb9dcddf6e - rustc_hir_analysis[6076d6bf04e2ff00]::check_crate
  37:     0x7ffb9dcda8c5 - rustc_interface[7c2e5611e1eae4f6]::passes::run_required_analyses
  38:     0x7ffb9e504ade - rustc_interface[7c2e5611e1eae4f6]::passes::analysis
  39:     0x7ffb9e504ab1 - rustc_query_impl[3b3b44733218f5bc]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[3b3b44733218f5bc]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[99c6bed041f57f4c]::query::erase::Erased<[u8; 1usize]>>
  40:     0x7ffb9e7eb06e - rustc_query_system[52f0d79d68908be]::query::plumbing::try_execute_query::<rustc_query_impl[3b3b44733218f5bc]::DynamicConfig<rustc_query_system[52f0d79d68908be]::query::caches::SingleCache<rustc_middle[99c6bed041f57f4c]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[3b3b44733218f5bc]::plumbing::QueryCtxt, false>
  41:     0x7ffb9e7eadcf - rustc_query_impl[3b3b44733218f5bc]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  42:     0x7ffb9e65c25e - rustc_interface[7c2e5611e1eae4f6]::interface::run_compiler::<core[60b858db6614a1bf]::result::Result<(), rustc_span[d9e8be537ef50d77]::ErrorGuaranteed>, rustc_driver_impl[2bd8fe8419d4e53d]::run_compiler::{closure#0}>::{closure#1}
  43:     0x7ffb9e714a10 - std[ee7033f0ed262c3b]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[7c2e5611e1eae4f6]::util::run_in_thread_with_globals<rustc_interface[7c2e5611e1eae4f6]::util::run_in_thread_pool_with_globals<rustc_interface[7c2e5611e1eae4f6]::interface::run_compiler<core[60b858db6614a1bf]::result::Result<(), rustc_span[d9e8be537ef50d77]::ErrorGuaranteed>, rustc_driver_impl[2bd8fe8419d4e53d]::run_compiler::{closure#0}>::{closure#1}, core[60b858db6614a1bf]::result::Result<(), rustc_span[d9e8be537ef50d77]::ErrorGuaranteed>>::{closure#0}, core[60b858db6614a1bf]::result::Result<(), rustc_span[d9e8be537ef50d77]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[60b858db6614a1bf]::result::Result<(), rustc_span[d9e8be537ef50d77]::ErrorGuaranteed>>
  44:     0x7ffb9e71507a - <<std[ee7033f0ed262c3b]::thread::Builder>::spawn_unchecked_<rustc_interface[7c2e5611e1eae4f6]::util::run_in_thread_with_globals<rustc_interface[7c2e5611e1eae4f6]::util::run_in_thread_pool_with_globals<rustc_interface[7c2e5611e1eae4f6]::interface::run_compiler<core[60b858db6614a1bf]::result::Result<(), rustc_span[d9e8be537ef50d77]::ErrorGuaranteed>, rustc_driver_impl[2bd8fe8419d4e53d]::run_compiler::{closure#0}>::{closure#1}, core[60b858db6614a1bf]::result::Result<(), rustc_span[d9e8be537ef50d77]::ErrorGuaranteed>>::{closure#0}, core[60b858db6614a1bf]::result::Result<(), rustc_span[d9e8be537ef50d77]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[60b858db6614a1bf]::result::Result<(), rustc_span[d9e8be537ef50d77]::ErrorGuaranteed>>::{closure#1} as core[60b858db6614a1bf]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  45:     0x7ffb9e71546b - std::sys::pal::unix::thread::Thread::new::thread_start::h172f6b61f4e28e39
  46:     0x7ffb98d25609 - start_thread
  47:     0x7ffb98c4a353 - clone
  48:                0x0 - <unknown>
@andrzejressel andrzejressel 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 Sep 20, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 20, 2024
@fmease fmease added F-trait_alias `#![feature(trait_alias)]` F-on_unimplemented Error messages that can be tackled with `#[rustc_on_unimplemented]` and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Sep 20, 2024
@matthiaskrgr matthiaskrgr added S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. and removed 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. C-bug Category: This is a bug. labels Sep 29, 2024
@matthiaskrgr matthiaskrgr added 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. C-bug Category: This is a bug. labels Oct 9, 2024
@bors bors closed this as completed in aad59a3 Apr 20, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 20, 2025
Rollup merge of rust-lang#139091 - mejrs:format, r=compiler-errors

Rewrite on_unimplemented format string parser.

This PR rewrites the format string parser for `rustc_on_unimplemented` and `diagnostic::on_unimplemented`. I plan on moving this code (and more) into the new attribute parsing system soon and wanted to PR it separately.

This PR introduces some minor differences though:
- `rustc_on_unimplemented` on trait *implementations* is no longer checked/used - this is actually never used (outside of some tests) so I plan on removing it in the future.
- for `rustc_on_unimplemented`, it introduces the `{This}` argument in favor of `{ThisTraitname}` (to be removed later). It'll be easier to parse.
- for `rustc_on_unimplemented`, `Self` can now consistently be used as a filter, rather than just `_Self`. It used to not match correctly on for example `Self = "[{integer}]"`
- Some error messages now have better spans.

Fixes rust-lang#130627
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this issue Apr 21, 2025
Rewrite on_unimplemented format string parser.

This PR rewrites the format string parser for `rustc_on_unimplemented` and `diagnostic::on_unimplemented`. I plan on moving this code (and more) into the new attribute parsing system soon and wanted to PR it separately.

This PR introduces some minor differences though:
- `rustc_on_unimplemented` on trait *implementations* is no longer checked/used - this is actually never used (outside of some tests) so I plan on removing it in the future.
- for `rustc_on_unimplemented`, it introduces the `{This}` argument in favor of `{ThisTraitname}` (to be removed later). It'll be easier to parse.
- for `rustc_on_unimplemented`, `Self` can now consistently be used as a filter, rather than just `_Self`. It used to not match correctly on for example `Self = "[{integer}]"`
- Some error messages now have better spans.

Fixes rust-lang/rust#130627
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Apr 21, 2025
Rewrite on_unimplemented format string parser.

This PR rewrites the format string parser for `rustc_on_unimplemented` and `diagnostic::on_unimplemented`. I plan on moving this code (and more) into the new attribute parsing system soon and wanted to PR it separately.

This PR introduces some minor differences though:
- `rustc_on_unimplemented` on trait *implementations* is no longer checked/used - this is actually never used (outside of some tests) so I plan on removing it in the future.
- for `rustc_on_unimplemented`, it introduces the `{This}` argument in favor of `{ThisTraitname}` (to be removed later). It'll be easier to parse.
- for `rustc_on_unimplemented`, `Self` can now consistently be used as a filter, rather than just `_Self`. It used to not match correctly on for example `Self = "[{integer}]"`
- Some error messages now have better spans.

Fixes rust-lang/rust#130627
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-on_unimplemented Error messages that can be tackled with `#[rustc_on_unimplemented]` F-trait_alias `#![feature(trait_alias)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. 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