Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
After inferring regions, scan for any bounds that are due to a lifetime
bound that is likely to change. In that case, it will change to 'static, so then scan down the graph to see whether there are any hard constraints that would prevent 'static from being a valid value here. Report a warning.
- Loading branch information
1 parent
9099577
commit 1e7a6b8
Showing
4 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/test/auxiliary/lifetime_bound_will_change_warning_lib.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright 2012 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. | ||
|
||
#![crate_type = "rlib"] | ||
|
||
// Helper for testing that we get suitable warnings when lifetime | ||
// bound change will cause breakage. | ||
|
||
pub fn just_ref(x: &Fn()) { | ||
} | ||
|
||
pub fn ref_obj(x: &Box<Fn()>) { | ||
// this will change to &Box<Fn()+'static>... | ||
} |
64 changes: 64 additions & 0 deletions
64
src/test/compile-fail/lifetime-bound-will-change-warning.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2012 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. | ||
|
||
// aux-build:lifetime_bound_will_change_warning_lib.rs | ||
|
||
// Test that we get suitable warnings when lifetime bound change will | ||
// cause breakage. | ||
|
||
#![allow(dead_code)] | ||
#![allow(unused_variables)] | ||
#![feature(rustc_attrs)] | ||
|
||
extern crate lifetime_bound_will_change_warning_lib as lib; | ||
|
||
fn just_ref(x: &Fn()) { | ||
} | ||
|
||
fn ref_obj(x: &Box<Fn()>) { | ||
// this will change to &Box<Fn()+'static>... | ||
|
||
// Note: no warning is issued here, because the type of `x` will change to 'static | ||
if false { ref_obj(x); } | ||
} | ||
|
||
fn test1<'a>(x: &'a Box<Fn()+'a>) { | ||
// just_ref will stay the same. | ||
just_ref(&**x) | ||
} | ||
|
||
fn test1cc<'a>(x: &'a Box<Fn()+'a>) { | ||
// same as test1, but cross-crate | ||
lib::just_ref(&**x) | ||
} | ||
|
||
fn test2<'a>(x: &'a Box<Fn()+'a>) { | ||
// but ref_obj will not, so warn. | ||
ref_obj(x) //~ WARNING this code may fail to compile in Rust 1.3 | ||
} | ||
|
||
fn test2cc<'a>(x: &'a Box<Fn()+'a>) { | ||
// same as test2, but cross crate | ||
lib::ref_obj(x) //~ WARNING this code may fail to compile in Rust 1.3 | ||
} | ||
|
||
fn test3<'a>(x: &'a Box<Fn()+'static>) { | ||
// here, we have a 'static bound, so even when ref_obj changes, no error results | ||
ref_obj(x) | ||
} | ||
|
||
fn test3cc<'a>(x: &'a Box<Fn()+'static>) { | ||
// same as test3, but cross crate | ||
lib::ref_obj(x) | ||
} | ||
|
||
#[rustc_error] | ||
fn main() { //~ ERROR compilation successful | ||
} |