parse/ast: move `Defaultness` into variants.

This commit is contained in:
Mazdak Farrokhzad 2020-02-23 10:24:30 +01:00
parent 842027f35b
commit 62930d3151
33 changed files with 630 additions and 359 deletions

View File

@ -173,7 +173,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
ids
}
ItemKind::Const(ref ty, ..) => {
ItemKind::Const(_, ref ty, ..) => {
let mut ids = smallvec![i.id];
if self.sess.features_untracked().impl_trait_in_bindings {
let mut visitor = ImplTraitTypeIdVisitor { ids: &mut ids };
@ -264,11 +264,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
let (ty, body_id) = self.lower_const_item(t, span, e.as_deref());
hir::ItemKind::Static(ty, m, body_id)
}
ItemKind::Const(ref t, ref e) => {
ItemKind::Const(_, ref t, ref e) => {
let (ty, body_id) = self.lower_const_item(t, span, e.as_deref());
hir::ItemKind::Const(ty, body_id)
}
ItemKind::Fn(FnSig { ref decl, header }, ref generics, ref body) => {
ItemKind::Fn(_, FnSig { ref decl, header }, ref generics, ref body) => {
let fn_def_id = self.resolver.definitions().local_def_id(id);
self.with_new_scopes(|this| {
this.current_item = Some(ident.span);
@ -297,16 +297,16 @@ impl<'hir> LoweringContext<'_, 'hir> {
ItemKind::Mod(ref m) => hir::ItemKind::Mod(self.lower_mod(m)),
ItemKind::ForeignMod(ref nm) => hir::ItemKind::ForeignMod(self.lower_foreign_mod(nm)),
ItemKind::GlobalAsm(ref ga) => hir::ItemKind::GlobalAsm(self.lower_global_asm(ga)),
ItemKind::TyAlias(ref generics, _, Some(ref ty)) => match ty.kind.opaque_top_hack() {
ItemKind::TyAlias(_, ref gen, _, Some(ref ty)) => match ty.kind.opaque_top_hack() {
None => {
let ty = self.lower_ty(ty, ImplTraitContext::disallowed());
let generics = self.lower_generics(generics, ImplTraitContext::disallowed());
let generics = self.lower_generics(gen, ImplTraitContext::disallowed());
hir::ItemKind::TyAlias(ty, generics)
}
Some(bounds) => {
let ctx = || ImplTraitContext::OpaqueTy(None, hir::OpaqueTyOrigin::Misc);
let ty = hir::OpaqueTy {
generics: self.lower_generics(generics, ctx()),
generics: self.lower_generics(gen, ctx()),
bounds: self.lower_param_bounds(bounds, ctx()),
impl_trait_fn: None,
origin: hir::OpaqueTyOrigin::TypeAlias,
@ -314,7 +314,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
hir::ItemKind::OpaqueTy(ty)
}
},
ItemKind::TyAlias(ref generics, _, None) => {
ItemKind::TyAlias(_, ref generics, _, None) => {
let ty = self.arena.alloc(self.ty(span, hir::TyKind::Err));
let generics = self.lower_generics(generics, ImplTraitContext::disallowed());
hir::ItemKind::TyAlias(ty, generics)
@ -654,7 +654,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
ident: i.ident,
attrs: self.lower_attrs(&i.attrs),
kind: match i.kind {
ForeignItemKind::Fn(ref sig, ref generics, _) => {
ForeignItemKind::Fn(_, ref sig, ref generics, _) => {
let fdec = &sig.decl;
let (generics, (fn_dec, fn_args)) = self.add_in_band_defs(
generics,
@ -675,7 +675,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
let ty = self.lower_ty(t, ImplTraitContext::disallowed());
hir::ForeignItemKind::Static(ty, m)
}
ForeignItemKind::Const(ref t, _) => {
ForeignItemKind::Const(_, ref t, _) => {
// For recovery purposes.
let ty = self.lower_ty(t, ImplTraitContext::disallowed());
hir::ForeignItemKind::Static(ty, Mutability::Not)
@ -758,24 +758,24 @@ impl<'hir> LoweringContext<'_, 'hir> {
let (generics, kind) = match i.kind {
AssocItemKind::Static(ref ty, _, ref default) // Let's pretend this is a `const`.
| AssocItemKind::Const(ref ty, ref default) => {
| AssocItemKind::Const(_, ref ty, ref default) => {
let ty = self.lower_ty(ty, ImplTraitContext::disallowed());
let body = default.as_ref().map(|x| self.lower_const_body(i.span, Some(x)));
(hir::Generics::empty(), hir::TraitItemKind::Const(ty, body))
}
AssocItemKind::Fn(ref sig, ref generics, None) => {
AssocItemKind::Fn(_, ref sig, ref generics, None) => {
let names = self.lower_fn_params_to_names(&sig.decl);
let (generics, sig) =
self.lower_method_sig(generics, sig, trait_item_def_id, false, None);
(generics, hir::TraitItemKind::Method(sig, hir::TraitMethod::Required(names)))
}
AssocItemKind::Fn(ref sig, ref generics, Some(ref body)) => {
AssocItemKind::Fn(_, ref sig, ref generics, Some(ref body)) => {
let body_id = self.lower_fn_body_block(i.span, &sig.decl, Some(body));
let (generics, sig) =
self.lower_method_sig(generics, sig, trait_item_def_id, false, None);
(generics, hir::TraitItemKind::Method(sig, hir::TraitMethod::Provided(body_id)))
}
AssocItemKind::TyAlias(ref generics, ref bounds, ref default) => {
AssocItemKind::TyAlias(_, ref generics, ref bounds, ref default) => {
let ty = default.as_ref().map(|x| self.lower_ty(x, ImplTraitContext::disallowed()));
let generics = self.lower_generics(generics, ImplTraitContext::disallowed());
let kind = hir::TraitItemKind::Type(
@ -801,11 +801,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn lower_trait_item_ref(&mut self, i: &AssocItem) -> hir::TraitItemRef {
let (kind, has_default) = match &i.kind {
AssocItemKind::Static(_, _, default) // Let's pretend this is a `const` for recovery.
| AssocItemKind::Const(_, default) => {
| AssocItemKind::Const(_, _, default) => {
(hir::AssocItemKind::Const, default.is_some())
}
AssocItemKind::TyAlias(_, _, default) => (hir::AssocItemKind::Type, default.is_some()),
AssocItemKind::Fn(sig, _, default) => {
AssocItemKind::TyAlias(_, _, _, default) => (hir::AssocItemKind::Type, default.is_some()),
AssocItemKind::Fn(_, sig, _, default) => {
(hir::AssocItemKind::Method { has_self: sig.decl.has_self() }, default.is_some())
}
AssocItemKind::Macro(..) => unimplemented!(),
@ -823,15 +823,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn lower_impl_item(&mut self, i: &AssocItem) -> hir::ImplItem<'hir> {
let impl_item_def_id = self.resolver.definitions().local_def_id(i.id);
let (generics, kind) = match i.kind {
AssocItemKind::Static(ref ty, _, ref expr) | AssocItemKind::Const(ref ty, ref expr) => {
let (generics, kind) = match &i.kind {
AssocItemKind::Static(ty, _, expr) | AssocItemKind::Const(_, ty, expr) => {
let ty = self.lower_ty(ty, ImplTraitContext::disallowed());
(
hir::Generics::empty(),
hir::ImplItemKind::Const(ty, self.lower_const_body(i.span, expr.as_deref())),
)
}
AssocItemKind::Fn(ref sig, ref generics, ref body) => {
AssocItemKind::Fn(_, sig, generics, body) => {
self.current_item = Some(i.span);
let asyncness = sig.header.asyncness;
let body_id =
@ -847,7 +847,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
(generics, hir::ImplItemKind::Method(sig, body_id))
}
AssocItemKind::TyAlias(ref generics, _, ref ty) => {
AssocItemKind::TyAlias(_, generics, _, ty) => {
let generics = self.lower_generics(generics, ImplTraitContext::disallowed());
let kind = match ty {
None => {
@ -876,7 +876,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
attrs: self.lower_attrs(&i.attrs),
generics,
vis: self.lower_visibility(&i.vis, None),
defaultness: self.lower_defaultness(i.defaultness, true /* [1] */),
defaultness: self.lower_defaultness(i.kind.defaultness(), true /* [1] */),
kind,
span: i.span,
}
@ -890,17 +890,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
ident: i.ident,
span: i.span,
vis: self.lower_visibility(&i.vis, Some(i.id)),
defaultness: self.lower_defaultness(i.defaultness, true /* [1] */),
defaultness: self.lower_defaultness(i.kind.defaultness(), true /* [1] */),
kind: match &i.kind {
AssocItemKind::Static(..) // Let's pretend this is a `const` for recovery.
| AssocItemKind::Const(..) => hir::AssocItemKind::Const,
AssocItemKind::TyAlias(_, _, ty) => {
AssocItemKind::TyAlias(.., ty) => {
match ty.as_deref().and_then(|ty| ty.kind.opaque_top_hack()) {
None => hir::AssocItemKind::Type,
Some(_) => hir::AssocItemKind::OpaqueTy,
}
}
AssocItemKind::Fn(sig, _, _) => {
AssocItemKind::Fn(_, sig, ..) => {
hir::AssocItemKind::Method { has_self: sig.decl.has_self() }
}
AssocItemKind::Macro(..) => unimplemented!(),

View File

@ -462,7 +462,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
ItemKind::Struct(_, ref generics)
| ItemKind::Union(_, ref generics)
| ItemKind::Enum(_, ref generics)
| ItemKind::TyAlias(ref generics, ..)
| ItemKind::TyAlias(_, ref generics, ..)
| ItemKind::Trait(_, _, ref generics, ..) => {
let def_id = self.lctx.resolver.definitions().local_def_id(item.id);
let count = generics
@ -490,7 +490,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.lctx.allocate_hir_id_counter(item.id);
let owner = match (&item.kind, ctxt) {
// Ignore patterns in trait methods without bodies.
(AssocItemKind::Fn(_, _, None), AssocCtxt::Trait) => None,
(AssocItemKind::Fn(_, _, _, None), AssocCtxt::Trait) => None,
_ => Some(item.id),
};
self.with_hir_id_owner(owner, |this| visit::walk_assoc_item(this, item, ctxt));

View File

@ -881,7 +881,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
.emit();
}
}
ItemKind::Fn(ref sig, ref generics, ref body) => {
ItemKind::Fn(def, ref sig, ref generics, ref body) => {
self.check_defaultness(item.span, def);
self.check_const_fn_const_generic(item.span, sig, generics);
if body.is_none() {
@ -965,7 +966,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
self.err_handler().span_err(item.span, "unions cannot have zero fields");
}
}
ItemKind::Const(.., None) => {
ItemKind::Const(def, .., None) => {
self.check_defaultness(item.span, def);
let msg = "free constant item without body";
self.error_item_without_body(item.span, "constant", msg, " = <expr>;");
}
@ -973,7 +975,8 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
let msg = "free static item without body";
self.error_item_without_body(item.span, "static", msg, " = <expr>;");
}
ItemKind::TyAlias(_, ref bounds, ref body) => {
ItemKind::TyAlias(def, _, ref bounds, ref body) => {
self.check_defaultness(item.span, def);
if body.is_none() {
let msg = "free type alias without body";
self.error_item_without_body(item.span, "type", msg, " = <type>;");
@ -988,11 +991,13 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
fn visit_foreign_item(&mut self, fi: &'a ForeignItem) {
match &fi.kind {
ForeignItemKind::Fn(sig, _, body) => {
ForeignItemKind::Fn(def, sig, _, body) => {
self.check_defaultness(fi.span, *def);
self.check_foreign_fn_bodyless(fi.ident, body.as_deref());
self.check_foreign_fn_headerless(fi.ident, fi.span, sig.header);
}
ForeignItemKind::TyAlias(generics, bounds, body) => {
ForeignItemKind::TyAlias(def, generics, bounds, body) => {
self.check_defaultness(fi.span, *def);
self.check_foreign_kind_bodyless(fi.ident, "type", body.as_ref().map(|b| b.span));
self.check_type_no_bounds(bounds, "`extern` blocks");
self.check_foreign_ty_genericless(generics);
@ -1233,19 +1238,19 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
}
fn visit_assoc_item(&mut self, item: &'a AssocItem, ctxt: AssocCtxt) {
if ctxt == AssocCtxt::Trait {
self.check_defaultness(item.span, item.defaultness);
if ctxt == AssocCtxt::Trait || !self.in_trait_impl {
self.check_defaultness(item.span, item.kind.defaultness());
}
if ctxt == AssocCtxt::Impl {
match &item.kind {
AssocItemKind::Const(_, body) => {
AssocItemKind::Const(_, _, body) => {
self.check_impl_item_provided(item.span, body, "constant", " = <expr>;");
}
AssocItemKind::Fn(_, _, body) => {
AssocItemKind::Fn(_, _, _, body) => {
self.check_impl_item_provided(item.span, body, "function", " { <body> }");
}
AssocItemKind::TyAlias(_, bounds, body) => {
AssocItemKind::TyAlias(_, _, bounds, body) => {
self.check_impl_item_provided(item.span, body, "type", " = <type>;");
self.check_type_no_bounds(bounds, "`impl`s");
}
@ -1255,7 +1260,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
if ctxt == AssocCtxt::Trait || self.in_trait_impl {
self.invalid_visibility(&item.vis, None);
if let AssocItemKind::Fn(sig, _, _) = &item.kind {
if let AssocItemKind::Fn(_, sig, _, _) = &item.kind {
self.check_trait_fn_not_const(sig.header.constness);
self.check_trait_fn_not_async(item.span, sig.header.asyncness);
}

View File

@ -372,7 +372,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
gate_feature_post!(&self, decl_macro, i.span, msg);
}
ast::ItemKind::TyAlias(_, _, Some(ref ty)) => self.check_impl_trait(&ty),
ast::ItemKind::TyAlias(_, _, _, Some(ref ty)) => self.check_impl_trait(&ty),
_ => {}
}
@ -543,17 +543,17 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
}
fn visit_assoc_item(&mut self, i: &'a ast::AssocItem, ctxt: AssocCtxt) {
if let ast::Defaultness::Default(_) = i.defaultness {
if let ast::Defaultness::Default(_) = i.kind.defaultness() {
gate_feature_post!(&self, specialization, i.span, "specialization is unstable");
}
match i.kind {
ast::AssocItemKind::Fn(ref sig, _, _) => {
ast::AssocItemKind::Fn(_, ref sig, _, _) => {
if let (ast::Const::Yes(_), AssocCtxt::Trait) = (sig.header.constness, ctxt) {
gate_feature_post!(&self, const_fn, i.span, "const fn is unstable");
}
}
ast::AssocItemKind::TyAlias(ref generics, _, ref ty) => {
ast::AssocItemKind::TyAlias(_, ref generics, _, ref ty) => {
if let (Some(_), AssocCtxt::Trait) = (ty, ctxt) {
gate_feature_post!(
&self,

View File

@ -1016,8 +1016,8 @@ impl<'a> State<'a> {
}
crate fn print_foreign_item(&mut self, item: &ast::ForeignItem) {
let ast::Item { id, span, ident, attrs, kind, vis, defaultness, tokens: _ } = item;
self.print_nested_item_kind(*id, *span, *ident, attrs, *defaultness, kind, vis);
let ast::Item { id, span, ident, attrs, kind, vis, tokens: _ } = item;
self.print_nested_item_kind(*id, *span, *ident, attrs, kind, vis);
}
fn print_nested_item_kind(
@ -1026,7 +1026,6 @@ impl<'a> State<'a> {
span: Span,
ident: ast::Ident,
attrs: &[Attribute],
def: ast::Defaultness,
kind: &ast::AssocItemKind,
vis: &ast::Visibility,
) {
@ -1035,17 +1034,18 @@ impl<'a> State<'a> {
self.maybe_print_comment(span.lo());
self.print_outer_attributes(attrs);
match kind {
ast::ForeignItemKind::Fn(sig, gen, body) => {
self.print_fn_full(sig, ident, gen, vis, def, body.as_deref(), attrs);
ast::ForeignItemKind::Fn(def, sig, gen, body) => {
self.print_fn_full(sig, ident, gen, vis, *def, body.as_deref(), attrs);
}
ast::ForeignItemKind::Const(ty, body) => {
self.print_item_const(ident, None, ty, body.as_deref(), vis, def);
ast::ForeignItemKind::Const(def, ty, body) => {
self.print_item_const(ident, None, ty, body.as_deref(), vis, *def);
}
ast::ForeignItemKind::Static(ty, mutbl, body) => {
let def = ast::Defaultness::Final;
self.print_item_const(ident, Some(*mutbl), ty, body.as_deref(), vis, def);
}
ast::ForeignItemKind::TyAlias(generics, bounds, ty) => {
self.print_associated_type(ident, generics, bounds, ty.as_deref(), vis, def);
ast::ForeignItemKind::TyAlias(def, generics, bounds, ty) => {
self.print_associated_type(ident, generics, bounds, ty.as_deref(), vis, *def);
}
ast::ForeignItemKind::Macro(m) => {
self.print_mac(m);
@ -1146,12 +1146,10 @@ impl<'a> State<'a> {
let def = ast::Defaultness::Final;
self.print_item_const(item.ident, Some(mutbl), ty, body.as_deref(), &item.vis, def);
}
ast::ItemKind::Const(ref ty, ref body) => {
let def = ast::Defaultness::Final;
ast::ItemKind::Const(def, ref ty, ref body) => {
self.print_item_const(item.ident, None, ty, body.as_deref(), &item.vis, def);
}
ast::ItemKind::Fn(ref sig, ref gen, ref body) => {
let def = ast::Defaultness::Final;
ast::ItemKind::Fn(def, ref sig, ref gen, ref body) => {
let body = body.as_deref();
self.print_fn_full(sig, item.ident, gen, &item.vis, def, body, &item.attrs);
}
@ -1185,8 +1183,7 @@ impl<'a> State<'a> {
self.s.word(ga.asm.to_string());
self.end();
}
ast::ItemKind::TyAlias(ref generics, ref bounds, ref ty) => {
let def = ast::Defaultness::Final;
ast::ItemKind::TyAlias(def, ref generics, ref bounds, ref ty) => {
let ty = ty.as_deref();
self.print_associated_type(item.ident, generics, bounds, ty, &item.vis, def);
}
@ -1461,8 +1458,8 @@ impl<'a> State<'a> {
}
crate fn print_assoc_item(&mut self, item: &ast::AssocItem) {
let ast::AssocItem { id, span, ident, attrs, defaultness, kind, vis, tokens: _ } = item;
self.print_nested_item_kind(*id, *span, *ident, attrs, *defaultness, kind, vis);
let ast::Item { id, span, ident, attrs, kind, vis, tokens: _ } = item;
self.print_nested_item_kind(*id, *span, *ident, attrs, kind, vis);
}
crate fn print_stmt(&mut self, st: &ast::Stmt) {

View File

@ -542,9 +542,9 @@ impl<'a> TraitDef<'a> {
span: self.span,
ident,
vis: respan(self.span.shrink_to_lo(), ast::VisibilityKind::Inherited),
defaultness: ast::Defaultness::Final,
attrs: Vec::new(),
kind: ast::AssocItemKind::TyAlias(
ast::Defaultness::Final,
Generics::default(),
Vec::new(),
Some(type_def.to_ty(cx, self.span, type_ident, generics)),
@ -968,6 +968,7 @@ impl<'a> MethodDef<'a> {
header: ast::FnHeader { unsafety, ext: ast::Extern::None, ..ast::FnHeader::default() },
decl: fn_decl,
};
let def = ast::Defaultness::Final;
// Create the method.
P(ast::AssocItem {
@ -975,9 +976,8 @@ impl<'a> MethodDef<'a> {
attrs: self.attributes.clone(),
span: trait_.span,
vis: respan(trait_lo_sp, ast::VisibilityKind::Inherited),
defaultness: ast::Defaultness::Final,
ident: method_ident,
kind: ast::AssocItemKind::Fn(sig, fn_generics, Some(body_block)),
kind: ast::AssocItemKind::Fn(def, sig, fn_generics, Some(body_block)),
tokens: None,
})
}

View File

@ -66,7 +66,8 @@ impl AllocFnFactory<'_, '_> {
let decl = self.cx.fn_decl(abi_args, ast::FnRetTy::Ty(output_ty));
let header = FnHeader { unsafety: Unsafe::Yes(self.span), ..FnHeader::default() };
let sig = FnSig { decl, header };
let kind = ItemKind::Fn(sig, Generics::default(), Some(self.cx.block_expr(output_expr)));
let block = Some(self.cx.block_expr(output_expr));
let kind = ItemKind::Fn(ast::Defaultness::Final, sig, Generics::default(), block);
let item = self.cx.item(
self.span,
self.cx.ident_of(&self.kind.fn_name(method.name), self.span),

View File

@ -30,7 +30,6 @@ pub fn expand_global_asm<'cx>(
id: ast::DUMMY_NODE_ID,
kind: ast::ItemKind::GlobalAsm(P(global_asm)),
vis: respan(sp.shrink_to_lo(), ast::VisibilityKind::Inherited),
defaultness: ast::Defaultness::Final,
span: cx.with_def_site_ctxt(sp),
tokens: None,
})]),

View File

@ -184,6 +184,7 @@ pub fn expand_test_or_bench(
],
// const $ident: test::TestDescAndFn =
ast::ItemKind::Const(
ast::Defaultness::Final,
cx.ty(sp, ast::TyKind::Path(None, test_path("TestDescAndFn"))),
// test::TestDescAndFn {
Some(
@ -378,7 +379,7 @@ fn test_type(cx: &ExtCtxt<'_>) -> TestType {
fn has_test_signature(cx: &ExtCtxt<'_>, i: &ast::Item) -> bool {
let has_should_panic_attr = attr::contains_name(&i.attrs, sym::should_panic);
let ref sd = cx.parse_sess.span_diagnostic;
if let ast::ItemKind::Fn(ref sig, ref generics, _) = i.kind {
if let ast::ItemKind::Fn(_, ref sig, ref generics, _) = i.kind {
if let ast::Unsafe::Yes(span) = sig.header.unsafety {
sd.struct_span_err(i.span, "unsafe functions cannot be used for tests")
.span_label(span, "`unsafe` because of this")
@ -427,7 +428,7 @@ fn has_test_signature(cx: &ExtCtxt<'_>, i: &ast::Item) -> bool {
}
fn has_bench_signature(cx: &ExtCtxt<'_>, i: &ast::Item) -> bool {
let has_sig = if let ast::ItemKind::Fn(ref sig, _, _) = i.kind {
let has_sig = if let ast::ItemKind::Fn(_, ref sig, _, _) = i.kind {
// N.B., inadequate check, but we're running
// well before resolve, can't get too deep.
sig.decl.inputs.len() == 1

View File

@ -162,7 +162,7 @@ impl MutVisitor for EntryPointCleaner {
// #[allow(dead_code)] to avoid printing warnings.
let item = match entry::entry_point_type(&item, self.depth) {
EntryPointType::MainNamed | EntryPointType::MainAttr | EntryPointType::Start => item
.map(|ast::Item { id, ident, attrs, kind, vis, defaultness, span, tokens }| {
.map(|ast::Item { id, ident, attrs, kind, vis, span, tokens }| {
let allow_ident = Ident::new(sym::allow, self.def_site);
let dc_nested = attr::mk_nested_word_item(Ident::from_str_and_span(
"dead_code",
@ -176,7 +176,7 @@ impl MutVisitor for EntryPointCleaner {
.chain(iter::once(allow_dead_code))
.collect();
ast::Item { id, ident, attrs, kind, vis, defaultness, span, tokens }
ast::Item { id, ident, attrs, kind, vis, span, tokens }
}),
EntryPointType::None | EntryPointType::OtherMain => item,
};
@ -298,7 +298,8 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
let decl = ecx.fn_decl(vec![], ast::FnRetTy::Ty(main_ret_ty));
let sig = ast::FnSig { decl, header: ast::FnHeader::default() };
let main = ast::ItemKind::Fn(sig, ast::Generics::default(), Some(main_body));
let def = ast::Defaultness::Final;
let main = ast::ItemKind::Fn(def, sig, ast::Generics::default(), Some(main_body));
// Honor the reexport_test_harness_main attribute
let main_id = match cx.reexport_test_harness_main {
@ -312,7 +313,6 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
id: ast::DUMMY_NODE_ID,
kind: main,
vis: respan(sp, ast::VisibilityKind::Public),
defaultness: ast::Defaultness::Final,
span: sp,
tokens: None,
});

View File

@ -588,7 +588,6 @@ impl<'a> ExtCtxt<'a> {
id: ast::DUMMY_NODE_ID,
kind,
vis: respan(span.shrink_to_lo(), ast::VisibilityKind::Inherited),
defaultness: ast::Defaultness::Final,
span,
tokens: None,
})
@ -645,7 +644,8 @@ impl<'a> ExtCtxt<'a> {
ty: P<ast::Ty>,
expr: P<ast::Expr>,
) -> P<ast::Item> {
self.item(span, name, Vec::new(), ast::ItemKind::Const(ty, Some(expr)))
let def = ast::Defaultness::Final;
self.item(span, name, Vec::new(), ast::ItemKind::Const(def, ty, Some(expr)))
}
pub fn attribute(&self, mi: ast::MetaItem) -> ast::Attribute {

View File

@ -358,7 +358,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
ident: Ident::invalid(),
id: ast::DUMMY_NODE_ID,
vis: respan(krate.span.shrink_to_lo(), ast::VisibilityKind::Public),
defaultness: ast::Defaultness::Final,
tokens: None,
})]);

View File

@ -26,7 +26,6 @@ pub fn placeholder(
let ident = ast::Ident::invalid();
let attrs = Vec::new();
let vis = vis.unwrap_or_else(|| dummy_spanned(ast::VisibilityKind::Inherited));
let defaultness = ast::Defaultness::Final;
let span = DUMMY_SP;
let expr_placeholder = || {
P(ast::Expr {
@ -47,7 +46,6 @@ pub fn placeholder(
span,
ident,
vis,
defaultness,
attrs,
kind: ast::ItemKind::Mac(mac_placeholder()),
tokens: None,
@ -59,7 +57,6 @@ pub fn placeholder(
vis,
attrs,
kind: ast::AssocItemKind::Macro(mac_placeholder()),
defaultness: ast::Defaultness::Final,
tokens: None,
})]),
AstFragmentKind::ImplItems => AstFragment::ImplItems(smallvec![P(ast::AssocItem {
@ -69,7 +66,6 @@ pub fn placeholder(
vis,
attrs,
kind: ast::AssocItemKind::Macro(mac_placeholder()),
defaultness: ast::Defaultness::Final,
tokens: None,
})]),
AstFragmentKind::ForeignItems => {
@ -78,7 +74,6 @@ pub fn placeholder(
span,
ident,
vis,
defaultness,
attrs,
kind: ast::ForeignItemKind::Macro(mac_placeholder()),
tokens: None,

View File

@ -677,7 +677,7 @@ impl<'a> MutVisitor for ReplaceBodyWithLoop<'a, '_> {
fn visit_item_kind(&mut self, i: &mut ast::ItemKind) {
let is_const = match i {
ast::ItemKind::Static(..) | ast::ItemKind::Const(..) => true,
ast::ItemKind::Fn(ref sig, _, _) => Self::is_sig_const(sig),
ast::ItemKind::Fn(_, ref sig, _, _) => Self::is_sig_const(sig),
_ => false,
};
self.run(is_const, |s| noop_visit_item_kind(i, s))
@ -686,7 +686,7 @@ impl<'a> MutVisitor for ReplaceBodyWithLoop<'a, '_> {
fn flat_map_trait_item(&mut self, i: P<ast::AssocItem>) -> SmallVec<[P<ast::AssocItem>; 1]> {
let is_const = match i.kind {
ast::AssocItemKind::Const(..) => true,
ast::AssocItemKind::Fn(ref sig, _, _) => Self::is_sig_const(sig),
ast::AssocItemKind::Fn(_, ref sig, _, _) => Self::is_sig_const(sig),
_ => false,
};
self.run(is_const, |s| noop_flat_map_assoc_item(i, s))

View File

@ -640,7 +640,7 @@ declare_lint_pass!(
impl EarlyLintPass for AnonymousParameters {
fn check_trait_item(&mut self, cx: &EarlyContext<'_>, it: &ast::AssocItem) {
match it.kind {
ast::AssocItemKind::Fn(ref sig, _, _) => {
ast::AssocItemKind::Fn(_, ref sig, _, _) => {
for arg in sig.decl.inputs.iter() {
match arg.pat.kind {
ast::PatKind::Ident(_, ident, None) => {

View File

@ -464,7 +464,6 @@ impl CStore {
legacy: def.legacy,
}),
vis: source_map::respan(local_span.shrink_to_lo(), ast::VisibilityKind::Inherited),
defaultness: ast::Defaultness::Final,
tokens: None,
},
data.root.edition,

View File

@ -36,9 +36,6 @@ impl<'a> Parser<'a> {
attributes_allowed: bool,
) -> PResult<'a, Option<P<Item>>> {
let item = self.parse_item_common(attrs, macros_allowed, attributes_allowed, |_| true)?;
if let Some(ref item) = item {
self.error_on_illegal_default(item.defaultness);
}
Ok(item.map(P))
}
@ -98,9 +95,10 @@ impl<'a> Parser<'a> {
let mut def = self.parse_defaultness();
let kind = self.parse_item_kind(&mut attrs, mac_allowed, lo, &vis, &mut def, req_name)?;
if let Some((ident, kind)) = kind {
self.error_on_unconsumed_default(def, &kind);
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 };
let item = Item { ident, attrs, id, kind, vis, span, tokens: None };
return Ok(Some(item));
}
@ -137,9 +135,10 @@ impl<'a> Parser<'a> {
}
/// Error in-case `default` was parsed in an in-appropriate context.
fn error_on_illegal_default(&self, def: Defaultness) {
fn error_on_unconsumed_default(&self, def: Defaultness, kind: &ItemKind) {
if let Defaultness::Default(span) = def {
self.struct_span_err(span, "item cannot be `default`")
let msg = format!("{} {} cannot be `default`", kind.article(), kind.descr());
self.struct_span_err(span, &msg)
.span_label(span, "`default` because of this")
.note("only associated `fn`, `const`, and `type` items can be `default`")
.emit();
@ -156,6 +155,8 @@ impl<'a> Parser<'a> {
def: &mut Defaultness,
req_name: ReqName,
) -> PResult<'a, Option<ItemInfo>> {
let mut def = || mem::replace(def, Defaultness::Final);
let info = if self.eat_keyword(kw::Use) {
// USE ITEM
let tree = self.parse_use_tree()?;
@ -164,7 +165,7 @@ impl<'a> Parser<'a> {
} else if self.check_fn_front_matter() {
// FUNCTION ITEM
let (ident, sig, generics, body) = self.parse_fn(attrs, req_name)?;
(ident, ItemKind::Fn(sig, generics, body))
(ident, ItemKind::Fn(def(), sig, generics, body))
} else if self.eat_keyword(kw::Extern) {
if self.eat_keyword(kw::Crate) {
// EXTERN CRATE
@ -177,11 +178,13 @@ impl<'a> Parser<'a> {
// STATIC ITEM
self.bump(); // `static`
let m = self.parse_mutability();
self.parse_item_const(Some(m))?
let (ident, ty, expr) = self.parse_item_global(Some(m))?;
(ident, ItemKind::Static(ty, m, expr))
} else if let Const::Yes(const_span) = self.parse_constness() {
// CONST ITEM
self.recover_const_mut(const_span);
self.parse_item_const(None)?
let (ident, ty, expr) = self.parse_item_global(None)?;
(ident, ItemKind::Const(def(), ty, expr))
} else if self.check_keyword(kw::Trait) || self.check_auto_or_unsafe_trait_item() {
// TRAIT ITEM
self.parse_item_trait(attrs, lo)?
@ -189,13 +192,13 @@ impl<'a> Parser<'a> {
|| self.check_keyword(kw::Unsafe) && self.is_keyword_ahead(1, &[kw::Impl])
{
// IMPL ITEM
self.parse_item_impl(attrs, mem::replace(def, Defaultness::Final))?
self.parse_item_impl(attrs, def())?
} else if self.eat_keyword(kw::Mod) {
// MODULE ITEM
self.parse_item_mod(attrs)?
} else if self.eat_keyword(kw::Type) {
// TYPE ITEM
self.parse_type_alias()?
self.parse_type_alias(def())?
} else if self.eat_keyword(kw::Enum) {
// ENUM ITEM
self.parse_item_enum()?
@ -652,19 +655,19 @@ impl<'a> Parser<'a> {
fn parse_assoc_item(&mut self, req_name: ReqName) -> PResult<'a, Option<Option<P<AssocItem>>>> {
let attrs = self.parse_outer_attributes()?;
let it = self.parse_item_common(attrs, true, false, req_name)?;
Ok(it.map(|Item { attrs, id, span, vis, ident, defaultness, kind, tokens }| {
Ok(it.map(|Item { attrs, id, span, vis, ident, kind, tokens }| {
let kind = match kind {
ItemKind::Mac(a) => AssocItemKind::Macro(a),
ItemKind::Fn(a, b, c) => AssocItemKind::Fn(a, b, c),
ItemKind::TyAlias(a, b, c) => AssocItemKind::TyAlias(a, b, c),
ItemKind::Const(a, c) => AssocItemKind::Const(a, c),
ItemKind::Fn(a, b, c, d) => AssocItemKind::Fn(a, b, c, d),
ItemKind::TyAlias(a, b, c, d) => AssocItemKind::TyAlias(a, b, c, d),
ItemKind::Const(a, b, c) => AssocItemKind::Const(a, b, c),
ItemKind::Static(a, _, b) => {
self.struct_span_err(span, "associated `static` items are not allowed").emit();
AssocItemKind::Const(a, b)
AssocItemKind::Const(Defaultness::Final, a, b)
}
_ => return self.error_bad_item_kind(span, &kind, "`trait` or `impl`"),
};
Some(P(Item { attrs, id, span, vis, ident, defaultness, kind, tokens }))
Some(P(Item { attrs, id, span, vis, ident, kind, tokens }))
}))
}
@ -673,7 +676,7 @@ impl<'a> Parser<'a> {
/// TypeAlias = "type" Ident Generics {":" GenericBounds}? {"=" Ty}? ";" ;
/// ```
/// The `"type"` has already been eaten.
fn parse_type_alias(&mut self) -> PResult<'a, (Ident, ItemKind)> {
fn parse_type_alias(&mut self, def: Defaultness) -> PResult<'a, ItemInfo> {
let ident = self.parse_ident()?;
let mut generics = self.parse_generics()?;
@ -685,7 +688,7 @@ impl<'a> Parser<'a> {
let default = if self.eat(&token::Eq) { Some(self.parse_ty()?) } else { None };
self.expect_semi()?;
Ok((ident, ItemKind::TyAlias(generics, bounds, default)))
Ok((ident, ItemKind::TyAlias(def, generics, bounds, default)))
}
/// Parses a `UseTree`.
@ -843,20 +846,19 @@ impl<'a> Parser<'a> {
let attrs = self.parse_outer_attributes()?;
let item = self.parse_item_common(attrs, true, false, |_| true)?;
Ok(item.map(|Item { attrs, id, span, vis, ident, defaultness, kind, tokens }| {
self.error_on_illegal_default(defaultness);
Ok(item.map(|Item { attrs, id, span, vis, ident, kind, tokens }| {
let kind = match kind {
ItemKind::Mac(a) => ForeignItemKind::Macro(a),
ItemKind::Fn(a, b, c) => ForeignItemKind::Fn(a, b, c),
ItemKind::TyAlias(a, b, c) => ForeignItemKind::TyAlias(a, b, c),
ItemKind::Fn(a, b, c, d) => ForeignItemKind::Fn(a, b, c, d),
ItemKind::TyAlias(a, b, c, d) => ForeignItemKind::TyAlias(a, b, c, d),
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);
ForeignItemKind::Static(a, Mutability::Not, b)
}
_ => return self.error_bad_item_kind(span, &kind, "`extern` block"),
};
Some(P(Item { attrs, id, span, vis, ident, defaultness, kind, tokens }))
Some(P(Item { attrs, id, span, vis, ident, kind, tokens }))
}))
}
@ -916,7 +918,10 @@ impl<'a> Parser<'a> {
/// `["const" | ("static" "mut"?)]` already parsed and stored in `m`.
///
/// When `m` is `"const"`, `$ident` may also be `"_"`.
fn parse_item_const(&mut self, m: Option<Mutability>) -> PResult<'a, ItemInfo> {
fn parse_item_global(
&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() }?;
// Parse the type of a `const` or `static mut?` item.
@ -929,12 +934,7 @@ impl<'a> Parser<'a> {
let expr = if self.eat(&token::Eq) { Some(self.parse_expr()?) } else { None };
self.expect_semi()?;
let item = match m {
Some(m) => ItemKind::Static(ty, m, expr),
None => ItemKind::Const(ty, expr),
};
Ok((id, item))
Ok((id, ty, expr))
}
/// We were supposed to parse `:` but the `:` was missing.

View File

@ -718,7 +718,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
}
// These items live in the type namespace.
ItemKind::TyAlias(_, _, ref ty) => {
ItemKind::TyAlias(_, _, _, ref ty) => {
let def_kind = match ty.as_deref().and_then(|ty| ty.kind.opaque_top_hack()) {
None => DefKind::TyAlias,
Some(_) => DefKind::OpaqueTy,
@ -1253,7 +1253,7 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
let (res, ns) = match item.kind {
AssocItemKind::Static(..) // Let's pretend it's a `const` for recovery.
| AssocItemKind::Const(..) => (Res::Def(DefKind::AssocConst, item_def_id), ValueNS),
AssocItemKind::Fn(ref sig, _, _) => {
AssocItemKind::Fn(_, ref sig, _, _) => {
if sig.decl.has_self() {
self.r.has_self.insert(item_def_id);
}

View File

@ -117,7 +117,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
| ItemKind::ExternCrate(..)
| ItemKind::ForeignMod(..)
| ItemKind::TyAlias(..) => DefPathData::TypeNs(i.ident.name),
ItemKind::Fn(sig, generics, body) if sig.header.asyncness.is_async() => {
ItemKind::Fn(_, sig, generics, body) if sig.header.asyncness.is_async() => {
return self.visit_async_fn(
i.id,
i.ident.name,
@ -215,7 +215,7 @@ impl<'a> visit::Visitor<'a> for DefCollector<'a> {
fn visit_assoc_item(&mut self, i: &'a AssocItem, ctxt: visit::AssocCtxt) {
let def_data = match &i.kind {
AssocItemKind::Fn(FnSig { header, decl }, generics, body)
AssocItemKind::Fn(_, FnSig { header, decl }, generics, body)
if header.asyncness.is_async() =>
{
return self.visit_async_fn(

View File

@ -437,8 +437,8 @@ impl<'a, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
}
fn visit_foreign_item(&mut self, foreign_item: &'ast ForeignItem) {
match foreign_item.kind {
ForeignItemKind::Fn(_, ref generics, _)
| ForeignItemKind::TyAlias(ref generics, ..) => {
ForeignItemKind::Fn(_, _, ref generics, _)
| ForeignItemKind::TyAlias(_, ref generics, ..) => {
self.with_generic_param_rib(generics, ItemRibKind(HasGenericParams::Yes), |this| {
visit::walk_foreign_item(this, foreign_item);
});
@ -797,7 +797,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
debug!("(resolving item) resolving {} ({:?})", name, item.kind);
match item.kind {
ItemKind::TyAlias(ref generics, _, _) | ItemKind::Fn(_, ref generics, _) => {
ItemKind::TyAlias(_, ref generics, _, _) | ItemKind::Fn(_, _, ref generics, _) => {
self.with_generic_param_rib(generics, ItemRibKind(HasGenericParams::Yes), |this| {
visit::walk_item(this, item)
});
@ -837,7 +837,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
this.with_trait_items(trait_items, |this| {
match &item.kind {
AssocItemKind::Static(ty, _, default)
| AssocItemKind::Const(ty, default) => {
| AssocItemKind::Const(_, ty, default) => {
this.visit_ty(ty);
// Only impose the restrictions of `ConstRibKind` for an
// actual constant expression in a provided default.
@ -845,10 +845,10 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
this.with_constant_rib(|this| this.visit_expr(expr));
}
}
AssocItemKind::Fn(_, generics, _) => {
AssocItemKind::Fn(_, _, generics, _) => {
walk_assoc_item(this, generics, item);
}
AssocItemKind::TyAlias(generics, _, _) => {
AssocItemKind::TyAlias(_, generics, _, _) => {
walk_assoc_item(this, generics, item);
}
AssocItemKind::Macro(_) => {
@ -878,7 +878,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
});
}
ItemKind::Static(ref ty, _, ref expr) | ItemKind::Const(ref ty, ref expr) => {
ItemKind::Static(ref ty, _, ref expr) | ItemKind::Const(_, ref ty, ref expr) => {
debug!("resolve_item ItemKind::Const");
self.with_item_rib(HasGenericParams::No, |this| {
this.visit_ty(ty);
@ -1015,7 +1015,9 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
trait_items
.iter()
.filter_map(|item| match &item.kind {
AssocItemKind::TyAlias(_, bounds, _) if bounds.len() == 0 => Some(item.ident),
AssocItemKind::TyAlias(_, _, bounds, _) if bounds.len() == 0 => {
Some(item.ident)
}
_ => None,
})
.collect(),
@ -1125,7 +1127,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
visit::walk_assoc_item(this, item, AssocCtxt::Impl)
});
}
AssocItemKind::Fn(_, generics, _) => {
AssocItemKind::Fn(_, _, generics, _) => {
// We also need a new scope for the impl item type parameters.
this.with_generic_param_rib(
generics,
@ -1148,7 +1150,7 @@ impl<'a, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
},
);
}
AssocItemKind::TyAlias(generics, _, _) => {
AssocItemKind::TyAlias(_, generics, _, _) => {
// We also need a new scope for the impl item type parameters.
this.with_generic_param_rib(
generics,

View File

@ -1005,7 +1005,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
let vis_span = trait_item.span.shrink_to_lo();
match trait_item.kind {
ast::AssocItemKind::Static(ref ty, _, ref expr)
| ast::AssocItemKind::Const(ref ty, ref expr) => {
| ast::AssocItemKind::Const(_, ref ty, ref expr) => {
self.process_assoc_const(
trait_item.id,
trait_item.ident,
@ -1016,7 +1016,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
&trait_item.attrs,
);
}
ast::AssocItemKind::Fn(ref sig, ref generics, ref body) => {
ast::AssocItemKind::Fn(_, ref sig, ref generics, ref body) => {
self.process_method(
sig,
body.as_ref().map(|x| &**x),
@ -1027,7 +1027,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
trait_item.span,
);
}
ast::AssocItemKind::TyAlias(_, ref bounds, ref default_ty) => {
ast::AssocItemKind::TyAlias(_, _, ref bounds, ref default_ty) => {
// FIXME do something with _bounds (for type refs)
let name = trait_item.ident.name.to_string();
let qualname = format!(
@ -1076,7 +1076,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
self.process_macro_use(impl_item.span);
match impl_item.kind {
ast::AssocItemKind::Static(ref ty, _, ref expr)
| ast::AssocItemKind::Const(ref ty, ref expr) => {
| ast::AssocItemKind::Const(_, ref ty, ref expr) => {
self.process_assoc_const(
impl_item.id,
impl_item.ident,
@ -1087,7 +1087,7 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
&impl_item.attrs,
);
}
ast::AssocItemKind::Fn(ref sig, ref generics, ref body) => {
ast::AssocItemKind::Fn(_, ref sig, ref generics, ref body) => {
self.process_method(
sig,
body.as_deref(),
@ -1098,8 +1098,8 @@ impl<'l, 'tcx> DumpVisitor<'l, 'tcx> {
impl_item.span,
);
}
ast::AssocItemKind::TyAlias(_, _, None) => {}
ast::AssocItemKind::TyAlias(_, _, Some(ref ty)) => {
ast::AssocItemKind::TyAlias(_, _, _, None) => {}
ast::AssocItemKind::TyAlias(_, _, _, Some(ref ty)) => {
// FIXME: uses of the assoc type should ideally point to this
// 'def' and the name here should be a ref to the def in the
// trait.
@ -1292,11 +1292,11 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
);
}
}
Fn(ref sig, ref ty_params, ref body) => {
Fn(_, ref sig, ref ty_params, ref body) => {
self.process_fn(item, &sig.decl, &sig.header, ty_params, body.as_deref())
}
Static(ref typ, _, ref e) => self.process_static_or_const_item(item, typ, e.as_deref()),
Const(ref typ, ref e) => self.process_static_or_const_item(item, typ, e.as_deref()),
Const(_, ref typ, ref e) => self.process_static_or_const_item(item, typ, e.as_deref()),
Struct(ref def, ref ty_params) | Union(ref def, ref ty_params) => {
self.process_struct(item, def, ty_params)
}
@ -1311,7 +1311,7 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
self.process_mod(item);
visit::walk_mod(self, m);
}
TyAlias(ref ty_params, _, ref ty) => {
TyAlias(_, ref ty_params, _, ref ty) => {
let qualname = format!(
"::{}",
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id))
@ -1520,7 +1520,7 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
let access = access_from!(self.save_ctxt, item, hir_id);
match item.kind {
ast::ForeignItemKind::Fn(ref sig, ref generics, _) => {
ast::ForeignItemKind::Fn(_, ref sig, ref generics, _) => {
let decl = &sig.decl;
if let Some(fn_data) = self.save_ctxt.get_extern_item_data(item) {
down_cast_data!(fn_data, DefData, item.span);
@ -1537,7 +1537,8 @@ impl<'l, 'tcx> Visitor<'l> for DumpVisitor<'l, 'tcx> {
self.visit_ty(&ret_ty);
}
}
ast::ForeignItemKind::Const(ref ty, _) | ast::ForeignItemKind::Static(ref ty, _, _) => {
ast::ForeignItemKind::Const(_, ref ty, _)
| ast::ForeignItemKind::Static(ref ty, _, _) => {
if let Some(var_data) = self.save_ctxt.get_extern_item_data(item) {
down_cast_data!(var_data, DefData, item.span);
self.dumper.dump_def(&access, var_data);

View File

@ -133,7 +133,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id))
);
match item.kind {
ast::ForeignItemKind::Fn(ref sig, ref generics, _) => {
ast::ForeignItemKind::Fn(_, ref sig, ref generics, _) => {
filter!(self.span_utils, item.ident.span);
Some(Data::DefData(Def {
@ -151,7 +151,8 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
attributes: lower_attributes(item.attrs.clone(), self),
}))
}
ast::ForeignItemKind::Const(ref ty, _) | ast::ForeignItemKind::Static(ref ty, _, _) => {
ast::ForeignItemKind::Const(_, ref ty, _)
| ast::ForeignItemKind::Static(ref ty, _, _) => {
filter!(self.span_utils, item.ident.span);
let id = id_from_node_id(item.id, self);
@ -180,7 +181,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
pub fn get_item_data(&self, item: &ast::Item) -> Option<Data> {
match item.kind {
ast::ItemKind::Fn(ref sig, .., ref generics, _) => {
ast::ItemKind::Fn(_, ref sig, .., ref generics, _) => {
let qualname = format!(
"::{}",
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id))
@ -227,7 +228,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
attributes: lower_attributes(item.attrs.clone(), self),
}))
}
ast::ItemKind::Const(ref typ, _) => {
ast::ItemKind::Const(_, ref typ, _) => {
let qualname = format!(
"::{}",
self.tcx.def_path_str(self.tcx.hir().local_def_id_from_node_id(item.id))

View File

@ -345,7 +345,7 @@ impl Sig for ast::Item {
Ok(extend_sig(ty, text, defs, vec![]))
}
ast::ItemKind::Const(ref ty, ref expr) => {
ast::ItemKind::Const(_, ref ty, ref expr) => {
let mut text = "const ".to_owned();
let name = self.ident.to_string();
let defs = vec![SigElement {
@ -369,7 +369,7 @@ impl Sig for ast::Item {
Ok(extend_sig(ty, text, defs, vec![]))
}
ast::ItemKind::Fn(ast::FnSig { ref decl, header }, ref generics, _) => {
ast::ItemKind::Fn(_, ast::FnSig { ref decl, header }, ref generics, _) => {
let mut text = String::new();
if let ast::Const::Yes(_) = header.constness {
text.push_str("const ");
@ -423,7 +423,7 @@ impl Sig for ast::Item {
Ok(Signature { text, defs, refs: vec![] })
}
ast::ItemKind::TyAlias(ref generics, _, ref ty) => {
ast::ItemKind::TyAlias(_, ref generics, _, ref ty) => {
let text = "type ".to_owned();
let mut sig = name_and_generics(text, offset, generics, self.id, self.ident, scx)?;
@ -732,7 +732,7 @@ impl Sig for ast::ForeignItem {
fn make(&self, offset: usize, _parent_id: Option<NodeId>, scx: &SaveContext<'_, '_>) -> Result {
let id = Some(self.id);
match self.kind {
ast::ForeignItemKind::Fn(ref sig, ref generics, _) => {
ast::ForeignItemKind::Fn(_, ref sig, ref generics, _) => {
let decl = &sig.decl;
let mut text = String::new();
text.push_str("fn ");

View File

@ -2421,9 +2421,6 @@ pub struct Item<K = ItemKind> {
/// The name of the item.
/// It might be a dummy name in case of anonymous items.
pub ident: Ident,
/// The `default`ness of this item.
/// This should only occur in syntactically well-formed code in associated contexts.
pub defaultness: Defaultness,
pub kind: K,
@ -2509,11 +2506,11 @@ pub enum ItemKind {
/// A constant item (`const`).
///
/// E.g., `const FOO: i32 = 42;`.
Const(P<Ty>, Option<P<Expr>>),
Const(Defaultness, P<Ty>, Option<P<Expr>>),
/// A function declaration (`fn`).
///
/// E.g., `fn foo(bar: usize) -> usize { .. }`.
Fn(FnSig, Generics, Option<P<Block>>),
Fn(Defaultness, FnSig, Generics, Option<P<Block>>),
/// A module declaration (`mod`).
///
/// E.g., `mod foo;` or `mod foo { .. }`.
@ -2527,7 +2524,7 @@ pub enum ItemKind {
/// A type alias (`type`).
///
/// E.g., `type Foo = Bar<u8>;`.
TyAlias(Generics, GenericBounds, Option<P<Ty>>),
TyAlias(Defaultness, Generics, GenericBounds, Option<P<Ty>>),
/// An enum definition (`enum`).
///
/// E.g., `enum Foo<A, B> { C<A>, D<B> }`.
@ -2607,8 +2604,8 @@ impl ItemKind {
pub fn generics(&self) -> Option<&Generics> {
match self {
Self::Fn(_, generics, _)
| Self::TyAlias(generics, ..)
Self::Fn(_, _, generics, _)
| Self::TyAlias(_, generics, ..)
| Self::Enum(_, generics)
| Self::Struct(_, generics)
| Self::Union(_, generics)
@ -2640,13 +2637,22 @@ pub type AssocItem = Item<AssocItemKind>;
pub enum AssocItemKind {
/// A constant, `const $ident: $ty $def?;` where `def ::= "=" $expr? ;`.
/// If `def` is parsed, then the constant is provided, and otherwise required.
Const(P<Ty>, Option<P<Expr>>),
Const(Defaultness, P<Ty>, Option<P<Expr>>),
/// A static item (`static FOO: u8`).
Static(P<Ty>, Mutability, Option<P<Expr>>),
/// A function.
Fn(FnSig, Generics, Option<P<Block>>),
Fn(Defaultness, FnSig, Generics, Option<P<Block>>),
/// A type.
TyAlias(Generics, GenericBounds, Option<P<Ty>>),
TyAlias(Defaultness, Generics, GenericBounds, Option<P<Ty>>),
/// A macro expanding to items.
Macro(Mac),
}
impl AssocItemKind {
pub fn defaultness(&self) -> Defaultness {
match *self {
Self::Const(def, ..) | Self::Fn(def, ..) | Self::TyAlias(def, ..) => def,
Self::Macro(..) | Self::Static(..) => Defaultness::Final,
}
}
}

View File

@ -890,11 +890,11 @@ pub fn noop_visit_item_kind<T: MutVisitor>(kind: &mut ItemKind, vis: &mut T) {
match kind {
ItemKind::ExternCrate(_orig_name) => {}
ItemKind::Use(use_tree) => vis.visit_use_tree(use_tree),
ItemKind::Static(ty, _, expr) | ItemKind::Const(ty, expr) => {
ItemKind::Static(ty, _, expr) | ItemKind::Const(_, ty, expr) => {
vis.visit_ty(ty);
visit_opt(expr, |expr| vis.visit_expr(expr));
}
ItemKind::Fn(sig, generics, body) => {
ItemKind::Fn(_, sig, generics, body) => {
visit_fn_sig(sig, vis);
vis.visit_generics(generics);
visit_opt(body, |body| vis.visit_block(body));
@ -902,7 +902,7 @@ pub fn noop_visit_item_kind<T: MutVisitor>(kind: &mut ItemKind, vis: &mut T) {
ItemKind::Mod(m) => vis.visit_mod(m),
ItemKind::ForeignMod(nm) => vis.visit_foreign_mod(nm),
ItemKind::GlobalAsm(_ga) => {}
ItemKind::TyAlias(generics, bounds, ty) => {
ItemKind::TyAlias(_, generics, bounds, ty) => {
vis.visit_generics(generics);
visit_bounds(bounds, vis);
visit_opt(ty, |ty| vis.visit_ty(ty));
@ -948,7 +948,7 @@ pub fn noop_flat_map_assoc_item<T: MutVisitor>(
mut item: P<AssocItem>,
visitor: &mut T,
) -> SmallVec<[P<AssocItem>; 1]> {
let Item { id, ident, vis, defaultness: _, attrs, kind, span, tokens: _ } = item.deref_mut();
let Item { id, ident, vis, attrs, kind, span, tokens: _ } = item.deref_mut();
walk_nested_item(visitor, id, span, ident, vis, attrs, kind);
smallvec![item]
}
@ -967,16 +967,16 @@ pub fn walk_nested_item(
visitor.visit_vis(vis);
visit_attrs(attrs, visitor);
match kind {
AssocItemKind::Const(ty, expr) | AssocItemKind::Static(ty, _, expr) => {
AssocItemKind::Const(_, ty, expr) | AssocItemKind::Static(ty, _, expr) => {
visitor.visit_ty(ty);
visit_opt(expr, |expr| visitor.visit_expr(expr));
}
AssocItemKind::Fn(sig, generics, body) => {
AssocItemKind::Fn(_, sig, generics, body) => {
visitor.visit_generics(generics);
visit_fn_sig(sig, visitor);
visit_opt(body, |body| visitor.visit_block(body));
}
AssocItemKind::TyAlias(generics, bounds, ty) => {
AssocItemKind::TyAlias(_, generics, bounds, ty) => {
visitor.visit_generics(generics);
visit_bounds(bounds, visitor);
visit_opt(ty, |ty| visitor.visit_ty(ty));
@ -1003,7 +1003,6 @@ pub fn noop_visit_crate<T: MutVisitor>(krate: &mut Crate, vis: &mut T) {
attrs,
id: DUMMY_NODE_ID,
vis: respan(span.shrink_to_lo(), VisibilityKind::Public),
defaultness: Defaultness::Final,
span,
kind: ItemKind::Mod(module),
tokens: None,
@ -1031,7 +1030,7 @@ pub fn noop_flat_map_item<T: MutVisitor>(
mut item: P<Item>,
visitor: &mut T,
) -> SmallVec<[P<Item>; 1]> {
let Item { ident, attrs, id, kind, vis, defaultness: _, span, tokens: _ } = item.deref_mut();
let Item { ident, attrs, id, kind, vis, span, tokens: _ } = item.deref_mut();
visitor.visit_ident(ident);
visit_attrs(attrs, visitor);
visitor.visit_id(id);
@ -1049,7 +1048,7 @@ pub fn noop_flat_map_foreign_item<T: MutVisitor>(
mut item: P<ForeignItem>,
visitor: &mut T,
) -> SmallVec<[P<ForeignItem>; 1]> {
let Item { ident, attrs, id, kind, vis, defaultness: _, span, tokens: _ } = item.deref_mut();
let Item { ident, attrs, id, kind, vis, span, tokens: _ } = item.deref_mut();
walk_nested_item(visitor, id, span, ident, vis, attrs, kind);
smallvec![item]
}

View File

@ -298,11 +298,11 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
}
}
ItemKind::Use(ref use_tree) => visitor.visit_use_tree(use_tree, item.id, false),
ItemKind::Static(ref typ, _, ref expr) | ItemKind::Const(ref typ, ref expr) => {
ItemKind::Static(ref typ, _, ref expr) | ItemKind::Const(_, ref typ, ref expr) => {
visitor.visit_ty(typ);
walk_list!(visitor, visit_expr, expr);
}
ItemKind::Fn(ref sig, ref generics, ref body) => {
ItemKind::Fn(_, ref sig, ref generics, ref body) => {
visitor.visit_generics(generics);
let kind = FnKind::Fn(FnCtxt::Free, item.ident, sig, &item.vis, body.as_deref());
visitor.visit_fn(kind, item.span, item.id)
@ -312,7 +312,7 @@ pub fn walk_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a Item) {
walk_list!(visitor, visit_foreign_item, &foreign_module.items);
}
ItemKind::GlobalAsm(ref ga) => visitor.visit_global_asm(ga),
ItemKind::TyAlias(ref generics, ref bounds, ref ty) => {
ItemKind::TyAlias(_, ref generics, ref bounds, ref ty) => {
visitor.visit_generics(generics);
walk_list!(visitor, visit_param_bound, bounds);
walk_list!(visitor, visit_ty, ty);
@ -526,7 +526,7 @@ pub fn walk_pat<'a, V: Visitor<'a>>(visitor: &mut V, pattern: &'a Pat) {
}
pub fn walk_foreign_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a ForeignItem) {
let ForeignItem { id, span, ident, vis, defaultness: _, attrs, kind, tokens: _ } = item;
let Item { id, span, ident, vis, attrs, kind, tokens: _ } = item;
walk_nested_item(visitor, *id, *span, *ident, vis, attrs, kind, FnCtxt::Foreign);
}
@ -610,7 +610,7 @@ pub fn walk_fn<'a, V: Visitor<'a>>(visitor: &mut V, kind: FnKind<'a>, _span: Spa
}
pub fn walk_assoc_item<'a, V: Visitor<'a>>(visitor: &mut V, item: &'a AssocItem, ctxt: AssocCtxt) {
let AssocItem { id, span, ident, vis, attrs, kind, tokens: _, defaultness: _ } = item;
let Item { id, span, ident, vis, attrs, kind, tokens: _ } = item;
walk_nested_item(visitor, *id, *span, *ident, vis, attrs, kind, FnCtxt::Assoc(ctxt));
}
@ -628,16 +628,16 @@ fn walk_nested_item<'a, V: Visitor<'a>>(
visitor.visit_ident(ident);
walk_list!(visitor, visit_attribute, attrs);
match kind {
AssocItemKind::Const(ty, expr) | AssocItemKind::Static(ty, _, expr) => {
AssocItemKind::Const(_, ty, expr) | AssocItemKind::Static(ty, _, expr) => {
visitor.visit_ty(ty);
walk_list!(visitor, visit_expr, expr);
}
AssocItemKind::Fn(sig, generics, body) => {
AssocItemKind::Fn(_, sig, generics, body) => {
visitor.visit_generics(generics);
let kind = FnKind::Fn(ctxt, ident, sig, vis, body.as_deref());
visitor.visit_fn(kind, span, id);
}
AssocItemKind::TyAlias(generics, bounds, ty) => {
AssocItemKind::TyAlias(_, generics, bounds, ty) => {
visitor.visit_generics(generics);
walk_list!(visitor, visit_param_bound, bounds);
walk_list!(visitor, visit_ty, ty);

View File

@ -1 +1 @@
{"module":{"inner":{"lo":0,"hi":0},"items":[{"attrs":[],"id":0,"span":{"lo":0,"hi":0},"vis":{"node":"Inherited","span":{"lo":0,"hi":0}},"ident":{"name":"core","span":{"lo":0,"hi":0}},"defaultness":"Final","kind":{"variant":"ExternCrate","fields":[null]},"tokens":{"_field0":[[{"variant":"Token","fields":[{"kind":{"variant":"Ident","fields":["extern",false]},"span":{"lo":0,"hi":0}}]},"NonJoint"],[{"variant":"Token","fields":[{"kind":{"variant":"Ident","fields":["crate",false]},"span":{"lo":0,"hi":0}}]},"NonJoint"],[{"variant":"Token","fields":[{"kind":{"variant":"Ident","fields":["core",false]},"span":{"lo":0,"hi":0}}]},"NonJoint"],[{"variant":"Token","fields":[{"kind":"Semi","span":{"lo":0,"hi":0}}]},"NonJoint"]]}}],"inline":true},"attrs":[],"span":{"lo":0,"hi":0},"proc_macros":[]}
{"module":{"inner":{"lo":0,"hi":0},"items":[{"attrs":[],"id":0,"span":{"lo":0,"hi":0},"vis":{"node":"Inherited","span":{"lo":0,"hi":0}},"ident":{"name":"core","span":{"lo":0,"hi":0}},"kind":{"variant":"ExternCrate","fields":[null]},"tokens":{"_field0":[[{"variant":"Token","fields":[{"kind":{"variant":"Ident","fields":["extern",false]},"span":{"lo":0,"hi":0}}]},"NonJoint"],[{"variant":"Token","fields":[{"kind":{"variant":"Ident","fields":["crate",false]},"span":{"lo":0,"hi":0}}]},"NonJoint"],[{"variant":"Token","fields":[{"kind":{"variant":"Ident","fields":["core",false]},"span":{"lo":0,"hi":0}}]},"NonJoint"],[{"variant":"Token","fields":[{"kind":"Semi","span":{"lo":0,"hi":0}}]},"NonJoint"]]}}],"inline":true},"attrs":[],"span":{"lo":0,"hi":0},"proc_macros":[]}

View File

@ -13,9 +13,11 @@ impl S {
//~| ERROR associated constant in `impl` without body
default static IC: u8 = 0;
//~^ ERROR associated `static` items are not allowed
//~| ERROR a static item cannot be `default`
pub(crate) default static ID: u8;
//~^ ERROR associated `static` items are not allowed
//~| ERROR associated constant in `impl` without body
//~| ERROR a static item cannot be `default`
}
trait T {
@ -25,11 +27,11 @@ trait T {
//~^ ERROR associated `static` items are not allowed
default static TC: u8 = 0;
//~^ ERROR associated `static` items are not allowed
//~| ERROR `default` is only allowed on items in
//~| ERROR a static item cannot be `default`
pub(crate) default static TD: u8;
//~^ ERROR associated `static` items are not allowed
//~| ERROR `default` is only allowed on items in
//~| ERROR unnecessary visibility qualifier
//~| ERROR a static item cannot be `default`
}
impl T for S {
@ -40,8 +42,10 @@ impl T for S {
//~| ERROR associated constant in `impl` without body
default static TC: u8 = 0;
//~^ ERROR associated `static` items are not allowed
//~| ERROR a static item cannot be `default`
pub default static TD: u8;
//~^ ERROR associated `static` items are not allowed
//~| ERROR associated constant in `impl` without body
//~| ERROR unnecessary visibility qualifier
//~| ERROR a static item cannot be `default`
}

View File

@ -10,62 +10,110 @@ error: associated `static` items are not allowed
LL | static IB: u8;
| ^^^^^^^^^^^^^^
error: a static item cannot be `default`
--> $DIR/assoc-static-semantic-fail.rs:14:5
|
LL | default static IC: u8 = 0;
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: associated `static` items are not allowed
--> $DIR/assoc-static-semantic-fail.rs:14:5
|
LL | default static IC: u8 = 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a static item cannot be `default`
--> $DIR/assoc-static-semantic-fail.rs:17:16
|
LL | pub(crate) default static ID: u8;
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: associated `static` items are not allowed
--> $DIR/assoc-static-semantic-fail.rs:16:5
--> $DIR/assoc-static-semantic-fail.rs:17:5
|
LL | pub(crate) default static ID: u8;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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 TA: u8 = 0;
| ^^^^^^^^^^^^^^^^^^
error: associated `static` items are not allowed
--> $DIR/assoc-static-semantic-fail.rs:24:5
--> $DIR/assoc-static-semantic-fail.rs:26:5
|
LL | static TB: u8;
| ^^^^^^^^^^^^^^
error: a static item cannot be `default`
--> $DIR/assoc-static-semantic-fail.rs:28:5
|
LL | default static TC: u8 = 0;
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: associated `static` items are not allowed
--> $DIR/assoc-static-semantic-fail.rs:26:5
--> $DIR/assoc-static-semantic-fail.rs:28:5
|
LL | default static TC: u8 = 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a static item cannot be `default`
--> $DIR/assoc-static-semantic-fail.rs:31:16
|
LL | pub(crate) default static TD: u8;
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: associated `static` items are not allowed
--> $DIR/assoc-static-semantic-fail.rs:29:5
--> $DIR/assoc-static-semantic-fail.rs:31:5
|
LL | pub(crate) default static TD: u8;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
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 TA: u8 = 0;
| ^^^^^^^^^^^^^^^^^^
error: associated `static` items are not allowed
--> $DIR/assoc-static-semantic-fail.rs:38:5
--> $DIR/assoc-static-semantic-fail.rs:40:5
|
LL | static TB: u8;
| ^^^^^^^^^^^^^^
error: a static item cannot be `default`
--> $DIR/assoc-static-semantic-fail.rs:43:5
|
LL | default static TC: u8 = 0;
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: associated `static` items are not allowed
--> $DIR/assoc-static-semantic-fail.rs:41:5
--> $DIR/assoc-static-semantic-fail.rs:43:5
|
LL | default static TC: u8 = 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a static item cannot be `default`
--> $DIR/assoc-static-semantic-fail.rs:46:9
|
LL | pub default static TD: u8;
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: associated `static` items are not allowed
--> $DIR/assoc-static-semantic-fail.rs:43:5
--> $DIR/assoc-static-semantic-fail.rs:46:5
|
LL | pub default static TD: u8;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -79,37 +127,21 @@ 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
--> $DIR/assoc-static-semantic-fail.rs:17: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
--> $DIR/assoc-static-semantic-fail.rs:26:5
|
LL | default static TC: u8 = 0;
| -------^^^^^^^^^^^^^^^^^^^
| |
| `default` because of this
error: `default` is only allowed on items in `impl` definitions
--> $DIR/assoc-static-semantic-fail.rs:29:5
|
LL | pub(crate) default static TD: u8;
| ^^^^^^^^^^^-------^^^^^^^^^^^^^^^
| |
| `default` because of this
error[E0449]: unnecessary visibility qualifier
--> $DIR/assoc-static-semantic-fail.rs:29:5
--> $DIR/assoc-static-semantic-fail.rs:31:5
|
LL | pub(crate) default static TD: u8;
| ^^^^^^^^^^
error: associated constant in `impl` without body
--> $DIR/assoc-static-semantic-fail.rs:38:5
--> $DIR/assoc-static-semantic-fail.rs:40:5
|
LL | static TB: u8;
| ^^^^^^^^^^^^^-
@ -117,7 +149,7 @@ 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
--> $DIR/assoc-static-semantic-fail.rs:46:5
|
LL | pub default static TD: u8;
| ^^^^^^^^^^^^^^^^^^^^^^^^^-
@ -125,11 +157,11 @@ LL | pub default static TD: u8;
| help: provide a definition for the constant: `= <expr>;`
error[E0449]: unnecessary visibility qualifier
--> $DIR/assoc-static-semantic-fail.rs:43:5
--> $DIR/assoc-static-semantic-fail.rs:46:5
|
LL | pub default static TD: u8;
| ^^^ `pub` not permitted here because it's implied
error: aborting due to 20 previous errors
error: aborting due to 24 previous errors
For more information about this error, try `rustc --explain E0449`.

View File

@ -7,7 +7,9 @@ impl S {
static IA: u8 = 0; //~ ERROR associated `static` items are not allowed
static IB: u8; //~ ERROR associated `static` items are not allowed
default static IC: u8 = 0; //~ ERROR associated `static` items are not allowed
//~^ ERROR a static item cannot be `default`
pub(crate) default static ID: u8; //~ ERROR associated `static` items are not allowed
//~^ ERROR a static item cannot be `default`
}
#[cfg(FALSE)]
@ -15,7 +17,9 @@ trait T {
static TA: u8 = 0; //~ ERROR associated `static` items are not allowed
static TB: u8; //~ ERROR associated `static` items are not allowed
default static TC: u8 = 0; //~ ERROR associated `static` items are not allowed
//~^ ERROR a static item cannot be `default`
pub(crate) default static TD: u8; //~ ERROR associated `static` items are not allowed
//~^ ERROR a static item cannot be `default`
}
#[cfg(FALSE)]
@ -23,5 +27,7 @@ impl T for S {
static TA: u8 = 0; //~ ERROR associated `static` items are not allowed
static TB: u8; //~ ERROR associated `static` items are not allowed
default static TC: u8 = 0; //~ ERROR associated `static` items are not allowed
//~^ ERROR a static item cannot be `default`
pub default static TD: u8; //~ ERROR associated `static` items are not allowed
//~^ ERROR a static item cannot be `default`
}

View File

@ -10,65 +10,113 @@ error: associated `static` items are not allowed
LL | static IB: u8;
| ^^^^^^^^^^^^^^
error: a static item cannot be `default`
--> $DIR/assoc-static-syntactic-fail.rs:9:5
|
LL | default static IC: u8 = 0;
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: associated `static` items are not allowed
--> $DIR/assoc-static-syntactic-fail.rs:9:5
|
LL | default static IC: u8 = 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a static item cannot be `default`
--> $DIR/assoc-static-syntactic-fail.rs:11:16
|
LL | pub(crate) default static ID: u8;
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: associated `static` items are not allowed
--> $DIR/assoc-static-syntactic-fail.rs:10:5
--> $DIR/assoc-static-syntactic-fail.rs:11:5
|
LL | pub(crate) default static ID: u8;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: associated `static` items are not allowed
--> $DIR/assoc-static-syntactic-fail.rs:15:5
--> $DIR/assoc-static-syntactic-fail.rs:17:5
|
LL | static TA: u8 = 0;
| ^^^^^^^^^^^^^^^^^^
error: associated `static` items are not allowed
--> $DIR/assoc-static-syntactic-fail.rs:16:5
--> $DIR/assoc-static-syntactic-fail.rs:18:5
|
LL | static TB: u8;
| ^^^^^^^^^^^^^^
error: a static item cannot be `default`
--> $DIR/assoc-static-syntactic-fail.rs:19:5
|
LL | default static TC: u8 = 0;
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: associated `static` items are not allowed
--> $DIR/assoc-static-syntactic-fail.rs:17:5
--> $DIR/assoc-static-syntactic-fail.rs:19:5
|
LL | default static TC: u8 = 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a static item cannot be `default`
--> $DIR/assoc-static-syntactic-fail.rs:21:16
|
LL | pub(crate) default static TD: u8;
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: associated `static` items are not allowed
--> $DIR/assoc-static-syntactic-fail.rs:18:5
--> $DIR/assoc-static-syntactic-fail.rs:21:5
|
LL | pub(crate) default static TD: u8;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: associated `static` items are not allowed
--> $DIR/assoc-static-syntactic-fail.rs:23:5
--> $DIR/assoc-static-syntactic-fail.rs:27:5
|
LL | static TA: u8 = 0;
| ^^^^^^^^^^^^^^^^^^
error: associated `static` items are not allowed
--> $DIR/assoc-static-syntactic-fail.rs:24:5
--> $DIR/assoc-static-syntactic-fail.rs:28:5
|
LL | static TB: u8;
| ^^^^^^^^^^^^^^
error: a static item cannot be `default`
--> $DIR/assoc-static-syntactic-fail.rs:29:5
|
LL | default static TC: u8 = 0;
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: associated `static` items are not allowed
--> $DIR/assoc-static-syntactic-fail.rs:25:5
--> $DIR/assoc-static-syntactic-fail.rs:29:5
|
LL | default static TC: u8 = 0;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: a static item cannot be `default`
--> $DIR/assoc-static-syntactic-fail.rs:31:9
|
LL | pub default static TD: u8;
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: associated `static` items are not allowed
--> $DIR/assoc-static-syntactic-fail.rs:26:5
--> $DIR/assoc-static-syntactic-fail.rs:31:5
|
LL | pub default static TD: u8;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 12 previous errors
error: aborting due to 18 previous errors

View File

@ -6,135 +6,135 @@ fn main() {}
#[cfg(FALSE)]
mod free_items {
default extern crate foo; //~ ERROR item cannot be `default`
default use foo; //~ ERROR item cannot be `default`
default static foo: u8; //~ ERROR item cannot be `default`
default const foo: u8; //~ ERROR item cannot be `default`
default fn foo(); //~ ERROR item cannot be `default`
default mod foo {} //~ ERROR item cannot be `default`
default extern "C" {} //~ ERROR item cannot be `default`
default type foo = u8; //~ ERROR item cannot be `default`
default enum foo {} //~ ERROR item cannot be `default`
default struct foo {} //~ ERROR item cannot be `default`
default union foo {} //~ ERROR item cannot be `default`
default trait foo {} //~ ERROR item cannot be `default`
default trait foo = Ord; //~ ERROR item cannot be `default`
default extern crate foo; //~ ERROR an extern crate cannot be `default`
default use foo; //~ ERROR a `use` import cannot be `default`
default static foo: u8; //~ ERROR a static item cannot be `default`
default const foo: u8;
default fn foo();
default mod foo {} //~ ERROR a module cannot be `default`
default extern "C" {} //~ ERROR an extern block cannot be `default`
default type foo = u8;
default enum foo {} //~ ERROR an enum cannot be `default`
default struct foo {} //~ ERROR a struct cannot be `default`
default union foo {} //~ ERROR a union cannot be `default`
default trait foo {} //~ ERROR a trait cannot be `default`
default trait foo = Ord; //~ ERROR a trait alias cannot be `default`
default impl foo {}
default!();
default::foo::bar!();
default default!(); //~ ERROR item cannot be `default`
default default::foo::bar!(); //~ ERROR item cannot be `default`
default macro foo {} //~ ERROR item cannot be `default`
default macro_rules! foo {} //~ ERROR item cannot be `default`
default default!(); //~ ERROR an item macro invocation cannot be `default`
default default::foo::bar!(); //~ ERROR an item macro invocation cannot be `default`
default macro foo {} //~ ERROR a macro definition cannot be `default`
default macro_rules! foo {} //~ ERROR a macro definition cannot be `default`
}
#[cfg(FALSE)]
extern "C" {
default extern crate foo; //~ ERROR item cannot be `default`
default extern crate foo; //~ ERROR an extern crate cannot be `default`
//~^ ERROR extern crate not supported in `extern` block
default use foo; //~ ERROR item cannot be `default`
default use foo; //~ ERROR a `use` import cannot be `default`
//~^ ERROR `use` import not supported in `extern` block
default static foo: u8; //~ ERROR item cannot be `default`
default const foo: u8; //~ ERROR item cannot be `default`
default static foo: u8; //~ ERROR a static item cannot be `default`
default const foo: u8;
//~^ ERROR extern items cannot be `const`
default fn foo(); //~ ERROR item cannot be `default`
default mod foo {} //~ ERROR item cannot be `default`
default fn foo();
default mod foo {} //~ ERROR a module cannot be `default`
//~^ ERROR module not supported in `extern` block
default extern "C" {} //~ ERROR item cannot be `default`
default extern "C" {} //~ ERROR an extern block cannot be `default`
//~^ ERROR extern block not supported in `extern` block
default type foo = u8; //~ ERROR item cannot be `default`
default enum foo {} //~ ERROR item cannot be `default`
default type foo = u8;
default enum foo {} //~ ERROR an enum cannot be `default`
//~^ ERROR enum not supported in `extern` block
default struct foo {} //~ ERROR item cannot be `default`
default struct foo {} //~ ERROR a struct cannot be `default`
//~^ ERROR struct not supported in `extern` block
default union foo {} //~ ERROR item cannot be `default`
default union foo {} //~ ERROR a union cannot be `default`
//~^ ERROR union not supported in `extern` block
default trait foo {} //~ ERROR item cannot be `default`
default trait foo {} //~ ERROR a trait cannot be `default`
//~^ ERROR trait not supported in `extern` block
default trait foo = Ord; //~ ERROR item cannot be `default`
default trait foo = Ord; //~ ERROR a trait alias cannot be `default`
//~^ ERROR trait alias not supported in `extern` block
default impl foo {}
//~^ ERROR implementation not supported in `extern` block
default!();
default::foo::bar!();
default default!(); //~ ERROR item cannot be `default`
default default::foo::bar!(); //~ ERROR item cannot be `default`
default macro foo {} //~ ERROR item cannot be `default`
default default!(); //~ ERROR an item macro invocation cannot be `default`
default default::foo::bar!(); //~ ERROR an item macro invocation cannot be `default`
default macro foo {} //~ ERROR a macro definition cannot be `default`
//~^ ERROR macro definition not supported in `extern` block
default macro_rules! foo {} //~ ERROR item cannot be `default`
default macro_rules! foo {} //~ ERROR a macro definition cannot be `default`
//~^ ERROR macro definition not supported in `extern` block
}
#[cfg(FALSE)]
impl S {
default extern crate foo;
default extern crate foo; //~ ERROR an extern crate cannot be `default`
//~^ ERROR extern crate not supported in `trait` or `impl`
default use foo;
default use foo; //~ ERROR a `use` import cannot be `default`
//~^ ERROR `use` import not supported in `trait` or `impl`
default static foo: u8;
default static foo: u8; //~ ERROR a static item cannot be `default`
//~^ ERROR associated `static` items are not allowed
default const foo: u8;
default fn foo();
default mod foo {}
default mod foo {}//~ ERROR a module cannot be `default`
//~^ ERROR module not supported in `trait` or `impl`
default extern "C" {}
default extern "C" {} //~ ERROR an extern block cannot be `default`
//~^ ERROR extern block not supported in `trait` or `impl`
default type foo = u8;
default enum foo {}
default enum foo {} //~ ERROR an enum cannot be `default`
//~^ ERROR enum not supported in `trait` or `impl`
default struct foo {}
default struct foo {} //~ ERROR a struct cannot be `default`
//~^ ERROR struct not supported in `trait` or `impl`
default union foo {}
default union foo {} //~ ERROR a union cannot be `default`
//~^ ERROR union not supported in `trait` or `impl`
default trait foo {}
default trait foo {} //~ ERROR a trait cannot be `default`
//~^ ERROR trait not supported in `trait` or `impl`
default trait foo = Ord;
default trait foo = Ord; //~ ERROR a trait alias cannot be `default`
//~^ ERROR trait alias not supported in `trait` or `impl`
default impl foo {}
//~^ ERROR implementation not supported in `trait` or `impl`
default!();
default::foo::bar!();
default default!();
default default::foo::bar!();
default macro foo {}
default default!(); //~ ERROR an item macro invocation cannot be `default`
default default::foo::bar!(); //~ ERROR an item macro invocation cannot be `default`
default macro foo {} //~ ERROR a macro definition cannot be `default`
//~^ ERROR macro definition not supported in `trait` or `impl`
default macro_rules! foo {}
default macro_rules! foo {} //~ ERROR a macro definition cannot be `default`
//~^ ERROR macro definition not supported in `trait` or `impl`
}
#[cfg(FALSE)]
trait T {
default extern crate foo;
default extern crate foo; //~ ERROR an extern crate cannot be `default`
//~^ ERROR extern crate not supported in `trait` or `impl`
default use foo;
default use foo; //~ ERROR a `use` import cannot be `default`
//~^ ERROR `use` import not supported in `trait` or `impl`
default static foo: u8;
default static foo: u8; //~ ERROR a static item cannot be `default`
//~^ ERROR associated `static` items are not allowed
default const foo: u8;
default fn foo();
default mod foo {}
default mod foo {}//~ ERROR a module cannot be `default`
//~^ ERROR module not supported in `trait` or `impl`
default extern "C" {}
default extern "C" {} //~ ERROR an extern block cannot be `default`
//~^ ERROR extern block not supported in `trait` or `impl`
default type foo = u8;
default enum foo {}
default enum foo {} //~ ERROR an enum cannot be `default`
//~^ ERROR enum not supported in `trait` or `impl`
default struct foo {}
default struct foo {} //~ ERROR a struct cannot be `default`
//~^ ERROR struct not supported in `trait` or `impl`
default union foo {}
default union foo {} //~ ERROR a union cannot be `default`
//~^ ERROR union not supported in `trait` or `impl`
default trait foo {}
default trait foo {} //~ ERROR a trait cannot be `default`
//~^ ERROR trait not supported in `trait` or `impl`
default trait foo = Ord;
default trait foo = Ord; //~ ERROR a trait alias cannot be `default`
//~^ ERROR trait alias not supported in `trait` or `impl`
default impl foo {}
//~^ ERROR implementation not supported in `trait` or `impl`
default!();
default::foo::bar!();
default default!();
default default::foo::bar!();
default macro foo {}
default default!(); //~ ERROR an item macro invocation cannot be `default`
default default::foo::bar!(); //~ ERROR an item macro invocation cannot be `default`
default macro foo {} //~ ERROR a macro definition cannot be `default`
//~^ ERROR macro definition not supported in `trait` or `impl`
default macro_rules! foo {}
default macro_rules! foo {} //~ ERROR a macro definition cannot be `default`
//~^ ERROR macro definition not supported in `trait` or `impl`
}

View File

@ -1,4 +1,4 @@
error: item cannot be `default`
error: an extern crate cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:9:5
|
LL | default extern crate foo;
@ -6,7 +6,7 @@ LL | default extern crate foo;
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: item cannot be `default`
error: a `use` import cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:10:5
|
LL | default use foo;
@ -14,7 +14,7 @@ LL | default use foo;
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: item cannot be `default`
error: a static item cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:11:5
|
LL | default static foo: u8;
@ -22,23 +22,7 @@ LL | default static foo: u8;
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: item cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:12:5
|
LL | default const foo: u8;
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: item cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:13:5
|
LL | default fn foo();
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: item cannot be `default`
error: a module cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:14:5
|
LL | default mod foo {}
@ -46,7 +30,7 @@ LL | default mod foo {}
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: item cannot be `default`
error: an extern block cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:15:5
|
LL | default extern "C" {}
@ -54,15 +38,7 @@ LL | default extern "C" {}
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: item cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:16:5
|
LL | default type foo = u8;
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: item cannot be `default`
error: an enum cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:17:5
|
LL | default enum foo {}
@ -70,7 +46,7 @@ LL | default enum foo {}
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: item cannot be `default`
error: a struct cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:18:5
|
LL | default struct foo {}
@ -78,7 +54,7 @@ LL | default struct foo {}
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: item cannot be `default`
error: a union cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:19:5
|
LL | default union foo {}
@ -86,7 +62,7 @@ LL | default union foo {}
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: item cannot be `default`
error: a trait cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:20:5
|
LL | default trait foo {}
@ -94,7 +70,7 @@ LL | default trait foo {}
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: item cannot be `default`
error: a trait alias cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:21:5
|
LL | default trait foo = Ord;
@ -102,7 +78,7 @@ LL | default trait foo = Ord;
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: item cannot be `default`
error: an item macro invocation cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:25:5
|
LL | default default!();
@ -110,7 +86,7 @@ LL | default default!();
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: item cannot be `default`
error: an item macro invocation cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:26:5
|
LL | default default::foo::bar!();
@ -118,7 +94,7 @@ LL | default default::foo::bar!();
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: item cannot be `default`
error: a macro definition cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:27:5
|
LL | default macro foo {}
@ -126,7 +102,7 @@ LL | default macro foo {}
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: item cannot be `default`
error: a macro definition cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:28:5
|
LL | default macro_rules! foo {}
@ -134,7 +110,7 @@ LL | default macro_rules! foo {}
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: item cannot be `default`
error: an extern crate cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:33:5
|
LL | default extern crate foo;
@ -148,7 +124,7 @@ error: extern crate not supported in `extern` block
LL | default extern crate foo;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: item cannot be `default`
error: a `use` import cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:35:5
|
LL | default use foo;
@ -162,7 +138,7 @@ error: `use` import not supported in `extern` block
LL | default use foo;
| ^^^^^^^^^^^^^^^^
error: item cannot be `default`
error: a static item cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:37:5
|
LL | default static foo: u8;
@ -170,14 +146,6 @@ LL | default static foo: u8;
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: item cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:38:5
|
LL | default const foo: u8;
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: extern items cannot be `const`
--> $DIR/default-on-wrong-item-kind.rs:38:19
|
@ -188,15 +156,7 @@ LL | default const foo: u8;
|
= note: for more information, visit https://doc.rust-lang.org/std/keyword.extern.html
error: item cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:40:5
|
LL | default fn foo();
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: item cannot be `default`
error: a module cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:41:5
|
LL | default mod foo {}
@ -210,7 +170,7 @@ error: module not supported in `extern` block
LL | default mod foo {}
| ^^^^^^^^^^^^^^^
error: item cannot be `default`
error: an extern block cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:43:5
|
LL | default extern "C" {}
@ -224,15 +184,7 @@ error: extern block not supported in `extern` block
LL | default extern "C" {}
| ^^^^^^^^^^^^^^^^^^
error: item cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:45:5
|
LL | default type foo = u8;
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: item cannot be `default`
error: an enum cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:46:5
|
LL | default enum foo {}
@ -246,7 +198,7 @@ error: enum not supported in `extern` block
LL | default enum foo {}
| ^^^^^^^^^^^^^^^^
error: item cannot be `default`
error: a struct cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:48:5
|
LL | default struct foo {}
@ -260,7 +212,7 @@ error: struct not supported in `extern` block
LL | default struct foo {}
| ^^^^^^^^^^^^^^^^^^
error: item cannot be `default`
error: a union cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:50:5
|
LL | default union foo {}
@ -274,7 +226,7 @@ error: union not supported in `extern` block
LL | default union foo {}
| ^^^^^^^^^^^^^^^^^
error: item cannot be `default`
error: a trait cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:52:5
|
LL | default trait foo {}
@ -288,7 +240,7 @@ error: trait not supported in `extern` block
LL | default trait foo {}
| ^^^^^^^^^^^^^^^^^
error: item cannot be `default`
error: a trait alias cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:54:5
|
LL | default trait foo = Ord;
@ -308,7 +260,7 @@ error: implementation not supported in `extern` block
LL | default impl foo {}
| ^^^^^^^^^^^^^^^^
error: item cannot be `default`
error: an item macro invocation cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:60:5
|
LL | default default!();
@ -316,7 +268,7 @@ LL | default default!();
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: item cannot be `default`
error: an item macro invocation cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:61:5
|
LL | default default::foo::bar!();
@ -324,7 +276,7 @@ LL | default default::foo::bar!();
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: item cannot be `default`
error: a macro definition cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:62:5
|
LL | default macro foo {}
@ -338,7 +290,7 @@ error: macro definition not supported in `extern` block
LL | default macro foo {}
| ^^^^^^^^^^^^^^^^^
error: item cannot be `default`
error: a macro definition cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:64:5
|
LL | default macro_rules! foo {}
@ -352,60 +304,140 @@ error: macro definition not supported in `extern` block
LL | default macro_rules! foo {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: an extern crate cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:70:5
|
LL | default extern crate foo;
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: extern crate not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:70:5
|
LL | default extern crate foo;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `use` import cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:72:5
|
LL | default use foo;
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: `use` import not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:72:5
|
LL | default use foo;
| ^^^^^^^^^^^^^^^^
error: a static item cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:74:5
|
LL | default static foo: u8;
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: associated `static` items are not allowed
--> $DIR/default-on-wrong-item-kind.rs:74:5
|
LL | default static foo: u8;
| ^^^^^^^^^^^^^^^^^^^^^^^
error: a module cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:78:5
|
LL | default mod foo {}
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: module not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:78:5
|
LL | default mod foo {}
| ^^^^^^^^^^^^^^^
error: an extern block cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:80:5
|
LL | default extern "C" {}
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: extern block not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:80:5
|
LL | default extern "C" {}
| ^^^^^^^^^^^^^^^^^^
error: an enum cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:83:5
|
LL | default enum foo {}
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: enum not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:83:5
|
LL | default enum foo {}
| ^^^^^^^^^^^^^^^^
error: a struct cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:85:5
|
LL | default struct foo {}
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: struct not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:85:5
|
LL | default struct foo {}
| ^^^^^^^^^^^^^^^^^^
error: a union cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:87:5
|
LL | default union foo {}
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: union not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:87:5
|
LL | default union foo {}
| ^^^^^^^^^^^^^^^^^
error: a trait cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:89:5
|
LL | default trait foo {}
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: trait not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:89:5
|
LL | default trait foo {}
| ^^^^^^^^^^^^^^^^^
error: a trait alias cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:91:5
|
LL | default trait foo = Ord;
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: trait alias not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:91:5
|
@ -418,72 +450,184 @@ error: implementation not supported in `trait` or `impl`
LL | default impl foo {}
| ^^^^^^^^^^^^^^^^
error: an item macro invocation cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:97:5
|
LL | default default!();
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: an item macro invocation cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:98:5
|
LL | default default::foo::bar!();
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: a macro definition cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:99:5
|
LL | default macro foo {}
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: macro definition not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:99:5
|
LL | default macro foo {}
| ^^^^^^^^^^^^^^^^^
error: a macro definition cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:101:5
|
LL | default macro_rules! foo {}
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: macro definition not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:101:5
|
LL | default macro_rules! foo {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: an extern crate cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:107:5
|
LL | default extern crate foo;
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: extern crate not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:107:5
|
LL | default extern crate foo;
| ^^^^^^^^^^^^^^^^^^^^^^^^^
error: a `use` import cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:109:5
|
LL | default use foo;
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: `use` import not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:109:5
|
LL | default use foo;
| ^^^^^^^^^^^^^^^^
error: a static item cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:111:5
|
LL | default static foo: u8;
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: associated `static` items are not allowed
--> $DIR/default-on-wrong-item-kind.rs:111:5
|
LL | default static foo: u8;
| ^^^^^^^^^^^^^^^^^^^^^^^
error: a module cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:115:5
|
LL | default mod foo {}
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: module not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:115:5
|
LL | default mod foo {}
| ^^^^^^^^^^^^^^^
error: an extern block cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:117:5
|
LL | default extern "C" {}
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: extern block not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:117:5
|
LL | default extern "C" {}
| ^^^^^^^^^^^^^^^^^^
error: an enum cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:120:5
|
LL | default enum foo {}
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: enum not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:120:5
|
LL | default enum foo {}
| ^^^^^^^^^^^^^^^^
error: a struct cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:122:5
|
LL | default struct foo {}
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: struct not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:122:5
|
LL | default struct foo {}
| ^^^^^^^^^^^^^^^^^^
error: a union cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:124:5
|
LL | default union foo {}
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: union not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:124:5
|
LL | default union foo {}
| ^^^^^^^^^^^^^^^^^
error: a trait cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:126:5
|
LL | default trait foo {}
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: trait not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:126:5
|
LL | default trait foo {}
| ^^^^^^^^^^^^^^^^^
error: a trait alias cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:128:5
|
LL | default trait foo = Ord;
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: trait alias not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:128:5
|
@ -496,17 +640,49 @@ error: implementation not supported in `trait` or `impl`
LL | default impl foo {}
| ^^^^^^^^^^^^^^^^
error: an item macro invocation cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:134:5
|
LL | default default!();
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: an item macro invocation cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:135:5
|
LL | default default::foo::bar!();
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: a macro definition cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:136:5
|
LL | default macro foo {}
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: macro definition not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:136:5
|
LL | default macro foo {}
| ^^^^^^^^^^^^^^^^^
error: a macro definition cannot be `default`
--> $DIR/default-on-wrong-item-kind.rs:138:5
|
LL | default macro_rules! foo {}
| ^^^^^^^ `default` because of this
|
= note: only associated `fn`, `const`, and `type` items can be `default`
error: macro definition not supported in `trait` or `impl`
--> $DIR/default-on-wrong-item-kind.rs:138:5
|
LL | default macro_rules! foo {}
| ^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 73 previous errors
error: aborting due to 95 previous errors