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

Modify derive(Debug) to use Self in struct literal to avoid redundant error #97458

Merged
merged 2 commits into from
May 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1039,7 +1039,9 @@ impl<'a> MethodDef<'a> {
let span = trait_.span;
let mut patterns = Vec::new();
for i in 0..self_args.len() {
let struct_path = cx.path(span, vec![type_ident]);
// We could use `type_ident` instead of `Self`, but in the case of a type parameter
// shadowing the struct name, that causes a second, unnecessary E0578 error. #97343
let struct_path = cx.path(span, vec![Ident::new(kw::SelfUpper, type_ident.span)]);
let (pat, ident_expr) = trait_.create_struct_pattern(
cx,
struct_path,
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/derives/issue-97343.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use std::fmt::Debug;

#[derive(Debug)]
pub struct Irrelevant<Irrelevant> { //~ ERROR type arguments are not allowed for this type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, this error message is very confusing imo. I guess that's not necessarily the purpose of this PR.
r=me anyways.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leaving #97343 open to both address that (I think a new error code is warranted) and potentially make the macro smarter to make this code work in the first place.

irrelevant: Irrelevant,
}

fn main() {}
13 changes: 13 additions & 0 deletions src/test/ui/derives/issue-97343.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
error[E0109]: type arguments are not allowed for this type
--> $DIR/issue-97343.rs:4:23
|
LL | #[derive(Debug)]
| ----- in this derive macro expansion
LL | pub struct Irrelevant<Irrelevant> {
| ^^^^^^^^^^ type argument not allowed
|
= note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0109`.