Skip to content

ICE : Proc macro : If Ident is invalid, panic occur #94913

Closed
@MolotovCherry

Description

@MolotovCherry

Summary

First off, I'll start by saying, I can see the obviousness of how an empty Ident would cause an ICE. But an ICE is an ICE, so I'm reporting it regardless. While I haven't tested, I can bet that similar errors for empty other stuff might also exist.

Code

Proc macro:
cargo.toml

[package]
name = "ice"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
proc-macro = true

[dependencies]
syn = { version="1.0.86", features=["full"] }
proc-macro2 = "1.0.36"
quote = "1.0.15"

lib.rs

use proc_macro::TokenStream;
use proc_macro2::{Ident, Span};
use quote::{quote, ToTokens};

#[proc_macro_attribute]
pub fn ice(attr: TokenStream, item: TokenStream) -> TokenStream {
    let i = Ident::new("", Span::mixed_site());

    let mut new = proc_macro2::TokenStream::new();

    let tk = quote! {
        0 as jni::sys::#i
    };

    new.extend(tk);

    new.into()
}

bin crate:
cargo.toml

[package]
name = "vanilla"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
ice = { path = "../ice" }

main.rs

use ice::ice; // baby, vanilla ice

#[ice]
fn main() {
    println!("Baby, vanilla ice!");
}

Meta

rustc --version --verbose:

rustc 1.61.0-nightly (532d3cda9 2022-02-23)
binary: rustc
commit-hash: 532d3cda90b8a729cd982548649d32803d265052
commit-date: 2022-02-23
host: x86_64-pc-windows-msvc
release: 1.61.0-nightly
LLVM version: 14.0.0

Also happens on stable 1.59.0

Error output

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.61.0-nightly (532d3cda9 2022-02-23) running on x86_64-pc-windows-msvc

note: compiler flags: --crate-type bin -C embed-bitcode=no -C debuginfo=2 -C incremental

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
error: custom attribute panicked
 --> bin\src\main.rs:3:1
  |
3 | #[ice]
  | ^^^^^^
  |
  = help: message: `""` is not a valid identifier
Backtrace

