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

ICE when passing numeric literals to str as generics #82199

Closed
JakeStanger opened this issue Feb 16, 2021 · 4 comments
Closed

ICE when passing numeric literals to str as generics #82199

JakeStanger opened this issue Feb 16, 2021 · 4 comments
Labels
A-const-generics Area: const generics (parameters and arguments) 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

@JakeStanger
Copy link

JakeStanger commented Feb 16, 2021

Here's a fun one I discovered back in 2019 when I first started learning Rust and forgot to report (sorry!). I figured I'd try the genius idea of making a string of length 3 by passing 3 as a generic. I dug up the code that caused the problem, and it sure enough causes the same crash now.

Code

let test: str<3> = "hello world";

Meta

rustc --version --verbose:

rustc 1.48.0-nightly (d006f5734 2020-08-28)
binary: rustc
commit-hash: d006f5734f49625c34d6fc33bf6b9967243abca8
commit-date: 2020-08-28
host: x86_64-unknown-linux-gnu
release: 1.48.0-nightly
LLVM version: 11.0

Error output

error: internal compiler error: src/librustc_typeck/collect/type_of.rs:114:26: unexpected anon const res PrimTy(Str) in path: Path { span: src/main.rs:14:17: 14:23 (#0), res: PrimTy(Str), segments: [PathSegment { ident: str#0, hir_id: Some(HirId { owner: DefId(0:10 ~ toffee[3d1d]::main[0]), local_id: 9 }), res: Some(Err), args: Some(GenericArgs { args: [Const(ConstArg { value: AnonConst { hir_id: HirId { owner: DefId(0:10 ~ toffee[3d1d]::main[0]), local_id: 7 }, body: BodyId { hir_id: HirId { owner: DefId(0:10 ~ toffee[3d1d]::main[0]), local_id: 8 } } }, span: src/main.rs:14:21: 14:22 (#0) })], bindings: [], parenthesized: false }), infer_args: false }] }

thread 'rustc' panicked at 'Box<Any>', /rustc/d006f5734f49625c34d6fc33bf6b9967243abca8/src/librustc_errors/lib.rs:873:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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.48.0-nightly (d006f5734 2020-08-28) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type bin

note: some of the compiler flags provided by cargo are hidden
Backtrace

thread 'rustc' panicked at 'Box<Any>', /rustc/d006f5734f49625c34d6fc33bf6b9967243abca8/src/librustc_errors/lib.rs:873:9
stack backtrace:
   0: std::panicking::begin_panic
   1: rustc_errors::HandlerInner::span_bug
   2: rustc_errors::Handler::span_bug
   3: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
   4: rustc_middle::ty::context::tls::with_opt::{{closure}}
   5: rustc_middle::ty::context::tls::with_opt
   6: rustc_middle::util::bug::opt_span_bug_fmt
   7: rustc_middle::util::bug::span_bug_fmt
   8: rustc_typeck::collect::type_of::opt_const_param_of
   9: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::opt_const_param_of>::compute
  10: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  11: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  12: rustc_data_structures::stack::ensure_sufficient_stack
  13: rustc_query_system::query::plumbing::get_query_impl
  14: rustc_typeck::check::typeck
  15: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::typeck>::compute
  16: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  17: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  18: rustc_data_structures::stack::ensure_sufficient_stack
  19: rustc_query_system::query::plumbing::get_query_impl
  20: rustc_query_system::query::plumbing::ensure_query_impl
  21: rustc_typeck::check::typeck_item_bodies
  22: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::typeck_item_bodies>::compute
  23: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  24: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  25: rustc_data_structures::stack::ensure_sufficient_stack
  26: rustc_query_system::query::plumbing::get_query_impl
  27: rustc_typeck::check_crate
  28: rustc_interface::passes::analysis
  29: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  30: rustc_middle::dep_graph::<impl rustc_query_system::dep_graph::DepKind for rustc_middle::dep_graph::dep_node::DepKind>::with_deps
  31: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  32: rustc_data_structures::stack::ensure_sufficient_stack
  33: rustc_query_system::query::plumbing::get_query_impl
  34: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  35: rustc_span::with_source_map
  36: rustc_interface::interface::create_compiler_and_run
  37: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@JakeStanger JakeStanger 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 Feb 16, 2021
@JakeStanger JakeStanger changed the title ICE when passing numeric literals to str ICE when passing numeric literals to str as generics Feb 16, 2021
@jonas-schievink jonas-schievink added A-const-generics Area: const generics (parameters and arguments) I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Feb 17, 2021
@jyn514
Copy link
Member

jyn514 commented Feb 17, 2021

1.48-nightly is 6 months old, this is fixed on master. https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=804b1c50345e46ef1473cd7341a3e1e9

@jyn514 jyn514 closed this as completed Feb 17, 2021
@jyn514 jyn514 removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Feb 17, 2021
@camelid
Copy link
Member

camelid commented Feb 17, 2021

Dang, you beat me to it by 1 minute! 😆

@camelid
Copy link
Member

camelid commented Feb 17, 2021

Based on testing with Godbolt, it looks like it was fixed in 1.49.0. Probably work on const generics is what fixed it.

@JakeStanger
Copy link
Author

🤦 my bad, I saw my version was nightly and didn't think to update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) 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

No branches or pull requests

4 participants