Skip to content

Commit 239dc5d

Browse files
committed
Auto merge of rust-lang#17941 - ChayimFriedman2:pre-closure-to-fn, r=Veykril
Preliminary work for rust-lang#17940 I split the PR as requested, and made small commits.
2 parents a3f1196 + becfc5a commit 239dc5d

File tree

26 files changed

+815
-166
lines changed

26 files changed

+815
-166
lines changed

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

+22-5
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ impl LangItemTarget {
7474
_ => None,
7575
}
7676
}
77+
78+
pub fn as_type_alias(self) -> Option<TypeAliasId> {
79+
match self {
80+
LangItemTarget::TypeAlias(id) => Some(id),
81+
_ => None,
82+
}
83+
}
7784
}
7885

7986
#[derive(Default, Debug, Clone, PartialEq, Eq)]
@@ -117,11 +124,19 @@ impl LangItems {
117124
match def {
118125
ModuleDefId::TraitId(trait_) => {
119126
lang_items.collect_lang_item(db, trait_, LangItemTarget::Trait);
120-
db.trait_data(trait_).items.iter().for_each(|&(_, assoc_id)| {
121-
if let AssocItemId::FunctionId(f) = assoc_id {
122-
lang_items.collect_lang_item(db, f, LangItemTarget::Function);
123-
}
124-
});
127+
db.trait_data(trait_).items.iter().for_each(
128+
|&(_, assoc_id)| match assoc_id {
129+
AssocItemId::FunctionId(f) => {
130+
lang_items.collect_lang_item(db, f, LangItemTarget::Function);
131+
}
132+
AssocItemId::TypeAliasId(alias) => lang_items.collect_lang_item(
133+
db,
134+
alias,
135+
LangItemTarget::TypeAlias,
136+
),
137+
AssocItemId::ConstId(_) => {}
138+
},
139+
);
125140
}
126141
ModuleDefId::AdtId(AdtId::EnumId(e)) => {
127142
lang_items.collect_lang_item(db, e, LangItemTarget::EnumId);
@@ -453,6 +468,7 @@ language_item_table! {
453468

454469
Context, sym::Context, context, Target::Struct, GenericRequirement::None;
455470
FuturePoll, sym::poll, future_poll_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
471+
FutureOutput, sym::future_output, future_output, Target::TypeAlias, GenericRequirement::None;
456472

457473
Option, sym::Option, option_type, Target::Enum, GenericRequirement::None;
458474
OptionSome, sym::Some, option_some_variant, Target::Variant, GenericRequirement::None;
@@ -467,6 +483,7 @@ language_item_table! {
467483
IntoFutureIntoFuture, sym::into_future, into_future_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
468484
IntoIterIntoIter, sym::into_iter, into_iter_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
469485
IteratorNext, sym::next, next_fn, Target::Method(MethodKind::Trait { body: false}), GenericRequirement::None;
486+
Iterator, sym::iterator, iterator, Target::Trait, GenericRequirement::None;
470487

471488
PinNewUnchecked, sym::new_unchecked, new_unchecked_fn, Target::Method(MethodKind::Inherent), GenericRequirement::None;
472489

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

+8
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ use crate::{
5959
generics::Generics,
6060
infer::{coerce::CoerceMany, unify::InferenceTable},
6161
lower::ImplTraitLoweringMode,
62+
mir::MirSpan,
6263
to_assoc_type_id,
6364
traits::FnTrait,
6465
utils::{InTypeConstIdMetadata, UnevaluatedConstEvaluatorFolder},
@@ -553,6 +554,12 @@ pub(crate) struct InferenceContext<'a> {
553554

554555
// fields related to closure capture
555556
current_captures: Vec<CapturedItemWithoutTy>,
557+
/// A stack that has an entry for each projection in the current capture.
558+
///
559+
/// For example, in `a.b.c`, we capture the spans of `a`, `a.b`, and `a.b.c`.
560+
/// We do that because sometimes we truncate projections (when a closure captures
561+
/// both `a.b` and `a.b.c`), and we want to provide accurate spans in this case.
562+
current_capture_span_stack: Vec<MirSpan>,
556563
current_closure: Option<ClosureId>,
557564
/// Stores the list of closure ids that need to be analyzed before this closure. See the
558565
/// comment on `InferenceContext::sort_closures`
@@ -634,6 +641,7 @@ impl<'a> InferenceContext<'a> {
634641
breakables: Vec::new(),
635642
deferred_cast_checks: Vec::new(),
636643
current_captures: Vec::new(),
644+
current_capture_span_stack: Vec::new(),
637645
current_closure: None,
638646
deferred_closures: FxHashMap::default(),
639647
closure_dependencies: FxHashMap::default(),

0 commit comments

Comments
 (0)