diff options
Diffstat (limited to 'crates/ra_hir_ty')
-rw-r--r-- | crates/ra_hir_ty/Cargo.toml | 4 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests.rs | 11 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/traits.rs | 93 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/traits/chalk.rs | 9 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/traits/chalk/mapping.rs | 5 |
5 files changed, 56 insertions, 66 deletions
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] |
34 | insta = "0.16.0" | 34 | insta = "0.16.0" |
35 | expect = { path = "../expect" } | 35 | expect = { path = "../expect" } |
36 | |||
37 | tracing = "0.1" | ||
38 | tracing-subscriber = { version = "0.2", default-features = false, features = ["env-filter", "registry"] } | ||
39 | 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::{ | |||
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 | ||
40 | fn 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 | |||
40 | fn check_types(ra_fixture: &str) { | 49 | fn 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 | ||
48 | fn check_types_impl(ra_fixture: &str, display_source: bool) { | 57 | fn 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 | ||
88 | fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { | 98 | fn 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] |
3002 | fn infer_dyn_fn_output() { | 3002 | fn 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 | 3007 | pub 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> { | 3013 | pub 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> { | 3017 | fn 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 | 3026 | fn infer_dyn_fn_once_output() { |
3037 | } | 3027 | check_types( |
3038 | } | 3028 | r#" |
3029 | //- /lib.rs | ||
3030 | #[lang = "fn_once"] | ||
3031 | pub trait FnOnce<Args> { | ||
3032 | type Output; | ||
3033 | extern "rust-call" fn call_once(self, args: Args) -> Self::Output; | ||
3034 | } | ||
3039 | 3035 | ||
3040 | fn foo() { | 3036 | fn 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 | ||
4 | use log::debug; | 4 | use log::debug; |
5 | 5 | ||
6 | use chalk_ir::{fold::shift::Shift, GenericArg, TypeName, CanonicalVarKinds}; | 6 | use chalk_ir::{fold::shift::Shift, CanonicalVarKinds, GenericArg, TypeName}; |
7 | use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait}; | 7 | use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait}; |
8 | 8 | ||
9 | use hir_def::{ | 9 | use 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> { |