diff options
-rw-r--r-- | crates/ra_hir/src/nameres.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir/src/ty.rs | 5 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/snapshots/tests__bug_651.snap | 13 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests.rs | 13 | ||||
-rw-r--r-- | crates/ra_ide_api_light/src/formatting.rs | 19 | ||||
-rw-r--r-- | crates/ra_ide_api_light/src/typing.rs | 40 |
6 files changed, 91 insertions, 4 deletions
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index 028c1882f..5193900e0 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs | |||
@@ -190,7 +190,12 @@ where | |||
190 | self.populate_module(module_id, Arc::clone(items)); | 190 | self.populate_module(module_id, Arc::clone(items)); |
191 | } | 191 | } |
192 | 192 | ||
193 | let mut iter = 0; | ||
193 | loop { | 194 | loop { |
195 | iter += 1; | ||
196 | if iter > 1000 { | ||
197 | panic!("failed to reach fixedpoint after 1000 iters") | ||
198 | } | ||
194 | let processed_imports_count = self.processed_imports.len(); | 199 | let processed_imports_count = self.processed_imports.len(); |
195 | for &module_id in self.input.keys() { | 200 | for &module_id in self.input.keys() { |
196 | self.db.check_canceled(); | 201 | self.db.check_canceled(); |
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs index 714eaaae5..179ebddee 100644 --- a/crates/ra_hir/src/ty.rs +++ b/crates/ra_hir/src/ty.rs | |||
@@ -790,7 +790,10 @@ fn binary_op_return_ty(op: BinaryOp, rhs_ty: Ty) -> Ty { | |||
790 | | BinaryOp::BitwiseAnd | 790 | | BinaryOp::BitwiseAnd |
791 | | BinaryOp::BitwiseOr | 791 | | BinaryOp::BitwiseOr |
792 | | BinaryOp::BitwiseXor => match rhs_ty { | 792 | | BinaryOp::BitwiseXor => match rhs_ty { |
793 | Ty::Int(..) | Ty::Float(..) => rhs_ty, | 793 | Ty::Int(..) |
794 | | Ty::Float(..) | ||
795 | | Ty::Infer(InferTy::IntVar(..)) | ||
796 | | Ty::Infer(InferTy::FloatVar(..)) => rhs_ty, | ||
794 | _ => Ty::Unknown, | 797 | _ => Ty::Unknown, |
795 | }, | 798 | }, |
796 | BinaryOp::RangeRightOpen | BinaryOp::RangeRightClosed => Ty::Unknown, | 799 | BinaryOp::RangeRightOpen | BinaryOp::RangeRightClosed => Ty::Unknown, |
diff --git a/crates/ra_hir/src/ty/snapshots/tests__bug_651.snap b/crates/ra_hir/src/ty/snapshots/tests__bug_651.snap new file mode 100644 index 000000000..d23d3f139 --- /dev/null +++ b/crates/ra_hir/src/ty/snapshots/tests__bug_651.snap | |||
@@ -0,0 +1,13 @@ | |||
1 | --- | ||
2 | created: "2019-01-25T20:31:47.275112244+00:00" | ||
3 | creator: [email protected] | ||
4 | expression: "&result" | ||
5 | source: crates/ra_hir/src/ty/tests.rs | ||
6 | --- | ||
7 | [11; 41) '{ ...+ y; }': () | ||
8 | [21; 22) 'y': i32 | ||
9 | [25; 27) '92': i32 | ||
10 | [33; 34) '1': i32 | ||
11 | [33; 38) '1 + y': i32 | ||
12 | [37; 38) 'y': i32 | ||
13 | |||
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index 92c74cf00..389bdaf23 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs | |||
@@ -532,6 +532,19 @@ fn test() { | |||
532 | ); | 532 | ); |
533 | } | 533 | } |
534 | 534 | ||
535 | #[test] | ||
536 | fn bug_651() { | ||
537 | check_inference( | ||
538 | "bug_651", | ||
539 | r#" | ||
540 | fn quux() { | ||
541 | let y = 92; | ||
542 | 1 + y; | ||
543 | } | ||
544 | "#, | ||
545 | ); | ||
546 | } | ||
547 | |||
535 | fn infer(content: &str) -> String { | 548 | fn infer(content: &str) -> String { |
536 | let (db, _, file_id) = MockDatabase::with_single_file(content); | 549 | let (db, _, file_id) = MockDatabase::with_single_file(content); |
537 | let source_file = db.source_file(file_id); | 550 | let source_file = db.source_file(file_id); |
diff --git a/crates/ra_ide_api_light/src/formatting.rs b/crates/ra_ide_api_light/src/formatting.rs index ca0fdb928..1f34b85d6 100644 --- a/crates/ra_ide_api_light/src/formatting.rs +++ b/crates/ra_ide_api_light/src/formatting.rs | |||
@@ -7,9 +7,22 @@ use ra_syntax::{ | |||
7 | 7 | ||
8 | /// If the node is on the beginning of the line, calculate indent. | 8 | /// If the node is on the beginning of the line, calculate indent. |
9 | pub(crate) fn leading_indent(node: &SyntaxNode) -> Option<&str> { | 9 | pub(crate) fn leading_indent(node: &SyntaxNode) -> Option<&str> { |
10 | let prev = prev_leaf(node)?; | 10 | for leaf in prev_leaves(node) { |
11 | let ws_text = ast::Whitespace::cast(prev)?.text(); | 11 | if let Some(ws) = ast::Whitespace::cast(leaf) { |
12 | ws_text.rfind('\n').map(|pos| &ws_text[pos + 1..]) | 12 | let ws_text = ws.text(); |
13 | if let Some(pos) = ws_text.rfind('\n') { | ||
14 | return Some(&ws_text[pos + 1..]); | ||
15 | } | ||
16 | } | ||
17 | if leaf.leaf_text().unwrap().contains('\n') { | ||
18 | break; | ||
19 | } | ||
20 | } | ||
21 | None | ||
22 | } | ||
23 | |||
24 | fn prev_leaves(node: &SyntaxNode) -> impl Iterator<Item = &SyntaxNode> { | ||
25 | generate(prev_leaf(node), |&node| prev_leaf(node)) | ||
13 | } | 26 | } |
14 | 27 | ||
15 | fn prev_leaf(node: &SyntaxNode) -> Option<&SyntaxNode> { | 28 | fn prev_leaf(node: &SyntaxNode) -> Option<&SyntaxNode> { |
diff --git a/crates/ra_ide_api_light/src/typing.rs b/crates/ra_ide_api_light/src/typing.rs index 5ff2b7c1f..861027b9f 100644 --- a/crates/ra_ide_api_light/src/typing.rs +++ b/crates/ra_ide_api_light/src/typing.rs | |||
@@ -296,6 +296,46 @@ fn foo() { | |||
296 | } | 296 | } |
297 | 297 | ||
298 | #[test] | 298 | #[test] |
299 | fn indents_middle_of_chain_call() { | ||
300 | type_dot( | ||
301 | r" | ||
302 | fn source_impl() { | ||
303 | let var = enum_defvariant_list().unwrap() | ||
304 | <|> | ||
305 | .nth(92) | ||
306 | .unwrap(); | ||
307 | } | ||
308 | ", | ||
309 | r" | ||
310 | fn source_impl() { | ||
311 | let var = enum_defvariant_list().unwrap() | ||
312 | . | ||
313 | .nth(92) | ||
314 | .unwrap(); | ||
315 | } | ||
316 | ", | ||
317 | ); | ||
318 | type_dot( | ||
319 | r" | ||
320 | fn source_impl() { | ||
321 | let var = enum_defvariant_list().unwrap() | ||
322 | <|> | ||
323 | .nth(92) | ||
324 | .unwrap(); | ||
325 | } | ||
326 | ", | ||
327 | r" | ||
328 | fn source_impl() { | ||
329 | let var = enum_defvariant_list().unwrap() | ||
330 | . | ||
331 | .nth(92) | ||
332 | .unwrap(); | ||
333 | } | ||
334 | ", | ||
335 | ); | ||
336 | } | ||
337 | |||
338 | #[test] | ||
299 | fn dont_indent_freestanding_dot() { | 339 | fn dont_indent_freestanding_dot() { |
300 | type_dot( | 340 | type_dot( |
301 | r" | 341 | r" |