Skip to content

Commit

Permalink
Fix minor parser problems
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Oct 16, 2018
1 parent 3812721 commit bfc4b41
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1089,9 +1089,9 @@ fn external_generic_args(cx: &DocContext, trait_did: Option<DefId>, has_self: bo
match trait_did {
// Attempt to sugar an external path like Fn<(A, B,), C> to Fn(A, B) -> C
Some(did) if cx.tcx.lang_items().fn_trait_kind(did).is_some() => {
assert_eq!(types.len(), 1);
let inputs = match types[0].sty {
ty::Tuple(ref tys) => tys.iter().map(|t| t.clean(cx)).collect(),
assert!(first_ty_sty.is_some());
let inputs = match first_ty_sty {
Some(ty::Tuple(ref tys)) => tys.iter().map(|t| t.clean(cx)).collect(),
_ => return GenericArgs::AngleBracketed { args, bindings },
};
let output = None;
Expand Down
15 changes: 6 additions & 9 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5067,6 +5067,7 @@ impl<'a> Parser<'a> {
crate fn parse_generic_params(&mut self) -> PResult<'a, Vec<ast::GenericParam>> {
let mut params = vec![];
let mut max_param = None;
// TODO(const_generics): move parameter order enforcement to AST.
fn enforce_param_order(parser: &Parser,
max_param: &mut Option<ParamKindOrd>,
param_ord: ParamKindOrd) {
Expand Down Expand Up @@ -5111,9 +5112,6 @@ impl<'a> Parser<'a> {
if let Some(max_param) = max_param {
self.span_err(attrs[0].span,
&format!("trailing attribute after {} parameters", max_param));
} else {
self.span_err(attrs[0].span,
"leading attribute before generic parameters");
}
}
break
Expand Down Expand Up @@ -5202,7 +5200,7 @@ impl<'a> Parser<'a> {
let lit = self.parse_lit()?;
self.mk_expr(lit.span, ExprKind::Lit(P(lit)), ThinVec::new())
} else {
unreachable!()
unreachable!() // TODO(const_generics): handle this case
};
debug!("const arg: expr={:?}", expr);
let value = AnonConst {
Expand Down Expand Up @@ -5253,7 +5251,7 @@ impl<'a> Parser<'a> {
// We are considering adding generics to the `where` keyword as an alternative higher-rank
// parameter syntax (as in `where<'a>` or `where<T>`. To avoid that being a breaking
// change we parse those generics now, but report an error.
if self.choose_generics_over_qpath(false) {
if self.choose_generics_over_qpath() {
let generics = self.parse_generics()?;
self.span_err(generics.span,
"generic parameters on `where` clauses are reserved for future use");
Expand Down Expand Up @@ -5827,7 +5825,7 @@ impl<'a> Parser<'a> {
}
}

fn choose_generics_over_qpath(&self, param: bool) -> bool {
fn choose_generics_over_qpath(&self) -> bool {
// There's an ambiguity between generic parameters and qualified paths in impls.
// If we see `<` it may start both, so we have to inspect some following tokens.
// The following combinations can only start generics,
Expand All @@ -5849,8 +5847,7 @@ impl<'a> Parser<'a> {
self.look_ahead(1, |t| t.is_lifetime() || t.is_ident()) &&
self.look_ahead(2, |t| t == &token::Gt || t == &token::Comma ||
t == &token::Colon || t == &token::Eq) ||
param && self.look_ahead(1, |t| t.is_keyword(keywords::Const) &&
self.look_ahead(2, |t| t.is_ident())))
self.look_ahead(1, |t| t.is_keyword(keywords::Const)))
}

fn parse_impl_body(&mut self) -> PResult<'a, (Vec<ImplItem>, Vec<Attribute>)> {
Expand Down Expand Up @@ -5883,7 +5880,7 @@ impl<'a> Parser<'a> {
fn parse_item_impl(&mut self, unsafety: Unsafety, defaultness: Defaultness)
-> PResult<'a, ItemInfo> {
// First, parse generic parameters if necessary.
let mut generics = if self.choose_generics_over_qpath(true) {
let mut generics = if self.choose_generics_over_qpath() {
self.parse_generics()?
} else {
ast::Generics::default()
Expand Down
6 changes: 6 additions & 0 deletions src/libsyntax/parse/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,12 @@ impl Token {
pub fn can_begin_const_arg(&self) -> bool {
match self {
OpenDelim(Brace) => true,
Interpolated(ref nt) => match nt.0 {
NtExpr(..) => true,
NtBlock(..) => true,
NtLiteral(..) => true,
_ => false,
}
_ => self.can_begin_literal_or_bool(),
}
}
Expand Down

0 comments on commit bfc4b41

Please sign in to comment.