Rollup merge of #43501 - topecongiro:span-to-whereclause, r=nrc

Add Span to ast::WhereClause

This PR adds `Span` field to `ast::WhereClause`. The motivation here is to make rustfmt's life easier when recovering comments before and after where clause.
r? @nrc
This commit is contained in:
Mark Simulacrum 2017-07-29 18:03:52 -06:00 committed by GitHub
commit e61e73fcc4
6 changed files with 13 additions and 2 deletions

View File

@ -336,6 +336,7 @@ impl Default for Generics {
where_clause: WhereClause {
id: DUMMY_NODE_ID,
predicates: Vec::new(),
span: DUMMY_SP,
},
span: DUMMY_SP,
}
@ -347,6 +348,7 @@ impl Default for Generics {
pub struct WhereClause {
pub id: NodeId,
pub predicates: Vec<WherePredicate>,
pub span: Span,
}
/// A single predicate in a `where` clause

View File

@ -737,14 +737,15 @@ pub fn noop_fold_generics<T: Folder>(Generics {ty_params, lifetimes, where_claus
}
pub fn noop_fold_where_clause<T: Folder>(
WhereClause {id, predicates}: WhereClause,
WhereClause {id, predicates, span}: WhereClause,
fld: &mut T)
-> WhereClause {
WhereClause {
id: fld.new_id(id),
predicates: predicates.move_map(|predicate| {
fld.fold_where_predicate(predicate)
})
}),
span: span,
}
}

View File

@ -892,6 +892,7 @@ mod tests {
where_clause: ast::WhereClause {
id: ast::DUMMY_NODE_ID,
predicates: Vec::new(),
span: syntax_pos::DUMMY_SP,
},
span: syntax_pos::DUMMY_SP,
},

View File

@ -4302,6 +4302,7 @@ impl<'a> Parser<'a> {
where_clause: WhereClause {
id: ast::DUMMY_NODE_ID,
predicates: Vec::new(),
span: syntax_pos::DUMMY_SP,
},
span: span_lo.to(self.prev_span),
})
@ -4369,11 +4370,13 @@ impl<'a> Parser<'a> {
let mut where_clause = WhereClause {
id: ast::DUMMY_NODE_ID,
predicates: Vec::new(),
span: syntax_pos::DUMMY_SP,
};
if !self.eat_keyword(keywords::Where) {
return Ok(where_clause);
}
let lo = self.prev_span;
// This is a temporary future proofing.
//
@ -4451,6 +4454,7 @@ impl<'a> Parser<'a> {
}
}
where_clause.span = lo.to(self.prev_span);
Ok(where_clause)
}

View File

@ -1041,6 +1041,7 @@ impl<'a> State<'a> {
where_clause: ast::WhereClause {
id: ast::DUMMY_NODE_ID,
predicates: Vec::new(),
span: syntax_pos::DUMMY_SP,
},
span: syntax_pos::DUMMY_SP,
};
@ -2983,6 +2984,7 @@ impl<'a> State<'a> {
where_clause: ast::WhereClause {
id: ast::DUMMY_NODE_ID,
predicates: Vec::new(),
span: syntax_pos::DUMMY_SP,
},
span: syntax_pos::DUMMY_SP,
};

View File

@ -216,6 +216,7 @@ fn mk_generics(lifetimes: Vec<ast::LifetimeDef>, ty_params: Vec<ast::TyParam>, s
where_clause: ast::WhereClause {
id: ast::DUMMY_NODE_ID,
predicates: Vec::new(),
span: span,
},
span: span,
}