summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-10-29 11:52:53 +0800
committerJohn Hodge <tpg@mutabah.net>2016-10-29 11:52:53 +0800
commit0c3cd458773f2fa416dbb3448b0976e1ab178476 (patch)
tree9ad9808f36a8097a2996a9d11c2163ee0606e744 /src
parent6be8db3efc9a9156e262a03c8d6b13d32e3b1c39 (diff)
downloadmrust-0c3cd458773f2fa416dbb3448b0976e1ab178476.tar.gz
Parse - Convert `<Foo>::BAR` into `<Foo as _>::BAR`
Diffstat (limited to 'src')
-rw-r--r--src/parse/expr.cpp22
-rw-r--r--src/parse/paths.cpp6
-rw-r--r--src/resolve/absolute.cpp2
3 files changed, 10 insertions, 20 deletions
diff --git a/src/parse/expr.cpp b/src/parse/expr.cpp
index ddac8a2b..018000db 100644
--- a/src/parse/expr.cpp
+++ b/src/parse/expr.cpp
@@ -1066,23 +1066,10 @@ ExprNodeP Parse_ExprVal(TokenStream& lex)
// UFCS
case TOK_DOUBLE_LT:
- PUTBACK(TOK_LT, lex);
- case TOK_LT: {
- TypeRef ty = Parse_Type(lex);
- if( GET_TOK(tok, lex) == TOK_RWORD_AS ) {
- auto trait = Parse_Path(lex, PATH_GENERIC_TYPE);
- GET_CHECK_TOK(tok, lex, TOK_GT);
- GET_CHECK_TOK(tok, lex, TOK_DOUBLE_COLON);
- path = AST::Path(AST::Path::TagUfcs(), ty, trait, Parse_PathNodes(lex, PATH_GENERIC_EXPR));
- }
- else {
- PUTBACK(tok, lex);
- GET_CHECK_TOK(tok, lex, TOK_GT);
- // TODO: Terminating the "path" here is sometimes valid
- GET_CHECK_TOK(tok, lex, TOK_DOUBLE_COLON);
- path = AST::Path(AST::Path::TagUfcs(), ty, Parse_PathNodes(lex, PATH_GENERIC_EXPR));
- }
- }
+ case TOK_LT:
+ PUTBACK(tok, lex);
+ path = Parse_Path(lex, PATH_GENERIC_EXPR);
+ // Skip down to method
if(0)
case TOK_RWORD_SELF:
{
@@ -1116,6 +1103,7 @@ ExprNodeP Parse_ExprVal(TokenStream& lex)
if(0)
case TOK_DOUBLE_COLON:
path = Parse_Path(lex, true, PATH_GENERIC_EXPR);
+ // SKIP TARGET
switch( GET_TOK(tok, lex) )
{
case TOK_PAREN_OPEN:
diff --git a/src/parse/paths.cpp b/src/parse/paths.cpp
index ecfdf7dd..c952d977 100644
--- a/src/parse/paths.cpp
+++ b/src/parse/paths.cpp
@@ -45,7 +45,7 @@ AST::Path Parse_Path(TokenStream& lex, eParsePathGenericMode generic_mode)
case TOK_DOUBLE_LT:
lex.putback( Token(TOK_LT) );
case TOK_LT: {
- TypeRef ty = Parse_Type(lex, false); // Don't allow un-parenthesied trait objects
+ TypeRef ty = Parse_Type(lex, true); // Allow trait objects without parens
if( GET_TOK(tok, lex) == TOK_RWORD_AS ) {
::AST::Path trait;
if( GET_TOK(tok, lex) == TOK_DOUBLE_COLON ) {
@@ -64,7 +64,9 @@ AST::Path Parse_Path(TokenStream& lex, eParsePathGenericMode generic_mode)
GET_CHECK_TOK(tok, lex, TOK_GT);
// TODO: Terminating the "path" here is sometimes valid?
GET_CHECK_TOK(tok, lex, TOK_DOUBLE_COLON);
- return AST::Path(AST::Path::TagUfcs(), ty, Parse_PathNodes(lex, generic_mode));
+ // NOTE: <Foo>::BAR is actually `<Foo as _>::BAR` (in mrustc parleance)
+ //return AST::Path(AST::Path::TagUfcs(), ty, Parse_PathNodes(lex, generic_mode));
+ return AST::Path(AST::Path::TagUfcs(), ty, AST::Path(), Parse_PathNodes(lex, generic_mode));
}
throw ""; }
diff --git a/src/resolve/absolute.cpp b/src/resolve/absolute.cpp
index d8b167c4..7f69f02d 100644
--- a/src/resolve/absolute.cpp
+++ b/src/resolve/absolute.cpp
@@ -1388,7 +1388,7 @@ void Resolve_Absolute_Path(/*const*/ Context& context, const Span& sp, Context::
(UFCS,
DEBUG("- UFCS");
Resolve_Absolute_Type(context, *e.type);
- if( e.trait ) {
+ if( e.trait && *e.trait != ::AST::Path() ) {
Resolve_Absolute_Path(context, sp, Context::LookupMode::Type, *e.trait);
}