aboutsummaryrefslogtreecommitdiff
path: root/crates/proc_macro_srv
diff options
context:
space:
mode:
Diffstat (limited to 'crates/proc_macro_srv')
-rw-r--r--crates/proc_macro_srv/src/dylib.rs11
-rw-r--r--crates/proc_macro_srv/src/lib.rs2
-rw-r--r--crates/proc_macro_srv/src/proc_macro/bridge/buffer.rs2
-rw-r--r--crates/proc_macro_srv/src/proc_macro/bridge/client.rs2
-rw-r--r--crates/proc_macro_srv/src/proc_macro/bridge/closure.rs2
-rw-r--r--crates/proc_macro_srv/src/proc_macro/bridge/handle.rs2
-rw-r--r--crates/proc_macro_srv/src/proc_macro/bridge/mod.rs2
-rw-r--r--crates/proc_macro_srv/src/proc_macro/bridge/rpc.rs2
-rw-r--r--crates/proc_macro_srv/src/proc_macro/bridge/scoped_cell.rs2
-rw-r--r--crates/proc_macro_srv/src/proc_macro/bridge/server.rs2
-rw-r--r--crates/proc_macro_srv/src/proc_macro/diagnostic.rs11
-rw-r--r--crates/proc_macro_srv/src/proc_macro/mod.rs2
-rw-r--r--crates/proc_macro_srv/src/rustc_server.rs4
-rw-r--r--crates/proc_macro_srv/src/tests/utils.rs29
14 files changed, 23 insertions, 52 deletions
diff --git a/crates/proc_macro_srv/src/dylib.rs b/crates/proc_macro_srv/src/dylib.rs
index cccc53220..5133e7c50 100644
--- a/crates/proc_macro_srv/src/dylib.rs
+++ b/crates/proc_macro_srv/src/dylib.rs
@@ -188,7 +188,9 @@ impl Expander {
188/// Copy the dylib to temp directory to prevent locking in Windows 188/// Copy the dylib to temp directory to prevent locking in Windows
189#[cfg(windows)] 189#[cfg(windows)]
190fn ensure_file_with_lock_free_access(path: &Path) -> io::Result<PathBuf> { 190fn ensure_file_with_lock_free_access(path: &Path) -> io::Result<PathBuf> {
191 use std::{ffi::OsString, time::SystemTime}; 191 use std::collections::hash_map::RandomState;
192 use std::ffi::OsString;
193 use std::hash::{BuildHasher, Hasher};
192 194
193 let mut to = std::env::temp_dir(); 195 let mut to = std::env::temp_dir();
194 196
@@ -199,10 +201,11 @@ fn ensure_file_with_lock_free_access(path: &Path) -> io::Result<PathBuf> {
199 ) 201 )
200 })?; 202 })?;
201 203
202 // generate a time deps unique number 204 // Generate a unique number by abusing `HashMap`'s hasher.
203 let t = SystemTime::now().duration_since(std::time::UNIX_EPOCH).expect("Time went backwards"); 205 // Maybe this will also "inspire" a libs team member to finally put `rand` in libstd.
206 let t = RandomState::new().build_hasher().finish();
204 207
205 let mut unique_name = OsString::from(t.as_millis().to_string()); 208 let mut unique_name = OsString::from(t.to_string());
206 unique_name.push(file_name); 209 unique_name.push(file_name);
207 210
208 to.push(unique_name); 211 to.push(unique_name);
diff --git a/crates/proc_macro_srv/src/lib.rs b/crates/proc_macro_srv/src/lib.rs
index d4f04ee06..f54cbcd61 100644
--- a/crates/proc_macro_srv/src/lib.rs
+++ b/crates/proc_macro_srv/src/lib.rs
@@ -1,7 +1,7 @@
1//! RA Proc Macro Server 1//! RA Proc Macro Server
2//! 2//!
3//! This library is able to call compiled Rust custom derive dynamic libraries on arbitrary code. 3//! This library is able to call compiled Rust custom derive dynamic libraries on arbitrary code.
4//! The general idea here is based on https://github.com/fedochet/rust-proc-macro-expander. 4//! The general idea here is based on <https://github.com/fedochet/rust-proc-macro-expander>.
5//! 5//!
6//! But we adapt it to better fit RA needs: 6//! But we adapt it to better fit RA needs:
7//! 7//!
diff --git a/crates/proc_macro_srv/src/proc_macro/bridge/buffer.rs b/crates/proc_macro_srv/src/proc_macro/bridge/buffer.rs
index dae6ff1d1..3b2afe01f 100644
--- a/crates/proc_macro_srv/src/proc_macro/bridge/buffer.rs
+++ b/crates/proc_macro_srv/src/proc_macro/bridge/buffer.rs
@@ -1,6 +1,6 @@
1//! lib-proc-macro Buffer management for same-process client<->server communication. 1//! lib-proc-macro Buffer management for same-process client<->server communication.
2//! 2//!
3//! Copy from https://github.com/rust-lang/rust/blob/6050e523bae6de61de4e060facc43dc512adaccd/src/libproc_macro/bridge/buffer.rs 3//! Copy from <https://github.com/rust-lang/rust/blob/6050e523bae6de61de4e060facc43dc512adaccd/src/libproc_macro/bridge/buffer.rs>
4//! augmented with removing unstable features 4//! augmented with removing unstable features
5 5
6use std::io::{self, Write}; 6use std::io::{self, Write};
diff --git a/crates/proc_macro_srv/src/proc_macro/bridge/client.rs b/crates/proc_macro_srv/src/proc_macro/bridge/client.rs
index b036d4e20..c135cf7a2 100644
--- a/crates/proc_macro_srv/src/proc_macro/bridge/client.rs
+++ b/crates/proc_macro_srv/src/proc_macro/bridge/client.rs
@@ -1,6 +1,6 @@
1//! lib-proc-macro Client-side types. 1//! lib-proc-macro Client-side types.
2//! 2//!
3//! Copy from https://github.com/rust-lang/rust/blob/6050e523bae6de61de4e060facc43dc512adaccd/src/libproc_macro/bridge/client.rs 3//! Copy from <https://github.com/rust-lang/rust/blob/6050e523bae6de61de4e060facc43dc512adaccd/src/libproc_macro/bridge/client.rs>
4//! augmented with removing unstable features 4//! augmented with removing unstable features
5 5
6use super::*; 6use super::*;
diff --git a/crates/proc_macro_srv/src/proc_macro/bridge/closure.rs b/crates/proc_macro_srv/src/proc_macro/bridge/closure.rs
index 273a97715..f5b6d897e 100644
--- a/crates/proc_macro_srv/src/proc_macro/bridge/closure.rs
+++ b/crates/proc_macro_srv/src/proc_macro/bridge/closure.rs
@@ -1,6 +1,6 @@
1//! lib-proc-macro Closure type (equivalent to `&mut dyn FnMut(A) -> R`) that's `repr(C)`. 1//! lib-proc-macro Closure type (equivalent to `&mut dyn FnMut(A) -> R`) that's `repr(C)`.
2//! 2//!
3//! Copy from https://github.com/rust-lang/rust/blob/6050e523bae6de61de4e060facc43dc512adaccd/src/libproc_macro/bridge/closure.rs# 3//! Copy from <https://github.com/rust-lang/rust/blob/6050e523bae6de61de4e060facc43dc512adaccd/src/libproc_macro/bridge/closure.rs>
4//! augmented with removing unstable features 4//! augmented with removing unstable features
5 5
6#[repr(C)] 6#[repr(C)]
diff --git a/crates/proc_macro_srv/src/proc_macro/bridge/handle.rs b/crates/proc_macro_srv/src/proc_macro/bridge/handle.rs
index a2f77b5ac..d2a65d249 100644
--- a/crates/proc_macro_srv/src/proc_macro/bridge/handle.rs
+++ b/crates/proc_macro_srv/src/proc_macro/bridge/handle.rs
@@ -1,6 +1,6 @@
1//! lib-proc-macro Server-side handles and storage for per-handle data. 1//! lib-proc-macro Server-side handles and storage for per-handle data.
2//! 2//!
3//! Copy from https://github.com/rust-lang/rust/blob/6050e523bae6de61de4e060facc43dc512adaccd/src/libproc_macro/bridge/handle.rs 3//! Copy from <https://github.com/rust-lang/rust/blob/6050e523bae6de61de4e060facc43dc512adaccd/src/libproc_macro/bridge/handle.rs>
4//! augmented with removing unstable features 4//! augmented with removing unstable features
5 5
6use std::collections::{BTreeMap, HashMap}; 6use std::collections::{BTreeMap, HashMap};
diff --git a/crates/proc_macro_srv/src/proc_macro/bridge/mod.rs b/crates/proc_macro_srv/src/proc_macro/bridge/mod.rs
index e67902682..375396d1b 100644
--- a/crates/proc_macro_srv/src/proc_macro/bridge/mod.rs
+++ b/crates/proc_macro_srv/src/proc_macro/bridge/mod.rs
@@ -1,6 +1,6 @@
1//! lib-proc-macro Internal interface for communicating between a `proc_macro` client 1//! lib-proc-macro Internal interface for communicating between a `proc_macro` client
2//! 2//!
3//! Copy from https://github.com/rust-lang/rust/blob/6050e523bae6de61de4e060facc43dc512adaccd/src/libproc_macro/bridge/mod.rs 3//! Copy from <https://github.com/rust-lang/rust/blob/6050e523bae6de61de4e060facc43dc512adaccd/src/libproc_macro/bridge/mod.rs>
4//! augmented with removing unstable features 4//! augmented with removing unstable features
5//! 5//!
6//! Internal interface for communicating between a `proc_macro` client 6//! Internal interface for communicating between a `proc_macro` client
diff --git a/crates/proc_macro_srv/src/proc_macro/bridge/rpc.rs b/crates/proc_macro_srv/src/proc_macro/bridge/rpc.rs
index bd1e7c2fc..69928ec84 100644
--- a/crates/proc_macro_srv/src/proc_macro/bridge/rpc.rs
+++ b/crates/proc_macro_srv/src/proc_macro/bridge/rpc.rs
@@ -1,6 +1,6 @@
1//! lib-proc-macro Serialization for client-server communication. 1//! lib-proc-macro Serialization for client-server communication.
2//! 2//!
3//! Copy from https://github.com/rust-lang/rust/blob/6050e523bae6de61de4e060facc43dc512adaccd/src/libproc_macro/bridge/rpc.rs 3//! Copy from <https://github.com/rust-lang/rust/blob/6050e523bae6de61de4e060facc43dc512adaccd/src/libproc_macro/bridge/rpc.rs>
4//! augmented with removing unstable features 4//! augmented with removing unstable features
5//! 5//!
6//! Serialization for client-server communication. 6//! Serialization for client-server communication.
diff --git a/crates/proc_macro_srv/src/proc_macro/bridge/scoped_cell.rs b/crates/proc_macro_srv/src/proc_macro/bridge/scoped_cell.rs
index 6ef7ea43c..0436bc418 100644
--- a/crates/proc_macro_srv/src/proc_macro/bridge/scoped_cell.rs
+++ b/crates/proc_macro_srv/src/proc_macro/bridge/scoped_cell.rs
@@ -1,6 +1,6 @@
1//! lib-proc-macro `Cell` variant for (scoped) existential lifetimes. 1//! lib-proc-macro `Cell` variant for (scoped) existential lifetimes.
2//! 2//!
3//! Copy from https://github.com/rust-lang/rust/blob/6050e523bae6de61de4e060facc43dc512adaccd/src/libproc_macro/bridge/scoped_cell.rs#L1 3//! Copy from <https://github.com/rust-lang/rust/blob/6050e523bae6de61de4e060facc43dc512adaccd/src/libproc_macro/bridge/scoped_cell.rs#L1>
4//! augmented with removing unstable features 4//! augmented with removing unstable features
5 5
6use std::cell::Cell; 6use std::cell::Cell;
diff --git a/crates/proc_macro_srv/src/proc_macro/bridge/server.rs b/crates/proc_macro_srv/src/proc_macro/bridge/server.rs
index 88fbdc078..cc9afd84b 100644
--- a/crates/proc_macro_srv/src/proc_macro/bridge/server.rs
+++ b/crates/proc_macro_srv/src/proc_macro/bridge/server.rs
@@ -1,6 +1,6 @@
1//! lib-proc-macro server-side traits 1//! lib-proc-macro server-side traits
2//! 2//!
3//! Copy from https://github.com/rust-lang/rust/blob/6050e523bae6de61de4e060facc43dc512adaccd/src/libproc_macro/bridge/server.rs 3//! Copy from <https://github.com/rust-lang/rust/blob/6050e523bae6de61de4e060facc43dc512adaccd/src/libproc_macro/bridge/server.rs>
4//! augmented with removing unstable features 4//! augmented with removing unstable features
5 5
6use super::*; 6use super::*;
diff --git a/crates/proc_macro_srv/src/proc_macro/diagnostic.rs b/crates/proc_macro_srv/src/proc_macro/diagnostic.rs
index 55d93917c..3c5b7bc01 100644
--- a/crates/proc_macro_srv/src/proc_macro/diagnostic.rs
+++ b/crates/proc_macro_srv/src/proc_macro/diagnostic.rs
@@ -1,6 +1,6 @@
1//! lib-proc-macro diagnostic 1//! lib-proc-macro diagnostic
2//! 2//!
3//! Copy from https://github.com/rust-lang/rust/blob/6050e523bae6de61de4e060facc43dc512adaccd/src/libproc_macro/diagnostic.rs 3//! Copy from <https://github.com/rust-lang/rust/blob/6050e523bae6de61de4e060facc43dc512adaccd/src/libproc_macro/diagnostic.rs>
4//! augmented with removing unstable features 4//! augmented with removing unstable features
5 5
6use crate::proc_macro::Span; 6use crate::proc_macro::Span;
@@ -91,7 +91,7 @@ impl<'a> Iterator for Children<'a> {
91impl Diagnostic { 91impl Diagnostic {
92 /// Creates a new diagnostic with the given `level` and `message`. 92 /// Creates a new diagnostic with the given `level` and `message`.
93 pub fn new<T: Into<String>>(level: Level, message: T) -> Diagnostic { 93 pub fn new<T: Into<String>>(level: Level, message: T) -> Diagnostic {
94 Diagnostic { level: level, message: message.into(), spans: vec![], children: vec![] } 94 Diagnostic { level, message: message.into(), spans: vec![], children: vec![] }
95 } 95 }
96 96
97 /// Creates a new diagnostic with the given `level` and `message` pointing to 97 /// Creates a new diagnostic with the given `level` and `message` pointing to
@@ -101,12 +101,7 @@ impl Diagnostic {
101 S: MultiSpan, 101 S: MultiSpan,
102 T: Into<String>, 102 T: Into<String>,
103 { 103 {
104 Diagnostic { 104 Diagnostic { level, message: message.into(), spans: spans.into_spans(), children: vec![] }
105 level: level,
106 message: message.into(),
107 spans: spans.into_spans(),
108 children: vec![],
109 }
110 } 105 }
111 106
112 diagnostic_child_methods!(span_error, error, Level::Error); 107 diagnostic_child_methods!(span_error, error, Level::Error);
diff --git a/crates/proc_macro_srv/src/proc_macro/mod.rs b/crates/proc_macro_srv/src/proc_macro/mod.rs
index fc6e7344f..b7c1d04b5 100644
--- a/crates/proc_macro_srv/src/proc_macro/mod.rs
+++ b/crates/proc_macro_srv/src/proc_macro/mod.rs
@@ -1,6 +1,6 @@
1//! lib-proc-macro main module 1//! lib-proc-macro main module
2//! 2//!
3//! Copy from https://github.com/rust-lang/rust/blob/6050e523bae6de61de4e060facc43dc512adaccd/src/libproc_macro/lib.rs 3//! Copy from <https://github.com/rust-lang/rust/blob/6050e523bae6de61de4e060facc43dc512adaccd/src/libproc_macro/lib.rs>
4//! augmented with removing unstable features 4//! augmented with removing unstable features
5 5
6// NOTE(@edwin0cheng): 6// NOTE(@edwin0cheng):
diff --git a/crates/proc_macro_srv/src/rustc_server.rs b/crates/proc_macro_srv/src/rustc_server.rs
index 5d765f6e2..65ca3eb6c 100644
--- a/crates/proc_macro_srv/src/rustc_server.rs
+++ b/crates/proc_macro_srv/src/rustc_server.rs
@@ -1,6 +1,6 @@
1//! Rustc proc-macro server implementation with tt 1//! Rustc proc-macro server implementation with tt
2//! 2//!
3//! Based on idea from https://github.com/fedochet/rust-proc-macro-expander 3//! Based on idea from <https://github.com/fedochet/rust-proc-macro-expander>
4//! The lib-proc-macro server backend is `TokenStream`-agnostic, such that 4//! The lib-proc-macro server backend is `TokenStream`-agnostic, such that
5//! we could provide any TokenStream implementation. 5//! we could provide any TokenStream implementation.
6//! The original idea from fedochet is using proc-macro2 as backend, 6//! The original idea from fedochet is using proc-macro2 as backend,
@@ -539,7 +539,7 @@ impl server::Literal for Rustc {
539 } else { 539 } else {
540 n.parse::<u128>().unwrap().to_string() 540 n.parse::<u128>().unwrap().to_string()
541 }; 541 };
542 return Literal { text: n.into(), id: tt::TokenId::unspecified() }; 542 Literal { text: n.into(), id: tt::TokenId::unspecified() }
543 } 543 }
544 544
545 fn typed_integer(&mut self, n: &str, kind: &str) -> Self::Literal { 545 fn typed_integer(&mut self, n: &str, kind: &str) -> Self::Literal {
diff --git a/crates/proc_macro_srv/src/tests/utils.rs b/crates/proc_macro_srv/src/tests/utils.rs
index 2e950c113..2c093aa0a 100644
--- a/crates/proc_macro_srv/src/tests/utils.rs
+++ b/crates/proc_macro_srv/src/tests/utils.rs
@@ -7,35 +7,8 @@ use proc_macro_api::ListMacrosTask;
7use std::str::FromStr; 7use std::str::FromStr;
8 8
9pub mod fixtures { 9pub mod fixtures {
10 use cargo_metadata::Message;
11 use std::path::PathBuf;
12 use std::process::Command;
13
14 // Use current project metadata to get the proc-macro dylib path
15 pub fn proc_macro_test_dylib_path() -> std::path::PathBuf { 10 pub fn proc_macro_test_dylib_path() -> std::path::PathBuf {
16 let name = "proc_macro_test"; 11 proc_macro_test::PROC_MACRO_TEST_LOCATION.into()
17 let version = "0.0.0";
18 let command = Command::new(toolchain::cargo())
19 .args(&["check", "--tests", "--message-format", "json"])
20 .output()
21 .unwrap()
22 .stdout;
23
24 for message in Message::parse_stream(command.as_slice()) {
25 match message.unwrap() {
26 Message::CompilerArtifact(artifact) => {
27 if artifact.target.kind.contains(&"proc-macro".to_string()) {
28 let repr = format!("{} {}", name, version);
29 if artifact.package_id.repr.starts_with(&repr) {
30 return PathBuf::from(&artifact.filenames[0]);
31 }
32 }
33 }
34 _ => (), // Unknown message
35 }
36 }
37
38 panic!("No proc-macro dylib for {} found!", name);
39 } 12 }
40} 13}
41 14