Closed
Description
I tried this code:
#[derive(Debug)]
pub struct Foo<T>(pub T);
impl<T> Access for T {}
pub trait Access {
fn field<N, T, Name: 'static>(&self) -> &T {
todo!()
}
fn field_mut<N, T, Name: 'static>(&mut self) -> &mut T {
todo!()
}
fn take_field<N, T, Name>(self) {
todo!()
}
}
I expected it to compile, but it doesn't because the Debug
macro expands to something like foo.field("field_name", &value)
, which incorrectly resolves to Access::field
instead of DebugTuple::field
(which is an inherent method).
error message
error[E0061]: this function takes 0 arguments but 1 argument was supplied
--> src/lib.rs:1:10
|
1 | #[derive(Debug)]
| ^^^^^ expected 0 arguments
2 | pub struct Foo<T>(pub T);
| ----- supplied 1 argument
|
note: associated function defined here
--> src/lib.rs:6:8
|
6 | fn field<N, T, Name: 'static>(&self) -> &T {
| ^^^^^ -----
= note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the size for values of type `Self` cannot be known at compilation time
--> src/lib.rs:14:31
|
14 | fn take_field<N, T, Name>(self) {
| ^^^^ doesn't have a size known at compile-time
|
= help: unsized fn params are gated as an unstable feature
help: consider further restricting `Self`
|
14 | fn take_field<N, T, Name>(self) where Self: Sized {
| ^^^^^^^^^^^^^^^^^
help: function arguments must have a statically known size, borrowed types always have a known size
|
14 | fn take_field<N, T, Name>(&self) {
| ^
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0061, E0277.
For more information about an error, try `rustc --explain E0061`.
error: could not compile `playground`
To learn more, run the command again with --verbose.
Metadata
Metadata
Assignees
Labels
Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Category: This is a bug.Call for participation: An issue has been fixed and does not reproduce, but no test has been added.Relevant to the compiler team, which will review and decide on the PR/issue.Performance or correctness regression from one stable version to another.