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

Fix pretty printing of empty bound lists in where-clause #98183

Merged
merged 2 commits into from
Jun 20, 2022

Conversation

dtolnay
Copy link
Member

@dtolnay dtolnay commented Jun 17, 2022

Repro:

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.

$ 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 {}
$ 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 `:`

Currently fails.

    ---- [pretty] src/test/pretty/where-clauses.rs stdout ----

    error: pretty-printed source does not match expected source
    expected:
    ------------------------------------------
    // pp-exact

    fn f<'a, 'b, T>(t: T) -> isize where T: 'a, 'a: 'b, T: Eq { 0 }

    // This is legal syntax, sometimes generated by macros. `where T: $($bound+)*`
    fn zero_bounds<'a, T>() where 'a:, T: {}

    fn main() {}

    ------------------------------------------
    actual:
    ------------------------------------------
    // pp-exact

    fn f<'a, 'b, T>(t: T) -> isize where T: 'a, 'a: 'b, T: Eq { 0 }

    // This is legal syntax, sometimes generated by macros. `where T: $($bound+)*`
    fn zero_bounds<'a, T>() where 'a, T {}

    fn main() {}

    ------------------------------------------
    diff:
    ------------------------------------------
    3	fn f<'a, 'b, T>(t: T) -> isize where T: 'a, 'a: 'b, T: Eq { 0 }
    4
    5	// This is legal syntax, sometimes generated by macros. `where T: $($bound+)*`
    -	fn zero_bounds<'a, T>() where 'a:, T: {}
    +	fn zero_bounds<'a, T>() where 'a, T {}
    7
    8	fn main() {}
    9
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 17, 2022
@rust-highfive
Copy link
Collaborator

r? @lcnr

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 17, 2022
@lcnr
Copy link
Contributor

lcnr commented Jun 20, 2022

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jun 20, 2022

📌 Commit fe9635f has been approved by lcnr

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 20, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 20, 2022
Rollup of 5 pull requests

Successful merges:

 - rust-lang#98183 (Fix pretty printing of empty bound lists in where-clause)
 - rust-lang#98268 (Improve `lifetime arguments are not allowed on` error message)
 - rust-lang#98273 (Fix minor documentation typo)
 - rust-lang#98274 (Minor improvements on error for `Self` type in items that don't allow it)
 - rust-lang#98281 (Fix typo in `HashMap::drain` docs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit b6fb582 into rust-lang:master Jun 20, 2022
@rustbot rustbot added this to the 1.63.0 milestone Jun 20, 2022
@dtolnay dtolnay deleted the emptybound branch June 20, 2022 11:09
@dtolnay dtolnay added the A-pretty Area: Pretty printing. label Dec 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-pretty Area: Pretty printing. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants