]> git.lizzy.rs Git - rust.git/commitdiff
Enable Chalk tracing in hir_ty tests
authorFlorian Diebold <florian.diebold@freiheit.com>
Fri, 10 Jul 2020 16:30:32 +0000 (18:30 +0200)
committerFlorian Diebold <flodiebold@gmail.com>
Sun, 12 Jul 2020 18:12:01 +0000 (20:12 +0200)
Cargo.lock
crates/ra_hir_ty/Cargo.toml
crates/ra_hir_ty/src/tests.rs
crates/ra_hir_ty/src/tests/traits.rs
crates/ra_hir_ty/src/traits/chalk.rs
crates/ra_hir_ty/src/traits/chalk/mapping.rs

index d6635640f707c03c4ef13bdca027444230f31629..8085f29d79ab61dd30646d3a4cee6116cf20f291 100644 (file)
@@ -33,6 +33,15 @@ dependencies = [
  "winapi 0.3.9",
 ]
 
+[[package]]
+name = "ansi_term"
+version = "0.12.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
+dependencies = [
+ "winapi 0.3.9",
+]
+
 [[package]]
 name = "anyhow"
 version = "1.0.31"
@@ -51,6 +60,17 @@ version = "0.5.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"
 
+[[package]]
+name = "atty"
+version = "0.2.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
+dependencies = [
+ "hermit-abi",
+ "libc",
+ "winapi 0.3.9",
+]
+
 [[package]]
 name = "autocfg"
 version = "1.0.0"
@@ -971,6 +991,16 @@ dependencies = [
  "unicode-xid",
 ]
 
+[[package]]
+name = "quanta"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f4f7a1905379198075914bc93d32a5465c40474f90a078bb13439cb00c547bcc"
+dependencies = [
+ "libc",
+ "winapi 0.3.9",
+]
+
 [[package]]
 name = "quote"
 version = "1.0.7"
@@ -1120,6 +1150,9 @@ dependencies = [
  "smallvec",
  "stdx",
  "test_utils",
+ "tracing",
+ "tracing-subscriber",
+ "tracing-tree",
 ]
 
 [[package]]
@@ -1722,6 +1755,15 @@ dependencies = [
  "winapi 0.3.9",
 ]
 
+[[package]]
+name = "termcolor"
+version = "1.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bb6bfa289a4d7c5766392812c0a1f4c1ba45afa1ad47803c11e1f407d846d75f"
+dependencies = [
+ "winapi-util",
+]
+
 [[package]]
 name = "terminal_size"
 version = "0.1.13"
@@ -1856,7 +1898,7 @@ version = "0.2.7"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "c72c8cf3ec4ed69fef614d011a5ae4274537a8a8c59133558029bd731eb71659"
 dependencies = [
- "ansi_term",
+ "ansi_term 0.11.0",
  "chrono",
  "lazy_static",
  "matchers",
@@ -1870,6 +1912,21 @@ dependencies = [
  "tracing-serde",
 ]
 
+[[package]]
+name = "tracing-tree"
+version = "0.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e0a389731c9e6c56fef11e438e5b6afae861d5bc301c8b4bdca8d19f0e830d82"
+dependencies = [
+ "ansi_term 0.12.1",
+ "atty",
+ "chrono",
+ "quanta",
+ "termcolor",
+ "tracing",
+ "tracing-subscriber",
+]
+
 [[package]]
 name = "unicode-bidi"
 version = "0.3.4"
index ce257dc0bb58d6d295261d6fda9c297139e06090..3370230a18c5843ab4464002bb96955467f75655 100644 (file)
@@ -33,3 +33,7 @@ chalk-ir = { version = "0.15.0" }
 [dev-dependencies]
 insta = "0.16.0"
 expect = { path = "../expect" }
+
+tracing = "0.1"
+tracing-subscriber = { version = "0.2", default-features = false, features = ["env-filter", "registry"] }
+tracing-tree = { version = "0.1.3" }
index 69f2d7667eec750bab4bcec3162e58e6da97b736..27f5a60bf6edbea68ffaed2db09cbbe9e7d7e91e 100644 (file)
 // against snapshots of the expected results using insta. Use cargo-insta to
 // update the snapshots.
 
+fn setup_tracing() -> tracing::subscriber::DefaultGuard {
+    use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry};
+    use tracing_tree::HierarchicalLayer;
+    let filter = EnvFilter::from_env("CHALK_DEBUG");
+    let layer = HierarchicalLayer::default().with_indent_amount(2).with_writer(std::io::stderr);
+    let subscriber = Registry::default().with(filter).with(layer);
+    tracing::subscriber::set_default(subscriber)
+}
+
 fn check_types(ra_fixture: &str) {
     check_types_impl(ra_fixture, false)
 }
