-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse
Ty?
as Option<Ty>
and provide structured suggestion
Swift has specific syntax that desugars to `Option<T>` similar to our `?` operator, which means that people might try to use it in Rust. Parse it and gracefully recover.
- Loading branch information
Showing
12 changed files
with
125 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
fn f(t:for<>t?) | ||
//~^ ERROR: expected parameter name | ||
//~| ERROR: expected one of | ||
//~| ERROR: expected one of | ||
//~^ ERROR: expected one of | ||
//~| ERROR: invalid `?` in type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,19 @@ | ||
error: expected parameter name, found `?` | ||
error: invalid `?` in type | ||
--> $DIR/issue-84148-1.rs:1:14 | ||
| | ||
LL | fn f(t:for<>t?) | ||
| ^ expected parameter name | ||
|
||
error: expected one of `(`, `)`, `+`, `,`, `::`, or `<`, found `?` | ||
--> $DIR/issue-84148-1.rs:1:14 | ||
| ^ `?` is only allowed on expressions, not types | ||
| | ||
LL | fn f(t:for<>t?) | ||
| ^ | ||
| | | ||
| expected one of `(`, `)`, `+`, `,`, `::`, or `<` | ||
| help: missing `,` | ||
help: if you meant to express that the type might not contain a value, use the `Option` wrapper type | ||
| | ||
LL | fn f(t:Option<for<>t>) | ||
| +++++++ ~ | ||
|
||
error: expected one of `->`, `where`, or `{`, found `<eof>` | ||
--> $DIR/issue-84148-1.rs:1:15 | ||
| | ||
LL | fn f(t:for<>t?) | ||
| ^ expected one of `->`, `where`, or `{` | ||
|
||
error: aborting due to 3 previous errors | ||
error: aborting due to 2 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
// error-pattern: this file contains an unclosed delimiter | ||
// error-pattern: expected parameter name | ||
// error-pattern: expected one of | ||
// error-pattern: invalid `?` in type | ||
fn f(t:for<>t? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,27 @@ | ||
error: this file contains an unclosed delimiter | ||
--> $DIR/issue-84148-2.rs:4:16 | ||
--> $DIR/issue-84148-2.rs:3:16 | ||
| | ||
LL | fn f(t:for<>t? | ||
| - ^ | ||
| | | ||
| unclosed delimiter | ||
|
||
error: expected parameter name, found `?` | ||
--> $DIR/issue-84148-2.rs:4:14 | ||
error: invalid `?` in type | ||
--> $DIR/issue-84148-2.rs:3:14 | ||
| | ||
LL | fn f(t:for<>t? | ||
| ^ expected parameter name | ||
|
||
error: expected one of `(`, `)`, `+`, `,`, `::`, or `<`, found `?` | ||
--> $DIR/issue-84148-2.rs:4:14 | ||
| ^ `?` is only allowed on expressions, not types | ||
| | ||
LL | fn f(t:for<>t? | ||
| ^ | ||
| | | ||
| expected one of `(`, `)`, `+`, `,`, `::`, or `<` | ||
| help: missing `,` | ||
help: if you meant to express that the type might not contain a value, use the `Option` wrapper type | ||
| | ||
LL | fn f(t:Option<for<>t> | ||
| +++++++ ~ | ||
|
||
error: expected one of `->`, `where`, or `{`, found `<eof>` | ||
--> $DIR/issue-84148-2.rs:4:16 | ||
--> $DIR/issue-84148-2.rs:3:16 | ||
| | ||
LL | fn f(t:for<>t? | ||
| ^ expected one of `->`, `where`, or `{` | ||
|
||
error: aborting due to 4 previous errors | ||
error: aborting due to 3 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// run-rustfix | ||
|
||
fn foo() -> Option<i32> { //~ ERROR invalid `?` in type | ||
let x: Option<i32> = Some(1); //~ ERROR invalid `?` in type | ||
x | ||
} | ||
|
||
fn main() { | ||
let _: Option<i32> = foo(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// run-rustfix | ||
|
||
fn foo() -> i32? { //~ ERROR invalid `?` in type | ||
let x: i32? = Some(1); //~ ERROR invalid `?` in type | ||
x | ||
} | ||
|
||
fn main() { | ||
let _: Option<i32> = foo(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
error: invalid `?` in type | ||
--> $DIR/trailing-question-in-type.rs:3:16 | ||
| | ||
LL | fn foo() -> i32? { | ||
| ^ `?` is only allowed on expressions, not types | ||
| | ||
help: if you meant to express that the type might not contain a value, use the `Option` wrapper type | ||
| | ||
LL | fn foo() -> Option<i32> { | ||
| +++++++ ~ | ||
|
||
error: invalid `?` in type | ||
--> $DIR/trailing-question-in-type.rs:4:15 | ||
| | ||
LL | let x: i32? = Some(1); | ||
| ^ `?` is only allowed on expressions, not types | ||
| | ||
help: if you meant to express that the type might not contain a value, use the `Option` wrapper type | ||
| | ||
LL | let x: Option<i32> = Some(1); | ||
| +++++++ ~ | ||
|
||
error: aborting due to 2 previous errors | ||
|