Prevent where < ident > from parsing.
In order to be forward compatible with `where<'a>` syntax for higher
rank parameters, prevent potential conflicts with UFCS from parsing
correctly for the near term.
In order to be forward compatible with `where<'a>` syntax for higher
rank parameters, prevent potential conflicts with UFCS from parsing
correctly for the near term.
Implement the `loop_break_value` feature.
This implements RFC 1624, tracking issue #37339.
- `FnCtxt` (in typeck) gets a stack of `LoopCtxt`s, which store the
currently deduced type of that loop, the desired type, and a list of
break expressions currently seen. `loop` loops get a fresh type
variable as their initial type (this logic is stolen from that for
arrays). `while` loops get `()`.
- `break {expr}` looks up the broken loop, and unifies the type of
`expr` with the type of the loop.
- `break` with no expr unifies the loop's type with `()`.
- When building MIR, loops no longer construct a `()` value at
termination of the loop; rather, the `break` expression assigns the
result of the loop.
- ~~I have also changed the loop scoping in MIR-building so that the test
of a while loop is not considered to be part of that loop. This makes
the rules consistent with #37360. The new loop scopes in typeck also
follow this rule. That means that `loop { while (break) {} }` now
terminates instead of looping forever. This is technically a breaking
change.~~
- ~~On that note, expressions like `while break {}` and `if break {}` no
longer parse because `{}` is interpreted as an expression argument to
`break`. But no code except compiler test cases should do that anyway
because it makes no sense.~~
- The RFC did not make it clear, but I chose to make `break ()` inside
of a `while` loop illegal, just in case we wanted to do anything with
that design space in the future.
This is my first time dealing with this part of rustc so I'm sure
there's plenty of problems to pick on here ^_^
This implements RFC 1624, tracking issue #37339.
- `FnCtxt` (in typeck) gets a stack of `LoopCtxt`s, which store the
currently deduced type of that loop, the desired type, and a list of
break expressions currently seen. `loop` loops get a fresh type
variable as their initial type (this logic is stolen from that for
arrays). `while` loops get `()`.
- `break {expr}` looks up the broken loop, and unifies the type of
`expr` with the type of the loop.
- `break` with no expr unifies the loop's type with `()`.
- When building MIR, `loop` loops no longer construct a `()` value at
termination of the loop; rather, the `break` expression assigns the
result of the loop. `while` loops are unchanged.
- `break` respects contexts in which expressions may not end with braced
blocks. That is, `while break { break-value } { while-body }` is
illegal; this preserves backwards compatibility.
- The RFC did not make it clear, but I chose to make `break ()` inside
of a `while` loop illegal, just in case we wanted to do anything with
that design space in the future.
This is my first time dealing with this part of rustc so I'm sure
there's plenty of problems to pick on here ^_^
Fix syntax error in the compiler
Currently `rustc` accepts the following code: `fn f<'a>() where 'a {}`. This should be a syntax error, shouldn't it?
Not sure if my changes actually compile, waiting for the LLVM to build.
Most of the Rust community agrees that the vec! macro is clearer when
called using square brackets [] instead of regular brackets (). Most of
these ocurrences are from before macros allowed using different types of
brackets.
There is one left unchanged in a pretty-print test, as the pretty
printer still wants it to have regular brackets.
Fix bad error message with `::<` in types
Fix#36116.
Before:
```rust
error: expected identifier, found `<`
--> src/test/compile-fail/issue-36116.rs:16:52
|
16 | let f = Some(Foo { _a: 42 }).map(|a| a as Foo::<i32>);
| ^
error: chained comparison operators require parentheses
--> src/test/compile-fail/issue-36116.rs:16:52
|
16 | let f = Some(Foo { _a: 42 }).map(|a| a as Foo::<i32>);
| ^^^^^^
|
= help: use `::<...>` instead of `<...>` if you meant to specify type arguments
error: expected expression, found `)`
--> src/test/compile-fail/issue-36116.rs:16:57
|
16 | let f = Some(Foo { _a: 42 }).map(|a| a as Foo::<i32>);
| ^
error: expected identifier, found `<`
--> src/test/compile-fail/issue-36116.rs:20:17
|
20 | let g: Foo::<i32> = Foo { _a: 42 };
| ^
error: aborting due to 5 previous errors
```
After:
```rust
error: unexpected token: `::`
--> src/test/compile-fail/issue-36116.rs:16:50
|
16 | let f = Some(Foo { _a: 42 }).map(|a| a as Foo::<i32>);
| ^^
|
= help: use `<...>` instead of `::<...>` if you meant to specify type arguments
error: unexpected token: `::`
--> src/test/compile-fail/issue-36116.rs:20:15
|
20 | let g: Foo::<i32> = Foo { _a: 42 };
| ^^
|
= help: use `<...>` instead of `::<...>` if you meant to specify type arguments
error: aborting due to 2 previous errors
```
Recover out of an enum or struct's braced block.
If we encounter a syntax error inside of a braced block, then we should
fail by consuming the rest of the block if possible.
This implements such recovery for enums and structs.
Fixes#37113.
If we encounter a syntax error inside of a braced block, then we should
fail by consuming the rest of the block if possible.
This implements such recovery for enums and structs.
Fixes#37113.