mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 11:59:49 +00:00
parent
b3ef934ccb
commit
25242fe93f
395 changed files with 14569 additions and 5755 deletions
|
@ -286,7 +286,7 @@ impl BridgeState<'_> {
|
|||
BRIDGE_STATE.with(|state| {
|
||||
state.replace(BridgeState::InUse, |mut state| {
|
||||
// FIXME(#52812) pass `f` directly to `replace` when `RefMutL` is gone
|
||||
f(&mut *state)
|
||||
f(&mut state)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -877,7 +877,7 @@ impl Literal {
|
|||
/// example if it is infinity or NaN this function will panic.
|
||||
pub fn f32_unsuffixed(n: f32) -> Literal {
|
||||
if !n.is_finite() {
|
||||
panic!("Invalid float literal {}", n);
|
||||
panic!("Invalid float literal {n}");
|
||||
}
|
||||
let mut repr = n.to_string();
|
||||
if !repr.contains('.') {
|
||||
|
@ -901,7 +901,7 @@ impl Literal {
|
|||
/// example if it is infinity or NaN this function will panic.
|
||||
pub fn f32_suffixed(n: f32) -> Literal {
|
||||
if !n.is_finite() {
|
||||
panic!("Invalid float literal {}", n);
|
||||
panic!("Invalid float literal {n}");
|
||||
}
|
||||
Literal(bridge::client::Literal::f32(&n.to_string()))
|
||||
}
|
||||
|
@ -920,7 +920,7 @@ impl Literal {
|
|||
/// example if it is infinity or NaN this function will panic.
|
||||
pub fn f64_unsuffixed(n: f64) -> Literal {
|
||||
if !n.is_finite() {
|
||||
panic!("Invalid float literal {}", n);
|
||||
panic!("Invalid float literal {n}");
|
||||
}
|
||||
let mut repr = n.to_string();
|
||||
if !repr.contains('.') {
|
||||
|
@ -944,7 +944,7 @@ impl Literal {
|
|||
/// example if it is infinity or NaN this function will panic.
|
||||
pub fn f64_suffixed(n: f64) -> Literal {
|
||||
if !n.is_finite() {
|
||||
panic!("Invalid float literal {}", n);
|
||||
panic!("Invalid float literal {n}");
|
||||
}
|
||||
Literal(bridge::client::Literal::f64(&n.to_string()))
|
||||
}
|
||||
|
|
|
@ -471,8 +471,12 @@ impl server::Punct for RustAnalyzer {
|
|||
}
|
||||
|
||||
impl server::Ident for RustAnalyzer {
|
||||
fn new(&mut self, string: &str, span: Self::Span, _is_raw: bool) -> Self::Ident {
|
||||
IdentId(self.ident_interner.intern(&IdentData(tt::Ident { text: string.into(), id: span })))
|
||||
fn new(&mut self, string: &str, span: Self::Span, is_raw: bool) -> Self::Ident {
|
||||
IdentId(self.ident_interner.intern(&IdentData(tt::Ident::new_with_is_raw(
|
||||
string.into(),
|
||||
span,
|
||||
is_raw,
|
||||
))))
|
||||
}
|
||||
|
||||
fn span(&mut self, ident: Self::Ident) -> Self::Span {
|
||||
|
@ -544,13 +548,13 @@ impl server::Literal for RustAnalyzer {
|
|||
|
||||
fn f32(&mut self, n: &str) -> Self::Literal {
|
||||
let n: f32 = n.parse().unwrap();
|
||||
let text = format!("{}f32", n);
|
||||
let text = format!("{n}f32");
|
||||
Literal { text: text.into(), id: tt::TokenId::unspecified() }
|
||||
}
|
||||
|
||||
fn f64(&mut self, n: &str) -> Self::Literal {
|
||||
let n: f64 = n.parse().unwrap();
|
||||
let text = format!("{}f64", n);
|
||||
let text = format!("{n}f64");
|
||||
Literal { text: text.into(), id: tt::TokenId::unspecified() }
|
||||
}
|
||||
|
||||
|
@ -559,11 +563,11 @@ impl server::Literal for RustAnalyzer {
|
|||
for ch in string.chars() {
|
||||
escaped.extend(ch.escape_debug());
|
||||
}
|
||||
Literal { text: format!("\"{}\"", escaped).into(), id: tt::TokenId::unspecified() }
|
||||
Literal { text: format!("\"{escaped}\"").into(), id: tt::TokenId::unspecified() }
|
||||
}
|
||||
|
||||
fn character(&mut self, ch: char) -> Self::Literal {
|
||||
Literal { text: format!("'{}'", ch).into(), id: tt::TokenId::unspecified() }
|
||||
Literal { text: format!("'{ch}'").into(), id: tt::TokenId::unspecified() }
|
||||
}
|
||||
|
||||
fn byte_string(&mut self, bytes: &[u8]) -> Self::Literal {
|
||||
|
@ -574,7 +578,7 @@ impl server::Literal for RustAnalyzer {
|
|||
.map(Into::<char>::into)
|
||||
.collect::<String>();
|
||||
|
||||
Literal { text: format!("b\"{}\"", string).into(), id: tt::TokenId::unspecified() }
|
||||
Literal { text: format!("b\"{string}\"").into(), id: tt::TokenId::unspecified() }
|
||||
}
|
||||
|
||||
fn span(&mut self, literal: &Self::Literal) -> Self::Span {
|
||||
|
|
|
@ -301,7 +301,7 @@ impl BridgeState<'_> {
|
|||
BRIDGE_STATE.with(|state| {
|
||||
state.replace(BridgeState::InUse, |mut state| {
|
||||
// FIXME(#52812) pass `f` directly to `replace` when `RefMutL` is gone
|
||||
f(&mut *state)
|
||||
f(&mut state)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
@ -486,8 +486,12 @@ impl server::Punct for RustAnalyzer {
|
|||
}
|
||||
|
||||
impl server::Ident for RustAnalyzer {
|
||||
fn new(&mut self, string: &str, span: Self::Span, _is_raw: bool) -> Self::Ident {
|
||||
IdentId(self.ident_interner.intern(&IdentData(tt::Ident { text: string.into(), id: span })))
|
||||
fn new(&mut self, string: &str, span: Self::Span, is_raw: bool) -> Self::Ident {
|
||||
IdentId(self.ident_interner.intern(&IdentData(tt::Ident::new_with_is_raw(
|
||||
string.into(),
|
||||
span,
|
||||
is_raw,
|
||||
))))
|
||||
}
|
||||
|
||||
fn span(&mut self, ident: Self::Ident) -> Self::Span {
|
||||
|
@ -559,13 +563,13 @@ impl server::Literal for RustAnalyzer {
|
|||
|
||||
fn f32(&mut self, n: &str) -> Self::Literal {
|
||||
let n: f32 = n.parse().unwrap();
|
||||
let text = format!("{}f32", n);
|
||||
let text = format!("{n}f32");
|
||||
Literal { text: text.into(), id: tt::TokenId::unspecified() }
|
||||
}
|
||||
|
||||
fn f64(&mut self, n: &str) -> Self::Literal {
|
||||
let n: f64 = n.parse().unwrap();
|
||||
let text = format!("{}f64", n);
|
||||
let text = format!("{n}f64");
|
||||
Literal { text: text.into(), id: tt::TokenId::unspecified() }
|
||||
}
|
||||
|
||||
|
@ -574,11 +578,11 @@ impl server::Literal for RustAnalyzer {
|
|||
for ch in string.chars() {
|
||||
escaped.extend(ch.escape_debug());
|
||||
}
|
||||
Literal { text: format!("\"{}\"", escaped).into(), id: tt::TokenId::unspecified() }
|
||||
Literal { text: format!("\"{escaped}\"").into(), id: tt::TokenId::unspecified() }
|
||||
}
|
||||
|
||||
fn character(&mut self, ch: char) -> Self::Literal {
|
||||
Literal { text: format!("'{}'", ch).into(), id: tt::TokenId::unspecified() }
|
||||
Literal { text: format!("'{ch}'").into(), id: tt::TokenId::unspecified() }
|
||||
}
|
||||
|
||||
fn byte_string(&mut self, bytes: &[u8]) -> Self::Literal {
|
||||
|
@ -589,7 +593,7 @@ impl server::Literal for RustAnalyzer {
|
|||
.map(Into::<char>::into)
|
||||
.collect::<String>();
|
||||
|
||||
Literal { text: format!("b\"{}\"", string).into(), id: tt::TokenId::unspecified() }
|
||||
Literal { text: format!("b\"{string}\"").into(), id: tt::TokenId::unspecified() }
|
||||
}
|
||||
|
||||
fn span(&mut self, literal: &Self::Literal) -> Self::Span {
|
||||
|
|
|
@ -107,8 +107,8 @@ impl server::TokenStream for RustAnalyzer {
|
|||
}
|
||||
|
||||
bridge::TokenTree::Ident(ident) => {
|
||||
// FIXME: handle raw idents
|
||||
let text = ident.sym.text();
|
||||
let text = if ident.is_raw { tt::SmolStr::from_iter(["r#", &text]) } else { text };
|
||||
let ident: tt::Ident = tt::Ident { text, id: ident.span };
|
||||
let leaf = tt::Leaf::from(ident);
|
||||
let tree = TokenTree::from(leaf);
|
||||
|
@ -182,9 +182,8 @@ impl server::TokenStream for RustAnalyzer {
|
|||
.map(|tree| match tree {
|
||||
tt::TokenTree::Leaf(tt::Leaf::Ident(ident)) => {
|
||||
bridge::TokenTree::Ident(bridge::Ident {
|
||||
sym: Symbol::intern(&ident.text),
|
||||
// FIXME: handle raw idents
|
||||
is_raw: false,
|
||||
sym: Symbol::intern(ident.text.trim_start_matches("r#")),
|
||||
is_raw: ident.text.starts_with("r#"),
|
||||
span: ident.id,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -117,7 +117,7 @@ impl Abi {
|
|||
let inner = unsafe { Abi_1_63::from_lib(lib, symbol_name) }?;
|
||||
Ok(Abi::Abi1_63(inner))
|
||||
}
|
||||
_ => Err(LoadProcMacroDylibError::UnsupportedABI(info.version_string.clone())),
|
||||
_ => Err(LoadProcMacroDylibError::UnsupportedABI(info.version_string)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ impl ProcMacroSrv {
|
|||
pub fn expand(&mut self, task: ExpandMacro) -> Result<FlatTree, PanicMessage> {
|
||||
let expander = self.expander(task.lib.as_ref()).map_err(|err| {
|
||||
debug_assert!(false, "should list macros before asking to expand");
|
||||
PanicMessage(format!("failed to load macro: {}", err))
|
||||
PanicMessage(format!("failed to load macro: {err}"))
|
||||
})?;
|
||||
|
||||
let prev_env = EnvSnapshot::new();
|
||||
|
@ -59,7 +59,7 @@ impl ProcMacroSrv {
|
|||
Some(dir) => {
|
||||
let prev_working_dir = std::env::current_dir().ok();
|
||||
if let Err(err) = std::env::set_current_dir(&dir) {
|
||||
eprintln!("Failed to set the current working dir to {}. Error: {:?}", dir, err)
|
||||
eprintln!("Failed to set the current working dir to {dir}. Error: {err:?}")
|
||||
}
|
||||
prev_working_dir
|
||||
}
|
||||
|
@ -112,14 +112,16 @@ impl ProcMacroSrv {
|
|||
}
|
||||
|
||||
fn expander(&mut self, path: &Path) -> Result<&dylib::Expander, String> {
|
||||
let time = fs::metadata(path).and_then(|it| it.modified()).map_err(|err| {
|
||||
format!("Failed to get file metadata for {}: {}", path.display(), err)
|
||||
})?;
|
||||
let time = fs::metadata(path)
|
||||
.and_then(|it| it.modified())
|
||||
.map_err(|err| format!("Failed to get file metadata for {}: {err}", path.display()))?;
|
||||
|
||||
Ok(match self.expanders.entry((path.to_path_buf(), time)) {
|
||||
Entry::Vacant(v) => v.insert(dylib::Expander::new(path).map_err(|err| {
|
||||
format!("Cannot create expander for {}: {}", path.display(), err)
|
||||
})?),
|
||||
Entry::Vacant(v) => {
|
||||
v.insert(dylib::Expander::new(path).map_err(|err| {
|
||||
format!("Cannot create expander for {}: {err}", path.display())
|
||||
})?)
|
||||
}
|
||||
Entry::Occupied(e) => e.into_mut(),
|
||||
})
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ fn test_fn_like_macro_clone_raw_ident() {
|
|||
"r#async",
|
||||
expect![[r#"
|
||||
SUBTREE $
|
||||
IDENT async 4294967295"#]],
|
||||
IDENT r#async 4294967295"#]],
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -86,15 +86,13 @@ fn test_fn_like_mk_literals() {
|
|||
|
||||
#[test]
|
||||
fn test_fn_like_mk_idents() {
|
||||
// FIXME: this test is wrong: raw should be 'r#raw' but ABIs 1.64 and below
|
||||
// simply ignore `is_raw` when implementing the `Ident` interface.
|
||||
assert_expand(
|
||||
"fn_like_mk_idents",
|
||||
r#""#,
|
||||
expect![[r#"
|
||||
SUBTREE $
|
||||
IDENT standard 4294967295
|
||||
IDENT raw 4294967295"#]],
|
||||
IDENT r#raw 4294967295"#]],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -30,12 +30,12 @@ fn assert_expand_impl(macro_name: &str, input: &str, attr: Option<&str>, expect:
|
|||
let attr = attr.map(|attr| parse_string(attr).unwrap().into_subtree());
|
||||
|
||||
let res = expander.expand(macro_name, &fixture.into_subtree(), attr.as_ref()).unwrap();
|
||||
expect.assert_eq(&format!("{:?}", res));
|
||||
expect.assert_eq(&format!("{res:?}"));
|
||||
}
|
||||
|
||||
pub(crate) fn list() -> Vec<String> {
|
||||
let dylib_path = proc_macro_test_dylib_path();
|
||||
let mut srv = ProcMacroSrv::default();
|
||||
let res = srv.list_macros(&dylib_path).unwrap();
|
||||
res.into_iter().map(|(name, kind)| format!("{} [{:?}]", name, kind)).collect()
|
||||
res.into_iter().map(|(name, kind)| format!("{name} [{kind:?}]")).collect()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue