Description
I think this broke macro-expansion (reduced snippet from num-traits
):
macro_rules! constant {
($( $method:ident () -> $ret:expr ; )*)
=> {$(
#[inline]
fn $method() -> Self {
$ret
}
)*};
}
trait M {
fn neg_zero() -> Self;
}
impl M for f32 {
constant! {
neg_zero() -> -0.0;
}
}
I am also getting this error with an unrelated project. (I can reproduce this with an empty crate with a single dependency: num-traits
):
Output
version: 0216ca61a 2022-05-05 dev
request: textDocument/semanticTokens/range SemanticTokensRangeParams {
work_done_progress_params: WorkDoneProgressParams {
work_done_token: None,
},
partial_result_params: PartialResultParams {
partial_result_token: None,
},
text_document: TextDocumentIdentifier {
uri: Url {
scheme: "file",
cannot_be_a_base: false,
username: "",
password: None,
host: None,
port: None,
query: None,
fragment: None,
},
},
range: Range {
start: Position {
line: 0,
character: 0,
},
end: Position {
line: 12,
character: 0,
},
},
}
> collect_items MacroCall: constant!{nan()->f32::NAN;infinity()->f32::INFINITY;neg_infinity()->f32::NEG_INFINITY;neg_zero()-> -0.0;min_value()->f32::MIN;min_positive_value()->f32::MIN_POSITIVE;epsilon()->f32::EPSILON;max_value()->f32::MAX;}#[
thread '<unnamed>' panicked at 'Punct {
char: 'f',
spacing: Joint,
id: TokenId(
74,
),
} is not a valid punct', crates/mbe/src/to_parser_input.rs:61:48
stack backtrace:
0: _rust_begin_unwind
1: core::panicking::panic_fmt
2: mbe::to_parser_input::to_parser_input
3: mbe::tt_iter::TtIter::expect_fragment
4: mbe::expander::matcher::match_loop
5: mbe::expander::expand_rules
6: mbe::DeclarativeMacro::expand
7: hir_expand::db::TokenExpander::expand
8: <hir_expand::db::MacroExpandQuery as salsa::plumbing::QueryFunction>::execute
9: salsa::runtime::Runtime::execute_query_implementation
10: salsa::derived::slot::Slot<Q,MP>::read_upgrade
11: salsa::derived::slot::Slot<Q,MP>::read
12: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
13: salsa::QueryTable<Q>::get
14: <DB as hir_expand::db::AstDatabase>::macro_expand
15: salsa::runtime::Runtime::execute_query_implementation
16: salsa::derived::slot::Slot<Q,MP>::read_upgrade
17: salsa::derived::slot::Slot<Q,MP>::read
18: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
19: salsa::QueryTable<Q>::get
20: <DB as hir_expand::db::AstDatabase>::macro_expand_error
21: hir_def::body::Expander::enter_expand_inner
22: hir_def::body::Expander::enter_expand
23: hir_def::data::AssocItemCollector::collect
24: hir_def::data::ImplData::impl_data_query
25: salsa::runtime::Runtime::execute_query_implementation
26: salsa::derived::slot::Slot<Q,MP>::read_upgrade
27: salsa::derived::slot::Slot<Q,MP>::read
28: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
29: <DB as hir_def::db::DefDatabase>::impl_data::__shim
30: hir_ty::lower::impl_trait_query
31: salsa::runtime::Runtime::execute_query_implementation
32: salsa::derived::slot::Slot<Q,MP>::read_upgrade
33: salsa::derived::slot::Slot<Q,MP>::read
34: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
35: salsa::QueryTable<Q>::get
36: <DB as hir_ty::db::HirDatabase>::impl_trait
37: hir_ty::method_resolution::TraitImpls::collect_def_map
38: hir_ty::method_resolution::TraitImpls::trait_impls_in_crate_query
39: salsa::runtime::Runtime::execute_query_implementation
40: salsa::derived::slot::Slot<Q,MP>::read_upgrade
41: salsa::derived::slot::Slot<Q,MP>::read
42: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
43: <DB as hir_ty::db::HirDatabase>::trait_impls_in_crate::__shim
44: hir_ty::method_resolution::TraitImpls::trait_impls_in_deps_query
45: salsa::runtime::Runtime::execute_query_implementation
46: salsa::derived::slot::Slot<Q,MP>::read_upgrade
47: salsa::derived::slot::Slot<Q,MP>::read
48: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
49: <DB as hir_ty::db::HirDatabase>::trait_impls_in_deps::__shim
50: hir_ty::chalk_db::<impl chalk_solve::RustIrDatabase<hir_ty::interner::Interner> for hir_ty::traits::ChalkContext>::impls_for_trait
51: chalk_solve::clauses::program_clauses_that_could_match
52: chalk_recursive::solve::SolveIteration::solve_iteration
53: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
54: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_root_goal
55: hir_ty::traits::trait_solve_query
56: salsa::runtime::Runtime::execute_query_implementation
57: salsa::derived::slot::Slot<Q,MP>::read_upgrade
58: salsa::derived::slot::Slot<Q,MP>::read
59: <salsa::derived::DerivedStorage<Q,MP> as salsa::plumbing::QueryStorageOps<Q>>::try_fetch
60: salsa::QueryTable<Q>::get
61: <DB as hir_ty::db::HirDatabase>::trait_solve_query
62: hir_ty::db::trait_solve_wait
63: <DB as hir_ty::db::HirDatabase>::trait_solve
64: hir_ty::method_resolution::implements_trait_unique
65: hir::Type::impls_fnonce
66: ide::syntax_highlighting::highlight::highlight_def
67: ide::syntax_highlighting::highlight::name_like
68: ide::syntax_highlighting::highlight
69: salsa::Cancelled::catch
70: rust_analyzer::handlers::handle_semantic_tokens_range
71: std::panicking::try
72: <F as threadpool::FnBox>::call_box
Originally posted by @cynecx in #12149 (comment)