Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
70214915
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
70214915
编写于
1月 24, 2015
作者:
S
Steven Fackler
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a missing fmt::Debug impl lint
Closes #20855
上级
d1519231
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
115 addition
and
0 deletion
+115
-0
src/libcore/fmt/mod.rs
src/libcore/fmt/mod.rs
+1
-0
src/librustc/lint/builtin.rs
src/librustc/lint/builtin.rs
+63
-0
src/librustc/lint/context.rs
src/librustc/lint/context.rs
+1
-0
src/librustc/middle/lang_items.rs
src/librustc/middle/lang_items.rs
+2
-0
src/test/compile-fail/missing_debug_impls.rs
src/test/compile-fail/missing_debug_impls.rs
+48
-0
未找到文件。
src/libcore/fmt/mod.rs
浏览文件 @
70214915
...
...
@@ -245,6 +245,7 @@ pub trait Show {
#[unstable
=
"I/O and core have yet to be reconciled"
]
#[rustc_on_unimplemented
=
"`{Self}` cannot be formatted using `:?`; if it is defined in your
\
crate, add `#[derive(Debug)]` or manually implement it"
]
#[lang
=
"debug_trait"
]
pub
trait
Debug
{
/// Formats the value using the given formatter.
fn
fmt
(
&
self
,
&
mut
Formatter
)
->
Result
;
...
...
src/librustc/lint/builtin.rs
浏览文件 @
70214915
...
...
@@ -1627,6 +1627,69 @@ fn check_item(&mut self, cx: &Context, item: &ast::Item) {
}
}
declare_lint!
{
MISSING_DEBUG_IMPLEMENTATIONS
,
Allow
,
"detects missing implementations of fmt::Debug"
}
pub
struct
MissingDebugImplementations
{
impling_types
:
Option
<
NodeSet
>
,
}
impl
MissingDebugImplementations
{
pub
fn
new
()
->
MissingDebugImplementations
{
MissingDebugImplementations
{
impling_types
:
None
,
}
}
}
impl
LintPass
for
MissingDebugImplementations
{
fn
get_lints
(
&
self
)
->
LintArray
{
lint_array!
(
MISSING_DEBUG_IMPLEMENTATIONS
)
}
fn
check_item
(
&
mut
self
,
cx
:
&
Context
,
item
:
&
ast
::
Item
)
{
if
!
cx
.exported_items
.contains
(
&
item
.id
)
{
return
;
}
match
item
.node
{
ast
::
ItemStruct
(
..
)
|
ast
::
ItemEnum
(
..
)
=>
{},
_
=>
return
,
}
let
debug
=
match
cx
.tcx.lang_items
.debug_trait
()
{
Some
(
debug
)
=>
debug
,
None
=>
return
,
};
if
self
.impling_types
.is_none
()
{
let
impls
=
cx
.tcx.trait_impls
.borrow
();
let
impls
=
match
impls
.get
(
&
debug
)
{
Some
(
impls
)
=>
{
impls
.borrow
()
.iter
()
.filter
(|
d
|
d
.krate
==
ast
::
LOCAL_CRATE
)
.filter_map
(|
d
|
ty
::
ty_to_def_id
(
ty
::
node_id_to_type
(
cx
.tcx
,
d
.node
)))
.map
(|
d
|
d
.node
)
.collect
()
}
None
=>
NodeSet
(),
};
self
.impling_types
=
Some
(
impls
);
debug!
(
"{:?}"
,
self
.impling_types
);
}
if
!
self
.impling_types
.as_ref
()
.unwrap
()
.contains
(
&
item
.id
)
{
cx
.span_lint
(
MISSING_DEBUG_IMPLEMENTATIONS
,
item
.span
,
"type does not implement `fmt::Debug`; consider adding #[derive(Debug)]
\
or a manual implementation"
)
}
}
}
declare_lint!
{
DEPRECATED
,
Warn
,
...
...
src/librustc/lint/context.rs
浏览文件 @
70214915
...
...
@@ -219,6 +219,7 @@ pub fn register_builtin(&mut self, sess: Option<&Session>) {
RawPointerDerive
,
MissingDoc
,
Stability
,
MissingDebugImplementations
,
);
add_lint_group!
(
sess
,
"bad_style"
,
...
...
src/librustc/middle/lang_items.rs
浏览文件 @
70214915
...
...
@@ -328,4 +328,6 @@ pub fn collect_language_items(krate: &ast::Crate,
IteratorItem
,
"iterator"
,
iterator
;
StackExhaustedLangItem
,
"stack_exhausted"
,
stack_exhausted
;
DebugTraitLangItem
,
"debug_trait"
,
debug_trait
;
}
src/test/compile-fail/missing_debug_impls.rs
0 → 100644
浏览文件 @
70214915
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// compile-flags: --crate-type lib
#![deny(missing_debug_implementations)]
#![allow(unused,
unstable,
missing_copy_implementations)]
use
std
::
fmt
;
pub
enum
A
{}
//~ ERROR type does not implement `fmt::Debug`
#[derive(Debug)]
pub
enum
B
{}
pub
enum
C
{}
impl
fmt
::
Debug
for
C
{
fn
fmt
(
&
self
,
fmt
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
Ok
(())
}
}
pub
struct
Foo
;
//~ ERROR type does not implement `fmt::Debug`
#[derive(Debug)]
pub
struct
Bar
;
pub
struct
Baz
;
impl
fmt
::
Debug
for
Baz
{
fn
fmt
(
&
self
,
fmt
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
Ok
(())
}
}
struct
PrivateStruct
;
enum
PrivateEnum
{}
#[derive(Debug)]
struct
GenericType
<
T
>
(
T
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录