thread 'rustc' panicked at '`""` is not a valid identifier', compiler\rustc_expand\src\proc_macro_server.rs:337:13
stack backtrace:
   0:     0x7ffd4b956f20 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h577a3eb580948643
   1:     0x7ffd4b9909da - core::fmt::write::he31981f37804287f
   2:     0x7ffd4b948579 - <std::io::IoSliceMut as core::fmt::Debug>::fmt::h40af00733c325a97
   3:     0x7ffd4b95a662 - std::panicking::default_hook::h705903547adb60cc
   4:     0x7ffd4b95a223 - std::panicking::default_hook::h705903547adb60cc
   5:     0x7ffd3e12d4b6 - <rustc_target[5b7874d97d7f3be7]::asm::hexagon::HexagonInlineAsmRegClass>::suggest_class
   6:     0x7ffd4b95af92 - std::panicking::rust_panic_with_hook::h5440f7bb6bcc125d
   7:     0x7ffd4b95acdd - <std::panicking::begin_panic_handler::StrPanicPayload as core::panic::BoxMeUp>::get::h236c37de01a8287a
   8:     0x7ffd4b957857 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h577a3eb580948643
   9:     0x7ffd4b95a959 - rust_begin_unwind
  10:     0x7ffd4b9c3f05 - core::panicking::panic_fmt::h6ec8867c00ee73b1
  11:     0x7ffd4214a410 - <proc_macro[e84c237094494b4c]::bridge::TokenTree<rustc_expand[f826a32ec6499ba7]::proc_macro_server::Group, rustc_expand[f826a32ec6499ba7]::proc_macro_server::Punct, rustc_expand[f826a32ec6499ba7]::proc_macro_server::Ident, rustc_expand[f826a32ec6499ba7]::proc_macro_server::Literal> as rustc_expand[f826a32ec6499ba7]::proc_macro_server::ToInternal<rustc_ast[87540cdc8299dfbd]::tokenstream::TokenStream>>::to_internal
  12:     0x7ffd4207974e - rustc_expand[f826a32ec6499ba7]::config::parse_cfg
  13:     0x7ffd4209de22 - <rustc_expand[f826a32ec6499ba7]::mbe::transcribe::Frame as core[26affad66e614045]::iter::traits::iterator::Iterator>::next
  14:     0x7ffd42056051 - <smallvec[2a1be4374bb6c6c2]::SmallVec<[rustc_expand[f826a32ec6499ba7]::mbe::KleeneToken; 1usize]> as core[26affad66e614045]::convert::From<&rustc_expand[f826a32ec6499ba7]::mbe::macro_check::Stack<rustc_expand[f826a32ec6499ba7]::mbe::KleeneToken>>>::from
  15:     0x7ffdae2ea4bc - proc_macro::bridge::closure::Closure::call
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\/library\proc_macro\src\bridge\closure.rs:27
  16:     0x7ffdae2ea4bc - proc_macro::bridge::client::impl$159::new::closure$0
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\/library\proc_macro\src\bridge\client.rs:244
  17:     0x7ffdae2ea4bc - proc_macro::bridge::client::impl$9::with::closure$0
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\/library\proc_macro\src\bridge\client.rs:335
  18:     0x7ffdae2ea4bc - proc_macro::bridge::client::impl$8::with::closure$0::closure$0
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\/library\proc_macro\src\bridge\client.rs:293
  19:     0x7ffdae2ea4bc - proc_macro::bridge::scoped_cell::ScopedCell::replace
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\/library\proc_macro\src\bridge\scoped_cell.rs:75
  20:     0x7ffdae2ea4bc - proc_macro::bridge::client::impl$8::with::closure$0
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\/library\proc_macro\src\bridge\client.rs:291
  21:     0x7ffdae2ea4bc - std::thread::local::LocalKey::try_with
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\library\std\src\thread\local.rs:413
  22:     0x7ffdae2ea4bc - std::thread::local::LocalKey::with
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\library\std\src\thread\local.rs:389
  23:     0x7ffdae2ea4bc - proc_macro::bridge::client::BridgeState::with
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\/library\proc_macro\src\bridge\client.rs:290
  24:     0x7ffdae2ea4bc - proc_macro::bridge::Bridge::with
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\/library\proc_macro\src\bridge\client.rs:328
  25:     0x7ffdae2ea4bc - proc_macro::bridge::client::Ident::new
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\/library\proc_macro\src\bridge\client.rs:237
  26:     0x7ffdae2cacb0 - enum$<proc_macro2::imp::Ident>::new
                               at C:\Users\<user>\.cargo\registry\src\github.com-1ecc6299db9ec823\proc-macro2-1.0.36\src\wrapper.rs:690
  27:     0x7ffdae2bdd1c - proc_macro2::Ident::new
                               at C:\Users\<user>\.cargo\registry\src\github.com-1ecc6299db9ec823\proc-macro2-1.0.36\src\lib.rs:952
  28:     0x7ffdae2b17e9 - ice::ice
                               at D:\Users\<user>\Desktop\ice\ice\src\lib.rs:7
  29:     0x7ffdae2b315f - core::ops::function::FnOnce::call_once<proc_macro::TokenStream (*)(proc_macro::TokenStream,proc_macro::TokenStream),tuple$<proc_macro::TokenStream,proc_macro::TokenStream> >
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\library\core\src\ops\function.rs:227
  30:     0x7ffdae2b55f9 - proc_macro::bridge::client::impl$11::expand2::run::closure$0<proc_macro::TokenStream (*)(proc_macro::TokenStream,proc_macro::TokenStream)>
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\library\proc_macro\src\bridge\client.rs:425
  31:     0x7ffdae2b526e - proc_macro::bridge::client::run_client::closure$0::closure$0<tuple$<proc_macro::bridge::client::TokenStream,proc_macro::bridge::client::TokenStream>,proc_macro::bridge::client::TokenStream,proc_macro::bridge::client::impl$11::expand2::run::closure_env$0<p
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\library\proc_macro\src\bridge\client.rs:376
  32:     0x7ffdae2b6748 - proc_macro::bridge::scoped_cell::impl$3::set::closure$0<enum$<proc_macro::bridge::client::BridgeStateL>,tuple$<>,proc_macro::bridge::client::run_client::closure$0::closure_env$0<tuple$<proc_macro::bridge::client::TokenStream,proc_macro::bridge::client::To
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\library\proc_macro\src\bridge\scoped_cell.rs:80
  33:     0x7ffdae2b5e7c - proc_macro::bridge::scoped_cell::ScopedCell<enum$<proc_macro::bridge::client::BridgeStateL> >::replace<enum$<proc_macro::bridge::client::BridgeStateL>,tuple$<>,proc_macro::bridge::scoped_cell::impl$3::set::closure_env$0<enum$<proc_macro::bridge::client::B
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\library\proc_macro\src\bridge\scoped_cell.rs:75
  34:     0x7ffdae2b6727 - proc_macro::bridge::scoped_cell::ScopedCell<enum$<proc_macro::bridge::client::BridgeStateL> >::set<enum$<proc_macro::bridge::client::BridgeStateL>,tuple$<>,proc_macro::bridge::client::run_client::closure$0::closure_env$0<tuple$<proc_macro::bridge::client:
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\library\proc_macro\src\bridge\scoped_cell.rs:80
  35:     0x7ffdae2b4cff - proc_macro::bridge::client::impl$9::enter::closure$1<tuple$<>,proc_macro::bridge::client::run_client::closure$0::closure_env$0<tuple$<proc_macro::bridge::client::TokenStream,proc_macro::bridge::client::TokenStream>,proc_macro::bridge::client::TokenStream,
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\library\proc_macro\src\bridge\client.rs:324
  36:     0x7ffdae2b23aa - std::thread::local::LocalKey<proc_macro::bridge::scoped_cell::ScopedCell<enum$<proc_macro::bridge::client::BridgeStateL> > >::try_with<proc_macro::bridge::scoped_cell::ScopedCell<enum$<proc_macro::bridge::client::BridgeStateL> >,proc_macro::bridge::client
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\library\std\src\thread\local.rs:413
  37:     0x7ffdae2b20e3 - std::thread::local::LocalKey<proc_macro::bridge::scoped_cell::ScopedCell<enum$<proc_macro::bridge::client::BridgeStateL> > >::with<proc_macro::bridge::scoped_cell::ScopedCell<enum$<proc_macro::bridge::client::BridgeStateL> >,proc_macro::bridge::client::im
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\library\std\src\thread\local.rs:389
  38:     0x7ffdae2b59f7 - proc_macro::bridge::Bridge::enter<tuple$<>,proc_macro::bridge::client::run_client::closure$0::closure_env$0<tuple$<proc_macro::bridge::client::TokenStream,proc_macro::bridge::client::TokenStream>,proc_macro::bridge::client::TokenStream,proc_macro::bridge:
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\library\proc_macro\src\bridge\client.rs:324
  39:     0x7ffdae2b5182 - proc_macro::bridge::client::run_client::closure$0<tuple$<proc_macro::bridge::client::TokenStream,proc_macro::bridge::client::TokenStream>,proc_macro::bridge::client::TokenStream,proc_macro::bridge::client::impl$11::expand2::run::closure_env$0<proc_macro::
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\library\proc_macro\src\bridge\client.rs:369
  40:     0x7ffdae2b5761 - core::panic::unwind_safe::impl$23::call_once<tuple$<>,proc_macro::bridge::client::run_client::closure_env$0<tuple$<proc_macro::bridge::client::TokenStream,proc_macro::bridge::client::TokenStream>,proc_macro::bridge::client::TokenStream,proc_macro::bridge:
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\library\core\src\panic\unwind_safe.rs:271
  41:     0x7ffdae2b145b - std::panicking::try::do_call<core::panic::unwind_safe::AssertUnwindSafe<proc_macro::bridge::client::run_client::closure_env$0<tuple$<proc_macro::bridge::client::TokenStream,proc_macro::bridge::client::TokenStream>,proc_macro::bridge::client::TokenStream,p
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\library\std\src\panicking.rs:492
  42:     0x7ffdae2b1543 - std::panicking::try::do_catch<core::panic::unwind_safe::AssertUnwindSafe<proc_macro::bridge::client::run_client::closure_env$0<tuple$<proc_macro::bridge::client::TokenStream,proc_macro::bridge::client::TokenStream>,proc_macro::bridge::client::TokenStream,
  43:     0x7ffdae2b139b - std::panicking::try<tuple$<>,core::panic::unwind_safe::AssertUnwindSafe<proc_macro::bridge::client::run_client::closure_env$0<tuple$<proc_macro::bridge::client::TokenStream,proc_macro::bridge::client::TokenStream>,proc_macro::bridge::client::TokenStream,p
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\library\std\src\panicking.rs:456
  44:     0x7ffdae2b1a74 - std::panic::catch_unwind<core::panic::unwind_safe::AssertUnwindSafe<proc_macro::bridge::client::run_client::closure_env$0<tuple$<proc_macro::bridge::client::TokenStream,proc_macro::bridge::client::TokenStream>,proc_macro::bridge::client::TokenStream,proc_
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\library\std\src\panic.rs:137
  45:     0x7ffdae2b5063 - proc_macro::bridge::client::run_client<tuple$<proc_macro::bridge::client::TokenStream,proc_macro::bridge::client::TokenStream>,proc_macro::bridge::client::TokenStream,proc_macro::bridge::client::impl$11::expand2::run::closure_env$0<proc_macro::TokenStream
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\library\proc_macro\src\bridge\client.rs:368
  46:     0x7ffdae2b557c - proc_macro::bridge::client::impl$11::expand2::run<proc_macro::TokenStream (*)(proc_macro::TokenStream,proc_macro::TokenStream)>
                               at /rustc/532d3cda90b8a729cd982548649d32803d265052\library\proc_macro\src\bridge\client.rs:424
  47:     0x7ffd4209ce6d - <rustc_expand[f826a32ec6499ba7]::mbe::transcribe::Frame as core[26affad66e614045]::iter::traits::iterator::Iterator>::next
  48:     0x7ffd4208826d - <rustc_expand[f826a32ec6499ba7]::proc_macro::AttrProcMacro as rustc_expand[f826a32ec6499ba7]::base::AttrProcMacro>::expand
  49:     0x7ffd421136a9 - <rustc_expand[f826a32ec6499ba7]::expand::MacroExpander>::fully_expand_fragment
  50:     0x7ffd42110a95 - <rustc_expand[f826a32ec6499ba7]::expand::MacroExpander>::expand_crate
  51:     0x7ffd3e2f93bf - rustc_interface[a4b4867a7d2d9d25]::callbacks::setup_callbacks
  52:     0x7ffd3e26e81a - <rustc_interface[a4b4867a7d2d9d25]::passes::LintStoreExpandImpl as rustc_expand[f826a32ec6499ba7]::base::LintStoreExpand>::pre_expansion_lint
  53:     0x7ffd3e24e2ef - <rustc_interface[a4b4867a7d2d9d25]::queries::Queries>::expansion
  54:     0x7ffd3e0d0a42 - <rustc_middle[ca79ffb15c061b93]::ty::SymbolName as core[26affad66e614045]::fmt::Display>::fmt  55:     0x7ffd3e0e3335 - <rustc_driver[8b679035a3cd5a8d]::args::Error as core[26affad66e614045]::fmt::Debug>::fmt
  56:     0x7ffd3e0cf36b - <rustc_middle[ca79ffb15c061b93]::ty::SymbolName as core[26affad66e614045]::fmt::Display>::fmt  57:     0x7ffd3e0b0ac5 - <rustc_privacy[20af47e3b1cb2b63]::NamePrivacyVisitor as rustc_hir[fed93e7bf99c031b]::intravisit::Visitor>::visit_mod
  58:     0x7ffd3e0ae8f4 - <rustc_privacy[20af47e3b1cb2b63]::NamePrivacyVisitor as rustc_hir[fed93e7bf99c031b]::intravisit::Visitor>::visit_mod
  59:     0x7ffd3e0a9fa8 - <rustc_privacy[20af47e3b1cb2b63]::NamePrivacyVisitor as rustc_hir[fed93e7bf99c031b]::intravisit::Visitor>::visit_mod
  60:     0x7ffd4b96bf3c - std::sys::windows::thread::Thread::new::h315d6649a5d88f22
  61:     0x7ffdcb1b7034 - BaseThreadInitThunk
  62:     0x7ffdcbbc2651 - RtlUserThreadStart

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions