mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
Infer range types
This commit is contained in:
parent
8b278b1ab6
commit
4992d2bf79
7 changed files with 209 additions and 4 deletions
|
@ -221,6 +221,56 @@ mod collections {
|
|||
assert_eq!("&str", type_at_pos(&db, pos));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_ranges() {
|
||||
let (db, pos) = TestDB::with_position(
|
||||
r#"
|
||||
//- /main.rs crate:main deps:std
|
||||
fn test() {
|
||||
let a = ..;
|
||||
let b = 1..;
|
||||
let c = ..2u32;
|
||||
let d = 1..2usize;
|
||||
let e = ..=10;
|
||||
let f = 'a'..='z';
|
||||
|
||||
let t = (a, b, c, d, e, f);
|
||||
t<|>;
|
||||
}
|
||||
|
||||
//- /std.rs crate:std
|
||||
#[prelude_import] use prelude::*;
|
||||
mod prelude {}
|
||||
|
||||
pub mod ops {
|
||||
pub struct Range<Idx> {
|
||||
pub start: Idx,
|
||||
pub end: Idx,
|
||||
}
|
||||
pub struct RangeFrom<Idx> {
|
||||
pub start: Idx,
|
||||
}
|
||||
struct RangeFull;
|
||||
pub struct RangeInclusive<Idx> {
|
||||
start: Idx,
|
||||
end: Idx,
|
||||
is_empty: u8,
|
||||
}
|
||||
pub struct RangeTo<Idx> {
|
||||
pub end: Idx,
|
||||
}
|
||||
pub struct RangeToInclusive<Idx> {
|
||||
pub end: Idx,
|
||||
}
|
||||
}
|
||||
"#,
|
||||
);
|
||||
assert_eq!(
|
||||
"(RangeFull, RangeFrom<i32>, RangeTo<u32>, Range<usize>, RangeToInclusive<i32>, RangeInclusive<char>)",
|
||||
type_at_pos(&db, pos),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn infer_while_let() {
|
||||
let (db, pos) = TestDB::with_position(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue