aboutsummaryrefslogtreecommitdiff
path: root/crates/base_db/src/input.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-12-27 14:39:05 +0000
committerGitHub <[email protected]>2020-12-27 14:39:05 +0000
commit8f2622199e86ea0d4c8accf72c364ac8eddbf545 (patch)
tree60202937d17883cd862b1c788e6bde495a16dd2a /crates/base_db/src/input.rs
parent0fd75c98ac81c9f6581712ec8802940e547315e3 (diff)
parent70877428a8d9f17834dee72f03ef80ce5c206e68 (diff)
Merge #6820
6820: Pass the crate environment to proc macros r=jonas-schievink a=jonas-schievink In theory, fixes https://github.com/rust-analyzer/rust-analyzer/issues/6696. This seems to result in these obscure crashes for some reason: ``` thread '<unnamed>' panicked at 'called `Option::unwrap()` on a `None` value', /home/jonas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro/src/bridge/scoped_cell.rs:75:51 stack backtrace: 0: rust_begin_unwind at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/panicking.rs:483 1: core::panicking::panic_fmt at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/panicking.rs:85 2: core::panicking::panic at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/panicking.rs:50 3: core::option::Option<T>::unwrap at /home/jonas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:383 4: proc_macro::bridge::scoped_cell::ScopedCell<T>::replace at /home/jonas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro/src/bridge/scoped_cell.rs:75 5: proc_macro::bridge::client::BridgeState::with::{{closure}} at /home/jonas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro/src/bridge/client.rs:291 6: std::thread::local::LocalKey<T>::try_with at /home/jonas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/local.rs:272 7: std::thread::local::LocalKey<T>::with at /home/jonas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/local.rs:248 8: proc_macro::bridge::client::BridgeState::with at /home/jonas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro/src/bridge/client.rs:290 9: proc_macro::bridge::client::<impl proc_macro::bridge::Bridge>::with at /home/jonas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro/src/bridge/client.rs:329 10: proc_macro::bridge::client::run_client::{{closure}}::{{closure}} at /home/jonas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro/src/bridge/client.rs:375 11: proc_macro::bridge::scoped_cell::ScopedCell<T>::set::{{closure}} at /home/jonas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro/src/bridge/scoped_cell.rs:80 12: proc_macro::bridge::scoped_cell::ScopedCell<T>::replace at /home/jonas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro/src/bridge/scoped_cell.rs:75 13: proc_macro::bridge::scoped_cell::ScopedCell<T>::set at /home/jonas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro/src/bridge/scoped_cell.rs:80 14: proc_macro::bridge::client::<impl proc_macro::bridge::Bridge>::enter::{{closure}} at /home/jonas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro/src/bridge/client.rs:325 15: std::thread::local::LocalKey<T>::try_with at /home/jonas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/local.rs:272 16: std::thread::local::LocalKey<T>::with at /home/jonas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/local.rs:248 17: proc_macro::bridge::client::<impl proc_macro::bridge::Bridge>::enter at /home/jonas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro/src/bridge/client.rs:325 18: proc_macro::bridge::client::run_client::{{closure}} at /home/jonas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro/src/bridge/client.rs:370 19: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once at /home/jonas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:308 20: std::panicking::try::do_call at /home/jonas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:381 21: __rust_try 22: std::panicking::try at /home/jonas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:345 23: std::panic::catch_unwind at /home/jonas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panic.rs:382 24: proc_macro::bridge::client::run_client at /home/jonas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro/src/bridge/client.rs:369 25: proc_macro::bridge::client::Client<fn(proc_macro::TokenStream) .> proc_macro::TokenStream>::expand1::run at /home/jonas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/proc_macro/src/bridge/client.rs:410 26: proc_macro_srv::proc_macro::bridge::server::run_server 27: proc_macro_srv::dylib::Expander::expand 28: proc_macro_srv::ProcMacroSrv::expand 29: proc_macro_srv::cli::run 30: rust_analyzer::main ``` Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates/base_db/src/input.rs')
-rw-r--r--crates/base_db/src/input.rs19
1 files changed, 16 insertions, 3 deletions
diff --git a/crates/base_db/src/input.rs b/crates/base_db/src/input.rs
index cda5e57dc..9567bcc42 100644
--- a/crates/base_db/src/input.rs
+++ b/crates/base_db/src/input.rs
@@ -6,12 +6,12 @@
6//! actual IO. See `vfs` and `project_model` in the `rust-analyzer` crate for how 6//! actual IO. See `vfs` and `project_model` in the `rust-analyzer` crate for how
7//! actual IO is done and lowered to input. 7//! actual IO is done and lowered to input.
8 8
9use std::{fmt, iter::FromIterator, ops, str::FromStr, sync::Arc}; 9use std::{fmt, iter::FromIterator, ops, panic::RefUnwindSafe, str::FromStr, sync::Arc};
10 10
11use cfg::CfgOptions; 11use cfg::CfgOptions;
12use rustc_hash::{FxHashMap, FxHashSet}; 12use rustc_hash::{FxHashMap, FxHashSet};
13use syntax::SmolStr; 13use syntax::SmolStr;
14use tt::TokenExpander; 14use tt::{ExpansionError, Subtree};
15use vfs::{file_set::FileSet, FileId, VfsPath}; 15use vfs::{file_set::FileSet, FileId, VfsPath};
16 16
17/// Files are grouped into source roots. A source root is a directory on the 17/// Files are grouped into source roots. A source root is a directory on the
@@ -150,11 +150,20 @@ pub enum ProcMacroKind {
150 Attr, 150 Attr,
151} 151}
152 152
153pub trait ProcMacroExpander: fmt::Debug + Send + Sync + RefUnwindSafe {
154 fn expand(
155 &self,
156 subtree: &Subtree,
157 attrs: Option<&Subtree>,
158 env: &Env,
159 ) -> Result<Subtree, ExpansionError>;
160}
161
153#[derive(Debug, Clone)] 162#[derive(Debug, Clone)]
154pub struct ProcMacro { 163pub struct ProcMacro {
155 pub name: SmolStr, 164 pub name: SmolStr,
156 pub kind: ProcMacroKind, 165 pub kind: ProcMacroKind,
157 pub expander: Arc<dyn TokenExpander>, 166 pub expander: Arc<dyn ProcMacroExpander>,
158} 167}
159 168
160impl Eq for ProcMacro {} 169impl Eq for ProcMacro {}
@@ -413,6 +422,10 @@ impl Env {
413 pub fn get(&self, env: &str) -> Option<String> { 422 pub fn get(&self, env: &str) -> Option<String> {
414 self.entries.get(env).cloned() 423 self.entries.get(env).cloned()
415 } 424 }
425
426 pub fn iter(&self) -> impl Iterator<Item = (&str, &str)> {
427 self.entries.iter().map(|(k, v)| (k.as_str(), v.as_str()))
428 }
416} 429}
417 430
418#[derive(Debug)] 431#[derive(Debug)]