Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
efb3872a
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
efb3872a
编写于
5月 07, 2015
作者:
S
Sean Patrick Santos
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix use of UFCS syntax to call methods on associated types.
上级
6b3d66b0
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
83 addition
and
45 deletion
+83
-45
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+13
-10
src/libsyntax/parse/parser.rs
src/libsyntax/parse/parser.rs
+15
-35
src/test/run-pass/associated-item-long-paths.rs
src/test/run-pass/associated-item-long-paths.rs
+55
-0
未找到文件。
src/librustc_resolve/lib.rs
浏览文件 @
efb3872a
...
...
@@ -2688,18 +2688,21 @@ fn resolve_possibly_assoc_item(&mut self,
check_ribs
:
bool
)
->
AssocItemResolveResult
{
let
max_assoc_types
;
match
maybe_qself
{
Some
(
&
ast
::
QSelf
{
position
:
0
,
..
})
=>
return
TypecheckRequired
,
_
=>
{}
Some
(
qself
)
=>
{
if
qself
.position
==
0
{
return
TypecheckRequired
;
}
max_assoc_types
=
path
.segments
.len
()
-
qself
.position
;
// Make sure the trait is valid.
let
_
=
self
.resolve_trait_reference
(
id
,
path
,
max_assoc_types
);
}
None
=>
{
max_assoc_types
=
path
.segments
.len
();
}
}
let
max_assoc_types
=
if
let
Some
(
qself
)
=
maybe_qself
{
// Make sure the trait is valid.
let
_
=
self
.resolve_trait_reference
(
id
,
path
,
1
);
path
.segments
.len
()
-
qself
.position
}
else
{
path
.segments
.len
()
};
let
mut
resolution
=
self
.with_no_errors
(|
this
|
{
this
.resolve_path
(
id
,
path
,
0
,
namespace
,
check_ribs
)
...
...
src/libsyntax/parse/parser.rs
浏览文件 @
efb3872a
...
...
@@ -110,15 +110,6 @@ pub enum PathParsingMode {
LifetimeAndTypesWithColons
,
}
/// How to parse a qualified path, whether to allow trailing parameters.
#[derive(Copy,
Clone,
PartialEq)]
pub
enum
QPathParsingMode
{
/// No trailing parameters, e.g. `<T as Trait>::Item`
NoParameters
,
/// Optional parameters, e.g. `<T as Trait>::item::<'a, U>`
MaybeParameters
,
}
/// How to parse a bound, whether to allow bound modifiers such as `?`.
#[derive(Copy,
Clone,
PartialEq)]
pub
enum
BoundParsingMode
{
...
...
@@ -1360,7 +1351,7 @@ pub fn parse_ty_nopanic(&mut self) -> PResult<P<Ty>> {
}
else
if
try!
(
self
.eat_lt
())
{
let
(
qself
,
path
)
=
try!
(
self
.parse_qualified_path
(
QPathParsingMode
::
NoParameters
));
try!
(
self
.parse_qualified_path
(
NoTypesAllowed
));
TyPath
(
Some
(
qself
),
path
)
}
else
if
self
.check
(
&
token
::
ModSep
)
||
...
...
@@ -1579,7 +1570,7 @@ pub fn parse_literal_maybe_minus(&mut self) -> PResult<P<Expr>> {
// QUALIFIED PATH `<TYPE [as TRAIT_REF]>::IDENT[::<PARAMS>]`
// Assumes that the leading `<` has been parsed already.
pub
fn
parse_qualified_path
(
&
mut
self
,
mode
:
Q
PathParsingMode
)
pub
fn
parse_qualified_path
(
&
mut
self
,
mode
:
PathParsingMode
)
->
PResult
<
(
QSelf
,
ast
::
Path
)
>
{
let
self_type
=
try!
(
self
.parse_ty_sum
());
let
mut
path
=
if
try!
(
self
.eat_keyword
(
keywords
::
As
))
{
...
...
@@ -1600,29 +1591,18 @@ pub fn parse_qualified_path(&mut self, mode: QPathParsingMode)
try!
(
self
.expect
(
&
token
::
Gt
));
try!
(
self
.expect
(
&
token
::
ModSep
));
let
item_name
=
try!
(
self
.parse_ident
());
let
parameters
=
match
mode
{
QPathParsingMode
::
NoParameters
=>
ast
::
PathParameters
::
none
(),
QPathParsingMode
::
MaybeParameters
=>
{
if
try!
(
self
.eat
(
&
token
::
ModSep
))
{
try!
(
self
.expect_lt
());
// Consumed `item::<`, go look for types
let
(
lifetimes
,
types
,
bindings
)
=
try!
(
self
.parse_generic_values_after_lt
());
ast
::
AngleBracketedParameters
(
ast
::
AngleBracketedParameterData
{
lifetimes
:
lifetimes
,
types
:
OwnedSlice
::
from_vec
(
types
),
bindings
:
OwnedSlice
::
from_vec
(
bindings
),
})
}
else
{
ast
::
PathParameters
::
none
()
}
let
segments
=
match
mode
{
LifetimeAndTypesWithoutColons
=>
{
try!
(
self
.parse_path_segments_without_colons
())
}
LifetimeAndTypesWithColons
=>
{
try!
(
self
.parse_path_segments_with_colons
())
}
NoTypesAllowed
=>
{
try!
(
self
.parse_path_segments_without_types
())
}
};
path
.segments
.push
(
ast
::
PathSegment
{
identifier
:
item_name
,
parameters
:
parameters
});
path
.segments
.extend
(
segments
);
if
path
.segments
.len
()
==
1
{
path
.span.lo
=
self
.last_span.lo
;
...
...
@@ -2097,7 +2077,7 @@ pub fn parse_bottom_expr(&mut self) -> PResult<P<Expr>> {
if
try!
(
self
.eat_lt
()){
let
(
qself
,
path
)
=
try!
(
self
.parse_qualified_path
(
QPathParsingMode
::
MaybeParameter
s
));
try!
(
self
.parse_qualified_path
(
LifetimeAndTypesWithColon
s
));
return
Ok
(
self
.mk_expr
(
lo
,
hi
,
ExprPath
(
Some
(
qself
),
path
)));
}
...
...
@@ -3177,7 +3157,7 @@ fn parse_pat_range_end(&mut self) -> PResult<P<Expr>> {
let
(
qself
,
path
)
=
if
try!
(
self
.eat_lt
())
{
// Parse a qualified path
let
(
qself
,
path
)
=
try!
(
self
.parse_qualified_path
(
QPathParsingMode
::
NoParameters
));
try!
(
self
.parse_qualified_path
(
NoTypesAllowed
));
(
Some
(
qself
),
path
)
}
else
{
// Parse an unqualified path
...
...
@@ -3271,7 +3251,7 @@ pub fn parse_pat_nopanic(&mut self) -> PResult<P<Pat>> {
let
(
qself
,
path
)
=
if
try!
(
self
.eat_lt
())
{
// Parse a qualified path
let
(
qself
,
path
)
=
try!
(
self
.parse_qualified_path
(
QPathParsingMode
::
NoParameters
));
try!
(
self
.parse_qualified_path
(
NoTypesAllowed
));
(
Some
(
qself
),
path
)
}
else
{
// Parse an unqualified path
...
...
src/test/run-pass/associated-item-long-paths.rs
0 → 100644
浏览文件 @
efb3872a
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use
std
::
mem
::
size_of
;
// The main point of this test is to ensure that we can parse and resolve
// associated items on associated types.
trait
Foo
{
type
U
;
}
trait
Bar
{
// Note 1: Chains of associated items in a path won't type-check.
// Note 2: Associated consts can't depend on type parameters or `Self`,
// which are the only types that an associated type can be referenced on for
// now, so we can only test methods.
fn
method
()
->
u32
;
fn
generic_method
<
T
>
()
->
usize
;
}
struct
MyFoo
;
struct
MyBar
;
impl
Foo
for
MyFoo
{
type
U
=
MyBar
;
}
impl
Bar
for
MyBar
{
fn
method
()
->
u32
{
2u32
}
fn
generic_method
<
T
>
()
->
usize
{
size_of
::
<
T
>
()
}
}
fn
foo
<
T
>
()
where
T
:
Foo
,
T
::
U
:
Bar
,
{
assert_eq!
(
2u32
,
<
T
as
Foo
>
::
U
::
method
());
assert_eq!
(
8u
size
,
<
T
as
Foo
>
::
U
::
generic_method
::
<
f64
>
());
}
fn
main
()
{
foo
::
<
MyFoo
>
();
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录