Navigation Menu

Skip to content

Commit

Permalink
librustc: Consider where clauses when traversing free regions in
Browse files Browse the repository at this point in the history
signatures.

Closes #16549.
Closes #16564.
  • Loading branch information
pcwalton committed Aug 22, 2014
1 parent b43596b commit 24a2137
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/librustc/middle/resolve_lifetime.rs
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
}
Expand All @@ -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
Expand All @@ -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 {
Expand Down
15 changes: 15 additions & 0 deletions src/test/run-pass/where-clauses-lifetimes.rs
@@ -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());
}
26 changes: 26 additions & 0 deletions src/test/run-pass/where-clauses-unboxed-closures.rs
@@ -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| () );
}

5 comments on commit 24a2137

@bors
Copy link
Contributor

@bors bors commented on 24a2137 Aug 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from nikomatsakis
at pcwalton@24a2137

@bors
Copy link
Contributor

@bors bors commented on 24a2137 Aug 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging pcwalton/rust/unboxed-closure-where-clause = 24a2137 into auto

@bors
Copy link
Contributor

@bors bors commented on 24a2137 Aug 22, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pcwalton/rust/unboxed-closure-where-clause = 24a2137 merged ok, testing candidate = 47b9a6f

@bors
Copy link
Contributor

@bors bors commented on 24a2137 Aug 22, 2014

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 = 47b9a6f

Please sign in to comment.