PageRenderTime 52ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/src/test/compile-fail/lint-stability.rs

http://github.com/eholk/rust
Rust | 452 lines | 341 code | 69 blank | 42 comment | 5 complexity | ff98acdf259fa9d20e21c2fee460126d MD5 | raw file
Possible License(s): AGPL-1.0, BSD-2-Clause, 0BSD, Apache-2.0, MIT, LGPL-2.0
  1. // Copyright 2013-2014 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. // aux-build:lint_stability.rs
  11. // aux-build:inherited_stability.rs
  12. // aux-build:stability_cfg1.rs
  13. // aux-build:stability_cfg2.rs
  14. #![allow(deprecated)]
  15. #![allow(dead_code)]
  16. #![feature(staged_api)]
  17. #![stable(feature = "rust1", since = "1.0.0")]
  18. #[macro_use]
  19. extern crate lint_stability;
  20. mod cross_crate {
  21. extern crate stability_cfg1;
  22. extern crate stability_cfg2; //~ ERROR use of unstable library feature
  23. use lint_stability::*;
  24. fn test() {
  25. type Foo = MethodTester;
  26. let foo = MethodTester;
  27. deprecated();
  28. foo.method_deprecated();
  29. Foo::method_deprecated(&foo);
  30. <Foo>::method_deprecated(&foo);
  31. foo.trait_deprecated();
  32. Trait::trait_deprecated(&foo);
  33. <Foo>::trait_deprecated(&foo);
  34. <Foo as Trait>::trait_deprecated(&foo);
  35. deprecated_text();
  36. foo.method_deprecated_text();
  37. Foo::method_deprecated_text(&foo);
  38. <Foo>::method_deprecated_text(&foo);
  39. foo.trait_deprecated_text();
  40. Trait::trait_deprecated_text(&foo);
  41. <Foo>::trait_deprecated_text(&foo);
  42. <Foo as Trait>::trait_deprecated_text(&foo);
  43. deprecated_unstable();
  44. //~^ ERROR use of unstable library feature
  45. Trait::trait_deprecated_unstable(&foo);
  46. //~^ ERROR use of unstable library feature
  47. <Foo as Trait>::trait_deprecated_unstable(&foo);
  48. //~^ ERROR use of unstable library feature
  49. deprecated_unstable_text();
  50. //~^ ERROR use of unstable library feature
  51. Trait::trait_deprecated_unstable_text(&foo);
  52. //~^ ERROR use of unstable library feature
  53. <Foo as Trait>::trait_deprecated_unstable_text(&foo);
  54. //~^ ERROR use of unstable library feature
  55. unstable(); //~ ERROR use of unstable library feature
  56. Trait::trait_unstable(&foo); //~ ERROR use of unstable library feature
  57. <Foo as Trait>::trait_unstable(&foo); //~ ERROR use of unstable library feature
  58. unstable_text();
  59. //~^ ERROR use of unstable library feature 'test_feature': text
  60. Trait::trait_unstable_text(&foo);
  61. //~^ ERROR use of unstable library feature 'test_feature': text
  62. <Foo as Trait>::trait_unstable_text(&foo);
  63. //~^ ERROR use of unstable library feature 'test_feature': text
  64. stable();
  65. foo.method_stable();
  66. Foo::method_stable(&foo);
  67. <Foo>::method_stable(&foo);
  68. foo.trait_stable();
  69. Trait::trait_stable(&foo);
  70. <Foo>::trait_stable(&foo);
  71. <Foo as Trait>::trait_stable(&foo);
  72. stable_text();
  73. foo.method_stable_text();
  74. Foo::method_stable_text(&foo);
  75. <Foo>::method_stable_text(&foo);
  76. foo.trait_stable_text();
  77. Trait::trait_stable_text(&foo);
  78. <Foo>::trait_stable_text(&foo);
  79. <Foo as Trait>::trait_stable_text(&foo);
  80. struct S1<T: TraitWithAssociatedTypes>(T::TypeUnstable);
  81. //~^ ERROR use of unstable library feature
  82. struct S2<T: TraitWithAssociatedTypes>(T::TypeDeprecated);
  83. let _ = DeprecatedStruct {
  84. i: 0
  85. };
  86. let _ = DeprecatedUnstableStruct {
  87. //~^ ERROR use of unstable library feature
  88. i: 0
  89. };
  90. let _ = UnstableStruct { i: 0 }; //~ ERROR use of unstable library feature
  91. let _ = StableStruct { i: 0 };
  92. let _ = DeprecatedUnitStruct;
  93. let _ = DeprecatedUnstableUnitStruct;
  94. //~^ ERROR use of unstable library feature
  95. let _ = UnstableUnitStruct; //~ ERROR use of unstable library feature
  96. let _ = StableUnitStruct;
  97. let _ = Enum::DeprecatedVariant;
  98. let _ = Enum::DeprecatedUnstableVariant;
  99. //~^ ERROR use of unstable library feature
  100. let _ = Enum::UnstableVariant; //~ ERROR use of unstable library feature
  101. let _ = Enum::StableVariant;
  102. let _ = DeprecatedTupleStruct (1);
  103. let _ = DeprecatedUnstableTupleStruct (1);
  104. //~^ ERROR use of unstable library feature
  105. let _ = UnstableTupleStruct (1); //~ ERROR use of unstable library feature
  106. let _ = StableTupleStruct (1);
  107. // At the moment, the lint checker only checks stability in
  108. // in the arguments of macros.
  109. // Eventually, we will want to lint the contents of the
  110. // macro in the module *defining* it. Also, stability levels
  111. // on macros themselves are not yet linted.
  112. macro_test_arg!(deprecated_text());
  113. macro_test_arg!(deprecated_unstable_text());
  114. //~^ ERROR use of unstable library feature
  115. macro_test_arg!(macro_test_arg!(deprecated_text()));
  116. }
  117. fn test_method_param<Foo: Trait>(foo: Foo) {
  118. foo.trait_deprecated();
  119. Trait::trait_deprecated(&foo);
  120. <Foo>::trait_deprecated(&foo);
  121. <Foo as Trait>::trait_deprecated(&foo);
  122. foo.trait_deprecated_text();
  123. Trait::trait_deprecated_text(&foo);
  124. <Foo>::trait_deprecated_text(&foo);
  125. <Foo as Trait>::trait_deprecated_text(&foo);
  126. Trait::trait_deprecated_unstable(&foo);
  127. //~^ ERROR use of unstable library feature
  128. <Foo as Trait>::trait_deprecated_unstable(&foo);
  129. //~^ ERROR use of unstable library feature
  130. Trait::trait_deprecated_unstable_text(&foo);
  131. //~^ ERROR use of unstable library feature
  132. <Foo as Trait>::trait_deprecated_unstable_text(&foo);
  133. //~^ ERROR use of unstable library feature
  134. Trait::trait_unstable(&foo); //~ ERROR use of unstable library feature
  135. <Foo as Trait>::trait_unstable(&foo); //~ ERROR use of unstable library feature
  136. Trait::trait_unstable_text(&foo);
  137. //~^ ERROR use of unstable library feature 'test_feature': text
  138. <Foo as Trait>::trait_unstable_text(&foo);
  139. //~^ ERROR use of unstable library feature 'test_feature': text
  140. foo.trait_stable();
  141. Trait::trait_stable(&foo);
  142. <Foo>::trait_stable(&foo);
  143. <Foo as Trait>::trait_stable(&foo);
  144. }
  145. fn test_method_object(foo: &Trait) {
  146. foo.trait_deprecated();
  147. foo.trait_deprecated_text();
  148. foo.trait_stable();
  149. }
  150. struct S;
  151. impl UnstableTrait for S { } //~ ERROR use of unstable library feature
  152. impl DeprecatedTrait for S {}
  153. trait LocalTrait : UnstableTrait { } //~ ERROR use of unstable library feature
  154. trait LocalTrait2 : DeprecatedTrait { }
  155. impl Trait for S {
  156. fn trait_stable(&self) {}
  157. fn trait_unstable(&self) {} //~ ERROR use of unstable library feature
  158. }
  159. }
  160. mod inheritance {
  161. extern crate inherited_stability; //~ ERROR use of unstable library feature
  162. use self::inherited_stability::*; //~ ERROR use of unstable library feature
  163. fn test_inheritance() {
  164. unstable(); //~ ERROR use of unstable library feature
  165. stable();
  166. stable_mod::unstable(); //~ ERROR use of unstable library feature
  167. stable_mod::stable();
  168. unstable_mod::deprecated();
  169. unstable_mod::unstable(); //~ ERROR use of unstable library feature
  170. let _ = Unstable::UnstableVariant; //~ ERROR use of unstable library feature
  171. let _ = Unstable::StableVariant;
  172. let x: usize = 0;
  173. x.stable();
  174. }
  175. }
  176. mod this_crate {
  177. #[unstable(feature = "test_feature", issue = "0")]
  178. #[rustc_deprecated(since = "1.0.0", reason = "text")]
  179. pub fn deprecated() {}
  180. #[unstable(feature = "test_feature", issue = "0")]
  181. #[rustc_deprecated(since = "1.0.0", reason = "text")]
  182. pub fn deprecated_text() {}
  183. #[unstable(feature = "test_feature", issue = "0")]
  184. pub fn unstable() {}
  185. #[unstable(feature = "test_feature", reason = "text", issue = "0")]
  186. pub fn unstable_text() {}
  187. #[stable(feature = "rust1", since = "1.0.0")]
  188. pub fn stable() {}
  189. #[stable(feature = "rust1", since = "1.0.0")]
  190. pub fn stable_text() {}
  191. #[stable(feature = "rust1", since = "1.0.0")]
  192. pub struct MethodTester;
  193. impl MethodTester {
  194. #[unstable(feature = "test_feature", issue = "0")]
  195. #[rustc_deprecated(since = "1.0.0", reason = "text")]
  196. pub fn method_deprecated(&self) {}
  197. #[unstable(feature = "test_feature", issue = "0")]
  198. #[rustc_deprecated(since = "1.0.0", reason = "text")]
  199. pub fn method_deprecated_text(&self) {}
  200. #[unstable(feature = "test_feature", issue = "0")]
  201. pub fn method_unstable(&self) {}
  202. #[unstable(feature = "test_feature", reason = "text", issue = "0")]
  203. pub fn method_unstable_text(&self) {}
  204. #[stable(feature = "rust1", since = "1.0.0")]
  205. pub fn method_stable(&self) {}
  206. #[stable(feature = "rust1", since = "1.0.0")]
  207. pub fn method_stable_text(&self) {}
  208. }
  209. pub trait Trait {
  210. #[unstable(feature = "test_feature", issue = "0")]
  211. #[rustc_deprecated(since = "1.0.0", reason = "text")]
  212. fn trait_deprecated(&self) {}
  213. #[unstable(feature = "test_feature", issue = "0")]
  214. #[rustc_deprecated(since = "1.0.0", reason = "text")]
  215. fn trait_deprecated_text(&self) {}
  216. #[unstable(feature = "test_feature", issue = "0")]
  217. fn trait_unstable(&self) {}
  218. #[unstable(feature = "test_feature", reason = "text", issue = "0")]
  219. fn trait_unstable_text(&self) {}
  220. #[stable(feature = "rust1", since = "1.0.0")]
  221. fn trait_stable(&self) {}
  222. #[stable(feature = "rust1", since = "1.0.0")]
  223. fn trait_stable_text(&self) {}
  224. }
  225. impl Trait for MethodTester {}
  226. #[unstable(feature = "test_feature", issue = "0")]
  227. #[rustc_deprecated(since = "1.0.0", reason = "text")]
  228. pub struct DeprecatedStruct {
  229. #[stable(feature = "test_feature", since = "1.0.0")] i: isize
  230. }
  231. #[unstable(feature = "test_feature", issue = "0")]
  232. pub struct UnstableStruct {
  233. #[stable(feature = "test_feature", since = "1.0.0")] i: isize
  234. }
  235. #[stable(feature = "rust1", since = "1.0.0")]
  236. pub struct StableStruct {
  237. #[stable(feature = "test_feature", since = "1.0.0")] i: isize
  238. }
  239. #[unstable(feature = "test_feature", issue = "0")]
  240. #[rustc_deprecated(since = "1.0.0", reason = "text")]
  241. pub struct DeprecatedUnitStruct;
  242. #[unstable(feature = "test_feature", issue = "0")]
  243. pub struct UnstableUnitStruct;
  244. #[stable(feature = "rust1", since = "1.0.0")]
  245. pub struct StableUnitStruct;
  246. pub enum Enum {
  247. #[unstable(feature = "test_feature", issue = "0")]
  248. #[rustc_deprecated(since = "1.0.0", reason = "text")]
  249. DeprecatedVariant,
  250. #[unstable(feature = "test_feature", issue = "0")]
  251. UnstableVariant,
  252. #[stable(feature = "rust1", since = "1.0.0")]
  253. StableVariant,
  254. }
  255. #[unstable(feature = "test_feature", issue = "0")]
  256. #[rustc_deprecated(since = "1.0.0", reason = "text")]
  257. pub struct DeprecatedTupleStruct(isize);
  258. #[unstable(feature = "test_feature", issue = "0")]
  259. pub struct UnstableTupleStruct(isize);
  260. #[stable(feature = "rust1", since = "1.0.0")]
  261. pub struct StableTupleStruct(isize);
  262. fn test() {
  263. // Only the deprecated cases of the following should generate
  264. // errors, because other stability attributes now have meaning
  265. // only *across* crates, not within a single crate.
  266. type Foo = MethodTester;
  267. let foo = MethodTester;
  268. deprecated();
  269. foo.method_deprecated();
  270. Foo::method_deprecated(&foo);
  271. <Foo>::method_deprecated(&foo);
  272. foo.trait_deprecated();
  273. Trait::trait_deprecated(&foo);
  274. <Foo>::trait_deprecated(&foo);
  275. <Foo as Trait>::trait_deprecated(&foo);
  276. deprecated_text();
  277. foo.method_deprecated_text();
  278. Foo::method_deprecated_text(&foo);
  279. <Foo>::method_deprecated_text(&foo);
  280. foo.trait_deprecated_text();
  281. Trait::trait_deprecated_text(&foo);
  282. <Foo>::trait_deprecated_text(&foo);
  283. <Foo as Trait>::trait_deprecated_text(&foo);
  284. unstable();
  285. foo.method_unstable();
  286. Foo::method_unstable(&foo);
  287. <Foo>::method_unstable(&foo);
  288. foo.trait_unstable();
  289. Trait::trait_unstable(&foo);
  290. <Foo>::trait_unstable(&foo);
  291. <Foo as Trait>::trait_unstable(&foo);
  292. unstable_text();
  293. foo.method_unstable_text();
  294. Foo::method_unstable_text(&foo);
  295. <Foo>::method_unstable_text(&foo);
  296. foo.trait_unstable_text();
  297. Trait::trait_unstable_text(&foo);
  298. <Foo>::trait_unstable_text(&foo);
  299. <Foo as Trait>::trait_unstable_text(&foo);
  300. stable();
  301. foo.method_stable();
  302. Foo::method_stable(&foo);
  303. <Foo>::method_stable(&foo);
  304. foo.trait_stable();
  305. Trait::trait_stable(&foo);
  306. <Foo>::trait_stable(&foo);
  307. <Foo as Trait>::trait_stable(&foo);
  308. stable_text();
  309. foo.method_stable_text();
  310. Foo::method_stable_text(&foo);
  311. <Foo>::method_stable_text(&foo);
  312. foo.trait_stable_text();
  313. Trait::trait_stable_text(&foo);
  314. <Foo>::trait_stable_text(&foo);
  315. <Foo as Trait>::trait_stable_text(&foo);
  316. let _ = DeprecatedStruct {
  317. i: 0
  318. };
  319. let _ = UnstableStruct { i: 0 };
  320. let _ = StableStruct { i: 0 };
  321. let _ = DeprecatedUnitStruct;
  322. let _ = UnstableUnitStruct;
  323. let _ = StableUnitStruct;
  324. let _ = Enum::DeprecatedVariant;
  325. let _ = Enum::UnstableVariant;
  326. let _ = Enum::StableVariant;
  327. let _ = DeprecatedTupleStruct (1);
  328. let _ = UnstableTupleStruct (1);
  329. let _ = StableTupleStruct (1);
  330. }
  331. fn test_method_param<Foo: Trait>(foo: Foo) {
  332. foo.trait_deprecated();
  333. Trait::trait_deprecated(&foo);
  334. <Foo>::trait_deprecated(&foo);
  335. <Foo as Trait>::trait_deprecated(&foo);
  336. foo.trait_deprecated_text();
  337. Trait::trait_deprecated_text(&foo);
  338. <Foo>::trait_deprecated_text(&foo);
  339. <Foo as Trait>::trait_deprecated_text(&foo);
  340. foo.trait_unstable();
  341. Trait::trait_unstable(&foo);
  342. <Foo>::trait_unstable(&foo);
  343. <Foo as Trait>::trait_unstable(&foo);
  344. foo.trait_unstable_text();
  345. Trait::trait_unstable_text(&foo);
  346. <Foo>::trait_unstable_text(&foo);
  347. <Foo as Trait>::trait_unstable_text(&foo);
  348. foo.trait_stable();
  349. Trait::trait_stable(&foo);
  350. <Foo>::trait_stable(&foo);
  351. <Foo as Trait>::trait_stable(&foo);
  352. }
  353. fn test_method_object(foo: &Trait) {
  354. foo.trait_deprecated();
  355. foo.trait_deprecated_text();
  356. foo.trait_unstable();
  357. foo.trait_unstable_text();
  358. foo.trait_stable();
  359. }
  360. #[unstable(feature = "test_feature", issue = "0")]
  361. #[rustc_deprecated(since = "1.0.0", reason = "text")]
  362. fn test_fn_body() {
  363. fn fn_in_body() {}
  364. fn_in_body();
  365. }
  366. impl MethodTester {
  367. #[unstable(feature = "test_feature", issue = "0")]
  368. #[rustc_deprecated(since = "1.0.0", reason = "text")]
  369. fn test_method_body(&self) {
  370. fn fn_in_body() {}
  371. fn_in_body();
  372. }
  373. }
  374. #[unstable(feature = "test_feature", issue = "0")]
  375. #[rustc_deprecated(since = "1.0.0", reason = "text")]
  376. pub trait DeprecatedTrait {
  377. fn dummy(&self) { }
  378. }
  379. struct S;
  380. impl DeprecatedTrait for S { }
  381. trait LocalTrait : DeprecatedTrait { }
  382. }
  383. fn main() {}