Skip to content

Commit 2e44898

Browse files
authored
Rollup merge of rust-lang#67148 - Centril:ty-polish, r=estebank
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
2 parents abb4234 + 690b0b3 commit 2e44898

11 files changed

+370
-285
lines changed

src/librustc_parse/parser/expr.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ impl<'a> Parser<'a> {
9191
self.parse_expr_res(Restrictions::empty(), None)
9292
}
9393

94+
pub(super) fn parse_anon_const_expr(&mut self) -> PResult<'a, AnonConst> {
95+
self.parse_expr().map(|value| AnonConst { id: DUMMY_NODE_ID, value })
96+
}
97+
9498
fn parse_paren_expr_seq(&mut self) -> PResult<'a, Vec<P<Expr>>> {
9599
self.parse_paren_comma_seq(|p| {
96100
match p.parse_expr() {
@@ -883,10 +887,7 @@ impl<'a> Parser<'a> {
883887
let first_expr = self.parse_expr()?;
884888
if self.eat(&token::Semi) {
885889
// Repeating array syntax: `[ 0; 512 ]`
886-
let count = AnonConst {
887-
id: DUMMY_NODE_ID,
888-
value: self.parse_expr()?,
889-
};
890+
let count = self.parse_anon_const_expr()?;
890891
self.expect(&token::CloseDelim(token::Bracket))?;
891892
ex = ExprKind::Repeat(first_expr, count);
892893
} else if self.eat(&token::Comma) {

src/librustc_parse/parser/item.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::maybe_whole;
55

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

13201320
let disr_expr = if self.eat(&token::Eq) {
1321-
Some(AnonConst {
1322-
id: DUMMY_NODE_ID,
1323-
value: self.parse_expr()?,
1324-
})
1321+
Some(self.parse_anon_const_expr()?)
13251322
} else {
13261323
None
13271324
};

src/librustc_parse/parser/ty.rs

+307-240
Large diffs are not rendered by default.

src/test/ui/issues/issue-58857.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ struct Conj<A> {a : A}
22
trait Valid {}
33

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

77
fn main() {}

src/test/ui/issues/issue-58857.stderr

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
error: negative trait bounds are not supported
1+
error: negative bounds are not supported
22
--> $DIR/issue-58857.rs:4:7
33
|
44
LL | impl<A: !Valid> Conj<A>{}
5-
| ^^^^^^^^ negative trait bounds are not supported
6-
|
7-
= help: remove the trait bound
5+
| ^^^^^^^^ negative bounds are not supported
86

97
error: aborting due to previous error
108

src/test/ui/parser/issue-33418.fixed

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// run-rustfix
22

33
trait Tr {}
4-
//~^ ERROR negative trait bounds are not supported
4+
//~^ ERROR negative bounds are not supported
55
trait Tr2: SuperA {}
6-
//~^ ERROR negative trait bounds are not supported
6+
//~^ ERROR negative bounds are not supported
77
trait Tr3: SuperB {}
8-
//~^ ERROR negative trait bounds are not supported
8+
//~^ ERROR negative bounds are not supported
99
trait Tr4: SuperB + SuperD {}
10-
//~^ ERROR negative trait bounds are not supported
10+
//~^ ERROR negative bounds are not supported
1111
trait Tr5 {}
12-
//~^ ERROR negative trait bounds are not supported
12+
//~^ ERROR negative bounds are not supported
1313

1414
trait SuperA {}
1515
trait SuperB {}

src/test/ui/parser/issue-33418.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
// run-rustfix
22

33
trait Tr: !SuperA {}
4-
//~^ ERROR negative trait bounds are not supported
4+
//~^ ERROR negative bounds are not supported
55
trait Tr2: SuperA + !SuperB {}
6-
//~^ ERROR negative trait bounds are not supported
6+
//~^ ERROR negative bounds are not supported
77
trait Tr3: !SuperA + SuperB {}
8-
//~^ ERROR negative trait bounds are not supported
8+
//~^ ERROR negative bounds are not supported
99
trait Tr4: !SuperA + SuperB
1010
+ !SuperC + SuperD {}
11-
//~^ ERROR negative trait bounds are not supported
11+
//~^ ERROR negative bounds are not supported
1212
trait Tr5: !SuperA
1313
+ !SuperB {}
14-
//~^ ERROR negative trait bounds are not supported
14+
//~^ ERROR negative bounds are not supported
1515

1616
trait SuperA {}
1717
trait SuperB {}

src/test/ui/parser/issue-33418.stderr

+10-20
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,36 @@
1-
error: negative trait bounds are not supported
1+
error: negative bounds are not supported
22
--> $DIR/issue-33418.rs:3:9
33
|
44
LL | trait Tr: !SuperA {}
5-
| ^^^^^^^^^ negative trait bounds are not supported
6-
|
7-
= help: remove the trait bound
5+
| ^^^^^^^^^ negative bounds are not supported
86

9-
error: negative trait bounds are not supported
7+
error: negative bounds are not supported
108
--> $DIR/issue-33418.rs:5:19
119
|
1210
LL | trait Tr2: SuperA + !SuperB {}
13-
| ^^^^^^^^^ negative trait bounds are not supported
14-
|
15-
= help: remove the trait bound
11+
| ^^^^^^^^^ negative bounds are not supported
1612

17-
error: negative trait bounds are not supported
13+
error: negative bounds are not supported
1814
--> $DIR/issue-33418.rs:7:10
1915
|
2016
LL | trait Tr3: !SuperA + SuperB {}
21-
| ^^^^^^^^^ negative trait bounds are not supported
22-
|
23-
= help: remove the trait bound
17+
| ^^^^^^^^^ negative bounds are not supported
2418

25-
error: negative trait bounds are not supported
19+
error: negative bounds are not supported
2620
--> $DIR/issue-33418.rs:9:10
2721
|
2822
LL | trait Tr4: !SuperA + SuperB
2923
| ^^^^^^^^^
3024
LL | + !SuperC + SuperD {}
31-
| ^^^^^^^^^ negative trait bounds are not supported
32-
|
33-
= help: remove the trait bounds
25+
| ^^^^^^^^^ negative bounds are not supported
3426

35-
error: negative trait bounds are not supported
27+
error: negative bounds are not supported
3628
--> $DIR/issue-33418.rs:12:10
3729
|
3830
LL | trait Tr5: !SuperA
3931
| ^^^^^^^^^
4032
LL | + !SuperB {}
41-
| ^^^^^^^^^ negative trait bounds are not supported
42-
|
43-
= help: remove the trait bounds
33+
| ^^^^^^^^^ negative bounds are not supported
4434

4535
error: aborting due to 5 previous errors
4636

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// In this regression test for #67146, we check that the
2+
// negative outlives bound `!'a` is rejected by the parser.
3+
// This regression was first introduced in PR #57364.
4+
5+
fn main() {}
6+
7+
fn f1<T: !'static>() {}
8+
//~^ ERROR negative bounds are not supported
9+
fn f2<'a, T: Ord + !'a>() {}
10+
//~^ ERROR negative bounds are not supported
11+
fn f3<'a, T: !'a + Ord>() {}
12+
//~^ ERROR negative bounds are not supported
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: negative bounds are not supported
2+
--> $DIR/issue-67146-negative-outlives-bound-syntactic-fail.rs:7:8
3+
|
4+
LL | fn f1<T: !'static>() {}
5+
| ^^^^^^^^^^ negative bounds are not supported
6+
7+
error: negative bounds are not supported
8+
--> $DIR/issue-67146-negative-outlives-bound-syntactic-fail.rs:9:18
9+
|
10+
LL | fn f2<'a, T: Ord + !'a>() {}
11+
| ^^^^^ negative bounds are not supported
12+
13+
error: negative bounds are not supported
14+
--> $DIR/issue-67146-negative-outlives-bound-syntactic-fail.rs:11:12
15+
|
16+
LL | fn f3<'a, T: !'a + Ord>() {}
17+
| ^^^^^ negative bounds are not supported
18+
19+
error: aborting due to 3 previous errors
20+

src/test/ui/type/ascription/issue-47666.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LL | let _ = Option:Some(vec![0, 1]);
1111
|
1212
= note: `#![feature(type_ascription)]` lets you annotate an expression with a type: `<expr>: <type>`
1313
= note: for more information, see https://github.com/rust-lang/rust/issues/23416
14-
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
14+
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
1515

1616
error: aborting due to previous error
1717

0 commit comments

Comments
 (0)