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

Closures can't be declared as diverging functions #1516

Closed
brson opened this issue Jan 14, 2012 · 3 comments
Closed

Closures can't be declared as diverging functions #1516

brson opened this issue Jan 14, 2012 · 3 comments
Labels
A-typesystem Area: The type system

Comments

@brson
Copy link
Contributor

brson commented Jan 14, 2012

This looks inferrable.

fn main() {                                                                                                                                                                   
    let early_error: fn@(str) -> !  = {|msg|                                                                                                                                  
        fail                                                                                                                                                                  
    };                                                                                                                                                                        
}
../src/test/run-pass/infer-closure.rs:2:38: 4:5 warning: unable to infer kind of closure, defaulting to block
../src/test/run-pass/infer-closure.rs:2     let early_error: fn@(str) -> !  = {|msg|
../src/test/run-pass/infer-closure.rs:3         fail
../src/test/run-pass/infer-closure.rs:4     };
../src/test/run-pass/infer-closure.rs:2:38: 4:5 error: mismatched types: expected `fn@(++str) -> !` but found `fn&(<T2>) -> <T3>` (types differ)
../src/test/run-pass/infer-closure.rs:2     let early_error: fn@(str) -> !  = {|msg|
../src/test/run-pass/infer-closure.rs:3         fail
../src/test/run-pass/infer-closure.rs:4     };
../src/test/run-pass/infer-closure.rs:2:38: 4:5 error: cannot determine a type for this expression
../src/test/run-pass/infer-closure.rs:2     let early_error: fn@(str) -> !  = {|msg|
../src/test/run-pass/infer-closure.rs:3         fail
../src/test/run-pass/infer-closure.rs:4     };
error: aborting due to previous errors
@catamorphism
Copy link
Contributor

In HEAD, I get a different error, but it's still wrong:

./src/test/run-pass/issue-1516.rs:1:47: 1:60 error: mismatched types: expected `fn@(str) -> !` but found `fn@(_|_) -> _|_` (return-by-value function found where non-returning function was expected)
./src/test/run-pass/issue-1516.rs:1 fn main() {  let early_error: fn@(str) -> !  = {|msg| fail }; }

This should compile.

@ghost ghost assigned catamorphism Apr 12, 2012
@catamorphism
Copy link
Contributor

Changed the title to reflect what seems to be the problem now.

@catamorphism
Copy link
Contributor

I disagree with my past self about whether this should compile. Right now, in the AST, there's only one way to introduce a diverging function: by writing a ! in place of its return type. Return styles are never inferred. Making closure potentially-diverging would require significant changes. It's possible, but it would add more outside-of-the-type-system baggage, if you know what I mean.

I'm going to close this, but @brson or anyone else, please file an RFC if you feel strongly about it :-)

flip1995 pushed a commit to flip1995/rust that referenced this issue Jan 13, 2022
Downgrade mutex_atomic to nursery

See rust-lang#1516 and rust-lang#4295.

There are suggestions about removing this lint from the default warned lints in both issues.
Also, [`mutex_integer`](https://rust-lang.github.io/rust-clippy/master/index.html#mutex_integer) lint that has the same problems as this lint is in `nursery` group.

changelog: Moved [`mutex_atomic`] to `nursery`
bjorn3 pushed a commit to bjorn3/rust that referenced this issue Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-typesystem Area: The type system
Projects
None yet
Development

No branches or pull requests

2 participants