Skip to content

Commit ac19a71

Browse files
committed
Use Attrs::docs in runnables instead of DocCommentsOwner
1 parent f304ce3 commit ac19a71

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

crates/hir_def/src/attr.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ impl Documentation {
3232
}
3333
}
3434

35-
impl Into<String> for Documentation {
36-
fn into(self) -> String {
37-
self.0
35+
impl From<Documentation> for String {
36+
fn from(Documentation(string): Documentation) -> Self {
37+
string
3838
}
3939
}
4040

crates/ide/src/runnables.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use hir::{AsAssocItem, Attrs, HirFileId, InFile, Semantics};
66
use ide_db::RootDatabase;
77
use itertools::Itertools;
88
use syntax::{
9-
ast::{self, AstNode, AttrsOwner, DocCommentsOwner, ModuleItemOwner, NameOwner},
9+
ast::{self, AstNode, AttrsOwner, ModuleItemOwner, NameOwner},
1010
match_ast, SyntaxNode,
1111
};
1212

@@ -118,6 +118,7 @@ fn runnable_fn(
118118
) -> Option<Runnable> {
119119
let name_string = fn_def.name()?.text().to_string();
120120

121+
let attrs = Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &fn_def));
121122
let kind = if name_string == "main" {
122123
RunnableKind::Bin
123124
} else {
@@ -162,14 +163,13 @@ fn runnable_fn(
162163
RunnableKind::Test { test_id, attr }
163164
} else if fn_def.has_atom_attr("bench") {
164165
RunnableKind::Bench { test_id }
165-
} else if has_runnable_doc_test(&fn_def) {
166+
} else if has_runnable_doc_test(&attrs) {
166167
RunnableKind::DocTest { test_id }
167168
} else {
168169
return None;
169170
}
170171
};
171172

172-
let attrs = Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &fn_def));
173173
let cfg = attrs.cfg();
174174

175175
let nav = if let RunnableKind::DocTest { .. } = kind {
@@ -189,13 +189,13 @@ fn runnable_struct(
189189
struct_def: ast::Struct,
190190
file_id: FileId,
191191
) -> Option<Runnable> {
192-
if !has_runnable_doc_test(&struct_def) {
193-
return None;
194-
}
195192
let name_string = struct_def.name()?.text().to_string();
196193

197194
let attrs =
198195
Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &struct_def));
196+
if !has_runnable_doc_test(&attrs) {
197+
return None;
198+
}
199199
let cfg = attrs.cfg();
200200

201201
let test_id = match sema.to_def(&struct_def).map(|def| def.module(sema.db)) {
@@ -240,11 +240,11 @@ const RUSTDOC_FENCE: &str = "```";
240240
const RUSTDOC_CODE_BLOCK_ATTRIBUTES_RUNNABLE: &[&str] =
241241
&["", "rust", "should_panic", "edition2015", "edition2018"];
242242

243-
fn has_runnable_doc_test(def: &dyn DocCommentsOwner) -> bool {
244-
def.doc_comment_text().map_or(false, |comments_text| {
243+
fn has_runnable_doc_test(attrs: &hir::Attrs) -> bool {
244+
attrs.docs().map_or(false, |doc| {
245245
let mut in_code_block = false;
246246

247-
for line in comments_text.lines() {
247+
for line in String::from(doc).lines() {
248248
if let Some(header) = line.strip_prefix(RUSTDOC_FENCE) {
249249
in_code_block = !in_code_block;
250250

0 commit comments

Comments
 (0)