提交 91b9dabd 编写于 作者: V Vadim Petrochenkov

resolve: Rewrite resolve_pattern

上级 ee00760a
......@@ -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(..) => "constant",
Def::AssociatedConst(..) => "associated constant",
Def::TyParam(..) => "type parameter",
Def::PrimTy(..) => "builtin type",
Def::Local(..) => "local variable",
......
......@@ -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 ...
}
此差异已折叠。
......@@ -23,5 +23,5 @@ impl Foo {
fn main() {
assert_eq!(1, bar1::Foo::ID);
//~^ERROR associated const `ID` is private
//~^ERROR associated constant `ID` is private
}
......@@ -12,6 +12,6 @@
fn main() {
let bar = 5;
//~^ ERROR cannot be named the same
//~^ ERROR let bindings cannot shadow structs
use foo::bar;
}
......@@ -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 constant
let c = 4; //~ ERROR let bindings cannot shadow constants
//~^ NOTE cannot be named the same as a constant
let d = 4; //~ ERROR let bindings cannot shadow constants
//~^ NOTE cannot be named the same as a constant
}
......@@ -29,9 +29,9 @@ fn main() {
// XEmpty1() => () // ERROR unresolved enum variant, struct or const `XEmpty1`
// }
match e1 {
Empty1(..) => () //~ ERROR unresolved enum variant, struct or const `Empty1`
Empty1(..) => () //~ ERROR unresolved variant or struct `Empty1`
}
match xe1 {
XEmpty1(..) => () //~ ERROR unresolved enum variant, struct or const `XEmpty1`
XEmpty1(..) => () //~ ERROR unresolved variant or struct `XEmpty1`
}
}
......@@ -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
}
......@@ -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`
}
......@@ -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`
=> ()
}
}
......@@ -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`
}
}
......@@ -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
};
}
......@@ -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
}
}
......@@ -12,10 +12,10 @@
extern crate issue_17718_const_privacy as other;
use a::B; //~ ERROR: const `B` is private
use a::B; //~ ERROR: constant `B` is private
use other::{
FOO,
BAR, //~ ERROR: const `BAR` is private
BAR, //~ ERROR: constant `BAR` is private
FOO2,
};
......
......@@ -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 => {}
_ => {}
}
......
......@@ -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`
_ => { },
}
}
......@@ -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() {
}
......@@ -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
};
}
......@@ -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);
}
_ => {}
......
......@@ -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
}
}
......@@ -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
}
......@@ -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);
......
......@@ -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`
}
}
......@@ -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`
}
......@@ -11,5 +11,5 @@
struct foo(usize);
fn main() {
let (foo, _) = (2, 3); //~ ERROR `foo` cannot be named the same as
let (foo, _) = (2, 3); //~ ERROR let bindings cannot shadow structs
}
......@@ -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
}
}
......@@ -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) } => (),
......
......@@ -14,7 +14,7 @@ mod a {
trait A {
}
impl A for a { //~ ERROR type name `a` is undefined or not in scope
impl A for a { //~ ERROR expected type, found module
}
fn main() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册