about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-05-13 15:42:45 +0000
committerbors <bors@rust-lang.org>2015-05-13 15:42:45 +0000
commit222cd73b8a422d2c4124375f6aaffd2663bb9718 (patch)
tree47922b9cae608808b0aea070e8a1367381d4af74 /src
parentaf41097b4906fdbd395b74f7de17f84f1666fe7a (diff)
parent36eb09f356ef49e94dc367467325fce6048273c8 (diff)
downloadrust-222cd73b8a422d2c4124375f6aaffd2663bb9718.tar.gz
rust-222cd73b8a422d2c4124375f6aaffd2663bb9718.zip
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).
Diffstat (limited to 'src')
-rw-r--r--src/librustc/middle/infer/freshen.rs5
-rw-r--r--src/librustc/middle/traits/select.rs6
-rw-r--r--src/librustc/middle/ty.rs10
-rw-r--r--src/librustc/middle/ty_match.rs3
-rw-r--r--src/librustc/util/ppaux.rs3
-rw-r--r--src/test/compile-fail/issue-22645.rs29
-rw-r--r--src/test/compile-fail/issue-24352.rs15
-rw-r--r--src/test/run-pass/issue-23825.rs30
8 files changed, 90 insertions, 11 deletions
diff --git a/src/librustc/middle/infer/freshen.rs b/src/librustc/middle/infer/freshen.rs
index d93d13beec8..111cf68726c 100644
--- a/src/librustc/middle/infer/freshen.rs
+++ b/src/librustc/middle/infer/freshen.rs
@@ -129,11 +129,12 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
                                                       .probe(v)
                                                       .map(|v| v.to_type(tcx)),
                     ty::FloatVar(v),
-                    ty::FreshIntTy)
+                    ty::FreshFloatTy)
             }
 
             ty::ty_infer(ty::FreshTy(c)) |
