Skip to content

Commit 84e5c11

Browse files
committed
rollup merge of rust-lang#22127: alexcrichton/stability-holes
There are a number of holes that the stability lint did not previously cover, including: * Types * Bounds on type parameters on functions and impls * Where clauses * Imports * Patterns (structs and enums) These holes have all been fixed by overriding the `visit_path` function on the AST visitor instead of a few specialized cases. This change also necessitated a few stability changes: * The `collections::fmt` module is now stable (it was already supposed to be). * The `thread_local::imp::Key` type is now stable (it was already supposed to be). * The `std::rt::{begin_unwind, begin_unwind_fmt}` functions are now stable. These are required via the `panic!` macro. * The `std::old_io::stdio::{println, println_args}` functions are now stable. These are required by the `print!` and `println!` macros. * The `ops::{FnOnce, FnMut, Fn}` traits are now `#[stable]`. This is required to make bounds with these traits stable. Note that manual implementations of these traits are still gated by default, this stability only allows bounds such as `F: FnOnce()`. Closes rust-lang#8962 Closes rust-lang#16360 Closes rust-lang#20327
2 parents c9fdfdb + bbbb571 commit 84e5c11

File tree

35 files changed

+187
-127
lines changed

35 files changed

+187
-127
lines changed

src/libcollections/fmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@
401401
//! them with the same character. For example, the `{` character is escaped with
402402
//! `{{` and the `}` character is escaped with `}}`.
403403
404-
#![unstable(feature = "std_misc")]
404+
#![stable(feature = "rust1", since = "1.0.0")]
405405

406406
pub use core::fmt::{Formatter, Result, Writer, rt};
407407
pub use core::fmt::{Show, String, Octal, Binary};

src/libcore/fmt/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ pub trait Debug {
268268
fn fmt(&self, &mut Formatter) -> Result;
269269
}
270270

