Skip to content

Commit

Permalink
Merge from rustc
Browse files Browse the repository at this point in the history
  • Loading branch information
flip1995 committed May 3, 2024
2 parents 10a00c6 + 1f2b15d commit 822528e
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 54 deletions.
10 changes: 5 additions & 5 deletions clippy_lints/src/from_over_into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,6 @@ fn convert_to_from(
let from = snippet_opt(cx, self_ty.span)?;
let into = snippet_opt(cx, target_ty.span)?;

let return_type = matches!(sig.decl.output, FnRetTy::Return(_))
.then_some(String::from("Self"))
.unwrap_or_default();
let mut suggestions = vec![
// impl Into<T> for U -> impl From<T> for U
// ~~~~ ~~~~
Expand All @@ -200,10 +197,13 @@ fn convert_to_from(
// fn into([mut] self) -> T -> fn into([mut] v: T) -> T
// ~~~~ ~~~~
(self_ident.span, format!("val: {from}")),
];

if let FnRetTy::Return(_) = sig.decl.output {
// fn into(self) -> T -> fn into(self) -> Self
// ~ ~~~~
(sig.decl.output.span(), return_type),
];
suggestions.push((sig.decl.output.span(), String::from("Self")));
}

let mut finder = SelfFinder {
cx,
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 @@ -5,8 +5,7 @@ use clippy_utils::ty::implements_trait;
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
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
2 changes: 1 addition & 1 deletion clippy_utils/src/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_hir::{BlockCheckMode, Expr, ExprKind, UnsafeSource};
use rustc_lint::{LateContext, LintContext};
use rustc_session::Session;
use rustc_span::source_map::{original_sp, SourceMap};
use rustc_span::{hygiene, BytePos, Pos, SourceFile, SourceFileAndLine, Span, SpanData, SyntaxContext, DUMMY_SP};
use rustc_span::{hygiene, BytePos, SourceFileAndLine, Pos, SourceFile, Span, SpanData, SyntaxContext, DUMMY_SP};
use std::borrow::Cow;
use std::ops::Range;

Expand Down
4 changes: 2 additions & 2 deletions tests/ui-internal/unnecessary_def_path_hardcoded_path.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ LL | const DEREF_MUT_TRAIT: [&str; 4] = ["core", "ops", "deref", "DerefMut"]
error: hardcoded path to a diagnostic item
--> tests/ui-internal/unnecessary_def_path_hardcoded_path.rs:12:43
|
LL | const DEREF_TRAIT_METHOD: [&str; 5] = ["core", "ops", "deref", "Deref", "deref"];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | const OPS_MOD: [&str; 5] = ["core", "ops"];
| ^^^^^^^^^^^^^^^
|
= help: convert all references to use `sym::deref_method`

Expand Down
1 change: 1 addition & 0 deletions tests/ui/derive.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(clippy::non_canonical_clone_impl, clippy::non_canonical_partial_ord_impl, dead_code)]
#![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
--> tests/ui/derive.rs:7:1
--> tests/ui/derive.rs:8:1
|
LL | / impl Clone for Qux {
LL | |
Expand All @@ -10,7 +10,7 @@ LL | | }
| |_^
|
note: consider deriving `Clone` or removing `Copy`
--> tests/ui/derive.rs:7:1
--> tests/ui/derive.rs:8:1
|
LL | / impl Clone for Qux {
LL | |
Expand All @@ -23,7 +23,7 @@ LL | | }
= help: to override `-D warnings` add `#[allow(clippy::expl_impl_clone_on_copy)]`

error: you are implementing `Clone` explicitly on a `Copy` type
--> tests/ui/derive.rs:32:1
--> tests/ui/derive.rs:33:1
|
LL | / impl<'a> Clone for Lt<'a> {
LL | |
Expand All @@ -34,7 +34,7 @@ LL | | }
| |_^
|
note: consider deriving `Clone` or removing `Copy`
--> tests/ui/derive.rs:32:1
--> tests/ui/derive.rs:33:1
|
LL | / impl<'a> Clone for Lt<'a> {
LL | |
Expand All @@ -45,7 +45,7 @@ LL | | }
| |_^

error: you are implementing `Clone` explicitly on a `Copy` type
--> tests/ui/derive.rs:44:1
--> tests/ui/derive.rs:45:1
|
LL | / impl Clone for BigArray {
LL | |
Expand All @@ -56,7 +56,7 @@ LL | | }
| |_^
|
note: consider deriving `Clone` or removing `Copy`
--> tests/ui/derive.rs:44:1
--> tests/ui/derive.rs:45:1
|
LL | / impl Clone for BigArray {
LL | |
Expand All @@ -67,7 +67,7 @@ LL | | }
| |_^

error: you are implementing `Clone` explicitly on a `Copy` type
--> tests/ui/derive.rs:56:1
--> tests/ui/derive.rs:57:1
|
LL | / impl Clone for FnPtr {
LL | |
Expand All @@ -78,7 +78,7 @@ LL | | }
| |_^
|
note: consider deriving `Clone` or removing `Copy`
--> tests/ui/derive.rs:56:1
--> tests/ui/derive.rs:57:1
|
LL | / impl Clone for FnPtr {
LL | |
Expand All @@ -89,7 +89,7 @@ LL | | }
| |_^

error: you are implementing `Clone` explicitly on a `Copy` type
--> tests/ui/derive.rs:77:1
--> tests/ui/derive.rs:78:1
|
LL | / impl<T: Clone> Clone for Generic2<T> {
LL | |
Expand All @@ -100,7 +100,7 @@ LL | | }
| |_^
|
note: consider deriving `Clone` or removing `Copy`
--> tests/ui/derive.rs:77:1
--> tests/ui/derive.rs:78:1
|
LL | / impl<T: Clone> Clone for Generic2<T> {
LL | |
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/needless_doc_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@
/// unimplemented!();
/// }
/// ```
///
///
/// With an explicit return type it should lint too
/// ```edition2015
/// fn main() -> () {
//~^ ERROR: needless `fn main` in doctest
/// unimplemented!();
/// }
/// ```
///
///
/// This should, too.
/// ```rust
/// fn main() {
//~^ ERROR: needless `fn main` in doctest
/// unimplemented!();
/// }
/// ```
///
///
/// This one too.
/// ```no_run
/// // the fn is not always the first line
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,5 +1,5 @@
error: assignment to temporary
--> tests/ui/temporary_assignment.rs:47:5
--> tests/ui/temporary_assignment.rs:48:5
|
LL | Struct { field: 0 }.field = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -8,7 +8,7 @@ LL | Struct { field: 0 }.field = 1;
= help: to override `-D warnings` add `#[allow(clippy::temporary_assignment)]`

error: assignment to temporary
--> tests/ui/temporary_assignment.rs:50:5
--> tests/ui/temporary_assignment.rs:51:5
|
LL | / MultiStruct {
LL | |
Expand All @@ -19,13 +19,13 @@ LL | | .field = 1;
| |______________^

error: assignment to temporary
--> tests/ui/temporary_assignment.rs:56:5
--> tests/ui/temporary_assignment.rs:57:5
|
LL | ArrayStruct { array: [0] }.array[0] = 1;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: assignment to temporary
--> tests/ui/temporary_assignment.rs:58:5
--> tests/ui/temporary_assignment.rs:59:5
|
LL | (0, 0).0 = 1;
| ^^^^^^^^^^^^
Expand Down
8 changes: 0 additions & 8 deletions tests/ui/to_string_in_format_args_incremental.fixed

This file was deleted.

8 changes: 0 additions & 8 deletions tests/ui/to_string_in_format_args_incremental.rs

This file was deleted.

11 changes: 0 additions & 11 deletions tests/ui/to_string_in_format_args_incremental.stderr

This file was deleted.

0 comments on commit 822528e

Please sign in to comment.