Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
953f6ec
fix lifetime shadowing check in GATs
basil-cow Feb 7, 2020
91b4a24
Enable use after scope detection in the new LLVM pass manager
tmiasko Feb 13, 2020
57a62f5
Add comment to SGX entry code
Feb 13, 2020
4f17dce
StripUnconfigured::in_cfg: simplify with slice patterns
Centril Dec 31, 2019
b8b32a9
simplify config::features
Centril Dec 31, 2019
64ea295
expand: extract error_derive_forbidden_on_non_adt
Centril Dec 31, 2019
10f342a
miri: fix exact_div
RalfJung Feb 13, 2020
acad033
expand: extract error_recursion_limit_reached
Centril Dec 31, 2019
7518492
expand: extract error_wrong_fragment_kind
Centril Dec 31, 2019
fcce5fa
expand: simplify classify_*
Centril Dec 31, 2019
dc6bd6a
expand: simplify flat_map_item
Centril Dec 31, 2019
ec43450
expand: simplify flat_map_item wrt. inline module detection
Centril Dec 31, 2019
9fed2d5
parser: extract common foreign item code for each kind
Centril Jan 31, 2020
7737d0f
parser: unify item list parsing.
Centril Jan 31, 2020
511dfdb
parser: extract `recover_missing_kw_before_item`
Centril Jan 31, 2020
73d5970
parser: introduce `parse_item_kind` as central `ItemInfo` logic.
Centril Jan 31, 2020
20ba687
parser_item_mod: avoid cloning outer attributes
Centril Jan 31, 2020
c202603
parser: remove `Option<Vec<Attribute>>` in `ItemInfo`.
Centril Jan 31, 2020
fd64b3b
parser: make `eat_macro_def` redundant.
Centril Jan 31, 2020
15e07a6
parser: fuse `trait` parsing & layer with `is_path_start_item`
Centril Jan 31, 2020
46d3ef5
parser: extract `recover_const_mut`.
Centril Jan 31, 2020
aaaf0ba
parser: misc small item related improvements & cleanups.
Centril Feb 1, 2020
ad72c3a
parser: inline parse_assoc_macro_invoc
Centril Feb 1, 2020
4706c38
Use HirId in TraitCandidate.
cjgillot Feb 12, 2020
2a899e2
Make TraitCandidate generic.
cjgillot Feb 13, 2020
026dec5
Spelling error "represening" to "representing"
drewrip Feb 13, 2020
23cb749
don't error on network failures
mark-i-m Feb 13, 2020
89f5dcf
Rollup merge of #68728 - Centril:towards-fn-merge, r=petrochenkov
Dylan-DPC Feb 13, 2020
998daf3
Rollup merge of #68938 - Areredify:gat_lifetime_shadowing, r=estebank
Dylan-DPC Feb 13, 2020
fc51170
Rollup merge of #69057 - Centril:clean-expand, r=petrochenkov
Dylan-DPC Feb 13, 2020
b5ee867
Rollup merge of #69108 - cjgillot:trait_candidate, r=Zoxc
Dylan-DPC Feb 13, 2020
8e2772c
Rollup merge of #69125 - jethrogb:jb/cleanup-sgx-entry, r=Dylan-DPC
Dylan-DPC Feb 13, 2020
c8343b8
Rollup merge of #69126 - RalfJung:exact-div, r=oli-obk
Dylan-DPC Feb 13, 2020
a8a2c14
Rollup merge of #69127 - tmiasko:new-pass-manager-use-after-scope, r=…
Dylan-DPC Feb 13, 2020
0bdf568
Rollup merge of #69135 - drewrip:drewrip-spelling, r=jonas-schievink
Dylan-DPC Feb 13, 2020
7704e59
Rollup merge of #69141 - mark-i-m:proper-linkcheck-2, r=Dylan-DPC
Dylan-DPC Feb 13, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
parser: misc small item related improvements & cleanups.
  • Loading branch information
Centril committed Feb 13, 2020
commit aaaf0ba072815d275820d8ac85ece6eeb9182321
258 changes: 120 additions & 138 deletions src/librustc_parse/parser/item.rs

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/librustc_parse/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,11 @@ impl<'a> Parser<'a> {
if !self.eat_keyword(kw) { self.unexpected() } else { Ok(()) }
}

/// Is the given keyword `kw` followed by a non-reserved identifier?
fn is_kw_followed_by_ident(&self, kw: Symbol) -> bool {
self.token.is_keyword(kw) && self.look_ahead(1, |t| t.is_ident() && !t.is_reserved_ident())
}

fn check_or_expected(&mut self, ok: bool, typ: TokenType) -> bool {
if ok {
true
Expand Down
18 changes: 6 additions & 12 deletions src/librustc_parse/parser/stmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::DirectoryOwnership;

use rustc_errors::{Applicability, PResult};
use rustc_span::source_map::{BytePos, Span};
use rustc_span::symbol::{kw, sym, Symbol};
use rustc_span::symbol::{kw, sym};
use syntax::ast;
use syntax::ast::{AttrStyle, AttrVec, Attribute, Mac, MacStmtStyle};
use syntax::ast::{Block, BlockCheckMode, Expr, ExprKind, Local, Stmt, StmtKind, DUMMY_NODE_ID};
Expand Down Expand Up @@ -55,13 +55,11 @@ impl<'a> Parser<'a> {
return self.recover_stmt_local(lo, attrs.into(), msg, "let");
}

// Starts like a simple path, being careful to avoid contextual keywords
// such as a union items, item with `crate` visibility or auto trait items.
// Our goal here is to parse an arbitrary path `a::b::c` but not something that starts
// like a path (1 token), but it fact not a path.
if self.token.is_path_start()
&& !self.token.is_qpath_start()
&& !self.is_path_start_item() // Confirm we don't steal syntax from `parse_item_`.
// Starts like a simple path, being careful to avoid contextual keywords,
// e.g., `union`, items with `crate` visibility, or `auto trait` items.
// We aim to parse an arbitrary path `a::b` but not something that starts like a path
// (1 token), but it fact not a path. Also, we avoid stealing syntax from `parse_item_`.
if self.token.is_path_start() && !self.token.is_qpath_start() && !self.is_path_start_item()
{
let path = self.parse_path(PathStyle::Expr)?;

Expand Down Expand Up @@ -191,10 +189,6 @@ impl<'a> Parser<'a> {
}
}

fn is_kw_followed_by_ident(&self, kw: Symbol) -> bool {
self.token.is_keyword(kw) && self.look_ahead(1, |t| t.is_ident() && !t.is_reserved_ident())
}

fn recover_stmt_local(
&mut self,
lo: Span,
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/issues/issue-58856-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ LL | fn how_are_you(&self -> Empty {
| | help: `)` may belong here
| unclosed delimiter

error: expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `)`
error: expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, `unsafe`, `}`, or identifier, found `)`
--> $DIR/issue-58856-2.rs:11:1
|
LL | }
| - expected one of 10 possible tokens
| - expected one of 11 possible tokens
LL | }
| ^ unexpected token

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/issues/issue-60075.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error: expected one of `.`, `;`, `?`, `else`, or an operator, found `}`
LL | });
| ^ expected one of `.`, `;`, `?`, `else`, or an operator

error: expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `;`
error: expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, `unsafe`, `}`, or identifier, found `;`
--> $DIR/issue-60075.rs:6:11
|
LL | fn qux() -> Option<usize> {
Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/macros/issue-54441.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
macro_rules! m {
//~^ ERROR missing `fn`, `type`, or `static` for extern-item declaration
() => {
let //~ ERROR expected
let
};
}

Expand Down
16 changes: 7 additions & 9 deletions src/test/ui/macros/issue-54441.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
error: expected one of `async`, `const`, `crate`, `extern`, `fn`, `pub`, `static`, `type`, or `unsafe`, found keyword `let`
--> $DIR/issue-54441.rs:3:9
error: missing `fn`, `type`, or `static` for extern-item declaration
--> $DIR/issue-54441.rs:1:1
|
LL | let
| ^^^ expected one of 9 possible tokens
...
LL | m!();
| ----- in this macro invocation
|
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
LL | / macro_rules! m {
LL | |
LL | | () => {
LL | | let
| |________^ missing `fn`, `type`, or `static`

error: aborting due to previous error

4 changes: 2 additions & 2 deletions src/test/ui/parser/attr-before-eof.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: expected item after attributes
--> $DIR/attr-before-eof.rs:3:16
--> $DIR/attr-before-eof.rs:3:1
|
LL | #[derive(Debug)]
| ^
| ^^^^^^^^^^^^^^^^

error: aborting due to previous error

4 changes: 2 additions & 2 deletions src/test/ui/parser/attr-dangling-in-mod.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: expected item after attributes
--> $DIR/attr-dangling-in-mod.rs:6:14
--> $DIR/attr-dangling-in-mod.rs:6:1
|
LL | #[foo = "bar"]
| ^
| ^^^^^^^^^^^^^^

error: aborting due to previous error

4 changes: 2 additions & 2 deletions src/test/ui/parser/attrs-after-extern-mod.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: expected item after attributes
--> $DIR/attrs-after-extern-mod.rs:6:19
--> $DIR/attrs-after-extern-mod.rs:6:5
|
LL | #[cfg(stage37)]
| ^
| ^^^^^^^^^^^^^^^

error: aborting due to previous error

3 changes: 2 additions & 1 deletion src/test/ui/parser/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ impl Foo for u16 {
}

impl Foo for u32 { //~ ERROR not all trait items implemented, missing: `foo`
default pub fn foo<T: Default>() -> T { T::default() } //~ ERROR expected one of
default pub fn foo<T: Default>() -> T { T::default() }
//~^ ERROR missing `fn`, `type`, or `const` for associated-item declaration
}

fn main() {}
6 changes: 3 additions & 3 deletions src/test/ui/parser/default.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: expected one of `async`, `const`, `extern`, `fn`, `type`, or `unsafe`, found keyword `pub`
--> $DIR/default.rs:22:13
error: missing `fn`, `type`, or `const` for associated-item declaration
--> $DIR/default.rs:22:12
|
LL | default pub fn foo<T: Default>() -> T { T::default() }
| ^^^ expected one of `async`, `const`, `extern`, `fn`, `type`, or `unsafe`
| ^ missing `fn`, `type`, or `const`

error[E0449]: unnecessary visibility qualifier
--> $DIR/default.rs:16:5
Expand Down
6 changes: 4 additions & 2 deletions src/test/ui/parser/doc-before-attr.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
error: expected item after attributes
--> $DIR/doc-before-attr.rs:4:16
--> $DIR/doc-before-attr.rs:4:1
|
LL | /// hi
| ------ other attributes here
LL | #[derive(Debug)]
| ^
| ^^^^^^^^^^^^^^^^

error: aborting due to previous error

3 changes: 1 addition & 2 deletions src/test/ui/parser/duplicate-visibility.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// error-pattern: expected one of `(`, `async`, `const`, `extern`, `fn`

fn main() {}

extern {
pub pub fn foo();
//~^ ERROR missing `fn`, `type`, or `static` for extern-item declaration
}
6 changes: 3 additions & 3 deletions src/test/ui/parser/duplicate-visibility.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: expected one of `(`, `async`, `const`, `extern`, `fn`, `static`, `type`, or `unsafe`, found keyword `pub`
--> $DIR/duplicate-visibility.rs:6:9
error: missing `fn`, `type`, or `static` for extern-item declaration
--> $DIR/duplicate-visibility.rs:4:8
|
LL | pub pub fn foo();
| ^^^ expected one of 8 possible tokens
| ^ missing `fn`, `type`, or `static`

error: aborting due to previous error

3 changes: 2 additions & 1 deletion src/test/ui/parser/issue-19398.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
trait T {
extern "Rust" unsafe fn foo(); //~ ERROR expected one of `async`, `const`
//~^ ERROR missing `fn`, `type`, or `const` for associated-item declaration
extern "Rust" unsafe fn foo();
}

fn main() {}
13 changes: 7 additions & 6 deletions src/test/ui/parser/issue-19398.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
error: expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found keyword `extern`
--> $DIR/issue-19398.rs:2:5
error: missing `fn`, `type`, or `const` for associated-item declaration
--> $DIR/issue-19398.rs:1:10
|
LL | trait T {
| - expected one of 10 possible tokens
LL | extern "Rust" unsafe fn foo();
| ^^^^^^ unexpected token
LL | trait T {
| __________^
LL | |
LL | | extern "Rust" unsafe fn foo();
| |____^ missing `fn`, `type`, or `const`

error: aborting due to previous error

3 changes: 2 additions & 1 deletion src/test/ui/parser/issue-20711-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ impl Foo {
fn foo() {}

#[stable(feature = "rust1", since = "1.0.0")]
} //~ ERROR expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, or
//~^ ERROR expected item after attributes
}

fn main() {}
8 changes: 3 additions & 5 deletions src/test/ui/parser/issue-20711-2.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
error: expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, or `unsafe`, found `}`
--> $DIR/issue-20711-2.rs:7:1
error: expected item after attributes
--> $DIR/issue-20711-2.rs:6:5
|
LL | #[stable(feature = "rust1", since = "1.0.0")]
| - expected one of 9 possible tokens
LL | }
| ^ unexpected token
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

3 changes: 2 additions & 1 deletion src/test/ui/parser/issue-20711.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ struct Foo;

impl Foo {
#[stable(feature = "rust1", since = "1.0.0")]
} //~ ERROR expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, or
//~^ ERROR expected item after attributes
}

fn main() {}
8 changes: 3 additions & 5 deletions src/test/ui/parser/issue-20711.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
error: expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, or `unsafe`, found `}`
--> $DIR/issue-20711.rs:5:1
error: expected item after attributes
--> $DIR/issue-20711.rs:4:5
|
LL | #[stable(feature = "rust1", since = "1.0.0")]
| - expected one of 9 possible tokens
LL | }
| ^ unexpected token
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error

4 changes: 2 additions & 2 deletions src/test/ui/parser/issue-32446.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, `unsafe`, or `}`, found `...`
error: expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, `unsafe`, `}`, or identifier, found `...`
--> $DIR/issue-32446.rs:4:11
|
LL | trait T { ... }
| ^^^ expected one of 10 possible tokens
| ^^^ expected one of 11 possible tokens

error: aborting due to previous error

4 changes: 2 additions & 2 deletions src/test/ui/parser/issue-41155.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: expected one of `(`, `async`, `const`, `default`, `extern`, `fn`, `type`, or `unsafe`, found `}`
error: expected one of `(`, `async`, `const`, `default`, `extern`, `fn`, `type`, `unsafe`, or identifier, found `}`
--> $DIR/issue-41155.rs:5:1
|
LL | pub
| - expected one of 8 possible tokens
| - expected one of 9 possible tokens
LL | }
| ^ unexpected token

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ LL | #[Ѕ
| unclosed delimiter

error: expected item after attributes
--> $DIR/issue-58094-missing-right-square-bracket.rs:4:4
--> $DIR/issue-58094-missing-right-square-bracket.rs:4:1
|
LL | #[Ѕ
| ^
| ^^^

error: aborting due to 2 previous errors

11 changes: 7 additions & 4 deletions src/test/ui/parser/macro/pub-item-macro.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// Issue #14660

macro_rules! priv_x { () => {
static x: u32 = 0;
}}
macro_rules! priv_x {
() => {
static x: u32 = 0;
};
}

macro_rules! pub_x { () => {
pub priv_x!(); //~ ERROR can't qualify macro invocation with `pub`
//~^ HELP try adjusting the macro to put `pub` inside the invocation
//~^ HELP remove the visibility
//~| HELP try adjusting the macro to put `pub` inside the invocation
}}

mod foo {
Expand Down
12 changes: 6 additions & 6 deletions src/test/ui/parser/macro/pub-item-macro.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: can't qualify macro invocation with `pub`
--> $DIR/pub-item-macro.rs:8:5
--> $DIR/pub-item-macro.rs:10:5
|
LL | pub priv_x!();
| ^^^
| ^^^ help: remove the visibility
...
LL | pub_x!();
| --------- in this macro invocation
Expand All @@ -11,16 +11,16 @@ LL | pub_x!();
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0603]: static `x` is private
--> $DIR/pub-item-macro.rs:17:23
--> $DIR/pub-item-macro.rs:20:23
|
LL | let y: u32 = foo::x;
| ^ this static is private
|
note: the static `x` is defined here
--> $DIR/pub-item-macro.rs:4:5
--> $DIR/pub-item-macro.rs:5:9
|
LL | static x: u32 = 0;
| ^^^^^^^^^^^^^^^^^^
LL | static x: u32 = 0;
| ^^^^^^^^^^^^^^^^^^
...
LL | pub_x!();
| --------- in this macro invocation
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/parser/macro/trait-non-item-macros.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, or `unsafe`, found `2`
error: expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `type`, `unsafe`, or identifier, found `2`
--> $DIR/trait-non-item-macros.rs:2:19
|
LL | ($a:expr) => ($a)
| ^^ expected one of 9 possible tokens
| ^^ expected one of 10 possible tokens
...
LL | bah!(2);
| -------- in this macro invocation
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
fn main() {}

impl T for () { //~ ERROR cannot find trait `T` in this scope

fn foo(&self) {}
//~^ ERROR missing `fn`, `type`, or `const`

trait T { //~ ERROR expected one of
trait T {
fn foo(&self);
}

pub(crate) struct Bar<T>();

fn main() {}
//~ ERROR this file contains an unclosed delimiter
Loading