Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: dtolnay/proc-macro2
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 1.0.50
Choose a base ref
...
head repository: dtolnay/proc-macro2
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 1.0.51
Choose a head ref
  • 7 commits
  • 7 files changed
  • 1 contributor

Commits on Jan 20, 2023

  1. Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    3915aee View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    bce0e5f View commit details

Commits on Feb 4, 2023

  1. Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    3b90e7d View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    f0a3490 View commit details
  3. Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    dffd53c View commit details
  4. Merge pull request #364 from dtolnay/hashes

    Reduce max hash in raw strings to 255
    dtolnay authored Feb 4, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ec804f1 View commit details
  5. Release 1.0.51

    dtolnay committed Feb 4, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    bc369f0 View commit details
Showing with 50 additions and 22 deletions.
  1. +1 −1 .github/workflows/ci.yml
  2. +1 −1 Cargo.toml
  3. +3 −3 src/fallback.rs
  4. +7 −7 src/lib.rs
  5. +4 −0 src/parse.rs
  6. +9 −9 src/wrapper.rs
  7. +25 −1 tests/test.rs
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -93,7 +93,7 @@ jobs:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/install@cargo-fuzz
- run: cargo fuzz build -O
- run: cargo fuzz check

clippy:
name: Clippy
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "proc-macro2"
version = "1.0.50" # remember to update html_root_url
version = "1.0.51" # remember to update html_root_url
authors = ["David Tolnay <dtolnay@gmail.com>", "Alex Crichton <alex@alexcrichton.com>"]
autobenches = false
categories = ["development-tools::procedural-macro-helpers"]
6 changes: 3 additions & 3 deletions src/fallback.rs
Original file line number Diff line number Diff line change
@@ -234,7 +234,7 @@ impl Debug for TokenStream {

#[cfg(use_proc_macro)]
impl From<proc_macro::TokenStream> for TokenStream {
fn from(inner: proc_macro::TokenStream) -> TokenStream {
fn from(inner: proc_macro::TokenStream) -> Self {
inner
.to_string()
.parse()
@@ -244,7 +244,7 @@ impl From<proc_macro::TokenStream> for TokenStream {

#[cfg(use_proc_macro)]
impl From<TokenStream> for proc_macro::TokenStream {
fn from(inner: TokenStream) -> proc_macro::TokenStream {
fn from(inner: TokenStream) -> Self {
inner
.to_string()
.parse()
@@ -253,7 +253,7 @@ impl From<TokenStream> for proc_macro::TokenStream {
}

impl From<TokenTree> for TokenStream {
fn from(tree: TokenTree) -> TokenStream {
fn from(tree: TokenTree) -> Self {
let mut stream = RcVecBuilder::new();
push_token_from_proc_macro(stream.as_mut(), tree);
TokenStream {
14 changes: 7 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -86,7 +86,7 @@
//! a different thread.
// Proc-macro2 types in rustdoc of other crates get linked to here.
#![doc(html_root_url = "https://docs.rs/proc-macro2/1.0.50")]
#![doc(html_root_url = "https://docs.rs/proc-macro2/1.0.51")]
#![cfg_attr(
any(proc_macro_span, super_unstable),
feature(proc_macro_span, proc_macro_span_shrink)
@@ -231,14 +231,14 @@ impl FromStr for TokenStream {

#[cfg(use_proc_macro)]
impl From<proc_macro::TokenStream> for TokenStream {
fn from(inner: proc_macro::TokenStream) -> TokenStream {
fn from(inner: proc_macro::TokenStream) -> Self {
TokenStream::_new(inner.into())
}
}

#[cfg(use_proc_macro)]
impl From<TokenStream> for proc_macro::TokenStream {
fn from(inner: TokenStream) -> proc_macro::TokenStream {
fn from(inner: TokenStream) -> Self {
inner.inner.into()
}
}
@@ -574,25 +574,25 @@ impl TokenTree {
}

impl From<Group> for TokenTree {
fn from(g: Group) -> TokenTree {
fn from(g: Group) -> Self {
TokenTree::Group(g)
}
}

impl From<Ident> for TokenTree {
fn from(g: Ident) -> TokenTree {
fn from(g: Ident) -> Self {
TokenTree::Ident(g)
}
}

impl From<Punct> for TokenTree {
fn from(g: Punct) -> TokenTree {
fn from(g: Punct) -> Self {
TokenTree::Punct(g)
}
}

impl From<Literal> for TokenTree {
fn from(g: Literal) -> TokenTree {
fn from(g: Literal) -> Self {
TokenTree::Literal(g)
}
}
4 changes: 4 additions & 0 deletions src/parse.rs
Original file line number Diff line number Diff line change
@@ -472,6 +472,10 @@ fn raw_string(input: Cursor) -> Result<Cursor, Reject> {
_ => return Err(Reject),
}
}
if n > 255 {
// https://github.com/rust-lang/rust/pull/95251
return Err(Reject);
}
while let Some((i, ch)) = chars.next() {
match ch {
'"' if input.rest[i + 1..].starts_with(&input.rest[..n]) => {
18 changes: 9 additions & 9 deletions src/wrapper.rs
Original file line number Diff line number Diff line change
@@ -131,13 +131,13 @@ impl Display for TokenStream {
}

impl From<proc_macro::TokenStream> for TokenStream {
fn from(inner: proc_macro::TokenStream) -> TokenStream {
fn from(inner: proc_macro::TokenStream) -> Self {
TokenStream::Compiler(DeferredTokenStream::new(inner))
}
}

impl From<TokenStream> for proc_macro::TokenStream {
fn from(inner: TokenStream) -> proc_macro::TokenStream {
fn from(inner: TokenStream) -> Self {
match inner {
TokenStream::Compiler(inner) => inner.into_token_stream(),
TokenStream::Fallback(inner) => inner.to_string().parse().unwrap(),
@@ -146,7 +146,7 @@ impl From<TokenStream> for proc_macro::TokenStream {
}

impl From<fallback::TokenStream> for TokenStream {
fn from(inner: fallback::TokenStream) -> TokenStream {
fn from(inner: fallback::TokenStream) -> Self {
TokenStream::Fallback(inner)
}
}
@@ -170,7 +170,7 @@ fn into_compiler_token(token: TokenTree) -> proc_macro::TokenTree {
}

impl From<TokenTree> for TokenStream {
fn from(token: TokenTree) -> TokenStream {
fn from(token: TokenTree) -> Self {
if inside_proc_macro() {
TokenStream::Compiler(DeferredTokenStream::new(into_compiler_token(token).into()))
} else {
@@ -263,13 +263,13 @@ impl LexError {
}

impl From<proc_macro::LexError> for LexError {
fn from(e: proc_macro::LexError) -> LexError {
fn from(e: proc_macro::LexError) -> Self {
LexError::Compiler(e)
}
}

impl From<fallback::LexError> for LexError {
fn from(e: fallback::LexError) -> LexError {
fn from(e: fallback::LexError) -> Self {
LexError::Fallback(e)
}
}
@@ -539,13 +539,13 @@ impl Span {
}

impl From<proc_macro::Span> for crate::Span {
fn from(proc_span: proc_macro::Span) -> crate::Span {
fn from(proc_span: proc_macro::Span) -> Self {
crate::Span::_new(Span::Compiler(proc_span))
}
}

impl From<fallback::Span> for Span {
fn from(inner: fallback::Span) -> Span {
fn from(inner: fallback::Span) -> Self {
Span::Fallback(inner)
}
}
@@ -929,7 +929,7 @@ impl Literal {
}

impl From<fallback::Literal> for Literal {
fn from(s: fallback::Literal) -> Literal {
fn from(s: fallback::Literal) -> Self {
Literal::Fallback(s)
}
}
26 changes: 25 additions & 1 deletion tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
#![allow(clippy::assertions_on_result_states, clippy::non_ascii_literal)]
#![allow(
clippy::assertions_on_result_states,
clippy::items_after_statements,
clippy::non_ascii_literal
)]

use proc_macro2::{Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree};
use std::iter;
use std::panic;
use std::str::{self, FromStr};

@@ -114,6 +119,25 @@ fn literal_string() {
#[test]
fn literal_raw_string() {
"r\"\r\n\"".parse::<TokenStream>().unwrap();

fn raw_string_literal_with_hashes(n: usize) -> String {
let mut literal = String::new();
literal.push('r');
literal.extend(iter::repeat('#').take(n));
literal.push('"');
literal.push('"');
literal.extend(iter::repeat('#').take(n));
literal
}

raw_string_literal_with_hashes(255)
.parse::<TokenStream>()
.unwrap();

// https://github.com/rust-lang/rust/pull/95251
raw_string_literal_with_hashes(256)
.parse::<TokenStream>()
.unwrap_err();
}

#[test]