-
Notifications
You must be signed in to change notification settings - Fork 13k
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
recursive type_alias_impl_trait
unsoundly allows different underlying types
#113314
Comments
type_alias_impl_trait
to unify stream generator types
@rustbot label +F-type_alias_impl_trait +I-unsound +T-compiler |
Only possible with unstable feature @rustbot label -I-prioritize |
it would be good to have an example which does not depend on external crates or macros here. |
slightly minimized #![feature(type_alias_impl_trait)]
#![feature(generators)]
#![feature(stmt_expr_attributes)]
#![feature(proc_macro_hygiene)]
use futures::stream::Stream;
use futures_async_stream::{stream, for_await};
type Op = impl Stream<Item = i32>;
async fn iter() -> Op {
futures::stream::iter(vec![])
}
#[stream(item = i32)]
async fn transform<S>(_: S)
where
S: Stream<Item = i32> + Unpin,
{}
async fn bad() -> Op {
transform(Box::pin(iter().await))
}
#[tokio::main]
async fn main() {
let s = bad().await;
#[for_await]
for i in s {
println!("{:#?}", i);
}
} Cargo.toml
completely minimized: #113278 + incorrectly ignoring recursive definitions, writing a clean MVCE rn |
#![feature(type_alias_impl_trait)]
type Op = impl std::fmt::Display;
fn foo() -> Op { &"hello world" }
fn transform<S>() -> impl std::fmt::Display {
&0usize
}
fn bad() -> Op {
transform::<Op>()
}
fn main() {
let mut x = foo();
println!("{x}");
x = bad();
println!("{x}");
}
rust/compiler/rustc_hir_typeck/src/writeback.rs Lines 555 to 574 in 4dbc7e3
I am not totally sure how this all interacts, would have to look at the code, but it feels like the same root cause as #113278 |
type_alias_impl_trait
to unify stream generator typestype_alias_impl_trait
unsoundly allows different underlying types
edit: minimized
see #113314 (comment) for more details
I tried this code:
I expected to see this happen: Compilation should fail, because different generator types should be generated by calling
transform
, meaningbad
anditer
should not share the same typeOp
.Instead, compilation passes, and
SEGFAULT
occurs during runtime:More context: https://github.com/risingwavelabs/risingwave/pull/10266/files#r1244771828
Meta
rustc --version --verbose
:No Backtrace from running it
The text was updated successfully, but these errors were encountered: