Skip to content

Commit e9205a2

Browse files
committed
Auto merge of #27803 - Manishearth:rollup, r=Manishearth
- Successful merges: #27699, #27757 - Failed merges:
2 parents ea3cd02 + 0f3fada commit e9205a2

File tree

2 files changed

+92
-3
lines changed

2 files changed

+92
-3
lines changed

src/librustc_borrowck/diagnostics.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,27 @@ Book:
138138
https://doc.rust-lang.org/book/ownership.html
139139
"##,
140140

141+
E0383: r##"
142+
This error occurs when an attempt is made to partially reinitialize a
143+
structure that is currently uninitialized.
144+
145+
For example, this can happen when a drop has taken place:
146+
147+
```
148+
let mut x = Foo { a: 1 };
149+
drop(x); // `x` is now uninitialized
150+
x.a = 2; // error, partial reinitialization of uninitialized structure `t`
151+
```
152+
153+
This error can be fixed by fully reinitializing the structure in question:
154+
155+
```
156+
let mut x = Foo { a: 1 };
157+
drop(x);
158+
x = Foo { a: 2 };
159+
```
160+
"##,
161+
141162
E0384: r##"
142163
This error occurs when an attempt is made to reassign an immutable variable.
143164
For example:
@@ -217,7 +238,6 @@ https://doc.rust-lang.org/std/cell/
217238
}
218239

219240
register_diagnostics! {
220-
E0383, // partial reinitialization of uninitialized structure
221241
E0385, // {} in an aliasable location
222242
E0386, // {} in an immutable container
223243
E0388, // {} in a static location

src/librustc_typeck/diagnostics.rs

+71-2
Original file line numberDiff line numberDiff line change
@@ -2429,6 +2429,77 @@ fn main() {
24292429
```
24302430
"##,
24312431

2432+
E0366: r##"
2433+
An attempt was made to implement `Drop` on a concrete specialization of a
2434+
generic type. An example is shown below:
2435+
2436+
```
2437+
struct Foo<T> {
2438+
t: T
2439+
}
2440+
2441+
impl Drop for Foo<u32> {
2442+
fn drop(&mut self) {}
2443+
}
2444+
```
2445+
2446+
This code is not legal: it is not possible to specialize `Drop` to a subset of
2447+
implementations of a generic type. One workaround for this is to wrap the
2448+
generic type, as shown below:
2449+
2450+
```
2451+
struct Foo<T> {
2452+
t: T
2453+
}
2454+
2455+
struct Bar {
2456+
t: Foo<u32>
2457+
}
2458+
2459+
impl Drop for Bar {
2460+
fn drop(&mut self) {}
2461+
}
2462+
```
2463+
"##,
2464+
2465+
E0367: r##"
2466+
An attempt was made to implement `Drop` on a specialization of a generic type.
2467+
An example is shown below:
2468+
2469+
```
2470+
trait Foo{}
2471+
2472+
struct MyStruct<T> {
2473+
t: T
2474+
}
2475+
2476+
impl<T: Foo> Drop for MyStruct<T> {
2477+
fn drop(&mut self) {}
2478+
}
2479+
```
2480+
2481+
This code is not legal: it is not possible to specialize `Drop` to a subset of
2482+
implementations of a generic type. In order for this code to work, `MyStruct`
2483+
must also require that `T` implements `Foo`. Alternatively, another option is
2484+
to wrap the generic type in another that specializes appropriately:
2485+
2486+
```
2487+
trait Foo{}
2488+
2489+
struct MyStruct<T> {
2490+
t: T
2491+
}
2492+
2493+
struct MyStructWrapper<T: Foo> {
2494+
t: MyStruct<T>
2495+
}
2496+
2497+
impl <T: Foo> Drop for MyStructWrapper<T> {
2498+
fn drop(&mut self) {}
2499+
}
2500+
```
2501+
"##,
2502+
24322503
E0368: r##"
24332504
This error indicates that a binary assignment operator like `+=` or `^=` was
24342505
applied to the wrong types. For example:
@@ -2659,8 +2730,6 @@ register_diagnostics! {
26592730
E0325, // implemented an associated type when another trait item expected
26602731
E0328, // cannot implement Unsize explicitly
26612732
E0329, // associated const depends on type parameter or Self.
2662-
E0366, // dropck forbid specialization to concrete type or region
2663-
E0367, // dropck forbid specialization to predicate not in struct/enum
26642733
E0369, // binary operation `<op>` cannot be applied to types
26652734
E0370, // discriminant overflow
26662735
E0374, // the trait `CoerceUnsized` may only be implemented for a coercion

0 commit comments

Comments
 (0)