Brace-ident-colon can certainly no longer start a block
thanks to the removal of type ascription.
This commit is contained in:
parent
848b0da34f
commit
82796dd858
7 changed files with 88 additions and 61 deletions
|
@ -3474,19 +3474,9 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_certainly_not_a_block(&self) -> bool {
|
fn is_certainly_not_a_block(&self) -> bool {
|
||||||
|
// `{ ident, ` and `{ ident: ` cannot start a block.
|
||||||
self.look_ahead(1, |t| t.is_ident())
|
self.look_ahead(1, |t| t.is_ident())
|
||||||
&& (
|
&& self.look_ahead(2, |t| t == &token::Comma || t == &token::Colon)
|
||||||
// `{ ident, ` cannot start a block.
|
|
||||||
self.look_ahead(2, |t| t == &token::Comma)
|
|
||||||
|| self.look_ahead(2, |t| t == &token::Colon)
|
|
||||||
&& (
|
|
||||||
// `{ ident: token, ` cannot start a block.
|
|
||||||
self.look_ahead(4, |t| t == &token::Comma)
|
|
||||||
// `{ ident: ` cannot start a block unless it's a type ascription
|
|
||||||
// `ident: Type`.
|
|
||||||
|| self.look_ahead(3, |t| !t.can_begin_type())
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn maybe_parse_struct_expr(
|
fn maybe_parse_struct_expr(
|
||||||
|
|
|
@ -9,23 +9,25 @@ mod module {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test(x: module::Type) {
|
fn test(x: module::Type) {
|
||||||
if x == module::Type { x: module::C, y: 1 } { //~ ERROR invalid struct literal
|
if x == module::Type { x: module::C, y: 1 } { //~ ERROR struct literals are not allowed here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test2(x: module::Type) {
|
fn test2(x: module::Type) {
|
||||||
if x ==module::Type { x: module::C, y: 1 } { //~ ERROR invalid struct literal
|
if x ==module::Type { x: module::C, y: 1 } { //~ ERROR struct literals are not allowed here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn test3(x: module::Type) {
|
fn test3(x: module::Type) {
|
||||||
if x == Type { x: module::C, y: 1 } { //~ ERROR invalid struct literal
|
use module::Type;
|
||||||
|
if x == Type { x: module::C, y: 1 } { //~ ERROR struct literals are not allowed here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test4(x: module::Type) {
|
fn test4(x: module::Type) {
|
||||||
if x == demo_module::Type { x: module::C, y: 1 } { //~ ERROR invalid struct literal
|
use module as demo_module;
|
||||||
|
if x == demo_module::Type { x: module::C, y: 1 } { //~ ERROR struct literals are not allowed here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,43 +1,43 @@
|
||||||
error: invalid struct literal
|
error: struct literals are not allowed here
|
||||||
--> $DIR/issue-111692.rs:12:21
|
--> $DIR/issue-111692.rs:12:13
|
||||||
|
|
|
|
||||||
LL | if x == module::Type { x: module::C, y: 1 } {
|
LL | if x == module::Type { x: module::C, y: 1 } {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
help: you might need to surround the struct literal with parentheses
|
help: surround the struct literal with parentheses
|
||||||
|
|
|
|
||||||
LL | if x == (module::Type { x: module::C, y: 1 }) {
|
LL | if x == (module::Type { x: module::C, y: 1 }) {
|
||||||
| + +
|
| + +
|
||||||
|
|
||||||
error: invalid struct literal
|
error: struct literals are not allowed here
|
||||||
--> $DIR/issue-111692.rs:17:20
|
--> $DIR/issue-111692.rs:17:12
|
||||||
|
|
|
|
||||||
LL | if x ==module::Type { x: module::C, y: 1 } {
|
LL | if x ==module::Type { x: module::C, y: 1 } {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
help: you might need to surround the struct literal with parentheses
|
help: surround the struct literal with parentheses
|
||||||
|
|
|
|
||||||
LL | if x ==(module::Type { x: module::C, y: 1 }) {
|
LL | if x ==(module::Type { x: module::C, y: 1 }) {
|
||||||
| + +
|
| + +
|
||||||
|
|
||||||
error: invalid struct literal
|
error: struct literals are not allowed here
|
||||||
--> $DIR/issue-111692.rs:23:13
|
--> $DIR/issue-111692.rs:24:13
|
||||||
|
|
|
|
||||||
LL | if x == Type { x: module::C, y: 1 } {
|
LL | if x == Type { x: module::C, y: 1 } {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
help: you might need to surround the struct literal with parentheses
|
help: surround the struct literal with parentheses
|
||||||
|
|
|
|
||||||
LL | if x == (Type { x: module::C, y: 1 }) {
|
LL | if x == (Type { x: module::C, y: 1 }) {
|
||||||
| + +
|
| + +
|
||||||
|
|
||||||
error: invalid struct literal
|
error: struct literals are not allowed here
|
||||||
--> $DIR/issue-111692.rs:28:26
|
--> $DIR/issue-111692.rs:30:13
|
||||||
|
|
|
|
||||||
LL | if x == demo_module::Type { x: module::C, y: 1 } {
|
LL | if x == demo_module::Type { x: module::C, y: 1 } {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
help: you might need to surround the struct literal with parentheses
|
help: surround the struct literal with parentheses
|
||||||
|
|
|
|
||||||
LL | if x == (demo_module::Type { x: module::C, y: 1 }) {
|
LL | if x == (demo_module::Type { x: module::C, y: 1 }) {
|
||||||
| + +
|
| + +
|
||||||
|
|
|
@ -7,7 +7,7 @@ impl Example {
|
||||||
fn one() -> i32 { 1 }
|
fn one() -> i32 { 1 }
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
if Example { a: one(), }.is_pos() { //~ ERROR invalid struct literal
|
if Example { a: one(), }.is_pos() { //~ ERROR struct literals are not allowed here
|
||||||
println!("Positive!");
|
println!("Positive!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
error: invalid struct literal
|
error: struct literals are not allowed here
|
||||||
--> $DIR/method-call-on-struct-literal-in-if-condition.rs:10:8
|
--> $DIR/method-call-on-struct-literal-in-if-condition.rs:10:8
|
||||||
|
|
|
|
||||||
LL | if Example { a: one(), }.is_pos() {
|
LL | if Example { a: one(), }.is_pos() {
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
|
|
||||||
help: you might need to surround the struct literal with parentheses
|
help: surround the struct literal with parentheses
|
||||||
|
|
|
|
||||||
LL | if (Example { a: one(), }).is_pos() {
|
LL | if (Example { a: one(), }).is_pos() {
|
||||||
| + +
|
| + +
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
fn foo(x: bool) -> i32 {
|
fn foo(x: bool) -> i32 {
|
||||||
match x {
|
match x { //~ ERROR struct literals are not allowed here
|
||||||
x: i32 => x, //~ ERROR expected
|
x: i32 => x, //~ ERROR expected
|
||||||
//~^ ERROR mismatched types
|
true => 42., //~ ERROR expected identifier
|
||||||
true => 42.,
|
false => 0.333, //~ ERROR expected identifier
|
||||||
false => 0.333,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
} //~ ERROR expected one of
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
match foo(true) {
|
match foo(true) {
|
||||||
|
|
|
@ -1,18 +1,64 @@
|
||||||
error: expected one of `@` or `|`, found `:`
|
error: expected one of `!`, `,`, `.`, `::`, `?`, `{`, `}`, or an operator, found `=>`
|
||||||
--> $DIR/type-ascription-in-pattern.rs:3:10
|
--> $DIR/type-ascription-in-pattern.rs:3:16
|
||||||
|
|
|
|
||||||
|
LL | match x {
|
||||||
|
| - while parsing this struct
|
||||||
LL | x: i32 => x,
|
LL | x: i32 => x,
|
||||||
| ^ --- specifying the type of a pattern isn't supported
|
| -^^ expected one of 8 possible tokens
|
||||||
| |
|
| |
|
||||||
| expected one of `@` or `|`
|
| help: try adding a comma: `,`
|
||||||
|
|
||||||
|
error: expected identifier, found keyword `true`
|
||||||
|
--> $DIR/type-ascription-in-pattern.rs:4:9
|
||||||
|
|
|
|
||||||
help: maybe write a path separator here
|
LL | match x {
|
||||||
|
| - while parsing this struct
|
||||||
|
LL | x: i32 => x,
|
||||||
|
LL | true => 42.,
|
||||||
|
| ^^^^ expected identifier, found keyword
|
||||||
|
|
||||||
|
error: expected identifier, found keyword `false`
|
||||||
|
--> $DIR/type-ascription-in-pattern.rs:5:9
|
||||||
|
|
|
|
||||||
LL | x::i32 => x,
|
LL | match x {
|
||||||
| ~~
|
| - while parsing this struct
|
||||||
|
...
|
||||||
|
LL | false => 0.333,
|
||||||
|
| ^^^^^ expected identifier, found keyword
|
||||||
|
|
||||||
|
error: struct literals are not allowed here
|
||||||
|
--> $DIR/type-ascription-in-pattern.rs:2:11
|
||||||
|
|
|
||||||
|
LL | match x {
|
||||||
|
| ___________^
|
||||||
|
LL | | x: i32 => x,
|
||||||
|
LL | | true => 42.,
|
||||||
|
LL | | false => 0.333,
|
||||||
|
LL | | }
|
||||||
|
| |_____^
|
||||||
|
|
|
||||||
|
help: surround the struct literal with parentheses
|
||||||
|
|
|
||||||
|
LL ~ match (x {
|
||||||
|
LL | x: i32 => x,
|
||||||
|
LL | true => 42.,
|
||||||
|
LL | false => 0.333,
|
||||||
|
LL ~ })
|
||||||
|
|
|
||||||
|
|
||||||
|
error: expected one of `.`, `?`, `{`, or an operator, found `}`
|
||||||
|
--> $DIR/type-ascription-in-pattern.rs:7:1
|
||||||
|
|
|
||||||
|
LL | match x {
|
||||||
|
| ----- while parsing this `match` expression
|
||||||
|
...
|
||||||
|
LL | }
|
||||||
|
| - expected one of `.`, `?`, `{`, or an operator
|
||||||
|
LL | }
|
||||||
|
| ^ unexpected token
|
||||||
|
|
||||||
error: expected one of `...`, `..=`, `..`, or `|`, found `:`
|
error: expected one of `...`, `..=`, `..`, or `|`, found `:`
|
||||||
--> $DIR/type-ascription-in-pattern.rs:12:11
|
--> $DIR/type-ascription-in-pattern.rs:11:11
|
||||||
|
|
|
|
||||||
LL | 42: i32 => (),
|
LL | 42: i32 => (),
|
||||||
| ^ --- specifying the type of a pattern isn't supported
|
| ^ --- specifying the type of a pattern isn't supported
|
||||||
|
@ -20,7 +66,7 @@ LL | 42: i32 => (),
|
||||||
| expected one of `...`, `..=`, `..`, or `|`
|
| expected one of `...`, `..=`, `..`, or `|`
|
||||||
|
|
||||||
error: expected `|`, found `:`
|
error: expected `|`, found `:`
|
||||||
--> $DIR/type-ascription-in-pattern.rs:13:10
|
--> $DIR/type-ascription-in-pattern.rs:12:10
|
||||||
|
|
|
|
||||||
LL | _: f64 => (),
|
LL | _: f64 => (),
|
||||||
| ^ --- specifying the type of a pattern isn't supported
|
| ^ --- specifying the type of a pattern isn't supported
|
||||||
|
@ -28,7 +74,7 @@ LL | _: f64 => (),
|
||||||
| expected `|`
|
| expected `|`
|
||||||
|
|
||||||
error: expected one of `@` or `|`, found `:`
|
error: expected one of `@` or `|`, found `:`
|
||||||
--> $DIR/type-ascription-in-pattern.rs:14:10
|
--> $DIR/type-ascription-in-pattern.rs:13:10
|
||||||
|
|
|
|
||||||
LL | x: i32 => (),
|
LL | x: i32 => (),
|
||||||
| ^ --- specifying the type of a pattern isn't supported
|
| ^ --- specifying the type of a pattern isn't supported
|
||||||
|
@ -40,15 +86,5 @@ help: maybe write a path separator here
|
||||||
LL | x::i32 => (),
|
LL | x::i32 => (),
|
||||||
| ~~
|
| ~~
|
||||||
|
|
||||||
error[E0308]: mismatched types
|
error: aborting due to 8 previous errors
|
||||||
--> $DIR/type-ascription-in-pattern.rs:3:19
|
|
||||||
|
|
|
||||||
LL | fn foo(x: bool) -> i32 {
|
|
||||||
| --- expected `i32` because of return type
|
|
||||||
LL | match x {
|
|
||||||
LL | x: i32 => x,
|
|
||||||
| ^ expected `i32`, found `bool`
|
|
||||||
|
|
||||||
error: aborting due to 5 previous errors
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0308`.
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue