Skip to content
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

Subtree update of rust-analyzer #118592

Merged
merged 36 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
be62e0b
fix: remove parenthesis should ensure space
Young-Flash Nov 9, 2023
97dea2c
remove unused PhantomData
Sarrus1 Nov 16, 2023
bd5a63b
move parentheses judge logic into builder
Young-Flash Nov 22, 2023
e790d7f
internal: simplify the removal of dulicate workspaces.
roife Nov 21, 2023
2411f13
fix variant resolve for type alias
Austaras Nov 26, 2023
cab9148
fix: don't make `MissingMatchArms` diagnostic for empty match body
Young-Flash Nov 26, 2023
81606ec
Merge commit '237712fa314237e428e7ef2ab83b979f928a43a1' into sync-fro…
lnicola Nov 27, 2023
57172f7
Merge branch 'master' into sync-from-rust
lnicola Nov 27, 2023
23dc01f
Auto merge of #15976 - lnicola:sync-from-rust, r=lnicola
bors Nov 27, 2023
9aa867c
Auto merge of #15946 - roife:master, r=Veykril
bors Nov 27, 2023
4ab6729
Auto merge of #15857 - Young-Flash:fix, r=Veykril
bors Nov 27, 2023
2ee17bc
Auto merge of #15970 - Austaras:master, r=Veykril
bors Nov 27, 2023
914a157
internal: bump triomphe to 0.1.10
davidbarsky Nov 28, 2023
c7c582a
Auto merge of #15985 - davidbarsky:david/bump-triomphe, r=lnicola
bors Nov 28, 2023
a0e690a
add different completion for fn fields
dfireBird Oct 10, 2023
7cf3ab4
implement completion render for callable fields
dfireBird Nov 12, 2023
5bcafd7
add tests for the completion of the callable field
dfireBird Nov 12, 2023
eedeb58
refactor obtaining receivers into idiomatic way
dfireBird Nov 15, 2023
aa1cf8d
add tests for tuple fields and expect fn type cases
dfireBird Nov 15, 2023
8296b16
fix the insertion of the surronding parens
dfireBird Nov 18, 2023
5c0c8ce
refactor `complete_fn_fields` function and correct branch checks
dfireBird Nov 22, 2023
21c09eb
update dot tests function with check_edit
dfireBird Nov 22, 2023
4ca86ed
Debug use cargo workspace root as cwd. fixes #13022
meowtec Nov 30, 2023
b46f378
update: filter out syntax error in test
Young-Flash Nov 30, 2023
2fd19ed
Err for comma after functional update syntax
ChayimFriedman2 Nov 30, 2023
56abc0a
Auto merge of #15971 - Young-Flash:fix_match_arm, r=lnicola
bors Nov 30, 2023
1c51e25
Auto merge of #15994 - ChayimFriedman2:err-comma-after-fus, r=Veykril
bors Nov 30, 2023
c9d189d
Auto merge of #15993 - meowtec:fix/workspaces-debug-cwd, r=Veykril
bors Nov 30, 2023
e076192
Improve error handling for top-level `let` statements
ohno418 Nov 25, 2023
57e9024
Auto merge of #15961 - ohno418:top-level-let-stmt, r=Veykril
bors Dec 1, 2023
c2f1334
Auto merge of #15912 - Sarrus1:master, r=HKalbasi
bors Dec 1, 2023
4d55cac
Initial support for implicit drop inlay hint
HKalbasi Dec 1, 2023
b7effe5
fix close parens position to move after field access
dfireBird Dec 1, 2023
6e6a0b0
Auto merge of #16000 - HKalbasi:drop-inlay-hint, r=HKalbasi
bors Dec 1, 2023
e402c49
Auto merge of #15879 - dfireBird:fix-14656, r=Veykril
bors Dec 1, 2023
638ba5a
Merge commit 'e402c494b7c7d94a37c6d789a216187aaf9ccd3e' into sync-fro…
lnicola Dec 4, 2023
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
4 changes: 2 additions & 2 deletions src/tools/rust-analyzer/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2000,9 +2000,9 @@ dependencies = [

[[package]]
name = "triomphe"
version = "0.1.8"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1ee9bd9239c339d714d657fac840c6d2a4f9c45f4f9ec7b0975113458be78db"
checksum = "d0c5a71827ac326072b6405552093e2ad2accd25a32fd78d4edc82d98c7f2409"

[[package]]
name = "tt"
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ text-size = "1.1.1"
rayon = "1.8.0"
serde = { version = "1.0.192", features = ["derive"] }
serde_json = "1.0.108"
triomphe = { version = "0.1.8", default-features = false, features = ["std"] }
triomphe = { version = "0.1.10", default-features = false, features = ["std"] }
# can't upgrade due to dashmap depending on 0.12.3 currently
hashbrown = { version = "0.12.3", features = [
"inline-more",
Expand Down
54 changes: 28 additions & 26 deletions src/tools/rust-analyzer/crates/hir-def/src/item_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ mod tests;
use std::{
fmt::{self, Debug},
hash::{Hash, Hasher},
marker::PhantomData,
ops::Index,
};

Expand Down Expand Up @@ -340,34 +339,37 @@ pub trait ItemTreeNode: Clone {
fn id_to_mod_item(id: FileItemTreeId<Self>) -> ModItem;
}

pub struct FileItemTreeId<N: ItemTreeNode> {
index: Idx<N>,
_p: PhantomData<N>,
pub struct FileItemTreeId<N: ItemTreeNode>(Idx<N>);

impl<N: ItemTreeNode> FileItemTreeId<N> {
pub fn index(&self) -> Idx<N> {
self.0
}
}

impl<N: ItemTreeNode> Clone for FileItemTreeId<N> {
fn clone(&self) -> Self {
Self { index: self.index, _p: PhantomData }
Self(self.0)
}
}
impl<N: ItemTreeNode> Copy for FileItemTreeId<N> {}

impl<N: ItemTreeNode> PartialEq for FileItemTreeId<N> {
fn eq(&self, other: &FileItemTreeId<N>) -> bool {
self.index == other.index
self.0 == other.0
}
}
impl<N: ItemTreeNode> Eq for FileItemTreeId<N> {}

impl<N: ItemTreeNode> Hash for FileItemTreeId<N> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.index.hash(state)
self.0.hash(state)
}
}

impl<N: ItemTreeNode> fmt::Debug for FileItemTreeId<N> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.index.fmt(f)
self.0.fmt(f)
}
}

Expand Down Expand Up @@ -548,7 +550,7 @@ impl Index<RawVisibilityId> for ItemTree {
impl<N: ItemTreeNode> Index<FileItemTreeId<N>> for ItemTree {
type Output = N;
fn index(&self, id: FileItemTreeId<N>) -> &N {
N::lookup(self, id.index)
N::lookup(self, id.index())
}
}

Expand Down Expand Up @@ -925,23 +927,23 @@ impl ModItem {

pub fn ast_id(&self, tree: &ItemTree) -> FileAstId<ast::Item> {
match self {
ModItem::Use(it) => tree[it.index].ast_id().upcast(),
ModItem::ExternCrate(it) => tree[it.index].ast_id().upcast(),
ModItem::ExternBlock(it) => tree[it.index].ast_id().upcast(),
ModItem::Function(it) => tree[it.index].ast_id().upcast(),
ModItem::Struct(it) => tree[it.index].ast_id().upcast(),
ModItem::Union(it) => tree[it.index].ast_id().upcast(),
ModItem::Enum(it) => tree[it.index].ast_id().upcast(),
ModItem::Const(it) => tree[it.index].ast_id().upcast(),
ModItem::Static(it) => tree[it.index].ast_id().upcast(),
ModItem::Trait(it) => tree[it.index].ast_id().upcast(),
ModItem::TraitAlias(it) => tree[it.index].ast_id().upcast(),
ModItem::Impl(it) => tree[it.index].ast_id().upcast(),
ModItem::TypeAlias(it) => tree[it.index].ast_id().upcast(),
ModItem::Mod(it) => tree[it.index].ast_id().upcast(),
ModItem::MacroCall(it) => tree[it.index].ast_id().upcast(),
ModItem::MacroRules(it) => tree[it.index].ast_id().upcast(),
ModItem::MacroDef(it) => tree[it.index].ast_id().upcast(),
ModItem::Use(it) => tree[it.index()].ast_id().upcast(),
ModItem::ExternCrate(it) => tree[it.index()].ast_id().upcast(),
ModItem::ExternBlock(it) => tree[it.index()].ast_id().upcast(),
ModItem::Function(it) => tree[it.index()].ast_id().upcast(),
ModItem::Struct(it) => tree[it.index()].ast_id().upcast(),
ModItem::Union(it) => tree[it.index()].ast_id().upcast(),
ModItem::Enum(it) => tree[it.index()].ast_id().upcast(),
ModItem::Const(it) => tree[it.index()].ast_id().upcast(),
ModItem::Static(it) => tree[it.index()].ast_id().upcast(),
ModItem::Trait(it) => tree[it.index()].ast_id().upcast(),
ModItem::TraitAlias(it) => tree[it.index()].ast_id().upcast(),
ModItem::Impl(it) => tree[it.index()].ast_id().upcast(),
ModItem::TypeAlias(it) => tree[it.index()].ast_id().upcast(),
ModItem::Mod(it) => tree[it.index()].ast_id().upcast(),
ModItem::MacroCall(it) => tree[it.index()].ast_id().upcast(),
ModItem::MacroRules(it) => tree[it.index()].ast_id().upcast(),
ModItem::MacroDef(it) => tree[it.index()].ast_id().upcast(),
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::{
use super::*;

fn id<N: ItemTreeNode>(index: Idx<N>) -> FileItemTreeId<N> {
FileItemTreeId { index, _p: PhantomData }
FileItemTreeId(index)
}

pub(super) struct Ctx<'a> {
Expand Down
21 changes: 8 additions & 13 deletions src/tools/rust-analyzer/crates/hir-ty/src/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,20 +1152,15 @@ impl<'a> InferenceContext<'a> {
(ty, variant)
}
TypeNs::TypeAliasId(it) => {
let container = it.lookup(self.db.upcast()).container;
let parent_subst = match container {
ItemContainerId::TraitId(id) => {
let subst = TyBuilder::subst_for_def(self.db, id, None)
.fill_with_inference_vars(&mut self.table)
.build();
Some(subst)
}
// Type aliases do not exist in impls.
_ => None,
let resolved_seg = match unresolved {
None => path.segments().last().unwrap(),
Some(n) => path.segments().get(path.segments().len() - n - 1).unwrap(),
};
let ty = TyBuilder::def_ty(self.db, it.into(), parent_subst)
.fill_with_inference_vars(&mut self.table)
.build();
let substs =
ctx.substs_from_path_segment(resolved_seg, Some(it.into()), true, None);
let ty = self.db.ty(it.into());
let ty = self.insert_type_vars(ty.substitute(Interner, &substs));

self.resolve_variant_on_alias(ty, unresolved, mod_path)
}
TypeNs::AdtSelfType(_) => {
Expand Down
2 changes: 1 addition & 1 deletion src/tools/rust-analyzer/crates/hir-ty/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ impl<'a> TyLoweringContext<'a> {
}
}

fn substs_from_path_segment(
pub(super) fn substs_from_path_segment(
&self,
segment: PathSegment<'_>,
def: Option<GenericDefId>,
Expand Down
14 changes: 14 additions & 0 deletions src/tools/rust-analyzer/crates/hir-ty/src/mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,10 @@ impl ProjectionStore {
impl ProjectionId {
pub const EMPTY: ProjectionId = ProjectionId(0);

pub fn is_empty(self) -> bool {
self == ProjectionId::EMPTY
}

pub fn lookup(self, store: &ProjectionStore) -> &[PlaceElem] {
store.id_to_proj.get(&self).unwrap()
}
Expand Down Expand Up @@ -1069,6 +1073,10 @@ pub struct MirBody {
}

impl MirBody {
pub fn local_to_binding_map(&self) -> ArenaMap<LocalId, BindingId> {
self.binding_locals.iter().map(|(it, y)| (*y, it)).collect()
}

fn walk_places(&mut self, mut f: impl FnMut(&mut Place, &mut ProjectionStore)) {
fn for_operand(
op: &mut Operand,
Expand Down Expand Up @@ -1188,3 +1196,9 @@ pub enum MirSpan {
}

impl_from!(ExprId, PatId for MirSpan);

impl From<&ExprId> for MirSpan {
fn from(value: &ExprId) -> Self {
(*value).into()
}
}
54 changes: 34 additions & 20 deletions src/tools/rust-analyzer/crates/hir-ty/src/mir/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,14 @@ pub enum MirLowerError {
/// A token to ensuring that each drop scope is popped at most once, thanks to the compiler that checks moves.
struct DropScopeToken;
impl DropScopeToken {
fn pop_and_drop(self, ctx: &mut MirLowerCtx<'_>, current: BasicBlockId) -> BasicBlockId {
fn pop_and_drop(
self,
ctx: &mut MirLowerCtx<'_>,
current: BasicBlockId,
span: MirSpan,
) -> BasicBlockId {
std::mem::forget(self);
ctx.pop_drop_scope_internal(current)
ctx.pop_drop_scope_internal(current, span)
}

/// It is useful when we want a drop scope is syntaxically closed, but we don't want to execute any drop
Expand Down Expand Up @@ -582,7 +587,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
self.lower_loop(current, place, *label, expr_id.into(), |this, begin| {
let scope = this.push_drop_scope();
if let Some((_, mut current)) = this.lower_expr_as_place(begin, *body, true)? {
current = scope.pop_and_drop(this, current);
current = scope.pop_and_drop(this, current, body.into());
this.set_goto(current, begin, expr_id.into());
} else {
scope.pop_assume_dropped(this);
Expand Down Expand Up @@ -720,7 +725,8 @@ impl<'ctx> MirLowerCtx<'ctx> {
.ok_or(MirLowerError::ContinueWithoutLoop)?,
};
let begin = loop_data.begin;
current = self.drop_until_scope(loop_data.drop_scope_index, current);
current =
self.drop_until_scope(loop_data.drop_scope_index, current, expr_id.into());
self.set_goto(current, begin, expr_id.into());
Ok(None)
}
Expand Down Expand Up @@ -759,7 +765,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
self.current_loop_blocks.as_ref().unwrap().drop_scope_index,
),
};
current = self.drop_until_scope(drop_scope, current);
current = self.drop_until_scope(drop_scope, current, expr_id.into());
self.set_goto(current, end, expr_id.into());
Ok(None)
}
Expand All @@ -773,7 +779,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
return Ok(None);
}
}
current = self.drop_until_scope(0, current);
current = self.drop_until_scope(0, current, expr_id.into());
self.set_terminator(current, TerminatorKind::Return, expr_id.into());
Ok(None)
}
Expand Down Expand Up @@ -1782,7 +1788,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
return Ok(None);
};
self.push_fake_read(c, p, expr.into());
current = scope2.pop_and_drop(self, c);
current = scope2.pop_and_drop(self, c, expr.into());
}
}
}
Expand All @@ -1793,7 +1799,7 @@ impl<'ctx> MirLowerCtx<'ctx> {
};
current = c;
}
current = scope.pop_and_drop(self, current);
current = scope.pop_and_drop(self, current, span);
Ok(Some(current))
}

Expand Down Expand Up @@ -1873,9 +1879,14 @@ impl<'ctx> MirLowerCtx<'ctx> {
}
}

fn drop_until_scope(&mut self, scope_index: usize, mut current: BasicBlockId) -> BasicBlockId {
fn drop_until_scope(
&mut self,
scope_index: usize,
mut current: BasicBlockId,
span: MirSpan,
) -> BasicBlockId {
for scope in self.drop_scopes[scope_index..].to_vec().iter().rev() {
self.emit_drop_and_storage_dead_for_scope(scope, &mut current);
self.emit_drop_and_storage_dead_for_scope(scope, &mut current, span);
}
current
}
Expand All @@ -1891,17 +1902,22 @@ impl<'ctx> MirLowerCtx<'ctx> {
}

/// Don't call directly
fn pop_drop_scope_internal(&mut self, mut current: BasicBlockId) -> BasicBlockId {
fn pop_drop_scope_internal(
&mut self,
mut current: BasicBlockId,
span: MirSpan,
) -> BasicBlockId {
let scope = self.drop_scopes.pop().unwrap();
self.emit_drop_and_storage_dead_for_scope(&scope, &mut current);
self.emit_drop_and_storage_dead_for_scope(&scope, &mut current, span);
current
}

fn pop_drop_scope_assert_finished(
&mut self,
mut current: BasicBlockId,
span: MirSpan,
) -> Result<BasicBlockId> {
current = self.pop_drop_scope_internal(current);
current = self.pop_drop_scope_internal(current, span);
if !self.drop_scopes.is_empty() {
implementation_error!("Mismatched count between drop scope push and pops");
}
Expand All @@ -1912,20 +1928,18 @@ impl<'ctx> MirLowerCtx<'ctx> {
&mut self,
scope: &DropScope,
current: &mut Idx<BasicBlock>,
span: MirSpan,
) {
for &l in scope.locals.iter().rev() {
if !self.result.locals[l].ty.clone().is_copy(self.db, self.owner) {
let prev = std::mem::replace(current, self.new_basic_block());
self.set_terminator(
prev,
TerminatorKind::Drop { place: l.into(), target: *current, unwind: None },
MirSpan::Unknown,
span,
);
}
self.push_statement(
*current,
StatementKind::StorageDead(l).with_span(MirSpan::Unknown),
);
self.push_statement(*current, StatementKind::StorageDead(l).with_span(span));
}
}
}
Expand Down Expand Up @@ -2002,7 +2016,7 @@ pub fn mir_body_for_closure_query(
|_| true,
)?;
if let Some(current) = ctx.lower_expr_to_place(*root, return_slot().into(), current)? {
let current = ctx.pop_drop_scope_assert_finished(current)?;
let current = ctx.pop_drop_scope_assert_finished(current, root.into())?;
ctx.set_terminator(current, TerminatorKind::Return, (*root).into());
}
let mut upvar_map: FxHashMap<LocalId, Vec<(&CapturedItem, usize)>> = FxHashMap::default();
Expand Down Expand Up @@ -2146,7 +2160,7 @@ pub fn lower_to_mir(
ctx.lower_params_and_bindings([].into_iter(), binding_picker)?
};
if let Some(current) = ctx.lower_expr_to_place(root_expr, return_slot().into(), current)? {
let current = ctx.pop_drop_scope_assert_finished(current)?;
let current = ctx.pop_drop_scope_assert_finished(current, root_expr.into())?;
ctx.set_terminator(current, TerminatorKind::Return, root_expr.into());
}
Ok(ctx.result)
Expand Down
4 changes: 2 additions & 2 deletions src/tools/rust-analyzer/crates/hir-ty/src/mir/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl<'a> MirPrettyCtx<'a> {
let indent = mem::take(&mut self.indent);
let mut ctx = MirPrettyCtx {
body: &body,
local_to_binding: body.binding_locals.iter().map(|(it, y)| (*y, it)).collect(),
local_to_binding: body.local_to_binding_map(),
result,
indent,
..*self
Expand All @@ -167,7 +167,7 @@ impl<'a> MirPrettyCtx<'a> {
}

fn new(body: &'a MirBody, hir_body: &'a Body, db: &'a dyn HirDatabase) -> Self {
let local_to_binding = body.binding_locals.iter().map(|(it, y)| (*y, it)).collect();
let local_to_binding = body.local_to_binding_map();
MirPrettyCtx {
body,
db,
Expand Down
Loading