From: Owen Avery <[email protected]>
Functions without bodies can have different parameters with the same
name.
gcc/rust/ChangeLog:
* resolve/rust-late-name-resolver-2.0.cc (Late::Late):
Initialize in_bodyless_params.
(Late::visit (FunctionParam)): New function definition, skip
visiting the patterns of function parameters on bodyless
functions.
(Late::visit_function_params): Set in_bodyless_params.
* resolve/rust-late-name-resolver-2.0.h
(Late::visit (FunctionParam)): New function declaration.
(Late::in_bodyless_params): New member variable.
gcc/testsuite/ChangeLog:
* rust/compile/multiple_bindings3.rs: New test.
Signed-off-by: Owen Avery <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github:
https://github.com/Rust-GCC/gccrs/commit/d412d003391bba6476e17be629b1870491dadffc
The commit has NOT been mentioned in any issue.
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4927
.../resolve/rust-late-name-resolver-2.0.cc | 21 ++++++++++++++++++-
.../resolve/rust-late-name-resolver-2.0.h | 3 +++
.../rust/compile/multiple_bindings3.rs | 10 +++++++++
3 files changed, 33 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/rust/compile/multiple_bindings3.rs
diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
index e910c7e3b..b568b19b0 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.cc
@@ -37,7 +37,8 @@ namespace Rust {
namespace Resolver2_0 {
Late::Late (NameResolutionContext &ctx)
- : DefaultResolver (ctx), funny_error (false), block_big_self (false)
+ : DefaultResolver (ctx), funny_error (false), block_big_self (false),
+ in_bodyless_params (false)
{}
void
@@ -226,15 +227,33 @@ Late::visit (AST::AltPattern &pattern)
ctx.bindings.peek ().merge ();
}
+void
+Late::visit (AST::FunctionParam ¶m)
+{
+ visit_outer_attrs (param);
+ // we can't handle bindings for bodyless functions
+ // since, ex, `fn foo (a: i32, a: f64);` is valid
+ // (parameter names are ignored)
+ if (param.has_name () && !in_bodyless_params)
+ visit (param.get_pattern ());
+
+ visit (param.get_type ());
+}
+
void
Late::visit_function_params (AST::Function &function)
{
+ bool was_in_bodyless_params = in_bodyless_params;
+ in_bodyless_params = !function.has_body ();
+
ctx.bindings.enter (BindingSource::Param);
for (auto ¶m : function.get_function_params ())
visit (param);
ctx.bindings.exit ();
+
+ in_bodyless_params = was_in_bodyless_params;
}
void
diff --git a/gcc/rust/resolve/rust-late-name-resolver-2.0.h
b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
index 387856334..04bb0b9d7 100644
--- a/gcc/rust/resolve/rust-late-name-resolver-2.0.h
+++ b/gcc/rust/resolve/rust-late-name-resolver-2.0.h
@@ -39,6 +39,7 @@ public:
// Specialized visit bits
void visit_function_params (AST::Function &function) override;
+ void visit (AST::FunctionParam &) override;
// some more label declarations
void visit (AST::LetStmt &) override;
@@ -79,6 +80,8 @@ private:
/* used to prevent "impl Self {}", "impl (Self, i32) {}", etc */
bool block_big_self;
+
+ bool in_bodyless_params;
};
// TODO: Add missing mappings and data structures
diff --git a/gcc/testsuite/rust/compile/multiple_bindings3.rs
b/gcc/testsuite/rust/compile/multiple_bindings3.rs
new file mode 100644
index 000000000..25bcb859f
--- /dev/null
+++ b/gcc/testsuite/rust/compile/multiple_bindings3.rs
@@ -0,0 +1,10 @@
+#![feature(no_core)]
+#![no_core]
+
+extern "C" {
+ fn f1(a: i32, a: i32);
+}
+
+trait A {
+ fn f2(a: i32, a: i32);
+}
base-commit: 69b7ef1a5d9a9cdec93df313259c37b16f3251eb
--
2.55.0