Skip to content

Commit 36eb09f

Browse files
author
Ariel Ben-Yehuda
committed
Create a FreshFloatTy separate from FreshIntTy
There is no subtyping relationship between the types (or their non-freshened variants), so they can not be merged. Fixes #22645 Fixes #24352 Fixes #23825 Should fix #25235 (no test in issue). Should fix #19976 (test is outdated).
1 parent 2a5a320 commit 36eb09f

File tree

8 files changed

+90
-11
lines changed

8 files changed

+90
-11
lines changed

src/librustc/middle/infer/freshen.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,12 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
129129
.probe(v)
130130
.map(|v| v.to_type(tcx)),
131131
ty::FloatVar(v),
132-
ty::FreshIntTy)
132+
ty::FreshFloatTy)
133133
}
134134

135135
ty::ty_infer(ty::FreshTy(c)) |
136-
ty::ty_infer(ty::FreshIntTy(c)) => {
136+
ty::ty_infer(ty::FreshIntTy(c)) |
137+
ty::ty_infer(ty::FreshFloatTy(c)) => {
137138
if c >= self.freshen_count {
138139
tcx.sess.bug(
139140
&format!("Encountered a freshend type with id {} \

src/librustc/middle/traits/select.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1685,7 +1685,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16851685
ty::ty_err => ok_if(Vec::new()),
16861686

16871687
ty::ty_infer(ty::FreshTy(_))
1688-
| ty::ty_infer(ty::FreshIntTy(_)) => {
1688+
| ty::ty_infer(ty::FreshIntTy(_))
1689+
| ty::ty_infer(ty::FreshFloatTy(_)) => {
16891690
self.tcx().sess.bug(
16901691
&format!(
16911692
"asked to assemble builtin bounds of unexpected type: {}",
@@ -1747,7 +1748,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
17471748
ty::ty_projection(..) |
17481749
ty::ty_infer(ty::TyVar(_)) |
17491750
ty::ty_infer(ty::FreshTy(_)) |
1750-
ty::ty_infer(ty::FreshIntTy(_)) => {
1751+
ty::ty_infer(ty::FreshIntTy(_)) |
1752+
ty::ty_infer(ty::FreshFloatTy(_)) => {
17511753
self.tcx().sess.bug(
17521754
&format!(
17531755
"asked to assemble constituent types of unexpected type: {}",

src/librustc/middle/ty.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1688,11 +1688,8 @@ pub enum InferTy {
16881688
/// unbound type variable. This is convenient for caching etc. See
16891689
/// `middle::infer::freshen` for more details.
16901690
FreshTy(u32),
1691-
1692-
// FIXME -- once integral fallback is impl'd, we should remove
1693-
// this type. It's only needed to prevent spurious errors for
1694-
// integers whose type winds up never being constrained.
16951691
FreshIntTy(u32),
1692+
FreshFloatTy(u32)
16961693
}
16971694

16981695
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug, Copy)]
@@ -1764,6 +1761,7 @@ impl fmt::Debug for InferTy {
17641761
FloatVar(ref v) => v.fmt(f),
17651762
FreshTy(v) => write!(f, "FreshTy({:?})", v),
17661763
FreshIntTy(v) => write!(f, "FreshIntTy({:?})", v),
1764+
FreshFloatTy(v) => write!(f, "FreshFloatTy({:?})", v)
17671765
}
17681766
}
17691767
}
@@ -3765,7 +3763,7 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {
37653763
}
37663764

37673765
// Scalar and unique types are sendable, and durable
3768-
ty_infer(ty::FreshIntTy(_)) |
3766+
ty_infer(ty::FreshIntTy(_)) | ty_infer(ty::FreshFloatTy(_)) |
37693767
ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
37703768
ty_bare_fn(..) | ty::ty_char => {
37713769
TC::None
@@ -4315,6 +4313,7 @@ pub fn type_is_fresh(ty: Ty) -> bool {
43154313
match ty.sty {
43164314
ty_infer(FreshTy(_)) => true,
43174315
ty_infer(FreshIntTy(_)) => true,
4316+
ty_infer(FreshFloatTy(_)) => true,
43184317
_ => false
43194318
}
43204319
}
@@ -5016,6 +5015,7 @@ pub fn ty_sort_string<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> String {
50165015
ty_infer(FloatVar(_)) => "floating-point variable".to_string(),
50175016
ty_infer(FreshTy(_)) => "skolemized type".to_string(),
50185017
ty_infer(FreshIntTy(_)) => "skolemized integral type".to_string(),
5018+
ty_infer(FreshFloatTy(_)) => "skolemized floating-point type".to_string(),
50195019
ty_projection(_) => "associated type".to_string(),
50205020
ty_param(ref p) => {
50215021
if p.space == subst::SelfSpace {

src/librustc/middle/ty_match.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Match<'a, 'tcx> {
6767

6868
match (&a.sty, &b.sty) {
6969
(_, &ty::ty_infer(ty::FreshTy(_))) |
70-
(_, &ty::ty_infer(ty::FreshIntTy(_))) => {
70+
(_, &ty::ty_infer(ty::FreshIntTy(_))) |
71+
(_, &ty::ty_infer(ty::FreshFloatTy(_))) => {
7172
Ok(a)
7273
}
7374

src/librustc/util/ppaux.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,8 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
349349
ty::FloatVar(ref vid) if print_var_ids => vid.repr(cx),
350350
ty::TyVar(_) | ty::IntVar(_) | ty::FloatVar(_) => format!("_"),
351351
ty::FreshTy(v) => format!("FreshTy({})", v),
352-
ty::FreshIntTy(v) => format!("FreshIntTy({})", v)
352+
ty::FreshIntTy(v) => format!("FreshIntTy({})", v),
353+
ty::FreshFloatTy(v) => format!("FreshFloatTy({})", v)
353354
}
354355
}
355356

src/test/compile-fail/issue-22645.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::ops::Add;
12+
13+
trait Scalar {}
14+
impl Scalar for f64 {}
15+
16+
struct Bob;
17+
18+
impl<RHS: Scalar> Add <RHS> for Bob {
19+
type Output = Bob;
20+
fn add(self, rhs : RHS) -> Bob {}
21+
}
22+
23+
fn main() {
24+
let b = Bob + 3.5;
25+
b + 3 //~ ERROR: is not implemented
26+
//~^ ERROR: is not implemented
27+
//~^^ ERROR: is not implemented
28+
//~^^^ ERROR: mismatched types
29+
}

src/test/compile-fail/issue-24352.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
1.0f64 - 1.0;
13+
1.0f64 - 1 //~ ERROR: is not implemented
14+
//~^ ERROR: is not implemented
15+
}

src/test/run-pass/issue-23825.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
trait Stringify {
12+
fn to_string(&self) -> String;
13+
}
14+
15+
impl Stringify for u32 {
16+
fn to_string(&self) -> String { format!("u32: {}", *self) }
17+
}
18+
19+
impl Stringify for f32 {
20+
fn to_string(&self) -> String { format!("f32: {}", *self) }
21+
}
22+
23+
fn print<T: Stringify>(x: T) -> String {
24+
x.to_string()
25+
}
26+
27+
fn main() {
28+
assert_eq!(&print(5), "u32: 5");
29+
assert_eq!(&print(5.0), "f32: 5");
30+
}

0 commit comments

Comments
 (0)