Skip to content

Commit e69e162

Browse files
committed
Support inference of generic parameters on paths behind reference's
We used a hack in the parser to turn simple cases such as &Foo(..) into: BorrowExpr CallExpr( IdentifierExpr + <Argument-expressions>)) The IdentifierExpr here is parsed as a PathExpression but to simplify things at the time it seemed logic to see these as identifier expressions but this is actually a Path and we need to be careful about generic arguments here. Identifiers are simply identifiers and must not be changed or coherence of inference variables will become a jumble of inference variables trying to infer one another inside purely generic code. This patch leaves the PathInExpressions as Path's instead of trying to be clever and turn them into identifiers. Fixes #1165
1 parent 2b1cb4b commit e69e162

File tree

2 files changed

+5
-20
lines changed

2 files changed

+5
-20
lines changed

gcc/rust/parse/rust-parse-impl.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12591,16 +12591,6 @@ Parser<ManagedTokenSource>::null_denotation (const_TokenPtr tok,
1259112591
// struct/enum expr struct
1259212592
if (!restrictions.can_be_struct_expr && !not_a_block)
1259312593
{
12594-
// assume path is returned if not single segment
12595-
if (path.is_single_segment ())
12596-
{
12597-
// have to return an identifier expression or something
12598-
/* HACK: may have to become permanent, but this is my
12599-
* current identifier expression */
12600-
return std::unique_ptr<AST::IdentifierExpr> (
12601-
new AST::IdentifierExpr (tok->get_str (), {},
12602-
tok->get_locus ()));
12603-
}
1260412594
// HACK: add outer attrs to path
1260512595
path.set_outer_attrs (std::move (outer_attrs));
1260612596
return std::unique_ptr<AST::PathInExpression> (
@@ -12613,16 +12603,6 @@ Parser<ManagedTokenSource>::null_denotation (const_TokenPtr tok,
1261312603
// struct/enum expr tuple
1261412604
if (!restrictions.can_be_struct_expr)
1261512605
{
12616-
// assume path is returned if not single segment
12617-
if (path.is_single_segment ())
12618-
{
12619-
// have to return an identifier expression or something, idk
12620-
/* HACK: may have to become permanent, but this is my
12621-
* current identifier expression */
12622-
return std::unique_ptr<AST::IdentifierExpr> (
12623-
new AST::IdentifierExpr (tok->get_str (), {},
12624-
tok->get_locus ()));
12625-
}
1262612606
// HACK: add outer attrs to path
1262712607
path.set_outer_attrs (std::move (outer_attrs));
1262812608
return std::unique_ptr<AST::PathInExpression> (
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
struct Foo<T>(T);
2+
3+
fn main() {
4+
&Foo(123);
5+
}

0 commit comments

Comments
 (0)