mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
Merge #8135
8135: more clippy::{perf, complexity, style} fixes r=Veykril a=matthiaskrgr Co-authored-by: Matthias Krüger <matthias.krueger@famsik.de>
This commit is contained in:
commit
d51cf133f6
@ -410,7 +410,7 @@ impl CrateId {
|
||||
|
||||
impl CrateData {
|
||||
fn add_dep(&mut self, name: CrateName, crate_id: CrateId) {
|
||||
self.dependencies.push(Dependency { name, crate_id })
|
||||
self.dependencies.push(Dependency { crate_id, name })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -255,9 +255,9 @@ impl Builder {
|
||||
fn make_dnf(expr: CfgExpr) -> CfgExpr {
|
||||
match expr {
|
||||
CfgExpr::Invalid | CfgExpr::Atom(_) | CfgExpr::Not(_) => expr,
|
||||
CfgExpr::Any(e) => CfgExpr::Any(e.into_iter().map(|expr| make_dnf(expr)).collect()),
|
||||
CfgExpr::Any(e) => CfgExpr::Any(e.into_iter().map(make_dnf).collect()),
|
||||
CfgExpr::All(e) => {
|
||||
let e = e.into_iter().map(|expr| make_nnf(expr)).collect::<Vec<_>>();
|
||||
let e = e.into_iter().map(make_nnf).collect::<Vec<_>>();
|
||||
|
||||
CfgExpr::Any(distribute_conj(&e))
|
||||
}
|
||||
@ -300,8 +300,8 @@ fn distribute_conj(conj: &[CfgExpr]) -> Vec<CfgExpr> {
|
||||
fn make_nnf(expr: CfgExpr) -> CfgExpr {
|
||||
match expr {
|
||||
CfgExpr::Invalid | CfgExpr::Atom(_) => expr,
|
||||
CfgExpr::Any(expr) => CfgExpr::Any(expr.into_iter().map(|expr| make_nnf(expr)).collect()),
|
||||
CfgExpr::All(expr) => CfgExpr::All(expr.into_iter().map(|expr| make_nnf(expr)).collect()),
|
||||
CfgExpr::Any(expr) => CfgExpr::Any(expr.into_iter().map(make_nnf).collect()),
|
||||
CfgExpr::All(expr) => CfgExpr::All(expr.into_iter().map(make_nnf).collect()),
|
||||
CfgExpr::Not(operand) => match *operand {
|
||||
CfgExpr::Invalid | CfgExpr::Atom(_) => CfgExpr::Not(operand.clone()), // Original negated expr
|
||||
CfgExpr::Not(expr) => {
|
||||
|
@ -213,7 +213,7 @@ impl Crate {
|
||||
Some(TokenTree::Leaf(Leaf::Literal(Literal{ref text, ..}))) => Some(text),
|
||||
_ => None
|
||||
}
|
||||
}).flat_map(|t| t).next();
|
||||
}).flatten().next();
|
||||
|
||||
doc_url.map(|s| s.trim_matches('"').trim_end_matches('/').to_owned() + "/")
|
||||
}
|
||||
|
@ -638,7 +638,7 @@ fn collect_attrs(
|
||||
owner: &dyn ast::AttrsOwner,
|
||||
) -> impl Iterator<Item = Either<ast::Attr, ast::Comment>> {
|
||||
let (inner_attrs, inner_docs) = inner_attributes(owner.syntax())
|
||||
.map_or((None, None), |(attrs, docs)| ((Some(attrs), Some(docs))));
|
||||
.map_or((None, None), |(attrs, docs)| (Some(attrs), Some(docs)));
|
||||
|
||||
let outer_attrs = owner.attrs().filter(|attr| attr.excl_token().is_none());
|
||||
let attrs = outer_attrs
|
||||
|
@ -472,7 +472,7 @@ impl Scope {
|
||||
}
|
||||
Scope::ExprScope(scope) => {
|
||||
if let Some((label, name)) = scope.expr_scopes.label(scope.scope_id) {
|
||||
f(name.clone(), ScopeDef::Label(label))
|
||||
f(name, ScopeDef::Label(label))
|
||||
}
|
||||
scope.expr_scopes.entries(scope.scope_id).iter().for_each(|e| {
|
||||
f(e.name().clone(), ScopeDef::Local(e.pat()));
|
||||
|
@ -173,7 +173,7 @@ fn macro_arg_text(db: &dyn AstDatabase, id: MacroCallId) -> Option<GreenNode> {
|
||||
};
|
||||
let loc = db.lookup_intern_macro(id);
|
||||
let arg = loc.kind.arg(db)?;
|
||||
Some(arg.green().to_owned())
|
||||
Some(arg.green())
|
||||
}
|
||||
|
||||
fn macro_arg(db: &dyn AstDatabase, id: MacroCallId) -> Option<Arc<(tt::Subtree, mbe::TokenMap)>> {
|
||||
|
@ -48,9 +48,8 @@ impl Name {
|
||||
|
||||
/// Resolve a name from the text of token.
|
||||
fn resolve(raw_text: &str) -> Name {
|
||||
let raw_start = "r#";
|
||||
if raw_text.starts_with(raw_start) {
|
||||
Name::new_text(SmolStr::new(&raw_text[raw_start.len()..]))
|
||||
if let Some(text) = raw_text.strip_prefix("r#") {
|
||||
Name::new_text(SmolStr::new(text))
|
||||
} else {
|
||||
Name::new_text(raw_text.into())
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ impl<'a> InferenceContext<'a> {
|
||||
let field_tys = def.map(|it| self.db.field_types(it)).unwrap_or_default();
|
||||
let (pre, post) = match ellipsis {
|
||||
Some(idx) => subpats.split_at(idx),
|
||||
None => (&subpats[..], &[][..]),
|
||||
None => (subpats, &[][..]),
|
||||
};
|
||||
let post_idx_offset = field_tys.iter().count() - post.len();
|
||||
|
||||
|
@ -946,8 +946,7 @@ pub(crate) fn trait_environment_query(
|
||||
let substs = Substitution::type_params(db, trait_id);
|
||||
let trait_ref = TraitRef { trait_id: to_chalk_trait_id(trait_id), substitution: substs };
|
||||
let pred = WhereClause::Implemented(trait_ref);
|
||||
let program_clause: chalk_ir::ProgramClause<Interner> =
|
||||
pred.clone().to_chalk(db).cast(&Interner);
|
||||
let program_clause: chalk_ir::ProgramClause<Interner> = pred.to_chalk(db).cast(&Interner);
|
||||
clauses.push(program_clause.into_from_env_clause(&Interner));
|
||||
}
|
||||
|
||||
|
@ -263,11 +263,10 @@ fn extend_list_item(node: &SyntaxNode) -> Option<TextRange> {
|
||||
) -> Option<SyntaxToken> {
|
||||
node.siblings_with_tokens(dir)
|
||||
.skip(1)
|
||||
.skip_while(|node| match node {
|
||||
NodeOrToken::Node(_) => false,
|
||||
NodeOrToken::Token(it) => is_single_line_ws(it),
|
||||
.find(|node| match node {
|
||||
NodeOrToken::Node(_) => true,
|
||||
NodeOrToken::Token(it) => !is_single_line_ws(it),
|
||||
})
|
||||
.next()
|
||||
.and_then(|it| it.into_token())
|
||||
.filter(|node| node.kind() == delimiter_kind)
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
use itertools::Itertools;
|
||||
use std::convert::identity;
|
||||
use syntax::{
|
||||
ast::{
|
||||
self,
|
||||
@ -140,7 +139,7 @@ fn relevant_line_comments(comment: &ast::Comment) -> Vec<Comment> {
|
||||
.filter(|s| !skippable(s))
|
||||
.map(|not| not.into_token().and_then(Comment::cast).filter(same_prefix))
|
||||
.take_while(|opt_com| opt_com.is_some())
|
||||
.filter_map(identity)
|
||||
.flatten()
|
||||
.skip(1); // skip the first element so we don't duplicate it in next_comments
|
||||
|
||||
let next_comments = comment
|
||||
@ -149,7 +148,7 @@ fn relevant_line_comments(comment: &ast::Comment) -> Vec<Comment> {
|
||||
.filter(|s| !skippable(s))
|
||||
.map(|not| not.into_token().and_then(Comment::cast).filter(same_prefix))
|
||||
.take_while(|opt_com| opt_com.is_some())
|
||||
.filter_map(identity);
|
||||
.flatten();
|
||||
|
||||
let mut comments: Vec<_> = prev_comments.collect();
|
||||
comments.reverse();
|
||||
|
@ -136,18 +136,13 @@ impl Refs {
|
||||
.into_iter()
|
||||
.filter(|r| {
|
||||
if let Def::ModuleDef(ModuleDef::Trait(tr)) = r.def {
|
||||
if tr
|
||||
.items(ctx.db())
|
||||
.into_iter()
|
||||
.find(|ai| {
|
||||
if let AssocItem::Function(f) = *ai {
|
||||
Def::ModuleDef(ModuleDef::Function(f)).is_referenced_in(ctx)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
})
|
||||
.is_some()
|
||||
{
|
||||
if tr.items(ctx.db()).into_iter().any(|ai| {
|
||||
if let AssocItem::Function(f) = ai {
|
||||
Def::ModuleDef(ModuleDef::Function(f)).is_referenced_in(ctx)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ fn compute_method_ranks(path: &ast::Path, ctx: &AssistContext) -> Option<FxHashM
|
||||
_ => None,
|
||||
})
|
||||
.enumerate()
|
||||
.map(|(idx, func)| ((func.name(ctx.db()).to_string(), idx)))
|
||||
.map(|(idx, func)| (func.name(ctx.db()).to_string(), idx))
|
||||
.collect(),
|
||||
)
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ fn test_has_block_expr_parent() {
|
||||
}
|
||||
|
||||
pub(crate) fn has_bind_pat_parent(element: SyntaxElement) -> bool {
|
||||
element.ancestors().find(|it| it.kind() == IDENT_PAT).is_some()
|
||||
element.ancestors().any(|it| it.kind() == IDENT_PAT)
|
||||
}
|
||||
#[test]
|
||||
fn test_has_bind_pat_parent() {
|
||||
|
@ -67,7 +67,7 @@ impl ParsedRule {
|
||||
) -> Result<Vec<ParsedRule>, SsrError> {
|
||||
let raw_pattern = pattern.as_rust_code();
|
||||
let raw_template = template.map(|t| t.as_rust_code());
|
||||
let raw_template = raw_template.as_ref().map(|s| s.as_str());
|
||||
let raw_template = raw_template.as_deref();
|
||||
let mut builder = RuleBuilder {
|
||||
placeholders_by_stand_in: pattern.placeholders_by_stand_in(),
|
||||
rules: Vec::new(),
|
||||
|
@ -304,7 +304,7 @@ impl BindingsBuilder {
|
||||
link_nodes: &'a Vec<LinkNode<Rc<BindingKind>>>,
|
||||
nodes: &mut Vec<&'a Rc<BindingKind>>,
|
||||
) {
|
||||
link_nodes.into_iter().for_each(|it| match it {
|
||||
link_nodes.iter().for_each(|it| match it {
|
||||
LinkNode::Node(it) => nodes.push(it),
|
||||
LinkNode::Parent { idx, len } => self.collect_nodes_ref(*idx, *len, nodes),
|
||||
});
|
||||
@ -713,10 +713,9 @@ fn match_meta_var(kind: &str, input: &mut TtIter) -> ExpandResult<Option<Fragmen
|
||||
.map(|ident| Some(tt::Leaf::from(ident.clone()).into()))
|
||||
.map_err(|()| err!("expected ident")),
|
||||
"tt" => input.expect_tt().map(Some).map_err(|()| err!()),
|
||||
"lifetime" => input
|
||||
.expect_lifetime()
|
||||
.map(|tt| Some(tt))
|
||||
.map_err(|()| err!("expected lifetime")),
|
||||
"lifetime" => {
|
||||
input.expect_lifetime().map(Some).map_err(|()| err!("expected lifetime"))
|
||||
}
|
||||
"literal" => {
|
||||
let neg = input.eat_char('-');
|
||||
input
|
||||
|
@ -356,6 +356,6 @@ impl<T> ExpandResult<T> {
|
||||
|
||||
impl<T: Default> From<Result<T, ExpandError>> for ExpandResult<T> {
|
||||
fn from(result: Result<T, ExpandError>) -> Self {
|
||||
result.map_or_else(|e| Self::only_err(e), |it| Self::ok(it))
|
||||
result.map_or_else(Self::only_err, Self::ok)
|
||||
}
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ impl<'a> Iterator for OpDelimitedIter<'a> {
|
||||
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
let len = self.inner.len() + if self.delimited.is_some() { 2 } else { 0 };
|
||||
let remain = len.checked_sub(self.idx).unwrap_or(0);
|
||||
let remain = len.saturating_sub(self.idx);
|
||||
(remain, Some(remain))
|
||||
}
|
||||
}
|
||||
|
@ -362,7 +362,7 @@ trait TokenConvertor {
|
||||
if let Some((kind, closed)) = delim {
|
||||
let mut subtree = tt::Subtree::default();
|
||||
let (id, idx) = self.id_alloc().open_delim(range);
|
||||
subtree.delimiter = Some(tt::Delimiter { kind, id });
|
||||
subtree.delimiter = Some(tt::Delimiter { id, kind });
|
||||
|
||||
while self.peek().map(|it| it.kind() != closed).unwrap_or(false) {
|
||||
self.collect_leaf(&mut subtree.token_trees);
|
||||
|
@ -1225,8 +1225,7 @@ macro_rules! m {
|
||||
)
|
||||
.expand_statements(r#"m!(C("0"))"#)
|
||||
.descendants()
|
||||
.find(|token| token.kind() == ERROR)
|
||||
.is_some());
|
||||
.any(|token| token.kind() == ERROR));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -137,60 +137,53 @@ fn collect_from_workspace(
|
||||
let stdout = BufReader::new(child_stdout);
|
||||
|
||||
let mut res = BuildDataMap::default();
|
||||
for message in cargo_metadata::Message::parse_stream(stdout) {
|
||||
if let Ok(message) = message {
|
||||
match message {
|
||||
Message::BuildScriptExecuted(BuildScript {
|
||||
package_id,
|
||||
out_dir,
|
||||
cfgs,
|
||||
env,
|
||||
..
|
||||
}) => {
|
||||
let cfgs = {
|
||||
let mut acc = Vec::new();
|
||||
for cfg in cfgs {
|
||||
match cfg.parse::<CfgFlag>() {
|
||||
Ok(it) => acc.push(it),
|
||||
Err(err) => {
|
||||
anyhow::bail!("invalid cfg from cargo-metadata: {}", err)
|
||||
}
|
||||
};
|
||||
}
|
||||
acc
|
||||
};
|
||||
let res = res.entry(package_id.repr.clone()).or_default();
|
||||
// cargo_metadata crate returns default (empty) path for
|
||||
// older cargos, which is not absolute, so work around that.
|
||||
if !out_dir.as_str().is_empty() {
|
||||
let out_dir = AbsPathBuf::assert(PathBuf::from(out_dir.into_os_string()));
|
||||
res.out_dir = Some(out_dir);
|
||||
res.cfgs = cfgs;
|
||||
for message in cargo_metadata::Message::parse_stream(stdout).flatten() {
|
||||
match message {
|
||||
Message::BuildScriptExecuted(BuildScript {
|
||||
package_id, out_dir, cfgs, env, ..
|
||||
}) => {
|
||||
let cfgs = {
|
||||
let mut acc = Vec::new();
|
||||
for cfg in cfgs {
|
||||
match cfg.parse::<CfgFlag>() {
|
||||
Ok(it) => acc.push(it),
|
||||
Err(err) => {
|
||||
anyhow::bail!("invalid cfg from cargo-metadata: {}", err)
|
||||
}
|
||||
};
|
||||
}
|
||||
acc
|
||||
};
|
||||
let res = res.entry(package_id.repr.clone()).or_default();
|
||||
// cargo_metadata crate returns default (empty) path for
|
||||
// older cargos, which is not absolute, so work around that.
|
||||
if !out_dir.as_str().is_empty() {
|
||||
let out_dir = AbsPathBuf::assert(PathBuf::from(out_dir.into_os_string()));
|
||||
res.out_dir = Some(out_dir);
|
||||
res.cfgs = cfgs;
|
||||
}
|
||||
|
||||
res.envs = env;
|
||||
}
|
||||
Message::CompilerArtifact(message) => {
|
||||
progress(format!("metadata {}", message.target.name));
|
||||
|
||||
if message.target.kind.contains(&"proc-macro".to_string()) {
|
||||
let package_id = message.package_id;
|
||||
// Skip rmeta file
|
||||
if let Some(filename) = message.filenames.iter().find(|name| is_dylib(name))
|
||||
{
|
||||
let filename = AbsPathBuf::assert(PathBuf::from(&filename));
|
||||
let res = res.entry(package_id.repr.clone()).or_default();
|
||||
res.proc_macro_dylib_path = Some(filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
Message::CompilerMessage(message) => {
|
||||
progress(message.target.name.clone());
|
||||
}
|
||||
Message::BuildFinished(_) => {}
|
||||
Message::TextLine(_) => {}
|
||||
_ => {}
|
||||
res.envs = env;
|
||||
}
|
||||
Message::CompilerArtifact(message) => {
|
||||
progress(format!("metadata {}", message.target.name));
|
||||
|
||||
if message.target.kind.contains(&"proc-macro".to_string()) {
|
||||
let package_id = message.package_id;
|
||||
// Skip rmeta file
|
||||
if let Some(filename) = message.filenames.iter().find(|name| is_dylib(name)) {
|
||||
let filename = AbsPathBuf::assert(PathBuf::from(&filename));
|
||||
let res = res.entry(package_id.repr.clone()).or_default();
|
||||
res.proc_macro_dylib_path = Some(filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
Message::CompilerMessage(message) => {
|
||||
progress(message.target.name.clone());
|
||||
}
|
||||
Message::BuildFinished(_) => {}
|
||||
Message::TextLine(_) => {}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -242,11 +242,8 @@ impl GlobalState {
|
||||
}
|
||||
BuildDataProgress::End(collector) => {
|
||||
self.fetch_build_data_completed();
|
||||
let workspaces = (*self.workspaces)
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|it| Ok(it))
|
||||
.collect();
|
||||
let workspaces =
|
||||
(*self.workspaces).clone().into_iter().map(Ok).collect();
|
||||
self.switch_workspaces(workspaces, Some(collector));
|
||||
(Some(Progress::End), None)
|
||||
}
|
||||
|
@ -237,7 +237,7 @@ impl GlobalState {
|
||||
None => None,
|
||||
};
|
||||
|
||||
if &*self.workspaces == &workspaces && self.workspace_build_data == workspace_build_data {
|
||||
if *self.workspaces == workspaces && self.workspace_build_data == workspace_build_data {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ impl<'a> Project<'a> {
|
||||
}
|
||||
|
||||
pub(crate) fn server(self) -> Server {
|
||||
let tmp_dir = self.tmp_dir.unwrap_or_else(|| TestDir::new());
|
||||
let tmp_dir = self.tmp_dir.unwrap_or_else(TestDir::new);
|
||||
static INIT: Once = Once::new();
|
||||
INIT.call_once(|| {
|
||||
env_logger::builder().is_test(true).parse_env("RA_LOG").try_init().unwrap();
|
||||
|
@ -567,7 +567,7 @@ impl<'a> SyntaxRewriter<'a> {
|
||||
|
||||
fn element_to_green(element: SyntaxElement) -> NodeOrToken<rowan::GreenNode, rowan::GreenToken> {
|
||||
match element {
|
||||
NodeOrToken::Node(it) => NodeOrToken::Node(it.green().to_owned()),
|
||||
NodeOrToken::Node(it) => NodeOrToken::Node(it.green()),
|
||||
NodeOrToken::Token(it) => NodeOrToken::Token(it.green().to_owned()),
|
||||
}
|
||||
}
|
||||
@ -625,7 +625,7 @@ fn position_of_child(parent: &SyntaxNode, child: SyntaxElement) -> usize {
|
||||
|
||||
fn to_green_element(element: SyntaxElement) -> NodeOrToken<rowan::GreenNode, rowan::GreenToken> {
|
||||
match element {
|
||||
NodeOrToken::Node(it) => it.green().to_owned().into(),
|
||||
NodeOrToken::Node(it) => it.green().into(),
|
||||
NodeOrToken::Token(it) => it.green().to_owned().into(),
|
||||
}
|
||||
}
|
||||
|
@ -333,8 +333,7 @@ impl ast::Use {
|
||||
.and_then(ast::Whitespace::cast);
|
||||
if let Some(next_ws) = next_ws {
|
||||
let ws_text = next_ws.syntax().text();
|
||||
if ws_text.starts_with('\n') {
|
||||
let rest = &ws_text[1..];
|
||||
if let Some(rest) = ws_text.strip_prefix('\n') {
|
||||
if rest.is_empty() {
|
||||
res.delete(next_ws.syntax())
|
||||
} else {
|
||||
@ -462,8 +461,7 @@ impl ast::MatchArmList {
|
||||
let end = if let Some(comma) = start
|
||||
.siblings_with_tokens(Direction::Next)
|
||||
.skip(1)
|
||||
.skip_while(|it| it.kind().is_trivia())
|
||||
.next()
|
||||
.find(|it| !it.kind().is_trivia())
|
||||
.filter(|it| it.kind() == T![,])
|
||||
{
|
||||
comma
|
||||
@ -597,7 +595,7 @@ impl IndentLevel {
|
||||
pub fn from_node(node: &SyntaxNode) -> IndentLevel {
|
||||
match node.first_token() {
|
||||
Some(it) => Self::from_token(&it),
|
||||
None => return IndentLevel(0),
|
||||
None => IndentLevel(0),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,16 +11,16 @@ impl ast::AttrsOwner for ast::Expr {}
|
||||
|
||||
impl ast::Expr {
|
||||
pub fn is_block_like(&self) -> bool {
|
||||
match self {
|
||||
matches!(
|
||||
self,
|
||||
ast::Expr::IfExpr(_)
|
||||
| ast::Expr::LoopExpr(_)
|
||||
| ast::Expr::ForExpr(_)
|
||||
| ast::Expr::WhileExpr(_)
|
||||
| ast::Expr::BlockExpr(_)
|
||||
| ast::Expr::MatchExpr(_)
|
||||
| ast::Expr::EffectExpr(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
| ast::Expr::LoopExpr(_)
|
||||
| ast::Expr::ForExpr(_)
|
||||
| ast::Expr::WhileExpr(_)
|
||||
| ast::Expr::BlockExpr(_)
|
||||
| ast::Expr::MatchExpr(_)
|
||||
| ast::Expr::EffectExpr(_)
|
||||
)
|
||||
}
|
||||
|
||||
pub fn name_ref(&self) -> Option<ast::NameRef> {
|
||||
@ -151,20 +151,20 @@ pub enum BinOp {
|
||||
|
||||
impl BinOp {
|
||||
pub fn is_assignment(self) -> bool {
|
||||
match self {
|
||||
matches!(
|
||||
self,
|
||||
BinOp::Assignment
|
||||
| BinOp::AddAssign
|
||||
| BinOp::DivAssign
|
||||
| BinOp::MulAssign
|
||||
| BinOp::RemAssign
|
||||
| BinOp::ShrAssign
|
||||
| BinOp::ShlAssign
|
||||
| BinOp::SubAssign
|
||||
| BinOp::BitOrAssign
|
||||
| BinOp::BitAndAssign
|
||||
| BinOp::BitXorAssign => true,
|
||||
_ => false,
|
||||
}
|
||||
| BinOp::AddAssign
|
||||
| BinOp::DivAssign
|
||||
| BinOp::MulAssign
|
||||
| BinOp::RemAssign
|
||||
| BinOp::ShrAssign
|
||||
| BinOp::ShlAssign
|
||||
| BinOp::SubAssign
|
||||
| BinOp::BitOrAssign
|
||||
| BinOp::BitAndAssign
|
||||
| BinOp::BitXorAssign
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -532,7 +532,7 @@ fn ast_from_text<N: AstNode>(text: &str) -> N {
|
||||
}
|
||||
|
||||
fn unroot(n: SyntaxNode) -> SyntaxNode {
|
||||
SyntaxNode::new_root(n.green().to_owned())
|
||||
SyntaxNode::new_root(n.green())
|
||||
}
|
||||
|
||||
pub mod tokens {
|
||||
|
@ -58,10 +58,7 @@ impl From<ast::MacroDef> for Macro {
|
||||
|
||||
impl AstNode for Macro {
|
||||
fn can_cast(kind: SyntaxKind) -> bool {
|
||||
match kind {
|
||||
SyntaxKind::MACRO_RULES | SyntaxKind::MACRO_DEF => true,
|
||||
_ => false,
|
||||
}
|
||||
matches!(kind, SyntaxKind::MACRO_RULES | SyntaxKind::MACRO_DEF)
|
||||
}
|
||||
fn cast(syntax: SyntaxNode) -> Option<Self> {
|
||||
let res = match syntax.kind() {
|
||||
@ -462,10 +459,8 @@ impl ast::FieldExpr {
|
||||
pub fn field_access(&self) -> Option<FieldKind> {
|
||||
if let Some(nr) = self.name_ref() {
|
||||
Some(FieldKind::Name(nr))
|
||||
} else if let Some(tok) = self.index_token() {
|
||||
Some(FieldKind::Index(tok))
|
||||
} else {
|
||||
None
|
||||
self.index_token().map(FieldKind::Index)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -482,16 +477,10 @@ impl ast::SlicePat {
|
||||
let prefix = args
|
||||
.peeking_take_while(|p| match p {
|
||||
ast::Pat::RestPat(_) => false,
|
||||
ast::Pat::IdentPat(bp) => match bp.pat() {
|
||||
Some(ast::Pat::RestPat(_)) => false,
|
||||
_ => true,
|
||||
},
|
||||
ast::Pat::IdentPat(bp) => !matches!(bp.pat(), Some(ast::Pat::RestPat(_))),
|
||||
ast::Pat::RefPat(rp) => match rp.pat() {
|
||||
Some(ast::Pat::RestPat(_)) => false,
|
||||
Some(ast::Pat::IdentPat(bp)) => match bp.pat() {
|
||||
Some(ast::Pat::RestPat(_)) => false,
|
||||
_ => true,
|
||||
},
|
||||
Some(ast::Pat::IdentPat(bp)) => !matches!(bp.pat(), Some(ast::Pat::RestPat(_))),
|
||||
_ => true,
|
||||
},
|
||||
_ => true,
|
||||
|
@ -494,9 +494,8 @@ pub trait HasFormatSpecifier: AstToken {
|
||||
}
|
||||
_ => {
|
||||
while let Some((_, Ok(next_char))) = chars.peek() {
|
||||
match next_char {
|
||||
'{' => break,
|
||||
_ => {}
|
||||
if next_char == &'{' {
|
||||
break;
|
||||
}
|
||||
chars.next();
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ impl CheckReparse {
|
||||
TextRange::at(delete_start.try_into().unwrap(), delete_len.try_into().unwrap());
|
||||
let edited_text =
|
||||
format!("{}{}{}", &text[..delete_start], &insert, &text[delete_start + delete_len..]);
|
||||
let edit = Indel { delete, insert };
|
||||
let edit = Indel { insert, delete };
|
||||
Some(CheckReparse { text, edit, edited_text })
|
||||
}
|
||||
|
||||
|
@ -297,7 +297,7 @@ fn validate_path_keywords(segment: ast::PathSegment, errors: &mut Vec<SyntaxErro
|
||||
}
|
||||
};
|
||||
}
|
||||
return None;
|
||||
None
|
||||
}
|
||||
|
||||
fn all_supers(path: &ast::Path) -> bool {
|
||||
@ -314,7 +314,7 @@ fn validate_path_keywords(segment: ast::PathSegment, errors: &mut Vec<SyntaxErro
|
||||
return all_supers(subpath);
|
||||
}
|
||||
|
||||
return true;
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -239,9 +239,8 @@ impl Subtree {
|
||||
|
||||
let mut res = String::new();
|
||||
res.push_str(delim.0);
|
||||
let mut iter = self.token_trees.iter();
|
||||
let mut last = None;
|
||||
while let Some(child) = iter.next() {
|
||||
for child in &self.token_trees {
|
||||
let s = match child {
|
||||
TokenTree::Leaf(it) => {
|
||||
let s = match it {
|
||||
|
@ -154,8 +154,8 @@ fn hide_hash_comments(text: &str) -> String {
|
||||
fn reveal_hash_comments(text: &str) -> String {
|
||||
text.split('\n') // want final newline
|
||||
.map(|it| {
|
||||
if it.starts_with("# ") {
|
||||
&it[2..]
|
||||
if let Some(stripped) = it.strip_prefix("# ") {
|
||||
stripped
|
||||
} else if it == "#" {
|
||||
""
|
||||
} else {
|
||||
|
@ -60,12 +60,10 @@ fn collect_tests(s: &str) -> Vec<Test> {
|
||||
let mut res = Vec::new();
|
||||
for comment_block in extract_comment_blocks(s) {
|
||||
let first_line = &comment_block[0];
|
||||
let (name, ok) = if first_line.starts_with("test ") {
|
||||
let name = first_line["test ".len()..].to_string();
|
||||
(name, true)
|
||||
} else if first_line.starts_with("test_err ") {
|
||||
let name = first_line["test_err ".len()..].to_string();
|
||||
(name, false)
|
||||
let (name, ok) = if let Some(name) = first_line.strip_prefix("test ") {
|
||||
(name.to_string(), true)
|
||||
} else if let Some(name) = first_line.strip_prefix("test_err ") {
|
||||
(name.to_string(), false)
|
||||
} else {
|
||||
continue;
|
||||
};
|
||||
|
@ -707,7 +707,7 @@ fn extract_struct_trait(node: &mut AstNodeSrc, trait_name: &str, methods: &[&str
|
||||
let mut to_remove = Vec::new();
|
||||
for (i, field) in node.fields.iter().enumerate() {
|
||||
let method_name = field.method_name().to_string();
|
||||
if methods.iter().any(|&it| it == &method_name) {
|
||||
if methods.iter().any(|&it| it == method_name) {
|
||||
to_remove.push(i);
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ fn main() -> Result<()> {
|
||||
match flags.subcommand {
|
||||
flags::XtaskCmd::Help(_) => {
|
||||
println!("{}", flags::Xtask::HELP);
|
||||
return Ok(());
|
||||
Ok(())
|
||||
}
|
||||
flags::XtaskCmd::Install(cmd) => cmd.run(),
|
||||
flags::XtaskCmd::FuzzTests(_) => run_fuzzer(),
|
||||
|
@ -167,7 +167,7 @@ impl Host {
|
||||
|
||||
return Ok(Host { os, cpu, mem });
|
||||
|
||||
fn read_field<'a>(path: &str, field: &str) -> Result<String> {
|
||||
fn read_field(path: &str, field: &str) -> Result<String> {
|
||||
let text = read_file(path)?;
|
||||
|
||||
let line = text
|
||||
|
@ -193,7 +193,7 @@ https://github.blog/2015-06-08-how-to-undo-almost-anything-with-git/#redo-after-
|
||||
}
|
||||
}
|
||||
|
||||
fn deny_clippy(path: &PathBuf, text: &String) {
|
||||
fn deny_clippy(path: &Path, text: &str) {
|
||||
let ignore = &[
|
||||
// The documentation in string literals may contain anything for its own purposes
|
||||
"ide_completion/src/generated_lint_completions.rs",
|
||||
|
Loading…
Reference in New Issue
Block a user