mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-07 13:25:45 +00:00
Merge #5472
5472: Replace insta with expect r=matklad a=lnicola Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
This commit is contained in:
commit
9307c7f363
87
Cargo.lock
generated
87
Cargo.lock
generated
@ -205,20 +205,6 @@ dependencies = [
|
||||
"cc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "console"
|
||||
version = "0.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8c0994e656bba7b922d8dd1245db90672ffb701e684e45be58f20719d69abc5a"
|
||||
dependencies = [
|
||||
"encode_unicode",
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"terminal_size",
|
||||
"termios",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.2.0"
|
||||
@ -298,12 +284,6 @@ version = "0.1.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69b26e475fd29098530e709294e94e661974c851aed42512793f120fed4e199f"
|
||||
|
||||
[[package]]
|
||||
name = "dtoa"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b"
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.5.3"
|
||||
@ -319,12 +299,6 @@ dependencies = [
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encode_unicode"
|
||||
version = "0.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
|
||||
|
||||
[[package]]
|
||||
name = "env_logger"
|
||||
version = "0.7.1"
|
||||
@ -537,20 +511,6 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "insta"
|
||||
version = "0.16.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "617e921abc813f96a3b00958c079e7bf1e2db998f8a04f1546dd967373a418ee"
|
||||
dependencies = [
|
||||
"console",
|
||||
"difference",
|
||||
"lazy_static",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_yaml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "instant"
|
||||
version = "0.1.6"
|
||||
@ -665,12 +625,6 @@ dependencies = [
|
||||
"cmake",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linked-hash-map"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8dd5a6d5999d9907cda8ed67bbd137d3af8085216c2ac62de5be860bd41f304a"
|
||||
|
||||
[[package]]
|
||||
name = "lock_api"
|
||||
version = "0.4.1"
|
||||
@ -1128,7 +1082,6 @@ dependencies = [
|
||||
"chalk-solve",
|
||||
"ena",
|
||||
"expect",
|
||||
"insta",
|
||||
"itertools",
|
||||
"log",
|
||||
"ra_arena",
|
||||
@ -1659,18 +1612,6 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_yaml"
|
||||
version = "0.8.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae3e2dd40a7cdc18ca80db804b7f461a39bb721160a85c9a1fa30134bf3c02a5"
|
||||
dependencies = [
|
||||
"dtoa",
|
||||
"linked-hash-map",
|
||||
"serde",
|
||||
"yaml-rust",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sharded-slab"
|
||||
version = "0.0.9"
|
||||
@ -1757,25 +1698,6 @@ dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "terminal_size"
|
||||
version = "0.1.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9a14cd9f8c72704232f0bfc8455c0e861f0ad4eb60cc9ec8a170e231414c1e13"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termios"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6f0fcee7b24a25675de40d5bb4de6e41b0df07bc9856295e7e2b3a3600c400c2"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "test_utils"
|
||||
version = "0.1.0"
|
||||
@ -2065,12 +1987,3 @@ dependencies = [
|
||||
"quote",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "yaml-rust"
|
||||
version = "0.4.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "39f0c922f1a334134dc2f7a8b67dc5d25f0735263feec974345ff706bcf20b0d"
|
||||
dependencies = [
|
||||
"linked-hash-map",
|
||||
]
|
||||
|
@ -33,7 +33,6 @@ chalk-ir = { version = "0.18.0" }
|
||||
chalk-recursive = { version = "0.18.0" }
|
||||
|
||||
[dev-dependencies]
|
||||
insta = "0.16.0"
|
||||
expect = { path = "../expect" }
|
||||
|
||||
tracing = "0.1"
|
||||
|
@ -34,8 +34,8 @@ use crate::{
|
||||
};
|
||||
|
||||
// These tests compare the inference results for all expressions in a file
|
||||
// against snapshots of the expected results using insta. Use cargo-insta to
|
||||
// update the snapshots.
|
||||
// against snapshots of the expected results using expect. Use
|
||||
// `env UPDATE_EXPECT=1 cargo test -p ra_hir_ty` to update the snapshots.
|
||||
|
||||
fn setup_tracing() -> tracing::subscriber::DefaultGuard {
|
||||
use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry};
|
||||
|
@ -1,9 +1,9 @@
|
||||
use std::fs;
|
||||
|
||||
use insta::assert_snapshot;
|
||||
use expect::expect;
|
||||
use test_utils::project_dir;
|
||||
|
||||
use super::{check_types, infer};
|
||||
use super::{check_infer, check_types};
|
||||
|
||||
#[test]
|
||||
fn cfg_impl_def() {
|
||||
@ -46,8 +46,8 @@ impl S {
|
||||
|
||||
#[test]
|
||||
fn infer_macros_expanded() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
struct Foo(Vec<i32>);
|
||||
|
||||
macro_rules! foo {
|
||||
@ -61,22 +61,22 @@ macro_rules! foo {
|
||||
fn main() {
|
||||
let x = foo!(1,2);
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[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}
|
||||
155..181 '{ ...,2); }': ()
|
||||
165..166 'x': Foo
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_legacy_textual_scoped_macros_expanded() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
struct Foo(Vec<i32>);
|
||||
|
||||
#[macro_use]
|
||||
@ -94,8 +94,8 @@ fn main() {
|
||||
let x = foo!(1,2);
|
||||
let y = crate::foo!(1,2);
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
!0..17 '{Foo(v...,2,])}': Foo
|
||||
!1..4 'Foo': Foo({unknown}) -> Foo
|
||||
!1..16 'Foo(vec![1,2,])': Foo
|
||||
@ -104,14 +104,14 @@ fn main() {
|
||||
204..205 'x': Foo
|
||||
227..228 'y': {unknown}
|
||||
231..247 'crate:...!(1,2)': {unknown}
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_path_qualified_macros_expanded() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
#[macro_export]
|
||||
macro_rules! foo {
|
||||
() => { 42i32 }
|
||||
@ -125,21 +125,21 @@ fn main() {
|
||||
let x = crate::foo!();
|
||||
let y = m::bar!();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
!0..5 '42i32': i32
|
||||
!0..5 '42i32': i32
|
||||
110..163 '{ ...!(); }': ()
|
||||
120..121 'x': i32
|
||||
147..148 'y': i32
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn expr_macro_expanded_in_various_places() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
macro_rules! spam {
|
||||
() => (1isize);
|
||||
}
|
||||
@ -166,8 +166,8 @@ fn spam() {
|
||||
spam!()..spam!();
|
||||
spam!() + spam!();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
!0..6 '1isize': isize
|
||||
!0..6 '1isize': isize
|
||||
!0..6 '1isize': isize
|
||||
@ -213,14 +213,14 @@ fn spam() {
|
||||
400..408 '-spam!()': isize
|
||||
414..430 'spam!(...pam!()': {unknown}
|
||||
436..453 'spam!(...pam!()': isize
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_type_value_macro_having_same_name() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
#[macro_export]
|
||||
macro_rules! foo {
|
||||
() => {
|
||||
@ -238,12 +238,12 @@ foo!();
|
||||
fn foo() {
|
||||
let foo = foo::foo!(42i32);
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
!0..5 '42i32': i32
|
||||
170..205 '{ ...32); }': ()
|
||||
180..183 'foo': i32
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
@ -372,8 +372,8 @@ expand!();
|
||||
|
||||
#[test]
|
||||
fn infer_type_value_non_legacy_macro_use_as() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
mod m {
|
||||
macro_rules! _foo {
|
||||
($x:ident) => { type $x = u64; }
|
||||
@ -387,35 +387,35 @@ fn f() -> bar { 0 }
|
||||
fn main() {
|
||||
let _a = f();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
158..163 '{ 0 }': u64
|
||||
160..161 '0': u64
|
||||
174..196 '{ ...f(); }': ()
|
||||
184..186 '_a': u64
|
||||
190..191 'f': fn f() -> u64
|
||||
190..193 'f()': u64
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_local_macro() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
fn main() {
|
||||
macro_rules! foo {
|
||||
() => { 1usize }
|
||||
}
|
||||
let _a = foo!();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
!0..6 '1usize': usize
|
||||
10..89 '{ ...!(); }': ()
|
||||
16..65 'macro_... }': {unknown}
|
||||
74..76 '_a': usize
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
@ -446,77 +446,77 @@ macro_rules! bar {
|
||||
|
||||
#[test]
|
||||
fn infer_builtin_macros_line() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! line {() => {}}
|
||||
|
||||
fn main() {
|
||||
let x = line!();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
!0..1 '0': i32
|
||||
63..87 '{ ...!(); }': ()
|
||||
73..74 'x': i32
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_builtin_macros_file() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! file {() => {}}
|
||||
|
||||
fn main() {
|
||||
let x = file!();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
!0..2 '""': &str
|
||||
63..87 '{ ...!(); }': ()
|
||||
73..74 'x': &str
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_builtin_macros_column() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! column {() => {}}
|
||||
|
||||
fn main() {
|
||||
let x = column!();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
!0..1 '0': i32
|
||||
65..91 '{ ...!(); }': ()
|
||||
75..76 'x': i32
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_builtin_macros_concat() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! concat {() => {}}
|
||||
|
||||
fn main() {
|
||||
let x = concat!("hello", concat!("world", "!"));
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
!0..13 '"helloworld!"': &str
|
||||
65..121 '{ ...")); }': ()
|
||||
75..76 'x': &str
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
@ -630,8 +630,8 @@ fn main() {
|
||||
|
||||
#[test]
|
||||
fn infer_builtin_macros_concat_with_lazy() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
macro_rules! hello {() => {"hello"}}
|
||||
|
||||
#[rustc_builtin_macro]
|
||||
@ -640,19 +640,19 @@ macro_rules! concat {() => {}}
|
||||
fn main() {
|
||||
let x = concat!(hello!(), concat!("world", "!"));
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
!0..13 '"helloworld!"': &str
|
||||
103..160 '{ ...")); }': ()
|
||||
113..114 'x': &str
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_builtin_macros_env() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
//- /main.rs env:foo=bar
|
||||
#[rustc_builtin_macro]
|
||||
macro_rules! env {() => {}}
|
||||
@ -660,12 +660,12 @@ macro_rules! env {() => {}}
|
||||
fn main() {
|
||||
let x = env!("foo");
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
!0..22 '"__RA_...TED__"': &str
|
||||
62..90 '{ ...o"); }': ()
|
||||
72..73 'x': &str
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
@ -763,8 +763,8 @@ fn test() {
|
||||
|
||||
#[test]
|
||||
fn macro_in_arm() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
macro_rules! unit {
|
||||
() => { () };
|
||||
}
|
||||
@ -774,14 +774,14 @@ fn main() {
|
||||
unit!() => 92u32,
|
||||
};
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
51..110 '{ ... }; }': ()
|
||||
61..62 'x': u32
|
||||
65..107 'match ... }': u32
|
||||
71..73 '()': ()
|
||||
84..91 'unit!()': ()
|
||||
95..100 '92u32': u32
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
use insta::assert_snapshot;
|
||||
use expect::expect;
|
||||
|
||||
use super::{check_types, infer};
|
||||
use super::{check_infer, check_types};
|
||||
|
||||
#[test]
|
||||
fn infer_slice_method() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
#[lang = "slice"]
|
||||
impl<T> [T] {
|
||||
fn foo(&self) -> T {
|
||||
@ -19,8 +19,8 @@ impl<T> [T] {}
|
||||
fn test(x: &[u8]) {
|
||||
<[_]>::foo(x);
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
44..48 'self': &[T]
|
||||
55..78 '{ ... }': T
|
||||
65..72 'loop {}': !
|
||||
@ -30,14 +30,14 @@ fn test(x: &[u8]) {
|
||||
146..156 '<[_]>::foo': fn foo<u8>(&[u8]) -> u8
|
||||
146..159 '<[_]>::foo(x)': u8
|
||||
157..158 'x': &[u8]
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_associated_method_struct() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
struct A { x: u32 }
|
||||
|
||||
impl A {
|
||||
@ -49,8 +49,8 @@ fn test() {
|
||||
let a = A::new();
|
||||
a.x;
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
48..74 '{ ... }': A
|
||||
58..68 'A { x: 0 }': A
|
||||
65..66 '0': u32
|
||||
@ -60,14 +60,14 @@ fn test() {
|
||||
101..109 'A::new()': A
|
||||
115..116 'a': A
|
||||
115..118 'a.x': u32
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_associated_method_enum() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
enum A { B, C }
|
||||
|
||||
impl A {
|
||||
@ -84,8 +84,8 @@ fn test() {
|
||||
let c = A::c();
|
||||
c;
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
46..66 '{ ... }': A
|
||||
56..60 'A::B': A
|
||||
87..107 '{ ... }': A
|
||||
@ -99,14 +99,14 @@ fn test() {
|
||||
161..165 'A::c': fn c() -> A
|
||||
161..167 'A::c()': A
|
||||
173..174 'c': A
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_associated_method_with_modules() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
mod a {
|
||||
struct A;
|
||||
impl A { pub fn thing() -> A { A {} }}
|
||||
@ -128,8 +128,8 @@ fn test() {
|
||||
let y = b::B::thing();
|
||||
let z = c::C::thing();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
55..63 '{ A {} }': A
|
||||
57..61 'A {}': A
|
||||
125..131 '{ 99 }': u32
|
||||
@ -146,14 +146,14 @@ fn test() {
|
||||
304..305 'z': C
|
||||
308..319 'c::C::thing': fn thing() -> C
|
||||
308..321 'c::C::thing()': C
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_associated_method_generics() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
struct Gen<T> {
|
||||
val: T
|
||||
}
|
||||
@ -167,8 +167,8 @@ impl<T> Gen<T> {
|
||||
fn test() {
|
||||
let a = Gen::make(0u32);
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
63..66 'val': T
|
||||
81..108 '{ ... }': Gen<T>
|
||||
91..102 'Gen { val }': Gen<T>
|
||||
@ -178,14 +178,14 @@ fn test() {
|
||||
136..145 'Gen::make': fn make<u32>(u32) -> Gen<u32>
|
||||
136..151 'Gen::make(0u32)': Gen<u32>
|
||||
146..150 '0u32': u32
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_associated_method_generics_without_args() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
struct Gen<T> {
|
||||
val: T
|
||||
}
|
||||
@ -199,8 +199,8 @@ impl<T> Gen<T> {
|
||||
fn test() {
|
||||
let a = Gen::<u32>::make();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
75..99 '{ ... }': Gen<T>
|
||||
85..93 'loop { }': !
|
||||
90..93 '{ }': ()
|
||||
@ -208,14 +208,14 @@ fn test() {
|
||||
123..124 'a': Gen<u32>
|
||||
127..143 'Gen::<...::make': fn make<u32>() -> Gen<u32>
|
||||
127..145 'Gen::<...make()': Gen<u32>
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_associated_method_generics_2_type_params_without_args() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
struct Gen<T, U> {
|
||||
val: T,
|
||||
val2: U,
|
||||
@ -230,8 +230,8 @@ impl<T> Gen<u32, T> {
|
||||
fn test() {
|
||||
let a = Gen::<u32, u64>::make();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
101..125 '{ ... }': Gen<u32, T>
|
||||
111..119 'loop { }': !
|
||||
116..119 '{ }': ()
|
||||
@ -239,7 +239,7 @@ fn test() {
|
||||
149..150 'a': Gen<u32, u64>
|
||||
153..174 'Gen::<...::make': fn make<u64>() -> Gen<u32, u64>
|
||||
153..176 'Gen::<...make()': Gen<u32, u64>
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
@ -267,8 +267,8 @@ mod foo {
|
||||
#[test]
|
||||
fn infer_trait_method_simple() {
|
||||
// the trait implementation is intentionally incomplete -- it shouldn't matter
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
trait Trait1 {
|
||||
fn method(&self) -> u32;
|
||||
}
|
||||
@ -283,8 +283,8 @@ fn test() {
|
||||
S1.method(); // -> u32
|
||||
S2.method(); // -> i128
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
30..34 'self': &Self
|
||||
109..113 'self': &Self
|
||||
169..227 '{ ...i128 }': ()
|
||||
@ -292,15 +292,15 @@ fn test() {
|
||||
175..186 'S1.method()': u32
|
||||
202..204 'S2': S2
|
||||
202..213 'S2.method()': i128
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_trait_method_scoped() {
|
||||
// the trait implementation is intentionally incomplete -- it shouldn't matter
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
struct S;
|
||||
mod foo {
|
||||
pub trait Trait1 {
|
||||
@ -330,8 +330,8 @@ mod bar_test {
|
||||
S.method(); // -> i128
|
||||
}
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
62..66 'self': &Self
|
||||
168..172 'self': &Self
|
||||
299..336 '{ ... }': ()
|
||||
@ -340,15 +340,15 @@ mod bar_test {
|
||||
415..453 '{ ... }': ()
|
||||
425..426 'S': S
|
||||
425..435 'S.method()': i128
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_trait_method_generic_1() {
|
||||
// the trait implementation is intentionally incomplete -- it shouldn't matter
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
trait Trait<T> {
|
||||
fn method(&self) -> T;
|
||||
}
|
||||
@ -357,21 +357,21 @@ impl Trait<u32> for S {}
|
||||
fn test() {
|
||||
S.method();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
32..36 'self': &Self
|
||||
91..110 '{ ...d(); }': ()
|
||||
97..98 'S': S
|
||||
97..107 'S.method()': u32
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_trait_method_generic_more_params() {
|
||||
// the trait implementation is intentionally incomplete -- it shouldn't matter
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
trait Trait<T1, T2, T3> {
|
||||
fn method1(&self) -> (T1, T2, T3);
|
||||
fn method2(&self) -> (T3, T2, T1);
|
||||
@ -386,8 +386,8 @@ fn test() {
|
||||
S2.method1(); // i8, i16, {unknown}
|
||||
S2.method2(); // {unknown}, i16, i8
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
42..46 'self': &Self
|
||||
81..85 'self': &Self
|
||||
209..360 '{ ..., i8 }': ()
|
||||
@ -399,15 +399,15 @@ fn test() {
|
||||
283..295 'S2.method1()': (i8, i16, {unknown})
|
||||
323..325 'S2': S2
|
||||
323..335 'S2.method2()': ({unknown}, i16, i8)
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_trait_method_generic_2() {
|
||||
// the trait implementation is intentionally incomplete -- it shouldn't matter
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
trait Trait<T> {
|
||||
fn method(&self) -> T;
|
||||
}
|
||||
@ -416,22 +416,22 @@ impl<U> Trait<U> for S<U> {}
|
||||
fn test() {
|
||||
S(1u32).method();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
32..36 'self': &Self
|
||||
101..126 '{ ...d(); }': ()
|
||||
107..108 'S': S<u32>(u32) -> S<u32>
|
||||
107..114 'S(1u32)': S<u32>
|
||||
107..123 'S(1u32...thod()': u32
|
||||
109..113 '1u32': u32
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_trait_assoc_method() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
trait Default {
|
||||
fn default() -> Self;
|
||||
}
|
||||
@ -442,8 +442,8 @@ fn test() {
|
||||
let s2 = S::default();
|
||||
let s3 = <S as Default>::default();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
86..192 '{ ...t(); }': ()
|
||||
96..98 's1': S
|
||||
104..120 'Defaul...efault': fn default<S>() -> S
|
||||
@ -454,14 +454,14 @@ fn test() {
|
||||
159..161 's3': S
|
||||
164..187 '<S as ...efault': fn default<S>() -> S
|
||||
164..189 '<S as ...ault()': S
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_trait_assoc_method_generics_1() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
trait Trait<T> {
|
||||
fn make() -> T;
|
||||
}
|
||||
@ -474,8 +474,8 @@ fn test() {
|
||||
let b = G::<u64>::make();
|
||||
let c: f64 = G::make();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
126..210 '{ ...e(); }': ()
|
||||
136..137 'a': u32
|
||||
140..147 'S::make': fn make<S, u32>() -> u32
|
||||
@ -486,14 +486,14 @@ fn test() {
|
||||
189..190 'c': f64
|
||||
198..205 'G::make': fn make<G<f64>, f64>() -> f64
|
||||
198..207 'G::make()': f64
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_trait_assoc_method_generics_2() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
trait Trait<T> {
|
||||
fn make<U>() -> (T, U);
|
||||
}
|
||||
@ -508,8 +508,8 @@ fn test() {
|
||||
let d: (u32, _) = G::make::<i64>();
|
||||
let e: (u32, i64) = G::make();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
134..312 '{ ...e(); }': ()
|
||||
144..145 'a': (u32, i64)
|
||||
148..162 'S::make::<i64>': fn make<S, u32, i64>() -> (u32, i64)
|
||||
@ -526,14 +526,14 @@ fn test() {
|
||||
284..285 'e': (u32, i64)
|
||||
300..307 'G::make': fn make<G<u32>, u32, i64>() -> (u32, i64)
|
||||
300..309 'G::make()': (u32, i64)
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_trait_assoc_method_generics_3() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
trait Trait<T> {
|
||||
fn make() -> (Self, T);
|
||||
}
|
||||
@ -542,20 +542,20 @@ impl Trait<i64> for S<i32> {}
|
||||
fn test() {
|
||||
let a = S::make();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
100..126 '{ ...e(); }': ()
|
||||
110..111 'a': (S<i32>, i64)
|
||||
114..121 'S::make': fn make<S<i32>, i64>() -> (S<i32>, i64)
|
||||
114..123 'S::make()': (S<i32>, i64)
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_trait_assoc_method_generics_4() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
trait Trait<T> {
|
||||
fn make() -> (Self, T);
|
||||
}
|
||||
@ -566,8 +566,8 @@ fn test() {
|
||||
let a: (S<u64>, _) = S::make();
|
||||
let b: (_, i32) = S::make();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
130..202 '{ ...e(); }': ()
|
||||
140..141 'a': (S<u64>, i64)
|
||||
157..164 'S::make': fn make<S<u64>, i64>() -> (S<u64>, i64)
|
||||
@ -575,14 +575,14 @@ fn test() {
|
||||
176..177 'b': (S<u32>, i32)
|
||||
190..197 'S::make': fn make<S<u32>, i32>() -> (S<u32>, i32)
|
||||
190..199 'S::make()': (S<u32>, i32)
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_trait_assoc_method_generics_5() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
trait Trait<T> {
|
||||
fn make<U>() -> (Self, T, U);
|
||||
}
|
||||
@ -592,8 +592,8 @@ fn test() {
|
||||
let a = <S as Trait<i64>>::make::<u8>();
|
||||
let b: (S<u64>, _, _) = Trait::<i64>::make::<u8>();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
106..210 '{ ...>(); }': ()
|
||||
116..117 'a': (S<u64>, i64, u8)
|
||||
120..149 '<S as ...::<u8>': fn make<S<u64>, i64, u8>() -> (S<u64>, i64, u8)
|
||||
@ -601,56 +601,56 @@ fn test() {
|
||||
161..162 'b': (S<u64>, i64, u8)
|
||||
181..205 'Trait:...::<u8>': fn make<S<u64>, i64, u8>() -> (S<u64>, i64, u8)
|
||||
181..207 'Trait:...<u8>()': (S<u64>, i64, u8)
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_call_trait_method_on_generic_param_1() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
trait Trait {
|
||||
fn method(&self) -> u32;
|
||||
}
|
||||
fn test<T: Trait>(t: T) {
|
||||
t.method();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
29..33 'self': &Self
|
||||
63..64 't': T
|
||||
69..88 '{ ...d(); }': ()
|
||||
75..76 't': T
|
||||
75..85 't.method()': u32
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_call_trait_method_on_generic_param_2() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
trait Trait<T> {
|
||||
fn method(&self) -> T;
|
||||
}
|
||||
fn test<U, T: Trait<U>>(t: T) {
|
||||
t.method();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
32..36 'self': &Self
|
||||
70..71 't': T
|
||||
76..95 '{ ...d(); }': ()
|
||||
82..83 't': T
|
||||
82..92 't.method()': U
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_with_multiple_trait_impls() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
trait Into<T> {
|
||||
fn into(self) -> T;
|
||||
}
|
||||
@ -662,8 +662,8 @@ fn test() {
|
||||
let y: u64 = S.into();
|
||||
let z = Into::<u64>::into(S);
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
28..32 'self': Self
|
||||
110..201 '{ ...(S); }': ()
|
||||
120..121 'x': u32
|
||||
@ -676,7 +676,7 @@ fn test() {
|
||||
178..195 'Into::...::into': fn into<S, u64>(S) -> u64
|
||||
178..198 'Into::...nto(S)': u64
|
||||
196..197 'S': S
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
@ -1023,8 +1023,8 @@ fn test() { (S {}).method(); }
|
||||
|
||||
#[test]
|
||||
fn dyn_trait_super_trait_not_in_scope() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
mod m {
|
||||
pub trait SuperTrait {
|
||||
fn foo(&self) -> u32 { 0 }
|
||||
@ -1039,8 +1039,8 @@ impl Trait for S {}
|
||||
fn test(d: &dyn Trait) {
|
||||
d.foo();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
51..55 'self': &Self
|
||||
64..69 '{ 0 }': u32
|
||||
66..67 '0': u32
|
||||
@ -1048,6 +1048,6 @@ fn test(d: &dyn Trait) {
|
||||
191..207 '{ ...o(); }': ()
|
||||
197..198 'd': &dyn Trait
|
||||
197..204 'd.foo()': u32
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
use insta::assert_snapshot;
|
||||
use expect::expect;
|
||||
use test_utils::mark;
|
||||
|
||||
use super::{infer, infer_with_mismatches};
|
||||
use super::{check_infer, check_infer_with_mismatches};
|
||||
|
||||
#[test]
|
||||
fn infer_pattern() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
fn test(x: &i32) {
|
||||
let y = x;
|
||||
let &z = x;
|
||||
@ -28,8 +28,8 @@ fn test(x: &i32) {
|
||||
let ref mut mut_ref_to_x = x;
|
||||
let k = mut_ref_to_x;
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
8..9 'x': &i32
|
||||
17..368 '{ ...o_x; }': ()
|
||||
27..28 'y': &i32
|
||||
@ -78,14 +78,14 @@ fn test(x: &i32) {
|
||||
338..339 'x': &i32
|
||||
349..350 'k': &mut &i32
|
||||
353..365 'mut_ref_to_x': &mut &i32
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_literal_pattern() {
|
||||
assert_snapshot!(
|
||||
infer_with_mismatches(r#"
|
||||
check_infer_with_mismatches(
|
||||
r#"
|
||||
fn any<T>() -> T { loop {} }
|
||||
fn test(x: &i32) {
|
||||
if let "foo" = any() {}
|
||||
@ -95,8 +95,8 @@ fn test(x: &i32) {
|
||||
if let 1.0 = any() {}
|
||||
if let true = any() {}
|
||||
}
|
||||
"#, true),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
17..28 '{ loop {} }': T
|
||||
19..26 'loop {}': !
|
||||
24..26 '{}': ()
|
||||
@ -138,20 +138,20 @@ fn test(x: &i32) {
|
||||
198..201 'any': fn any<bool>() -> bool
|
||||
198..203 'any()': bool
|
||||
204..206 '{}': ()
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_range_pattern() {
|
||||
assert_snapshot!(
|
||||
infer_with_mismatches(r#"
|
||||
check_infer_with_mismatches(
|
||||
r#"
|
||||
fn test(x: &i32) {
|
||||
if let 1..76 = 2u32 {}
|
||||
if let 1..=76 = 2u32 {}
|
||||
}
|
||||
"#, true),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
8..9 'x': &i32
|
||||
17..75 '{ ...2 {} }': ()
|
||||
23..45 'if let...u32 {}': ()
|
||||
@ -162,22 +162,22 @@ fn test(x: &i32) {
|
||||
57..63 '1..=76': u32
|
||||
66..70 '2u32': u32
|
||||
71..73 '{}': ()
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_pattern_match_ergonomics() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
struct A<T>(T);
|
||||
|
||||
fn test() {
|
||||
let A(n) = &A(1);
|
||||
let A(n) = &mut A(1);
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
27..78 '{ ...(1); }': ()
|
||||
37..41 'A(n)': A<i32>
|
||||
39..40 'n': &i32
|
||||
@ -191,21 +191,21 @@ fn test() {
|
||||
71..72 'A': A<i32>(i32) -> A<i32>
|
||||
71..75 'A(1)': A<i32>
|
||||
73..74 '1': i32
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_pattern_match_ergonomics_ref() {
|
||||
mark::check!(match_ergonomics_ref);
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
fn test() {
|
||||
let v = &(1, &2);
|
||||
let (_, &w) = v;
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
10..56 '{ ...= v; }': ()
|
||||
20..21 'v': &(i32, &i32)
|
||||
24..32 '&(1, &2)': &(i32, &i32)
|
||||
@ -218,14 +218,14 @@ fn test() {
|
||||
46..48 '&w': &i32
|
||||
47..48 'w': i32
|
||||
52..53 'v': &(i32, &i32)
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_pattern_match_slice() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
fn test() {
|
||||
let slice: &[f64] = &[0.0];
|
||||
match slice {
|
||||
@ -240,8 +240,8 @@ fn test() {
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
10..209 '{ ... } }': ()
|
||||
20..25 'slice': &[f64]
|
||||
36..42 '&[0.0]': &[f64; _]
|
||||
@ -266,14 +266,14 @@ fn test() {
|
||||
173..174 'c': f64
|
||||
194..195 '_': &[f64]
|
||||
199..201 '{}': ()
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_pattern_match_string_literal() {
|
||||
assert_snapshot!(
|
||||
infer_with_mismatches(r#"
|
||||
check_infer_with_mismatches(
|
||||
r#"
|
||||
fn test() {
|
||||
let s: &str = "hello";
|
||||
match s {
|
||||
@ -281,8 +281,8 @@ fn test() {
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
"#, true),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
10..98 '{ ... } }': ()
|
||||
20..21 's': &str
|
||||
30..37 '"hello"': &str
|
||||
@ -293,14 +293,14 @@ fn test() {
|
||||
72..74 '{}': ()
|
||||
83..84 '_': &str
|
||||
88..90 '{}': ()
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_pattern_match_or() {
|
||||
assert_snapshot!(
|
||||
infer_with_mismatches(r#"
|
||||
check_infer_with_mismatches(
|
||||
r#"
|
||||
fn test() {
|
||||
let s: &str = "hello";
|
||||
match s {
|
||||
@ -308,8 +308,8 @@ fn test() {
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
"#, true),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
10..108 '{ ... } }': ()
|
||||
20..21 's': &str
|
||||
30..37 '"hello"': &str
|
||||
@ -323,14 +323,14 @@ fn test() {
|
||||
82..84 '{}': ()
|
||||
93..94 '_': &str
|
||||
98..100 '{}': ()
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_pattern_match_arr() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
fn test() {
|
||||
let arr: [f64; 2] = [0.0, 1.0];
|
||||
match arr {
|
||||
@ -343,8 +343,8 @@ fn test() {
|
||||
}
|
||||
}
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
10..179 '{ ... } }': ()
|
||||
20..23 'arr': [f64; _]
|
||||
36..46 '[0.0, 1.0]': [f64; _]
|
||||
@ -364,14 +364,14 @@ fn test() {
|
||||
130..171 '{ ... }': ()
|
||||
144..145 'b': f64
|
||||
159..160 'c': f64
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_adt_pattern() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
enum E {
|
||||
A { x: usize },
|
||||
B
|
||||
@ -394,8 +394,8 @@ fn test() {
|
||||
let ref d @ E::A { .. } = e;
|
||||
d;
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
67..288 '{ ... d; }': ()
|
||||
77..78 'e': E
|
||||
81..94 'E::A { x: 3 }': E
|
||||
@ -421,14 +421,14 @@ fn test() {
|
||||
263..274 'E::A { .. }': E
|
||||
277..278 'e': E
|
||||
284..285 'd': &E
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn enum_variant_through_self_in_pattern() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
enum E {
|
||||
A { x: usize },
|
||||
B(usize),
|
||||
@ -444,8 +444,8 @@ impl E {
|
||||
};
|
||||
}
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
75..217 '{ ... }': ()
|
||||
85..210 'match ... }': ()
|
||||
92..99 'loop {}': !
|
||||
@ -460,14 +460,14 @@ impl E {
|
||||
168..169 'x': usize
|
||||
186..193 'Self::C': E
|
||||
197..199 '{}': ()
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_generics_in_patterns() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
struct A<T> {
|
||||
x: T,
|
||||
}
|
||||
@ -485,8 +485,8 @@ fn test(a1: A<u32>, o: Option<u64>) {
|
||||
_ => 1,
|
||||
};
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
78..80 'a1': A<u32>
|
||||
90..91 'o': Option<u64>
|
||||
106..243 '{ ... }; }': ()
|
||||
@ -504,14 +504,14 @@ fn test(a1: A<u32>, o: Option<u64>) {
|
||||
216..217 't': u64
|
||||
227..228 '_': Option<u64>
|
||||
232..233 '1': u64
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_const_pattern() {
|
||||
assert_snapshot!(
|
||||
infer_with_mismatches(r#"
|
||||
check_infer_with_mismatches(
|
||||
r#"
|
||||
enum Option<T> { None }
|
||||
use Option::None;
|
||||
struct Foo;
|
||||
@ -525,8 +525,8 @@ fn test() {
|
||||
let _: () = match () { Foo => Foo }; // Expected mismatch
|
||||
let _: () = match () { Bar => Bar }; // Expected mismatch
|
||||
}
|
||||
"#, true),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
73..74 '1': usize
|
||||
87..309 '{ ...atch }': ()
|
||||
97..98 'a': Option<u32>
|
||||
@ -548,14 +548,14 @@ fn test() {
|
||||
280..283 'Bar': usize
|
||||
200..223: expected (), got Foo
|
||||
262..285: expected (), got usize
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_guard() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
struct S;
|
||||
impl S { fn foo(&self) -> bool { false } }
|
||||
|
||||
@ -564,7 +564,8 @@ fn main() {
|
||||
s if s.foo() => (),
|
||||
}
|
||||
}
|
||||
"#), @r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
27..31 'self': &S
|
||||
41..50 '{ false }': bool
|
||||
43..48 'false': bool
|
||||
@ -575,13 +576,14 @@ fn main() {
|
||||
93..94 's': S
|
||||
93..100 's.foo()': bool
|
||||
104..106 '()': ()
|
||||
"###)
|
||||
"#]],
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn match_ergonomics_in_closure_params() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
#[lang = "fn_once"]
|
||||
trait FnOnce<Args> {
|
||||
type Output;
|
||||
@ -593,8 +595,8 @@ fn test() {
|
||||
foo(&(1, "a"), |&(x, y)| x); // normal, no match ergonomics
|
||||
foo(&(1, "a"), |(x, y)| x);
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
93..94 't': T
|
||||
99..100 'f': F
|
||||
110..121 '{ loop {} }': U
|
||||
@ -624,22 +626,22 @@ fn test() {
|
||||
220..221 'x': &i32
|
||||
223..224 'y': &&str
|
||||
227..228 'x': &i32
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn slice_tail_pattern() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
fn foo(params: &[i32]) {
|
||||
match params {
|
||||
[head, tail @ ..] => {
|
||||
}
|
||||
}
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
7..13 'params': &[i32]
|
||||
23..92 '{ ... } }': ()
|
||||
29..90 'match ... }': ()
|
||||
@ -649,6 +651,6 @@ fn foo(params: &[i32]) {
|
||||
59..68 'tail @ ..': &[i32]
|
||||
66..68 '..': [i32]
|
||||
73..84 '{ }': ()
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
@ -1,49 +1,49 @@
|
||||
use insta::assert_snapshot;
|
||||
use expect::expect;
|
||||
use test_utils::mark;
|
||||
|
||||
use super::{check_types, infer};
|
||||
use super::{check_infer, check_types};
|
||||
|
||||
#[test]
|
||||
fn bug_484() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
fn test() {
|
||||
let x = if true {};
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
10..36 '{ l... {}; }': ()
|
||||
19..20 'x': ()
|
||||
23..33 'if true {}': ()
|
||||
26..30 'true': bool
|
||||
31..33 '{}': ()
|
||||
"###
|
||||
"#,
|
||||
expect![[r#"
|
||||
10..37 '{ ... {}; }': ()
|
||||
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#"
|
||||
check_infer(
|
||||
r#"
|
||||
enum X {}
|
||||
|
||||
fn test(x: X) {
|
||||
x.some_field;
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
19..20 'x': X
|
||||
25..46 '{ ...eld; }': ()
|
||||
31..32 'x': X
|
||||
31..43 'x.some_field': {unknown}
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bug_585() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
fn test() {
|
||||
X {};
|
||||
match x {
|
||||
@ -51,8 +51,8 @@ fn test() {
|
||||
A::Y() => (),
|
||||
}
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
10..88 '{ ... } }': ()
|
||||
16..20 'X {}': {unknown}
|
||||
26..86 'match ... }': ()
|
||||
@ -61,27 +61,27 @@ fn test() {
|
||||
55..57 '()': ()
|
||||
67..73 'A::Y()': {unknown}
|
||||
77..79 '()': ()
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bug_651() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
fn quux() {
|
||||
let y = 92;
|
||||
1 + y;
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
10..40 '{ ...+ y; }': ()
|
||||
20..21 'y': i32
|
||||
24..26 '92': i32
|
||||
32..33 '1': i32
|
||||
32..37 '1 + y': i32
|
||||
36..37 'y': i32
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
@ -89,14 +89,14 @@ fn quux() {
|
||||
fn recursive_vars() {
|
||||
mark::check!(type_var_cycles_resolve_completely);
|
||||
mark::check!(type_var_cycles_resolve_as_possible);
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
fn test() {
|
||||
let y = unknown;
|
||||
[y, &y];
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
10..47 '{ ...&y]; }': ()
|
||||
20..21 'y': &{unknown}
|
||||
24..31 'unknown': &{unknown}
|
||||
@ -104,21 +104,21 @@ fn test() {
|
||||
38..39 'y': &{unknown}
|
||||
41..43 '&y': &&{unknown}
|
||||
42..43 'y': &{unknown}
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn recursive_vars_2() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
fn test() {
|
||||
let x = unknown;
|
||||
let y = unknown;
|
||||
[(x, y), (&y, &x)];
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
10..79 '{ ...x)]; }': ()
|
||||
20..21 'x': &&{unknown}
|
||||
24..31 'unknown': &&{unknown}
|
||||
@ -133,15 +133,15 @@ fn test() {
|
||||
69..70 'y': &&{unknown}
|
||||
72..74 '&x': &&&{unknown}
|
||||
73..74 'x': &&{unknown}
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_std_crash_1() {
|
||||
// caused stack overflow, taken from std
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
enum Maybe<T> {
|
||||
Real(T),
|
||||
Fake,
|
||||
@ -152,15 +152,15 @@ fn write() {
|
||||
Maybe::Real(ref mut something) => (),
|
||||
}
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
53..138 '{ ... } }': ()
|
||||
59..136 'match ... }': ()
|
||||
65..82 'someth...nknown': Maybe<{unknown}>
|
||||
93..123 'Maybe:...thing)': Maybe<{unknown}>
|
||||
105..122 'ref mu...ething': &mut {unknown}
|
||||
127..129 '()': ()
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
@ -168,13 +168,13 @@ fn write() {
|
||||
fn infer_std_crash_2() {
|
||||
mark::check!(type_var_resolves_to_int_var);
|
||||
// caused "equating two type variables, ...", taken from std
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
fn test_line_buffer() {
|
||||
&[0, b'\n', 1, b'\n'];
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
22..52 '{ ...n']; }': ()
|
||||
28..49 '&[0, b...b'\n']': &[u8; _]
|
||||
29..49 '[0, b'...b'\n']': [u8; _]
|
||||
@ -182,22 +182,22 @@ fn test_line_buffer() {
|
||||
33..38 'b'\n'': u8
|
||||
40..41 '1': u8
|
||||
43..48 'b'\n'': u8
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_std_crash_3() {
|
||||
// taken from rustc
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
pub fn compute() {
|
||||
match nope!() {
|
||||
SizeSkeleton::Pointer { non_zero: true, tail } => {}
|
||||
}
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
17..107 '{ ... } }': ()
|
||||
23..105 'match ... }': ()
|
||||
29..36 'nope!()': {unknown}
|
||||
@ -206,22 +206,22 @@ pub fn compute() {
|
||||
81..85 'true': bool
|
||||
87..91 'tail': {unknown}
|
||||
97..99 '{}': ()
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_std_crash_4() {
|
||||
// taken from rustc
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
pub fn primitive_type() {
|
||||
match *self {
|
||||
BorrowedRef { type_: Primitive(p), ..} => {},
|
||||
}
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
24..105 '{ ... } }': ()
|
||||
30..103 'match ... }': ()
|
||||
36..41 '*self': {unknown}
|
||||
@ -230,15 +230,15 @@ pub fn primitive_type() {
|
||||
73..85 'Primitive(p)': {unknown}
|
||||
83..84 'p': {unknown}
|
||||
94..96 '{}': ()
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_std_crash_5() {
|
||||
// taken from rustc
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
fn extra_compiler_flags() {
|
||||
for content in doesnt_matter {
|
||||
let name = if doesnt_matter {
|
||||
@ -254,8 +254,8 @@ fn extra_compiler_flags() {
|
||||
};
|
||||
}
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
26..322 '{ ... } }': ()
|
||||
32..320 'for co... }': ()
|
||||
36..43 'content': &{unknown}
|
||||
@ -279,15 +279,15 @@ fn extra_compiler_flags() {
|
||||
262..266 'name': &&{unknown}
|
||||
282..313 '{ ... }': &{unknown}
|
||||
296..303 'content': &{unknown}
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_nested_generics_crash() {
|
||||
// another crash found typechecking rustc
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
struct Canonical<V> {
|
||||
value: V,
|
||||
}
|
||||
@ -297,37 +297,38 @@ struct QueryResponse<V> {
|
||||
fn test<R>(query_response: Canonical<QueryResponse<R>>) {
|
||||
&query_response.value;
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
91..105 'query_response': Canonical<QueryResponse<R>>
|
||||
136..166 '{ ...lue; }': ()
|
||||
142..163 '&query....value': &QueryResponse<R>
|
||||
143..157 'query_response': Canonical<QueryResponse<R>>
|
||||
143..163 'query_....value': QueryResponse<R>
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_paren_macro_call() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
macro_rules! bar { () => {0u32} }
|
||||
fn test() {
|
||||
let a = (bar!());
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
!0..4 '0u32': u32
|
||||
44..69 '{ ...()); }': ()
|
||||
54..55 'a': u32
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bug_1030() {
|
||||
assert_snapshot!(infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
struct HashSet<T, H>;
|
||||
struct FxHasher;
|
||||
type FxHashSet<T> = HashSet<T, FxHasher>;
|
||||
@ -339,21 +340,21 @@ impl<T, H> HashSet<T, H> {
|
||||
pub fn main_loop() {
|
||||
FxHashSet::default();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
143..145 '{}': ()
|
||||
168..197 '{ ...t(); }': ()
|
||||
174..192 'FxHash...efault': fn default<{unknown}, FxHasher>() -> HashSet<{unknown}, FxHasher>
|
||||
174..194 'FxHash...ault()': HashSet<{unknown}, FxHasher>
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_2669() {
|
||||
assert_snapshot!(
|
||||
infer(
|
||||
r#"trait A {}
|
||||
check_infer(
|
||||
r#"
|
||||
trait A {}
|
||||
trait Write {}
|
||||
struct Response<T> {}
|
||||
|
||||
@ -368,34 +369,34 @@ fn issue_2669() {
|
||||
let _x: T = loop {};
|
||||
}
|
||||
}
|
||||
}"#
|
||||
),
|
||||
@r###"
|
||||
147..262 '{ ... }': ()
|
||||
161..164 'end': fn end<{unknown}>()
|
||||
161..166 'end()': ()
|
||||
199..252 '{ ... }': ()
|
||||
221..223 '_x': !
|
||||
230..237 'loop {}': !
|
||||
235..237 '{}': ()
|
||||
"###
|
||||
}
|
||||
"#,
|
||||
expect![[r#"
|
||||
119..214 '{ ... }': ()
|
||||
129..132 'end': fn end<{unknown}>()
|
||||
129..134 'end()': ()
|
||||
163..208 '{ ... }': ()
|
||||
181..183 '_x': !
|
||||
190..197 'loop {}': !
|
||||
195..197 '{}': ()
|
||||
"#]],
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_2705() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
trait Trait {}
|
||||
fn test() {
|
||||
<Trait<u32>>::foo()
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
25..52 '{ ...oo() }': ()
|
||||
31..48 '<Trait...>::foo': {unknown}
|
||||
31..50 '<Trait...:foo()': ()
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
@ -479,15 +480,15 @@ fn main() {
|
||||
|
||||
#[test]
|
||||
fn issue_3999_slice() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
fn foo(params: &[usize]) {
|
||||
match params {
|
||||
[ps @ .., _] => {}
|
||||
}
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
7..13 'params': &[usize]
|
||||
25..80 '{ ... } }': ()
|
||||
31..78 'match ... }': ()
|
||||
@ -497,7 +498,7 @@ fn foo(params: &[usize]) {
|
||||
60..62 '..': [usize]
|
||||
64..65 '_': usize
|
||||
70..72 '{}': ()
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
@ -505,8 +506,8 @@ fn foo(params: &[usize]) {
|
||||
fn issue_3999_struct() {
|
||||
// rust-analyzer should not panic on seeing this malformed
|
||||
// record pattern.
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
struct Bar {
|
||||
a: bool,
|
||||
}
|
||||
@ -515,8 +516,8 @@ fn foo(b: Bar) {
|
||||
Bar { a: .. } => {},
|
||||
}
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
35..36 'b': Bar
|
||||
43..95 '{ ... } }': ()
|
||||
49..93 'match ... }': ()
|
||||
@ -524,14 +525,14 @@ fn foo(b: Bar) {
|
||||
67..80 'Bar { a: .. }': Bar
|
||||
76..78 '..': bool
|
||||
84..86 '{}': ()
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_4235_name_conflicts() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
struct FOO {}
|
||||
static FOO:FOO = FOO {};
|
||||
|
||||
@ -543,7 +544,8 @@ fn main() {
|
||||
let a = &FOO;
|
||||
a.foo();
|
||||
}
|
||||
"#), @r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
31..37 'FOO {}': FOO
|
||||
63..67 'self': &FOO
|
||||
69..71 '{}': ()
|
||||
@ -553,14 +555,14 @@ fn main() {
|
||||
100..103 'FOO': FOO
|
||||
109..110 'a': &FOO
|
||||
109..116 'a.foo()': ()
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_4465_dollar_crate_at_type() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
pub struct Foo {}
|
||||
pub fn anything<T>() -> T {
|
||||
loop {}
|
||||
@ -574,7 +576,8 @@ macro_rules! foo {
|
||||
fn main() {
|
||||
let _a = foo!();
|
||||
}
|
||||
"#), @r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
44..59 '{ loop {} }': T
|
||||
50..57 'loop {}': !
|
||||
55..57 '{}': ()
|
||||
@ -585,13 +588,14 @@ fn main() {
|
||||
!29..30 'r': Foo
|
||||
163..187 '{ ...!(); }': ()
|
||||
173..175 '_a': Foo
|
||||
"###);
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_4053_diesel_where_clauses() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
trait BoxedDsl<DB> {
|
||||
type Output;
|
||||
fn internal_into_boxed(self) -> Self::Output;
|
||||
@ -616,8 +620,8 @@ where
|
||||
self.order.into();
|
||||
}
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
65..69 'self': Self
|
||||
267..271 'self': Self
|
||||
466..470 'self': SelectStatement<F, S, D, W, O, LOf, {unknown}, {unknown}>
|
||||
@ -625,46 +629,46 @@ where
|
||||
498..502 'self': SelectStatement<F, S, D, W, O, LOf, {unknown}, {unknown}>
|
||||
498..508 'self.order': O
|
||||
498..515 'self.o...into()': dyn QueryFragment<DB>
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_4953() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
pub struct Foo(pub i64);
|
||||
impl Foo {
|
||||
fn test() -> Self { Self(0i64) }
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
58..72 '{ Self(0i64) }': Foo
|
||||
60..64 'Self': Foo(i64) -> Foo
|
||||
60..70 'Self(0i64)': Foo
|
||||
65..69 '0i64': i64
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
pub struct Foo<T>(pub T);
|
||||
impl Foo<i64> {
|
||||
fn test() -> Self { Self(0i64) }
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
64..78 '{ Self(0i64) }': Foo<i64>
|
||||
66..70 'Self': Foo<i64>(i64) -> Foo<i64>
|
||||
66..76 'Self(0i64)': Foo<i64>
|
||||
71..75 '0i64': i64
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_4931() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
trait Div<T> {
|
||||
type Output;
|
||||
}
|
||||
@ -678,21 +682,21 @@ trait PrimInt: CheckedDiv<Output = ()> {
|
||||
fn check<T: PrimInt>(i: T) {
|
||||
i.pow();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
117..121 'self': Self
|
||||
148..149 'i': T
|
||||
154..170 '{ ...w(); }': ()
|
||||
160..161 'i': T
|
||||
160..167 'i.pow()': ()
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_4885() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
#[lang = "coerce_unsized"]
|
||||
pub trait CoerceUnsized<T> {}
|
||||
|
||||
@ -713,8 +717,8 @@ where
|
||||
K: Foo<R>,
|
||||
{
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
136..139 'key': &K
|
||||
198..214 '{ ...key) }': impl Future<Output = <K as Foo<R>>::Bar>
|
||||
204..207 'bar': fn bar<R, K>(&K) -> impl Future<Output = <K as Foo<R>>::Bar>
|
||||
@ -722,14 +726,14 @@ where
|
||||
208..211 'key': &K
|
||||
228..231 'key': &K
|
||||
290..293 '{ }': ()
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_4800() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
trait Debug {}
|
||||
|
||||
struct Foo<T>;
|
||||
@ -769,21 +773,21 @@ pub trait Service<Request> {
|
||||
type Future: Future<Output = Self::Error>;
|
||||
fn call(&mut self) -> Self::Future;
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
379..383 'self': &mut PeerSet<D>
|
||||
401..424 '{ ... }': dyn Future<Output = ()>
|
||||
411..418 'loop {}': !
|
||||
416..418 '{}': ()
|
||||
575..579 'self': &mut Self
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn issue_4966() {
|
||||
assert_snapshot!(
|
||||
infer(r#"
|
||||
check_infer(
|
||||
r#"
|
||||
pub trait IntoIterator {
|
||||
type Item;
|
||||
}
|
||||
@ -814,8 +818,8 @@ fn main() {
|
||||
|
||||
vec.foo_bar();
|
||||
}
|
||||
"#),
|
||||
@r###"
|
||||
"#,
|
||||
expect![[r#"
|
||||
270..274 'iter': T
|
||||
289..291 '{}': ()
|
||||
303..447 '{ ...r(); }': ()
|
||||
@ -833,6 +837,6 @@ fn main() {
|
||||
417..423 'repeat': Repeat<Map<|&f64| -> f64>>
|
||||
431..434 'vec': Vec<IntoIterator::Item<Repeat<Map<|&f64| -> f64>>>>
|
||||
431..444 'vec.foo_bar()': {unknown}
|
||||
"###
|
||||
"#]],
|
||||
);
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -170,8 +170,7 @@ The innermost and most elaborate boundary is `hir`. It has a much richer
|
||||
vocabulary of types than `ide`, but the basic testing setup is the same: we
|
||||
create a database, run some queries, assert result.
|
||||
|
||||
For comparisons, we use [insta](https://github.com/mitsuhiko/insta/) library for
|
||||
snapshot testing.
|
||||
For comparisons, we use the `expect` crate for snapshot testing.
|
||||
|
||||
To test various analysis corner cases and avoid forgetting about old tests, we
|
||||
use so-called marks. See the `marks` module in the `test_utils` crate for more.
|
||||
|
Loading…
Reference in New Issue
Block a user