mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-01 12:24:29 +00:00
cargo clippy --fix
This commit is contained in:
parent
1ab8c7fd27
commit
fad4fa163c
178 changed files with 595 additions and 738 deletions
|
|
@ -207,7 +207,7 @@ pub fn diff(from: &SyntaxNode, to: &SyntaxNode) -> TreeDiff {
|
|||
TreeDiffInsertPos::AsFirstChild(lhs.clone().into())
|
||||
}
|
||||
};
|
||||
diff.insertions.entry(insert_pos).or_insert_with(Vec::new).push(element);
|
||||
diff.insertions.entry(insert_pos).or_default().push(element);
|
||||
}
|
||||
(Some(element), None) => {
|
||||
cov_mark::hit!(diff_delete);
|
||||
|
|
@ -239,7 +239,7 @@ pub fn diff(from: &SyntaxNode, to: &SyntaxNode) -> TreeDiff {
|
|||
TreeDiffInsertPos::AsFirstChild(lhs.clone().into())
|
||||
};
|
||||
|
||||
diff.insertions.entry(insert_pos).or_insert_with(Vec::new).extend(drain);
|
||||
diff.insertions.entry(insert_pos).or_default().extend(drain);
|
||||
rhs_children = rhs_children_clone;
|
||||
} else {
|
||||
go(diff, lhs_ele, rhs_ele);
|
||||
|
|
|
|||
|
|
@ -356,8 +356,12 @@ impl ast::UseTreeList {
|
|||
let remove_brace_in_use_tree_list = |u: &ast::UseTreeList| {
|
||||
let use_tree_count = u.use_trees().count();
|
||||
if use_tree_count == 1 {
|
||||
u.l_curly_token().map(ted::remove);
|
||||
u.r_curly_token().map(ted::remove);
|
||||
if let Some(a) = u.l_curly_token() {
|
||||
ted::remove(a)
|
||||
}
|
||||
if let Some(a) = u.r_curly_token() {
|
||||
ted::remove(a)
|
||||
}
|
||||
u.comma().for_each(ted::remove);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -478,6 +478,38 @@ impl Radix {
|
|||
}
|
||||
}
|
||||
|
||||
impl ast::Char {
|
||||
pub fn value(&self) -> Option<char> {
|
||||
let mut text = self.text();
|
||||
if text.starts_with('\'') {
|
||||
text = &text[1..];
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
if text.ends_with('\'') {
|
||||
text = &text[0..text.len() - 1];
|
||||
}
|
||||
|
||||
unescape_char(text).ok()
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::Byte {
|
||||
pub fn value(&self) -> Option<u8> {
|
||||
let mut text = self.text();
|
||||
if text.starts_with("b\'") {
|
||||
text = &text[2..];
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
if text.ends_with('\'') {
|
||||
text = &text[0..text.len() - 1];
|
||||
}
|
||||
|
||||
unescape_byte(text).ok()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::ast::{self, make, FloatNumber, IntNumber};
|
||||
|
|
@ -579,35 +611,3 @@ bcde", b"abcde",
|
|||
check_int_value("1_1_1_1_1_1", 111111);
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::Char {
|
||||
pub fn value(&self) -> Option<char> {
|
||||
let mut text = self.text();
|
||||
if text.starts_with('\'') {
|
||||
text = &text[1..];
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
if text.ends_with('\'') {
|
||||
text = &text[0..text.len() - 1];
|
||||
}
|
||||
|
||||
unescape_char(text).ok()
|
||||
}
|
||||
}
|
||||
|
||||
impl ast::Byte {
|
||||
pub fn value(&self) -> Option<u8> {
|
||||
let mut text = self.text();
|
||||
if text.starts_with("b\'") {
|
||||
text = &text[2..];
|
||||
} else {
|
||||
return None;
|
||||
}
|
||||
if text.ends_with('\'') {
|
||||
text = &text[0..text.len() - 1];
|
||||
}
|
||||
|
||||
unescape_byte(text).ok()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ impl<N: AstNode + std::fmt::Debug> std::fmt::Debug for AstPtr<N> {
|
|||
impl<N: AstNode> Copy for AstPtr<N> {}
|
||||
impl<N: AstNode> Clone for AstPtr<N> {
|
||||
fn clone(&self) -> AstPtr<N> {
|
||||
AstPtr { raw: self.raw.clone(), _ty: PhantomData }
|
||||
AstPtr { raw: self.raw, _ty: PhantomData }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -65,7 +65,7 @@ impl<N: AstNode> AstPtr<N> {
|
|||
}
|
||||
|
||||
pub fn syntax_node_ptr(&self) -> SyntaxNodePtr {
|
||||
self.raw.clone()
|
||||
self.raw
|
||||
}
|
||||
|
||||
pub fn text_range(&self) -> TextRange {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue