aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2020-07-10 17:30:32 +0100
committerFlorian Diebold <[email protected]>2020-07-12 19:12:01 +0100
commitc82f5379de49344eb418cc6aaf5bf8c35bc4aaef (patch)
tree7c060a12fcdb8cbd2054e064257602374c3df0cb
parent209c492432c15b017f99dba06d5937389c1f9546 (diff)
Enable Chalk tracing in hir_ty tests
-rw-r--r--Cargo.lock59
-rw-r--r--crates/ra_hir_ty/Cargo.toml4
-rw-r--r--crates/ra_hir_ty/src/tests.rs11
-rw-r--r--crates/ra_hir_ty/src/tests/traits.rs93
-rw-r--r--crates/ra_hir_ty/src/traits/chalk.rs9
-rw-r--r--crates/ra_hir_ty/src/traits/chalk/mapping.rs5
6 files changed, 114 insertions, 67 deletions
diff --git a/Cargo.lock b/Cargo.lock
index d6635640f..8085f29d7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -34,6 +34,15 @@ dependencies = [
34] 34]
35 35
36[[package]] 36[[package]]
37name = "ansi_term"
38version = "0.12.1"
39source = "registry+https://github.com/rust-lang/crates.io-index"
40checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
41dependencies = [
42 "winapi 0.3.9",
43]
44
45[[package]]
37name = "anyhow" 46name = "anyhow"
38version = "1.0.31" 47version = "1.0.31"
39source = "registry+https://github.com/rust-lang/crates.io-index" 48source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -52,6 +61,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
52checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" 61checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"
53 62
54[[package]] 63[[package]]
64name = "atty"
65version = "0.2.14"
66source = "registry+https://github.com/rust-lang/crates.io-index"
67checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
68dependencies = [
69 "hermit-abi",
70 "libc",
71 "winapi 0.3.9",
72]
73
74[[package]]
55name = "autocfg" 75name = "autocfg"
56version = "1.0.0" 76version = "1.0.0"
57source = "registry+https://github.com/rust-lang/crates.io-index" 77source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -972,6 +992,16 @@ dependencies = [
972] 992]
973 993
974[[package]] 994[[package]]
995name = "quanta"
996version = "0.3.1"
997source = "registry+https://github.com/rust-lang/crates.io-index"
998checksum = "f4f7a1905379198075914bc93d32a5465c40474f90a078bb13439cb00c547bcc"
999dependencies = [
1000 "libc",
1001 "winapi 0.3.9",
1002]
1003
1004[[package]]
975name = "quote" 1005name = "quote"
976version = "1.0.7" 1006version = "1.0.7"
977source = "registry+https://github.com/rust-lang/crates.io-index" 1007source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1120,6 +1150,9 @@ dependencies = [
1120 "smallvec", 1150 "smallvec",
1121 "stdx", 1151 "stdx",
1122 "test_utils", 1152 "test_utils",
1153 "tracing",
1154 "tracing-subscriber",
1155 "tracing-tree",
1123] 1156]
1124 1157
1125[[package]] 1158[[package]]
@@ -1723,6 +1756,15 @@ dependencies = [
1723] 1756]
1724 1757
1725[[package]] 1758[[package]]
1759name = "termcolor"
1760version = "1.1.0"
1761source = "registry+https://github.com/rust-lang/crates.io-index"
1762checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f"
1763dependencies = [
1764 "winapi-util",
1765]
1766
1767[[package]]
1726name = "terminal_size" 1768name = "terminal_size"
1727version = "0.1.13" 1769version = "0.1.13"
1728source = "registry+https://github.com/rust-lang/crates.io-index" 1770source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1856,7 +1898,7 @@ version = "0.2.7"
1856source = "registry+https://github.com/rust-lang/crates.io-index" 1898source = "registry+https://github.com/rust-lang/crates.io-index"
1857checksum = "c72c8cf3ec4ed69fef614d011a5ae4274537a8a8c59133558029bd731eb71659" 1899checksum = "c72c8cf3ec4ed69fef614d011a5ae4274537a8a8c59133558029bd731eb71659"
1858dependencies = [ 1900dependencies = [
1859 "ansi_term", 1901 "ansi_term 0.11.0",
1860 "chrono", 1902 "chrono",
1861 "lazy_static", 1903 "lazy_static",
1862 "matchers", 1904 "matchers",
@@ -1871,6 +1913,21 @@ dependencies = [
1871] 1913]
1872 1914
1873[[package]] 1915[[package]]
1916name = "tracing-tree"
1917version = "0.1.3"
1918source = "registry+https://github.com/rust-lang/crates.io-index"
1919checksum = "e0a389731c9e6c56fef11e438e5b6afae861d5bc301c8b4bdca8d19f0e830d82"
1920dependencies = [
1921 "ansi_term 0.12.1",
1922 "atty",
1923 "chrono",
1924 "quanta",
1925 "termcolor",
1926 "tracing",
1927 "tracing-subscriber",
1928]
1929
1930[[package]]
1874name = "unicode-bidi" 1931name = "unicode-bidi"
1875version = "0.3.4" 1932version = "0.3.4"
1876source = "registry+https://github.com/rust-lang/crates.io-index" 1933source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/crates/ra_hir_ty/Cargo.toml b/crates/ra_hir_ty/Cargo.toml
index ce257dc0b..3370230a1 100644
--- a/crates/ra_hir_ty/Cargo.toml
+++ b/crates/ra_hir_ty/Cargo.toml
@@ -33,3 +33,7 @@ chalk-ir = { version = "0.15.0" }
33[dev-dependencies] 33[dev-dependencies]
34insta = "0.16.0" 34insta = "0.16.0"
35expect = { path = "../expect" } 35expect = { path = "../expect" }
36
37tracing = "0.1"
38tracing-subscriber = { version = "0.2", default-features = false, features = ["env-filter", "registry"] }
39tracing-tree = { version = "0.1.3" }
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs
index 69f2d7667..27f5a60bf 100644
--- a/crates/ra_hir_ty/src/tests.rs
+++ b/crates/ra_hir_ty/src/tests.rs
@@ -37,6 +37,15 @@ use crate::{
37// against snapshots of the expected results using insta. Use cargo-insta to 37// against snapshots of the expected results using insta. Use cargo-insta to
38// update the snapshots. 38// update the snapshots.
39 39
40fn setup_tracing() -> tracing::subscriber::DefaultGuard {
41 use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry};
42 use tracing_tree::HierarchicalLayer;
43 let filter = EnvFilter::from_env("CHALK_DEBUG");
44 let layer = HierarchicalLayer::default().with_indent_amount(2).with_writer(std::io::stderr);
45 let subscriber = Registry::default().with(filter).with(layer);
46 tracing::subscriber::set_default(subscriber)
47}
48
40fn check_types(ra_fixture: &str) { 49fn check_types(ra_fixture: &str) {
41 check_types_impl(ra_fixture, false) 50 check_types_impl(ra_fixture, false)
42} 51}
@@ -46,6 +55,7 @@ fn check_types_source_code(ra_fixture: &str) {
46} 55}
47 56
48fn check_types_impl(ra_fixture: &str, display_source: bool) { 57fn check_types_impl(ra_fixture: &str, display_source: bool) {
58 let _tracing = setup_tracing();
49 let db = TestDB::with_files(ra_fixture); 59 let db = TestDB::with_files(ra_fixture);
50 let mut checked_one = false; 60 let mut checked_one = false;
51 for (file_id, annotations) in db.extract_annotations() { 61 for (file_id, annotations) in db.extract_annotations() {
@@ -86,6 +96,7 @@ fn infer(ra_fixture: &str) -> String {
86} 96}
87 97
88fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { 98fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
99 let _tracing = setup_tracing();
89 let (db, file_id) = TestDB::with_single_file(content); 100 let (db, file_id) = TestDB::with_single_file(content);
90 101
91 let mut buf = String::new(); 102 let mut buf = String::new();
diff --git a/crates/ra_hir_ty/src/tests/traits.rs b/crates/ra_hir_ty/src/tests/traits.rs
index 529d9e253..85bcd0050 100644
--- a/crates/ra_hir_ty/src/tests/traits.rs
+++ b/crates/ra_hir_ty/src/tests/traits.rs
@@ -3000,69 +3000,44 @@ fn infer_box_fn_arg() {
3000 3000
3001#[test] 3001#[test]
3002fn infer_dyn_fn_output() { 3002fn infer_dyn_fn_output() {
3003 assert_snapshot!( 3003 check_types(
3004 infer( 3004 r#"
3005 r#" 3005//- /lib.rs
3006 //- /lib.rs deps:std 3006#[lang = "fn_once"]
3007 3007pub trait FnOnce<Args> {
3008 #[lang = "fn_once"] 3008 type Output;
3009 pub trait FnOnce<Args> { 3009 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3010 type Output; 3010}
3011
3012 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3013 }
3014
3015 #[lang = "fn"]
3016 pub trait Fn<Args>:FnOnce<Args> {
3017 extern "rust-call" fn call(&self, args: Args) -> Self::Output;
3018 }
3019
3020 #[lang = "deref"]
3021 pub trait Deref {
3022 type Target: ?Sized;
3023
3024 fn deref(&self) -> &Self::Target;
3025 }
3026 3011
3027 #[lang = "owned_box"] 3012#[lang = "fn"]
3028 pub struct Box<T: ?Sized> { 3013pub trait Fn<Args>: FnOnce<Args> {
3029 inner: *mut T, 3014 extern "rust-call" fn call(&self, args: Args) -> Self::Output;
3030 } 3015}
3031 3016
3032 impl<T: ?Sized> Deref for Box<T> { 3017fn foo() {
3033 type Target = T; 3018 let f: &dyn Fn() -> i32;
3019 f();
3020 //^^^ i32
3021}"#,
3022 );
3023}
3034 3024
3035 fn deref(&self) -> &T { 3025#[test]
3036 &self.inner 3026fn infer_dyn_fn_once_output() {
3037 } 3027 check_types(
3038 } 3028 r#"
3029//- /lib.rs
3030#[lang = "fn_once"]
3031pub trait FnOnce<Args> {
3032 type Output;
3033 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
3034}
3039 3035
3040 fn foo() { 3036fn foo() {
3041 let f: Box<dyn Fn() -> i32> = box(|| 5); 3037 let f: dyn FnOnce() -> i32;
3042 let x = f(); 3038 f();
3043 } 3039 //^^^ i32
3044 "# 3040}"#,
3045 ),
3046 @r###"
3047 100..104 'self': Self
3048 106..110 'args': Args
3049 219..223 'self': &Self
3050 225..229 'args': Args
3051 333..337 'self': &Self
3052 503..507 'self': &Box<T>
3053 515..542 '{ ... }': &T
3054 525..536 '&self.inner': &*mut T
3055 526..530 'self': &Box<T>
3056 526..536 'self.inner': *mut T
3057 555..620 '{ ...f(); }': ()
3058 565..566 'f': Box<dyn Fn<(), Output = i32>>
3059 591..600 'box(|| 5)': Box<|| -> i32>
3060 595..599 '|| 5': || -> i32
3061 598..599 '5': i32
3062 610..611 'x': FnOnce::Output<dyn Fn<(), Output = i32>, ()>
3063 614..615 'f': Box<dyn Fn<(), Output = i32>>
3064 614..617 'f()': FnOnce::Output<dyn Fn<(), Output = i32>, ()>
3065 "###
3066 ); 3041 );
3067} 3042}
3068 3043
diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs
index a9b39474a..e944c1976 100644
--- a/crates/ra_hir_ty/src/traits/chalk.rs
+++ b/crates/ra_hir_ty/src/traits/chalk.rs
@@ -3,7 +3,7 @@ use std::sync::Arc;
3 3
4use log::debug; 4use log::debug;
5 5
6use chalk_ir::{fold::shift::Shift, GenericArg, TypeName, CanonicalVarKinds}; 6use chalk_ir::{fold::shift::Shift, CanonicalVarKinds, GenericArg, TypeName};
7use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait}; 7use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait};
8 8
9use hir_def::{ 9use hir_def::{
@@ -377,16 +377,13 @@ pub(crate) fn struct_datum_query(
377 let variant = rust_ir::AdtVariantDatum { 377 let variant = rust_ir::AdtVariantDatum {
378 fields: Vec::new(), // FIXME add fields (only relevant for auto traits), 378 fields: Vec::new(), // FIXME add fields (only relevant for auto traits),
379 }; 379 };
380 let struct_datum_bound = rust_ir::AdtDatumBound { 380 let struct_datum_bound = rust_ir::AdtDatumBound { variants: vec![variant], where_clauses };
381 variants: vec![variant],
382 where_clauses,
383 };
384 let struct_datum = StructDatum { 381 let struct_datum = StructDatum {
385 // FIXME set ADT kind 382 // FIXME set ADT kind
386 kind: rust_ir::AdtKind::Struct, 383 kind: rust_ir::AdtKind::Struct,
387 id: struct_id, 384 id: struct_id,
388 binders: make_binders(struct_datum_bound, num_params), 385 binders: make_binders(struct_datum_bound, num_params),
389 flags 386 flags,
390 }; 387 };
391 Arc::new(struct_datum) 388 Arc::new(struct_datum)
392} 389}
diff --git a/crates/ra_hir_ty/src/traits/chalk/mapping.rs b/crates/ra_hir_ty/src/traits/chalk/mapping.rs
index bc0c6de17..848cb6e7d 100644
--- a/crates/ra_hir_ty/src/traits/chalk/mapping.rs
+++ b/crates/ra_hir_ty/src/traits/chalk/mapping.rs
@@ -575,7 +575,10 @@ where
575 ) 575 )
576 }); 576 });
577 let value = self.value.to_chalk(db); 577 let value = self.value.to_chalk(db);
578 chalk_ir::Canonical { value, binders: chalk_ir::CanonicalVarKinds::from_iter(&Interner, kinds) } 578 chalk_ir::Canonical {
579 value,
580 binders: chalk_ir::CanonicalVarKinds::from_iter(&Interner, kinds),
581 }
579 } 582 }
580 583
581 fn from_chalk(db: &dyn HirDatabase, canonical: chalk_ir::Canonical<T::Chalk>) -> Canonical<T> { 584 fn from_chalk(db: &dyn HirDatabase, canonical: chalk_ir::Canonical<T::Chalk>) -> Canonical<T> {