mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-27 04:15:08 +00:00
Merge #5651
5651: Add track_env_var to the proc macro server r=kjeremy a=lnicola See https://github.com/rust-lang/rust/pull/74653. Fixes #6054. Fixes #5640, maybe. Should be merged when 1.47 is released. Proc macros still don't work for me, but it no longer crashes. Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
This commit is contained in:
commit
e6a05e6566
6 changed files with 40 additions and 1 deletions
|
@ -160,6 +160,7 @@ macro_rules! define_handles {
|
||||||
}
|
}
|
||||||
define_handles! {
|
define_handles! {
|
||||||
'owned:
|
'owned:
|
||||||
|
FreeFunctions,
|
||||||
TokenStream,
|
TokenStream,
|
||||||
TokenStreamBuilder,
|
TokenStreamBuilder,
|
||||||
TokenStreamIter,
|
TokenStreamIter,
|
||||||
|
|
|
@ -57,6 +57,10 @@ use std::thread;
|
||||||
macro_rules! with_api {
|
macro_rules! with_api {
|
||||||
($S:ident, $self:ident, $m:ident) => {
|
($S:ident, $self:ident, $m:ident) => {
|
||||||
$m! {
|
$m! {
|
||||||
|
FreeFunctions {
|
||||||
|
fn drop($self: $S::FreeFunctions);
|
||||||
|
fn track_env_var(var: &str, value: Option<&str>);
|
||||||
|
},
|
||||||
TokenStream {
|
TokenStream {
|
||||||
fn drop($self: $S::TokenStream);
|
fn drop($self: $S::TokenStream);
|
||||||
fn clone($self: &$S::TokenStream) -> $S::TokenStream;
|
fn clone($self: &$S::TokenStream) -> $S::TokenStream;
|
||||||
|
|
|
@ -11,6 +11,8 @@ use super::client::HandleStore;
|
||||||
/// Declare an associated item of one of the traits below, optionally
|
/// Declare an associated item of one of the traits below, optionally
|
||||||
/// adjusting it (i.e., adding bounds to types and default bodies to methods).
|
/// adjusting it (i.e., adding bounds to types and default bodies to methods).
|
||||||
macro_rules! associated_item {
|
macro_rules! associated_item {
|
||||||
|
(type FreeFunctions) =>
|
||||||
|
(type FreeFunctions: 'static;);
|
||||||
(type TokenStream) =>
|
(type TokenStream) =>
|
||||||
(type TokenStream: 'static + Clone;);
|
(type TokenStream: 'static + Clone;);
|
||||||
(type TokenStreamBuilder) =>
|
(type TokenStreamBuilder) =>
|
||||||
|
|
|
@ -924,3 +924,25 @@ impl fmt::Debug for Literal {
|
||||||
self.0.fmt(f)
|
self.0.fmt(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod tracked_env {
|
||||||
|
use std::env::{self, VarError};
|
||||||
|
use std::ffi::OsStr;
|
||||||
|
|
||||||
|
/// Retrieve an environment variable and add it to build dependency info.
|
||||||
|
/// Build system executing the compiler will know that the variable was accessed during
|
||||||
|
/// compilation, and will be able to rerun the build when the value of that variable changes.
|
||||||
|
/// Besides the dependency tracking this function should be equivalent to `env::var` from the
|
||||||
|
/// standard library, except that the argument must be UTF-8.
|
||||||
|
pub fn var<K: AsRef<OsStr> + AsRef<str>>(key: K) -> Result<String, VarError> {
|
||||||
|
use std::ops::Deref;
|
||||||
|
|
||||||
|
let key: &str = key.as_ref();
|
||||||
|
let value = env::var(key);
|
||||||
|
super::bridge::client::FreeFunctions::track_env_var(
|
||||||
|
key,
|
||||||
|
value.as_ref().map(|t| t.deref()).ok(),
|
||||||
|
);
|
||||||
|
value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -242,6 +242,8 @@ impl TokenStreamBuilder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct FreeFunctions;
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct TokenStreamIter {
|
pub struct TokenStreamIter {
|
||||||
trees: IntoIter<TokenTree>,
|
trees: IntoIter<TokenTree>,
|
||||||
|
@ -254,6 +256,7 @@ pub struct Rustc {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl server::Types for Rustc {
|
impl server::Types for Rustc {
|
||||||
|
type FreeFunctions = FreeFunctions;
|
||||||
type TokenStream = TokenStream;
|
type TokenStream = TokenStream;
|
||||||
type TokenStreamBuilder = TokenStreamBuilder;
|
type TokenStreamBuilder = TokenStreamBuilder;
|
||||||
type TokenStreamIter = TokenStreamIter;
|
type TokenStreamIter = TokenStreamIter;
|
||||||
|
@ -267,6 +270,13 @@ impl server::Types for Rustc {
|
||||||
type MultiSpan = Vec<Span>;
|
type MultiSpan = Vec<Span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl server::FreeFunctions for Rustc {
|
||||||
|
fn track_env_var(&mut self, _var: &str, _value: Option<&str>) {
|
||||||
|
// FIXME: track env var accesses
|
||||||
|
// https://github.com/rust-lang/rust/pull/71858
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl server::TokenStream for Rustc {
|
impl server::TokenStream for Rustc {
|
||||||
fn new(&mut self) -> Self::TokenStream {
|
fn new(&mut self) -> Self::TokenStream {
|
||||||
Self::TokenStream::new()
|
Self::TokenStream::new()
|
||||||
|
|
|
@ -7,7 +7,7 @@ use anyhow::{bail, format_err, Context, Result};
|
||||||
use crate::not_bash::{pushd, run};
|
use crate::not_bash::{pushd, run};
|
||||||
|
|
||||||
// Latest stable, feel free to send a PR if this lags behind.
|
// Latest stable, feel free to send a PR if this lags behind.
|
||||||
const REQUIRED_RUST_VERSION: u32 = 46;
|
const REQUIRED_RUST_VERSION: u32 = 47;
|
||||||
|
|
||||||
pub struct InstallCmd {
|
pub struct InstallCmd {
|
||||||
pub client: Option<ClientOpt>,
|
pub client: Option<ClientOpt>,
|
||||||
|
|
Loading…
Reference in a new issue