aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_assists/src/handlers/add_custom_impl.rs4
-rw-r--r--crates/ra_assists/src/handlers/move_guard.rs6
-rw-r--r--crates/ra_hir/src/code_model.rs36
-rw-r--r--crates/ra_hir_def/src/item_scope.rs2
-rw-r--r--crates/ra_hir_def/src/lib.rs4
-rw-r--r--crates/ra_hir_expand/src/builtin_macro.rs11
-rw-r--r--crates/ra_hir_expand/src/quote.rs5
-rw-r--r--crates/ra_hir_ty/src/diagnostics.rs2
-rw-r--r--crates/ra_hir_ty/src/expr.rs2
-rw-r--r--crates/ra_hir_ty/src/infer/coerce.rs7
-rw-r--r--crates/ra_hir_ty/src/infer/expr.rs16
-rw-r--r--crates/ra_hir_ty/src/infer/unify.rs5
-rw-r--r--crates/ra_hir_ty/src/lib.rs5
-rw-r--r--crates/ra_hir_ty/src/op.rs24
-rw-r--r--crates/ra_hir_ty/src/test_db.rs7
-rw-r--r--crates/ra_hir_ty/src/tests.rs8
-rw-r--r--crates/ra_hir_ty/src/traits.rs9
-rw-r--r--crates/ra_hir_ty/src/traits/builtin.rs4
-rw-r--r--crates/ra_hir_ty/src/traits/chalk.rs3
-rw-r--r--crates/ra_ide/src/call_info.rs2
-rw-r--r--crates/ra_ide/src/completion/complete_trait_impl.rs8
-rw-r--r--crates/ra_ide/src/completion/completion_item.rs4
-rw-r--r--crates/ra_ide/src/display/function_signature.rs5
-rw-r--r--crates/ra_ide/src/display/navigation_target.rs4
-rw-r--r--crates/ra_ide/src/references.rs2
-rw-r--r--crates/ra_ide/src/ssr.rs14
-rw-r--r--crates/ra_mbe/src/parser.rs17
-rw-r--r--crates/ra_parser/src/grammar/items.rs2
-rw-r--r--crates/ra_parser/src/parser.rs4
-rw-r--r--crates/ra_project_model/src/cargo_workspace.rs2
-rw-r--r--crates/ra_project_model/src/lib.rs67
-rw-r--r--xtask/src/install.rs9
32 files changed, 141 insertions, 159 deletions
diff --git a/crates/ra_assists/src/handlers/add_custom_impl.rs b/crates/ra_assists/src/handlers/add_custom_impl.rs
index 4d3a72c18..74aa4b001 100644
--- a/crates/ra_assists/src/handlers/add_custom_impl.rs
+++ b/crates/ra_assists/src/handlers/add_custom_impl.rs
@@ -43,7 +43,7 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> {
43 .clone(); 43 .clone();
44 44
45 let trait_token = 45 let trait_token =
46 ctx.token_at_offset().filter(|t| t.kind() == IDENT && *t.text() != attr_name).next()?; 46 ctx.token_at_offset().find(|t| t.kind() == IDENT && *t.text() != attr_name)?;
47 47
48 let annotated = attr.syntax().siblings(Direction::Next).find_map(ast::Name::cast)?; 48 let annotated = attr.syntax().siblings(Direction::Next).find_map(ast::Name::cast)?;
49 let annotated_name = annotated.syntax().text().to_string(); 49 let annotated_name = annotated.syntax().text().to_string();
@@ -86,7 +86,7 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> {
86 .next_sibling_or_token() 86 .next_sibling_or_token()
87 .filter(|t| t.kind() == WHITESPACE) 87 .filter(|t| t.kind() == WHITESPACE)
88 .map(|t| t.text_range()) 88 .map(|t| t.text_range())
89 .unwrap_or(TextRange::from_to(TextUnit::from(0), TextUnit::from(0))); 89 .unwrap_or_else(|| TextRange::from_to(TextUnit::from(0), TextUnit::from(0)));
90 edit.delete(line_break_range); 90 edit.delete(line_break_range);
91 91
92 attr_range.len() + line_break_range.len() 92 attr_range.len() + line_break_range.len()
diff --git a/crates/ra_assists/src/handlers/move_guard.rs b/crates/ra_assists/src/handlers/move_guard.rs
index a61a2ba3e..1cc498638 100644
--- a/crates/ra_assists/src/handlers/move_guard.rs
+++ b/crates/ra_assists/src/handlers/move_guard.rs
@@ -44,7 +44,7 @@ pub(crate) fn move_guard_to_arm_body(ctx: AssistCtx) -> Option<Assist> {
44 edit.target(guard.syntax().text_range()); 44 edit.target(guard.syntax().text_range());
45 let offseting_amount = match space_before_guard.and_then(|it| it.into_token()) { 45 let offseting_amount = match space_before_guard.and_then(|it| it.into_token()) {
46 Some(tok) => { 46 Some(tok) => {
47 if let Some(_) = ast::Whitespace::cast(tok.clone()) { 47 if ast::Whitespace::cast(tok.clone()).is_some() {
48 let ele = tok.text_range(); 48 let ele = tok.text_range();
49 edit.delete(ele); 49 edit.delete(ele);
50 ele.len() 50 ele.len()
@@ -98,11 +98,11 @@ pub(crate) fn move_arm_cond_to_match_guard(ctx: AssistCtx) -> Option<Assist> {
98 let then_block = if_expr.then_branch()?; 98 let then_block = if_expr.then_branch()?;
99 99
100 // Not support if with else branch 100 // Not support if with else branch
101 if let Some(_) = if_expr.else_branch() { 101 if if_expr.else_branch().is_some() {
102 return None; 102 return None;
103 } 103 }
104 // Not support moving if let to arm guard 104 // Not support moving if let to arm guard
105 if let Some(_) = cond.pat() { 105 if cond.pat().is_some() {
106 return None; 106 return None;
107 } 107 }
108 108
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs
index fe9149c9d..1bdcda069 100644
--- a/crates/ra_hir/src/code_model.rs
+++ b/crates/ra_hir/src/code_model.rs
@@ -988,20 +988,17 @@ impl Type {
988 988
989 pub fn fields(&self, db: &impl HirDatabase) -> Vec<(StructField, Type)> { 989 pub fn fields(&self, db: &impl HirDatabase) -> Vec<(StructField, Type)> {
990 if let Ty::Apply(a_ty) = &self.ty.value { 990 if let Ty::Apply(a_ty) = &self.ty.value {
991 match a_ty.ctor { 991 if let TypeCtor::Adt(AdtId::StructId(s)) = a_ty.ctor {
992 TypeCtor::Adt(AdtId::StructId(s)) => { 992 let var_def = s.into();
993 let var_def = s.into(); 993 return db
994 return db 994 .field_types(var_def)
995 .field_types(var_def) 995 .iter()
996 .iter() 996 .map(|(local_id, ty)| {
997 .map(|(local_id, ty)| { 997 let def = StructField { parent: var_def.into(), id: local_id };
998 let def = StructField { parent: var_def.into(), id: local_id }; 998 let ty = ty.clone().subst(&a_ty.parameters);
999 let ty = ty.clone().subst(&a_ty.parameters); 999 (def, self.derived(ty))
1000 (def, self.derived(ty)) 1000 })
1001 }) 1001 .collect();
1002 .collect();
1003 }
1004 _ => {}
1005 } 1002 }
1006 }; 1003 };
1007 Vec::new() 1004 Vec::new()
@@ -1010,14 +1007,11 @@ impl Type {
1010 pub fn tuple_fields(&self, _db: &impl HirDatabase) -> Vec<Type> { 1007 pub fn tuple_fields(&self, _db: &impl HirDatabase) -> Vec<Type> {
1011 let mut res = Vec::new(); 1008 let mut res = Vec::new();
1012 if let Ty::Apply(a_ty) = &self.ty.value { 1009 if let Ty::Apply(a_ty) = &self.ty.value {
1013 match a_ty.ctor { 1010 if let TypeCtor::Tuple { .. } = a_ty.ctor {
1014 TypeCtor::Tuple { .. } => { 1011 for ty in a_ty.parameters.iter() {
1015 for ty in a_ty.parameters.iter() { 1012 let ty = ty.clone();
1016 let ty = ty.clone(); 1013 res.push(self.derived(ty));
1017 res.push(self.derived(ty));
1018 }
1019 } 1014 }
1020 _ => {}
1021 } 1015 }
1022 }; 1016 };
1023 res 1017 res
diff --git a/crates/ra_hir_def/src/item_scope.rs b/crates/ra_hir_def/src/item_scope.rs
index f8dc06d10..6e958ca75 100644
--- a/crates/ra_hir_def/src/item_scope.rs
+++ b/crates/ra_hir_def/src/item_scope.rs
@@ -157,7 +157,7 @@ impl ItemScope {
157 } 157 }
158 158
159 pub(crate) fn resolutions<'a>(&'a self) -> impl Iterator<Item = (Name, PerNs)> + 'a { 159 pub(crate) fn resolutions<'a>(&'a self) -> impl Iterator<Item = (Name, PerNs)> + 'a {
160 self.visible.iter().map(|(name, res)| (name.clone(), res.clone())) 160 self.visible.iter().map(|(name, res)| (name.clone(), *res))
161 } 161 }
162 162
163 pub(crate) fn collect_legacy_macros(&self) -> FxHashMap<Name, MacroDefId> { 163 pub(crate) fn collect_legacy_macros(&self) -> FxHashMap<Name, MacroDefId> {
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs
index aa0b558b8..564b5fec5 100644
--- a/crates/ra_hir_def/src/lib.rs
+++ b/crates/ra_hir_def/src/lib.rs
@@ -460,7 +460,7 @@ impl AsMacroCall for AstIdWithPath<ast::MacroCall> {
460 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>, 460 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>,
461 ) -> Option<MacroCallId> { 461 ) -> Option<MacroCallId> {
462 let def = resolver(self.path.clone())?; 462 let def = resolver(self.path.clone())?;
463 Some(def.as_call_id(db, MacroCallKind::FnLike(self.ast_id.clone()))) 463 Some(def.as_call_id(db, MacroCallKind::FnLike(self.ast_id)))
464 } 464 }
465} 465}
466 466
@@ -471,6 +471,6 @@ impl AsMacroCall for AstIdWithPath<ast::ModuleItem> {
471 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>, 471 resolver: impl Fn(path::ModPath) -> Option<MacroDefId>,
472 ) -> Option<MacroCallId> { 472 ) -> Option<MacroCallId> {
473 let def = resolver(self.path.clone())?; 473 let def = resolver(self.path.clone())?;
474 Some(def.as_call_id(db, MacroCallKind::Attr(self.ast_id.clone()))) 474 Some(def.as_call_id(db, MacroCallKind::Attr(self.ast_id)))
475 } 475 }
476} 476}
diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs
index 4adaa9b07..f2bb0bddb 100644
--- a/crates/ra_hir_expand/src/builtin_macro.rs
+++ b/crates/ra_hir_expand/src/builtin_macro.rs
@@ -155,14 +155,11 @@ fn compile_error_expand(
155 tt: &tt::Subtree, 155 tt: &tt::Subtree,
156) -> Result<tt::Subtree, mbe::ExpandError> { 156) -> Result<tt::Subtree, mbe::ExpandError> {
157 if tt.count() == 1 { 157 if tt.count() == 1 {
158 match &tt.token_trees[0] { 158 if let tt::TokenTree::Leaf(tt::Leaf::Literal(it)) = &tt.token_trees[0] {
159 tt::TokenTree::Leaf(tt::Leaf::Literal(it)) => { 159 let s = it.text.as_str();
160 let s = it.text.as_str(); 160 if s.contains('"') {
161 if s.contains('"') { 161 return Ok(quote! { loop { #it }});
162 return Ok(quote! { loop { #it }});
163 }
164 } 162 }
165 _ => {}
166 }; 163 };
167 } 164 }
168 165
diff --git a/crates/ra_hir_expand/src/quote.rs b/crates/ra_hir_expand/src/quote.rs
index b54e00b68..57e7eebf9 100644
--- a/crates/ra_hir_expand/src/quote.rs
+++ b/crates/ra_hir_expand/src/quote.rs
@@ -15,14 +15,13 @@ macro_rules! __quote {
15 ( @SUBTREE $delim:ident $($tt:tt)* ) => { 15 ( @SUBTREE $delim:ident $($tt:tt)* ) => {
16 { 16 {
17 let children = $crate::__quote!($($tt)*); 17 let children = $crate::__quote!($($tt)*);
18 let subtree = tt::Subtree { 18 tt::Subtree {
19 delimiter: Some(tt::Delimiter { 19 delimiter: Some(tt::Delimiter {
20 kind: tt::DelimiterKind::$delim, 20 kind: tt::DelimiterKind::$delim,
21 id: tt::TokenId::unspecified(), 21 id: tt::TokenId::unspecified(),
22 }), 22 }),
23 token_trees: $crate::quote::IntoTt::to_tokens(children), 23 token_trees: $crate::quote::IntoTt::to_tokens(children),
24 }; 24 }
25 subtree
26 } 25 }
27 }; 26 };
28 27
diff --git a/crates/ra_hir_ty/src/diagnostics.rs b/crates/ra_hir_ty/src/diagnostics.rs
index 5054189cc..6eafdc8f6 100644
--- a/crates/ra_hir_ty/src/diagnostics.rs
+++ b/crates/ra_hir_ty/src/diagnostics.rs
@@ -40,7 +40,7 @@ impl Diagnostic for MissingFields {
40 use std::fmt::Write; 40 use std::fmt::Write;
41 let mut message = String::from("Missing structure fields:\n"); 41 let mut message = String::from("Missing structure fields:\n");
42 for field in &self.missed_fields { 42 for field in &self.missed_fields {
43 write!(message, "- {}\n", field).unwrap(); 43 writeln!(message, "- {}", field).unwrap();
44 } 44 }
45 message 45 message
46 } 46 }
diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs
index f752a9f09..0d11b537c 100644
--- a/crates/ra_hir_ty/src/expr.rs
+++ b/crates/ra_hir_ty/src/expr.rs
@@ -138,7 +138,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
138 _ => return, 138 _ => return,
139 }; 139 };
140 140
141 if params.len() == 2 && &params[0] == &mismatch.actual { 141 if params.len() == 2 && params[0] == mismatch.actual {
142 let (_, source_map) = db.body_with_source_map(self.func.into()); 142 let (_, source_map) = db.body_with_source_map(self.func.into());
143 143
144 if let Some(source_ptr) = source_map.expr_syntax(id) { 144 if let Some(source_ptr) = source_map.expr_syntax(id) {
diff --git a/crates/ra_hir_ty/src/infer/coerce.rs b/crates/ra_hir_ty/src/infer/coerce.rs
index 4a0eabdfc..fb6a51b12 100644
--- a/crates/ra_hir_ty/src/infer/coerce.rs
+++ b/crates/ra_hir_ty/src/infer/coerce.rs
@@ -26,7 +26,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
26 /// Note that it is only possible that one type are coerced to another. 26 /// Note that it is only possible that one type are coerced to another.
27 /// Coercing both types to another least upper bound type is not possible in rustc, 27 /// Coercing both types to another least upper bound type is not possible in rustc,
28 /// which will simply result in "incompatible types" error. 28 /// which will simply result in "incompatible types" error.
29 pub(super) fn coerce_merge_branch<'t>(&mut self, ty1: &Ty, ty2: &Ty) -> Ty { 29 pub(super) fn coerce_merge_branch(&mut self, ty1: &Ty, ty2: &Ty) -> Ty {
30 if self.coerce(ty1, ty2) { 30 if self.coerce(ty1, ty2) {
31 ty2.clone() 31 ty2.clone()
32 } else if self.coerce(ty2, ty1) { 32 } else if self.coerce(ty2, ty1) {
@@ -252,15 +252,14 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
252 let unsize_generic_index = { 252 let unsize_generic_index = {
253 let mut index = None; 253 let mut index = None;
254 let mut multiple_param = false; 254 let mut multiple_param = false;
255 field_tys[last_field_id].value.walk(&mut |ty| match ty { 255 field_tys[last_field_id].value.walk(&mut |ty| {
256 &Ty::Bound(idx) => { 256 if let &Ty::Bound(idx) = ty {
257 if index.is_none() { 257 if index.is_none() {
258 index = Some(idx); 258 index = Some(idx);
259 } else if Some(idx) != index { 259 } else if Some(idx) != index {
260 multiple_param = true; 260 multiple_param = true;
261 } 261 }
262 } 262 }
263 _ => {}
264 }); 263 });
265 264
266 if multiple_param { 265 if multiple_param {
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs
index 0af94ae32..9d5f75625 100644
--- a/crates/ra_hir_ty/src/infer/expr.rs
+++ b/crates/ra_hir_ty/src/infer/expr.rs
@@ -35,8 +35,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
35 TypeMismatch { expected: expected.ty.clone(), actual: ty.clone() }, 35 TypeMismatch { expected: expected.ty.clone(), actual: ty.clone() },
36 ); 36 );
37 } 37 }
38 let ty = self.resolve_ty_as_possible(ty); 38 self.resolve_ty_as_possible(ty)
39 ty
40 } 39 }
41 40
42 /// Infer type of expression with possibly implicit coerce to the expected type. 41 /// Infer type of expression with possibly implicit coerce to the expected type.
@@ -155,8 +154,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
155 }; 154 };
156 self.register_obligations_for_call(&callee_ty); 155 self.register_obligations_for_call(&callee_ty);
157 self.check_call_arguments(args, &param_tys); 156 self.check_call_arguments(args, &param_tys);
158 let ret_ty = self.normalize_associated_types_in(ret_ty); 157 self.normalize_associated_types_in(ret_ty)
159 ret_ty
160 } 158 }
161 Expr::MethodCall { receiver, args, method_name, generic_args } => self 159 Expr::MethodCall { receiver, args, method_name, generic_args } => self
162 .infer_method_call(tgt_expr, *receiver, &args, &method_name, generic_args.as_ref()), 160 .infer_method_call(tgt_expr, *receiver, &args, &method_name, generic_args.as_ref()),
@@ -280,14 +278,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
280 } 278 }
281 Expr::Await { expr } => { 279 Expr::Await { expr } => {
282 let inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); 280 let inner_ty = self.infer_expr_inner(*expr, &Expectation::none());
283 let ty = 281 self.resolve_associated_type(inner_ty, self.resolve_future_future_output())
284 self.resolve_associated_type(inner_ty, self.resolve_future_future_output());
285 ty
286 } 282 }
287 Expr::Try { expr } => { 283 Expr::Try { expr } => {
288 let inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); 284 let inner_ty = self.infer_expr_inner(*expr, &Expectation::none());
289 let ty = self.resolve_associated_type(inner_ty, self.resolve_ops_try_ok()); 285 self.resolve_associated_type(inner_ty, self.resolve_ops_try_ok())
290 ty
291 } 286 }
292 Expr::Cast { expr, type_ref } => { 287 Expr::Cast { expr, type_ref } => {
293 let _inner_ty = self.infer_expr_inner(*expr, &Expectation::none()); 288 let _inner_ty = self.infer_expr_inner(*expr, &Expectation::none());
@@ -611,8 +606,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> {
611 self.unify(&expected_receiver_ty, &actual_receiver_ty); 606 self.unify(&expected_receiver_ty, &actual_receiver_ty);
612 607
613 self.check_call_arguments(args, &param_tys); 608 self.check_call_arguments(args, &param_tys);
614 let ret_ty = self.normalize_associated_types_in(ret_ty); 609 self.normalize_associated_types_in(ret_ty)
615 ret_ty
616 } 610 }
617 611
618 fn check_call_arguments(&mut self, args: &[ExprId], param_tys: &[Ty]) { 612 fn check_call_arguments(&mut self, args: &[ExprId], param_tys: &[Ty]) {
diff --git a/crates/ra_hir_ty/src/infer/unify.rs b/crates/ra_hir_ty/src/infer/unify.rs
index 1dc842f40..9c7996572 100644
--- a/crates/ra_hir_ty/src/infer/unify.rs
+++ b/crates/ra_hir_ty/src/infer/unify.rs
@@ -140,13 +140,12 @@ where
140impl<T> Canonicalized<T> { 140impl<T> Canonicalized<T> {
141 pub fn decanonicalize_ty(&self, mut ty: Ty) -> Ty { 141 pub fn decanonicalize_ty(&self, mut ty: Ty) -> Ty {
142 ty.walk_mut_binders( 142 ty.walk_mut_binders(
143 &mut |ty, binders| match ty { 143 &mut |ty, binders| {
144 &mut Ty::Bound(idx) => { 144 if let &mut Ty::Bound(idx) = ty {
145 if idx as usize >= binders && (idx as usize - binders) < self.free_vars.len() { 145 if idx as usize >= binders && (idx as usize - binders) < self.free_vars.len() {
146 *ty = Ty::Infer(self.free_vars[idx as usize - binders]); 146 *ty = Ty::Infer(self.free_vars[idx as usize - binders]);
147 } 147 }
148 } 148 }
149 _ => {}
150 }, 149 },
151 0, 150 0,
152 ); 151 );
diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs
index 302bb8aa2..13c5e6c6b 100644
--- a/crates/ra_hir_ty/src/lib.rs
+++ b/crates/ra_hir_ty/src/lib.rs
@@ -763,8 +763,8 @@ pub trait TypeWalk {
763 Self: Sized, 763 Self: Sized,
764 { 764 {
765 self.walk_mut_binders( 765 self.walk_mut_binders(
766 &mut |ty, binders| match ty { 766 &mut |ty, binders| {
767 &mut Ty::Bound(idx) => { 767 if let &mut Ty::Bound(idx) = ty {
768 if idx as usize >= binders && (idx as usize - binders) < substs.len() { 768 if idx as usize >= binders && (idx as usize - binders) < substs.len() {
769 *ty = substs.0[idx as usize - binders].clone(); 769 *ty = substs.0[idx as usize - binders].clone();
770 } else if idx as usize >= binders + substs.len() { 770 } else if idx as usize >= binders + substs.len() {
@@ -772,7 +772,6 @@ pub trait TypeWalk {
772 *ty = Ty::Bound(idx - substs.len() as u32); 772 *ty = Ty::Bound(idx - substs.len() as u32);
773 } 773 }
774 } 774 }
775 _ => {}
776 }, 775 },
777 0, 776 0,
778 ); 777 );
diff --git a/crates/ra_hir_ty/src/op.rs b/crates/ra_hir_ty/src/op.rs
index ae253ca04..54e2bd05a 100644
--- a/crates/ra_hir_ty/src/op.rs
+++ b/crates/ra_hir_ty/src/op.rs
@@ -30,20 +30,18 @@ pub(super) fn binary_op_return_ty(op: BinaryOp, lhs_ty: Ty, rhs_ty: Ty) -> Ty {
30pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty { 30pub(super) fn binary_op_rhs_expectation(op: BinaryOp, lhs_ty: Ty) -> Ty {
31 match op { 31 match op {
32 BinaryOp::LogicOp(..) => Ty::simple(TypeCtor::Bool), 32 BinaryOp::LogicOp(..) => Ty::simple(TypeCtor::Bool),
33 BinaryOp::Assignment { op: None } | BinaryOp::CmpOp(CmpOp::Eq { negated: _ }) => { 33 BinaryOp::Assignment { op: None } | BinaryOp::CmpOp(CmpOp::Eq { .. }) => match lhs_ty {
34 match lhs_ty { 34 Ty::Apply(ApplicationTy { ctor, .. }) => match ctor {
35 Ty::Apply(ApplicationTy { ctor, .. }) => match ctor { 35 TypeCtor::Int(..)
36 TypeCtor::Int(..) 36 | TypeCtor::Float(..)
37 | TypeCtor::Float(..) 37 | TypeCtor::Str
38 | TypeCtor::Str 38 | TypeCtor::Char
39 | TypeCtor::Char 39 | TypeCtor::Bool => lhs_ty,
40 | TypeCtor::Bool => lhs_ty,
41 _ => Ty::Unknown,
42 },
43 Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty,
44 _ => Ty::Unknown, 40 _ => Ty::Unknown,
45 } 41 },
46 } 42 Ty::Infer(InferTy::IntVar(..)) | Ty::Infer(InferTy::FloatVar(..)) => lhs_ty,
43 _ => Ty::Unknown,
44 },
47 BinaryOp::ArithOp(ArithOp::Shl) | BinaryOp::ArithOp(ArithOp::Shr) => Ty::Unknown, 45 BinaryOp::ArithOp(ArithOp::Shl) | BinaryOp::ArithOp(ArithOp::Shr) => Ty::Unknown,
48 BinaryOp::CmpOp(CmpOp::Ord { .. }) 46 BinaryOp::CmpOp(CmpOp::Ord { .. })
49 | BinaryOp::Assignment { op: Some(_) } 47 | BinaryOp::Assignment { op: Some(_) }
diff --git a/crates/ra_hir_ty/src/test_db.rs b/crates/ra_hir_ty/src/test_db.rs
index 1a31b587b..c794f7b84 100644
--- a/crates/ra_hir_ty/src/test_db.rs
+++ b/crates/ra_hir_ty/src/test_db.rs
@@ -86,15 +86,14 @@ impl TestDB {
86 pub fn diagnostics(&self) -> String { 86 pub fn diagnostics(&self) -> String {
87 let mut buf = String::new(); 87 let mut buf = String::new();
88 let crate_graph = self.crate_graph(); 88 let crate_graph = self.crate_graph();
89 for krate in crate_graph.iter().next() { 89 for krate in crate_graph.iter() {
90 let crate_def_map = self.crate_def_map(krate); 90 let crate_def_map = self.crate_def_map(krate);
91 91
92 let mut fns = Vec::new(); 92 let mut fns = Vec::new();
93 for (module_id, _) in crate_def_map.modules.iter() { 93 for (module_id, _) in crate_def_map.modules.iter() {
94 for decl in crate_def_map[module_id].scope.declarations() { 94 for decl in crate_def_map[module_id].scope.declarations() {
95 match decl { 95 if let ModuleDefId::FunctionId(f) = decl {
96 ModuleDefId::FunctionId(f) => fns.push(f), 96 fns.push(f)
97 _ => (),
98 } 97 }
99 } 98 }
100 99
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs
index d1f10e675..240cc03a2 100644
--- a/crates/ra_hir_ty/src/tests.rs
+++ b/crates/ra_hir_ty/src/tests.rs
@@ -101,9 +101,9 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
101 (src_ptr.value.range(), node.text().to_string().replace("\n", " ")) 101 (src_ptr.value.range(), node.text().to_string().replace("\n", " "))
102 }; 102 };
103 let macro_prefix = if src_ptr.file_id != file_id.into() { "!" } else { "" }; 103 let macro_prefix = if src_ptr.file_id != file_id.into() { "!" } else { "" };
104 write!( 104 writeln!(
105 acc, 105 acc,
106 "{}{} '{}': {}\n", 106 "{}{} '{}': {}",
107 macro_prefix, 107 macro_prefix,
108 range, 108 range,
109 ellipsize(text, 15), 109 ellipsize(text, 15),
@@ -118,9 +118,9 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
118 for (src_ptr, mismatch) in &mismatches { 118 for (src_ptr, mismatch) in &mismatches {
119 let range = src_ptr.value.range(); 119 let range = src_ptr.value.range();
120 let macro_prefix = if src_ptr.file_id != file_id.into() { "!" } else { "" }; 120 let macro_prefix = if src_ptr.file_id != file_id.into() { "!" } else { "" };
121 write!( 121 writeln!(
122 acc, 122 acc,
123 "{}{}: expected {}, got {}\n", 123 "{}{}: expected {}, got {}",
124 macro_prefix, 124 macro_prefix,
125 range, 125 range,
126 mismatch.expected.display(&db), 126 mismatch.expected.display(&db),
diff --git a/crates/ra_hir_ty/src/traits.rs b/crates/ra_hir_ty/src/traits.rs
index ff8e75b48..e83449957 100644
--- a/crates/ra_hir_ty/src/traits.rs
+++ b/crates/ra_hir_ty/src/traits.rs
@@ -248,12 +248,9 @@ fn solution_from_chalk(
248 let value = subst 248 let value = subst
249 .value 249 .value
250 .into_iter() 250 .into_iter()
251 .map(|p| { 251 .map(|p| match p.ty() {
252 let ty = match p.ty() { 252 Some(ty) => from_chalk(db, ty.clone()),
253 Some(ty) => from_chalk(db, ty.clone()), 253 None => unimplemented!(),
254 None => unimplemented!(),
255 };
256 ty
257 }) 254 })
258 .collect(); 255 .collect();
259 let result = Canonical { value, num_vars: subst.binders.len() }; 256 let result = Canonical { value, num_vars: subst.binders.len() };
diff --git a/crates/ra_hir_ty/src/traits/builtin.rs b/crates/ra_hir_ty/src/traits/builtin.rs
index 67120abf6..a537420a5 100644
--- a/crates/ra_hir_ty/src/traits/builtin.rs
+++ b/crates/ra_hir_ty/src/traits/builtin.rs
@@ -122,7 +122,7 @@ fn closure_fn_trait_impl_datum(
122 substs: Substs::build_for_def(db, trait_).push(self_ty).push(arg_ty).build(), 122 substs: Substs::build_for_def(db, trait_).push(self_ty).push(arg_ty).build(),
123 }; 123 };
124 124
125 let output_ty_id = AssocTyValue::ClosureFnTraitImplOutput(data.clone()); 125 let output_ty_id = AssocTyValue::ClosureFnTraitImplOutput(data);
126 126
127 BuiltinImplData { 127 BuiltinImplData {
128 num_vars: num_args as usize + 1, 128 num_vars: num_args as usize + 1,
@@ -137,7 +137,7 @@ fn closure_fn_trait_output_assoc_ty_value(
137 krate: CrateId, 137 krate: CrateId,
138 data: super::ClosureFnTraitImplData, 138 data: super::ClosureFnTraitImplData,
139) -> BuiltinImplAssocTyValueData { 139) -> BuiltinImplAssocTyValueData {
140 let impl_ = Impl::ClosureFnTraitImpl(data.clone()); 140 let impl_ = Impl::ClosureFnTraitImpl(data);
141 141
142 let num_args: u16 = match &db.body(data.def)[data.expr] { 142 let num_args: u16 = match &db.body(data.def)[data.expr] {
143 Expr::Lambda { args, .. } => args.len() as u16, 143 Expr::Lambda { args, .. } => args.len() as u16,
diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs
index 306909ec2..1bdf13e48 100644
--- a/crates/ra_hir_ty/src/traits/chalk.rs
+++ b/crates/ra_hir_ty/src/traits/chalk.rs
@@ -409,8 +409,7 @@ where
409 fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Canonical<T::Chalk> { 409 fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Canonical<T::Chalk> {
410 let parameter = chalk_ir::ParameterKind::Ty(chalk_ir::UniverseIndex::ROOT); 410 let parameter = chalk_ir::ParameterKind::Ty(chalk_ir::UniverseIndex::ROOT);
411 let value = self.value.to_chalk(db); 411 let value = self.value.to_chalk(db);
412 let canonical = chalk_ir::Canonical { value, binders: vec![parameter; self.num_vars] }; 412 chalk_ir::Canonical { value, binders: vec![parameter; self.num_vars] }
413 canonical
414 } 413 }
415 414
416 fn from_chalk(db: &impl HirDatabase, canonical: chalk_ir::Canonical<T::Chalk>) -> Canonical<T> { 415 fn from_chalk(db: &impl HirDatabase, canonical: chalk_ir::Canonical<T::Chalk>) -> Canonical<T> {
diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs
index f2b29306e..7c6322cb4 100644
--- a/crates/ra_ide/src/call_info.rs
+++ b/crates/ra_ide/src/call_info.rs
@@ -128,7 +128,7 @@ impl FnCallNode {
128 }), 128 }),
129 129
130 FnCallNode::MethodCallExpr(call_expr) => { 130 FnCallNode::MethodCallExpr(call_expr) => {
131 call_expr.syntax().children().filter_map(ast::NameRef::cast).nth(0) 131 call_expr.syntax().children().filter_map(ast::NameRef::cast).next()
132 } 132 }
133 133
134 FnCallNode::MacroCallExpr(call_expr) => call_expr.path()?.segment()?.name_ref(), 134 FnCallNode::MacroCallExpr(call_expr) => call_expr.path()?.segment()?.name_ref(),
diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs
index 6ff10c017..83628e35c 100644
--- a/crates/ra_ide/src/completion/complete_trait_impl.rs
+++ b/crates/ra_ide/src/completion/complete_trait_impl.rs
@@ -59,7 +59,7 @@ pub(crate) fn complete_trait_impl(acc: &mut Completions, ctx: &CompletionContext
59 .as_ref() 59 .as_ref()
60 .and_then(|node| node.parent()) 60 .and_then(|node| node.parent())
61 .and_then(|node| node.parent()) 61 .and_then(|node| node.parent())
62 .and_then(|node| ast::ImplBlock::cast(node)); 62 .and_then(ast::ImplBlock::cast);
63 63
64 if let (Some(trigger), Some(impl_block)) = (trigger, impl_block) { 64 if let (Some(trigger), Some(impl_block)) = (trigger, impl_block) {
65 match trigger.kind() { 65 match trigger.kind() {
@@ -110,17 +110,17 @@ fn add_function_impl(
110 ctx: &CompletionContext, 110 ctx: &CompletionContext,
111 func: &hir::Function, 111 func: &hir::Function,
112) { 112) {
113 let display = FunctionSignature::from_hir(ctx.db, func.clone()); 113 let display = FunctionSignature::from_hir(ctx.db, *func);
114 114
115 let fn_name = func.name(ctx.db).to_string(); 115 let fn_name = func.name(ctx.db).to_string();
116 116
117 let label = if func.params(ctx.db).len() > 0 { 117 let label = if !func.params(ctx.db).is_empty() {
118 format!("fn {}(..)", fn_name) 118 format!("fn {}(..)", fn_name)
119 } else { 119 } else {
120 format!("fn {}()", fn_name) 120 format!("fn {}()", fn_name)
121 }; 121 };
122 122
123 let builder = CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label.clone()) 123 let builder = CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label)
124 .lookup_by(fn_name) 124 .lookup_by(fn_name)
125 .set_documentation(func.docs(ctx.db)); 125 .set_documentation(func.docs(ctx.db));
126 126
diff --git a/crates/ra_ide/src/completion/completion_item.rs b/crates/ra_ide/src/completion/completion_item.rs
index 93f336370..61867c0ff 100644
--- a/crates/ra_ide/src/completion/completion_item.rs
+++ b/crates/ra_ide/src/completion/completion_item.rs
@@ -159,7 +159,7 @@ impl CompletionItem {
159 159
160 /// Short one-line additional information, like a type 160 /// Short one-line additional information, like a type
161 pub fn detail(&self) -> Option<&str> { 161 pub fn detail(&self) -> Option<&str> {
162 self.detail.as_ref().map(|it| it.as_str()) 162 self.detail.as_deref()
163 } 163 }
164 /// A doc-comment 164 /// A doc-comment
165 pub fn documentation(&self) -> Option<Documentation> { 165 pub fn documentation(&self) -> Option<Documentation> {
@@ -167,7 +167,7 @@ impl CompletionItem {
167 } 167 }
168 /// What string is used for filtering. 168 /// What string is used for filtering.
169 pub fn lookup(&self) -> &str { 169 pub fn lookup(&self) -> &str {
170 self.lookup.as_ref().map(|it| it.as_str()).unwrap_or_else(|| self.label()) 170 self.lookup.as_deref().unwrap_or_else(|| self.label())
171 } 171 }
172 172
173 pub fn kind(&self) -> Option<CompletionItemKind> { 173 pub fn kind(&self) -> Option<CompletionItemKind> {
diff --git a/crates/ra_ide/src/display/function_signature.rs b/crates/ra_ide/src/display/function_signature.rs
index c23e08e9a..b85fd8075 100644
--- a/crates/ra_ide/src/display/function_signature.rs
+++ b/crates/ra_ide/src/display/function_signature.rs
@@ -54,9 +54,8 @@ impl FunctionSignature {
54 54
55 pub(crate) fn from_struct(db: &RootDatabase, st: hir::Struct) -> Option<Self> { 55 pub(crate) fn from_struct(db: &RootDatabase, st: hir::Struct) -> Option<Self> {
56 let node: ast::StructDef = st.source(db).value; 56 let node: ast::StructDef = st.source(db).value;
57 match node.kind() { 57 if let ast::StructKind::Record(_) = node.kind() {
58 ast::StructKind::Record(_) => return None, 58 return None;
59 _ => (),
60 }; 59 };
61 60
62 let params = st 61 let params = st
diff --git a/crates/ra_ide/src/display/navigation_target.rs b/crates/ra_ide/src/display/navigation_target.rs
index 906aab1eb..096c41c81 100644
--- a/crates/ra_ide/src/display/navigation_target.rs
+++ b/crates/ra_ide/src/display/navigation_target.rs
@@ -64,11 +64,11 @@ impl NavigationTarget {
64 } 64 }
65 65
66 pub fn docs(&self) -> Option<&str> { 66 pub fn docs(&self) -> Option<&str> {
67 self.docs.as_ref().map(String::as_str) 67 self.docs.as_deref()
68 } 68 }
69 69
70 pub fn description(&self) -> Option<&str> { 70 pub fn description(&self) -> Option<&str> {
71 self.description.as_ref().map(String::as_str) 71 self.description.as_deref()
72 } 72 }
73 73
74 /// A "most interesting" range withing the `full_range`. 74 /// A "most interesting" range withing the `full_range`.
diff --git a/crates/ra_ide/src/references.rs b/crates/ra_ide/src/references.rs
index de924fad2..97c08ade5 100644
--- a/crates/ra_ide/src/references.rs
+++ b/crates/ra_ide/src/references.rs
@@ -268,7 +268,7 @@ fn decl_access(
268 }; 268 };
269 269
270 let stmt = find_node_at_offset::<ast::LetStmt>(syntax, range.start())?; 270 let stmt = find_node_at_offset::<ast::LetStmt>(syntax, range.start())?;
271 if let Some(_) = stmt.initializer() { 271 if stmt.initializer().is_some() {
272 let pat = stmt.pat()?; 272 let pat = stmt.pat()?;
273 if let ast::Pat::BindPat(it) = pat { 273 if let ast::Pat::BindPat(it) = pat {
274 if it.name()?.text().as_str() == name { 274 if it.name()?.text().as_str() == name {
diff --git a/crates/ra_ide/src/ssr.rs b/crates/ra_ide/src/ssr.rs
index 14eb0b8b2..902c29fc6 100644
--- a/crates/ra_ide/src/ssr.rs
+++ b/crates/ra_ide/src/ssr.rs
@@ -85,8 +85,11 @@ impl FromStr for SsrQuery {
85 fn from_str(query: &str) -> Result<SsrQuery, SsrError> { 85 fn from_str(query: &str) -> Result<SsrQuery, SsrError> {
86 let mut it = query.split("==>>"); 86 let mut it = query.split("==>>");
87 let pattern = it.next().expect("at least empty string").trim(); 87 let pattern = it.next().expect("at least empty string").trim();
88 let mut template = 88 let mut template = it
89 it.next().ok_or(SsrError("Cannot find delemiter `==>>`".into()))?.trim().to_string(); 89 .next()
90 .ok_or_else(|| SsrError("Cannot find delemiter `==>>`".into()))?
91 .trim()
92 .to_string();
90 if it.next().is_some() { 93 if it.next().is_some() {
91 return Err(SsrError("More than one delimiter found".into())); 94 return Err(SsrError("More than one delimiter found".into()));
92 } 95 }
@@ -131,11 +134,12 @@ fn traverse(node: &SyntaxNode, go: &mut impl FnMut(&SyntaxNode) -> bool) {
131} 134}
132 135
133fn split_by_var(s: &str) -> Result<(&str, &str, &str), SsrError> { 136fn split_by_var(s: &str) -> Result<(&str, &str, &str), SsrError> {
134 let end_of_name = s.find(":").ok_or(SsrError("Use $<name>:expr".into()))?; 137 let end_of_name = s.find(':').ok_or_else(|| SsrError("Use $<name>:expr".into()))?;
135 let name = &s[0..end_of_name]; 138 let name = &s[0..end_of_name];
136 is_name(name)?; 139 is_name(name)?;
137 let type_begin = end_of_name + 1; 140 let type_begin = end_of_name + 1;
138 let type_length = s[type_begin..].find(|c| !char::is_ascii_alphanumeric(&c)).unwrap_or(s.len()); 141 let type_length =
142 s[type_begin..].find(|c| !char::is_ascii_alphanumeric(&c)).unwrap_or_else(|| s.len());
139 let type_name = &s[type_begin..type_begin + type_length]; 143 let type_name = &s[type_begin..type_begin + type_length];
140 Ok((name, type_name, &s[type_begin + type_length..])) 144 Ok((name, type_name, &s[type_begin + type_length..]))
141} 145}
@@ -182,7 +186,7 @@ fn find(pattern: &SsrPattern, code: &SyntaxNode) -> SsrMatches {
182 pattern.text() == code.text() 186 pattern.text() == code.text()
183 } 187 }
184 (SyntaxElement::Node(ref pattern), SyntaxElement::Node(ref code)) => { 188 (SyntaxElement::Node(ref pattern), SyntaxElement::Node(ref code)) => {
185 if placeholders.iter().find(|&n| n.0.as_str() == pattern.text()).is_some() { 189 if placeholders.iter().any(|n| n.0.as_str() == pattern.text()) {
186 match_.binding.insert(Var(pattern.text().to_string()), code.clone()); 190 match_.binding.insert(Var(pattern.text().to_string()), code.clone());
187 true 191 true
188 } else { 192 } else {
diff --git a/crates/ra_mbe/src/parser.rs b/crates/ra_mbe/src/parser.rs
index 1cdebc216..10a6f300a 100644
--- a/crates/ra_mbe/src/parser.rs
+++ b/crates/ra_mbe/src/parser.rs
@@ -45,15 +45,15 @@ impl PartialEq for Separator {
45 } 45 }
46} 46}
47 47
48pub(crate) fn parse_template<'a>( 48pub(crate) fn parse_template(
49 template: &'a tt::Subtree, 49 template: &tt::Subtree,
50) -> impl Iterator<Item = Result<Op<'a>, ExpandError>> { 50) -> impl Iterator<Item = Result<Op<'_>, ExpandError>> {
51 parse_inner(template, Mode::Template) 51 parse_inner(template, Mode::Template)
52} 52}
53 53
54pub(crate) fn parse_pattern<'a>( 54pub(crate) fn parse_pattern(
55 pattern: &'a tt::Subtree, 55 pattern: &tt::Subtree,
56) -> impl Iterator<Item = Result<Op<'a>, ExpandError>> { 56) -> impl Iterator<Item = Result<Op<'_>, ExpandError>> {
57 parse_inner(pattern, Mode::Pattern) 57 parse_inner(pattern, Mode::Pattern)
58} 58}
59 59
@@ -63,10 +63,7 @@ enum Mode {
63 Template, 63 Template,
64} 64}
65 65
66fn parse_inner<'a>( 66fn parse_inner(src: &tt::Subtree, mode: Mode) -> impl Iterator<Item = Result<Op<'_>, ExpandError>> {
67 src: &'a tt::Subtree,
68 mode: Mode,
69) -> impl Iterator<Item = Result<Op<'a>, ExpandError>> {
70 let mut src = TtIter::new(src); 67 let mut src = TtIter::new(src);
71 std::iter::from_fn(move || { 68 std::iter::from_fn(move || {
72 let first = src.next()?; 69 let first = src.next()?;
diff --git a/crates/ra_parser/src/grammar/items.rs b/crates/ra_parser/src/grammar/items.rs
index 54284c933..f8b43866c 100644
--- a/crates/ra_parser/src/grammar/items.rs
+++ b/crates/ra_parser/src/grammar/items.rs
@@ -21,7 +21,7 @@ use super::*;
21// struct S; 21// struct S;
22pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) { 22pub(super) fn mod_contents(p: &mut Parser, stop_on_r_curly: bool) {
23 attributes::inner_attributes(p); 23 attributes::inner_attributes(p);
24 while !p.at(EOF) && !(stop_on_r_curly && p.at(T!['}'])) { 24 while !(stop_on_r_curly && p.at(T!['}']) || p.at(EOF)) {
25 item_or_macro(p, stop_on_r_curly, ItemFlavor::Mod) 25 item_or_macro(p, stop_on_r_curly, ItemFlavor::Mod)
26 } 26 }
27} 27}
diff --git a/crates/ra_parser/src/parser.rs b/crates/ra_parser/src/parser.rs
index 1071c46dc..76e2d4f7d 100644
--- a/crates/ra_parser/src/parser.rs
+++ b/crates/ra_parser/src/parser.rs
@@ -126,13 +126,13 @@ impl<'t> Parser<'t> {
126 } 126 }
127 127
128 fn at_composite2(&self, n: usize, k1: SyntaxKind, k2: SyntaxKind) -> bool { 128 fn at_composite2(&self, n: usize, k1: SyntaxKind, k2: SyntaxKind) -> bool {
129 let t1 = self.token_source.lookahead_nth(n + 0); 129 let t1 = self.token_source.lookahead_nth(n);
130 let t2 = self.token_source.lookahead_nth(n + 1); 130 let t2 = self.token_source.lookahead_nth(n + 1);
131 t1.kind == k1 && t1.is_jointed_to_next && t2.kind == k2 131 t1.kind == k1 && t1.is_jointed_to_next && t2.kind == k2
132 } 132 }
133 133
134 fn at_composite3(&self, n: usize, k1: SyntaxKind, k2: SyntaxKind, k3: SyntaxKind) -> bool { 134 fn at_composite3(&self, n: usize, k1: SyntaxKind, k2: SyntaxKind, k3: SyntaxKind) -> bool {
135 let t1 = self.token_source.lookahead_nth(n + 0); 135 let t1 = self.token_source.lookahead_nth(n);
136 let t2 = self.token_source.lookahead_nth(n + 1); 136 let t2 = self.token_source.lookahead_nth(n + 1);
137 let t3 = self.token_source.lookahead_nth(n + 2); 137 let t3 = self.token_source.lookahead_nth(n + 2);
138 (t1.kind == k1 && t1.is_jointed_to_next) 138 (t1.kind == k1 && t1.is_jointed_to_next)
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs
index 34fd73bb7..4fea459d5 100644
--- a/crates/ra_project_model/src/cargo_workspace.rs
+++ b/crates/ra_project_model/src/cargo_workspace.rs
@@ -197,7 +197,7 @@ impl CargoWorkspace {
197 let pkg_data = &mut packages[pkg]; 197 let pkg_data = &mut packages[pkg];
198 pkg_by_id.insert(id, pkg); 198 pkg_by_id.insert(id, pkg);
199 for meta_tgt in meta_pkg.targets { 199 for meta_tgt in meta_pkg.targets {
200 let is_proc_macro = meta_tgt.kind.as_slice() == &["proc-macro"]; 200 let is_proc_macro = meta_tgt.kind.as_slice() == ["proc-macro"];
201 let tgt = targets.alloc(TargetData { 201 let tgt = targets.alloc(TargetData {
202 pkg, 202 pkg,
203 name: meta_tgt.name, 203 name: meta_tgt.name,
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs
index 9e67d2498..e35f7fbbc 100644
--- a/crates/ra_project_model/src/lib.rs
+++ b/crates/ra_project_model/src/lib.rs
@@ -197,8 +197,9 @@ impl ProjectWorkspace {
197 if let (Some(&from), Some(&to)) = 197 if let (Some(&from), Some(&to)) =
198 (crates.get(&from_crate_id), crates.get(&to_crate_id)) 198 (crates.get(&from_crate_id), crates.get(&to_crate_id))
199 { 199 {
200 if let Err(_) = 200 if crate_graph
201 crate_graph.add_dep(from, CrateName::new(&dep.name).unwrap(), to) 201 .add_dep(from, CrateName::new(&dep.name).unwrap(), to)
202 .is_err()
202 { 203 {
203 log::error!( 204 log::error!(
204 "cyclic dependency {:?} -> {:?}", 205 "cyclic dependency {:?} -> {:?}",
@@ -237,8 +238,7 @@ impl ProjectWorkspace {
237 if let (Some(&from), Some(&to)) = 238 if let (Some(&from), Some(&to)) =
238 (sysroot_crates.get(&from), sysroot_crates.get(&to)) 239 (sysroot_crates.get(&from), sysroot_crates.get(&to))
239 { 240 {
240 if let Err(_) = 241 if crate_graph.add_dep(from, CrateName::new(name).unwrap(), to).is_err()
241 crate_graph.add_dep(from, CrateName::new(name).unwrap(), to)
242 { 242 {
243 log::error!("cyclic dependency between sysroot crates") 243 log::error!("cyclic dependency between sysroot crates")
244 } 244 }
@@ -279,11 +279,14 @@ impl ProjectWorkspace {
279 } 279 }
280 if tgt.is_proc_macro(&cargo) { 280 if tgt.is_proc_macro(&cargo) {
281 if let Some(proc_macro) = libproc_macro { 281 if let Some(proc_macro) = libproc_macro {
282 if let Err(_) = crate_graph.add_dep( 282 if crate_graph
283 crate_id, 283 .add_dep(
284 CrateName::new("proc_macro").unwrap(), 284 crate_id,
285 proc_macro, 285 CrateName::new("proc_macro").unwrap(),
286 ) { 286 proc_macro,
287 )
288 .is_err()
289 {
287 log::error!( 290 log::error!(
288 "cyclic dependency on proc_macro for {}", 291 "cyclic dependency on proc_macro for {}",
289 pkg.name(&cargo) 292 pkg.name(&cargo)
@@ -299,15 +302,19 @@ impl ProjectWorkspace {
299 // Set deps to the core, std and to the lib target of the current package 302 // Set deps to the core, std and to the lib target of the current package
300 for &from in pkg_crates.get(&pkg).into_iter().flatten() { 303 for &from in pkg_crates.get(&pkg).into_iter().flatten() {
301 if let Some(to) = lib_tgt { 304 if let Some(to) = lib_tgt {
302 if to != from { 305 if to != from
303 if let Err(_) = crate_graph.add_dep( 306 && crate_graph
304 from, 307 .add_dep(
305 // For root projects with dashes in their name, 308 from,
306 // cargo metadata does not do any normalization, 309 // For root projects with dashes in their name,
307 // so we do it ourselves currently 310 // cargo metadata does not do any normalization,
308 CrateName::normalize_dashes(pkg.name(&cargo)), 311 // so we do it ourselves currently
309 to, 312 CrateName::normalize_dashes(pkg.name(&cargo)),
310 ) { 313 to,
314 )
315 .is_err()
316 {
317 {
311 log::error!( 318 log::error!(
312 "cyclic dependency between targets of {}", 319 "cyclic dependency between targets of {}",
313 pkg.name(&cargo) 320 pkg.name(&cargo)
@@ -318,22 +325,25 @@ impl ProjectWorkspace {
318 // core is added as a dependency before std in order to 325 // core is added as a dependency before std in order to
319 // mimic rustcs dependency order 326 // mimic rustcs dependency order
320 if let Some(core) = libcore { 327 if let Some(core) = libcore {
321 if let Err(_) = 328 if crate_graph
322 crate_graph.add_dep(from, CrateName::new("core").unwrap(), core) 329 .add_dep(from, CrateName::new("core").unwrap(), core)
330 .is_err()
323 { 331 {
324 log::error!("cyclic dependency on core for {}", pkg.name(&cargo)) 332 log::error!("cyclic dependency on core for {}", pkg.name(&cargo))
325 } 333 }
326 } 334 }
327 if let Some(alloc) = liballoc { 335 if let Some(alloc) = liballoc {
328 if let Err(_) = 336 if crate_graph
329 crate_graph.add_dep(from, CrateName::new("alloc").unwrap(), alloc) 337 .add_dep(from, CrateName::new("alloc").unwrap(), alloc)
338 .is_err()
330 { 339 {
331 log::error!("cyclic dependency on alloc for {}", pkg.name(&cargo)) 340 log::error!("cyclic dependency on alloc for {}", pkg.name(&cargo))
332 } 341 }
333 } 342 }
334 if let Some(std) = libstd { 343 if let Some(std) = libstd {
335 if let Err(_) = 344 if crate_graph
336 crate_graph.add_dep(from, CrateName::new("std").unwrap(), std) 345 .add_dep(from, CrateName::new("std").unwrap(), std)
346 .is_err()
337 { 347 {
338 log::error!("cyclic dependency on std for {}", pkg.name(&cargo)) 348 log::error!("cyclic dependency on std for {}", pkg.name(&cargo))
339 } 349 }
@@ -347,11 +357,10 @@ impl ProjectWorkspace {
347 for dep in pkg.dependencies(&cargo) { 357 for dep in pkg.dependencies(&cargo) {
348 if let Some(&to) = pkg_to_lib_crate.get(&dep.pkg) { 358 if let Some(&to) = pkg_to_lib_crate.get(&dep.pkg) {
349 for &from in pkg_crates.get(&pkg).into_iter().flatten() { 359 for &from in pkg_crates.get(&pkg).into_iter().flatten() {
350 if let Err(_) = crate_graph.add_dep( 360 if crate_graph
351 from, 361 .add_dep(from, CrateName::new(&dep.name).unwrap(), to)
352 CrateName::new(&dep.name).unwrap(), 362 .is_err()
353 to, 363 {
354 ) {
355 log::error!( 364 log::error!(
356 "cyclic dependency {} -> {}", 365 "cyclic dependency {} -> {}",
357 pkg.name(&cargo), 366 pkg.name(&cargo),
diff --git a/xtask/src/install.rs b/xtask/src/install.rs
index cc6fecc85..3df021acc 100644
--- a/xtask/src/install.rs
+++ b/xtask/src/install.rs
@@ -94,8 +94,7 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
94 }) 94 })
95 }; 95 };
96 96
97 let installed_extensions; 97 let installed_extensions = if cfg!(unix) {
98 if cfg!(unix) {
99 run!("npm --version").context("`npm` is required to build the VS Code plugin")?; 98 run!("npm --version").context("`npm` is required to build the VS Code plugin")?;
100 run!("npm install")?; 99 run!("npm install")?;
101 100
@@ -103,7 +102,7 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
103 102
104 let code = find_code(|bin| run!("{} --version", bin).is_ok())?; 103 let code = find_code(|bin| run!("{} --version", bin).is_ok())?;
105 run!("{} --install-extension rust-analyzer.vsix --force", code)?; 104 run!("{} --install-extension rust-analyzer.vsix --force", code)?;
106 installed_extensions = run!("{} --list-extensions", code; echo = false)?; 105 run!("{} --list-extensions", code; echo = false)?
107 } else { 106 } else {
108 run!("cmd.exe /c npm --version") 107 run!("cmd.exe /c npm --version")
109 .context("`npm` is required to build the VS Code plugin")?; 108 .context("`npm` is required to build the VS Code plugin")?;
@@ -113,8 +112,8 @@ fn install_client(ClientOpt::VsCode: ClientOpt) -> Result<()> {
113 112
114 let code = find_code(|bin| run!("cmd.exe /c {}.cmd --version", bin).is_ok())?; 113 let code = find_code(|bin| run!("cmd.exe /c {}.cmd --version", bin).is_ok())?;
115 run!(r"cmd.exe /c {}.cmd --install-extension rust-analyzer.vsix --force", code)?; 114 run!(r"cmd.exe /c {}.cmd --install-extension rust-analyzer.vsix --force", code)?;
116 installed_extensions = run!("cmd.exe /c {}.cmd --list-extensions", code; echo = false)?; 115 run!("cmd.exe /c {}.cmd --list-extensions", code; echo = false)?
117 } 116 };
118 117
119 if !installed_extensions.contains("rust-analyzer") { 118 if !installed_extensions.contains("rust-analyzer") {
120 bail!( 119 bail!(