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

Change the trivial cast lints to allow by default #23776

Merged
merged 1 commit into from
Mar 28, 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
1 change: 0 additions & 1 deletion src/libcollections/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#![doc(test(no_crate_inject))]

#![allow(trivial_casts)]
#![allow(trivial_numeric_casts)]
#![feature(alloc)]
#![feature(box_syntax)]
#![feature(box_patterns)]
Expand Down
1 change: 0 additions & 1 deletion src/libcore/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// FIXME: #6220 Implement floating point formatting

#![allow(unsigned_negation)]
#![allow(trivial_numeric_casts)]

use fmt;
use iter::IteratorExt;
Expand Down
1 change: 0 additions & 1 deletion src/libcore/num/i16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@

#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "i16")]
#![allow(trivial_numeric_casts)]

int_module! { i16, 16 }
1 change: 0 additions & 1 deletion src/libcore/num/i32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@

#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "i32")]
#![allow(trivial_numeric_casts)]

int_module! { i32, 32 }
1 change: 0 additions & 1 deletion src/libcore/num/i64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@

#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "i64")]
#![allow(trivial_numeric_casts)]

int_module! { i64, 64 }
1 change: 0 additions & 1 deletion src/libcore/num/i8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@

#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "i8")]
#![allow(trivial_numeric_casts)]

int_module! { i8, 8 }
1 change: 0 additions & 1 deletion src/libcore/num/int_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// except according to those terms.

#![doc(hidden)]
#![allow(trivial_numeric_casts)]

macro_rules! int_module { ($T:ty, $bits:expr) => (

Expand Down
1 change: 0 additions & 1 deletion src/libcore/num/isize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "isize")]
#![allow(trivial_numeric_casts)]

#[cfg(target_pointer_width = "32")]
int_module! { isize, 32 }
Expand Down
1 change: 0 additions & 1 deletion src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#![stable(feature = "rust1", since = "1.0.0")]
#![allow(missing_docs)]
#![allow(trivial_numeric_casts)]

use self::wrapping::{OverflowingOps, WrappingOps};

Expand Down
1 change: 0 additions & 1 deletion src/libcore/num/u16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@

#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "u16")]
#![allow(trivial_numeric_casts)]

uint_module! { u16, i16, 16 }
1 change: 0 additions & 1 deletion src/libcore/num/u32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@

#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "u32")]
#![allow(trivial_numeric_casts)]

uint_module! { u32, i32, 32 }
1 change: 0 additions & 1 deletion src/libcore/num/u64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@

#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "u64")]
#![allow(trivial_numeric_casts)]

uint_module! { u64, i64, 64 }
1 change: 0 additions & 1 deletion src/libcore/num/u8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@

#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "u8")]
#![allow(trivial_numeric_casts)]

uint_module! { u8, i8, 8 }
1 change: 0 additions & 1 deletion src/libcore/num/uint_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// except according to those terms.

#![doc(hidden)]
#![allow(trivial_numeric_casts)]

