Skip to content

Commit

Permalink
Auto merge of rust-lang#132594 - 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 Nov 4, 2024
2 parents 82c24ec + 0cd3fb2 commit fbab782
Show file tree
Hide file tree
Showing 68 changed files with 1,907 additions and 849 deletions.
1 change: 1 addition & 0 deletions src/tools/rust-analyzer/.github/workflows/autopublish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ jobs:
cargo workspaces rename --from proc-macro-api proc_macro_api
cargo workspaces rename --from proc-macro-srv proc_macro_srv
cargo workspaces rename --from project-model project_model
cargo workspaces rename --from test-fixture test_fixture
cargo workspaces rename --from test-utils test_utils
cargo workspaces rename --from text-edit text_edit
# Remove library crates from the workspaces so we don't auto-publish them as well
Expand Down
24 changes: 12 additions & 12 deletions src/tools/rust-analyzer/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1492,9 +1492,9 @@ dependencies = [

[[package]]
name = "ra-ap-rustc_abi"
version = "0.75.0"
version = "0.76.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d5bc2cfc7264d84215a08875ef90a1d35f76b5c9ad1993515d2da7e4e40b2b4b"
checksum = "709fde78db053c78c87776ec738677649f791645883f82ff145f68caf9f18e1a"
dependencies = [
"bitflags 2.6.0",
"ra-ap-rustc_index",
Expand All @@ -1503,9 +1503,9 @@ dependencies = [

[[package]]
name = "ra-ap-rustc_index"
version = "0.75.0"
version = "0.76.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8929140697812e5dd09e19cf446d85146332363f0dbc125d4214834c34ead96"
checksum = "da115d496e5abd65e2dceb6883d7597593badfe23fea3439202b8da5a11ea250"
dependencies = [
"arrayvec",
"ra-ap-rustc_index_macros",
Expand All @@ -1514,9 +1514,9 @@ dependencies = [

[[package]]
name = "ra-ap-rustc_index_macros"
version = "0.75.0"
version = "0.76.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "514a3f5d04c8b4a2750f29746cc9abb1f78deb7e72e4ad1dc95bbc608f3db157"
checksum = "be86d06a75a8125c1ace197d5030e6e02721348d32e572baea35c891669ad1e2"
dependencies = [
"proc-macro2",
"quote",
Expand All @@ -1525,29 +1525,29 @@ dependencies = [

[[package]]
name = "ra-ap-rustc_lexer"
version = "0.75.0"
version = "0.76.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "276fcb1205da071a0cd64416f3f0e198043c11f176c5b501a45dbf0cb33979f2"
checksum = "b64b46ae0d8f59acc32e64e0085532b831f0d6182d870a7cd86c046c2c46e722"
dependencies = [
"unicode-properties",
"unicode-xid",
]

[[package]]
name = "ra-ap-rustc_parse_format"
version = "0.75.0"
version = "0.76.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "961b30b22cfac296b14b72e9f95e79c16cebc8c926872755fb1568a6c4243a62"
checksum = "dbdaad19ddbd0ff46e947ca8dbb6ae678a112d3938669fb3ad6bfd244917e24b"
dependencies = [
"ra-ap-rustc_index",
"ra-ap-rustc_lexer",
]

[[package]]
name = "ra-ap-rustc_pattern_analysis"
version = "0.75.0"
version = "0.76.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "614232513814a4b714fea7f11345d31c0c277bca3089bb6ca1ec20870bfc022a"
checksum = "dc5761e37c78d98ede9f20f6b66526093d0be66aa256d5cbdf214495843ba74d"
dependencies = [
"ra-ap-rustc_index",
"rustc-hash 2.0.0",
Expand Down
10 changes: 5 additions & 5 deletions src/tools/rust-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ tt = { path = "./crates/tt", version = "0.0.0" }
vfs-notify = { path = "./crates/vfs-notify", version = "0.0.0" }
vfs = { path = "./crates/vfs", version = "0.0.0" }

ra-ap-rustc_lexer = { version = "0.75", default-features = false }
ra-ap-rustc_parse_format = { version = "0.75", default-features = false }
ra-ap-rustc_index = { version = "0.75", default-features = false }
ra-ap-rustc_abi = { version = "0.75", default-features = false }
ra-ap-rustc_pattern_analysis = { version = "0.75", default-features = false }
ra-ap-rustc_lexer = { version = "0.76", default-features = false }
ra-ap-rustc_parse_format = { version = "0.76", default-features = false }
ra-ap-rustc_index = { version = "0.76", default-features = false }
ra-ap-rustc_abi = { version = "0.76", default-features = false }
ra-ap-rustc_pattern_analysis = { version = "0.76", default-features = false }

# local crates that aren't published to crates.io. These should not have versions.
test-fixture = { path = "./crates/test-fixture" }
Expand Down
16 changes: 9 additions & 7 deletions src/tools/rust-analyzer/crates/hir-def/src/body/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ impl ExprCollector<'_> {
let method_name = e.name_ref().map(|nr| nr.as_name()).unwrap_or_else(Name::missing);
let generic_args = e
.generic_arg_list()
.and_then(|it| GenericArgs::from_ast(&self.ctx(), it))
.and_then(|it| GenericArgs::from_ast(&mut self.ctx(), it))
.map(Box::new);
self.alloc_expr(
Expr::MethodCall { receiver, method_name, args, generic_args },
Expand Down Expand Up @@ -533,7 +533,7 @@ impl ExprCollector<'_> {
ast::Expr::TryExpr(e) => self.collect_try_operator(syntax_ptr, e),
ast::Expr::CastExpr(e) => {
let expr = self.collect_expr_opt(e.expr());
let type_ref = TypeRef::from_ast_opt(&self.ctx(), e.ty());
let type_ref = TypeRef::from_ast_opt(&mut self.ctx(), e.ty());
self.alloc_expr(Expr::Cast { expr, type_ref }, syntax_ptr)
}
ast::Expr::RefExpr(e) => {
Expand Down Expand Up @@ -572,13 +572,15 @@ impl ExprCollector<'_> {
arg_types.reserve_exact(num_params);
for param in pl.params() {
let pat = this.collect_pat_top(param.pat());
let type_ref = param.ty().map(|it| TypeRef::from_ast(&this.ctx(), it));
let type_ref = param.ty().map(|it| TypeRef::from_ast(&mut this.ctx(), it));
args.push(pat);
arg_types.push(type_ref);
}
}
let ret_type =
e.ret_type().and_then(|r| r.ty()).map(|it| TypeRef::from_ast(&this.ctx(), it));
let ret_type = e
.ret_type()
.and_then(|r| r.ty())
.map(|it| TypeRef::from_ast(&mut this.ctx(), it));

let prev_is_lowering_coroutine = mem::take(&mut this.is_lowering_coroutine);
let prev_try_block_label = this.current_try_block_label.take();
Expand Down Expand Up @@ -705,7 +707,7 @@ impl ExprCollector<'_> {
ast::Expr::UnderscoreExpr(_) => self.alloc_expr(Expr::Underscore, syntax_ptr),
ast::Expr::AsmExpr(e) => self.lower_inline_asm(e, syntax_ptr),
ast::Expr::OffsetOfExpr(e) => {
let container = TypeRef::from_ast_opt(&self.ctx(), e.ty());
let container = TypeRef::from_ast_opt(&mut self.ctx(), e.ty());
let fields = e.fields().map(|it| it.as_name()).collect();
self.alloc_expr(Expr::OffsetOf(OffsetOf { container, fields }), syntax_ptr)
}
Expand Down Expand Up @@ -1317,7 +1319,7 @@ impl ExprCollector<'_> {
return;
}
let pat = self.collect_pat_top(stmt.pat());
let type_ref = stmt.ty().map(|it| TypeRef::from_ast(&self.ctx(), it));
let type_ref = stmt.ty().map(|it| TypeRef::from_ast(&mut self.ctx(), it));
let initializer = stmt.initializer().map(|e| self.collect_expr(e));
let else_branch = stmt
.let_else()
Expand Down
1 change: 1 addition & 0 deletions src/tools/rust-analyzer/crates/hir-def/src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub struct FunctionData {
pub name: Name,
pub params: Box<[TypeRefId]>,
pub ret_type: TypeRefId,
// FIXME: why are these stored here? They should be accessed via the query
pub attrs: Attrs,
pub visibility: RawVisibility,
pub abi: Option<Symbol>,
Expand Down
74 changes: 73 additions & 1 deletion src/tools/rust-analyzer/crates/hir-def/src/dyn_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,79 @@
//!
//! This is a work of fiction. Any similarities to Kotlin's `BindingContext` are
//! a coincidence.
pub mod keys;

pub mod keys {
use std::marker::PhantomData;

use hir_expand::{attrs::AttrId, MacroCallId};
use rustc_hash::FxHashMap;
use syntax::{ast, AstNode, AstPtr};

use crate::{
dyn_map::{DynMap, Policy},
BlockId, ConstId, EnumId, EnumVariantId, ExternCrateId, FieldId, FunctionId, ImplId,
LifetimeParamId, Macro2Id, MacroRulesId, ProcMacroId, StaticId, StructId, TraitAliasId,
TraitId, TypeAliasId, TypeOrConstParamId, UnionId, UseId,
};

pub type Key<K, V> = crate::dyn_map::Key<AstPtr<K>, V, AstPtrPolicy<K, V>>;

pub const BLOCK: Key<ast::BlockExpr, BlockId> = Key::new();
pub const FUNCTION: Key<ast::Fn, FunctionId> = Key::new();
pub const CONST: Key<ast::Const, ConstId> = Key::new();
pub const STATIC: Key<ast::Static, StaticId> = Key::new();
pub const TYPE_ALIAS: Key<ast::TypeAlias, TypeAliasId> = Key::new();
pub const IMPL: Key<ast::Impl, ImplId> = Key::new();
pub const TRAIT: Key<ast::Trait, TraitId> = Key::new();
pub const TRAIT_ALIAS: Key<ast::TraitAlias, TraitAliasId> = Key::new();
pub const STRUCT: Key<ast::Struct, StructId> = Key::new();
pub const UNION: Key<ast::Union, UnionId> = Key::new();
pub const ENUM: Key<ast::Enum, EnumId> = Key::new();
pub const EXTERN_CRATE: Key<ast::ExternCrate, ExternCrateId> = Key::new();
pub const USE: Key<ast::Use, UseId> = Key::new();

pub const ENUM_VARIANT: Key<ast::Variant, EnumVariantId> = Key::new();
pub const TUPLE_FIELD: Key<ast::TupleField, FieldId> = Key::new();
pub const RECORD_FIELD: Key<ast::RecordField, FieldId> = Key::new();
pub const TYPE_PARAM: Key<ast::TypeParam, TypeOrConstParamId> = Key::new();
pub const CONST_PARAM: Key<ast::ConstParam, TypeOrConstParamId> = Key::new();
pub const LIFETIME_PARAM: Key<ast::LifetimeParam, LifetimeParamId> = Key::new();

pub const MACRO_RULES: Key<ast::MacroRules, MacroRulesId> = Key::new();
pub const MACRO2: Key<ast::MacroDef, Macro2Id> = Key::new();
pub const PROC_MACRO: Key<ast::Fn, ProcMacroId> = Key::new();
pub const MACRO_CALL: Key<ast::MacroCall, MacroCallId> = Key::new();
pub const ATTR_MACRO_CALL: Key<ast::Item, MacroCallId> = Key::new();
pub const DERIVE_MACRO_CALL: Key<ast::Attr, (AttrId, MacroCallId, Box<[Option<MacroCallId>]>)> =
Key::new();

/// XXX: AST Nodes and SyntaxNodes have identity equality semantics: nodes are
/// equal if they point to exactly the same object.
///
/// In general, we do not guarantee that we have exactly one instance of a
/// syntax tree for each file. We probably should add such guarantee, but, for
/// the time being, we will use identity-less AstPtr comparison.
pub struct AstPtrPolicy<AST, ID> {
_phantom: PhantomData<(AST, ID)>,
}

impl<AST: AstNode + 'static, ID: 'static> Policy for AstPtrPolicy<AST, ID> {
type K = AstPtr<AST>;
type V = ID;
fn insert(map: &mut DynMap, key: AstPtr<AST>, value: ID) {
map.map
.entry::<FxHashMap<AstPtr<AST>, ID>>()
.or_insert_with(Default::default)
.insert(key, value);
}
fn get<'a>(map: &'a DynMap, key: &AstPtr<AST>) -> Option<&'a ID> {
map.map.get::<FxHashMap<AstPtr<AST>, ID>>()?.get(key)
}
fn is_empty(map: &DynMap) -> bool {
map.map.get::<FxHashMap<AstPtr<AST>, ID>>().map_or(true, |it| it.is_empty())
}
}
}

use std::{
hash::Hash,
Expand Down
72 changes: 0 additions & 72 deletions src/tools/rust-analyzer/crates/hir-def/src/dyn_map/keys.rs

This file was deleted.

4 changes: 2 additions & 2 deletions src/tools/rust-analyzer/crates/hir-def/src/expander.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@ impl Expander {
types_map: &mut TypesMap,
types_source_map: &mut TypesSourceMap,
) -> Option<Path> {
let ctx = LowerCtx::with_span_map_cell(
let mut ctx = LowerCtx::with_span_map_cell(
db,
self.current_file_id,
self.span_map.clone(),
types_map,
types_source_map,
);
Path::from_src(&ctx, path)
Path::from_src(&mut ctx, path)
}

fn within_limit<F, T: ast::AstNode>(
Expand Down
19 changes: 12 additions & 7 deletions src/tools/rust-analyzer/crates/hir-def/src/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ pub(crate) struct GenericParamsCollector {
impl GenericParamsCollector {
pub(crate) fn fill(
&mut self,
lower_ctx: &LowerCtx<'_>,
lower_ctx: &mut LowerCtx<'_>,
node: &dyn HasGenericParams,
add_param_attrs: impl FnMut(
Either<LocalTypeOrConstParamId, LocalLifetimeParamId>,
Expand All @@ -468,7 +468,7 @@ impl GenericParamsCollector {

pub(crate) fn fill_bounds(
&mut self,
lower_ctx: &LowerCtx<'_>,
lower_ctx: &mut LowerCtx<'_>,
type_bounds: Option<ast::TypeBoundList>,
target: Either<TypeRefId, LifetimeRef>,
) {
Expand All @@ -479,7 +479,7 @@ impl GenericParamsCollector {

fn fill_params(
&mut self,
lower_ctx: &LowerCtx<'_>,
lower_ctx: &mut LowerCtx<'_>,
params: ast::GenericParamList,
mut add_param_attrs: impl FnMut(
Either<LocalTypeOrConstParamId, LocalLifetimeParamId>,
Expand Down Expand Up @@ -535,7 +535,11 @@ impl GenericParamsCollector {
}
}

fn fill_where_predicates(&mut self, lower_ctx: &LowerCtx<'_>, where_clause: ast::WhereClause) {
fn fill_where_predicates(
&mut self,
lower_ctx: &mut LowerCtx<'_>,
where_clause: ast::WhereClause,
) {
for pred in where_clause.predicates() {
let target = if let Some(type_ref) = pred.ty() {
Either::Left(TypeRef::from_ast(lower_ctx, type_ref))
Expand Down Expand Up @@ -569,7 +573,7 @@ impl GenericParamsCollector {

fn add_where_predicate_from_bound(
&mut self,
lower_ctx: &LowerCtx<'_>,
lower_ctx: &mut LowerCtx<'_>,
bound: ast::TypeBound,
hrtb_lifetimes: Option<&[Name]>,
target: Either<TypeRefId, LifetimeRef>,
Expand Down Expand Up @@ -670,8 +674,9 @@ impl GenericParamsCollector {
{
let (mut macro_types_map, mut macro_types_source_map) =
(TypesMap::default(), TypesSourceMap::default());
let ctx = expander.ctx(db, &mut macro_types_map, &mut macro_types_source_map);
let type_ref = TypeRef::from_ast(&ctx, expanded.tree());
let mut ctx =
expander.ctx(db, &mut macro_types_map, &mut macro_types_source_map);
let type_ref = TypeRef::from_ast(&mut ctx, expanded.tree());
self.fill_implicit_impl_trait_args(
db,
generics_types_map,
Expand Down
Loading

0 comments on commit fbab782

Please sign in to comment.