-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ice on using clone #3139
Comments
ah, nice find - this is because we don't use the type's generics when generating code for |
this works if you define the clone directly: impl<T: Clone> Clone for Be<T> {
fn clone(&self) -> Self {
return Be::<T> {
a: self.a.clone(),
b: self.b.clone(),
};
}
} I think this is meant to be the correct clone i need to look into the derive here |
Yeah looks like we are just missing doing the generics on derive impl blocks |
@philberty this should be pretty easy to fix, the derive clone mechanism is a simple AST builder. rustc shows the following when outputting expanded/generated code: #[automatically_derived]
impl <T> ::core::clone::Clone for Be<T> where T: ::core::clone::Clone
{
#[inline]
fn clone<'_>(self: &'_ Self)
->
Be<T> {
Be{
a: ::core::clone::Clone::clone(&self.a),
b: ::core::clone::Clone::clone(&self.b),}
}
} so we should simply be able to add the bound |
TODO Fixes #3139 gcc/rust/ChangeLog: * Make-lang.in: * ast/rust-ast-builder.cc (Builder::generic_type_path_segment): (Builder::single_generic_type_path): (Builder::new_type): (Builder::new_lifetime_param): (Builder::new_type_param): * ast/rust-ast-builder.h: * ast/rust-ast.h: * ast/rust-type.h: * expand/rust-derive-clone.cc (DeriveClone::clone_impl): (DeriveClone::visit_tuple): (DeriveClone::visit_struct): (DeriveClone::visit_union): * expand/rust-derive-clone.h: * ast/rust-ast-builder-base.cc: New file. * ast/rust-ast-builder-base.h: New file. * ast/rust-ast-builder-type.cc: New file. * ast/rust-ast-builder-type.h: New file. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
When we generate derivations for Copy and Clone we need to make sure the associated impl block sets up the generic parameters and arguments correctly. This patch introduces the framework to copy chunks of the AST because we need to make sure these new AST nodes have their own associated id, calling clone on the nodes will just confuse name-resolution and subsequent mappings. Fixes #3139 gcc/rust/ChangeLog: * Make-lang.in: new objects * ast/rust-ast-builder.cc (Builder::generic_type_path_segment): new helper (Builder::single_generic_type_path): likewise (Builder::new_type): likewise (Builder::new_lifetime_param): likewise (Builder::new_type_param): likewise (Builder::new_lifetime): likewise (Builder::new_generic_args): likewise * ast/rust-ast-builder.h: new helper decls * ast/rust-ast.h: new const getters * ast/rust-path.h: likewise * ast/rust-type.h: likewise * expand/rust-derive-clone.cc (DeriveClone::clone_impl): take the types generics (DeriveClone::visit_tuple): likewise (DeriveClone::visit_struct): likewise (DeriveClone::visit_union): likewise * expand/rust-derive-clone.h: update header * expand/rust-derive-copy.cc (DeriveCopy::copy_impl): similarly take type generics (DeriveCopy::visit_struct): likewise (DeriveCopy::visit_tuple): likewise (DeriveCopy::visit_enum): likewise (DeriveCopy::visit_union): likewise * expand/rust-derive-copy.h: likewse * ast/rust-ast-builder-base.cc: New file. * ast/rust-ast-builder-base.h: New file. * ast/rust-ast-builder-type.cc: New file. * ast/rust-ast-builder-type.h: New file. gcc/testsuite/ChangeLog: * rust/compile/issue-3139-1.rs: New test. * rust/compile/issue-3139-2.rs: New test. * rust/compile/issue-3139-3.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
When we generate derivations for Copy and Clone we need to make sure the associated impl block sets up the generic parameters and arguments correctly. This patch introduces the framework to copy chunks of the AST because we need to make sure these new AST nodes have their own associated id, calling clone on the nodes will just confuse name-resolution and subsequent mappings. Fixes #3139 gcc/rust/ChangeLog: * Make-lang.in: new objects * ast/rust-ast-builder.cc (Builder::generic_type_path_segment): new helper (Builder::single_generic_type_path): likewise (Builder::new_type): likewise (Builder::new_lifetime_param): likewise (Builder::new_type_param): likewise (Builder::new_lifetime): likewise (Builder::new_generic_args): likewise * ast/rust-ast-builder.h: new helper decls * ast/rust-ast.h: new const getters * ast/rust-path.h: likewise * ast/rust-type.h: likewise * expand/rust-derive-clone.cc (DeriveClone::clone_impl): take the types generics (DeriveClone::visit_tuple): likewise (DeriveClone::visit_struct): likewise (DeriveClone::visit_union): likewise * expand/rust-derive-clone.h: update header * expand/rust-derive-copy.cc (DeriveCopy::copy_impl): similarly take type generics (DeriveCopy::visit_struct): likewise (DeriveCopy::visit_tuple): likewise (DeriveCopy::visit_enum): likewise (DeriveCopy::visit_union): likewise * expand/rust-derive-copy.h: likewse * ast/rust-ast-builder-base.cc: New file. * ast/rust-ast-builder-base.h: New file. * ast/rust-ast-builder-type.cc: New file. * ast/rust-ast-builder-type.h: New file. gcc/testsuite/ChangeLog: * rust/compile/issue-3139-1.rs: New test. * rust/compile/issue-3139-2.rs: New test. * rust/compile/issue-3139-3.rs: New test. * rust/compile/nr2/exclude: these all break nr2
When we generate derivations for Copy and Clone we need to make sure the associated impl block sets up the generic parameters and arguments correctly. This patch introduces the framework to copy chunks of the AST because we need to make sure these new AST nodes have their own associated id, calling clone on the nodes will just confuse name-resolution and subsequent mappings. Fixes #3139 gcc/rust/ChangeLog: * Make-lang.in: new objects * ast/rust-ast-builder.cc (Builder::generic_type_path_segment): new helper (Builder::single_generic_type_path): likewise (Builder::new_type): likewise (Builder::new_lifetime_param): likewise (Builder::new_type_param): likewise (Builder::new_lifetime): likewise (Builder::new_generic_args): likewise * ast/rust-ast-builder.h: new helper decls * ast/rust-ast.h: new const getters * ast/rust-path.h: likewise * ast/rust-type.h: likewise * expand/rust-derive-clone.cc (DeriveClone::clone_impl): take the types generics (DeriveClone::visit_tuple): likewise (DeriveClone::visit_struct): likewise (DeriveClone::visit_union): likewise * expand/rust-derive-clone.h: update header * expand/rust-derive-copy.cc (DeriveCopy::copy_impl): similarly take type generics (DeriveCopy::visit_struct): likewise (DeriveCopy::visit_tuple): likewise (DeriveCopy::visit_enum): likewise (DeriveCopy::visit_union): likewise * expand/rust-derive-copy.h: likewse * ast/rust-ast-builder-base.cc: New file. * ast/rust-ast-builder-base.h: New file. * ast/rust-ast-builder-type.cc: New file. * ast/rust-ast-builder-type.h: New file. gcc/testsuite/ChangeLog: * rust/compile/issue-3139-1.rs: New test. * rust/compile/issue-3139-2.rs: New test. * rust/compile/issue-3139-3.rs: New test. * rust/compile/nr2/exclude: these all break nr2
When we generate derivations for Copy and Clone we need to make sure the associated impl block sets up the generic parameters and arguments correctly. This patch introduces the framework to copy chunks of the AST because we need to make sure these new AST nodes have their own associated id, calling clone on the nodes will just confuse name-resolution and subsequent mappings. Fixes #3139 gcc/rust/ChangeLog: * Make-lang.in: new objects * ast/rust-ast-builder.cc (Builder::generic_type_path_segment): new helper (Builder::single_generic_type_path): likewise (Builder::new_type): likewise (Builder::new_lifetime_param): likewise (Builder::new_type_param): likewise (Builder::new_lifetime): likewise (Builder::new_generic_args): likewise * ast/rust-ast-builder.h: new helper decls * ast/rust-ast.h: new const getters * ast/rust-path.h: likewise * ast/rust-type.h: likewise * expand/rust-derive-clone.cc (DeriveClone::clone_impl): take the types generics (DeriveClone::visit_tuple): likewise (DeriveClone::visit_struct): likewise (DeriveClone::visit_union): likewise * expand/rust-derive-clone.h: update header * expand/rust-derive-copy.cc (DeriveCopy::copy_impl): similarly take type generics (DeriveCopy::visit_struct): likewise (DeriveCopy::visit_tuple): likewise (DeriveCopy::visit_enum): likewise (DeriveCopy::visit_union): likewise * expand/rust-derive-copy.h: likewse * ast/rust-ast-builder-type.cc: New file. * ast/rust-ast-builder-type.h: New file. gcc/testsuite/ChangeLog: * rust/compile/issue-3139-1.rs: New test. * rust/compile/issue-3139-2.rs: New test. * rust/compile/issue-3139-3.rs: New test. * rust/compile/nr2/exclude: these all break nr2
When we generate derivations for Copy and Clone we need to make sure the associated impl block sets up the generic parameters and arguments correctly. This patch introduces the framework to copy chunks of the AST because we need to make sure these new AST nodes have their own associated id, calling clone on the nodes will just confuse name-resolution and subsequent mappings. Fixes #3139 gcc/rust/ChangeLog: * Make-lang.in: new objects * ast/rust-ast-builder.cc (Builder::generic_type_path_segment): new helper (Builder::single_generic_type_path): likewise (Builder::new_type): likewise (Builder::new_lifetime_param): likewise (Builder::new_type_param): likewise (Builder::new_lifetime): likewise (Builder::new_generic_args): likewise * ast/rust-ast-builder.h: new helper decls * ast/rust-ast.h: new const getters * ast/rust-path.h: likewise * ast/rust-type.h: likewise * expand/rust-derive-clone.cc (DeriveClone::clone_impl): take the types generics (DeriveClone::visit_tuple): likewise (DeriveClone::visit_struct): likewise (DeriveClone::visit_union): likewise * expand/rust-derive-clone.h: update header * expand/rust-derive-copy.cc (DeriveCopy::copy_impl): similarly take type generics (DeriveCopy::visit_struct): likewise (DeriveCopy::visit_tuple): likewise (DeriveCopy::visit_enum): likewise (DeriveCopy::visit_union): likewise * expand/rust-derive-copy.h: likewse * ast/rust-ast-builder-type.cc: New file. * ast/rust-ast-builder-type.h: New file. gcc/testsuite/ChangeLog: * rust/compile/issue-3139-1.rs: New test. * rust/compile/issue-3139-2.rs: New test. * rust/compile/issue-3139-3.rs: New test. * rust/compile/nr2/exclude: these all break nr2
When we generate derivations for Copy and Clone we need to make sure the associated impl block sets up the generic parameters and arguments correctly. This patch introduces the framework to copy chunks of the AST because we need to make sure these new AST nodes have their own associated id, calling clone on the nodes will just confuse name-resolution and subsequent mappings. Fixes #3139 gcc/rust/ChangeLog: * Make-lang.in: new objects * ast/rust-ast-builder.cc (Builder::generic_type_path_segment): new helper (Builder::single_generic_type_path): likewise (Builder::new_type): likewise (Builder::new_lifetime_param): likewise (Builder::new_type_param): likewise (Builder::new_lifetime): likewise (Builder::new_generic_args): likewise * ast/rust-ast-builder.h: new helper decls * ast/rust-ast.h: new const getters * ast/rust-path.h: likewise * ast/rust-type.h: likewise * expand/rust-derive-clone.cc (DeriveClone::clone_impl): take the types generics (DeriveClone::visit_tuple): likewise (DeriveClone::visit_struct): likewise (DeriveClone::visit_union): likewise * expand/rust-derive-clone.h: update header * expand/rust-derive-copy.cc (DeriveCopy::copy_impl): similarly take type generics (DeriveCopy::visit_struct): likewise (DeriveCopy::visit_tuple): likewise (DeriveCopy::visit_enum): likewise (DeriveCopy::visit_union): likewise * expand/rust-derive-copy.h: likewse * ast/rust-ast-builder-type.cc: New file. * ast/rust-ast-builder-type.h: New file. gcc/testsuite/ChangeLog: * rust/compile/issue-3139-1.rs: New test. * rust/compile/issue-3139-2.rs: New test. * rust/compile/issue-3139-3.rs: New test. * rust/compile/nr2/exclude: these all break nr2
When we generate derivations for Copy and Clone we need to make sure the associated impl block sets up the generic parameters and arguments correctly. This patch introduces the framework to copy chunks of the AST because we need to make sure these new AST nodes have their own associated id, calling clone on the nodes will just confuse name-resolution and subsequent mappings. Fixes #3139 gcc/rust/ChangeLog: * Make-lang.in: new objects * ast/rust-ast-builder.cc (Builder::generic_type_path_segment): new helper (Builder::single_generic_type_path): likewise (Builder::new_type): likewise (Builder::new_lifetime_param): likewise (Builder::new_type_param): likewise (Builder::new_lifetime): likewise (Builder::new_generic_args): likewise * ast/rust-ast-builder.h: new helper decls * ast/rust-ast.h: new const getters * ast/rust-path.h: likewise * ast/rust-type.h: likewise * expand/rust-derive-clone.cc (DeriveClone::clone_impl): take the types generics (DeriveClone::visit_tuple): likewise (DeriveClone::visit_struct): likewise (DeriveClone::visit_union): likewise * expand/rust-derive-clone.h: update header * expand/rust-derive-copy.cc (DeriveCopy::copy_impl): similarly take type generics (DeriveCopy::visit_struct): likewise (DeriveCopy::visit_tuple): likewise (DeriveCopy::visit_enum): likewise (DeriveCopy::visit_union): likewise * expand/rust-derive-copy.h: likewse * ast/rust-ast-builder-type.cc: New file. * ast/rust-ast-builder-type.h: New file. gcc/testsuite/ChangeLog: * rust/compile/issue-3139-1.rs: New test. * rust/compile/issue-3139-2.rs: New test. * rust/compile/issue-3139-3.rs: New test. * rust/compile/nr2/exclude: these all break nr2
Code
Meta
Error output
Backtrace
The text was updated successfully, but these errors were encountered: