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

Something funky crashes typeck (stable and nightly) #90444

Closed
mental32 opened this issue Oct 31, 2021 · 2 comments · Fixed by #90646
Closed

Something funky crashes typeck (stable and nightly) #90444

mental32 opened this issue Oct 31, 2021 · 2 comments · Fixed by #90646
Assignees
Labels
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

@mental32
Copy link
Contributor

mental32 commented Oct 31, 2021

Code

type A = ();

pub struct B(());

enum Thing {}

type FnAlias<R = B> = fn(A, &[B], R);

impl From<FnAlias<()>> for Thing {
    fn from(_: FnAlias) -> Self {}
}

Meta

rustc --version --verbose:

rustc 1.58.0-nightly (e249ce6b2 2021-10-30)
binary: rustc
commit-hash: e249ce6b2345587d6e11052779c86adbad626dff
commit-date: 2021-10-30
host: x86_64-unknown-linux-gnu
release: 1.58.0-nightly
LLVM version: 13.0.0

Also get this using stable:

rustc 1.56.0 (09c42c458 2021-10-18)
binary: rustc
commit-hash: 09c42c45858d5f3aedfa670698275303a3d19afa
commit-date: 2021-10-18
host: x86_64-unknown-linux-gnu
release: 1.56.0
LLVM version: 13.0.0

You can see it on the playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=3249dfb3850d684ed13b10623e3dfa60

Error output

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler/rustc_typeck/src/check/compare_method.rs:485:31
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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.56.0 (09c42c458 2021-10-18) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
#0 [check_mod_item_types] checking item types in top-level module
#1 [analysis] running analysis passes on this crate
end of query stack
Backtrace

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler/rustc_typeck/src/check/compare_method.rs:485:31
stack backtrace:
   0: rust_begin_unwind
             at /rustc/09c42c45858d5f3aedfa670698275303a3d19afa/library/std/src/panicking.rs:517:5
   1: core::panicking::panic_fmt
             at /rustc/09c42c45858d5f3aedfa670698275303a3d19afa/library/core/src/panicking.rs:101:14
   2: core::panicking::panic
             at /rustc/09c42c45858d5f3aedfa670698275303a3d19afa/library/core/src/panicking.rs:50:5
   3: rustc_typeck::check::compare_method::extract_spans_for_error_reporting
   4: rustc_infer::infer::InferCtxtBuilder::enter
   5: rustc_typeck::check::compare_method::compare_impl_method
   6: rustc_typeck::check::check::check_item_type
   7: rustc_middle::hir::map::Map::visit_item_likes_in_module
   8: rustc_typeck::check::check::check_mod_item_types
   9: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  10: rustc_data_structures::stack::ensure_sufficient_stack
  11: rustc_query_system::query::plumbing::force_query_with_job
  12: rustc_query_system::query::plumbing::get_query_impl
  13: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::check_mod_item_types
  14: rustc_session::utils::<impl rustc_session::session::Session>::time
  15: rustc_typeck::check_crate
  16: rustc_interface::passes::analysis
  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::force_query_with_job
  20: rustc_query_system::query::plumbing::get_query_impl
  21: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::analysis
  22: rustc_interface::passes::QueryContext::enter
  23: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  24: rustc_span::with_source_map
  25: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

@mental32 mental32 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 Oct 31, 2021
@mental32 mental32 changed the title From<Alias> for Type impls for aliases with some for<'...> lifetimes crashes typechecking (stable and nightly) From<Alias> for Type impls for aliases ice's during typeck (stable and nightly) Oct 31, 2021
@mental32 mental32 changed the title From<Alias> for Type impls for aliases ice's during typeck (stable and nightly) Something funky about From<Alias<T>> an fn from(_: Alias) crashes typeck (stable and nightly) Oct 31, 2021
@mental32 mental32 changed the title Something funky about From<Alias<T>> an fn from(_: Alias) crashes typeck (stable and nightly) Something funky about From<Alias<T>> and fn from(_: Alias) crashes typeck (stable and nightly) Oct 31, 2021
@mental32 mental32 changed the title Something funky about From<Alias<T>> and fn from(_: Alias) crashes typeck (stable and nightly) Something funky about a missing generic in an alias crashes typeck (stable and nightly) Oct 31, 2021
@mental32 mental32 changed the title Something funky about a missing generic in an alias crashes typeck (stable and nightly) Something funky crashes typeck (stable and nightly) Oct 31, 2021
@BlaCoiso
Copy link
Contributor

