Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
91b9dabd
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,发现更多精彩内容 >>
提交
91b9dabd
编写于
6月 03, 2016
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
resolve: Rewrite resolve_pattern
上级
ee00760a
变更
28
展开全部
隐藏空白更改
内联
并排
Showing
28 changed file
with
339 addition
and
483 deletion
+339
-483
src/librustc/hir/def.rs
src/librustc/hir/def.rs
+10
-2
src/librustc_resolve/diagnostics.rs
src/librustc_resolve/diagnostics.rs
+3
-34
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+279
-402
src/test/compile-fail/associated-const-private-impl.rs
src/test/compile-fail/associated-const-private-impl.rs
+1
-1
src/test/compile-fail/blind-item-block-middle.rs
src/test/compile-fail/blind-item-block-middle.rs
+1
-1
src/test/compile-fail/const-pattern-irrefutable.rs
src/test/compile-fail/const-pattern-irrefutable.rs
+6
-6
src/test/compile-fail/empty-struct-braces-pat-2.rs
src/test/compile-fail/empty-struct-braces-pat-2.rs
+2
-2
src/test/compile-fail/enum-in-scope.rs
src/test/compile-fail/enum-in-scope.rs
+1
-1
src/test/compile-fail/enums-pats-not-idents.rs
src/test/compile-fail/enums-pats-not-idents.rs
+1
-4
src/test/compile-fail/issue-10200.rs
src/test/compile-fail/issue-10200.rs
+1
-1
src/test/compile-fail/issue-12863.rs
src/test/compile-fail/issue-12863.rs
+1
-1
src/test/compile-fail/issue-16149.rs
src/test/compile-fail/issue-16149.rs
+1
-1
src/test/compile-fail/issue-17405.rs
src/test/compile-fail/issue-17405.rs
+2
-1
src/test/compile-fail/issue-17718-const-privacy.rs
src/test/compile-fail/issue-17718-const-privacy.rs
+2
-2
src/test/compile-fail/issue-17718-patterns.rs
src/test/compile-fail/issue-17718-patterns.rs
+2
-2
src/test/compile-fail/issue-17933.rs
src/test/compile-fail/issue-17933.rs
+1
-1
src/test/compile-fail/issue-23716.rs
src/test/compile-fail/issue-23716.rs
+6
-6
src/test/compile-fail/issue-26459.rs
src/test/compile-fail/issue-26459.rs
+2
-1
src/test/compile-fail/issue-27033.rs
src/test/compile-fail/issue-27033.rs
+2
-2
src/test/compile-fail/issue-27815.rs
src/test/compile-fail/issue-27815.rs
+4
-2
src/test/compile-fail/issue-28992-empty.rs
src/test/compile-fail/issue-28992-empty.rs
+1
-1
src/test/compile-fail/issue-5927.rs
src/test/compile-fail/issue-5927.rs
+1
-1
src/test/compile-fail/method-resolvable-path-in-pattern.rs
src/test/compile-fail/method-resolvable-path-in-pattern.rs
+1
-1
src/test/compile-fail/name-clash-nullary.rs
src/test/compile-fail/name-clash-nullary.rs
+3
-2
src/test/compile-fail/pat-shadow-in-nested-binding.rs
src/test/compile-fail/pat-shadow-in-nested-binding.rs
+1
-1
src/test/compile-fail/qualified-path-params.rs
src/test/compile-fail/qualified-path-params.rs
+1
-1
src/test/compile-fail/static-mut-not-pat.rs
src/test/compile-fail/static-mut-not-pat.rs
+2
-2
src/test/compile-fail/trait-impl-for-module.rs
src/test/compile-fail/trait-impl-for-module.rs
+1
-1
未找到文件。
src/librustc/hir/def.rs
浏览文件 @
91b9dabd
...
...
@@ -88,6 +88,14 @@ pub fn new(base_def: Def,
depth
:
depth
,
}
}
pub
fn
kind_name
(
&
self
)
->
&
'static
str
{
if
self
.depth
!=
0
{
"associated item"
}
else
{
self
.base_def
.kind_name
()
}
}
}
// Definition mapping
...
...
@@ -161,8 +169,8 @@ pub fn kind_name(&self) -> &'static str {
Def
::
Struct
(
..
)
=>
"struct"
,
Def
::
Trait
(
..
)
=>
"trait"
,
Def
::
Method
(
..
)
=>
"method"
,
Def
::
Const
(
..
)
=>
"const"
,
Def
::
AssociatedConst
(
..
)
=>
"associated const"
,
Def
::
Const
(
..
)
=>
"const
ant
"
,
Def
::
AssociatedConst
(
..
)
=>
"associated const
ant
"
,
Def
::
TyParam
(
..
)
=>
"type parameter"
,
Def
::
PrimTy
(
..
)
=>
"builtin type"
,
Def
::
Local
(
..
)
=>
"local variable"
,
...
...
src/librustc_resolve/diagnostics.rs
浏览文件 @
91b9dabd
...
...
@@ -842,32 +842,6 @@ fn foo(f: i32, g: i32) {} // ok!
```
"##
,
E0419
:
r##"
An unknown enum variant, struct or const was used. Example of erroneous code:
```compile_fail
match 0 {
Something::Foo => {} // error: unresolved enum variant, struct
// or const `Foo`
}
```
Please verify you didn't misspell it and the enum variant, struct or const has
been declared and imported into scope. Example:
```
enum Something {
Foo,
NotFoo,
}
match Something::NotFoo {
Something::Foo => {} // ok!
_ => {}
}
```
"##
,
E0422
:
r##"
You are trying to use an identifier that is either undefined or not a struct.
For instance:
...
...
@@ -1247,16 +1221,11 @@ impl Foo for i32 {}
}
register_diagnostics!
{
// E0153, unused error code
// E0157, unused error code
E0254
,
// import conflicts with imported crate in this module
// E0257,
// E0258,
E0402
,
// cannot use an outer type parameter in this context
E0406
,
// undeclared associated type
// E0410, merged into 408
E0418
,
// is not an enum variant, struct or const
E0420
,
// is not an associated const
E0421
,
// unresolved associated const
E0418
,
// X bindings cannot shadow Ys
E0419
,
// unresolved pattern path kind `name`
E0420
,
// expected pattern path kind, found another pattern path kind
E0427
,
// cannot use `ref` binding mode with ...
}
src/librustc_resolve/lib.rs
浏览文件 @
91b9dabd
此差异已折叠。
点击以展开。
src/test/compile-fail/associated-const-private-impl.rs
浏览文件 @
91b9dabd
...
...
@@ -23,5 +23,5 @@ impl Foo {
fn
main
()
{
assert_eq!
(
1
,
bar1
::
Foo
::
ID
);
//~^ERROR associated const `ID` is private
//~^ERROR associated const
ant
`ID` is private
}
src/test/compile-fail/blind-item-block-middle.rs
浏览文件 @
91b9dabd
...
...
@@ -12,6 +12,6 @@
fn
main
()
{
let
bar
=
5
;
//~^ ERROR
cannot be named the same
//~^ ERROR
let bindings cannot shadow structs
use
foo
::
bar
;
}
src/test/compile-fail/const-pattern-irrefutable.rs
浏览文件 @
91b9dabd
...
...
@@ -19,10 +19,10 @@ mod foo {
const
a
:
u8
=
2
;
//~ NOTE is defined here
fn
main
()
{
let
a
=
4
;
//~ ERROR let
variables cannot
//~^ NOTE cannot be named the same as a const
variable
let
c
=
4
;
//~ ERROR let
variables cannot
//~^ NOTE cannot be named the same as a const
variable
let
d
=
4
;
//~ ERROR let
variables cannot
//~^ NOTE cannot be named the same as a const
variable
let
a
=
4
;
//~ ERROR let
bindings cannot shadow constants
//~^ NOTE cannot be named the same as a const
ant
let
c
=
4
;
//~ ERROR let
bindings cannot shadow constants
//~^ NOTE cannot be named the same as a const
ant
let
d
=
4
;
//~ ERROR let
bindings cannot shadow constants
//~^ NOTE cannot be named the same as a const
ant
}
src/test/compile-fail/empty-struct-braces-pat-2.rs
浏览文件 @
91b9dabd
...
...
@@ -29,9 +29,9 @@ fn main() {
// XEmpty1() => () // ERROR unresolved enum variant, struct or const `XEmpty1`
// }
match
e1
{
Empty1
(
..
)
=>
()
//~ ERROR unresolved
enum variant, struct or cons
t `Empty1`
Empty1
(
..
)
=>
()
//~ ERROR unresolved
variant or struc
t `Empty1`
}
match
xe1
{
XEmpty1
(
..
)
=>
()
//~ ERROR unresolved
enum variant, struct or cons
t `XEmpty1`
XEmpty1
(
..
)
=>
()
//~ ERROR unresolved
variant or struc
t `XEmpty1`
}
}
src/test/compile-fail/enum-in-scope.rs
浏览文件 @
91b9dabd
...
...
@@ -11,5 +11,5 @@
struct
hello
(
isize
);
fn
main
()
{
let
hello
=
0
;
//~ERROR
cannot be named the same
let
hello
=
0
;
//~ERROR
let bindings cannot shadow structs
}
src/test/compile-fail/enums-pats-not-idents.rs
浏览文件 @
91b9dabd
...
...
@@ -8,9 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//error-pattern:unresolved enum variant
fn
main
()
{
// a bug in the parser is allowing this:
let
a
(
1
)
=
13
;
let
a
(
1
)
=
13
;
//~ ERROR unresolved variant or struct `a`
}
src/test/compile-fail/issue-10200.rs
浏览文件 @
91b9dabd
...
...
@@ -13,7 +13,7 @@ fn foo(_: usize) -> Foo { Foo(false) }
fn
main
()
{
match
Foo
(
true
)
{
foo
(
x
)
//~ ERROR
`foo` is not an enum variant, struct or const
foo
(
x
)
//~ ERROR
expected variant or struct, found function `foo`
=>
()
}
}
src/test/compile-fail/issue-12863.rs
浏览文件 @
91b9dabd
...
...
@@ -12,6 +12,6 @@ mod foo { pub fn bar() {} }
fn
main
()
{
match
()
{
foo
::
bar
=>
{}
//~ ERROR
`bar` is not an enum variant, struct or const
foo
::
bar
=>
{}
//~ ERROR
expected variant, struct or constant, found function `bar`
}
}
src/test/compile-fail/issue-16149.rs
浏览文件 @
91b9dabd
...
...
@@ -15,7 +15,7 @@
fn
main
()
{
let
boolValue
=
match
42
{
externalValue
=>
true
,
//~^ ERROR
static variables cannot be referenced in a pattern
//~^ ERROR
match bindings cannot shadow statics
_
=>
false
};
}
src/test/compile-fail/issue-17405.rs
浏览文件 @
91b9dabd
...
...
@@ -14,6 +14,7 @@ enum Foo {
fn
main
()
{
match
Foo
::
Bar
(
1
)
{
Foo
{
i
}
=>
()
//~ ERROR `Foo` does not name a struct or a struct variant
Foo
{
i
}
=>
()
//~ ERROR expected variant, struct or type alias, found enum `Foo`
//~^ ERROR `Foo` does not name a struct or a struct variant
}
}
src/test/compile-fail/issue-17718-const-privacy.rs
浏览文件 @
91b9dabd
...
...
@@ -12,10 +12,10 @@
extern
crate
issue_17718_const_privacy
as
other
;
use
a
::
B
;
//~ ERROR: const `B` is private
use
a
::
B
;
//~ ERROR: const
ant
`B` is private
use
other
::{
FOO
,
BAR
,
//~ ERROR: const `BAR` is private
BAR
,
//~ ERROR: const
ant
`BAR` is private
FOO2
,
};
...
...
src/test/compile-fail/issue-17718-patterns.rs
浏览文件 @
91b9dabd
...
...
@@ -14,8 +14,8 @@
fn
main
()
{
match
1
{
A1
=>
{}
//~ ERROR:
static variables cannot be referenced in a pattern
A2
=>
{}
//~ ERROR:
static variables cannot be referenced in a pattern
A1
=>
{}
//~ ERROR:
match bindings cannot shadow statics
A2
=>
{}
//~ ERROR:
match bindings cannot shadow statics
A3
=>
{}
_
=>
{}
}
...
...
src/test/compile-fail/issue-17933.rs
浏览文件 @
91b9dabd
...
...
@@ -13,7 +13,7 @@
fn
main
()
{
match
1
{
self
::
X
=>
{
},
//~^ ERROR
static variables cannot be referenced in a pattern, use a `const` instead
//~^ ERROR
expected variant, struct or constant, found static `X`
_
=>
{
},
}
}
src/test/compile-fail/issue-23716.rs
浏览文件 @
91b9dabd
...
...
@@ -9,21 +9,21 @@
// except according to those terms.
static
foo
:
i32
=
0
;
//~^ NOTE
static variable
defined here
//~^ NOTE
a static `foo` is
defined here
fn
bar
(
foo
:
i32
)
{}
//~^ ERROR
static variables cannot be referenced in a pattern, use a `const` instead
//~|
static variable used in pattern
//~^ ERROR
function parameters cannot shadow statics
//~|
cannot be named the same as a static
mod
submod
{
pub
static
answer
:
i32
=
42
;
}
use
self
::
submod
::
answer
;
//~^ NOTE
static variable
imported here
//~^ NOTE
a static `answer` is
imported here
fn
question
(
answer
:
i32
)
{}
//~^ ERROR
static variables cannot be referenced in a pattern, use a `const` instead
//~|
static variable used in pattern
//~^ ERROR
function parameters cannot shadow statics
//~|
cannot be named the same as a static
fn
main
()
{
}
src/test/compile-fail/issue-26459.rs
浏览文件 @
91b9dabd
...
...
@@ -11,6 +11,7 @@
fn
main
()
{
match
'a'
{
char
{
ch
}
=>
true
//~^ ERROR `char` does not name a struct or a struct variant
//~^ ERROR expected variant, struct or type alias, found builtin type `char`
//~| ERROR `char` does not name a struct or a struct variant
};
}
src/test/compile-fail/issue-27033.rs
浏览文件 @
91b9dabd
...
...
@@ -10,11 +10,11 @@
fn
main
()
{
match
Some
(
1
)
{
None
@
_
=>
{}
//~ ERROR
cannot be named the same
None
@
_
=>
{}
//~ ERROR
match bindings cannot shadow variants
};
const
C
:
u8
=
1
;
match
1
{
C
@
2
=>
{
//~ ERROR
cannot be named the same
C
@
2
=>
{
//~ ERROR
match bindings cannot shadow constant
println!
(
"{}"
,
C
);
}
_
=>
{}
...
...
src/test/compile-fail/issue-27815.rs
浏览文件 @
91b9dabd
...
...
@@ -14,7 +14,9 @@ fn main() {
let
u
=
A
{
x
:
1
};
//~ ERROR `A` does not name a structure
let
v
=
u32
{
x
:
1
};
//~ ERROR `u32` does not name a structure
match
()
{
A
{
x
:
1
}
=>
{}
//~ ERROR `A` does not name a struct
u32
{
x
:
1
}
=>
{}
//~ ERROR `u32` does not name a struct
A
{
x
:
1
}
=>
{}
//~ ERROR expected variant, struct or type alias, found module `A`
//~^ ERROR `A` does not name a struct or a struct variant
u32
{
x
:
1
}
=>
{}
//~ ERROR expected variant, struct or type alias, found builtin type `u32
//~^ ERROR `u32` does not name a struct or a struct variant
}
}
src/test/compile-fail/issue-28992-empty.rs
浏览文件 @
91b9dabd
...
...
@@ -21,6 +21,6 @@ impl S {
}
fn
main
()
{
if
let
C1
(
..
)
=
0
{}
//~ ERROR
`C1` does not name a tuple variant or a tuple struct
if
let
C1
(
..
)
=
0
{}
//~ ERROR
expected variant or struct, found constant `C1`
if
let
S
::
C2
(
..
)
=
0
{}
//~ ERROR `S::C2` does not name a tuple variant or a tuple struct
}
src/test/compile-fail/issue-5927.rs
浏览文件 @
91b9dabd
...
...
@@ -11,7 +11,7 @@
fn
main
()
{
let
z
=
match
3
{
x
(
1
)
=>
x
(
1
)
//~ ERROR unresolved
enum variant
x
(
1
)
=>
x
(
1
)
//~ ERROR unresolved
variant or struct `x`
//~^ ERROR unresolved name `x`
};
assert
!
(
z
==
3
);
...
...
src/test/compile-fail/method-resolvable-path-in-pattern.rs
浏览文件 @
91b9dabd
...
...
@@ -19,6 +19,6 @@ impl MyTrait for Foo {}
fn
main
()
{
match
0u32
{
<
Foo
as
MyTrait
>
::
trait_bar
=>
{}
//~^ ERROR
`trait_bar` is not an associated const
//~^ ERROR
expected associated constant, found method `trait_bar`
}
}
src/test/compile-fail/name-clash-nullary.rs
浏览文件 @
91b9dabd
...
...
@@ -8,10 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// error-pattern:cannot be named the same
use
std
::
option
::
*
;
fn
main
()
{
let
None
:
isize
=
42
;
let
None
:
isize
=
42
;
//~ ERROR let bindings cannot shadow variants
log
(
debug
,
None
);
//~^ ERROR unresolved name `debug`
//~| ERROR unresolved name `log`
}
src/test/compile-fail/pat-shadow-in-nested-binding.rs
浏览文件 @
91b9dabd
...
...
@@ -11,5 +11,5 @@
struct
foo
(
usize
);
fn
main
()
{
let
(
foo
,
_
)
=
(
2
,
3
);
//~ ERROR
`foo` cannot be named the same a
s
let
(
foo
,
_
)
=
(
2
,
3
);
//~ ERROR
let bindings cannot shadow struct
s
}
src/test/compile-fail/qualified-path-params.rs
浏览文件 @
91b9dabd
...
...
@@ -27,7 +27,7 @@ fn f<T>() {}
fn
main
()
{
match
10
{
<
S
as
Tr
>
::
A
::
f
::
<
u8
>
=>
{}
//~ ERROR
`f` is not an associated const
<
S
as
Tr
>
::
A
::
f
::
<
u8
>
=>
{}
//~ ERROR
associated items in match patterns must be constants
0
...
<
S
as
Tr
>
::
A
::
f
::
<
u8
>
=>
{}
//~ ERROR only char and numeric types are allowed in range
}
}
src/test/compile-fail/static-mut-not-pat.rs
浏览文件 @
91b9dabd
...
...
@@ -20,7 +20,7 @@ fn main() {
// instead of spitting out a custom error about some identifier collisions
// (we should allow shadowing)
match
4
{
a
=>
{}
//~ ERROR
static variables cannot be referenced in a pattern
a
=>
{}
//~ ERROR
match bindings cannot shadow statics
_
=>
{}
}
}
...
...
@@ -44,7 +44,7 @@ fn mutable_statics() {
match
(
Foo
{
bar
:
Some
(
Direction
::
North
),
baz
:
NewBool
(
true
)
})
{
Foo
{
bar
:
None
,
baz
:
NewBool
(
true
)
}
=>
(),
STATIC_MUT_FOO
=>
(),
//~^ ERROR
static variables cannot be referenced in a pattern
//~^ ERROR
match bindings cannot shadow statics
Foo
{
bar
:
Some
(
Direction
::
South
),
..
}
=>
(),
Foo
{
bar
:
Some
(
EAST
),
..
}
=>
(),
Foo
{
bar
:
Some
(
Direction
::
North
),
baz
:
NewBool
(
true
)
}
=>
(),
...
...
src/test/compile-fail/trait-impl-for-module.rs
浏览文件 @
91b9dabd
...
...
@@ -14,7 +14,7 @@ mod a {
trait
A
{
}
impl
A
for
a
{
//~ ERROR
type name `a` is undefined or not in scop
e
impl
A
for
a
{
//~ ERROR
expected type, found modul
e
}
fn
main
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录