Skip to content

Commit de99da3

Browse files
committed
auto merge of #13898 : nikomatsakis/rust/type-bounds-b, r=acrichto
This is needed to bootstrap fix for #5723.
2 parents 0f9a74f + 92b741a commit de99da3

File tree

13 files changed

+91
-17
lines changed

13 files changed

+91
-17
lines changed

Diff for: src/librustc/front/feature_gate.rs

+9-2
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
}

Diff for: src/librustc/middle/resolve.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3824,7 +3824,8 @@ impl<'a> Resolver<'a> {
38243824
TraitTyParamBound(ref tref) => {
38253825
self.resolve_trait_reference(id, tref, TraitBoundingTypeParameter)
38263826
}
3827-
RegionTyParamBound => {}
3827+
StaticRegionTyParamBound => {}
3828+
OtherRegionTyParamBound(_) => {}
38283829
}
38293830
}
38303831

Diff for: src/librustc/middle/typeck/astconv.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -898,9 +898,17 @@ fn conv_builtin_bounds(tcx: &ty::ctxt, ast_bounds: &Option<OwnedSlice<ast::TyPar
898898
format!("only the builtin traits can be used \
899899
as closure or object bounds"));
900900
}
901-
ast::RegionTyParamBound => {
901+
ast::StaticRegionTyParamBound => {
902902
builtin_bounds.add(ty::BoundStatic);
903903
}
904+
ast::OtherRegionTyParamBound(span) => {
905+
if !tcx.sess.features.issue_5723_bootstrap.get() {
906+
tcx.sess.span_err(
907+
span,
908+
format!("only the 'static lifetime is \
909+
accepted here."));
910+
}
911+
}
904912
}
905913
}
906914
builtin_bounds

Diff for: src/librustc/middle/typeck/collect.rs

+12-2
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};
@@ -1102,9 +1103,18 @@ fn ty_generics(ccx: &CrateCtxt,
11021103
}
11031104
}
11041105

1105-
RegionTyParamBound => {
1106+
StaticRegionTyParamBound => {
11061107
param_bounds.builtin_bounds.add(ty::BoundStatic);
11071108
}
1109+
1110+
OtherRegionTyParamBound(span) => {
1111+
if !ccx.tcx.sess.features.issue_5723_bootstrap.get() {
1112+
ccx.tcx.sess.span_err(
1113+
span,
1114+
format!("only the 'static lifetime is \
1115+
accepted here."));
1116+
}
1117+
}
11081118
}
11091119
}
11101120

Diff for: src/librustc/middle/typeck/infer/error_reporting.rs

+2-1
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();

Diff for: src/librustdoc/clean.rs

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

Diff for: src/libsyntax/ast.rs

+2-1
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)]

Diff for: src/libsyntax/fold.rs

+2-1
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

Diff for: src/libsyntax/parse/parser.rs

+3-4
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
}

Diff for: src/libsyntax/print/pprust.rs

+4-2
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;
@@ -1881,7 +1882,8 @@ impl<'a> State<'a> {
18811882

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

Diff for: src/libsyntax/visit.rs

+2-1
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
}
+19
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() { }
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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+
// ignore-pretty
12+
13+
#![feature(issue_5723_bootstrap)]
14+
15+
trait Foo { }
16+
17+
fn foo<'a>(x: ~Foo:'a) {
18+
}
19+
20+
fn bar<'a, T:'a>() {
21+
}
22+
23+
pub fn main() { }

0 commit comments

Comments
 (0)