#![warn(rust_2021_compatibility)]
trait Static<'a> {}
struct Foo((u32, u32));
fn main() {
type T = impl Static;
let foo: T = Foo((1u32, 2u32));
let x = move || {
let Foo((a, b)) = foo;
};
}
I'm not sure whether it is okay to report ICE which requires #![warn(rust_2021_compatibility)] attribute.
(original, ~100 lines)
```Rust
//@ edition:2018
//@ revisions: rpass1
// Regression test for #86753. The `type_implements_trait` query (since moved to a method)
// was encountering an ICE during incremental testing when hashing its arguments.
#![warn(rust_2021_compatibility)]
use std::future::Future;
use std::pin::Pin;
use std::task::{Poll, Context};
struct LocalSet {}
struct RunUntil<'a, F> {
_local_set: &'a LocalSet,
_future: F,
}
impl<'a, F> RunUntil<'a, F> {
fn project<'pin>(self: Pin<&'pin mut Self>) -> Projection<'pin, 'a, F> {
unimplemented!()
}
}
struct Projection<'pin, 'a, F>
where
RunUntil<'a, F>: 'pin,
{
pub local_set: &'pin mut &'a LocalSet,
pub future: Pin<&'pin mut F>,
}
impl LocalSet {
fn with(&self, _f: impl FnOnce() -> T) -> T {
unimplemented!()
}
}
impl Future for RunUntil<'_, T> {
type Output = T::Output;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll {
let me = self.project();
me.local_set.with(|| {
let _ = cx.waker();
let f = me.future;
let _ = f.poll(cx);
Poll::Pending
})
}
}
fn main() {}
#![feature(arbitrary_self_types)]
trait Static<'a> {
fn proof(self: *const Self, s: &'a str) -> &'static str;
}
fn bad_cast<'a>(x: Self::Output) -> *const dyn Static<'a> {
x as _
}
impl Static<'static> for () {
fn proof(self: *const Self, s: &'static str) -> &'static str {
s
}
}
fn extend_lifetime(s: &str) -> &'static str {
bad_cast(&()).proof(s)
}
fn main() {
let s = String::from("Hello World");
let slice = extend_lifetime(&s);
println!("Now it exists: {slice}");
drop(s);
println!("Now it’s gone: {slice}");
}
#![feature(type_alias_impl_trait)]
#[derive(Copy, Clone)]
struct Foo((u32, u32));
fn main() {
type T = impl Static;
let foo: T = Foo((1u32, 2u32));
let x = move || {
let Foo((a, b)) = foo;
};
}
```
error[E0106]: missing lifetime specifier
--> r_closure331_419FDD4D.rs:8:19
|
8 | type T = impl Static;
| ^^^^^^ expected named lifetime parameter
|
= note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
help: consider making the bound lifetime-generic with a new `'a` lifetime
|
8 | type T = impl for<'a> Static<'a>;
| +++++++ ++++
help: consider introducing a named lifetime parameter
|
8 | type T<'a> = impl Static<'a>;
| ++++ ++++
error[E0658]: `impl Trait` in type aliases is unstable
--> r_closure331_419FDD4D.rs:8:14
|
8 | type T = impl Static;
| ^^^^^^^^^^^
|
= note: see issue #63063 <https://github.com/rust-lang/rust/issues/63063> for more information
= help: add `#![feature(type_alias_impl_trait)]` to the crate attributes to enable
= note: this compiler was built on 2024-06-18; consider upgrading it if it is out of date
Backtrace
```
error: internal compiler error: compiler/rustc_middle/src/ty/closure.rs:331:21: OpaqueCast unexpected because it isn't captured
thread 'rustc' panicked at compiler/rustc_middle/src/ty/closure.rs:331:21:
Box
stack backtrace:
0: std::panicking::begin_panic::
1: ::emit_producing_guarantee
2: rustc_middle::util::bug::opt_span_bug_fmt::::{closure#0}
3: rustc_middle::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0}
4: rustc_middle::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !>
5: rustc_middle::util::bug::bug_fmt
6: rustc_middle::ty::closure::place_to_string_for_capture
7: ::compute_2229_migrations
8: ::analyze_closure
9: ::visit_expr
10: ::visit_block
11: rustc_hir_typeck::typeck
[... omitted 1 frame ...]
12: rustc_middle::query::plumbing::query_get_at::>>
13: ::check
14: rustc_hir_analysis::collect::type_of::type_of_opaque
[... omitted 1 frame ...]
15: rustc_middle::query::plumbing::query_get_at::>>
16: rustc_hir_analysis::collect::type_of::type_of
[... omitted 1 frame ...]
17: rustc_middle::query::plumbing::query_get_at::>>
18: rustc_hir_analysis::check::check::check_item_type
19: rustc_hir_analysis::check::wfcheck::check_well_formed
[... omitted 1 frame ...]
20: rustc_middle::query::plumbing::query_ensure_error_guaranteed::>, ()>
21: rustc_hir_analysis::check::wfcheck::check_mod_type_wf
[... omitted 1 frame ...]
22: rustc_hir_analysis::check_crate
23: rustc_interface::passes::run_required_analyses
24: rustc_interface::passes::analysis
[... omitted 1 frame ...]
25: >::enter::, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}::{closure#3}>
26: rustc_interface::interface::run_compiler::, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
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: please make sure that you have updated to the latest nightly
note: please attach the file at `/Volumes/T7/workspace/240615_100chaos_tree_combine_typ/icefiles/rustc-ice-2024-06-19T06_47_34-44593.txt` to your bug report
query stack during panic:
#0 [typeck] type-checking `main`
#1 [type_of_opaque] computing type of opaque `main::T::{opaque#0}`
#2 [type_of] computing type of `main::T::{opaque#0}`
#3 [check_well_formed] checking that `main::T::{opaque#0}` is well-formed
#4 [check_mod_type_wf] checking that types are well-formed in top-level module
#5 [analysis] running analysis passes on this crate
end of query stack
error[E0391]: cycle detected when computing type of opaque `main::T::{opaque#0}`
--> r_closure331_419FDD4D.rs:8:14
|
8 | type T = impl Static;
| ^^^^^^^^^^^
|
note: ...which requires type-checking `main`...
--> r_closure331_419FDD4D.rs:7:1
|
7 | fn main() {
| ^^^^^^^^^
= note: ...which requires evaluating trait selection obligation `main::T: core::panic::unwind_safe::RefUnwindSafe`...
= note: ...which again requires computing type of opaque `main::T::{opaque#0}`, completing the cycle
note: cycle used when computing type of `main::T::{opaque#0}`
--> r_closure331_419FDD4D.rs:8:14
|
8 | type T = impl Static;
| ^^^^^^^^^^^
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0106, E0391, E0658.
For more information about an error, try `rustc --explain E0106`.
```
Code
(hand-reduced)
I'm not sure whether it is okay to report ICE which requires
#![warn(rust_2021_compatibility)]
attribute.(original, ~100 lines)
```Rust //@ edition:2018 //@ revisions: rpass1 // Regression test for #86753. The `type_implements_trait` query (since moved to a method) // was encountering an ICE during incremental testing when hashing its arguments. #![warn(rust_2021_compatibility)] use std::future::Future; use std::pin::Pin; use std::task::{Poll, Context}; struct LocalSet {} struct RunUntil<'a, F> { _local_set: &'a LocalSet, _future: F, } impl<'a, F> RunUntil<'a, F> { fn project<'pin>(self: Pin<&'pin mut Self>) -> Projection<'pin, 'a, F> { unimplemented!() } } struct Projection<'pin, 'a, F> where RunUntil<'a, F>: 'pin, { pub local_set: &'pin mut &'a LocalSet, pub future: Pin<&'pin mut F>, } impl LocalSet { fn with(&self, _f: impl FnOnce() -> T) -> T {
unimplemented!()
}
}
impl Future for RunUntil<'_, T> {
type Output = T::Output;
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll {
let me = self.project();
me.local_set.with(|| {
let _ = cx.waker();
let f = me.future;
let _ = f.poll(cx);
Poll::Pending
})
}
}
fn main() {}
#![feature(arbitrary_self_types)]
trait Static<'a> {
fn proof(self: *const Self, s: &'a str) -> &'static str;
}
fn bad_cast<'a>(x: Self::Output) -> *const dyn Static<'a> {
x as _
}
impl Static<'static> for () {
fn proof(self: *const Self, s: &'static str) -> &'static str {
s
}
}
fn extend_lifetime(s: &str) -> &'static str {
bad_cast(&()).proof(s)
}
fn main() {
let s = String::from("Hello World");
let slice = extend_lifetime(&s);
println!("Now it exists: {slice}");
drop(s);
println!("Now it’s gone: {slice}");
}
#![feature(type_alias_impl_trait)]
#[derive(Copy, Clone)]
struct Foo((u32, u32));
fn main() {
type T = impl Static;
let foo: T = Foo((1u32, 2u32));
let x = move || {
let Foo((a, b)) = foo;
};
}
```
Meta
rustc --version --verbose
:Error output
Command:
rustc
Backtrace
``` error: internal compiler error: compiler/rustc_middle/src/ty/closure.rs:331:21: OpaqueCast unexpected because it isn't captured thread 'rustc' panicked at compiler/rustc_middle/src/ty/closure.rs:331:21: Box
stack backtrace:
0: std::panicking::begin_panic::
1: ::emit_producing_guarantee
2: rustc_middle::util::bug::opt_span_bug_fmt::::{closure#0}
3: rustc_middle::ty::context::tls::with_opt::::{closure#0}, !>::{closure#0}
4: rustc_middle::ty::context::tls::with_context_opt::::{closure#0}, !>::{closure#0}, !>
5: rustc_middle::util::bug::bug_fmt
6: rustc_middle::ty::closure::place_to_string_for_capture
7: ::compute_2229_migrations
8: ::analyze_closure
9: ::visit_expr
10: ::visit_block
11: rustc_hir_typeck::typeck
[... omitted 1 frame ...]
12: rustc_middle::query::plumbing::query_get_at::>>
13: ::check
14: rustc_hir_analysis::collect::type_of::type_of_opaque
[... omitted 1 frame ...]
15: rustc_middle::query::plumbing::query_get_at::>>
16: rustc_hir_analysis::collect::type_of::type_of
[... omitted 1 frame ...]
17: rustc_middle::query::plumbing::query_get_at::>>
18: rustc_hir_analysis::check::check::check_item_type
19: rustc_hir_analysis::check::wfcheck::check_well_formed
[... omitted 1 frame ...]
20: rustc_middle::query::plumbing::query_ensure_error_guaranteed::>, ()>
21: rustc_hir_analysis::check::wfcheck::check_mod_type_wf
[... omitted 1 frame ...]
22: rustc_hir_analysis::check_crate
23: rustc_interface::passes::run_required_analyses
24: rustc_interface::passes::analysis
[... omitted 1 frame ...]
25: >::enter::, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}::{closure#3}>
26: rustc_interface::interface::run_compiler::, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
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: please make sure that you have updated to the latest nightly
note: please attach the file at `/Volumes/T7/workspace/240615_100chaos_tree_combine_typ/icefiles/rustc-ice-2024-06-19T06_47_34-44593.txt` to your bug report
query stack during panic:
#0 [typeck] type-checking `main`
#1 [type_of_opaque] computing type of opaque `main::T::{opaque#0}`
#2 [type_of] computing type of `main::T::{opaque#0}`
#3 [check_well_formed] checking that `main::T::{opaque#0}` is well-formed
#4 [check_mod_type_wf] checking that types are well-formed in top-level module
#5 [analysis] running analysis passes on this crate
end of query stack
error[E0391]: cycle detected when computing type of opaque `main::T::{opaque#0}`
--> r_closure331_419FDD4D.rs:8:14
|
8 | type T = impl Static;
| ^^^^^^^^^^^
|
note: ...which requires type-checking `main`...
--> r_closure331_419FDD4D.rs:7:1
|
7 | fn main() {
| ^^^^^^^^^
= note: ...which requires evaluating trait selection obligation `main::T: core::panic::unwind_safe::RefUnwindSafe`...
= note: ...which again requires computing type of opaque `main::T::{opaque#0}`, completing the cycle
note: cycle used when computing type of `main::T::{opaque#0}`
--> r_closure331_419FDD4D.rs:8:14
|
8 | type T = impl Static;
| ^^^^^^^^^^^
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
error: aborting due to 4 previous errors
Some errors have detailed explanations: E0106, E0391, E0658.
For more information about an error, try `rustc --explain E0106`.
```
Note
compiler/rustc_middle/src/ty/closure.rs#L331
https://github.com/rust-lang/rust/blob/8fcd4dd08e2ba3e922d917d819ba0be066bdb005/compiler/rustc_middle/src/ty/closure.rs#L309-L332