Skip to content

Commit 3d1996a

Browse files
committed
Add #[must_use] to From::from and Into::into
1 parent 86d6d2b commit 3d1996a

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

library/core/src/convert/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ pub trait AsMut<T: ?Sized> {
273273
#[stable(feature = "rust1", since = "1.0.0")]
274274
pub trait Into<T>: Sized {
275275
/// Performs the conversion.
276+
#[must_use]
276277
#[stable(feature = "rust1", since = "1.0.0")]
277278
fn into(self) -> T;
278279
}
@@ -367,6 +368,7 @@ pub trait Into<T>: Sized {
367368
pub trait From<T>: Sized {
368369
/// Performs the conversion.
369370
#[lang = "from"]
371+
#[must_use]
370372
#[stable(feature = "rust1", since = "1.0.0")]
371373
fn from(_: T) -> Self;
372374
}

src/test/ui/never_type/never-value-fallback-issue-66757.nofallback.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0277]: the trait bound `E: From<()>` is not satisfied
2-
--> $DIR/never-value-fallback-issue-66757.rs:27:5
2+
--> $DIR/never-value-fallback-issue-66757.rs:28:5
33
|
44
LL | <E as From<_>>::from(never);
55
| ^^^^^^^^^^^^^^^^^^^^ the trait `From<()>` is not implemented for `E`

src/test/ui/never_type/never-value-fallback-issue-66757.rs

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ impl From<!> for E {
2222

2323
#[allow(unreachable_code)]
2424
#[allow(dead_code)]
25+
#[allow(unused_must_use)]
2526
fn foo(never: !) {
2627
<E as From<!>>::from(never); // Ok
2728
<E as From<_>>::from(never); //[nofallback]~ ERROR trait bound `E: From<()>` is not satisfied

0 commit comments

Comments
 (0)