aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide/src/display.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2020-03-28 10:20:34 +0000
committerAleksey Kladov <[email protected]>2020-03-28 11:27:54 +0000
commit311cbbdad599d51c6f08f7dd72c299f7c0128bb2 (patch)
treed3ccef4aa8f681cc9de29f0435ad20e87911a6ba /crates/ra_ide/src/display.rs
parent6596e7cddfc00281362c3640781f6cd6bc0b5614 (diff)
Remove some unwraps
Diffstat (limited to 'crates/ra_ide/src/display.rs')
-rw-r--r--crates/ra_ide/src/display.rs13
1 files changed, 7 insertions, 6 deletions
diff --git a/crates/ra_ide/src/display.rs b/crates/ra_ide/src/display.rs
index c395057a7..722092de9 100644
--- a/crates/ra_ide/src/display.rs
+++ b/crates/ra_ide/src/display.rs
@@ -6,12 +6,13 @@ mod navigation_target;
6mod structure; 6mod structure;
7mod short_label; 7mod short_label;
8 8
9use std::fmt::{Display, Write}; 9use std::fmt::Display;
10 10
11use ra_syntax::{ 11use ra_syntax::{
12 ast::{self, AstNode, AttrsOwner, NameOwner, TypeParamsOwner}, 12 ast::{self, AstNode, AttrsOwner, NameOwner, TypeParamsOwner},
13 SyntaxKind::{ATTR, COMMENT}, 13 SyntaxKind::{ATTR, COMMENT},
14}; 14};
15use stdx::format_to;
15 16
16pub use function_signature::FunctionSignature; 17pub use function_signature::FunctionSignature;
17pub use navigation_target::NavigationTarget; 18pub use navigation_target::NavigationTarget;
@@ -78,18 +79,18 @@ pub(crate) fn rust_code_markup_with_doc(
78 doc: Option<&str>, 79 doc: Option<&str>,
79 mod_path: Option<&str>, 80 mod_path: Option<&str>,
80) -> String { 81) -> String {
81 let mut markup = "```rust\n".to_owned(); 82 let mut buf = "```rust\n".to_owned();
82 83
83 if let Some(mod_path) = mod_path { 84 if let Some(mod_path) = mod_path {
84 if !mod_path.is_empty() { 85 if !mod_path.is_empty() {
85 write!(markup, "{}\n", mod_path).unwrap(); 86 format_to!(buf, "{}\n", mod_path);
86 } 87 }
87 } 88 }
88 write!(markup, "{}\n```", code).unwrap(); 89 format_to!(buf, "{}\n```", code);
89 90
90 if let Some(doc) = doc { 91 if let Some(doc) = doc {
91 write!(markup, "\n\n{}", doc).unwrap(); 92 format_to!(buf, "\n\n{}", doc);
92 } 93 }
93 94
94 markup 95 buf
95} 96}