Auto merge of #46720 - estebank:issue-46302, r=nikomatsakis

Fix incorrect type mismatch label pointing at return type

CC #46302.
This commit is contained in:
bors 2018-06-29 20:22:03 +00:00
commit 1029775ad5
6 changed files with 41 additions and 16 deletions

View file

@ -13,9 +13,6 @@ LL | | };
error[E0308]: mismatched types
--> $DIR/break-while-condition.rs:26:13
|
LL | fn main() {
| - expected `()` because of default return type
...
LL | / while false { //~ ERROR mismatched types
LL | | break
LL | | }
@ -27,9 +24,6 @@ LL | | }
error[E0308]: mismatched types
--> $DIR/break-while-condition.rs:34:13
|
LL | fn main() {
| - expected `()` because of default return type
...
LL | / while false { //~ ERROR mismatched types
LL | | return
LL | | }

View file

@ -1,8 +1,6 @@
error[E0308]: mismatched types
--> $DIR/issue-50585.rs:12:18
|
LL | fn main() {
| - expected `()` because of default return type
LL | |y: Vec<[(); for x in 0..2 {}]>| {};
| ^^^^^^^^^^^^^^^^ expected usize, found ()
|

View file

@ -0,0 +1,19 @@
// 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 foo() {
let s = "abc";
let u: &str = if true { s[..2] } else { s };
//~^ ERROR mismatched types
}
fn main() {
foo();
}

View file

@ -0,0 +1,15 @@
error[E0308]: mismatched types
--> $DIR/issue-46302.rs:13:27
|
LL | let u: &str = if true { s[..2] } else { s };
| ^^^^^^
| |
| expected &str, found str
| help: consider borrowing here: `&s[..2]`
|
= note: expected type `&str`
found type `str`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0308`.

View file

@ -10,9 +10,6 @@ LL | let t = if true { s[..2] } else { s };
error[E0308]: mismatched types
--> $DIR/str-array-assignment.rs:15:27
|
LL | fn main() {
| - expected `()` because of default return type
...
LL | let u: &str = if true { s[..2] } else { s };
| ^^^^^^
| |