From c82f5379de49344eb418cc6aaf5bf8c35bc4aaef Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Fri, 10 Jul 2020 18:30:32 +0200 Subject: Enable Chalk tracing in hir_ty tests --- Cargo.lock | 59 +++++++++++++++++- crates/ra_hir_ty/Cargo.toml | 4 ++ crates/ra_hir_ty/src/tests.rs | 11 ++++ crates/ra_hir_ty/src/tests/traits.rs | 93 ++++++++++------------------ crates/ra_hir_ty/src/traits/chalk.rs | 9 +-- crates/ra_hir_ty/src/traits/chalk/mapping.rs | 5 +- 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 @@ -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" 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" } [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" } 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::{ // 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(); 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() { #[test] fn infer_dyn_fn_output() { - assert_snapshot!( - infer( - r#" - //- /lib.rs deps:std - - #[lang = "fn_once"] - pub trait FnOnce { - type Output; - - extern "rust-call" fn call_once(self, args: Args) -> Self::Output; - } - - #[lang = "fn"] - pub trait Fn:FnOnce { - 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 { + type Output; + extern "rust-call" fn call_once(self, args: Args) -> Self::Output; +} - #[lang = "owned_box"] - pub struct Box { - inner: *mut T, - } +#[lang = "fn"] +pub trait Fn: FnOnce { + extern "rust-call" fn call(&self, args: Args) -> Self::Output; +} - impl Deref for Box { - 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 { + type Output; + extern "rust-call" fn call_once(self, args: Args) -> Self::Output; +} - fn foo() { - let f: Box 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 - 515..542 '{ ... }': &T - 525..536 '&self.inner': &*mut T - 526..530 'self': &Box - 526..536 'self.inner': *mut T - 555..620 '{ ...f(); }': () - 565..566 'f': Box> - 591..600 'box(|| 5)': Box<|| -> i32> - 595..599 '|| 5': || -> i32 - 598..599 '5': i32 - 610..611 'x': FnOnce::Output, ()> - 614..615 'f': Box> - 614..617 'f()': FnOnce::Output, ()> - "### +fn foo() { + let f: dyn FnOnce() -> i32; + f(); + //^^^ i32 +}"#, ); } 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; 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) } 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 ) }); 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) -> Canonical { -- cgit v1.2.3