Skip to content

Commit 4847294

Browse files
Fix switched types in type mismatch
1 parent 6537fd1 commit 4847294

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

src/librustc_typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4194,7 +4194,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
41944194
// type of the lvalue it is referencing, and not some
41954195
// supertype thereof.
41964196
let init_ty = self.check_expr_with_lvalue_pref(init, LvaluePreference::from_mutbl(m));
4197-
self.demand_eqtype(init.span, init_ty, local_ty);
4197+
self.demand_eqtype(init.span, local_ty, init_ty);
41984198
init_ty
41994199
} else {
42004200
self.check_expr_coercable_to_type(init, local_ty)

src/test/ui/switched-expectations.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let var = 10i32;
13+
let ref string: String = var; //~ ERROR mismatched types [E0308]
14+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/switched-expectations.rs:13:30
3+
|
4+
13 | let ref string: String = var; //~ ERROR mismatched types [E0308]
5+
| ^^^ expected struct `std::string::String`, found i32
6+
|
7+
= note: expected type `std::string::String`
8+
found type `i32`
9+
10+
error: aborting due to previous error
11+

0 commit comments

Comments
 (0)