@@ -46,6 +55,7 @@ fn check_types_source_code(ra_fixture: &str) {
 }
 
 fn check_types_impl(ra_fixture: &str, display_source: bool) {
+    let _tracing = setup_tracing();
     let db = TestDB::with_files(ra_fixture);
     let mut checked_one = false;
     for (file_id, annotations) in db.extract_annotations() {
@@ -86,6 +96,7 @@ fn infer(ra_fixture: &str) -> String {
 }
 
 fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
+    let _tracing = setup_tracing();
     let (db, file_id) = TestDB::with_single_file(content);
 
     let mut buf = String::new();
index 529d9e253e7a4aa23a8782a2e23a82560d54ef1c..85bcd00504fa6a4920d56720c1525541846cb286 100644 (file)
@@ -3000,69 +3000,44 @@ fn foo() {
 
 #[test]
 fn infer_dyn_fn_output() {
-    assert_snapshot!(
-        infer(
-            r#"
-            //- /lib.rs deps:std
-
-            #[lang = "fn_once"]
-            pub trait FnOnce<Args> {
-                type Output;
-
-                extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
-            }
-
-            #[lang = "fn"]
-            pub trait Fn<Args>:FnOnce<Args> {
-                extern "rust-call" fn call(&self, args: Args) -> Self::Output;
-            }
-
-            #[lang = "deref"]
-            pub trait Deref {
-                type Target: ?Sized;
-
-                fn deref(&self) -> &Self::Target;
-            }
+    check_types(
+        r#"
+//- /lib.rs
+#[lang = "fn_once"]
+pub trait FnOnce<Args> {
+    type Output;
+    extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
+}
 
-            #[lang = "owned_box"]
-            pub struct Box<T: ?Sized> {
-                inner: *mut T,
-            }
+#[lang = "fn"]
+pub trait Fn<Args>: FnOnce<Args> {
+    extern "rust-call" fn call(&self, args: Args) -> Self::Output;
+}
 
-            impl<T: ?Sized> Deref for Box<T> {
-                type Target = T;
+fn foo() {
+    let f: &dyn Fn() -> i32;
+    f();
+  //^^^ i32
+}"#,
+    );
+}
 
-                fn deref(&self) -> &T {
-                    &self.inner
-                }
-            }
+#[test]
+fn infer_dyn_fn_once_output() {
+    check_types(
+        r#"
+//- /lib.rs
+#[lang = "fn_once"]
+pub trait FnOnce<Args> {
+    type Output;
+    extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
+}
 
-            fn foo() {
-                let f: Box<dyn Fn() -> i32> = box(|| 5);
-                let x = f();
-            }
-        "#
-        ),
-        @r###"
-    100..104 'self': Self
-    106..110 'args': Args
-    219..223 'self': &Self
-    225..229 'args': Args
-    333..337 'self': &Self
-    503..507 'self': &Box<T>
-    515..542 '{     ...     }': &T
-    525..536 '&self.inner': &*mut T
-    526..530 'self': &Box<T>
-    526..536 'self.inner': *mut T
-    555..620 '{     ...f(); }': ()
-    565..566 'f': Box<dyn Fn<(), Output = i32>>
-    591..600 'box(|| 5)': Box<|| -> i32>
-    595..599 '|| 5': || -> i32
-    598..599 '5': i32
-    610..611 'x': FnOnce::Output<dyn Fn<(), Output = i32>, ()>
-    614..615 'f': Box<dyn Fn<(), Output = i32>>
-    614..617 'f()': FnOnce::Output<dyn Fn<(), Output = i32>, ()>
-    "###
+fn foo() {
+    let f: dyn FnOnce() -> i32;
+    f();
+  //^^^ i32
+}"#,
     );
 }
 
index a9b39474ad89f1f7b9a250023b79c84706bfcf2f..e944c19768190dbb4918fd16feb415cda2661703 100644 (file)
@@ -3,7 +3,7 @@
 
 use log::debug;
 
-use chalk_ir::{fold::shift::Shift, GenericArg, TypeName, CanonicalVarKinds};
+use chalk_ir::{fold::shift::Shift, CanonicalVarKinds, GenericArg, TypeName};
 use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait};
 
 use hir_def::{
@@ -377,16 +377,13 @@ pub(crate) fn struct_datum_query(
     let variant = rust_ir::AdtVariantDatum {
         fields: Vec::new(), // FIXME add fields (only relevant for auto traits),
     };
-    let struct_datum_bound = rust_ir::AdtDatumBound {
-        variants: vec![variant],
-        where_clauses,
-    };
+    let struct_datum_bound = rust_ir::AdtDatumBound { variants: vec![variant], where_clauses };
     let struct_datum = StructDatum {
         // FIXME set ADT kind
         kind: rust_ir::AdtKind::Struct,
         id: struct_id,
         binders: make_binders(struct_datum_bound, num_params),
-        flags
+        flags,
     };
     Arc::new(struct_datum)
 }
index bc0c6de176f07ec4ad4bd3b5c02e4b14c92bdcf1..848cb6e7dbc3dca648a43e00f0076d4f45449eef 100644 (file)
@@ -575,7 +575,10 @@ fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Canonical<T::Chalk> {
                 )
             });
         let value = self.value.to_chalk(db);
-        chalk_ir::Canonical { value, binders: chalk_ir::CanonicalVarKinds::from_iter(&Interner, kinds) }
+        chalk_ir::Canonical {
+            value,
+            binders: chalk_ir::CanonicalVarKinds::from_iter(&Interner, kinds),
+        }
     }
 
     fn from_chalk(db: &dyn HirDatabase, canonical: chalk_ir::Canonical<T::Chalk>) -> Canonical<T> {