From c8bcfe6a05d82e151d459bcd2bd8a7b2742f7a66 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 28 May 2019 18:07:39 +0300 Subject: [PATCH] fix syntax errors in tests --- crates/ra_db/src/lib.rs | 6 +- crates/ra_hir/src/code_model.rs | 2 +- crates/ra_hir/src/expr/scope.rs | 4 +- crates/ra_hir/src/expr/validation.rs | 2 +- crates/ra_hir/src/ids.rs | 2 +- crates/ra_hir/src/source_binder.rs | 2 +- crates/ra_hir/src/ty/tests.rs | 240 ++++++++++++++------------- 7 files changed, 137 insertions(+), 121 deletions(-) diff --git a/crates/ra_db/src/lib.rs b/crates/ra_db/src/lib.rs index 68b9a7143bc..7c49c585bca 100644 --- a/crates/ra_db/src/lib.rs +++ b/crates/ra_db/src/lib.rs @@ -4,7 +4,7 @@ use std::{panic, sync::Arc}; -use ra_syntax::{TextUnit, TextRange, SourceFile, TreeArc}; +use ra_syntax::{TextUnit, TextRange, SourceFile, Parse}; use relative_path::RelativePathBuf; use ra_prof::profile; @@ -74,7 +74,7 @@ pub trait SourceDatabase: CheckCanceled + std::fmt::Debug { fn file_text(&self, file_id: FileId) -> Arc; // Parses the file into the syntax tree. #[salsa::invoke(parse_query)] - fn parse(&self, file_id: FileId) -> TreeArc; + fn parse(&self, file_id: FileId) -> Parse; /// Path to a file, relative to the root of its source root. #[salsa::input] fn file_relative_path(&self, file_id: FileId) -> RelativePathBuf; @@ -98,7 +98,7 @@ fn source_root_crates(db: &impl SourceDatabase, id: SourceRootId) -> Arc TreeArc { +fn parse_query(db: &impl SourceDatabase, file_id: FileId) -> Parse { let _p = profile("parse_query"); let text = db.file_text(file_id); SourceFile::parse(&*text) diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index a9ffc878225..69496b6242d 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs @@ -116,7 +116,7 @@ pub(crate) fn new( ) -> ModuleSource { match (file_id, decl_id) { (Some(file_id), _) => { - let source_file = db.parse(file_id); + let source_file = db.parse(file_id).tree; ModuleSource::SourceFile(source_file) } (None, Some(item_id)) => { diff --git a/crates/ra_hir/src/expr/scope.rs b/crates/ra_hir/src/expr/scope.rs index 58f365128b9..83d226fc15e 100644 --- a/crates/ra_hir/src/expr/scope.rs +++ b/crates/ra_hir/src/expr/scope.rs @@ -190,7 +190,7 @@ fn do_check(code: &str, expected: &[&str]) { }; let (db, _source_root, file_id) = MockDatabase::with_single_file(&code); - let file = db.parse(file_id); + let file = db.parse(file_id).ok().unwrap(); let marker: &ast::PathExpr = find_node_at_offset(file.syntax(), off).unwrap(); let analyzer = SourceAnalyzer::new(&db, file_id, marker.syntax(), None); @@ -288,7 +288,7 @@ fn do_check_local_name(code: &str, expected_offset: u32) { let (off, code) = extract_offset(code); let (db, _source_root, file_id) = MockDatabase::with_single_file(&code); - let file = db.parse(file_id); + let file = db.parse(file_id).ok().unwrap(); let expected_name = find_node_at_offset::(file.syntax(), expected_offset.into()) .expect("failed to find a name at the target offset"); let name_ref: &ast::NameRef = find_node_at_offset(file.syntax(), off).unwrap(); diff --git a/crates/ra_hir/src/expr/validation.rs b/crates/ra_hir/src/expr/validation.rs index 3f758f28386..2816144a747 100644 --- a/crates/ra_hir/src/expr/validation.rs +++ b/crates/ra_hir/src/expr/validation.rs @@ -75,7 +75,7 @@ fn validate_struct_literal( } let source_map = self.func.body_source_map(db); let file_id = self.func.source(db).0; - let source_file = db.parse(file_id.original_file(db)); + let source_file = db.parse(file_id.original_file(db)).tree; if let Some(field_list_node) = source_map .expr_syntax(id) .map(|ptr| ptr.to_node(source_file.syntax())) diff --git a/crates/ra_hir/src/ids.rs b/crates/ra_hir/src/ids.rs index 5c3799e95b7..06b6888f424 100644 --- a/crates/ra_hir/src/ids.rs +++ b/crates/ra_hir/src/ids.rs @@ -64,7 +64,7 @@ pub(crate) fn parse_or_expand_query( db.check_canceled(); let _p = profile("parse_or_expand_query"); match file_id.0 { - HirFileIdRepr::File(file_id) => Some(db.parse(file_id).syntax().to_owned()), + HirFileIdRepr::File(file_id) => Some(db.parse(file_id).tree.syntax().to_owned()), HirFileIdRepr::Macro(macro_file) => { let macro_call_id = macro_file.macro_call_id; let tt = db diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index 179faebfb10..860e1006943 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs @@ -46,7 +46,7 @@ pub fn module_from_declaration( /// Locates the module by position in the source code. pub fn module_from_position(db: &impl HirDatabase, position: FilePosition) -> Option { - let file = db.parse(position.file_id); + let file = db.parse(position.file_id).tree; match find_node_at_offset::(file.syntax(), position.offset) { Some(m) if !m.has_semi() => module_from_inline(db, position.file_id.into(), m), _ => module_from_file_id(db, position.file_id.into()), diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs index cd24faba529..da9aeec6dca 100644 --- a/crates/ra_hir/src/ty/tests.rs +++ b/crates/ra_hir/src/ty/tests.rs @@ -59,7 +59,7 @@ fn test() { let b: usize = 1; let c = b; } -}"#), +"#), @r###" [11; 71) '{ ...= b; }': () [21; 22) 'a': isize @@ -85,7 +85,7 @@ fn test() { a(); b::c(); } -}"#), +"#), @r###" [15; 20) '{ 1 }': u32 [17; 18) '1': u32 @@ -1004,7 +1004,7 @@ fn infer_tuple_struct_generics() { assert_snapshot_matches!( infer(r#" struct A(T); -enum Option { Some(T), None }; +enum Option { Some(T), None } use Option::*; fn test() { @@ -1017,22 +1017,24 @@ fn test() { } "#), @r###" -[77; 185) '{ ...one; }': () -[83; 84) 'A': A(T) -> A -[83; 88) 'A(42)': A -[85; 87) '42': i32 -[94; 95) 'A': A(T) -> A -[94; 103) 'A(42u128)': A -[96; 102) '42u128': u128 -[109; 113) 'Some': Some<&str>(T) -> Option -[109; 118) 'Some("x")': Option<&str> -[114; 117) '"x"': &str -[124; 136) 'Option::Some': Some<&str>(T) -> Option -[124; 141) 'Option...e("x")': Option<&str> -[137; 140) '"x"': &str -[147; 151) 'None': Option<{unknown}> -[161; 162) 'x': Option -[178; 182) 'None': Option"### + ⋮ + ⋮[76; 184) '{ ...one; }': () + ⋮[82; 83) 'A': A(T) -> A + ⋮[82; 87) 'A(42)': A + ⋮[84; 86) '42': i32 + ⋮[93; 94) 'A': A(T) -> A + ⋮[93; 102) 'A(42u128)': A + ⋮[95; 101) '42u128': u128 + ⋮[108; 112) 'Some': Some<&str>(T) -> Option + ⋮[108; 117) 'Some("x")': Option<&str> + ⋮[113; 116) '"x"': &str + ⋮[123; 135) 'Option::Some': Some<&str>(T) -> Option + ⋮[123; 140) 'Option...e("x")': Option<&str> + ⋮[136; 139) '"x"': &str + ⋮[146; 150) 'None': Option<{unknown}> + ⋮[160; 161) 'x': Option + ⋮[177; 181) 'None': Option + "### ); } @@ -1268,7 +1270,7 @@ impl Struct { const FOO: u32 = 1; } -enum Enum; +enum Enum {} impl Enum { const BAR: u32 = 2; @@ -1291,16 +1293,18 @@ fn test() { } "#), @r###" -[52; 53) '1': u32 -[103; 104) '2': u32 -[211; 212) '5': u32 -[227; 305) '{ ...:ID; }': () -[237; 238) 'x': u32 -[241; 252) 'Struct::FOO': u32 -[262; 263) 'y': u32 -[266; 275) 'Enum::BAR': u32 -[285; 286) 'z': {unknown} -[289; 302) 'TraitTest::ID': {unknown}"### + ⋮ + ⋮[52; 53) '1': u32 + ⋮[105; 106) '2': u32 + ⋮[213; 214) '5': u32 + ⋮[229; 307) '{ ...:ID; }': () + ⋮[239; 240) 'x': u32 + ⋮[243; 254) 'Struct::FOO': u32 + ⋮[264; 265) 'y': u32 + ⋮[268; 277) 'Enum::BAR': u32 + ⋮[287; 288) 'z': {unknown} + ⋮[291; 304) 'TraitTest::ID': {unknown} + "### ); } @@ -1308,7 +1312,7 @@ fn test() { fn infer_associated_method_struct() { assert_snapshot_matches!( infer(r#" -struct A { x: u32 }; +struct A { x: u32 } impl A { fn new() -> A { @@ -1321,15 +1325,17 @@ fn test() { } "#), @r###" -[50; 76) '{ ... }': A -[60; 70) 'A { x: 0 }': A -[67; 68) '0': u32 -[89; 123) '{ ...a.x; }': () -[99; 100) 'a': A -[103; 109) 'A::new': fn new() -> A -[103; 111) 'A::new()': A -[117; 118) 'a': A -[117; 120) 'a.x': u32"### + ⋮ + ⋮[49; 75) '{ ... }': A + ⋮[59; 69) 'A { x: 0 }': A + ⋮[66; 67) '0': u32 + ⋮[88; 122) '{ ...a.x; }': () + ⋮[98; 99) 'a': A + ⋮[102; 108) 'A::new': fn new() -> A + ⋮[102; 110) 'A::new()': A + ⋮[116; 117) 'a': A + ⋮[116; 119) 'a.x': u32 + "### ); } @@ -1337,7 +1343,7 @@ fn test() { fn infer_associated_method_enum() { assert_snapshot_matches!( infer(r#" -enum A { B, C }; +enum A { B, C } impl A { pub fn b() -> A { @@ -1355,19 +1361,21 @@ fn test() { } "#), @r###" -[48; 68) '{ ... }': A -[58; 62) 'A::B': A -[89; 109) '{ ... }': A -[99; 103) 'A::C': A -[122; 179) '{ ... c; }': () -[132; 133) 'a': A -[136; 140) 'A::b': fn b() -> A -[136; 142) 'A::b()': A -[148; 149) 'a': A -[159; 160) 'c': A -[163; 167) 'A::c': fn c() -> A -[163; 169) 'A::c()': A -[175; 176) 'c': A"### + ⋮ + ⋮[47; 67) '{ ... }': A + ⋮[57; 61) 'A::B': A + ⋮[88; 108) '{ ... }': A + ⋮[98; 102) 'A::C': A + ⋮[121; 178) '{ ... c; }': () + ⋮[131; 132) 'a': A + ⋮[135; 139) 'A::b': fn b() -> A + ⋮[135; 141) 'A::b()': A + ⋮[147; 148) 'a': A + ⋮[158; 159) 'c': A + ⋮[162; 166) 'A::c': fn c() -> A + ⋮[162; 168) 'A::c()': A + ⋮[174; 175) 'c': A + "### ); } @@ -1540,7 +1548,7 @@ fn test() { fn infer_type_alias() { assert_snapshot_matches!( infer(r#" -struct A { x: X, y: Y }; +struct A { x: X, y: Y } type Foo = A; type Bar = A; type Baz = A; @@ -1554,22 +1562,24 @@ fn test(x: Foo, y: Bar<&str>, z: Baz) { } "#), @r###" -[117; 118) 'x': A -[125; 126) 'y': A<&str, u128> -[139; 140) 'z': A -[155; 212) '{ ...z.y; }': () -[161; 162) 'x': A -[161; 164) 'x.x': u32 -[170; 171) 'x': A -[170; 173) 'x.y': i128 -[179; 180) 'y': A<&str, u128> -[179; 182) 'y.x': &str -[188; 189) 'y': A<&str, u128> -[188; 191) 'y.y': u128 -[197; 198) 'z': A -[197; 200) 'z.x': u8 -[206; 207) 'z': A -[206; 209) 'z.y': i8"### + ⋮ + ⋮[116; 117) 'x': A + ⋮[124; 125) 'y': A<&str, u128> + ⋮[138; 139) 'z': A + ⋮[154; 211) '{ ...z.y; }': () + ⋮[160; 161) 'x': A + ⋮[160; 163) 'x.x': u32 + ⋮[169; 170) 'x': A + ⋮[169; 172) 'x.y': i128 + ⋮[178; 179) 'y': A<&str, u128> + ⋮[178; 181) 'y.x': &str + ⋮[187; 188) 'y': A<&str, u128> + ⋮[187; 190) 'y.y': u128 + ⋮[196; 197) 'z': A + ⋮[196; 199) 'z.x': u8 + ⋮[205; 206) 'z': A + ⋮[205; 208) 'z.y': i8 + "### ) } @@ -1578,7 +1588,7 @@ fn test(x: Foo, y: Bar<&str>, z: Baz) { fn recursive_type_alias() { assert_snapshot_matches!( infer(r#" -struct A {}; +struct A {} type Foo = Foo; type Bar = A; fn test(x: Foo) {} @@ -1795,18 +1805,21 @@ fn infer_std_crash_3() { assert_snapshot_matches!( infer(r#" pub fn compute() { - match _ { + match nope!() { SizeSkeleton::Pointer { non_zero: true, tail } => {} } } "#), @r###" -[18; 102) '{ ... } }': () -[24; 100) 'match ... }': () -[42; 88) 'SizeSk...tail }': {unknown} -[76; 80) 'true': {unknown} -[82; 86) 'tail': {unknown} -[92; 94) '{}': ()"### + ⋮ + ⋮[18; 108) '{ ... } }': () + ⋮[24; 106) 'match ... }': () + ⋮[30; 37) 'nope!()': {unknown} + ⋮[48; 94) 'SizeSk...tail }': {unknown} + ⋮[82; 86) 'true': {unknown} + ⋮[88; 92) 'tail': {unknown} + ⋮[98; 100) '{}': () + "### ); } @@ -1817,20 +1830,21 @@ fn infer_std_crash_4() { infer(r#" pub fn primitive_type() { match *self { - BorrowedRef { type_: box Primitive(p), ..} => {}, + BorrowedRef { type_: Primitive(p), ..} => {}, } } "#), @r###" -[25; 110) '{ ... } }': () -[31; 108) 'match ... }': () -[37; 42) '*self': {unknown} -[38; 42) 'self': {unknown} -[53; 95) 'Borrow...), ..}': {unknown} -[74; 77) 'box': {unknown} -[78; 87) 'Primitive': {unknown} -[88; 89) 'p': {unknown} -[99; 101) '{}': ()"### + ⋮ + ⋮[25; 106) '{ ... } }': () + ⋮[31; 104) 'match ... }': () + ⋮[37; 42) '*self': {unknown} + ⋮[38; 42) 'self': {unknown} + ⋮[53; 91) 'Borrow...), ..}': {unknown} + ⋮[74; 86) 'Primitive(p)': {unknown} + ⋮[84; 85) 'p': {unknown} + ⋮[95; 97) '{}': () + "### ); } @@ -2304,8 +2318,8 @@ trait Into { fn into(self) -> T; } struct S; -impl Into for S; -impl Into for S; +impl Into for S {} +impl Into for S {} fn test() { let x: u32 = S.into(); let y: u64 = S.into(); @@ -2313,18 +2327,20 @@ fn test() { } "#), @r###" -[29; 33) 'self': Self -[107; 198) '{ ...(S); }': () -[117; 118) 'x': u32 -[126; 127) 'S': S -[126; 134) 'S.into()': u32 -[144; 145) 'y': u64 -[153; 154) 'S': S -[153; 161) 'S.into()': u64 -[171; 172) 'z': {unknown} -[175; 192) 'Into::...::into': {unknown} -[175; 195) 'Into::...nto(S)': {unknown} -[193; 194) 'S': S"### + ⋮ + ⋮[29; 33) 'self': Self + ⋮[111; 202) '{ ...(S); }': () + ⋮[121; 122) 'x': u32 + ⋮[130; 131) 'S': S + ⋮[130; 138) 'S.into()': u32 + ⋮[148; 149) 'y': u64 + ⋮[157; 158) 'S': S + ⋮[157; 165) 'S.into()': u64 + ⋮[175; 176) 'z': {unknown} + ⋮[179; 196) 'Into::...::into': {unknown} + ⋮[179; 199) 'Into::...nto(S)': {unknown} + ⋮[197; 198) 'S': S + "### ); } @@ -2617,7 +2633,7 @@ fn method_resolution_where_clause_1() { trait Clone {} trait Trait { fn foo(self) -> u128; } struct S; -impl Clone for S {}; +impl Clone for S {} impl Trait for T where T: Clone {} fn test() { S.foo()<|>; } "#, @@ -2634,7 +2650,7 @@ fn method_resolution_where_clause_2() { trait From { fn from(other: T) -> Self; } struct S1; struct S2; -impl From for S1 {}; +impl From for S1 {} impl Into for T where U: From {} fn test() { S2.into()<|>; } "#, @@ -2651,7 +2667,7 @@ fn method_resolution_where_clause_inline() { trait From { fn from(other: T) -> Self; } struct S1; struct S2; -impl From for S1 {}; +impl From for S1 {} impl> Into for T {} fn test() { S2.into()<|>; } "#, @@ -2680,8 +2696,8 @@ fn method_resolution_slow() { //- /main.rs trait SendX {} -struct S1; impl SendX for S1; -struct S2; impl SendX for S2; +struct S1; impl SendX for S1 {} +struct S2; impl SendX for S2 {} struct U1; trait Trait { fn method(self); } @@ -2702,7 +2718,7 @@ impl Trait for S where C: FnX, B: SendX {} } fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String { - let file = db.parse(pos.file_id); + let file = db.parse(pos.file_id).ok().unwrap(); let expr = algo::find_node_at_offset::(file.syntax(), pos.offset).unwrap(); let analyzer = SourceAnalyzer::new(db, pos.file_id, expr.syntax(), Some(pos.offset)); let ty = analyzer.type_of(db, expr).unwrap(); @@ -2716,7 +2732,7 @@ fn type_at(content: &str) -> String { fn infer(content: &str) -> String { let (db, _, file_id) = MockDatabase::with_single_file(content); - let source_file = db.parse(file_id); + let source_file = db.parse(file_id).ok().unwrap(); let mut acc = String::new(); acc.push_str("\n"); @@ -2794,7 +2810,7 @@ fn foo() -> i32 { ", ); { - let file = db.parse(pos.file_id); + let file = db.parse(pos.file_id).ok().unwrap(); let node = algo::find_token_at_offset(file.syntax(), pos.offset).right_biased().unwrap().parent(); let events = db.log_executed(|| { @@ -2815,7 +2831,7 @@ fn foo() -> i32 { db.query_mut(ra_db::FileTextQuery).set(pos.file_id, Arc::new(new_text)); { - let file = db.parse(pos.file_id); + let file = db.parse(pos.file_id).ok().unwrap(); let node = algo::find_token_at_offset(file.syntax(), pos.offset).right_biased().unwrap().parent(); let events = db.log_executed(|| {