mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-27 20:35:09 +00:00
Use expect in never_type tests
This commit is contained in:
parent
b82899ad76
commit
3b6979be77
3 changed files with 185 additions and 186 deletions
|
@ -10,6 +10,7 @@ mod display_source_code;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use expect::Expect;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
body::{BodySourceMap, SyntheticSyntax},
|
body::{BodySourceMap, SyntheticSyntax},
|
||||||
child_by_source::ChildBySource,
|
child_by_source::ChildBySource,
|
||||||
|
@ -344,3 +345,29 @@ fn typing_whitespace_inside_a_function_should_not_invalidate_types() {
|
||||||
assert!(!format!("{:?}", events).contains("infer"), "{:#?}", events)
|
assert!(!format!("{:?}", events).contains("infer"), "{:#?}", events)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Infer with some common definitions and impls.
|
||||||
|
fn check_infer(ra_fixture: &str, expect: Expect) {
|
||||||
|
let defs = r#"
|
||||||
|
#[lang = "sized"]
|
||||||
|
pub trait Sized {}
|
||||||
|
#[lang = "unsize"]
|
||||||
|
pub trait Unsize<T: ?Sized> {}
|
||||||
|
#[lang = "coerce_unsized"]
|
||||||
|
pub trait CoerceUnsized<T> {}
|
||||||
|
|
||||||
|
impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
|
||||||
|
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
|
||||||
|
"#;
|
||||||
|
|
||||||
|
// Append to the end to keep positions unchanged.
|
||||||
|
let mut actual = infer(&format!("{}{}", ra_fixture, defs));
|
||||||
|
actual.push('\n');
|
||||||
|
expect.assert_eq(&actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn check_infer_with_mismatches(ra_fixture: &str, expect: Expect) {
|
||||||
|
let mut actual = infer_with_mismatches(ra_fixture, true);
|
||||||
|
actual.push('\n');
|
||||||
|
expect.assert_eq(&actual);
|
||||||
|
}
|
||||||
|
|
|
@ -1,32 +1,7 @@
|
||||||
|
use expect::expect;
|
||||||
use test_utils::mark;
|
use test_utils::mark;
|
||||||
|
|
||||||
use expect::{expect, Expect};
|
use super::{check_infer, check_infer_with_mismatches};
|
||||||
|
|
||||||
// Infer with some common definitions and impls.
|
|
||||||
fn check_infer(ra_fixture: &str, expect: Expect) {
|
|
||||||
let defs = r#"
|
|
||||||
#[lang = "sized"]
|
|
||||||
pub trait Sized {}
|
|
||||||
#[lang = "unsize"]
|
|
||||||
pub trait Unsize<T: ?Sized> {}
|
|
||||||
#[lang = "coerce_unsized"]
|
|
||||||
pub trait CoerceUnsized<T> {}
|
|
||||||
|
|
||||||
impl<'a, 'b: 'a, T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<&'a U> for &'b T {}
|
|
||||||
impl<T: ?Sized + Unsize<U>, U: ?Sized> CoerceUnsized<*mut U> for *mut T {}
|
|
||||||
"#;
|
|
||||||
|
|
||||||
// Append to the end to keep positions unchanged.
|
|
||||||
let mut actual = super::infer(&format!("{}{}", ra_fixture, defs));
|
|
||||||
actual.push('\n');
|
|
||||||
expect.assert_eq(&actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check_infer_with_mismatches(ra_fixture: &str, expect: Expect) {
|
|
||||||
let mut actual = super::infer_with_mismatches(ra_fixture, true);
|
|
||||||
actual.push('\n');
|
|
||||||
expect.assert_eq(&actual);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn infer_block_expr_type_mismatch() {
|
fn infer_block_expr_type_mismatch() {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use insta::assert_snapshot;
|
use expect::expect;
|
||||||
|
|
||||||
use super::{check_types, infer_with_mismatches};
|
use super::{check_infer_with_mismatches, check_types};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn infer_never1() {
|
fn infer_never1() {
|
||||||
|
@ -240,8 +240,8 @@ fn test(a: i32) {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn diverging_expression_1() {
|
fn diverging_expression_1() {
|
||||||
let t = infer_with_mismatches(
|
check_infer_with_mismatches(
|
||||||
r#"
|
r"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
fn test1() {
|
fn test1() {
|
||||||
let x: u32 = return;
|
let x: u32 = return;
|
||||||
|
@ -261,10 +261,8 @@ fn test5() {
|
||||||
fn test6() {
|
fn test6() {
|
||||||
let x: u32 = { let y: u32 = { loop {}; }; };
|
let x: u32 = { let y: u32 = { loop {}; }; };
|
||||||
}
|
}
|
||||||
"#,
|
",
|
||||||
true,
|
expect![[r"
|
||||||
);
|
|
||||||
assert_snapshot!(t, @r###"
|
|
||||||
11..39 '{ ...urn; }': ()
|
11..39 '{ ...urn; }': ()
|
||||||
21..22 'x': u32
|
21..22 'x': u32
|
||||||
30..36 'return': !
|
30..36 'return': !
|
||||||
|
@ -299,12 +297,13 @@ fn test6() {
|
||||||
292..304 '{ loop {}; }': u32
|
292..304 '{ loop {}; }': u32
|
||||||
294..301 'loop {}': !
|
294..301 'loop {}': !
|
||||||
299..301 '{}': ()
|
299..301 '{}': ()
|
||||||
"###);
|
"]],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn diverging_expression_2() {
|
fn diverging_expression_2() {
|
||||||
let t = infer_with_mismatches(
|
check_infer_with_mismatches(
|
||||||
r#"
|
r#"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
fn test1() {
|
fn test1() {
|
||||||
|
@ -312,9 +311,7 @@ fn test1() {
|
||||||
let x: u32 = { loop {}; "foo" };
|
let x: u32 = { loop {}; "foo" };
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
true,
|
expect![[r#"
|
||||||
);
|
|
||||||
assert_snapshot!(t, @r###"
|
|
||||||
11..84 '{ ..." }; }': ()
|
11..84 '{ ..." }; }': ()
|
||||||
54..55 'x': u32
|
54..55 'x': u32
|
||||||
63..81 '{ loop...foo" }': &str
|
63..81 '{ loop...foo" }': &str
|
||||||
|
@ -323,13 +320,14 @@ fn test1() {
|
||||||
74..79 '"foo"': &str
|
74..79 '"foo"': &str
|
||||||
63..81: expected u32, got &str
|
63..81: expected u32, got &str
|
||||||
74..79: expected u32, got &str
|
74..79: expected u32, got &str
|
||||||
"###);
|
"#]],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn diverging_expression_3_break() {
|
fn diverging_expression_3_break() {
|
||||||
let t = infer_with_mismatches(
|
check_infer_with_mismatches(
|
||||||
r#"
|
r"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
fn test1() {
|
fn test1() {
|
||||||
// should give type mismatch
|
// should give type mismatch
|
||||||
|
@ -351,10 +349,8 @@ fn test3() {
|
||||||
// should give type mismatch as well
|
// should give type mismatch as well
|
||||||
let x: u32 = { while true { return; }; };
|
let x: u32 = { while true { return; }; };
|
||||||
}
|
}
|
||||||
"#,
|
",
|
||||||
true,
|
expect![[r"
|
||||||
);
|
|
||||||
assert_snapshot!(t, @r###"
|
|
||||||
11..85 '{ ...} }; }': ()
|
11..85 '{ ...} }; }': ()
|
||||||
54..55 'x': u32
|
54..55 'x': u32
|
||||||
63..82 '{ loop...k; } }': ()
|
63..82 '{ loop...k; } }': ()
|
||||||
|
@ -408,5 +404,6 @@ fn test3() {
|
||||||
407..433: expected u32, got ()
|
407..433: expected u32, got ()
|
||||||
546..564: expected u32, got ()
|
546..564: expected u32, got ()
|
||||||
624..651: expected u32, got ()
|
624..651: expected u32, got ()
|
||||||
"###);
|
"]],
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue