Skip to content

Commit

Permalink
Merge branch 'master' into fix-check_infinite_loop
Browse files Browse the repository at this point in the history
  • Loading branch information
yerke committed Nov 22, 2019
2 parents 4028625 + b4f1769 commit 4265143
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions clippy_lints/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
pub fn miri_to_const(result: &ty::Const<'_>) -> Option<Constant> {
use rustc::mir::interpret::{ConstValue, Scalar};
match result.val {
ConstValue::Scalar(Scalar::Raw { data: d, .. }) => match result.ty.kind {
ty::ConstKind::Value(ConstValue::Scalar(Scalar::Raw { data: d, .. })) => match result.ty.kind {
ty::Bool => Some(Constant::Bool(d == 1)),
ty::Uint(_) | ty::Int(_) => Some(Constant::Int(d)),
ty::Float(FloatTy::F32) => Some(Constant::F32(f32::from_bits(
Expand All @@ -492,7 +492,7 @@ pub fn miri_to_const(result: &ty::Const<'_>) -> Option<Constant> {
// FIXME: implement other conversions.
_ => None,
},
ConstValue::Slice { data, start, end } => match result.ty.kind {
ty::ConstKind::Value(ConstValue::Slice { data, start, end }) => match result.ty.kind {
ty::Ref(_, tam, _) => match tam.kind {
ty::Str => String::from_utf8(
data.inspect_with_undef_and_ptr_outside_interpreter(start..end)
Expand Down
7 changes: 5 additions & 2 deletions clippy_lints/src/functions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::utils::{
attrs::is_proc_macro, iter_input_pats, match_def_path, qpath_res, return_ty, snippet, snippet_opt,
span_help_and_lint, span_lint, span_lint_and_then, type_is_unsafe_function,
span_help_and_lint, span_lint, span_lint_and_then, trait_ref_of_method, type_is_unsafe_function,
};
use matches::matches;
use rustc::hir::{self, def::Res, def_id::DefId, intravisit};
Expand Down Expand Up @@ -254,7 +254,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
if let Some(attr) = attr {
let fn_header_span = item.span.with_hi(sig.decl.output.span().hi());
check_needless_must_use(cx, &sig.decl, item.hir_id, item.span, fn_header_span, attr);
} else if cx.access_levels.is_exported(item.hir_id) && !is_proc_macro(&item.attrs) {
} else if cx.access_levels.is_exported(item.hir_id)
&& !is_proc_macro(&item.attrs)
&& trait_ref_of_method(cx, item.hir_id).is_none()
{
check_must_use_candidate(
cx,
&sig.decl,
Expand Down
4 changes: 2 additions & 2 deletions src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,14 @@ pub fn main() {

// Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.
// We're invoking the compiler programmatically, so we ignore this/
let wrapper_mode = Path::new(&orig_args[1]).file_stem() == Some("rustc".as_ref());
let wrapper_mode = orig_args.get(1).map(Path::new).and_then(Path::file_stem) == Some("rustc".as_ref());

if wrapper_mode {
// we still want to be able to invoke it normally though
orig_args.remove(1);
}

if !wrapper_mode && std::env::args().any(|a| a == "--help" || a == "-h") {
if !wrapper_mode && (orig_args.iter().any(|a| a == "--help" || a == "-h") || orig_args.len() == 1) {
display_help();
exit(0);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/must_use_candidates.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub trait MyPureTrait {
}

impl MyPureTrait for MyPure {
#[must_use] fn trait_impl_pure(&self, i: u32) -> u32 {
fn trait_impl_pure(&self, i: u32) -> u32 {
i
}
}
Expand Down
8 changes: 1 addition & 7 deletions tests/ui/must_use_candidates.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ error: this method could have a `#[must_use]` attribute
LL | pub fn inherent_pure(&self) -> u8 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn inherent_pure(&self) -> u8`

error: this method could have a `#[must_use]` attribute
--> $DIR/must_use_candidates.rs:31:5
|
LL | fn trait_impl_pure(&self, i: u32) -> u32 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] fn trait_impl_pure(&self, i: u32) -> u32`

error: this function could have a `#[must_use]` attribute
--> $DIR/must_use_candidates.rs:48:1
|
Expand All @@ -36,5 +30,5 @@ error: this function could have a `#[must_use]` attribute
LL | pub fn arcd(_x: Arc<u32>) -> bool {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: add the attribute: `#[must_use] pub fn arcd(_x: Arc<u32>) -> bool`

error: aborting due to 6 previous errors
error: aborting due to 5 previous errors

0 comments on commit 4265143

Please sign in to comment.