271+
#[allow(deprecated)]
271272
impl<T: Show + ?Sized> Debug for T {
272273
#[allow(deprecated)]
273274
fn fmt(&self, f: &mut Formatter) -> Result { Show::fmt(self, f) }
@@ -295,6 +296,7 @@ pub trait Display {
295296
fn fmt(&self, &mut Formatter) -> Result;
296297
}
297298

299+
#[allow(deprecated)]
298300
impl<T: String + ?Sized> Display for T {
299301
#[allow(deprecated)]
300302
fn fmt(&self, f: &mut Formatter) -> Result { String::fmt(self, f) }

src/libcore/ops.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1119,8 +1119,7 @@ impl<'a, T: ?Sized> DerefMut for &'a mut T {
11191119

11201120
/// A version of the call operator that takes an immutable receiver.
11211121
#[lang="fn"]
1122-
#[unstable(feature = "core",
1123-
reason = "uncertain about variadic generics, input versus associated types")]
1122+
#[stable(feature = "rust1", since = "1.0.0")]
11241123
#[rustc_paren_sugar]
11251124
pub trait Fn<Args> {
11261125
type Output;
@@ -1131,8 +1130,7 @@ pub trait Fn<Args> {
11311130

11321131
/// A version of the call operator that takes a mutable receiver.
11331132
#[lang="fn_mut"]
1134-
#[unstable(feature = "core",
1135-
reason = "uncertain about variadic generics, input versus associated types")]
1133+
#[stable(feature = "rust1", since = "1.0.0")]
11361134
#[rustc_paren_sugar]
11371135
pub trait FnMut<Args> {
11381136
type Output;
@@ -1143,8 +1141,7 @@ pub trait FnMut<Args> {
11431141

11441142
/// A version of the call operator that takes a by-value receiver.
11451143
#[lang="fn_once"]
1146-
#[unstable(feature = "core",
1147-
reason = "uncertain about variadic generics, input versus associated types")]
1144+
#[stable(feature = "rust1", since = "1.0.0")]
11481145
#[rustc_paren_sugar]
11491146
pub trait FnOnce<Args> {
11501147
type Output;

src/libcore/str/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use ptr::PtrExt;
3434
use raw::{Repr, Slice};
3535
use result::Result::{self, Ok, Err};
3636
use slice::{self, SliceExt};
37-
use uint;
37+
use usize;
3838

3939
macro_rules! delegate_iter {
4040
(exact $te:ty : $ti:ty) => {
@@ -783,7 +783,7 @@ impl TwoWaySearcher {
783783
byteset: byteset,
784784

785785
position: 0,
786-
memory: uint::MAX // Dummy value to signify that the period is long
786+
memory: usize::MAX // Dummy value to signify that the period is long
787787
}
788788
}
789789
}
@@ -911,7 +911,7 @@ impl Searcher {
911911
Naive(NaiveSearcher::new())
912912
} else {
913913
let searcher = TwoWaySearcher::new(needle);
914-
if searcher.memory == uint::MAX { // If the period is long
914+
if searcher.memory == usize::MAX { // If the period is long
915915
TwoWayLong(searcher)
916916
} else {
917917
TwoWay(searcher)

src/librbml/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl fmt::Display for Error {
130130
pub mod reader {
131131
use std::char;
132132

133-
use std::int;
133+
use std::isize;
134134
use std::old_io::extensions::u64_from_be_bytes;
135135
use std::mem::transmute;
136136
use std::num::Int;
@@ -440,7 +440,7 @@ pub mod reader {
440440
fn read_u8 (&mut self) -> DecodeResult<u8 > { Ok(doc_as_u8 (try!(self.next_doc(EsU8 )))) }
441441
fn read_uint(&mut self) -> DecodeResult<uint> {
442442
let v = doc_as_u64(try!(self.next_doc(EsUint)));
443-
if v > (::std::uint::MAX as u64) {
443+
if v > (::std::usize::MAX as u64) {
444444
Err(IntTooBig(v as uint))
445445
} else {
446446
Ok(v as uint)
@@ -461,7 +461,7 @@ pub mod reader {
461461
}
462462
fn read_int(&mut self) -> DecodeResult<int> {
463463
let v = doc_as_u64(try!(self.next_doc(EsInt))) as i64;
464-
if v > (int::MAX as i64) || v < (int::MIN as i64) {
464+
if v > (isize::MAX as i64) || v < (isize::MIN as i64) {
465465
debug!("FIXME \\#6122: Removing this makes this function miscompile");
466466
Err(IntTooBig(v as uint))
467467
} else {

src/librustc/lint/builtin.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1768,6 +1768,11 @@ impl LintPass for Stability {
17681768
stability::check_expr(cx.tcx, e,
17691769
&mut |id, sp, stab| self.lint(cx, id, sp, stab));
17701770
}
1771+
1772+
fn check_path(&mut self, cx: &Context, path: &ast::Path, id: ast::NodeId) {
1773+
stability::check_path(cx.tcx, path, id,
1774+
&mut |id, sp, stab| self.lint(cx, id, sp, stab));
1775+
}
17711776
}
17721777

17731778
declare_lint! {

src/librustc/middle/dataflow.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use middle::cfg;
2020
use middle::cfg::CFGIndex;
2121
use middle::ty;
2222
use std::old_io;
23-
use std::uint;
23+
use std::usize;
2424
use std::iter::repeat;
2525
use syntax::ast;
2626
use syntax::ast_util::IdRange;
@@ -48,7 +48,7 @@ pub struct DataFlowContext<'a, 'tcx: 'a, O> {
4848
bits_per_id: uint,
4949

5050
/// number of words we will use to store bits_per_id.
51-
/// equal to bits_per_id/uint::BITS rounded up.
51+
/// equal to bits_per_id/usize::BITS rounded up.
5252
words_per_id: uint,
5353

5454
// mapping from node to cfg node index
@@ -193,7 +193,7 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> {
193193
oper: O,
194194
id_range: IdRange,
195195
bits_per_id: uint) -> DataFlowContext<'a, 'tcx, O> {
196-
let words_per_id = (bits_per_id + uint::BITS - 1) / uint::BITS;
196+
let words_per_id = (bits_per_id + usize::BITS - 1) / usize::BITS;
197197
let num_nodes = cfg.graph.all_nodes().len();
198198

199199
debug!("DataFlowContext::new(analysis_name: {}, id_range={:?}, \
@@ -202,7 +202,7 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> {
202202
analysis_name, id_range, bits_per_id, words_per_id,
203203
num_nodes);
204204

205-
let entry = if oper.initial_value() { uint::MAX } else {0};
205+
let entry = if oper.initial_value() { usize::MAX } else {0};
206206

207207
let gens: Vec<_> = repeat(0).take(num_nodes * words_per_id).collect();
208208
let kills: Vec<_> = repeat(0).take(num_nodes * words_per_id).collect();
@@ -351,13 +351,13 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> {
351351
352352
for (word_index, &word) in words.iter().enumerate() {
353353
if word != 0 {
354-
let base_index = word_index * uint::BITS;
355-
for offset in 0..uint::BITS {
354+
let base_index = word_index * usize::BITS;
355+
for offset in 0..usize::BITS {
356356
let bit = 1 << offset;
357357
if (word & bit) != 0 {
358358
// NB: we round up the total number of bits
359359
// that we store in any given bit set so that
360-
// it is an even multiple of uint::BITS. This
360+
// it is an even multiple of usize::BITS. This
361361
// means that there may be some stray bits at
362362
// the end that do not correspond to any
363363
// actual value. So before we callback, check
@@ -500,7 +500,7 @@ impl<'a, 'b, 'tcx, O:DataFlowOperator> PropagationContext<'a, 'b, 'tcx, O> {
500500
}
501501

502502
fn reset(&mut self, bits: &mut [uint]) {
503-
let e = if self.dfcx.oper.initial_value() {uint::MAX} else {0};
503+
let e = if self.dfcx.oper.initial_value() {usize::MAX} else {0};
504504
for b in bits {
505505
*b = e;
506506
}
@@ -552,7 +552,7 @@ fn bits_to_string(words: &[uint]) -> String {
552552

553553
for &word in words {
554554
let mut v = word;
555-
for _ in 0..uint::BYTES {
555+
for _ in 0..usize::BYTES {
556556
result.push(sep);
557557
result.push_str(&format!("{:02x}", v & 0xFF)[]);
558558
v >>= 8;
@@ -581,8 +581,8 @@ fn bitwise<Op:BitwiseOperator>(out_vec: &mut [uint],
581581
fn set_bit(words: &mut [uint], bit: uint) -> bool {
582582
debug!("set_bit: words={} bit={}",
583583
mut_bits_to_string(words), bit_str(bit));
584-
let word = bit / uint::BITS;
585-
let bit_in_word = bit % uint::BITS;
584+
let word = bit / usize::BITS;
585+
let bit_in_word = bit % usize::BITS;
586586
let bit_mask = 1 << bit_in_word;
587587
debug!("word={} bit_in_word={} bit_mask={}", word, bit_in_word, word);
588588
let oldv = words[word];

src/librustc/middle/graph.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#![allow(dead_code)] // still WIP
3434

3535
use std::fmt::{Formatter, Error, Debug};
36-
use std::uint;
36+
use std::usize;
3737
use std::collections::BitvSet;
3838

3939
pub struct Graph<N,E> {
@@ -64,12 +64,12 @@ impl<E: Debug> Debug for Edge<E> {
6464
#[derive(Clone, Copy, PartialEq, Debug)]
6565
pub struct NodeIndex(pub uint);
6666
#[allow(non_upper_case_globals)]
67-
pub const InvalidNodeIndex: NodeIndex = NodeIndex(uint::MAX);
67+
pub const InvalidNodeIndex: NodeIndex = NodeIndex(usize::MAX);
6868

6969
#[derive(Copy, PartialEq, Debug)]
7070
pub struct EdgeIndex(pub uint);
7171
#[allow(non_upper_case_globals)]
72-
pub const InvalidEdgeIndex: EdgeIndex = EdgeIndex(uint::MAX);
72+
pub const InvalidEdgeIndex: EdgeIndex = EdgeIndex(usize::MAX);
7373

7474
// Use a private field here to guarantee no more instances are created:
7575
#[derive(Copy, Debug)]

src/librustc/middle/stability.rs

+23-20
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
1414
use session::Session;
1515
use lint;
16+
use middle::def;
1617
use middle::ty;
1718
use middle::privacy::PublicItems;
1819
use metadata::csearch;
@@ -277,6 +278,11 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
277278

278279
impl<'a, 'v, 'tcx> Visitor<'v> for Checker<'a, 'tcx> {
279280
fn visit_item(&mut self, item: &ast::Item) {
281+
// When compiling with --test we don't enforce stability on the
282+
// compiler-generated test module, demarcated with `DUMMY_SP` plus the
283+
// name `__test`
284+
if item.span == DUMMY_SP && item.ident.as_str() == "__test" { return }
285+
280286
check_item(self.tcx, item,
281287
&mut |id, sp, stab| self.check(id, sp, stab));
282288
visit::walk_item(self, item);
@@ -287,6 +293,12 @@ impl<'a, 'v, 'tcx> Visitor<'v> for Checker<'a, 'tcx> {
287293
&mut |id, sp, stab| self.check(id, sp, stab));
288294
visit::walk_expr(self, ex);
289295
}
296+
297+
fn visit_path(&mut self, path: &ast::Path, id: ast::NodeId) {
298+
check_path(self.tcx, path, id,
299+
&mut |id, sp, stab| self.check(id, sp, stab));
300+
visit::walk_path(self, path)
301+
}
290302
}
291303

292304
/// Helper for discovering nodes to check for stability
@@ -304,18 +316,6 @@ pub fn check_item(tcx: &ty::ctxt, item: &ast::Item,
304316
let id = ast::DefId { krate: cnum, node: ast::CRATE_NODE_ID };
305317
maybe_do_stability_check(tcx, id, item.span, cb);
306318
}
307-
ast::ItemTrait(_, _, ref supertraits, _) => {
308-
for t in &**supertraits {
309-
if let ast::TraitTyParamBound(ref t, _) = *t {
310-
let id = ty::trait_ref_to_def_id(tcx, &t.trait_ref);
311-
maybe_do_stability_check(tcx, id, t.trait_ref.path.span, cb);
312-
}
313-
}
314-
}
315-
ast::ItemImpl(_, _, _, Some(ref t), _, _) => {
316-
let id = ty::trait_ref_to_def_id(tcx, t);
317-
maybe_do_stability_check(tcx, id, t.path.span, cb);
318-
}
319319
_ => (/* pass */)
320320
}
321321
}
@@ -325,15 +325,8 @@ pub fn check_expr(tcx: &ty::ctxt, e: &ast::Expr,
325325
cb: &mut FnMut(ast::DefId, Span, &Option<Stability>)) {
326326
if is_internal(tcx, e.span) { return; }
327327

328-
let mut span = e.span;
329-
328+
let span;
330329
let id = match e.node {
331-
ast::ExprPath(..) | ast::ExprQPath(..) | ast::ExprStruct(..) => {
332-
match tcx.def_map.borrow().get(&e.id) {
333-
Some(&def) => def.def_id(),
334-
None => return
335-
}
336-
}
337330
ast::ExprMethodCall(i, _, _) => {
338331
span = i.span;
339332
let method_call = ty::MethodCall::expr(e.id);
@@ -369,6 +362,16 @@ pub fn check_expr(tcx: &ty::ctxt, e: &ast::Expr,
369362
maybe_do_stability_check(tcx, id, span, cb);
370363
}
371364

365+
pub fn check_path(tcx: &ty::ctxt, path: &ast::Path, id: ast::NodeId,
366+
cb: &mut FnMut(ast::DefId, Span, &Option<Stability>)) {
367+
let did = match tcx.def_map.borrow().get(&id) {
368+
Some(&def::DefPrimTy(..)) => return,
369+
Some(def) => def.def_id(),
370+
None => return
371+
};
372+
maybe_do_stability_check(tcx, did, path.span, cb)
373+
}
374+
372375
fn maybe_do_stability_check(tcx: &ty::ctxt, id: ast::DefId, span: Span,
373376
cb: &mut FnMut(ast::DefId, Span, &Option<Stability>)) {
374377
if !is_staged_api(tcx, id) { return }

src/librustc_borrowck/borrowck/move_data.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use rustc::util::nodemap::{FnvHashMap, NodeSet};
2424
use rustc::util::ppaux::Repr;
2525
use std::cell::RefCell;
2626
use std::rc::Rc;
27-
use std::uint;
27+
use std::usize;
2828
use syntax::ast;
2929
use syntax::ast_util;
3030
use syntax::codemap::Span;
@@ -92,7 +92,7 @@ impl Clone for MovePathIndex {
9292

9393
#[allow(non_upper_case_globals)]
9494
static InvalidMovePathIndex: MovePathIndex =
95-
MovePathIndex(uint::MAX);
95+
MovePathIndex(usize::MAX);
9696

9797
/// Index into `MoveData.moves`, used like a pointer
9898
#[derive(Copy, PartialEq)]
@@ -106,7 +106,7 @@ impl MoveIndex {
106106

107107
#[allow(non_upper_case_globals)]
108108
static InvalidMoveIndex: MoveIndex =
109-
MoveIndex(uint::MAX);
109+
MoveIndex(usize::MAX);
110110

111111
pub struct MovePath<'tcx> {
112112
/// Loan path corresponding to this move path

src/librustc_resolve/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ use std::cell::{Cell, RefCell};
101101
use std::fmt;
102102
use std::mem::replace;
103103
use std::rc::{Rc, Weak};
104-
use std::uint;
104+
use std::usize;
105105

106106
// NB: This module needs to be declared first so diagnostics are
107107
// registered before they are used.
@@ -4370,7 +4370,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
43704370
for rib in this.value_ribs.iter().rev() {
43714371
for (&k, _) in &rib.bindings {
43724372
maybes.push(token::get_name(k));
4373-
values.push(uint::MAX);
4373+
values.push(usize::MAX);
43744374
}
43754375
}
43764376

@@ -4384,7 +4384,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
43844384
}
43854385

43864386
if values.len() > 0 &&
4387-
values[smallest] != uint::MAX &&
4387+
values[smallest] != usize::MAX &&
43884388
values[smallest] < name.len() + 2 &&
43894389
values[smallest] <= max_distance &&
43904390
name != &maybes[smallest][] {

src/librustc_typeck/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ This API is completely unstable and subject to change.
7979
#![feature(collections)]
8080
#![feature(core)]
8181
#![feature(int_uint)]
82+
#![feature(std_misc)]
8283
#![feature(quote)]
8384
#![feature(rustc_diagnostic_macros)]
8485
#![feature(rustc_private)]

0 commit comments

Comments
 (0)