Skip to content

Commit 18730a2

Browse files
authored
Rollup merge of rust-lang#89770 - jkugelman:must-use-from-and-into, r=joshtriplett
Add #[must_use] to From::from and Into::into Risk of churn: **High** Magic 8-Ball says: **Outlook not so good** I figured I'd put this out there. If we don't do it now maybe we save it for a rainy day. Parent issue: rust-lang#89692 r? `@joshtriplett`
2 parents 817ccb7 + 3d1996a commit 18730a2

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

library/core/src/convert/mod.rs

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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)