diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index e75513e924eec..4c1e8689c7b7e 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -169,9 +169,11 @@ pub struct InferCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { /// Caches the results of trait evaluation. pub evaluation_cache: traits::EvaluationCache<'tcx>, - // the set of predicates on which errors have been reported, to - // avoid reporting the same error twice. + /// Set of predicates on which errors have been reported, to + /// avoid reporting the same error twice. pub reported_trait_errors: RefCell>>, + /// Set of selection errors have been reported, to avoid reporting them twice. + pub reported_selection_errors: RefCell)>>, // Sadly, the behavior of projection varies a bit depending on the // stage of compilation. The specifics are given in the @@ -502,6 +504,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'gcx> { evaluation_cache: traits::EvaluationCache::new(), projection_cache: RefCell::new(traits::ProjectionCache::new()), reported_trait_errors: RefCell::new(FxHashSet()), + reported_selection_errors: RefCell::new(FxHashSet()), projection_mode: Reveal::UserFacing, tainted_by_errors_flag: Cell::new(false), err_count_on_creation: self.sess.err_count(), @@ -540,6 +543,7 @@ impl<'a, 'gcx, 'tcx> InferCtxtBuilder<'a, 'gcx, 'tcx> { selection_cache: traits::SelectionCache::new(), evaluation_cache: traits::EvaluationCache::new(), reported_trait_errors: RefCell::new(FxHashSet()), + reported_selection_errors: RefCell::new(FxHashSet()), projection_mode: projection_mode, tainted_by_errors_flag: Cell::new(false), err_count_on_creation: tcx.sess.err_count(), diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index e846d74febfb7..89f667aefb223 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -15,6 +15,7 @@ use super::{ Obligation, ObligationCause, ObligationCauseCode, + ParameterCountMismatch, OutputTypeParameterMismatch, TraitNotObjectSafe, PredicateObligation, @@ -54,11 +55,11 @@ pub struct TraitErrorKey<'tcx> { impl<'a, 'gcx, 'tcx> TraitErrorKey<'tcx> { fn from_error(infcx: &InferCtxt<'a, 'gcx, 'tcx>, e: &FulfillmentError<'tcx>) -> Self { - let predicate = - infcx.resolve_type_vars_if_possible(&e.obligation.predicate); + let predicate = infcx.resolve_type_vars_if_possible(&e.obligation.predicate); + let predicate = infcx.tcx.erase_regions(&predicate); TraitErrorKey { span: e.obligation.cause.span, - predicate: infcx.tcx.erase_regions(&predicate) + predicate: predicate, } } } @@ -523,6 +524,11 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { { let span = obligation.cause.span; + if !self.reported_selection_errors.borrow_mut().insert((span, error.clone())) { + debug!("report_selection_error: skipping duplicate {:?}", error); + return; + } + let mut err = match *error { SelectionError::Unimplemented => { if let ObligationCauseCode::CompareImplMethodObligation { @@ -657,6 +663,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { } } + ParameterCountMismatch(expected_found, ty, def_id) => { + let found_span = self.tcx.hir.span_if_local(def_id); + self.report_arg_count_mismatch(span, + found_span, + expected_found.expected, + expected_found.found, + ty.is_closure()) + } OutputTypeParameterMismatch(ref expected_trait_ref, ref actual_trait_ref, ref e) => { let expected_trait_ref = self.resolve_type_vars_if_possible(&*expected_trait_ref); let actual_trait_ref = self.resolve_type_vars_if_possible(&*actual_trait_ref); @@ -668,49 +682,12 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { self.tcx.hir.span_if_local(did) }); - if let &TypeError::TupleSize(ref expected_found) = e { - // Expected `|x| { }`, found `|x, y| { }` - self.report_arg_count_mismatch(span, - found_span, - expected_found.expected, - expected_found.found, - expected_trait_ty.is_closure()) - } else if let &TypeError::Sorts(ref expected_found) = e { - let expected = if let ty::TyTuple(tys, _) = expected_found.expected.sty { - tys.len() - } else { - 1 - }; - let found = if let ty::TyTuple(tys, _) = expected_found.found.sty { - tys.len() - } else { - 1 - }; - - if expected != found { - // Expected `|| { }`, found `|x, y| { }` - // Expected `fn(x) -> ()`, found `|| { }` - self.report_arg_count_mismatch(span, - found_span, - expected, - found, - expected_trait_ty.is_closure()) - } else { - self.report_type_argument_mismatch(span, - found_span, - expected_trait_ty, - expected_trait_ref, - actual_trait_ref, - e) - } - } else { - self.report_type_argument_mismatch(span, - found_span, - expected_trait_ty, - expected_trait_ref, - actual_trait_ref, - e) - } + self.report_type_argument_mismatch(span, + found_span, + expected_trait_ty, + expected_trait_ref, + actual_trait_ref, + e) } TraitNotObjectSafe(did) => { diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index a7f9cc74c4f58..409a0d73b1394 100644 --- a/src/librustc/traits/mod.rs +++ b/src/librustc/traits/mod.rs @@ -196,12 +196,13 @@ pub type TraitObligations<'tcx> = Vec>; pub type Selection<'tcx> = Vtable<'tcx, PredicateObligation<'tcx>>; -#[derive(Clone,Debug)] +#[derive(Clone, Debug, PartialEq, Eq, Hash)] pub enum SelectionError<'tcx> { Unimplemented, OutputTypeParameterMismatch(ty::PolyTraitRef<'tcx>, ty::PolyTraitRef<'tcx>, ty::error::TypeError<'tcx>), + ParameterCountMismatch(ExpectedFound, Ty<'tcx>, DefId), TraitNotObjectSafe(DefId), } diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index cccc20e5b296b..9f4f7ba2dec58 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -19,7 +19,7 @@ use super::project; use super::project::{normalize_with_depth, Normalized}; use super::{PredicateObligation, TraitObligation, ObligationCause}; use super::{ObligationCauseCode, BuiltinDerivedObligation, ImplDerivedObligation}; -use super::{SelectionError, Unimplemented, OutputTypeParameterMismatch}; +use super::{SelectionError, Unimplemented, ParameterCountMismatch, OutputTypeParameterMismatch}; use super::{ObjectCastObligation, Obligation}; use super::Reveal; use super::TraitNotObjectSafe; @@ -39,6 +39,7 @@ use ty::{self, ToPredicate, ToPolyTraitRef, Ty, TyCtxt, TypeFoldable}; use traits; use ty::fast_reject; use ty::relate::TypeRelation; +use ty::error::TypeError::{TupleSize, Sorts}; use middle::lang_items; use rustc_data_structures::bitvec::BitVector; @@ -2425,7 +2426,42 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { expected_trait_ref.clone(), obligation_trait_ref.clone()) .map(|InferOk { obligations, .. }| self.inferred_obligations.extend(obligations)) - .map_err(|e| OutputTypeParameterMismatch(expected_trait_ref, obligation_trait_ref, e)) + .map_err(|e| { + let self_ty = expected_trait_ref.self_ty(); + match (&self_ty.sty, &e) { + (&ty::TyClosure(def_id, ..), &TupleSize(expected_found)) | + (&ty::TyFnDef(def_id, ..), &TupleSize(expected_found)) => { + // Expected `fn(x)`/`|x| { }`, found `fn(x, y)`/`|x, y| { }` + ParameterCountMismatch(expected_found, self_ty, def_id) + } + (&ty::TyClosure(def_id, ..), &Sorts(expected_found)) | + (&ty::TyFnDef(def_id, ..), &Sorts(expected_found)) => { + // Expected `|| { }`, found `|x, y| { }` + // Expected `fn(x)`, found `|| { }` + let expected = if let ty::TyTuple(tys, _) = expected_found.expected.sty { + tys.len() + } else { + 1 + }; + let found = if let ty::TyTuple(tys, _) = expected_found.found.sty { + tys.len() + } else { + 1 + }; + + if expected != found { + let expected_found = ty::error::ExpectedFound { + expected: expected, + found: found, + }; + ParameterCountMismatch(expected_found, self_ty, def_id) + } else { + OutputTypeParameterMismatch(expected_trait_ref, obligation_trait_ref, e) + } + } + _ => OutputTypeParameterMismatch(expected_trait_ref, obligation_trait_ref, e), + } + }) } fn confirm_builtin_unsize_candidate(&mut self, diff --git a/src/librustc/traits/structural_impls.rs b/src/librustc/traits/structural_impls.rs index 9d0b1035ade49..a91a1c50ecf1d 100644 --- a/src/librustc/traits/structural_impls.rs +++ b/src/librustc/traits/structural_impls.rs @@ -151,6 +151,11 @@ impl<'a, 'tcx> Lift<'tcx> for traits::SelectionError<'a> { fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option { match *self { super::Unimplemented => Some(super::Unimplemented), + super::ParameterCountMismatch(expected_found, ref ty, def_id) => { + tcx.lift(ty).map(|ty| { + super::ParameterCountMismatch(expected_found, ty, def_id) + }) + } super::OutputTypeParameterMismatch(a, b, ref err) => { tcx.lift(&(a, b)).and_then(|(a, b)| { tcx.lift(err).map(|err| { diff --git a/src/librustc/ty/error.rs b/src/librustc/ty/error.rs index e41202771ccbf..7e5d1eb86a9b7 100644 --- a/src/librustc/ty/error.rs +++ b/src/librustc/ty/error.rs @@ -20,14 +20,14 @@ use syntax_pos::Span; use hir; -#[derive(Clone, Copy, Debug)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] pub struct ExpectedFound { pub expected: T, pub found: T, } // Data structures used in type unification -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq, Eq, Hash)] pub enum TypeError<'tcx> { Mismatch, UnsafetyMismatch(ExpectedFound), diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 7d43e0d0659cc..d6b72fefb6dc7 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -613,7 +613,7 @@ pub struct ClosureUpvar<'tcx> { pub ty: Ty<'tcx>, } -#[derive(Clone, Copy, PartialEq)] +#[derive(Clone, Copy, PartialEq, Eq, Hash)] pub enum IntVarValue { IntType(ast::IntTy), UintType(ast::UintTy), diff --git a/src/librustc_data_structures/obligation_forest/mod.rs b/src/librustc_data_structures/obligation_forest/mod.rs index 3515e5c5ede35..e29e28f954ff8 100644 --- a/src/librustc_data_structures/obligation_forest/mod.rs +++ b/src/librustc_data_structures/obligation_forest/mod.rs @@ -261,7 +261,7 @@ impl ObligationForest { /// Convert all remaining obligations to the given error. /// /// This cannot be done during a snapshot. - pub fn to_errors(&mut self, error: E) -> Vec> { + pub fn to_errors(&mut self, error: E) -> Vec> { assert!(!self.in_snapshot()); let mut errors = vec![]; for index in 0..self.nodes.len() { diff --git a/src/test/compile-fail/extern-wrong-value-type.rs b/src/test/compile-fail/extern-wrong-value-type.rs index 576368aef312f..66b06c505e476 100644 --- a/src/test/compile-fail/extern-wrong-value-type.rs +++ b/src/test/compile-fail/extern-wrong-value-type.rs @@ -18,5 +18,4 @@ fn main() { let _x: extern "C" fn() = f; // OK is_fn(f); //~^ ERROR `extern "C" fn() {f}: std::ops::Fn<()>` is not satisfied - //~| ERROR `extern "C" fn() {f}: std::ops::FnOnce<()>` is not satisfied } diff --git a/src/test/compile-fail/fn-trait-formatting.rs b/src/test/compile-fail/fn-trait-formatting.rs index 6377550d3d22f..6d70f54edb429 100644 --- a/src/test/compile-fail/fn-trait-formatting.rs +++ b/src/test/compile-fail/fn-trait-formatting.rs @@ -28,5 +28,4 @@ fn main() { needs_fn(1); //~^ ERROR : std::ops::Fn<(isize,)>` - //~| ERROR : std::ops::FnOnce<(isize,)>` } diff --git a/src/test/compile-fail/issue-22034.rs b/src/test/compile-fail/issue-22034.rs index dfa9520f38bb7..5271ea7991784 100644 --- a/src/test/compile-fail/issue-22034.rs +++ b/src/test/compile-fail/issue-22034.rs @@ -17,6 +17,5 @@ fn main() { let _: &mut Fn() = unsafe { &mut *(ptr as *mut Fn()) //~^ ERROR `(): std::ops::Fn<()>` is not satisfied - //~| ERROR `(): std::ops::FnOnce<()>` is not satisfied }; } diff --git a/src/test/compile-fail/issue-23966.rs b/src/test/compile-fail/issue-23966.rs index 7f9c7a292f2be..544d3c8af2054 100644 --- a/src/test/compile-fail/issue-23966.rs +++ b/src/test/compile-fail/issue-23966.rs @@ -11,5 +11,4 @@ fn main() { "".chars().fold(|_, _| (), ()); //~^ ERROR E0277 - //~| ERROR E0277 } diff --git a/src/test/compile-fail/kindck-impl-type-params.rs b/src/test/compile-fail/kindck-impl-type-params.rs index 2a86cdef9812f..53ad4d1163bfa 100644 --- a/src/test/compile-fail/kindck-impl-type-params.rs +++ b/src/test/compile-fail/kindck-impl-type-params.rs @@ -27,14 +27,12 @@ fn f(val: T) { let t: S = S(marker::PhantomData); let a = &t as &Gettable; //~^ ERROR : std::marker::Send` is not satisfied - //~^^ ERROR : std::marker::Copy` is not satisfied } fn g(val: T) { let t: S = S(marker::PhantomData); let a: &Gettable = &t; //~^ ERROR : std::marker::Send` is not satisfied - //~^^ ERROR : std::marker::Copy` is not satisfied } fn foo<'a>() { diff --git a/src/test/compile-fail/not-panic-safe-2.rs b/src/test/compile-fail/not-panic-safe-2.rs index 7107211fc914b..f12edca5cb910 100644 --- a/src/test/compile-fail/not-panic-safe-2.rs +++ b/src/test/compile-fail/not-panic-safe-2.rs @@ -19,5 +19,4 @@ fn assert() {} fn main() { assert::>>(); //~^ ERROR `std::cell::UnsafeCell: std::panic::RefUnwindSafe` is not satisfied - //~^^ ERROR `std::cell::UnsafeCell: std::panic::RefUnwindSafe` is not satisfied } diff --git a/src/test/compile-fail/not-panic-safe-3.rs b/src/test/compile-fail/not-panic-safe-3.rs index 76c34e4dc0b44..b6dc2d8b04395 100644 --- a/src/test/compile-fail/not-panic-safe-3.rs +++ b/src/test/compile-fail/not-panic-safe-3.rs @@ -19,5 +19,4 @@ fn assert() {} fn main() { assert::>>(); //~^ ERROR `std::cell::UnsafeCell: std::panic::RefUnwindSafe` is not satisfied - //~^^ ERROR `std::cell::UnsafeCell: std::panic::RefUnwindSafe` is not satisfied } diff --git a/src/test/compile-fail/not-panic-safe-4.rs b/src/test/compile-fail/not-panic-safe-4.rs index 177a43e2a7f71..db9c23d4be46a 100644 --- a/src/test/compile-fail/not-panic-safe-4.rs +++ b/src/test/compile-fail/not-panic-safe-4.rs @@ -18,5 +18,4 @@ fn assert() {} fn main() { assert::<&RefCell>(); //~^ ERROR `std::cell::UnsafeCell: std::panic::RefUnwindSafe` is not satisfied - //~^^ ERROR `std::cell::UnsafeCell: std::panic::RefUnwindSafe` is not satisfied } diff --git a/src/test/compile-fail/not-panic-safe-6.rs b/src/test/compile-fail/not-panic-safe-6.rs index f03e1d545a808..0dad8ec1ef65c 100644 --- a/src/test/compile-fail/not-panic-safe-6.rs +++ b/src/test/compile-fail/not-panic-safe-6.rs @@ -18,5 +18,4 @@ fn assert() {} fn main() { assert::<*mut RefCell>(); //~^ ERROR `std::cell::UnsafeCell: std::panic::RefUnwindSafe` is not satisfied - //~^^ ERROR `std::cell::UnsafeCell: std::panic::RefUnwindSafe` is not satisfied } diff --git a/src/test/compile-fail/range_traits-1.rs b/src/test/compile-fail/range_traits-1.rs index 852197177585f..e77d37422dfd7 100644 --- a/src/test/compile-fail/range_traits-1.rs +++ b/src/test/compile-fail/range_traits-1.rs @@ -17,76 +17,70 @@ use std::ops::*; struct AllTheRanges { a: Range, //~^ ERROR PartialOrd - //~^^ ERROR PartialOrd - //~^^^ ERROR Ord - //~^^^^ ERROR binary operation - //~^^^^^ ERROR binary operation - //~^^^^^^ ERROR binary operation - //~^^^^^^^ ERROR binary operation - //~^^^^^^^^ ERROR binary operation - //~^^^^^^^^^ ERROR binary operation - //~^^^^^^^^^^ ERROR binary operation - //~^^^^^^^^^^^ ERROR binary operation + //~| ERROR PartialOrd + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation b: RangeTo, //~^ ERROR PartialOrd - //~^^ ERROR PartialOrd - //~^^^ ERROR Ord - //~^^^^ ERROR binary operation - //~^^^^^ ERROR binary operation - //~^^^^^^ ERROR binary operation - //~^^^^^^^ ERROR binary operation - //~^^^^^^^^ ERROR binary operation - //~^^^^^^^^^ ERROR binary operation - //~^^^^^^^^^^ ERROR binary operation - //~^^^^^^^^^^^ ERROR binary operation + //~| ERROR PartialOrd + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation c: RangeFrom, //~^ ERROR PartialOrd - //~^^ ERROR PartialOrd - //~^^^ ERROR Ord - //~^^^^ ERROR binary operation - //~^^^^^ ERROR binary operation - //~^^^^^^ ERROR binary operation - //~^^^^^^^ ERROR binary operation - //~^^^^^^^^ ERROR binary operation - //~^^^^^^^^^ ERROR binary operation - //~^^^^^^^^^^ ERROR binary operation - //~^^^^^^^^^^^ ERROR binary operation + //~| ERROR PartialOrd + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation d: RangeFull, //~^ ERROR PartialOrd - //~^^ ERROR PartialOrd - //~^^^ ERROR Ord - //~^^^^ ERROR binary operation - //~^^^^^ ERROR binary operation - //~^^^^^^ ERROR binary operation - //~^^^^^^^ ERROR binary operation - //~^^^^^^^^ ERROR binary operation - //~^^^^^^^^^ ERROR binary operation - //~^^^^^^^^^^ ERROR binary operation - //~^^^^^^^^^^^ ERROR binary operation + //~| ERROR PartialOrd + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation e: RangeInclusive, //~^ ERROR PartialOrd - //~^^ ERROR PartialOrd - //~^^^ ERROR Ord - //~^^^^ ERROR binary operation - //~^^^^^ ERROR binary operation - //~^^^^^^ ERROR binary operation - //~^^^^^^^ ERROR binary operation - //~^^^^^^^^ ERROR binary operation - //~^^^^^^^^^ ERROR binary operation - //~^^^^^^^^^^ ERROR binary operation - //~^^^^^^^^^^^ ERROR binary operation + //~| ERROR PartialOrd + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation f: RangeToInclusive, //~^ ERROR PartialOrd - //~^^ ERROR PartialOrd - //~^^^ ERROR Ord - //~^^^^ ERROR binary operation - //~^^^^^ ERROR binary operation - //~^^^^^^ ERROR binary operation - //~^^^^^^^ ERROR binary operation - //~^^^^^^^^ ERROR binary operation - //~^^^^^^^^^ ERROR binary operation - //~^^^^^^^^^^ ERROR binary operation - //~^^^^^^^^^^^ ERROR binary operation + //~| ERROR PartialOrd + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation + //~| ERROR binary operation } fn main() {} diff --git a/src/test/compile-fail/str-mut-idx.rs b/src/test/compile-fail/str-mut-idx.rs index 8851e5e07973c..052df24876ad4 100644 --- a/src/test/compile-fail/str-mut-idx.rs +++ b/src/test/compile-fail/str-mut-idx.rs @@ -16,7 +16,6 @@ fn mutate(s: &mut str) { //~| ERROR `str: std::marker::Sized` is not satisfied s[1usize] = bot(); //~^ ERROR `str: std::ops::Index` is not satisfied - //~| ERROR `str: std::ops::IndexMut` is not satisfied } pub fn main() {} diff --git a/src/test/compile-fail/trait-item-privacy.rs b/src/test/compile-fail/trait-item-privacy.rs index 721d7583230a7..da1d93982dc8b 100644 --- a/src/test/compile-fail/trait-item-privacy.rs +++ b/src/test/compile-fail/trait-item-privacy.rs @@ -108,10 +108,8 @@ fn check_assoc_const() { S::C; // OK // A, B, C are resolved as inherent items, their traits don't need to be in scope C::A; //~ ERROR associated constant `A` is private - //~^ ERROR the trait `assoc_const::C` cannot be made into an object - //~| ERROR the trait bound `assoc_const::C: assoc_const::A` is not satisfied - C::B; // ERROR the trait `assoc_const::C` cannot be made into an object - //~^ ERROR the trait bound `assoc_const::C: assoc_const::B` is not satisfied + //~^ ERROR the trait bound `assoc_const::C: assoc_const::A` is not satisfied + C::B; //~ ERROR the trait bound `assoc_const::C: assoc_const::B` is not satisfied C::C; // OK } diff --git a/src/test/compile-fail/unboxed-closures-unsafe-extern-fn.rs b/src/test/compile-fail/unboxed-closures-unsafe-extern-fn.rs index 2b0a8baf4f23d..5ba93bf483f2d 100644 --- a/src/test/compile-fail/unboxed-closures-unsafe-extern-fn.rs +++ b/src/test/compile-fail/unboxed-closures-unsafe-extern-fn.rs @@ -21,13 +21,11 @@ fn call_it_onceisize>(_: F, _: isize) -> isize { 0 } fn a() { let x = call_it(&square, 22); //~^ ERROR E0277 - //~| ERROR E0277 } fn b() { let y = call_it_mut(&mut square, 22); //~^ ERROR E0277 - //~| ERROR E0277 } fn c() { diff --git a/src/test/compile-fail/unboxed-closures-wrong-abi.rs b/src/test/compile-fail/unboxed-closures-wrong-abi.rs index f6ba25f43685c..ff06f7c559b2a 100644 --- a/src/test/compile-fail/unboxed-closures-wrong-abi.rs +++ b/src/test/compile-fail/unboxed-closures-wrong-abi.rs @@ -21,13 +21,11 @@ fn call_it_onceisize>(_: F, _: isize) -> isize { 0 } fn a() { let x = call_it(&square, 22); //~^ ERROR E0277 - //~| ERROR E0277 } fn b() { let y = call_it_mut(&mut square, 22); //~^ ERROR E0277 - //~| ERROR E0277 } fn c() { diff --git a/src/test/compile-fail/unboxed-closures-wrong-arg-type-extern-fn.rs b/src/test/compile-fail/unboxed-closures-wrong-arg-type-extern-fn.rs index 9d907ffc17f2b..d77750d2a0409 100644 --- a/src/test/compile-fail/unboxed-closures-wrong-arg-type-extern-fn.rs +++ b/src/test/compile-fail/unboxed-closures-wrong-arg-type-extern-fn.rs @@ -22,13 +22,11 @@ fn call_it_onceisize>(_: F, _: isize) -> isize { 0 } fn a() { let x = call_it(&square, 22); //~^ ERROR E0277 - //~| ERROR E0277 } fn b() { let y = call_it_mut(&mut square, 22); //~^ ERROR E0277 - //~| ERROR E0277 } fn c() { diff --git a/src/test/ui/mismatched_types/E0281.stderr b/src/test/ui/mismatched_types/E0281.stderr index 28a649d4c91a4..887412d1be7af 100644 --- a/src/test/ui/mismatched_types/E0281.stderr +++ b/src/test/ui/mismatched_types/E0281.stderr @@ -9,16 +9,5 @@ error[E0281]: type mismatch: `[closure@$DIR/E0281.rs:14:9: 14:24]` implements th | = note: required by `foo` -error[E0281]: type mismatch: `[closure@$DIR/E0281.rs:14:9: 14:24]` implements the trait `std::ops::FnOnce<(std::string::String,)>`, but the trait `std::ops::FnOnce<(usize,)>` is required - --> $DIR/E0281.rs:14:5 - | -14 | foo(|y: String| { }); - | ^^^ --------------- implements `std::ops::FnOnce<(std::string::String,)>` - | | - | requires `std::ops::FnOnce<(usize,)>` - | expected usize, found struct `std::string::String` - | - = note: required by `foo` - -error: aborting due to 2 previous errors +error: aborting due to previous error diff --git a/src/test/ui/mismatched_types/closure-arg-count.rs b/src/test/ui/mismatched_types/closure-arg-count.rs index 284f82d86eb92..847b0383ff044 100644 --- a/src/test/ui/mismatched_types/closure-arg-count.rs +++ b/src/test/ui/mismatched_types/closure-arg-count.rs @@ -8,8 +8,16 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +fn foo() {} +fn bar(x: &usize) {} +fn qux(x: &usize, y: &usize) -> std::cmp::Ordering { panic!() } + fn main() { - [1, 2, 3].sort_by(|| panic!()); - [1, 2, 3].sort_by(|tuple| panic!()); - [1, 2, 3].sort_by(|(tuple, tuple2)| panic!()); + let mut vec = [1, 2, 3]; + vec.sort_by(|| panic!()); + vec.sort_by(|tuple| panic!()); + vec.sort_by(|(tuple, tuple2)| panic!()); + vec.sort_by(foo); + vec.sort_by(bar); + vec.sort_by(qux); } diff --git a/src/test/ui/mismatched_types/closure-arg-count.stderr b/src/test/ui/mismatched_types/closure-arg-count.stderr index c1b880b616273..fa33328594f89 100644 --- a/src/test/ui/mismatched_types/closure-arg-count.stderr +++ b/src/test/ui/mismatched_types/closure-arg-count.stderr @@ -1,59 +1,53 @@ error[E0593]: closure takes 0 arguments but 2 arguments are required - --> $DIR/closure-arg-count.rs:12:15 + --> $DIR/closure-arg-count.rs:17:9 | -12 | [1, 2, 3].sort_by(|| panic!()); - | ^^^^^^^ ----------- takes 0 arguments - | | - | expected closure that takes 2 arguments - -error[E0593]: closure takes 0 arguments but 2 arguments are required - --> $DIR/closure-arg-count.rs:12:15 - | -12 | [1, 2, 3].sort_by(|| panic!()); - | ^^^^^^^ ----------- takes 0 arguments - | | - | expected closure that takes 2 arguments +17 | vec.sort_by(|| panic!()); + | ^^^^^^^ ----------- takes 0 arguments + | | + | expected closure that takes 2 arguments error[E0593]: closure takes 1 argument but 2 arguments are required - --> $DIR/closure-arg-count.rs:13:15 + --> $DIR/closure-arg-count.rs:18:9 | -13 | [1, 2, 3].sort_by(|tuple| panic!()); - | ^^^^^^^ ---------------- takes 1 argument - | | - | expected closure that takes 2 arguments - -error[E0593]: closure takes 1 argument but 2 arguments are required - --> $DIR/closure-arg-count.rs:13:15 - | -13 | [1, 2, 3].sort_by(|tuple| panic!()); - | ^^^^^^^ ---------------- takes 1 argument - | | - | expected closure that takes 2 arguments +18 | vec.sort_by(|tuple| panic!()); + | ^^^^^^^ ---------------- takes 1 argument + | | + | expected closure that takes 2 arguments error[E0308]: mismatched types - --> $DIR/closure-arg-count.rs:14:24 + --> $DIR/closure-arg-count.rs:19:18 | -14 | [1, 2, 3].sort_by(|(tuple, tuple2)| panic!()); - | ^^^^^^^^^^^^^^^ expected &{integer}, found tuple +19 | vec.sort_by(|(tuple, tuple2)| panic!()); + | ^^^^^^^^^^^^^^^ expected &{integer}, found tuple | = note: expected type `&{integer}` found type `(_, _)` error[E0593]: closure takes 1 argument but 2 arguments are required - --> $DIR/closure-arg-count.rs:14:15 + --> $DIR/closure-arg-count.rs:19:9 | -14 | [1, 2, 3].sort_by(|(tuple, tuple2)| panic!()); - | ^^^^^^^ -------------------------- takes 1 argument - | | - | expected closure that takes 2 arguments +19 | vec.sort_by(|(tuple, tuple2)| panic!()); + | ^^^^^^^ -------------------------- takes 1 argument + | | + | expected closure that takes 2 arguments -error[E0593]: closure takes 1 argument but 2 arguments are required - --> $DIR/closure-arg-count.rs:14:15 +error[E0593]: function takes 0 arguments but 2 arguments are required + --> $DIR/closure-arg-count.rs:20:9 + | +11 | fn foo() {} + | ----------- takes 0 arguments +... +20 | vec.sort_by(foo); + | ^^^^^^^ expected function that takes 2 arguments + +error[E0593]: function takes 1 argument but 2 arguments are required + --> $DIR/closure-arg-count.rs:21:9 | -14 | [1, 2, 3].sort_by(|(tuple, tuple2)| panic!()); - | ^^^^^^^ -------------------------- takes 1 argument - | | - | expected closure that takes 2 arguments +12 | fn bar(x: &usize) {} + | -------------------- takes 1 argument +... +21 | vec.sort_by(bar); + | ^^^^^^^ expected function that takes 2 arguments -error: aborting due to 7 previous errors +error: aborting due to 6 previous errors diff --git a/src/test/ui/mismatched_types/issue-36053-2.stderr b/src/test/ui/mismatched_types/issue-36053-2.stderr index adc229aaacc54..ae33431298e77 100644 --- a/src/test/ui/mismatched_types/issue-36053-2.stderr +++ b/src/test/ui/mismatched_types/issue-36053-2.stderr @@ -15,14 +15,5 @@ error[E0281]: type mismatch: `[closure@$DIR/issue-36053-2.rs:17:39: 17:53]` impl | requires `for<'r> std::ops::FnMut<(&'r &str,)>` | expected &str, found str -error[E0281]: type mismatch: `[closure@$DIR/issue-36053-2.rs:17:39: 17:53]` implements the trait `for<'r> std::ops::FnOnce<(&'r str,)>`, but the trait `for<'r> std::ops::FnOnce<(&'r &str,)>` is required - --> $DIR/issue-36053-2.rs:17:32 - | -17 | once::<&str>("str").fuse().filter(|a: &str| true).count(); - | ^^^^^^ -------------- implements `for<'r> std::ops::FnOnce<(&'r str,)>` - | | - | requires `for<'r> std::ops::FnOnce<(&'r &str,)>` - | expected &str, found str - -error: aborting due to 3 previous errors +error: aborting due to 2 previous errors diff --git a/src/test/ui/mismatched_types/unboxed-closures-vtable-mismatch.stderr b/src/test/ui/mismatched_types/unboxed-closures-vtable-mismatch.stderr index e100520e561f5..995a125845477 100644 --- a/src/test/ui/mismatched_types/unboxed-closures-vtable-mismatch.stderr +++ b/src/test/ui/mismatched_types/unboxed-closures-vtable-mismatch.stderr @@ -12,19 +12,5 @@ error[E0281]: type mismatch: `[closure@$DIR/unboxed-closures-vtable-mismatch.rs: | = note: required by `call_it` -error[E0281]: type mismatch: `[closure@$DIR/unboxed-closures-vtable-mismatch.rs:22:23: 22:73]` implements the trait `std::ops::FnOnce<(usize, isize)>`, but the trait `std::ops::FnOnce<(isize, isize)>` is required - --> $DIR/unboxed-closures-vtable-mismatch.rs:25:13 - | -22 | let f = to_fn_mut(|x: usize, y: isize| -> isize { (x as isize) + y }); - | -------------------------------------------------- implements `std::ops::FnOnce<(usize, isize)>` -... -25 | let z = call_it(3, f); - | ^^^^^^^ - | | - | requires `std::ops::FnOnce<(isize, isize)>` - | expected isize, found usize - | - = note: required by `call_it` - -error: aborting due to 2 previous errors +error: aborting due to previous error