Skip to content

Commit 5fe2f01

Browse files
committed
Temporary patch to accept arbitrary lifetimes (behind feature gate) in bound lists. This is needed to bootstrap fix for #5723.
1 parent e97d4e6 commit 5fe2f01

File tree

13 files changed

+90
-17
lines changed

13 files changed

+90
-17
lines changed

src/librustc/front/feature_gate.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ static KNOWN_FEATURES: &'static [(&'static str, Status)] = &[
5959

6060
("quad_precision_float", Active),
6161

62+
// A temporary feature gate used to enable parser extensions needed
63+
// to bootstrap fix for #5723.
64+
("issue_5723_bootstrap", Active),
65+
6266
// These are used to test this portion of the compiler, they don't actually
6367
// mean anything
6468
("test_accepted_feature", Accepted),
@@ -80,14 +84,16 @@ enum Status {
8084
/// A set of features to be used by later passes.
8185
pub struct Features {
8286
pub default_type_params: Cell<bool>,
83-
pub quad_precision_float: Cell<bool>
87+
pub quad_precision_float: Cell<bool>,
88+
pub issue_5723_bootstrap: Cell<bool>,
8489
}
8590

8691
impl Features {
8792
pub fn new() -> Features {
8893
Features {
8994
default_type_params: Cell::new(false),
90-
quad_precision_float: Cell::new(false)
95+
quad_precision_float: Cell::new(false),
96+
issue_5723_bootstrap: Cell::new(false),
9197
}
9298
}
9399
}
@@ -367,4 +373,5 @@ pub fn check_crate(sess: &Session, krate: &ast::Crate) {
367373

368374
sess.features.default_type_params.set(cx.has_feature("default_type_params"));
369375
sess.features.quad_precision_float.set(cx.has_feature("quad_precision_float"));
376+
sess.features.issue_5723_bootstrap.set(cx.has_feature("issue_5723_bootstrap"));
370377
}

src/librustc/middle/resolve.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3828,7 +3828,8 @@ impl<'a> Resolver<'a> {
38283828
TraitTyParamBound(ref tref) => {
38293829
self.resolve_trait_reference(id, tref, TraitBoundingTypeParameter)
38303830
}
3831-
RegionTyParamBound => {}
3831+
StaticRegionTyParamBound => {}
3832+
OtherRegionTyParamBound(_) => {}
38323833
}
38333834
}
38343835

src/librustc/middle/typeck/astconv.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,9 +818,17 @@ fn conv_builtin_bounds(tcx: &ty::ctxt, ast_bounds: &Option<OwnedSlice<ast::TyPar
818818
format!("only the builtin traits can be used \
819819
as closure or object bounds"));
820820
}
821-
ast::RegionTyParamBound => {
821+
ast::StaticRegionTyParamBound => {
822822
builtin_bounds.add(ty::BoundStatic);
823823
}
824+
ast::OtherRegionTyParamBound(span) => {
825+
if !tcx.sess.features.issue_5723_bootstrap.get() {
826+
tcx.sess.span_err(
827+
span,
828+
format!("only the 'static lifetime is \
829+
accepted here."));
830+
}
831+
}
824832
}
825833
}
826834
builtin_bounds

src/librustc/middle/typeck/collect.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ use std::rc::Rc;
5050
use collections::{HashMap, HashSet};
5151

5252
use syntax::abi;
53-
use syntax::ast::{RegionTyParamBound, TraitTyParamBound};
53+
use syntax::ast::{StaticRegionTyParamBound, OtherRegionTyParamBound,
54+
TraitTyParamBound};
5455
use syntax::ast;
5556
use syntax::ast_map;
5657
use syntax::ast_util::{local_def, split_trait_methods};
@@ -1109,9 +1110,18 @@ fn ty_generics(ccx: &CrateCtxt,
11091110
}
11101111
}
11111112

1112-
RegionTyParamBound => {
1113+
StaticRegionTyParamBound => {
11131114
param_bounds.builtin_bounds.add(ty::BoundStatic);
11141115
}
1116+
1117+
OtherRegionTyParamBound(span) => {
1118+
if !ccx.tcx.sess.features.issue_5723_bootstrap.get() {
1119+
ccx.tcx.sess.span_err(
1120+
span,
1121+
format!("only the 'static lifetime is \
1122+
accepted here."));
1123+
}
1124+
}
11151125
}
11161126
}
11171127

src/librustc/middle/typeck/infer/error_reporting.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,8 @@ impl<'a> Rebuilder<'a> {
893893
-> OwnedSlice<ast::TyParamBound> {
894894
ty_param_bounds.map(|tpb| {
895895
match tpb {
896-
&ast::RegionTyParamBound => ast::RegionTyParamBound,
896+
&ast::StaticRegionTyParamBound => ast::StaticRegionTyParamBound,
897+
&ast::OtherRegionTyParamBound(s) => ast::OtherRegionTyParamBound(s),
897898
&ast::TraitTyParamBound(ref tr) => {
898899
let last_seg = tr.path.segments.last().unwrap();
899900
let mut insert = Vec::new();

src/librustdoc/clean.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ pub enum TyParamBound {
350350
impl Clean<TyParamBound> for ast::TyParamBound {
351351
fn clean(&self) -> TyParamBound {
352352
match *self {
353-
ast::RegionTyParamBound => RegionBound,
353+
ast::StaticRegionTyParamBound => RegionBound,
354+
ast::OtherRegionTyParamBound(_) => RegionBound,
354355
ast::TraitTyParamBound(ref t) => TraitBound(t.clean()),
355356
}
356357
}

src/libsyntax/ast.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,8 @@ pub static DUMMY_NODE_ID: NodeId = -1;
173173
#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)]
174174
pub enum TyParamBound {
175175
TraitTyParamBound(TraitRef),
176-
RegionTyParamBound
176+
StaticRegionTyParamBound,
177+
OtherRegionTyParamBound(Span) // FIXME -- just here until work for #5723 lands
177178
}
178179

179180
#[deriving(Clone, Eq, TotalEq, Encodable, Decodable, Hash)]

src/libsyntax/fold.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,8 @@ fn fold_ty_param_bound<T: Folder>(tpb: &TyParamBound, fld: &mut T)
437437
-> TyParamBound {
438438
match *tpb {
439439
TraitTyParamBound(ref ty) => TraitTyParamBound(fold_trait_ref(ty, fld)),
440-
RegionTyParamBound => RegionTyParamBound
440+
StaticRegionTyParamBound => StaticRegionTyParamBound,
441+
OtherRegionTyParamBound(s) => OtherRegionTyParamBound(s)
441442
}
442443
}
443444

src/libsyntax/parse/parser.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
use abi;
1414
use ast::{BareFnTy, ClosureTy};
15-
use ast::{RegionTyParamBound, TraitTyParamBound};
15+
use ast::{StaticRegionTyParamBound, OtherRegionTyParamBound, TraitTyParamBound};
1616
use ast::{Provided, Public, FnStyle};
1717
use ast::{Mod, BiAdd, Arg, Arm, Attribute, BindByRef, BindByValue};
1818
use ast::{BiBitAnd, BiBitOr, BiBitXor, Block};
@@ -3351,7 +3351,7 @@ impl<'a> Parser<'a> {
33513351
token::LIFETIME(lifetime) => {
33523352
let lifetime_interned_string = token::get_ident(lifetime);
33533353
if lifetime_interned_string.equiv(&("static")) {
3354-
result.push(RegionTyParamBound);
3354+
result.push(StaticRegionTyParamBound);
33553355
if allow_any_lifetime && ret_lifetime.is_none() {
33563356
ret_lifetime = Some(ast::Lifetime {
33573357
id: ast::DUMMY_NODE_ID,
@@ -3366,8 +3366,7 @@ impl<'a> Parser<'a> {
33663366
name: lifetime.name
33673367
});
33683368
} else {
3369-
self.span_err(self.span,
3370-
"`'static` is the only permissible region bound here");
3369+
result.push(OtherRegionTyParamBound(self.span));
33713370
}
33723371
self.bump();
33733372
}

src/libsyntax/print/pprust.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
// except according to those terms.
1010

1111
use abi;
12-
use ast::{P, RegionTyParamBound, TraitTyParamBound, Required, Provided};
12+
use ast::{P, StaticRegionTyParamBound, OtherRegionTyParamBound,
13+
TraitTyParamBound, Required, Provided};
1314
use ast;
1415
use ast_util;
1516
use owned_slice::OwnedSlice;
@@ -1882,7 +1883,8 @@ impl<'a> State<'a> {
18821883

18831884
try!(match *bound {
18841885
TraitTyParamBound(ref tref) => self.print_trait_ref(tref),
1885-
RegionTyParamBound => word(&mut self.s, "'static"),
1886+
StaticRegionTyParamBound => word(&mut self.s, "'static"),
1887+
OtherRegionTyParamBound(_) => Ok(())
18861888
})
18871889
}
18881890
Ok(())

src/libsyntax/visit.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,8 @@ pub fn walk_ty_param_bounds<E: Clone, V: Visitor<E>>(visitor: &mut V,
472472
TraitTyParamBound(ref typ) => {
473473
walk_trait_ref_helper(visitor, typ, env.clone())
474474
}
475-
RegionTyParamBound => {}
475+
StaticRegionTyParamBound => {}
476+
OtherRegionTyParamBound(..) => {}
476477
}
477478
}
478479
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
trait Foo { }
12+
13+
fn foo<'a>(x: ~Foo:'a) { //~ ERROR only the 'static lifetime is accepted here
14+
}
15+
16+
fn bar<'a, T:'a>() { //~ ERROR only the 'static lifetime is accepted here
17+
}
18+
19+
fn main() { }
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
12+
#![feature(issue_5723_bootstrap)]
13+
14+
trait Foo { }
15+
16+
fn foo<'a>(x: ~Foo:'a) {
17+
}
18+
19+
fn bar<'a, T:'a>() {
20+
}
21+
22+
pub fn main() { }

0 commit comments

Comments
 (0)