Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/base_db/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/cfg/src/dnf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() + "/")
}
Expand Down
2 changes: 1 addition & 1 deletion crates/hir_def/src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/hir_def/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
2 changes: 1 addition & 1 deletion crates/hir_expand/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)>> {
Expand Down
5 changes: 2 additions & 3 deletions crates/hir_expand/src/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
2 changes: 1 addition & 1 deletion crates/hir_ty/src/infer/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
3 changes: 1 addition & 2 deletions crates/hir_ty/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
7 changes: 3 additions & 4 deletions crates/ide/src/extend_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
5 changes: 2 additions & 3 deletions crates/ide_assists/src/handlers/convert_comment_block.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use itertools::Itertools;
use std::convert::identity;
use syntax::{
ast::{
self,
Expand Down Expand Up @@ -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
Expand All @@ -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();
Expand Down
19 changes: 7 additions & 12 deletions crates/ide_assists/src/handlers/expand_glob_import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ide_assists/src/handlers/reorder_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/ide_completion/src/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion crates/ide_ssr/src/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
9 changes: 4 additions & 5 deletions crates/mbe/src/expander/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
});
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion crates/mbe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion crates/mbe/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
Expand Down
2 changes: 1 addition & 1 deletion crates/mbe/src/syntax_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions crates/mbe/src/tests/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
91 changes: 42 additions & 49 deletions crates/project_model/src/build_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
};
}

res.envs = env;
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;
}
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);
}

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(_) => {}
_ => {}
}
Message::CompilerMessage(message) => {
progress(message.target.name.clone());
}
Message::BuildFinished(_) => {}
Message::TextLine(_) => {}
_ => {}
}
}

Expand Down
7 changes: 2 additions & 5 deletions crates/rust-analyzer/src/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rust-analyzer/src/reload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion crates/rust-analyzer/tests/rust-analyzer/support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading