Unnamed repository; edit this file 'description' to name the repository.
33 files changed, 31 insertions, 647 deletions
diff --git a/crates/hir-def/src/expr_store/body.rs b/crates/hir-def/src/expr_store/body.rs index 3177b2c74a..a55fec4f8b 100644 --- a/crates/hir-def/src/expr_store/body.rs +++ b/crates/hir-def/src/expr_store/body.rs @@ -122,9 +122,6 @@ impl Body { src.map(|it| it.expr()) } DefWithBodyId::InTypeConstId(c) => c.lookup(db).id.map(|_| c.source(db).expr()), - DefWithBodyId::FieldId(f) => { - f.record_field_source(db).map(|it| it.and_then(|it| it.expr())) - } } }; let module = def.module(db); diff --git a/crates/hir-def/src/expr_store/lower.rs b/crates/hir-def/src/expr_store/lower.rs index 35cd8f3c69..88f770da02 100644 --- a/crates/hir-def/src/expr_store/lower.rs +++ b/crates/hir-def/src/expr_store/lower.rs @@ -90,7 +90,6 @@ pub(super) fn lower_body( DefWithBodyId::ConstId(it) => db.attrs(it.into()), DefWithBodyId::InTypeConstId(_) => Attrs::EMPTY, DefWithBodyId::VariantId(it) => db.attrs(it.into()), - DefWithBodyId::FieldId(it) => db.attrs(it.into()), } .rust_analyzer_tool() .any(|attr| *attr.path() == tool_path![skip]); @@ -169,7 +168,6 @@ pub(super) fn lower_body( Awaitable::No("constant") } DefWithBodyId::VariantId(..) => Awaitable::No("enum variant"), - DefWithBodyId::FieldId(..) => Awaitable::No("field"), } }, ); diff --git a/crates/hir-def/src/expr_store/pretty.rs b/crates/hir-def/src/expr_store/pretty.rs index 6ba0bbd61c..6a0b1e5197 100644 --- a/crates/hir-def/src/expr_store/pretty.rs +++ b/crates/hir-def/src/expr_store/pretty.rs @@ -11,7 +11,6 @@ use crate::{ Statement, }, pretty::{print_generic_args, print_path, print_type_ref}, - VariantId, }; use super::*; @@ -57,32 +56,6 @@ pub(super) fn print_body_hir( loc.id.item_tree(db)[loc.id.value].name.display(db.upcast(), edition), ) } - DefWithBodyId::FieldId(it) => { - let parent_name: String = match it.parent { - VariantId::EnumVariantId(it) => { - let loc = it.lookup(db); - let enum_loc = loc.parent.lookup(db); - format!( - "{}::{}", - enum_loc.id.item_tree(db)[enum_loc.id.value] - .name - .display(db.upcast(), edition), - loc.id.item_tree(db)[loc.id.value].name.display(db.upcast(), edition), - ) - } - VariantId::StructId(it) => it - .lookup(db) - .id - .resolved(db, |it| it.name.display(db.upcast(), edition).to_string()), - VariantId::UnionId(it) => it - .lookup(db) - .id - .resolved(db, |it| it.name.display(db.upcast(), edition).to_string()), - }; - let variant_data = it.parent.variant_data(db); - let field_name = &variant_data.fields()[it.local_id].name; - format!("field {}.{}", parent_name, field_name.display(db.upcast(), edition),) - } }; let mut p = Printer { diff --git a/crates/hir-def/src/lib.rs b/crates/hir-def/src/lib.rs index 95700b54db..c8efd90432 100644 --- a/crates/hir-def/src/lib.rs +++ b/crates/hir-def/src/lib.rs @@ -55,7 +55,6 @@ pub mod visibility; use intern::Interned; pub use rustc_abi as layout; -use src::HasSource; use triomphe::Arc; #[cfg(test)] @@ -78,7 +77,6 @@ use hir_expand::{ builtin::{BuiltinAttrExpander, BuiltinDeriveExpander, BuiltinFnLikeExpander, EagerExpander}, db::ExpandDatabase, eager::expand_eager_macro_input, - files::InFileWrapper, impl_intern_lookup, name::Name, proc_macro::{CustomProcMacroExpander, ProcMacroKind}, @@ -521,41 +519,6 @@ pub struct FieldId { pub local_id: LocalFieldId, } -impl FieldId { - pub fn record_field_source( - &self, - db: &dyn DefDatabase, - ) -> InFileWrapper<HirFileId, Option<ast::RecordField>> { - let field_list = match self.parent { - crate::VariantId::EnumVariantId(it) => { - let s = it.lookup(db); - s.source(db).map(|it| { - it.field_list().and_then(|it| match it { - ast::FieldList::RecordFieldList(it) => Some(it), - _ => None, - }) - }) - } - crate::VariantId::StructId(it) => { - let s = it.lookup(db); - s.source(db).map(|it| { - it.field_list().and_then(|it| match it { - ast::FieldList::RecordFieldList(it) => Some(it), - _ => None, - }) - }) - } - crate::VariantId::UnionId(it) => { - let s = it.lookup(db); - s.source(db).map(|it| it.record_field_list()) - } - }; - field_list.map(|it| { - it.and_then(|it| it.fields().nth(self.local_id.into_raw().into_u32() as usize)) - }) - } -} - pub type LocalFieldId = Idx<data::adt::FieldData>; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -723,7 +686,6 @@ pub enum TypeOwnerId { TypeAliasId(TypeAliasId), ImplId(ImplId), EnumVariantId(EnumVariantId), - FieldId(FieldId), } impl TypeOwnerId { @@ -741,11 +703,6 @@ impl TypeOwnerId { GenericDefId::AdtId(AdtId::EnumId(it.lookup(db).parent)) } TypeOwnerId::InTypeConstId(_) => return None, - TypeOwnerId::FieldId(it) => GenericDefId::AdtId(match it.parent { - VariantId::EnumVariantId(it) => AdtId::EnumId(it.lookup(db).parent), - VariantId::StructId(it) => it.into(), - VariantId::UnionId(it) => it.into(), - }), }) } } @@ -760,8 +717,7 @@ impl_from!( TraitAliasId, TypeAliasId, ImplId, - EnumVariantId, - FieldId + EnumVariantId for TypeOwnerId ); @@ -774,7 +730,6 @@ impl From<DefWithBodyId> for TypeOwnerId { DefWithBodyId::ConstId(it) => it.into(), DefWithBodyId::InTypeConstId(it) => it.into(), DefWithBodyId::VariantId(it) => it.into(), - DefWithBodyId::FieldId(it) => it.into(), } } } @@ -930,7 +885,6 @@ pub enum DefWithBodyId { ConstId(ConstId), InTypeConstId(InTypeConstId), VariantId(EnumVariantId), - FieldId(FieldId), } impl_from!(FunctionId, ConstId, StaticId, InTypeConstId for DefWithBodyId); @@ -951,7 +905,6 @@ impl DefWithBodyId { // FIXME: stable rust doesn't allow generics in constants, but we should // use `TypeOwnerId::as_generic_def_id` when it does. DefWithBodyId::InTypeConstId(_) => None, - DefWithBodyId::FieldId(_) => None, } } } @@ -1379,11 +1332,6 @@ impl HasModule for TypeOwnerId { TypeOwnerId::ImplId(it) => it.module(db), TypeOwnerId::EnumVariantId(it) => it.module(db), TypeOwnerId::InTypeConstId(it) => it.lookup(db).owner.module(db), - TypeOwnerId::FieldId(it) => match it.parent { - VariantId::EnumVariantId(it) => it.module(db), - VariantId::StructId(it) => it.module(db), - VariantId::UnionId(it) => it.module(db), - }, } } } @@ -1396,11 +1344,6 @@ impl HasModule for DefWithBodyId { DefWithBodyId::ConstId(it) => it.module(db), DefWithBodyId::VariantId(it) => it.module(db), DefWithBodyId::InTypeConstId(it) => it.lookup(db).owner.module(db), - DefWithBodyId::FieldId(it) => match it.parent { - VariantId::EnumVariantId(it) => it.module(db), - VariantId::StructId(it) => it.module(db), - VariantId::UnionId(it) => it.module(db), - }, } } } diff --git a/crates/hir-def/src/macro_expansion_tests/builtin_derive_macro.rs b/crates/hir-def/src/macro_expansion_tests/builtin_derive_macro.rs index 25391c910e..c31d322132 100644 --- a/crates/hir-def/src/macro_expansion_tests/builtin_derive_macro.rs +++ b/crates/hir-def/src/macro_expansion_tests/builtin_derive_macro.rs @@ -211,20 +211,6 @@ enum Bar { #[default] Bar, } -#[derive(Default)] -struct Baz { - field1: i32 = 2, - field2: bool = { false }, -} -#[derive(Default)] -enum Qux { - #[default] - Foo { - field1: i32, - field2: bool = true, - field3: (), - } -} "#, expect![[r#" #[derive(Default)] @@ -238,20 +224,6 @@ enum Bar { #[default] Bar, } -#[derive(Default)] -struct Baz { - field1: i32 = 2, - field2: bool = { false }, -} -#[derive(Default)] -enum Qux { - #[default] - Foo { - field1: i32, - field2: bool = true, - field3: (), - } -} impl <> $crate::default::Default for Foo< > where { fn default() -> Self { @@ -264,20 +236,6 @@ impl <> $crate::default::Default for Bar< > where { fn default() -> Self { Bar::Bar } -} -impl <> $crate::default::Default for Baz< > where { - fn default() -> Self { - Baz { - .. - } - } -} -impl <> $crate::default::Default for Qux< > where { - fn default() -> Self { - Qux::Foo { - field1: $crate::default::Default::default(), field3: $crate::default::Default::default(), .. - } - } }"#]], ); } diff --git a/crates/hir-def/src/resolver.rs b/crates/hir-def/src/resolver.rs index 5299894296..7e13ae2f7a 100644 --- a/crates/hir-def/src/resolver.rs +++ b/crates/hir-def/src/resolver.rs @@ -1227,11 +1227,6 @@ impl HasResolver for TypeOwnerId { TypeOwnerId::TypeAliasId(it) => it.resolver(db), TypeOwnerId::ImplId(it) => it.resolver(db), TypeOwnerId::EnumVariantId(it) => it.resolver(db), - TypeOwnerId::FieldId(it) => match it.parent { - VariantId::EnumVariantId(it) => it.resolver(db), - VariantId::StructId(it) => it.resolver(db), - VariantId::UnionId(it) => it.resolver(db), - }, } } } @@ -1244,11 +1239,6 @@ impl HasResolver for DefWithBodyId { DefWithBodyId::StaticId(s) => s.resolver(db), DefWithBodyId::VariantId(v) => v.resolver(db), DefWithBodyId::InTypeConstId(c) => c.lookup(db).owner.resolver(db), - DefWithBodyId::FieldId(f) => match f.parent { - VariantId::EnumVariantId(it) => it.resolver(db), - VariantId::StructId(it) => it.resolver(db), - VariantId::UnionId(it) => it.resolver(db), - }, } } } diff --git a/crates/hir-expand/src/builtin/derive_macro.rs b/crates/hir-expand/src/builtin/derive_macro.rs index f8fb700d55..28b6812139 100644 --- a/crates/hir-expand/src/builtin/derive_macro.rs +++ b/crates/hir-expand/src/builtin/derive_macro.rs @@ -80,15 +80,9 @@ pub fn find_builtin_derive(ident: &name::Name) -> Option<BuiltinDeriveExpander> BuiltinDeriveExpander::find_by_name(ident) } -#[derive(Clone, Copy)] -enum HasDefault { - Yes, - No, -} - #[derive(Clone)] enum VariantShape { - Struct(Vec<(tt::Ident, HasDefault)>), + Struct(Vec<tt::Ident>), Tuple(usize), Unit, } @@ -104,7 +98,7 @@ impl VariantShape { fn field_names(&self, span: Span) -> Vec<tt::Ident> { match self { - VariantShape::Struct(s) => s.iter().map(|(ident, _)| ident.clone()).collect(), + VariantShape::Struct(s) => s.clone(), VariantShape::Tuple(n) => tuple_field_iterator(span, *n).collect(), VariantShape::Unit => vec![], } @@ -118,7 +112,7 @@ impl VariantShape { ) -> tt::TopSubtree { match self { VariantShape::Struct(fields) => { - let fields = fields.iter().map(|(it, _)| { + let fields = fields.iter().map(|it| { let mapped = field_map(it); quote! {span => #it : #mapped , } }); @@ -141,63 +135,6 @@ impl VariantShape { } } - fn default_expand( - &self, - path: tt::TopSubtree, - span: Span, - field_map: impl Fn(&tt::Ident) -> tt::TopSubtree, - ) -> tt::TopSubtree { - match self { - VariantShape::Struct(fields) => { - let contains_default = fields.iter().any(|it| matches!(it.1, HasDefault::Yes)); - let fields = fields - .iter() - .filter_map(|(it, has_default)| match has_default { - HasDefault::Yes => None, - HasDefault::No => Some(it), - }) - .map(|it| { - let mapped = field_map(it); - quote! {span => #it : #mapped , } - }); - if contains_default { - let mut double_dots = - tt::TopSubtreeBuilder::new(tt::Delimiter::invisible_spanned(span)); - double_dots.push(tt::Leaf::Punct(tt::Punct { - char: '.', - spacing: tt::Spacing::Joint, - span, - })); - double_dots.push(tt::Leaf::Punct(tt::Punct { - char: '.', - spacing: tt::Spacing::Alone, - span, - })); - let double_dots = double_dots.build(); - quote! {span => - #path { ##fields #double_dots } - } - } else { - quote! {span => - #path { ##fields } - } - } - } - &VariantShape::Tuple(n) => { - let fields = tuple_field_iterator(span, n).map(|it| { - let mapped = field_map(&it); - quote! {span => - #mapped , - } - }); - quote! {span => - #path ( ##fields ) - } - } - VariantShape::Unit => path, - } - } - fn from( call_site: Span, tm: &ExpansionSpanMap, @@ -207,15 +144,8 @@ impl VariantShape { None => VariantShape::Unit, Some(FieldList::RecordFieldList(it)) => VariantShape::Struct( it.fields() - .map(|it| { - ( - it.name(), - if it.expr().is_some() { HasDefault::Yes } else { HasDefault::No }, - ) - }) - .map(|(it, has_default)| { - name_to_token(call_site, tm, it).map(|ident| (ident, has_default)) - }) + .map(|it| it.name()) + .map(|it| name_to_token(call_site, tm, it)) .collect::<Result<_, _>>()?, ), Some(FieldList::TupleFieldList(it)) => VariantShape::Tuple(it.fields().count()), @@ -671,7 +601,7 @@ fn default_expand( let body = match &adt.shape { AdtShape::Struct(fields) => { let name = &adt.name; - fields.default_expand( + fields.as_pattern_map( quote!(span =>#name), span, |_| quote!(span =>#krate::default::Default::default()), @@ -681,7 +611,7 @@ fn default_expand( if let Some(d) = default_variant { let (name, fields) = &variants[*d]; let adt_name = &adt.name; - fields.default_expand( + fields.as_pattern_map( quote!(span =>#adt_name :: #name), span, |_| quote!(span =>#krate::default::Default::default()), @@ -713,7 +643,7 @@ fn debug_expand( expand_simple_derive(db, span, tt, quote! {span => #krate::fmt::Debug }, |adt| { let for_variant = |name: String, v: &VariantShape| match v { VariantShape::Struct(fields) => { - let for_fields = fields.iter().map(|(it, _)| { + let for_fields = fields.iter().map(|it| { let x_string = it.to_string(); quote! {span => .field(#x_string, & #it) diff --git a/crates/hir-ty/src/diagnostics/unsafe_check.rs b/crates/hir-ty/src/diagnostics/unsafe_check.rs index 2aca99c93b..ac849b0762 100644 --- a/crates/hir-ty/src/diagnostics/unsafe_check.rs +++ b/crates/hir-ty/src/diagnostics/unsafe_check.rs @@ -35,8 +35,7 @@ pub fn missing_unsafe(db: &dyn HirDatabase, def: DefWithBodyId) -> MissingUnsafe DefWithBodyId::StaticId(_) | DefWithBodyId::ConstId(_) | DefWithBodyId::VariantId(_) - | DefWithBodyId::InTypeConstId(_) - | DefWithBodyId::FieldId(_) => false, + | DefWithBodyId::InTypeConstId(_) => false, }; let mut res = MissingUnsafeResult { fn_is_unsafe: is_unsafe, ..MissingUnsafeResult::default() }; diff --git a/crates/hir-ty/src/infer.rs b/crates/hir-ty/src/infer.rs index 1b2ef2aef3..3c258e3c4c 100644 --- a/crates/hir-ty/src/infer.rs +++ b/crates/hir-ty/src/infer.rs @@ -134,9 +134,6 @@ pub(crate) fn infer_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<Infer .unwrap() .0; } - DefWithBodyId::FieldId(f) => { - ctx.collect_field(f); - } } ctx.infer_body(); @@ -913,19 +910,6 @@ impl<'a> InferenceContext<'a> { self.return_ty = return_ty; } - fn collect_field(&mut self, field: FieldId) { - let variant_data = field.parent.variant_data(self.db.upcast()); - let field_data = &variant_data.fields()[field.local_id]; - let types_map = variant_data.types_map(); - let return_ty = - self.make_ty(field_data.type_ref, types_map, InferenceTyDiagnosticSource::Signature); - - // Field default value exprs might be defining usage sites of TAITs. - self.make_tait_coercion_table(iter::once(&return_ty)); - - self.return_ty = return_ty; - } - fn collect_fn(&mut self, func: FunctionId) { let data = self.db.function_data(func); let mut param_tys = diff --git a/crates/hir-ty/src/mir/lower.rs b/crates/hir-ty/src/mir/lower.rs index 23072011a7..cc6ed122af 100644 --- a/crates/hir-ty/src/mir/lower.rs +++ b/crates/hir-ty/src/mir/lower.rs @@ -2130,10 +2130,6 @@ pub fn mir_body_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Result<Arc<Mi db.enum_variant_data(it).name.display(db.upcast(), edition).to_string() } DefWithBodyId::InTypeConstId(it) => format!("in type const {it:?}"), - DefWithBodyId::FieldId(it) => it.parent.variant_data(db.upcast()).fields()[it.local_id] - .name - .display(db.upcast(), edition) - .to_string(), }; let _p = tracing::info_span!("mir_body_query", ?detail).entered(); let body = db.body(def); diff --git a/crates/hir-ty/src/mir/pretty.rs b/crates/hir-ty/src/mir/pretty.rs index 193b7bcd97..2a26101ac4 100644 --- a/crates/hir-ty/src/mir/pretty.rs +++ b/crates/hir-ty/src/mir/pretty.rs @@ -6,7 +6,7 @@ use std::{ }; use either::Either; -use hir_def::{expr_store::Body, hir::BindingId, VariantId}; +use hir_def::{expr_store::Body, hir::BindingId}; use hir_expand::{name::Name, Lookup}; use la_arena::ArenaMap; use span::Edition; @@ -79,38 +79,6 @@ impl MirBody { hir_def::DefWithBodyId::InTypeConstId(id) => { w!(this, "in type const {id:?} = "); } - hir_def::DefWithBodyId::FieldId(id) => { - w!(this, "field "); - match id.parent { - VariantId::EnumVariantId(it) => { - let loc = it.lookup(db.upcast()); - let enum_loc = loc.parent.lookup(db.upcast()); - w!( - this, - "{}::{}", - enum_loc.id.item_tree(db.upcast())[enum_loc.id.value] - .name - .display(db.upcast(), Edition::LATEST), - loc.id.item_tree(db.upcast())[loc.id.value] - .name - .display(db.upcast(), Edition::LATEST), - ); - } - VariantId::StructId(id) => { - id.lookup(db.upcast()).id.resolved(db.upcast(), |it| { - w!(this, "{}", it.name.display(db.upcast(), Edition::LATEST)); - }); - } - VariantId::UnionId(id) => { - id.lookup(db.upcast()).id.resolved(db.upcast(), |it| { - w!(this, "{}", it.name.display(db.upcast(), Edition::LATEST)); - }); - } - }; - let variant_data = id.parent.variant_data(db.upcast()); - let field_name = &variant_data.fields()[id.local_id].name; - w!(this, ".{}: _ = ", field_name.display(db.upcast(), Edition::LATEST)); - } }); ctx.result } diff --git a/crates/hir-ty/src/tests.rs b/crates/hir-ty/src/tests.rs index a5af712b42..69ec35f406 100644 --- a/crates/hir-ty/src/tests.rs +++ b/crates/hir-ty/src/tests.rs @@ -160,7 +160,6 @@ fn check_impl( loc.source(&db).value.syntax().text_range().start() } DefWithBodyId::InTypeConstId(it) => it.source(&db).syntax().text_range().start(), - DefWithBodyId::FieldId(_) => unreachable!(), }); let mut unexpected_type_mismatches = String::new(); for def in defs { @@ -416,7 +415,6 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String { loc.source(&db).value.syntax().text_range().start() } DefWithBodyId::InTypeConstId(it) => it.source(&db).syntax().text_range().start(), - DefWithBodyId::FieldId(_) => unreachable!(), }); for def in defs { let (body, source_map) = db.body_with_source_map(def); diff --git a/crates/hir/src/from_id.rs b/crates/hir/src/from_id.rs index dd26e894d7..537401afdc 100644 --- a/crates/hir/src/from_id.rs +++ b/crates/hir/src/from_id.rs @@ -147,7 +147,6 @@ impl From<DefWithBody> for DefWithBodyId { DefWithBody::Const(it) => DefWithBodyId::ConstId(it.id), DefWithBody::Variant(it) => DefWithBodyId::VariantId(it.into()), DefWithBody::InTypeConst(it) => DefWithBodyId::InTypeConstId(it.id), - DefWithBody::Field(it) => DefWithBodyId::FieldId(it.into()), } } } @@ -160,7 +159,6 @@ impl From<DefWithBodyId> for DefWithBody { DefWithBodyId::ConstId(it) => DefWithBody::Const(it.into()), DefWithBodyId::VariantId(it) => DefWithBody::Variant(it.into()), DefWithBodyId::InTypeConstId(it) => DefWithBody::InTypeConst(it.into()), - DefWithBodyId::FieldId(it) => DefWithBody::Field(it.into()), } } } diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index ff9832d310..56090bc6b6 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -415,19 +415,6 @@ impl ModuleDef { def.diagnostics(db, &mut acc); } - let fields = match self { - ModuleDef::Adt(Adt::Struct(it)) => Some(it.fields(db)), - ModuleDef::Adt(Adt::Union(it)) => Some(it.fields(db)), - ModuleDef::Variant(it) => Some(it.fields(db)), - _ => None, - }; - if let Some(fields) = fields { - for field in fields { - let def: DefWithBody = field.into(); - def.diagnostics(db, &mut acc, style_lints); - } - } - acc } @@ -1239,12 +1226,6 @@ impl HasVisibility for Module { } } -impl From<&Field> for DefWithBodyId { - fn from(&f: &Field) -> Self { - DefWithBodyId::FieldId(f.into()) - } -} - #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct Field { pub(crate) parent: VariantDef, @@ -1310,10 +1291,6 @@ impl AstNode for FieldSource { } impl Field { - pub fn module(self, db: &dyn HirDatabase) -> Module { - self.parent.module(db) - } - pub fn name(&self, db: &dyn HirDatabase) -> Name { self.parent.variant_data(db).fields()[self.id].name.clone() } @@ -1376,14 +1353,6 @@ impl Field { pub fn parent_def(&self, _db: &dyn HirDatabase) -> VariantDef { self.parent } - - pub fn default_value_source( - &self, - db: &dyn HirDatabase, - ) -> Option<InFileWrapper<HirFileId, ast::Expr>> { - let id: hir_def::FieldId = (*self).into(); - id.record_field_source(db.upcast()).map(|it| it.and_then(|it| it.expr())).transpose() - } } impl HasVisibility for Field { @@ -1820,9 +1789,8 @@ pub enum DefWithBody { Const(Const), Variant(Variant), InTypeConst(InTypeConst), - Field(Field), } -impl_from!(Function, Const, Static, Variant, InTypeConst, Field for DefWithBody); +impl_from!(Function, Const, Static, Variant, InTypeConst for DefWithBody); impl DefWithBody { pub fn module(self, db: &dyn HirDatabase) -> Module { @@ -1832,7 +1800,6 @@ impl DefWithBody { DefWithBody::Static(s) => s.module(db), DefWithBody::Variant(v) => v.module(db), DefWithBody::InTypeConst(c) => c.module(db), - DefWithBody::Field(f) => f.module(db), } } @@ -1843,7 +1810,6 @@ impl DefWithBody { DefWithBody::Const(c) => c.name(db), DefWithBody::Variant(v) => Some(v.name(db)), DefWithBody::InTypeConst(_) => None, - DefWithBody::Field(f) => Some(f.name(db)), } } @@ -1859,7 +1825,6 @@ impl DefWithBody { &DefWithBodyId::from(it.id).resolver(db.upcast()), TyKind::Error.intern(Interner), ), - DefWithBody::Field(it) => it.ty(db), } } @@ -1870,7 +1835,6 @@ impl DefWithBody { DefWithBody::Const(it) => it.id.into(), DefWithBody::Variant(it) => it.into(), DefWithBody::InTypeConst(it) => it.id.into(), - DefWithBody::Field(it) => it.into(), } } @@ -1916,23 +1880,6 @@ impl DefWithBody { item_tree_source_maps.konst(konst.value) } DefWithBody::Variant(_) | DefWithBody::InTypeConst(_) => &TypesSourceMap::EMPTY, - DefWithBody::Field(field) => match field.parent { - VariantDef::Struct(strukt) => { - let strukt = strukt.id.lookup(db.upcast()).id; - item_tree_source_maps = strukt.item_tree_with_source_map(db.upcast()).1; - item_tree_source_maps.strukt(strukt.value).item() - } - VariantDef::Union(union) => { - let union = union.id.lookup(db.upcast()).id; - item_tree_source_maps = union.item_tree_with_source_map(db.upcast()).1; - item_tree_source_maps.union(union.value).item() - } - VariantDef::Variant(variant) => { - let variant = variant.id.lookup(db.upcast()).id; - item_tree_source_maps = variant.item_tree_with_source_map(db.upcast()).1; - item_tree_source_maps.variant(variant.value) - } - }, }; for (_, def_map) in body.blocks(db.upcast()) { @@ -2188,8 +2135,8 @@ impl DefWithBody { DefWithBody::Static(it) => it.into(), DefWithBody::Const(it) => it.into(), DefWithBody::Variant(it) => it.into(), - // FIXME: don't ignore diagnostics for in type const and default field value exprs - DefWithBody::InTypeConst(_) | DefWithBody::Field(_) => return, + // FIXME: don't ignore diagnostics for in type const + DefWithBody::InTypeConst(_) => return, }; for diag in hir_ty::diagnostics::incorrect_case(db, def.into()) { acc.push(diag.into()) @@ -3322,10 +3269,7 @@ impl AsAssocItem for DefWithBody { match self { DefWithBody::Function(it) => it.as_assoc_item(db), DefWithBody::Const(it) => it.as_assoc_item(db), - DefWithBody::Static(_) - | DefWithBody::Variant(_) - | DefWithBody::InTypeConst(_) - | DefWithBody::Field(_) => None, + DefWithBody::Static(_) | DefWithBody::Variant(_) | DefWithBody::InTypeConst(_) => None, } } } diff --git a/crates/ide-db/src/defs.rs b/crates/ide-db/src/defs.rs index 6925880ba9..bad5360805 100644 --- a/crates/ide-db/src/defs.rs +++ b/crates/ide-db/src/defs.rs @@ -972,7 +972,6 @@ impl TryFrom<DefWithBody> for Definition { DefWithBody::Const(it) => Ok(it.into()), DefWithBody::Variant(it) => Ok(it.into()), DefWithBody::InTypeConst(_) => Err(()), - DefWithBody::Field(it) => Ok(it.into()), } } } diff --git a/crates/ide-db/src/search.rs b/crates/ide-db/src/search.rs index d2a237a5c0..7963e8ae4f 100644 --- a/crates/ide-db/src/search.rs +++ b/crates/ide-db/src/search.rs @@ -310,9 +310,6 @@ impl Definition { DefWithBody::Variant(v) => v.source(db).map(|src| src.syntax().cloned()), // FIXME: implement DefWithBody::InTypeConst(_) => return SearchScope::empty(), - DefWithBody::Field(f) => { - f.default_value_source(db).map(|src| src.syntax().cloned()) - } }; return match def { Some(def) => SearchScope::file_range( @@ -330,9 +327,6 @@ impl Definition { DefWithBody::Variant(v) => v.source(db).map(|src| src.syntax().cloned()), // FIXME: implement DefWithBody::InTypeConst(_) => return SearchScope::empty(), - DefWithBody::Field(f) => { - f.default_value_source(db).map(|src| src.syntax().cloned()) - } }; return match def { Some(def) => SearchScope::file_range( diff --git a/crates/ide-diagnostics/src/handlers/type_mismatch.rs b/crates/ide-diagnostics/src/handlers/type_mismatch.rs index 4080b5f12e..73dcbc13b7 100644 --- a/crates/ide-diagnostics/src/handlers/type_mismatch.rs +++ b/crates/ide-diagnostics/src/handlers/type_mismatch.rs @@ -1235,19 +1235,4 @@ fn f() { "#, ); } - - #[test] - fn diagnostics_inside_field_default_expr() { - check_diagnostics( - r#" -struct Foo { - foo: i32 = { - let x = false; - x - // ^ error: expected i32, found bool - }, -} -"#, - ); - } } diff --git a/crates/parser/src/grammar/expressions.rs b/crates/parser/src/grammar/expressions.rs index fe1316c9bf..389c01933c 100644 --- a/crates/parser/src/grammar/expressions.rs +++ b/crates/parser/src/grammar/expressions.rs @@ -678,8 +678,6 @@ fn path_expr(p: &mut Parser<'_>, r: Restrictions) -> (CompletedMarker, BlockLike // S { x }; // S { x, y: 32, }; // S { x, y: 32, ..Default::default() }; -// S { x, y: 32, .. }; -// S { .. }; // S { x: ::default() }; // TupleStruct { 0: 1 }; // } @@ -711,8 +709,6 @@ pub(crate) fn record_expr_field_list(p: &mut Parser<'_>) { // fn main() { // S { field ..S::default() } // S { 0 ..S::default() } - // S { field .. } - // S { 0 .. } // } name_ref_or_index(p); p.error("expected `:`"); @@ -743,13 +739,7 @@ pub(crate) fn record_expr_field_list(p: &mut Parser<'_>) { // S { .. } = S {}; // } - // test struct_initializer_with_defaults - // fn foo() { - // let _s = S { .. }; - // } - - // We permit `.. }` on the left-hand side of a destructuring assignment - // or defaults values. + // We permit `.. }` on the left-hand side of a destructuring assignment. if !p.at(T!['}']) { expr(p); @@ -760,12 +750,6 @@ pub(crate) fn record_expr_field_list(p: &mut Parser<'_>) { // S { ..x, a: 0 } // } - // test_err comma_after_default_values_syntax - // fn foo() { - // S { .., }; - // S { .., a: 0 } - // } - // Do not bump, so we can support additional fields after this comma. p.error("cannot use a comma after the base struct"); } diff --git a/crates/parser/src/grammar/items/adt.rs b/crates/parser/src/grammar/items/adt.rs index 9a16c9db6d..21078175c0 100644 --- a/crates/parser/src/grammar/items/adt.rs +++ b/crates/parser/src/grammar/items/adt.rs @@ -135,11 +135,6 @@ pub(crate) fn record_field_list(p: &mut Parser<'_>) { name(p); p.expect(T![:]); types::type_(p); - // test record_field_default_values - // struct S { f: f32 = 0.0 } - if p.eat(T![=]) { - expressions::expr(p); - } m.complete(p, RECORD_FIELD); } else { m.abandon(p); diff --git a/crates/parser/test_data/generated/runner.rs b/crates/parser/test_data/generated/runner.rs index c8ea8c547a..b9f87b6af2 100644 --- a/crates/parser/test_data/generated/runner.rs +++ b/crates/parser/test_data/generated/runner.rs @@ -482,10 +482,6 @@ mod ok { run_and_expect_no_errors("test_data/parser/inline/ok/record_field_attrs.rs"); } #[test] - fn record_field_default_values() { - run_and_expect_no_errors("test_data/parser/inline/ok/record_field_default_values.rs"); - } - #[test] fn record_field_list() { run_and_expect_no_errors("test_data/parser/inline/ok/record_field_list.rs"); } @@ -548,10 +544,6 @@ mod ok { run_and_expect_no_errors("test_data/parser/inline/ok/stmt_postfix_expr_ambiguity.rs"); } #[test] - fn struct_initializer_with_defaults() { - run_and_expect_no_errors("test_data/parser/inline/ok/struct_initializer_with_defaults.rs"); - } - #[test] fn struct_item() { run_and_expect_no_errors("test_data/parser/inline/ok/struct_item.rs"); } #[test] fn trait_alias() { run_and_expect_no_errors("test_data/parser/inline/ok/trait_alias.rs"); } @@ -727,10 +719,6 @@ mod err { ); } #[test] - fn comma_after_default_values_syntax() { - run_and_expect_errors("test_data/parser/inline/err/comma_after_default_values_syntax.rs"); - } - #[test] fn crate_visibility_empty_recover() { run_and_expect_errors("test_data/parser/inline/err/crate_visibility_empty_recover.rs"); } diff --git a/crates/parser/test_data/parser/inline/err/comma_after_default_values_syntax.rast b/crates/parser/test_data/parser/inline/err/comma_after_default_values_syntax.rast deleted file mode 100644 index feb617e1aa..0000000000 --- a/crates/parser/test_data/parser/inline/err/comma_after_default_values_syntax.rast +++ /dev/null @@ -1,59 +0,0 @@ -SOURCE_FILE - FN - FN_KW "fn" - WHITESPACE " " - NAME - IDENT "foo" - PARAM_LIST - L_PAREN "(" - R_PAREN ")" - WHITESPACE " " - BLOCK_EXPR - STMT_LIST - L_CURLY "{" - WHITESPACE "\n " - EXPR_STMT - RECORD_EXPR - PATH - PATH_SEGMENT - NAME_REF - IDENT "S" - WHITESPACE " " - RECORD_EXPR_FIELD_LIST - L_CURLY "{" - WHITESPACE " " - DOT2 ".." - ERROR - COMMA "," - WHITESPACE " " - R_CURLY "}" - SEMICOLON ";" - WHITESPACE "\n " - RECORD_EXPR - PATH - PATH_SEGMENT - NAME_REF - IDENT "S" - WHITESPACE " " - RECORD_EXPR_FIELD_LIST - L_CURLY "{" - WHITESPACE " " - DOT2 ".." - ERROR - COMMA "," - WHITESPACE " " - RECORD_EXPR_FIELD - NAME_REF - IDENT "a" - COLON ":" - WHITESPACE " " - LITERAL - INT_NUMBER "0" - WHITESPACE " " - R_CURLY "}" - WHITESPACE "\n" - R_CURLY "}" - WHITESPACE "\n" -error 21: expected expression -error 36: expected expression -error 37: expected COMMA diff --git a/crates/parser/test_data/parser/inline/err/comma_after_default_values_syntax.rs b/crates/parser/test_data/parser/inline/err/comma_after_default_values_syntax.rs deleted file mode 100644 index f1ecdf89fa..0000000000 --- a/crates/parser/test_data/parser/inline/err/comma_after_default_values_syntax.rs +++ /dev/null @@ -1,4 +0,0 @@ -fn foo() { - S { .., }; - S { .., a: 0 } -} diff --git a/crates/parser/test_data/parser/inline/err/record_literal_before_ellipsis_recovery.rast b/crates/parser/test_data/parser/inline/err/record_literal_before_ellipsis_recovery.rast index 12b4e233e3..08ae906421 100644 --- a/crates/parser/test_data/parser/inline/err/record_literal_before_ellipsis_recovery.rast +++ b/crates/parser/test_data/parser/inline/err/record_literal_before_ellipsis_recovery.rast @@ -44,56 +44,6 @@ SOURCE_FILE WHITESPACE " " R_CURLY "}" WHITESPACE "\n " - EXPR_STMT - RECORD_EXPR - PATH - PATH_SEGMENT - NAME_REF - IDENT "S" - WHITESPACE " " - RECORD_EXPR_FIELD_LIST - L_CURLY "{" - WHITESPACE " " - RECORD_EXPR_FIELD - NAME_REF - INT_NUMBER "0" - WHITESPACE " " - DOT2 ".." - CALL_EXPR - PATH_EXPR - PATH - PATH - PATH_SEGMENT - NAME_REF - IDENT "S" - COLON2 "::" - PATH_SEGMENT - NAME_REF - IDENT "default" - ARG_LIST - L_PAREN "(" - R_PAREN ")" - WHITESPACE " " - R_CURLY "}" - WHITESPACE "\n " - EXPR_STMT - RECORD_EXPR - PATH - PATH_SEGMENT - NAME_REF - IDENT "S" - WHITESPACE " " - RECORD_EXPR_FIELD_LIST - L_CURLY "{" - WHITESPACE " " - RECORD_EXPR_FIELD - NAME_REF - IDENT "field" - WHITESPACE " " - DOT2 ".." - WHITESPACE " " - R_CURLY "}" - WHITESPACE "\n " RECORD_EXPR PATH PATH_SEGMENT @@ -108,6 +58,20 @@ SOURCE_FILE INT_NUMBER "0" WHITESPACE " " DOT2 ".." + CALL_EXPR + PATH_EXPR + PATH + PATH + PATH_SEGMENT + NAME_REF + IDENT "S" + COLON2 "::" + PATH_SEGMENT + NAME_REF + IDENT "default" + ARG_LIST + L_PAREN "(" + R_PAREN ")" WHITESPACE " " R_CURLY "}" WHITESPACE "\n" @@ -118,9 +82,3 @@ error 25: expected COMMA error 42: expected SEMICOLON error 52: expected `:` error 52: expected COMMA -error 69: expected SEMICOLON -error 83: expected `:` -error 83: expected COMMA -error 88: expected SEMICOLON -error 98: expected `:` -error 98: expected COMMA diff --git a/crates/parser/test_data/parser/inline/err/record_literal_before_ellipsis_recovery.rs b/crates/parser/test_data/parser/inline/err/record_literal_before_ellipsis_recovery.rs index 416cd763fd..65398ccb88 100644 --- a/crates/parser/test_data/parser/inline/err/record_literal_before_ellipsis_recovery.rs +++ b/crates/parser/test_data/parser/inline/err/record_literal_before_ellipsis_recovery.rs @@ -1,6 +1,4 @@ fn main() { S { field ..S::default() } S { 0 ..S::default() } - S { field .. } - S { 0 .. } } diff --git a/crates/parser/test_data/parser/inline/ok/record_field_default_values.rast b/crates/parser/test_data/parser/inline/ok/record_field_default_values.rast deleted file mode 100644 index 33088f2cab..0000000000 --- a/crates/parser/test_data/parser/inline/ok/record_field_default_values.rast +++ /dev/null @@ -1,28 +0,0 @@ -SOURCE_FILE - STRUCT - STRUCT_KW "struct" - WHITESPACE " " - NAME - IDENT "S" - WHITESPACE " " - RECORD_FIELD_LIST - L_CURLY "{" - WHITESPACE " " - RECORD_FIELD - NAME - IDENT "f" - COLON ":" - WHITESPACE " " - PATH_TYPE - PATH - PATH_SEGMENT - NAME_REF - IDENT "f32" - WHITESPACE " " - EQ "=" - WHITESPACE " " - LITERAL - FLOAT_NUMBER "0.0" - WHITESPACE " " - R_CURLY "}" - WHITESPACE "\n" diff --git a/crates/parser/test_data/parser/inline/ok/record_field_default_values.rs b/crates/parser/test_data/parser/inline/ok/record_field_default_values.rs deleted file mode 100644 index d7b38944a8..0000000000 --- a/crates/parser/test_data/parser/inline/ok/record_field_default_values.rs +++ /dev/null @@ -1 +0,0 @@ -struct S { f: f32 = 0.0 } diff --git a/crates/parser/test_data/parser/inline/ok/record_lit.rast b/crates/parser/test_data/parser/inline/ok/record_lit.rast index b868da55bc..00948c322f 100644 --- a/crates/parser/test_data/parser/inline/ok/record_lit.rast +++ b/crates/parser/test_data/parser/inline/ok/record_lit.rast @@ -131,53 +131,6 @@ SOURCE_FILE L_CURLY "{" WHITESPACE " " RECORD_EXPR_FIELD - PATH_EXPR - PATH - PATH_SEGMENT - NAME_REF - IDENT "x" - COMMA "," - WHITESPACE " " - RECORD_EXPR_FIELD - NAME_REF - IDENT "y" - COLON ":" - WHITESPACE " " - LITERAL - INT_NUMBER "32" - COMMA "," - WHITESPACE " " - DOT2 ".." - WHITESPACE " " - R_CURLY "}" - SEMICOLON ";" - WHITESPACE "\n " - EXPR_STMT - RECORD_EXPR - PATH - PATH_SEGMENT - NAME_REF - IDENT "S" - WHITESPACE " " - RECORD_EXPR_FIELD_LIST - L_CURLY "{" - WHITESPACE " " - DOT2 ".." - WHITESPACE " " - R_CURLY "}" - SEMICOLON ";" - WHITESPACE "\n " - EXPR_STMT - RECORD_EXPR - PATH - PATH_SEGMENT - NAME_REF - IDENT "S" - WHITESPACE " " - RECORD_EXPR_FIELD_LIST - L_CURLY "{" - WHITESPACE " " - RECORD_EXPR_FIELD NAME_REF IDENT "x" COLON ":" diff --git a/crates/parser/test_data/parser/inline/ok/record_lit.rs b/crates/parser/test_data/parser/inline/ok/record_lit.rs index 42895f759b..86411fbb7d 100644 --- a/crates/parser/test_data/parser/inline/ok/record_lit.rs +++ b/crates/parser/test_data/parser/inline/ok/record_lit.rs @@ -3,8 +3,6 @@ fn foo() { S { x }; S { x, y: 32, }; S { x, y: 32, ..Default::default() }; - S { x, y: 32, .. }; - S { .. }; S { x: ::default() }; TupleStruct { 0: 1 }; } diff --git a/crates/parser/test_data/parser/inline/ok/struct_initializer_with_defaults.rast b/crates/parser/test_data/parser/inline/ok/struct_initializer_with_defaults.rast deleted file mode 100644 index 987e219ae8..0000000000 --- a/crates/parser/test_data/parser/inline/ok/struct_initializer_with_defaults.rast +++ /dev/null @@ -1,39 +0,0 @@ -SOURCE_FILE - FN - FN_KW "fn" - WHITESPACE " " - NAME - IDENT "foo" - PARAM_LIST - L_PAREN "(" - R_PAREN ")" - WHITESPACE " " - BLOCK_EXPR - STMT_LIST - L_CURLY "{" - WHITESPACE "\n " - LET_STMT - LET_KW "let" - WHITESPACE " " - IDENT_PAT - NAME - IDENT "_s" - WHITESPACE " " - EQ "=" - WHITESPACE " " - RECORD_EXPR - PATH - PATH_SEGMENT - NAME_REF - IDENT "S" - WHITESPACE " " - RECORD_EXPR_FIELD_LIST - L_CURLY "{" - WHITESPACE " " - DOT2 ".." - WHITESPACE " " - R_CURLY "}" - SEMICOLON ";" - WHITESPACE "\n" - R_CURLY "}" - WHITESPACE "\n" diff --git a/crates/parser/test_data/parser/inline/ok/struct_initializer_with_defaults.rs b/crates/parser/test_data/parser/inline/ok/struct_initializer_with_defaults.rs deleted file mode 100644 index e08204f94c..0000000000 --- a/crates/parser/test_data/parser/inline/ok/struct_initializer_with_defaults.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn foo() { - let _s = S { .. }; -} diff --git a/crates/rust-analyzer/src/cli/analysis_stats.rs b/crates/rust-analyzer/src/cli/analysis_stats.rs index 824f262ca3..cd709afe09 100644 --- a/crates/rust-analyzer/src/cli/analysis_stats.rs +++ b/crates/rust-analyzer/src/cli/analysis_stats.rs @@ -673,9 +673,6 @@ impl flags::AnalysisStats { DefWithBody::Const(it) => it.source(db).map(|it| it.syntax().cloned()), DefWithBody::Variant(it) => it.source(db).map(|it| it.syntax().cloned()), DefWithBody::InTypeConst(_) => unimplemented!(), - DefWithBody::Field(it) => { - it.default_value_source(db).map(|it| it.syntax().cloned()) - } }; if let Some(src) = source { let original_file = src.file_id.original_file(db); @@ -990,9 +987,6 @@ impl flags::AnalysisStats { DefWithBody::Const(it) => it.source(db).map(|it| it.syntax().cloned()), DefWithBody::Variant(it) => it.source(db).map(|it| it.syntax().cloned()), DefWithBody::InTypeConst(_) => unimplemented!(), - DefWithBody::Field(it) => { - it.default_value_source(db).map(|it| it.syntax().cloned()) - } }; if let Some(src) = source { let original_file = src.file_id.original_file(db); diff --git a/crates/syntax/rust.ungram b/crates/syntax/rust.ungram index bbb8413cbc..4e2a70d6cd 100644 --- a/crates/syntax/rust.ungram +++ b/crates/syntax/rust.ungram @@ -241,7 +241,7 @@ RecordFieldList = RecordField = Attr* Visibility? - Name ':' Type ('=' Expr)? + Name ':' Type TupleFieldList = '(' fields:(TupleField (',' TupleField)* ','?)? ')' diff --git a/crates/syntax/src/ast/generated/nodes.rs b/crates/syntax/src/ast/generated/nodes.rs index 8f10ea9464..69e2a9f9c1 100644 --- a/crates/syntax/src/ast/generated/nodes.rs +++ b/crates/syntax/src/ast/generated/nodes.rs @@ -1539,13 +1539,9 @@ impl ast::HasName for RecordField {} impl ast::HasVisibility for RecordField {} impl RecordField { #[inline] - pub fn expr(&self) -> Option<Expr> { support::child(&self.syntax) } - #[inline] pub fn ty(&self) -> Option<Type> { support::child(&self.syntax) } #[inline] pub fn colon_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![:]) } - #[inline] - pub fn eq_token(&self) -> Option<SyntaxToken> { support::token(&self.syntax, T![=]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] |