Skip to content

Commit

Permalink
Rollup merge of rust-lang#67148 - Centril:ty-polish, r=estebank
Browse files Browse the repository at this point in the history
 Refactor type & bounds parsing thoroughly

PR is based on rust-lang#67131 with first one from this PR being ` extract parse_ty_tuple_or_parens`.

Also fixes rust-lang#67146.

r? @estebank
  • Loading branch information
Centril authored Dec 21, 2019
2 parents abb4234 + 690b0b3 commit 2e44898
Show file tree
Hide file tree
Showing 11 changed files with 370 additions and 285 deletions.
9 changes: 5 additions & 4 deletions src/librustc_parse/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ impl<'a> Parser<'a> {
self.parse_expr_res(Restrictions::empty(), None)
}

pub(super) fn parse_anon_const_expr(&mut self) -> PResult<'a, AnonConst> {
self.parse_expr().map(|value| AnonConst { id: DUMMY_NODE_ID, value })
}

fn parse_paren_expr_seq(&mut self) -> PResult<'a, Vec<P<Expr>>> {
self.parse_paren_comma_seq(|p| {
match p.parse_expr() {
Expand Down Expand Up @@ -883,10 +887,7 @@ impl<'a> Parser<'a> {
let first_expr = self.parse_expr()?;
if self.eat(&token::Semi) {
// Repeating array syntax: `[ 0; 512 ]`
let count = AnonConst {
id: DUMMY_NODE_ID,
value: self.parse_expr()?,
};
let count = self.parse_anon_const_expr()?;
self.expect(&token::CloseDelim(token::Bracket))?;
ex = ExprKind::Repeat(first_expr, count);
} else if self.eat(&token::Comma) {
Expand Down
7 changes: 2 additions & 5 deletions src/librustc_parse/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::maybe_whole;

use rustc_errors::{PResult, Applicability, DiagnosticBuilder, StashKey};
use rustc_error_codes::*;
use syntax::ast::{self, DUMMY_NODE_ID, Ident, Attribute, AttrKind, AttrStyle, AnonConst, Item};
use syntax::ast::{self, DUMMY_NODE_ID, Ident, Attribute, AttrKind, AttrStyle, Item};
use syntax::ast::{AssocItem, AssocItemKind, ItemKind, UseTree, UseTreeKind};
use syntax::ast::{PathSegment, IsAuto, Constness, IsAsync, Unsafety, Defaultness, Extern, StrLit};
use syntax::ast::{Visibility, VisibilityKind, Mutability, FnHeader, ForeignItem, ForeignItemKind};
Expand Down Expand Up @@ -1318,10 +1318,7 @@ impl<'a> Parser<'a> {
};

let disr_expr = if self.eat(&token::Eq) {
Some(AnonConst {
id: DUMMY_NODE_ID,
value: self.parse_expr()?,
})
Some(self.parse_anon_const_expr()?)
} else {
None
};
Expand Down
547 changes: 307 additions & 240 deletions src/librustc_parse/parser/ty.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-58857.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ struct Conj<A> {a : A}
trait Valid {}

impl<A: !Valid> Conj<A>{}
//~^ ERROR negative trait bounds are not supported
//~^ ERROR negative bounds are not supported

fn main() {}
6 changes: 2 additions & 4 deletions src/test/ui/issues/issue-58857.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
error: negative trait bounds are not supported
error: negative bounds are not supported
--> $DIR/issue-58857.rs:4:7
|
LL | impl<A: !Valid> Conj<A>{}
| ^^^^^^^^ negative trait bounds are not supported
|
= help: remove the trait bound
| ^^^^^^^^ negative bounds are not supported

error: aborting due to previous error

10 changes: 5 additions & 5 deletions src/test/ui/parser/issue-33418.fixed
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// run-rustfix

trait Tr {}
//~^ ERROR negative trait bounds are not supported
//~^ ERROR negative bounds are not supported
trait Tr2: SuperA {}
//~^ ERROR negative trait bounds are not supported
//~^ ERROR negative bounds are not supported
trait Tr3: SuperB {}
//~^ ERROR negative trait bounds are not supported
//~^ ERROR negative bounds are not supported
trait Tr4: SuperB + SuperD {}
//~^ ERROR negative trait bounds are not supported
//~^ ERROR negative bounds are not supported
trait Tr5 {}
//~^ ERROR negative trait bounds are not supported
//~^ ERROR negative bounds are not supported

trait SuperA {}
trait SuperB {}
Expand Down
10 changes: 5 additions & 5 deletions src/test/ui/parser/issue-33418.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// run-rustfix

trait Tr: !SuperA {}
//~^ ERROR negative trait bounds are not supported
//~^ ERROR negative bounds are not supported
trait Tr2: SuperA + !SuperB {}
//~^ ERROR negative trait bounds are not supported
//~^ ERROR negative bounds are not supported
trait Tr3: !SuperA + SuperB {}
//~^ ERROR negative trait bounds are not supported
//~^ ERROR negative bounds are not supported
trait Tr4: !SuperA + SuperB
+ !SuperC + SuperD {}
//~^ ERROR negative trait bounds are not supported
//~^ ERROR negative bounds are not supported
trait Tr5: !SuperA
+ !SuperB {}
//~^ ERROR negative trait bounds are not supported
//~^ ERROR negative bounds are not supported

trait SuperA {}
trait SuperB {}
Expand Down
30 changes: 10 additions & 20 deletions src/test/ui/parser/issue-33418.stderr
Original file line number Diff line number Diff line change
@@ -1,46 +1,36 @@
error: negative trait bounds are not supported
error: negative bounds are not supported
--> $DIR/issue-33418.rs:3:9
|
LL | trait Tr: !SuperA {}
| ^^^^^^^^^ negative trait bounds are not supported
|
= help: remove the trait bound
| ^^^^^^^^^ negative bounds are not supported

error: negative trait bounds are not supported
error: negative bounds are not supported
--> $DIR/issue-33418.rs:5:19
|
LL | trait Tr2: SuperA + !SuperB {}
| ^^^^^^^^^ negative trait bounds are not supported
|
= help: remove the trait bound
| ^^^^^^^^^ negative bounds are not supported

error: negative trait bounds are not supported
error: negative bounds are not supported
--> $DIR/issue-33418.rs:7:10
|
LL | trait Tr3: !SuperA + SuperB {}
| ^^^^^^^^^ negative trait bounds are not supported
|
= help: remove the trait bound
| ^^^^^^^^^ negative bounds are not supported

error: negative trait bounds are not supported
error: negative bounds are not supported
--> $DIR/issue-33418.rs:9:10
|
LL | trait Tr4: !SuperA + SuperB
| ^^^^^^^^^
LL | + !SuperC + SuperD {}
| ^^^^^^^^^ negative trait bounds are not supported
|
= help: remove the trait bounds
| ^^^^^^^^^ negative bounds are not supported

error: negative trait bounds are not supported
error: negative bounds are not supported
--> $DIR/issue-33418.rs:12:10
|
LL | trait Tr5: !SuperA
| ^^^^^^^^^
LL | + !SuperB {}
| ^^^^^^^^^ negative trait bounds are not supported
|
= help: remove the trait bounds
| ^^^^^^^^^ negative bounds are not supported

error: aborting due to 5 previous errors

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// In this regression test for #67146, we check that the
// negative outlives bound `!'a` is rejected by the parser.
// This regression was first introduced in PR #57364.

fn main() {}

fn f1<T: !'static>() {}
//~^ ERROR negative bounds are not supported
fn f2<'a, T: Ord + !'a>() {}
//~^ ERROR negative bounds are not supported
fn f3<'a, T: !'a + Ord>() {}
//~^ ERROR negative bounds are not supported
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error: negative bounds are not supported
--> $DIR/issue-67146-negative-outlives-bound-syntactic-fail.rs:7:8
|
LL | fn f1<T: !'static>() {}
| ^^^^^^^^^^ negative bounds are not supported

error: negative bounds are not supported
--> $DIR/issue-67146-negative-outlives-bound-syntactic-fail.rs:9:18
|
LL | fn f2<'a, T: Ord + !'a>() {}
| ^^^^^ negative bounds are not supported

error: negative bounds are not supported
--> $DIR/issue-67146-negative-outlives-bound-syntactic-fail.rs:11:12
|
LL | fn f3<'a, T: !'a + Ord>() {}
| ^^^^^ negative bounds are not supported

error: aborting due to 3 previous errors

2 changes: 1 addition & 1 deletion src/test/ui/type/ascription/issue-47666.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ LL | let _ = Option:Some(vec![0, 1]);
|
= note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `<expr>: <type>`
= note: for more information, see https://github.com/rust-lang/rust/issues/23416
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: aborting due to previous error

0 comments on commit 2e44898

Please sign in to comment.