Skip to content

Commit 48718e5

Browse files
committed
Rust: adapt extractor to ra_ap 0.0.347 API
1 parent bd980d2 commit 48718e5

4 files changed

Lines changed: 34 additions & 35 deletions

File tree

‎rust/extractor/src/main.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ impl<'a> Extractor<'a> {
106106
.push(ExtractionStep::extract(before_extract, source_kind, file));
107107
}
108108

109-
pub fn extract_with_semantics(
109+
pub fn extract_with_semantics<'db>(
110110
&mut self,
111111
file: &Path,
112-
semantics: &Semantics<'_, RootDatabase>,
113-
vfs: &Vfs,
112+
semantics: &'db Semantics<'db, RootDatabase>,
113+
vfs: &'db Vfs,
114114
source_kind: SourceKind,
115115
) {
116116
self.extract(&RustAnalyzer::new(vfs, semantics), file, source_kind);

‎rust/extractor/src/rust_analyzer.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl<'a> RustAnalyzer<'a> {
9999
fn get_file_data(
100100
&self,
101101
path: &Path,
102-
) -> Result<(&Semantics<'_, RootDatabase>, EditionedFileId, FileText), RustAnalyzerNoSemantics>
102+
) -> Result<(&'a Semantics<'a, RootDatabase>, EditionedFileId, FileText), RustAnalyzerNoSemantics>
103103
{
104104
match self {
105105
RustAnalyzer::WithoutSemantics { severity, reason } => Err(RustAnalyzerNoSemantics {
@@ -118,12 +118,12 @@ impl<'a> RustAnalyzer<'a> {
118118
let editioned_file_id = semantics.attach_first_edition_opt(file_id).ok_or(
119119
RustAnalyzerNoSemantics::warning("failed to determine rust edition"),
120120
)?;
121-
Ok((semantics, editioned_file_id, input))
121+
Ok((*semantics, editioned_file_id, input))
122122
}
123123
}
124124
}
125125

126-
pub fn parse(&self, path: &Path) -> ParseResult<'_> {
126+
pub fn parse(&self, path: &Path) -> ParseResult<'a> {
127127
match self.get_file_data(path) {
128128
Ok((semantics, file_id, input)) => {
129129
let source_file = semantics.parse(file_id);

‎rust/extractor/src/translate/base.rs‎

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::trap::{DiagnosticSeverity, TrapFile, TrapId};
55
use crate::trap::{Label, TrapClass};
66
use ra_ap_base_db::EditionedFileId;
77
use ra_ap_hir::Semantics;
8-
use ra_ap_hir::db::ExpandDatabase;
98
use ra_ap_hir_expand::builtin::{BuiltinDeriveExpander, find_builtin_derive};
109
use ra_ap_hir_expand::span_map::ExpansionSpanMap;
1110
use ra_ap_hir_expand::{ExpandResult, ExpandTo, HirFileId, InFile, map_node_range_up_rooted};
@@ -22,7 +21,7 @@ use ra_ap_syntax_bridge::{
2221
DocCommentDesugarMode, syntax_node_to_token_tree, token_tree_to_syntax_node,
2322
};
2423

25-
impl Emission<ast::Item> for Translator<'_> {
24+
impl Emission<ast::Item> for Translator<'_, '_> {
2625
fn pre_emit(&mut self, node: &ast::Item) -> Option<Label<generated::Item>> {
2726
self.item_pre_emit(node).map(Into::into)
2827
}
@@ -32,7 +31,7 @@ impl Emission<ast::Item> for Translator<'_> {
3231
}
3332
}
3433

35-
impl Emission<ast::AssocItem> for Translator<'_> {
34+
impl Emission<ast::AssocItem> for Translator<'_, '_> {
3635
fn pre_emit(&mut self, node: &ast::AssocItem) -> Option<Label<generated::AssocItem>> {
3736
self.item_pre_emit(&node.clone().into()).map(Into::into)
3837
}
@@ -42,7 +41,7 @@ impl Emission<ast::AssocItem> for Translator<'_> {
4241
}
4342
}
4443

45-
impl Emission<ast::ExternItem> for Translator<'_> {
44+
impl Emission<ast::ExternItem> for Translator<'_, '_> {
4645
fn pre_emit(&mut self, node: &ast::ExternItem) -> Option<Label<generated::ExternItem>> {
4746
self.item_pre_emit(&node.clone().into()).map(Into::into)
4847
}
@@ -52,7 +51,7 @@ impl Emission<ast::ExternItem> for Translator<'_> {
5251
}
5352
}
5453

55-
impl Emission<ast::Meta> for Translator<'_> {
54+
impl Emission<ast::Meta> for Translator<'_, '_> {
5655
fn pre_emit(&mut self, _node: &ast::Meta) -> Option<Label<generated::Meta>> {
5756
self.macro_context_depth += 1;
5857
None
@@ -63,43 +62,43 @@ impl Emission<ast::Meta> for Translator<'_> {
6362
}
6463
}
6564

66-
impl Emission<ast::Fn> for Translator<'_> {
65+
impl Emission<ast::Fn> for Translator<'_, '_> {
6766
fn post_emit(&mut self, node: &ast::Fn, label: Label<generated::Function>) {
6867
self.emit_function_has_implementation(node, label);
6968
}
7069
}
7170

72-
impl Emission<ast::Struct> for Translator<'_> {
71+
impl Emission<ast::Struct> for Translator<'_, '_> {
7372
fn post_emit(&mut self, node: &ast::Struct, label: Label<generated::Struct>) {
7473
self.emit_derive_expansion(node, label);
7574
}
7675
}
7776

78-
impl Emission<ast::Enum> for Translator<'_> {
77+
impl Emission<ast::Enum> for Translator<'_, '_> {
7978
fn post_emit(&mut self, node: &ast::Enum, label: Label<generated::Enum>) {
8079
self.emit_derive_expansion(node, label);
8180
}
8281
}
8382

84-
impl Emission<ast::Union> for Translator<'_> {
83+
impl Emission<ast::Union> for Translator<'_, '_> {
8584
fn post_emit(&mut self, node: &ast::Union, label: Label<generated::Union>) {
8685
self.emit_derive_expansion(node, label);
8786
}
8887
}
8988

90-
impl Emission<ast::PathSegment> for Translator<'_> {
89+
impl Emission<ast::PathSegment> for Translator<'_, '_> {
9190
fn post_emit(&mut self, node: &ast::PathSegment, label: Label<generated::PathSegment>) {
9291
self.extract_types_from_path_segment(node, label);
9392
}
9493
}
9594

96-
impl Emission<ast::Const> for Translator<'_> {
95+
impl Emission<ast::Const> for Translator<'_, '_> {
9796
fn post_emit(&mut self, node: &ast::Const, label: Label<generated::Const>) {
9897
self.emit_const_has_implementation(node, label);
9998
}
10099
}
101100

102-
impl Emission<ast::MacroCall> for Translator<'_> {
101+
impl Emission<ast::MacroCall> for Translator<'_, '_> {
103102
fn post_emit(&mut self, node: &ast::MacroCall, label: Label<generated::MacroCall>) {
104103
self.extract_macro_call_expanded(node, label);
105104
}
@@ -123,13 +122,16 @@ pub enum SourceKind {
123122
Library,
124123
}
125124

126-
pub struct Translator<'a> {
125+
// `'a` is the (short) lifetime of the borrowed `path`, `'db` the lifetime of the borrowed
126+
// `Semantics`/database. They must stay separate: `Semantics<'db>` is invariant over `'db`, so
127+
// coupling it to the shorter `'a` fails to type-check.
128+
pub struct Translator<'a, 'db> {
127129
pub trap: TrapFile,
128130
path: &'a str,
129131
label: Label<generated::File>,
130132
line_index: LineIndex,
131133
file_id: Option<EditionedFileId>,
132-
pub semantics: Option<&'a Semantics<'a, RootDatabase>>,
134+
pub semantics: Option<&'db Semantics<'db, RootDatabase>>,
133135
source_kind: SourceKind,
134136
pub(crate) macro_context_depth: usize,
135137
diagnostic_count: usize,
@@ -144,15 +146,15 @@ const UNKNOWN_LOCATION: (LineCol, LineCol) =
144146

145147
const DIAGNOSTIC_LIMIT_PER_FILE: usize = 100;
146148

147-
impl<'a> Translator<'a> {
149+
impl<'a, 'db> Translator<'a, 'db> {
148150
pub fn new(
149151
trap: TrapFile,
150152
path: &'a str,
151153
label: Label<generated::File>,
152154
line_index: LineIndex,
153-
semantic_info: Option<&FileSemanticInformation<'a>>,
155+
semantic_info: Option<&FileSemanticInformation<'db>>,
154156
source_kind: SourceKind,
155-
) -> Translator<'a> {
157+
) -> Translator<'a, 'db> {
156158
Translator {
157159
trap,
158160
path,
@@ -372,7 +374,7 @@ impl<'a> Translator<'a> {
372374
if let Some(value) = semantics
373375
.hir_file_for(expanded)
374376
.macro_file()
375-
.and_then(|macro_call_id| semantics.db.parse_macro_expansion_error(macro_call_id))
377+
.and_then(|macro_call_id| macro_call_id.parse_macro_expansion_error(semantics.db))
376378
{
377379
if let Some(err) = &value.err {
378380
let error = err.render_to_string(semantics.db);
@@ -381,9 +383,8 @@ impl<'a> Translator<'a> {
381383
== hir_file_id.file_id().map(|f| f.file_id(semantics.db))
382384
{
383385
let location = err.span().range
384-
+ semantics
385-
.db
386-
.ast_id_map(hir_file_id)
386+
+ hir_file_id
387+
.ast_id_map(semantics.db)
387388
.get_erased(err.span().anchor.ast_id)
388389
.text_range()
389390
.start();
@@ -515,11 +516,9 @@ impl<'a> Translator<'a> {
515516
None => return false,
516517
}
517518
}
518-
HirFileId::MacroFile(macro_call) => sema
519-
.db
520-
.lookup_intern_macro_call(macro_call)
521-
.krate
522-
.cfg_options(sema.db),
519+
HirFileId::MacroFile(macro_call) => {
520+
macro_call.loc(sema.db).krate.cfg_options(sema.db)
521+
}
523522
};
524523
cfg_options.check(&cfg_expr) == Some(false)
525524
})
@@ -755,11 +754,11 @@ impl<'a> Translator<'a> {
755754
let semantics = self.semantics?;
756755
let db = semantics.db;
757756
let file_id = semantics.hir_file_for(adt.syntax());
758-
let span_map = db.span_map(file_id);
757+
let span_map = file_id.span_map(db);
759758
let call_site = span_map.span_for_range(adt.syntax().text_range());
760759
let input = syntax_node_to_token_tree(
761760
adt.syntax(),
762-
span_map.as_ref(),
761+
span_map,
763762
call_site,
764763
DocCommentDesugarMode::ProcMacro,
765764
);

‎rust/extractor/src/translate/generated.rs‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)