Skip to content

Commit f0b0a4f

Browse files
Normalize return type when checking for E0269
Fixes #31597
1 parent 3317cc9 commit f0b0a4f

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

src/librustc/middle/liveness.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ use dep_graph::DepNode;
113113
use middle::def::*;
114114
use middle::pat_util;
115115
use middle::ty::{self, TyCtxt};
116+
use middle::traits;
117+
use middle::infer;
116118
use lint;
117119
use util::nodemap::NodeMap;
118120

@@ -1490,9 +1492,17 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
14901492

14911493
match fn_ret {
14921494
ty::FnConverging(t_ret)
1493-
if self.live_on_entry(entry_ln, self.s.no_ret_var).is_some() => {
1495+
if self.live_on_entry(entry_ln, self.s.no_ret_var).is_some() => {
14941496

1495-
if t_ret.is_nil() {
1497+
let infcx = infer::new_infer_ctxt(&self.ir.tcx, &self.ir.tcx.tables, None);
1498+
let mut selcx = traits::SelectionContext::new(&infcx);
1499+
let cause = traits::ObligationCause::dummy();
1500+
1501+
let norm = traits::normalize(&mut selcx,
1502+
cause,
1503+
&t_ret);
1504+
1505+
if norm.value.is_nil() {
14961506
// for nil return types, it is ok to not return a value expl.
14971507
} else {
14981508
let ends_with_stmt = match body.expr {

src/test/run-pass/issue-31597.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Copyright 2016 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+
trait Make {
12+
type Out;
13+
14+
fn make() -> Self::Out;
15+
}
16+
17+
impl Make for () {
18+
type Out = ();
19+
20+
fn make() -> Self::Out {}
21+
}
22+
23+
fn main() {}

0 commit comments

Comments
 (0)