gccrs: add bare trait objects lint#4634
Open
lucasly-ba wants to merge 1 commit into
Open
Conversation
philberty
reviewed
Jun 28, 2026
philberty
requested changes
Jun 28, 2026
philberty
left a comment
Member
There was a problem hiding this comment.
that one check i think can be done simpler
82ed7c0 to
6ca9899
Compare
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>
6ca9899 to
aed4f2f
Compare
Contributor
Author
|
@philberty should be good |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 invisit (HIR::TypePath); a bare trait object with several bounds (e.g.&(Foo + Bar)) is aTraitObjectTypewithout thedynkeyword.gcc/testsuite/ChangeLog: