Skip to content

Commit b34bf38

Browse files
Rollup merge of #164196 - lnicola:sync-from-ra, r=lnicola
`rust-analyzer` subtree update Subtree update of `rust-analyzer` to rust-lang/rust-analyzer@f0eebde. Created using https://github.com/rust-lang/josh-sync. r? @ghost
2 parents 34ca1df + b5e7e91 commit b34bf38

141 files changed

Lines changed: 5166 additions & 1947 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎src/tools/rust-analyzer/.github/workflows/autopublish.yaml‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ jobs:
1414
if: ${{ github.repository == 'rust-lang/rust-analyzer' || github.event_name == 'workflow_dispatch' }}
1515
name: publish
1616
runs-on: ubuntu-latest
17+
permissions:
18+
contents: read
19+
id-token: write
20+
environment: publish-auto
1721
steps:
1822
- name: Checkout repository
1923
uses: actions/checkout@v6
@@ -30,9 +34,12 @@ jobs:
3034
- name: Install cargo-workspaces
3135
run: cargo install --locked cargo-workspaces --version "0.3.6"
3236

37+
- uses: rust-lang/crates-io-auth-action@v1
38+
id: auth
39+
3340
- name: Publish Crates
3441
env:
35-
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
42+
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
3643
RUN_NUMBER: ${{ github.run_number }}
3744
shell: bash
3845
run: |

‎src/tools/rust-analyzer/.github/workflows/publish-libs.yaml‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ jobs:
1212
if: ${{ github.repository == 'rust-lang/rust-analyzer' || github.event_name == 'workflow_dispatch' }}
1313
name: publish
1414
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
id-token: write
18+
environment: publish-libs
1519
steps:
1620
- name: Checkout repository
1721
uses: actions/checkout@v6
@@ -24,9 +28,12 @@ jobs:
2428
- name: Install cargo-workspaces
2529
run: cargo install --locked cargo-workspaces --version "0.3.6"
2630

31+
- uses: rust-lang/crates-io-auth-action@v1
32+
id: auth
33+
2734
- name: Publish Crates
2835
env:
29-
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
36+
CARGO_REGISTRY_TOKEN: ${{ steps.auth.outputs.token }}
3037
shell: bash
3138
run: |
3239
git config --global user.email "[email protected]"

‎src/tools/rust-analyzer/.github/workflows/release.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ jobs:
236236
- run: ls -al ./dist
237237

238238
- name: Publish Release
239-
uses: ./.github/actions/github-release
239+
uses: $/.github/actions/github-release
240240
with:
241241
files: "dist/*"
242242
name: ${{ env.TAG }}

‎src/tools/rust-analyzer/Cargo.lock‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,7 @@ dependencies = [
873873
"tracing",
874874
"triomphe",
875875
"tt",
876+
"unicode-ident",
876877
]
877878

