Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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]
- Loading branch information
1 parent
3550068
commit 103d888
Showing
3 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/test/compile-fail/structure-constructor-type-mismatch.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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, | ||
}; | ||
} | ||
|