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 expected statement --test #112360

Closed
matthiaskrgr opened this issue Jun 6, 2023 · 1 comment · Fixed by #112366
Closed

ICE expected statement --test #112360

matthiaskrgr opened this issue Jun 6, 2023 · 1 comment · Fixed by #112366
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

Code

rustc --test file.rs

#[test]
mod FOO2 {
    fn r#final() {
        #[test] 
        fn fooS(&'late u8) {}
        bar(-16);
    }
}

Meta

rustc --version --verbose:

rustc 1.72.0-nightly (e6d4725c7 2023-06-05)
binary: rustc
commit-hash: e6d4725c76f3b526c74454bc51afdf6daf133506
commit-date: 2023-06-05
host: x86_64-unknown-linux-gnu
release: 1.72.0-nightly
LLVM version: 16.0.4

Error output

<output>
Backtrace

error: functions used as tests can not have any arguments
 --> treereduce.out:5:9
  |
5 |         fn fooS(&'late u8) {}
  |         ^^^^^^^^^^^^^^^^^^^^^

thread 'rustc' panicked at 'expected statement', compiler/rustc_expand/src/base.rs:174:18
stack backtrace:
   0:     0x7f7491b69ba1 - trace
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f7491b69ba1 - trace_unsynchronized<std::sys_common::backtrace::_print_fmt::{closure_env#1}>
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f7491b69ba1 - _print_fmt
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f7491b69ba1 - fmt
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f7491bca18f - fmt
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/core/src/fmt/rt.rs:138:9
   5:     0x7f7491bca18f - write
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/core/src/fmt/mod.rs:1094:21
   6:     0x7f7491b5ce51 - write_fmt<std::sys::unix::stdio::Stderr>
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/std/src/io/mod.rs:1713:15
   7:     0x7f7491b699b5 - _print
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x7f7491b699b5 - print
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x7f7491b6c677 - {closure#1}
  10:     0x7f7491b6c464 - default_hook
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/std/src/panicking.rs:288:9
  11:     0x7f7494da03eb - rustc_driver_impl[19f317ad306b3be2]::install_ice_hook::{closure#0}
  12:     0x7f7491b6cdbd - call<(&core::panic::panic_info::PanicInfo), (dyn core::ops::function::Fn<(&core::panic::panic_info::PanicInfo), Output=()> + core::marker::Send + core::marker::Sync), alloc::alloc::Global>
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/alloc/src/boxed.rs:1999:9
  13:     0x7f7491b6cdbd - rust_panic_with_hook
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/std/src/panicking.rs:709:13
  14:     0x7f7491b6cb11 - {closure#0}
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/std/src/panicking.rs:595:13
  15:     0x7f7491b69fd6 - __rust_end_short_backtrace<std::panicking::begin_panic_handler::{closure_env#0}, !>
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/std/src/sys_common/backtrace.rs:151:18
  16:     0x7f7491b6c8a2 - begin_panic_handler
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/std/src/panicking.rs:593:5
  17:     0x7f7491bc6413 - panic_fmt
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/core/src/panicking.rs:67:14
  18:     0x7f749393ae62 - <smallvec[816c5806f2fd16a1]::SmallVec<[rustc_ast[991827be689883d]::ast::Stmt; 1usize]> as core[89b1b7d1b31a1e7d]::iter::traits::collect::Extend<rustc_ast[991827be689883d]::ast::Stmt>>::extend::<core[89b1b7d1b31a1e7d]::iter::adapters::map::Map<alloc[bb2455db20450995]::vec::into_iter::IntoIter<rustc_expand[b112cc884c002b49]::base::Annotatable>, <rustc_expand[b112cc884c002b49]::base::Annotatable>::expect_stmt>>
  19:     0x7f7493900d8d - <rustc_expand[b112cc884c002b49]::expand::AstFragmentKind>::expect_from_annotatables::<alloc[bb2455db20450995]::vec::Vec<rustc_expand[b112cc884c002b49]::base::Annotatable>>
  20:     0x7f74938ed201 - <rustc_expand[b112cc884c002b49]::expand::MacroExpander>::fully_expand_fragment
  21:     0x7f7493dd3fb7 - <rustc_expand[b112cc884c002b49]::expand::MacroExpander>::expand_crate
  22:     0x7f7493dd3260 - <rustc_session[23023510f27a6956]::session::Session>::time::<rustc_ast[991827be689883d]::ast::Crate, rustc_interface[e4001d1c190a5888]::passes::configure_and_expand::{closure#1}>
  23:     0x7f7493d87658 - rustc_interface[e4001d1c190a5888]::passes::resolver_for_lowering
  24:     0x7f749429a91a - rustc_query_impl[1543b9ffeb56b6f4]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[1543b9ffeb56b6f4]::query_impl::resolver_for_lowering::dynamic_query::{closure#2}::{closure#0}, rustc_middle[ef323c168d9384f4]::query::erase::Erased<[u8; 8usize]>>
  25:     0x7f749429a909 - <rustc_query_impl[1543b9ffeb56b6f4]::query_impl::resolver_for_lowering::dynamic_query::{closure#2} as core[89b1b7d1b31a1e7d]::ops::function::FnOnce<(rustc_middle[ef323c168d9384f4]::ty::context::TyCtxt, ())>>::call_once
  26:     0x7f74941efa7c - rustc_query_system[494966daf0575a9b]::query::plumbing::try_execute_query::<rustc_query_impl[1543b9ffeb56b6f4]::DynamicConfig<rustc_query_system[494966daf0575a9b]::query::caches::SingleCache<rustc_middle[ef323c168d9384f4]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[1543b9ffeb56b6f4]::plumbing::QueryCtxt, false>
  27:     0x7f74947244c7 - rustc_query_impl[1543b9ffeb56b6f4]::query_impl::resolver_for_lowering::get_query_non_incr::__rust_end_short_backtrace
  28:     0x7f749441e413 - <rustc_middle[ef323c168d9384f4]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[19f317ad306b3be2]::run_compiler::{closure#1}::{closure#2}::{closure#2}, &rustc_data_structures[7856cba86f978d37]::steal::Steal<(rustc_middle[ef323c168d9384f4]::ty::ResolverAstLowering, alloc[bb2455db20450995]::rc::Rc<rustc_ast[991827be689883d]::ast::Crate>)>>
  29:     0x7f7493fd9c86 - <rustc_interface[e4001d1c190a5888]::interface::Compiler>::enter::<rustc_driver_impl[19f317ad306b3be2]::run_compiler::{closure#1}::{closure#2}, core[89b1b7d1b31a1e7d]::result::Result<core[89b1b7d1b31a1e7d]::option::Option<rustc_interface[e4001d1c190a5888]::queries::Linker>, rustc_span[c9fd14582bbb5db9]::ErrorGuaranteed>>
  30:     0x7f7493fd7370 - std[4cc418835f9904b9]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[e4001d1c190a5888]::util::run_in_thread_pool_with_globals<rustc_interface[e4001d1c190a5888]::interface::run_compiler<core[89b1b7d1b31a1e7d]::result::Result<(), rustc_span[c9fd14582bbb5db9]::ErrorGuaranteed>, rustc_driver_impl[19f317ad306b3be2]::run_compiler::{closure#1}>::{closure#0}, core[89b1b7d1b31a1e7d]::result::Result<(), rustc_span[c9fd14582bbb5db9]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[89b1b7d1b31a1e7d]::result::Result<(), rustc_span[c9fd14582bbb5db9]::ErrorGuaranteed>>
  31:     0x7f7493fd6b15 - <<std[4cc418835f9904b9]::thread::Builder>::spawn_unchecked_<rustc_interface[e4001d1c190a5888]::util::run_in_thread_pool_with_globals<rustc_interface[e4001d1c190a5888]::interface::run_compiler<core[89b1b7d1b31a1e7d]::result::Result<(), rustc_span[c9fd14582bbb5db9]::ErrorGuaranteed>, rustc_driver_impl[19f317ad306b3be2]::run_compiler::{closure#1}>::{closure#0}, core[89b1b7d1b31a1e7d]::result::Result<(), rustc_span[c9fd14582bbb5db9]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[89b1b7d1b31a1e7d]::result::Result<(), rustc_span[c9fd14582bbb5db9]::ErrorGuaranteed>>::{closure#1} as core[89b1b7d1b31a1e7d]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  32:     0x7f7491b772b5 - call_once<(), dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global>
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/alloc/src/boxed.rs:1985:9
  33:     0x7f7491b772b5 - call_once<(), alloc::boxed::Box<dyn core::ops::function::FnOnce<(), Output=()>, alloc::alloc::Global>, alloc::alloc::Global>
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/alloc/src/boxed.rs:1985:9
  34:     0x7f7491b772b5 - thread_start
                               at /rustc/e6d4725c76f3b526c74454bc51afdf6daf133506/library/std/src/sys/unix/thread.rs:108:17
  35:     0x7f749191144b - <unknown>
  36:     0x7f7491994e40 - <unknown>
  37:                0x0 - <unknown>

error: 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.72.0-nightly (e6d4725c7 2023-06-05) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [resolver_for_lowering] getting the resolver for lowering
end of query stack
error: aborting due to 4 previous errors

@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 Jun 6, 2023
@matthiaskrgr
Copy link
Member Author

matthiaskrgr commented Jun 6, 2023

reduced even more

fn a() {
	#[test] 
	fn b(c) {}
}

@matthiaskrgr matthiaskrgr added the S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue label Jun 6, 2023
jyn514 added a commit to jyn514/rust that referenced this issue Jun 19, 2023
`#[test]` function signature verification improvements

This PR contains two improvements to the expansion of the `#[test]` macro.

The first one fixes rust-lang#112360 by correctly recovering item statements if the signature verification fails.

The second one forbids non-lifetime generics on `#[test]` functions. These were previously allowed if the function returned `()`, but always caused an inference error:

before:
```text
error[E0282]: type annotations needed
 --> src/lib.rs:2:1
  |
1 | #[test]
  | ------- in this procedural macro expansion
2 | fn foo<T>() {}
  | ^^^^^^^^^^^^^^ cannot infer type
```

after:
```text
error: functions used as tests can not have any non-lifetime generic parameters
 --> src/lib.rs:2:1
  |
2 | fn foo<T>() {}
  | ^^^^^^^^^^^^^^
```

Also includes some basic tests for test function signature verification, because I couldn't find any (???) in the test suite.
@bors bors closed this as completed in 6895110 Jun 19, 2023
bors added a commit to rust-lang/miri that referenced this issue Jun 22, 2023
`#[test]` function signature verification improvements

This PR contains two improvements to the expansion of the `#[test]` macro.

The first one fixes rust-lang/rust#112360 by correctly recovering item statements if the signature verification fails.

The second one forbids non-lifetime generics on `#[test]` functions. These were previously allowed if the function returned `()`, but always caused an inference error:

before:
```text
error[E0282]: type annotations needed
 --> src/lib.rs:2:1
  |
1 | #[test]
  | ------- in this procedural macro expansion
2 | fn foo<T>() {}
  | ^^^^^^^^^^^^^^ cannot infer type
```

after:
```text
error: functions used as tests can not have any non-lifetime generic parameters
 --> src/lib.rs:2:1
  |
2 | fn foo<T>() {}
  | ^^^^^^^^^^^^^^
```

Also includes some basic tests for test function signature verification, because I couldn't find any (???) in the test suite.
lnicola pushed a commit to lnicola/rust-analyzer that referenced this issue Apr 7, 2024
`#[test]` function signature verification improvements

This PR contains two improvements to the expansion of the `#[test]` macro.

The first one fixes rust-lang/rust#112360 by correctly recovering item statements if the signature verification fails.

The second one forbids non-lifetime generics on `#[test]` functions. These were previously allowed if the function returned `()`, but always caused an inference error:

before:
```text
error[E0282]: type annotations needed
 --> src/lib.rs:2:1
  |
1 | #[test]
  | ------- in this procedural macro expansion
2 | fn foo<T>() {}
  | ^^^^^^^^^^^^^^ cannot infer type
```

after:
```text
error: functions used as tests can not have any non-lifetime generic parameters
 --> src/lib.rs:2:1
  |
2 | fn foo<T>() {}
  | ^^^^^^^^^^^^^^
```

Also includes some basic tests for test function signature verification, because I couldn't find any (???) in the test suite.
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 27, 2024
`#[test]` function signature verification improvements

This PR contains two improvements to the expansion of the `#[test]` macro.

The first one fixes rust-lang/rust#112360 by correctly recovering item statements if the signature verification fails.

The second one forbids non-lifetime generics on `#[test]` functions. These were previously allowed if the function returned `()`, but always caused an inference error:

before:
```text
error[E0282]: type annotations needed
 --> src/lib.rs:2:1
  |
1 | #[test]
  | ------- in this procedural macro expansion
2 | fn foo<T>() {}
  | ^^^^^^^^^^^^^^ cannot infer type
```

after:
```text
error: functions used as tests can not have any non-lifetime generic parameters
 --> src/lib.rs:2:1
  |
2 | fn foo<T>() {}
  | ^^^^^^^^^^^^^^
```

Also includes some basic tests for test function signature verification, because I couldn't find any (???) in the test suite.
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) ❄️ S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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.

1 participant