diff --git a/src/libcollections/bench.rs b/src/libcollections/bench.rs index 107f6031c1156..b83c9e81a2e2e 100644 --- a/src/libcollections/bench.rs +++ b/src/libcollections/bench.rs @@ -22,13 +22,13 @@ macro_rules! map_insert_rand_bench { let mut rng = rand::weak_rng(); for _ in 0..n { - let i = rng.gen() % n; + let i = rng.gen::() % n; map.insert(i, i); } // measure b.iter(|| { - let k = rng.gen() % n; + let k = rng.gen::() % n; map.insert(k, k); map.remove(&k); }); @@ -77,7 +77,7 @@ macro_rules! map_find_rand_bench { // setup let mut rng = rand::weak_rng(); - let mut keys: Vec<_> = (0..n).map(|_| rng.gen() % n).collect(); + let mut keys: Vec<_> = (0..n).map(|_| rng.gen::() % n).collect(); for &k in &keys { map.insert(k, k); diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 88a729a3db09e..1fa01f70d0e84 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -1146,7 +1146,8 @@ pub trait AdditiveIterator { /// /// let a = [1i32, 2, 3, 4, 5]; /// let mut it = a.iter().cloned(); - /// assert!(it.sum() == 15); + /// let sum: i32 = it.sum(); + /// assert!(sum == 15); /// ``` fn sum(self) -> A; } diff --git a/src/librand/distributions/mod.rs b/src/librand/distributions/mod.rs index 5a85552dc384e..642c4e59b41aa 100644 --- a/src/librand/distributions/mod.rs +++ b/src/librand/distributions/mod.rs @@ -257,7 +257,7 @@ fn ziggurat( return zero_case(rng, u); } // algebraically equivalent to f1 + DRanU()*(f0 - f1) < 1 - if f_tab[i + 1] + (f_tab[i] - f_tab[i + 1]) * rng.gen() < pdf(x) { + if f_tab[i + 1] + (f_tab[i] - f_tab[i + 1]) * rng.gen::() < pdf(x) { return x; } } diff --git a/src/librand/distributions/range.rs b/src/librand/distributions/range.rs index 6eb1d68a081aa..021c4e5a17e0b 100644 --- a/src/librand/distributions/range.rs +++ b/src/librand/distributions/range.rs @@ -152,7 +152,7 @@ macro_rules! float_impl { } } fn sample_range(r: &Range<$ty>, rng: &mut R) -> $ty { - r.low + r.range * rng.gen() + r.low + r.range * rng.gen::<$ty>() } } } diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index c409c8fb13f14..839a6e7734085 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -25,7 +25,7 @@ use middle::ty::*; use middle::ty; use std::cmp::Ordering; use std::fmt; -use std::iter::{range_inclusive, AdditiveIterator, FromIterator, IntoIterator, repeat}; +use std::iter::{range_inclusive, FromIterator, IntoIterator, repeat}; use std::num::Float; use std::slice; use syntax::ast::{self, DUMMY_NODE_ID, NodeId, Pat}; @@ -61,6 +61,8 @@ struct Matrix<'a>(Vec>); /// ++++++++++++++++++++++++++ impl<'a> fmt::Debug for Matrix<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + use std::ops::Add; + try!(write!(f, "\n")); let &Matrix(ref m) = self; @@ -76,7 +78,8 @@ impl<'a> fmt::Debug for Matrix<'a> { pretty_printed_matrix.iter().map(|row| row[col].len()).max().unwrap_or(0) }).collect(); - let total_width = column_widths.iter().cloned().sum() + column_count * 3 + 1; + // FIXME(japaric) using `sum()` asks for type annotations + let total_width = column_widths.iter().cloned().fold(0, Add::add) + column_count * 3 + 1; let br = repeat('+').take(total_width).collect::(); try!(write!(f, "{}\n", br)); for row in pretty_printed_matrix { diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 635ec09d3394c..31913ab2e2c79 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -5755,26 +5755,30 @@ pub fn closure_upvars<'tcx>(typer: &mc::Typer<'tcx>, } } -pub fn is_binopable<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>, op: ast::BinOp) -> bool { +pub fn is_builtin_binop<'tcx>(cx: &ctxt<'tcx>, + lhs: Ty<'tcx>, + rhs: Ty<'tcx>, + op: ast::BinOp) + -> bool { #![allow(non_upper_case_globals)] - static tycat_other: int = 0; - static tycat_bool: int = 1; - static tycat_char: int = 2; - static tycat_int: int = 3; - static tycat_float: int = 4; - static tycat_raw_ptr: int = 6; - - static opcat_add: int = 0; - static opcat_sub: int = 1; - static opcat_mult: int = 2; - static opcat_shift: int = 3; - static opcat_rel: int = 4; - static opcat_eq: int = 5; - static opcat_bit: int = 6; - static opcat_logic: int = 7; - static opcat_mod: int = 8; - - fn opcat(op: ast::BinOp) -> int { + const tycat_other: usize = 0; + const tycat_bool: usize = 1; + const tycat_char: usize = 2; + const tycat_int: usize = 3; + const tycat_float: usize = 4; + const tycat_raw_ptr: usize = 5; + + const opcat_add: usize = 0; + const opcat_sub: usize = 1; + const opcat_mult: usize = 2; + const opcat_shift: usize = 3; + const opcat_rel: usize = 4; + const opcat_eq: usize = 5; + const opcat_bit: usize = 6; + const opcat_logic: usize = 7; + const opcat_mod: usize = 8; + + fn opcat(op: ast::BinOp) -> usize { match op.node { ast::BiAdd => opcat_add, ast::BiSub => opcat_sub, @@ -5797,7 +5801,7 @@ pub fn is_binopable<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>, op: ast::BinOp) -> bool } } - fn tycat<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> int { + fn tycat<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>) -> usize { if type_is_simd(cx, ty) { return tycat(cx, simd_type(cx, ty)) } @@ -5811,8 +5815,8 @@ pub fn is_binopable<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>, op: ast::BinOp) -> bool } } - static t: bool = true; - static f: bool = false; + const t: bool = true; + const f: bool = false; let tbl = [ // +, -, *, shift, rel, ==, bit, logic, mod @@ -5821,10 +5825,16 @@ pub fn is_binopable<'tcx>(cx: &ctxt<'tcx>, ty: Ty<'tcx>, op: ast::BinOp) -> bool /*char*/ [f, f, f, f, t, t, f, f, f], /*int*/ [t, t, t, t, t, t, t, f, t], /*float*/ [t, t, t, f, t, t, f, f, f], - /*bot*/ [t, t, t, t, t, t, t, t, t], /*raw ptr*/ [f, f, f, f, t, t, f, f, f]]; - return tbl[tycat(cx, ty) as uint ][opcat(op) as uint]; + let lhs_cat = tycat(cx, lhs); + let rhs_cat = tycat(cx, rhs); + + if lhs_cat == rhs_cat { + tbl[lhs_cat][opcat(op)] + } else { + false + } } // Returns the repeat count for a repeating vector expression. diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index fd6ba79ec21bb..9f5916c011760 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -2683,8 +2683,14 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>, unifier: F) where F: FnOnce(), { - debug!(">> typechecking: expr={} expected={}", - expr.repr(fcx.tcx()), expected.repr(fcx.tcx())); + if fcx.inh.node_types.borrow().get(&expr.id).is_some() { + debug!(">> already checked, skipping expr={}", expr.repr(fcx.tcx())); + + return unifier(); + } else { + debug!(">> typechecking: expr={} expected={}", + expr.repr(fcx.tcx()), expected.repr(fcx.tcx())); + } // Checks a method call. fn check_method_call<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, @@ -2881,46 +2887,21 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>, SimpleBinop => NoPreference }; check_expr_with_lvalue_pref(fcx, lhs, lvalue_pref); + check_expr(fcx, rhs); - // Callee does bot / err checking - let lhs_t = - structurally_resolve_type_or_else(fcx, lhs.span, fcx.expr_ty(lhs), || { - if ast_util::is_symmetric_binop(op.node) { - // Try RHS first - check_expr(fcx, &**rhs); - fcx.expr_ty(&**rhs) - } else { - fcx.tcx().types.err - } - }); + let lhs_t = fcx.resolve_type_vars_if_possible(fcx.expr_ty(lhs)); + let rhs_t = fcx.resolve_type_vars_if_possible(fcx.expr_ty(rhs)); - if ty::type_is_integral(lhs_t) && ast_util::is_shift_binop(op.node) { - // Shift is a special case: rhs must be uint, no matter what lhs is - check_expr(fcx, &**rhs); - let rhs_ty = fcx.expr_ty(&**rhs); - let rhs_ty = structurally_resolved_type(fcx, rhs.span, rhs_ty); - if ty::type_is_integral(rhs_ty) { - fcx.write_ty(expr.id, lhs_t); - } else { - fcx.type_error_message( - expr.span, - |actual| { - format!( - "right-hand-side of a shift operation must have integral type, \ - not `{}`", - actual) - }, - rhs_ty, - None); - fcx.write_ty(expr.id, fcx.tcx().types.err); + if ty::is_builtin_binop(tcx, lhs_t, rhs_t, op) { + match op.node { + ast::BiShl | ast::BiShr => { + // NB most built-in binops are restricted to arguments of the same type, `>>` + // and `<<` are the exception. + }, + _ => { + demand::suptype(fcx, rhs.span, rhs_t, lhs_t); + } } - return; - } - - if ty::is_binopable(tcx, lhs_t, op) { - let tvar = fcx.infcx().next_ty_var(); - demand::suptype(fcx, expr.span, tvar, lhs_t); - check_expr_has_type(fcx, &**rhs, tvar); let result_t = match op.node { ast::BiEq | ast::BiNe | ast::BiLt | ast::BiLe | ast::BiGe | @@ -2955,25 +2936,49 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>, } if op.node == ast::BiOr || op.node == ast::BiAnd { - // This is an error; one of the operands must have the wrong - // type - fcx.write_error(expr.id); - fcx.write_error(rhs.id); - fcx.type_error_message(expr.span, - |actual| { - format!("binary operation `{}` cannot be applied \ - to type `{}`", - ast_util::binop_to_string(op.node), - actual) - }, - lhs_t, - None) + if ty::type_is_bool(lhs_t) { + demand::suptype(fcx, rhs.span, rhs_t, lhs_t); + fcx.write_ty(expr.id, lhs_t); + return + } else if ty::type_is_bool(rhs_t) { + demand::suptype(fcx, lhs.span, lhs_t, rhs_t); + fcx.write_ty(expr.id, rhs_t); + return + } else { + // This is an error; one of the operands must have the wrong + // type + fcx.write_error(expr.id); + fcx.write_error(rhs.id); + fcx.type_error_message(expr.span, + |actual| { + format!("binary operation `{}` cannot be applied \ + to type `{}`", + ast_util::binop_to_string(op.node), + actual) + }, + lhs_t, + None) + } } // Check for overloaded operators if not an assignment. let result_t = if is_binop_assignment == SimpleBinop { check_user_binop(fcx, expr, lhs, lhs_t, op, rhs) } else { + // NB currently, `lhs += rhs` is only valid if `lhs` and `rhs` have the same type. This + // won't be true once the `OpAssign` traits land as they'll allow overloading the RHS + if ty::is_builtin_binop(tcx, lhs_t, lhs_t, op) { + demand::suptype(fcx, rhs.span, rhs_t, lhs_t); + + fcx.write_ty(expr.id, lhs_t); + return + } else if ty::is_builtin_binop(tcx, rhs_t, rhs_t, op) { + demand::suptype(fcx, lhs.span, lhs_t, rhs_t); + + fcx.write_ty(expr.id, rhs_t); + return + } + fcx.type_error_message(expr.span, |actual| { format!("binary assignment \ @@ -2985,7 +2990,6 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>, }, lhs_t, None); - check_expr(fcx, &**rhs); fcx.tcx().types.err }; @@ -3021,7 +3025,6 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>, ast::BiEq => ("eq", lang.eq_trait()), ast::BiNe => ("ne", lang.eq_trait()), ast::BiAnd | ast::BiOr => { - check_expr(fcx, &**rhs); return tcx.types.err; } }; diff --git a/src/libstd/rand/mod.rs b/src/libstd/rand/mod.rs index 5c89144119803..f82066b1e7efe 100644 --- a/src/libstd/rand/mod.rs +++ b/src/libstd/rand/mod.rs @@ -386,7 +386,7 @@ impl Rng for ThreadRng { /// ``` /// use std::rand; /// -/// let x = rand::random(); +/// let x = rand::random::(); /// println!("{}", 2u8 * x); /// /// let y = rand::random::(); diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs index 264e05f5c8d31..b518397cc04d8 100644 --- a/src/libsyntax/ast_util.rs +++ b/src/libsyntax/ast_util.rs @@ -102,20 +102,6 @@ pub fn is_by_value_binop(b: BinOp_) -> bool { } } -/// Returns `true` if the binary operator is symmetric in the sense that LHS -/// and RHS must have the same type. So the type of LHS can serve as an hint -/// for the type of RHS and vice versa. -pub fn is_symmetric_binop(b: BinOp_) -> bool { - match b { - BiAdd | BiSub | BiMul | BiDiv | BiRem | - BiBitXor | BiBitAnd | BiBitOr | - BiEq | BiLt | BiLe | BiNe | BiGt | BiGe => { - true - } - _ => false - } -} - /// Returns `true` if the unary operator takes its argument by value pub fn is_by_value_unop(u: UnOp) -> bool { match u { diff --git a/src/test/bench/noise.rs b/src/test/bench/noise.rs index 53c52ae3019f0..a5a0daee7586a 100644 --- a/src/test/bench/noise.rs +++ b/src/test/bench/noise.rs @@ -27,7 +27,7 @@ fn lerp(a: f32, b: f32, v: f32) -> f32 { a * (1.0 - v) + b * v } fn smooth(v: f32) -> f32 { v * v * (3.0 - 2.0 * v) } fn random_gradient(r: &mut R) -> Vec2 { - let v = PI * 2.0 * r.gen(); + let v = PI * 2.0 * r.gen::(); Vec2 { x: v.cos(), y: v.sin() } } diff --git a/src/test/compile-fail/associated-types-ICE-when-projecting-out-of-err.rs b/src/test/compile-fail/associated-types-ICE-when-projecting-out-of-err.rs index edd1b8255ccdc..00ccc61f2681d 100644 --- a/src/test/compile-fail/associated-types-ICE-when-projecting-out-of-err.rs +++ b/src/test/compile-fail/associated-types-ICE-when-projecting-out-of-err.rs @@ -35,5 +35,7 @@ trait Add { fn ice(a: A) { let r = loop {}; r = r + a; - //~^ ERROR binary operation `+` cannot be applied to type `A` + //~^ ERROR the trait `Add` is not implemented for the type `()` + //~| ERROR + // FIXME(#21528) the error should be reported once, not twice } diff --git a/src/test/compile-fail/binop-fail-3.rs b/src/test/compile-fail/binop-fail-3.rs index 097a52b894179..1cd92b6a2565e 100644 --- a/src/test/compile-fail/binop-fail-3.rs +++ b/src/test/compile-fail/binop-fail-3.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-test FIXME(japaric) remove test? + fn foo() -> ! { panic!("quux"); } fn main() { foo() //~ ERROR the type of this value must be known in this context diff --git a/src/test/compile-fail/binop-unknown-lhs.rs b/src/test/compile-fail/binop-unknown-lhs.rs new file mode 100644 index 0000000000000..f23271fe88a90 --- /dev/null +++ b/src/test/compile-fail/binop-unknown-lhs.rs @@ -0,0 +1,14 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn main() { + let x = "5".parse().unwrap(); //~ ERROR unable to infer enough type information about `_` + let y = x + 0u8; +} diff --git a/src/test/compile-fail/issue-11771.rs b/src/test/compile-fail/issue-11771.rs index 2de86e527ef59..8ca307526e926 100644 --- a/src/test/compile-fail/issue-11771.rs +++ b/src/test/compile-fail/issue-11771.rs @@ -10,20 +10,12 @@ fn main() { let x = (); - 1 + - x //~ ERROR mismatched types - //~| expected `_` - //~| found `()` - //~| expected integral variable - //~| found () - ; + 1 + //~ ERROR the trait `core::ops::Add<()>` is not implemented for the type `_` + x //~| ERROR + ; // FIXME(#21528) error should be reported once, not twice let x: () = (); - 1 + - x //~ ERROR mismatched types - //~| expected `_` - //~| found `()` - //~| expected integral variable - //~| found () - ; + 1 + //~ ERROR the trait `core::ops::Add<()>` is not implemented for the type `_` + x //~| ERROR + ; // FIXME(#21528) error should be reported once, not twice } diff --git a/src/test/compile-fail/issue-2149.rs b/src/test/compile-fail/issue-2149.rs index 37dbcaf39bd10..5c360f16a7e0c 100644 --- a/src/test/compile-fail/issue-2149.rs +++ b/src/test/compile-fail/issue-2149.rs @@ -16,7 +16,9 @@ impl vec_monad for Vec { fn bind(&self, mut f: F) where F: FnMut(A) -> Vec { let mut r = panic!(); for elt in self { r = r + f(*elt); } - //~^ ERROR binary operation `+` cannot be applied to type `collections::vec::Vec` + //~^ ERROR the trait `core::ops::Add>` is not implemented + //~| ERROR + // FIXME(#21528) error should be reported once, not twice } } fn main() { diff --git a/src/test/compile-fail/issue-5239-1.rs b/src/test/compile-fail/issue-5239-1.rs index 49a43ee37adca..4c3e7316cd8d8 100644 --- a/src/test/compile-fail/issue-5239-1.rs +++ b/src/test/compile-fail/issue-5239-1.rs @@ -8,9 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// FIXME(japaric) the error message seems a bit weird + // Regression test for issue #5239 fn main() { - let x = |ref x: isize| -> isize { x += 1; }; - //~^ ERROR binary assignment operation `+=` cannot be applied to type `&isize` + let x = |ref x: isize| -> isize { //~ ERROR + x + = + 1 //~ ERROR mismatched types + ; //~| expected `&isize` + //~| found `_` + }; } diff --git a/src/test/compile-fail/shift-various-bad-types.rs b/src/test/compile-fail/shift-various-bad-types.rs index 901ae1d5e2ab1..a390e12a4d9dc 100644 --- a/src/test/compile-fail/shift-various-bad-types.rs +++ b/src/test/compile-fail/shift-various-bad-types.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. + // Test that we can do shifts by any integral type. struct Panolpy { @@ -17,19 +18,24 @@ struct Panolpy { fn foo(p: &Panolpy) { 22 >> p.char; - //~^ ERROR right-hand-side of a shift operation must have integral type + //~^ ERROR the trait `core::ops::Shr` is not implemented for the type `_` + //~| ERROR + // FIXME(#21528) error should be reported once, not twice 22 >> p.str; - //~^ ERROR right-hand-side of a shift operation must have integral type + //~^ ERROR the trait `core::ops::Shr<&str>` is not implemented for the type `_` + //~| ERROR + // FIXME(#21528) error should be reported once, not twice 22 >> p; - //~^ ERROR right-hand-side of a shift operation must have integral type + //~^ ERROR the trait `core::ops::Shr<&Panolpy>` is not implemented for the type `_` + //~| ERROR + // FIXME(#21528) error should be reported once, not twice // We could be more accepting in the case of a type not yet inferred, but not // known to be an integer, but meh. let x; 22 >> x; - //~^ ERROR the type of this value must be known in this context 22 >> 1; // Integer literal types are OK diff --git a/src/test/pretty/issue-929.rs b/src/test/pretty/issue-929.rs index 75a6b919342bf..bc6e7b1171780 100644 --- a/src/test/pretty/issue-929.rs +++ b/src/test/pretty/issue-929.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-test FIXME(japaric) remove test? + fn f() { if (1 == panic!()) { } else { } } fn main() { } diff --git a/src/test/run-pass/early-ret-binop-add.rs b/src/test/run-pass/early-ret-binop-add.rs index 97e873e9aff95..8af350fafa60b 100644 --- a/src/test/run-pass/early-ret-binop-add.rs +++ b/src/test/run-pass/early-ret-binop-add.rs @@ -8,5 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-test FIXME(japaric) remove test? + fn wsucc(n: int) -> int { 0 + { return n + 1 } } pub fn main() { } diff --git a/src/test/run-pass/issue-13352.rs b/src/test/run-pass/issue-13352.rs index a834371203480..f56ac8a646364 100644 --- a/src/test/run-pass/issue-13352.rs +++ b/src/test/run-pass/issue-13352.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-test FIXME(japaric) remove test? + extern crate libc; use std::thunk::Thunk; diff --git a/src/test/run-pass/issue-16560.rs b/src/test/run-pass/issue-16560.rs index 9448e605937f7..1934eb65b946a 100644 --- a/src/test/run-pass/issue-16560.rs +++ b/src/test/run-pass/issue-16560.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-test + #![feature(unboxed_closures)] use std::thread; @@ -15,6 +17,7 @@ use std::mem; fn main() { let y = 0u8; + // FIXME(japaric) weird, "unable to infer enough type information" with span on `y` let closure = move |x| y + x; // Check that both closures are capturing by value diff --git a/src/test/run-pass/issue-21634.rs b/src/test/run-pass/issue-21634.rs index e5a2790917ff0..f02de4dfac6fd 100644 --- a/src/test/run-pass/issue-21634.rs +++ b/src/test/run-pass/issue-21634.rs @@ -10,13 +10,13 @@ fn main() { - if let Ok(x) = "3.1415".parse() { + if let Ok(x) = "3.1415".parse::() { assert_eq!(false, x <= 0.0); } - if let Ok(x) = "3.1415".parse() { + if let Ok(x) = "3.1415".parse::() { assert_eq!(3.1415, x + 0.0); } - if let Ok(mut x) = "3.1415".parse() { + if let Ok(mut x) = "3.1415".parse::() { assert_eq!(8.1415, { x += 5.0; x }); } } diff --git a/src/test/run-pass/issue-22743.rs b/src/test/run-pass/issue-22743.rs new file mode 100644 index 0000000000000..75927822d220d --- /dev/null +++ b/src/test/run-pass/issue-22743.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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use std::ops::Mul; + +pub struct Foo { + x: f64, +} + +impl Mul for f64 { + type Output = Foo; + + fn mul(self, rhs: Foo) -> Foo { + println!("Multiplying!"); + rhs + } +} + +pub fn main() { + let f: Foo = Foo { x: 5.0 }; + let val: f64 = 3.0; + let f2: Foo = val * f; +} diff --git a/src/test/run-pass/issue-8460.rs b/src/test/run-pass/issue-8460.rs index 00339a4e84b2b..74f23128d8807 100644 --- a/src/test/run-pass/issue-8460.rs +++ b/src/test/run-pass/issue-8460.rs @@ -21,19 +21,19 @@ fn main() { assert!(thread::spawn(move|| { min_val::() / -1; }).join().is_err()); assert!(thread::spawn(move|| { min_val::() / -1; }).join().is_err()); assert!(thread::spawn(move|| { min_val::() / -1; }).join().is_err()); - assert!(thread::spawn(move|| { 1isize / zero(); }).join().is_err()); - assert!(thread::spawn(move|| { 1i8 / zero(); }).join().is_err()); - assert!(thread::spawn(move|| { 1i16 / zero(); }).join().is_err()); - assert!(thread::spawn(move|| { 1i32 / zero(); }).join().is_err()); - assert!(thread::spawn(move|| { 1i64 / zero(); }).join().is_err()); + assert!(thread::spawn(move|| { 1isize / zero::(); }).join().is_err()); + assert!(thread::spawn(move|| { 1i8 / zero::(); }).join().is_err()); + assert!(thread::spawn(move|| { 1i16 / zero::(); }).join().is_err()); + assert!(thread::spawn(move|| { 1i32 / zero::(); }).join().is_err()); + assert!(thread::spawn(move|| { 1i64 / zero::(); }).join().is_err()); assert!(thread::spawn(move|| { min_val::() % -1; }).join().is_err()); assert!(thread::spawn(move|| { min_val::() % -1; }).join().is_err()); assert!(thread::spawn(move|| { min_val::() % -1; }).join().is_err()); assert!(thread::spawn(move|| { min_val::() % -1; }).join().is_err()); assert!(thread::spawn(move|| { min_val::() % -1; }).join().is_err()); - assert!(thread::spawn(move|| { 1isize % zero(); }).join().is_err()); - assert!(thread::spawn(move|| { 1i8 % zero(); }).join().is_err()); - assert!(thread::spawn(move|| { 1i16 % zero(); }).join().is_err()); - assert!(thread::spawn(move|| { 1i32 % zero(); }).join().is_err()); - assert!(thread::spawn(move|| { 1i64 % zero(); }).join().is_err()); + assert!(thread::spawn(move|| { 1isize % zero::(); }).join().is_err()); + assert!(thread::spawn(move|| { 1i8 % zero::(); }).join().is_err()); + assert!(thread::spawn(move|| { 1i16 % zero::(); }).join().is_err()); + assert!(thread::spawn(move|| { 1i32 % zero::(); }).join().is_err()); + assert!(thread::spawn(move|| { 1i64 % zero::(); }).join().is_err()); } diff --git a/src/test/run-pass/reexported-static-methods-cross-crate.rs b/src/test/run-pass/reexported-static-methods-cross-crate.rs index 5399f3cfd3597..1a86e37760a4b 100644 --- a/src/test/run-pass/reexported-static-methods-cross-crate.rs +++ b/src/test/run-pass/reexported-static-methods-cross-crate.rs @@ -17,8 +17,8 @@ use reexported_static_methods::Boz; use reexported_static_methods::Bort; pub fn main() { - assert_eq!(42, Foo::foo()); - assert_eq!(84, Baz::bar()); + assert_eq!(42, int::foo()); + assert_eq!(84, int::bar()); assert!(Boz::boz(1)); assert_eq!("bort()".to_string(), Bort::bort()); }