Skip to content

Commit

Permalink
Delete no_ident_new_raw config for rustc older than 1.47
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jul 16, 2023
1 parent 56c04ea commit 3f96a77
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 24 deletions.
4 changes: 0 additions & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ fn main() {
println!("cargo:rustc-cfg=span_locations");
}

if version.minor < 47 {
println!("cargo:rustc-cfg=no_ident_new_raw");
}

if version.minor < 54 {
println!("cargo:rustc-cfg=no_literal_from_str");
}
Expand Down
20 changes: 0 additions & 20 deletions src/wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,27 +654,7 @@ impl Ident {

pub fn new_raw(string: &str, span: Span) -> Self {
match span {
#[cfg(not(no_ident_new_raw))]
Span::Compiler(s) => Ident::Compiler(proc_macro::Ident::new_raw(string, s)),
#[cfg(no_ident_new_raw)]
Span::Compiler(s) => {
let _ = proc_macro::Ident::new(string, s);
// At this point the un-r#-prefixed string is known to be a
// valid identifier. Try to produce a valid raw identifier by
// running the `TokenStream` parser, and unwrapping the first
// token as an `Ident`.
let raw_prefixed = format!("r#{}", string);
if let Ok(ts) = raw_prefixed.parse::<proc_macro::TokenStream>() {
let mut iter = ts.into_iter();
if let (Some(proc_macro::TokenTree::Ident(mut id)), None) =
(iter.next(), iter.next())
{
id.set_span(s);
return Ident::Compiler(id);
}
}
panic!("not allowed as a raw identifier: `{}`", raw_prefixed)
}
Span::Fallback(s) => Ident::Fallback(fallback::Ident::new_raw(string, s)),
}
}
Expand Down

0 comments on commit 3f96a77

Please sign in to comment.