Skip to content

gccrs: add bare trait objects lint#4634

Open
lucasly-ba wants to merge 1 commit into
Rust-GCC:masterfrom
lucasly-ba:bare-trait-objects
Open

gccrs: add bare trait objects lint#4634
lucasly-ba wants to merge 1 commit into
Rust-GCC:masterfrom
lucasly-ba:bare-trait-objects

Conversation

@lucasly-ba

Copy link
Copy Markdown
Contributor

This patch adds the bare trait objects lint, which warns on trait objects written without an explicit dyn.

A single bare trait (e.g. &Foo) is lowered to a type-path that resolves to a trait definition, handled in visit (HIR::TypePath); a bare trait object with several bounds (e.g. &(Foo + Bar)) is a TraitObjectType without the dyn keyword.

gcc/testsuite/ChangeLog:

* rust/compile/bare-trait-objects_0.rs: New test.

Comment thread gcc/rust/typecheck/rust-hir-type-check-type.cc Outdated

@philberty philberty 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.

that one check i think can be done simpler

@lucasly-ba lucasly-ba force-pushed the bare-trait-objects branch 2 times, most recently from 82ed7c0 to 6ca9899 Compare July 8, 2026 14:47
Warn on trait objects written without an explicit `dyn`. A single bare
trait resolves to a DynamicObjectType while walking the type-path
segments; a bare trait object with several bounds is a TraitObjectType
without the `dyn` keyword.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path):
	Warn when a path segment resolves to a trait object.
	(TypeCheckType::visit): Warn on a bare multi-bound trait object.

gcc/testsuite/ChangeLog:

	* rust/compile/bare-trait-objects_0.rs: New test.

Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
@lucasly-ba lucasly-ba force-pushed the bare-trait-objects branch from 6ca9899 to aed4f2f Compare July 9, 2026 13:45
@lucasly-ba

Copy link
Copy Markdown
Contributor Author

@philberty should be good

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