diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 9d543563c0f96..a121b5a9bed3d 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -2788,7 +2788,11 @@ pub enum VariantData { /// Struct variant. /// /// E.g., `Bar { .. }` as in `enum Foo { Bar { .. } }`. - Struct(ThinVec, bool), + Struct { + fields: ThinVec, + // FIXME: investigate making this a `Option` + recovered: bool, + }, /// Tuple variant. /// /// E.g., `Bar(..)` as in `enum Foo { Bar(..) }`. @@ -2803,7 +2807,7 @@ impl VariantData { /// Return the fields of this variant. pub fn fields(&self) -> &[FieldDef] { match self { - VariantData::Struct(fields, ..) | VariantData::Tuple(fields, _) => fields, + VariantData::Struct { fields, .. } | VariantData::Tuple(fields, _) => fields, _ => &[], } } @@ -2811,7 +2815,7 @@ impl VariantData { /// Return the `NodeId` of this variant's constructor, if it has one. pub fn ctor_node_id(&self) -> Option { match *self { - VariantData::Struct(..) => None, + VariantData::Struct { .. } => None, VariantData::Tuple(_, id) | VariantData::Unit(id) => Some(id), } } diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 10b2025f93783..557ae02a8f9e3 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -976,7 +976,7 @@ pub fn noop_visit_where_predicate(pred: &mut WherePredicate, vis: pub fn noop_visit_variant_data(vdata: &mut VariantData, vis: &mut T) { match vdata { - VariantData::Struct(fields, ..) => { + VariantData::Struct { fields, .. } => { fields.flat_map_in_place(|field| vis.flat_map_field_def(field)); } VariantData::Tuple(fields, id) => { diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 83452c2228029..5bddbe5f41774 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -661,11 +661,12 @@ impl<'hir> LoweringContext<'_, 'hir> { vdata: &VariantData, ) -> hir::VariantData<'hir> { match vdata { - VariantData::Struct(fields, recovered) => hir::VariantData::Struct( - self.arena + VariantData::Struct { fields, recovered } => hir::VariantData::Struct { + fields: self + .arena .alloc_from_iter(fields.iter().enumerate().map(|f| self.lower_field_def(f))), - *recovered, - ), + recovered: *recovered, + }, VariantData::Tuple(fields, id) => { let ctor_id = self.lower_node_id(*id); self.alias_attrs(ctor_id, parent_id); diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index e0a7b06c05094..887cb434a60ce 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -1000,7 +1000,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { } } ItemKind::Struct(vdata, generics) => match vdata { - VariantData::Struct(fields, ..) => { + VariantData::Struct { fields, .. } => { self.visit_vis(&item.vis); self.visit_ident(item.ident); self.visit_generics(generics); @@ -1016,7 +1016,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { self.dcx().emit_err(errors::FieldlessUnion { span: item.span }); } match vdata { - VariantData::Struct(fields, ..) => { + VariantData::Struct { fields, .. } => { self.visit_vis(&item.vis); self.visit_ident(item.ident); self.visit_generics(generics); diff --git a/compiler/rustc_ast_pretty/src/pprust/state/item.rs b/compiler/rustc_ast_pretty/src/pprust/state/item.rs index ea5d22a344877..405ccc722d4bc 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state/item.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state/item.rs @@ -500,7 +500,7 @@ impl<'a> State<'a> { self.end(); self.end(); // Close the outer-box. } - ast::VariantData::Struct(fields, ..) => { + ast::VariantData::Struct { fields, .. } => { self.print_where_clause(&generics.where_clause); self.print_record_struct_body(fields, span); } diff --git a/compiler/rustc_builtin_macros/src/deriving/clone.rs b/compiler/rustc_builtin_macros/src/deriving/clone.rs index 1649cc76c8d52..467fa5a2b15e8 100644 --- a/compiler/rustc_builtin_macros/src/deriving/clone.rs +++ b/compiler/rustc_builtin_macros/src/deriving/clone.rs @@ -188,7 +188,7 @@ fn cs_clone( } let expr = match *vdata { - VariantData::Struct(..) => { + VariantData::Struct { .. } => { let fields = all_fields .iter() .map(|field| { diff --git a/compiler/rustc_builtin_macros/src/deriving/debug.rs b/compiler/rustc_builtin_macros/src/deriving/debug.rs index 30c9b35bbacd3..50ea862886157 100644 --- a/compiler/rustc_builtin_macros/src/deriving/debug.rs +++ b/compiler/rustc_builtin_macros/src/deriving/debug.rs @@ -71,7 +71,7 @@ fn show_substructure(cx: &mut ExtCtxt<'_>, span: Span, substr: &Substructure<'_> (false, 0) } ast::VariantData::Tuple(..) => (false, 1), - ast::VariantData::Struct(..) => (true, 2), + ast::VariantData::Struct { .. } => (true, 2), }; // The number of fields that can be handled without an array. @@ -226,7 +226,7 @@ fn show_fieldless_enum( debug_assert!(fields.is_empty()); cx.pat_tuple_struct(span, variant_path, ThinVec::new()) } - ast::VariantData::Struct(fields, _) => { + ast::VariantData::Struct { fields, .. } => { debug_assert!(fields.is_empty()); cx.pat_struct(span, variant_path, ThinVec::new()) } diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index 23502b6eafc6d..841cac7814998 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -1485,7 +1485,7 @@ impl<'a> TraitDef<'a> { let struct_path = struct_path.clone(); match *struct_def { - VariantData::Struct(..) => { + VariantData::Struct { .. } => { let field_pats = pieces_iter .map(|(sp, ident, pat)| { if ident.is_none() { diff --git a/compiler/rustc_error_codes/src/error_codes/E0761.md b/compiler/rustc_error_codes/src/error_codes/E0761.md index 760c5897698aa..975f967d0e173 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0761.md +++ b/compiler/rustc_error_codes/src/error_codes/E0761.md @@ -15,7 +15,7 @@ fn foo() {} mod ambiguous_module; // error: file for module `ambiguous_module` // found at both ambiguous_module.rs and - // ambiguous_module.rs/mod.rs + // ambiguous_module/mod.rs ``` Please remove this ambiguity by deleting/renaming one of the candidate files. diff --git a/compiler/rustc_expand/src/placeholders.rs b/compiler/rustc_expand/src/placeholders.rs index ded0baa9563e8..2c4187031cacf 100644 --- a/compiler/rustc_expand/src/placeholders.rs +++ b/compiler/rustc_expand/src/placeholders.rs @@ -174,7 +174,7 @@ pub fn placeholder( }]), AstFragmentKind::Variants => AstFragment::Variants(smallvec![ast::Variant { attrs: Default::default(), - data: ast::VariantData::Struct(Default::default(), false), + data: ast::VariantData::Struct { fields: Default::default(), recovered: false }, disr_expr: None, id, ident, diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs index e2bccf1ffa594..81ec7ddb629e3 100644 --- a/compiler/rustc_hir/src/def.rs +++ b/compiler/rustc_hir/src/def.rs @@ -603,7 +603,7 @@ impl CtorKind { match *vdata { ast::VariantData::Tuple(_, node_id) => Some((CtorKind::Fn, node_id)), ast::VariantData::Unit(node_id) => Some((CtorKind::Const, node_id)), - ast::VariantData::Struct(..) => None, + ast::VariantData::Struct { .. } => None, } } } diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index d148137091cf4..3179fd7360423 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -2848,7 +2848,11 @@ pub enum VariantData<'hir> { /// A struct variant. /// /// E.g., `Bar { .. }` as in `enum Foo { Bar { .. } }`. - Struct(&'hir [FieldDef<'hir>], /* recovered */ bool), + Struct { + fields: &'hir [FieldDef<'hir>], + // FIXME: investigate making this a `Option` + recovered: bool, + }, /// A tuple variant. /// /// E.g., `Bar(..)` as in `enum Foo { Bar(..) }`. @@ -2863,7 +2867,7 @@ impl<'hir> VariantData<'hir> { /// Return the fields of this variant. pub fn fields(&self) -> &'hir [FieldDef<'hir>] { match *self { - VariantData::Struct(ref fields, ..) | VariantData::Tuple(ref fields, ..) => fields, + VariantData::Struct { fields, .. } | VariantData::Tuple(fields, ..) => fields, _ => &[], } } @@ -2872,7 +2876,7 @@ impl<'hir> VariantData<'hir> { match *self { VariantData::Tuple(_, hir_id, def_id) => Some((CtorKind::Fn, hir_id, def_id)), VariantData::Unit(hir_id, def_id) => Some((CtorKind::Const, hir_id, def_id)), - VariantData::Struct(..) => None, + VariantData::Struct { .. } => None, } } diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 688d32fa32d12..d48535c82f59d 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -814,7 +814,7 @@ fn convert_variant( }) .collect(); let recovered = match def { - hir::VariantData::Struct(_, r) => *r, + hir::VariantData::Struct { recovered, .. } => *recovered, _ => false, }; ty::VariantDef::new( diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 15d546537dde8..19e7fe388aae7 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -481,7 +481,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder match def { - VariantData::Unit(..) | VariantData::Struct(..) => { + VariantData::Unit(..) | VariantData::Struct { .. } => { tcx.type_of(tcx.hir().get_parent_item(hir_id)).instantiate_identity() } VariantData::Tuple(..) => { diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index 21a50b94a37a8..6715d01c9e0bf 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -741,7 +741,7 @@ impl<'a> State<'a> { self.end(); self.end() // close the outer-box } - hir::VariantData::Struct(..) => { + hir::VariantData::Struct { .. } => { self.print_where_clause(generics); self.nbsp(); self.bopen(); diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index bf619daba5013..09ee042ef6b4e 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -1484,7 +1484,7 @@ impl<'a> Parser<'a> { (thin_vec![], true) } }; - VariantData::Struct(fields, recovered) + VariantData::Struct { fields, recovered } } else if this.check(&token::OpenDelim(Delimiter::Parenthesis)) { let body = match this.parse_tuple_struct_body() { Ok(body) => body, @@ -1569,7 +1569,7 @@ impl<'a> Parser<'a> { class_name.span, generics.where_clause.has_where_token, )?; - VariantData::Struct(fields, recovered) + VariantData::Struct { fields, recovered } } // No `where` so: `struct Foo;` } else if self.eat(&token::Semi) { @@ -1581,7 +1581,7 @@ impl<'a> Parser<'a> { class_name.span, generics.where_clause.has_where_token, )?; - VariantData::Struct(fields, recovered) + VariantData::Struct { fields, recovered } // Tuple-style struct definition with optional where-clause. } else if self.token == token::OpenDelim(Delimiter::Parenthesis) { let body = VariantData::Tuple(self.parse_tuple_struct_body()?, DUMMY_NODE_ID); @@ -1610,14 +1610,14 @@ impl<'a> Parser<'a> { class_name.span, generics.where_clause.has_where_token, )?; - VariantData::Struct(fields, recovered) + VariantData::Struct { fields, recovered } } else if self.token == token::OpenDelim(Delimiter::Brace) { let (fields, recovered) = self.parse_record_struct_body( "union", class_name.span, generics.where_clause.has_where_token, )?; - VariantData::Struct(fields, recovered) + VariantData::Struct { fields, recovered } } else { let token_str = super::token_descr(&self.token); let msg = format!("expected `where` or `{{` after union name, found {token_str}"); diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 7ff3c523685cc..98a9d0ba4c2f6 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -394,6 +394,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> { id: NodeId, parent_prefix: &[Segment], nested: bool, + list_stem: bool, // The whole `use` item item: &Item, vis: ty::Visibility, @@ -404,7 +405,9 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> { parent_prefix, use_tree, nested ); - if nested { + // Top level use tree reuses the item's id and list stems reuse their parent + // use tree's ids, so in both cases their visibilities are already filled. + if nested && !list_stem { self.r.feed_visibility(self.r.local_def_id(id), vis); } @@ -592,7 +595,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> { for &(ref tree, id) in items { self.build_reduced_graph_for_use_tree( // This particular use tree - tree, id, &prefix, true, // The whole `use` item + tree, id, &prefix, true, false, // The whole `use` item item, vis, root_span, ); } @@ -613,6 +616,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> { id, &prefix, true, + true, // The whole `use` item item, ty::Visibility::Restricted( @@ -648,6 +652,7 @@ impl<'a, 'b, 'tcx> BuildReducedGraphVisitor<'a, 'b, 'tcx> { item.id, &[], false, + false, // The whole `use` item item, vis, diff --git a/compiler/rustc_smir/src/rustc_smir/context.rs b/compiler/rustc_smir/src/rustc_smir/context.rs index 621766c695e43..f84c466cc440d 100644 --- a/compiler/rustc_smir/src/rustc_smir/context.rs +++ b/compiler/rustc_smir/src/rustc_smir/context.rs @@ -341,6 +341,12 @@ impl<'tcx> Context for TablesWrapper<'tcx> { instance.ty(tables.tcx, ParamEnv::reveal_all()).stable(&mut *tables) } + fn instance_args(&self, def: InstanceDef) -> GenericArgs { + let mut tables = self.0.borrow_mut(); + let instance = tables.instances[def]; + instance.args.stable(&mut *tables) + } + fn instance_abi(&self, def: InstanceDef) -> Result { let mut tables = self.0.borrow_mut(); let instance = tables.instances[def]; diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index cf6ac5285c245..e1ee40c0b60ee 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -15,7 +15,7 @@ use rustc_span::def_id::{CrateNum, DefId, LOCAL_CRATE}; use stable_mir::abi::Layout; use stable_mir::mir::mono::InstanceDef; use stable_mir::ty::{ConstId, Span}; -use stable_mir::ItemKind; +use stable_mir::{CtorKind, ItemKind}; use std::ops::RangeInclusive; use tracing::debug; @@ -88,7 +88,6 @@ pub(crate) fn new_item_kind(kind: DefKind) -> ItemKind { | DefKind::Field | DefKind::LifetimeParam | DefKind::Impl { .. } - | DefKind::Ctor(_, _) | DefKind::GlobalAsm => { unreachable!("Not a valid item kind: {kind:?}"); } @@ -97,6 +96,8 @@ pub(crate) fn new_item_kind(kind: DefKind) -> ItemKind { ItemKind::Const } DefKind::Static(_) => ItemKind::Static, + DefKind::Ctor(_, rustc_hir::def::CtorKind::Const) => ItemKind::Ctor(CtorKind::Const), + DefKind::Ctor(_, rustc_hir::def::CtorKind::Fn) => ItemKind::Ctor(CtorKind::Fn), } } diff --git a/compiler/stable_mir/src/compiler_interface.rs b/compiler/stable_mir/src/compiler_interface.rs index 98b1d484c034e..f52e506059bd1 100644 --- a/compiler/stable_mir/src/compiler_interface.rs +++ b/compiler/stable_mir/src/compiler_interface.rs @@ -125,6 +125,9 @@ pub trait Context { /// Get the instance type with generic substitutions applied and lifetimes erased. fn instance_ty(&self, instance: InstanceDef) -> Ty; + /// Get the instantiation types. + fn instance_args(&self, def: InstanceDef) -> GenericArgs; + /// Get the instance. fn instance_def_id(&self, instance: InstanceDef) -> DefId; diff --git a/compiler/stable_mir/src/lib.rs b/compiler/stable_mir/src/lib.rs index 4941e54fe4b7e..9194f1e6bdb5e 100644 --- a/compiler/stable_mir/src/lib.rs +++ b/compiler/stable_mir/src/lib.rs @@ -91,6 +91,13 @@ pub enum ItemKind { Fn, Static, Const, + Ctor(CtorKind), +} + +#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] +pub enum CtorKind { + Const, + Fn, } pub type Filename = String; diff --git a/compiler/stable_mir/src/mir/mono.rs b/compiler/stable_mir/src/mir/mono.rs index 70d44ef8c2256..6c791ae855225 100644 --- a/compiler/stable_mir/src/mir/mono.rs +++ b/compiler/stable_mir/src/mir/mono.rs @@ -35,6 +35,11 @@ pub enum InstanceKind { } impl Instance { + /// Get the arguments this instance was instantiated with. + pub fn args(&self) -> GenericArgs { + with(|cx| cx.instance_args(self.def)) + } + /// Get the body of an Instance. The body will be eagerly monomorphized. pub fn body(&self) -> Option { with(|context| context.instance_body(self.def)) @@ -148,6 +153,7 @@ impl Debug for Instance { f.debug_struct("Instance") .field("kind", &self.kind) .field("def", &self.mangled_name()) + .field("args", &self.args()) .finish() } } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 828e7f959b44a..75f9560f52682 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2479,8 +2479,8 @@ fn clean_variant_data<'tcx>( .map(|disr| Discriminant { expr: Some(disr.body), value: disr.def_id.to_def_id() }); let kind = match variant { - hir::VariantData::Struct(..) => VariantKind::Struct(VariantStruct { - fields: variant.fields().iter().map(|x| clean_field(x, cx)).collect(), + hir::VariantData::Struct { fields, .. } => VariantKind::Struct(VariantStruct { + fields: fields.iter().map(|x| clean_field(x, cx)).collect(), }), hir::VariantData::Tuple(..) => { VariantKind::Tuple(variant.fields().iter().map(|x| clean_field(x, cx)).collect()) diff --git a/src/tools/clippy/clippy_lints/src/item_name_repetitions.rs b/src/tools/clippy/clippy_lints/src/item_name_repetitions.rs index b6aacba2517a1..a9f1612ff05ed 100644 --- a/src/tools/clippy/clippy_lints/src/item_name_repetitions.rs +++ b/src/tools/clippy/clippy_lints/src/item_name_repetitions.rs @@ -436,7 +436,7 @@ impl LateLintPass<'_> for ItemNameRepetitions { { match item.kind { ItemKind::Enum(def, _) => check_variant(cx, self.enum_threshold, &def, item_name, item.span), - ItemKind::Struct(VariantData::Struct(fields, _), _) => { + ItemKind::Struct(VariantData::Struct { fields, .. }, _) => { check_fields(cx, self.struct_threshold, item, fields); }, _ => (), diff --git a/src/tools/clippy/clippy_lints/src/manual_non_exhaustive.rs b/src/tools/clippy/clippy_lints/src/manual_non_exhaustive.rs index 545b122930e5f..d2ac0ad8363e9 100644 --- a/src/tools/clippy/clippy_lints/src/manual_non_exhaustive.rs +++ b/src/tools/clippy/clippy_lints/src/manual_non_exhaustive.rs @@ -103,7 +103,7 @@ impl EarlyLintPass for ManualNonExhaustiveStruct { if let ast::ItemKind::Struct(variant_data, _) = &item.kind { let (fields, delimiter) = match variant_data { - ast::VariantData::Struct(fields, _) => (&**fields, '{'), + ast::VariantData::Struct { fields, .. } => (&**fields, '{'), ast::VariantData::Tuple(fields, _) => (&**fields, '('), ast::VariantData::Unit(_) => return, }; diff --git a/src/tools/clippy/clippy_utils/src/ast_utils.rs b/src/tools/clippy/clippy_utils/src/ast_utils.rs index e36f2fa87a72a..c271e498665e8 100644 --- a/src/tools/clippy/clippy_utils/src/ast_utils.rs +++ b/src/tools/clippy/clippy_utils/src/ast_utils.rs @@ -546,7 +546,9 @@ pub fn eq_variant_data(l: &VariantData, r: &VariantData) -> bool { use VariantData::*; match (l, r) { (Unit(_), Unit(_)) => true, - (Struct(l, _), Struct(r, _)) | (Tuple(l, _), Tuple(r, _)) => over(l, r, eq_struct_field), + (Struct { fields: l, .. }, Struct { fields: r, .. }) | (Tuple(l, _), Tuple(r, _)) => { + over(l, r, eq_struct_field) + }, _ => false, } } diff --git a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs index 470d31fa3e1a1..d751aeaf90222 100644 --- a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs +++ b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs @@ -200,7 +200,7 @@ fn item_search_pat(item: &Item<'_>) -> (Pat, Pat) { ItemKind::ForeignMod { .. } => (Pat::Str("extern"), Pat::Str("}")), ItemKind::TyAlias(..) | ItemKind::OpaqueTy(_) => (Pat::Str("type"), Pat::Str(";")), ItemKind::Enum(..) => (Pat::Str("enum"), Pat::Str("}")), - ItemKind::Struct(VariantData::Struct(..), _) => (Pat::Str("struct"), Pat::Str("}")), + ItemKind::Struct(VariantData::Struct { .. }, _) => (Pat::Str("struct"), Pat::Str("}")), ItemKind::Struct(..) => (Pat::Str("struct"), Pat::Str(";")), ItemKind::Union(..) => (Pat::Str("union"), Pat::Str("}")), ItemKind::Trait(_, Unsafety::Unsafe, ..) @@ -255,7 +255,7 @@ fn field_def_search_pat(def: &FieldDef<'_>) -> (Pat, Pat) { fn variant_search_pat(v: &Variant<'_>) -> (Pat, Pat) { match v.data { - VariantData::Struct(..) => (Pat::Sym(v.ident.name), Pat::Str("}")), + VariantData::Struct { .. } => (Pat::Sym(v.ident.name), Pat::Str("}")), VariantData::Tuple(..) => (Pat::Sym(v.ident.name), Pat::Str("")), VariantData::Unit(..) => (Pat::Sym(v.ident.name), Pat::Sym(v.ident.name)), } diff --git a/src/tools/rustfmt/src/items.rs b/src/tools/rustfmt/src/items.rs index a4256730f19da..6fb69d6b88393 100644 --- a/src/tools/rustfmt/src/items.rs +++ b/src/tools/rustfmt/src/items.rs @@ -666,7 +666,7 @@ impl<'a> FmtVisitor<'a> { let span = mk_sp(lo, field.span.lo()); let variant_body = match field.data { - ast::VariantData::Tuple(..) | ast::VariantData::Struct(..) => format_struct( + ast::VariantData::Tuple(..) | ast::VariantData::Struct { .. } => format_struct( &context, &StructParts::from_variant(field, &context), self.block_indent, @@ -1092,7 +1092,7 @@ fn enum_variant_span(variant: &ast::Variant, context: &RewriteContext<'_>) -> Sp if let Some(ref anon_const) = variant.disr_expr { let span_before_consts = variant.span.until(anon_const.value.span); let hi = match &variant.data { - Struct(..) => context + Struct { .. } => context .snippet_provider .span_after_last(span_before_consts, "}"), Tuple(..) => context @@ -1112,12 +1112,12 @@ fn format_struct( offset: Indent, one_line_width: Option, ) -> Option { - match *struct_parts.def { + match struct_parts.def { ast::VariantData::Unit(..) => format_unit_struct(context, struct_parts, offset), - ast::VariantData::Tuple(ref fields, _) => { + ast::VariantData::Tuple(fields, _) => { format_tuple_struct(context, struct_parts, fields, offset) } - ast::VariantData::Struct(ref fields, _) => { + ast::VariantData::Struct { fields, .. } => { format_struct_struct(context, struct_parts, fields, offset, one_line_width) } } diff --git a/tests/ui-fulldeps/stable-mir/check_item_kind.rs b/tests/ui-fulldeps/stable-mir/check_item_kind.rs new file mode 100644 index 0000000000000..72e0e09e6e363 --- /dev/null +++ b/tests/ui-fulldeps/stable-mir/check_item_kind.rs @@ -0,0 +1,84 @@ +// run-pass +//! Test that item kind works as expected. + +// ignore-stage1 +// ignore-cross-compile +// ignore-remote +// ignore-windows-gnu mingw has troubles with linking https://github.com/rust-lang/rust/pull/116837 +// edition: 2021 + +#![feature(rustc_private)] +#![feature(assert_matches)] +#![feature(control_flow_enum)] + +extern crate rustc_middle; +#[macro_use] +extern crate rustc_smir; +extern crate rustc_driver; +extern crate rustc_interface; +extern crate stable_mir; + +use rustc_middle::ty::TyCtxt; +use rustc_smir::rustc_internal; +use stable_mir::*; +use std::io::Write; +use std::ops::ControlFlow; + +const CRATE_NAME: &str = "input"; + +/// This function uses the Stable MIR APIs to get information about the test crate. +fn test_item_kind(_tcx: TyCtxt<'_>) -> ControlFlow<()> { + let items = stable_mir::all_local_items(); + assert_eq!(items.len(), 4); + // Constructor item. + for item in items { + let expected_kind = match item.name().as_str() { + "Dummy" => ItemKind::Ctor(CtorKind::Fn), + "dummy" => ItemKind::Fn, + "unit" => ItemKind::Fn, + "DUMMY_CONST" => ItemKind::Const, + name => unreachable!("Unexpected item {name}"), + }; + assert_eq!(item.kind(), expected_kind, "Mismatched type for {}", item.name()); + } + ControlFlow::Continue(()) +} + +/// This test will generate and analyze a dummy crate using the stable mir. +/// For that, it will first write the dummy crate into a file. +/// Then it will create a `StableMir` using custom arguments and then +/// it will run the compiler. +fn main() { + let path = "item_kind_input.rs"; + generate_input(&path).unwrap(); + let args = vec![ + "rustc".to_string(), + "-Cpanic=abort".to_string(), + "--crate-type=lib".to_string(), + "--crate-name".to_string(), + CRATE_NAME.to_string(), + path.to_string(), + ]; + run!(args, tcx, test_item_kind(tcx)).unwrap(); +} + +fn generate_input(path: &str) -> std::io::Result<()> { + let mut file = std::fs::File::create(path)?; + write!( + file, + r#" + pub struct Dummy(u32); + pub const DUMMY_CONST: Dummy = Dummy(0); + pub struct DummyUnit; + + pub fn dummy() -> Dummy {{ + Dummy(5) + }} + + pub fn unit() -> DummyUnit {{ + DummyUnit + }} + "# + )?; + Ok(()) +} diff --git a/tests/ui/privacy/import-list-stem-visibility-issue-119126.rs b/tests/ui/privacy/import-list-stem-visibility-issue-119126.rs new file mode 100644 index 0000000000000..21f7828fc8442 --- /dev/null +++ b/tests/ui/privacy/import-list-stem-visibility-issue-119126.rs @@ -0,0 +1,14 @@ +// check-pass +// edition: 2018 + +mod outer { + mod inner { + pub mod inner2 {} + } + pub(crate) use inner::{}; + pub(crate) use inner::{{}}; + pub(crate) use inner::{inner2::{}}; + pub(crate) use inner::{inner2::{{}}}; +} + +fn main() {}