Skip to content

Resolve lang items from extern crate#4694

Open
P-E-P wants to merge 3 commits into
Rust-GCC:masterfrom
P-E-P:lang_items_extern_crate
Open

Resolve lang items from extern crate#4694
P-E-P wants to merge 3 commits into
Rust-GCC:masterfrom
P-E-P:lang_items_extern_crate

Conversation

@P-E-P

@P-E-P P-E-P commented Jul 8, 2026

Copy link
Copy Markdown
Member

I've decided we should keep the current behavior of not visiting extern crate through their extern crate declaration and have an exception for the lang item collector.

P-E-P added 3 commits July 8, 2026 12:06
The metadata format will likely change over the upcoming month and right
now it doesn't support trait impl. This commit simplifies metadata export
by dumping the whole AST within metadatas. This is slower but it should
be more complete and correct.

gcc/rust/ChangeLog:

	* ast/rust-collect-lang-items.cc (CollectLangItems::visit): Visit
	extern crate's content when collecting lang items.
	* ast/rust-collect-lang-items.h: Add function protototype.
	* metadata/rust-export-metadata.cc (ExportContext::push_module_scope):
	Remove.
	(ExportContext::emit_crate): Add a function to export the whole crate.
	(ExportContext::pop_module_scope): Remove.
	(ExportContext::emit_trait): Likewise.
	(ExportContext::emit_use_declaration): Likewise.
	(ExportContext::emit_function): Likewise.
	(ExportContext::emit_extern_block): Likewise.
	(ExportContext::emit_module): Likewise.
	(class ExportVisItems): Likewise.
	(PublicInterface::gather_export_data): Dump the AST.
	* metadata/rust-export-metadata.h: Update prototypes.

gcc/testsuite/ChangeLog:

	* rust/link/simple_function_0.rs: Remove bogus match.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Those metadata files are meant to be read by the parser and not by humans
Although it may help during compiler development, they could still get
expanded by any rust pretty printer.

gcc/rust/ChangeLog:

	* ast/rust-ast-dump.cc (Dump::Dump): Add a default indentation level of
	four and dump newlines.
	* ast/rust-ast-dump.h: Add newline and indentation level configuration
	options.
	* metadata/rust-export-metadata.cc (ExportContext::emit_crate): Do not
	export indentation and newlines.
	* rust-session-manager.cc (Session::dump_ast_pretty_internal): Use an
	indentation level of 4 and dump newlines.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Using the local path for the Clone trait cannot be used with the core
library. This broke most test that "emulate core" with a Clone trait
placed outside a "clone" module.

gcc/rust/ChangeLog:

	* expand/rust-derive-clone.cc (DeriveClone::clone_call): Use the
	canonical path to Clone.

gcc/testsuite/ChangeLog:

	* rust/compile/derive_clone_enum2.rs: Fix test with a clone module
	to mimic the core library.
	* rust/compile/derive_clone_enum3.rs: Likewise.
	* rust/compile/issue-3139-1.rs: Likewise.
	* rust/compile/issue-3144.rs: Likewise.
	* rust/execute/torture/derive_clone_enum1.rs: Likewise.
	* rust/execute/torture/derive_macro3.rs: Likewise.
	* rust/execute/torture/derive_macro4.rs: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
@P-E-P P-E-P marked this pull request as ready for review July 8, 2026 14:49
Dump,
Hide,
} newline;
size_t indentation;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have an enum here as well

enum class Indentation {
    None,
    Spaces4,
}

or something like that if we want more option. If we just want standard implementation then I would do

enum class Indentation {
    None,
    Standard,
}

@CohenArthur CohenArthur left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants