]> git.lizzy.rs Git - rust.git/commitdiff
Merge #427
authorbors[bot] <bors[bot]@users.noreply.github.com>
Sat, 5 Jan 2019 07:16:48 +0000 (07:16 +0000)
committerbors[bot] <bors[bot]@users.noreply.github.com>
Sat, 5 Jan 2019 07:16:48 +0000 (07:16 +0000)
427: Remove extra space when joining lines in use items r=matklad a=alanhdu

Fixes #423.

Co-authored-by: Alan Du <alanhdu@gmail.com>
53 files changed:
Cargo.lock
Cargo.toml
crates/ra_analysis/Cargo.toml
crates/ra_analysis/src/completion/complete_dot.rs
crates/ra_analysis/src/db.rs
crates/ra_analysis/src/mock_analysis.rs
crates/ra_analysis/tests/test/main.rs
crates/ra_db/Cargo.toml
crates/ra_editor/src/structure.rs
crates/ra_hir/Cargo.toml
crates/ra_hir/src/db.rs
crates/ra_hir/src/function.rs
crates/ra_hir/src/ids.rs
crates/ra_hir/src/impl_block.rs [new file with mode: 0644]
crates/ra_hir/src/krate.rs
crates/ra_hir/src/lib.rs
crates/ra_hir/src/mock.rs
crates/ra_hir/src/module.rs
crates/ra_hir/src/module/nameres.rs
crates/ra_hir/src/name.rs
crates/ra_hir/src/path.rs
crates/ra_hir/src/ty.rs
crates/ra_hir/src/ty/tests.rs
crates/ra_hir/src/ty/tests/data/0007_self.txt [new file with mode: 0644]
crates/ra_lsp_server/src/conv.rs
crates/ra_syntax/src/ast.rs
crates/ra_syntax/src/ast/generated.rs
crates/ra_syntax/src/grammar.ron
crates/ra_syntax/src/grammar/items.rs
crates/ra_syntax/src/grammar/items/traits.rs
crates/ra_syntax/src/reparsing.rs
crates/ra_syntax/src/syntax_kinds/generated.rs
crates/ra_syntax/tests/data/parser/err/0018_incomplete_fn.txt
crates/ra_syntax/tests/data/parser/err/0022_bad_exprs.txt
crates/ra_syntax/tests/data/parser/err/0026_imp_recovery.txt
crates/ra_syntax/tests/data/parser/inline/err/0002_misplaced_label_err.txt
crates/ra_syntax/tests/data/parser/inline/err/0004_impl_type.txt
crates/ra_syntax/tests/data/parser/inline/ok/0001_trait_item_list.txt
crates/ra_syntax/tests/data/parser/inline/ok/0006_self_param.txt
crates/ra_syntax/tests/data/parser/inline/ok/0018_arb_self_types.txt
crates/ra_syntax/tests/data/parser/inline/ok/0021_impl_item_list.txt
crates/ra_syntax/tests/data/parser/inline/ok/0047_unsafe_default_impl.txt
crates/ra_syntax/tests/data/parser/inline/ok/0063_impl_block_neg.rs [new file with mode: 0644]
crates/ra_syntax/tests/data/parser/inline/ok/0063_impl_block_neg.txt [new file with mode: 0644]
crates/ra_syntax/tests/data/parser/inline/ok/0063_impl_item_neg.rs [deleted file]
crates/ra_syntax/tests/data/parser/inline/ok/0063_impl_item_neg.txt [deleted file]
crates/ra_syntax/tests/data/parser/inline/ok/0079_impl_block.rs [new file with mode: 0644]
crates/ra_syntax/tests/data/parser/inline/ok/0079_impl_block.txt [new file with mode: 0644]
crates/ra_syntax/tests/data/parser/inline/ok/0079_impl_item.rs [deleted file]
crates/ra_syntax/tests/data/parser/inline/ok/0079_impl_item.txt [deleted file]
crates/ra_syntax/tests/data/parser/inline/ok/0087_unsafe_impl.txt
crates/ra_syntax/tests/data/parser/inline/ok/0097_default_impl.txt
crates/ra_syntax/tests/data/parser/ok/0037_mod.txt

index b060586884366d99d3c8891db687e74877bc6051..dbadfc64ef067cf518714f231d036bac71abac2a 100644 (file)
@@ -32,7 +32,7 @@ name = "atty"
 version = "0.2.11"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)",
  "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
@@ -50,8 +50,8 @@ dependencies = [
  "autocfg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)",
  "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
- "rustc-demangle 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)",
  "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -61,7 +61,7 @@ version = "0.1.28"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "cc 1.0.28 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -170,8 +170,8 @@ version = "0.3.6"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "crossbeam-utils 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -270,16 +270,16 @@ dependencies = [
 
 [[package]]
 name = "failure"
-version = "0.1.4"
+version = "0.1.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "backtrace 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
- "failure_derive 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "failure_derive"
-version = "0.1.4"
+version = "0.1.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -337,7 +337,7 @@ name = "gen_lsp_server"
 version = "0.1.0"
 dependencies = [
  "crossbeam-channel 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "failure 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "languageserver-types 0.53.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde 1.0.84 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -434,7 +434,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
 name = "libc"
-version = "0.2.45"
+version = "0.2.46"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
@@ -470,7 +470,7 @@ version = "2.1.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)",
  "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -479,7 +479,7 @@ name = "memmap"
 version = "0.6.2"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)",
  "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -522,7 +522,7 @@ name = "num_cpus"
 version = "1.9.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -535,41 +535,20 @@ dependencies = [
 
 [[package]]
 name = "parking_lot"
-version = "0.6.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
- "parking_lot_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
-[[package]]
-name = "parking_lot"
-version = "0.7.0"
+version = "0.7.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
-[[package]]
-name = "parking_lot_core"
-version = "0.3.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-dependencies = [
- "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
- "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
- "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)",
- "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
-]
-
 [[package]]
 name = "parking_lot_core"
 version = "0.4.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
- "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)",
  "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -664,7 +643,7 @@ dependencies = [
  "fst 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "ra_db 0.1.0",
  "ra_editor 0.1.0",
  "ra_hir 0.1.0",
