diff options
Diffstat (limited to 'crates')
48 files changed, 132 insertions, 149 deletions
diff --git a/crates/ra_assists/src/handlers/add_custom_impl.rs b/crates/ra_assists/src/handlers/add_custom_impl.rs index 7fdd816bf..4d3a72c18 100644 --- a/crates/ra_assists/src/handlers/add_custom_impl.rs +++ b/crates/ra_assists/src/handlers/add_custom_impl.rs | |||
@@ -45,7 +45,7 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> { | |||
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().filter(|t| t.kind() == IDENT && *t.text() != attr_name).next()?; |
47 | 47 | ||
48 | let annotated = attr.syntax().siblings(Direction::Next).find_map(|s| ast::Name::cast(s))?; | 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(); |
50 | let start_offset = annotated.syntax().parent()?.text_range().end(); | 50 | let start_offset = annotated.syntax().parent()?.text_range().end(); |
51 | 51 | ||
@@ -62,7 +62,7 @@ pub(crate) fn add_custom_impl(ctx: AssistCtx) -> Option<Assist> { | |||
62 | .filter_map(|t| t.into_token().map(|t| t.text().clone())) | 62 | .filter_map(|t| t.into_token().map(|t| t.text().clone())) |
63 | .filter(|t| t != trait_token.text()) | 63 | .filter(|t| t != trait_token.text()) |
64 | .collect::<Vec<SmolStr>>(); | 64 | .collect::<Vec<SmolStr>>(); |
65 | let has_more_derives = new_attr_input.len() > 0; | 65 | let has_more_derives = !new_attr_input.is_empty(); |
66 | let new_attr_input = | 66 | let new_attr_input = |
67 | join(new_attr_input.iter()).separator(", ").surround_with("(", ")").to_string(); | 67 | join(new_attr_input.iter()).separator(", ").surround_with("(", ")").to_string(); |
68 | let new_attr_input_len = new_attr_input.len(); | 68 | let new_attr_input_len = new_attr_input.len(); |
diff --git a/crates/ra_assists/src/handlers/add_new.rs b/crates/ra_assists/src/handlers/add_new.rs index 2701eddb8..dd070e8ec 100644 --- a/crates/ra_assists/src/handlers/add_new.rs +++ b/crates/ra_assists/src/handlers/add_new.rs | |||
@@ -53,7 +53,7 @@ pub(crate) fn add_new(ctx: AssistCtx) -> Option<Assist> { | |||
53 | } | 53 | } |
54 | 54 | ||
55 | let vis = strukt.visibility().map(|v| format!("{} ", v.syntax())); | 55 | let vis = strukt.visibility().map(|v| format!("{} ", v.syntax())); |
56 | let vis = vis.as_ref().map(String::as_str).unwrap_or(""); | 56 | let vis = vis.as_deref().unwrap_or(""); |
57 | write!(&mut buf, " {}fn new(", vis).unwrap(); | 57 | write!(&mut buf, " {}fn new(", vis).unwrap(); |
58 | 58 | ||
59 | join(field_list.fields().filter_map(|f| { | 59 | join(field_list.fields().filter_map(|f| { |
diff --git a/crates/ra_assists/src/handlers/replace_if_let_with_match.rs b/crates/ra_assists/src/handlers/replace_if_let_with_match.rs index e6cd50bc1..0a0a88f3d 100644 --- a/crates/ra_assists/src/handlers/replace_if_let_with_match.rs +++ b/crates/ra_assists/src/handlers/replace_if_let_with_match.rs | |||
@@ -61,7 +61,7 @@ pub(crate) fn replace_if_let_with_match(ctx: AssistCtx) -> Option<Assist> { | |||
61 | 61 | ||
62 | edit.target(if_expr.syntax().text_range()); | 62 | edit.target(if_expr.syntax().text_range()); |
63 | edit.set_cursor(if_expr.syntax().text_range().start()); | 63 | edit.set_cursor(if_expr.syntax().text_range().start()); |
64 | edit.replace_ast::<ast::Expr>(if_expr.into(), match_expr.into()); | 64 | edit.replace_ast::<ast::Expr>(if_expr.into(), match_expr); |
65 | }) | 65 | }) |
66 | } | 66 | } |
67 | 67 | ||
diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index cb124eaf0..a0e7fe17e 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs | |||
@@ -38,8 +38,8 @@ pub struct GroupLabel(pub String); | |||
38 | impl AssistLabel { | 38 | impl AssistLabel { |
39 | pub(crate) fn new(label: String, id: AssistId) -> AssistLabel { | 39 | pub(crate) fn new(label: String, id: AssistId) -> AssistLabel { |
40 | // FIXME: make fields private, so that this invariant can't be broken | 40 | // FIXME: make fields private, so that this invariant can't be broken |
41 | assert!(label.chars().nth(0).unwrap().is_uppercase()); | 41 | assert!(label.chars().next().unwrap().is_uppercase()); |
42 | AssistLabel { label: label.into(), id } | 42 | AssistLabel { label, id } |
43 | } | 43 | } |
44 | } | 44 | } |
45 | 45 | ||
diff --git a/crates/ra_cargo_watch/src/conv.rs b/crates/ra_cargo_watch/src/conv.rs index 506370535..0246adfb5 100644 --- a/crates/ra_cargo_watch/src/conv.rs +++ b/crates/ra_cargo_watch/src/conv.rs | |||
@@ -234,7 +234,7 @@ pub(crate) fn map_rust_diagnostic_to_lsp( | |||
234 | let child = map_rust_child_diagnostic(&child, workspace_root); | 234 | let child = map_rust_child_diagnostic(&child, workspace_root); |
235 | match child { | 235 | match child { |
236 | MappedRustChildDiagnostic::Related(related) => related_information.push(related), | 236 | MappedRustChildDiagnostic::Related(related) => related_information.push(related), |
237 | MappedRustChildDiagnostic::SuggestedFix(code_action) => fixes.push(code_action.into()), | 237 | MappedRustChildDiagnostic::SuggestedFix(code_action) => fixes.push(code_action), |
238 | MappedRustChildDiagnostic::MessageLine(message_line) => { | 238 | MappedRustChildDiagnostic::MessageLine(message_line) => { |
239 | write!(&mut message, "\n{}", message_line).unwrap(); | 239 | write!(&mut message, "\n{}", message_line).unwrap(); |
240 | 240 | ||
diff --git a/crates/ra_db/src/input.rs b/crates/ra_db/src/input.rs index 1b4b47215..78d121683 100644 --- a/crates/ra_db/src/input.rs +++ b/crates/ra_db/src/input.rs | |||
@@ -249,7 +249,7 @@ impl FromStr for Edition { | |||
249 | let res = match s { | 249 | let res = match s { |
250 | "2015" => Edition::Edition2015, | 250 | "2015" => Edition::Edition2015, |
251 | "2018" => Edition::Edition2018, | 251 | "2018" => Edition::Edition2018, |
252 | _ => Err(ParseEditionError { invalid_input: s.to_string() })?, | 252 | _ => return Err(ParseEditionError { invalid_input: s.to_string() }), |
253 | }; | 253 | }; |
254 | Ok(res) | 254 | Ok(res) |
255 | } | 255 | } |
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index b6adb7589..fe9149c9d 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -283,7 +283,7 @@ impl StructField { | |||
283 | }; | 283 | }; |
284 | let substs = Substs::type_params(db, generic_def_id); | 284 | let substs = Substs::type_params(db, generic_def_id); |
285 | let ty = db.field_types(var_id)[self.id].clone().subst(&substs); | 285 | let ty = db.field_types(var_id)[self.id].clone().subst(&substs); |
286 | Type::new(db, self.parent.module(db).id.krate.into(), var_id, ty) | 286 | Type::new(db, self.parent.module(db).id.krate, var_id, ty) |
287 | } | 287 | } |
288 | 288 | ||
289 | pub fn parent_def(&self, _db: &impl HirDatabase) -> VariantDef { | 289 | pub fn parent_def(&self, _db: &impl HirDatabase) -> VariantDef { |
@@ -315,11 +315,11 @@ impl Struct { | |||
315 | } | 315 | } |
316 | 316 | ||
317 | pub fn name(self, db: &impl DefDatabase) -> Name { | 317 | pub fn name(self, db: &impl DefDatabase) -> Name { |
318 | db.struct_data(self.id.into()).name.clone() | 318 | db.struct_data(self.id).name.clone() |
319 | } | 319 | } |
320 | 320 | ||
321 | pub fn fields(self, db: &impl HirDatabase) -> Vec<StructField> { | 321 | pub fn fields(self, db: &impl HirDatabase) -> Vec<StructField> { |
322 | db.struct_data(self.id.into()) | 322 | db.struct_data(self.id) |
323 | .variant_data | 323 | .variant_data |
324 | .fields() | 324 | .fields() |
325 | .iter() | 325 | .iter() |
@@ -332,7 +332,7 @@ impl Struct { | |||
332 | } | 332 | } |
333 | 333 | ||
334 | fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> { | 334 | fn variant_data(self, db: &impl DefDatabase) -> Arc<VariantData> { |
335 | db.struct_data(self.id.into()).variant_data.clone() | 335 | db.struct_data(self.id).variant_data.clone() |
336 | } | 336 | } |
337 | } | 337 | } |
338 | 338 | ||
@@ -1049,7 +1049,7 @@ impl Type { | |||
1049 | // FIXME check that? | 1049 | // FIXME check that? |
1050 | let canonical = Canonical { value: self.ty.value.clone(), num_vars: 0 }; | 1050 | let canonical = Canonical { value: self.ty.value.clone(), num_vars: 0 }; |
1051 | let environment = self.ty.environment.clone(); | 1051 | let environment = self.ty.environment.clone(); |
1052 | let ty = InEnvironment { value: canonical, environment: environment.clone() }; | 1052 | let ty = InEnvironment { value: canonical, environment }; |
1053 | autoderef(db, Some(self.krate), ty) | 1053 | autoderef(db, Some(self.krate), ty) |
1054 | .map(|canonical| canonical.value) | 1054 | .map(|canonical| canonical.value) |
1055 | .map(move |ty| self.derived(ty)) | 1055 | .map(move |ty| self.derived(ty)) |
diff --git a/crates/ra_hir/src/source_analyzer.rs b/crates/ra_hir/src/source_analyzer.rs index 94d5b4cfd..efa3f8a79 100644 --- a/crates/ra_hir/src/source_analyzer.rs +++ b/crates/ra_hir/src/source_analyzer.rs | |||
@@ -361,9 +361,8 @@ impl SourceAnalyzer { | |||
361 | db: &impl HirDatabase, | 361 | db: &impl HirDatabase, |
362 | macro_call: InFile<&ast::MacroCall>, | 362 | macro_call: InFile<&ast::MacroCall>, |
363 | ) -> Option<Expansion> { | 363 | ) -> Option<Expansion> { |
364 | let macro_call_id = macro_call.as_call_id(db, |path| { | 364 | let macro_call_id = |
365 | self.resolver.resolve_path_as_macro(db, &path).map(|it| it.into()) | 365 | macro_call.as_call_id(db, |path| self.resolver.resolve_path_as_macro(db, &path))?; |
366 | })?; | ||
367 | Some(Expansion { macro_call_id }) | 366 | Some(Expansion { macro_call_id }) |
368 | } | 367 | } |
369 | } | 368 | } |
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index 1fc892362..b1626fa11 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs | |||
@@ -448,7 +448,7 @@ where | |||
448 | // FIXME expand to statements in statement position | 448 | // FIXME expand to statements in statement position |
449 | ast::Expr::MacroCall(e) => { | 449 | ast::Expr::MacroCall(e) => { |
450 | let macro_call = self.expander.to_source(AstPtr::new(&e)); | 450 | let macro_call = self.expander.to_source(AstPtr::new(&e)); |
451 | match self.expander.enter_expand(self.db, e.clone()) { | 451 | match self.expander.enter_expand(self.db, e) { |
452 | Some((mark, expansion)) => { | 452 | Some((mark, expansion)) => { |
453 | self.source_map | 453 | self.source_map |
454 | .expansions | 454 | .expansions |
diff --git a/crates/ra_hir_def/src/generics.rs b/crates/ra_hir_def/src/generics.rs index f765e6edc..e07a4f947 100644 --- a/crates/ra_hir_def/src/generics.rs +++ b/crates/ra_hir_def/src/generics.rs | |||
@@ -71,7 +71,7 @@ impl GenericParams { | |||
71 | db: &impl DefDatabase, | 71 | db: &impl DefDatabase, |
72 | def: GenericDefId, | 72 | def: GenericDefId, |
73 | ) -> Arc<GenericParams> { | 73 | ) -> Arc<GenericParams> { |
74 | let (params, _source_map) = GenericParams::new(db, def.into()); | 74 | let (params, _source_map) = GenericParams::new(db, def); |
75 | Arc::new(params) | 75 | Arc::new(params) |
76 | } | 76 | } |
77 | 77 | ||
diff --git a/crates/ra_hir_def/src/item_scope.rs b/crates/ra_hir_def/src/item_scope.rs index d74a1cef2..f8dc06d10 100644 --- a/crates/ra_hir_def/src/item_scope.rs +++ b/crates/ra_hir_def/src/item_scope.rs | |||
@@ -138,7 +138,7 @@ impl ItemScope { | |||
138 | 138 | ||
139 | pub(crate) fn push_res(&mut self, name: Name, def: PerNs) -> bool { | 139 | pub(crate) fn push_res(&mut self, name: Name, def: PerNs) -> bool { |
140 | let mut changed = false; | 140 | let mut changed = false; |
141 | let existing = self.visible.entry(name.clone()).or_default(); | 141 | let existing = self.visible.entry(name).or_default(); |
142 | 142 | ||
143 | if existing.types.is_none() && def.types.is_some() { | 143 | if existing.types.is_none() && def.types.is_some() { |
144 | existing.types = def.types; | 144 | existing.types = def.types; |
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs index 852304dd0..c5137a0ab 100644 --- a/crates/ra_hir_def/src/nameres.rs +++ b/crates/ra_hir_def/src/nameres.rs | |||
@@ -156,7 +156,7 @@ impl ModuleOrigin { | |||
156 | ModuleOrigin::File { definition, .. } | ModuleOrigin::CrateRoot { definition } => { | 156 | ModuleOrigin::File { definition, .. } | ModuleOrigin::CrateRoot { definition } => { |
157 | let file_id = *definition; | 157 | let file_id = *definition; |
158 | let sf = db.parse(file_id).tree(); | 158 | let sf = db.parse(file_id).tree(); |
159 | return InFile::new(file_id.into(), ModuleSource::SourceFile(sf)); | 159 | InFile::new(file_id.into(), ModuleSource::SourceFile(sf)) |
160 | } | 160 | } |
161 | ModuleOrigin::Inline { definition } => { | 161 | ModuleOrigin::Inline { definition } => { |
162 | InFile::new(definition.file_id, ModuleSource::Module(definition.to_node(db))) | 162 | InFile::new(definition.file_id, ModuleSource::Module(definition.to_node(db))) |
diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index 650cf1f98..0e8c9da76 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs | |||
@@ -357,9 +357,7 @@ impl RawItemsCollector { | |||
357 | let visibility = | 357 | let visibility = |
358 | RawVisibility::from_ast_with_hygiene(extern_crate.visibility(), &self.hygiene); | 358 | RawVisibility::from_ast_with_hygiene(extern_crate.visibility(), &self.hygiene); |
359 | let alias = extern_crate.alias().map(|a| { | 359 | let alias = extern_crate.alias().map(|a| { |
360 | a.name() | 360 | a.name().map(|it| it.as_name()).map_or(ImportAlias::Underscore, ImportAlias::Alias) |
361 | .map(|it| it.as_name()) | ||
362 | .map_or(ImportAlias::Underscore, |a| ImportAlias::Alias(a)) | ||
363 | }); | 361 | }); |
364 | let attrs = self.parse_attrs(&extern_crate); | 362 | let attrs = self.parse_attrs(&extern_crate); |
365 | // FIXME: cfg_attr | 363 | // FIXME: cfg_attr |
diff --git a/crates/ra_hir_def/src/nameres/tests/incremental.rs b/crates/ra_hir_def/src/nameres/tests/incremental.rs index faeb7aa4d..83f429c29 100644 --- a/crates/ra_hir_def/src/nameres/tests/incremental.rs +++ b/crates/ra_hir_def/src/nameres/tests/incremental.rs | |||
@@ -116,7 +116,7 @@ fn typing_inside_a_macro_should_not_invalidate_def_map() { | |||
116 | let events = db.log_executed(|| { | 116 | let events = db.log_executed(|| { |
117 | let crate_def_map = db.crate_def_map(krate); | 117 | let crate_def_map = db.crate_def_map(krate); |
118 | let (_, module_data) = crate_def_map.modules.iter().last().unwrap(); | 118 | let (_, module_data) = crate_def_map.modules.iter().last().unwrap(); |
119 | assert_eq!(module_data.scope.resolutions().collect::<Vec<_>>().len(), 1); | 119 | assert_eq!(module_data.scope.resolutions().count(), 1); |
120 | }); | 120 | }); |
121 | assert!(format!("{:?}", events).contains("crate_def_map"), "{:#?}", events) | 121 | assert!(format!("{:?}", events).contains("crate_def_map"), "{:#?}", events) |
122 | } | 122 | } |
@@ -126,7 +126,7 @@ fn typing_inside_a_macro_should_not_invalidate_def_map() { | |||
126 | let events = db.log_executed(|| { | 126 | let events = db.log_executed(|| { |
127 | let crate_def_map = db.crate_def_map(krate); | 127 | let crate_def_map = db.crate_def_map(krate); |
128 | let (_, module_data) = crate_def_map.modules.iter().last().unwrap(); | 128 | let (_, module_data) = crate_def_map.modules.iter().last().unwrap(); |
129 | assert_eq!(module_data.scope.resolutions().collect::<Vec<_>>().len(), 1); | 129 | assert_eq!(module_data.scope.resolutions().count(), 1); |
130 | }); | 130 | }); |
131 | assert!(!format!("{:?}", events).contains("crate_def_map"), "{:#?}", events) | 131 | assert!(!format!("{:?}", events).contains("crate_def_map"), "{:#?}", events) |
132 | } | 132 | } |
diff --git a/crates/ra_hir_def/src/path/lower/lower_use.rs b/crates/ra_hir_def/src/path/lower/lower_use.rs index d2bc9d193..b6d1125e2 100644 --- a/crates/ra_hir_def/src/path/lower/lower_use.rs +++ b/crates/ra_hir_def/src/path/lower/lower_use.rs | |||
@@ -32,9 +32,7 @@ pub(crate) fn lower_use_tree( | |||
32 | } | 32 | } |
33 | } else { | 33 | } else { |
34 | let alias = tree.alias().map(|a| { | 34 | let alias = tree.alias().map(|a| { |
35 | a.name() | 35 | a.name().map(|it| it.as_name()).map_or(ImportAlias::Underscore, ImportAlias::Alias) |
36 | .map(|it| it.as_name()) | ||
37 | .map_or(ImportAlias::Underscore, |a| ImportAlias::Alias(a)) | ||
38 | }); | 36 | }); |
39 | let is_glob = tree.has_star(); | 37 | let is_glob = tree.has_star(); |
40 | if let Some(ast_path) = tree.path() { | 38 | if let Some(ast_path) = tree.path() { |
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs index e2b228e80..5365b80e2 100644 --- a/crates/ra_hir_def/src/resolver.rs +++ b/crates/ra_hir_def/src/resolver.rs | |||
@@ -474,7 +474,7 @@ impl Scope { | |||
474 | f(name.clone(), ScopeDef::PerNs(PerNs::macros(macro_, Visibility::Public))); | 474 | f(name.clone(), ScopeDef::PerNs(PerNs::macros(macro_, Visibility::Public))); |
475 | }); | 475 | }); |
476 | m.crate_def_map.extern_prelude.iter().for_each(|(name, &def)| { | 476 | m.crate_def_map.extern_prelude.iter().for_each(|(name, &def)| { |
477 | f(name.clone(), ScopeDef::PerNs(PerNs::types(def.into(), Visibility::Public))); | 477 | f(name.clone(), ScopeDef::PerNs(PerNs::types(def, Visibility::Public))); |
478 | }); | 478 | }); |
479 | if let Some(prelude) = m.crate_def_map.prelude { | 479 | if let Some(prelude) = m.crate_def_map.prelude { |
480 | let prelude_def_map = db.crate_def_map(prelude.krate); | 480 | let prelude_def_map = db.crate_def_map(prelude.krate); |
@@ -499,10 +499,10 @@ impl Scope { | |||
499 | } | 499 | } |
500 | } | 500 | } |
501 | Scope::ImplBlockScope(i) => { | 501 | Scope::ImplBlockScope(i) => { |
502 | f(name![Self], ScopeDef::ImplSelfType((*i).into())); | 502 | f(name![Self], ScopeDef::ImplSelfType(*i)); |
503 | } | 503 | } |
504 | Scope::AdtScope(i) => { | 504 | Scope::AdtScope(i) => { |
505 | f(name![Self], ScopeDef::AdtSelfType((*i).into())); | 505 | f(name![Self], ScopeDef::AdtSelfType(*i)); |
506 | } | 506 | } |
507 | Scope::ExprScope(scope) => { | 507 | Scope::ExprScope(scope) => { |
508 | scope.expr_scopes.entries(scope.scope_id).iter().for_each(|e| { | 508 | scope.expr_scopes.entries(scope.scope_id).iter().for_each(|e| { |
diff --git a/crates/ra_hir_expand/src/builtin_derive.rs b/crates/ra_hir_expand/src/builtin_derive.rs index 62c60e336..d0e3eaf7e 100644 --- a/crates/ra_hir_expand/src/builtin_derive.rs +++ b/crates/ra_hir_expand/src/builtin_derive.rs | |||
@@ -235,7 +235,7 @@ mod tests { | |||
235 | let (db, file_id) = TestDB::with_single_file(&s); | 235 | let (db, file_id) = TestDB::with_single_file(&s); |
236 | let parsed = db.parse(file_id); | 236 | let parsed = db.parse(file_id); |
237 | let items: Vec<_> = | 237 | let items: Vec<_> = |
238 | parsed.syntax_node().descendants().filter_map(|it| ast::ModuleItem::cast(it)).collect(); | 238 | parsed.syntax_node().descendants().filter_map(ast::ModuleItem::cast).collect(); |
239 | 239 | ||
240 | let ast_id_map = db.ast_id_map(file_id.into()); | 240 | let ast_id_map = db.ast_id_map(file_id.into()); |
241 | 241 | ||
diff --git a/crates/ra_hir_expand/src/builtin_macro.rs b/crates/ra_hir_expand/src/builtin_macro.rs index f3f959ac6..4adaa9b07 100644 --- a/crates/ra_hir_expand/src/builtin_macro.rs +++ b/crates/ra_hir_expand/src/builtin_macro.rs | |||
@@ -158,7 +158,7 @@ fn compile_error_expand( | |||
158 | match &tt.token_trees[0] { | 158 | match &tt.token_trees[0] { |
159 | tt::TokenTree::Leaf(tt::Leaf::Literal(it)) => { | 159 | tt::TokenTree::Leaf(tt::Leaf::Literal(it)) => { |
160 | let s = it.text.as_str(); | 160 | let s = it.text.as_str(); |
161 | if s.contains(r#"""#) { | 161 | if s.contains('"') { |
162 | return Ok(quote! { loop { #it }}); | 162 | return Ok(quote! { loop { #it }}); |
163 | } | 163 | } |
164 | } | 164 | } |
@@ -222,7 +222,7 @@ mod tests { | |||
222 | let (db, file_id) = TestDB::with_single_file(&s); | 222 | let (db, file_id) = TestDB::with_single_file(&s); |
223 | let parsed = db.parse(file_id); | 223 | let parsed = db.parse(file_id); |
224 | let macro_calls: Vec<_> = | 224 | let macro_calls: Vec<_> = |
225 | parsed.syntax_node().descendants().filter_map(|it| ast::MacroCall::cast(it)).collect(); | 225 | parsed.syntax_node().descendants().filter_map(ast::MacroCall::cast).collect(); |
226 | 226 | ||
227 | let ast_id_map = db.ast_id_map(file_id.into()); | 227 | let ast_id_map = db.ast_id_map(file_id.into()); |
228 | 228 | ||
diff --git a/crates/ra_hir_expand/src/quote.rs b/crates/ra_hir_expand/src/quote.rs index 4de219ce4..b54e00b68 100644 --- a/crates/ra_hir_expand/src/quote.rs +++ b/crates/ra_hir_expand/src/quote.rs | |||
@@ -259,8 +259,7 @@ mod tests { | |||
259 | // } | 259 | // } |
260 | let struct_name = mk_ident("Foo"); | 260 | let struct_name = mk_ident("Foo"); |
261 | let fields = [mk_ident("name"), mk_ident("id")]; | 261 | let fields = [mk_ident("name"), mk_ident("id")]; |
262 | let fields = | 262 | let fields = fields.iter().map(|it| quote!(#it: self.#it.clone(), ).token_trees).flatten(); |
263 | fields.iter().map(|it| quote!(#it: self.#it.clone(), ).token_trees.clone()).flatten(); | ||
264 | 263 | ||
265 | let list = tt::Subtree { | 264 | let list = tt::Subtree { |
266 | delimiter: Some(tt::Delimiter { | 265 | delimiter: Some(tt::Delimiter { |
diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs index a9d958c8b..76069eb9c 100644 --- a/crates/ra_hir_ty/src/infer.rs +++ b/crates/ra_hir_ty/src/infer.rs | |||
@@ -225,14 +225,14 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
225 | coerce_unsized_map: Self::init_coerce_unsized_map(db, &resolver), | 225 | coerce_unsized_map: Self::init_coerce_unsized_map(db, &resolver), |
226 | db, | 226 | db, |
227 | owner, | 227 | owner, |
228 | body: db.body(owner.into()), | 228 | body: db.body(owner), |
229 | resolver, | 229 | resolver, |
230 | } | 230 | } |
231 | } | 231 | } |
232 | 232 | ||
233 | fn resolve_all(mut self) -> InferenceResult { | 233 | fn resolve_all(mut self) -> InferenceResult { |
234 | // FIXME resolve obligations as well (use Guidance if necessary) | 234 | // FIXME resolve obligations as well (use Guidance if necessary) |
235 | let mut result = mem::replace(&mut self.result, InferenceResult::default()); | 235 | let mut result = std::mem::take(&mut self.result); |
236 | for ty in result.type_of_expr.values_mut() { | 236 | for ty in result.type_of_expr.values_mut() { |
237 | let resolved = self.table.resolve_ty_completely(mem::replace(ty, Ty::Unknown)); | 237 | let resolved = self.table.resolve_ty_completely(mem::replace(ty, Ty::Unknown)); |
238 | *ty = resolved; | 238 | *ty = resolved; |
@@ -261,7 +261,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
261 | } | 261 | } |
262 | 262 | ||
263 | fn write_assoc_resolution(&mut self, id: ExprOrPatId, item: AssocItemId) { | 263 | fn write_assoc_resolution(&mut self, id: ExprOrPatId, item: AssocItemId) { |
264 | self.result.assoc_resolutions.insert(id, item.into()); | 264 | self.result.assoc_resolutions.insert(id, item); |
265 | } | 265 | } |
266 | 266 | ||
267 | fn write_pat_ty(&mut self, pat: PatId, ty: Ty) { | 267 | fn write_pat_ty(&mut self, pat: PatId, ty: Ty) { |
@@ -312,9 +312,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
312 | for obligation in obligations { | 312 | for obligation in obligations { |
313 | let in_env = InEnvironment::new(self.trait_env.clone(), obligation.clone()); | 313 | let in_env = InEnvironment::new(self.trait_env.clone(), obligation.clone()); |
314 | let canonicalized = self.canonicalizer().canonicalize_obligation(in_env); | 314 | let canonicalized = self.canonicalizer().canonicalize_obligation(in_env); |
315 | let solution = self | 315 | let solution = |
316 | .db | 316 | self.db.trait_solve(self.resolver.krate().unwrap(), canonicalized.value.clone()); |
317 | .trait_solve(self.resolver.krate().unwrap().into(), canonicalized.value.clone()); | ||
318 | 317 | ||
319 | match solution { | 318 | match solution { |
320 | Some(Solution::Unique(substs)) => { | 319 | Some(Solution::Unique(substs)) => { |
diff --git a/crates/ra_hir_ty/src/infer/coerce.rs b/crates/ra_hir_ty/src/infer/coerce.rs index f68a1439f..4a0eabdfc 100644 --- a/crates/ra_hir_ty/src/infer/coerce.rs +++ b/crates/ra_hir_ty/src/infer/coerce.rs | |||
@@ -44,10 +44,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
44 | resolver: &Resolver, | 44 | resolver: &Resolver, |
45 | ) -> FxHashMap<(TypeCtor, TypeCtor), usize> { | 45 | ) -> FxHashMap<(TypeCtor, TypeCtor), usize> { |
46 | let krate = resolver.krate().unwrap(); | 46 | let krate = resolver.krate().unwrap(); |
47 | let impls = match db.lang_item(krate.into(), "coerce_unsized".into()) { | 47 | let impls = match db.lang_item(krate, "coerce_unsized".into()) { |
48 | Some(LangItemTarget::TraitId(trait_)) => { | 48 | Some(LangItemTarget::TraitId(trait_)) => db.impls_for_trait(krate, trait_), |
49 | db.impls_for_trait(krate.into(), trait_.into()) | ||
50 | } | ||
51 | _ => return FxHashMap::default(), | 49 | _ => return FxHashMap::default(), |
52 | }; | 50 | }; |
53 | 51 | ||
diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index 39d8bc0ca..0af94ae32 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs | |||
@@ -127,10 +127,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
127 | TypeCtor::FnPtr { num_args: sig_tys.len() as u16 - 1 }, | 127 | TypeCtor::FnPtr { num_args: sig_tys.len() as u16 - 1 }, |
128 | Substs(sig_tys.into()), | 128 | Substs(sig_tys.into()), |
129 | ); | 129 | ); |
130 | let closure_ty = Ty::apply_one( | 130 | let closure_ty = |
131 | TypeCtor::Closure { def: self.owner.into(), expr: tgt_expr }, | 131 | Ty::apply_one(TypeCtor::Closure { def: self.owner, expr: tgt_expr }, sig_ty); |
132 | sig_ty, | ||
133 | ); | ||
134 | 132 | ||
135 | // Eagerly try to relate the closure type with the expected | 133 | // Eagerly try to relate the closure type with the expected |
136 | // type, otherwise we often won't have enough information to | 134 | // type, otherwise we often won't have enough information to |
@@ -165,7 +163,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
165 | Expr::Match { expr, arms } => { | 163 | Expr::Match { expr, arms } => { |
166 | let input_ty = self.infer_expr(*expr, &Expectation::none()); | 164 | let input_ty = self.infer_expr(*expr, &Expectation::none()); |
167 | 165 | ||
168 | let mut result_ty = if arms.len() == 0 { | 166 | let mut result_ty = if arms.is_empty() { |
169 | Ty::simple(TypeCtor::Never) | 167 | Ty::simple(TypeCtor::Never) |
170 | } else { | 168 | } else { |
171 | self.table.new_type_var() | 169 | self.table.new_type_var() |
@@ -188,7 +186,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
188 | } | 186 | } |
189 | Expr::Path(p) => { | 187 | Expr::Path(p) => { |
190 | // FIXME this could be more efficient... | 188 | // FIXME this could be more efficient... |
191 | let resolver = resolver_for_expr(self.db, self.owner.into(), tgt_expr); | 189 | let resolver = resolver_for_expr(self.db, self.owner, tgt_expr); |
192 | self.infer_path(&resolver, p, tgt_expr.into()).unwrap_or(Ty::Unknown) | 190 | self.infer_path(&resolver, p, tgt_expr.into()).unwrap_or(Ty::Unknown) |
193 | } | 191 | } |
194 | Expr::Continue => Ty::simple(TypeCtor::Never), | 192 | Expr::Continue => Ty::simple(TypeCtor::Never), |
@@ -217,8 +215,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
217 | self.unify(&ty, &expected.ty); | 215 | self.unify(&ty, &expected.ty); |
218 | 216 | ||
219 | let substs = ty.substs().unwrap_or_else(Substs::empty); | 217 | let substs = ty.substs().unwrap_or_else(Substs::empty); |
220 | let field_types = | 218 | let field_types = def_id.map(|it| self.db.field_types(it)).unwrap_or_default(); |
221 | def_id.map(|it| self.db.field_types(it.into())).unwrap_or_default(); | ||
222 | let variant_data = def_id.map(|it| variant_data(self.db, it)); | 219 | let variant_data = def_id.map(|it| variant_data(self.db, it)); |
223 | for (field_idx, field) in fields.iter().enumerate() { | 220 | for (field_idx, field) in fields.iter().enumerate() { |
224 | let field_def = | 221 | let field_def = |
@@ -264,7 +261,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
264 | .and_then(|idx| a_ty.parameters.0.get(idx).cloned()), | 261 | .and_then(|idx| a_ty.parameters.0.get(idx).cloned()), |
265 | TypeCtor::Adt(AdtId::StructId(s)) => { | 262 | TypeCtor::Adt(AdtId::StructId(s)) => { |
266 | self.db.struct_data(s).variant_data.field(name).map(|local_id| { | 263 | self.db.struct_data(s).variant_data.field(name).map(|local_id| { |
267 | let field = StructFieldId { parent: s.into(), local_id }.into(); | 264 | let field = StructFieldId { parent: s.into(), local_id }; |
268 | self.write_field_resolution(tgt_expr, field); | 265 | self.write_field_resolution(tgt_expr, field); |
269 | self.db.field_types(s.into())[field.local_id] | 266 | self.db.field_types(s.into())[field.local_id] |
270 | .clone() | 267 | .clone() |
@@ -700,10 +697,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
700 | // construct a TraitDef | 697 | // construct a TraitDef |
701 | let substs = | 698 | let substs = |
702 | a_ty.parameters.prefix(generics(self.db, trait_.into()).len()); | 699 | a_ty.parameters.prefix(generics(self.db, trait_.into()).len()); |
703 | self.obligations.push(Obligation::Trait(TraitRef { | 700 | self.obligations.push(Obligation::Trait(TraitRef { trait_, substs })); |
704 | trait_: trait_.into(), | ||
705 | substs, | ||
706 | })); | ||
707 | } | 701 | } |
708 | } | 702 | } |
709 | CallableDef::StructId(_) | CallableDef::EnumVariantId(_) => {} | 703 | CallableDef::StructId(_) | CallableDef::EnumVariantId(_) => {} |
diff --git a/crates/ra_hir_ty/src/infer/pat.rs b/crates/ra_hir_ty/src/infer/pat.rs index a5dfdf6c4..a495ecbfe 100644 --- a/crates/ra_hir_ty/src/infer/pat.rs +++ b/crates/ra_hir_ty/src/infer/pat.rs | |||
@@ -28,7 +28,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
28 | 28 | ||
29 | let substs = ty.substs().unwrap_or_else(Substs::empty); | 29 | let substs = ty.substs().unwrap_or_else(Substs::empty); |
30 | 30 | ||
31 | let field_tys = def.map(|it| self.db.field_types(it.into())).unwrap_or_default(); | 31 | let field_tys = def.map(|it| self.db.field_types(it)).unwrap_or_default(); |
32 | 32 | ||
33 | for (i, &subpat) in subpats.iter().enumerate() { | 33 | for (i, &subpat) in subpats.iter().enumerate() { |
34 | let expected_ty = var_data | 34 | let expected_ty = var_data |
@@ -60,7 +60,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
60 | 60 | ||
61 | let substs = ty.substs().unwrap_or_else(Substs::empty); | 61 | let substs = ty.substs().unwrap_or_else(Substs::empty); |
62 | 62 | ||
63 | let field_tys = def.map(|it| self.db.field_types(it.into())).unwrap_or_default(); | 63 | let field_tys = def.map(|it| self.db.field_types(it)).unwrap_or_default(); |
64 | for subpat in subpats { | 64 | for subpat in subpats { |
65 | let matching_field = var_data.as_ref().and_then(|it| it.field(&subpat.name)); | 65 | let matching_field = var_data.as_ref().and_then(|it| it.field(&subpat.name)); |
66 | let expected_ty = | 66 | let expected_ty = |
diff --git a/crates/ra_hir_ty/src/infer/path.rs b/crates/ra_hir_ty/src/infer/path.rs index 686ce7a21..471d60342 100644 --- a/crates/ra_hir_ty/src/infer/path.rs +++ b/crates/ra_hir_ty/src/infer/path.rs | |||
@@ -104,8 +104,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
104 | let segment = | 104 | let segment = |
105 | remaining_segments.last().expect("there should be at least one segment here"); | 105 | remaining_segments.last().expect("there should be at least one segment here"); |
106 | let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver); | 106 | let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver); |
107 | let trait_ref = | 107 | let trait_ref = TraitRef::from_resolved_path(&ctx, trait_, resolved_segment, None); |
108 | TraitRef::from_resolved_path(&ctx, trait_.into(), resolved_segment, None); | ||
109 | self.resolve_trait_assoc_item(trait_ref, segment, id) | 108 | self.resolve_trait_assoc_item(trait_ref, segment, id) |
110 | } | 109 | } |
111 | (def, _) => { | 110 | (def, _) => { |
@@ -144,30 +143,32 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
144 | id: ExprOrPatId, | 143 | id: ExprOrPatId, |
145 | ) -> Option<(ValueNs, Option<Substs>)> { | 144 | ) -> Option<(ValueNs, Option<Substs>)> { |
146 | let trait_ = trait_ref.trait_; | 145 | let trait_ = trait_ref.trait_; |
147 | let item = self | 146 | let item = |
148 | .db | 147 | self.db.trait_data(trait_).items.iter().map(|(_name, id)| (*id)).find_map(|item| { |
149 | .trait_data(trait_) | 148 | match item { |
150 | .items | 149 | AssocItemId::FunctionId(func) => { |
151 | .iter() | 150 | if segment.name == &self.db.function_data(func).name { |
152 | .map(|(_name, id)| (*id).into()) | 151 | Some(AssocItemId::FunctionId(func)) |
153 | .find_map(|item| match item { | 152 | } else { |
154 | AssocItemId::FunctionId(func) => { | 153 | None |
155 | if segment.name == &self.db.function_data(func).name { | 154 | } |
156 | Some(AssocItemId::FunctionId(func)) | ||
157 | } else { | ||
158 | None | ||
159 | } | 155 | } |
160 | } | ||
161 | 156 | ||
162 | AssocItemId::ConstId(konst) => { | 157 | AssocItemId::ConstId(konst) => { |
163 | if self.db.const_data(konst).name.as_ref().map_or(false, |n| n == segment.name) | 158 | if self |
164 | { | 159 | .db |
165 | Some(AssocItemId::ConstId(konst)) | 160 | .const_data(konst) |
166 | } else { | 161 | .name |
167 | None | 162 | .as_ref() |
163 | .map_or(false, |n| n == segment.name) | ||
164 | { | ||
165 | Some(AssocItemId::ConstId(konst)) | ||
166 | } else { | ||
167 | None | ||
168 | } | ||
168 | } | 169 | } |
170 | AssocItemId::TypeAliasId(_) => None, | ||
169 | } | 171 | } |
170 | AssocItemId::TypeAliasId(_) => None, | ||
171 | })?; | 172 | })?; |
172 | let def = match item { | 173 | let def = match item { |
173 | AssocItemId::FunctionId(f) => ValueNs::FunctionId(f), | 174 | AssocItemId::FunctionId(f) => ValueNs::FunctionId(f), |
@@ -233,7 +234,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { | |||
233 | AssocContainerId::ContainerId(_) => None, | 234 | AssocContainerId::ContainerId(_) => None, |
234 | }; | 235 | }; |
235 | 236 | ||
236 | self.write_assoc_resolution(id, item.into()); | 237 | self.write_assoc_resolution(id, item); |
237 | Some((def, substs)) | 238 | Some((def, substs)) |
238 | }, | 239 | }, |
239 | ) | 240 | ) |
diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs index 571579cc4..302bb8aa2 100644 --- a/crates/ra_hir_ty/src/lib.rs +++ b/crates/ra_hir_ty/src/lib.rs | |||
@@ -167,7 +167,7 @@ impl TypeCtor { | |||
167 | | TypeCtor::Closure { .. } // 1 param representing the signature of the closure | 167 | | TypeCtor::Closure { .. } // 1 param representing the signature of the closure |
168 | => 1, | 168 | => 1, |
169 | TypeCtor::Adt(adt) => { | 169 | TypeCtor::Adt(adt) => { |
170 | let generic_params = generics(db, AdtId::from(adt).into()); | 170 | let generic_params = generics(db, adt.into()); |
171 | generic_params.len() | 171 | generic_params.len() |
172 | } | 172 | } |
173 | TypeCtor::FnDef(callable) => { | 173 | TypeCtor::FnDef(callable) => { |
@@ -247,7 +247,7 @@ pub struct ProjectionTy { | |||
247 | 247 | ||
248 | impl ProjectionTy { | 248 | impl ProjectionTy { |
249 | pub fn trait_ref(&self, db: &impl HirDatabase) -> TraitRef { | 249 | pub fn trait_ref(&self, db: &impl HirDatabase) -> TraitRef { |
250 | TraitRef { trait_: self.trait_(db).into(), substs: self.parameters.clone() } | 250 | TraitRef { trait_: self.trait_(db), substs: self.parameters.clone() } |
251 | } | 251 | } |
252 | 252 | ||
253 | fn trait_(&self, db: &impl HirDatabase) -> TraitId { | 253 | fn trait_(&self, db: &impl HirDatabase) -> TraitId { |
diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs index c2a3703fa..52da34574 100644 --- a/crates/ra_hir_ty/src/lower.rs +++ b/crates/ra_hir_ty/src/lower.rs | |||
@@ -361,10 +361,8 @@ impl Ty { | |||
361 | for t in traits { | 361 | for t in traits { |
362 | if let Some(associated_ty) = ctx.db.trait_data(t).associated_type_by_name(&segment.name) | 362 | if let Some(associated_ty) = ctx.db.trait_data(t).associated_type_by_name(&segment.name) |
363 | { | 363 | { |
364 | let substs = Substs::build_for_def(ctx.db, t) | 364 | let substs = |
365 | .push(self_ty.clone()) | 365 | Substs::build_for_def(ctx.db, t).push(self_ty).fill_with_unknown().build(); |
366 | .fill_with_unknown() | ||
367 | .build(); | ||
368 | // FIXME handle type parameters on the segment | 366 | // FIXME handle type parameters on the segment |
369 | return Ty::Projection(ProjectionTy { associated_ty, parameters: substs }); | 367 | return Ty::Projection(ProjectionTy { associated_ty, parameters: substs }); |
370 | } | 368 | } |
@@ -428,7 +426,7 @@ pub(super) fn substs_from_path_segment( | |||
428 | _add_self_param: bool, | 426 | _add_self_param: bool, |
429 | ) -> Substs { | 427 | ) -> Substs { |
430 | let mut substs = Vec::new(); | 428 | let mut substs = Vec::new(); |
431 | let def_generics = def_generic.map(|def| generics(ctx.db, def.into())); | 429 | let def_generics = def_generic.map(|def| generics(ctx.db, def)); |
432 | 430 | ||
433 | let (parent_params, self_params, type_params, impl_trait_params) = | 431 | let (parent_params, self_params, type_params, impl_trait_params) = |
434 | def_generics.map_or((0, 0, 0, 0), |g| g.provenance_split()); | 432 | def_generics.map_or((0, 0, 0, 0), |g| g.provenance_split()); |
@@ -459,7 +457,7 @@ pub(super) fn substs_from_path_segment( | |||
459 | 457 | ||
460 | // handle defaults | 458 | // handle defaults |
461 | if let Some(def_generic) = def_generic { | 459 | if let Some(def_generic) = def_generic { |
462 | let default_substs = ctx.db.generic_defaults(def_generic.into()); | 460 | let default_substs = ctx.db.generic_defaults(def_generic); |
463 | assert_eq!(substs.len(), default_substs.len()); | 461 | assert_eq!(substs.len(), default_substs.len()); |
464 | 462 | ||
465 | for (i, default_ty) in default_substs.iter().enumerate() { | 463 | for (i, default_ty) in default_substs.iter().enumerate() { |
@@ -483,7 +481,7 @@ impl TraitRef { | |||
483 | _ => return None, | 481 | _ => return None, |
484 | }; | 482 | }; |
485 | let segment = path.segments().last().expect("path should have at least one segment"); | 483 | let segment = path.segments().last().expect("path should have at least one segment"); |
486 | Some(TraitRef::from_resolved_path(ctx, resolved.into(), segment, explicit_self_ty)) | 484 | Some(TraitRef::from_resolved_path(ctx, resolved, segment, explicit_self_ty)) |
487 | } | 485 | } |
488 | 486 | ||
489 | pub(crate) fn from_resolved_path( | 487 | pub(crate) fn from_resolved_path( |
@@ -728,7 +726,7 @@ pub(crate) fn generic_predicates_query( | |||
728 | pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDefId) -> Substs { | 726 | pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDefId) -> Substs { |
729 | let resolver = def.resolver(db); | 727 | let resolver = def.resolver(db); |
730 | let ctx = TyLoweringContext::new(db, &resolver); | 728 | let ctx = TyLoweringContext::new(db, &resolver); |
731 | let generic_params = generics(db, def.into()); | 729 | let generic_params = generics(db, def); |
732 | 730 | ||
733 | let defaults = generic_params | 731 | let defaults = generic_params |
734 | .iter() | 732 | .iter() |
@@ -792,7 +790,7 @@ fn type_for_builtin(def: BuiltinType) -> Ty { | |||
792 | } | 790 | } |
793 | 791 | ||
794 | fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> PolyFnSig { | 792 | fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> PolyFnSig { |
795 | let struct_data = db.struct_data(def.into()); | 793 | let struct_data = db.struct_data(def); |
796 | let fields = struct_data.variant_data.fields(); | 794 | let fields = struct_data.variant_data.fields(); |
797 | let resolver = def.resolver(db); | 795 | let resolver = def.resolver(db); |
798 | let ctx = | 796 | let ctx = |
@@ -805,7 +803,7 @@ fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> PolyFn | |||
805 | 803 | ||
806 | /// Build the type of a tuple struct constructor. | 804 | /// Build the type of a tuple struct constructor. |
807 | fn type_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> Binders<Ty> { | 805 | fn type_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> Binders<Ty> { |
808 | let struct_data = db.struct_data(def.into()); | 806 | let struct_data = db.struct_data(def); |
809 | if let StructKind::Unit = struct_data.variant_data.kind() { | 807 | if let StructKind::Unit = struct_data.variant_data.kind() { |
810 | return type_for_adt(db, def.into()); | 808 | return type_for_adt(db, def.into()); |
811 | } | 809 | } |
@@ -836,7 +834,7 @@ fn type_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariantId) | |||
836 | } | 834 | } |
837 | let generics = generics(db, def.parent.into()); | 835 | let generics = generics(db, def.parent.into()); |
838 | let substs = Substs::bound_vars(&generics); | 836 | let substs = Substs::bound_vars(&generics); |
839 | Binders::new(substs.len(), Ty::apply(TypeCtor::FnDef(EnumVariantId::from(def).into()), substs)) | 837 | Binders::new(substs.len(), Ty::apply(TypeCtor::FnDef(def.into()), substs)) |
840 | } | 838 | } |
841 | 839 | ||
842 | fn type_for_adt(db: &impl HirDatabase, adt: AdtId) -> Binders<Ty> { | 840 | fn type_for_adt(db: &impl HirDatabase, adt: AdtId) -> Binders<Ty> { |
@@ -964,6 +962,6 @@ pub(crate) fn impl_trait_query( | |||
964 | let target_trait = impl_data.target_trait.as_ref()?; | 962 | let target_trait = impl_data.target_trait.as_ref()?; |
965 | Some(Binders::new( | 963 | Some(Binders::new( |
966 | self_ty.num_binders, | 964 | self_ty.num_binders, |
967 | TraitRef::from_hir(&ctx, target_trait, Some(self_ty.value.clone()))?, | 965 | TraitRef::from_hir(&ctx, target_trait, Some(self_ty.value))?, |
968 | )) | 966 | )) |
969 | } | 967 | } |
diff --git a/crates/ra_hir_ty/src/method_resolution.rs b/crates/ra_hir_ty/src/method_resolution.rs index 4f8c52433..964acdb09 100644 --- a/crates/ra_hir_ty/src/method_resolution.rs +++ b/crates/ra_hir_ty/src/method_resolution.rs | |||
@@ -214,7 +214,7 @@ pub fn iterate_method_candidates<T>( | |||
214 | // the methods by autoderef order of *receiver types*, not *self | 214 | // the methods by autoderef order of *receiver types*, not *self |
215 | // types*. | 215 | // types*. |
216 | 216 | ||
217 | let deref_chain: Vec<_> = autoderef::autoderef(db, Some(krate), ty.clone()).collect(); | 217 | let deref_chain: Vec<_> = autoderef::autoderef(db, Some(krate), ty).collect(); |
218 | for i in 0..deref_chain.len() { | 218 | for i in 0..deref_chain.len() { |
219 | if let Some(result) = iterate_method_candidates_with_autoref( | 219 | if let Some(result) = iterate_method_candidates_with_autoref( |
220 | &deref_chain[i..], | 220 | &deref_chain[i..], |
@@ -290,7 +290,7 @@ fn iterate_method_candidates_with_autoref<T>( | |||
290 | &ref_muted, | 290 | &ref_muted, |
291 | deref_chain, | 291 | deref_chain, |
292 | db, | 292 | db, |
293 | env.clone(), | 293 | env, |
294 | krate, | 294 | krate, |
295 | &traits_in_scope, | 295 | &traits_in_scope, |
296 | name, | 296 | name, |
@@ -391,17 +391,17 @@ fn iterate_trait_method_candidates<T>( | |||
391 | // iteration | 391 | // iteration |
392 | let mut known_implemented = false; | 392 | let mut known_implemented = false; |
393 | for (_name, item) in data.items.iter() { | 393 | for (_name, item) in data.items.iter() { |
394 | if !is_valid_candidate(db, name, receiver_ty, (*item).into(), self_ty) { | 394 | if !is_valid_candidate(db, name, receiver_ty, *item, self_ty) { |
395 | continue; | 395 | continue; |
396 | } | 396 | } |
397 | if !known_implemented { | 397 | if !known_implemented { |
398 | let goal = generic_implements_goal(db, env.clone(), t, self_ty.clone()); | 398 | let goal = generic_implements_goal(db, env.clone(), t, self_ty.clone()); |
399 | if db.trait_solve(krate.into(), goal).is_none() { | 399 | if db.trait_solve(krate, goal).is_none() { |
400 | continue 'traits; | 400 | continue 'traits; |
401 | } | 401 | } |
402 | } | 402 | } |
403 | known_implemented = true; | 403 | known_implemented = true; |
404 | if let Some(result) = callback(&self_ty.value, (*item).into()) { | 404 | if let Some(result) = callback(&self_ty.value, *item) { |
405 | return Some(result); | 405 | return Some(result); |
406 | } | 406 | } |
407 | } | 407 | } |
@@ -521,7 +521,7 @@ pub fn implements_trait( | |||
521 | return true; | 521 | return true; |
522 | } | 522 | } |
523 | let goal = generic_implements_goal(db, env, trait_, ty.clone()); | 523 | let goal = generic_implements_goal(db, env, trait_, ty.clone()); |
524 | let solution = db.trait_solve(krate.into(), goal); | 524 | let solution = db.trait_solve(krate, goal); |
525 | 525 | ||
526 | solution.is_some() | 526 | solution.is_some() |
527 | } | 527 | } |
diff --git a/crates/ra_hir_ty/src/traits/builtin.rs b/crates/ra_hir_ty/src/traits/builtin.rs index dd41176f0..67120abf6 100644 --- a/crates/ra_hir_ty/src/traits/builtin.rs +++ b/crates/ra_hir_ty/src/traits/builtin.rs | |||
@@ -98,7 +98,7 @@ fn closure_fn_trait_impl_datum( | |||
98 | // the existence of the Fn trait has been checked before | 98 | // the existence of the Fn trait has been checked before |
99 | .expect("fn trait for closure impl missing"); | 99 | .expect("fn trait for closure impl missing"); |
100 | 100 | ||
101 | let num_args: u16 = match &db.body(data.def.into())[data.expr] { | 101 | let num_args: u16 = match &db.body(data.def)[data.expr] { |
102 | Expr::Lambda { args, .. } => args.len() as u16, | 102 | Expr::Lambda { args, .. } => args.len() as u16, |
103 | _ => { | 103 | _ => { |
104 | log::warn!("closure for closure type {:?} not found", data); | 104 | log::warn!("closure for closure type {:?} not found", data); |
@@ -118,7 +118,7 @@ fn closure_fn_trait_impl_datum( | |||
118 | let self_ty = Ty::apply_one(TypeCtor::Closure { def: data.def, expr: data.expr }, sig_ty); | 118 | let self_ty = Ty::apply_one(TypeCtor::Closure { def: data.def, expr: data.expr }, sig_ty); |
119 | 119 | ||
120 | let trait_ref = TraitRef { | 120 | let trait_ref = TraitRef { |
121 | trait_: trait_.into(), | 121 | trait_, |
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 | ||
@@ -139,7 +139,7 @@ fn closure_fn_trait_output_assoc_ty_value( | |||
139 | ) -> BuiltinImplAssocTyValueData { | 139 | ) -> BuiltinImplAssocTyValueData { |
140 | let impl_ = Impl::ClosureFnTraitImpl(data.clone()); | 140 | let impl_ = Impl::ClosureFnTraitImpl(data.clone()); |
141 | 141 | ||
142 | let num_args: u16 = match &db.body(data.def.into())[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, |
144 | _ => { | 144 | _ => { |
145 | log::warn!("closure for closure type {:?} not found", data); | 145 | log::warn!("closure for closure type {:?} not found", data); |
diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs index 882160fa8..306909ec2 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs | |||
@@ -565,10 +565,10 @@ where | |||
565 | // and will panic if the trait can't be resolved. | 565 | // and will panic if the trait can't be resolved. |
566 | let mut result: Vec<_> = self | 566 | let mut result: Vec<_> = self |
567 | .db | 567 | .db |
568 | .impls_for_trait(self.krate, trait_.into()) | 568 | .impls_for_trait(self.krate, trait_) |
569 | .iter() | 569 | .iter() |
570 | .copied() | 570 | .copied() |
571 | .map(|it| Impl::ImplBlock(it.into())) | 571 | .map(Impl::ImplBlock) |
572 | .map(|impl_| impl_.to_chalk(self.db)) | 572 | .map(|impl_| impl_.to_chalk(self.db)) |
573 | .collect(); | 573 | .collect(); |
574 | 574 | ||
@@ -586,7 +586,7 @@ where | |||
586 | false // FIXME | 586 | false // FIXME |
587 | } | 587 | } |
588 | fn associated_ty_value(&self, id: AssociatedTyValueId) -> Arc<AssociatedTyValue> { | 588 | fn associated_ty_value(&self, id: AssociatedTyValueId) -> Arc<AssociatedTyValue> { |
589 | self.db.associated_ty_value(self.krate.into(), id) | 589 | self.db.associated_ty_value(self.krate, id) |
590 | } | 590 | } |
591 | fn custom_clauses(&self) -> Vec<chalk_ir::ProgramClause<TypeFamily>> { | 591 | fn custom_clauses(&self) -> Vec<chalk_ir::ProgramClause<TypeFamily>> { |
592 | vec![] | 592 | vec![] |
@@ -674,7 +674,7 @@ pub(crate) fn struct_datum_query( | |||
674 | let where_clauses = type_ctor | 674 | let where_clauses = type_ctor |
675 | .as_generic_def() | 675 | .as_generic_def() |
676 | .map(|generic_def| { | 676 | .map(|generic_def| { |
677 | let generic_params = generics(db, generic_def.into()); | 677 | let generic_params = generics(db, generic_def); |
678 | let bound_vars = Substs::bound_vars(&generic_params); | 678 | let bound_vars = Substs::bound_vars(&generic_params); |
679 | convert_where_clauses(db, generic_def, &bound_vars) | 679 | convert_where_clauses(db, generic_def, &bound_vars) |
680 | }) | 680 | }) |
@@ -805,7 +805,7 @@ fn type_alias_associated_ty_value( | |||
805 | let ty = db.ty(type_alias.into()); | 805 | let ty = db.ty(type_alias.into()); |
806 | let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty: ty.value.to_chalk(db) }; | 806 | let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty: ty.value.to_chalk(db) }; |
807 | let value = chalk_rust_ir::AssociatedTyValue { | 807 | let value = chalk_rust_ir::AssociatedTyValue { |
808 | impl_id: Impl::ImplBlock(impl_id.into()).to_chalk(db), | 808 | impl_id: Impl::ImplBlock(impl_id).to_chalk(db), |
809 | associated_ty_id: assoc_ty.to_chalk(db), | 809 | associated_ty_id: assoc_ty.to_chalk(db), |
810 | value: make_binders(value_bound, ty.num_binders), | 810 | value: make_binders(value_bound, ty.num_binders), |
811 | }; | 811 | }; |
diff --git a/crates/ra_ide_db/src/change.rs b/crates/ra_ide_db/src/change.rs index 4668784d3..7e9310005 100644 --- a/crates/ra_ide_db/src/change.rs +++ b/crates/ra_ide_db/src/change.rs | |||
@@ -44,7 +44,7 @@ impl fmt::Debug for AnalysisChange { | |||
44 | if !self.libraries_added.is_empty() { | 44 | if !self.libraries_added.is_empty() { |
45 | d.field("libraries_added", &self.libraries_added.len()); | 45 | d.field("libraries_added", &self.libraries_added.len()); |
46 | } | 46 | } |
47 | if !self.crate_graph.is_none() { | 47 | if self.crate_graph.is_some() { |
48 | d.field("crate_graph", &self.crate_graph); | 48 | d.field("crate_graph", &self.crate_graph); |
49 | } | 49 | } |
50 | d.finish() | 50 | d.finish() |
diff --git a/crates/ra_mbe/src/mbe_expander/matcher.rs b/crates/ra_mbe/src/mbe_expander/matcher.rs index e36b5a412..2bdea11e1 100644 --- a/crates/ra_mbe/src/mbe_expander/matcher.rs +++ b/crates/ra_mbe/src/mbe_expander/matcher.rs | |||
@@ -101,7 +101,7 @@ fn match_subtree( | |||
101 | tt::Leaf::Literal(tt::Literal { text: lhs, .. }), | 101 | tt::Leaf::Literal(tt::Literal { text: lhs, .. }), |
102 | tt::Leaf::Literal(tt::Literal { text: rhs, .. }), | 102 | tt::Leaf::Literal(tt::Literal { text: rhs, .. }), |
103 | ) if lhs == rhs => (), | 103 | ) if lhs == rhs => (), |
104 | _ => Err(ExpandError::UnexpectedToken)?, | 104 | _ => return Err(ExpandError::UnexpectedToken), |
105 | } | 105 | } |
106 | } | 106 | } |
107 | Op::TokenTree(tt::TokenTree::Subtree(lhs)) => { | 107 | Op::TokenTree(tt::TokenTree::Subtree(lhs)) => { |
diff --git a/crates/ra_mbe/src/parser.rs b/crates/ra_mbe/src/parser.rs index 50b8011a9..1cdebc216 100644 --- a/crates/ra_mbe/src/parser.rs +++ b/crates/ra_mbe/src/parser.rs | |||
@@ -100,7 +100,7 @@ fn next_op<'a>( | |||
100 | Op::Repeat { subtree, separator, kind } | 100 | Op::Repeat { subtree, separator, kind } |
101 | } | 101 | } |
102 | tt::TokenTree::Leaf(leaf) => match leaf { | 102 | tt::TokenTree::Leaf(leaf) => match leaf { |
103 | tt::Leaf::Punct(..) => Err(ExpandError::UnexpectedToken)?, | 103 | tt::Leaf::Punct(..) => return Err(ExpandError::UnexpectedToken), |
104 | tt::Leaf::Ident(ident) => { | 104 | tt::Leaf::Ident(ident) => { |
105 | let name = &ident.text; | 105 | let name = &ident.text; |
106 | let kind = eat_fragment_kind(src, mode)?; | 106 | let kind = eat_fragment_kind(src, mode)?; |
@@ -147,15 +147,15 @@ fn parse_repeat(src: &mut TtIter) -> Result<(Option<Separator>, RepeatKind), Exp | |||
147 | for tt in src { | 147 | for tt in src { |
148 | let tt = match tt { | 148 | let tt = match tt { |
149 | tt::TokenTree::Leaf(leaf) => leaf, | 149 | tt::TokenTree::Leaf(leaf) => leaf, |
150 | tt::TokenTree::Subtree(_) => Err(ExpandError::InvalidRepeat)?, | 150 | tt::TokenTree::Subtree(_) => return Err(ExpandError::InvalidRepeat), |
151 | }; | 151 | }; |
152 | let has_sep = match &separator { | 152 | let has_sep = match &separator { |
153 | Separator::Puncts(puncts) => puncts.len() != 0, | 153 | Separator::Puncts(puncts) => !puncts.is_empty(), |
154 | _ => true, | 154 | _ => true, |
155 | }; | 155 | }; |
156 | match tt { | 156 | match tt { |
157 | tt::Leaf::Ident(_) | tt::Leaf::Literal(_) if has_sep => { | 157 | tt::Leaf::Ident(_) | tt::Leaf::Literal(_) if has_sep => { |
158 | Err(ExpandError::InvalidRepeat)? | 158 | return Err(ExpandError::InvalidRepeat) |
159 | } | 159 | } |
160 | tt::Leaf::Ident(ident) => separator = Separator::Ident(ident.clone()), | 160 | tt::Leaf::Ident(ident) => separator = Separator::Ident(ident.clone()), |
161 | tt::Leaf::Literal(lit) => separator = Separator::Literal(lit.clone()), | 161 | tt::Leaf::Literal(lit) => separator = Separator::Literal(lit.clone()), |
@@ -168,11 +168,11 @@ fn parse_repeat(src: &mut TtIter) -> Result<(Option<Separator>, RepeatKind), Exp | |||
168 | match &mut separator { | 168 | match &mut separator { |
169 | Separator::Puncts(puncts) => { | 169 | Separator::Puncts(puncts) => { |
170 | if puncts.len() == 3 { | 170 | if puncts.len() == 3 { |
171 | Err(ExpandError::InvalidRepeat)? | 171 | return Err(ExpandError::InvalidRepeat); |
172 | } | 172 | } |
173 | puncts.push(punct.clone()) | 173 | puncts.push(punct.clone()) |
174 | } | 174 | } |
175 | _ => Err(ExpandError::InvalidRepeat)?, | 175 | _ => return Err(ExpandError::InvalidRepeat), |
176 | } | 176 | } |
177 | continue; | 177 | continue; |
178 | } | 178 | } |
diff --git a/crates/ra_mbe/src/subtree_source.rs b/crates/ra_mbe/src/subtree_source.rs index c9f42b3dd..eb8b79e9a 100644 --- a/crates/ra_mbe/src/subtree_source.rs +++ b/crates/ra_mbe/src/subtree_source.rs | |||
@@ -124,7 +124,7 @@ fn convert_delim(d: Option<tt::DelimiterKind>, closing: bool) -> TtToken { | |||
124 | 124 | ||
125 | let idx = closing as usize; | 125 | let idx = closing as usize; |
126 | let kind = kinds[idx]; | 126 | let kind = kinds[idx]; |
127 | let text = if texts.len() > 0 { &texts[idx..texts.len() - (1 - idx)] } else { "" }; | 127 | let text = if !texts.is_empty() { &texts[idx..texts.len() - (1 - idx)] } else { "" }; |
128 | TtToken { kind, is_joint_to_next: false, text: SmolStr::new(text) } | 128 | TtToken { kind, is_joint_to_next: false, text: SmolStr::new(text) } |
129 | } | 129 | } |
130 | 130 | ||
diff --git a/crates/ra_parser/src/grammar/expressions/atom.rs b/crates/ra_parser/src/grammar/expressions/atom.rs index b72d2e9e6..b77b683b5 100644 --- a/crates/ra_parser/src/grammar/expressions/atom.rs +++ b/crates/ra_parser/src/grammar/expressions/atom.rs | |||
@@ -230,10 +230,8 @@ fn lambda_expr(p: &mut Parser) -> CompletedMarker { | |||
230 | p.eat(T![async]); | 230 | p.eat(T![async]); |
231 | p.eat(T![move]); | 231 | p.eat(T![move]); |
232 | params::param_list_closure(p); | 232 | params::param_list_closure(p); |
233 | if opt_fn_ret_type(p) { | 233 | if opt_fn_ret_type(p) && !p.at(T!['{']) { |
234 | if !p.at(T!['{']) { | 234 | p.error("expected `{`"); |
235 | p.error("expected `{`"); | ||
236 | } | ||
237 | } | 235 | } |
238 | 236 | ||
239 | if p.at_ts(EXPR_FIRST) { | 237 | if p.at_ts(EXPR_FIRST) { |
diff --git a/crates/ra_parser/src/grammar/paths.rs b/crates/ra_parser/src/grammar/paths.rs index f5bf3d7ce..332acc1a0 100644 --- a/crates/ra_parser/src/grammar/paths.rs +++ b/crates/ra_parser/src/grammar/paths.rs | |||
@@ -94,7 +94,7 @@ fn path_segment(p: &mut Parser, mode: Mode, first: bool) { | |||
94 | 94 | ||
95 | fn opt_path_type_args(p: &mut Parser, mode: Mode) { | 95 | fn opt_path_type_args(p: &mut Parser, mode: Mode) { |
96 | match mode { | 96 | match mode { |
97 | Mode::Use => return, | 97 | Mode::Use => {} |
98 | Mode::Type => { | 98 | Mode::Type => { |
99 | // test path_fn_trait_args | 99 | // test path_fn_trait_args |
100 | // type F = Box<Fn(i32) -> ()>; | 100 | // type F = Box<Fn(i32) -> ()>; |
diff --git a/crates/ra_prof/src/lib.rs b/crates/ra_prof/src/lib.rs index c267bc85f..660d85b42 100644 --- a/crates/ra_prof/src/lib.rs +++ b/crates/ra_prof/src/lib.rs | |||
@@ -214,7 +214,7 @@ impl Drop for Profiler { | |||
214 | let start = stack.starts.pop().unwrap(); | 214 | let start = stack.starts.pop().unwrap(); |
215 | let duration = start.elapsed(); | 215 | let duration = start.elapsed(); |
216 | let level = stack.starts.len(); | 216 | let level = stack.starts.len(); |
217 | stack.messages.push(Message { level, duration, label: label }); | 217 | stack.messages.push(Message { level, duration, label }); |
218 | if level == 0 { | 218 | if level == 0 { |
219 | let stdout = stderr(); | 219 | let stdout = stderr(); |
220 | let longer_than = stack.filter_data.longer_than; | 220 | let longer_than = stack.filter_data.longer_than; |
diff --git a/crates/ra_project_model/src/cargo_workspace.rs b/crates/ra_project_model/src/cargo_workspace.rs index 22d226a74..34fd73bb7 100644 --- a/crates/ra_project_model/src/cargo_workspace.rs +++ b/crates/ra_project_model/src/cargo_workspace.rs | |||
@@ -164,7 +164,7 @@ impl CargoWorkspace { | |||
164 | // FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures` | 164 | // FIXME: `NoDefaultFeatures` is mutual exclusive with `SomeFeatures` |
165 | // https://github.com/oli-obk/cargo_metadata/issues/79 | 165 | // https://github.com/oli-obk/cargo_metadata/issues/79 |
166 | meta.features(CargoOpt::NoDefaultFeatures); | 166 | meta.features(CargoOpt::NoDefaultFeatures); |
167 | } else if cargo_features.features.len() > 0 { | 167 | } else if !cargo_features.features.is_empty() { |
168 | meta.features(CargoOpt::SomeFeatures(cargo_features.features.clone())); | 168 | meta.features(CargoOpt::SomeFeatures(cargo_features.features.clone())); |
169 | } | 169 | } |
170 | if let Some(parent) = cargo_toml.parent() { | 170 | if let Some(parent) = cargo_toml.parent() { |
diff --git a/crates/ra_project_model/src/lib.rs b/crates/ra_project_model/src/lib.rs index 250255813..9e67d2498 100644 --- a/crates/ra_project_model/src/lib.rs +++ b/crates/ra_project_model/src/lib.rs | |||
@@ -409,7 +409,7 @@ fn find_cargo_toml(path: &Path) -> Result<PathBuf> { | |||
409 | } | 409 | } |
410 | curr = path.parent(); | 410 | curr = path.parent(); |
411 | } | 411 | } |
412 | Err(CargoTomlNotFoundError(path.to_path_buf()))? | 412 | Err(CargoTomlNotFoundError(path.to_path_buf()).into()) |
413 | } | 413 | } |
414 | 414 | ||
415 | pub fn get_rustc_cfg_options() -> CfgOptions { | 415 | pub fn get_rustc_cfg_options() -> CfgOptions { |
diff --git a/crates/ra_syntax/src/algo.rs b/crates/ra_syntax/src/algo.rs index acf677e7d..21fca99a6 100644 --- a/crates/ra_syntax/src/algo.rs +++ b/crates/ra_syntax/src/algo.rs | |||
@@ -95,16 +95,17 @@ pub fn diff(from: &SyntaxNode, to: &SyntaxNode) -> TreeDiff { | |||
95 | lhs: SyntaxElement, | 95 | lhs: SyntaxElement, |
96 | rhs: SyntaxElement, | 96 | rhs: SyntaxElement, |
97 | ) { | 97 | ) { |
98 | if lhs.kind() == rhs.kind() && lhs.text_range().len() == rhs.text_range().len() { | 98 | if lhs.kind() == rhs.kind() |
99 | if match (&lhs, &rhs) { | 99 | && lhs.text_range().len() == rhs.text_range().len() |
100 | && match (&lhs, &rhs) { | ||
100 | (NodeOrToken::Node(lhs), NodeOrToken::Node(rhs)) => { | 101 | (NodeOrToken::Node(lhs), NodeOrToken::Node(rhs)) => { |
101 | lhs.green() == rhs.green() || lhs.text() == rhs.text() | 102 | lhs.green() == rhs.green() || lhs.text() == rhs.text() |
102 | } | 103 | } |
103 | (NodeOrToken::Token(lhs), NodeOrToken::Token(rhs)) => lhs.text() == rhs.text(), | 104 | (NodeOrToken::Token(lhs), NodeOrToken::Token(rhs)) => lhs.text() == rhs.text(), |
104 | _ => false, | 105 | _ => false, |
105 | } { | ||
106 | return; | ||
107 | } | 106 | } |
107 | { | ||
108 | return; | ||
108 | } | 109 | } |
109 | if let (Some(lhs), Some(rhs)) = (lhs.as_node(), rhs.as_node()) { | 110 | if let (Some(lhs), Some(rhs)) = (lhs.as_node(), rhs.as_node()) { |
110 | if lhs.children_with_tokens().count() == rhs.children_with_tokens().count() { | 111 | if lhs.children_with_tokens().count() == rhs.children_with_tokens().count() { |
diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs index 2e50a095c..77cceb382 100644 --- a/crates/ra_syntax/src/ast/expr_extensions.rs +++ b/crates/ra_syntax/src/ast/expr_extensions.rs | |||
@@ -30,7 +30,7 @@ pub enum ElseBranch { | |||
30 | 30 | ||
31 | impl ast::IfExpr { | 31 | impl ast::IfExpr { |
32 | pub fn then_branch(&self) -> Option<ast::BlockExpr> { | 32 | pub fn then_branch(&self) -> Option<ast::BlockExpr> { |
33 | self.blocks().nth(0) | 33 | self.blocks().next() |
34 | } | 34 | } |
35 | pub fn else_branch(&self) -> Option<ElseBranch> { | 35 | pub fn else_branch(&self) -> Option<ElseBranch> { |
36 | let res = match self.blocks().nth(1) { | 36 | let res = match self.blocks().nth(1) { |
@@ -208,7 +208,7 @@ impl ast::BinExpr { | |||
208 | } | 208 | } |
209 | 209 | ||
210 | pub fn lhs(&self) -> Option<ast::Expr> { | 210 | pub fn lhs(&self) -> Option<ast::Expr> { |
211 | children(self).nth(0) | 211 | children(self).next() |
212 | } | 212 | } |
213 | 213 | ||
214 | pub fn rhs(&self) -> Option<ast::Expr> { | 214 | pub fn rhs(&self) -> Option<ast::Expr> { |
@@ -271,7 +271,7 @@ impl ast::RangeExpr { | |||
271 | 271 | ||
272 | impl ast::IndexExpr { | 272 | impl ast::IndexExpr { |
273 | pub fn base(&self) -> Option<ast::Expr> { | 273 | pub fn base(&self) -> Option<ast::Expr> { |
274 | children(self).nth(0) | 274 | children(self).next() |
275 | } | 275 | } |
276 | pub fn index(&self) -> Option<ast::Expr> { | 276 | pub fn index(&self) -> Option<ast::Expr> { |
277 | children(self).nth(1) | 277 | children(self).nth(1) |
@@ -287,7 +287,7 @@ impl ast::ArrayExpr { | |||
287 | pub fn kind(&self) -> ArrayExprKind { | 287 | pub fn kind(&self) -> ArrayExprKind { |
288 | if self.is_repeat() { | 288 | if self.is_repeat() { |
289 | ArrayExprKind::Repeat { | 289 | ArrayExprKind::Repeat { |
290 | initializer: children(self).nth(0), | 290 | initializer: children(self).next(), |
291 | repeat: children(self).nth(1), | 291 | repeat: children(self).nth(1), |
292 | } | 292 | } |
293 | } else { | 293 | } else { |
@@ -328,10 +328,10 @@ impl ast::Literal { | |||
328 | } | 328 | } |
329 | 329 | ||
330 | pub fn kind(&self) -> LiteralKind { | 330 | pub fn kind(&self) -> LiteralKind { |
331 | const INT_SUFFIXES: [&'static str; 12] = [ | 331 | const INT_SUFFIXES: [&str; 12] = [ |
332 | "u64", "u32", "u16", "u8", "usize", "isize", "i64", "i32", "i16", "i8", "u128", "i128", | 332 | "u64", "u32", "u16", "u8", "usize", "isize", "i64", "i32", "i16", "i8", "u128", "i128", |
333 | ]; | 333 | ]; |
334 | const FLOAT_SUFFIXES: [&'static str; 2] = ["f32", "f64"]; | 334 | const FLOAT_SUFFIXES: [&str; 2] = ["f32", "f64"]; |
335 | 335 | ||
336 | let token = self.token(); | 336 | let token = self.token(); |
337 | 337 | ||
diff --git a/crates/ra_syntax/src/ast/make.rs b/crates/ra_syntax/src/ast/make.rs index 89d1403e7..7c20fcc10 100644 --- a/crates/ra_syntax/src/ast/make.rs +++ b/crates/ra_syntax/src/ast/make.rs | |||
@@ -152,7 +152,7 @@ pub fn match_arm_list(arms: impl IntoIterator<Item = ast::MatchArm>) -> ast::Mat | |||
152 | format!(" {}{}\n", arm.syntax(), comma) | 152 | format!(" {}{}\n", arm.syntax(), comma) |
153 | }) | 153 | }) |
154 | .collect::<String>(); | 154 | .collect::<String>(); |
155 | return from_text(&format!("{}", arms_str)); | 155 | return from_text(&arms_str); |
156 | 156 | ||
157 | fn from_text(text: &str) -> ast::MatchArmList { | 157 | fn from_text(text: &str) -> ast::MatchArmList { |
158 | ast_from_text(&format!("fn f() {{ match () {{\n{}}} }}", text)) | 158 | ast_from_text(&format!("fn f() {{ match () {{\n{}}} }}", text)) |
diff --git a/crates/ra_syntax/src/parsing/text_token_source.rs b/crates/ra_syntax/src/parsing/text_token_source.rs index e793f93a4..e2433913c 100644 --- a/crates/ra_syntax/src/parsing/text_token_source.rs +++ b/crates/ra_syntax/src/parsing/text_token_source.rs | |||
@@ -48,7 +48,7 @@ impl<'t> TokenSource for TextTokenSource<'t> { | |||
48 | 48 | ||
49 | fn is_keyword(&self, kw: &str) -> bool { | 49 | fn is_keyword(&self, kw: &str) -> bool { |
50 | let pos = self.curr.1; | 50 | let pos = self.curr.1; |
51 | if !(pos < self.tokens.len()) { | 51 | if pos >= self.tokens.len() { |
52 | return false; | 52 | return false; |
53 | } | 53 | } |
54 | let range = TextRange::offset_len(self.start_offsets[pos], self.tokens[pos].len); | 54 | let range = TextRange::offset_len(self.start_offsets[pos], self.tokens[pos].len); |
diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs index 69e709a25..dd15b3458 100644 --- a/crates/rust-analyzer/src/bin/main.rs +++ b/crates/rust-analyzer/src/bin/main.rs | |||
@@ -4,7 +4,7 @@ | |||
4 | mod args; | 4 | mod args; |
5 | 5 | ||
6 | use lsp_server::Connection; | 6 | use lsp_server::Connection; |
7 | use ra_prof; | 7 | |
8 | use rust_analyzer::{cli, from_json, show_message, Result, ServerConfig}; | 8 | use rust_analyzer::{cli, from_json, show_message, Result, ServerConfig}; |
9 | 9 | ||
10 | use crate::args::HelpPrinted; | 10 | use crate::args::HelpPrinted; |
diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs index 99ab6e443..4d59db1ee 100644 --- a/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/crates/rust-analyzer/src/cli/analysis_stats.rs | |||
@@ -130,7 +130,7 @@ pub fn analysis_stats( | |||
130 | write!(msg, " ({:?} {})", path, syntax_range).unwrap(); | 130 | write!(msg, " ({:?} {})", path, syntax_range).unwrap(); |
131 | } | 131 | } |
132 | if verbosity.is_spammy() { | 132 | if verbosity.is_spammy() { |
133 | bar.println(format!("{}", msg)); | 133 | bar.println(msg.to_string()); |
134 | } | 134 | } |
135 | bar.set_message(&msg); | 135 | bar.set_message(&msg); |
136 | let f_id = FunctionId::from(f); | 136 | let f_id = FunctionId::from(f); |
diff --git a/crates/rust-analyzer/src/main_loop.rs b/crates/rust-analyzer/src/main_loop.rs index dc16a234d..71917a62e 100644 --- a/crates/rust-analyzer/src/main_loop.rs +++ b/crates/rust-analyzer/src/main_loop.rs | |||
@@ -206,17 +206,17 @@ pub fn main_loop( | |||
206 | let event = select! { | 206 | let event = select! { |
207 | recv(&connection.receiver) -> msg => match msg { | 207 | recv(&connection.receiver) -> msg => match msg { |
208 | Ok(msg) => Event::Msg(msg), | 208 | Ok(msg) => Event::Msg(msg), |
209 | Err(RecvError) => Err("client exited without shutdown")?, | 209 | Err(RecvError) => return Err("client exited without shutdown".into()), |
210 | }, | 210 | }, |
211 | recv(task_receiver) -> task => Event::Task(task.unwrap()), | 211 | recv(task_receiver) -> task => Event::Task(task.unwrap()), |
212 | recv(world_state.task_receiver) -> task => match task { | 212 | recv(world_state.task_receiver) -> task => match task { |
213 | Ok(task) => Event::Vfs(task), | 213 | Ok(task) => Event::Vfs(task), |
214 | Err(RecvError) => Err("vfs died")?, | 214 | Err(RecvError) => return Err("vfs died".into()), |
215 | }, | 215 | }, |
216 | recv(libdata_receiver) -> data => Event::Lib(data.unwrap()), | 216 | recv(libdata_receiver) -> data => Event::Lib(data.unwrap()), |
217 | recv(world_state.check_watcher.task_recv) -> task => match task { | 217 | recv(world_state.check_watcher.task_recv) -> task => match task { |
218 | Ok(task) => Event::CheckWatcher(task), | 218 | Ok(task) => Event::CheckWatcher(task), |
219 | Err(RecvError) => Err("check watcher died")?, | 219 | Err(RecvError) => return Err("check watcher died".into()), |
220 | } | 220 | } |
221 | }; | 221 | }; |
222 | if let Event::Msg(Message::Request(req)) = &event { | 222 | if let Event::Msg(Message::Request(req)) = &event { |
diff --git a/crates/rust-analyzer/tests/heavy_tests/main.rs b/crates/rust-analyzer/tests/heavy_tests/main.rs index 3af63d9cf..970185dec 100644 --- a/crates/rust-analyzer/tests/heavy_tests/main.rs +++ b/crates/rust-analyzer/tests/heavy_tests/main.rs | |||
@@ -17,7 +17,7 @@ use test_utils::skip_slow_tests; | |||
17 | 17 | ||
18 | use crate::support::{project, Project}; | 18 | use crate::support::{project, Project}; |
19 | 19 | ||
20 | const PROFILE: &'static str = ""; | 20 | const PROFILE: &str = ""; |
21 | // const PROFILE: &'static str = "*@3>100"; | 21 | // const PROFILE: &'static str = "*@3>100"; |
22 | 22 | ||
23 | #[test] | 23 | #[test] |
diff --git a/crates/rust-analyzer/tests/heavy_tests/support.rs b/crates/rust-analyzer/tests/heavy_tests/support.rs index 5b90b3218..e28ae61fe 100644 --- a/crates/rust-analyzer/tests/heavy_tests/support.rs +++ b/crates/rust-analyzer/tests/heavy_tests/support.rs | |||
@@ -52,7 +52,7 @@ impl<'a> Project<'a> { | |||
52 | let tmp_dir = self.tmp_dir.unwrap_or_else(|| TempDir::new().unwrap()); | 52 | let tmp_dir = self.tmp_dir.unwrap_or_else(|| TempDir::new().unwrap()); |
53 | static INIT: Once = Once::new(); | 53 | static INIT: Once = Once::new(); |
54 | INIT.call_once(|| { | 54 | INIT.call_once(|| { |
55 | let _ = env_logger::builder().is_test(true).try_init().unwrap(); | 55 | env_logger::builder().is_test(true).try_init().unwrap(); |
56 | ra_prof::set_filter(if crate::PROFILE.is_empty() { | 56 | ra_prof::set_filter(if crate::PROFILE.is_empty() { |
57 | ra_prof::Filter::disabled() | 57 | ra_prof::Filter::disabled() |
58 | } else { | 58 | } else { |
diff --git a/crates/test_utils/src/lib.rs b/crates/test_utils/src/lib.rs index 336c594a6..e6e8d7110 100644 --- a/crates/test_utils/src/lib.rs +++ b/crates/test_utils/src/lib.rs | |||
@@ -279,7 +279,7 @@ pub fn find_mismatch<'a>(expected: &'a Value, actual: &'a Value) -> Option<(&'a | |||
279 | return Some((expected, actual)); | 279 | return Some((expected, actual)); |
280 | } | 280 | } |
281 | 281 | ||
282 | l.values().zip(r.values()).filter_map(|(l, r)| find_mismatch(l, r)).nth(0) | 282 | l.values().zip(r.values()).filter_map(|(l, r)| find_mismatch(l, r)).next() |
283 | } | 283 | } |
284 | (&Null, &Null) => None, | 284 | (&Null, &Null) => None, |
285 | // magic string literal "{...}" acts as wildcard for any sub-JSON | 285 | // magic string literal "{...}" acts as wildcard for any sub-JSON |