Skip to content

Bounds parsing refactoring #37511

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix where clauses parsing
Require at least one predicate for a lifetime in a where clause
  • Loading branch information
matklad committed Oct 19, 2016
commit 9d179e6cc89124ae40e231b3393c0ffa144cd7fd
2 changes: 1 addition & 1 deletion src/librustc_borrowck/borrowck/mir/dataflow/graphviz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub trait MirWithFlowState<'tcx> {
}

impl<'a, 'tcx: 'a, BD> MirWithFlowState<'tcx> for MirBorrowckCtxtPreDataflow<'a, 'tcx, BD>
where 'a, 'tcx: 'a, BD: BitDenotation<Ctxt=MoveDataParamEnv<'tcx>>
where 'tcx: 'a, BD: BitDenotation<Ctxt=MoveDataParamEnv<'tcx>>
{
type BD = BD;
fn node_id(&self) -> NodeId { self.node_id }
Expand Down
8 changes: 7 additions & 1 deletion src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4440,14 +4440,20 @@ impl<'a> Parser<'a> {
let bounded_lifetime =
self.parse_lifetime()?;

self.eat(&token::Colon);
self.expect(&token::Colon)?;

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

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

if bounds.is_empty() {
self.span_err(span,
"each predicate in a `where` clause must have \
at least one bound in it");
}

where_clause.predicates.push(ast::WherePredicate::RegionPredicate(
ast::WhereRegionPredicate {
span: span,
Expand Down
10 changes: 8 additions & 2 deletions src/test/parse-fail/where-clauses-no-bounds-or-predicates.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
Expand All @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z parse-only
// compile-flags: -Z parse-only -Z continue-parse-after-error

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

fn foo2<'a>() where 'a: {}
//~^ ERROR each predicate in a `where` clause must have at least one bound

fn foo1<'a>() where 'a {}
//~^ ERROR expected `:`, found `{`

fn main() {
}