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

Parser does not parse ~fn() #10767

Closed
jvns opened this issue Dec 2, 2013 · 7 comments · Fixed by #13268
Closed

Parser does not parse ~fn() #10767

jvns opened this issue Dec 2, 2013 · 7 comments · Fixed by #13268

Comments

@jvns
Copy link
Contributor

jvns commented Dec 2, 2013

When I run

fn f() {
}; 
let x: ~fn() = ~f;

I get the error message

rust> fn f() {}; let x: ~fn() = ~f;
<anon>:7:18: 7:19 error: obsolete syntax: managed or owned closure
<anon>:7 fn f() {}; let x: ~fn() = ~f;
                           ^
note: managed closures have been removed and owned closures are now written `proc()`
error: aborting due to previous error
task 'rustc' failed at 'explicit failure', /build/buildd/rust-nightly-201312020805~61443dc~precise/src/libsyntax/diagnos
@ben0x539
Copy link
Contributor

ben0x539 commented Dec 2, 2013

So, the parser still thinks ~fn() is a heap closure but it's also the obvious way to write the type of a bare function (pointer) stored in a ~-box. let x: ~(fn()) = ~f; works right now, too. I think the error message / type-to-string logic is right and the parser ought to give. :)

@emberian
Copy link
Member

emberian commented Dec 4, 2013

I don't actually think this is an issue. ~fn() should be valid, though nonsensical, after the obsolete heap function handling is removed.

@pcwalton is this accurate?

@jvns
Copy link
Contributor Author

jvns commented Dec 4, 2013

Restated the issue as a parser bug.

@huonw
Copy link
Member

huonw commented Dec 4, 2013

It's probably worth keeping the obsolete syntax warning around at least until the next release to help anyone tracking the releases and not master to upgrade.

(And also those who try Rust for the first time after the media storm we cook up for each release ;) , who chance upon some old code... Getting a sane error message rather than a mismatched types one is nicer.)

@alexcrichton
Copy link
Member

Closing ~fn() has long been gone.

@alexcrichton
Copy link
Member

Whoops, this isn't related to that, carry on!

@alexcrichton alexcrichton reopened this Feb 10, 2014
@huonw
Copy link
Member

huonw commented Feb 10, 2014

It's been enough time (and we've had a release), so I imagine we can remove the obsolete syntax warning now.

alexcrichton added a commit to alexcrichton/rust that referenced this issue Apr 4, 2014
In summary these are some example transitions this change makes:

    'a ||       => ||: 'a
    proc:Send() => proc():Send

The intended syntax for closures is to put the lifetime bound not at the front
but rather in the list of bounds. Currently there is no official support in the
AST for bounds that are not 'static, so this case is currently specially handled
in the parser to desugar to what the AST is expecting. Additionally, this moves
the bounds on procedures to the correct position, which is after the argument
list.

The current grammar for closures and procedures is:

    procedure := 'proc' [ '<' lifetime-list '>' ] '(' arg-list ')'
                        [ ':' bound-list ] [ '->' type ]
    closure := [ 'unsafe' ] ['<' lifetime-list '>' ] '|' arg-list '|'
                        [ ':' bound-list ] [ '->' type ]
    lifetime-list := lifetime | lifetime ',' lifetime-list
    arg-list := ident ':' type | ident ':' type ',' arg-list
    bound-list := bound | bound '+' bound-list
    bound := path | lifetime

This does not currently handle the << ambiguity in `Option<<'a>||>`, I am
deferring that to a later patch. Additionally, this removes the support for the
obsolete syntaxes of ~fn and &fn.

Closes rust-lang#10553
Closes rust-lang#10767
Closes rust-lang#11209
Closes rust-lang#11210
Closes rust-lang#11211
bors added a commit that referenced this issue Apr 5, 2014
In summary these are some example transitions this change makes:

    'a ||       => ||: 'a
    proc:Send() => proc():Send

The intended syntax for closures is to put the lifetime bound not at the front
but rather in the list of bounds. Currently there is no official support in the
AST for bounds that are not 'static, so this case is currently specially handled
in the parser to desugar to what the AST is expecting. Additionally, this moves
the bounds on procedures to the correct position, which is after the argument
list.

The current grammar for closures and procedures is:

    procedure := 'proc' [ '<' lifetime-list '>' ] '(' arg-list ')'
                        [ ':' bound-list ] [ '->' type ]
    closure := [ 'unsafe' ] ['<' lifetime-list '>' ] '|' arg-list '|'
                        [ ':' bound-list ] [ '->' type ]
    lifetime-list := lifetime | lifetime ',' lifetime-list
    arg-list := ident ':' type | ident ':' type ',' arg-list
    bound-list := bound | bound '+' bound-list
    bound := path | lifetime

This does not currently handle the << ambiguity in `Option<<'a>||>`, I am
deferring that to a later patch. Additionally, this removes the support for the
obsolete syntaxes of ~fn and &fn.

Closes #10553
Closes #10767 
Closes #11209
Closes #11210
Closes #11211
bors added a commit that referenced this issue Apr 6, 2014
In summary these are some example transitions this change makes:

    'a ||       => ||: 'a
    proc:Send() => proc():Send

The intended syntax for closures is to put the lifetime bound not at the front
but rather in the list of bounds. Currently there is no official support in the
AST for bounds that are not 'static, so this case is currently specially handled
in the parser to desugar to what the AST is expecting. Additionally, this moves
the bounds on procedures to the correct position, which is after the argument
list.

The current grammar for closures and procedures is:

    procedure := 'proc' [ '<' lifetime-list '>' ] '(' arg-list ')'
                        [ ':' bound-list ] [ '->' type ]
    closure := [ 'unsafe' ] ['<' lifetime-list '>' ] '|' arg-list '|'
                        [ ':' bound-list ] [ '->' type ]
    lifetime-list := lifetime | lifetime ',' lifetime-list
    arg-list := ident ':' type | ident ':' type ',' arg-list
    bound-list := bound | bound '+' bound-list
    bound := path | lifetime

This does not currently handle the << ambiguity in `Option<<'a>||>`, I am
deferring that to a later patch. Additionally, this removes the support for the
obsolete syntaxes of ~fn and &fn.

Closes #10553
Closes #10767 
Closes #11209
Closes #11210
Closes #11211
flip1995 pushed a commit to flip1995/rust that referenced this issue May 20, 2023
[arithmetic_side_effects] Consider referenced allowed or hard-coded types

Fix rust-lang#10767

```
changelog: [`arithmetic_side_effects`]: Do not fire when dealing with allowed or hard-coded types that are referenced.
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants