librustc: Consider where clauses when traversing free regions in

signatures.

Closes #16549.
Closes #16564.
This commit is contained in:
Patrick Walton 2014-08-19 14:39:00 -07:00
parent b43596b43e
commit 24a2137269
3 changed files with 51 additions and 3 deletions

View File

@ -206,7 +206,8 @@ impl<'a> LifetimeContext<'a> {
self.check_lifetime_names(&generics.lifetimes);
let referenced_idents = free_lifetimes(&generics.ty_params);
let referenced_idents = free_lifetimes(&generics.ty_params,
&generics.where_clause);
debug!("pushing fn scope id={} due to fn item/method\
referenced_idents={:?}",
n,
@ -403,7 +404,8 @@ fn search_lifetimes(lifetimes: &Vec<ast::LifetimeDef>,
///////////////////////////////////////////////////////////////////////////
pub fn early_bound_lifetimes<'a>(generics: &'a ast::Generics) -> Vec<ast::LifetimeDef> {
let referenced_idents = free_lifetimes(&generics.ty_params);
let referenced_idents = free_lifetimes(&generics.ty_params,
&generics.where_clause);
if referenced_idents.is_empty() {
return Vec::new();
}
@ -414,7 +416,9 @@ pub fn early_bound_lifetimes<'a>(generics: &'a ast::Generics) -> Vec<ast::Lifeti
.collect()
}
pub fn free_lifetimes(ty_params: &OwnedSlice<ast::TyParam>) -> Vec<ast::Name> {
pub fn free_lifetimes(ty_params: &OwnedSlice<ast::TyParam>,
where_clause: &ast::WhereClause)
-> Vec<ast::Name> {
/*!
* Gathers up and returns the names of any lifetimes that appear
* free in `ty_params`. Of course, right now, all lifetimes appear
@ -426,6 +430,9 @@ pub fn free_lifetimes(ty_params: &OwnedSlice<ast::TyParam>) -> Vec<ast::Name> {
for ty_param in ty_params.iter() {
visit::walk_ty_param_bounds(&mut collector, &ty_param.bounds, ());
}
for predicate in where_clause.predicates.iter() {
visit::walk_ty_param_bounds(&mut collector, &predicate.bounds, ());
}
return collector.names;
struct FreeLifetimeCollector {

View File

@ -0,0 +1,15 @@
// Copyright 2014 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.
fn foo<'a, I>(mut it: I) where I: Iterator<&'a int> {}
fn main() {
foo([1i, 2].iter());
}

View File

@ -0,0 +1,26 @@
// Copyright 2014 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.
#![feature(unboxed_closures)]
struct Bencher;
// ICE
fn warm_up<'a, F>(f: F) where F: |&: &'a mut Bencher| {
}
fn main() {
// ICE trigger
warm_up(|&: b: &mut Bencher| () );
// OK
warm_up(|&: b| () );
}