Skip to content

Add range_inclusive_new#4704

Open
nsvke wants to merge 2 commits into
Rust-GCC:masterfrom
nsvke:add-range-inclusive-new
Open

Add range_inclusive_new#4704
nsvke wants to merge 2 commits into
Rust-GCC:masterfrom
nsvke:add-range-inclusive-new

Conversation

@nsvke

@nsvke nsvke commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

This patch introduces the 'range_inclusive_new' lang item to the compiler.
When the compiler encounters an inclusive range expression, it now
correctly desugars the operation into a function call targeting this
lang item instead of lowering it directly into a static struct.

gcc/rust/ChangeLog:

* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Add
desugaring for range_inclusive_new lang item.
* util/rust-lang-item.cc (Rust::LangItem::lang_items): Add
range_inclusive_new to the BiMap.
* util/rust-lang-item.h (class LangItem): Add RANGE_INCLUSIVE_NEW
to the Kind enum.

gcc/testsuite/ChangeLog:

* rust/compile/torture/range-lang-item1.rs: Update test to use
the new lang item.

This patch removes the unnecessary HIR::RangeFromToInclExpr class and its
associated visitors across the compiler. Since inclusive ranges are now
directly desugared into a CallExpr targeting the 'range_inclusive_new'
lang item during AST-to-HIR lowering, this HIR node and its
codegen/typecheck implementations are dead code.

gcc/rust/ChangeLog:

* backend/rust-compile-block.h: Remove RangeFromToInclExpr visit.
* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise.
* backend/rust-compile-expr.h: Likewise.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
(ExprStmtBuilder::visit): Likewise.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Likewise.
* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h:
Likewise.
* checks/errors/borrowck/rust-bir-builder-struct.h: Likewise.
* checks/errors/borrowck/rust-function-collector.h: Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc
(PrivacyReporter::visit): Likewise.
* checks/errors/privacy/rust-privacy-reporter.h: Likewise.
* checks/errors/rust-const-checker.cc (ConstChecker::visit):
Likewise.
* checks/errors/rust-const-checker.h: Likewise.
* checks/errors/rust-hir-pattern-analysis.cc
(PatternChecker::visit): Likewise.
* checks/errors/rust-hir-pattern-analysis.h: Likewise.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit):
Likewise.
* checks/errors/rust-unsafe-checker.h: Likewise.
* hir/rust-hir-dump.cc (Dump::visit): Likewise.
* hir/rust-hir-dump.h: Likewise.
* hir/tree/rust-hir-expr.cc
(RangeFromToInclExpr::RangeFromToInclExpr): Likewise.
(RangeFromToInclExpr::operator=): Likewise.
* hir/tree/rust-hir-expr.h (class RangeFromToInclExpr): Remove
class.
* hir/tree/rust-hir-full-decls.h (class RangeFromToInclExpr):
Remove forward declaration.
* hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor::walk): Remove
RangeFromToInclExpr visit.
* hir/tree/rust-hir-visitor.h: Likewise.
* hir/tree/rust-hir.cc (RangeFromToInclExpr::to_string): Remove.
(RangeFromToInclExpr::accept_vis): Remove.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Remove.
* typecheck/rust-hir-type-check-expr.h: Remove
RangeFromToInclExpr visit.

nsvke added 2 commits July 14, 2026 14:46
This patch introduces the 'range_inclusive_new' lang item to the compiler.
When the compiler encounters an inclusive range expression, it now
correctly desugars the operation into a function call targeting this
lang item instead of lowering it directly into a static struct.

gcc/rust/ChangeLog:

	* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Add
	desugaring for range_inclusive_new lang item.
	* util/rust-lang-item.cc (Rust::LangItem::lang_items): Add
	range_inclusive_new to the BiMap.
	* util/rust-lang-item.h (class LangItem): Add RANGE_INCLUSIVE_NEW
	to the Kind enum.

gcc/testsuite/ChangeLog:

	* rust/compile/torture/range-lang-item1.rs: Update test to use
	the new lang item.

Signed-off-by: Enes Cevik <enes@nsvke.com>
This patch removes the unnecessary HIR::RangeFromToInclExpr class and its
associated visitors across the compiler. Since inclusive ranges are now
directly desugared into a CallExpr targeting the 'range_inclusive_new'
lang item during AST-to-HIR lowering, this HIR node and its
codegen/typecheck implementations are dead code.

gcc/rust/ChangeLog:

	* backend/rust-compile-block.h: Remove RangeFromToInclExpr visit.
	* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise.
	* backend/rust-compile-expr.h: Likewise.
	* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
	(ExprStmtBuilder::visit): Likewise.
	* checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Likewise.
	* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h:
	Likewise.
	* checks/errors/borrowck/rust-bir-builder-struct.h: Likewise.
	* checks/errors/borrowck/rust-function-collector.h: Likewise.
	* checks/errors/privacy/rust-privacy-reporter.cc
	(PrivacyReporter::visit): Likewise.
	* checks/errors/privacy/rust-privacy-reporter.h: Likewise.
	* checks/errors/rust-const-checker.cc (ConstChecker::visit):
	Likewise.
	* checks/errors/rust-const-checker.h: Likewise.
	* checks/errors/rust-hir-pattern-analysis.cc
	(PatternChecker::visit): Likewise.
	* checks/errors/rust-hir-pattern-analysis.h: Likewise.
	* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit):
	Likewise.
	* checks/errors/rust-unsafe-checker.h: Likewise.
	* hir/rust-hir-dump.cc (Dump::visit): Likewise.
	* hir/rust-hir-dump.h: Likewise.
	* hir/tree/rust-hir-expr.cc
	(RangeFromToInclExpr::RangeFromToInclExpr): Likewise.
	(RangeFromToInclExpr::operator=): Likewise.
	* hir/tree/rust-hir-expr.h (class RangeFromToInclExpr): Remove
	class.
	* hir/tree/rust-hir-full-decls.h (class RangeFromToInclExpr):
	Remove forward declaration.
	* hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor::walk): Remove
	RangeFromToInclExpr visit.
	* hir/tree/rust-hir-visitor.h: Likewise.
	* hir/tree/rust-hir.cc (RangeFromToInclExpr::to_string): Remove.
	(RangeFromToInclExpr::accept_vis): Remove.
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
	Remove.
	* typecheck/rust-hir-type-check-expr.h: Remove
	RangeFromToInclExpr visit.

Signed-off-by: Enes Cevik <enes@nsvke.com>
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.

1 participant