-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
delegation: add support for wrapping of the return value with From::from
#160433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rust-bors
merged 1 commit into
rust-lang:main
from
aerooneqq:delegation-return-wrapping-3
Aug 8, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -456,6 +456,7 @@ language_item_table! { | |
|
|
||
| // Used to fallback `{float}` to `f32` when `f32: From<{float}>` | ||
| From, sym::From, from_trait, Target::Trait, GenericRequirement::Exact(1); | ||
| FromFn, sym::from, from_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I expected this to already be used by AST lowering, but apparently all the operators were migrated to other more specific trait methods like |
||
| } | ||
|
|
||
| /// The requirement imposed on the generics of a lang item | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
tests/ui/delegation/self-mapping-output-from-wrap-errors.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| #![feature(fn_delegation)] | ||
|
|
||
| mod pin_box_self { | ||
| use std::pin::Pin; | ||
|
|
||
| trait MyAdd { | ||
| fn add(self, other: Self) -> Pin<Box<Self>>; | ||
| } | ||
|
|
||
| impl MyAdd for usize { | ||
| fn add(self, other: usize) -> Pin<Box<usize>> { | ||
| Pin::new(Box::new(self + other)) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Eq, PartialEq, Debug)] | ||
| struct W(Pin<Box<usize>>); | ||
|
|
||
| reuse impl MyAdd for W { | ||
| //~^ ERROR: the trait bound `Pin<Box<pin_box_self::W>>: From<pin_box_self::W>` is not satisfied | ||
| *self.0 | ||
| } | ||
| } | ||
|
|
||
| mod many_froms { | ||
| use std::sync::Arc; | ||
| use std::rc::Rc; | ||
|
|
||
| trait MyAdd { | ||
| fn add(self, other: Self) -> Box<Box<Box<Arc<Box<Rc<Self>>>>>>; | ||
| } | ||
|
|
||
| impl MyAdd for usize { | ||
| fn add(self, other: usize) -> Box<Box<Box<Arc<Box<Rc<usize>>>>>> { | ||
| Box::new(Box::new(Box::new(Arc::new(Box::new(Rc::new(self + other)))))) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Eq, PartialEq, Debug)] | ||
| struct W(Box<Box<Box<Arc<Box<Rc<usize>>>>>>); | ||
|
|
||
| reuse impl MyAdd for W { | ||
| //~^ ERROR: the trait bound `Box<Box<Box<Arc<Box<Rc<many_froms::W>>>>>>: From<many_froms::W>` is not satisfied | ||
| ******self.0 | ||
| } | ||
| } | ||
|
|
||
| mod many_froms_2 { | ||
| use std::sync::Arc; | ||
| use std::rc::Rc; | ||
|
|
||
| trait MyAdd { | ||
| fn add(self, other: Self) -> Box<Arc<Rc<Box<Rc<Self>>>>>; | ||
| } | ||
|
|
||
| impl MyAdd for usize { | ||
| fn add(self, other: usize) -> Box<Arc<Rc<Box<Rc<usize>>>>> { | ||
| Box::new(Arc::new(Rc::new(Box::new(Rc::new(self + other))))) | ||
| } | ||
| } | ||
|
|
||
| #[derive(Eq, PartialEq, Debug)] | ||
| struct W(Box<Arc<Rc<Box<Rc<usize>>>>>); | ||
|
|
||
| reuse impl MyAdd for W { | ||
| //~^ ERROR: the trait bound `Box<Arc<Rc<Box<Rc<many_froms_2::W>>>>>: From<many_froms_2::W>` is not satisfied | ||
| *****self.0 | ||
| } | ||
| } | ||
|
|
||
| fn main() { | ||
| } |
57 changes: 57 additions & 0 deletions
57
tests/ui/delegation/self-mapping-output-from-wrap-errors.stderr
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| error[E0277]: the trait bound `Pin<Box<pin_box_self::W>>: From<pin_box_self::W>` is not satisfied | ||
| --> $DIR/self-mapping-output-from-wrap-errors.rs:19:5 | ||
| | | ||
| LL | / reuse impl MyAdd for W { | ||
| LL | | | ||
| LL | | *self.0 | ||
| LL | | } | ||
| | |_____^ the trait `From<pin_box_self::W>` is not implemented for `Pin<Box<pin_box_self::W>>` | ||
| | | ||
| help: the trait `From<W>` is not implemented for `Pin<Box<pin_box_self::W>>` | ||
| but trait `From<Box<W>>` is implemented for it | ||
| --> $SRC_DIR/alloc/src/boxed/convert.rs:LL:COL | ||
| = help: for that trait implementation, expected `Box<pin_box_self::W>`, found `pin_box_self::W` | ||
|
|
||
| error[E0277]: the trait bound `Box<Box<Box<Arc<Box<Rc<many_froms::W>>>>>>: From<many_froms::W>` is not satisfied | ||
| --> $DIR/self-mapping-output-from-wrap-errors.rs:42:5 | ||
| | | ||
| LL | / reuse impl MyAdd for W { | ||
| LL | | | ||
| LL | | ******self.0 | ||
| LL | | } | ||
| | |_____^ the trait `From<many_froms::W>` is not implemented for `Box<Box<Box<Arc<Box<Rc<many_froms::W>>>>>>` | ||
| | | ||
| = help: the following other types implement trait `From<T>`: | ||
| `Box<ByteStr>` implements `From<Box<[u8]>>` | ||
| `Box<CStr>` implements `From<&CStr>` | ||
| `Box<CStr>` implements `From<&mut CStr>` | ||
| `Box<CStr>` implements `From<CString>` | ||
| `Box<CStr>` implements `From<Cow<'_, CStr>>` | ||
| `Box<OsStr>` implements `From<&OsStr>` | ||
| `Box<OsStr>` implements `From<&mut OsStr>` | ||
| `Box<OsStr>` implements `From<Cow<'_, OsStr>>` | ||
| and 25 others | ||
|
|
||
| error[E0277]: the trait bound `Box<Arc<Rc<Box<Rc<many_froms_2::W>>>>>: From<many_froms_2::W>` is not satisfied | ||
| --> $DIR/self-mapping-output-from-wrap-errors.rs:65:5 | ||
| | | ||
| LL | / reuse impl MyAdd for W { | ||
| LL | | | ||
| LL | | *****self.0 | ||
| LL | | } | ||
| | |_____^ the trait `From<many_froms_2::W>` is not implemented for `Box<Arc<Rc<Box<Rc<many_froms_2::W>>>>>` | ||
| | | ||
| = help: the following other types implement trait `From<T>`: | ||
| `Box<ByteStr>` implements `From<Box<[u8]>>` | ||
| `Box<CStr>` implements `From<&CStr>` | ||
| `Box<CStr>` implements `From<&mut CStr>` | ||
| `Box<CStr>` implements `From<CString>` | ||
| `Box<CStr>` implements `From<Cow<'_, CStr>>` | ||
| `Box<OsStr>` implements `From<&OsStr>` | ||
| `Box<OsStr>` implements `From<&mut OsStr>` | ||
| `Box<OsStr>` implements `From<Cow<'_, OsStr>>` | ||
| and 25 others | ||
|
|
||
| error: aborting due to 3 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0277`. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.