Split up ty tests a bit
This commit is contained in:
parent
96b9d5b44e
commit
9747156f6c
File diff suppressed because it is too large
Load Diff
268
crates/ra_hir_ty/src/tests/macros.rs
Normal file
268
crates/ra_hir_ty/src/tests/macros.rs
Normal file
@ -0,0 +1,268 @@
|
||||
use super::{infer, type_at, type_at_pos};
|
||||
use crate::test_db::TestDB;
|
||||
use insta::assert_snapshot;
|
||||
use ra_db::fixture::WithFixture;
|
||||
|
||||
#[test]
|
||||
fn cfg_impl_block() {
|
||||
let (db, pos) = TestDB::with_position(
|
||||
r#"
|
||||
//- /main.rs crate:main deps:foo cfg:test
|
||||
use foo::S as T;
|
||||
struct S;
|
||||
|
||||
#[cfg(test)]
|
||||
impl S {
|
||||
fn foo1(&self) -> i32 { 0 }
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
impl S {
|
||||
fn foo2(&self) -> i32 { 0 }
|
||||
}
|
||||
|
||||
fn test() {
|
||||
let t = (S.foo1(), S.foo2(), T.foo3(), T.foo4());
|
||||
t<|>;
|
||||
}
|
||||
|
||||
//- /foo.rs crate:foo
|
||||
struct S;
|
||||
|
||||
#[cfg(not(test))]
|
||||
impl S {
|
||||
fn foo3(&self) -> i32 { 0 }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
impl S {
|
||||
fn foo4(&self) -> i32 { 0 }
|
||||
}
|
||||
"#,
|
||||
);
|
||||
assert_eq!("(i32, {unknown}, i32, {unknown})", type_at_pos(&db, pos));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_macros_expanded() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
struct Foo(Vec<i32>);
|
||||
|
||||
macro_rules! foo {
|
||||
($($item:expr),*) => {
|
||||
{
|
||||
Foo(vec![$($item,)*])
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = foo!(1,2);
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
![0; 17) '{Foo(v...,2,])}': Foo
|
||||
![1; 4) 'Foo': Foo({unknown}) -> Foo
|
||||
![1; 16) 'Foo(vec![1,2,])': Foo
|
||||
![5; 15) 'vec![1,2,]': {unknown}
|
||||
[156; 182) '{ ...,2); }': ()
|
||||
[166; 167) 'x': Foo
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_legacy_textual_scoped_macros_expanded() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
struct Foo(Vec<i32>);
|
||||
|
||||
#[macro_use]
|
||||
mod m {
|
||||
macro_rules! foo {
|
||||
($($item:expr),*) => {
|
||||
{
|
||||
Foo(vec![$($item,)*])
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = foo!(1,2);
|
||||
let y = crate::foo!(1,2);
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
![0; 17) '{Foo(v...,2,])}': Foo
|
||||
![1; 4) 'Foo': Foo({unknown}) -> Foo
|
||||
![1; 16) 'Foo(vec![1,2,])': Foo
|
||||
![5; 15) 'vec![1,2,]': {unknown}
|
||||
[195; 251) '{ ...,2); }': ()
|
||||
[205; 206) 'x': Foo
|
||||
[228; 229) 'y': {unknown}
|
||||
[232; 248) 'crate:...!(1,2)': {unknown}
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_path_qualified_macros_expanded() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
#[macro_export]
|
||||
macro_rules! foo {
|
||||
() => { 42i32 }
|
||||
}
|
||||
|
||||
mod m {
|
||||
pub use super::foo as bar;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = crate::foo!();
|
||||
let y = m::bar!();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
![0; 5) '42i32': i32
|
||||
![0; 5) '42i32': i32
|
||||
[111; 164) '{ ...!(); }': ()
|
||||
[121; 122) 'x': i32
|
||||
[148; 149) 'y': i32
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_type_value_macro_having_same_name() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
#[macro_export]
|
||||
macro_rules! foo {
|
||||
() => {
|
||||
mod foo {
|
||||
pub use super::foo;
|
||||
}
|
||||
};
|
||||
($x:tt) => {
|
||||
$x
|
||||
};
|
||||
}
|
||||
|
||||
foo!();
|
||||
|
||||
fn foo() {
|
||||
let foo = foo::foo!(42i32);
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
![0; 5) '42i32': i32
|
||||
[171; 206) '{ ...32); }': ()
|
||||
[181; 184) 'foo': i32
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn processes_impls_generated_by_macros() {
|
||||
let t = type_at(
|
||||
r#"
|
||||
//- /main.rs
|
||||
macro_rules! m {
|
||||
($ident:ident) => (impl Trait for $ident {})
|
||||
}
|
||||
trait Trait { fn foo(self) -> u128 {} }
|
||||
struct S;
|
||||
m!(S);
|
||||
fn test() { S.foo()<|>; }
|
||||
"#,
|
||||
);
|
||||
assert_eq!(t, "u128");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_macro_with_dollar_crate_is_correct_in_expr() {
|
||||
let (db, pos) = TestDB::with_position(
|
||||
r#"
|
||||
//- /main.rs crate:main deps:foo
|
||||
fn test() {
|
||||
let x = (foo::foo!(1), foo::foo!(2));
|
||||
x<|>;
|
||||
}
|
||||
|
||||
//- /lib.rs crate:foo
|
||||
#[macro_export]
|
||||
macro_rules! foo {
|
||||
(1) => { $crate::bar!() };
|
||||
(2) => { 1 + $crate::baz() };
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! bar {
|
||||
() => { 42 }
|
||||
}
|
||||
|
||||
pub fn baz() -> usize { 31usize }
|
||||
"#,
|
||||
);
|
||||
assert_eq!("(i32, usize)", type_at_pos(&db, pos));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_builtin_macros_line() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! line {() => {}}
|
||||
|
||||
fn main() {
|
||||
let x = line!();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
![0; 1) '6': i32
|
||||
[64; 88) '{ ...!(); }': ()
|
||||
[74; 75) 'x': i32
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_builtin_macros_file() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! file {() => {}}
|
||||
|
||||
fn main() {
|
||||
let x = file!();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
![0; 2) '""': &str
|
||||
[64; 88) '{ ...!(); }': ()
|
||||
[74; 75) 'x': &str
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_builtin_macros_column() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! column {() => {}}
|
||||
|
||||
fn main() {
|
||||
let x = column!();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
![0; 2) '13': i32
|
||||
[66; 92) '{ ...!(); }': ()
|
||||
[76; 77) 'x': i32
|
||||
"###
|
||||
);
|
||||
}
|
1005
crates/ra_hir_ty/src/tests/method_resolution.rs
Normal file
1005
crates/ra_hir_ty/src/tests/method_resolution.rs
Normal file
File diff suppressed because it is too large
Load Diff
238
crates/ra_hir_ty/src/tests/patterns.rs
Normal file
238
crates/ra_hir_ty/src/tests/patterns.rs
Normal file
@ -0,0 +1,238 @@
|
||||
use super::infer;
|
||||
use insta::assert_snapshot;
|
||||
use test_utils::covers;
|
||||
|
||||
#[test]
|
||||
fn infer_pattern() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
fn test(x: &i32) {
|
||||
let y = x;
|
||||
let &z = x;
|
||||
let a = z;
|
||||
let (c, d) = (1, "hello");
|
||||
|
||||
for (e, f) in some_iter {
|
||||
let g = e;
|
||||
}
|
||||
|
||||
if let [val] = opt {
|
||||
let h = val;
|
||||
}
|
||||
|
||||
let lambda = |a: u64, b, c: i32| { a + b; c };
|
||||
|
||||
let ref ref_to_x = x;
|
||||
let mut mut_x = x;
|
||||
let ref mut mut_ref_to_x = x;
|
||||
let k = mut_ref_to_x;
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
[9; 10) 'x': &i32
|
||||
[18; 369) '{ ...o_x; }': ()
|
||||
[28; 29) 'y': &i32
|
||||
[32; 33) 'x': &i32
|
||||
[43; 45) '&z': &i32
|
||||
[44; 45) 'z': i32
|
||||
[48; 49) 'x': &i32
|
||||
[59; 60) 'a': i32
|
||||
[63; 64) 'z': i32
|
||||
[74; 80) '(c, d)': (i32, &str)
|
||||
[75; 76) 'c': i32
|
||||
[78; 79) 'd': &str
|
||||
[83; 95) '(1, "hello")': (i32, &str)
|
||||
[84; 85) '1': i32
|
||||
[87; 94) '"hello"': &str
|
||||
[102; 152) 'for (e... }': ()
|
||||
[106; 112) '(e, f)': ({unknown}, {unknown})
|
||||
[107; 108) 'e': {unknown}
|
||||
[110; 111) 'f': {unknown}
|
||||
[116; 125) 'some_iter': {unknown}
|
||||
[126; 152) '{ ... }': ()
|
||||
[140; 141) 'g': {unknown}
|
||||
[144; 145) 'e': {unknown}
|
||||
[158; 205) 'if let... }': ()
|
||||
[165; 170) '[val]': {unknown}
|
||||
[173; 176) 'opt': {unknown}
|
||||
[177; 205) '{ ... }': ()
|
||||
[191; 192) 'h': {unknown}
|
||||
[195; 198) 'val': {unknown}
|
||||
[215; 221) 'lambda': |u64, u64, i32| -> i32
|
||||
[224; 256) '|a: u6...b; c }': |u64, u64, i32| -> i32
|
||||
[225; 226) 'a': u64
|
||||
[233; 234) 'b': u64
|
||||
[236; 237) 'c': i32
|
||||
[244; 256) '{ a + b; c }': i32
|
||||
[246; 247) 'a': u64
|
||||
[246; 251) 'a + b': u64
|
||||
[250; 251) 'b': u64
|
||||
[253; 254) 'c': i32
|
||||
[267; 279) 'ref ref_to_x': &&i32
|
||||
[282; 283) 'x': &i32
|
||||
[293; 302) 'mut mut_x': &i32
|
||||
[305; 306) 'x': &i32
|
||||
[316; 336) 'ref mu...f_to_x': &mut &i32
|
||||
[339; 340) 'x': &i32
|
||||
[350; 351) 'k': &mut &i32
|
||||
[354; 366) 'mut_ref_to_x': &mut &i32
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_pattern_match_ergonomics() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
struct A<T>(T);
|
||||
|
||||
fn test() {
|
||||
let A(n) = &A(1);
|
||||
let A(n) = &mut A(1);
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
[28; 79) '{ ...(1); }': ()
|
||||
[38; 42) 'A(n)': A<i32>
|
||||
[40; 41) 'n': &i32
|
||||
[45; 50) '&A(1)': &A<i32>
|
||||
[46; 47) 'A': A<i32>(T) -> A<T>
|
||||
[46; 50) 'A(1)': A<i32>
|
||||
[48; 49) '1': i32
|
||||
[60; 64) 'A(n)': A<i32>
|
||||
[62; 63) 'n': &mut i32
|
||||
[67; 76) '&mut A(1)': &mut A<i32>
|
||||
[72; 73) 'A': A<i32>(T) -> A<T>
|
||||
[72; 76) 'A(1)': A<i32>
|
||||
[74; 75) '1': i32
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_pattern_match_ergonomics_ref() {
|
||||
covers!(match_ergonomics_ref);
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
fn test() {
|
||||
let v = &(1, &2);
|
||||
let (_, &w) = v;
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
[11; 57) '{ ...= v; }': ()
|
||||
[21; 22) 'v': &(i32, &i32)
|
||||
[25; 33) '&(1, &2)': &(i32, &i32)
|
||||
[26; 33) '(1, &2)': (i32, &i32)
|
||||
[27; 28) '1': i32
|
||||
[30; 32) '&2': &i32
|
||||
[31; 32) '2': i32
|
||||
[43; 50) '(_, &w)': (i32, &i32)
|
||||
[44; 45) '_': i32
|
||||
[47; 49) '&w': &i32
|
||||
[48; 49) 'w': i32
|
||||
[53; 54) 'v': &(i32, &i32)
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_adt_pattern() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
enum E {
|
||||
A { x: usize },
|
||||
B
|
||||
}
|
||||
|
||||
struct S(u32, E);
|
||||
|
||||
fn test() {
|
||||
let e = E::A { x: 3 };
|
||||
|
||||
let S(y, z) = foo;
|
||||
let E::A { x: new_var } = e;
|
||||
|
||||
match e {
|
||||
E::A { x } => x,
|
||||
E::B if foo => 1,
|
||||
E::B => 10,
|
||||
};
|
||||
|
||||
let ref d @ E::A { .. } = e;
|
||||
d;
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
[68; 289) '{ ... d; }': ()
|
||||
[78; 79) 'e': E
|
||||
[82; 95) 'E::A { x: 3 }': E
|
||||
[92; 93) '3': usize
|
||||
[106; 113) 'S(y, z)': S
|
||||
[108; 109) 'y': u32
|
||||
[111; 112) 'z': E
|
||||
[116; 119) 'foo': S
|
||||
[129; 148) 'E::A {..._var }': E
|
||||
[139; 146) 'new_var': usize
|
||||
[151; 152) 'e': E
|
||||
[159; 245) 'match ... }': usize
|
||||
[165; 166) 'e': E
|
||||
[177; 187) 'E::A { x }': E
|
||||
[184; 185) 'x': usize
|
||||
[191; 192) 'x': usize
|
||||
[202; 206) 'E::B': E
|
||||
[210; 213) 'foo': bool
|
||||
[217; 218) '1': usize
|
||||
[228; 232) 'E::B': E
|
||||
[236; 238) '10': usize
|
||||
[256; 275) 'ref d ...{ .. }': &E
|
||||
[264; 275) 'E::A { .. }': E
|
||||
[278; 279) 'e': E
|
||||
[285; 286) 'd': &E
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_generics_in_patterns() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
struct A<T> {
|
||||
x: T,
|
||||
}
|
||||
|
||||
enum Option<T> {
|
||||
Some(T),
|
||||
None,
|
||||
}
|
||||
|
||||
fn test(a1: A<u32>, o: Option<u64>) {
|
||||
let A { x: x2 } = a1;
|
||||
let A::<i64> { x: x3 } = A { x: 1 };
|
||||
match o {
|
||||
Option::Some(t) => t,
|
||||
_ => 1,
|
||||
};
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
[79; 81) 'a1': A<u32>
|
||||
[91; 92) 'o': Option<u64>
|
||||
[107; 244) '{ ... }; }': ()
|
||||
[117; 128) 'A { x: x2 }': A<u32>
|
||||
[124; 126) 'x2': u32
|
||||
[131; 133) 'a1': A<u32>
|
||||
[143; 161) 'A::<i6...: x3 }': A<i64>
|
||||
[157; 159) 'x3': i64
|
||||
[164; 174) 'A { x: 1 }': A<i64>
|
||||
[171; 172) '1': i64
|
||||
[180; 241) 'match ... }': u64
|
||||
[186; 187) 'o': Option<u64>
|
||||
[198; 213) 'Option::Some(t)': Option<u64>
|
||||
[211; 212) 't': u64
|
||||
[217; 218) 't': u64
|
||||
[228; 229) '_': Option<u64>
|
||||
[233; 234) '1': u64
|
||||
"###
|
||||
);
|
||||
}
|
333
crates/ra_hir_ty/src/tests/regression.rs
Normal file
333
crates/ra_hir_ty/src/tests/regression.rs
Normal file
@ -0,0 +1,333 @@
|
||||
use super::infer;
|
||||
use insta::assert_snapshot;
|
||||
use test_utils::covers;
|
||||
|
||||
#[test]
|
||||
fn bug_484() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
fn test() {
|
||||
let x = if true {};
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
[11; 37) '{ l... {}; }': ()
|
||||
[20; 21) 'x': ()
|
||||
[24; 34) 'if true {}': ()
|
||||
[27; 31) 'true': bool
|
||||
[32; 34) '{}': ()
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn no_panic_on_field_of_enum() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
enum X {}
|
||||
|
||||
fn test(x: X) {
|
||||
x.some_field;
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
[20; 21) 'x': X
|
||||
[26; 47) '{ ...eld; }': ()
|
||||
[32; 33) 'x': X
|
||||
[32; 44) 'x.some_field': {unknown}
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bug_585() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
fn test() {
|
||||
X {};
|
||||
match x {
|
||||
A::B {} => (),
|
||||
A::Y() => (),
|
||||
}
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
[11; 89) '{ ... } }': ()
|
||||
[17; 21) 'X {}': {unknown}
|
||||
[27; 87) 'match ... }': ()
|
||||
[33; 34) 'x': {unknown}
|
||||
[45; 52) 'A::B {}': {unknown}
|
||||
[56; 58) '()': ()
|
||||
[68; 74) 'A::Y()': {unknown}
|
||||
[78; 80) '()': ()
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bug_651() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
fn quux() {
|
||||
let y = 92;
|
||||
1 + y;
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
[11; 41) '{ ...+ y; }': ()
|
||||
[21; 22) 'y': i32
|
||||
[25; 27) '92': i32
|
||||
[33; 34) '1': i32
|
||||
[33; 38) '1 + y': i32
|
||||
[37; 38) 'y': i32
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recursive_vars() {
|
||||
covers!(type_var_cycles_resolve_completely);
|
||||
covers!(type_var_cycles_resolve_as_possible);
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
fn test() {
|
||||
let y = unknown;
|
||||
[y, &y];
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
[11; 48) '{ ...&y]; }': ()
|
||||
[21; 22) 'y': &{unknown}
|
||||
[25; 32) 'unknown': &{unknown}
|
||||
[38; 45) '[y, &y]': [&&{unknown};_]
|
||||
[39; 40) 'y': &{unknown}
|
||||
[42; 44) '&y': &&{unknown}
|
||||
[43; 44) 'y': &{unknown}
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recursive_vars_2() {
|
||||
covers!(type_var_cycles_resolve_completely);
|
||||
covers!(type_var_cycles_resolve_as_possible);
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
fn test() {
|
||||
let x = unknown;
|
||||
let y = unknown;
|
||||
[(x, y), (&y, &x)];
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
[11; 80) '{ ...x)]; }': ()
|
||||
[21; 22) 'x': &&{unknown}
|
||||
[25; 32) 'unknown': &&{unknown}
|
||||
[42; 43) 'y': &&{unknown}
|
||||
[46; 53) 'unknown': &&{unknown}
|
||||
[59; 77) '[(x, y..., &x)]': [(&&&{unknown}, &&&{unknown});_]
|
||||
[60; 66) '(x, y)': (&&&{unknown}, &&&{unknown})
|
||||
[61; 62) 'x': &&{unknown}
|
||||
[64; 65) 'y': &&{unknown}
|
||||
[68; 76) '(&y, &x)': (&&&{unknown}, &&&{unknown})
|
||||
[69; 71) '&y': &&&{unknown}
|
||||
[70; 71) 'y': &&{unknown}
|
||||
[73; 75) '&x': &&&{unknown}
|
||||
[74; 75) 'x': &&{unknown}
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_std_crash_1() {
|
||||
// caused stack overflow, taken from std
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
enum Maybe<T> {
|
||||
Real(T),
|
||||
Fake,
|
||||
}
|
||||
|
||||
fn write() {
|
||||
match something_unknown {
|
||||
Maybe::Real(ref mut something) => (),
|
||||
}
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
[54; 139) '{ ... } }': ()
|
||||
[60; 137) 'match ... }': ()
|
||||
[66; 83) 'someth...nknown': Maybe<{unknown}>
|
||||
[94; 124) 'Maybe:...thing)': Maybe<{unknown}>
|
||||
[106; 123) 'ref mu...ething': &mut {unknown}
|
||||
[128; 130) '()': ()
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_std_crash_2() {
|
||||
covers!(type_var_resolves_to_int_var);
|
||||
// caused "equating two type variables, ...", taken from std
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
fn test_line_buffer() {
|
||||
&[0, b'\n', 1, b'\n'];
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
[23; 53) '{ ...n']; }': ()
|
||||
[29; 50) '&[0, b...b'\n']': &[u8;_]
|
||||
[30; 50) '[0, b'...b'\n']': [u8;_]
|
||||
[31; 32) '0': u8
|
||||
[34; 39) 'b'\n'': u8
|
||||
[41; 42) '1': u8
|
||||
[44; 49) 'b'\n'': u8
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_std_crash_3() {
|
||||
// taken from rustc
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
pub fn compute() {
|
||||
match nope!() {
|
||||
SizeSkeleton::Pointer { non_zero: true, tail } => {}
|
||||
}
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
[18; 108) '{ ... } }': ()
|
||||
[24; 106) 'match ... }': ()
|
||||
[30; 37) 'nope!()': {unknown}
|
||||
[48; 94) 'SizeSk...tail }': {unknown}
|
||||
[82; 86) 'true': {unknown}
|
||||
[88; 92) 'tail': {unknown}
|
||||
[98; 100) '{}': ()
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_std_crash_4() {
|
||||
// taken from rustc
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
pub fn primitive_type() {
|
||||
match *self {
|
||||
BorrowedRef { type_: Primitive(p), ..} => {},
|
||||
}
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
[25; 106) '{ ... } }': ()
|
||||
[31; 104) 'match ... }': ()
|
||||
[37; 42) '*self': {unknown}
|
||||
[38; 42) 'self': {unknown}
|
||||
[53; 91) 'Borrow...), ..}': {unknown}
|
||||
[74; 86) 'Primitive(p)': {unknown}
|
||||
[84; 85) 'p': {unknown}
|
||||
[95; 97) '{}': ()
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_std_crash_5() {
|
||||
// taken from rustc
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
fn extra_compiler_flags() {
|
||||
for content in doesnt_matter {
|
||||
let name = if doesnt_matter {
|
||||
first
|
||||
} else {
|
||||
&content
|
||||
};
|
||||
|
||||
let content = if ICE_REPORT_COMPILER_FLAGS_STRIP_VALUE.contains(&name) {
|
||||
name
|
||||
} else {
|
||||
content
|
||||
};
|
||||
}
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
[27; 323) '{ ... } }': ()
|
||||
[33; 321) 'for co... }': ()
|
||||
[37; 44) 'content': &{unknown}
|
||||
[48; 61) 'doesnt_matter': {unknown}
|
||||
[62; 321) '{ ... }': ()
|
||||
[76; 80) 'name': &&{unknown}
|
||||
[83; 167) 'if doe... }': &&{unknown}
|
||||
[86; 99) 'doesnt_matter': bool
|
||||
[100; 129) '{ ... }': &&{unknown}
|
||||
[114; 119) 'first': &&{unknown}
|
||||
[135; 167) '{ ... }': &&{unknown}
|
||||
[149; 157) '&content': &&{unknown}
|
||||
[150; 157) 'content': &{unknown}
|
||||
[182; 189) 'content': &{unknown}
|
||||
[192; 314) 'if ICE... }': &{unknown}
|
||||
[195; 232) 'ICE_RE..._VALUE': {unknown}
|
||||
[195; 248) 'ICE_RE...&name)': bool
|
||||
[242; 247) '&name': &&&{unknown}
|
||||
[243; 247) 'name': &&{unknown}
|
||||
[249; 277) '{ ... }': &&{unknown}
|
||||
[263; 267) 'name': &&{unknown}
|
||||
[283; 314) '{ ... }': &{unknown}
|
||||
[297; 304) 'content': &{unknown}
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_nested_generics_crash() {
|
||||
// another crash found typechecking rustc
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
struct Canonical<V> {
|
||||
value: V,
|
||||
}
|
||||
struct QueryResponse<V> {
|
||||
value: V,
|
||||
}
|
||||
fn test<R>(query_response: Canonical<QueryResponse<R>>) {
|
||||
&query_response.value;
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
[92; 106) 'query_response': Canonical<QueryResponse<R>>
|
||||
[137; 167) '{ ...lue; }': ()
|
||||
[143; 164) '&query....value': &QueryResponse<R>
|
||||
[144; 158) 'query_response': Canonical<QueryResponse<R>>
|
||||
[144; 164) 'query_....value': QueryResponse<R>
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bug_1030() {
|
||||
assert_snapshot!(infer(r#"
|
||||
struct HashSet<T, H>;
|
||||
struct FxHasher;
|
||||
type FxHashSet<T> = HashSet<T, FxHasher>;
|
||||
|
||||
impl<T, H> HashSet<T, H> {
|
||||
fn default() -> HashSet<T, H> {}
|
||||
}
|
||||
|
||||
pub fn main_loop() {
|
||||
FxHashSet::default();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
[144; 146) '{}': ()
|
||||
[169; 198) '{ ...t(); }': ()
|
||||
[175; 193) 'FxHash...efault': fn default<{unknown}, FxHasher>() -> HashSet<T, H>
|
||||
[175; 195) 'FxHash...ault()': HashSet<{unknown}, FxHasher>
|
||||
"###
|
||||
);
|
||||
}
|
1608
crates/ra_hir_ty/src/tests/simple.rs
Normal file
1608
crates/ra_hir_ty/src/tests/simple.rs
Normal file
File diff suppressed because it is too large
Load Diff
1424
crates/ra_hir_ty/src/tests/traits.rs
Normal file
1424
crates/ra_hir_ty/src/tests/traits.rs
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user