BlaCoiso commented Oct 31, 2021

Can reproduce even without the type aliases:

pub struct B(());

enum Thing {}

impl From<fn((), &[B], ())> for Thing {
    fn from(_: fn((), &[B], ()) -> Self {}
}

Edit: even smaller reproducer:

enum Thing {}

impl From<fn((), ())> for Thing {
    fn from(_: fn((), ()) -> Self {}
}

Produces this output: (rustc rustc_crash.rs)

error: mismatched closing delimiter: `}`
 --> rustc_crash.rs:6:12
  |
5 | impl From<fn((), &[B], ())> for Thing {
  |                                       - closing delimiter possibly meant for this
6 |     fn from(_: fn((), &[B], ()) -> Self {}
  |            ^ unclosed delimiter
7 | }
  | ^ mismatched closing delimiter

error: expected one of `!`, `(`, `)`, `,`, `::`, or `<`, found `{`
 --> rustc_crash.rs:6:12
  |
6 |     fn from(_: fn((), &[B], ()) -> Self {}
  |            ^                           -^
  |            |                           |
  |            unclosed delimiter          help: `)` may belong here

error: non-item in item list
 --> rustc_crash.rs:7:1
  |
5 | impl From<fn((), &[B], ())> for Thing {
  |                                       - item list starts here
6 |     fn from(_: fn((), &[B], ()) -> Self {}
7 | }
  | ^
  | |
  | non-item starts here
  | item list ends here

error[E0601]: `main` function not found in crate `rustc_crash`
 --> rustc_crash.rs:1:1
  |
1 | / pub struct B(());
2 | |
3 | | enum Thing {}
4 | |
5 | | impl From<fn((), &[B], ())> for Thing {
6 | |     fn from(_: fn((), &[B], ()) -> Self {}
7 | | }
  | |_^ consider adding a `main` function to `rustc_crash.rs`

thread 'rustc' panicked at 'called `Option::unwrap()` on a `None` value', compiler\rustc_typeck\src\check\compare_method.rs:485:31
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

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.56.0 (09c42c458 2021-10-18) running on x86_64-pc-windows-msvc

query stack during panic:
#0 [check_mod_item_types] checking item types in top-level module
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0601`.

rustc --version --verbose:

rustc 1.56.0 (09c42c458 2021-10-18)
binary: rustc
commit-hash: 09c42c45858d5f3aedfa670698275303a3d19afa
commit-date: 2021-10-18
host: x86_64-pc-windows-msvc
release: 1.56.0
LLVM version: 13.0.0

@BlaCoiso
Copy link
Contributor

BlaCoiso commented Oct 31, 2021

After some testing, this can be reproduced since 1.53, might have been introduced in d43ede1

match *terr {
TypeError::ArgumentMutability(i) => {
(impl_args.nth(i).unwrap(), trait_args.and_then(|mut args| args.nth(i)))
}
TypeError::ArgumentSorts(ExpectedFound { .. }, i) => {
(impl_args.nth(i).unwrap(), trait_args.and_then(|mut args| args.nth(i)))
}
_ => (cause.span(tcx), tcx.hir().span_if_local(trait_m.def_id)),
}

@BoxyUwU BoxyUwU self-assigned this Nov 6, 2021
@bors bors closed this as completed in 43fee0e Nov 7, 2021
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. 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.

3 participants