-            ty::ty_infer(ty::FreshIntTy(c)) => {
+            ty::ty_infer(ty::FreshIntTy(c)) |
+            ty::ty_infer(ty::FreshFloatTy(c)) => {
                 if c >= self.freshen_count {
                     tcx.sess.bug(
                         &format!("Encountered a freshend type with id {} \
diff --git a/src/librustc/middle/traits/select.rs b/src/librustc/middle/traits/select.rs
index cb889b76eac..8011d296263 100644
--- a/src/librustc/middle/traits/select.rs
+++ b/src/librustc/middle/traits/select.rs
@@ -1773,7 +1773,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
             ty::ty_err => ok_if(Vec::new()),
 
             ty::ty_infer(ty::FreshTy(_))
-            | ty::ty_infer(ty::FreshIntTy(_)) => {
+            | ty::ty_infer(ty::FreshIntTy(_))
+            | ty::ty_infer(ty::FreshFloatTy(_)) => {
                 self.tcx().sess.bug(
                     &format!(
                         "asked to assemble builtin bounds of unexpected type: {}",
@@ -1835,7 +1836,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
             ty::ty_projection(..) |
             ty::ty_infer(ty::TyVar(_)) |
             ty::ty_infer(ty::FreshTy(_)) |
-            ty::ty_infer(ty::FreshIntTy(_)) => {
+            ty::ty_infer(ty::FreshIntTy(_)) |
+            ty::ty_infer(ty::FreshFloatTy(_)) => {
                 self.tcx().sess.bug(
                     &format!(
                         "asked to assemble constituent types of unexpected type: {}",
diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs
index 9054cd65473..e988423ac57 100644
--- a/src/librustc/middle/ty.rs
+++ b/src/librustc/middle/ty.rs
@@ -1697,11 +1697,8 @@ pub enum InferTy {
     /// unbound type variable. This is convenient for caching etc. See
     /// `middle::infer::freshen` for more details.
     FreshTy(u32),
-
-    // FIXME -- once integral fallback is impl'd, we should remove
-    // this type. It's only needed to prevent spurious errors for
-    // integers whose type winds up never being constrained.
     FreshIntTy(u32),
+    FreshFloatTy(u32)
 }
 
 #[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Debug, Copy)]
@@ -1773,6 +1770,7 @@ impl fmt::Debug for InferTy {
             FloatVar(ref v) => v.fmt(f),
             FreshTy(v) => write!(f, "FreshTy({:?})", v),
             FreshIntTy(v) => write!(f, "FreshIntTy({:?})", v),
+            FreshFloatTy(v) => write!(f, "FreshFloatTy({:?})", v)
         }
     }
 }
@@ -3775,7 +3773,7 @@ pub fn type_contents<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> TypeContents {
             }
 
             // Scalar and unique types are sendable, and durable
-            ty_infer(ty::FreshIntTy(_)) |
+            ty_infer(ty::FreshIntTy(_)) | ty_infer(ty::FreshFloatTy(_)) |
             ty_bool | ty_int(_) | ty_uint(_) | ty_float(_) |
             ty_bare_fn(..) | ty::ty_char => {
                 TC::None
@@ -4325,6 +4323,7 @@ pub fn type_is_fresh(ty: Ty) -> bool {
     match ty.sty {
       ty_infer(FreshTy(_)) => true,
       ty_infer(FreshIntTy(_)) => true,
+      ty_infer(FreshFloatTy(_)) => true,
       _ => false
     }
 }
@@ -5026,6 +5025,7 @@ pub fn ty_sort_string<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> String {
         ty_infer(FloatVar(_)) => "floating-point variable".to_string(),
         ty_infer(FreshTy(_)) => "skolemized type".to_string(),
         ty_infer(FreshIntTy(_)) => "skolemized integral type".to_string(),
+        ty_infer(FreshFloatTy(_)) => "skolemized floating-point type".to_string(),
         ty_projection(_) => "associated type".to_string(),
         ty_param(ref p) => {
             if p.space == subst::SelfSpace {
diff --git a/src/librustc/middle/ty_match.rs b/src/librustc/middle/ty_match.rs
index bb00fadc39c..526ad0ec1c9 100644
--- a/src/librustc/middle/ty_match.rs
+++ b/src/librustc/middle/ty_match.rs
@@ -67,7 +67,8 @@ impl<'a, 'tcx> TypeRelation<'a, 'tcx> for Match<'a, 'tcx> {
 
         match (&a.sty, &b.sty) {
             (_, &ty::ty_infer(ty::FreshTy(_))) |
-            (_, &ty::ty_infer(ty::FreshIntTy(_))) => {
+            (_, &ty::ty_infer(ty::FreshIntTy(_))) |
+            (_, &ty::ty_infer(ty::FreshFloatTy(_))) => {
                 Ok(a)
             }
 
diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs
index 32ec70c4878..cf2911ab182 100644
--- a/src/librustc/util/ppaux.rs
+++ b/src/librustc/util/ppaux.rs
@@ -349,7 +349,8 @@ pub fn ty_to_string<'tcx>(cx: &ctxt<'tcx>, typ: &ty::TyS<'tcx>) -> String {
             ty::FloatVar(ref vid) if print_var_ids => vid.repr(cx),
             ty::TyVar(_) | ty::IntVar(_) | ty::FloatVar(_) => format!("_"),
             ty::FreshTy(v) => format!("FreshTy({})", v),
-            ty::FreshIntTy(v) => format!("FreshIntTy({})", v)
+            ty::FreshIntTy(v) => format!("FreshIntTy({})", v),
+            ty::FreshFloatTy(v) => format!("FreshFloatTy({})", v)
         }
     }
 
diff --git a/src/test/compile-fail/issue-22645.rs b/src/test/compile-fail/issue-22645.rs
new file mode 100644
index 00000000000..8677934fd64
--- /dev/null
+++ b/src/test/compile-fail/issue-22645.rs
@@ -0,0 +1,29 @@
+// Copyright 2015 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.
+
+use std::ops::Add;
+
+trait Scalar {}
+impl Scalar for f64 {}
+
+struct Bob;
+
+impl<RHS: Scalar> Add <RHS> for Bob {
+  type Output = Bob;
+  fn add(self, rhs : RHS) -> Bob {}
+}
+
+fn main() {
+  let b = Bob + 3.5;
+  b + 3 //~ ERROR: is not implemented
+  //~^ ERROR: is not implemented
+  //~^^ ERROR: is not implemented
+  //~^^^ ERROR: mismatched types
+}
diff --git a/src/test/compile-fail/issue-24352.rs b/src/test/compile-fail/issue-24352.rs
new file mode 100644
index 00000000000..0fbc634826b
--- /dev/null
+++ b/src/test/compile-fail/issue-24352.rs
@@ -0,0 +1,15 @@
+// Copyright 2015 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.
+
+fn main() {
+    1.0f64 - 1.0;
+    1.0f64 - 1 //~ ERROR: is not implemented
+    //~^ ERROR: is not implemented
+}
diff --git a/src/test/run-pass/issue-23825.rs b/src/test/run-pass/issue-23825.rs
new file mode 100644
index 00000000000..1b857d94c72
--- /dev/null
+++ b/src/test/run-pass/issue-23825.rs
@@ -0,0 +1,30 @@
+// Copyright 2015 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.
+
+trait Stringify {
+    fn to_string(&self) -> String;
+}
+
+impl Stringify for u32 {
+    fn to_string(&self) -> String { format!("u32: {}", *self) }
+}
+
+impl Stringify for f32 {
+    fn to_string(&self) -> String { format!("f32: {}", *self) }
+}
+
+fn print<T: Stringify>(x: T) -> String {
+    x.to_string()
+}
+
+fn main() {
+    assert_eq!(&print(5), "u32: 5");
+    assert_eq!(&print(5.0), "f32: 5");
+}