Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc: Fix a number of stability lint holes #22127

Merged
merged 1 commit into from
Feb 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libcollections/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@
//! them with the same character. For example, the `{` character is escaped with
//! `{{` and the `}` character is escaped with `}}`.

#![unstable(feature = "std_misc")]
#![stable(feature = "rust1", since = "1.0.0")]

pub use core::fmt::{Formatter, Result, Writer, rt};
pub use core::fmt::{Show, String, Octal, Binary};
Expand Down
2 changes: 2 additions & 0 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ pub trait Debug {
fn fmt(&self, &mut Formatter) -> Result;
}

#[allow(deprecated)]
impl<T: Show + ?Sized> Debug for T {
#[allow(deprecated)]
fn fmt(&self, f: &mut Formatter) -> Result { Show::fmt(self, f) }
Expand Down Expand Up @@ -295,6 +296,7 @@ pub trait Display {
fn fmt(&self, &mut Formatter) -> Result;
}

#[allow(deprecated)]
impl<T: String + ?Sized> Display for T {
#[allow(deprecated)]
fn fmt(&self, f: &mut Formatter) -> Result { String::fmt(self, f) }
Expand Down
9 changes: 3 additions & 6 deletions src/libcore/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,8 +1119,7 @@ impl<'a, T: ?Sized> DerefMut for &'a mut T {

/// A version of the call operator that takes an immutable receiver.
#[lang="fn"]
#[unstable(feature = "core",
reason = "uncertain about variadic generics, input versus associated types")]
#[stable(feature = "rust1", since = "1.0.0")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uhoh. These are supposed to stay unstable, and only be usable via the -> sugar.

#[rustc_paren_sugar]
pub trait Fn<Args> {
type Output;
Expand All @@ -1131,8 +1130,7 @@ pub trait Fn<Args> {

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

/// A version of the call operator that takes a by-value receiver.
#[lang="fn_once"]
#[unstable(feature = "core",
reason = "uncertain about variadic generics, input versus associated types")]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_paren_sugar]
pub trait FnOnce<Args> {
type Output;
Expand Down
6 changes: 3 additions & 3 deletions src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use ptr::PtrExt;
use raw::{Repr, Slice};
use result::Result::{self, Ok, Err};
use slice::{self, SliceExt};
use uint;
use usize;

macro_rules! delegate_iter {
(exact $te:ty : $ti:ty) => {
Expand Down Expand Up @@ -783,7 +783,7 @@ impl TwoWaySearcher {
byteset: byteset,

position: 0,
memory: uint::MAX // Dummy value to signify that the period is long
memory: usize::MAX // Dummy value to signify that the period is long
}
}
}
Expand Down Expand Up @@ -911,7 +911,7 @@ impl Searcher {
Naive(NaiveSearcher::new())
} else {
let searcher = TwoWaySearcher::new(needle);
if searcher.memory == uint::MAX { // If the period is long
if searcher.memory == usize::MAX { // If the period is long
TwoWayLong(searcher)
} else {
TwoWay(searcher)
Expand Down
6 changes: 3 additions & 3 deletions src/librbml/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ impl fmt::Display for Error {
pub mod reader {
use std::char;

use std::int;
use std::isize;
use std::old_io::extensions::u64_from_be_bytes;
use std::mem::transmute;
use std::num::Int;
Expand Down Expand Up @@ -440,7 +440,7 @@ pub mod reader {
fn read_u8 (&mut self) -> DecodeResult<u8 > { Ok(doc_as_u8 (try!(self.next_doc(EsU8 )))) }
fn read_uint(&mut self) -> DecodeResult<uint> {
let v = doc_as_u64(try!(self.next_doc(EsUint)));
if v > (::std::uint::MAX as u64) {
if v > (::std::usize::MAX as u64) {
Err(IntTooBig(v as uint))
} else {
Ok(v as uint)
Expand All @@ -461,7 +461,7 @@ pub mod reader {
}
fn read_int(&mut self) -> DecodeResult<int> {
let v = doc_as_u64(try!(self.next_doc(EsInt))) as i64;
if v > (int::MAX as i64) || v < (int::MIN as i64) {
if v > (isize::MAX as i64) || v < (isize::MIN as i64) {
debug!("FIXME \\#6122: Removing this makes this function miscompile");
Err(IntTooBig(v as uint))
} else {
Expand Down
5 changes: 5 additions & 0 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1768,6 +1768,11 @@ impl LintPass for Stability {
stability::check_expr(cx.tcx, e,
&mut |id, sp, stab| self.lint(cx, id, sp, stab));
}

fn check_path(&mut self, cx: &Context, path: &ast::Path, id: ast::NodeId) {
stability::check_path(cx.tcx, path, id,
&mut |id, sp, stab| self.lint(cx, id, sp, stab));
}
}

declare_lint! {
Expand Down
22 changes: 11 additions & 11 deletions src/librustc/middle/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use middle::cfg;
use middle::cfg::CFGIndex;
use middle::ty;
use std::old_io;
use std::uint;
use std::usize;
use std::iter::repeat;
use syntax::ast;
use syntax::ast_util::IdRange;
Expand Down Expand Up @@ -48,7 +48,7 @@ pub struct DataFlowContext<'a, 'tcx: 'a, O> {
bits_per_id: uint,

/// number of words we will use to store bits_per_id.
/// equal to bits_per_id/uint::BITS rounded up.
/// equal to bits_per_id/usize::BITS rounded up.
words_per_id: uint,

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

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

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

let gens: Vec<_> = repeat(0).take(num_nodes * words_per_id).collect();
let kills: Vec<_> = repeat(0).take(num_nodes * words_per_id).collect();
Expand Down Expand Up @@ -351,13 +351,13 @@ impl<'a, 'tcx, O:DataFlowOperator> DataFlowContext<'a, 'tcx, O> {

for (word_index, &word) in words.iter().enumerate() {
if word != 0 {
let base_index = word_index * uint::BITS;
for offset in 0..uint::BITS {
let base_index = word_index * usize::BITS;
for offset in 0..usize::BITS {
let bit = 1 << offset;
if (word & bit) != 0 {
// NB: we round up the total number of bits
// that we store in any given bit set so that
// it is an even multiple of uint::BITS. This
// it is an even multiple of usize::BITS. This
// means that there may be some stray bits at
// the end that do not correspond to any
// actual value. So before we callback, check
Expand Down Expand Up @@ -500,7 +500,7 @@ impl<'a, 'b, 'tcx, O:DataFlowOperator> PropagationContext<'a, 'b, 'tcx, O> {
}

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

for &word in words {
let mut v = word;
for _ in 0..uint::BYTES {
for _ in 0..usize::BYTES {
result.push(sep);
result.push_str(&format!("{:02x}", v & 0xFF)[]);
v >>= 8;
Expand Down Expand Up @@ -581,8 +581,8 @@ fn bitwise<Op:BitwiseOperator>(out_vec: &mut [uint],
fn set_bit(words: &mut [uint], bit: uint) -> bool {
debug!("set_bit: words={} bit={}",
mut_bits_to_string(words), bit_str(bit));
let word = bit / uint::BITS;
let bit_in_word = bit % uint::BITS;
let word = bit / usize::BITS;
let bit_in_word = bit % usize::BITS;
let bit_mask = 1 << bit_in_word;
debug!("word={} bit_in_word={} bit_mask={}", word, bit_in_word, word);
let oldv = words[word];
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#![allow(dead_code)] // still WIP

use std::fmt::{Formatter, Error, Debug};
use std::uint;
use std::usize;
use std::collections::BitvSet;

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

#[derive(Copy, PartialEq, Debug)]
pub struct EdgeIndex(pub uint);
#[allow(non_upper_case_globals)]
pub const InvalidEdgeIndex: EdgeIndex = EdgeIndex(uint::MAX);
pub const InvalidEdgeIndex: EdgeIndex = EdgeIndex(usize::MAX);

// Use a private field here to guarantee no more instances are created:
#[derive(Copy, Debug)]
Expand Down
43 changes: 23 additions & 20 deletions src/librustc/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use session::Session;
use lint;
use middle::def;
use middle::ty;
use middle::privacy::PublicItems;
use metadata::csearch;
Expand Down Expand Up @@ -277,6 +278,11 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {

impl<'a, 'v, 'tcx> Visitor<'v> for Checker<'a, 'tcx> {
fn visit_item(&mut self, item: &ast::Item) {
// When compiling with --test we don't enforce stability on the
// compiler-generated test module, demarcated with `DUMMY_SP` plus the
// name `__test`
if item.span == DUMMY_SP && item.ident.as_str() == "__test" { return }

check_item(self.tcx, item,
&mut |id, sp, stab| self.check(id, sp, stab));
visit::walk_item(self, item);
Expand All @@ -287,6 +293,12 @@ impl<'a, 'v, 'tcx> Visitor<'v> for Checker<'a, 'tcx> {
&mut |id, sp, stab| self.check(id, sp, stab));
visit::walk_expr(self, ex);
}

fn visit_path(&mut self, path: &ast::Path, id: ast::NodeId) {
check_path(self.tcx, path, id,
&mut |id, sp, stab| self.check(id, sp, stab));
visit::walk_path(self, path)
}
}

/// Helper for discovering nodes to check for stability
Expand All @@ -304,18 +316,6 @@ pub fn check_item(tcx: &ty::ctxt, item: &ast::Item,
let id = ast::DefId { krate: cnum, node: ast::CRATE_NODE_ID };
maybe_do_stability_check(tcx, id, item.span, cb);
}
ast::ItemTrait(_, _, ref supertraits, _) => {
for t in &**supertraits {
if let ast::TraitTyParamBound(ref t, _) = *t {
let id = ty::trait_ref_to_def_id(tcx, &t.trait_ref);
maybe_do_stability_check(tcx, id, t.trait_ref.path.span, cb);
}
}
}
ast::ItemImpl(_, _, _, Some(ref t), _, _) => {
let id = ty::trait_ref_to_def_id(tcx, t);
maybe_do_stability_check(tcx, id, t.path.span, cb);
}
_ => (/* pass */)
}
}
Expand All @@ -325,15 +325,8 @@ pub fn check_expr(tcx: &ty::ctxt, e: &ast::Expr,
cb: &mut FnMut(ast::DefId, Span, &Option<Stability>)) {
if is_internal(tcx, e.span) { return; }

let mut span = e.span;

let span;
let id = match e.node {
ast::ExprPath(..) | ast::ExprQPath(..) | ast::ExprStruct(..) => {
match tcx.def_map.borrow().get(&e.id) {
Some(&def) => def.def_id(),
None => return
}
}
ast::ExprMethodCall(i, _, _) => {
span = i.span;
let method_call = ty::MethodCall::expr(e.id);
Expand Down Expand Up @@ -369,6 +362,16 @@ pub fn check_expr(tcx: &ty::ctxt, e: &ast::Expr,
maybe_do_stability_check(tcx, id, span, cb);
}

pub fn check_path(tcx: &ty::ctxt, path: &ast::Path, id: ast::NodeId,
cb: &mut FnMut(ast::DefId, Span, &Option<Stability>)) {
let did = match tcx.def_map.borrow().get(&id) {
Some(&def::DefPrimTy(..)) => return,
Some(def) => def.def_id(),
None => return
};
maybe_do_stability_check(tcx, did, path.span, cb)
}

fn maybe_do_stability_check(tcx: &ty::ctxt, id: ast::DefId, span: Span,
cb: &mut FnMut(ast::DefId, Span, &Option<Stability>)) {
if !is_staged_api(tcx, id) { return }
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_borrowck/borrowck/move_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use rustc::util::nodemap::{FnvHashMap, NodeSet};
use rustc::util::ppaux::Repr;
use std::cell::RefCell;
use std::rc::Rc;
use std::uint;
use std::usize;
use syntax::ast;
use syntax::ast_util;
use syntax::codemap::Span;
Expand Down Expand Up @@ -92,7 +92,7 @@ impl Clone for MovePathIndex {

#[allow(non_upper_case_globals)]
static InvalidMovePathIndex: MovePathIndex =
MovePathIndex(uint::MAX);
MovePathIndex(usize::MAX);

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

#[allow(non_upper_case_globals)]
static InvalidMoveIndex: MoveIndex =
MoveIndex(uint::MAX);
MoveIndex(usize::MAX);

pub struct MovePath<'tcx> {
/// Loan path corresponding to this move path
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ use std::cell::{Cell, RefCell};
use std::fmt;
use std::mem::replace;
use std::rc::{Rc, Weak};
use std::uint;
use std::usize;

// NB: This module needs to be declared first so diagnostics are
// registered before they are used.
Expand Down Expand Up @@ -4366,7 +4366,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
for rib in this.value_ribs.iter().rev() {
for (&k, _) in &rib.bindings {
maybes.push(token::get_name(k));
values.push(uint::MAX);
values.push(usize::MAX);
}
}

Expand All @@ -4380,7 +4380,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
}

if values.len() > 0 &&
values[smallest] != uint::MAX &&
values[smallest] != usize::MAX &&
values[smallest] < name.len() + 2 &&
values[smallest] <= max_distance &&
name != &maybes[smallest][] {
Expand Down
1 change: 1 addition & 0 deletions src/librustc_typeck/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ This API is completely unstable and subject to change.
#![feature(collections)]
#![feature(core)]
#![feature(int_uint)]
#![feature(std_misc)]
#![feature(quote)]
#![feature(rustc_diagnostic_macros)]
#![feature(rustc_private)]
Expand Down
Loading