rust/src/test/compile-fail/range-1.rs
bors c2bda2a5bb Auto merge of #21806 - edwardw:new-range-impl, r=alexcrichton
The new `::ops::Range` has separated implementations for each of the
numeric types, while the old `::iter::Range` has one for type `Int`.
However, we do not take output bindings into account when selecting
traits. So it confuses `typeck` and makes the new range does not work as
good as the old one when it comes to type inference.

This patch implements `Iterator` for the new range for one type `Int`.
This limitation could be lifted, however, if we ever reconsider the
output types' role in type inference.

Closes #21595
Closes #21649
Closes #21672
2015-02-01 19:07:11 +00:00

27 lines
930 B
Rust

// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Test range syntax - type errors.
pub fn main() {
// Mixed types.
let _ = 0u32..10i32;
//~^ ERROR start and end of range have incompatible types
// Float => does not implement iterator.
for i in 0f32..42f32 {}
//~^ ERROR the trait `core::num::Int` is not implemented for the type `f32`
// Unsized type.
let arr: &[_] = &[1u32, 2, 3];
let range = *arr..;
//~^ ERROR the trait `core::marker::Sized` is not implemented
}