Skip to content

Commit 58d77bb

Browse files
committed
Auto merge of #150702 - lnicola:sync-from-ra, r=lnicola
`rust-analyzer` subtree update Subtree update of `rust-analyzer` to 6a1246b. Created using https://github.com/rust-lang/josh-sync. r? `@ghost`
2 parents 7d4a5b7 + 6a1246b commit 58d77bb

60 files changed

Lines changed: 764 additions & 366 deletions

File tree

Some content is hidden

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

crates/base-db/src/editioned_file_id.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ const _: () = {
2626
krate: Crate,
2727
}
2828

29+
// FIXME: This poses an invalidation problem, if one constructs an `EditionedFileId` with a
30+
// different crate then whatever the input of a memo used, it will invalidate the memo causing
31+
// it to recompute even if the crate is not really used.
2932
/// We like to include the origin crate in an `EditionedFileId` (for use in the item tree),
3033
/// but this poses us a problem.
3134
///

crates/hir-def/src/expr_store.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ impl HygieneId {
5757
Self(ctx)
5858
}
5959

60-
// FIXME: Inline this
61-
pub(crate) fn lookup(self) -> SyntaxContext {
60+
pub(crate) fn syntax_context(self) -> SyntaxContext {
6261
self.0
6362
}
6463

@@ -73,7 +72,8 @@ pub type ExprSource = InFile<ExprPtr>;
7372
pub type PatPtr = AstPtr<ast::Pat>;
7473
pub type PatSource = InFile<PatPtr>;
7574

76-
pub type LabelPtr = AstPtr<ast::Label>;
75+
/// BlockExpr -> Desugared label from try block
76+
pub type LabelPtr = AstPtr<Either<ast::Label, ast::BlockExpr>>;
7777
pub type LabelSource = InFile<LabelPtr>;
7878

7979
pub type FieldPtr = AstPtr<ast::RecordExprField>;
@@ -942,7 +942,7 @@ impl ExpressionStoreSourceMap {
942942
}
943943

944944
pub fn node_label(&self, node: InFile<&ast::Label>) -> Option<LabelId> {
945-
let src = node.map(AstPtr::new);
945+
let src = node.map(AstPtr::new).map(AstPtr::wrap_left);
946946
self.expr_only()?.label_map.get(&src).cloned()
947947
}
948948

crates/hir-def/src/expr_store/expander.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use hir_expand::{
1111
ExpandError, ExpandErrorKind, ExpandResult, HirFileId, InFile, Lookup, MacroCallId,
1212
eager::EagerCallBackFn, mod_path::ModPath, span_map::SpanMap,
1313
};
14-
use span::{AstIdMap, Edition, SyntaxContext};
14+
use span::{AstIdMap, SyntaxContext};
1515
use syntax::ast::HasAttrs;
1616
use syntax::{AstNode, Parse, ast};
1717
use triomphe::Arc;
@@ -75,11 +75,6 @@ impl Expander {
7575
AttrFlags::is_cfg_enabled_for(owner, cfg_options)
7676
}
7777

78-
pub(super) fn call_syntax_ctx(&self) -> SyntaxContext {
79-
// FIXME:
80-
SyntaxContext::root(Edition::CURRENT_FIXME)
81-
}
82-
8378
pub(super) fn enter_expand<T: ast::AstNode>(
8479
&mut self,
8580
db: &dyn DefDatabase,

crates/hir-def/src/expr_store/lower.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,7 +1096,7 @@ impl<'db> ExprCollector<'db> {
10961096
ast::Expr::WhileExpr(e) => self.collect_while_loop(syntax_ptr, e),
10971097
ast::Expr::ForExpr(e) => self.collect_for_loop(syntax_ptr, e),
10981098
ast::Expr::CallExpr(e) => {
1099-
// FIXME: Remove this once we drop support for <1.86, https://github.com/rust-lang/rust/commit/ac9cb908ac4301dfc25e7a2edee574320022ae2c
1099+
// FIXME(MINIMUM_SUPPORTED_TOOLCHAIN_VERSION): Remove this once we drop support for <1.86, https://github.com/rust-lang/rust/commit/ac9cb908ac4301dfc25e7a2edee574320022ae2c
11001100
let is_rustc_box = {
11011101
let attrs = e.attrs();
11021102
attrs.filter_map(|it| it.as_simple_atom()).any(|it| it == "rustc_box")
@@ -1649,7 +1649,7 @@ impl<'db> ExprCollector<'db> {
16491649
fn desugar_try_block(&mut self, e: BlockExpr) -> ExprId {
16501650
let try_from_output = self.lang_path(self.lang_items().TryTraitFromOutput);
16511651
let label = self.generate_new_name();
1652-
let label = self.alloc_label_desugared(Label { name: label });
1652+
let label = self.alloc_label_desugared(Label { name: label }, AstPtr::new(&e).wrap_right());
16531653
let old_label = self.current_try_block_label.replace(label);
16541654

16551655
let ptr = AstPtr::new(&e).upcast();
@@ -2319,7 +2319,6 @@ impl<'db> ExprCollector<'db> {
23192319
ast::Pat::SlicePat(p) => {
23202320
let SlicePatComponents { prefix, slice, suffix } = p.components();
23212321

2322-
// FIXME properly handle `RestPat`
23232322
Pat::Slice {
23242323
prefix: prefix.into_iter().map(|p| self.collect_pat(p, binding_list)).collect(),
23252324
slice: slice.map(|p| self.collect_pat(p, binding_list)),
@@ -2399,7 +2398,6 @@ impl<'db> ExprCollector<'db> {
23992398
};
24002399
let start = range_part_lower(p.start());
24012400
let end = range_part_lower(p.end());
2402-
// FIXME: Exclusive ended pattern range is stabilised
24032401
match p.op_kind() {
24042402
Some(range_type) => Pat::Range { start, end, range_type },
24052403
None => Pat::Missing,
@@ -2519,9 +2517,9 @@ impl<'db> ExprCollector<'db> {
25192517
let mut hygiene_info = if hygiene_id.is_root() {
25202518
None
25212519
} else {
2522-
hygiene_id.lookup().outer_expn(self.db).map(|expansion| {
2520+
hygiene_id.syntax_context().outer_expn(self.db).map(|expansion| {
25232521
let expansion = self.db.lookup_intern_macro_call(expansion.into());
2524-
(hygiene_id.lookup().parent(self.db), expansion.def)
2522+
(hygiene_id.syntax_context().parent(self.db), expansion.def)
25252523
})
25262524
};
25272525
let name = Name::new_lifetime(&lifetime.text());
@@ -2727,17 +2725,17 @@ impl ExprCollector<'_> {
27272725
self.store.pats.alloc(Pat::Missing)
27282726
}
27292727

2730-
fn alloc_label(&mut self, label: Label, ptr: LabelPtr) -> LabelId {
2728+
fn alloc_label(&mut self, label: Label, ptr: AstPtr<ast::Label>) -> LabelId {
2729+
self.alloc_label_desugared(label, ptr.wrap_left())
2730+
}
2731+
2732+
fn alloc_label_desugared(&mut self, label: Label, ptr: LabelPtr) -> LabelId {
27312733
let src = self.expander.in_file(ptr);
27322734
let id = self.store.labels.alloc(label);
27332735
self.store.label_map_back.insert(id, src);
27342736
self.store.label_map.insert(src, id);
27352737
id
27362738
}
2737-
// FIXME: desugared labels don't have ptr, that's wrong and should be fixed somehow.
2738-
fn alloc_label_desugared(&mut self, label: Label) -> LabelId {
2739-
self.store.labels.alloc(label)
2740-
}
27412739

27422740
fn is_lowering_awaitable_block(&self) -> &Awaitable {
27432741
self.awaitable_context.as_ref().unwrap_or(&Awaitable::No("unknown"))

crates/hir-def/src/expr_store/lower/format_args.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
use base_db::FxIndexSet;
44
use hir_expand::name::Name;
55
use intern::{Symbol, sym};
6+
use span::SyntaxContext;
67
use syntax::{AstPtr, AstToken as _, ast};
78

89
use crate::{
@@ -49,7 +50,7 @@ impl<'db> ExprCollector<'db> {
4950
self.expand_macros_to_string(template.clone()).map(|it| (it, template))
5051
}) {
5152
Some(((s, is_direct_literal), template)) => {
52-
let call_ctx = self.expander.call_syntax_ctx();
53+
let call_ctx = SyntaxContext::root(self.def_map.edition());
5354
let hygiene = self.hygiene_id_for(s.syntax().text_range());
5455
let fmt = format_args::parse(
5556
&s,

crates/hir-def/src/hir/generics.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ pub type LocalLifetimeParamId = Idx<LifetimeParamData>;
2020
/// Data about a generic type parameter (to a function, struct, impl, ...).
2121
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
2222
pub struct TypeParamData {
23-
/// [`None`] only if the type ref is an [`crate::type_ref::TypeRef::ImplTrait`]. FIXME: Might be better to just
24-
/// make it always be a value, giving impl trait a special name.
23+
/// [`None`] only if the type ref is an [`crate::type_ref::TypeRef::ImplTrait`].
2524
pub name: Option<Name>,
2625
pub default: Option<TypeRefId>,
2726
pub provenance: TypeParamProvenance,

crates/hir-def/src/hir/type_ref.rs

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
//! HIR for references to types. Paths in these are not yet resolved. They can
22
//! be directly created from an ast::TypeRef, without further queries.
33
4-
use std::fmt::Write;
5-
64
use hir_expand::name::Name;
75
use intern::Symbol;
86
use la_arena::Idx;
97
use thin_vec::ThinVec;
108

119
use crate::{
1210
LifetimeParamId, TypeParamId,
13-
builtin_type::{BuiltinInt, BuiltinType, BuiltinUint},
1411
expr_store::{
1512
ExpressionStore,
1613
path::{GenericArg, Path},
1714
},
18-
hir::{ExprId, Literal},
15+
hir::ExprId,
1916
};
2017

2118
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
@@ -275,56 +272,3 @@ impl TypeBound {
275272
pub struct ConstRef {
276273
pub expr: ExprId,
277274
}
278-
279-
/// A literal constant value
280-
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
281-
pub enum LiteralConstRef {
282-
Int(i128),
283-
UInt(u128),
284-
Bool(bool),
285-
Char(char),
286-
287-
/// Case of an unknown value that rustc might know but we don't
288-
// FIXME: this is a hack to get around chalk not being able to represent unevaluatable
289-
// constants
290-
// https://github.com/rust-lang/rust-analyzer/pull/8813#issuecomment-840679177
291-
// https://rust-lang.zulipchat.com/#narrow/stream/144729-wg-traits/topic/Handling.20non.20evaluatable.20constants'.20equality/near/238386348
292-
Unknown,
293-
}
294-
295-
impl LiteralConstRef {
296-
pub fn builtin_type(&self) -> BuiltinType {
297-
match self {
298-
LiteralConstRef::UInt(_) | LiteralConstRef::Unknown => {
299-
BuiltinType::Uint(BuiltinUint::U128)
300-
}
301-
LiteralConstRef::Int(_) => BuiltinType::Int(BuiltinInt::I128),
302-
LiteralConstRef::Char(_) => BuiltinType::Char,
303-
LiteralConstRef::Bool(_) => BuiltinType::Bool,
304-
}
305-
}
306-
}
307-
308-
impl From<Literal> for LiteralConstRef {
309-
fn from(literal: Literal) -> Self {
310-
match literal {
311-
Literal::Char(c) => Self::Char(c),
312-
Literal::Bool(flag) => Self::Bool(flag),
313-
Literal::Int(num, _) => Self::Int(num),
314-
Literal::Uint(num, _) => Self::UInt(num),
315-
_ => Self::Unknown,
316-
}
317-
}
318-
}
319-
320-
impl std::fmt::Display for LiteralConstRef {
321-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
322-
match self {
323-
LiteralConstRef::Int(num) => num.fmt(f),
324-
LiteralConstRef::UInt(num) => num.fmt(f),
325-
LiteralConstRef::Bool(flag) => flag.fmt(f),
326-
LiteralConstRef::Char(c) => write!(f, "'{c}'"),
327-
LiteralConstRef::Unknown => f.write_char('_'),
328-
}
329-
}
330-
}

crates/hir-def/src/item_scope.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub struct ItemScope {
158158
/// declared.
159159
declarations: ThinVec<ModuleDefId>,
160160

161-
impls: ThinVec<ImplId>,
161+
impls: ThinVec<(ImplId, /* trait impl */ bool)>,
162162
builtin_derive_impls: ThinVec<BuiltinDeriveImplId>,
163163
extern_blocks: ThinVec<ExternBlockId>,
164164
unnamed_consts: ThinVec<ConstId>,
@@ -327,7 +327,15 @@ impl ItemScope {
327327
}
328328

329329
pub fn impls(&self) -> impl ExactSizeIterator<Item = ImplId> + '_ {
330-
self.impls.iter().copied()
330+
self.impls.iter().map(|&(id, _)| id)
331+
}
332+
333+
pub fn trait_impls(&self) -> impl Iterator<Item = ImplId> + '_ {
334+
self.impls.iter().filter(|&&(_, is_trait_impl)| is_trait_impl).map(|&(id, _)| id)
335+
}
336+
337+
pub fn inherent_impls(&self) -> impl Iterator<Item = ImplId> + '_ {
338+
self.impls.iter().filter(|&&(_, is_trait_impl)| !is_trait_impl).map(|&(id, _)| id)
331339
}
332340

333341
pub fn builtin_derive_impls(&self) -> impl ExactSizeIterator<Item = BuiltinDeriveImplId> + '_ {
@@ -472,8 +480,8 @@ impl ItemScope {
472480
self.legacy_macros.get(name).map(|it| &**it)
473481
}
474482

475-
pub(crate) fn define_impl(&mut self, imp: ImplId) {
476-
self.impls.push(imp);
483+
pub(crate) fn define_impl(&mut self, imp: ImplId, is_trait_impl: bool) {
484+
self.impls.push((imp, is_trait_impl));
477485
}
478486

479487
pub(crate) fn define_builtin_derive_impl(&mut self, imp: BuiltinDeriveImplId) {

crates/hir-def/src/item_tree.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,9 @@ pub struct Trait {
614614
}
615615

616616
#[derive(Debug, Clone, Eq, PartialEq)]
617-
pub struct Impl {}
617+
pub struct Impl {
618+
pub is_trait_impl: bool,
619+
}
618620

619621
#[derive(Debug, Clone, PartialEq, Eq)]
620622
pub struct TypeAlias {

crates/hir-def/src/item_tree/lower.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ impl<'a> Ctx<'a> {
271271
let ast_id = self.source_ast_id_map.ast_id(impl_def);
272272
// Note that trait impls don't get implicit `Self` unlike traits, because here they are a
273273
// type alias rather than a type parameter, so this is handled by the resolver.
274-
let res = Impl {};
274+
let res = Impl { is_trait_impl: impl_def.trait_().is_some() };
275275
self.tree.small_data.insert(ast_id.upcast(), SmallModItem::Impl(res));
276276
ast_id
277277
}

0 commit comments

Comments
 (0)