Skip to content

Commit 8b71323

Browse files
committed
Add test for const "equivalent"
1 parent ab57d60 commit 8b71323

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed

tests/ui/structs/manual-default-impl-could-be-derived.fixed

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,27 @@ fn foo() -> K {
7979
}
8080

8181
// Verify that cross-crate tracking of "equivalences" keeps working.
82-
#[derive(PartialEq, Debug)]
8382
#[derive(Default)] struct L {
8483
x: Vec<i32>,
8584
}
8685

8786

87+
// Account for `const`s
88+
#[derive(Default)] struct M {
89+
x: N,
90+
}
91+
92+
93+
struct N;
94+
95+
impl Default for N { // ok
96+
fn default() -> Self {
97+
N_CONST
98+
}
99+
}
100+
101+
const N_CONST: N = N;
102+
88103
fn main() {
89104
let _ = A::default();
90105
let _ = B::default();
@@ -98,4 +113,6 @@ fn main() {
98113
let _ = J::default();
99114
let _ = K::default();
100115
let _ = L::default();
116+
let _ = M::default();
117+
let _ = N::default();
101118
}

tests/ui/structs/manual-default-impl-could-be-derived.rs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ fn foo() -> K {
137137
}
138138

139139
// Verify that cross-crate tracking of "equivalences" keeps working.
140-
#[derive(PartialEq, Debug)]
141140
struct L {
142141
x: Vec<i32>,
143142
}
@@ -150,6 +149,29 @@ impl Default for L { //~ ERROR
150149
}
151150
}
152151

152+
// Account for `const`s
153+
struct M {
154+
x: N,
155+
}
156+
157+
impl Default for M { //~ ERROR
158+
fn default() -> Self {
159+
M {
160+
x: N_CONST,
161+
}
162+
}
163+
}
164+
165+
struct N;
166+
167+
impl Default for N { // ok
168+
fn default() -> Self {
169+
N_CONST
170+
}
171+
}
172+
173+
const N_CONST: N = N;
174+
153175
fn main() {
154176
let _ = A::default();
155177
let _ = B::default();
@@ -163,4 +185,6 @@ fn main() {
163185
let _ = J::default();
164186
let _ = K::default();
165187
let _ = L::default();
188+
let _ = M::default();
189+
let _ = N::default();
166190
}

tests/ui/structs/manual-default-impl-could-be-derived.stderr

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ LL ~ #[derive(Default)] struct J {
176176
|
177177

178178
error: `impl Default` that could be derived
179-
--> $DIR/manual-default-impl-could-be-derived.rs:145:1
179+
--> $DIR/manual-default-impl-could-be-derived.rs:144:1
180180
|
181181
LL | / impl Default for L {
182182
LL | | fn default() -> Self {
@@ -192,5 +192,22 @@ help: you don't need to manually `impl Default`, you can derive it
192192
LL ~ #[derive(Default)] struct L {
193193
|
194194

195-
error: aborting due to 11 previous errors
195+
error: `impl Default` that could be derived
196+
--> $DIR/manual-default-impl-could-be-derived.rs:157:1
197+
|
198+
LL | / impl Default for M {
199+
LL | | fn default() -> Self {
200+
LL | | M {
201+
LL | | x: N_CONST,
202+
LL | | }
203+
LL | | }
204+
LL | | }
205+
| |_^
206+
|
207+
help: you don't need to manually `impl Default`, you can derive it
208+
|
209+
LL ~ #[derive(Default)] struct M {
210+
|
211+
212+
error: aborting due to 12 previous errors
196213

0 commit comments

Comments
 (0)