mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +00:00
Auto merge of #14755 - poliorcetics:clippy-fixes, r=Veykril
Fix: a TODO and some clippy fixes - fix(todo): implement IntoIterator for ArenaMap<IDX, V> - chore: remove unused method - fix: remove useless `return`s - fix: various clippy lints - fix: simplify boolean test to a single negation
This commit is contained in:
commit
2df56cadcb
10 changed files with 71 additions and 30 deletions
|
@ -485,7 +485,7 @@ impl CargoActor {
|
||||||
|
|
||||||
error.push_str(line);
|
error.push_str(line);
|
||||||
error.push('\n');
|
error.push('\n');
|
||||||
return false;
|
false
|
||||||
};
|
};
|
||||||
let output = streaming_output(
|
let output = streaming_output(
|
||||||
self.stdout,
|
self.stdout,
|
||||||
|
|
|
@ -35,11 +35,10 @@ pub(super) fn print_body_hir(db: &dyn DefDatabase, body: &Body, owner: DefWithBo
|
||||||
DefWithBodyId::VariantId(it) => {
|
DefWithBodyId::VariantId(it) => {
|
||||||
let src = it.parent.child_source(db);
|
let src = it.parent.child_source(db);
|
||||||
let variant = &src.value[it.local_id];
|
let variant = &src.value[it.local_id];
|
||||||
let name = match &variant.name() {
|
match &variant.name() {
|
||||||
Some(name) => name.to_string(),
|
Some(name) => name.to_string(),
|
||||||
None => "_".to_string(),
|
None => "_".to_string(),
|
||||||
};
|
}
|
||||||
format!("{name}")
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -456,7 +455,7 @@ impl<'a> Printer<'a> {
|
||||||
fn print_block(
|
fn print_block(
|
||||||
&mut self,
|
&mut self,
|
||||||
label: Option<&str>,
|
label: Option<&str>,
|
||||||
statements: &Box<[Statement]>,
|
statements: &[Statement],
|
||||||
tail: &Option<la_arena::Idx<Expr>>,
|
tail: &Option<la_arena::Idx<Expr>>,
|
||||||
) {
|
) {
|
||||||
self.whitespace();
|
self.whitespace();
|
||||||
|
@ -466,7 +465,7 @@ impl<'a> Printer<'a> {
|
||||||
w!(self, "{{");
|
w!(self, "{{");
|
||||||
if !statements.is_empty() || tail.is_some() {
|
if !statements.is_empty() || tail.is_some() {
|
||||||
self.indented(|p| {
|
self.indented(|p| {
|
||||||
for stmt in &**statements {
|
for stmt in statements {
|
||||||
p.print_stmt(stmt);
|
p.print_stmt(stmt);
|
||||||
}
|
}
|
||||||
if let Some(tail) = tail {
|
if let Some(tail) = tail {
|
||||||
|
|
|
@ -417,7 +417,7 @@ fn postfix_expr(
|
||||||
allow_calls = true;
|
allow_calls = true;
|
||||||
block_like = BlockLike::NotBlock;
|
block_like = BlockLike::NotBlock;
|
||||||
}
|
}
|
||||||
return (lhs, block_like);
|
(lhs, block_like)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn postfix_dot_expr<const FLOAT_RECOVERY: bool>(
|
fn postfix_dot_expr<const FLOAT_RECOVERY: bool>(
|
||||||
|
|
|
@ -19,7 +19,7 @@ use super::*;
|
||||||
// struct S;
|
// struct S;
|
||||||
pub(super) fn mod_contents(p: &mut Parser<'_>, stop_on_r_curly: bool) {
|
pub(super) fn mod_contents(p: &mut Parser<'_>, stop_on_r_curly: bool) {
|
||||||
attributes::inner_attrs(p);
|
attributes::inner_attrs(p);
|
||||||
while !p.at(EOF) && !(p.at(T!['}']) && stop_on_r_curly) {
|
while !(p.at(EOF) || (p.at(T!['}']) && stop_on_r_curly)) {
|
||||||
item_or_macro(p, stop_on_r_curly);
|
item_or_macro(p, stop_on_r_curly);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,7 +205,7 @@ impl<'t> Parser<'t> {
|
||||||
marker.bomb.defuse();
|
marker.bomb.defuse();
|
||||||
marker = new_marker;
|
marker = new_marker;
|
||||||
};
|
};
|
||||||
self.pos += 1 as usize;
|
self.pos += 1;
|
||||||
self.push_event(Event::FloatSplitHack { ends_in_dot });
|
self.push_event(Event::FloatSplitHack { ends_in_dot });
|
||||||
(ends_in_dot, marker)
|
(ends_in_dot, marker)
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,12 +46,10 @@ impl<'a> LexedStr<'a> {
|
||||||
// Tag the token as joint if it is float with a fractional part
|
// Tag the token as joint if it is float with a fractional part
|
||||||
// we use this jointness to inform the parser about what token split
|
// we use this jointness to inform the parser about what token split
|
||||||
// event to emit when we encounter a float literal in a field access
|
// event to emit when we encounter a float literal in a field access
|
||||||
if kind == SyntaxKind::FLOAT_NUMBER {
|
if kind == SyntaxKind::FLOAT_NUMBER && !self.text(i).ends_with('.') {
|
||||||
if !self.text(i).ends_with('.') {
|
|
||||||
res.was_joint();
|
res.was_joint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
was_joint = true;
|
was_joint = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -370,8 +370,7 @@ impl ast::BlockExpr {
|
||||||
match parent.kind() {
|
match parent.kind() {
|
||||||
FOR_EXPR | IF_EXPR => parent
|
FOR_EXPR | IF_EXPR => parent
|
||||||
.children()
|
.children()
|
||||||
.filter(|it| ast::Expr::can_cast(it.kind()))
|
.find(|it| ast::Expr::can_cast(it.kind()))
|
||||||
.next()
|
|
||||||
.map_or(true, |it| it == *self.syntax()),
|
.map_or(true, |it| it == *self.syntax()),
|
||||||
LET_ELSE | FN | WHILE_EXPR | LOOP_EXPR | CONST_BLOCK_PAT => false,
|
LET_ELSE | FN | WHILE_EXPR | LOOP_EXPR | CONST_BLOCK_PAT => false,
|
||||||
_ => true,
|
_ => true,
|
||||||
|
|
|
@ -195,7 +195,7 @@ pub fn ty_alias(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
s.push_str(";");
|
s.push(';');
|
||||||
ast_from_text(&s)
|
ast_from_text(&s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -399,7 +399,7 @@ pub fn hacky_block_expr(
|
||||||
format_to!(buf, " {t}\n")
|
format_to!(buf, " {t}\n")
|
||||||
} else if kind == SyntaxKind::WHITESPACE {
|
} else if kind == SyntaxKind::WHITESPACE {
|
||||||
let content = t.text().trim_matches(|c| c != '\n');
|
let content = t.text().trim_matches(|c| c != '\n');
|
||||||
if content.len() >= 1 {
|
if !content.is_empty() {
|
||||||
format_to!(buf, "{}", &content[1..])
|
format_to!(buf, "{}", &content[1..])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,13 +109,6 @@ pub enum ChangeKind {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Vfs {
|
impl Vfs {
|
||||||
/// Amount of files currently stored.
|
|
||||||
///
|
|
||||||
/// Note that this includes deleted files.
|
|
||||||
pub fn len(&self) -> usize {
|
|
||||||
self.data.len()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Id of the given path if it exists in the `Vfs` and is not deleted.
|
/// Id of the given path if it exists in the `Vfs` and is not deleted.
|
||||||
pub fn file_id(&self, path: &VfsPath) -> Option<FileId> {
|
pub fn file_id(&self, path: &VfsPath) -> Option<FileId> {
|
||||||
self.interner.get(path).filter(|&it| self.get(it).is_some())
|
self.interner.get(path).filter(|&it| self.get(it).is_some())
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use std::iter::Enumerate;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
use crate::Idx;
|
use crate::Idx;
|
||||||
|
@ -94,12 +95,6 @@ impl<T, V> ArenaMap<Idx<T>, V> {
|
||||||
.filter_map(|(idx, o)| Some((Self::from_idx(idx), o.as_mut()?)))
|
.filter_map(|(idx, o)| Some((Self::from_idx(idx), o.as_mut()?)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns an iterator over the arena indexes and values in the map.
|
|
||||||
// FIXME: Implement `IntoIterator` trait.
|
|
||||||
pub fn into_iter(self) -> impl Iterator<Item = (Idx<T>, V)> + DoubleEndedIterator {
|
|
||||||
self.v.into_iter().enumerate().filter_map(|(idx, o)| Some((Self::from_idx(idx), o?)))
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Gets the given key's corresponding entry in the map for in-place manipulation.
|
/// Gets the given key's corresponding entry in the map for in-place manipulation.
|
||||||
pub fn entry(&mut self, idx: Idx<T>) -> Entry<'_, Idx<T>, V> {
|
pub fn entry(&mut self, idx: Idx<T>) -> Entry<'_, Idx<T>, V> {
|
||||||
let idx = Self::to_idx(idx);
|
let idx = Self::to_idx(idx);
|
||||||
|
@ -154,6 +149,63 @@ impl<T, V> FromIterator<(Idx<V>, T)> for ArenaMap<Idx<V>, T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct ArenaMapIter<IDX, V> {
|
||||||
|
iter: Enumerate<std::vec::IntoIter<Option<V>>>,
|
||||||
|
_ty: PhantomData<IDX>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T, V> IntoIterator for ArenaMap<Idx<T>, V> {
|
||||||
|
type Item = (Idx<T>, V);
|
||||||
|
|
||||||
|
type IntoIter = ArenaMapIter<Idx<T>, V>;
|
||||||
|
|
||||||
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
|
let iter = self.v.into_iter().enumerate();
|
||||||
|
Self::IntoIter { iter, _ty: PhantomData }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T, V> ArenaMapIter<Idx<T>, V> {
|
||||||
|
fn mapper((idx, o): (usize, Option<V>)) -> Option<(Idx<T>, V)> {
|
||||||
|
Some((ArenaMap::<Idx<T>, V>::from_idx(idx), o?))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T, V> Iterator for ArenaMapIter<Idx<T>, V> {
|
||||||
|
type Item = (Idx<T>, V);
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
|
for next in self.iter.by_ref() {
|
||||||
|
match Self::mapper(next) {
|
||||||
|
Some(r) => return Some(r),
|
||||||
|
None => continue,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||||
|
self.iter.size_hint()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T, V> DoubleEndedIterator for ArenaMapIter<Idx<T>, V> {
|
||||||
|
#[inline]
|
||||||
|
fn next_back(&mut self) -> Option<Self::Item> {
|
||||||
|
while let Some(next_back) = self.iter.next_back() {
|
||||||
|
match Self::mapper(next_back) {
|
||||||
|
Some(r) => return Some(r),
|
||||||
|
None => continue,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// A view into a single entry in a map, which may either be vacant or occupied.
|
/// A view into a single entry in a map, which may either be vacant or occupied.
|
||||||
///
|
///
|
||||||
/// This `enum` is constructed from the [`entry`] method on [`ArenaMap`].
|
/// This `enum` is constructed from the [`entry`] method on [`ArenaMap`].
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue