Skip to content
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

Remove impl of Allocator for &A #123213

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

workingjubilee
Copy link
Contributor

A T-opsem convo on Zulip pointed out that this is hard to optimize-out:

https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/abi.20compat.20of.20.26mut.20T.20and.20*mut.20T.20where.20T.20is.20a.20ZST/near/429718899

This impl merely existing makes the opt story around Allocated<T, A>, e.g. Vec<T, A>, Box<T, A>, etc. much worse. Now, there may be cases where we would want this pattern to be used but we can let implementors decide: We do not need to force everyone to be implicitly opted-into it.

A T-opsem convo on Zulip pointed out that this is hard to optimize-out:

https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/abi.20compat.20of.20.26mut.20T.20and.20*mut.20T.20where.20T.20is.20a.20ZST/near/429718899

This impl merely existing makes the opt story around `Allocated<T, A>`, e.g.
`Vec<T, A>`, `Box<T, A>`, etc. much worse. Now, there may be cases where we
would want this pattern to be used but we can let implementors decide:
We do not need to force everyone to be implicitly opted-into it.
@rustbot
Copy link
Collaborator

rustbot commented Mar 30, 2024

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 30, 2024
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-17 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
#16 exporting to docker image format
#16 sending tarball 31.5s done
#16 DONE 34.3s
##[endgroup]
Setting extra environment values for docker:  --env ENABLE_GCC_CODEGEN=1 --env GCC_EXEC_PREFIX=/usr/lib/gcc/
[CI_JOB_NAME=x86_64-gnu-llvm-17]
---
sccache: Starting the server...
##[group]Configure the build
configure: processing command line
configure: 
configure: build.configure-args := ['--build=x86_64-unknown-linux-gnu', '--llvm-root=/usr/lib/llvm-17', '--enable-llvm-link-shared', '--set', 'rust.thin-lto-import-instr-limit=10', '--set', 'change-id=99999999', '--enable-verbose-configure', '--enable-sccache', '--disable-manage-submodules', '--enable-locked-deps', '--enable-cargo-native-static', '--set', 'rust.codegen-units-std=1', '--set', 'dist.compression-profile=balanced', '--dist-compression-formats=xz', '--disable-dist-src', '--release-channel=nightly', '--enable-debug-assertions', '--enable-overflow-checks', '--enable-llvm-assertions', '--set', 'rust.verify-llvm-ir', '--set', 'rust.codegen-backends=llvm,cranelift,gcc', '--set', 'llvm.static-libstdcpp', '--enable-new-symbol-mangling']
configure: target.x86_64-unknown-linux-gnu.llvm-config := /usr/lib/llvm-17/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.thin-lto-import-instr-limit := 10
configure: change-id            := 99999999
---
   Compiling unwind v0.0.0 (/checkout/library/unwind)
error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
   --> library/alloc/src/collections/linked_list.rs:195:44
    |
195 |     fn pop_front_node(&mut self) -> Option<Box<Node<T>, &A>> {
    |                                            ^^^^^^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
    = help: the trait `core::alloc::Allocator` is implemented for `alloc::Global`
note: required by a bound in `Box`
   --> library/alloc/src/boxed.rs:198:64
    |
    |
196 | pub struct Box<
    |            --- required by a bound in this struct
197 |     T: ?Sized,
198 |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
   --> library/alloc/src/collections/linked_list.rs:240:43
    |
    |
240 |     fn pop_back_node(&mut self) -> Option<Box<Node<T>, &A>> {
    |                                           ^^^^^^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
    = help: the trait `core::alloc::Allocator` is implemented for `alloc::Global`
note: required by a bound in `Box`
   --> library/alloc/src/boxed.rs:198:64
    |
    |
196 | pub struct Box<
    |            --- required by a bound in this struct
197 |     T: ?Sized,
198 |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
    --> library/alloc/src/collections/linked_list.rs:199:56
     |
     |
199  |             let node = Box::from_raw_in(node.as_ptr(), &self.alloc);
     |                        ----------------                ^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
     |                        required by a bound introduced by this call
     |
note: required by a bound in `Box::<T, A>::from_raw_in`
    --> library/alloc/src/boxed.rs:956:20
    --> library/alloc/src/boxed.rs:956:20
     |
956  | impl<T: ?Sized, A: Allocator> Box<T, A> {
     |                    ^^^^^^^^^ required by this bound in `Box::<T, A>::from_raw_in`
...
1007 |     pub const unsafe fn from_raw_in(raw: *mut T, alloc: A) -> Self {
     |                         ----------- required by a bound in this associated function
help: consider removing the leading `&`-reference
     |
199  -             let node = Box::from_raw_in(node.as_ptr(), &self.alloc);
199  +             let node = Box::from_raw_in(node.as_ptr(), self.alloc);

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
   --> library/alloc/src/collections/linked_list.rs:199:24
    |
    |
199 |             let node = Box::from_raw_in(node.as_ptr(), &self.alloc);
    |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
    = help: the trait `core::alloc::Allocator` is implemented for `alloc::Global`
note: required by a bound in `Box`
   --> library/alloc/src/boxed.rs:198:64
    |
    |
196 | pub struct Box<
    |            --- required by a bound in this struct
197 |     T: ?Sized,
198 |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
   --> library/alloc/src/collections/linked_list.rs:198:9
    |
    |
198 | /         self.head.map(|node| unsafe {
199 | |             let node = Box::from_raw_in(node.as_ptr(), &self.alloc);
200 | |             self.head = node.next;
...   |
209 | |             node
210 | |         })
    | |__________^ the trait `core::alloc::Allocator` is not implemented for `&A`
    | |__________^ the trait `core::alloc::Allocator` is not implemented for `&A`
    |
    = help: the trait `core::alloc::Allocator` is implemented for `alloc::Global`
note: required by a bound in `Box`
   --> library/alloc/src/boxed.rs:198:64
    |
196 | pub struct Box<
    |            --- required by a bound in this struct
197 |     T: ?Sized,
198 |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
    --> library/alloc/src/collections/linked_list.rs:244:56
     |
     |
244  |             let node = Box::from_raw_in(node.as_ptr(), &self.alloc);
     |                        ----------------                ^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
     |                        required by a bound introduced by this call
     |
note: required by a bound in `Box::<T, A>::from_raw_in`
    --> library/alloc/src/boxed.rs:956:20
    --> library/alloc/src/boxed.rs:956:20
     |
956  | impl<T: ?Sized, A: Allocator> Box<T, A> {
     |                    ^^^^^^^^^ required by this bound in `Box::<T, A>::from_raw_in`
...
1007 |     pub const unsafe fn from_raw_in(raw: *mut T, alloc: A) -> Self {
     |                         ----------- required by a bound in this associated function
help: consider removing the leading `&`-reference
     |
244  -             let node = Box::from_raw_in(node.as_ptr(), &self.alloc);
244  +             let node = Box::from_raw_in(node.as_ptr(), self.alloc);

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
   --> library/alloc/src/collections/linked_list.rs:244:24
    |
    |
244 |             let node = Box::from_raw_in(node.as_ptr(), &self.alloc);
    |                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
    = help: the trait `core::alloc::Allocator` is implemented for `alloc::Global`
note: required by a bound in `Box`
   --> library/alloc/src/boxed.rs:198:64
    |
    |
196 | pub struct Box<
    |            --- required by a bound in this struct
197 |     T: ?Sized,
198 |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
   --> library/alloc/src/collections/linked_list.rs:243:9
    |
    |
243 | /         self.tail.map(|node| unsafe {
244 | |             let node = Box::from_raw_in(node.as_ptr(), &self.alloc);
245 | |             self.tail = node.prev;
...   |
254 | |             node
255 | |         })
    | |__________^ the trait `core::alloc::Allocator` is not implemented for `&A`
    | |__________^ the trait `core::alloc::Allocator` is not implemented for `&A`
    |
    = help: the trait `core::alloc::Allocator` is implemented for `alloc::Global`
note: required by a bound in `Box`
   --> library/alloc/src/boxed.rs:198:64
    |
196 | pub struct Box<
    |            --- required by a bound in this struct
197 |     T: ?Sized,
198 |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
   --> library/alloc/src/collections/linked_list.rs:689:14
    |
---
   --> library/alloc/src/collections/linked_list.rs:53:64
    |
51  | pub struct LinkedList<
    |            ---------- required by a bound in this struct
52  |     T,
53  |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
   --> library/alloc/src/collections/linked_list.rs:694:21
    |
---
   --> library/alloc/src/boxed.rs:198:64
    |
196 | pub struct Box<
    |            --- required by a bound in this struct
197 |     T: ?Sized,
198 |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
   --> library/alloc/src/collections/linked_list.rs:689:9
    |
---
   --> library/alloc/src/collections/linked_list.rs:53:64
    |
51  | pub struct LinkedList<
    |            ---------- required by a bound in this struct
52  |     T,
53  |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
   --> library/alloc/src/collections/linked_list.rs:848:48
    |
    |
848 |         let node = Box::new_in(Node::new(elt), &self.alloc);
    |                    -----------                 ^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
    |                    required by a bound introduced by this call
    |
note: required by a bound in `Box::<T, A>::new_in`
   --> library/alloc/src/boxed.rs:361:12
   --> library/alloc/src/boxed.rs:361:12
    |
361 | impl<T, A: Allocator> Box<T, A> {
    |            ^^^^^^^^^ required by this bound in `Box::<T, A>::new_in`
...
379 |     pub fn new_in(x: T, alloc: A) -> Self
    |            ------ required by a bound in this associated function
help: consider removing the leading `&`-reference
    |
848 -         let node = Box::new_in(Node::new(elt), &self.alloc);
848 +         let node = Box::new_in(Node::new(elt), self.alloc);

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
   --> library/alloc/src/collections/linked_list.rs:848:20
    |
    |
848 |         let node = Box::new_in(Node::new(elt), &self.alloc);
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
    = help: the trait `core::alloc::Allocator` is implemented for `alloc::Global`
note: required by a bound in `Box`
   --> library/alloc/src/boxed.rs:198:64
    |
    |
196 | pub struct Box<
    |            --- required by a bound in this struct
197 |     T: ?Sized,
198 |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
   --> library/alloc/src/collections/linked_list.rs:849:48
    |
---

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
   --> library/alloc/src/collections/linked_list.rs:877:14
    |
877 |         self.pop_front_node().map(Node::into_element)
    |              ^^^^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
    = help: the trait `core::alloc::Allocator` is implemented for `alloc::Global`
note: required by a bound in `Box`
   --> library/alloc/src/boxed.rs:198:64
    |
    |
196 | pub struct Box<
    |            --- required by a bound in this struct
197 |     T: ?Sized,
198 |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
   --> library/alloc/src/collections/linked_list.rs:877:9
    |
    |
877 |         self.pop_front_node().map(Node::into_element)
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
    = help: the trait `core::alloc::Allocator` is implemented for `alloc::Global`
note: required by a bound in `Box`
   --> library/alloc/src/boxed.rs:198:64
    |
    |
196 | pub struct Box<
    |            --- required by a bound in this struct
197 |     T: ?Sized,
198 |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
   --> library/alloc/src/collections/linked_list.rs:877:35
    |
    |
877 |         self.pop_front_node().map(Node::into_element)
    |                                   ^^^^^^^^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
    = help: the trait `core::alloc::Allocator` is implemented for `alloc::Global`
note: required by a bound in `Node::<T>::into_element`
   --> library/alloc/src/collections/linked_list.rs:161:24
    |
    |
161 |     fn into_element<A: Allocator>(self: Box<Self, A>) -> T {
    |                        ^^^^^^^^^ required by this bound in `Node::<T>::into_element`
error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
   --> library/alloc/src/collections/linked_list.rs:897:48
    |
    |
897 |         let node = Box::new_in(Node::new(elt), &self.alloc);
    |                    -----------                 ^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
    |                    required by a bound introduced by this call
    |
note: required by a bound in `Box::<T, A>::new_in`
   --> library/alloc/src/boxed.rs:361:12
   --> library/alloc/src/boxed.rs:361:12
    |
361 | impl<T, A: Allocator> Box<T, A> {
    |            ^^^^^^^^^ required by this bound in `Box::<T, A>::new_in`
...
379 |     pub fn new_in(x: T, alloc: A) -> Self
    |            ------ required by a bound in this associated function
help: consider removing the leading `&`-reference
    |
897 -         let node = Box::new_in(Node::new(elt), &self.alloc);
897 +         let node = Box::new_in(Node::new(elt), self.alloc);

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
   --> library/alloc/src/collections/linked_list.rs:897:20
    |
    |
897 |         let node = Box::new_in(Node::new(elt), &self.alloc);
    |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
    = help: the trait `core::alloc::Allocator` is implemented for `alloc::Global`
note: required by a bound in `Box`
   --> library/alloc/src/boxed.rs:198:64
    |
    |
196 | pub struct Box<
    |            --- required by a bound in this struct
197 |     T: ?Sized,
198 |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
   --> library/alloc/src/collections/linked_list.rs:898:48
    |
---

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
   --> library/alloc/src/collections/linked_list.rs:923:14
    |
923 |         self.pop_back_node().map(Node::into_element)
    |              ^^^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
    = help: the trait `core::alloc::Allocator` is implemented for `alloc::Global`
note: required by a bound in `Box`
   --> library/alloc/src/boxed.rs:198:64
    |
    |
196 | pub struct Box<
    |            --- required by a bound in this struct
197 |     T: ?Sized,
198 |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
   --> library/alloc/src/collections/linked_list.rs:923:9
    |
    |
923 |         self.pop_back_node().map(Node::into_element)
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
    = help: the trait `core::alloc::Allocator` is implemented for `alloc::Global`
note: required by a bound in `Box`
   --> library/alloc/src/boxed.rs:198:64
    |
    |
196 | pub struct Box<
    |            --- required by a bound in this struct
197 |     T: ?Sized,
198 |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
   --> library/alloc/src/collections/linked_list.rs:923:34
    |
    |
923 |         self.pop_back_node().map(Node::into_element)
    |                                  ^^^^^^^^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
    = help: the trait `core::alloc::Allocator` is implemented for `alloc::Global`
note: required by a bound in `Node::<T>::into_element`
   --> library/alloc/src/collections/linked_list.rs:161:24
    |
    |
161 |     fn into_element<A: Allocator>(self: Box<Self, A>) -> T {
    |                        ^^^^^^^^^ required by this bound in `Node::<T>::into_element`
error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
    --> library/alloc/src/collections/linked_list.rs:1184:23
     |
     |
1184 |         while guard.0.pop_front_node().is_some() {}
     |                       ^^^^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
     = help: the trait `core::alloc::Allocator` is implemented for `alloc::Global`
note: required by a bound in `Box`
    --> library/alloc/src/boxed.rs:198:64
     |
     |
196  | pub struct Box<
     |            --- required by a bound in this struct
197  |     T: ?Sized,
198  |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
    --> library/alloc/src/collections/linked_list.rs:1184:15
     |
     |
1184 |         while guard.0.pop_front_node().is_some() {}
     |               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
     = help: the trait `core::alloc::Allocator` is implemented for `alloc::Global`
note: required by a bound in `Box`
    --> library/alloc/src/boxed.rs:198:64
     |
     |
196  | pub struct Box<
     |            --- required by a bound in this struct
197  |     T: ?Sized,
198  |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
    --> library/alloc/src/collections/linked_list.rs:1178:30
     |
     |
1178 |                 while self.0.pop_front_node().is_some() {}
     |                              ^^^^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
     = help: the trait `core::alloc::Allocator` is implemented for `alloc::Global`
note: required by a bound in `Box`
    --> library/alloc/src/boxed.rs:198:64
     |
     |
196  | pub struct Box<
     |            --- required by a bound in this struct
197  |     T: ?Sized,
198  |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
    --> library/alloc/src/collections/linked_list.rs:1178:23
     |
     |
1178 |                 while self.0.pop_front_node().is_some() {}
     |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
     = help: the trait `core::alloc::Allocator` is implemented for `alloc::Global`
note: required by a bound in `Box`
    --> library/alloc/src/boxed.rs:198:64
     |
     |
196  | pub struct Box<
     |            --- required by a bound in this struct
197  |     T: ?Sized,
198  |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
    --> library/alloc/src/collections/linked_list.rs:1665:71
     |
     |
1665 |             let spliced_node = Box::leak(Box::new_in(Node::new(item), &self.list.alloc)).into();
     |                                          -----------                  ^^^^^^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
     |                                          required by a bound introduced by this call
     |
note: required by a bound in `Box::<T, A>::new_in`
    --> library/alloc/src/boxed.rs:361:12
    --> library/alloc/src/boxed.rs:361:12
     |
361  | impl<T, A: Allocator> Box<T, A> {
     |            ^^^^^^^^^ required by this bound in `Box::<T, A>::new_in`
...
379  |     pub fn new_in(x: T, alloc: A) -> Self
     |            ------ required by a bound in this associated function
help: consider removing the leading `&`-reference
     |
1665 -             let spliced_node = Box::leak(Box::new_in(Node::new(item), &self.list.alloc)).into();
1665 +             let spliced_node = Box::leak(Box::new_in(Node::new(item), self.list.alloc)).into();

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
    --> library/alloc/src/collections/linked_list.rs:1665:42
     |
     |
1665 |             let spliced_node = Box::leak(Box::new_in(Node::new(item), &self.list.alloc)).into();
     |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
     = help: the trait `core::alloc::Allocator` is implemented for `alloc::Global`
note: required by a bound in `Box`
    --> library/alloc/src/boxed.rs:198:64
     |
     |
196  | pub struct Box<
     |            --- required by a bound in this struct
197  |     T: ?Sized,
198  |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
    --> library/alloc/src/collections/linked_list.rs:1685:71
     |
     |
1685 |             let spliced_node = Box::leak(Box::new_in(Node::new(item), &self.list.alloc)).into();
     |                                          -----------                  ^^^^^^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
     |                                          required by a bound introduced by this call
     |
note: required by a bound in `Box::<T, A>::new_in`
    --> library/alloc/src/boxed.rs:361:12
    --> library/alloc/src/boxed.rs:361:12
     |
361  | impl<T, A: Allocator> Box<T, A> {
     |            ^^^^^^^^^ required by this bound in `Box::<T, A>::new_in`
...
379  |     pub fn new_in(x: T, alloc: A) -> Self
     |            ------ required by a bound in this associated function
help: consider removing the leading `&`-reference
     |
1685 -             let spliced_node = Box::leak(Box::new_in(Node::new(item), &self.list.alloc)).into();
1685 +             let spliced_node = Box::leak(Box::new_in(Node::new(item), self.list.alloc)).into();

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
    --> library/alloc/src/collections/linked_list.rs:1685:42
     |
     |
1685 |             let spliced_node = Box::leak(Box::new_in(Node::new(item), &self.list.alloc)).into();
     |                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
     = help: the trait `core::alloc::Allocator` is implemented for `alloc::Global`
note: required by a bound in `Box`
    --> library/alloc/src/boxed.rs:198:64
     |
     |
196  | pub struct Box<
     |            --- required by a bound in this struct
197  |     T: ?Sized,
198  |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
    --> library/alloc/src/rc.rs:1995:75
     |
     |
1995 |             let src = Box::from_raw_in(bptr as *mut mem::ManuallyDrop<T>, alloc.by_ref());
     |                       ----------------                                    ^^^^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
     |                       required by a bound introduced by this call
     |
     = help: the trait `core::alloc::Allocator` is implemented for `alloc::Global`
note: required by a bound in `Box::<T, A>::from_raw_in`
note: required by a bound in `Box::<T, A>::from_raw_in`
    --> library/alloc/src/boxed.rs:956:20
     |
956  | impl<T: ?Sized, A: Allocator> Box<T, A> {
     |                    ^^^^^^^^^ required by this bound in `Box::<T, A>::from_raw_in`
...
1007 |     pub const unsafe fn from_raw_in(raw: *mut T, alloc: A) -> Self {
     |                         ----------- required by a bound in this associated function
help: consider removing this method call, as the receiver has type `A` and `A: core::alloc::Allocator` trivially holds
     |
1995 -             let src = Box::from_raw_in(bptr as *mut mem::ManuallyDrop<T>, alloc.by_ref());
1995 +             let src = Box::from_raw_in(bptr as *mut mem::ManuallyDrop<T>, alloc);

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
    --> library/alloc/src/rc.rs:1995:23
     |
     |
1995 |             let src = Box::from_raw_in(bptr as *mut mem::ManuallyDrop<T>, alloc.by_ref());
     |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
     = help: the trait `core::alloc::Allocator` is implemented for `alloc::Global`
note: required by a bound in `Box`
    --> library/alloc/src/boxed.rs:198:64
     |
     |
196  | pub struct Box<
     |            --- required by a bound in this struct
197  |     T: ?Sized,
198  |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
    --> library/alloc/src/rc.rs:1996:13
     |
---
    --> library/alloc/src/boxed.rs:198:64
     |
196  | pub struct Box<
     |            --- required by a bound in this struct
197  |     T: ?Sized,
198  |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
    --> library/alloc/src/rc.rs:2607:61
     |
     |
2607 |             let _ = Vec::from_raw_parts_in(vec_ptr, 0, cap, &alloc);
     |                     ----------------------                  ^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
     |                     required by a bound introduced by this call
     |
     |
note: required by a bound in `Vec::<T, A>::from_raw_parts_in`
     |
     |
608  | impl<T, A: Allocator> Vec<T, A> {
     |            ^^^^^^^^^ required by this bound in `Vec::<T, A>::from_raw_parts_in`
...
819  |     pub unsafe fn from_raw_parts_in(ptr: *mut T, length: usize, capacity: usize, alloc: A) -> Self {
     |                   ----------------- required by a bound in this associated function
help: consider removing the leading `&`-reference
     |
2607 -             let _ = Vec::from_raw_parts_in(vec_ptr, 0, cap, &alloc);
2607 +             let _ = Vec::from_raw_parts_in(vec_ptr, 0, cap, alloc);

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
    --> library/alloc/src/rc.rs:2607:21
     |
     |
2607 |             let _ = Vec::from_raw_parts_in(vec_ptr, 0, cap, &alloc);
     |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
     = help: the trait `core::alloc::Allocator` is implemented for `alloc::Global`
note: required by a bound in `Vec`
    --> library/alloc/src/vec/mod.rs:398:78
     |
     |
398  | pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
     |                                                                              ^^^^^^^^^ required by this bound in `Vec`
error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
    --> library/alloc/src/sync.rs:1810:43
     |
     |
1810 |         drop(Weak { ptr: self.ptr, alloc: &self.alloc });
     |                                           ^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
note: required by a bound in `sync::Weak`
    --> library/alloc/src/sync.rs:323:64
     |
321  | pub struct Weak<
321  | pub struct Weak<
     |            ---- required by a bound in this struct
322  |     T: ?Sized,
323  |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
     |                                                                ^^^^^^^^^ required by this bound in `Weak`
help: consider removing the leading `&`-reference
     |
1810 -         drop(Weak { ptr: self.ptr, alloc: &self.alloc });
1810 +         drop(Weak { ptr: self.ptr, alloc: self.alloc });

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
    --> library/alloc/src/sync.rs:1810:9
     |
     |
1810 |         drop(Weak { ptr: self.ptr, alloc: &self.alloc });
     |         ^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
     = help: the trait `core::alloc::Allocator` is implemented for `alloc::Global`
note: required by a bound in `sync::Weak`
    --> library/alloc/src/sync.rs:323:64
     |
     |
321  | pub struct Weak<
     |            ---- required by a bound in this struct
322  |     T: ?Sized,
323  |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
     |                                                                ^^^^^^^^^ required by this bound in `Weak`
error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
    --> library/alloc/src/sync.rs:1924:75
     |
     |
1924 |             let src = Box::from_raw_in(bptr as *mut mem::ManuallyDrop<T>, alloc.by_ref());
     |                       ----------------                                    ^^^^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
     |                       required by a bound introduced by this call
     |
     = help: the trait `core::alloc::Allocator` is implemented for `alloc::Global`
note: required by a bound in `Box::<T, A>::from_raw_in`
note: required by a bound in `Box::<T, A>::from_raw_in`
    --> library/alloc/src/boxed.rs:956:20
     |
956  | impl<T: ?Sized, A: Allocator> Box<T, A> {
     |                    ^^^^^^^^^ required by this bound in `Box::<T, A>::from_raw_in`
...
1007 |     pub const unsafe fn from_raw_in(raw: *mut T, alloc: A) -> Self {
     |                         ----------- required by a bound in this associated function
help: consider removing this method call, as the receiver has type `A` and `A: core::alloc::Allocator` trivially holds
     |
1924 -             let src = Box::from_raw_in(bptr as *mut mem::ManuallyDrop<T>, alloc.by_ref());
1924 +             let src = Box::from_raw_in(bptr as *mut mem::ManuallyDrop<T>, alloc);

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
    --> library/alloc/src/sync.rs:1924:23
     |
     |
1924 |             let src = Box::from_raw_in(bptr as *mut mem::ManuallyDrop<T>, alloc.by_ref());
     |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
     = help: the trait `core::alloc::Allocator` is implemented for `alloc::Global`
note: required by a bound in `Box`
    --> library/alloc/src/boxed.rs:198:64
     |
     |
196  | pub struct Box<
     |            --- required by a bound in this struct
197  |     T: ?Sized,
198  |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
    --> library/alloc/src/sync.rs:1925:13
     |
---
    --> library/alloc/src/boxed.rs:198:64
     |
196  | pub struct Box<
     |            --- required by a bound in this struct
197  |     T: ?Sized,
198  |     #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
    --> library/alloc/src/sync.rs:3442:61
     |
     |
3442 |             let _ = Vec::from_raw_parts_in(vec_ptr, 0, cap, &alloc);
     |                     ----------------------                  ^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
     |                     required by a bound introduced by this call
     |
     |
note: required by a bound in `Vec::<T, A>::from_raw_parts_in`
     |
     |
608  | impl<T, A: Allocator> Vec<T, A> {
     |            ^^^^^^^^^ required by this bound in `Vec::<T, A>::from_raw_parts_in`
...
819  |     pub unsafe fn from_raw_parts_in(ptr: *mut T, length: usize, capacity: usize, alloc: A) -> Self {
     |                   ----------------- required by a bound in this associated function
help: consider removing the leading `&`-reference
     |
3442 -             let _ = Vec::from_raw_parts_in(vec_ptr, 0, cap, &alloc);
3442 +             let _ = Vec::from_raw_parts_in(vec_ptr, 0, cap, alloc);

error[E0277]: the trait bound `&A: core::alloc::Allocator` is not satisfied
    --> library/alloc/src/sync.rs:3442:21
     |
     |
3442 |             let _ = Vec::from_raw_parts_in(vec_ptr, 0, cap, &alloc);
     |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `core::alloc::Allocator` is not implemented for `&A`
     = help: the trait `core::alloc::Allocator` is implemented for `alloc::Global`
note: required by a bound in `Vec`
    --> library/alloc/src/vec/mod.rs:398:78
     |
     |
398  | pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
     |                                                                              ^^^^^^^^^ required by this bound in `Vec`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `alloc` (lib) due to 43 previous errors
warning: build failed, waiting for other jobs to finish...
Build completed unsuccessfully in 0:00:11

@workingjubilee workingjubilee marked this pull request as draft March 30, 2024 00:36
@workingjubilee
Copy link
Contributor Author

didn't realize we actually depended on this lmao.

@Mark-Simulacrum
Copy link
Member

The PR description doesn't seem accurate to me. This impl existing or not doesn't by itself make things harder to optimize - the problem is rather that allocators are not bounded by : Copy and lack a way to get a ZST handle if that's possible for that type. This impl just makes it easier to accidentally pass an Allocator that's a ZST by reference instead of by copy which does make things needlessly slower.

I think the right solution is something like a fn alloc_ref(&mut self) -> Self::Handle<'_> on Allocator that lets you cheaply get a ZST handle...

@workingjubilee
Copy link
Contributor Author

yeah I probably should've said something like "makes it easier to deoptimize your own code by mistake".

@RalfJung
Copy link
Member

Cc #98232

@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants