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

Restrict PartialOrd comparison to only tokens in the same buffer #1237

merged 2 commits into from Oct 20, 2022


Copy link

@dtolnay dtolnay commented Oct 20, 2022

How does this look @CAD97? I was hesitant about directly exposing a pointer comparison across unrelated allocations.

use syn::buffer::TokenBuffer;
let a = TokenBuffer::new2("...".parse().unwrap());
let b = TokenBuffer::new2("...".parse().unwrap());
println!("{:?}", a.begin().partial_cmp(&b.begin()));

    error: casting `usize` to `isize` may wrap around the value
      --> src/
    56 |                     entries.push(Entry::End(-(group_end_index as isize)));
       |                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^
       = help: for further information visit
       = note: `-D clippy::cast-possible-wrap` implied by `-D clippy::pedantic`

    error: casting `usize` to `isize` may wrap around the value
      --> src/
    82 |         entries.push(Entry::End(-(entries.len() as isize)));
       |                                  ^^^^^^^^^^^^^^^^^^^^^^^^
       = help: for further information visit
Copy link

@CAD97 CAD97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That looks really good to me! It's definitely nice to have the cursors for distinct buffers unordered rather than arbitrary-but-consistent order.

It's nice it also gives a purpose to the End entries rather than them solely existing to make implementation easier.

(And as a tertiary nicety, it doesn't necessarily preclude a rewrite of Cursor that uses slices and less unsafe, as such could still do the offset for comparison, just not access outside the cursor range.)

TLDR: r+

(Apparently, "Can not approve pull request without explicit repository access" — did GH decide to prevent drive-by PR approvals? Or is that an old setting I don't know about? Irrelevant, I guess; though it is nice to be able to give a structured ±1 without merge capabilities, it's definitely abusable.)

@dtolnay dtolnay merged commit 8e81cad into master Oct 20, 2022
@dtolnay dtolnay deleted the partialord branch October 20, 2022 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

2 participants