Correctly infer - and ! using std::ops::{Neg,Not}

This commit is contained in:
Emil Lauridsen
2019-12-13 12:44:42 +01:00
parent 95dc2de8e9
commit 7705209051
5 changed files with 114 additions and 23 deletions

View File

@@ -115,6 +115,70 @@ mod collections {
assert_eq!("&str", type_at_pos(&db, pos));
}
#[test]
fn infer_ops_neg() {
let (db, pos) = TestDB::with_position(
r#"
//- /main.rs crate:main deps:std
struct Bar;
struct Foo;
impl std::ops::Neg for Bar {
type Output = Foo;
}
fn test() {
let a = Bar;
let b = -a;
b<|>;
}
//- /std.rs crate:std
#[prelude_import] use ops::*;
mod ops {
pub trait Neg {
type Output;
}
}
"#,
);
assert_eq!("Foo", type_at_pos(&db, pos));
}
#[test]
fn infer_ops_not() {
let (db, pos) = TestDB::with_position(
r#"
//- /main.rs crate:main deps:std
struct Bar;
struct Foo;
impl std::ops::Not for Bar {
type Output = Foo;
}
fn test() {
let a = Bar;
let b = !a;
b<|>;
}
//- /std.rs crate:std
#[prelude_import] use ops::*;
mod ops {
pub trait Not {
type Output;
}
}
"#,
);
assert_eq!("Foo", type_at_pos(&db, pos));
}
#[test]
fn infer_from_bound_1() {
assert_snapshot!(