aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-04-13 10:50:13 +0000
committerGitHub <noreply@github.com>2021-04-13 10:50:13 +0000
commit636ad7d95e0f2afa1544ba7deeadf3d52de18a82 (patch)
treefc50976ff47ed0e69ec2d483188e075f7066d2d2 /gcc/rust/backend
parentca8744db3e56bfcf0cf3f0e2a0bf76450aef9438 (diff)
parent4ee35b6edb549be11571536bf78f8585a0282991 (diff)
downloadgcc-636ad7d95e0f2afa1544ba7deeadf3d52de18a82.zip
gcc-636ad7d95e0f2afa1544ba7deeadf3d52de18a82.tar.gz
gcc-636ad7d95e0f2afa1544ba7deeadf3d52de18a82.tar.bz2
Merge #358
358: Canonical Paths for Name Resolution and handle TurboFish properly r=philberty a=philberty Add Canonical paths to name resolution In order to support name resolution and checks for duplicate definitions of names we need canonical paths for all DefId items such as inherent impl items and normal items. Consider: ```rust struct Foo<T>(T); impl Foo<f32> { fn name()... } impl Foo<i32> { fn name()... } ``` Each of the impl blocks have a name function but these are separate due to the concrete impl of the Parameter type passed in. The caveat here is that to call this Function name the programmer must be explicit in which implentation they wish to call such as: ```rust let a = Foo::<f32>::name(); ``` This lets the Path probe lookup the appropriate impl block. The problem here is that rust also allows for the compiler to infer the impl you wish such as: ```rust let a = Foo::name(); ``` This should fail since there are multiple candidates possible for this Path. Unless there might have only been one name function in which case it would have worked. This patch is also responsible to implement PathInExpression by iterating each segment and applying generic arguments as we go. Fixes #355 #335 #325 #353 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust/backend')
-rw-r--r--gcc/rust/backend/rust-compile-expr.h2
-rw-r--r--gcc/rust/backend/rust-compile-resolve-path.h4
2 files changed, 3 insertions, 3 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.h b/gcc/rust/backend/rust-compile-expr.h
index d0c752c..f98ebc6 100644
--- a/gcc/rust/backend/rust-compile-expr.h
+++ b/gcc/rust/backend/rust-compile-expr.h
@@ -526,7 +526,7 @@ public:
void visit (HIR::PathInExpression &expr) override
{
- translated = ResolvePathRef::Compile (&expr, ctx);
+ translated = ResolvePathRef::Compile (expr, ctx);
}
void visit (HIR::LoopExpr &expr) override
diff --git a/gcc/rust/backend/rust-compile-resolve-path.h b/gcc/rust/backend/rust-compile-resolve-path.h
index da1d97e..30486d0 100644
--- a/gcc/rust/backend/rust-compile-resolve-path.h
+++ b/gcc/rust/backend/rust-compile-resolve-path.h
@@ -30,10 +30,10 @@ class ResolvePathRef : public HIRCompileBase
using Rust::Compile::HIRCompileBase::visit;
public:
- static Bexpression *Compile (HIR::Expr *expr, Context *ctx)
+ static Bexpression *Compile (HIR::PathInExpression &expr, Context *ctx)
{
ResolvePathRef resolver (ctx);
- expr->accept_vis (resolver);
+ expr.accept_vis (resolver);
return resolver.resolved;
}