878879
[[package]]
@@ -2446,9 +2447,9 @@ dependencies = [
24462447

24472448
[[package]]
24482449
name = "salsa"
2449-
version = "0.28.2"
2450+
version = "0.28.5"
24502451
source = "registry+https://github.com/rust-lang/crates.io-index"
2451-
checksum = "cf0e374215cd2db2b5c75d7b3a99cb0cc052c0595335dfdefc03d4eb08f4aa81"
2452+
checksum = "27d2e6e19e39591cd99c01ac4141544b4d012cfd0831348629b8187fa9fe6d34"
24522453
dependencies = [
24532454
"boxcar",
24542455
"crossbeam-queue",
@@ -2473,15 +2474,15 @@ dependencies = [
24732474

24742475
[[package]]
24752476
name = "salsa-macro-rules"
2476-
version = "0.28.2"
2477+
version = "0.28.5"
24772478
source = "registry+https://github.com/rust-lang/crates.io-index"
2478-
checksum = "85f4b7d4405540bbd6d4ffa52d4322d983f3781954d3073067ac1bdb028459b3"
2479+
checksum = "baf90a551c38f25ed8489111d3d5827aa18e1b85963f5e6a298505b1d1e2cb7e"
24792480

24802481
[[package]]
24812482
name = "salsa-macros"
2482-
version = "0.28.2"
2483+
version = "0.28.5"
24832484
source = "registry+https://github.com/rust-lang/crates.io-index"
2484-
checksum = "445be2bfbb2f67cb663225ecd7bc5a25370c0250fca30f9d8cbad9a913650370"
2485+
checksum = "69dd77f86ec10e72e314f4ddf7c44c8d349e73cdff1aad524ba9668603fb0549"
24852486
dependencies = [
24862487
"proc-macro2",
24872488
"quote",

‎src/tools/rust-analyzer/Cargo.toml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ rayon = "1.10.0"
122122
rowan = "0.17.0"
123123
# Ideally we'd not enable the macros feature but unfortunately the `tracked` attribute does not work
124124
# on impls without it
125-
salsa = { version = "0.28.2", default-features = false, features = [
125+
salsa = { version = "0.28.5", default-features = false, features = [
126126
"rayon",
127127
"salsa_unstable",
128128
"macros",
@@ -165,6 +165,10 @@ hashbrown = { version = "0.17.0", features = [
165165
# We need to freeze the version of the crate, as the raw-api feature is considered unstable
166166
dashmap = { version = "=6.2.1", features = ["raw-api", "inline"] }
167167

168+
# We need to freeze this as `1.0.26` breaks the compilation of `rustc_lexer` during our in-tree
169+
# libraries publish
170+
unicode-ident = "=1.0.24"
171+
168172
[workspace.lints.cargo]
169173
unused_dependencies = "allow"
170174

‎src/tools/rust-analyzer/crates/hir-def/Cargo.toml‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ edition.workspace = true
99
license.workspace = true
1010
rust-version.workspace = true
1111

12+
[package.metadata.cargo-machete]
13+
ignored = ["unicode-ident"]
14+
1215
[lib]
1316
doctest = false
1417

@@ -44,6 +47,10 @@ span.workspace = true
4447
thin-vec.workspace = true
4548
syntax-bridge.workspace = true
4649

50+
# This is a transitive dep, but we need to specify this
51+
# for the workspace-wide pinning
52+
unicode-ident.workspace = true
53+
4754
[dev-dependencies]
4855
expect-test.workspace = true
4956

‎src/tools/rust-analyzer/crates/hir-def/src/attrs/docs.rs‎

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//! and highlight injection).
88
99
use std::{
10+
borrow::Cow,
1011
convert::Infallible,
1112
ops::{ControlFlow, Range},
1213
};
@@ -222,9 +223,12 @@ impl Docs {
222223
fn extend_with_doc_attr(&mut self, value: ast::String, indent: &mut Indent) {
223224
let Some(value_offset) = value.text_range_between_quotes() else { return };
224225
let value_offset = value_offset.start();
225-
let Ok(value) = value.value() else { return };
226-
// FIXME: Handle source maps for escaped text.
227-
self.extend_with_doc_str(&value, value_offset, DocCommentKind::Desugared, indent);
226+
let Ok(unescaped) = value.value() else { return };
227+
// `value()` borrows the source text only when the string has no escapes. With escapes,
228+
// offsets in the unescaped text don't match offsets in the source, so leave it unmapped.
229+
// FIXME: Map the text between escapes.
230+
let ast_offset = matches!(unescaped, Cow::Borrowed(_)).then_some(value_offset);
231+
self.push_doc_lines(&unescaped, ast_offset, DocCommentKind::Desugared, indent);
228232
}
229233

230234
fn extend_with_doc_str(
@@ -791,7 +795,7 @@ pub(crate) fn extract_docs<'a, 'db>(
791795
mod tests {
792796
use expect_test::expect;
793797
use hir_expand::InFile;
794-
use syntax::{AstNode, ast};
798+
use syntax::{AstNode, AstToken, ast};
795799
use test_fixture::WithFixture;
796800
use thin_vec::ThinVec;
797801
use tt::{TextRange, TextSize};
@@ -1079,4 +1083,54 @@ mod tests {
10791083
assert_eq!(mapped(0, 3), Some((in_file(range(7, 10)), IsInnerDoc::No)));
10801084
assert_eq!(mapped(4, 7), Some((in_file(range(14, 17)), IsInnerDoc::No)));
10811085
}
1086+
1087+
/// Extracts the docs of the first string in `source`, as if it were a `#[doc = "..."]` value.
1088+
fn doc_attr_docs(source: &str) -> Docs {
1089+
let (_db, file_id) = TestDB::with_single_file("");
1090+
let value = syntax::SourceFile::parse(source, span::Edition::CURRENT)
1091+
.syntax_node()
1092+
.descendants_with_tokens()
1093+
.filter_map(|it| it.into_token())
1094+
.find_map(ast::String::cast)
1095+
.expect("no string in the fixture");
1096+
let mut docs = Docs {
1097+
docs: String::new(),
1098+
docs_source_map: Vec::new(),
1099+
outline_mod: None,
1100+
inline_file: file_id.into(),
1101+
prefix_len: TextSize::new(0),
1102+
inline_inner_docs_start: None,
1103+
outline_inner_docs_start: None,
1104+
macro_calls: ThinVec::new(),
1105+
};
1106+
let mut indent = Indent::default();
1107+
docs.extend_with_doc_attr(value, &mut indent);
1108+
docs.remove_indent(&indent);
1109+
docs.remove_last_newline();
1110+
docs
1111+
}
1112+
1113+
#[test]
1114+
fn doc_attr_source_map() {
1115+
let range = |start, end| TextRange::new(TextSize::new(start), TextSize::new(end));
1116+
let mapped = |docs: &Docs, start, end| {
1117+
docs.find_ast_range(range(start, end)).map(|(range, _)| range.value)
1118+
};
1119+
1120+
// No escapes: `bar` maps back to the source.
1121+
let docs = doc_attr_docs(r#"#[doc = "foo bar"] fn f() {}"#);
1122+
assert_eq!(docs.docs, "foo bar");
1123+
assert_eq!(mapped(&docs, 4, 7), Some(range(13, 16)));
1124+
1125+
// Raw strings have no escapes either.
1126+
let docs = doc_attr_docs(r##"#[doc = r"a\b"] fn f() {}"##);
1127+
assert_eq!(docs.docs, r"a\b");
1128+
assert_eq!(mapped(&docs, 2, 3), Some(range(12, 13)));
1129+
1130+
// With an escape, `b` is at offset 2 in the docs but at offset 3 in the source,
1131+
// so the docs can't be mapped back.
1132+
let docs = doc_attr_docs(r#"#[doc = "a\"b"] fn f() {}"#);
1133+
assert_eq!(docs.docs, "a\"b");
1134+
assert_eq!(mapped(&docs, 2, 3), None);
1135+
}
10821136
}

‎src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower.rs‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1925,7 +1925,11 @@ impl<'db> ExprCollector<'db> {
19251925
self.alloc_expr(Expr::OffsetOf(OffsetOf { container, fields }), syntax_ptr)
19261926
}
19271927
ast::Expr::FormatArgsExpr(f) => self.collect_format_args(f, syntax_ptr),
1928-
ast::Expr::IncludeBytesExpr(_) => self.alloc_expr(Expr::IncludeBytes, syntax_ptr)
1928+
ast::Expr::IncludeBytesExpr(_) => self.alloc_expr(Expr::IncludeBytes, syntax_ptr),
1929+
ast::Expr::CfgPredExpr(e) => {
1930+
let enabled = Expr::Literal(Literal::Bool(self.check_cfg_pred(e.cfg_predicate())));
1931+
self.alloc_expr(enabled, syntax_ptr)
1932+
},
19291933
})
19301934
}
19311935

@@ -3083,6 +3087,11 @@ impl<'db> ExprCollector<'db> {
30833087
}
30843088
ast::Pat::NotNull(_) => Pat::NotNull,
30853089
ast::Pat::ConstBlockPat(_) => Pat::Missing,
3090+
ast::Pat::CfgPredPat(p) => {
3091+
let enabled = Expr::Literal(Literal::Bool(self.check_cfg_pred(p.cfg_predicate())));
3092+
let expr_id = self.alloc_expr_from_pat(enabled, AstPtr::new(&pat));
3093+
Pat::Lit(expr_id)
3094+
}
30863095
ast::Pat::MacroPat(mac) => {
30873096
return self.collect_macro_pat_with(mac.clone(), |this, expanded_pat| {
30883097
this.collect_pat(expanded_pat, binding_list)
@@ -3327,6 +3336,12 @@ impl<'db> ExprCollector<'db> {
33273336
}
33283337
}
33293338

3339+
/// Used for `cfg!()`, conducting imprecise checks
3340+
fn check_cfg_pred(&self, pred: Option<ast::CfgPredicate>) -> bool {
3341+
let expr = pred.map_or(cfg::CfgExpr::Invalid, cfg::CfgExpr::parse_from_ast);
3342+
self.cfg_options.check(&expr) != Some(false)
3343+
}
3344+
33303345
fn add_definition_to_binding(&mut self, binding_id: BindingId, pat_id: PatId) {
33313346
self.store.binding_definitions.entry(binding_id).or_default().push(pat_id);
33323347
}

‎src/tools/rust-analyzer/crates/hir-def/src/expr_store/lower/generics.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,13 @@ impl GenericParamsCollector {
8686

8787
pub(crate) fn finish(self) -> GenericParams {
8888
let Self { mut lifetimes, mut type_or_consts, where_predicates, parent: _ } = self;
89+
let early_bound_lifetimes_len =
90+
lifetimes.iter().filter(|(_, lt)| lt.is_early_bound()).count();
8991

9092
lifetimes.shrink_to_fit();
9193
type_or_consts.shrink_to_fit();
9294
GenericParams {
95+
early_bound_lifetimes_len,
9396
type_or_consts,
9497
lifetimes,
9598
where_predicates: where_predicates.into_boxed_slice(),

‎src/tools/rust-analyzer/crates/hir-def/src/hir/generics.rs‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,15 @@ pub enum LifetimeBoundType {
4444
}
4545

4646
impl LifetimeParamData {
47+
#[inline]
4748
pub fn is_late_bound(&self) -> bool {
4849
self.bound_type == LifetimeBoundType::LateBound
4950
}
51+
52+
#[inline]
53+
pub fn is_early_bound(&self) -> bool {
54+
self.bound_type == LifetimeBoundType::EarlyBound
55+
}
5056
}
5157

5258
/// Data about a generic const parameter (to a function, struct, impl, ...).
@@ -164,6 +170,7 @@ pub struct GenericParams {
164170
pub(crate) type_or_consts: Arena<TypeOrConstParamData>,
165171
pub(crate) lifetimes: Arena<LifetimeParamData>,
166172
pub(crate) where_predicates: Box<[WherePredicate]>,
173+
pub(crate) early_bound_lifetimes_len: usize,
167174
}
168175

169176
impl ops::Index<LocalTypeOrConstParamId> for GenericParams {
@@ -194,6 +201,7 @@ static EMPTY: LazyLock<GenericParams> = LazyLock::new(|| GenericParams {
194201
type_or_consts: Arena::default(),
195202
lifetimes: Arena::default(),
196203
where_predicates: Box::default(),
204+
early_bound_lifetimes_len: 0,
197205
});
198206

199207
impl GenericParams {
@@ -304,14 +312,24 @@ impl GenericParams {
304312
self.type_or_consts.len() + self.lifetimes.len()
305313
}
306314

315+
#[inline]
316+
pub fn len_no_late(&self) -> usize {
317+
self.type_or_consts.len() + self.early_bound_lifetimes_len
318+
}
319+
307320
#[inline]
308321
pub fn len_lifetimes(&self) -> usize {
309-
self.lifetimes.len() - self.len_late_bound_lifetimes()
322+
self.lifetimes.len()
323+
}
324+
325+
#[inline]
326+
pub fn len_early_bound_lifetimes(&self) -> usize {
327+
self.early_bound_lifetimes_len
310328
}
311329

312330
#[inline]
313331
pub fn len_late_bound_lifetimes(&self) -> usize {
314-
self.lifetimes.iter().filter(|(_, p)| p.bound_type == LifetimeBoundType::LateBound).count()
332+
self.len_lifetimes() - self.len_early_bound_lifetimes()
315333
}
316334

317335
#[inline]

0 commit comments

Comments
 (0)