Skip to content

Commit 7ce1eb7

Browse files
Update ui test
1 parent 7d3284e commit 7ce1eb7

File tree

4 files changed

+10
-30
lines changed

4 files changed

+10
-30
lines changed

src/librustc_typeck/check/coercion.rs

+4-19
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ use check::{Diverges, FnCtxt};
6565
use rustc::hir;
6666
use rustc::hir::def_id::DefId;
6767
use rustc::infer::{Coercion, InferResult, InferOk, TypeTrace};
68-
use rustc::infer::type_variable::{TypeVariableOrigin};
69-
use rustc::traits::{self, /*FulfillmentContext,*/ ObligationCause, ObligationCauseCode};
68+
use rustc::infer::type_variable::TypeVariableOrigin;
69+
use rustc::traits::{self, ObligationCause, ObligationCauseCode};
7070
use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow};
7171
use rustc::ty::{self, LvaluePreference, TypeAndMut,
7272
Ty, ClosureSubsts};
@@ -724,28 +724,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
724724
}
725725

726726
/// Same as `try_coerce()`, but without side-effects.
727-
pub fn can_coerce(&self,
728-
expr_ty: Ty<'tcx>,
729-
target: Ty<'tcx>)
730-
-> bool {
731-
// FIXME: This is a hack, but coercion wasn't made to be run
732-
// in a probe. It leaks obligations and bounds and things out
733-
// into the environment. For now we just save-and-restore the
734-
// fulfillment context.
735-
/*let saved_fulfillment_cx =
736-
mem::replace(
737-
&mut *self.inh.fulfillment_cx.borrow_mut(),
738-
FulfillmentContext::new());*/
727+
pub fn can_coerce(&self, expr_ty: Ty<'tcx>, target: Ty<'tcx>) -> bool {
739728
let source = self.resolve_type_vars_with_obligations(expr_ty);
740729
debug!("coercion::can({:?} -> {:?})", source, target);
741730

742731
let cause = self.cause(syntax_pos::DUMMY_SP, ObligationCauseCode::ExprAssignable);
743732
let coerce = Coerce::new(self, cause);
744-
let result = self.probe(|_| coerce.coerce::<hir::Expr>(&[], source, target)).is_ok();
745-
746-
//*self.inh.fulfillment_cx.borrow_mut() = saved_fulfillment_cx;
747-
748-
result
733+
self.probe(|_| coerce.coerce::<hir::Expr>(&[], source, target)).is_ok()
749734
}
750735

751736
/// Given some expressions, their known unified type and another expression,

src/librustc_typeck/check/demand.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
9393
ast::DUMMY_NODE_ID);
9494
if suggestions.len() > 0 {
9595
err.help(&format!("here are some functions which \
96-
might fulfill your needs:\n - {}",
96+
might fulfill your needs:\n{}",
9797
self.get_best_match(&suggestions).join("\n")));
9898
}
9999
}

src/test/ui/span/coerce-suggestions.rs

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ fn main() {
3232
//~| NOTE types differ in mutability
3333
//~| NOTE expected type `&mut std::string::String`
3434
//~| NOTE found type `&std::string::String`
35-
//~| HELP try with `&mut y`
3635
test2(&y);
3736
//~^ ERROR E0308
3837
//~| NOTE types differ in mutability

src/test/ui/span/coerce-suggestions.stderr

+5-9
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ error[E0308]: mismatched types
1818
|
1919
= note: expected type `&str`
2020
found type `std::string::String`
21-
= help: here are some functions which might fulfill your needs:
22-
- .as_str()
23-
- .trim()
24-
- .trim_left()
25-
- .trim_right()
21+
= help: try with `&String::new()`
2622

2723
error[E0308]: mismatched types
2824
--> $DIR/coerce-suggestions.rs:30:10
@@ -34,18 +30,18 @@ error[E0308]: mismatched types
3430
found type `&std::string::String`
3531

3632
error[E0308]: mismatched types
37-
--> $DIR/coerce-suggestions.rs:36:11
33+
--> $DIR/coerce-suggestions.rs:35:11
3834
|
39-
36 | test2(&y);
35+
35 | test2(&y);
4036
| ^^ types differ in mutability
4137
|
4238
= note: expected type `&mut i32`
4339
found type `&std::string::String`
4440

4541
error[E0308]: mismatched types
46-
--> $DIR/coerce-suggestions.rs:42:9
42+
--> $DIR/coerce-suggestions.rs:41:9
4743
|
48-
42 | f = box f;
44+
41 | f = box f;
4945
| ^^^^^ cyclic type of infinite size
5046
|
5147
= note: expected type `_`

0 commit comments

Comments
 (0)