Skip to content

Commit 9d179e6

Browse files
committed
Fix where clauses parsing
Require at least one predicate for a lifetime in a where clause
1 parent a41505f commit 9d179e6

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/librustc_borrowck/borrowck/mir/dataflow/graphviz.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub trait MirWithFlowState<'tcx> {
8888
}
8989

9090
impl<'a, 'tcx: 'a, BD> MirWithFlowState<'tcx> for MirBorrowckCtxtPreDataflow<'a, 'tcx, BD>
91-
where 'a, 'tcx: 'a, BD: BitDenotation<Ctxt=MoveDataParamEnv<'tcx>>
91+
where 'tcx: 'a, BD: BitDenotation<Ctxt=MoveDataParamEnv<'tcx>>
9292
{
9393
type BD = BD;
9494
fn node_id(&self) -> NodeId { self.node_id }

src/libsyntax/parse/parser.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -4440,14 +4440,20 @@ impl<'a> Parser<'a> {
44404440
let bounded_lifetime =
44414441
self.parse_lifetime()?;
44424442

4443-
self.eat(&token::Colon);
4443+
self.expect(&token::Colon)?;
44444444

44454445
let bounds =
44464446
self.parse_lifetimes(token::BinOp(token::Plus))?;
44474447

44484448
let hi = self.prev_span.hi;
44494449
let span = mk_sp(lo, hi);
44504450

4451+
if bounds.is_empty() {
4452+
self.span_err(span,
4453+
"each predicate in a `where` clause must have \
4454+
at least one bound in it");
4455+
}
4456+
44514457
where_clause.predicates.push(ast::WherePredicate::RegionPredicate(
44524458
ast::WhereRegionPredicate {
44534459
span: span,

src/test/parse-fail/where-clauses-no-bounds-or-predicates.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// compile-flags: -Z parse-only
11+
// compile-flags: -Z parse-only -Z continue-parse-after-error
1212

1313
fn equal1<T>(_: &T, _: &T) -> bool where {
1414
//~^ ERROR a `where` clause must have at least one predicate in it
@@ -20,5 +20,11 @@ fn equal2<T>(_: &T, _: &T) -> bool where T: {
2020
true
2121
}
2222

23+
fn foo2<'a>() where 'a: {}
24+
//~^ ERROR each predicate in a `where` clause must have at least one bound
25+
26+
fn foo1<'a>() where 'a {}
27+
//~^ ERROR expected `:`, found `{`
28+
2329
fn main() {
2430
}

0 commit comments

Comments
 (0)