Skip to content

Subtree update of rust-analyzer #141693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 42 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
06da7b3
fixes: ide-assists, generate_new indent loses
A4-Tacks May 12, 2025
6a35b51
fix: ide-assists, generate mut trait impl indent
A4-Tacks May 14, 2025
687eeea
Change import prefix default to be by crate
Veykril May 19, 2025
31b4808
Fix cache problems with lints level
ChayimFriedman2 May 19, 2025
226db31
Correctly set the span of the proc_macro crate's Group delimiters
ChayimFriedman2 May 21, 2025
8acb1b5
internal: fix `integrated_benchmarks` to make actual edits
davidbarsky May 21, 2025
0cb50cd
Merge pull request #19840 from rust-lang/davidbarsky/fix-integrated-b…
ChayimFriedman2 May 21, 2025
2580d83
Merge pull request #19839 from ChayimFriedman2/inlay-hints-attr
Veykril May 21, 2025
1c58418
Merge pull request #19824 from ChayimFriedman2/lints-again
Veykril May 22, 2025
24a416c
Support `transmute_unchecked` intrinsic for mir-eval
Veykril May 22, 2025
b64a934
Merge pull request #19842 from Veykril/push-zunlmrzpnrzk
Veykril May 22, 2025
fb181cf
Remove rust-analyzer.vs from other editors
oli-obk May 22, 2025
11afee4
Merge pull request #19843 from oli-obk/rust-analyzer.vs
Veykril May 22, 2025
f0096ae
Normalize when checking for uninhabited types for pattern exhaustiven…
ChayimFriedman2 May 22, 2025
69ba323
Bump salsa
Veykril May 23, 2025
9d61d8a
Merge pull request #19853 from Veykril/push-ovpvzkxmpsuk
Veykril May 23, 2025
fe18087
Fix IDE resolution of item macros
ChayimFriedman2 May 25, 2025
753c62c
Properly implement `might_be_inside_macro_call()` using semantic info…
ChayimFriedman2 May 25, 2025
a493526
Merge pull request #19864 from ChayimFriedman2/is-in-macro
Veykril May 26, 2025
6b49172
Merge pull request #19851 from ChayimFriedman2/normalize-exhaustiveness
Veykril May 26, 2025
3d67336
Merge pull request #19785 from A4-Tacks/fix-generate-new-indent
Veykril May 26, 2025
376edac
Merge pull request #19819 from Veykril/push-utvzwvwuuvlm
Veykril May 26, 2025
94c624e
Merge pull request #19792 from A4-Tacks/fix-generate-mut-trait-impl-i…
Veykril May 26, 2025
2e9c2ce
Merge pull request #19862 from ChayimFriedman2/item-resolve-macro-hir
ChayimFriedman2 May 26, 2025
7baa85d
Fix inference of `AsyncFnX` return type
ChayimFriedman2 May 27, 2025
68ff7f2
Make `Semantics<'db, DB>` support `Semantics<'db, dyn HirDatabase>`, …
regexident May 26, 2025
5b6ca80
Merge pull request #19850 from regexident/dyn-semantics
ChayimFriedman2 May 27, 2025
a55a370
fix: Skip pattern analysis on type mismatches
ShoyuVanilla May 27, 2025
2c5d840
Merge pull request #19875 from ShoyuVanilla/issue-19844
ChayimFriedman2 May 27, 2025
9f94b13
chore: Remove support for `concat_idents!`
tgross35 May 28, 2025
f67ee9c
Merge pull request #19877 from tgross35/remove-concat-idents
Veykril May 28, 2025
cfe488c
fix: Fix IDE layer not resolving some macro calls
Veykril May 28, 2025
711546a
Drop unnecessay code
Veykril May 28, 2025
7ec351e
Back out "Fix IDE resolution of item macros"
Veykril May 28, 2025
636495c
feat: Render padding information when hovering on structs
ShoyuVanilla May 28, 2025
7840bc0
Merge pull request #19879 from Veykril/push-mqykxnqtktuw
Veykril May 28, 2025
fa22119
Merge pull request #19876 from ShoyuVanilla/layout-padding
Veykril May 28, 2025
457e84f
fix: Handle included files better in IDE layer
Veykril May 28, 2025
035cf40
Merge pull request #19872 from ChayimFriedman2/async-fn-output
Veykril May 28, 2025
c205ef7
Merge pull request #19880 from Veykril/push-xmpxumsrkymk
Veykril May 28, 2025
8231d88
feat: Desugar assist for `let pat = expr?;` -> `let else`
Veykril May 28, 2025
d08ab51
Merge pull request #19881 from Veykril/push-wsrmttkymyps
Veykril May 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
241 changes: 18 additions & 223 deletions src/tools/rust-analyzer/Cargo.lock

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions src/tools/rust-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,8 @@ pulldown-cmark-to-cmark = "10.0.4"
pulldown-cmark = { version = "0.9.6", default-features = false }
rayon = "1.10.0"
rowan = "=0.15.15"
salsa = { version = "0.21.1", default-features = false, features = [
"rayon",
"salsa_unstable",
] }
salsa-macros = "0.21.1"
salsa = { version = "0.22.0", default-features = false, features = ["rayon","salsa_unstable"] }
salsa-macros = "0.22.0"
semver = "1.0.26"
serde = { version = "1.0.219" }
serde_derive = { version = "1.0.219" }
Expand Down
12 changes: 6 additions & 6 deletions src/tools/rust-analyzer/crates/base-db/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,21 +395,21 @@ impl BuiltDependency {
pub type CratesIdMap = FxHashMap<CrateBuilderId, Crate>;

#[salsa_macros::input]
#[derive(Debug)]
#[derive(Debug, PartialOrd, Ord)]
pub struct Crate {
#[return_ref]
#[returns(ref)]
pub data: BuiltCrateData,
/// Crate data that is not needed for analysis.
///
/// This is split into a separate field to increase incrementality.
#[return_ref]
#[returns(ref)]
pub extra_data: ExtraCrateData,
// This is in `Arc` because it is shared for all crates in a workspace.
#[return_ref]
#[returns(ref)]
pub workspace_data: Arc<CrateWorkspaceData>,
#[return_ref]
#[returns(ref)]
pub cfg_options: CfgOptions,
#[return_ref]
#[returns(ref)]
pub env: Env,
}

Expand Down
4 changes: 3 additions & 1 deletion src/tools/rust-analyzer/crates/base-db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub use vfs::{AnchoredPath, AnchoredPathBuf, FileId, VfsPath, file_set::FileSet}
macro_rules! impl_intern_key {
($id:ident, $loc:ident) => {
#[salsa_macros::interned(no_lifetime)]
#[derive(PartialOrd, Ord)]
pub struct $id {
pub loc: $loc,
}
Expand Down Expand Up @@ -165,6 +166,7 @@ impl Files {
}

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

fn parse_errors(db: &dyn RootQueryDb, file_id: EditionedFileId) -> Option<&[SyntaxError]> {
#[salsa_macros::tracked(return_ref)]
#[salsa_macros::tracked(returns(ref))]
fn parse_errors(db: &dyn RootQueryDb, file_id: EditionedFileId) -> Option<Box<[SyntaxError]>> {
let errors = db.parse(file_id).errors();
match &*errors {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir-def/src/lang_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl LangItemTarget {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,24 +509,6 @@ fn main() { "s"; }
);
}

#[test]
fn test_concat_idents_expand() {
check(
r##"
#[rustc_builtin_macro]
macro_rules! concat_idents {}

fn main() { concat_idents!(foo, bar); }
"##,
expect![[r##"
#[rustc_builtin_macro]
macro_rules! concat_idents {}

fn main() { foobar; }
"##]],
);
}

#[test]
fn test_quote_string() {
check(
Expand Down
8 changes: 4 additions & 4 deletions src/tools/rust-analyzer/crates/hir-def/src/nameres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,15 +381,15 @@ mod __ {
#[salsa_macros::tracked]
pub(crate) struct DefMapPair<'db> {
#[tracked]
#[return_ref]
#[returns(ref)]
pub(crate) def_map: DefMap,
#[return_ref]
#[returns(ref)]
pub(crate) local: LocalDefMap,
}
}
pub(crate) use __::DefMapPair;

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

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

Expand Down
4 changes: 2 additions & 2 deletions src/tools/rust-analyzer/crates/hir-def/src/nameres/assoc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl TraitItems {
})
}

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

pub fn attribute_calls(&self) -> impl Iterator<Item = (AstId<ast::Item>, MacroCallId)> + '_ {
pub fn macro_calls(&self) -> impl Iterator<Item = (AstId<ast::Item>, MacroCallId)> + '_ {
self.macro_calls.iter().flat_map(|it| it.iter()).copied()
}
}
Expand Down
23 changes: 12 additions & 11 deletions src/tools/rust-analyzer/crates/hir-def/src/test_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,18 @@ pub(crate) struct TestDB {

impl Default for TestDB {
fn default() -> Self {
let events = <Arc<Mutex<Option<Vec<salsa::Event>>>>>::default();
let mut this = Self {
storage: Default::default(),
events: Default::default(),
storage: salsa::Storage::new(Some(Box::new({
let events = events.clone();
move |event| {
let mut events = events.lock().unwrap();
if let Some(events) = &mut *events {
events.push(event);
}
}
}))),
events,
files: Default::default(),
crates_map: Default::default(),
};
Expand All @@ -45,15 +54,7 @@ impl Default for TestDB {
}

#[salsa_macros::db]
impl salsa::Database for TestDB {
fn salsa_event(&self, event: &dyn std::ops::Fn() -> salsa::Event) {
let mut events = self.events.lock().unwrap();
if let Some(events) = &mut *events {
let event = event();
events.push(event);
}
}
}
impl salsa::Database for TestDB {}

impl fmt::Debug for TestDB {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
25 changes: 0 additions & 25 deletions src/tools/rust-analyzer/crates/hir-expand/src/builtin/fn_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ register_builtin! {
EagerExpander:
(compile_error, CompileError) => compile_error_expand,
(concat, Concat) => concat_expand,
(concat_idents, ConcatIdents) => concat_idents_expand,
(concat_bytes, ConcatBytes) => concat_bytes_expand,
(include, Include) => include_expand,
(include_bytes, IncludeBytes) => include_bytes_expand,
Expand Down Expand Up @@ -660,30 +659,6 @@ fn concat_bytes_expand_subtree(
Ok(())
}

fn concat_idents_expand(
_db: &dyn ExpandDatabase,
_arg_id: MacroCallId,
tt: &tt::TopSubtree,
span: Span,
) -> ExpandResult<tt::TopSubtree> {
let mut err = None;
let mut ident = String::new();
for (i, t) in tt.iter().enumerate() {
match t {
TtElement::Leaf(tt::Leaf::Ident(id)) => {
ident.push_str(id.sym.as_str());
}
TtElement::Leaf(tt::Leaf::Punct(punct)) if i % 2 == 1 && punct.char == ',' => (),
_ => {
err.get_or_insert(ExpandError::other(span, "unexpected token"));
}
}
}
// FIXME merge spans
let ident = tt::Ident { sym: Symbol::intern(&ident), span, is_raw: tt::IdentIsRaw::No };
ExpandResult { value: quote!(span =>#ident), err }
}

fn relative_file(
db: &dyn ExpandDatabase,
call_id: MacroCallId,
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir-ty/src/chalk_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
}
fn well_known_trait_id(
&self,
well_known_trait: rust_ir::WellKnownTrait,
well_known_trait: WellKnownTrait,
) -> Option<chalk_ir::TraitId<Interner>> {
let lang_attr = lang_item_from_well_known_trait(well_known_trait);
let trait_ = lang_attr.resolve_trait(self.db, self.krate)?;
Expand Down
13 changes: 9 additions & 4 deletions src/tools/rust-analyzer/crates/hir-ty/src/diagnostics/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use triomphe::Arc;
use typed_arena::Arena;

use crate::{
Adjust, InferenceResult, Interner, Ty, TyExt, TyKind,
Adjust, InferenceResult, Interner, TraitEnvironment, Ty, TyExt, TyKind,
db::HirDatabase,
diagnostics::match_check::{
self,
Expand Down Expand Up @@ -74,8 +74,9 @@ impl BodyValidationDiagnostic {
let _p = tracing::info_span!("BodyValidationDiagnostic::collect").entered();
let infer = db.infer(owner);
let body = db.body(owner);
let env = db.trait_environment_for_body(owner);
let mut validator =
ExprValidator { owner, body, infer, diagnostics: Vec::new(), validate_lints };
ExprValidator { owner, body, infer, diagnostics: Vec::new(), validate_lints, env };
validator.validate_body(db);
validator.diagnostics
}
Expand All @@ -85,6 +86,7 @@ struct ExprValidator {
owner: DefWithBodyId,
body: Arc<Body>,
infer: Arc<InferenceResult>,
env: Arc<TraitEnvironment>,
diagnostics: Vec<BodyValidationDiagnostic>,
validate_lints: bool,
}
Expand Down Expand Up @@ -190,7 +192,7 @@ impl ExprValidator {
return;
}

let cx = MatchCheckCtx::new(self.owner.module(db), self.owner, db);
let cx = MatchCheckCtx::new(self.owner.module(db), self.owner, db, self.env.clone());

let pattern_arena = Arena::new();
let mut m_arms = Vec::with_capacity(arms.len());
Expand Down Expand Up @@ -317,11 +319,14 @@ impl ExprValidator {
return;
};
let pattern_arena = Arena::new();
let cx = MatchCheckCtx::new(self.owner.module(db), self.owner, db);
let cx = MatchCheckCtx::new(self.owner.module(db), self.owner, db, self.env.clone());
for stmt in &**statements {
let &Statement::Let { pat, initializer, else_branch: None, .. } = stmt else {
continue;
};
if self.infer.type_mismatch_for_pat(pat).is_some() {
continue;
}
let Some(initializer) = initializer else { continue };
let ty = &self.infer[initializer];
if ty.contains_unknown() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ use rustc_pattern_analysis::{
};
use smallvec::{SmallVec, smallvec};
use stdx::never;
use triomphe::Arc;

use crate::{
AdtId, Interner, Scalar, Ty, TyExt, TyKind,
AdtId, Interner, Scalar, TraitEnvironment, Ty, TyExt, TyKind,
db::HirDatabase,
infer::normalize,
inhabitedness::{is_enum_variant_uninhabited_from, is_ty_uninhabited_from},
Expand Down Expand Up @@ -69,13 +70,19 @@ pub(crate) struct MatchCheckCtx<'db> {
body: DefWithBodyId,
pub(crate) db: &'db dyn HirDatabase,
exhaustive_patterns: bool,
env: Arc<TraitEnvironment>,
}

impl<'db> MatchCheckCtx<'db> {
pub(crate) fn new(module: ModuleId, body: DefWithBodyId, db: &'db dyn HirDatabase) -> Self {
pub(crate) fn new(
module: ModuleId,
body: DefWithBodyId,
db: &'db dyn HirDatabase,
env: Arc<TraitEnvironment>,
) -> Self {
let def_map = module.crate_def_map(db);
let exhaustive_patterns = def_map.is_unstable_feature_enabled(&sym::exhaustive_patterns);
Self { module, body, db, exhaustive_patterns }
Self { module, body, db, exhaustive_patterns, env }
}

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

fn is_uninhabited(&self, ty: &Ty) -> bool {
is_ty_uninhabited_from(self.db, ty, self.module)
is_ty_uninhabited_from(self.db, ty, self.module, self.env.clone())
}

/// Returns whether the given ADT is from another crate declared `#[non_exhaustive]`.
Expand Down Expand Up @@ -459,8 +466,13 @@ impl PatCx for MatchCheckCtx<'_> {
} else {
let mut variants = IndexVec::with_capacity(enum_data.variants.len());
for &(variant, _) in enum_data.variants.iter() {
let is_uninhabited =
is_enum_variant_uninhabited_from(cx.db, variant, subst, cx.module);
let is_uninhabited = is_enum_variant_uninhabited_from(
cx.db,
variant,
subst,
cx.module,
self.env.clone(),
);
let visibility = if is_uninhabited {
VariantVisibility::Empty
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/tools/rust-analyzer/crates/hir-ty/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,8 @@ impl HirDisplay for Ty {
}
if f.closure_style == ClosureStyle::RANotation || !sig.ret().is_unit() {
write!(f, " -> ")?;
// FIXME: We display `AsyncFn` as `-> impl Future`, but this is hard to fix because
// we don't have a trait environment here, required to normalize `<Ret as Future>::Output`.
sig.ret().hir_fmt(f)?;
}
} else {
Expand Down
Loading
Loading