Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
e9990bc6
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
e9990bc6
编写于
1月 02, 2020
作者:
A
Andy Russell
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
clarify that `Drop` can be implemented for enums and unions too
上级
e5893582
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
41 addition
and
42 deletion
+41
-42
src/librustc_typeck/coherence/builtin.rs
src/librustc_typeck/coherence/builtin.rs
+18
-29
src/test/ui/dropck/drop-on-non-struct.rs
src/test/ui/dropck/drop-on-non-struct.rs
+6
-1
src/test/ui/dropck/drop-on-non-struct.stderr
src/test/ui/dropck/drop-on-non-struct.stderr
+10
-4
src/test/ui/error-codes/E0117.rs
src/test/ui/error-codes/E0117.rs
+1
-2
src/test/ui/error-codes/E0117.stderr
src/test/ui/error-codes/E0117.stderr
+2
-2
src/test/ui/error-codes/E0120.stderr
src/test/ui/error-codes/E0120.stderr
+2
-2
src/test/ui/issues/issue-41974.stderr
src/test/ui/issues/issue-41974.stderr
+2
-2
未找到文件。
src/librustc_typeck/coherence/builtin.rs
浏览文件 @
e9990bc6
...
...
@@ -13,7 +13,6 @@
use
rustc
::
ty
::
TypeFoldable
;
use
rustc
::
ty
::{
self
,
Ty
,
TyCtxt
};
use
hir
::
Node
;
use
rustc
::
hir
::
def_id
::
DefId
;
use
rustc
::
hir
::{
self
,
ItemKind
};
...
...
@@ -51,35 +50,25 @@ fn check<F>(&self, trait_def_id: Option<DefId>, mut f: F) -> &Self
}
fn
visit_implementation_of_drop
(
tcx
:
TyCtxt
<
'_
>
,
impl_did
:
DefId
)
{
if
let
ty
::
Adt
(
..
)
=
tcx
.type_of
(
impl_did
)
.kind
{
/* do nothing */
}
else
{
// Destructors only work on nominal types.
if
let
Some
(
impl_hir_id
)
=
tcx
.hir
()
.as_local_hir_id
(
impl_did
)
{
if
let
Some
(
Node
::
Item
(
item
))
=
tcx
.hir
()
.find
(
impl_hir_id
)
{
let
span
=
match
item
.kind
{
ItemKind
::
Impl
(
..
,
ref
ty
,
_
)
=>
ty
.span
,
_
=>
item
.span
,
};
struct_span_err!
(
tcx
.sess
,
span
,
E0120
,
"the Drop trait may only be implemented on
\
structures"
)
.span_label
(
span
,
"implementing Drop requires a struct"
)
.emit
();
}
else
{
bug!
(
"didn't find impl in ast map"
);
}
}
else
{
bug!
(
"found external impl of Drop trait on
\
something other than a struct"
);
}
// Destructors only work on nominal types.
if
let
ty
::
Adt
(
..
)
|
ty
::
Error
=
tcx
.type_of
(
impl_did
)
.kind
{
return
;
}
let
impl_hir_id
=
tcx
.hir
()
.as_local_hir_id
(
impl_did
)
.expect
(
"foreign Drop impl on non-ADT"
);
let
sp
=
match
tcx
.hir
()
.expect_item
(
impl_hir_id
)
.kind
{
ItemKind
::
Impl
(
..
,
ty
,
_
)
=>
ty
.span
,
_
=>
bug!
(
"expected Drop impl item"
),
};
struct_span_err!
(
tcx
.sess
,
sp
,
E0120
,
"the `Drop` trait may only be implemented for structs, enums, and unions"
,
)
.span_label
(
sp
,
"must be a struct, enum, or union"
)
.emit
();
}
fn
visit_implementation_of_copy
(
tcx
:
TyCtxt
<
'_
>
,
impl_did
:
DefId
)
{
...
...
src/test/ui/dropck/drop-on-non-struct.rs
浏览文件 @
e9990bc6
impl
<
'a
>
Drop
for
&
'a
mut
isize
{
//~^ ERROR the
Drop trait may only be implemented on structure
s
//~^ ERROR the
`Drop` trait may only be implemented for structs, enums, and union
s
//~^^ ERROR E0117
fn
drop
(
&
mut
self
)
{
println!
(
"kaboom"
);
}
}
impl
Drop
for
Nonexistent
{
//~^ ERROR cannot find type `Nonexistent`
fn
drop
(
&
mut
self
)
{
}
}
fn
main
()
{
}
src/test/ui/dropck/drop-on-non-struct.stderr
浏览文件 @
e9990bc6
error[E0120]: the Drop trait may only be implemented on structures
error[E0412]: cannot find type `Nonexistent` in this scope
--> $DIR/drop-on-non-struct.rs:9:15
|
LL | impl Drop for Nonexistent {
| ^^^^^^^^^^^ not found in this scope
error[E0120]: the `Drop` trait may only be implemented for structs, enums, and unions
--> $DIR/drop-on-non-struct.rs:1:19
|
LL | impl<'a> Drop for &'a mut isize {
| ^^^^^^^^^^^^^
implementing Drop requires a struct
| ^^^^^^^^^^^^^
must be a struct, enum, or union
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> $DIR/drop-on-non-struct.rs:1:1
...
...
@@ -15,7 +21,7 @@ LL | impl<'a> Drop for &'a mut isize {
|
= note: define and implement a trait or new type instead
error: aborting due to
2
previous errors
error: aborting due to
3
previous errors
Some errors have detailed explanations: E0117, E0120.
Some errors have detailed explanations: E0117, E0120
, E0412
.
For more information about an error, try `rustc --explain E0117`.
src/test/ui/error-codes/E0117.rs
浏览文件 @
e9990bc6
impl
Drop
for
u32
{}
//~ ERROR E0117
//~| ERROR the Drop trait may only be implemented on structures
//~| implementing Drop requires a struct
//~| ERROR the `Drop` trait may only be implemented for structs, enums, and unions
fn
main
()
{
}
src/test/ui/error-codes/E0117.stderr
浏览文件 @
e9990bc6
error[E0120]: the
Drop trait may only be implemented on structure
s
error[E0120]: the
`Drop` trait may only be implemented for structs, enums, and union
s
--> $DIR/E0117.rs:1:15
|
LL | impl Drop for u32 {}
| ^^^
implementing Drop requires a struct
| ^^^
must be a struct, enum, or union
error[E0117]: only traits defined in the current crate can be implemented for arbitrary types
--> $DIR/E0117.rs:1:1
...
...
src/test/ui/error-codes/E0120.stderr
浏览文件 @
e9990bc6
error[E0120]: the
Drop trait may only be implemented on structure
s
error[E0120]: the
`Drop` trait may only be implemented for structs, enums, and union
s
--> $DIR/E0120.rs:3:15
|
LL | impl Drop for dyn MyTrait {
| ^^^^^^^^^^^
implementing Drop requires a struct
| ^^^^^^^^^^^
must be a struct, enum, or union
error: aborting due to previous error
...
...
src/test/ui/issues/issue-41974.stderr
浏览文件 @
e9990bc6
...
...
@@ -9,11 +9,11 @@ LL | impl<T> Drop for T where T: A {
where T: ?Sized;
= note: downstream crates may implement trait `A` for type `std::boxed::Box<_>`
error[E0120]: the
Drop trait may only be implemented on structure
s
error[E0120]: the
`Drop` trait may only be implemented for structs, enums, and union
s
--> $DIR/issue-41974.rs:7:18
|
LL | impl<T> Drop for T where T: A {
| ^
implementing Drop requires a struct
| ^
must be a struct, enum, or union
error[E0210]: type parameter `T` must be used as the type parameter for some local type (e.g., `MyStruct<T>`)
--> $DIR/issue-41974.rs:7:6
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录