Rollup merge of #98183 - dtolnay:emptybound, r=lcnr
Fix pretty printing of empty bound lists in where-clause
Repro:
```rust
macro_rules! assert_item_stringify {
($item:item $expected:literal) => {
assert_eq!(stringify!($item), $expected);
};
}
fn main() {
assert_item_stringify! {
fn f<'a, T>() where 'a:, T: {}
"fn f<'a, T>() where 'a:, T: {}"
}
}
```
Previously this assertion would fail because rustc renders the where-clause as `where 'a, T` which is invalid syntax.
This PR makes the above assertion pass.
This bug also affects `-Zunpretty=expanded`. The intention is for that to emit syntactically valid code, but the buggy output is not valid Rust syntax.
```console
$ rustc <(echo "fn f<'a, T>() where 'a:, T: {}") -Zunpretty=expanded
#![feature(prelude_import)]
#![no_std]
#[prelude_import]
use ::std::prelude::rust_2015::*;
#[macro_use]
extern crate std;
fn f<'a, T>() where 'a, T {}
```
```console
$ rustc <(echo "fn f<'a, T>() where 'a:, T: {}") -Zunpretty=expanded | rustc -
error: expected `:`, found `,`
--> <anon>:7:23
|
7 | fn f<'a, T>() where 'a, T {}
| ^ expected `:`
```
This commit is contained in:
@@ -1355,7 +1355,10 @@ impl<'a> Parser<'a> {
|
||||
s.print_mutability(mut_ty.mutbl, false);
|
||||
s.popen();
|
||||
s.print_type(&mut_ty.ty);
|
||||
s.print_type_bounds(" +", &bounds);
|
||||
if !bounds.is_empty() {
|
||||
s.word(" + ");
|
||||
s.print_type_bounds(&bounds);
|
||||
}
|
||||
s.pclose()
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user