librustc: Check structure constructors against their types.
This breaks code like:
struct Point<T> {
x: T,
y: T,
}
let pt = Point::<bool> {
x: 1,
y: 2,
};
Change this code to not contain a type error. For example:
let pt = Point::<int> {
x: 1,
y: 2,
};
Closes #9620.
Closes #15875.
[breaking-change]
This commit is contained in:
parent
3550068b53
commit
103d888f65
3 changed files with 136 additions and 1 deletions
56
src/test/compile-fail/structure-constructor-type-mismatch.rs
Normal file
56
src/test/compile-fail/structure-constructor-type-mismatch.rs
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
// 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.
|
||||
|
||||
struct Point<T> {
|
||||
x: T,
|
||||
y: T,
|
||||
}
|
||||
|
||||
type PointF = Point<f32>;
|
||||
|
||||
struct Pair<T,U> {
|
||||
x: T,
|
||||
y: U,
|
||||
}
|
||||
|
||||
type PairF<U> = Pair<f32,U>;
|
||||
|
||||
fn main() {
|
||||
let pt = PointF {
|
||||
//~^ ERROR expected f32 but found int
|
||||
x: 1i,
|
||||
y: 2i,
|
||||
};
|
||||
|
||||
let pt2 = Point::<f32> {
|
||||
//~^ ERROR expected f32 but found int
|
||||
x: 3i,
|
||||
y: 4i,
|
||||
};
|
||||
|
||||
let pair = PairF {
|
||||
//~^ ERROR expected f32 but found int
|
||||
x: 5i,
|
||||
y: 6i,
|
||||
};
|
||||
|
||||
let pair2 = PairF::<int> {
|
||||
//~^ ERROR expected f32 but found int
|
||||
x: 7i,
|
||||
y: 8i,
|
||||
};
|
||||
|
||||
let pt3 = PointF::<int> {
|
||||
//~^ ERROR wrong number of type arguments
|
||||
x: 9i,
|
||||
y: 10i,
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue