aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/ast
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-07-06 09:15:56 +0000
committerGitHub <noreply@github.com>2022-07-06 09:15:56 +0000
commite0844def89deb7953b6eee563833b0e8e8e2668d (patch)
tree7b5e1dc63abdd67e9e9a1ccf8e76ddeb5e10ab64 /gcc/rust/ast
parent408b7f87b99c1b9d074787ac279c86319ab00667 (diff)
parentf4a5629fb7f6274433005c255bc9baf113856a5d (diff)
downloadgcc-e0844def89deb7953b6eee563833b0e8e8e2668d.zip
gcc-e0844def89deb7953b6eee563833b0e8e8e2668d.tar.gz
gcc-e0844def89deb7953b6eee563833b0e8e8e2668d.tar.bz2
Merge #1346
1346: Support self paths r=philberty a=philberty This adds support for the self path which is used in two different contexts. One where it refers to the self parameter within methods the other is where it can refer to the crate module scope. Handling self has some limitations where it must be the first the segment in the path or be a single segment path for example see: ``` struct foo; fn test() { crate::self::foo; } ``` Errors with (rustc 1.61): ``` Error[E0433]: failed to resolve: `self` in paths can only be used in start position ``` crate and super keywords can be chained as expected but self seems to be a special case. The patch here reorders the algorithm to look at the name/type scope first if its the first segment and handle the lower case self as a special case. If this fails to result in a resolved node we then try to look at the module_scope_id hierarchy to handle the case that the previous segments were crate or super and finally error out at the end if we failed to resolve the segment. We can only error for the first segment as associated paths such as Foo::Bar with Bar being an associated impl block item requiring type-resolution. Fixes #1231 #1227 Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust/ast')
-rw-r--r--gcc/rust/ast/rust-path.h6
1 files changed, 6 insertions, 0 deletions
diff --git a/gcc/rust/ast/rust-path.h b/gcc/rust/ast/rust-path.h
index 36f1c04..c6485c0 100644
--- a/gcc/rust/ast/rust-path.h
+++ b/gcc/rust/ast/rust-path.h
@@ -50,6 +50,8 @@ public:
std::string as_string () const { return segment_name; }
+ Location get_locus () const { return locus; }
+
bool is_super_segment () const { return as_string ().compare ("super") == 0; }
bool is_crate_segment () const { return as_string ().compare ("crate") == 0; }
bool is_lower_self () const { return as_string ().compare ("self") == 0; }
@@ -691,6 +693,10 @@ public:
return get_ident_segment ().is_super_segment ();
}
bool is_big_self_seg () const { return get_ident_segment ().is_big_self (); }
+ bool is_lower_self_seg () const
+ {
+ return get_ident_segment ().is_lower_self ();
+ }
};
// Segment used in type path with generic args