Skip to content

Commit 9317204

Browse files
committed
Fix a bug with yielding subtypes of the yield type.
1 parent dcddd80 commit 9317204

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

src/librustc_mir/transform/type_check.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -516,14 +516,16 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
516516
let value_ty = value.ty(mir, tcx);
517517
match mir.yield_ty {
518518
None => span_mirbug!(self, term, "yield in non-generator"),
519-
Some(ty) if ty != value_ty => {
520-
span_mirbug!(self,
521-
term,
522-
"type of yield value is ({:?}, but the yield type is ({:?}",
523-
value_ty,
524-
ty);
519+
Some(ty) => {
520+
if let Err(terr) = self.sub_types(value_ty, ty) {
521+
span_mirbug!(self,
522+
term,
523+
"22 - type of yield value is {:?}, but the yield type is {:?}: {:?}",
524+
value_ty,
525+
ty,
526+
terr);
527+
}
525528
}
526-
_ => (),
527529
}
528530
}
529531
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
#![feature(generators)]
12+
13+
fn bar<'a>() {
14+
let a: &'static str = "hi";
15+
let b: &'a str = a;
16+
17+
|| {
18+
yield a;
19+
yield b;
20+
};
21+
}
22+
23+
fn main() {}

0 commit comments

Comments
 (0)