Skip to content

Commit

Permalink
Merge from rustc
Browse files Browse the repository at this point in the history
  • Loading branch information
flip1995 committed Aug 14, 2023
2 parents 442af5d + f6f9cda commit 4d01318
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 26 deletions.
10 changes: 7 additions & 3 deletions clippy_lints/src/incorrect_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use clippy_utils::{get_parent_node, is_res_lang_ctor, last_path_segment, match_d
use rustc_errors::Applicability;
use rustc_hir::def_id::LocalDefId;
use rustc_hir::{Expr, ExprKind, ImplItem, ImplItemKind, ItemKind, LangItem, Node, UnOp};
use rustc_hir_analysis::hir_ty_to_ty;
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty::EarlyBinder;
use rustc_session::{declare_lint_pass, declare_tool_lint};
Expand Down Expand Up @@ -126,7 +125,7 @@ impl LateLintPass<'_> for IncorrectImpls {
if cx.tcx.is_automatically_derived(item.owner_id.to_def_id()) {
return;
}
let ItemKind::Impl(imp) = item.kind else {
let ItemKind::Impl(_) = item.kind else {
return;
};
let ImplItemKind::Fn(_, impl_item_id) = cx.tcx.hir().impl_item(impl_item.impl_item_id()).kind else {
Expand Down Expand Up @@ -189,7 +188,12 @@ impl LateLintPass<'_> for IncorrectImpls {
.diagnostic_items(trait_impl.def_id.krate)
.name_to_id
.get(&sym::Ord)
&& implements_trait(cx, hir_ty_to_ty(cx.tcx, imp.self_ty), *ord_def_id, &[])
&& implements_trait(
cx,
trait_impl.self_ty(),
*ord_def_id,
&[],
)
{
// If the `cmp` call likely needs to be fully qualified in the suggestion
// (like `std::cmp::Ord::cmp`). It's unfortunate we must put this here but we can't
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/macro_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ struct PathAndSpan {
span: Span,
}

/// `MacroRefData` includes the name of the macro
/// and the path from `SourceMap::span_to_filename`.
/// `MacroRefData` includes the name of the macro.
#[derive(Debug, Clone)]
pub struct MacroRefData {
name: String,
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/methods/unnecessary_sort_by.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ use if_chain::if_chain;
use rustc_errors::Applicability;
use rustc_hir::{Closure, Expr, ExprKind, Mutability, Param, Pat, PatKind, Path, PathSegment, QPath};
use rustc_lint::LateContext;
use rustc_middle::ty;
use rustc_middle::ty::GenericArgKind;
use rustc_middle::ty::{self, GenericArgKind};
use rustc_span::sym;
use rustc_span::symbol::Ident;
use std::iter;
Expand Down
1 change: 0 additions & 1 deletion clippy_lints/src/missing_inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ fn is_executable_or_proc_macro(cx: &LateContext<'_>) -> bool {
use rustc_session::config::CrateType;

cx.tcx
.sess
.crate_types()
.iter()
.any(|t: &CrateType| matches!(t, CrateType::Executable | CrateType::ProcMacro))
Expand Down
4 changes: 4 additions & 0 deletions clippy_lints/src/mutable_debug_assertion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ impl<'a, 'tcx> Visitor<'tcx> for MutArgVisitor<'a, 'tcx> {
self.found = true;
return;
},
ExprKind::If(..) => {
self.found = true;
return;
},
ExprKind::Path(_) => {
if let Some(adj) = self.cx.typeck_results().adjustments().get(expr.hir_id) {
if adj
Expand Down
17 changes: 13 additions & 4 deletions clippy_lints/src/redundant_locals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ use clippy_utils::is_from_proc_macro;
use clippy_utils::ty::needs_ordered_drop;
use rustc_ast::Mutability;
use rustc_hir::def::Res;
use rustc_hir::{BindingAnnotation, ByRef, Expr, ExprKind, HirId, Local, Node, Pat, PatKind, QPath};
use rustc_hir::{
BindingAnnotation, ByRef, Expr, ExprKind, HirId, Local, Node, Pat, PatKind, QPath,
};
use rustc_lint::{LateContext, LateLintPass, LintContext};
use rustc_middle::lint::in_external_macro;
use rustc_middle::lint::{in_external_macro, is_from_async_await};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::symbol::Ident;
use rustc_span::DesugaringKind;
Expand Down Expand Up @@ -47,7 +49,9 @@ declare_lint_pass!(RedundantLocals => [REDUNDANT_LOCALS]);
impl<'tcx> LateLintPass<'tcx> for RedundantLocals {
fn check_local(&mut self, cx: &LateContext<'tcx>, local: &'tcx Local<'tcx>) {
if_chain! {
if !local.span.is_desugaring(DesugaringKind::Async);
// Async function parameters are lowered into the closure body, so we can't lint them.
// see `lower_maybe_async_body` in `rust_ast_lowering`
if !is_from_async_await(local.span);
// the pattern is a single by-value binding
if let PatKind::Binding(BindingAnnotation(ByRef::No, mutability), _, ident, None) = local.pat.kind;
// the binding is not type-ascribed
Expand Down Expand Up @@ -106,7 +110,12 @@ fn affects_assignments(cx: &LateContext<'_>, mutability: Mutability, bind: HirId
}

/// Check if a rebinding of a local affects the code's drop behavior.
fn affects_drop_behavior<'tcx>(cx: &LateContext<'tcx>, bind: HirId, rebind: HirId, rebind_expr: &Expr<'tcx>) -> bool {
fn affects_drop_behavior<'tcx>(
cx: &LateContext<'tcx>,
bind: HirId,
rebind: HirId,
rebind_expr: &Expr<'tcx>,
) -> bool {
let hir = cx.tcx.hir();

// the rebinding is in a different scope than the original binding
Expand Down
1 change: 1 addition & 0 deletions tests/ui/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
)]
#![warn(clippy::expl_impl_clone_on_copy)]


#[derive(Copy)]
struct Qux;

Expand Down
20 changes: 10 additions & 10 deletions tests/ui/derive.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: you are implementing `Clone` explicitly on a `Copy` type
--> $DIR/derive.rs:11:1
--> $DIR/derive.rs:12:1
|
LL | / impl Clone for Qux {
LL | | fn clone(&self) -> Self {
Expand All @@ -9,7 +9,7 @@ LL | | }
| |_^
|
note: consider deriving `Clone` or removing `Copy`
--> $DIR/derive.rs:11:1
--> $DIR/derive.rs:12:1
|
LL | / impl Clone for Qux {
LL | | fn clone(&self) -> Self {
Expand All @@ -20,7 +20,7 @@ LL | | }
= note: `-D clippy::expl-impl-clone-on-copy` implied by `-D warnings`

error: you are implementing `Clone` explicitly on a `Copy` type
--> $DIR/derive.rs:35:1
--> $DIR/derive.rs:36:1
|
LL | / impl<'a> Clone for Lt<'a> {
LL | | fn clone(&self) -> Self {
Expand All @@ -30,7 +30,7 @@ LL | | }
| |_^
|
note: consider deriving `Clone` or removing `Copy`
--> $DIR/derive.rs:35:1
--> $DIR/derive.rs:36:1
|
LL | / impl<'a> Clone for Lt<'a> {
LL | | fn clone(&self) -> Self {
Expand All @@ -40,7 +40,7 @@ LL | | }
| |_^

error: you are implementing `Clone` explicitly on a `Copy` type
--> $DIR/derive.rs:46:1
--> $DIR/derive.rs:47:1
|
LL | / impl Clone for BigArray {
LL | | fn clone(&self) -> Self {
Expand All @@ -50,7 +50,7 @@ LL | | }
| |_^
|
note: consider deriving `Clone` or removing `Copy`
--> $DIR/derive.rs:46:1
--> $DIR/derive.rs:47:1
|
LL | / impl Clone for BigArray {
LL | | fn clone(&self) -> Self {
Expand All @@ -60,7 +60,7 @@ LL | | }
| |_^

error: you are implementing `Clone` explicitly on a `Copy` type
--> $DIR/derive.rs:57:1
--> $DIR/derive.rs:58:1
|
LL | / impl Clone for FnPtr {
LL | | fn clone(&self) -> Self {
Expand All @@ -70,7 +70,7 @@ LL | | }
| |_^
|
note: consider deriving `Clone` or removing `Copy`
--> $DIR/derive.rs:57:1
--> $DIR/derive.rs:58:1
|
LL | / impl Clone for FnPtr {
LL | | fn clone(&self) -> Self {
Expand All @@ -80,7 +80,7 @@ LL | | }
| |_^

error: you are implementing `Clone` explicitly on a `Copy` type
--> $DIR/derive.rs:77:1
--> $DIR/derive.rs:78:1
|
LL | / impl<T: Clone> Clone for Generic2<T> {
LL | | fn clone(&self) -> Self {
Expand All @@ -90,7 +90,7 @@ LL | | }
| |_^
|
note: consider deriving `Clone` or removing `Copy`
--> $DIR/derive.rs:77:1
--> $DIR/derive.rs:78:1
|
LL | / impl<T: Clone> Clone for Generic2<T> {
LL | | fn clone(&self) -> Self {
Expand Down
1 change: 1 addition & 0 deletions tests/ui/temporary_assignment.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![warn(clippy::temporary_assignment)]
#![allow(const_item_mutation)]

use std::ops::{Deref, DerefMut};

Expand Down
8 changes: 4 additions & 4 deletions tests/ui/temporary_assignment.stderr
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
error: assignment to temporary
--> $DIR/temporary_assignment.rs:47:5
--> $DIR/temporary_assignment.rs:48:5
|
LL | Struct { field: 0 }.field = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::temporary-assignment` implied by `-D warnings`

error: assignment to temporary
--> $DIR/temporary_assignment.rs:48:5
--> $DIR/temporary_assignment.rs:49:5
|
LL | / MultiStruct {
LL | | structure: Struct { field: 0 },
Expand All @@ -17,13 +17,13 @@ LL | | .field = 1;
| |______________^

error: assignment to temporary
--> $DIR/temporary_assignment.rs:53:5
--> $DIR/temporary_assignment.rs:54:5
|
LL | ArrayStruct { array: [0] }.array[0] = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: assignment to temporary
--> $DIR/temporary_assignment.rs:54:5
--> $DIR/temporary_assignment.rs:55:5
|
LL | (0, 0).0 = 1;
| ^^^^^^^^^^^^
Expand Down

0 comments on commit 4d01318

Please sign in to comment.