diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_cargo_watch/src/conv.rs | 14 | ||||
-rw-r--r-- | crates/ra_cargo_watch/src/conv/snapshots/ra_cargo_watch__conv__test__snap_clippy_pass_by_ref.snap | 52 | ||||
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 24 | ||||
-rw-r--r-- | crates/ra_hir_def/src/body.rs | 9 | ||||
-rw-r--r-- | crates/ra_hir_def/src/body/lower.rs | 12 | ||||
-rw-r--r-- | crates/ra_hir_def/src/path.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/method_resolution.rs | 16 | ||||
-rw-r--r-- | crates/ra_ide_db/src/symbol_index.rs | 7 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/extensions.rs | 13 |
9 files changed, 69 insertions, 80 deletions
diff --git a/crates/ra_cargo_watch/src/conv.rs b/crates/ra_cargo_watch/src/conv.rs index c6f8ca329..817543deb 100644 --- a/crates/ra_cargo_watch/src/conv.rs +++ b/crates/ra_cargo_watch/src/conv.rs | |||
@@ -1,7 +1,8 @@ | |||
1 | //! This module provides the functionality needed to convert diagnostics from | 1 | //! This module provides the functionality needed to convert diagnostics from |
2 | //! `cargo check` json format to the LSP diagnostic format. | 2 | //! `cargo check` json format to the LSP diagnostic format. |
3 | use cargo_metadata::diagnostic::{ | 3 | use cargo_metadata::diagnostic::{ |
4 | Diagnostic as RustDiagnostic, DiagnosticLevel, DiagnosticSpan, DiagnosticSpanMacroExpansion, | 4 | Applicability, Diagnostic as RustDiagnostic, DiagnosticLevel, DiagnosticSpan, |
5 | DiagnosticSpanMacroExpansion, | ||
5 | }; | 6 | }; |
6 | use lsp_types::{ | 7 | use lsp_types::{ |
7 | CodeAction, Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, DiagnosticTag, | 8 | CodeAction, Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, DiagnosticTag, |
@@ -136,10 +137,13 @@ fn map_rust_child_diagnostic( | |||
136 | 137 | ||
137 | let mut edit_map: HashMap<Url, Vec<TextEdit>> = HashMap::new(); | 138 | let mut edit_map: HashMap<Url, Vec<TextEdit>> = HashMap::new(); |
138 | for &span in &spans { | 139 | for &span in &spans { |
139 | if let Some(suggested_replacement) = &span.suggested_replacement { | 140 | match (&span.suggestion_applicability, &span.suggested_replacement) { |
140 | let location = map_span_to_location(span, workspace_root); | 141 | (Some(Applicability::MachineApplicable), Some(suggested_replacement)) => { |
141 | let edit = TextEdit::new(location.range, suggested_replacement.clone()); | 142 | let location = map_span_to_location(span, workspace_root); |
142 | edit_map.entry(location.uri).or_default().push(edit); | 143 | let edit = TextEdit::new(location.range, suggested_replacement.clone()); |
144 | edit_map.entry(location.uri).or_default().push(edit); | ||
145 | } | ||
146 | _ => {} | ||
143 | } | 147 | } |
144 | } | 148 | } |
145 | 149 | ||
diff --git a/crates/ra_cargo_watch/src/conv/snapshots/ra_cargo_watch__conv__test__snap_clippy_pass_by_ref.snap b/crates/ra_cargo_watch/src/conv/snapshots/ra_cargo_watch__conv__test__snap_clippy_pass_by_ref.snap index 9e8f4eff4..a59fa84fa 100644 --- a/crates/ra_cargo_watch/src/conv/snapshots/ra_cargo_watch__conv__test__snap_clippy_pass_by_ref.snap +++ b/crates/ra_cargo_watch/src/conv/snapshots/ra_cargo_watch__conv__test__snap_clippy_pass_by_ref.snap | |||
@@ -58,44 +58,26 @@ expression: diag | |||
58 | }, | 58 | }, |
59 | message: "lint level defined here", | 59 | message: "lint level defined here", |
60 | }, | 60 | }, |
61 | DiagnosticRelatedInformation { | ||
62 | location: Location { | ||
63 | uri: "file:///test/compiler/mir/tagset.rs", | ||
64 | range: Range { | ||
65 | start: Position { | ||
66 | line: 41, | ||
67 | character: 23, | ||
68 | }, | ||
69 | end: Position { | ||
70 | line: 41, | ||
71 | character: 28, | ||
72 | }, | ||
73 | }, | ||
74 | }, | ||
75 | message: "consider passing by value instead", | ||
76 | }, | ||
61 | ], | 77 | ], |
62 | ), | 78 | ), |
63 | tags: None, | 79 | tags: None, |
64 | }, | 80 | }, |
65 | fixes: [ | 81 | fixes: [], |
66 | CodeAction { | ||
67 | title: "consider passing by value instead", | ||
68 | kind: Some( | ||
69 | "quickfix", | ||
70 | ), | ||
71 | diagnostics: None, | ||
72 | edit: Some( | ||
73 | WorkspaceEdit { | ||
74 | changes: Some( | ||
75 | { | ||
76 | "file:///test/compiler/mir/tagset.rs": [ | ||
77 | TextEdit { | ||
78 | range: Range { | ||
79 | start: Position { | ||
80 | line: 41, | ||
81 | character: 23, | ||
82 | }, | ||
83 | end: Position { | ||
84 | line: 41, | ||
85 | character: 28, | ||
86 | }, | ||
87 | }, | ||
88 | new_text: "self", | ||
89 | }, | ||
90 | ], | ||
91 | }, | ||
92 | ), | ||
93 | document_changes: None, | ||
94 | }, | ||
95 | ), | ||
96 | command: None, | ||
97 | is_preferred: None, | ||
98 | }, | ||
99 | ], | ||
100 | }, | 82 | }, |
101 | ] | 83 | ] |
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 45e31095c..4b150ef06 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -1042,30 +1042,18 @@ impl Type { | |||
1042 | } | 1042 | } |
1043 | 1043 | ||
1044 | pub fn is_bool(&self) -> bool { | 1044 | pub fn is_bool(&self) -> bool { |
1045 | match &self.ty.value { | 1045 | matches!(self.ty.value, Ty::Apply(ApplicationTy { ctor: TypeCtor::Bool, .. })) |
1046 | Ty::Apply(a_ty) => match a_ty.ctor { | ||
1047 | TypeCtor::Bool => true, | ||
1048 | _ => false, | ||
1049 | }, | ||
1050 | _ => false, | ||
1051 | } | ||
1052 | } | 1046 | } |
1053 | 1047 | ||
1054 | pub fn is_mutable_reference(&self) -> bool { | 1048 | pub fn is_mutable_reference(&self) -> bool { |
1055 | match &self.ty.value { | 1049 | matches!( |
1056 | Ty::Apply(a_ty) => match a_ty.ctor { | 1050 | self.ty.value, |
1057 | TypeCtor::Ref(Mutability::Mut) => true, | 1051 | Ty::Apply(ApplicationTy { ctor: TypeCtor::Ref(Mutability::Mut), .. }) |
1058 | _ => false, | 1052 | ) |
1059 | }, | ||
1060 | _ => false, | ||
1061 | } | ||
1062 | } | 1053 | } |
1063 | 1054 | ||
1064 | pub fn is_unknown(&self) -> bool { | 1055 | pub fn is_unknown(&self) -> bool { |
1065 | match &self.ty.value { | 1056 | matches!(self.ty.value, Ty::Unknown) |
1066 | Ty::Unknown => true, | ||
1067 | _ => false, | ||
1068 | } | ||
1069 | } | 1057 | } |
1070 | 1058 | ||
1071 | /// Checks that particular type `ty` implements `std::future::Future`. | 1059 | /// Checks that particular type `ty` implements `std::future::Future`. |
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs index 27a297e8b..5f9d53ecb 100644 --- a/crates/ra_hir_def/src/body.rs +++ b/crates/ra_hir_def/src/body.rs | |||
@@ -30,6 +30,7 @@ pub(crate) struct Expander { | |||
30 | hygiene: Hygiene, | 30 | hygiene: Hygiene, |
31 | ast_id_map: Arc<AstIdMap>, | 31 | ast_id_map: Arc<AstIdMap>, |
32 | module: ModuleId, | 32 | module: ModuleId, |
33 | recursive_limit: usize, | ||
33 | } | 34 | } |
34 | 35 | ||
35 | impl Expander { | 36 | impl Expander { |
@@ -41,7 +42,7 @@ impl Expander { | |||
41 | let crate_def_map = db.crate_def_map(module.krate); | 42 | let crate_def_map = db.crate_def_map(module.krate); |
42 | let hygiene = Hygiene::new(db.upcast(), current_file_id); | 43 | let hygiene = Hygiene::new(db.upcast(), current_file_id); |
43 | let ast_id_map = db.ast_id_map(current_file_id); | 44 | let ast_id_map = db.ast_id_map(current_file_id); |
44 | Expander { crate_def_map, current_file_id, hygiene, ast_id_map, module } | 45 | Expander { crate_def_map, current_file_id, hygiene, ast_id_map, module, recursive_limit: 0 } |
45 | } | 46 | } |
46 | 47 | ||
47 | pub(crate) fn enter_expand<T: ast::AstNode>( | 48 | pub(crate) fn enter_expand<T: ast::AstNode>( |
@@ -50,6 +51,10 @@ impl Expander { | |||
50 | local_scope: Option<&ItemScope>, | 51 | local_scope: Option<&ItemScope>, |
51 | macro_call: ast::MacroCall, | 52 | macro_call: ast::MacroCall, |
52 | ) -> Option<(Mark, T)> { | 53 | ) -> Option<(Mark, T)> { |
54 | if self.recursive_limit > 1024 { | ||
55 | return None; | ||
56 | } | ||
57 | |||
53 | let macro_call = InFile::new(self.current_file_id, ¯o_call); | 58 | let macro_call = InFile::new(self.current_file_id, ¯o_call); |
54 | 59 | ||
55 | if let Some(call_id) = macro_call.as_call_id(db, |path| { | 60 | if let Some(call_id) = macro_call.as_call_id(db, |path| { |
@@ -73,6 +78,7 @@ impl Expander { | |||
73 | self.hygiene = Hygiene::new(db.upcast(), file_id); | 78 | self.hygiene = Hygiene::new(db.upcast(), file_id); |
74 | self.current_file_id = file_id; | 79 | self.current_file_id = file_id; |
75 | self.ast_id_map = db.ast_id_map(file_id); | 80 | self.ast_id_map = db.ast_id_map(file_id); |
81 | self.recursive_limit += 1; | ||
76 | 82 | ||
77 | return Some((mark, expr)); | 83 | return Some((mark, expr)); |
78 | } | 84 | } |
@@ -88,6 +94,7 @@ impl Expander { | |||
88 | self.hygiene = Hygiene::new(db.upcast(), mark.file_id); | 94 | self.hygiene = Hygiene::new(db.upcast(), mark.file_id); |
89 | self.current_file_id = mark.file_id; | 95 | self.current_file_id = mark.file_id; |
90 | self.ast_id_map = mem::take(&mut mark.ast_id_map); | 96 | self.ast_id_map = mem::take(&mut mark.ast_id_map); |
97 | self.recursive_limit -= 1; | ||
91 | mark.bomb.defuse(); | 98 | mark.bomb.defuse(); |
92 | } | 99 | } |
93 | 100 | ||
diff --git a/crates/ra_hir_def/src/body/lower.rs b/crates/ra_hir_def/src/body/lower.rs index e8c58ed32..3cf0c66ea 100644 --- a/crates/ra_hir_def/src/body/lower.rs +++ b/crates/ra_hir_def/src/body/lower.rs | |||
@@ -453,7 +453,7 @@ impl ExprCollector<'_> { | |||
453 | } | 453 | } |
454 | } | 454 | } |
455 | ast::Expr::MacroCall(e) => { | 455 | ast::Expr::MacroCall(e) => { |
456 | if let Some(name) = is_macro_rules(&e) { | 456 | if let Some(name) = e.is_macro_rules().map(|it| it.as_name()) { |
457 | let mac = MacroDefId { | 457 | let mac = MacroDefId { |
458 | krate: Some(self.expander.module.krate), | 458 | krate: Some(self.expander.module.krate), |
459 | ast_id: Some(self.expander.ast_id(&e)), | 459 | ast_id: Some(self.expander.ast_id(&e)), |
@@ -697,16 +697,6 @@ impl ExprCollector<'_> { | |||
697 | } | 697 | } |
698 | } | 698 | } |
699 | 699 | ||
700 | fn is_macro_rules(m: &ast::MacroCall) -> Option<Name> { | ||
701 | let name = m.path()?.segment()?.name_ref()?.as_name(); | ||
702 | |||
703 | if name == name![macro_rules] { | ||
704 | Some(m.name()?.as_name()) | ||
705 | } else { | ||
706 | None | ||
707 | } | ||
708 | } | ||
709 | |||
710 | impl From<ast::BinOp> for BinaryOp { | 700 | impl From<ast::BinOp> for BinaryOp { |
711 | fn from(ast_op: ast::BinOp) -> Self { | 701 | fn from(ast_op: ast::BinOp) -> Self { |
712 | match ast_op { | 702 | match ast_op { |
diff --git a/crates/ra_hir_def/src/path.rs b/crates/ra_hir_def/src/path.rs index 246032c13..904080341 100644 --- a/crates/ra_hir_def/src/path.rs +++ b/crates/ra_hir_def/src/path.rs | |||
@@ -95,7 +95,7 @@ pub struct Path { | |||
95 | /// Note that paths like `<Type as Trait>::foo` are desugard to `Trait::<Self=Type>::foo`. | 95 | /// Note that paths like `<Type as Trait>::foo` are desugard to `Trait::<Self=Type>::foo`. |
96 | type_anchor: Option<Box<TypeRef>>, | 96 | type_anchor: Option<Box<TypeRef>>, |
97 | mod_path: ModPath, | 97 | mod_path: ModPath, |
98 | /// Invariant: the same len as self.path.segments | 98 | /// Invariant: the same len as `self.mod_path.segments` |
99 | generic_args: Vec<Option<Arc<GenericArgs>>>, | 99 | generic_args: Vec<Option<Arc<GenericArgs>>>, |
100 | } | 100 | } |
101 | 101 | ||
diff --git a/crates/ra_hir_ty/src/method_resolution.rs b/crates/ra_hir_ty/src/method_resolution.rs index 69c059ac8..533c6ccfb 100644 --- a/crates/ra_hir_ty/src/method_resolution.rs +++ b/crates/ra_hir_ty/src/method_resolution.rs | |||
@@ -95,14 +95,14 @@ impl Ty { | |||
95 | // Types like slice can have inherent impls in several crates, (core and alloc). | 95 | // Types like slice can have inherent impls in several crates, (core and alloc). |
96 | // The corresponding impls are marked with lang items, so we can use them to find the required crates. | 96 | // The corresponding impls are marked with lang items, so we can use them to find the required crates. |
97 | macro_rules! lang_item_crate { | 97 | macro_rules! lang_item_crate { |
98 | ($($name:expr),+ $(,)?) => {{ | 98 | ($($name:expr),+ $(,)?) => {{ |
99 | let mut v = ArrayVec::<[LangItemTarget; 2]>::new(); | 99 | let mut v = ArrayVec::<[LangItemTarget; 2]>::new(); |
100 | $( | 100 | $( |
101 | v.extend(db.lang_item(cur_crate, $name.into())); | 101 | v.extend(db.lang_item(cur_crate, $name.into())); |
102 | )+ | 102 | )+ |
103 | v | 103 | v |
104 | }}; | 104 | }}; |
105 | } | 105 | } |
106 | 106 | ||
107 | let lang_item_targets = match self { | 107 | let lang_item_targets = match self { |
108 | Ty::Apply(a_ty) => match a_ty.ctor { | 108 | Ty::Apply(a_ty) => match a_ty.ctor { |
diff --git a/crates/ra_ide_db/src/symbol_index.rs b/crates/ra_ide_db/src/symbol_index.rs index 884359ee3..0f46f93c1 100644 --- a/crates/ra_ide_db/src/symbol_index.rs +++ b/crates/ra_ide_db/src/symbol_index.rs | |||
@@ -362,6 +362,13 @@ fn to_symbol(node: &SyntaxNode) -> Option<(SmolStr, SyntaxNodePtr, TextRange)> { | |||
362 | ast::TypeAliasDef(it) => { decl(it) }, | 362 | ast::TypeAliasDef(it) => { decl(it) }, |
363 | ast::ConstDef(it) => { decl(it) }, | 363 | ast::ConstDef(it) => { decl(it) }, |
364 | ast::StaticDef(it) => { decl(it) }, | 364 | ast::StaticDef(it) => { decl(it) }, |
365 | ast::MacroCall(it) => { | ||
366 | if it.is_macro_rules().is_some() { | ||
367 | decl(it) | ||
368 | } else { | ||
369 | None | ||
370 | } | ||
371 | }, | ||
365 | _ => None, | 372 | _ => None, |
366 | } | 373 | } |
367 | } | 374 | } |
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index c3ae8f90e..392731dac 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs | |||
@@ -4,7 +4,7 @@ | |||
4 | use itertools::Itertools; | 4 | use itertools::Itertools; |
5 | 5 | ||
6 | use crate::{ | 6 | use crate::{ |
7 | ast::{self, child_opt, children, AstNode, AttrInput, SyntaxNode}, | 7 | ast::{self, child_opt, children, AstNode, AttrInput, NameOwner, SyntaxNode}, |
8 | SmolStr, SyntaxElement, | 8 | SmolStr, SyntaxElement, |
9 | SyntaxKind::*, | 9 | SyntaxKind::*, |
10 | SyntaxToken, T, | 10 | SyntaxToken, T, |
@@ -514,3 +514,14 @@ impl ast::Visibility { | |||
514 | self.syntax().children_with_tokens().any(|it| it.kind() == T![super]) | 514 | self.syntax().children_with_tokens().any(|it| it.kind() == T![super]) |
515 | } | 515 | } |
516 | } | 516 | } |
517 | |||
518 | impl ast::MacroCall { | ||
519 | pub fn is_macro_rules(&self) -> Option<ast::Name> { | ||
520 | let name_ref = self.path()?.segment()?.name_ref()?; | ||
521 | if name_ref.text() == "macro_rules" { | ||
522 | self.name() | ||
523 | } else { | ||
524 | None | ||
525 | } | ||
526 | } | ||
527 | } | ||