Skip to content

gccrs: add self_constructor_from_outer_item lint - #4652

Open
lucasly-ba wants to merge 1 commit into
Rust-GCC:masterfrom
lucasly-ba:self-constructor-from-outer-item
Open

gccrs: add self_constructor_from_outer_item lint#4652
lucasly-ba wants to merge 1 commit into
Rust-GCC:masterfrom
lucasly-ba:self-constructor-from-outer-item

Conversation

@lucasly-ba

Copy link
Copy Markdown
Contributor

Warn when the Self constructor is used from an item nested inside an impl or trait, such as a function defined in a method body. Nested items do not inherit the Self of the surrounding impl. Gated behind -frust-unused-check-2.0.

@lucasly-ba
lucasly-ba force-pushed the self-constructor-from-outer-item branch from c01321f to 6616157 Compare June 29, 2026 16:17
@philberty

Copy link
Copy Markdown
Member

merge conflicts

@lucasly-ba
lucasly-ba force-pushed the self-constructor-from-outer-item branch from 6616157 to 0e907be Compare July 6, 2026 12:02
@powerboat9

Copy link
Copy Markdown
Collaborator

I think this should be an error unassociated with the unused checker

@lucasly-ba
lucasly-ba force-pushed the self-constructor-from-outer-item branch from 0e907be to 7e9b048 Compare July 8, 2026 14:42
A function nested inside an associated item cannot capture the outer
item's Self.

gcc/rust/ChangeLog:

	* Make-lang.in (GRS_OBJS): Add rust-hir-self-constructor.o.
	* checks/errors/rust-hir-self-constructor.cc: New file.
	* checks/errors/rust-hir-self-constructor.h: New file.
	* rust-session-manager.cc (Session::compile_crate): Run the
	self-constructor checker.

gcc/testsuite/ChangeLog:

	* rust/compile/self-constructor-from-outer-item_0.rs: New test.

Signed-off-by: Lucas Ly Ba <lucas.ly-ba@outlook.com>
@lucasly-ba
lucasly-ba force-pushed the self-constructor-from-outer-item branch from 7e9b048 to aee4b85 Compare July 9, 2026 15:54
@lucasly-ba

Copy link
Copy Markdown
Contributor Author

@P-E-P

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.

3 participants