From ac19a71459765f897c3bb38ffd9a5a179e0beb02 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 11 Dec 2020 20:11:03 +0100 Subject: Use Attrs::docs in runnables instead of DocCommentsOwner --- crates/hir_def/src/attr.rs | 6 +++--- crates/ide/src/runnables.rs | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'crates') diff --git a/crates/hir_def/src/attr.rs b/crates/hir_def/src/attr.rs index 228d706db..ff8fb7483 100644 --- a/crates/hir_def/src/attr.rs +++ b/crates/hir_def/src/attr.rs @@ -32,9 +32,9 @@ impl Documentation { } } -impl Into for Documentation { - fn into(self) -> String { - self.0 +impl From for String { + fn from(Documentation(string): Documentation) -> Self { + string } } diff --git a/crates/ide/src/runnables.rs b/crates/ide/src/runnables.rs index e15411777..646f63704 100644 --- a/crates/ide/src/runnables.rs +++ b/crates/ide/src/runnables.rs @@ -6,7 +6,7 @@ use hir::{AsAssocItem, Attrs, HirFileId, InFile, Semantics}; use ide_db::RootDatabase; use itertools::Itertools; use syntax::{ - ast::{self, AstNode, AttrsOwner, DocCommentsOwner, ModuleItemOwner, NameOwner}, + ast::{self, AstNode, AttrsOwner, ModuleItemOwner, NameOwner}, match_ast, SyntaxNode, }; @@ -118,6 +118,7 @@ fn runnable_fn( ) -> Option { let name_string = fn_def.name()?.text().to_string(); + let attrs = Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &fn_def)); let kind = if name_string == "main" { RunnableKind::Bin } else { @@ -162,14 +163,13 @@ fn runnable_fn( RunnableKind::Test { test_id, attr } } else if fn_def.has_atom_attr("bench") { RunnableKind::Bench { test_id } - } else if has_runnable_doc_test(&fn_def) { + } else if has_runnable_doc_test(&attrs) { RunnableKind::DocTest { test_id } } else { return None; } }; - let attrs = Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &fn_def)); let cfg = attrs.cfg(); let nav = if let RunnableKind::DocTest { .. } = kind { @@ -189,13 +189,13 @@ fn runnable_struct( struct_def: ast::Struct, file_id: FileId, ) -> Option { - if !has_runnable_doc_test(&struct_def) { - return None; - } let name_string = struct_def.name()?.text().to_string(); let attrs = Attrs::from_attrs_owner(sema.db, InFile::new(HirFileId::from(file_id), &struct_def)); + if !has_runnable_doc_test(&attrs) { + return None; + } let cfg = attrs.cfg(); let test_id = match sema.to_def(&struct_def).map(|def| def.module(sema.db)) { @@ -240,11 +240,11 @@ const RUSTDOC_FENCE: &str = "```"; const RUSTDOC_CODE_BLOCK_ATTRIBUTES_RUNNABLE: &[&str] = &["", "rust", "should_panic", "edition2015", "edition2018"]; -fn has_runnable_doc_test(def: &dyn DocCommentsOwner) -> bool { - def.doc_comment_text().map_or(false, |comments_text| { +fn has_runnable_doc_test(attrs: &hir::Attrs) -> bool { + attrs.docs().map_or(false, |doc| { let mut in_code_block = false; - for line in comments_text.lines() { + for line in String::from(doc).lines() { if let Some(header) = line.strip_prefix(RUSTDOC_FENCE) { in_code_block = !in_code_block; -- cgit v1.2.3