Skip to content

Commit 34737e3

Browse files
committed
Add more tests for unnameable reachable items
1 parent 767a447 commit 34737e3

File tree

4 files changed

+168
-28
lines changed

4 files changed

+168
-28
lines changed
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use inner_private_module::*;
12+
13+
mod inner_private_module {
14+
pub struct Unnameable1;
15+
pub struct Unnameable2;
16+
#[derive(Clone, Copy)]
17+
pub struct Unnameable3;
18+
pub struct Unnameable4;
19+
pub struct Unnameable5;
20+
pub struct Unnameable6;
21+
pub struct Unnameable7;
22+
#[derive(Default)]
23+
pub struct Unnameable8;
24+
pub enum UnnameableEnum {
25+
NameableVariant
26+
}
27+
pub trait UnnameableTrait {
28+
type Alias: Default;
29+
}
30+
31+
impl Unnameable1 {
32+
pub fn method_of_unnameable_type1(&self) -> &'static str {
33+
"Hello1"
34+
}
35+
}
36+
impl Unnameable2 {
37+
pub fn method_of_unnameable_type2(&self) -> &'static str {
38+
"Hello2"
39+
}
40+
}
41+
impl Unnameable3 {
42+
pub fn method_of_unnameable_type3(&self) -> &'static str {
43+
"Hello3"
44+
}
45+
}
46+
impl Unnameable4 {
47+
pub fn method_of_unnameable_type4(&self) -> &'static str {
48+
"Hello4"
49+
}
50+
}
51+
impl Unnameable5 {
52+
pub fn method_of_unnameable_type5(&self) -> &'static str {
53+
"Hello5"
54+
}
55+
}
56+
impl Unnameable6 {
57+
pub fn method_of_unnameable_type6(&self) -> &'static str {
58+
"Hello6"
59+
}
60+
}
61+
impl Unnameable7 {
62+
pub fn method_of_unnameable_type7(&self) -> &'static str {
63+
"Hello7"
64+
}
65+
}
66+
impl Unnameable8 {
67+
pub fn method_of_unnameable_type8(&self) -> &'static str {
68+
"Hello8"
69+
}
70+
}
71+
impl UnnameableEnum {
72+
pub fn method_of_unnameable_enum(&self) -> &'static str {
73+
"HelloEnum"
74+
}
75+
}
76+
}
77+
78+
pub fn function_returning_unnameable_type() -> Unnameable1 {
79+
Unnameable1
80+
}
81+
82+
pub const CONSTANT_OF_UNNAMEABLE_TYPE: Unnameable2 =
83+
Unnameable2;
84+
85+
pub fn function_accepting_unnameable_type(_: Option<Unnameable3>) {}
86+
87+
pub type AliasOfUnnameableType = Unnameable4;
88+
89+
impl Unnameable1 {
90+
pub fn inherent_method_returning_unnameable_type(&self) -> Unnameable5 {
91+
Unnameable5
92+
}
93+
}
94+
95+
pub trait Tr {
96+
fn trait_method_returning_unnameable_type(&self) -> Unnameable6 {
97+
Unnameable6
98+
}
99+
}
100+
impl Tr for Unnameable1 {}
101+
102+
pub use inner_private_module::UnnameableEnum::NameableVariant;
103+
104+
pub struct Struct {
105+
pub field_of_unnameable_type: Unnameable7
106+
}
107+
108+
pub static STATIC: Struct = Struct { field_of_unnameable_type: Unnameable7 } ;
109+
110+
impl UnnameableTrait for AliasOfUnnameableType {
111+
type Alias = Unnameable8;
112+
}
113+
114+
pub fn generic_function<T: UnnameableTrait>() -> T::Alias {
115+
Default::default()
116+
}

src/test/run-pass/issue-16734.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:reachable-unnameable-items.rs
12+
13+
#![feature(braced_empty_structs)]
14+
#![feature(recover)]
15+
16+
extern crate reachable_unnameable_items;
17+
use reachable_unnameable_items::*;
18+
19+
fn main() {
20+
let res1 = function_returning_unnameable_type().method_of_unnameable_type1();
21+
let res2 = CONSTANT_OF_UNNAMEABLE_TYPE.method_of_unnameable_type2();
22+
let res4 = AliasOfUnnameableType{}.method_of_unnameable_type4();
23+
let res5 = function_returning_unnameable_type().inherent_method_returning_unnameable_type().
24+
method_of_unnameable_type5();
25+
let res6 = function_returning_unnameable_type().trait_method_returning_unnameable_type().
26+
method_of_unnameable_type6();
27+
let res7 = STATIC.field_of_unnameable_type.method_of_unnameable_type7();
28+
let res8 = generic_function::<AliasOfUnnameableType>().method_of_unnameable_type8();
29+
let res_enum = NameableVariant.method_of_unnameable_enum();
30+
assert_eq!(res1, "Hello1");
31+
assert_eq!(res2, "Hello2");
32+
assert_eq!(res4, "Hello4");
33+
assert_eq!(res5, "Hello5");
34+
assert_eq!(res6, "Hello6");
35+
assert_eq!(res7, "Hello7");
36+
assert_eq!(res8, "Hello8");
37+
assert_eq!(res_enum, "HelloEnum");
38+
39+
let none = None;
40+
function_accepting_unnameable_type(none);
41+
let _guard = std::panic::recover(|| none.unwrap().method_of_unnameable_type3());
42+
}

src/test/auxiliary/issue-16734.rs renamed to src/test/run-pass/reachable-unnameable-type-alias.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
mod inner_private_module {
12-
pub struct Unnameable;
11+
#![feature(staged_api)]
12+
#![stable(feature = "a", since = "b")]
1313

14-
impl Unnameable {
15-
pub fn method_of_unnameable_type(&self) -> &'static str {
16-
"Hello!"
17-
}
18-
}
14+
mod inner_private_module {
15+
// UnnameableTypeAlias isn't marked as reachable, so no stability annotation is required here
16+
pub type UnnameableTypeAlias = u8;
1917
}
2018

21-
pub fn public_function_returning_unnameable_type() -> inner_private_module::Unnameable {
22-
inner_private_module::Unnameable
19+
#[stable(feature = "a", since = "b")]
20+
pub fn f() -> inner_private_module::UnnameableTypeAlias {
21+
0
2322
}
23+
24+
fn main() {}

0 commit comments

Comments
 (0)