From 62792f09f20221add2484608fc3071259067b79a Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Thu, 13 Mar 2014 18:53:14 +1100 Subject: [PATCH 1/2] lint: add lint for use of a `~[T]`. This is useless at the moment (since pretty much every crate uses `~[]`), but should help avoid regressions once completely removed from a crate. --- src/compiletest/compiletest.rs | 1 + src/libarena/lib.rs | 1 + src/libcollections/lib.rs | 1 + src/libextra/lib.rs | 1 + src/libflate/lib.rs | 1 + src/libgetopts/lib.rs | 1 + src/libglob/lib.rs | 1 + src/libgreen/lib.rs | 1 + src/libnative/lib.rs | 1 + src/libnum/lib.rs | 1 + src/librand/lib.rs | 1 + src/librustc/lib.rs | 1 + src/librustc/middle/lint.rs | 23 ++++++++++++++++++- src/librustdoc/lib.rs | 1 + src/librustdoc/test.rs | 3 +++ src/librustuv/lib.rs | 1 + src/libsemver/lib.rs | 2 ++ src/libserialize/lib.rs | 1 + src/libstd/lib.rs | 1 + src/libsync/lib.rs | 2 ++ src/libsyntax/lib.rs | 1 + src/libterm/lib.rs | 1 + src/libtest/lib.rs | 1 + src/libtime/lib.rs | 1 + src/libuuid/lib.rs | 2 ++ src/test/compile-fail/issue-2150.rs | 1 + src/test/compile-fail/issue-8727.rs | 1 + .../lint-deprecated-owned-vector.rs | 17 ++++++++++++++ src/test/compile-fail/lint-heap-memory.rs | 1 + src/test/compile-fail/lint-unused-imports.rs | 1 + .../compile-fail/lint-unused-mut-variables.rs | 1 + src/test/compile-fail/lint-unused-unsafe.rs | 1 + src/test/run-pass/ifmt.rs | 1 + 33 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 src/test/compile-fail/lint-deprecated-owned-vector.rs diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 5f8c63d60715..35e1c242fe28 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -12,6 +12,7 @@ #[allow(non_camel_case_types)]; #[deny(warnings)]; +#[allow(deprecated_owned_vector)]; extern crate test; extern crate getopts; diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index 2ccb8e9c4c25..895c498aa87d 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -21,6 +21,7 @@ #[license = "MIT/ASL2"]; #[allow(missing_doc)]; #[feature(managed_boxes)]; +#[allow(deprecated_owned_vector)]; extern crate collections; diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index a087180d9a50..b5199913f026 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -22,6 +22,7 @@ // NOTE remove the following two attributes after the next snapshot. #[allow(unrecognized_lint)]; #[allow(default_type_param_usage)]; +#[allow(deprecated_owned_vector)]; extern crate rand; diff --git a/src/libextra/lib.rs b/src/libextra/lib.rs index 32de7bf08667..4bb6b0050b89 100644 --- a/src/libextra/lib.rs +++ b/src/libextra/lib.rs @@ -31,6 +31,7 @@ Rust extras are part of the standard Rust distribution. #[feature(macro_rules, globs, managed_boxes, asm, default_type_params)]; +#[allow(deprecated_owned_vector)]; #[deny(non_camel_case_types)]; #[deny(missing_doc)]; diff --git a/src/libflate/lib.rs b/src/libflate/lib.rs index 6bf5092bb2d5..e0da51a75af7 100644 --- a/src/libflate/lib.rs +++ b/src/libflate/lib.rs @@ -90,6 +90,7 @@ pub fn inflate_bytes_zlib(bytes: &[u8]) -> CVec { #[cfg(test)] mod tests { + #[allow(deprecated_owned_vector)]; extern crate rand; use super::{inflate_bytes, deflate_bytes}; diff --git a/src/libgetopts/lib.rs b/src/libgetopts/lib.rs index b1b8351b040a..007557c1d582 100644 --- a/src/libgetopts/lib.rs +++ b/src/libgetopts/lib.rs @@ -81,6 +81,7 @@ #[crate_type = "dylib"]; #[license = "MIT/ASL2"]; #[allow(missing_doc)]; +#[allow(deprecated_owned_vector)]; #[feature(globs)]; diff --git a/src/libglob/lib.rs b/src/libglob/lib.rs index a33d041ab20c..126eebaa1d3a 100644 --- a/src/libglob/lib.rs +++ b/src/libglob/lib.rs @@ -27,6 +27,7 @@ #[crate_type = "rlib"]; #[crate_type = "dylib"]; #[license = "MIT/ASL2"]; +#[allow(deprecated_owned_vector)]; use std::cell::Cell; use std::{cmp, os, path}; diff --git a/src/libgreen/lib.rs b/src/libgreen/lib.rs index 22dd4c74936b..3cef60896b9a 100644 --- a/src/libgreen/lib.rs +++ b/src/libgreen/lib.rs @@ -174,6 +174,7 @@ // NB this does *not* include globs, please keep it that way. #[feature(macro_rules)]; #[allow(visible_private_types)]; +#[allow(deprecated_owned_vector)]; extern crate rand; diff --git a/src/libnative/lib.rs b/src/libnative/lib.rs index 4b6942a10831..b7a38dec1acb 100644 --- a/src/libnative/lib.rs +++ b/src/libnative/lib.rs @@ -50,6 +50,7 @@ html_root_url = "http://static.rust-lang.org/doc/master")]; #[deny(unused_result, unused_must_use)]; #[allow(non_camel_case_types)]; +#[allow(deprecated_owned_vector)]; // NB this crate explicitly does *not* allow glob imports, please seriously // consider whether they're needed before adding that feature here (the diff --git a/src/libnum/lib.rs b/src/libnum/lib.rs index 8ff042ba3621..1cbb7a279a50 100644 --- a/src/libnum/lib.rs +++ b/src/libnum/lib.rs @@ -14,6 +14,7 @@ #[crate_type = "rlib"]; #[crate_type = "dylib"]; #[license = "MIT/ASL2"]; +#[allow(deprecated_owned_vector)]; extern crate rand; diff --git a/src/librand/lib.rs b/src/librand/lib.rs index 87a18497b8af..70e5bb928161 100644 --- a/src/librand/lib.rs +++ b/src/librand/lib.rs @@ -71,6 +71,7 @@ println!("{:?}", tuple_ptr) html_root_url = "http://static.rust-lang.org/doc/master")]; #[feature(macro_rules, managed_boxes)]; +#[allow(deprecated_owned_vector)]; use std::cast; use std::kinds::marker; diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index af0acee07fd2..ebc85c8c5dfe 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -28,6 +28,7 @@ This API is completely unstable and subject to change. html_root_url = "http://static.rust-lang.org/doc/master")]; #[allow(deprecated)]; +#[allow(deprecated_owned_vector)]; #[feature(macro_rules, globs, struct_variant, managed_boxes)]; #[feature(quote, default_type_params)]; diff --git a/src/librustc/middle/lint.rs b/src/librustc/middle/lint.rs index 31d705dc6aa9..ae2600533559 100644 --- a/src/librustc/middle/lint.rs +++ b/src/librustc/middle/lint.rs @@ -113,6 +113,8 @@ pub enum Lint { UnusedMustUse, UnusedResult, + DeprecatedOwnedVector, + Warnings, } @@ -397,7 +399,14 @@ static lint_table: &'static [(&'static str, LintSpec)] = &[ lint: UnusedResult, desc: "unused result of an expression in a statement", default: allow, - }) + }), + + ("deprecated_owned_vector", + LintSpec { + lint: DeprecatedOwnedVector, + desc: "use of a `~[T]` vector", + default: warn + }), ]; /* @@ -1107,6 +1116,17 @@ fn check_unused_result(cx: &Context, s: &ast::Stmt) { } } +fn check_deprecated_owned_vector(cx: &Context, e: &ast::Expr) { + let t = ty::expr_ty(cx.tcx, e); + match ty::get(t).sty { + ty::ty_vec(_, ty::vstore_uniq) => { + cx.span_lint(DeprecatedOwnedVector, e.span, + "use of deprecated `~[]` vector; replaced by `std::vec_ng::Vec`") + } + _ => {} + } +} + fn check_item_non_camel_case_types(cx: &Context, it: &ast::Item) { fn is_camel_case(ident: ast::Ident) -> bool { let ident = token::get_ident(ident); @@ -1634,6 +1654,7 @@ impl<'a> Visitor<()> for Context<'a> { check_type_limits(self, e); check_unused_casts(self, e); + check_deprecated_owned_vector(self, e); visit::walk_expr(self, e, ()); } diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index e6b4e2c09430..c4fef2245526 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -14,6 +14,7 @@ #[crate_type = "dylib"]; #[crate_type = "rlib"]; +#[allow(deprecated_owned_vector)]; #[feature(globs, struct_variant, managed_boxes, macro_rules)]; extern crate syntax; diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 45607a0992e2..efe71b32f0a3 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -166,6 +166,9 @@ fn maketest(s: &str, cratename: &str, loose_feature_gating: bool) -> ~str { let mut prog = ~r" #[deny(warnings)]; #[allow(unused_variable, dead_assignment, unused_mut, attribute_usage, dead_code)]; + +// FIXME: remove when ~[] disappears from tests. +#[allow(deprecated_owned_vector)]; "; if loose_feature_gating { diff --git a/src/librustuv/lib.rs b/src/librustuv/lib.rs index 890f44faabc0..e2d13d65da0c 100644 --- a/src/librustuv/lib.rs +++ b/src/librustuv/lib.rs @@ -42,6 +42,7 @@ via `close` and `delete` methods. #[feature(macro_rules)]; #[deny(unused_result, unused_must_use)]; #[allow(visible_private_types)]; +#[allow(deprecated_owned_vector)]; #[cfg(test)] extern crate green; diff --git a/src/libsemver/lib.rs b/src/libsemver/lib.rs index 700dc9867940..3ffafbada910 100644 --- a/src/libsemver/lib.rs +++ b/src/libsemver/lib.rs @@ -33,6 +33,8 @@ #[crate_type = "dylib"]; #[license = "MIT/ASL2"]; +#[allow(deprecated_owned_vector)]; + use std::char; use std::cmp; use std::fmt; diff --git a/src/libserialize/lib.rs b/src/libserialize/lib.rs index 028e1e742c47..2f4996a92681 100644 --- a/src/libserialize/lib.rs +++ b/src/libserialize/lib.rs @@ -25,6 +25,7 @@ Core encoding and decoding interfaces. // NOTE remove the following two attributes after the next snapshot. #[allow(unrecognized_lint)]; #[allow(default_type_param_usage)]; +#[allow(deprecated_owned_vector)]; // test harness access #[cfg(test)] diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index a873eccfb038..24a77b71fba1 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -65,6 +65,7 @@ #[deny(non_camel_case_types)]; #[deny(missing_doc)]; #[allow(unknown_features)]; +#[allow(deprecated_owned_vector)]; // When testing libstd, bring in libuv as the I/O backend so tests can print // things and all of the std::io tests have an I/O interface to run on top diff --git a/src/libsync/lib.rs b/src/libsync/lib.rs index 80abcce0df35..2b8df3f17c5a 100644 --- a/src/libsync/lib.rs +++ b/src/libsync/lib.rs @@ -17,6 +17,8 @@ #[crate_type = "dylib"]; #[license = "MIT/ASL2"]; +#[allow(deprecated_owned_vector)]; + pub use arc::{Arc, MutexArc, RWArc, RWWriteMode, RWReadMode, ArcCondvar, CowArc}; pub use sync::{Mutex, RWLock, Condvar, Semaphore, RWLockWriteMode, RWLockReadMode, Barrier, one, mutex}; diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 0d465e8475c9..e84d43117e5e 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -32,6 +32,7 @@ This API is completely unstable and subject to change. #[allow(deprecated)]; #[deny(non_camel_case_types)]; +#[allow(deprecated_owned_vector)]; extern crate serialize; extern crate term; diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index 903fede5faa8..ca142ab86976 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -22,6 +22,7 @@ #[feature(macro_rules)]; #[deny(non_camel_case_types)]; #[allow(missing_doc)]; +#[allow(deprecated_owned_vector)]; extern crate collections; diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 9ebd7d72c918..d791fa0479e7 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -30,6 +30,7 @@ #[crate_type = "dylib"]; #[feature(asm)]; +#[allow(deprecated_owned_vector)]; extern crate collections; extern crate extra; diff --git a/src/libtime/lib.rs b/src/libtime/lib.rs index 7ac338a92a4c..019ad2c4b4c3 100644 --- a/src/libtime/lib.rs +++ b/src/libtime/lib.rs @@ -14,6 +14,7 @@ #[license = "MIT/ASL2"]; #[allow(missing_doc)]; +#[allow(deprecated_owned_vector)]; extern crate serialize; diff --git a/src/libuuid/lib.rs b/src/libuuid/lib.rs index 922393d8bb3a..2fa6c0906c71 100644 --- a/src/libuuid/lib.rs +++ b/src/libuuid/lib.rs @@ -59,6 +59,8 @@ Examples of string representations: #[crate_type = "dylib"]; #[license = "MIT/ASL2"]; +#[allow(deprecated_owned_vector)]; + #[feature(default_type_params)]; // NOTE remove the following two attributes after the next snapshot. diff --git a/src/test/compile-fail/issue-2150.rs b/src/test/compile-fail/issue-2150.rs index 2c54b6220211..b5269519bb78 100644 --- a/src/test/compile-fail/issue-2150.rs +++ b/src/test/compile-fail/issue-2150.rs @@ -11,6 +11,7 @@ #[deny(unreachable_code)]; #[allow(unused_variable)]; #[allow(dead_code)]; +#[allow(deprecated_owned_vector)]; fn fail_len(v: ~[int]) -> uint { let mut i = 3; diff --git a/src/test/compile-fail/issue-8727.rs b/src/test/compile-fail/issue-8727.rs index fca59ed74ee8..be676becd5ac 100644 --- a/src/test/compile-fail/issue-8727.rs +++ b/src/test/compile-fail/issue-8727.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[allow(deprecated_owned_vector)]; // Verify the compiler fails with an error on infinite function // recursions. diff --git a/src/test/compile-fail/lint-deprecated-owned-vector.rs b/src/test/compile-fail/lint-deprecated-owned-vector.rs new file mode 100644 index 000000000000..c21ca87e244a --- /dev/null +++ b/src/test/compile-fail/lint-deprecated-owned-vector.rs @@ -0,0 +1,17 @@ +// Copyright 2014 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[deny(deprecated_owned_vector)]; + +fn main() { + ~[1]; //~ ERROR use of deprecated `~[]` + //~^ ERROR use of deprecated `~[]` + std::vec::with_capacity::(10); //~ ERROR use of deprecated `~[]` +} diff --git a/src/test/compile-fail/lint-heap-memory.rs b/src/test/compile-fail/lint-heap-memory.rs index fa359dcd538f..4c178cdf65c0 100644 --- a/src/test/compile-fail/lint-heap-memory.rs +++ b/src/test/compile-fail/lint-heap-memory.rs @@ -11,6 +11,7 @@ #[feature(managed_boxes)]; #[forbid(heap_memory)]; #[allow(dead_code)]; +#[allow(deprecated_owned_vector)]; struct Foo { x: @int //~ ERROR type uses managed diff --git a/src/test/compile-fail/lint-unused-imports.rs b/src/test/compile-fail/lint-unused-imports.rs index 8d294af3e3eb..c20546d85904 100644 --- a/src/test/compile-fail/lint-unused-imports.rs +++ b/src/test/compile-fail/lint-unused-imports.rs @@ -11,6 +11,7 @@ #[feature(globs)]; #[deny(unused_imports)]; #[allow(dead_code)]; +#[allow(deprecated_owned_vector)]; use cal = bar::c::cc; diff --git a/src/test/compile-fail/lint-unused-mut-variables.rs b/src/test/compile-fail/lint-unused-mut-variables.rs index 271aedd3f6a6..6b6311739f05 100644 --- a/src/test/compile-fail/lint-unused-mut-variables.rs +++ b/src/test/compile-fail/lint-unused-mut-variables.rs @@ -13,6 +13,7 @@ #[allow(dead_assignment)]; #[allow(unused_variable)]; #[allow(dead_code)]; +#[allow(deprecated_owned_vector)]; #[deny(unused_mut)]; fn main() { diff --git a/src/test/compile-fail/lint-unused-unsafe.rs b/src/test/compile-fail/lint-unused-unsafe.rs index 96a4c2adca32..de01a711a3e5 100644 --- a/src/test/compile-fail/lint-unused-unsafe.rs +++ b/src/test/compile-fail/lint-unused-unsafe.rs @@ -12,6 +12,7 @@ #[allow(dead_code)]; #[deny(unused_unsafe)]; +#[allow(deprecated_owned_vector)]; mod foo { extern { diff --git a/src/test/run-pass/ifmt.rs b/src/test/run-pass/ifmt.rs index 564f7b434263..753e98422b3d 100644 --- a/src/test/run-pass/ifmt.rs +++ b/src/test/run-pass/ifmt.rs @@ -13,6 +13,7 @@ #[feature(macro_rules)]; #[deny(warnings)]; #[allow(unused_must_use)]; +#[allow(deprecated_owned_vector)]; use std::fmt; use std::io::MemWriter; From adc357abe6de869159a6268dc14709a4dd19e008 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Thu, 13 Mar 2014 23:59:01 +1100 Subject: [PATCH 2/2] std: render the vec_ng docs. These are wildly incomplete, but having something there is better than nothing, e.g. so that people know it exists, and many of the functions behaviour can be guessed from the name or by checking the source: it's knowing they exist at all that's the hard part. --- src/libstd/vec_ng.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/libstd/vec_ng.rs b/src/libstd/vec_ng.rs index 199fc68be479..7b77a4b60fbd 100644 --- a/src/libstd/vec_ng.rs +++ b/src/libstd/vec_ng.rs @@ -8,8 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// Migrate documentation over from `std::vec` when it is removed. -#[doc(hidden)]; +// Migrate documentation over from `std::vec` progressively. (This is +// shown in docs so that people have something to refer too, even if +// the page is rather empty.) +#[allow(missing_doc)]; use cast::{forget, transmute}; use clone::Clone;