Preserve struct/variant kinds in metadata

Add tests for use of empty structs in cross-crate scenarios
This commit is contained in:
Vadim Petrochenkov 2016-01-14 14:26:50 +03:00
parent 1f4e317e45
commit ccb4b35897
12 changed files with 229 additions and 50 deletions

View file

@ -0,0 +1,19 @@
// 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.
#![feature(braced_empty_structs)]
pub struct XEmpty1 {}
pub struct XEmpty2;
pub enum XE {
XEmpty3 {},
XEmpty4,
}

View file

@ -10,17 +10,28 @@
// Can't use empty braced struct as constant or constructor function
// aux-build:empty-struct.rs
#![feature(braced_empty_structs)]
extern crate empty_struct;
use empty_struct::*;
struct Empty1 {}
enum E {
Empty2 {}
Empty3 {}
}
fn main() {
let e1 = Empty1; //~ ERROR `Empty1` is the name of a struct or struct variant
let e1 = Empty1(); //~ ERROR `Empty1` is the name of a struct or struct variant
let e2 = E::Empty2; //~ ERROR `E::Empty2` is the name of a struct or struct variant
let e2 = E::Empty2(); //~ ERROR `E::Empty2` is the name of a struct or struct variant
let e3 = E::Empty3; //~ ERROR `E::Empty3` is the name of a struct or struct variant
let e3 = E::Empty3(); //~ ERROR `E::Empty3` is the name of a struct or struct variant
// FIXME: non-local struct kind should be known early (e.g. kept in `DefStruct`)
// let xe1 = XEmpty1; // ERROR `XEmpty1` is the name of a struct or struct variant
let xe1 = XEmpty1(); //~ ERROR expected function, found `empty_struct::XEmpty1`
let xe3 = XE::Empty3; //~ ERROR no associated item named `Empty3` found for type
let xe3 = XE::Empty3(); //~ ERROR no associated item named `Empty3` found for type
}

View file

