mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Fix switched types in type mismatch
This commit is contained in:
parent
6537fd184e
commit
484729478b
@ -4194,7 +4194,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||
// type of the lvalue it is referencing, and not some
|
||||
// supertype thereof.
|
||||
let init_ty = self.check_expr_with_lvalue_pref(init, LvaluePreference::from_mutbl(m));
|
||||
self.demand_eqtype(init.span, init_ty, local_ty);
|
||||
self.demand_eqtype(init.span, local_ty, init_ty);
|
||||
init_ty
|
||||
} else {
|
||||
self.check_expr_coercable_to_type(init, local_ty)
|
||||
|
14
src/test/ui/switched-expectations.rs
Normal file
14
src/test/ui/switched-expectations.rs
Normal file
@ -0,0 +1,14 @@
|
||||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
fn main() {
|
||||
let var = 10i32;
|
||||
let ref string: String = var; //~ ERROR mismatched types [E0308]
|
||||
}
|
11
src/test/ui/switched-expectations.stderr
Normal file
11
src/test/ui/switched-expectations.stderr
Normal file
@ -0,0 +1,11 @@
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/switched-expectations.rs:13:30
|
||||
|
|
||||
13 | let ref string: String = var; //~ ERROR mismatched types [E0308]
|
||||
| ^^^ expected struct `std::string::String`, found i32
|
||||
|
|
||||
= note: expected type `std::string::String`
|
||||
found type `i32`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
Reference in New Issue
Block a user