Skip to content

Commit

Permalink
Update ui test
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Apr 21, 2017
1 parent 7d3284e commit 7ce1eb7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 30 deletions.
23 changes: 4 additions & 19 deletions src/librustc_typeck/check/coercion.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -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::<hir::Expr>(&[], source, target)).is_ok();

//*self.inh.fulfillment_cx.borrow_mut() = saved_fulfillment_cx;

result
self.probe(|_| coerce.coerce::<hir::Expr>(&[], source, target)).is_ok()
}

/// Given some expressions, their known unified type and another expression,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_typeck/check/demand.rs
Expand Up @@ -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")));
}
}
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/span/coerce-suggestions.rs
Expand Up @@ -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
Expand Down
14 changes: 5 additions & 9 deletions src/test/ui/span/coerce-suggestions.stderr
Expand Up @@ -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
Expand All @@ -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 `_`
Expand Down

0 comments on commit 7ce1eb7

Please sign in to comment.