Skip to content

Commit aeb2353

Browse files
committed
Add a UI test that the span for the catch type error is in the right place
1 parent c4b6521 commit aeb2353

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

src/test/ui/catch-block-type-error.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2018 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+
#![feature(catch_expr)]
12+
13+
fn foo() -> Option<()> { Some(()) }
14+
15+
fn main() {
16+
let _: Option<f32> = do catch {
17+
foo()?;
18+
42
19+
//~^ ERROR type mismatch
20+
};
21+
22+
let _: Option<i32> = do catch {
23+
//~^ ERROR type mismatch
24+
foo()?;
25+
};
26+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error[E0271]: type mismatch resolving `<std::option::Option<f32> as std::ops::Try>::Ok == {integer}`
2+
--> $DIR/catch-block-type-error.rs:18:9
3+
|
4+
LL | 42
5+
| ^^ expected f32, found integral variable
6+
|
7+
= note: expected type `f32`
8+
found type `{integer}`
9+
10+
error[E0271]: type mismatch resolving `<std::option::Option<i32> as std::ops::Try>::Ok == ()`
11+
--> $DIR/catch-block-type-error.rs:22:35
12+
|
13+
LL | let _: Option<i32> = do catch {
14+
| ___________________________________^
15+
LL | | //~^ ERROR type mismatch
16+
LL | | foo()?;
17+
LL | | };
18+
| |_____^ expected i32, found ()
19+
|
20+
= note: expected type `i32`
21+
found type `()`
22+
23+
error: aborting due to 2 previous errors
24+
25+
For more information about this error, try `rustc --explain E0271`.

0 commit comments

Comments
 (0)