@ -10,22 +10,35 @@
// Can't use empty braced struct as constant pattern
// aux-build:empty-struct.rs
#![feature(braced_empty_structs)]
extern crate empty_struct;
use empty_struct::*;
struct Empty1 {}
enum E {
Empty2 {}
Empty3 {}
}
fn main() {
let e1 = Empty1 {};
let e2 = E::Empty2 {};
let e3 = E::Empty3 {};
let xe1 = XEmpty1 {};
let xe3 = XE::XEmpty3 {};
match e1 {
Empty1 => () // Not an error, `Empty1` is interpreted as a new binding
}
match e2 {
E::Empty2 => () //~ ERROR `E::Empty2` does not name a tuple variant or a tuple struct
match e3 {
E::Empty3 => () //~ ERROR `E::Empty3` does not name a tuple variant or a tuple struct
}
match xe1 {
XEmpty1 => () // Not an error, `XEmpty1` is interpreted as a new binding
}
match xe3 {
XE::XEmpty3 => () //~ ERROR no associated item named `XEmpty3` found for type
}
}

View file

@ -10,18 +10,30 @@
// Can't use empty braced struct as enum pattern
// aux-build:empty-struct.rs
#![feature(braced_empty_structs)]
extern crate empty_struct;
use empty_struct::*;
struct Empty1 {}
fn main() {
let e1 = Empty1 {};
let xe1 = XEmpty1 {};
// Rejected by parser as yet
// match e1 {
// Empty1() => () // ERROR unresolved enum variant, struct or const `Empty1`
// }
// match xe1 {
// XEmpty1() => () // ERROR unresolved enum variant, struct or const `XEmpty1`
// }
match e1 {
Empty1(..) => () //~ ERROR unresolved enum variant, struct or const `Empty1`
}
match xe1 {
XEmpty1(..) => () //~ ERROR `XEmpty1` does not name a tuple variant or a tuple struct
}
}

View file

@ -10,20 +10,32 @@
// Can't use empty braced struct as enum pattern
// aux-build:empty-struct.rs
#![feature(braced_empty_structs)]
extern crate empty_struct;
use empty_struct::*;
enum E {
Empty2 {}
Empty3 {}
}
fn main() {
let e2 = E::Empty2 {};
let e3 = E::Empty3 {};
let xe3 = XE::XEmpty3 {};
// Rejected by parser as yet
// match e2 {
// E::Empty2() => () // ERROR `E::Empty2` does not name a tuple variant or a tuple struct
// match e3 {
// E::Empty3() => () // ERROR `E::Empty3` does not name a tuple variant or a tuple struct
// }
match e2 {
E::Empty2(..) => () //~ ERROR `E::Empty2` does not name a tuple variant or a tuple struct
// match xe3 {
// E::Empty3() => () // ERROR `XE::XEmpty3` does not name a tuple variant or a tuple struct
// }
match e3 {
E::Empty3(..) => () //~ ERROR `E::Empty3` does not name a tuple variant or a tuple struct
}
match xe3 {
XE::XEmpty3(..) => () //~ ERROR no associated item named `XEmpty3` found for type
}
}

View file

@ -10,15 +10,22 @@
// Can't use unit struct as constructor function
// aux-build:empty-struct.rs
#![feature(braced_empty_structs)]
struct Empty1;
extern crate empty_struct;
use empty_struct::*;
struct Empty2;
enum E {
Empty2
Empty4
}
fn main() {
let e1 = Empty1(); //~ ERROR expected function, found `Empty1`
let e2 = E::Empty2(); //~ ERROR expected function, found `E`
let e2 = Empty2(); //~ ERROR expected function, found `Empty2`
let e4 = E::Empty4(); //~ ERROR expected function, found `E`
let xe2 = XEmpty2(); //~ ERROR expected function, found `empty_struct::XEmpty2`
let xe4 = XE::XEmpty4(); //~ ERROR expected function, found `empty_struct::XE`
}

View file

@ -10,36 +10,59 @@
// Can't use unit struct as enum pattern
// aux-build:empty-struct.rs
#![feature(rustc_attrs)]
// remove prior feature after warning cycle and promoting warnings to errors
#![feature(braced_empty_structs)]
struct Empty1;
extern crate empty_struct;
use empty_struct::*;
struct Empty2;
enum E {
Empty2
Empty4
}
// remove attribute after warning cycle and promoting warnings to errors
#[rustc_error]
fn main() { //~ ERROR: compilation successful
let e1 = Empty1;
let e2 = E::Empty2;
let e2 = Empty2;
let e4 = E::Empty4;
let xe2 = XEmpty2;
let xe4 = XE::XEmpty4;
// Rejected by parser as yet
// match e1 {
// Empty1() => () // ERROR `Empty1` does not name a tuple variant or a tuple struct
// match e2 {
// Empty2() => () // ERROR `Empty2` does not name a tuple variant or a tuple struct
// }
match e1 {
Empty1(..) => () //~ WARN `Empty1` does not name a tuple variant or a tuple struct
// match xe2 {
// XEmpty2() => () // ERROR `XEmpty2` does not name a tuple variant or a tuple struct
// }
match e2 {
Empty2(..) => () //~ WARN `Empty2` does not name a tuple variant or a tuple struct
//~^ WARN hard error
}
match xe2 {
XEmpty2(..) => () //~ WARN `XEmpty2` does not name a tuple variant or a tuple struct
//~^ WARN hard error
}
// Rejected by parser as yet
// match e2 {
// E::Empty2() => () // ERROR `E::Empty2` does not name a tuple variant or a tuple struct
// match e4 {
// E::Empty4() => () // ERROR `E::Empty4` does not name a tuple variant or a tuple struct
// }
match e2 {
E::Empty2(..) => () //~ WARN `E::Empty2` does not name a tuple variant or a tuple struct
// match xe4 {
// XE::XEmpty4() => (), // ERROR `XE::XEmpty4` does not name a tuple variant or a tuple
// _ => {},
// }
match e4 {
E::Empty4(..) => () //~ WARN `E::Empty4` does not name a tuple variant or a tuple struct
//~^ WARN hard error
}
match xe4 {
XE::XEmpty4(..) => (), //~ WARN `XE::XEmpty4` does not name a tuple variant or a tuple
//~^ WARN hard error
_ => {},
}
}

View file

@ -11,8 +11,13 @@
// Empty struct defined with braces add names into type namespace
// Empty struct defined without braces add names into both type and value namespaces
// aux-build:empty-struct.rs
#![feature(braced_empty_structs)]
extern crate empty_struct;
use empty_struct::*;
struct Empty1 {}
struct Empty2;
struct Empty3 {}
@ -23,7 +28,7 @@ enum E {
Empty5,
}
fn main() {
fn local() {
let e1: Empty1 = Empty1 {};
let e2: Empty2 = Empty2 {};
let e2: Empty2 = Empty2;
@ -84,3 +89,59 @@ fn main() {
let e22: Empty2 = Empty2 { ..e2 };
let e33: Empty3 = Empty3 { ..e3 };
}
fn xcrate() {
let e1: XEmpty1 = XEmpty1 {};
let e2: XEmpty2 = XEmpty2 {};
let e2: XEmpty2 = XEmpty2;
let e3: XE = XE::XEmpty3 {};
// FIXME: Commented out tests are waiting for PR 30882 (fixes for variant namespaces)
// let e4: XE = XE::XEmpty4 {};
let e4: XE = XE::XEmpty4;
match e1 {
XEmpty1 {} => {}
}
match e2 {
XEmpty2 {} => {}
}
match e3 {
XE::XEmpty3 {} => {}
_ => {}
}
// match e4 {
// XE::XEmpty4 {} => {}
// _ => {}
// }
match e1 {
XEmpty1 { .. } => {}
}
match e2 {
XEmpty2 { .. } => {}
}
match e3 {
XE::XEmpty3 { .. } => {}
_ => {}
}
// match e4 {
// XE::XEmpty4 { .. } => {}
// _ => {}
// }
match e2 {
XEmpty2 => {}
}
// match e4 {
// XE::XEmpty4 => {}
// _ => {}
// }
let e11: XEmpty1 = XEmpty1 { ..e1 };
let e22: XEmpty2 = XEmpty2 { ..e2 };
}
fn main() {
local();
xcrate();
}