Skip to content

Commit fd5603b

Browse files
committed
Auto merge of #32228 - jonas-schievink:diag1, r=sanxiyn
Normalize return type when checking for E0269 Fixes #31597 First time dealing with normalization. Maybe `normalize_associated_type` would be better here, but it seems to imply it's only used during trans.
2 parents e68d40e + 96d9408 commit fd5603b

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

src/librustc/middle/liveness.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ use self::VarKind::*;
112112
use dep_graph::DepNode;
113113
use middle::def::*;
114114
use middle::pat_util;
115-
use middle::ty::{self, TyCtxt};
115+
use middle::ty::{self, TyCtxt, ParameterEnvironment};
116+
use middle::traits::{self, ProjectionMode};
117+
use middle::infer;
116118
use lint;
117119
use util::nodemap::NodeMap;
118120

@@ -1490,9 +1492,19 @@ 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() => {
1494-
1495-
if t_ret.is_nil() {
1495+
if self.live_on_entry(entry_ln, self.s.no_ret_var).is_some() => {
1496+
1497+
let param_env = ParameterEnvironment::for_item(&self.ir.tcx, id);
1498+
let infcx = infer::new_infer_ctxt(&self.ir.tcx,
1499+
&self.ir.tcx.tables,
1500+
Some(param_env),
1501+
ProjectionMode::Any);
1502+
let cause = traits::ObligationCause::dummy();
1503+
let norm = traits::fully_normalize(&infcx,
1504+
cause,
1505+
&t_ret);
1506+
1507+
if norm.unwrap().is_nil() {
14961508
// for nil return types, it is ok to not return a value expl.
14971509
} else {
14981510
let ends_with_stmt = match body.expr {

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

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
// Also make sure we don't hit an ICE when the projection can't be known
24+
fn f<T: Make>() -> <T as Make>::Out { loop {} }
25+
26+
// ...and that it works with a blanket impl
27+
trait Tr {
28+
type Assoc;
29+
}
30+
31+
impl<T: Make> Tr for T {
32+
type Assoc = ();
33+
}
34+
35+
fn g<T: Make>() -> <T as Tr>::Assoc { }
36+
37+
fn main() {}

0 commit comments

Comments
 (0)