Skip to content

Commit 222cd73

Browse files
committed
Auto merge of #25344 - arielb1:fresh-float, r=nikomatsakis
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).
2 parents af41097 + 36eb09f commit 222cd73

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
@@ -1773,7 +1773,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
17731773
ty::ty_err => ok_if(Vec::new()),
17741774

17751775
ty::ty_infer(ty::FreshTy(_))
1776-
| ty::ty_infer(ty::FreshIntTy(_)) => {
1776+
| ty::ty_infer(ty::FreshIntTy(_))
1777+
| ty::ty_infer(ty::FreshFloatTy(_)) => {
17771778
self.tcx().sess.bug(
17781779
&format!(
17791780
"asked to assemble builtin bounds of unexpected type: {}",
@@ -1835,7 +1836,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
18351836
ty::ty_projection(..) |
18361837
ty::ty_infer(ty::TyVar(_)) |
18371838
ty::ty_infer(ty::FreshTy(_)) |
1838-
ty::ty_infer(ty::FreshIntTy(_)) => {
1839+
ty::ty_infer(ty::FreshIntTy(_)) |
1840+
ty::ty_infer(ty::FreshFloatTy(_)) => {
18391841
self.tcx().sess.bug(
18401842
&format!(
18411843
"asked to assemble constituent types of unexpected type: {}",

src/librustc/middle/ty.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1697,11 +1697,8 @@ pub enum InferTy {
16971697
/// unbound type variable. This is convenient for caching etc. See
16981698
/// `middle::infer::freshen` for more details.
16991699
FreshTy(u32),
1700-
1701-
// FIXME -- once integral fallback is impl'd, we should remove
1702-
// this type. It's only needed to prevent spurious errors for
1703-
// integers whose type winds up never being constrained.
17041700
FreshIntTy(u32),
1701+
FreshFloatTy(u32)
17051702
}
17061703

17071704
#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug, Copy)]
@@ -1773,6 +1770,7 @@ impl fmt::Debug for InferTy {
17731770
FloatVar(ref v) => v.fmt(f),
17741771
FreshTy(v) => write!(f, "FreshTy({:?})", v),
17751772
FreshIntTy(v) => write!(f, "FreshIntTy({:?})", v),
1773+
FreshFloatTy(v) => write!(f, "FreshFloatTy({:?})", v)
17761774
}
17771775
}
17781776
}
@@ -3775,7 +3773,7 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {
37753773
}
37763774

37773775
// Scalar and unique types are sendable, and durable
3778-
ty_infer(ty::FreshIntTy(_)) |
3776+
ty_infer(ty::FreshIntTy(_)) | ty_infer(ty::FreshFloatTy(_)) |
37793777
ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
37803778
ty_bare_fn(..) | ty::ty_char => {
37813779
TC::None
@@ -4325,6 +4323,7 @@ pub fn type_is_fresh(ty: Ty) -> bool {
43254323
match ty.sty {
43264324
ty_infer(FreshTy(_)) => true,
43274325
ty_infer(FreshIntTy(_)) => true,
4326+
ty_infer(FreshFloatTy(_)) => true,
43284327
_ => false
43294328
}
43304329
}
@@ -5026,6 +5025,7 @@ pub fn ty_sort_string<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> String {
50265025
ty_infer(FloatVar(_)) => "floating-point variable".to_string(),
50275026
ty_infer(FreshTy(_)) => "skolemized type".to_string(),
50285027
ty_infer(FreshIntTy(_)) => "skolemized integral type".to_string(),
5028+
ty_infer(FreshFloatTy(_)) => "skolemized floating-point type".to_string(),
50295029
ty_projection(_) => "associated type".to_string(),
50305030
ty_param(ref p) => {
50315031
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)