diff options
Diffstat (limited to 'crates/syntax/src/ast')
-rw-r--r-- | crates/syntax/src/ast/edit.rs | 4 | ||||
-rw-r--r-- | crates/syntax/src/ast/node_ext.rs | 9 | ||||
-rw-r--r-- | crates/syntax/src/ast/token_ext.rs | 2 |
3 files changed, 12 insertions, 3 deletions
diff --git a/crates/syntax/src/ast/edit.rs b/crates/syntax/src/ast/edit.rs index 19107ee38..2663c0759 100644 --- a/crates/syntax/src/ast/edit.rs +++ b/crates/syntax/src/ast/edit.rs | |||
@@ -30,7 +30,7 @@ impl ast::UseTree { | |||
30 | let suffix = if self.path().as_ref() == Some(prefix) && self.use_tree_list().is_none() { | 30 | let suffix = if self.path().as_ref() == Some(prefix) && self.use_tree_list().is_none() { |
31 | make::path_unqualified(make::path_segment_self()) | 31 | make::path_unqualified(make::path_segment_self()) |
32 | } else { | 32 | } else { |
33 | match split_path_prefix(&prefix) { | 33 | match split_path_prefix(prefix) { |
34 | Some(it) => it, | 34 | Some(it) => it, |
35 | None => return self.clone(), | 35 | None => return self.clone(), |
36 | } | 36 | } |
@@ -95,7 +95,7 @@ impl fmt::Display for IndentLevel { | |||
95 | let indent = if len <= spaces.len() { | 95 | let indent = if len <= spaces.len() { |
96 | &spaces[..len] | 96 | &spaces[..len] |
97 | } else { | 97 | } else { |
98 | buf = iter::repeat(' ').take(len).collect::<String>(); | 98 | buf = " ".repeat(len); |
99 | &buf | 99 | &buf |
100 | }; | 100 | }; |
101 | fmt::Display::fmt(indent, f) | 101 | fmt::Display::fmt(indent, f) |
diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs index 3d27d2c1a..2bd9ad867 100644 --- a/crates/syntax/src/ast/node_ext.rs +++ b/crates/syntax/src/ast/node_ext.rs | |||
@@ -325,6 +325,15 @@ impl ast::Impl { | |||
325 | let second = types.next(); | 325 | let second = types.next(); |
326 | (first, second) | 326 | (first, second) |
327 | } | 327 | } |
328 | |||
329 | pub fn for_trait_name_ref(name_ref: &ast::NameRef) -> Option<ast::Impl> { | ||
330 | let this = name_ref.syntax().ancestors().find_map(ast::Impl::cast)?; | ||
331 | if this.trait_()?.syntax().text_range().start() == name_ref.syntax().text_range().start() { | ||
332 | Some(this) | ||
333 | } else { | ||
334 | None | ||
335 | } | ||
336 | } | ||
328 | } | 337 | } |
329 | 338 | ||
330 | #[derive(Debug, Clone, PartialEq, Eq)] | 339 | #[derive(Debug, Clone, PartialEq, Eq)] |
diff --git a/crates/syntax/src/ast/token_ext.rs b/crates/syntax/src/ast/token_ext.rs index 4b1e1ccee..ad52d9f54 100644 --- a/crates/syntax/src/ast/token_ext.rs +++ b/crates/syntax/src/ast/token_ext.rs | |||
@@ -242,7 +242,7 @@ impl ast::ByteString { | |||
242 | (Ok(c), true) if char_range.len() == 1 && Some(c) == text_iter.next() => (), | 242 | (Ok(c), true) if char_range.len() == 1 && Some(c) == text_iter.next() => (), |
243 | (Ok(c), true) => { | 243 | (Ok(c), true) => { |
244 | buf.reserve_exact(text.len()); | 244 | buf.reserve_exact(text.len()); |
245 | buf.extend_from_slice(&text[..char_range.start].as_bytes()); | 245 | buf.extend_from_slice(text[..char_range.start].as_bytes()); |
246 | buf.push(c as u8); | 246 | buf.push(c as u8); |
247 | } | 247 | } |
248 | (Err(_), _) => has_error = true, | 248 | (Err(_), _) => has_error = true, |