From 7ce1eb77c77ce0a56efc7d11ac8003e6a95208d0 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 21 Apr 2017 13:28:31 +0200 Subject: [PATCH] Update ui test --- src/librustc_typeck/check/coercion.rs | 23 ++++------------------ src/librustc_typeck/check/demand.rs | 2 +- src/test/ui/span/coerce-suggestions.rs | 1 - src/test/ui/span/coerce-suggestions.stderr | 14 +++++-------- 4 files changed, 10 insertions(+), 30 deletions(-) diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index a769b55c520ba..d21b5f739bd7b 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -65,8 +65,8 @@ use check::{Diverges, FnCtxt}; use rustc::hir; use rustc::hir::def_id::DefId; use rustc::infer::{Coercion, InferResult, InferOk, TypeTrace}; -use rustc::infer::type_variable::{TypeVariableOrigin}; -use rustc::traits::{self, /*FulfillmentContext,*/ ObligationCause, ObligationCauseCode}; +use rustc::infer::type_variable::TypeVariableOrigin; +use rustc::traits::{self, ObligationCause, ObligationCauseCode}; use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow}; use rustc::ty::{self, LvaluePreference, TypeAndMut, Ty, ClosureSubsts}; @@ -724,28 +724,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } /// Same as `try_coerce()`, but without side-effects. - pub fn can_coerce(&self, - expr_ty: Ty<'tcx>, - target: Ty<'tcx>) - -> bool { - // FIXME: This is a hack, but coercion wasn't made to be run - // in a probe. It leaks obligations and bounds and things out - // into the environment. For now we just save-and-restore the - // fulfillment context. - /*let saved_fulfillment_cx = - mem::replace( - &mut *self.inh.fulfillment_cx.borrow_mut(), - FulfillmentContext::new());*/ + pub fn can_coerce(&self, expr_ty: Ty<'tcx>, target: Ty<'tcx>) -> bool { let source = self.resolve_type_vars_with_obligations(expr_ty); debug!("coercion::can({:?} -> {:?})", source, target); let cause = self.cause(syntax_pos::DUMMY_SP, ObligationCauseCode::ExprAssignable); let coerce = Coerce::new(self, cause); - let result = self.probe(|_| coerce.coerce::(&[], source, target)).is_ok(); - - //*self.inh.fulfillment_cx.borrow_mut() = saved_fulfillment_cx; - - result + self.probe(|_| coerce.coerce::(&[], source, target)).is_ok() } /// Given some expressions, their known unified type and another expression, diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index 0fd98232becfa..4cc3f2dacdfe9 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -93,7 +93,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { ast::DUMMY_NODE_ID); if suggestions.len() > 0 { err.help(&format!("here are some functions which \ - might fulfill your needs:\n - {}", + might fulfill your needs:\n{}", self.get_best_match(&suggestions).join("\n"))); } } diff --git a/src/test/ui/span/coerce-suggestions.rs b/src/test/ui/span/coerce-suggestions.rs index 3177e858ff4fd..bc3122bf71c0e 100644 --- a/src/test/ui/span/coerce-suggestions.rs +++ b/src/test/ui/span/coerce-suggestions.rs @@ -32,7 +32,6 @@ fn main() { //~| NOTE types differ in mutability //~| NOTE expected type `&mut std::string::String` //~| NOTE found type `&std::string::String` - //~| HELP try with `&mut y` test2(&y); //~^ ERROR E0308 //~| NOTE types differ in mutability diff --git a/src/test/ui/span/coerce-suggestions.stderr b/src/test/ui/span/coerce-suggestions.stderr index 6a70b8ff851d7..220b2f471da9a 100644 --- a/src/test/ui/span/coerce-suggestions.stderr +++ b/src/test/ui/span/coerce-suggestions.stderr @@ -18,11 +18,7 @@ error[E0308]: mismatched types | = note: expected type `&str` found type `std::string::String` - = help: here are some functions which might fulfill your needs: - - .as_str() - - .trim() - - .trim_left() - - .trim_right() + = help: try with `&String::new()` error[E0308]: mismatched types --> $DIR/coerce-suggestions.rs:30:10 @@ -34,18 +30,18 @@ error[E0308]: mismatched types found type `&std::string::String` error[E0308]: mismatched types - --> $DIR/coerce-suggestions.rs:36:11 + --> $DIR/coerce-suggestions.rs:35:11 | -36 | test2(&y); +35 | test2(&y); | ^^ types differ in mutability | = note: expected type `&mut i32` found type `&std::string::String` error[E0308]: mismatched types - --> $DIR/coerce-suggestions.rs:42:9 + --> $DIR/coerce-suggestions.rs:41:9 | -42 | f = box f; +41 | f = box f; | ^^^^^ cyclic type of infinite size | = note: expected type `_`