Skip to content

Commit

Permalink
Auto merge of #125576 - lnicola:sync-from-ra, r=lnicola
Browse files Browse the repository at this point in the history
Subtree update of `rust-analyzer`

r? `@ghost`
  • Loading branch information
bors committed May 26, 2024
2 parents bdbbb6c + f7ca8a6 commit 0aad3f6
Show file tree
Hide file tree
Showing 92 changed files with 1,974 additions and 1,321 deletions.
3 changes: 0 additions & 3 deletions src/tools/rust-analyzer/crates/hir-def/src/attr/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ use std::sync::OnceLock;

use rustc_hash::FxHashMap;

/// Ignored attribute namespaces used by tools.
pub const TOOL_MODULES: &[&str] = &["rustfmt", "clippy"];

pub struct BuiltinAttribute {
pub name: &'static str,
pub template: AttributeTemplate,
Expand Down
10 changes: 8 additions & 2 deletions src/tools/rust-analyzer/crates/hir-def/src/body/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use syntax::{
self, ArrayExprKind, AstChildren, BlockExpr, HasArgList, HasAttrs, HasLoopBody, HasName,
RangeItem, SlicePatComponents,
},
AstNode, AstPtr, SyntaxNodePtr,
AstNode, AstPtr, AstToken as _, SyntaxNodePtr,
};
use triomphe::Arc;

Expand Down Expand Up @@ -1577,7 +1577,13 @@ impl ExprCollector<'_> {
});
});
let template = f.template();
let fmt_snippet = template.as_ref().map(ToString::to_string);
let fmt_snippet = template.as_ref().and_then(|it| match it {
ast::Expr::Literal(literal) => match literal.kind() {
ast::LiteralKind::String(s) => Some(s.text().to_owned()),
_ => None,
},
_ => None,
});
let mut mappings = vec![];
let fmt = match template.and_then(|it| self.expand_macros_to_string(it)) {
Some((s, is_direct_literal)) => format_args::parse(
Expand Down
4 changes: 2 additions & 2 deletions src/tools/rust-analyzer/crates/hir-def/src/body/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ fn desugar_builtin_format_args() {
fn main() {
let are = "are";
let count = 10;
builtin#format_args("hello {count:02} {} friends, we {are:?} {0}{last}", "fancy", last = "!");
builtin#format_args("\u{1b}hello {count:02} {} friends, we {are:?} {0}{last}", "fancy", last = "!");
}
"#,
);
Expand All @@ -161,7 +161,7 @@ fn main() {
let count = 10;
builtin#lang(Arguments::new_v1_formatted)(
&[
"hello ", " ", " friends, we ", " ", "",
"\u{1b}hello ", " ", " friends, we ", " ", "",
],
&[
builtin#lang(Argument::new_display)(
Expand Down
62 changes: 62 additions & 0 deletions src/tools/rust-analyzer/crates/hir-def/src/body/tests/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,3 +528,65 @@ fn f() {$0
"#]],
)
}

#[test]
fn resolve_extern_prelude_in_block() {
check_at(
r#"
//- /main.rs crate:main deps:core
fn main() {
mod f {
use core::S;
$0
}
}
//- /core.rs crate:core
pub struct S;
"#,
expect![[r#"
block scope
f: t
block scope::f
S: ti vi
crate
main: v
"#]],
)
}

#[test]
fn shadow_extern_prelude_in_block() {
check_at(
r#"
//- /main.rs crate:main deps:core
fn main() {
mod core { pub struct S; }
{
fn inner() {} // forces a block def map
use core::S; // should resolve to the local one
$0
}
}
//- /core.rs crate:core
pub const S;
"#,
expect![[r#"
block scope
S: ti vi
inner: v
block scope
core: t
block scope::core
S: t v
crate
main: v
"#]],
)
}
Loading

0 comments on commit 0aad3f6

Please sign in to comment.