-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Explicitly stated argument-type of a closure gets overwritten by its type alias #100800
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
Comments
Anything? Not even anyone adding the appropriate tags? I can't do that myself. |
@rustbot label +A-closures +F-type_alias_impl_trait +requires-nightly |
Triage: definitely a bug that should be fixed, but not a blocker for stabilization, as we can backwards compatibly fix it. |
I'm not so sure this is the case. This bug doesn't necessarily lead to a compile error, but actually changes the semantics of the code. #![feature(type_alias_impl_trait)]
trait Foo {
fn foo(&self) {println!("A");}
}
impl<T> Foo for T {}
struct B;
impl B {
fn foo(&self) {println!("B");}
}
type Input = impl Foo;
fn run1<F: FnOnce(Input)>(f: F, i: Input) {f(i)}
fn run2<F: FnOnce(B)>(f: F, i: B) {f(i)}
fn main() {
run1(|x: B| {x.foo()}, B);
run2(|x: B| {x.foo()}, B);
} which prints
instead of
|
OK, that is very wrong obviously. Thanks! |
…ler-errors Prefer explict closure sig types over expected ones fixes rust-lang#100800 Previously we only checked that given closure arguments are equal to expected closure arguments, but now we choose the given closure arguments for the signature that is used when type checking the closure body, and keep the other signature for the type of the closure as seen outside of it.
…ler-errors Prefer explict closure sig types over expected ones fixes rust-lang#100800 Previously we only checked that given closure arguments are equal to expected closure arguments, but now we choose the given closure arguments for the signature that is used when type checking the closure body, and keep the other signature for the type of the closure as seen outside of it.
I tried this code:
The type of the closure's argument is explicitly stated and not inferred. Therefore, the closure-body should be aware of the type of its argument as it was stated (
u32
) and the code should compile correctly.Instead, this code behaves as if the type was inferred to be its type alias (
Input
). This hides theDisplay
implementation ofu32
and results in an error:Another way to look at this is that if
is valid on its own without requiring the inferring of any types, then doing
should not cause any changes in semantics inside the closure-body.
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: