Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tweak region inference to ignore constraints like 'a <= 'static, sinc…
…e they have no value. This also ensures that we can handle some obscure cases of fn subtyping with bound regions that we didn't used to handle correctly. Fixes #13974.
- Loading branch information
1 parent
061db52
commit 7cdd02d
Showing
2 changed files
with
63 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
60 changes: 60 additions & 0 deletions
60
src/test/compile-fail/regions-fn-subtyping-return-static.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,60 @@ | ||
// 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. | ||
|
||
// In this fn, the type `F` is a function that takes a reference to a | ||
// struct and returns another reference with the same lifetime. | ||
// | ||
// Meanwhile, the bare fn `foo` takes a reference to a struct with | ||
// *ANY* lifetime and returns a reference with the 'static lifetime. | ||
// This can safely be considered to be an instance of `F` because all | ||
// lifetimes are sublifetimes of 'static. | ||
|
||
#![allow(dead_code)] | ||
#![allow(unused_variable)] | ||
|
||
struct S; | ||
|
||
// Given 'cx, return 'cx | ||
type F = fn<'cx>(&'cx S) -> &'cx S; | ||
fn want_F(f: F) { } | ||
|
||
// Given anything, return 'static | ||
type G = fn<'cx>(&'cx S) -> &'static S; | ||
fn want_G(f: G) { } | ||
|
||
// Should meet both. | ||
fn foo(x: &S) -> &'static S { | ||
fail!() | ||
} | ||
|
||
// Should meet both. | ||
fn bar<'a,'b>(x: &'a S) -> &'b S { | ||
fail!() | ||
} | ||
|
||
// Meets F, but not G. | ||
fn baz<'a>(x: &'a S) -> &'a S { | ||
fail!() | ||
} | ||
|
||
fn supply_F() { | ||
want_F(foo); | ||
want_F(bar); | ||
want_F(baz); | ||
} | ||
|
||
fn supply_G() { | ||
want_G(foo); | ||
want_G(bar); | ||
want_G(baz); //~ ERROR expected concrete lifetime | ||
} | ||
|
||
pub fn main() { | ||
} |
7cdd02d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from pnkfelix
at nikomatsakis@7cdd02d
7cdd02d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging nikomatsakis/rust/issue-13794-fn-subtyping-and-static = 7cdd02d into auto
7cdd02d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nikomatsakis/rust/issue-13794-fn-subtyping-and-static = 7cdd02d merged ok, testing candidate = 6ecf7d9
7cdd02d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all tests pass:
success: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/5861
success: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/5859
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-c/builds/4955
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/4963
success: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/5958
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-c/builds/5047
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/5055
success: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/5961
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-c/builds/5046
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/5052
success: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android/builds/5114
success: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android-t/builds/2847
success: http://buildbot.rust-lang.org/builders/auto-win-32-opt/builds/5954
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-c/builds/5050
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-t/builds/5065
7cdd02d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fast-forwarding master to auto = 6ecf7d9