Skip to content

Commit 59a621c

Browse files
committed
remove custom impl error for field traits and use attribute instead
1 parent 2dcfc93 commit 59a621c

File tree

8 files changed

+11
-56
lines changed

8 files changed

+11
-56
lines changed

compiler/rustc_error_codes/src/error_codes/E0806.md

Lines changed: 0 additions & 23 deletions
This file was deleted.

compiler/rustc_error_codes/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,6 @@ E0802: 0802,
548548
E0803: 0803,
549549
E0804: 0804,
550550
E0805: 0805,
551-
E0806: 0806,
552551
);
553552
)
554553
}

compiler/rustc_hir_analysis/messages.ftl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,6 @@ hir_analysis_drop_impl_on_wrong_item =
161161
the `{$trait_}` trait may only be implemented for local structs, enums, and unions
162162
.label = must be a struct, enum, or union in the current crate
163163
164-
hir_analysis_field_trait_impl =
165-
the `{$trait_}` trait may not be implemented manually
166-
167164
hir_analysis_drop_impl_reservation = reservation `Drop` impls are not supported
168165
169166
hir_analysis_duplicate_precise_capture = cannot capture parameter `{$name}` twice

compiler/rustc_hir_analysis/src/coherence/builtin.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,6 @@ pub(super) fn check_trait<'tcx>(
5252
lang_items.coerce_pointee_validated_trait(),
5353
visit_implementation_of_coerce_pointee_validity,
5454
)?;
55-
checker.check(lang_items.unaligned_field_trait(), visit_implementation_of_field_trait)?;
56-
checker.check(lang_items.field_trait(), visit_implementation_of_field_trait)?;
5755
Ok(())
5856
}
5957

@@ -376,18 +374,6 @@ fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<()
376374
}
377375
}
378376

379-
fn visit_implementation_of_field_trait(checker: &Checker<'_>) -> Result<(), ErrorGuaranteed> {
380-
let tcx = checker.tcx;
381-
let impl_did = checker.impl_def_id;
382-
383-
let span = tcx.span_of_impl(impl_did.into()).expect("impl_did is local");
384-
385-
Err(tcx.dcx().emit_err(errors::FieldTraitImpl {
386-
span,
387-
trait_: tcx.item_name(checker.impl_header.trait_ref.skip_binder().def_id),
388-
}))
389-
}
390-
391377
pub(crate) fn coerce_unsized_info<'tcx>(
392378
tcx: TyCtxt<'tcx>,
393379
impl_did: LocalDefId,

compiler/rustc_hir_analysis/src/errors.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,6 @@ pub(crate) struct DropImplOnWrongItem {
208208
pub trait_: Symbol,
209209
}
210210

211-
#[derive(Diagnostic)]
212-
#[diag(hir_analysis_field_trait_impl, code = E0806)]
213-
pub(crate) struct FieldTraitImpl {
214-
#[primary_span]
215-
pub span: Span,
216-
pub trait_: Symbol,
217-
}
218-
219211
#[derive(Diagnostic)]
220212
pub(crate) enum FieldAlreadyDeclared {
221213
#[diag(hir_analysis_field_already_declared, code = E0124)]

library/core/src/field.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
/// byte offset `OFFSET`.
99
#[lang = "UnalignedField"]
1010
#[unstable(feature = "field_projections", issue = "145383")]
11+
#[rustc_deny_explicit_impl]
12+
#[rustc_do_not_implement_via_object]
1113
pub unsafe trait UnalignedField: Sized {
1214
/// The type of the base where this field exists in.
1315
#[lang = "UnalignedFieldBase"]
@@ -30,6 +32,8 @@ pub unsafe trait UnalignedField: Sized {
3032
/// `Self::Type` is well-aligned.
3133
#[lang = "Field"]
3234
#[unstable(feature = "field_projections", issue = "145383")]
35+
#[rustc_deny_explicit_impl]
36+
#[rustc_do_not_implement_via_object]
3337
pub unsafe trait Field: UnalignedField {}
3438

3539
/// Expands to the field representing type of the given field.

tests/ui/field_projections/deny-manual-impl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ use std::field::{Field, UnalignedField, field_of};
77
pub struct MyStruct(usize);
88

99
unsafe impl UnalignedField for MyStruct {
10-
//~^ ERROR: the `UnalignedField` trait may not be implemented manually [E0806]
10+
//~^ ERROR: explicit impls for the `UnalignedField` trait are not permitted [E0322]
1111
type Base = ();
1212
type Type = ();
1313
const OFFSET: usize = 0;
1414
}
1515

16-
unsafe impl Field for field_of!(MyStruct, 0) {} //~ ERROR: the `Field` trait may not be implemented manually [E0806]
16+
unsafe impl Field for field_of!(MyStruct, 0) {} //~ ERROR: explicit impls for the `Field` trait are not permitted [E0322]
1717

1818
fn main() {}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
error[E0806]: the `UnalignedField` trait may not be implemented manually
1+
error[E0322]: explicit impls for the `UnalignedField` trait are not permitted
22
--> $DIR/deny-manual-impl.rs:9:1
33
|
44
LL | unsafe impl UnalignedField for MyStruct {
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl of `UnalignedField` not allowed
66

7-
error[E0806]: the `Field` trait may not be implemented manually
7+
error[E0322]: explicit impls for the `Field` trait are not permitted
88
--> $DIR/deny-manual-impl.rs:16:1
99
|
1010
LL | unsafe impl Field for field_of!(MyStruct, 0) {}
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ impl of `Field` not allowed
1212

1313
error: aborting due to 2 previous errors
1414

15-
For more information about this error, try `rustc --explain E0806`.
15+
For more information about this error, try `rustc --explain E0322`.

0 commit comments

Comments
 (0)