Skip to content

Commit ebe9b00

Browse files
committed
Auto merge of rust-lang#141693 - lnicola:sync-from-ra, r=lnicola
Subtree update of `rust-analyzer` r? `@ghost`
2 parents 6f69710 + d08ab51 commit ebe9b00

File tree

62 files changed

+1513
-956
lines changed

Some content is hidden

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

62 files changed

+1513
-956
lines changed

src/tools/rust-analyzer/Cargo.lock

Lines changed: 18 additions & 223 deletions
Large diffs are not rendered by default.

src/tools/rust-analyzer/Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,8 @@ pulldown-cmark-to-cmark = "10.0.4"
132132
pulldown-cmark = { version = "0.9.6", default-features = false }
133133
rayon = "1.10.0"
134134
rowan = "=0.15.15"
135-
salsa = { version = "0.21.1", default-features = false, features = [
136-
"rayon",
137-
"salsa_unstable",
138-
] }
139-
salsa-macros = "0.21.1"
135+
salsa = { version = "0.22.0", default-features = false, features = ["rayon","salsa_unstable"] }
136+
salsa-macros = "0.22.0"
140137
semver = "1.0.26"
141138
serde = { version = "1.0.219" }
142139
serde_derive = { version = "1.0.219" }

src/tools/rust-analyzer/crates/base-db/src/input.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -395,21 +395,21 @@ impl BuiltDependency {
395395
pub type CratesIdMap = FxHashMap<CrateBuilderId, Crate>;
396396

397397
#[salsa_macros::input]
398-
#[derive(Debug)]
398+
#[derive(Debug, PartialOrd, Ord)]
399399
pub struct Crate {
400-
#[return_ref]
400+
#[returns(ref)]
401401
pub data: BuiltCrateData,
402402
/// Crate data that is not needed for analysis.
403403
///
404404
/// This is split into a separate field to increase incrementality.
405-
#[return_ref]
405+
#[returns(ref)]
406406
pub extra_data: ExtraCrateData,
407407
// This is in `Arc` because it is shared for all crates in a workspace.
408-
#[return_ref]
408+
#[returns(ref)]
409409
pub workspace_data: Arc<CrateWorkspaceData>,
410-
#[return_ref]
410+
#[returns(ref)]
411411
pub cfg_options: CfgOptions,
412-
#[return_ref]
412+
#[returns(ref)]
413413
pub env: Env,
414414
}
415415

src/tools/rust-analyzer/crates/base-db/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub use vfs::{AnchoredPath, AnchoredPathBuf, FileId, VfsPath, file_set::FileSet}
3232
macro_rules! impl_intern_key {
3333
($id:ident, $loc:ident) => {
3434
#[salsa_macros::interned(no_lifetime)]
35+
#[derive(PartialOrd, Ord)]
3536
pub struct $id {
3637
pub loc: $loc,
3738
}
@@ -165,6 +166,7 @@ impl Files {
165166
}
166167

167168
#[salsa_macros::interned(no_lifetime, debug, constructor=from_span)]
169+
#[derive(PartialOrd, Ord)]
168170
pub struct EditionedFileId {
169171
pub editioned_file_id: span::EditionedFileId,
170172
}
@@ -356,7 +358,7 @@ fn parse(db: &dyn RootQueryDb, file_id: EditionedFileId) -> Parse<ast::SourceFil
356358
}
357359

358360
fn parse_errors(db: &dyn RootQueryDb, file_id: EditionedFileId) -> Option<&[SyntaxError]> {
359-
#[salsa_macros::tracked(return_ref)]
361+
#[salsa_macros::tracked(returns(ref))]
360362
fn parse_errors(db: &dyn RootQueryDb, file_id: EditionedFileId) -> Option<Box<[SyntaxError]>> {
361363
let errors = db.parse(file_id).errors();
362364
match &*errors {

src/tools/rust-analyzer/crates/hir-def/src/lang_item.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl LangItemTarget {
8585
}
8686

8787
/// Salsa query. This will look for lang items in a specific crate.
88-
#[salsa_macros::tracked(return_ref)]
88+
#[salsa_macros::tracked(returns(ref))]
8989
pub fn crate_lang_items(db: &dyn DefDatabase, krate: Crate) -> Option<Box<LangItems>> {
9090
let _p = tracing::info_span!("crate_lang_items_query").entered();
9191

src/tools/rust-analyzer/crates/hir-def/src/macro_expansion_tests/builtin_fn_macro.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -509,24 +509,6 @@ fn main() { "s"; }
509509
);
510510
}
511511

512-
#[test]
513-
fn test_concat_idents_expand() {
514-
check(
515-
r##"
516-
#[rustc_builtin_macro]
517-
macro_rules! concat_idents {}
518-
519-
fn main() { concat_idents!(foo, bar); }
520-
"##,
521-
expect![[r##"
522-
#[rustc_builtin_macro]
523-
macro_rules! concat_idents {}
524-
525-
fn main() { foobar; }
526-
"##]],
527-
);
528-
}
529-
530512
#[test]
531513
fn test_quote_string() {
532514
check(

src/tools/rust-analyzer/crates/hir-def/src/nameres.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,15 +381,15 @@ mod __ {
381381
#[salsa_macros::tracked]
382382
pub(crate) struct DefMapPair<'db> {
383383
#[tracked]
384-
#[return_ref]
384+
#[returns(ref)]
385385
pub(crate) def_map: DefMap,
386-
#[return_ref]
386+
#[returns(ref)]
387387
pub(crate) local: LocalDefMap,
388388
}
389389
}
390390
pub(crate) use __::DefMapPair;
391391

392-
#[salsa_macros::tracked(return_ref)]
392+
#[salsa_macros::tracked(returns(ref))]
393393
pub(crate) fn crate_local_def_map(db: &dyn DefDatabase, crate_id: Crate) -> DefMapPair<'_> {
394394
let krate = crate_id.data(db);
395395
let _p = tracing::info_span!(
@@ -420,7 +420,7 @@ pub(crate) fn crate_local_def_map(db: &dyn DefDatabase, crate_id: Crate) -> DefM
420420
DefMapPair::new(db, def_map, local_def_map)
421421
}
422422

423-
#[salsa_macros::tracked(return_ref)]
423+
#[salsa_macros::tracked(returns(ref))]
424424
pub fn block_def_map(db: &dyn DefDatabase, block_id: BlockId) -> DefMap {
425425
let BlockLoc { ast_id, module } = block_id.lookup(db);
426426

src/tools/rust-analyzer/crates/hir-def/src/nameres/assoc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl TraitItems {
7575
})
7676
}
7777

78-
pub fn attribute_calls(&self) -> impl Iterator<Item = (AstId<ast::Item>, MacroCallId)> + '_ {
78+
pub fn macro_calls(&self) -> impl Iterator<Item = (AstId<ast::Item>, MacroCallId)> + '_ {
7979
self.macro_calls.iter().flat_map(|it| it.iter()).copied()
8080
}
8181
}
@@ -109,7 +109,7 @@ impl ImplItems {
109109
(Arc::new(ImplItems { items, macro_calls }), DefDiagnostics::new(diagnostics))
110110
}
111111

112-
pub fn attribute_calls(&self) -> impl Iterator<Item = (AstId<ast::Item>, MacroCallId)> + '_ {
112+
pub fn macro_calls(&self) -> impl Iterator<Item = (AstId<ast::Item>, MacroCallId)> + '_ {
113113
self.macro_calls.iter().flat_map(|it| it.iter()).copied()
114114
}
115115
}

src/tools/rust-analyzer/crates/hir-def/src/test_db.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,18 @@ pub(crate) struct TestDB {
3030

3131
impl Default for TestDB {
3232
fn default() -> Self {
33+
let events = <Arc<Mutex<Option<Vec<salsa::Event>>>>>::default();
3334
let mut this = Self {
34-
storage: Default::default(),
35-
events: Default::default(),
35+
storage: salsa::Storage::new(Some(Box::new({
36+
let events = events.clone();
37+
move |event| {
38+
let mut events = events.lock().unwrap();
39+
if let Some(events) = &mut *events {
40+
events.push(event);
41+
}
42+
}
43+
}))),
44+
events,
3645
files: Default::default(),
3746
crates_map: Default::default(),
3847
};
@@ -45,15 +54,7 @@ impl Default for TestDB {
4554
}
4655

4756
#[salsa_macros::db]
48-
impl salsa::Database for TestDB {
49-
fn salsa_event(&self, event: &dyn std::ops::Fn() -> salsa::Event) {
50-
let mut events = self.events.lock().unwrap();
51-
if let Some(events) = &mut *events {
52-
let event = event();
53-
events.push(event);
54-
}
55-
}
56-
}
57+
impl salsa::Database for TestDB {}
5758

5859
impl fmt::Debug for TestDB {
5960
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {

src/tools/rust-analyzer/crates/hir-expand/src/builtin/fn_macro.rs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ register_builtin! {
140140
EagerExpander:
141141
(compile_error, CompileError) => compile_error_expand,
142142
(concat, Concat) => concat_expand,
143-
(concat_idents, ConcatIdents) => concat_idents_expand,
144143
(concat_bytes, ConcatBytes) => concat_bytes_expand,
145144
(include, Include) => include_expand,
146145
(include_bytes, IncludeBytes) => include_bytes_expand,
@@ -660,30 +659,6 @@ fn concat_bytes_expand_subtree(
660659
Ok(())
661660
}
662661

663-
fn concat_idents_expand(
664-
_db: &dyn ExpandDatabase,
665-
_arg_id: MacroCallId,
666-
tt: &tt::TopSubtree,
667-
span: Span,
668-
) -> ExpandResult<tt::TopSubtree> {
669-
let mut err = None;
670-
let mut ident = String::new();
671-
for (i, t) in tt.iter().enumerate() {
672-
match t {
673-
TtElement::Leaf(tt::Leaf::Ident(id)) => {
674-
ident.push_str(id.sym.as_str());
675-
}
676-
TtElement::Leaf(tt::Leaf::Punct(punct)) if i % 2 == 1 && punct.char == ',' => (),
677-
_ => {
678-
err.get_or_insert(ExpandError::other(span, "unexpected token"));
679-
}
680-
}
681-
}
682-
// FIXME merge spans
683-
let ident = tt::Ident { sym: Symbol::intern(&ident), span, is_raw: tt::IdentIsRaw::No };
684-
ExpandResult { value: quote!(span =>#ident), err }
685-
}
686-
687662
fn relative_file(
688663
db: &dyn ExpandDatabase,
689664
call_id: MacroCallId,

src/tools/rust-analyzer/crates/hir-ty/src/chalk_db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
259259
}
260260
fn well_known_trait_id(
261261
&self,
262-
well_known_trait: rust_ir::WellKnownTrait,
262+
well_known_trait: WellKnownTrait,
263263
) -> Option<chalk_ir::TraitId<Interner>> {
264264
let lang_attr = lang_item_from_well_known_trait(well_known_trait);
265265
let trait_ = lang_attr.resolve_trait(self.db, self.krate)?;

src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/expr.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use triomphe::Arc;
2525
use typed_arena::Arena;
2626

2727
use crate::{
28-
Adjust, InferenceResult, Interner, Ty, TyExt, TyKind,
28+
Adjust, InferenceResult, Interner, TraitEnvironment, Ty, TyExt, TyKind,
2929
db::HirDatabase,
3030
diagnostics::match_check::{
3131
self,
@@ -74,8 +74,9 @@ impl BodyValidationDiagnostic {
7474
let _p = tracing::info_span!("BodyValidationDiagnostic::collect").entered();
7575
let infer = db.infer(owner);
7676
let body = db.body(owner);
77+
let env = db.trait_environment_for_body(owner);
7778
let mut validator =
78-
ExprValidator { owner, body, infer, diagnostics: Vec::new(), validate_lints };
79+
ExprValidator { owner, body, infer, diagnostics: Vec::new(), validate_lints, env };
7980
validator.validate_body(db);
8081
validator.diagnostics
8182
}
@@ -85,6 +86,7 @@ struct ExprValidator {
8586
owner: DefWithBodyId,
8687
body: Arc<Body>,
8788
infer: Arc<InferenceResult>,
89+
env: Arc<TraitEnvironment>,
8890
diagnostics: Vec<BodyValidationDiagnostic>,
8991
validate_lints: bool,
9092
}
@@ -190,7 +192,7 @@ impl ExprValidator {
190192
return;
191193
}
192194

193-
let cx = MatchCheckCtx::new(self.owner.module(db), self.owner, db);
195+
let cx = MatchCheckCtx::new(self.owner.module(db), self.owner, db, self.env.clone());
194196

195197
let pattern_arena = Arena::new();
196198
let mut m_arms = Vec::with_capacity(arms.len());
@@ -317,11 +319,14 @@ impl ExprValidator {
317319
return;
318320
};
319321
let pattern_arena = Arena::new();
320-
let cx = MatchCheckCtx::new(self.owner.module(db), self.owner, db);
322+
let cx = MatchCheckCtx::new(self.owner.module(db), self.owner, db, self.env.clone());
321323
for stmt in &**statements {
322324
let &Statement::Let { pat, initializer, else_branch: None, .. } = stmt else {
323325
continue;
324326
};
327+
if self.infer.type_mismatch_for_pat(pat).is_some() {
328+
continue;
329+
}
325330
let Some(initializer) = initializer else { continue };
326331
let ty = &self.infer[initializer];
327332
if ty.contains_unknown() {

src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ use rustc_pattern_analysis::{
1212
};
1313
use smallvec::{SmallVec, smallvec};
1414
use stdx::never;
15+
use triomphe::Arc;
1516

1617
use crate::{
17-
AdtId, Interner, Scalar, Ty, TyExt, TyKind,
18+
AdtId, Interner, Scalar, TraitEnvironment, Ty, TyExt, TyKind,
1819
db::HirDatabase,
1920
infer::normalize,
2021
inhabitedness::{is_enum_variant_uninhabited_from, is_ty_uninhabited_from},
@@ -69,13 +70,19 @@ pub(crate) struct MatchCheckCtx<'db> {
6970
body: DefWithBodyId,
7071
pub(crate) db: &'db dyn HirDatabase,
7172
exhaustive_patterns: bool,
73+
env: Arc<TraitEnvironment>,
7274
}
7375

7476
impl<'db> MatchCheckCtx<'db> {
75-
pub(crate) fn new(module: ModuleId, body: DefWithBodyId, db: &'db dyn HirDatabase) -> Self {
77+
pub(crate) fn new(
78+
module: ModuleId,
79+
body: DefWithBodyId,
80+
db: &'db dyn HirDatabase,
81+
env: Arc<TraitEnvironment>,
82+
) -> Self {
7683
let def_map = module.crate_def_map(db);
7784
let exhaustive_patterns = def_map.is_unstable_feature_enabled(&sym::exhaustive_patterns);
78-
Self { module, body, db, exhaustive_patterns }
85+
Self { module, body, db, exhaustive_patterns, env }
7986
}
8087

8188
pub(crate) fn compute_match_usefulness(
@@ -100,7 +107,7 @@ impl<'db> MatchCheckCtx<'db> {
100107
}
101108

102109
fn is_uninhabited(&self, ty: &Ty) -> bool {
103-
is_ty_uninhabited_from(self.db, ty, self.module)
110+
is_ty_uninhabited_from(self.db, ty, self.module, self.env.clone())
104111
}
105112

106113
/// Returns whether the given ADT is from another crate declared `#[non_exhaustive]`.
@@ -459,8 +466,13 @@ impl PatCx for MatchCheckCtx<'_> {
459466
} else {
460467
let mut variants = IndexVec::with_capacity(enum_data.variants.len());
461468
for &(variant, _) in enum_data.variants.iter() {
462-
let is_uninhabited =
463-
is_enum_variant_uninhabited_from(cx.db, variant, subst, cx.module);
469+
let is_uninhabited = is_enum_variant_uninhabited_from(
470+
cx.db,
471+
variant,
472+
subst,
473+
cx.module,
474+
self.env.clone(),
475+
);
464476
let visibility = if is_uninhabited {
465477
VariantVisibility::Empty
466478
} else {

src/tools/rust-analyzer/crates/hir-ty/src/display.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,8 @@ impl HirDisplay for Ty {
14631463
}
14641464
if f.closure_style == ClosureStyle::RANotation || !sig.ret().is_unit() {
14651465
write!(f, " -> ")?;
1466+
// FIXME: We display `AsyncFn` as `-> impl Future`, but this is hard to fix because
1467+
// we don't have a trait environment here, required to normalize `<Ret as Future>::Output`.
14661468
sig.ret().hir_fmt(f)?;
14671469
}
14681470
} else {

0 commit comments

Comments
 (0)