Skip to content
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
6 changes: 3 additions & 3 deletions compiler/rustc_attr_ir/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ impl FormatString {
/// ```rust,ignore (just an example)
/// FormatArgs {
/// this: "FromResidual",
/// this_resolved: "FromResidual<Option<Infallible>>",
/// this_resolved: "FromResidual<Option<!>>",
/// item_context: "an async function",
/// generic_args: [("Self", "u32"), ("R", "Option<Infallible>")],
/// generic_args: [("Self", "u32"), ("R", "Option<!>")],
/// }
/// ```
#[derive(Debug)]
Expand Down Expand Up @@ -444,7 +444,7 @@ pub enum LitOrArg {
/// crate_local: false,
/// direct: true,
/// generic_args: [("Self","u32"),
/// ("R", "core::option::Option<core::convert::Infallible>"),
/// ("R", "core::option::Option<!>"),
/// ("R", "core::option::Option<T>" ),
/// ],
/// }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
// `std::marker::Sized` is not implemented for `T`" as we will point
// at the type param with a label to suggest constraining it.
&& !self.tcx.is_diagnostic_item(sym::FromResidual, leaf_trait_predicate.def_id())
// Don't say "the trait `FromResidual<Option<Infallible>>` is
// Don't say "the trait `FromResidual<Option<!>>` is
// not implemented for `Result<T, E>`".
{
// We do this just so that the JSON output's `help` position is the
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4193,7 +4193,7 @@ declare_clippy_lint! {
/// ### Why is this bad?
/// In those cases, the `TryInto` and `TryFrom` trait implementation is a blanket impl that forwards
/// to `Into` or `From`, which always succeeds.
/// The returned `Result<_, Infallible>` requires error handling to get the contained value
/// The returned `Result<_, !>` requires error handling to get the contained value
/// even though the conversion can never fail.
///
/// ### Example
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fn check<'tcx>(
// If `T: TryFrom<U>` and `T: From<U>` both exist, then that means that the `TryFrom`
// _must_ be from the blanket impl and cannot have been manually implemented
// (else there would be conflicting impls, even with #![feature(spec)]), so we don't even need to check
// what `<T as TryFrom<U>>::Error` is: it's always `Infallible`
// what `<T as TryFrom<U>>::Error` is: it's always `!`
&& implements_trait(cx, self_ty, from_into_trait, &[other_ty])
&& let Some(other_ty) = other_ty.as_type()
{
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/tests/ui/drop_non_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn make_result<T>(t: T) -> Result<T, ()> {
}

// The return type should behave as `T` as the `Err` variant is uninhabited
fn make_result_uninhabited_err<T>(t: T) -> Result<T, std::convert::Infallible> {
fn make_result_uninhabited_err<T>(t: T) -> Result<T, !> {
Ok(t)
}

Expand Down
6 changes: 2 additions & 4 deletions src/tools/clippy/tests/ui/infallible_try_from.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![warn(clippy::infallible_try_from)]

use std::convert::Infallible;

struct MyStruct(i32);

impl TryFrom<i8> for MyStruct {
Expand All @@ -14,8 +12,8 @@ impl TryFrom<i8> for MyStruct {

impl TryFrom<i16> for MyStruct {
//~^ infallible_try_from
type Error = Infallible;
fn try_from(other: i16) -> Result<Self, Infallible> {
type Error = !;
fn try_from(other: i16) -> Result<Self, !> {
Ok(Self(other.into()))
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/tools/clippy/tests/ui/infallible_try_from.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: infallible TryFrom impl; consider implementing From instead
--> tests/ui/infallible_try_from.rs:7:1
--> tests/ui/infallible_try_from.rs:5:1
|
LL | impl TryFrom<i8> for MyStruct {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand All @@ -11,13 +11,13 @@ LL | type Error = !;
= help: to override `-D warnings` add `#[allow(clippy::infallible_try_from)]`

error: infallible TryFrom impl; consider implementing From instead
--> tests/ui/infallible_try_from.rs:15:1
--> tests/ui/infallible_try_from.rs:13:1
|
LL | impl TryFrom<i16> for MyStruct {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL |
LL | type Error = Infallible;
| ---------- infallible error type
LL | type Error = !;
| - infallible error type

error: aborting due to 2 previous errors

12 changes: 10 additions & 2 deletions src/tools/clippy/tests/ui/let_underscore_must_use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,24 @@ fn main() {
let _ = a;
//~^ let_underscore_must_use

enum Uninhabited {}

#[allow(clippy::let_underscore_must_use)]
let _ = a;

// No lint because this type should behave as `()`
let _ = Result::<_, std::convert::Infallible>::Ok(());
let _ = Result::<_, !>::Ok(());

// No lint because this type should behave as `()`
let _ = Result::<_, Uninhabited>::Ok(());
#[must_use]
struct T;

// Lint because this type should behave as `T`
let _ = Result::<_, std::convert::Infallible>::Ok(T);
let _ = Result::<_, !>::Ok(T);
//~^ let_underscore_must_use

// Lint because this type should behave as `T`
let _ = Result::<_, Uninhabited>::Ok(T);
//~^ let_underscore_must_use
}
27 changes: 20 additions & 7 deletions src/tools/clippy/tests/ui/let_underscore_must_use.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,30 @@ LL | let _ = a;
| ^

error: non-binding `let` on an expression with `#[must_use]` type
--> tests/ui/let_underscore_must_use.rs:123:5
--> tests/ui/let_underscore_must_use.rs:127:5
|
LL | let _ = Result::<_, std::convert::Infallible>::Ok(T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | let _ = Result::<_, !>::Ok(T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider explicitly using expression value
note: type is `main::T` in a `Result` with an uninhabited error
--> tests/ui/let_underscore_must_use.rs:123:13
--> tests/ui/let_underscore_must_use.rs:127:13
|
LL | let _ = Result::<_, std::convert::Infallible>::Ok(T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | let _ = Result::<_, !>::Ok(T);
| ^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 14 previous errors
error: non-binding `let` on an expression with `#[must_use]` type
--> tests/ui/let_underscore_must_use.rs:131:5
|
LL | let _ = Result::<_, Uninhabited>::Ok(T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: consider explicitly using expression value
note: type is `main::T` in a `Result` with an uninhabited error
--> tests/ui/let_underscore_must_use.rs:131:13
|
LL | let _ = Result::<_, Uninhabited>::Ok(T);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 15 previous errors

2 changes: 1 addition & 1 deletion src/tools/clippy/tests/ui/manual_ok_err.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn no_lint() {
Ok(v) => Some(v),
};

let _ = match Ok::<_, std::convert::Infallible>(1) {
let _ = match Ok::<_, !>(1) {
Ok(3) => None,
Ok(v) => Some(v),
};
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/tests/ui/manual_ok_err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fn no_lint() {
Ok(v) => Some(v),
};

let _ = match Ok::<_, std::convert::Infallible>(1) {
let _ = match Ok::<_, !>(1) {
Ok(3) => None,
Ok(v) => Some(v),
};
Expand Down
17 changes: 15 additions & 2 deletions src/tools/clippy/tests/ui/must_use_candidates.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,30 @@ pub fn main() -> std::process::ExitCode {
std::process::ExitCode::SUCCESS
}

pub enum Uninhabited {}

//~v must_use_candidate
#[must_use]
pub fn result_uninhabited_1() -> Result<i32, Uninhabited> {
todo!()
}

//~v must_use_candidate
#[must_use]
pub fn result_uninhabited_1() -> Result<i32, std::convert::Infallible> {
pub fn result_never_1() -> Result<i32, !> {
todo!()
}

#[must_use]
pub struct T;

// Do not lint, `T` is `#[must_use]`, so the `Result<T, uninhabited>` also is.
pub fn result_uninhabited_2() -> Result<T, std::convert::Infallible> {
pub fn result_uninhabited_2() -> Result<T, Uninhabited> {
todo!()
}

// Do not lint, `T` is `#[must_use]`, so the `Result<T, uninhabited>` also is.
pub fn result_never_2() -> Result<T, !> {
todo!()
}

Expand Down
16 changes: 14 additions & 2 deletions src/tools/clippy/tests/ui/must_use_candidates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,28 @@ pub fn main() -> std::process::ExitCode {
std::process::ExitCode::SUCCESS
}

pub enum Uninhabited {}

//~v must_use_candidate
pub fn result_uninhabited_1() -> Result<i32, Uninhabited> {
todo!()
}

//~v must_use_candidate
pub fn result_uninhabited_1() -> Result<i32, std::convert::Infallible> {
pub fn result_never_1() -> Result<i32, !> {
todo!()
}

#[must_use]
pub struct T;

// Do not lint, `T` is `#[must_use]`, so the `Result<T, uninhabited>` also is.
pub fn result_uninhabited_2() -> Result<T, std::convert::Infallible> {
pub fn result_uninhabited_2() -> Result<T, Uninhabited> {
todo!()
}

// Do not lint, `T` is `#[must_use]`, so the `Result<T, uninhabited>` also is.
pub fn result_never_2() -> Result<T, !> {
todo!()
}

Expand Down
20 changes: 16 additions & 4 deletions src/tools/clippy/tests/ui/must_use_candidates.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,28 @@ LL | pub fn arcd(_x: Arc<u32>) -> bool {
|

error: this function could have a `#[must_use]` attribute
--> tests/ui/must_use_candidates.rs:101:8
--> tests/ui/must_use_candidates.rs:103:8
|
LL | pub fn result_uninhabited_1() -> Result<i32, std::convert::Infallible> {
LL | pub fn result_uninhabited_1() -> Result<i32, Uninhabited> {
| ^^^^^^^^^^^^^^^^^^^^
|
help: add the attribute
|
LL + #[must_use]
LL | pub fn result_uninhabited_1() -> Result<i32, std::convert::Infallible> {
LL | pub fn result_uninhabited_1() -> Result<i32, Uninhabited> {
|

error: aborting due to 6 previous errors
error: this function could have a `#[must_use]` attribute
--> tests/ui/must_use_candidates.rs:108:8
|
LL | pub fn result_never_1() -> Result<i32, !> {
| ^^^^^^^^^^^^^^
|
help: add the attribute
|
LL + #[must_use]
LL | pub fn result_never_1() -> Result<i32, !> {
|

error: aborting due to 7 previous errors

12 changes: 10 additions & 2 deletions src/tools/clippy/tests/ui/single_match_else.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,16 @@ fn main() {
//~| NOTE: you might want to preserve the comments from inside the `match`

// lint here
use std::convert::Infallible;
if let Ok(a) = Result::<i32, &Infallible>::Ok(1) { println!("${:?}", a) } else {
if let Ok(a) = Result::<i32, &!>::Ok(1) { println!("${:?}", a) } else {
println!("else block");
return;
}
//~^^^^^^^ single_match_else

enum Uninhabited {}

// lint here
if let Ok(a) = Result::<i32, &Uninhabited>::Ok(1) { println!("${:?}", a) } else {
println!("else block");
return;
}
Expand Down
15 changes: 13 additions & 2 deletions src/tools/clippy/tests/ui/single_match_else.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,19 @@ fn main() {
//~| NOTE: you might want to preserve the comments from inside the `match`

// lint here
use std::convert::Infallible;
match Result::<i32, &Infallible>::Ok(1) {
match Result::<i32, &!>::Ok(1) {
Ok(a) => println!("${:?}", a),
Err(_) => {
println!("else block");
return;
}
}
//~^^^^^^^ single_match_else

enum Uninhabited {}

// lint here
match Result::<i32, &Uninhabited>::Ok(1) {
Ok(a) => println!("${:?}", a),
Err(_) => {
println!("else block");
Expand Down
Loading
Loading