1
Fork 0

parse: use parse_item_common in parse_assoc_item_.

This commit is contained in:
Mazdak Farrokhzad 2020-02-22 08:16:39 +01:00
parent a63f35daee
commit a05c83b2eb
38 changed files with 669 additions and 287 deletions

View file

@ -865,15 +865,15 @@ pub fn parse_ast_fragment<'a>(
} }
AstFragmentKind::TraitItems => { AstFragmentKind::TraitItems => {
let mut items = SmallVec::new(); let mut items = SmallVec::new();
while this.token != token::Eof { while let Some(item) = this.parse_trait_item()? {
items.push(this.parse_trait_item(&mut false)?); items.extend(item);
} }
AstFragment::TraitItems(items) AstFragment::TraitItems(items)
} }
AstFragmentKind::ImplItems => { AstFragmentKind::ImplItems => {
let mut items = SmallVec::new(); let mut items = SmallVec::new();
while this.token != token::Eof { while let Some(item) = this.parse_impl_item()? {
items.push(this.parse_impl_item(&mut false)?); items.extend(item);
} }
AstFragment::ImplItems(items) AstFragment::ImplItems(items)
} }

View file

@ -5,12 +5,12 @@ use super::{FollowedByType, Parser, PathStyle};
use crate::maybe_whole; use crate::maybe_whole;
use rustc_ast_pretty::pprust; use rustc_ast_pretty::pprust;
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, PResult, StashKey}; use rustc_errors::{struct_span_err, Applicability, PResult, StashKey};
use rustc_span::source_map::{self, Span}; use rustc_span::source_map::{self, Span};
use rustc_span::symbol::{kw, sym, Symbol}; use rustc_span::symbol::{kw, sym, Symbol};
use syntax::ast::{self, AttrStyle, AttrVec, Attribute, Ident, DUMMY_NODE_ID}; use syntax::ast::{self, AttrStyle, AttrVec, Attribute, Ident, DUMMY_NODE_ID};
use syntax::ast::{AssocItem, AssocItemKind, Item, ItemKind, UseTree, UseTreeKind}; use syntax::ast::{AssocItem, AssocItemKind, ForeignItemKind, Item, ItemKind};
use syntax::ast::{Async, Const, Defaultness, IsAuto, PathSegment, Unsafe}; use syntax::ast::{Async, Const, Defaultness, IsAuto, PathSegment, Unsafe, UseTree, UseTreeKind};
use syntax::ast::{BindingMode, Block, FnDecl, FnSig, Mac, MacArgs, MacDelimiter, Param, SelfKind}; use syntax::ast::{BindingMode, Block, FnDecl, FnSig, Mac, MacArgs, MacDelimiter, Param, SelfKind};
use syntax::ast::{EnumDef, Generics, StructField, TraitRef, Ty, TyKind, Variant, VariantData}; use syntax::ast::{EnumDef, Generics, StructField, TraitRef, Ty, TyKind, Variant, VariantData};
use syntax::ast::{FnHeader, ForeignItem, Mutability, Visibility, VisibilityKind}; use syntax::ast::{FnHeader, ForeignItem, Mutability, Visibility, VisibilityKind};
@ -81,7 +81,7 @@ impl<'a> Parser<'a> {
Some(item) Some(item)
}); });
let item = self.parse_item_common(attrs, macros_allowed, attributes_allowed)?; let item = self.parse_item_common(attrs, macros_allowed, attributes_allowed, |_| true)?;
if let Some(ref item) = item { if let Some(ref item) = item {
self.error_on_illegal_default(item.defaultness); self.error_on_illegal_default(item.defaultness);
} }
@ -91,21 +91,25 @@ impl<'a> Parser<'a> {
fn parse_item_common( fn parse_item_common(
&mut self, &mut self,
mut attrs: Vec<Attribute>, mut attrs: Vec<Attribute>,
macros_allowed: bool, mac_allowed: bool,
attributes_allowed: bool, attrs_allowed: bool,
req_name: ReqName,
) -> PResult<'a, Option<Item>> { ) -> PResult<'a, Option<Item>> {
let lo = self.token.span; let lo = self.token.span;
let vis = self.parse_visibility(FollowedByType::No)?; let vis = self.parse_visibility(FollowedByType::No)?;
let mut def = self.parse_defaultness(); let mut def = self.parse_defaultness();
let kind = self.parse_item_kind(&mut attrs, macros_allowed, lo, &vis, &mut def)?; let kind = self.parse_item_kind(&mut attrs, mac_allowed, lo, &vis, &mut def, req_name)?;
if let Some((ident, kind)) = kind { if let Some((ident, kind)) = kind {
return Ok(Some(self.mk_item(lo, ident, kind, vis, def, attrs))); let span = lo.to(self.prev_span);
let id = DUMMY_NODE_ID;
let item = Item { ident, attrs, id, kind, vis, defaultness: def, span, tokens: None };
return Ok(Some(item));
} }
// At this point, we have failed to parse an item. // At this point, we have failed to parse an item.
self.error_on_unmatched_vis(&vis); self.error_on_unmatched_vis(&vis);
self.error_on_unmatched_defaultness(def); self.error_on_unmatched_defaultness(def);
if !attributes_allowed { if !attrs_allowed {
self.recover_attrs_no_item(&attrs)?; self.recover_attrs_no_item(&attrs)?;
} }
Ok(None) Ok(None)
@ -151,6 +155,7 @@ impl<'a> Parser<'a> {
lo: Span, lo: Span,
vis: &Visibility, vis: &Visibility,
def: &mut Defaultness, def: &mut Defaultness,
req_name: ReqName,
) -> PResult<'a, Option<ItemInfo>> { ) -> PResult<'a, Option<ItemInfo>> {
let info = if self.eat_keyword(kw::Use) { let info = if self.eat_keyword(kw::Use) {
// USE ITEM // USE ITEM
@ -159,7 +164,7 @@ impl<'a> Parser<'a> {
(Ident::invalid(), ItemKind::Use(P(tree))) (Ident::invalid(), ItemKind::Use(P(tree)))
} else if self.check_fn_front_matter() { } else if self.check_fn_front_matter() {
// FUNCTION ITEM // FUNCTION ITEM
let (ident, sig, generics, body) = self.parse_fn(&mut false, attrs, |_| true)?; let (ident, sig, generics, body) = self.parse_fn(&mut false, attrs, req_name)?;
(ident, ItemKind::Fn(sig, generics, body)) (ident, ItemKind::Fn(sig, generics, body))
} else if self.eat_keyword(kw::Extern) { } else if self.eat_keyword(kw::Extern) {
if self.eat_keyword(kw::Crate) { if self.eat_keyword(kw::Crate) {
@ -367,23 +372,6 @@ impl<'a> Parser<'a> {
self.token.is_keyword(kw::Async) && self.is_keyword_ahead(1, &[kw::Fn]) self.token.is_keyword(kw::Async) && self.is_keyword_ahead(1, &[kw::Fn])
} }
/// Given this code `path(`, it seems like this is not
/// setting the visibility of a macro invocation,
/// but rather a mistyped method declaration.
/// Create a diagnostic pointing out that `fn` is missing.
///
/// ```
/// x | pub path(&self) {
/// | ^ missing `fn`, `type`, `const`, or `static`
/// ```
fn missing_nested_item_kind_err(&self, prev_span: Span) -> DiagnosticBuilder<'a> {
let sp = prev_span.between(self.token.span);
let expected_kinds = "missing `fn`, `type`, `const`, or `static`";
let mut err = self.struct_span_err(sp, &format!("{} for item declaration", expected_kinds));
err.span_label(sp, expected_kinds);
err
}
/// Parses an implementation item. /// Parses an implementation item.
/// ///
/// ``` /// ```
@ -457,8 +445,7 @@ impl<'a> Parser<'a> {
generics.where_clause = self.parse_where_clause()?; generics.where_clause = self.parse_where_clause()?;
let impl_items = let impl_items = self.parse_item_list(attrs, |p| p.parse_impl_item())?;
self.parse_item_list(attrs, |p, at_end| p.parse_impl_item(at_end).map(Some).map(Some))?;
let item_kind = match ty_second { let item_kind = match ty_second {
Some(ty_second) => { Some(ty_second) => {
@ -517,7 +504,7 @@ impl<'a> Parser<'a> {
fn parse_item_list<T>( fn parse_item_list<T>(
&mut self, &mut self,
attrs: &mut Vec<Attribute>, attrs: &mut Vec<Attribute>,
mut parse_item: impl FnMut(&mut Parser<'a>, &mut bool) -> PResult<'a, Option<Option<T>>>, mut parse_item: impl FnMut(&mut Parser<'a>) -> PResult<'a, Option<Option<T>>>,
) -> PResult<'a, Vec<T>> { ) -> PResult<'a, Vec<T>> {
let open_brace_span = self.token.span; let open_brace_span = self.token.span;
self.expect(&token::OpenDelim(token::Brace))?; self.expect(&token::OpenDelim(token::Brace))?;
@ -528,8 +515,7 @@ impl<'a> Parser<'a> {
if self.recover_doc_comment_before_brace() { if self.recover_doc_comment_before_brace() {
continue; continue;
} }
let mut at_end = false; match parse_item(self) {
match parse_item(self, &mut at_end) {
Ok(None) => { Ok(None) => {
// We have to bail or we'll potentially never make progress. // We have to bail or we'll potentially never make progress.
let non_item_span = self.token.span; let non_item_span = self.token.span;
@ -543,11 +529,11 @@ impl<'a> Parser<'a> {
} }
Ok(Some(item)) => items.extend(item), Ok(Some(item)) => items.extend(item),
Err(mut err) => { Err(mut err) => {
err.emit(); self.consume_block(token::Brace, ConsumeClosingDelim::Yes);
if !at_end { err.span_label(open_brace_span, "while parsing this item list starting here")
self.consume_block(token::Brace, ConsumeClosingDelim::Yes); .span_label(self.prev_span, "the item list ends here")
break; .emit();
} break;
} }
} }
} }
@ -644,103 +630,69 @@ impl<'a> Parser<'a> {
} else { } else {
// It's a normal trait. // It's a normal trait.
tps.where_clause = self.parse_where_clause()?; tps.where_clause = self.parse_where_clause()?;
let items = self.parse_item_list(attrs, |p, at_end| { let items = self.parse_item_list(attrs, |p| p.parse_trait_item())?;
p.parse_trait_item(at_end).map(Some).map(Some)
})?;
Ok((ident, ItemKind::Trait(is_auto, unsafety, tps, bounds, items))) Ok((ident, ItemKind::Trait(is_auto, unsafety, tps, bounds, items)))
} }
} }
pub fn parse_impl_item(&mut self, at_end: &mut bool) -> PResult<'a, P<AssocItem>> { pub fn parse_impl_item(&mut self) -> PResult<'a, Option<Option<P<AssocItem>>>> {
maybe_whole!(self, NtImplItem, |x| x); maybe_whole!(self, NtImplItem, |x| Some(Some(x)));
self.parse_assoc_item(at_end, |_| true) self.parse_assoc_item(|_| true)
} }
pub fn parse_trait_item(&mut self, at_end: &mut bool) -> PResult<'a, P<AssocItem>> { pub fn parse_trait_item(&mut self) -> PResult<'a, Option<Option<P<AssocItem>>>> {
maybe_whole!(self, NtTraitItem, |x| x); maybe_whole!(self, NtTraitItem, |x| Some(Some(x)));
// This is somewhat dubious; We don't want to allow // This is somewhat dubious; We don't want to allow
// param names to be left off if there is a definition... // param names to be left off if there is a definition...
// //
// We don't allow param names to be left off in edition 2018. // We don't allow param names to be left off in edition 2018.
self.parse_assoc_item(at_end, |t| t.span.rust_2018()) self.parse_assoc_item(|t| t.span.rust_2018())
} }
/// Parses associated items. /// Parses associated items.
fn parse_assoc_item( fn parse_assoc_item(&mut self, req_name: ReqName) -> PResult<'a, Option<Option<P<AssocItem>>>> {
&mut self,
at_end: &mut bool,
req_name: ReqName,
) -> PResult<'a, P<AssocItem>> {
let attrs = self.parse_outer_attributes()?; let attrs = self.parse_outer_attributes()?;
let mut unclosed_delims = vec![]; let mut unclosed_delims = vec![];
let (mut item, tokens) = self.collect_tokens(|this| { let (mut item, tokens) = self.collect_tokens(|this| {
let item = this.parse_assoc_item_(at_end, attrs, req_name); let item = this.parse_assoc_item_(attrs, req_name);
unclosed_delims.append(&mut this.unclosed_delims); unclosed_delims.append(&mut this.unclosed_delims);
item item
})?; })?;
self.unclosed_delims.append(&mut unclosed_delims); self.unclosed_delims.append(&mut unclosed_delims);
// See `parse_item` for why this clause is here. // See `parse_item` for why this clause is here.
if !item.attrs.iter().any(|attr| attr.style == AttrStyle::Inner) { if let Some(Some(item)) = &mut item {
item.tokens = Some(tokens); if !item.attrs.iter().any(|attr| attr.style == AttrStyle::Inner) {
} item.tokens = Some(tokens);
self.error_on_assoc_static(&item); }
Ok(P(item))
}
fn error_on_assoc_static(&self, item: &AssocItem) {
if let AssocItemKind::Static(..) = item.kind {
self.struct_span_err(item.span, "associated `static` items are not allowed").emit();
} }
Ok(item)
} }
fn parse_assoc_item_( fn parse_assoc_item_(
&mut self, &mut self,
at_end: &mut bool, attrs: Vec<Attribute>,
mut attrs: Vec<Attribute>,
req_name: ReqName, req_name: ReqName,
) -> PResult<'a, AssocItem> { ) -> PResult<'a, Option<Option<P<AssocItem>>>> {
let lo = self.token.span; let it = self.parse_item_common(attrs, true, false, req_name)?;
let vis = self.parse_visibility(FollowedByType::No)?; Ok(it.map(|Item { attrs, id, span, vis, ident, defaultness, kind, tokens }| {
let defaultness = self.parse_defaultness(); let kind = match kind {
let (ident, kind) = self.parse_assoc_item_kind(at_end, &mut attrs, req_name, &vis)?; ItemKind::Mac(a) => AssocItemKind::Macro(a),
let span = lo.to(self.prev_span); ItemKind::Fn(a, b, c) => AssocItemKind::Fn(a, b, c),
let id = DUMMY_NODE_ID; ItemKind::TyAlias(a, b, c) => AssocItemKind::TyAlias(a, b, c),
Ok(AssocItem { id, span, ident, attrs, vis, defaultness, kind, tokens: None }) ItemKind::Const(a, c) => AssocItemKind::Const(a, c),
} ItemKind::Static(a, _, b) => {
self.struct_span_err(span, "associated `static` items are not allowed").emit();
fn parse_assoc_item_kind( AssocItemKind::Const(a, b)
&mut self, }
at_end: &mut bool, _ => {
attrs: &mut Vec<Attribute>, let span = self.sess.source_map().def_span(span);
req_name: ReqName, self.struct_span_err(span, "item kind not supported in `trait` or `impl`")
vis: &Visibility, .emit();
) -> PResult<'a, (Ident, AssocItemKind)> { return None;
if self.eat_keyword(kw::Type) { }
match self.parse_type_alias()? { };
(ident, ItemKind::TyAlias(a, b, c)) => Ok((ident, AssocItemKind::TyAlias(a, b, c))), Some(P(Item { attrs, id, span, vis, ident, defaultness, kind, tokens }))
_ => unreachable!(), }))
}
} else if self.check_fn_front_matter() {
let (ident, sig, generics, body) = self.parse_fn(at_end, attrs, req_name)?;
Ok((ident, AssocItemKind::Fn(sig, generics, body)))
} else if self.is_static_global() {
self.bump(); // `static`
let mutbl = self.parse_mutability();
let (ident, ty, expr) = self.parse_item_const_common(Some(mutbl))?;
Ok((ident, AssocItemKind::Static(ty, mutbl, expr)))
} else if self.eat_keyword(kw::Const) {
let (ident, ty, expr) = self.parse_item_const_common(None)?;
Ok((ident, AssocItemKind::Const(ty, expr)))
} else if self.isnt_macro_invocation() {
Err(self.missing_nested_item_kind_err(self.prev_span))
} else if self.token.is_path_start() {
let mac = self.parse_item_macro(&vis)?;
*at_end = true;
Ok((Ident::invalid(), AssocItemKind::Macro(mac)))
} else {
self.recover_attrs_no_item(attrs)?;
self.unexpected()
}
} }
/// Parses a `type` alias with the following grammar: /// Parses a `type` alias with the following grammar:
@ -907,7 +859,7 @@ impl<'a> Parser<'a> {
/// ``` /// ```
fn parse_item_foreign_mod(&mut self, attrs: &mut Vec<Attribute>) -> PResult<'a, ItemInfo> { fn parse_item_foreign_mod(&mut self, attrs: &mut Vec<Attribute>) -> PResult<'a, ItemInfo> {
let abi = self.parse_abi(); // ABI? let abi = self.parse_abi(); // ABI?
let items = self.parse_item_list(attrs, |p, _| p.parse_foreign_item())?; let items = self.parse_item_list(attrs, |p| p.parse_foreign_item())?;
let module = ast::ForeignMod { abi, items }; let module = ast::ForeignMod { abi, items };
Ok((Ident::invalid(), ItemKind::ForeignMod(module))) Ok((Ident::invalid(), ItemKind::ForeignMod(module)))
} }
@ -917,17 +869,17 @@ impl<'a> Parser<'a> {
maybe_whole!(self, NtForeignItem, |item| Some(Some(item))); maybe_whole!(self, NtForeignItem, |item| Some(Some(item)));
let attrs = self.parse_outer_attributes()?; let attrs = self.parse_outer_attributes()?;
let it = self.parse_item_common(attrs, true, false)?; let it = self.parse_item_common(attrs, true, false, |_| true)?;
Ok(it.map(|Item { attrs, id, span, vis, ident, defaultness, kind, tokens }| { Ok(it.map(|Item { attrs, id, span, vis, ident, defaultness, kind, tokens }| {
self.error_on_illegal_default(defaultness); self.error_on_illegal_default(defaultness);
let kind = match kind { let kind = match kind {
ItemKind::Mac(a) => AssocItemKind::Macro(a), ItemKind::Mac(a) => ForeignItemKind::Macro(a),
ItemKind::Fn(a, b, c) => AssocItemKind::Fn(a, b, c), ItemKind::Fn(a, b, c) => ForeignItemKind::Fn(a, b, c),
ItemKind::TyAlias(a, b, c) => AssocItemKind::TyAlias(a, b, c), ItemKind::TyAlias(a, b, c) => ForeignItemKind::TyAlias(a, b, c),
ItemKind::Static(a, b, c) => AssocItemKind::Static(a, b, c), ItemKind::Static(a, b, c) => ForeignItemKind::Static(a, b, c),
ItemKind::Const(a, b) => { ItemKind::Const(a, b) => {
self.error_on_foreign_const(span, ident); self.error_on_foreign_const(span, ident);
AssocItemKind::Static(a, Mutability::Not, b) ForeignItemKind::Static(a, Mutability::Not, b)
} }
_ => { _ => {
let span = self.sess.source_map().def_span(span); let span = self.sess.source_map().def_span(span);
@ -989,22 +941,6 @@ impl<'a> Parser<'a> {
/// ///
/// When `m` is `"const"`, `$ident` may also be `"_"`. /// When `m` is `"const"`, `$ident` may also be `"_"`.
fn parse_item_const(&mut self, m: Option<Mutability>) -> PResult<'a, ItemInfo> { fn parse_item_const(&mut self, m: Option<Mutability>) -> PResult<'a, ItemInfo> {
let (id, ty, expr) = self.parse_item_const_common(m)?;
let item = match m {
Some(m) => ItemKind::Static(ty, m, expr),
None => ItemKind::Const(ty, expr),
};
Ok((id, item))
}
/// Parse `["const" | ("static" "mut"?)] $ident ":" $ty (= $expr)?` with
/// `["const" | ("static" "mut"?)]` already parsed and stored in `m`.
///
/// When `m` is `"const"`, `$ident` may also be `"_"`.
fn parse_item_const_common(
&mut self,
m: Option<Mutability>,
) -> PResult<'a, (Ident, P<Ty>, Option<P<ast::Expr>>)> {
let id = if m.is_none() { self.parse_ident_or_underscore() } else { self.parse_ident() }?; let id = if m.is_none() { self.parse_ident_or_underscore() } else { self.parse_ident() }?;
// Parse the type of a `const` or `static mut?` item. // Parse the type of a `const` or `static mut?` item.
@ -1017,7 +953,12 @@ impl<'a> Parser<'a> {
let expr = if self.eat(&token::Eq) { Some(self.parse_expr()?) } else { None }; let expr = if self.eat(&token::Eq) { Some(self.parse_expr()?) } else { None };
self.expect_semi()?; self.expect_semi()?;
Ok((id, ty, expr))
let item = match m {
Some(m) => ItemKind::Static(ty, m, expr),
None => ItemKind::Const(ty, expr),
};
Ok((id, item))
} }
/// We were supposed to parse `:` but the `:` was missing. /// We were supposed to parse `:` but the `:` was missing.
@ -1477,19 +1418,6 @@ impl<'a> Parser<'a> {
} }
Ok(true) Ok(true)
} }
fn mk_item<K>(
&self,
lo: Span,
ident: Ident,
kind: K,
vis: Visibility,
defaultness: Defaultness,
attrs: Vec<Attribute>,
) -> Item<K> {
let span = lo.to(self.prev_span);
Item { ident, attrs, id: DUMMY_NODE_ID, kind, vis, defaultness, span, tokens: None }
}
} }
/// The parsing configuration used to parse a parameter list (see `parse_fn_params`). /// The parsing configuration used to parse a parameter list (see `parse_fn_params`).

View file

@ -1,8 +1,13 @@
error: expected one of `extern` or `fn`, found keyword `async` error: expected one of `extern` or `fn`, found keyword `async`
--> $DIR/no-unsafe-async.rs:7:12 --> $DIR/no-unsafe-async.rs:7:12
| |
LL | impl S {
| - while parsing this item list starting here
LL | #[cfg(FALSE)]
LL | unsafe async fn g() {} LL | unsafe async fn g() {}
| ^^^^^ expected one of `extern` or `fn` | ^^^^^ expected one of `extern` or `fn`
LL | }
| - the item list ends here
error: expected one of `extern` or `fn`, found keyword `async` error: expected one of `extern` or `fn`, found keyword `async`
--> $DIR/no-unsafe-async.rs:11:8 --> $DIR/no-unsafe-async.rs:11:8

View file

@ -1,28 +1,28 @@
impl dyn A { //~ ERROR missing impl dyn A {
Y Y
} } //~ ERROR expected one of `!` or `::`, found `}`
struct S; struct S;
trait X { //~ ERROR missing trait X {
X() {} X() {} //~ ERROR expected one of `!` or `::`, found `(`
fn xxx() { ### } fn xxx() { ### }
L = M; L = M;
Z = { 2 + 3 }; Z = { 2 + 3 };
::Y (); ::Y ();
} }
trait A { //~ ERROR missing trait A {
X() {} X() {} //~ ERROR expected one of `!` or `::`, found `(`
} }
trait B { trait B {
fn xxx() { ### } //~ ERROR expected fn xxx() { ### } //~ ERROR expected
} }
trait C { //~ ERROR missing `fn`, `type`, `const`, or `static` for item declaration trait C {
L = M; L = M; //~ ERROR expected one of `!` or `::`, found `=`
} }
trait D { //~ ERROR missing `fn`, `type`, `const`, or `static` for item declaration trait D {
Z = { 2 + 3 }; Z = { 2 + 3 }; //~ ERROR expected one of `!` or `::`, found `=`
} }
trait E { trait E {
::Y (); //~ ERROR expected one of ::Y (); //~ ERROR expected one of

View file

@ -1,26 +1,36 @@
error: missing `fn`, `type`, `const`, or `static` for item declaration error: expected one of `!` or `::`, found `}`
--> $DIR/issue-40006.rs:1:13 --> $DIR/issue-40006.rs:3:1
| |
LL | impl dyn A { LL | impl dyn A {
| _____________^ | - while parsing this item list starting here
LL | | Y LL | Y
| |____^ missing `fn`, `type`, `const`, or `static` | - expected one of `!` or `::`
LL | }
| ^
| |
| unexpected token
| the item list ends here
error: missing `fn`, `type`, `const`, or `static` for item declaration error: expected one of `!` or `::`, found `(`
--> $DIR/issue-40006.rs:7:10 --> $DIR/issue-40006.rs:8:6
| |
LL | trait X { LL | trait X {
| __________^ | - while parsing this item list starting here
LL | | X() {} LL | X() {}
| |____^ missing `fn`, `type`, `const`, or `static` | ^ expected one of `!` or `::`
...
LL | }
| - the item list ends here
error: missing `fn`, `type`, `const`, or `static` for item declaration error: expected one of `!` or `::`, found `(`
--> $DIR/issue-40006.rs:15:10 --> $DIR/issue-40006.rs:16:6
| |
LL | trait A { LL | trait A {
| __________^ | - while parsing this item list starting here
LL | | X() {} LL | X() {}
| |____^ missing `fn`, `type`, `const`, or `static` | ^ expected one of `!` or `::`
LL | }
| - the item list ends here
error: expected `[`, found `#` error: expected `[`, found `#`
--> $DIR/issue-40006.rs:19:17 --> $DIR/issue-40006.rs:19:17
@ -28,33 +38,51 @@ error: expected `[`, found `#`
LL | fn xxx() { ### } LL | fn xxx() { ### }
| ^ expected `[` | ^ expected `[`
error: missing `fn`, `type`, `const`, or `static` for item declaration error: expected one of `!` or `::`, found `=`
--> $DIR/issue-40006.rs:21:10 --> $DIR/issue-40006.rs:22:7
| |
LL | trait C { LL | trait C {
| __________^ | - while parsing this item list starting here
LL | | L = M; LL | L = M;
| |____^ missing `fn`, `type`, `const`, or `static` | ^ expected one of `!` or `::`
LL | }
| - the item list ends here
error: missing `fn`, `type`, `const`, or `static` for item declaration error: expected one of `!` or `::`, found `=`
--> $DIR/issue-40006.rs:24:10 --> $DIR/issue-40006.rs:25:7
| |
LL | trait D { LL | trait D {
| __________^ | - while parsing this item list starting here
LL | | Z = { 2 + 3 }; LL | Z = { 2 + 3 };
| |____^ missing `fn`, `type`, `const`, or `static` | ^ expected one of `!` or `::`
LL | }
| - the item list ends here
error: expected one of `!` or `::`, found `(` error: expected one of `!` or `::`, found `(`
--> $DIR/issue-40006.rs:28:9 --> $DIR/issue-40006.rs:28:9
| |
LL | trait E {
| - while parsing this item list starting here
LL | ::Y (); LL | ::Y ();
| ^ expected one of `!` or `::` | ^ expected one of `!` or `::`
LL | }
| - the item list ends here
error: missing `fn`, `type`, `const`, or `static` for item declaration error: missing `fn` for method definition
--> $DIR/issue-40006.rs:32:8 --> $DIR/issue-40006.rs:32:8
| |
LL | impl S {
| - while parsing this item list starting here
LL | pub hello_method(&self) { LL | pub hello_method(&self) {
| ^ missing `fn`, `type`, `const`, or `static` | ^
...
LL | }
| - the item list ends here
|
help: add `fn` here to parse `hello_method` as a public method
|
LL | pub fn hello_method(&self) {
| ^^
error[E0599]: no method named `hello_method` found for struct `S` in the current scope error[E0599]: no method named `hello_method` found for struct `S` in the current scope
--> $DIR/issue-40006.rs:38:7 --> $DIR/issue-40006.rs:38:7

View file

@ -1,8 +1,13 @@
error: expected one of `>`, `const`, identifier, or lifetime, found `,` error: expected one of `>`, `const`, identifier, or lifetime, found `,`
--> $DIR/empty_generics.rs:5:14 --> $DIR/empty_generics.rs:5:14
| |
LL | trait Foo {
| - while parsing this item list starting here
LL | type Bar<,>; LL | type Bar<,>;
| ^ expected one of `>`, `const`, identifier, or lifetime | ^ expected one of `>`, `const`, identifier, or lifetime
LL |
LL | }
| - the item list ends here
error: aborting due to previous error error: aborting due to previous error

View file

@ -9,8 +9,14 @@ LL | fn b(self>
error: expected `;` or `{`, found `>` error: expected `;` or `{`, found `>`
--> $DIR/issue-58856-1.rs:3:14 --> $DIR/issue-58856-1.rs:3:14
| |
LL | impl A {
| - while parsing this item list starting here
LL |
LL | fn b(self> LL | fn b(self>
| ^ expected `;` or `{` | ^ expected `;` or `{`
...
LL | }
| - the item list ends here
error[E0412]: cannot find type `A` in this scope error[E0412]: cannot find type `A` in this scope
--> $DIR/issue-58856-1.rs:1:6 --> $DIR/issue-58856-1.rs:1:6

View file

@ -9,6 +9,6 @@ impl Howness for () {
Empty Empty
} }
} }
//~^ ERROR expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, //~^ ERROR non-item in item list
fn main() {} fn main() {}

View file

@ -7,13 +7,17 @@ LL | fn how_are_you(&self -> Empty {
| | help: `)` may belong here | | help: `)` may belong here
| unclosed delimiter | unclosed delimiter
error: expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `static`, `type`, `unsafe`, `}`, or identifier, found `)` error: non-item in item list
--> $DIR/issue-58856-2.rs:11:1 --> $DIR/issue-58856-2.rs:11:1
| |
LL | } LL | impl Howness for () {
| - expected one of 12 possible tokens | - item list starts here
...
LL | } LL | }
| ^ unexpected token | ^
| |
| non-item starts here
| item list ends here
error[E0407]: method `how_are_you` is not a member of trait `Howness` error[E0407]: method `how_are_you` is not a member of trait `Howness`
--> $DIR/issue-58856-2.rs:6:5 --> $DIR/issue-58856-2.rs:6:5

View file

@ -4,7 +4,8 @@ trait T {
fn qux() -> Option<usize> { fn qux() -> Option<usize> {
let _ = if true { let _ = if true {
}); });
//~^ ERROR expected one of `async` //~^ ERROR non-item in item list
//~| ERROR expected one of `.`, `;`, `?`, `else`, or an operator, found `}` //~| ERROR mismatched closing delimiter: `)`
//~| ERROR expected one of `.`, `;`
Some(4) Some(4)
} }

View file

@ -4,14 +4,26 @@ error: expected one of `.`, `;`, `?`, `else`, or an operator, found `}`
LL | }); LL | });
| ^ expected one of `.`, `;`, `?`, `else`, or an operator | ^ expected one of `.`, `;`, `?`, `else`, or an operator
error: expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `static`, `type`, `unsafe`, `}`, or identifier, found `;` error: non-item in item list
--> $DIR/issue-60075.rs:6:11 --> $DIR/issue-60075.rs:6:11
| |
LL | trait T {
| - item list starts here
...
LL | });
| ^ non-item starts here
...
LL | }
| - item list ends here
error: mismatched closing delimiter: `)`
--> $DIR/issue-60075.rs:6:10
|
LL | fn qux() -> Option<usize> { LL | fn qux() -> Option<usize> {
| - unclosed delimiter | - unclosed delimiter
LL | let _ = if true { LL | let _ = if true {
LL | }); LL | });
| ^ help: `}` may belong here | ^ mismatched closing delimiter
error: aborting due to 2 previous errors error: aborting due to 3 previous errors

View file

@ -10,10 +10,12 @@ impl S {
//~^ ERROR associated `static` items are not allowed //~^ ERROR associated `static` items are not allowed
static IB: u8; static IB: u8;
//~^ ERROR associated `static` items are not allowed //~^ ERROR associated `static` items are not allowed
//~| ERROR associated constant in `impl` without body
default static IC: u8 = 0; default static IC: u8 = 0;
//~^ ERROR associated `static` items are not allowed //~^ ERROR associated `static` items are not allowed
pub(crate) default static ID: u8; pub(crate) default static ID: u8;
//~^ ERROR associated `static` items are not allowed //~^ ERROR associated `static` items are not allowed
//~| ERROR associated constant in `impl` without body
} }
trait T { trait T {
@ -35,9 +37,11 @@ impl T for S {
//~^ ERROR associated `static` items are not allowed //~^ ERROR associated `static` items are not allowed
static TB: u8; static TB: u8;
//~^ ERROR associated `static` items are not allowed //~^ ERROR associated `static` items are not allowed
//~| ERROR associated constant in `impl` without body
default static TC: u8 = 0; default static TC: u8 = 0;
//~^ ERROR associated `static` items are not allowed //~^ ERROR associated `static` items are not allowed
pub default static TD: u8; pub default static TD: u8;
//~^ ERROR associated `static` items are not allowed //~^ ERROR associated `static` items are not allowed
//~| ERROR associated constant in `impl` without body
//~| ERROR unnecessary visibility qualifier //~| ERROR unnecessary visibility qualifier
} }

View file

@ -11,67 +11,83 @@ LL | static IB: u8;
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^
error: associated `static` items are not allowed error: associated `static` items are not allowed
--> $DIR/assoc-static-semantic-fail.rs:13:5 --> $DIR/assoc-static-semantic-fail.rs:14:5
| |
LL | default static IC: u8 = 0; LL | default static IC: u8 = 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: associated `static` items are not allowed error: associated `static` items are not allowed
--> $DIR/assoc-static-semantic-fail.rs:15:5 --> $DIR/assoc-static-semantic-fail.rs:16:5
| |
LL | pub(crate) default static ID: u8; LL | pub(crate) default static ID: u8;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: associated `static` items are not allowed error: associated `static` items are not allowed
--> $DIR/assoc-static-semantic-fail.rs:20:5 --> $DIR/assoc-static-semantic-fail.rs:22:5
| |
LL | static TA: u8 = 0; LL | static TA: u8 = 0;
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
error: associated `static` items are not allowed error: associated `static` items are not allowed
--> $DIR/assoc-static-semantic-fail.rs:22:5 --> $DIR/assoc-static-semantic-fail.rs:24:5
| |
LL | static TB: u8; LL | static TB: u8;
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^
error: associated `static` items are not allowed error: associated `static` items are not allowed
--> $DIR/assoc-static-semantic-fail.rs:24:5 --> $DIR/assoc-static-semantic-fail.rs:26:5
| |
LL | default static TC: u8 = 0; LL | default static TC: u8 = 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: associated `static` items are not allowed error: associated `static` items are not allowed
--> $DIR/assoc-static-semantic-fail.rs:27:5 --> $DIR/assoc-static-semantic-fail.rs:29:5
| |
LL | pub(crate) default static TD: u8; LL | pub(crate) default static TD: u8;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: associated `static` items are not allowed error: associated `static` items are not allowed
--> $DIR/assoc-static-semantic-fail.rs:34:5 --> $DIR/assoc-static-semantic-fail.rs:36:5
| |
LL | static TA: u8 = 0; LL | static TA: u8 = 0;
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
error: associated `static` items are not allowed error: associated `static` items are not allowed
--> $DIR/assoc-static-semantic-fail.rs:36:5 --> $DIR/assoc-static-semantic-fail.rs:38:5
| |
LL | static TB: u8; LL | static TB: u8;
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^
error: associated `static` items are not allowed error: associated `static` items are not allowed
--> $DIR/assoc-static-semantic-fail.rs:38:5 --> $DIR/assoc-static-semantic-fail.rs:41:5
| |
LL | default static TC: u8 = 0; LL | default static TC: u8 = 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: associated `static` items are not allowed error: associated `static` items are not allowed
--> $DIR/assoc-static-semantic-fail.rs:40:5 --> $DIR/assoc-static-semantic-fail.rs:43:5
| |
LL | pub default static TD: u8; LL | pub default static TD: u8;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: associated constant in `impl` without body
--> $DIR/assoc-static-semantic-fail.rs:11:5
|
LL | static IB: u8;
| ^^^^^^^^^^^^^-
| |
| help: provide a definition for the constant: `= <expr>;`
error: associated constant in `impl` without body
--> $DIR/assoc-static-semantic-fail.rs:16:5
|
LL | pub(crate) default static ID: u8;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
| help: provide a definition for the constant: `= <expr>;`
error: `default` is only allowed on items in `impl` definitions error: `default` is only allowed on items in `impl` definitions
--> $DIR/assoc-static-semantic-fail.rs:24:5 --> $DIR/assoc-static-semantic-fail.rs:26:5
| |
LL | default static TC: u8 = 0; LL | default static TC: u8 = 0;
| -------^^^^^^^^^^^^^^^^^^^ | -------^^^^^^^^^^^^^^^^^^^
@ -79,7 +95,7 @@ LL | default static TC: u8 = 0;
| `default` because of this | `default` because of this
error: `default` is only allowed on items in `impl` definitions error: `default` is only allowed on items in `impl` definitions
--> $DIR/assoc-static-semantic-fail.rs:27:5 --> $DIR/assoc-static-semantic-fail.rs:29:5
| |
LL | pub(crate) default static TD: u8; LL | pub(crate) default static TD: u8;
| ^^^^^^^^^^^-------^^^^^^^^^^^^^^^ | ^^^^^^^^^^^-------^^^^^^^^^^^^^^^
@ -87,17 +103,33 @@ LL | pub(crate) default static TD: u8;
| `default` because of this | `default` because of this
error[E0449]: unnecessary visibility qualifier error[E0449]: unnecessary visibility qualifier
--> $DIR/assoc-static-semantic-fail.rs:27:5 --> $DIR/assoc-static-semantic-fail.rs:29:5
| |
LL | pub(crate) default static TD: u8; LL | pub(crate) default static TD: u8;
| ^^^^^^^^^^ | ^^^^^^^^^^
error: associated constant in `impl` without body
--> $DIR/assoc-static-semantic-fail.rs:38:5
|
LL | static TB: u8;
| ^^^^^^^^^^^^^-
| |
| help: provide a definition for the constant: `= <expr>;`
error: associated constant in `impl` without body
--> $DIR/assoc-static-semantic-fail.rs:43:5
|
LL | pub default static TD: u8;
| ^^^^^^^^^^^^^^^^^^^^^^^^^-
| |
| help: provide a definition for the constant: `= <expr>;`
error[E0449]: unnecessary visibility qualifier error[E0449]: unnecessary visibility qualifier
--> $DIR/assoc-static-semantic-fail.rs:40:5 --> $DIR/assoc-static-semantic-fail.rs:43:5
| |
LL | pub default static TD: u8; LL | pub default static TD: u8;
| ^^^ `pub` not permitted here because it's implied | ^^^ `pub` not permitted here because it's implied
error: aborting due to 16 previous errors error: aborting due to 20 previous errors
For more information about this error, try `rustc --explain E0449`. For more information about this error, try `rustc --explain E0449`.

View file

@ -1,8 +1,12 @@
error: expected item after attributes error: expected item after attributes
--> $DIR/attrs-after-extern-mod.rs:6:5 --> $DIR/attrs-after-extern-mod.rs:6:5
| |
LL | extern {
| - while parsing this item list starting here
LL | #[cfg(stage37)] LL | #[cfg(stage37)]
| ^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^
LL | }
| - the item list ends here
error: aborting due to previous error error: aborting due to previous error

View file

@ -60,3 +60,73 @@ extern "C" {
default macro_rules! foo {} //~ ERROR item cannot be `default` default macro_rules! foo {} //~ ERROR item cannot be `default`
//~^ ERROR item kind not supported in `extern` block //~^ ERROR item kind not supported in `extern` block
} }
#[cfg(FALSE)]
impl S {
default extern crate foo;
//~^ ERROR item kind not supported in `trait` or `impl`
default use foo;
//~^ ERROR item kind not supported in `trait` or `impl`
default static foo: u8;
//~^ ERROR associated `static` items are not allowed
default const foo: u8;
default fn foo();
default mod foo {}
//~^ ERROR item kind not supported in `trait` or `impl`
default extern "C" {}
//~^ ERROR item kind not supported in `trait` or `impl`
default type foo = u8;
default enum foo {}
//~^ ERROR item kind not supported in `trait` or `impl`
default struct foo {}
//~^ ERROR item kind not supported in `trait` or `impl`
default union foo {}
//~^ ERROR item kind not supported in `trait` or `impl`
default trait foo {}
//~^ ERROR item kind not supported in `trait` or `impl`
default trait foo = Ord;
//~^ ERROR item kind not supported in `trait` or `impl`
default impl foo {}
//~^ ERROR item kind not supported in `trait` or `impl`
default!();
default::foo::bar!();
default macro foo {}
//~^ ERROR item kind not supported in `trait` or `impl`
default macro_rules! foo {}
//~^ ERROR item kind not supported in `trait` or `impl`
}
#[cfg(FALSE)]
trait T {
default extern crate foo;
//~^ ERROR item kind not supported in `trait` or `impl`
default use foo;
//~^ ERROR item kind not supported in `trait` or `impl`
default static foo: u8;
//~^ ERROR associated `static` items are not allowed
default const foo: u8;
default fn foo();
default mod foo {}
//~^ ERROR item kind not supported in `trait` or `impl`
default extern "C" {}
//~^ ERROR item kind not supported in `trait` or `impl`
default type foo = u8;
default enum foo {}
//~^ ERROR item kind not supported in `trait` or `impl`
default struct foo {}
//~^ ERROR item kind not supported in `trait` or `impl`
default union foo {}
//~^ ERROR item kind not supported in `trait` or `impl`
default trait foo {}
//~^ ERROR item kind not supported in `trait` or `impl`
default trait foo = Ord;
//~^ ERROR item kind not supported in `trait` or `impl`
default impl foo {}
//~^ ERROR item kind not supported in `trait` or `impl`
default!();
default::foo::bar!();
default macro foo {}
//~^ ERROR item kind not supported in `trait` or `impl`
default macro_rules! foo {}
//~^ ERROR item kind not supported in `trait` or `impl`
}

View file

@ -320,5 +320,161 @@ error: item kind not supported in `extern` block
LL | default macro_rules! foo {} LL | default macro_rules! foo {}
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 43 previous errors error: item kind not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:66:5
|
LL | default extern crate foo;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: item kind not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:68:5
|
LL | default use foo;
| ^^^^^^^^^^^^^^^^
error: associated `static` items are not allowed
--> $DIR/default-on-wrong-item-kind.rs:70:5
|
LL | default static foo: u8;
| ^^^^^^^^^^^^^^^^^^^^^^^
error: item kind not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:74:5
|
LL | default mod foo {}
| ^^^^^^^^^^^^^^^
error: item kind not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:76:5
|
LL | default extern "C" {}
| ^^^^^^^^^^^^^^^^^^
error: item kind not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:79:5
|
LL | default enum foo {}
| ^^^^^^^^^^^^^^^^
error: item kind not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:81:5
|
LL | default struct foo {}
| ^^^^^^^^^^^^^^^^^^
error: item kind not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:83:5
|
LL | default union foo {}
| ^^^^^^^^^^^^^^^^^
error: item kind not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:85:5
|
LL | default trait foo {}
| ^^^^^^^^^^^^^^^^^
error: item kind not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:87:5
|
LL | default trait foo = Ord;
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: item kind not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:89:5
|
LL | default impl foo {}
| ^^^^^^^^^^^^^^^^
error: item kind not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:93:5
|
LL | default macro foo {}
| ^^^^^^^^^^^^^^^^^
error: item kind not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:95:5
|
LL | default macro_rules! foo {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: item kind not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:101:5
|
LL | default extern crate foo;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: item kind not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:103:5
|
LL | default use foo;
| ^^^^^^^^^^^^^^^^
error: associated `static` items are not allowed
--> $DIR/default-on-wrong-item-kind.rs:105:5
|
LL | default static foo: u8;
| ^^^^^^^^^^^^^^^^^^^^^^^
error: item kind not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:109:5
|
LL | default mod foo {}
| ^^^^^^^^^^^^^^^
error: item kind not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:111:5
|
LL | default extern "C" {}
| ^^^^^^^^^^^^^^^^^^
error: item kind not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:114:5
|
LL | default enum foo {}
| ^^^^^^^^^^^^^^^^
error: item kind not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:116:5
|
LL | default struct foo {}
| ^^^^^^^^^^^^^^^^^^
error: item kind not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:118:5
|
LL | default union foo {}
| ^^^^^^^^^^^^^^^^^
error: item kind not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:120:5
|
LL | default trait foo {}
| ^^^^^^^^^^^^^^^^^
error: item kind not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:122:5
|
LL | default trait foo = Ord;
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: item kind not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:124:5
|
LL | default impl foo {}
| ^^^^^^^^^^^^^^^^
error: item kind not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:128:5
|
LL | default macro foo {}
| ^^^^^^^^^^^^^^^^^
error: item kind not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:130:5
|
LL | default macro_rules! foo {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 69 previous errors

View file

@ -0,0 +1,16 @@
fn main() {}
trait Foo {
default!(); //~ ERROR cannot find macro `default` in this scope
default do
//~^ ERROR unmatched `default`
//~| ERROR non-item in item list
}
struct S;
impl S {
default!(); //~ ERROR cannot find macro `default` in this scope
default do
//~^ ERROR unmatched `default`
//~| ERROR non-item in item list
}

View file

@ -0,0 +1,50 @@
error: unmatched `default`
--> $DIR/default-unmatched-assoc.rs:5:5
|
LL | default do
| ^^^^^^^ the unmatched `default`
error: non-item in item list
--> $DIR/default-unmatched-assoc.rs:5:13
|
LL | trait Foo {
| - item list starts here
LL | default!();
LL | default do
| ^^ non-item starts here
...
LL | }
| - item list ends here
error: unmatched `default`
--> $DIR/default-unmatched-assoc.rs:13:5
|
LL | default do
| ^^^^^^^ the unmatched `default`
error: non-item in item list
--> $DIR/default-unmatched-assoc.rs:13:13
|
LL | impl S {
| - item list starts here
LL | default!();
LL | default do
| ^^ non-item starts here
...
LL | }
| - item list ends here
error: cannot find macro `default` in this scope
--> $DIR/default-unmatched-assoc.rs:12:5
|
LL | default!();
| ^^^^^^^
error: cannot find macro `default` in this scope
--> $DIR/default-unmatched-assoc.rs:4:5
|
LL | default!();
| ^^^^^^^
error: aborting due to 6 previous errors

View file

@ -20,7 +20,8 @@ impl Foo for u16 {
impl Foo for u32 { //~ ERROR not all trait items implemented, missing: `foo` impl Foo for u32 { //~ ERROR not all trait items implemented, missing: `foo`
default pub fn foo<T: Default>() -> T { T::default() } default pub fn foo<T: Default>() -> T { T::default() }
//~^ ERROR missing `fn`, `type`, `const`, or `static` for item declaration //~^ ERROR unmatched `default`
//~| ERROR non-item in item list
} }
fn main() {} fn main() {}

View file

@ -1,8 +1,19 @@
error: missing `fn`, `type`, `const`, or `static` for item declaration error: unmatched `default`
--> $DIR/default.rs:22:12 --> $DIR/default.rs:22:5
| |
LL | default pub fn foo<T: Default>() -> T { T::default() } LL | default pub fn foo<T: Default>() -> T { T::default() }
| ^ missing `fn`, `type`, `const`, or `static` | ^^^^^^^ the unmatched `default`
error: non-item in item list
--> $DIR/default.rs:22:13
|
LL | impl Foo for u32 {
| - item list starts here
LL | default pub fn foo<T: Default>() -> T { T::default() }
| ^^^ non-item starts here
...
LL | }
| - item list ends here
error[E0449]: unnecessary visibility qualifier error[E0449]: unnecessary visibility qualifier
--> $DIR/default.rs:16:5 --> $DIR/default.rs:16:5
@ -19,7 +30,7 @@ LL | fn foo<T: Default>() -> T;
LL | impl Foo for u32 { LL | impl Foo for u32 {
| ^^^^^^^^^^^^^^^^ missing `foo` in implementation | ^^^^^^^^^^^^^^^^ missing `foo` in implementation
error: aborting due to 3 previous errors error: aborting due to 4 previous errors
Some errors have detailed explanations: E0046, E0449. Some errors have detailed explanations: E0046, E0449.
For more information about an error, try `rustc --explain E0046`. For more information about an error, try `rustc --explain E0046`.

View file

@ -1,8 +1,12 @@
error: expected one of `!` or `::`, found `(` error: expected one of `!` or `::`, found `(`
--> $DIR/extern-no-fn.rs:2:6 --> $DIR/extern-no-fn.rs:2:6
| |
LL | extern {
| - while parsing this item list starting here
LL | f(); LL | f();
| ^ expected one of `!` or `::` | ^ expected one of `!` or `::`
LL | }
| - the item list ends here
error: aborting due to previous error error: aborting due to previous error

View file

@ -1,6 +1,6 @@
trait T { trait T {
//~^ ERROR missing `fn`, `type`, `const`, or `static` for item declaration
extern "Rust" unsafe fn foo(); extern "Rust" unsafe fn foo();
//~^ ERROR expected `{`, found keyword `unsafe`
} }
fn main() {} fn main() {}

View file

@ -1,11 +1,13 @@
error: missing `fn`, `type`, `const`, or `static` for item declaration error: expected `{`, found keyword `unsafe`
--> $DIR/issue-19398.rs:1:10 --> $DIR/issue-19398.rs:2:19
| |
LL | trait T { LL | trait T {
| __________^ | - while parsing this item list starting here
LL | | LL | extern "Rust" unsafe fn foo();
LL | | extern "Rust" unsafe fn foo(); | ^^^^^^ expected `{`
| |____^ missing `fn`, `type`, `const`, or `static` LL |
LL | }
| - the item list ends here
error: aborting due to previous error error: aborting due to previous error

View file

@ -1,8 +1,14 @@
error: expected item after attributes error: expected item after attributes
--> $DIR/issue-20711-2.rs:6:5 --> $DIR/issue-20711-2.rs:6:5
| |
LL | impl Foo {
| - while parsing this item list starting here
...
LL | #[stable(feature = "rust1", since = "1.0.0")] LL | #[stable(feature = "rust1", since = "1.0.0")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL |
LL | }
| - the item list ends here
error: aborting due to previous error error: aborting due to previous error

View file

@ -1,8 +1,13 @@
error: expected item after attributes error: expected item after attributes
--> $DIR/issue-20711.rs:4:5 --> $DIR/issue-20711.rs:4:5
| |
LL | impl Foo {
| - while parsing this item list starting here
LL | #[stable(feature = "rust1", since = "1.0.0")] LL | #[stable(feature = "rust1", since = "1.0.0")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL |
LL | }
| - the item list ends here
error: aborting due to previous error error: aborting due to previous error

View file

@ -1,6 +1,6 @@
trait MyTrait<T>: Iterator { trait MyTrait<T>: Iterator {
//~^ ERROR missing `fn`, `type`, `const`, or `static` for item declaration
Item = T; Item = T;
//~^ ERROR expected one of `!` or `::`, found `=`
} }
fn main() {} fn main() {}

View file

@ -1,11 +1,13 @@
error: missing `fn`, `type`, `const`, or `static` for item declaration error: expected one of `!` or `::`, found `=`
--> $DIR/issue-21153.rs:1:29 --> $DIR/issue-21153.rs:2:10
| |
LL | trait MyTrait<T>: Iterator { LL | trait MyTrait<T>: Iterator {
| _____________________________^ | - while parsing this item list starting here
LL | | LL | Item = T;
LL | | Item = T; | ^ expected one of `!` or `::`
| |____^ missing `fn`, `type`, `const`, or `static` LL |
LL | }
| - the item list ends here
error: aborting due to previous error error: aborting due to previous error

View file

@ -1,8 +1,11 @@
error: expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `static`, `type`, `unsafe`, `}`, or identifier, found `...` error: non-item in item list
--> $DIR/issue-32446.rs:4:11 --> $DIR/issue-32446.rs:4:11
| |
LL | trait T { ... } LL | trait T { ... }
| ^^^ expected one of 12 possible tokens | - ^^^ - item list ends here
| | |
| | non-item starts here
| item list starts here
error: aborting due to previous error error: aborting due to previous error

View file

@ -1,7 +1,7 @@
struct S; struct S;
impl S { impl S {
pub pub //~ ERROR unmatched visibility `pub`
} //~ ERROR expected one of } //~ ERROR non-item in item list
fn main() {} fn main() {}

View file

@ -1,10 +1,22 @@
error: expected one of `(`, `async`, `const`, `default`, `extern`, `fn`, `static`, `type`, `unsafe`, or identifier, found `}` error: unmatched visibility `pub`
--> $DIR/issue-41155.rs:5:1 --> $DIR/issue-41155.rs:4:5
| |
LL | pub LL | pub
| - expected one of 10 possible tokens | ^^^ the unmatched visibility
|
= help: you likely meant to define an item, e.g., `pub fn foo() {}`
error: non-item in item list
--> $DIR/issue-41155.rs:5:1
|
LL | impl S {
| - item list starts here
LL | pub
LL | } LL | }
| ^ unexpected token | ^
| |
| non-item starts here
| item list ends here
error: aborting due to previous error error: aborting due to 2 previous errors

View file

@ -2,7 +2,11 @@ error: expected `;` or `{`, found `}`
--> $DIR/issue-6610.rs:1:20 --> $DIR/issue-6610.rs:1:20
| |
LL | trait Foo { fn a() } LL | trait Foo { fn a() }
| ^ expected `;` or `{` | - ^
| | |
| | expected `;` or `{`
| | the item list ends here
| while parsing this item list starting here
error: aborting due to previous error error: aborting due to previous error

View file

@ -1,10 +1,13 @@
macro_rules! bah { macro_rules! bah {
($a:expr) => ($a) ($a:expr) => {
//~^ ERROR expected one of `async` $a
}; //~^ ERROR macro expansion ignores token `2` and any following
} }
trait bar { trait Bar {
bah!(2); bah!(2);
} }
fn main() {} fn main() {
let _recovery_witness: () = 0; //~ ERROR mismatched types
}

View file

@ -1,13 +1,22 @@
error: expected one of `async`, `const`, `crate`, `default`, `extern`, `fn`, `pub`, `static`, `type`, `unsafe`, or identifier, found `2` error: macro expansion ignores token `2` and any following
--> $DIR/trait-non-item-macros.rs:2:19 --> $DIR/trait-non-item-macros.rs:3:9
| |
LL | ($a:expr) => ($a) LL | $a
| ^^ expected one of 11 possible tokens | ^^
... ...
LL | bah!(2); LL | bah!(2);
| -------- in this macro invocation | -------- caused by the macro expansion here
| |
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) = note: the usage of `bah!` is likely invalid in trait item context
error: aborting due to previous error error[E0308]: mismatched types
--> $DIR/trait-non-item-macros.rs:12:33
|
LL | let _recovery_witness: () = 0;
| -- ^ expected `()`, found integer
| |
| expected due to this
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0308`.

View file

@ -3,12 +3,11 @@ fn main() {}
impl T for () { //~ ERROR cannot find trait `T` in this scope impl T for () { //~ ERROR cannot find trait `T` in this scope
fn foo(&self) {} fn foo(&self) {}
//~^ ERROR missing `fn`, `type`, `const`, or `static` for item declaration
trait T { trait T { //~ ERROR item kind not supported in `trait` or `impl`
fn foo(&self); fn foo(&self);
} }
pub(crate) struct Bar<T>(); pub(crate) struct Bar<T>(); //~ ERROR item kind not supported in `trait` or `impl`
//~ ERROR this file contains an unclosed delimiter //~ ERROR this file contains an unclosed delimiter

View file

@ -1,5 +1,5 @@
error: this file contains an unclosed delimiter error: this file contains an unclosed delimiter
--> $DIR/missing-close-brace-in-impl-trait.rs:14:52 --> $DIR/missing-close-brace-in-impl-trait.rs:13:52
| |
LL | impl T for () { LL | impl T for () {
| - unclosed delimiter | - unclosed delimiter
@ -7,15 +7,17 @@ LL | impl T for () {
LL | LL |
| ^ | ^
error: missing `fn`, `type`, `const`, or `static` for item declaration error: item kind not supported in `trait` or `impl`
--> $DIR/missing-close-brace-in-impl-trait.rs:5:17 --> $DIR/missing-close-brace-in-impl-trait.rs:7:1
| |
LL | fn foo(&self) {} LL | trait T {
| _________________^ | ^^^^^^^
LL | |
LL | | error: item kind not supported in `trait` or `impl`
LL | | trait T { --> $DIR/missing-close-brace-in-impl-trait.rs:11:1
| |_ missing `fn`, `type`, `const`, or `static` |
LL | pub(crate) struct Bar<T>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0405]: cannot find trait `T` in this scope error[E0405]: cannot find trait `T` in this scope
--> $DIR/missing-close-brace-in-impl-trait.rs:3:6 --> $DIR/missing-close-brace-in-impl-trait.rs:3:6
@ -23,6 +25,6 @@ error[E0405]: cannot find trait `T` in this scope
LL | impl T for () { LL | impl T for () {
| ^ not found in this scope | ^ not found in this scope
error: aborting due to 3 previous errors error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0405`. For more information about this error, try `rustc --explain E0405`.

View file

@ -1,11 +1,11 @@
trait T { trait T {
//~^ ERROR `main` function not found in crate `missing_close_brace_in_trait`
fn foo(&self); fn foo(&self);
pub(crate) struct Bar<T>(); pub(crate) struct Bar<T>();
//~^ ERROR missing `fn`, `type`, `const`, or `static` for item declaration //~^ ERROR item kind not supported in `trait` or `impl`
impl T for Bar<usize> { impl T for Bar<usize> {
//~^ ERROR item kind not supported in `trait` or `impl`
fn foo(&self) {} fn foo(&self) {}
} }

View file

@ -7,24 +7,17 @@ LL | trait T {
LL | fn main() {} LL | fn main() {}
| ^ | ^
error: missing `fn`, `type`, `const`, or `static` for item declaration error: item kind not supported in `trait` or `impl`
--> $DIR/missing-close-brace-in-trait.rs:5:11 --> $DIR/missing-close-brace-in-trait.rs:4:1
| |
LL | pub(crate) struct Bar<T>(); LL | pub(crate) struct Bar<T>();
| ^ missing `fn`, `type`, `const`, or `static` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0601]: `main` function not found in crate `missing_close_brace_in_trait` error: item kind not supported in `trait` or `impl`
--> $DIR/missing-close-brace-in-trait.rs:1:1 --> $DIR/missing-close-brace-in-trait.rs:7:1
| |
LL | / trait T { LL | impl T for Bar<usize> {
LL | | | ^^^^^^^^^^^^^^^^^^^^^
LL | | fn foo(&self);
LL | |
... |
LL | |
LL | | fn main() {}
| |________________________________________________________________^ consider adding a `main` function to `$DIR/missing-close-brace-in-trait.rs`
error: aborting due to 3 previous errors error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0601`.

View file

@ -7,8 +7,13 @@ LL | static fn f() {}
error: expected one of `:`, `;`, or `=`, found `f` error: expected one of `:`, `;`, or `=`, found `f`
--> $DIR/removed-syntax-static-fn.rs:4:15 --> $DIR/removed-syntax-static-fn.rs:4:15
| |
LL | impl S {
| - while parsing this item list starting here
LL | static fn f() {} LL | static fn f() {}
| ^ expected one of `:`, `;`, or `=` | ^ expected one of `:`, `;`, or `=`
...
LL | }
| - the item list ends here
error: missing type for `static` item error: missing type for `static` item
--> $DIR/removed-syntax-static-fn.rs:4:12 --> $DIR/removed-syntax-static-fn.rs:4:12