Skip to content

Commit 0804ef6

Browse files
authored
Rollup merge of #97458 - estebank:use-self-in-derive-macro, r=compiler-errors
Modify `derive(Debug)` to use `Self` in struct literal to avoid redundant error Reduce verbosity in #97343.
2 parents 29ac9b1 + f2a1b7b commit 0804ef6

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1039,7 +1039,9 @@ impl<'a> MethodDef<'a> {
10391039
let span = trait_.span;
10401040
let mut patterns = Vec::new();
10411041
for i in 0..self_args.len() {
1042-
let struct_path = cx.path(span, vec![type_ident]);
1042+
// We could use `type_ident` instead of `Self`, but in the case of a type parameter
1043+
// shadowing the struct name, that causes a second, unnecessary E0578 error. #97343
1044+
let struct_path = cx.path(span, vec![Ident::new(kw::SelfUpper, type_ident.span)]);
10431045
let (pat, ident_expr) = trait_.create_struct_pattern(
10441046
cx,
10451047
struct_path,

src/test/ui/derives/issue-97343.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use std::fmt::Debug;
2+
3+
#[derive(Debug)]
4+
pub struct Irrelevant<Irrelevant> { //~ ERROR type arguments are not allowed for this type
5+
irrelevant: Irrelevant,
6+
}
7+
8+
fn main() {}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0109]: type arguments are not allowed for this type
2+
--> $DIR/issue-97343.rs:4:23
3+
|
4+
LL | #[derive(Debug)]
5+
| ----- in this derive macro expansion
6+
LL | pub struct Irrelevant<Irrelevant> {
7+
| ^^^^^^^^^^ type argument not allowed
8+
|
9+
= note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0109`.

0 commit comments

Comments
 (0)