Skip to content

Commit

Permalink
Auto merge of #40043 - petrochenkov:objpars, r=nikomatsakis
Browse files Browse the repository at this point in the history
Refactor parsing of trait object types

Bugs are fixed and code is cleaned up.

User visible changes:
- `ty` matcher in macros accepts trait object types like `Write + Send` (#39080)
- Buggy priority of `+` in trait object types starting with `for` is fixed (#39317). `&for<'a> Trait<'a> + Send` is now parsed as `(&for<'a> Trait<'a>) + Send` and requires parens `&(for<'a> Trait<'a> + Send)`. For comparison, `&Send + for<'a> Trait<'a>` was parsed like this since [Nov 27, 2014](#19298).
- Trailing `+`s are supported in trait objects, like in other bounds.
- Better error reporting for trait objects starting with `?Sized`.

Fixes #39080
Fixes #39317 [breaking-change]
Closes #39298
cc #39085 (fixed, then reverted #40043 (comment))
cc #39318 (fixed, then reverted #40043 (comment))

r? @nikomatsakis
  • Loading branch information
bors committed Mar 22, 2017
2 parents 50c4e3e + b5e8897 commit 8c4f2c6
Show file tree
Hide file tree
Showing 21 changed files with 294 additions and 267 deletions.
12 changes: 11 additions & 1 deletion src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub use self::PathParameters::*;
pub use symbol::Symbol as Name;
pub use util::ThinVec;

use syntax_pos::{mk_sp, Span, DUMMY_SP, ExpnId};
use syntax_pos::{mk_sp, BytePos, Span, DUMMY_SP, ExpnId};
use codemap::{respan, Spanned};
use abi::Abi;
use ext::hygiene::SyntaxContext;
Expand Down Expand Up @@ -1716,6 +1716,16 @@ pub struct PolyTraitRef {
pub span: Span,
}

impl PolyTraitRef {
pub fn new(lifetimes: Vec<LifetimeDef>, path: Path, lo: BytePos, hi: BytePos) -> Self {
PolyTraitRef {
bound_lifetimes: lifetimes,
trait_ref: TraitRef { path: path, ref_id: DUMMY_NODE_ID },
span: mk_sp(lo, hi),
}
}
}

#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
pub enum Visibility {
Public,
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ impl<'a> Parser<'a> {
}
ExpansionKind::Expr => Expansion::Expr(self.parse_expr()?),
ExpansionKind::OptExpr => Expansion::OptExpr(Some(self.parse_expr()?)),
ExpansionKind::Ty => Expansion::Ty(self.parse_ty_no_plus()?),
ExpansionKind::Ty => Expansion::Ty(self.parse_ty()?),
ExpansionKind::Pat => Expansion::Pat(self.parse_pat()?),
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ pub fn parse_arm_panic(parser: &mut Parser) -> Arm {
}

pub fn parse_ty_panic(parser: &mut Parser) -> P<Ty> {
panictry!(parser.parse_ty_no_plus())
panictry!(parser.parse_ty())
}

pub fn parse_stmt_panic(parser: &mut Parser) -> Option<Stmt> {
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/tt/macro_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ fn parse_nt<'a>(p: &mut Parser<'a>, sp: Span, name: &str) -> Nonterminal {
},
"pat" => token::NtPat(panictry!(p.parse_pat())),
"expr" => token::NtExpr(panictry!(p.parse_expr())),
"ty" => token::NtTy(panictry!(p.parse_ty_no_plus())),
"ty" => token::NtTy(panictry!(p.parse_ty())),
// this could be handled like a token, since it is one
"ident" => match p.token {
token::Ident(sn) => {
Expand Down
Loading

0 comments on commit 8c4f2c6

Please sign in to comment.