@@ -673,7 +652,7 @@ dependencies = [
  "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "salsa 0.9.0 (git+https://github.com/matklad/salsa.git?branch=transitive-untracked)",
+ "salsa 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "test_utils 0.1.0",
  "unicase 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
@@ -687,7 +666,7 @@ name = "ra_cli"
 version = "0.1.0"
 dependencies = [
  "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "failure 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "join_to_string 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "ra_editor 0.1.0",
  "ra_syntax 0.1.0",
@@ -698,12 +677,12 @@ dependencies = [
 name = "ra_db"
 version = "0.1.0"
 dependencies = [
- "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "ra_editor 0.1.0",
  "ra_syntax 0.1.0",
  "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "salsa 0.9.0 (git+https://github.com/matklad/salsa.git?branch=transitive-untracked)",
+ "salsa 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "test_utils 0.1.0",
 ]
 
@@ -729,14 +708,14 @@ dependencies = [
  "ena 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "flexi_logger 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "ra_arena 0.1.0",
  "ra_db 0.1.0",
  "ra_editor 0.1.0",
  "ra_syntax 0.1.0",
  "relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "salsa 0.9.0 (git+https://github.com/matklad/salsa.git?branch=transitive-untracked)",
+ "salsa 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "test_utils 0.1.0",
 ]
 
@@ -747,14 +726,14 @@ dependencies = [
  "cargo_metadata 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "crossbeam-channel 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "drop_bomb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "failure 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
- "failure_derive 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
+ "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "flexi_logger 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "gen_lsp_server 0.1.0",
  "im 12.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "languageserver-types 0.53.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "ra_analysis 0.1.0",
  "ra_editor 0.1.0",
  "ra_syntax 0.1.0",
@@ -783,9 +762,9 @@ dependencies = [
  "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
  "drop_bomb 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "ra_text_edit 0.1.0",
- "rowan 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rowan 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "test_utils 0.1.0",
  "text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -822,36 +801,35 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)",
  "rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "rand"
-version = "0.6.1"
+version = "0.6.3"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
- "rand_chacha 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "autocfg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_os 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "rand_pcg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
- "rand_xorshift 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "rand_chacha"
-version = "0.1.0"
+version = "0.1.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
+ "autocfg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -883,6 +861,18 @@ dependencies = [
  "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "rand_os"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "rand_pcg"
 version = "0.1.1"
@@ -894,7 +884,7 @@ dependencies = [
 
 [[package]]
 name = "rand_xorshift"
-version = "0.1.0"
+version = "0.1.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -917,7 +907,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)",
  "num_cpus 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -979,17 +969,17 @@ dependencies = [
 
 [[package]]
 name = "rowan"
-version = "0.1.3"
+version = "0.1.4"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "smol_str 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)",
  "text_unit 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
 name = "rustc-demangle"
-version = "0.1.11"
+version = "0.1.13"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
@@ -1031,14 +1021,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 
 [[package]]
 name = "salsa"
-version = "0.9.0"
-source = "git+https://github.com/matklad/salsa.git?branch=transitive-untracked#a2198f1f8a1d09894b842035a1af6b0b4c133c93"
+version = "0.9.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)",
  "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
@@ -1175,8 +1165,8 @@ version = "3.0.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
- "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
- "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)",
+ "rand 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
  "redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)",
  "remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1207,7 +1197,7 @@ name = "teraron"
 version = "0.0.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "failure 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "ron 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "tera 0.11.20 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1218,7 +1208,7 @@ name = "termion"
 version = "1.5.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)",
  "redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)",
  "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
@@ -1279,7 +1269,7 @@ name = "time"
 version = "0.1.41"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)",
  "redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)",
  "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
@@ -1289,7 +1279,7 @@ name = "tools"
 version = "0.1.0"
 dependencies = [
  "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "failure 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
  "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "teraron 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1442,7 +1432,7 @@ name = "wait-timeout"
 version = "0.1.5"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
- "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)",
+ "libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -1517,8 +1507,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 "checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0"
 "checksum ena 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f56c93cc076508c549d9bb747f79aa9b4eb098be7b8cad8830c3137ef52d1e00"
 "checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02"
-"checksum failure 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "e945b93ec214c6e97b520ec6c5d80267fc97af327658ee5b9f35984626e51fbf"
-"checksum failure_derive 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "7c395a14ab27b42704e85bf2435c5c51f334ad7a96e16fe23c6e63a1cad6cc12"
+"checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2"
+"checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1"
 "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
 "checksum flexi_logger 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4dda06444ccc8b0a6da19d939989b4a4e83f328710ada449eedaed48c8b903cd"
 "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
@@ -1537,7 +1527,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 "checksum join_to_string 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7bddc885f3fd69dd4b5d747c2efe6dd2c36d795ea9938281ed50910e32c95e31"
 "checksum languageserver-types 0.53.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7c01845f71b8b3b3557a8179af4434a4b2570829da12371f05272d28183a06ce"
 "checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1"
-"checksum libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "2d2857ec59fadc0773853c664d2d18e7198e83883e7060b63c924cb077bd5c74"
+"checksum libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)" = "023a4cd09b2ff695f9734c1934145a315594b7986398496841c7031a5a1bbdbd"
 "checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c"
 "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6"
 "checksum maplit 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08cbb6b4fef96b6d77bfc40ec491b1690c779e77b05cd9f07f787ed376fd4c43"
@@ -1551,9 +1541,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 "checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"
 "checksum num_cpus 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5a69d464bdc213aaaff628444e99578ede64e9c854025aa43b9796530afa9238"
 "checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13"
-"checksum parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f0802bff09003b291ba756dc7e79313e51cc31667e94afbe847def490424cde5"
-"checksum parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9723236a9525c757d9725b993511e3fc941e33f27751942232f0058298297edf"
-"checksum parking_lot_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad7f7e6ebdc79edff6fdcb87a55b620174f7a989e3eb31b65231f4af57f00b8c"
+"checksum parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337"
 "checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9"
 "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831"
 "checksum pest 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "54f0c72a98d8ab3c99560bfd16df8059cc10e1f9a8e83e6e3b97718dd766e9c3"
@@ -1565,14 +1553,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0"
 "checksum quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "53fa22a1994bd0f9372d7a816207d8a2677ad0325b073f5c5332760f0fb62b5c"
 "checksum rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e464cd887e869cddcae8792a4ee31d23c7edd516700695608f5b98c67ee0131c"
-"checksum rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ae9d223d52ae411a33cf7e54ec6034ec165df296ccd23533d671a28252b6f66a"
-"checksum rand_chacha 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "771b009e3a508cb67e8823dda454aaa5368c7bc1c16829fb77d3e980440dd34a"
+"checksum rand 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b65e163105a6284f841bd23100a015895f54340e88a5ffc9ca7b8b33827cfce0"
+"checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef"
 "checksum rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1961a422c4d189dfb50ffa9320bf1f2a9bd54ecb92792fb9477f99a1045f3372"
 "checksum rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0905b6b7079ec73b314d4c748701f6931eb79fd97c668caa3f1899b22b32c6db"
 "checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4"
 "checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08"
+"checksum rand_os 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de5ac4de1c2973e1391dc305cb0fbf8788cb58068e98255439b7485a77022273"
 "checksum rand_pcg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "086bd09a33c7044e56bb44d5bdde5a60e7f119a9e95b0775f545de759a32fe05"
-"checksum rand_xorshift 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "effa3fcaa47e18db002bdde6060944b6d2f9cfd8db471c30e873448ad9187be3"
+"checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c"
 "checksum rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "373814f27745b2686b350dd261bfd24576a6fb0e2c5919b3a2b6005f820b0473"
 "checksum rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b055d1e92aba6877574d8fe604a63c8b5df60f60e5982bf7ccbb1338ea527356"
 "checksum redox_syscall 0.1.50 (registry+https://github.com/rust-lang/crates.io-index)" = "52ee9a534dc1301776eff45b4fa92d2c39b1d8c3d3357e6eb593e0d795506fc2"
@@ -1582,14 +1571,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 "checksum relative-path 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0e7790c7f1cc73d831d28dc5a7deb316a006e7848e6a7f467cdb10a0a9e0fb1c"
 "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5"
 "checksum ron 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c48677d8a9247a4e0d1f3f9cb4b0a8e29167fdc3c04f383a5e669cd7a960ae0f"
-"checksum rowan 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a9ccca91953e9c549cac18e8f41daa5d49dad1c9a4c9bb977ac42718bb34e1bf"
-"checksum rustc-demangle 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "01b90379b8664dd83460d59bdc5dd1fd3172b8913788db483ed1325171eab2f7"
+"checksum rowan 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c218b4430ab922850b71b14fa9bca224425097f935f6155c0b6a4b1f398a54f0"
+"checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619"
 "checksum rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8"
 "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a"
 "checksum rusty-fork 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9591f190d2852720b679c21f66ad929f9f1d7bb09d1193c26167586029d8489c"
 "checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7"
 "checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9"
-"checksum salsa 0.9.0 (git+https://github.com/matklad/salsa.git?branch=transitive-untracked)" = "<none>"
+"checksum salsa 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "442ef4acdb48c0e24ddaf4f3b62555af2d1da7047f2f26acd54ae73010aa0c02"
 "checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267"
 "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27"
 "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403"
index dd8499c069d17a53a40a0f503c9c8cd3abdd4d8e..c5155e89960b763dc64f4e8b824a75df180716a1 100644 (file)
@@ -6,4 +6,3 @@ incremental = true
 debug = true
 
 [patch.'crates-io']
-salsa = { git = "https://github.com/matklad/salsa.git", branch = "transitive-untracked" }
index 7a4fdaed97453cbc655f51786ef4ec6d1c120dc9..11c78ced82c48745dfab179a28b5464db3901936 100644 (file)
@@ -10,7 +10,7 @@ log = "0.4.5"
 relative-path = "0.4.0"
 rayon = "1.0.2"
 fst = "0.3.1"
-salsa = "0.9.0"
+salsa = "0.9.1"
 rustc-hash = "1.0"
 parking_lot = "0.7.0"
 unicase = "2.2.0"
index f24835d17779cacfea67ea7570a719e1ecc1be7f..031d8b98f2aceabae0f07b2e2eb52e1d9d13091c 100644 (file)
@@ -72,6 +72,21 @@ fn foo(a: A) {
         );
     }
 
+    #[test]
+    fn test_struct_field_completion_self() {
+        check_ref_completion(
+            r"
+            struct A { the_field: u32 }
+            impl A {
+                fn foo(self) {
+                    self.<|>
+                }
+            }
+            ",
+            r#"the_field"#,
+        );
+    }
+
     #[test]
     fn test_no_struct_field_completion_for_method_call() {
         check_ref_completion(
index d7740f0c4ed7173ded851f51390a3dbdb09b240e..5422a400b63db81ae780601ee71677f9ff732a95 100644 (file)
@@ -105,6 +105,7 @@ impl hir::db::HirDatabase {
             fn type_for_field() for hir::db::TypeForFieldQuery;
             fn struct_data() for hir::db::StructDataQuery;
             fn enum_data() for hir::db::EnumDataQuery;
+            fn impls_in_module() for hir::db::ImplsInModuleQuery;
         }
     }
 }
index 9605294046de9e98b0706f0f152461718b336f74..846c76cfe7ae2abf668b5ac26c86a918a8461588 100644 (file)
@@ -4,7 +4,7 @@
 use test_utils::{extract_offset, extract_range, parse_fixture, CURSOR_MARKER};
 use ra_db::mock::FileMap;
 
-use crate::{Analysis, AnalysisChange, AnalysisHost, FileId, FilePosition, FileRange, SourceRootId};
+use crate::{Analysis, AnalysisChange, AnalysisHost, CrateGraph, FileId, FilePosition, FileRange, SourceRootId};
 
 /// Mock analysis is used in test to bootstrap an AnalysisHost/Analysis
 /// from a set of in-memory files.
@@ -87,12 +87,17 @@ pub fn analysis_host(self) -> AnalysisHost {
         let source_root = SourceRootId(0);
         let mut change = AnalysisChange::new();
         change.add_root(source_root, true);
+        let mut crate_graph = CrateGraph::default();
         for (path, contents) in self.files.into_iter() {
             assert!(path.starts_with('/'));
             let path = RelativePathBuf::from_path(&path[1..]).unwrap();
             let file_id = file_map.add(path.clone());
+            if path == "/lib.rs" || path == "/main.rs" {
+                crate_graph.add_crate_root(file_id);
+            }
             change.add_file(source_root, file_id, path, Arc::new(contents));
         }
+        change.set_crate_graph(crate_graph);
         // change.set_file_resolver(Arc::new(file_map));
         host.apply_change(change);
         host
index 859778024a4aa81e9cde50ef5d54a903eadc9881..beeae1e1967b4ae563434ff66c5a928e4a7b5eb8 100644 (file)
@@ -138,14 +138,14 @@ mod baz { <|> }
 fn test_resolve_crate_root() {
     let mock = MockAnalysis::with_files(
         "
-        //- /lib.rs
+        //- /bar.rs
         mod foo;
-        //- /foo.rs
+        //- /bar/foo.rs
         // emtpy <|>
     ",
     );
-    let root_file = mock.id_of("/lib.rs");
-    let mod_file = mock.id_of("/foo.rs");
+    let root_file = mock.id_of("/bar.rs");
+    let mod_file = mock.id_of("/bar/foo.rs");
     let mut host = mock.analysis_host();
     assert!(host.analysis().crate_for(mod_file).unwrap().is_empty());
 
index ecc56d9532eac122f39be368fb914a7eddff7b69..c0e83a140e2fe948ae20c8cf258cc845f45ef2c0 100644 (file)
@@ -6,7 +6,7 @@ authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
 
 [dependencies]
 relative-path = "0.4.0"
-salsa = "0.9.0"
+salsa = "0.9.1"
 rustc-hash = "1.0"
 parking_lot = "0.7.0"
 ra_syntax = { path = "../ra_syntax" }
index 2292b1ddf0f6699bf5e21a1febe5dac6c4ef3389..32d59e33518957ccee3a0323dd00382c4dd18bbd 100644 (file)
@@ -60,7 +60,7 @@ fn decl<'a, N: NameOwner<'a>>(node: N) -> Option<StructureNode> {
         .visit(decl::<ast::TypeDef>)
         .visit(decl::<ast::ConstDef>)
         .visit(decl::<ast::StaticDef>)
-        .visit(|im: ast::ImplItem| {
+        .visit(|im: ast::ImplBlock| {
             let target_type = im.target_type()?;
             let target_trait = im.target_trait();
             let label = match target_trait {
@@ -121,8 +121,8 @@ impl fmt::Debug for E {}
                 StructureNode { parent: None, label: "T", navigation_range: [81; 82), node_range: [76; 88), kind: TYPE_DEF },
                 StructureNode { parent: None, label: "S", navigation_range: [96; 97), node_range: [89; 108), kind: STATIC_DEF },
                 StructureNode { parent: None, label: "C", navigation_range: [115; 116), node_range: [109; 127), kind: CONST_DEF },
-                StructureNode { parent: None, label: "impl E", navigation_range: [134; 135), node_range: [129; 138), kind: IMPL_ITEM },
-                StructureNode { parent: None, label: "impl fmt::Debug for E", navigation_range: [160; 161), node_range: [140; 164), kind: IMPL_ITEM }]"#,
+                StructureNode { parent: None, label: "impl E", navigation_range: [134; 135), node_range: [129; 138), kind: IMPL_BLOCK },
+                StructureNode { parent: None, label: "impl fmt::Debug for E", navigation_range: [160; 161), node_range: [140; 164), kind: IMPL_BLOCK }]"#,
             &structure,
         )
     }
index 8c0cf4b866e2e90c9e7b32ab058b9499362bc2d1..245a21ce3737e34a68f01e8ff57eee2152d83f7b 100644 (file)
@@ -8,7 +8,7 @@ authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>"]
 arrayvec = "0.4.10"
 log = "0.4.5"
 relative-path = "0.4.0"
-salsa = "0.9.0"
+salsa = "0.9.1"
 rustc-hash = "1.0"
 parking_lot = "0.7.0"
 ena = "0.11"
index 73a4cdc5c828f28ad99780411e3df2bc77755828..58296fc6f3bc369a8eab8bedceb0551080f04fac 100644 (file)
@@ -13,6 +13,7 @@
     nameres::{ItemMap, InputModuleItems}},
     ty::{InferenceResult, Ty},
     adt::{StructData, EnumData},
+    impl_block::ModuleImplBlocks,
 };
 
 salsa::query_group! {
@@ -87,6 +88,11 @@ fn module_tree(source_root_id: SourceRootId) -> Cancelable<Arc<ModuleTree>> {
         type ModuleTreeQuery;
         use fn crate::module::imp::module_tree;
     }
+
+    fn impls_in_module(source_root_id: SourceRootId, module_id: ModuleId) -> Cancelable<Arc<ModuleImplBlocks>> {
+        type ImplsInModuleQuery;
+        use fn crate::impl_block::impls_in_module;
+    }
 }
 
 }
index 5a44132fcca965826ce1bf49332c9df888484446..75ef308ae4912c93d4a242c3fc66393b1f49d1a7 100644 (file)
     ast::{self, AstNode, DocCommentsOwner, NameOwner},
 };
 
-use crate::{DefId, DefKind, HirDatabase, ty::InferenceResult, Module};
+use crate::{DefId, DefKind, HirDatabase, ty::InferenceResult, Module, Crate, impl_block::ImplBlock};
 
 pub use self::scope::FnScopes;
 
-#[derive(Debug)]
+#[derive(Debug, Clone, PartialEq, Eq)]
 pub struct Function {
     def_id: DefId,
 }
@@ -25,6 +25,10 @@ pub(crate) fn new(def_id: DefId) -> Function {
         Function { def_id }
     }
 
+    pub fn def_id(&self) -> DefId {
+        self.def_id
+    }
+
     pub fn syntax(&self, db: &impl HirDatabase) -> ast::FnDefNode {
         let def_loc = self.def_id.loc(db);
         assert!(def_loc.kind == DefKind::Function);
@@ -48,6 +52,15 @@ pub fn infer(&self, db: &impl HirDatabase) -> Cancelable<Arc<InferenceResult>> {
     pub fn module(&self, db: &impl HirDatabase) -> Cancelable<Module> {
         self.def_id.module(db)
     }
+
+    pub fn krate(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> {
+        self.def_id.krate(db)
+    }
+
+    /// The containing impl block, if this is a method.
+    pub fn impl_block(&self, db: &impl HirDatabase) -> Cancelable<Option<ImplBlock>> {
+        self.def_id.impl_block(db)
+    }
 }
 
 #[derive(Debug, Clone)]
index 66adacc7d4ace54f11dd43ba4d9892df7edf97bb..4d6378e0286353d3c817b985edb27642ea44bd0f 100644 (file)
@@ -2,7 +2,7 @@
 use ra_syntax::{SourceFileNode, SyntaxKind, SyntaxNode, SyntaxNodeRef, SourceFile, AstNode, ast};
 use ra_arena::{Arena, RawId, impl_arena_id};
 
-use crate::{HirDatabase, PerNs, ModuleId, Module, Def, Function, Struct, Enum};
+use crate::{HirDatabase, PerNs, ModuleId, Module, Def, Function, Struct, Enum, ImplBlock, Crate};
 
 /// hir makes a heavy use of ids: integer (u32) handlers to various things. You
 /// can think of id as a pointer (but without a lifetime) or a file descriptor
@@ -177,6 +177,18 @@ pub fn module(self, db: &impl HirDatabase) -> Cancelable<Module> {
         let loc = self.loc(db);
         Module::new(db, loc.source_root_id, loc.module_id)
     }
+
+    /// Returns the containing crate.
+    pub fn krate(&self, db: &impl HirDatabase) -> Cancelable<Option<Crate>> {
+        Ok(self.module(db)?.krate(db))
+    }
+
+    /// Returns the containing impl block, if this is an impl item.
+    pub fn impl_block(self, db: &impl HirDatabase) -> Cancelable<Option<ImplBlock>> {
+        let loc = self.loc(db);
+        let module_impls = db.impls_in_module(loc.source_root_id, loc.module_id)?;
+        Ok(ImplBlock::containing(module_impls, self))
+    }
 }
 
 impl DefLoc {
diff --git a/crates/ra_hir/src/impl_block.rs b/crates/ra_hir/src/impl_block.rs
new file mode 100644 (file)
index 0000000..01afa84
--- /dev/null
@@ -0,0 +1,180 @@
+use std::sync::Arc;
+use rustc_hash::FxHashMap;
+
+use ra_arena::{Arena, RawId, impl_arena_id};
+use ra_syntax::ast::{self, AstNode};
+use ra_db::{LocationIntener, Cancelable, SourceRootId};
+
+use crate::{
+    DefId, DefLoc, DefKind, SourceItemId, SourceFileItems,
+    Module, Function,
+    db::HirDatabase,
+    type_ref::TypeRef,
+    module::{ModuleSourceNode, ModuleId},
+};
+
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct ImplBlock {
+    module_impl_blocks: Arc<ModuleImplBlocks>,
+    impl_id: ImplId,
+}
+
+impl ImplBlock {
+    pub(crate) fn containing(
+        module_impl_blocks: Arc<ModuleImplBlocks>,
+        def_id: DefId,
+    ) -> Option<ImplBlock> {
+        let impl_id = *module_impl_blocks.impls_by_def.get(&def_id)?;
+        Some(ImplBlock {
+            module_impl_blocks,
+            impl_id,
+        })
+    }
+
+    fn impl_data(&self) -> &ImplData {
+        &self.module_impl_blocks.impls[self.impl_id]
+    }
+
+    pub fn target_trait(&self) -> Option<&TypeRef> {
+        self.impl_data().target_trait.as_ref()
+    }
+
+    pub fn target_type(&self) -> &TypeRef {
+        &self.impl_data().target_type
+    }
+
+    pub fn items(&self) -> &[ImplItem] {
+        &self.impl_data().items
+    }
+}
+
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct ImplData {
+    target_trait: Option<TypeRef>,
+    target_type: TypeRef,
+    items: Vec<ImplItem>,
+}
+
+impl ImplData {
+    pub(crate) fn from_ast(
+        db: &impl AsRef<LocationIntener<DefLoc, DefId>>,
+        file_items: &SourceFileItems,
+        module: &Module,
+        node: ast::ImplBlock,
+    ) -> Self {
+        let target_trait = node.target_type().map(TypeRef::from_ast);
+        let target_type = TypeRef::from_ast_opt(node.target_type());
+        let file_id = module.source().file_id();
+        let items = if let Some(item_list) = node.item_list() {
+            item_list
+                .impl_items()
+                .map(|item_node| {
+                    let kind = match item_node {
+                        ast::ImplItem::FnDef(..) => DefKind::Function,
+                        ast::ImplItem::ConstDef(..) => DefKind::Item,
+                        ast::ImplItem::TypeDef(..) => DefKind::Item,
+                    };
+                    let item_id = file_items.id_of_unchecked(item_node.syntax());
+                    let def_loc = DefLoc {
+                        kind,
+                        source_root_id: module.source_root_id,
+                        module_id: module.module_id,
+                        source_item_id: SourceItemId {
+                            file_id,
+                            item_id: Some(item_id),
+                        },
+                    };
+                    let def_id = def_loc.id(db);
+                    match item_node {
+                        ast::ImplItem::FnDef(..) => ImplItem::Method(Function::new(def_id)),
+                        ast::ImplItem::ConstDef(..) => ImplItem::Const(def_id),
+                        ast::ImplItem::TypeDef(..) => ImplItem::Type(def_id),
+                    }
+                })
+                .collect()
+        } else {
+            Vec::new()
+        };
+        ImplData {
+            target_trait,
+            target_type,
+            items,
+        }
+    }
+}
+
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub enum ImplItem {
+    Method(Function),
+    // these don't have their own types yet
+    Const(DefId),
+    Type(DefId),
+    // Existential
+}
+
+impl ImplItem {
+    pub fn def_id(&self) -> DefId {
+        match self {
+            ImplItem::Method(f) => f.def_id(),
+            ImplItem::Const(def_id) => *def_id,
+            ImplItem::Type(def_id) => *def_id,
+        }
+    }
+}
+
+#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
+pub struct ImplId(pub RawId);
+impl_arena_id!(ImplId);
+
+/// Collection of impl blocks is a two-step process: First we collect the blocks
+/// per-module; then we build an index of all impl blocks in the crate. This
+/// way, we avoid having to do this process for the whole crate whenever someone
+/// types in any file; as long as the impl blocks in the file don't change, we
+/// don't need to do the second step again.
+///
+/// (The second step does not yet exist currently.)
+#[derive(Debug, PartialEq, Eq)]
+pub struct ModuleImplBlocks {
+    impls: Arena<ImplId, ImplData>,
+    impls_by_def: FxHashMap<DefId, ImplId>,
+}
+
+impl ModuleImplBlocks {
+    fn new() -> Self {
+        ModuleImplBlocks {
+            impls: Arena::default(),
+            impls_by_def: FxHashMap::default(),
+        }
+    }
+
+    fn collect(&mut self, db: &impl HirDatabase, module: Module) -> Cancelable<()> {
+        let module_source_node = module.source().resolve(db);
+        let node = match &module_source_node {
+            ModuleSourceNode::SourceFile(node) => node.borrowed().syntax(),
+            ModuleSourceNode::Module(node) => node.borrowed().syntax(),
+        };
+
+        let source_file_items = db.file_items(module.source().file_id());
+
+        for impl_block_ast in node.children().filter_map(ast::ImplBlock::cast) {
+            let impl_block = ImplData::from_ast(db, &source_file_items, &module, impl_block_ast);
+            let id = self.impls.alloc(impl_block);
+            for impl_item in &self.impls[id].items {
+                self.impls_by_def.insert(impl_item.def_id(), id);
+            }
+        }
+
+        Ok(())
+    }
+}
+
+pub(crate) fn impls_in_module(
+    db: &impl HirDatabase,
+    source_root_id: SourceRootId,
+    module_id: ModuleId,
+) -> Cancelable<Arc<ModuleImplBlocks>> {
+    let mut result = ModuleImplBlocks::new();
+    let module = Module::new(db, source_root_id, module_id)?;
+    result.collect(db, module)?;
+    Ok(Arc::new(result))
+}
index a0821d15dd2d551ae4080bce8aed0750b054a414..5194e280b751b2d07c2cacaa32648e9c26356269 100644 (file)
@@ -5,7 +5,7 @@
 /// hir::Crate describes a single crate. It's the main inteface with which
 /// crate's dependencies interact. Mostly, it should be just a proxy for the
 /// root module.
-#[derive(Debug)]
+#[derive(Debug, Clone, PartialEq, Eq, Hash)]
 pub struct Crate {
     crate_id: CrateId,
 }
index 344b543b6e4d319dcac9b3bb7469ff3976ef846e..2abcec441b846d1f65a7550edf79e9dbf7001a30 100644 (file)
@@ -31,6 +31,7 @@ macro_rules! ctry {
 mod adt;
 mod type_ref;
 mod ty;
+mod impl_block;
 
 use crate::{
     db::HirDatabase,
@@ -48,6 +49,7 @@ macro_rules! ctry {
     function::{Function, FnScopes},
     adt::{Struct, Enum},
     ty::Ty,
+    impl_block::{ImplBlock, ImplItem},
 };
 
 pub use self::function::FnSignatureInfo;
index 89b18194ac0f8402b8cde1feaa0b1df1eff7d166..a9db932ff023e479078c1ce271da7590b1eae08f 100644 (file)
@@ -30,6 +30,10 @@ pub(crate) fn with_single_file(text: &str) -> (MockDatabase, SourceRoot, FileId)
         let file_id = db.add_file(&mut source_root, "/main.rs", text);
         db.query_mut(ra_db::SourceRootQuery)
             .set(WORKSPACE, Arc::new(source_root.clone()));
+
+        let mut crate_graph = CrateGraph::default();
+        crate_graph.add_crate_root(file_id);
+        db.set_crate_graph(crate_graph);
         (db, source_root, file_id)
     }
 
@@ -203,6 +207,7 @@ impl db::HirDatabase {
             fn type_for_field() for db::TypeForFieldQuery;
             fn struct_data() for db::StructDataQuery;
             fn enum_data() for db::EnumDataQuery;
+            fn impls_in_module() for db::ImplsInModuleQuery;
         }
     }
 }
index c70dc54dd946d07479cd48eda02b673db5b81dcb..b9821115ce8ba39b232c5c3d245b2799b23ddf90 100644 (file)
@@ -71,6 +71,21 @@ pub fn parent(&self) -> Option<Module> {
         })
     }
 
+    /// Returns an iterator of all children of this module.
+    pub fn children<'a>(&'a self) -> impl Iterator<Item = (Name, Module)> + 'a {
+        self.module_id
+            .children(&self.tree)
+            .map(move |(name, module_id)| {
+                (
+                    name,
+                    Module {
+                        module_id,
+                        ..self.clone()
+                    },
+                )
+            })
+    }
+
     /// Returns the crate this module is part of.
     pub fn krate(&self, db: &impl HirDatabase) -> Option<Crate> {
         let root_id = self.module_id.crate_root(&self.tree);
index 8d120962608217bad6ddc243c0a3c2ca69667b55..3c6851a0a3d273bf1f23f36b14cbe38c107e1c7f 100644 (file)
@@ -233,7 +233,7 @@ pub(crate) fn add_item(
             ast::ModuleItem::TypeDef(it) => {
                 self.items.push(ModuleItem::new(file_id, file_items, it)?)
             }
-            ast::ModuleItem::ImplItem(_) => {
+            ast::ModuleItem::ImplBlock(_) => {
                 // impls don't define items
             }
             ast::ModuleItem::UseItem(it) => self.add_use_item(file_items, it),
index 51e8b3da86f4a58e31af945c46b964b95f360d45..017caf442e29c56b082c6e6280741bd79689ec7d 100644 (file)
@@ -51,6 +51,7 @@ pub(crate) fn as_known_name(&self) -> Option<KnownName> {
             "u128" => KnownName::U128,
             "f32" => KnownName::F32,
             "f64" => KnownName::F64,
+            "Self" => KnownName::Self_,
             _ => return None,
         };
         Some(name)
@@ -84,7 +85,7 @@ fn as_name(&self) -> Name {
 // const ISIZE: Name = Name::new("isize")
 // ```
 // but const-fn is not that powerful yet.
-#[derive(Debug)]
+#[derive(Debug, PartialEq, Eq)]
 pub(crate) enum KnownName {
     Isize,
     I8,
@@ -102,4 +103,6 @@ pub(crate) enum KnownName {
 
     F32,
     F64,
+
+    Self_,
 }
index 93f7203fe26587388c8392689da2d9464f62f57f..9fdfa0d131238b5f46661babe8c626176892229e 100644 (file)
@@ -70,6 +70,11 @@ pub fn is_ident(&self) -> bool {
         self.kind == PathKind::Plain && self.segments.len() == 1
     }
 
+    /// `true` if this path is just a standalone `self`
+    pub fn is_self(&self) -> bool {
+        self.kind == PathKind::Self_ && self.segments.len() == 0
+    }
+
     /// If this path is a single identifier, like `foo`, return its name.
     pub fn as_ident(&self) -> Option<&Name> {
         if self.kind != PathKind::Plain || self.segments.len() > 1 {
index 719b3f7cd70035230745bbd04a866566bea996a8..e33762e0ddb2a11479dc0302d24b4a12ab636627 100644 (file)
 };
 
 use crate::{
-    Def, DefId, FnScopes, Module, Function, Struct, Enum, Path, Name, AsName,
+    Def, DefId, FnScopes, Module, Function, Struct, Enum, Path, Name, AsName, ImplBlock,
     db::HirDatabase,
     type_ref::{TypeRef, Mutability},
+    name::KnownName,
 };
 
 /// The ID of a type variable.
@@ -235,6 +236,7 @@ impl Ty {
     pub(crate) fn from_hir(
         db: &impl HirDatabase,
         module: &Module,
+        impl_block: Option<&ImplBlock>,
         type_ref: &TypeRef,
     ) -> Cancelable<Self> {
         Ok(match type_ref {
@@ -242,29 +244,29 @@ pub(crate) fn from_hir(
             TypeRef::Tuple(inner) => {
                 let inner_tys = inner
                     .iter()
-                    .map(|tr| Ty::from_hir(db, module, tr))
+                    .map(|tr| Ty::from_hir(db, module, impl_block, tr))
                     .collect::<Cancelable<Vec<_>>>()?;
                 Ty::Tuple(inner_tys.into())
             }
-            TypeRef::Path(path) => Ty::from_hir_path(db, module, path)?,
+            TypeRef::Path(path) => Ty::from_hir_path(db, module, impl_block, path)?,
             TypeRef::RawPtr(inner, mutability) => {
-                let inner_ty = Ty::from_hir(db, module, inner)?;
+                let inner_ty = Ty::from_hir(db, module, impl_block, inner)?;
                 Ty::RawPtr(Arc::new(inner_ty), *mutability)
             }
             TypeRef::Array(_inner) => Ty::Unknown, // TODO
             TypeRef::Slice(inner) => {
-                let inner_ty = Ty::from_hir(db, module, inner)?;
+                let inner_ty = Ty::from_hir(db, module, impl_block, inner)?;
                 Ty::Slice(Arc::new(inner_ty))
             }
             TypeRef::Reference(inner, mutability) => {
-                let inner_ty = Ty::from_hir(db, module, inner)?;
+                let inner_ty = Ty::from_hir(db, module, impl_block, inner)?;
                 Ty::Ref(Arc::new(inner_ty), *mutability)
             }
             TypeRef::Placeholder => Ty::Unknown,
             TypeRef::Fn(params) => {
                 let mut inner_tys = params
                     .iter()
-                    .map(|tr| Ty::from_hir(db, module, tr))
+                    .map(|tr| Ty::from_hir(db, module, impl_block, tr))
                     .collect::<Cancelable<Vec<_>>>()?;
                 let return_ty = inner_tys
                     .pop()
@@ -279,9 +281,21 @@ pub(crate) fn from_hir(
         })
     }
 
+    pub(crate) fn from_hir_opt(
+        db: &impl HirDatabase,
+        module: &Module,
+        impl_block: Option<&ImplBlock>,
+        type_ref: Option<&TypeRef>,
+    ) -> Cancelable<Self> {
+        type_ref
+            .map(|t| Ty::from_hir(db, module, impl_block, t))
+            .unwrap_or(Ok(Ty::Unknown))
+    }
+
     pub(crate) fn from_hir_path(
         db: &impl HirDatabase,
         module: &Module,
+        impl_block: Option<&ImplBlock>,
         path: &Path,
     ) -> Cancelable<Self> {
         if let Some(name) = path.as_ident() {
@@ -291,6 +305,8 @@ pub(crate) fn from_hir_path(
                 return Ok(Ty::Uint(uint_ty));
             } else if let Some(float_ty) = primitive::FloatTy::from_name(name) {
                 return Ok(Ty::Float(float_ty));
+            } else if name.as_known_name() == Some(KnownName::Self_) {
+                return Ty::from_hir_opt(db, module, None, impl_block.map(|i| i.target_type()));
             }
         }
 
@@ -308,18 +324,20 @@ pub(crate) fn from_hir_path(
     pub(crate) fn from_ast_opt(
         db: &impl HirDatabase,
         module: &Module,
+        impl_block: Option<&ImplBlock>,
         node: Option<ast::TypeRef>,
     ) -> Cancelable<Self> {
-        node.map(|n| Ty::from_ast(db, module, n))
+        node.map(|n| Ty::from_ast(db, module, impl_block, n))
             .unwrap_or(Ok(Ty::Unknown))
     }
 
     pub(crate) fn from_ast(
         db: &impl HirDatabase,
         module: &Module,
+        impl_block: Option<&ImplBlock>,
         node: ast::TypeRef,
     ) -> Cancelable<Self> {
-        Ty::from_hir(db, module, &TypeRef::from_ast(node))
+        Ty::from_hir(db, module, impl_block, &TypeRef::from_ast(node))
     }
 
     pub fn unit() -> Self {
@@ -402,18 +420,19 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
 fn type_for_fn(db: &impl HirDatabase, f: Function) -> Cancelable<Ty> {
     let syntax = f.syntax(db);
     let module = f.module(db)?;
+    let impl_block = f.impl_block(db)?;
     let node = syntax.borrowed();
     // TODO we ignore type parameters for now
     let input = node
         .param_list()
         .map(|pl| {
             pl.params()
-                .map(|p| Ty::from_ast_opt(db, &module, p.type_ref()))
+                .map(|p| Ty::from_ast_opt(db, &module, impl_block.as_ref(), p.type_ref()))
                 .collect()
         })
         .unwrap_or_else(|| Ok(Vec::new()))?;
     let output = if let Some(type_ref) = node.ret_type().and_then(|rt| rt.type_ref()) {
-        Ty::from_ast(db, &module, type_ref)?
+        Ty::from_ast(db, &module, impl_block.as_ref(), type_ref)?
     } else {
         Ty::unit()
     };
@@ -467,12 +486,13 @@ pub(super) fn type_for_field(db: &impl HirDatabase, def_id: DefId, field: Name)
         ),
     };
     let module = def_id.module(db)?;
+    let impl_block = def_id.impl_block(db)?;
     let type_ref = if let Some(tr) = variant_data.get_field_type_ref(&field) {
         tr
     } else {
         return Ok(Ty::Unknown);
     };
-    Ty::from_hir(db, &module, &type_ref)
+    Ty::from_hir(db, &module, impl_block.as_ref(), &type_ref)
 }
 
 /// The result of type inference: A mapping from expressions and patterns to types.
@@ -496,19 +516,32 @@ pub fn type_of_node(&self, node: SyntaxNodeRef) -> Option<Ty> {
 struct InferenceContext<'a, D: HirDatabase> {
     db: &'a D,
     scopes: Arc<FnScopes>,
+    /// The self param for the current method, if it exists.
+    self_param: Option<LocalSyntaxPtr>,
     module: Module,
+    impl_block: Option<ImplBlock>,
     var_unification_table: InPlaceUnificationTable<TypeVarId>,
     type_of: FxHashMap<LocalSyntaxPtr, Ty>,
+    /// The return type of the function being inferred.
+    return_ty: Ty,
 }
 
 impl<'a, D: HirDatabase> InferenceContext<'a, D> {
-    fn new(db: &'a D, scopes: Arc<FnScopes>, module: Module) -> Self {
+    fn new(
+        db: &'a D,
+        scopes: Arc<FnScopes>,
+        module: Module,
+        impl_block: Option<ImplBlock>,
+    ) -> Self {
         InferenceContext {
             type_of: FxHashMap::default(),
             var_unification_table: InPlaceUnificationTable::new(),
+            self_param: None,       // set during parameter typing
+            return_ty: Ty::Unknown, // set in collect_fn_signature
             db,
             scopes,
             module,
+            impl_block,
         }
     }
 
@@ -525,6 +558,14 @@ fn write_ty(&mut self, node: SyntaxNodeRef, ty: Ty) {
         self.type_of.insert(LocalSyntaxPtr::new(node), ty);
     }
 
+    fn make_ty(&self, type_ref: &TypeRef) -> Cancelable<Ty> {
+        Ty::from_hir(self.db, &self.module, self.impl_block.as_ref(), type_ref)
+    }
+
+    fn make_ty_opt(&self, type_ref: Option<&TypeRef>) -> Cancelable<Ty> {
+        Ty::from_hir_opt(self.db, &self.module, self.impl_block.as_ref(), type_ref)
+    }
+
     fn unify(&mut self, ty1: &Ty, ty2: &Ty) -> bool {
         match (ty1, ty2) {
             (Ty::Unknown, ..) => true,
@@ -628,6 +669,12 @@ fn infer_path_expr(&mut self, expr: ast::PathExpr) -> Cancelable<Option<Ty>> {
                 let ty = self.resolve_ty_as_possible(ty.clone());
                 return Ok(Some(ty));
             };
+        } else if path.is_self() {
+            // resolve `self` param
+            let self_param = ctry!(self.self_param);
+            let ty = ctry!(self.type_of.get(&self_param));
+            let ty = self.resolve_ty_as_possible(ty.clone());
+            return Ok(Some(ty));
         };
 
         // resolve in module
@@ -826,7 +873,12 @@ fn infer_expr(&mut self, expr: ast::Expr, expected: &Expectation) -> Cancelable<
             }
             ast::Expr::CastExpr(e) => {
                 let _inner_ty = self.infer_expr_opt(e.expr(), &Expectation::none())?;
-                let cast_ty = Ty::from_ast_opt(self.db, &self.module, e.type_ref())?;
+                let cast_ty = Ty::from_ast_opt(
+                    self.db,
+                    &self.module,
+                    self.impl_block.as_ref(),
+                    e.type_ref(),
+                )?;
                 let cast_ty = self.insert_type_vars(cast_ty);
                 // TODO do the coercion...
                 cast_ty
@@ -880,7 +932,12 @@ fn infer_block(&mut self, node: ast::Block, expected: &Expectation) -> Cancelabl
         for stmt in node.statements() {
             match stmt {
                 ast::Stmt::LetStmt(stmt) => {
-                    let decl_ty = Ty::from_ast_opt(self.db, &self.module, stmt.type_ref())?;
+                    let decl_ty = Ty::from_ast_opt(
+                        self.db,
+                        &self.module,
+                        self.impl_block.as_ref(),
+                        stmt.type_ref(),
+                    )?;
                     let decl_ty = self.insert_type_vars(decl_ty);
                     let ty = if let Some(expr) = stmt.initializer() {
                         let expr_ty = self.infer_expr(expr, &Expectation::has_type(decl_ty))?;
@@ -906,46 +963,71 @@ fn infer_block(&mut self, node: ast::Block, expected: &Expectation) -> Cancelabl
         self.write_ty(node.syntax(), ty.clone());
         Ok(ty)
     }
+
+    fn collect_fn_signature(&mut self, node: ast::FnDef) -> Cancelable<()> {
+        if let Some(param_list) = node.param_list() {
+            if let Some(self_param) = param_list.self_param() {
+                let self_type = if let Some(type_ref) = self_param.type_ref() {
+                    let ty = self.make_ty(&TypeRef::from_ast(type_ref))?;
+                    self.insert_type_vars(ty)
+                } else {
+                    // TODO this should be handled by desugaring during HIR conversion
+                    let ty = self.make_ty_opt(self.impl_block.as_ref().map(|i| i.target_type()))?;
+                    let ty = match self_param.flavor() {
+                        ast::SelfParamFlavor::Owned => ty,
+                        ast::SelfParamFlavor::Ref => Ty::Ref(Arc::new(ty), Mutability::Shared),
+                        ast::SelfParamFlavor::MutRef => Ty::Ref(Arc::new(ty), Mutability::Mut),
+                    };
+                    self.insert_type_vars(ty)
+                };
+                if let Some(self_kw) = self_param.self_kw() {
+                    let self_param = LocalSyntaxPtr::new(self_kw.syntax());
+                    self.self_param = Some(self_param);
+                    self.type_of.insert(self_param, self_type);
+                }
+            }
+            for param in param_list.params() {
+                let pat = if let Some(pat) = param.pat() {
+                    pat
+                } else {
+                    continue;
+                };
+                let ty = if let Some(type_ref) = param.type_ref() {
+                    let ty = self.make_ty(&TypeRef::from_ast(type_ref))?;
+                    self.insert_type_vars(ty)
+                } else {
+                    // missing type annotation
+                    self.new_type_var()
+                };
+                self.type_of.insert(LocalSyntaxPtr::new(pat.syntax()), ty);
+            }
+        }
+
+        self.return_ty = if let Some(type_ref) = node.ret_type().and_then(|n| n.type_ref()) {
+            let ty = self.make_ty(&TypeRef::from_ast(type_ref))?;
+            self.insert_type_vars(ty)
+        } else {
+            Ty::unit()
+        };
+
+        Ok(())
+    }
 }
 
 pub fn infer(db: &impl HirDatabase, def_id: DefId) -> Cancelable<Arc<InferenceResult>> {
     let function = Function::new(def_id); // TODO: consts also need inference
     let scopes = function.scopes(db);
     let module = function.module(db)?;
-    let mut ctx = InferenceContext::new(db, scopes, module);
+    let impl_block = function.impl_block(db)?;
+    let mut ctx = InferenceContext::new(db, scopes, module, impl_block);
 
     let syntax = function.syntax(db);
     let node = syntax.borrowed();
 
-    if let Some(param_list) = node.param_list() {
-        for param in param_list.params() {
-            let pat = if let Some(pat) = param.pat() {
-                pat
-            } else {
-                continue;
-            };
-            if let Some(type_ref) = param.type_ref() {
-                let ty = Ty::from_ast(db, &ctx.module, type_ref)?;
-                let ty = ctx.insert_type_vars(ty);
-                ctx.type_of.insert(LocalSyntaxPtr::new(pat.syntax()), ty);
-            } else {
-                // TODO self param
-                let type_var = ctx.new_type_var();
-                ctx.type_of
-                    .insert(LocalSyntaxPtr::new(pat.syntax()), type_var);
-            };
-        }
-    }
-
-    let ret_ty = if let Some(type_ref) = node.ret_type().and_then(|n| n.type_ref()) {
-        let ty = Ty::from_ast(db, &ctx.module, type_ref)?;
-        ctx.insert_type_vars(ty)
-    } else {
-        Ty::unit()
-    };
+    ctx.collect_fn_signature(node)?;
 
     if let Some(block) = node.body() {
-        ctx.infer_block(block, &Expectation::has_type(ret_ty))?;
+        ctx.infer_block(block, &Expectation::has_type(ctx.return_ty.clone()))?;
     }
 
     Ok(Arc::new(ctx.resolve_all()))
index 93bf431c4d5763dc295168bb5841d6f32085476c..fb53fcf0be965fee00458bf159c3499a50af4a92 100644 (file)
@@ -134,6 +134,25 @@ fn test() -> &mut &f64 {
     );
 }
 
+#[test]
+fn infer_self() {
+    check_inference(
+        r#"
+struct S;
+
+impl S {
+    fn test(&self) {
+        self;
+    }
+    fn test2(self: &Self) {
+        self;
+    }
+}
+"#,
+        "0007_self.txt",
+    );
+}
+
 fn infer(content: &str) -> String {
     let (db, _, file_id) = MockDatabase::with_single_file(content);
     let source_file = db.source_file(file_id);
diff --git a/crates/ra_hir/src/ty/tests/data/0007_self.txt b/crates/ra_hir/src/ty/tests/data/0007_self.txt
new file mode 100644 (file)
index 0000000..db4ba17
--- /dev/null
@@ -0,0 +1,6 @@
+[50; 54) 'self': &S
+[34; 38) 'self': &S
+[40; 61) '{     ...     }': ()
+[88; 109) '{     ...     }': ()
+[98; 102) 'self': &S
+[75; 79) 'self': &S
index 7230fb101b9bd4fcb09ce14af87db590c960e767..e8eb3940f99c0c1c07fb5c26d61d8cbd723d9ccb 100644 (file)
@@ -44,7 +44,7 @@ fn conv(self) -> <Self as Conv>::Output {
             SyntaxKind::TYPE_DEF => SymbolKind::TypeParameter,
             SyntaxKind::STATIC_DEF => SymbolKind::Constant,
             SyntaxKind::CONST_DEF => SymbolKind::Constant,
-            SyntaxKind::IMPL_ITEM => SymbolKind::Object,
+            SyntaxKind::IMPL_BLOCK => SymbolKind::Object,
             _ => SymbolKind::Variable,
         }
     }
index 3aaa5edda61f5f1efa42f6a92e54d701c68e53d4..2a3bd27e25fc09084e5b6ceab49e6c122ff75d0d 100644 (file)
@@ -279,7 +279,7 @@ pub fn text(&self) -> SmolStr {
     }
 }
 
-impl<'a> ImplItem<'a> {
+impl<'a> ImplBlock<'a> {
     pub fn target_type(self) -> Option<TypeRef<'a>> {
         match self.target() {
             (Some(t), None) | (_, Some(t)) => Some(t),
@@ -482,6 +482,37 @@ pub fn op(&self) -> Option<PrefixOp> {
     }
 }
 
+#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
+pub enum SelfParamFlavor {
+    /// self
+    Owned,
+    /// &self
+    Ref,
+    /// &mut self
+    MutRef,
+}
+
+impl<'a> SelfParam<'a> {
+    pub fn flavor(&self) -> SelfParamFlavor {
+        let borrowed = self.syntax().children().any(|n| n.kind() == AMP);
+        if borrowed {
+            // check for a `mut` coming after the & -- `mut &self` != `&mut self`
+            if self
+                .syntax()
+                .children()
+                .skip_while(|n| n.kind() != AMP)
+                .any(|n| n.kind() == MUT_KW)
+            {
+                SelfParamFlavor::MutRef
+            } else {
+                SelfParamFlavor::Ref
+            }
+        } else {
+            SelfParamFlavor::Owned
+        }
+    }
+}
+
 #[test]
 fn test_doc_comment_of_items() {
     let file = SourceFileNode::parse(
index c619fc130363a9839c671de09b6797671ffa7d29..7df6a9c4661fd2c6a982bef127d63b86779eacee 100644 (file)
@@ -1407,41 +1407,73 @@ pub fn condition(self) -> Option<Condition<'a>> {
     }
 }
 
-// ImplItem
+// ImplBlock
 #[derive(Debug, Clone, Copy,)]
-pub struct ImplItemNode<R: TreeRoot<RaTypes> = OwnedRoot> {
+pub struct ImplBlockNode<R: TreeRoot<RaTypes> = OwnedRoot> {
     pub(crate) syntax: SyntaxNode<R>,
 }
-pub type ImplItem<'a> = ImplItemNode<RefRoot<'a>>;
+pub type ImplBlock<'a> = ImplBlockNode<RefRoot<'a>>;
 
-impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ImplItemNode<R1>> for ImplItemNode<R2> {
-    fn eq(&self, other: &ImplItemNode<R1>) -> bool { self.syntax == other.syntax }
+impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<ImplBlockNode<R1>> for ImplBlockNode<R2> {
+    fn eq(&self, other: &ImplBlockNode<R1>) -> bool { self.syntax == other.syntax }
 }
-impl<R: TreeRoot<RaTypes>> Eq for ImplItemNode<R> {}
-impl<R: TreeRoot<RaTypes>> Hash for ImplItemNode<R> {
+impl<R: TreeRoot<RaTypes>> Eq for ImplBlockNode<R> {}
+impl<R: TreeRoot<RaTypes>> Hash for ImplBlockNode<R> {
     fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
 }
 
-impl<'a> AstNode<'a> for ImplItem<'a> {
+impl<'a> AstNode<'a> for ImplBlock<'a> {
     fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
         match syntax.kind() {
-            IMPL_ITEM => Some(ImplItem { syntax }),
+            IMPL_BLOCK => Some(ImplBlock { syntax }),
             _ => None,
         }
     }
     fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
 }
 
-impl<R: TreeRoot<RaTypes>> ImplItemNode<R> {
-    pub fn borrowed(&self) -> ImplItem {
-        ImplItemNode { syntax: self.syntax.borrowed() }
+impl<R: TreeRoot<RaTypes>> ImplBlockNode<R> {
+    pub fn borrowed(&self) -> ImplBlock {
+        ImplBlockNode { syntax: self.syntax.borrowed() }
     }
-    pub fn owned(&self) -> ImplItemNode {
-        ImplItemNode { syntax: self.syntax.owned() }
+    pub fn owned(&self) -> ImplBlockNode {
+        ImplBlockNode { syntax: self.syntax.owned() }
     }
 }
 
 
+impl<'a> ImplBlock<'a> {
+    pub fn item_list(self) -> Option<ItemList<'a>> {
+        super::child_opt(self)
+    }
+}
+
+// ImplItem
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+pub enum ImplItem<'a> {
+    FnDef(FnDef<'a>),
+    TypeDef(TypeDef<'a>),
+    ConstDef(ConstDef<'a>),
+}
+
+impl<'a> AstNode<'a> for ImplItem<'a> {
+    fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
+        match syntax.kind() {
+            FN_DEF => Some(ImplItem::FnDef(FnDef { syntax })),
+            TYPE_DEF => Some(ImplItem::TypeDef(TypeDef { syntax })),
+            CONST_DEF => Some(ImplItem::ConstDef(ConstDef { syntax })),
+            _ => None,
+        }
+    }
+    fn syntax(self) -> SyntaxNodeRef<'a> {
+        match self {
+            ImplItem::FnDef(inner) => inner.syntax(),
+            ImplItem::TypeDef(inner) => inner.syntax(),
+            ImplItem::ConstDef(inner) => inner.syntax(),
+        }
+    }
+}
+
 impl<'a> ImplItem<'a> {}
 
 // ImplTraitType
@@ -1555,7 +1587,11 @@ pub fn owned(&self) -> ItemListNode {
 
 impl<'a> ast::FnDefOwner<'a> for ItemList<'a> {}
 impl<'a> ast::ModuleItemOwner<'a> for ItemList<'a> {}
-impl<'a> ItemList<'a> {}
+impl<'a> ItemList<'a> {
+    pub fn impl_items(self) -> impl Iterator<Item = ImplItem<'a>> + 'a {
+        super::children(self)
+    }
+}
 
 // Label
 #[derive(Debug, Clone, Copy,)]
@@ -2157,7 +2193,7 @@ pub enum ModuleItem<'a> {
     FnDef(FnDef<'a>),
     TraitDef(TraitDef<'a>),
     TypeDef(TypeDef<'a>),
-    ImplItem(ImplItem<'a>),
+    ImplBlock(ImplBlock<'a>),
     UseItem(UseItem<'a>),
     ExternCrateItem(ExternCrateItem<'a>),
     ConstDef(ConstDef<'a>),
@@ -2173,7 +2209,7 @@ fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
             FN_DEF => Some(ModuleItem::FnDef(FnDef { syntax })),
             TRAIT_DEF => Some(ModuleItem::TraitDef(TraitDef { syntax })),
             TYPE_DEF => Some(ModuleItem::TypeDef(TypeDef { syntax })),
-            IMPL_ITEM => Some(ModuleItem::ImplItem(ImplItem { syntax })),
+            IMPL_BLOCK => Some(ModuleItem::ImplBlock(ImplBlock { syntax })),
             USE_ITEM => Some(ModuleItem::UseItem(UseItem { syntax })),
             EXTERN_CRATE_ITEM => Some(ModuleItem::ExternCrateItem(ExternCrateItem { syntax })),
             CONST_DEF => Some(ModuleItem::ConstDef(ConstDef { syntax })),
@@ -2189,7 +2225,7 @@ fn syntax(self) -> SyntaxNodeRef<'a> {
             ModuleItem::FnDef(inner) => inner.syntax(),
             ModuleItem::TraitDef(inner) => inner.syntax(),
             ModuleItem::TypeDef(inner) => inner.syntax(),
-            ModuleItem::ImplItem(inner) => inner.syntax(),
+            ModuleItem::ImplBlock(inner) => inner.syntax(),
             ModuleItem::UseItem(inner) => inner.syntax(),
             ModuleItem::ExternCrateItem(inner) => inner.syntax(),
             ModuleItem::ConstDef(inner) => inner.syntax(),
@@ -3452,6 +3488,43 @@ pub fn expr(self) -> Option<Expr<'a>> {
     }
 }
 
+// SelfKw
+#[derive(Debug, Clone, Copy,)]
+pub struct SelfKwNode<R: TreeRoot<RaTypes> = OwnedRoot> {
+    pub(crate) syntax: SyntaxNode<R>,
+}
+pub type SelfKw<'a> = SelfKwNode<RefRoot<'a>>;
+
+impl<R1: TreeRoot<RaTypes>, R2: TreeRoot<RaTypes>> PartialEq<SelfKwNode<R1>> for SelfKwNode<R2> {
+    fn eq(&self, other: &SelfKwNode<R1>) -> bool { self.syntax == other.syntax }
+}
+impl<R: TreeRoot<RaTypes>> Eq for SelfKwNode<R> {}
+impl<R: TreeRoot<RaTypes>> Hash for SelfKwNode<R> {
+    fn hash<H: Hasher>(&self, state: &mut H) { self.syntax.hash(state) }
+}
+
+impl<'a> AstNode<'a> for SelfKw<'a> {
+    fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
+        match syntax.kind() {
+            SELF_KW => Some(SelfKw { syntax }),
+            _ => None,
+        }
+    }
+    fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
+}
+
+impl<R: TreeRoot<RaTypes>> SelfKwNode<R> {
+    pub fn borrowed(&self) -> SelfKw {
+        SelfKwNode { syntax: self.syntax.borrowed() }
+    }
+    pub fn owned(&self) -> SelfKwNode {
+        SelfKwNode { syntax: self.syntax.owned() }
+    }
+}
+
+
+impl<'a> SelfKw<'a> {}
+
 // SelfParam
 #[derive(Debug, Clone, Copy,)]
 pub struct SelfParamNode<R: TreeRoot<RaTypes> = OwnedRoot> {
@@ -3487,7 +3560,15 @@ pub fn owned(&self) -> SelfParamNode {
 }
 
 
-impl<'a> SelfParam<'a> {}
+impl<'a> SelfParam<'a> {
+    pub fn type_ref(self) -> Option<TypeRef<'a>> {
+        super::child_opt(self)
+    }
+
+    pub fn self_kw(self) -> Option<SelfKw<'a>> {
+        super::child_opt(self)
+    }
+}
 
 // SlicePat
 #[derive(Debug, Clone, Copy,)]
index 2abb9da61fd4ce0d406028ebaef9654cf1e4780f..c55e9e07a83b7ee88013a83201b106c3857cfa3c 100644 (file)
@@ -128,7 +128,7 @@ Grammar(
         "STATIC_DEF",
         "CONST_DEF",
         "TRAIT_DEF",
-        "IMPL_ITEM",
+        "IMPL_BLOCK",
         "TYPE_DEF",
         "MACRO_CALL",
         "TOKEN_TREE",
@@ -284,6 +284,7 @@ Grammar(
             options: [ "ItemList" ]
         ),
         "ItemList": (
+            collections: [["impl_items", "ImplItem"]],
             traits: [ "FnDefOwner", "ModuleItemOwner" ],
         ),
         "ConstDef": ( traits: [
@@ -307,7 +308,7 @@ Grammar(
             "AttrsOwner",
             "DocCommentsOwner"
         ] ),
-        "ImplItem": (),
+        "ImplBlock": (options: ["ItemList"]),
 
         "ParenType": (options: ["TypeRef"]),
         "TupleType": ( collections: [["fields", "TypeRef"]] ),
@@ -348,9 +349,12 @@ Grammar(
             ],
         ),
         "ModuleItem": (
-            enum: ["StructDef", "EnumDef", "FnDef", "TraitDef", "TypeDef", "ImplItem",
+            enum: ["StructDef", "EnumDef", "FnDef", "TraitDef", "TypeDef", "ImplBlock",
                    "UseItem", "ExternCrateItem", "ConstDef", "StaticDef", "Module" ]
         ),
+        "ImplItem": (
+            enum: ["FnDef", "TypeDef", "ConstDef"]
+        ),
 
         "TupleExpr": (),
         "ArrayExpr": (),
@@ -530,7 +534,8 @@ Grammar(
                 ["params", "Param"]
             ]
         ),
-        "SelfParam": (),
+        "SelfParam": (options: ["TypeRef", "SelfKw"]),
+        "SelfKw": (),
         "Param": (
             options: [ "Pat", "TypeRef" ],
         ),
index aa5fe0777215ee9605b06493c09c502cbf53957b..265e84570d519469a20a10315a0ac1db414fd02a 100644 (file)
@@ -151,8 +151,8 @@ pub(super) fn maybe_item(p: &mut Parser, flavor: ItemFlavor) -> MaybeItem {
         // test unsafe_default_impl
         // unsafe default impl Foo {}
         IMPL_KW => {
-            traits::impl_item(p);
-            IMPL_ITEM
+            traits::impl_block(p);
+            IMPL_BLOCK
         }
         _ => {
             return if has_mods {
index d4da8b2f7237c311f03214995737751e6a4eeb29..0a0621753fc189e9907f9a28f14a14c5cb4ef828 100644 (file)
@@ -40,9 +40,9 @@ pub(crate) fn trait_item_list(p: &mut Parser) {
     m.complete(p, ITEM_LIST);
 }
 
-// test impl_item
+// test impl_block
 // impl Foo {}
-pub(super) fn impl_item(p: &mut Parser) {
+pub(super) fn impl_block(p: &mut Parser) {
     assert!(p.at(IMPL_KW));
     p.bump();
     if choose_type_params_over_qpath(p) {
@@ -52,7 +52,7 @@ pub(super) fn impl_item(p: &mut Parser) {
     // TODO: never type
     // impl ! {}
 
-    // test impl_item_neg
+    // test impl_block_neg
     // impl !Send for X {}
     p.eat(EXCL);
     impl_type(p);
index 208cae5c8f85a23acc4c0ffe650f63135e9040fd..7ee71a1b6a57745f478ea6fde7e6ee6bd6f113e5 100644 (file)
@@ -100,7 +100,7 @@ fn reparser(node: SyntaxNodeRef) -> Option<ParseFn> {
             ITEM_LIST => {
                 let parent = node.parent().unwrap();
                 match parent.kind() {
-                    IMPL_ITEM => grammar::impl_item_list,
+                    IMPL_BLOCK => grammar::impl_item_list,
                     TRAIT_DEF => grammar::trait_item_list,
                     MODULE => grammar::mod_item_list,
                     _ => return None,
index 3a869ad34b386c61cbbf8d044f050fe0e2f64f26..ef4588d939724c1d5b40b1074dabecaecad7c2d8 100644 (file)
@@ -128,7 +128,7 @@ pub enum SyntaxKind {
     STATIC_DEF,
     CONST_DEF,
     TRAIT_DEF,
-    IMPL_ITEM,
+    IMPL_BLOCK,
     TYPE_DEF,
     MACRO_CALL,
     TOKEN_TREE,
@@ -389,7 +389,7 @@ pub(crate) fn info(self) -> &'static SyntaxInfo {
             STATIC_DEF => &SyntaxInfo { name: "STATIC_DEF" },
             CONST_DEF => &SyntaxInfo { name: "CONST_DEF" },
             TRAIT_DEF => &SyntaxInfo { name: "TRAIT_DEF" },
-            IMPL_ITEM => &SyntaxInfo { name: "IMPL_ITEM" },
+            IMPL_BLOCK => &SyntaxInfo { name: "IMPL_BLOCK" },
             TYPE_DEF => &SyntaxInfo { name: "TYPE_DEF" },
             MACRO_CALL => &SyntaxInfo { name: "MACRO_CALL" },
             TOKEN_TREE => &SyntaxInfo { name: "TOKEN_TREE" },
index 3937be2552128039a21dae26c567107fbc08e081..262cbba1e9bd93aeec646f356518241e9f318279 100644 (file)
@@ -1,5 +1,5 @@
 SOURCE_FILE@[0; 183)
-  IMPL_ITEM@[0; 182)
+  IMPL_BLOCK@[0; 182)
     IMPL_KW@[0; 4)
     WHITESPACE@[4; 5)
     PATH_TYPE@[5; 13)
index 55999c16095c54bea5d36cdb7566c9061f34e687..da3894133f9811efc04bbc13c3451cb7587efc12 100644 (file)
@@ -94,7 +94,7 @@ SOURCE_FILE@[0; 112)
           COMMA@[54; 55)
           err: `expected SEMI`
       WHITESPACE@[55; 56)
-      IMPL_ITEM@[56; 60)
+      IMPL_BLOCK@[56; 60)
         IMPL_KW@[56; 60)
         err: `expected type`
         err: `expected `{``
index 82683f6ee9eca523e3ea5c7f30d9514d91cea273..9b5fadcf7fb990d7bb3e6d32dcff4172cd305332 100644 (file)
@@ -1,5 +1,5 @@
 SOURCE_FILE@[0; 38)
-  IMPL_ITEM@[0; 14)
+  IMPL_BLOCK@[0; 14)
     IMPL_KW@[0; 4)
     TYPE_PARAM_LIST@[4; 14)
       L_ANGLE@[4; 5)
@@ -17,7 +17,7 @@ SOURCE_FILE@[0; 38)
       err: `expected trait or type`
       err: `expected `{``
   WHITESPACE@[14; 15)
-  IMPL_ITEM@[15; 37)
+  IMPL_BLOCK@[15; 37)
     IMPL_KW@[15; 19)
     TYPE_PARAM_LIST@[19; 22)
       L_ANGLE@[19; 20)
index 75533ecc18a903f211638fb92f59230bb89b6749..8021aee00b4efc9584272c7b9590605a366436a1 100644 (file)
@@ -19,7 +19,7 @@ SOURCE_FILE@[0; 30)
             err: `expected a loop`
             err: `expected SEMI`
       WHITESPACE@[22; 23)
-      IMPL_ITEM@[23; 27)
+      IMPL_BLOCK@[23; 27)
         IMPL_KW@[23; 27)
         err: `expected type`
         err: `expected `{``
index 7279d5cae4eefdc0de0bb28500b61a2ab995f7a7..6875ed016c54445318c12db268455822d0fbef01 100644 (file)
@@ -1,5 +1,5 @@
 SOURCE_FILE@[0; 87)
-  IMPL_ITEM@[0; 12)
+  IMPL_BLOCK@[0; 12)
     IMPL_KW@[0; 4)
     WHITESPACE@[4; 5)
     PATH_TYPE@[5; 9)
@@ -12,7 +12,7 @@ SOURCE_FILE@[0; 87)
       L_CURLY@[10; 11)
       R_CURLY@[11; 12)
   WHITESPACE@[12; 13)
-  IMPL_ITEM@[13; 33)
+  IMPL_BLOCK@[13; 33)
     IMPL_KW@[13; 17)
     WHITESPACE@[17; 18)
     PATH_TYPE@[18; 24)
@@ -33,12 +33,12 @@ SOURCE_FILE@[0; 87)
       L_CURLY@[31; 32)
       R_CURLY@[32; 33)
   WHITESPACE@[33; 34)
-  IMPL_ITEM@[34; 38)
+  IMPL_BLOCK@[34; 38)
     IMPL_KW@[34; 38)
     err: `expected trait or type`
     err: `expected `{``
   WHITESPACE@[38; 39)
-  IMPL_ITEM@[39; 54)
+  IMPL_BLOCK@[39; 54)
     IMPL_KW@[39; 43)
     WHITESPACE@[43; 44)
     PATH_TYPE@[44; 51)
@@ -51,7 +51,7 @@ SOURCE_FILE@[0; 87)
       L_CURLY@[52; 53)
       R_CURLY@[53; 54)
   WHITESPACE@[54; 55)
-  IMPL_ITEM@[55; 70)
+  IMPL_BLOCK@[55; 70)
     IMPL_KW@[55; 59)
     WHITESPACE@[59; 60)
     PATH_TYPE@[60; 66)
@@ -64,7 +64,7 @@ SOURCE_FILE@[0; 87)
     err: `expected trait or type`
     err: `expected `{``
   WHITESPACE@[70; 71)
-  IMPL_ITEM@[71; 86)
+  IMPL_BLOCK@[71; 86)
     IMPL_KW@[71; 75)
     WHITESPACE@[75; 76)
     PATH_TYPE@[76; 83)
index 998ac3da9efbbfb66da22ae721c20df7f2a0211b..de7df73122e8e2668fea78d893c46f89c745bd85 100644 (file)
@@ -1,5 +1,5 @@
 SOURCE_FILE@[0; 83)
-  IMPL_ITEM@[0; 82)
+  IMPL_BLOCK@[0; 82)
     IMPL_KW@[0; 4)
     WHITESPACE@[4; 5)
     PATH_TYPE@[5; 6)
index 53027c852da858feb1430266f746a7086f43658c..4df01c6e5c6a9715513ba0247ac71f9686e8b48f 100644 (file)
@@ -1,5 +1,5 @@
 SOURCE_FILE@[0; 128)
-  IMPL_ITEM@[0; 127)
+  IMPL_BLOCK@[0; 127)
     IMPL_KW@[0; 4)
     WHITESPACE@[4; 5)
     PATH_TYPE@[5; 6)
index b2f04ea7bbb74048ccbca1e8a5f121a99f6fa032..03139f7a4939e8ab66c01484b3616edee8448cb6 100644 (file)
@@ -1,5 +1,5 @@
 SOURCE_FILE@[0; 69)
-  IMPL_ITEM@[0; 68)
+  IMPL_BLOCK@[0; 68)
     IMPL_KW@[0; 4)
     WHITESPACE@[4; 5)
     PATH_TYPE@[5; 6)
index b15f93cd2a889efd4fdb5911243c276a0278b045..50426bdfec34997e8d035037d2ef3716867ce769 100644 (file)
@@ -1,5 +1,5 @@
 SOURCE_FILE@[0; 89)
-  IMPL_ITEM@[0; 88)
+  IMPL_BLOCK@[0; 88)
     IMPL_KW@[0; 4)
     WHITESPACE@[4; 5)
     PATH_TYPE@[5; 6)
index 6003ba645be87bbc0537922dacb6f1dea7cf892c..5d68e88d6fc74c65571805eb07fd0c0ffcf1937f 100644 (file)
@@ -1,5 +1,5 @@
 SOURCE_FILE@[0; 27)
-  IMPL_ITEM@[0; 26)
+  IMPL_BLOCK@[0; 26)
     UNSAFE_KW@[0; 6)
     WHITESPACE@[6; 7)
     DEFAULT_KW@[7; 14)
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0063_impl_block_neg.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0063_impl_block_neg.rs
new file mode 100644 (file)
index 0000000..b7527c8
--- /dev/null
@@ -0,0 +1 @@
+impl !Send for X {}
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0063_impl_block_neg.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0063_impl_block_neg.txt
new file mode 100644 (file)
index 0000000..563e435
--- /dev/null
@@ -0,0 +1,23 @@
+SOURCE_FILE@[0; 20)
+  IMPL_BLOCK@[0; 19)
+    IMPL_KW@[0; 4)
+    WHITESPACE@[4; 5)
+    EXCL@[5; 6)
+    PATH_TYPE@[6; 10)
+      PATH@[6; 10)
+        PATH_SEGMENT@[6; 10)
+          NAME_REF@[6; 10)
+            IDENT@[6; 10) "Send"
+    WHITESPACE@[10; 11)
+    FOR_KW@[11; 14)
+    WHITESPACE@[14; 15)
+    PATH_TYPE@[15; 16)
+      PATH@[15; 16)
+        PATH_SEGMENT@[15; 16)
+          NAME_REF@[15; 16)
+            IDENT@[15; 16) "X"
+    WHITESPACE@[16; 17)
+    ITEM_LIST@[17; 19)
+      L_CURLY@[17; 18)
+      R_CURLY@[18; 19)
+  WHITESPACE@[19; 20)
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0063_impl_item_neg.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0063_impl_item_neg.rs
deleted file mode 100644 (file)
index b7527c8..0000000
+++ /dev/null
@@ -1 +0,0 @@
-impl !Send for X {}
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0063_impl_item_neg.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0063_impl_item_neg.txt
deleted file mode 100644 (file)
index b83db38..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-SOURCE_FILE@[0; 20)
-  IMPL_ITEM@[0; 19)
-    IMPL_KW@[0; 4)
-    WHITESPACE@[4; 5)
-    EXCL@[5; 6)
-    PATH_TYPE@[6; 10)
-      PATH@[6; 10)
-        PATH_SEGMENT@[6; 10)
-          NAME_REF@[6; 10)
-            IDENT@[6; 10) "Send"
-    WHITESPACE@[10; 11)
-    FOR_KW@[11; 14)
-    WHITESPACE@[14; 15)
-    PATH_TYPE@[15; 16)
-      PATH@[15; 16)
-        PATH_SEGMENT@[15; 16)
-          NAME_REF@[15; 16)
-            IDENT@[15; 16) "X"
-    WHITESPACE@[16; 17)
-    ITEM_LIST@[17; 19)
-      L_CURLY@[17; 18)
-      R_CURLY@[18; 19)
-  WHITESPACE@[19; 20)
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0079_impl_block.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0079_impl_block.rs
new file mode 100644 (file)
index 0000000..d6337f6
--- /dev/null
@@ -0,0 +1 @@
+impl Foo {}
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0079_impl_block.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0079_impl_block.txt
new file mode 100644 (file)
index 0000000..a2c218a
--- /dev/null
@@ -0,0 +1,14 @@
+SOURCE_FILE@[0; 12)
+  IMPL_BLOCK@[0; 11)
+    IMPL_KW@[0; 4)
+    WHITESPACE@[4; 5)
+    PATH_TYPE@[5; 8)
+      PATH@[5; 8)
+        PATH_SEGMENT@[5; 8)
+          NAME_REF@[5; 8)
+            IDENT@[5; 8) "Foo"
+    WHITESPACE@[8; 9)
+    ITEM_LIST@[9; 11)
+      L_CURLY@[9; 10)
+      R_CURLY@[10; 11)
+  WHITESPACE@[11; 12)
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0079_impl_item.rs b/crates/ra_syntax/tests/data/parser/inline/ok/0079_impl_item.rs
deleted file mode 100644 (file)
index d6337f6..0000000
+++ /dev/null
@@ -1 +0,0 @@
-impl Foo {}
diff --git a/crates/ra_syntax/tests/data/parser/inline/ok/0079_impl_item.txt b/crates/ra_syntax/tests/data/parser/inline/ok/0079_impl_item.txt
deleted file mode 100644 (file)
index 1b9a8aa..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-SOURCE_FILE@[0; 12)
-  IMPL_ITEM@[0; 11)
-    IMPL_KW@[0; 4)
-    WHITESPACE@[4; 5)
-    PATH_TYPE@[5; 8)
-      PATH@[5; 8)
-        PATH_SEGMENT@[5; 8)
-          NAME_REF@[5; 8)
-            IDENT@[5; 8) "Foo"
-    WHITESPACE@[8; 9)
-    ITEM_LIST@[9; 11)
-      L_CURLY@[9; 10)
-      R_CURLY@[10; 11)
-  WHITESPACE@[11; 12)
index f9c96c2429da186dde670a0b42fe71a161c4725b..d93c0df4d1bacd678bf77364ef38239c82a16197 100644 (file)
@@ -1,5 +1,5 @@
 SOURCE_FILE@[0; 19)
-  IMPL_ITEM@[0; 18)
+  IMPL_BLOCK@[0; 18)
     UNSAFE_KW@[0; 6)
     WHITESPACE@[6; 7)
     IMPL_KW@[7; 11)
index f45b6251fa8e8d0cb0e16ed8eaf95dfbf5ce6057..0b9af800bd544e9f584ba2d24216552ab1eee1c9 100644 (file)
@@ -1,5 +1,5 @@
 SOURCE_FILE@[0; 20)
-  IMPL_ITEM@[0; 19)
+  IMPL_BLOCK@[0; 19)
     DEFAULT_KW@[0; 7)
     WHITESPACE@[7; 8)
     IMPL_KW@[8; 12)
index e11c4a06df8d85dadae1f5290b42201d46a5f5f5..f8a20ac53fcb68ff9635c8853acc8d68c9ff8dd5 100644 (file)
@@ -14,4 +14,3 @@ SOURCE_FILE@[0; 93)
     ITEM_LIST@[91; 93)
       L_CURLY@[91; 92)
       R_CURLY@[92; 93)
-