fn main()
{
let v : Vec<i32> = Vec::new();
println!("first element of a vector is :{}",v[0]);
println!("Second element of a vector is :{}",v[1]);
println!("Third element of a vector is :{}",v[2]);
println!("Fourth element of a vector is :{}",v[3]);
}
my running: error
thread 'main' panicked at 'index out of bounds: the len is 0 but the index is 0', src\main.rs:5:49
Why compiler do not check index out of bounds for Vec?
Why should it? Compile-time checks are all based on types, but Vec<T> is a single type, no matter the length. It's not as powerful as Idris, if that's what you're looking for (it's possible to emulate something like Idris' Vect n, but not fully, not very cleanly and without proper core support).
Vec would have to become part of the language instead of part of the standard library, built with the language. (Indexing is defined by a trait implementation.) Or at least, the compiler would need special knowledge of how Vec works. Even that would only help so much; the length of a Vec isn't always statically determinable.
For arrays the compiler indeed gives a lint error (through the unconditional_panic lint) when the index is known at compile time. If it is computed at runtime, it won't give an error or warning either.