Skip to content

Commit 398af02

Browse files
Merge branch 'master' into alias-based-completion2
2 parents 33ee157 + 7501d3b commit 398af02

File tree

172 files changed

+5165
-5934
lines changed

Some content is hidden

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

172 files changed

+5165
-5934
lines changed

.github/workflows/ci.yaml

+6-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ jobs:
2424
runs-on: ${{ matrix.os }}
2525
env:
2626
CC: deny_c
27+
# we want to build r-a on stable to check that it keeps building on stable,
28+
# but we also want to test our proc-macro-srv which depends on nightly features
29+
RUSTC_BOOTSTRAP: 1
2730

2831
strategy:
2932
fail-fast: false
@@ -50,15 +53,15 @@ jobs:
5053
run: sed -i '/\[profile.dev]/a opt-level=1' Cargo.toml
5154

5255
- name: Compile (tests)
53-
run: cargo test --no-run --locked
56+
run: cargo test --no-run --locked --features sysroot-abi
5457

5558
# It's faster to `test` before `build` ¯\_(ツ)_/¯
5659
- name: Compile (rust-analyzer)
5760
if: matrix.os == 'ubuntu-latest'
58-
run: cargo build --quiet
61+
run: cargo build --quiet --features sysroot-abi
5962

6063
- name: Test
61-
run: cargo test -- --nocapture --quiet
64+
run: cargo test --features sysroot-abi -- --nocapture --quiet
6265

6366
- name: Run analysis-stats on rust-analyzer
6467
if: matrix.os == 'ubuntu-latest'

Cargo.lock

+4-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ vfs = { path = "./crates/vfs", version = "0.0.0" }
7777

7878
# non-local crates
7979
smallvec = { version = "1.10.0", features = ["const_new", "union", "const_generics"] }
80+
smol_str = "0.2.0"
8081
# the following crates are pinned to prevent us from pulling in syn 2 until all our dependencies have moved
8182
serde = { version = "=1.0.156", features = ["derive"] }
8283
serde_json = "1.0.94"

crates/base-db/src/fixture.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ use std::{mem, str::FromStr, sync::Arc};
44
use cfg::CfgOptions;
55
use rustc_hash::FxHashMap;
66
use test_utils::{
7-
extract_range_or_offset, Fixture, RangeOrOffset, CURSOR_MARKER, ESCAPED_CURSOR_MARKER,
7+
extract_range_or_offset, Fixture, FixtureWithProjectMeta, RangeOrOffset, CURSOR_MARKER,
8+
ESCAPED_CURSOR_MARKER,
89
};
910
use tt::token_id::{Leaf, Subtree, TokenTree};
1011
use vfs::{file_set::FileSet, VfsPath};
1112

1213
use crate::{
1314
input::{CrateName, CrateOrigin, LangCrateOrigin},
1415
Change, CrateDisplayName, CrateGraph, CrateId, Dependency, Edition, Env, FileId, FilePosition,
15-
FileRange, ProcMacro, ProcMacroExpander, ProcMacroExpansionError, ProcMacros,
16+
FileRange, ProcMacro, ProcMacroExpander, ProcMacroExpansionError, ProcMacros, ReleaseChannel,
1617
SourceDatabaseExt, SourceRoot, SourceRootId,
1718
};
1819

@@ -102,7 +103,14 @@ impl ChangeFixture {
102103
ra_fixture: &str,
103104
mut proc_macro_defs: Vec<(String, ProcMacro)>,
104105
) -> ChangeFixture {
105-
let (mini_core, proc_macro_names, fixture) = Fixture::parse(ra_fixture);
106+
let FixtureWithProjectMeta { fixture, mini_core, proc_macro_names, toolchain } =
107+
FixtureWithProjectMeta::parse(ra_fixture);
108+
let toolchain = toolchain
109+
.map(|it| {
110+
ReleaseChannel::from_str(&it)
111+
.unwrap_or_else(|| panic!("unknown release channel found: {it}"))
112+
})
113+
.unwrap_or(ReleaseChannel::Stable);
106114
let mut change = Change::new();
107115

108116
let mut files = Vec::new();
@@ -166,7 +174,7 @@ impl ChangeFixture {
166174
.as_deref()
167175
.map(Arc::from)
168176
.ok_or_else(|| "target_data_layout unset".into()),
169-
None,
177+
Some(toolchain),
170178
);
171179
let prev = crates.insert(crate_name.clone(), crate_id);
172180
assert!(prev.is_none());
@@ -205,7 +213,7 @@ impl ChangeFixture {
205213
default_target_data_layout
206214
.map(|x| x.into())
207215
.ok_or_else(|| "target_data_layout unset".into()),
208-
None,
216+
Some(toolchain),
209217
);
210218
} else {
211219
for (from, to, prelude) in crate_deps {
@@ -247,7 +255,7 @@ impl ChangeFixture {
247255
false,
248256
CrateOrigin::Lang(LangCrateOrigin::Core),
249257
target_layout.clone(),
250-
None,
258+
Some(toolchain),
251259
);
252260

253261
for krate in all_crates {
@@ -286,7 +294,7 @@ impl ChangeFixture {
286294
true,
287295
CrateOrigin::Local { repo: None, name: None },
288296
target_layout,
289-
None,
297+
Some(toolchain),
290298
);
291299
proc_macros.insert(proc_macros_crate, Ok(proc_macro));
292300

crates/hir-def/src/attr.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! A higher level attributes based on TokenTree, with also some shortcuts.
22
3+
pub mod builtin;
4+
35
#[cfg(test)]
46
mod tests;
57

@@ -267,6 +269,10 @@ impl Attrs {
267269
pub fn is_proc_macro_derive(&self) -> bool {
268270
self.by_key("proc_macro_derive").exists()
269271
}
272+
273+
pub fn is_unstable(&self) -> bool {
274+
self.by_key("unstable").exists()
275+
}
270276
}
271277

272278
use std::slice::Iter as SliceIter;

crates/hir-def/src/body.rs

+52-4
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@ use cfg::{CfgExpr, CfgOptions};
1313
use drop_bomb::DropBomb;
1414
use either::Either;
1515
use hir_expand::{
16-
attrs::RawAttrs, hygiene::Hygiene, ExpandError, ExpandResult, HirFileId, InFile, MacroCallId,
16+
ast_id_map::AstIdMap, attrs::RawAttrs, hygiene::Hygiene, name::Name, AstId, ExpandError,
17+
ExpandResult, HirFileId, InFile, MacroCallId,
1718
};
1819
use la_arena::{Arena, ArenaMap};
1920
use limit::Limit;
21+
use once_cell::unsync::OnceCell;
2022
use profile::Count;
2123
use rustc_hash::FxHashMap;
2224
use syntax::{ast, AstPtr, SyntaxNode, SyntaxNodePtr};
2325

2426
use crate::{
2527
attr::Attrs,
2628
db::DefDatabase,
27-
expr::{
29+
hir::{
2830
dummy_expr_id, Binding, BindingId, Expr, ExprId, Label, LabelId, Pat, PatId, RecordFieldPat,
2931
},
3032
item_scope::BuiltinShadowMode,
@@ -36,7 +38,43 @@ use crate::{
3638
UnresolvedMacro,
3739
};
3840

39-
pub use lower::LowerCtx;
41+
pub struct LowerCtx<'a> {
42+
pub db: &'a dyn DefDatabase,
43+
hygiene: Hygiene,
44+
ast_id_map: Option<(HirFileId, OnceCell<Arc<AstIdMap>>)>,
45+
}
46+
47+
impl<'a> LowerCtx<'a> {
48+
pub fn new(db: &'a dyn DefDatabase, hygiene: &Hygiene, file_id: HirFileId) -> Self {
49+
LowerCtx { db, hygiene: hygiene.clone(), ast_id_map: Some((file_id, OnceCell::new())) }
50+
}
51+
52+
pub fn with_file_id(db: &'a dyn DefDatabase, file_id: HirFileId) -> Self {
53+
LowerCtx {
54+
db,
55+
hygiene: Hygiene::new(db.upcast(), file_id),
56+
ast_id_map: Some((file_id, OnceCell::new())),
57+
}
58+
}
59+
60+
pub fn with_hygiene(db: &'a dyn DefDatabase, hygiene: &Hygiene) -> Self {
61+
LowerCtx { db, hygiene: hygiene.clone(), ast_id_map: None }
62+
}
63+
64+
pub(crate) fn hygiene(&self) -> &Hygiene {
65+
&self.hygiene
66+
}
67+
68+
pub(crate) fn lower_path(&self, ast: ast::Path) -> Option<Path> {
69+
Path::from_src(ast, self)
70+
}
71+
72+
pub(crate) fn ast_id<N: syntax::AstNode>(&self, item: &N) -> Option<AstId<N>> {
73+
let &(file_id, ref ast_id_map) = self.ast_id_map.as_ref()?;
74+
let ast_id_map = ast_id_map.get_or_init(|| self.db.ast_id_map(file_id));
75+
Some(InFile::new(file_id, ast_id_map.ast_id(item)))
76+
}
77+
}
4078

4179
/// A subset of Expander that only deals with cfg attributes. We only need it to
4280
/// avoid cyclic queries in crate def map during enum processing.
@@ -76,6 +114,10 @@ impl CfgExpander {
76114
let attrs = self.parse_attrs(db, owner);
77115
attrs.is_cfg_enabled(&self.cfg_options)
78116
}
117+
118+
pub(crate) fn hygiene(&self) -> &Hygiene {
119+
&self.hygiene
120+
}
79121
}
80122

81123
impl Expander {
@@ -180,6 +222,10 @@ impl Expander {
180222
mark.bomb.defuse();
181223
}
182224

225+
pub fn ctx<'a>(&self, db: &'a dyn DefDatabase) -> LowerCtx<'a> {
226+
LowerCtx::new(db, &self.cfg_expander.hygiene, self.current_file_id)
227+
}
228+
183229
pub(crate) fn to_source<T>(&self, value: T) -> InFile<T> {
184230
InFile { file_id: self.current_file_id, value }
185231
}
@@ -232,7 +278,7 @@ impl Expander {
232278
// The overflow error should have been reported when it occurred (see the next branch),
233279
// so don't return overflow error here to avoid diagnostics duplication.
234280
cov_mark::hit!(overflow_but_not_me);
235-
return ExpandResult::only_err(ExpandError::RecursionOverflowPosioned);
281+
return ExpandResult::only_err(ExpandError::RecursionOverflowPoisoned);
236282
} else if self.recursion_limit(db).check(self.recursion_depth + 1).is_err() {
237283
self.recursion_depth = usize::MAX;
238284
cov_mark::hit!(your_stack_belongs_to_me);
@@ -343,6 +389,8 @@ pub enum BodyDiagnostic {
343389
MacroError { node: InFile<AstPtr<ast::MacroCall>>, message: String },
344390
UnresolvedProcMacro { node: InFile<AstPtr<ast::MacroCall>>, krate: CrateId },
345391
UnresolvedMacroCall { node: InFile<AstPtr<ast::MacroCall>>, path: ModPath },
392+
UnreachableLabel { node: InFile<AstPtr<ast::Lifetime>>, name: Name },
393+
UndeclaredLabel { node: InFile<AstPtr<ast::Lifetime>>, name: Name },
346394
}
347395

348396
impl Body {

0 commit comments

Comments
 (0)