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};
}
/// 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,
|
= 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
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 `_`