Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
use test
  • Loading branch information
cyrgani committed Nov 5, 2025
commit a50d34341cf8fe94f5ef2ff6d0a5d3eabb77f464
8 changes: 5 additions & 3 deletions library/proc_macro/src/bridge/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ fn parse_numeral(mut s: &str) -> Result<Literal> {
}
}
let is_negative = s.starts_with('-');
let non_negative = s.strip_prefix('-').unwrap();
let non_negative = s.trim_prefix('-');
if non_negative.starts_with("0b")
|| non_negative.starts_with("0o")
|| non_negative.starts_with("0x")
Expand All @@ -168,12 +168,12 @@ fn parse_numeral(mut s: &str) -> Result<Literal> {
}
let (s, suffix) = strip_number_suffix(s, FLOAT_SUFFIXES);

Ok(Literal { kind: LitKind::Float, symbol: todo!(), suffix, span: Span })
Ok(Literal { kind: LitKind::Float, symbol: Symbol::new(s), suffix, span: Span })
}

fn parse_integer(mut s: &str) -> Result<Literal> {
let is_negative = s.starts_with('-');
s = s.strip_prefix('-').unwrap();
s = s.trim_prefix('-');

let (s, valid_chars) = if let Some(s) = s.strip_prefix("0b") {
(s, '0'..='1')
Expand Down Expand Up @@ -272,6 +272,8 @@ impl server::TokenStream for NoRustc {
}

fn from_str(&mut self, src: &str) -> Self::TokenStream {
return TokenStream::new();

/// Returns the delimiter, and whether it is the opening form.
fn char_to_delim(c: char) -> Option<(Delimiter, bool)> {
Some(match c {
Expand Down
7 changes: 4 additions & 3 deletions library/proc_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#![feature(restricted_std)]
#![feature(rustc_attrs)]
#![feature(extend_one)]
#![feature(trim_prefix_suffix)]
#![recursion_limit = "256"]
#![allow(internal_features)]
#![deny(ffi_unwind_calls)]
Expand Down Expand Up @@ -101,15 +102,15 @@ enum StandaloneLevel {
/// The standalone implementation is only used outside of procedural macros.
FallbackOnly,
/// The standalone implementation is always used, even in procedural macros.
///
///
/// This does not actually work and should be removed before merging.
Always,
}

/// Enables the new experimental standalone backend, which allows calling the
/// functions in this crate outside of procedural macros.
///
/// When stabilizing this feature, this function will be removed and all programs
///
/// When stabilizing this feature, this function will be removed and all programs
/// will have the fallback activated automatically.
#[unstable(feature = "proc_macro_standalone", issue = "130856")]
pub fn enable_standalone() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ LL | c 'r'
| +

error: unexpected closing delimiter: `)`
--> $DIR/nonfatal-parsing.rs:14:5
--> $DIR/nonfatal-parsing.rs:20:5
|
LL | nonfatal_parsing::run!();
| ^^^^^^^^^^^^^^^^^^^^^^^^ unexpected closing delimiter
|
= note: this error originates in the macro `nonfatal_parsing::run` (in Nightly builds, run with -Z macro-backtrace for more info)

error: unexpected closing delimiter: `]`
--> $DIR/nonfatal-parsing.rs:14:5
--> $DIR/nonfatal-parsing.rs:20:5
|
LL | nonfatal_parsing::run!();
| -^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -43,39 +43,39 @@ LL | nonfatal_parsing::run!();
= note: this error originates in the macro `nonfatal_parsing::run` (in Nightly builds, run with -Z macro-backtrace for more info)

error: found invalid character; only `#` is allowed in raw string delimitation: \u{0}
--> $DIR/nonfatal-parsing.rs:14:5
--> $DIR/nonfatal-parsing.rs:20:5
|
LL | nonfatal_parsing::run!();
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `nonfatal_parsing::run` (in Nightly builds, run with -Z macro-backtrace for more info)

error: invalid digit for a base 2 literal
--> $DIR/nonfatal-parsing.rs:14:5
--> $DIR/nonfatal-parsing.rs:20:5
|
LL | nonfatal_parsing::run!();
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `nonfatal_parsing::run` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0768]: no valid digits found for number
--> $DIR/nonfatal-parsing.rs:14:5
--> $DIR/nonfatal-parsing.rs:20:5
|
LL | nonfatal_parsing::run!();
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `nonfatal_parsing::run` (in Nightly builds, run with -Z macro-backtrace for more info)

error: binary float literal is not supported
--> $DIR/nonfatal-parsing.rs:14:5
--> $DIR/nonfatal-parsing.rs:20:5
|
LL | nonfatal_parsing::run!();
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `nonfatal_parsing::run` (in Nightly builds, run with -Z macro-backtrace for more info)

error: character constant must be escaped: `'`
--> $DIR/nonfatal-parsing.rs:14:5
--> $DIR/nonfatal-parsing.rs:20:5
|
LL | nonfatal_parsing::run!();
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -88,7 +88,7 @@ LL + nonfatal_parsing::run!(\';
|

error: character constant must be escaped: `\n`
--> $DIR/nonfatal-parsing.rs:14:5
--> $DIR/nonfatal-parsing.rs:20:5
|
LL | nonfatal_parsing::run!();
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -101,15 +101,15 @@ LL + nonfatal_parsing::run!(\n;
|

error: too many `#` symbols: raw strings may be delimited by up to 255 `#` symbols, but found 256
--> $DIR/nonfatal-parsing.rs:14:5
--> $DIR/nonfatal-parsing.rs:20:5
|
LL | nonfatal_parsing::run!();
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `nonfatal_parsing::run` (in Nightly builds, run with -Z macro-backtrace for more info)

error: invalid digit for a base 2 literal
--> $DIR/nonfatal-parsing.rs:14:5
--> $DIR/nonfatal-parsing.rs:20:5
|
LL | nonfatal_parsing::run!();
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
Ok(Literal { kind: Integer, symbol: "123", suffix: None, span: #25 bytes(276..300) })
Ok(Literal { kind: Str, symbol: "ab", suffix: None, span: #25 bytes(276..300) })
Ok(Literal { kind: Char, symbol: "b", suffix: None, span: #25 bytes(276..300) })
Ok(Literal { kind: Char, symbol: "b", suffix: None, span: #25 bytes(276..300) })
Ok(Literal { kind: ByteStr, symbol: "b", suffix: None, span: #25 bytes(276..300) })
Ok(Literal { kind: CStr, symbol: "b", suffix: None, span: #25 bytes(276..300) })
Ok(Literal { kind: CStrRaw(0), symbol: "b", suffix: None, span: #25 bytes(276..300) })
Ok(Literal { kind: Byte, symbol: "b", suffix: None, span: #25 bytes(276..300) })
Ok(Literal { kind: Integer, symbol: "256", suffix: Some("u8"), span: #25 bytes(276..300) })
Ok(Literal { kind: Integer, symbol: "-256", suffix: Some("u8"), span: #25 bytes(276..300) })
Ok(TokenStream [Punct { ch: '-', spacing: Alone, span: #25 bytes(276..300) }, Literal { kind: Integer, symbol: "256", suffix: Some("u8"), span: #25 bytes(276..300) }])
Ok(Literal { kind: Integer, symbol: "0b11111000000001111", suffix: Some("i16"), span: #25 bytes(276..300) })
Ok(Literal { kind: Integer, symbol: "0xf32", suffix: None, span: #25 bytes(276..300) })
Ok(Literal { kind: Integer, symbol: "0b0", suffix: Some("f32"), span: #25 bytes(276..300) })
Ok(Literal { kind: Float, symbol: "2E4", suffix: None, span: #25 bytes(276..300) })
Ok(Literal { kind: Float, symbol: "2.2E-4", suffix: Some("f64"), span: #25 bytes(276..300) })
Ok(Literal { kind: Integer, symbol: "18", suffix: Some("u8E"), span: #25 bytes(276..300) })
Ok(Literal { kind: Float, symbol: "18.0", suffix: Some("u8E"), span: #25 bytes(276..300) })
Ok(Literal { kind: CStrRaw(1), symbol: "// /* // \n */", suffix: None, span: #25 bytes(276..300) })
Ok(Literal { kind: Char, symbol: "\'", suffix: None, span: #25 bytes(276..300) })
Ok(Literal { kind: Char, symbol: "\'", suffix: None, span: #25 bytes(276..300) })
Ok(Literal { kind: StrRaw(255), symbol: "a", suffix: None, span: #25 bytes(276..300) })
Ok(TokenStream [Ident { ident: "fn", span: #25 bytes(276..300) }, Ident { ident: "main", span: #25 bytes(276..300) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: #25 bytes(276..300) }, Group { delimiter: Brace, stream: TokenStream [Ident { ident: "println", span: #25 bytes(276..300) }, Punct { ch: '!', spacing: Alone, span: #25 bytes(276..300) }, Group { delimiter: Parenthesis, stream: TokenStream [Literal { kind: Str, symbol: "Hello, world!", suffix: None, span: #25 bytes(276..300) }], span: #25 bytes(276..300) }], span: #25 bytes(276..300) }])
Ok(TokenStream [Literal { kind: Integer, symbol: "18", suffix: None, span: #25 bytes(276..300) }, Punct { ch: '.', spacing: Alone, span: #25 bytes(276..300) }, Ident { ident: "u8E", span: #25 bytes(276..300) }])
Ok(TokenStream [Literal { kind: Float, symbol: "18.0", suffix: Some("f32"), span: #25 bytes(276..300) }])
Ok(TokenStream [Literal { kind: Float, symbol: "18.0", suffix: Some("f34"), span: #25 bytes(276..300) }])
Ok(TokenStream [Literal { kind: Integer, symbol: "18", suffix: None, span: #25 bytes(276..300) }, Punct { ch: '.', spacing: Alone, span: #25 bytes(276..300) }, Ident { ident: "bu8", span: #25 bytes(276..300) }])
Ok(TokenStream [Literal { kind: Integer, symbol: "3", suffix: None, span: #25 bytes(276..300) }, Literal { kind: Integer, symbol: "4", suffix: None, span: #25 bytes(276..300) }])
Ok(TokenStream [Literal { kind: Char, symbol: "c", suffix: None, span: #25 bytes(276..300) }])
Ok(Literal { kind: Integer, symbol: "123", suffix: None, span: #25 bytes(460..484) })
Ok(Literal { kind: Str, symbol: "ab", suffix: None, span: #25 bytes(460..484) })
Ok(Literal { kind: Char, symbol: "b", suffix: None, span: #25 bytes(460..484) })
Ok(Literal { kind: Char, symbol: "b", suffix: None, span: #25 bytes(460..484) })
Ok(Literal { kind: ByteStr, symbol: "b", suffix: None, span: #25 bytes(460..484) })
Ok(Literal { kind: CStr, symbol: "b", suffix: None, span: #25 bytes(460..484) })
Ok(Literal { kind: CStrRaw(0), symbol: "b", suffix: None, span: #25 bytes(460..484) })
Ok(Literal { kind: Byte, symbol: "b", suffix: None, span: #25 bytes(460..484) })
Ok(Literal { kind: Integer, symbol: "256", suffix: Some("u8"), span: #25 bytes(460..484) })
Ok(Literal { kind: Integer, symbol: "-256", suffix: Some("u8"), span: #25 bytes(460..484) })
Ok(TokenStream [Punct { ch: '-', spacing: Alone, span: #25 bytes(460..484) }, Literal { kind: Integer, symbol: "256", suffix: Some("u8"), span: #25 bytes(460..484) }])
Ok(Literal { kind: Integer, symbol: "0b11111000000001111", suffix: Some("i16"), span: #25 bytes(460..484) })
Ok(Literal { kind: Integer, symbol: "0xf32", suffix: None, span: #25 bytes(460..484) })
Ok(Literal { kind: Integer, symbol: "0b0", suffix: Some("f32"), span: #25 bytes(460..484) })
Ok(Literal { kind: Float, symbol: "2E4", suffix: None, span: #25 bytes(460..484) })
Ok(Literal { kind: Float, symbol: "2.2E-4", suffix: Some("f64"), span: #25 bytes(460..484) })
Ok(Literal { kind: Integer, symbol: "18", suffix: Some("u8E"), span: #25 bytes(460..484) })
Ok(Literal { kind: Float, symbol: "18.0", suffix: Some("u8E"), span: #25 bytes(460..484) })
Ok(Literal { kind: CStrRaw(1), symbol: "// /* // \n */", suffix: None, span: #25 bytes(460..484) })
Ok(Literal { kind: Char, symbol: "\'", suffix: None, span: #25 bytes(460..484) })
Ok(Literal { kind: Char, symbol: "\'", suffix: None, span: #25 bytes(460..484) })
Ok(Literal { kind: StrRaw(255), symbol: "a", suffix: None, span: #25 bytes(460..484) })
Ok(TokenStream [Ident { ident: "fn", span: #25 bytes(460..484) }, Ident { ident: "main", span: #25 bytes(460..484) }, Group { delimiter: Parenthesis, stream: TokenStream [], span: #25 bytes(460..484) }, Group { delimiter: Brace, stream: TokenStream [Ident { ident: "println", span: #25 bytes(460..484) }, Punct { ch: '!', spacing: Alone, span: #25 bytes(460..484) }, Group { delimiter: Parenthesis, stream: TokenStream [Literal { kind: Str, symbol: "Hello, world!", suffix: None, span: #25 bytes(460..484) }], span: #25 bytes(460..484) }], span: #25 bytes(460..484) }])
Ok(TokenStream [Literal { kind: Integer, symbol: "18", suffix: None, span: #25 bytes(460..484) }, Punct { ch: '.', spacing: Alone, span: #25 bytes(460..484) }, Ident { ident: "u8E", span: #25 bytes(460..484) }])
Ok(TokenStream [Literal { kind: Float, symbol: "18.0", suffix: Some("f32"), span: #25 bytes(460..484) }])
Ok(TokenStream [Literal { kind: Float, symbol: "18.0", suffix: Some("f34"), span: #25 bytes(460..484) }])
Ok(TokenStream [Literal { kind: Integer, symbol: "18", suffix: None, span: #25 bytes(460..484) }, Punct { ch: '.', spacing: Alone, span: #25 bytes(460..484) }, Ident { ident: "bu8", span: #25 bytes(460..484) }])
Ok(TokenStream [Literal { kind: Integer, symbol: "3", suffix: None, span: #25 bytes(460..484) }, Literal { kind: Integer, symbol: "4", suffix: None, span: #25 bytes(460..484) }])
Ok(TokenStream [Literal { kind: Char, symbol: "c", suffix: None, span: #25 bytes(460..484) }])
Ok(TokenStream [])
### ERRORS
Err(LexError)
Expand All @@ -38,17 +38,17 @@ Err(LexError)
Err(LexError)
Err(LexError)
Err(LexError)
Ok(TokenStream [Ident { ident: "r", span: #25 bytes(276..300) }, Literal { kind: Char, symbol: "r", suffix: None, span: #25 bytes(276..300) }])
Ok(TokenStream [Ident { ident: "c", span: #25 bytes(276..300) }, Literal { kind: Char, symbol: "r", suffix: None, span: #25 bytes(276..300) }])
Ok(TokenStream [Literal { kind: ErrWithGuar, symbol: "0b2", suffix: None, span: #25 bytes(276..300) }])
Ok(TokenStream [Literal { kind: ErrWithGuar, symbol: "0b", suffix: Some("f32"), span: #25 bytes(276..300) }])
Ok(TokenStream [Literal { kind: ErrWithGuar, symbol: "0b0.0", suffix: Some("f32"), span: #25 bytes(276..300) }])
Ok(TokenStream [Literal { kind: ErrWithGuar, symbol: "'''", suffix: None, span: #25 bytes(276..300) }])
Ok(TokenStream [Literal { kind: ErrWithGuar, symbol: "'\n'", suffix: None, span: #25 bytes(276..300) }])
Ok(TokenStream [Literal { kind: ErrWithGuar, symbol: "0b2", suffix: None, span: #25 bytes(276..300) }])
Ok(Literal { kind: ErrWithGuar, symbol: "0b2", suffix: None, span: #25 bytes(276..300) })
Ok(Literal { kind: ErrWithGuar, symbol: "0b", suffix: Some("f32"), span: #25 bytes(276..300) })
Ok(Literal { kind: ErrWithGuar, symbol: "0b0.0", suffix: Some("f32"), span: #25 bytes(276..300) })
Ok(Literal { kind: ErrWithGuar, symbol: "'''", suffix: None, span: #25 bytes(276..300) })
Ok(Literal { kind: ErrWithGuar, symbol: "'\n'", suffix: None, span: #25 bytes(276..300) })
Ok(TokenStream [Ident { ident: "r", span: #25 bytes(460..484) }, Literal { kind: Char, symbol: "r", suffix: None, span: #25 bytes(460..484) }])
Ok(TokenStream [Ident { ident: "c", span: #25 bytes(460..484) }, Literal { kind: Char, symbol: "r", suffix: None, span: #25 bytes(460..484) }])
Ok(TokenStream [Literal { kind: ErrWithGuar, symbol: "0b2", suffix: None, span: #25 bytes(460..484) }])
Ok(TokenStream [Literal { kind: ErrWithGuar, symbol: "0b", suffix: Some("f32"), span: #25 bytes(460..484) }])
Ok(TokenStream [Literal { kind: ErrWithGuar, symbol: "0b0.0", suffix: Some("f32"), span: #25 bytes(460..484) }])
Ok(TokenStream [Literal { kind: ErrWithGuar, symbol: "'''", suffix: None, span: #25 bytes(460..484) }])
Ok(TokenStream [Literal { kind: ErrWithGuar, symbol: "'\n'", suffix: None, span: #25 bytes(460..484) }])
Ok(TokenStream [Literal { kind: ErrWithGuar, symbol: "0b2", suffix: None, span: #25 bytes(460..484) }])
Ok(Literal { kind: ErrWithGuar, symbol: "0b2", suffix: None, span: #25 bytes(460..484) })
Ok(Literal { kind: ErrWithGuar, symbol: "0b", suffix: Some("f32"), span: #25 bytes(460..484) })
Ok(Literal { kind: ErrWithGuar, symbol: "0b0.0", suffix: Some("f32"), span: #25 bytes(460..484) })
Ok(Literal { kind: ErrWithGuar, symbol: "'''", suffix: None, span: #25 bytes(460..484) })
Ok(Literal { kind: ErrWithGuar, symbol: "'\n'", suffix: None, span: #25 bytes(460..484) })
Err(LexError)
15 changes: 12 additions & 3 deletions tests/ui/proc-macro/nonfatal-parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
//@ needs-unwind
//@ edition:2024
//@ dont-require-annotations: ERROR
// FIXME: should be a check-pass test
//@ revisions: in_macro standalone
//@[in_macro] check-fail
//@[standalone] run-pass
//@[standalone] check-run-results
// FIXME: in_macro should be a check-pass test
#![feature(proc_macro_standalone)]

extern crate proc_macro;
extern crate nonfatal_parsing;
Expand All @@ -11,7 +16,11 @@ extern crate nonfatal_parsing;
mod body;

fn main() {
#[cfg(in_macro)]
nonfatal_parsing::run!();
// FIXME: enable this once the standalone backend exists
// body::run();

#[cfg(standalone)]
proc_macro::enable_standalone();
#[cfg(standalone)]
body::run();
}
8 changes: 8 additions & 0 deletions tests/ui/proc-macro/nonfatal-parsing.standalone.run.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
1 ) 2 did not panic
( x [ ) ] did not panic
r# did not panic
r################################################################################################################################################################################################################################################################"a"################################################################################################################################################################################################################################################################ did not panic
1 ) 2 did not panic
( x [ ) ] did not panic
r# did not panic
r################################################################################################################################################################################################################################################################"a"################################################################################################################################################################################################################################################################ did not panic
62 changes: 62 additions & 0 deletions tests/ui/proc-macro/nonfatal-parsing.standalone.run.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
Ok(Literal { kind: Float, symbol: "123", suffix: None, span: Span })
Ok(Literal { kind: Str, symbol: "ab", suffix: None, span: Span })
Err(LexError)
Err(LexError)
Ok(Literal { kind: ByteStr, symbol: "b", suffix: None, span: Span })
Ok(Literal { kind: CStr, symbol: "b", suffix: None, span: Span })
Ok(Literal { kind: CStrRaw(0), symbol: "b", suffix: None, span: Span })
Err(LexError)
Ok(Literal { kind: Integer, symbol: "256", suffix: Some("u8"), span: Span })
Ok(Literal { kind: Integer, symbol: "256", suffix: Some("u8"), span: Span })
Ok(TokenStream [])
Ok(Literal { kind: Integer, symbol: "11111000000001111", suffix: Some("i16"), span: Span })
Err(LexError)
Err(LexError)
Ok(Literal { kind: Float, symbol: "2E4", suffix: None, span: Span })
Ok(Literal { kind: Float, symbol: "2.2E-4", suffix: Some("f64"), span: Span })
Ok(Literal { kind: Float, symbol: "18u8E", suffix: None, span: Span })
Ok(Literal { kind: Float, symbol: "18.0u8E", suffix: None, span: Span })
Ok(Literal { kind: CStrRaw(1), symbol: "// /* // \n */", suffix: None, span: Span })
Err(LexError)
Err(LexError)
Err(LexError)
Ok(TokenStream [])
Ok(TokenStream [])
Ok(TokenStream [])
Ok(TokenStream [])
Ok(TokenStream [])
Ok(TokenStream [])
Ok(TokenStream [])
Ok(TokenStream [])
### ERRORS
Err(LexError)
Err(LexError)
Ok(Literal { kind: Float, symbol: "0 ", suffix: None, span: Span })
Ok(Literal { kind: Float, symbol: "0//", suffix: None, span: Span })
Ok(Literal { kind: Float, symbol: "3//\n4", suffix: None, span: Span })
Ok(Literal { kind: Float, symbol: "18.u8E", suffix: None, span: Span })
Err(LexError)
Err(LexError)
Err(LexError)
Ok(TokenStream [])
Ok(TokenStream [])
Ok(TokenStream [])
Ok(TokenStream [])
Ok(TokenStream [])
Ok(TokenStream [])
Ok(TokenStream [])
Ok(TokenStream [])
Ok(TokenStream [])
Ok(TokenStream [])
Ok(TokenStream [])
Ok(TokenStream [])
Ok(Literal { kind: Float, symbol: "1 ) 2", suffix: None, span: Span })
Err(LexError)
Err(LexError)
Err(LexError)
Err(LexError)
Err(LexError)
Err(LexError)
Err(LexError)
Err(LexError)
Err(LexError)
Loading