Skip to content

Commit

Permalink
Rollup merge of rust-lang#89770 - jkugelman:must-use-from-and-into, r…
Browse files Browse the repository at this point in the history
…=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`
  • Loading branch information
matthiaskrgr authored Oct 11, 2021
2 parents 817ccb7 + 3d1996a commit 18730a2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions library/core/src/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ pub trait AsMut<T: ?Sized> {
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Into<T>: Sized {
/// Performs the conversion.
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
fn into(self) -> T;
}
Expand Down Expand Up @@ -367,6 +368,7 @@ pub trait Into<T>: Sized {
pub trait From<T>: Sized {
/// Performs the conversion.
#[lang = "from"]
#[must_use]
#[stable(feature = "rust1", since = "1.0.0")]
fn from(_: T) -> Self;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0277]: the trait bound `E: From<()>` is not satisfied
--> $DIR/never-value-fallback-issue-66757.rs:27:5
--> $DIR/never-value-fallback-issue-66757.rs:28:5
|
LL | <E as From<_>>::from(never);
| ^^^^^^^^^^^^^^^^^^^^ the trait `From<()>` is not implemented for `E`
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/never_type/never-value-fallback-issue-66757.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ impl From<!> for E {

#[allow(unreachable_code)]
#[allow(dead_code)]
#[allow(unused_must_use)]
fn foo(never: !) {
<E as From<!>>::from(never); // Ok
<E as From<_>>::from(never); //[nofallback]~ ERROR trait bound `E: From<()>` is not satisfied
Expand Down

0 comments on commit 18730a2

Please sign in to comment.