File tree Expand file tree Collapse file tree
compiler/rustc_hir_analysis Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -224,6 +224,10 @@ hir_analysis_impl_not_marked_default = `{$ident}` specializes an item from a par
224224hir_analysis_impl_not_marked_default_err = `{ $ident } ` specializes an item from a parent `impl`, but that item is not marked `default`
225225 .note = parent implementation is in crate `{ $cname } `
226226
227+ hir_analysis_impl_unpin_for_pin_projected_type = explicit impls for the `Unpin` trait are not permitted for structurally pinned types
228+ .label = impl of `Unpin` not allowed
229+ .help = `{ $adt_name } ` is structurally pinned because it is marked as `#[pin_v2]`
230+
227231hir_analysis_inherent_dyn = cannot define inherent `impl` for a dyn auto trait
228232 .label = impl requires at least one non-auto trait
229233 .note = define and implement a new trait or type instead
Original file line number Diff line number Diff line change @@ -90,6 +90,20 @@ fn enforce_trait_manually_implementable(
9090 return Err ( err. emit ( ) ) ;
9191 }
9292
93+ // Disallow explicit impls of the `Unpin` trait for structurally pinned types
94+ if tcx. features ( ) . pin_ergonomics ( )
95+ && tcx. is_lang_item ( trait_def_id, LangItem :: Unpin )
96+ && let Some ( adt) =
97+ tcx. impl_trait_ref ( impl_def_id) . instantiate_identity ( ) . self_ty ( ) . ty_adt_def ( )
98+ && adt. is_pin_project ( )
99+ {
100+ return Err ( tcx. dcx ( ) . emit_err ( crate :: errors:: ImplUnpinForPinProjectedType {
101+ span : impl_header_span,
102+ adt_span : tcx. def_span ( adt. did ( ) ) ,
103+ adt_name : tcx. item_name ( adt. did ( ) ) ,
104+ } ) ) ;
105+ }
106+
93107 if let ty:: trait_def:: TraitSpecializationKind :: AlwaysApplicable = trait_def. specialization_kind
94108 {
95109 if !tcx. features ( ) . specialization ( )
Original file line number Diff line number Diff line change @@ -1690,3 +1690,14 @@ pub(crate) struct EiiWithGenerics {
16901690 pub eii_name : Symbol ,
16911691 pub impl_name : Symbol ,
16921692}
1693+
1694+ #[ derive( Diagnostic ) ]
1695+ #[ diag( hir_analysis_impl_unpin_for_pin_projected_type) ]
1696+ pub ( crate ) struct ImplUnpinForPinProjectedType {
1697+ #[ primary_span]
1698+ #[ label]
1699+ pub span : Span ,
1700+ #[ help]
1701+ pub adt_span : Span ,
1702+ pub adt_name : Symbol ,
1703+ }
Original file line number Diff line number Diff line change 1+ #![ feature( pin_ergonomics) ]
2+ #![ allow( incomplete_features) ]
3+
4+ #[ pin_v2]
5+ struct Foo ;
6+ struct Bar ;
7+
8+ impl Unpin for Foo { } //~ ERROR explicit impls for the `Unpin` trait are not permitted for structurally pinned types
9+ impl Unpin for Bar { } // ok
10+
11+ fn main ( ) { }
Original file line number Diff line number Diff line change 1+ error: explicit impls for the `Unpin` trait are not permitted for structurally pinned types
2+ --> $DIR/impl-unpin.rs:8:1
3+ |
4+ LL | impl Unpin for Foo {}
5+ | ^^^^^^^^^^^^^^^^^^ impl of `Unpin` not allowed
6+ |
7+ help: `Foo` is structurally pinned because it is marked as `#[pin_v2]`
8+ --> $DIR/impl-unpin.rs:5:1
9+ |
10+ LL | struct Foo;
11+ | ^^^^^^^^^^
12+
13+ error: aborting due to 1 previous error
14+
You can’t perform that action at this time.
0 commit comments