"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"
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"
"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"
"smallvec",
"stdx",
"test_utils",
+ "tracing",
+ "tracing-subscriber",
+ "tracing-tree",
]
[[package]]
"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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c72c8cf3ec4ed69fef614d011a5ae4274537a8a8c59133558029bd731eb71659"
dependencies = [
- "ansi_term",
+ "ansi_term 0.11.0",
"chrono",
"lazy_static",
"matchers",
"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"
[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" }
// 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)
}
}
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() {
}
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();
#[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
+}"#,
);
}
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::{
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)
}
)
});
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> {