macro_rules! uint_module { ($T:ty, $T_SIGNED:ty, $bits:expr) => (

Expand Down
1 change: 0 additions & 1 deletion src/libcore/num/usize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@

#![stable(feature = "rust1", since = "1.0.0")]
#![doc(primitive = "usize")]
#![allow(trivial_numeric_casts)]

uint_module! { usize, isize, ::isize::BITS }
2 changes: 0 additions & 2 deletions src/librand/distributions/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

//! Generating numbers between two others.

#![allow(trivial_numeric_casts)]

// this is surprisingly complicated to be both generic & correct

use core::prelude::{PartialOrd};
Expand Down
1 change: 0 additions & 1 deletion src/librand/isaac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ impl Rng for Isaac64Rng {

#[inline]
fn next_u64(&mut self) -> u64 {
#![allow(trivial_numeric_casts)]
if self.cnt == 0 {
// make some more numbers
self.isaac64();
Expand Down
1 change: 0 additions & 1 deletion src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
#![cfg_attr(test, feature(test))]

#![allow(trivial_casts)]
#![allow(trivial_numeric_casts)]

extern crate arena;
extern crate flate;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@ declare_lint! {

declare_lint! {
pub TRIVIAL_CASTS,
Warn,
Allow,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this stay "Warn"? People asked only for allowing numeric casts.

Copy link
Member Author

Choose a reason for hiding this comment

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

We decided we would make the trivial cast lint Allow too until type ascription lands.

"detects trivial casts which could be removed"
}

declare_lint! {
pub TRIVIAL_NUMERIC_CASTS,
Warn,
Allow,
"detects trivial casts of numeric types which could be removed"
}
/// Does nothing as a lint pass, but registers some `Lint`s
Expand Down
1 change: 0 additions & 1 deletion src/librustc_llvm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(trivial_casts)]
#![allow(trivial_numeric_casts)]

#![crate_name = "rustc_llvm"]
#![unstable(feature = "rustc_private")]
Expand Down
1 change: 0 additions & 1 deletion src/librustc_trans/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
#![feature(path_relative_from)]

#![allow(trivial_casts)]
#![allow(trivial_numeric_casts)]

extern crate arena;
extern crate flate;
Expand Down
11 changes: 6 additions & 5 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1105,14 +1105,18 @@ fn check_cast<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>, cast: &CastCheck<'tcx>) {
fcx.tcx().sess.add_lint(lint::builtin::TRIVIAL_NUMERIC_CASTS,
e.id,
span,
format!("trivial numeric cast: `{}` as `{}`",
format!("trivial numeric cast: `{}` as `{}`. Cast can be \
replaced by coercion, this might require type \
ascription or a temporary variable",
fcx.infcx().ty_to_string(t_e),
fcx.infcx().ty_to_string(t_1)));
} else {
fcx.tcx().sess.add_lint(lint::builtin::TRIVIAL_CASTS,
e.id,
span,
format!("trivial cast: `{}` as `{}`",
format!("trivial cast: `{}` as `{}`. Cast can be \
replaced by coercion, this might require type \
ascription or a temporary variable",
fcx.infcx().ty_to_string(t_e),
fcx.infcx().ty_to_string(t_1)));
}
Expand Down Expand Up @@ -4595,8 +4599,6 @@ pub fn check_enum_variants<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
ty: attr::IntType,
disr: ty::Disr) -> bool {
fn uint_in_range(ccx: &CrateCtxt, ty: ast::UintTy, disr: ty::Disr) -> bool {
#![allow(trivial_numeric_casts)]

match ty {
ast::TyU8 => disr as u8 as Disr == disr,
ast::TyU16 => disr as u16 as Disr == disr,
Expand Down Expand Up @@ -4625,7 +4627,6 @@ pub fn check_enum_variants<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
id: ast::NodeId,
hint: attr::ReprAttr)
-> Vec<Rc<ty::VariantInfo<'tcx>>> {
#![allow(trivial_numeric_casts)]
use std::num::Int;

let rty = ty::node_id_to_type(ccx.tcx, id);
Expand Down
2 changes: 0 additions & 2 deletions src/libserialize/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2430,7 +2430,6 @@ macro_rules! to_json_impl_i64 {
($($t:ty), +) => (
$(impl ToJson for $t {
fn to_json(&self) -> Json {
#![allow(trivial_numeric_casts)]
Json::I64(*self as i64)
}
})+
Expand All @@ -2443,7 +2442,6 @@ macro_rules! to_json_impl_u64 {
($($t:ty), +) => (
$(impl ToJson for $t {
fn to_json(&self) -> Json {
#![allow(trivial_numeric_casts)]
Json::U64(*self as u64)
}
})+
Expand Down
1 change: 0 additions & 1 deletion src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@
#![no_std]

#![allow(trivial_casts)]
#![allow(trivial_numeric_casts)]
#![deny(missing_docs)]

#[cfg(test)] extern crate test;
Expand Down
1 change: 0 additions & 1 deletion src/libsyntax/ext/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ pub mod rt {
(unsigned, $t:ty, $tag:expr) => (
impl ToSource for $t {
fn to_source(&self) -> String {
#![allow(trivial_numeric_casts)]
let lit = ast::LitInt(*self as u64, ast::UnsignedIntLit($tag));
pprust::lit_to_string(&dummy_spanned(lit))
}
Expand Down