connect NLL type checker to the impl trait code

We now add the suitable `impl Trait` constraints.
This commit is contained in:
Niko Matsakis 2017-12-10 10:23:45 -05:00
parent da63aaa7ab
commit 93afb1affc
14 changed files with 339 additions and 38 deletions

View file

@ -0,0 +1,27 @@
// Copyright 2016 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.
// compile-flags:-Znll -Zborrowck=mir -Zverbose
#![allow(warnings)]
#![feature(conservative_impl_trait)]
trait Foo<'a> {
}
impl<'a, T> Foo<'a> for T { }
fn foo<'a, T>(x: &T) -> impl Foo<'a> {
x
//~^ WARNING not reporting region error due to -Znll
//~| ERROR free region `'_#2r` does not outlive free region `ReEarlyBound(0, 'a)`
}
fn main() {}

View file

@ -0,0 +1,14 @@
warning: not reporting region error due to -Znll
--> $DIR/impl-trait-captures.rs:22:5
|
22 | x
| ^
error: free region `'_#2r` does not outlive free region `ReEarlyBound(0, 'a)`
--> $DIR/impl-trait-captures.rs:22:5
|
22 | x
| ^
error: aborting due to previous error

View file

@ -0,0 +1,51 @@
// Copyright 2016 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.
// compile-flags:-Znll -Zborrowck=mir -Zverbose
#![allow(warnings)]
#![feature(conservative_impl_trait)]
use std::fmt::Debug;
fn no_region<'a, T>(x: Box<T>) -> impl Debug + 'a
//~^ WARNING not reporting region error due to -Znll
where
T: Debug,
{
x
//~^ ERROR `T` does not outlive
}
fn correct_region<'a, T>(x: Box<T>) -> impl Debug + 'a
where
T: 'a + Debug,
{
x
}
fn wrong_region<'a, 'b, T>(x: Box<T>) -> impl Debug + 'a
//~^ WARNING not reporting region error due to -Znll
where
T: 'b + Debug,
{
x
//~^ ERROR `T` does not outlive
}
fn outlives_region<'a, 'b, T>(x: Box<T>) -> impl Debug + 'a
where
T: 'b + Debug,
'b: 'a,
{
x
}
fn main() {}

View file

@ -0,0 +1,26 @@
warning: not reporting region error due to -Znll
--> $DIR/impl-trait-outlives.rs:18:35
|
18 | fn no_region<'a, T>(x: Box<T>) -> impl Debug + 'a
| ^^^^^^^^^^^^^^^
warning: not reporting region error due to -Znll
--> $DIR/impl-trait-outlives.rs:34:42
|
34 | fn wrong_region<'a, 'b, T>(x: Box<T>) -> impl Debug + 'a
| ^^^^^^^^^^^^^^^
error: `T` does not outlive `'_#1r`
--> $DIR/impl-trait-outlives.rs:23:5
|
23 | x
| ^
error: `T` does not outlive `'_#1r`
--> $DIR/impl-trait-outlives.rs:39:5
|
39 | x
| ^
error: aborting due to 2 previous errors