Rollup merge of #143699 - compiler-errors:async-drop-fund, r=oli-obk
Make `AsyncDrop` check that it's being implemented on a local ADT Fixes https://github.com/rust-lang/rust/issues/143691
This commit is contained in:
commit
3acbb4d421
6 changed files with 53 additions and 3 deletions
|
|
@ -158,7 +158,7 @@ hir_analysis_dispatch_from_dyn_zst = the trait `DispatchFromDyn` may only be imp
|
|||
hir_analysis_drop_impl_negative = negative `Drop` impls are not supported
|
||||
|
||||
hir_analysis_drop_impl_on_wrong_item =
|
||||
the `Drop` trait may only be implemented for local structs, enums, and unions
|
||||
the `{$trait_}` trait may only be implemented for local structs, enums, and unions
|
||||
.label = must be a struct, enum, or union in the current crate
|
||||
|
||||
hir_analysis_drop_impl_reservation = reservation `Drop` impls are not supported
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ pub(super) fn check_trait<'tcx>(
|
|||
let lang_items = tcx.lang_items();
|
||||
let checker = Checker { tcx, trait_def_id, impl_def_id, impl_header };
|
||||
checker.check(lang_items.drop_trait(), visit_implementation_of_drop)?;
|
||||
checker.check(lang_items.async_drop_trait(), visit_implementation_of_drop)?;
|
||||
checker.check(lang_items.copy_trait(), visit_implementation_of_copy)?;
|
||||
checker.check(lang_items.const_param_ty_trait(), |checker| {
|
||||
visit_implementation_of_const_param_ty(checker, LangItem::ConstParamTy)
|
||||
|
|
@ -83,7 +84,10 @@ fn visit_implementation_of_drop(checker: &Checker<'_>) -> Result<(), ErrorGuaran
|
|||
|
||||
let impl_ = tcx.hir_expect_item(impl_did).expect_impl();
|
||||
|
||||
Err(tcx.dcx().emit_err(errors::DropImplOnWrongItem { span: impl_.self_ty.span }))
|
||||
Err(tcx.dcx().emit_err(errors::DropImplOnWrongItem {
|
||||
span: impl_.self_ty.span,
|
||||
trait_: tcx.item_name(checker.impl_header.trait_ref.skip_binder().def_id),
|
||||
}))
|
||||
}
|
||||
|
||||
fn visit_implementation_of_copy(checker: &Checker<'_>) -> Result<(), ErrorGuaranteed> {
|
||||
|
|
|
|||
|
|
@ -205,6 +205,7 @@ pub(crate) struct DropImplOnWrongItem {
|
|||
#[primary_span]
|
||||
#[label]
|
||||
pub span: Span,
|
||||
pub trait_: Symbol,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
|
|
|
|||
21
tests/ui/async-await/async-drop/foreign-fundamental.rs
Normal file
21
tests/ui/async-await/async-drop/foreign-fundamental.rs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
//@ edition: 2018
|
||||
|
||||
#![feature(async_drop)]
|
||||
//~^ WARN the feature `async_drop` is incomplete
|
||||
|
||||
use std::future::AsyncDrop;
|
||||
use std::pin::Pin;
|
||||
|
||||
struct Foo;
|
||||
|
||||
impl AsyncDrop for &Foo {
|
||||
//~^ ERROR the `AsyncDrop` trait may only be implemented for
|
||||
async fn drop(self: Pin<&mut Self>) {}
|
||||
}
|
||||
|
||||
impl AsyncDrop for Pin<Foo> {
|
||||
//~^ ERROR the `AsyncDrop` trait may only be implemented for
|
||||
async fn drop(self: Pin<&mut Self>) {}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
24
tests/ui/async-await/async-drop/foreign-fundamental.stderr
Normal file
24
tests/ui/async-await/async-drop/foreign-fundamental.stderr
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
warning: the feature `async_drop` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/foreign-fundamental.rs:3:12
|
||||
|
|
||||
LL | #![feature(async_drop)]
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #126482 <https://github.com/rust-lang/rust/issues/126482> for more information
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
|
||||
error[E0120]: the `AsyncDrop` trait may only be implemented for local structs, enums, and unions
|
||||
--> $DIR/foreign-fundamental.rs:11:20
|
||||
|
|
||||
LL | impl AsyncDrop for &Foo {
|
||||
| ^^^^ must be a struct, enum, or union in the current crate
|
||||
|
||||
error[E0120]: the `AsyncDrop` trait may only be implemented for local structs, enums, and unions
|
||||
--> $DIR/foreign-fundamental.rs:16:20
|
||||
|
|
||||
LL | impl AsyncDrop for Pin<Foo> {
|
||||
| ^^^^^^^^ must be a struct, enum, or union in the current crate
|
||||
|
||||
error: aborting due to 2 previous errors; 1 warning emitted
|
||||
|
||||
For more information about this error, try `rustc --explain E0120`.
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
trait MyTrait { fn foo() {} }
|
||||
trait MyTrait { fn foo(&self) {} }
|
||||
|
||||
impl Drop for dyn MyTrait {
|
||||
//~^ ERROR E0120
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue