mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 12:33:33 +00:00
Fix clippy warnings
This commit is contained in:
parent
f3336509e5
commit
6344a7f362
11 changed files with 38 additions and 34 deletions
|
@ -74,7 +74,7 @@ impl fmt::Display for Position {
|
|||
impl Expect {
|
||||
pub fn assert_eq(&self, actual: &str) {
|
||||
let trimmed = self.trimmed();
|
||||
if &trimmed == actual {
|
||||
if trimmed == actual {
|
||||
return;
|
||||
}
|
||||
Runtime::fail_expect(self, &trimmed, actual);
|
||||
|
|
|
@ -108,7 +108,7 @@ struct FlycheckActor {
|
|||
|
||||
enum Event {
|
||||
Restart(Restart),
|
||||
CheckEvent(Option<cargo_metadata::Message>),
|
||||
CheckEvent(Option<Box<cargo_metadata::Message>>),
|
||||
}
|
||||
|
||||
impl FlycheckActor {
|
||||
|
@ -123,7 +123,7 @@ impl FlycheckActor {
|
|||
let check_chan = self.cargo_handle.as_ref().map(|cargo| &cargo.receiver);
|
||||
select! {
|
||||
recv(inbox) -> msg => msg.ok().map(Event::Restart),
|
||||
recv(check_chan.unwrap_or(&never())) -> msg => Some(Event::CheckEvent(msg.ok())),
|
||||
recv(check_chan.unwrap_or(&never())) -> msg => Some(Event::CheckEvent(msg.ok().map(Box::new))),
|
||||
}
|
||||
}
|
||||
fn run(mut self, inbox: Receiver<Restart>) {
|
||||
|
@ -149,7 +149,7 @@ impl FlycheckActor {
|
|||
let res = cargo_handle.join();
|
||||
self.send(Message::Progress(Progress::DidFinish(res)));
|
||||
}
|
||||
Event::CheckEvent(Some(message)) => match message {
|
||||
Event::CheckEvent(Some(message)) => match *message {
|
||||
cargo_metadata::Message::CompilerArtifact(msg) => {
|
||||
self.send(Message::Progress(Progress::DidCheckCrate(msg.target.name)));
|
||||
}
|
||||
|
|
|
@ -13,18 +13,18 @@ pub struct ArenaMap<ID, V> {
|
|||
|
||||
impl<T, V> ArenaMap<Idx<T>, V> {
|
||||
pub fn insert(&mut self, id: Idx<T>, t: V) {
|
||||
let idx = Self::to_idx(id);
|
||||
let idx = Self::into_idx(id);
|
||||
|
||||
self.v.resize_with((idx + 1).max(self.v.len()), || None);
|
||||
self.v[idx] = Some(t);
|
||||
}
|
||||
|
||||
pub fn get(&self, id: Idx<T>) -> Option<&V> {
|
||||
self.v.get(Self::to_idx(id)).and_then(|it| it.as_ref())
|
||||
self.v.get(Self::into_idx(id)).and_then(|it| it.as_ref())
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self, id: Idx<T>) -> Option<&mut V> {
|
||||
self.v.get_mut(Self::to_idx(id)).and_then(|it| it.as_mut())
|
||||
self.v.get_mut(Self::into_idx(id)).and_then(|it| it.as_mut())
|
||||
}
|
||||
|
||||
pub fn values(&self) -> impl Iterator<Item = &V> {
|
||||
|
@ -39,7 +39,7 @@ impl<T, V> ArenaMap<Idx<T>, V> {
|
|||
self.v.iter().enumerate().filter_map(|(idx, o)| Some((Self::from_idx(idx), o.as_ref()?)))
|
||||
}
|
||||
|
||||
fn to_idx(id: Idx<T>) -> usize {
|
||||
fn into_idx(id: Idx<T>) -> usize {
|
||||
u32::from(id.into_raw()) as usize
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ impl<T, V> ArenaMap<Idx<T>, V> {
|
|||
impl<T, V> std::ops::Index<Idx<V>> for ArenaMap<Idx<V>, T> {
|
||||
type Output = T;
|
||||
fn index(&self, id: Idx<V>) -> &T {
|
||||
self.v[Self::to_idx(id)].as_ref().unwrap()
|
||||
self.v[Self::into_idx(id)].as_ref().unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -276,7 +276,7 @@ impl<'a> TtIter<'a> {
|
|||
Ok(tt::Subtree {
|
||||
delimiter: None,
|
||||
token_trees: vec![
|
||||
tt::Leaf::Punct(punct.clone()).into(),
|
||||
tt::Leaf::Punct(*punct).into(),
|
||||
tt::Leaf::Ident(ident.clone()).into(),
|
||||
],
|
||||
}
|
||||
|
|
|
@ -243,12 +243,10 @@ fn lambda_expr(p: &mut Parser) -> CompletedMarker {
|
|||
// test lambda_ret_block
|
||||
// fn main() { || -> i32 { 92 }(); }
|
||||
block_expr(p);
|
||||
} else if p.at_ts(EXPR_FIRST) {
|
||||
expr(p);
|
||||
} else {
|
||||
if p.at_ts(EXPR_FIRST) {
|
||||
expr(p);
|
||||
} else {
|
||||
p.error("expected expression");
|
||||
}
|
||||
p.error("expected expression");
|
||||
}
|
||||
m.complete(p, CLOSURE_EXPR)
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ impl ProcMacroProcessSrv {
|
|||
}
|
||||
Some(it) => it,
|
||||
};
|
||||
sender.send(Task { req: req.into(), result_tx }).unwrap();
|
||||
sender.send(Task { req, result_tx }).unwrap();
|
||||
let res = result_rx
|
||||
.recv()
|
||||
.map_err(|_| ra_tt::ExpansionError::Unknown("Proc macro thread is closed.".into()))?;
|
||||
|
|
|
@ -76,10 +76,6 @@ impl TextEdit {
|
|||
self.indels.iter()
|
||||
}
|
||||
|
||||
pub fn into_iter(self) -> vec::IntoIter<Indel> {
|
||||
self.indels.into_iter()
|
||||
}
|
||||
|
||||
pub fn apply(&self, text: &mut String) {
|
||||
match self.len() {
|
||||
0 => return,
|
||||
|
@ -141,6 +137,15 @@ impl TextEdit {
|
|||
}
|
||||
}
|
||||
|
||||
impl IntoIterator for TextEdit {
|
||||
type Item = Indel;
|
||||
type IntoIter = vec::IntoIter<Self::Item>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.indels.into_iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl TextEditBuilder {
|
||||
pub fn replace(&mut self, range: TextRange, replace_with: String) {
|
||||
self.indels.push(Indel::replace(range, replace_with))
|
||||
|
|
|
@ -107,7 +107,7 @@ fn print_debug_subtree(f: &mut fmt::Formatter<'_>, subtree: &Subtree, level: usi
|
|||
for (idx, child) in subtree.token_trees.iter().enumerate() {
|
||||
print_debug_token(f, child, level + 1)?;
|
||||
if idx != subtree.token_trees.len() - 1 {
|
||||
writeln!(f, "")?;
|
||||
writeln!(f)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@ pub fn is_ci() -> bool {
|
|||
|
||||
pub trait SepBy: Sized {
|
||||
/// Returns an `impl fmt::Display`, which joins elements via a separator.
|
||||
fn sep_by<'a>(self, sep: &'a str) -> SepByBuilder<'a, Self>;
|
||||
fn sep_by(self, sep: &str) -> SepByBuilder<'_, Self>;
|
||||
}
|
||||
|
||||
impl<I> SepBy for I
|
||||
|
@ -18,7 +18,7 @@ where
|
|||
I: Iterator,
|
||||
I::Item: fmt::Display,
|
||||
{
|
||||
fn sep_by<'a>(self, sep: &'a str) -> SepByBuilder<'a, Self> {
|
||||
fn sep_by(self, sep: &str) -> SepByBuilder<'_, Self> {
|
||||
SepByBuilder::new(sep, self)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,9 @@ impl FileSet {
|
|||
pub fn len(&self) -> usize {
|
||||
self.files.len()
|
||||
}
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.len() == 0
|
||||
}
|
||||
pub fn resolve_path(&self, anchor: FileId, path: &str) -> Option<FileId> {
|
||||
let mut base = self.paths[&anchor].clone();
|
||||
base.pop();
|
||||
|
|
|
@ -91,18 +91,16 @@ fn generate_nodes(kinds: KindsSrc<'_>, grammar: &AstSrc) -> Result<String> {
|
|||
support::children(&self.syntax)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if let Some(token_kind) = field.token_kind() {
|
||||
quote! {
|
||||
pub fn #method_name(&self) -> Option<#ty> {
|
||||
support::token(&self.syntax, #token_kind)
|
||||
}
|
||||
} else if let Some(token_kind) = field.token_kind() {
|
||||
quote! {
|
||||
pub fn #method_name(&self) -> Option<#ty> {
|
||||
support::token(&self.syntax, #token_kind)
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
pub fn #method_name(&self) -> Option<#ty> {
|
||||
support::child(&self.syntax)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
quote! {
|
||||
pub fn #method_name(&self) -> Option<#ty> {
|
||||
support::child(&self.syntax)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue