Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
cdd80550
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,发现更多精彩内容 >>
提交
cdd80550
编写于
9月 07, 2019
作者:
M
Mark Rousskov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Replace DiagnosticBuilder with Diagnostic when emitting error
上级
5670d048
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
60 addition
and
26 deletion
+60
-26
src/librustc/session/mod.rs
src/librustc/session/mod.rs
+10
-4
src/librustc_codegen_ssa/back/write.rs
src/librustc_codegen_ssa/back/write.rs
+2
-2
src/librustc_driver/lib.rs
src/librustc_driver/lib.rs
+1
-0
src/librustc_errors/annotate_snippet_emitter_writer.rs
src/librustc_errors/annotate_snippet_emitter_writer.rs
+8
-4
src/librustc_errors/emitter.rs
src/librustc_errors/emitter.rs
+14
-6
src/librustc_errors/lib.rs
src/librustc_errors/lib.rs
+2
-1
src/librustdoc/core.rs
src/librustdoc/core.rs
+2
-0
src/librustdoc/test.rs
src/librustdoc/test.rs
+1
-1
src/libsyntax/json.rs
src/libsyntax/json.rs
+18
-8
src/libsyntax/parse/lexer/tests.rs
src/libsyntax/parse/lexer/tests.rs
+1
-0
src/libsyntax/tests.rs
src/libsyntax/tests.rs
+1
-0
未找到文件。
src/librustc/session/mod.rs
浏览文件 @
cdd80550
...
...
@@ -1040,6 +1040,7 @@ fn default_emitter(
source_map
:
&
Lrc
<
source_map
::
SourceMap
>
,
emitter_dest
:
Option
<
Box
<
dyn
Write
+
Send
>>
,
)
->
Box
<
dyn
Emitter
+
sync
::
Send
>
{
let
external_macro_backtrace
=
sopts
.debugging_opts.external_macro_backtrace
;
match
(
sopts
.error_format
,
emitter_dest
)
{
(
config
::
ErrorOutputType
::
HumanReadable
(
kind
),
dst
)
=>
{
let
(
short
,
color_config
)
=
kind
.unzip
();
...
...
@@ -1048,6 +1049,7 @@ fn default_emitter(
let
emitter
=
AnnotateSnippetEmitterWriter
::
new
(
Some
(
source_map
.clone
()),
short
,
external_macro_backtrace
,
);
Box
::
new
(
emitter
.ui_testing
(
sopts
.debugging_opts.ui_testing
))
}
else
{
...
...
@@ -1058,6 +1060,7 @@ fn default_emitter(
short
,
sopts
.debugging_opts.teach
,
sopts
.debugging_opts.terminal_width
,
external_macro_backtrace
,
),
Some
(
dst
)
=>
EmitterWriter
::
new
(
dst
,
...
...
@@ -1066,6 +1069,7 @@ fn default_emitter(
false
,
// no teach messages when writing to a buffer
false
,
// no colors when writing to a buffer
None
,
// no terminal width
external_macro_backtrace
,
),
};
Box
::
new
(
emitter
.ui_testing
(
sopts
.debugging_opts.ui_testing
))
...
...
@@ -1077,6 +1081,7 @@ fn default_emitter(
source_map
.clone
(),
pretty
,
json_rendered
,
external_macro_backtrace
,
)
.ui_testing
(
sopts
.debugging_opts.ui_testing
),
),
(
config
::
ErrorOutputType
::
Json
{
pretty
,
json_rendered
},
Some
(
dst
))
=>
Box
::
new
(
...
...
@@ -1086,6 +1091,7 @@ fn default_emitter(
source_map
.clone
(),
pretty
,
json_rendered
,
external_macro_backtrace
,
)
.ui_testing
(
sopts
.debugging_opts.ui_testing
),
),
}
...
...
@@ -1382,10 +1388,10 @@ pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
let
emitter
:
Box
<
dyn
Emitter
+
sync
::
Send
>
=
match
output
{
config
::
ErrorOutputType
::
HumanReadable
(
kind
)
=>
{
let
(
short
,
color_config
)
=
kind
.unzip
();
Box
::
new
(
EmitterWriter
::
stderr
(
color_config
,
None
,
short
,
false
,
None
))
Box
::
new
(
EmitterWriter
::
stderr
(
color_config
,
None
,
short
,
false
,
None
,
false
))
}
config
::
ErrorOutputType
::
Json
{
pretty
,
json_rendered
}
=>
Box
::
new
(
JsonEmitter
::
basic
(
pretty
,
json_rendered
)),
Box
::
new
(
JsonEmitter
::
basic
(
pretty
,
json_rendered
,
false
)),
};
let
handler
=
errors
::
Handler
::
with_emitter
(
true
,
None
,
emitter
);
handler
.emit
(
&
MultiSpan
::
new
(),
msg
,
errors
::
Level
::
Fatal
);
...
...
@@ -1396,10 +1402,10 @@ pub fn early_warn(output: config::ErrorOutputType, msg: &str) {
let
emitter
:
Box
<
dyn
Emitter
+
sync
::
Send
>
=
match
output
{
config
::
ErrorOutputType
::
HumanReadable
(
kind
)
=>
{
let
(
short
,
color_config
)
=
kind
.unzip
();
Box
::
new
(
EmitterWriter
::
stderr
(
color_config
,
None
,
short
,
false
,
None
))
Box
::
new
(
EmitterWriter
::
stderr
(
color_config
,
None
,
short
,
false
,
None
,
false
))
}
config
::
ErrorOutputType
::
Json
{
pretty
,
json_rendered
}
=>
Box
::
new
(
JsonEmitter
::
basic
(
pretty
,
json_rendered
)),
Box
::
new
(
JsonEmitter
::
basic
(
pretty
,
json_rendered
,
false
)),
};
let
handler
=
errors
::
Handler
::
with_emitter
(
true
,
None
,
emitter
);
handler
.emit
(
&
MultiSpan
::
new
(),
msg
,
errors
::
Level
::
Warning
);
...
...
src/librustc_codegen_ssa/back/write.rs
浏览文件 @
cdd80550
...
...
@@ -22,7 +22,7 @@
use
rustc
::
util
::
profiling
::
SelfProfiler
;
use
rustc_fs_util
::
link_or_copy
;
use
rustc_data_structures
::
svh
::
Svh
;
use
rustc_errors
::{
Handler
,
Level
,
DiagnosticBuilder
,
FatalError
,
DiagnosticId
};
use
rustc_errors
::{
Handler
,
Level
,
FatalError
,
DiagnosticId
};
use
rustc_errors
::
emitter
::{
Emitter
};
use
rustc_target
::
spec
::
MergeFunctions
;
use
syntax
::
attr
;
...
...
@@ -1725,7 +1725,7 @@ pub fn fatal(&self, msg: &str) {
}
impl
Emitter
for
SharedEmitter
{
fn
emit_diagnostic
(
&
mut
self
,
db
:
&
DiagnosticBuilder
<
'_
>
)
{
fn
emit_diagnostic
(
&
mut
self
,
db
:
&
rustc_errors
::
Diagnostic
)
{
drop
(
self
.sender
.send
(
SharedEmitterMessage
::
Diagnostic
(
Diagnostic
{
msg
:
db
.message
(),
code
:
db
.code
.clone
(),
...
...
src/librustc_driver/lib.rs
浏览文件 @
cdd80550
...
...
@@ -1196,6 +1196,7 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
false
,
false
,
None
,
false
,
));
let
handler
=
errors
::
Handler
::
with_emitter
(
true
,
None
,
emitter
);
...
...
src/librustc_errors/annotate_snippet_emitter_writer.rs
浏览文件 @
cdd80550
...
...
@@ -7,7 +7,7 @@
use
syntax_pos
::{
SourceFile
,
MultiSpan
,
Loc
};
use
crate
::{
Level
,
CodeSuggestion
,
Diagnostic
Builder
,
Emitter
,
Level
,
CodeSuggestion
,
Diagnostic
,
Emitter
,
SourceMapperDyn
,
SubDiagnostic
,
DiagnosticId
};
use
crate
::
emitter
::
FileWithAnnotatedLines
;
...
...
@@ -25,11 +25,13 @@ pub struct AnnotateSnippetEmitterWriter {
short_message
:
bool
,
/// If true, will normalize line numbers with `LL` to prevent noise in UI test diffs.
ui_testing
:
bool
,
external_macro_backtrace
:
bool
,
}
impl
Emitter
for
AnnotateSnippetEmitterWriter
{
/// The entry point for the diagnostics generation
fn
emit_diagnostic
(
&
mut
self
,
db
:
&
Diagnostic
Builder
<
'_
>
)
{
fn
emit_diagnostic
(
&
mut
self
,
db
:
&
Diagnostic
)
{
let
mut
children
=
db
.children
.clone
();
let
(
mut
primary_span
,
suggestions
)
=
self
.primary_span_formatted
(
&
db
);
...
...
@@ -37,7 +39,7 @@ fn emit_diagnostic(&mut self, db: &DiagnosticBuilder<'_>) {
&
mut
primary_span
,
&
mut
children
,
&
db
.level
,
db
.handler
()
.flags
.external_macro_backtrace
);
self
.external_macro_backtrace
);
self
.emit_messages_default
(
&
db
.level
,
db
.message
(),
...
...
@@ -163,12 +165,14 @@ fn annotation_type_for_level(level: Level) -> AnnotationType {
impl
AnnotateSnippetEmitterWriter
{
pub
fn
new
(
source_map
:
Option
<
Lrc
<
SourceMapperDyn
>>
,
short_message
:
bool
short_message
:
bool
,
external_macro_backtrace
:
bool
,
)
->
Self
{
Self
{
source_map
,
short_message
,
ui_testing
:
false
,
external_macro_backtrace
,
}
}
...
...
src/librustc_errors/emitter.rs
浏览文件 @
cdd80550
...
...
@@ -12,7 +12,7 @@
use
syntax_pos
::{
SourceFile
,
Span
,
MultiSpan
};
use
crate
::{
Level
,
CodeSuggestion
,
Diagnostic
Builder
,
SubDiagnostic
,
Level
,
CodeSuggestion
,
Diagnostic
,
SubDiagnostic
,
SuggestionStyle
,
SourceMapperDyn
,
DiagnosticId
,
};
use
crate
::
Level
::
Error
;
...
...
@@ -52,10 +52,12 @@ pub fn new_emitter(
source_map
:
Option
<
Lrc
<
SourceMapperDyn
>>
,
teach
:
bool
,
terminal_width
:
Option
<
usize
>
,
external_macro_backtrace
:
bool
,
)
->
EmitterWriter
{
let
(
short
,
color_config
)
=
self
.unzip
();
let
color
=
color_config
.suggests_using_colors
();
EmitterWriter
::
new
(
dst
,
source_map
,
short
,
teach
,
color
,
terminal_width
)
EmitterWriter
::
new
(
dst
,
source_map
,
short
,
teach
,
color
,
terminal_width
,
external_macro_backtrace
)
}
}
...
...
@@ -180,7 +182,7 @@ fn right(&self, line_len: usize) -> usize {
/// Emitter trait for emitting errors.
pub
trait
Emitter
{
/// Emit a structured diagnostic.
fn
emit_diagnostic
(
&
mut
self
,
db
:
&
Diagnostic
Builder
<
'_
>
);
fn
emit_diagnostic
(
&
mut
self
,
db
:
&
Diagnostic
);
/// Emit a notification that an artifact has been output.
/// This is currently only supported for the JSON format,
...
...
@@ -204,7 +206,7 @@ fn should_show_explain(&self) -> bool {
/// we return the original `primary_span` and the original suggestions.
fn
primary_span_formatted
<
'a
>
(
&
mut
self
,
db
:
&
'a
Diagnostic
Builder
<
'_
>
db
:
&
'a
Diagnostic
)
->
(
MultiSpan
,
&
'a
[
CodeSuggestion
])
{
let
mut
primary_span
=
db
.span
.clone
();
if
let
Some
((
sugg
,
rest
))
=
db
.suggestions
.split_first
()
{
...
...
@@ -377,7 +379,7 @@ fn fix_multispan_in_std_macros(&self,
}
impl
Emitter
for
EmitterWriter
{
fn
emit_diagnostic
(
&
mut
self
,
db
:
&
Diagnostic
Builder
<
'_
>
)
{
fn
emit_diagnostic
(
&
mut
self
,
db
:
&
Diagnostic
)
{
let
mut
children
=
db
.children
.clone
();
let
(
mut
primary_span
,
suggestions
)
=
self
.primary_span_formatted
(
&
db
);
...
...
@@ -385,7 +387,7 @@ fn emit_diagnostic(&mut self, db: &DiagnosticBuilder<'_>) {
&
mut
primary_span
,
&
mut
children
,
&
db
.level
,
db
.handler
()
.flags
.external_macro_backtrace
);
self
.external_macro_backtrace
);
self
.emit_messages_default
(
&
db
.level
,
&
db
.styled_message
(),
...
...
@@ -449,6 +451,8 @@ pub struct EmitterWriter {
teach
:
bool
,
ui_testing
:
bool
,
terminal_width
:
Option
<
usize
>
,
external_macro_backtrace
:
bool
,
}
#[derive(Debug)]
...
...
@@ -465,6 +469,7 @@ pub fn stderr(
short_message
:
bool
,
teach
:
bool
,
terminal_width
:
Option
<
usize
>
,
external_macro_backtrace
:
bool
,
)
->
EmitterWriter
{
let
dst
=
Destination
::
from_stderr
(
color_config
);
EmitterWriter
{
...
...
@@ -474,6 +479,7 @@ pub fn stderr(
teach
,
ui_testing
:
false
,
terminal_width
,
external_macro_backtrace
,
}
}
...
...
@@ -484,6 +490,7 @@ pub fn new(
teach
:
bool
,
colored
:
bool
,
terminal_width
:
Option
<
usize
>
,
external_macro_backtrace
:
bool
,
)
->
EmitterWriter
{
EmitterWriter
{
dst
:
Raw
(
dst
,
colored
),
...
...
@@ -492,6 +499,7 @@ pub fn new(
teach
,
ui_testing
:
false
,
terminal_width
,
external_macro_backtrace
,
}
}
...
...
src/librustc_errors/lib.rs
浏览文件 @
cdd80550
...
...
@@ -383,7 +383,8 @@ pub fn with_tty_emitter_and_flags(color_config: ColorConfig,
cm
:
Option
<
Lrc
<
SourceMapperDyn
>>
,
flags
:
HandlerFlags
)
->
Handler
{
let
emitter
=
Box
::
new
(
EmitterWriter
::
stderr
(
color_config
,
cm
,
false
,
false
,
None
));
let
emitter
=
Box
::
new
(
EmitterWriter
::
stderr
(
color_config
,
cm
,
false
,
false
,
None
,
flags
.external_macro_backtrace
));
Handler
::
with_emitter_and_flags
(
emitter
,
flags
)
}
...
...
src/librustdoc/core.rs
浏览文件 @
cdd80550
...
...
@@ -193,6 +193,7 @@ pub fn new_handler(error_format: ErrorOutputType,
short
,
sessopts
.debugging_opts.teach
,
sessopts
.debugging_opts.terminal_width
,
false
,
)
.ui_testing
(
ui_testing
)
)
},
...
...
@@ -205,6 +206,7 @@ pub fn new_handler(error_format: ErrorOutputType,
source_map
,
pretty
,
json_rendered
,
false
,
)
.ui_testing
(
ui_testing
)
)
},
...
...
src/librustdoc/test.rs
浏览文件 @
cdd80550
...
...
@@ -401,7 +401,7 @@ pub fn make_test(s: &str,
// Any errors in parsing should also appear when the doctest is compiled for real, so just
// send all the errors that libsyntax emits directly into a `Sink` instead of stderr.
let
cm
=
Lrc
::
new
(
SourceMap
::
new
(
FilePathMapping
::
empty
()));
let
emitter
=
EmitterWriter
::
new
(
box
io
::
sink
(),
None
,
false
,
false
,
false
,
None
);
let
emitter
=
EmitterWriter
::
new
(
box
io
::
sink
(),
None
,
false
,
false
,
false
,
None
,
false
);
// FIXME(misdreavus): pass `-Z treat-err-as-bug` to the doctest parser
let
handler
=
Handler
::
with_emitter
(
false
,
None
,
box
emitter
);
let
sess
=
ParseSess
::
with_span_handler
(
handler
,
cm
);
...
...
src/libsyntax/json.rs
浏览文件 @
cdd80550
...
...
@@ -12,7 +12,7 @@
use
crate
::
source_map
::{
SourceMap
,
FilePathMapping
};
use
errors
::
registry
::
Registry
;
use
errors
::{
DiagnosticBuilder
,
SubDiagnostic
,
CodeSuggestion
,
SourceMapper
};
use
errors
::{
SubDiagnostic
,
CodeSuggestion
,
SourceMapper
};
use
errors
::{
DiagnosticId
,
Applicability
};
use
errors
::
emitter
::{
Emitter
,
HumanReadableErrorType
};
...
...
@@ -32,6 +32,7 @@ pub struct JsonEmitter {
pretty
:
bool
,
ui_testing
:
bool
,
json_rendered
:
HumanReadableErrorType
,
external_macro_backtrace
:
bool
,
}
impl
JsonEmitter
{
...
...
@@ -40,6 +41,7 @@ pub fn stderr(
source_map
:
Lrc
<
SourceMap
>
,
pretty
:
bool
,
json_rendered
:
HumanReadableErrorType
,
external_macro_backtrace
:
bool
,
)
->
JsonEmitter
{
JsonEmitter
{
dst
:
Box
::
new
(
io
::
stderr
()),
...
...
@@ -48,13 +50,18 @@ pub fn stderr(
pretty
,
ui_testing
:
false
,
json_rendered
,
external_macro_backtrace
,
}
}
pub
fn
basic
(
pretty
:
bool
,
json_rendered
:
HumanReadableErrorType
)
->
JsonEmitter
{
pub
fn
basic
(
pretty
:
bool
,
json_rendered
:
HumanReadableErrorType
,
external_macro_backtrace
:
bool
,
)
->
JsonEmitter
{
let
file_path_mapping
=
FilePathMapping
::
empty
();
JsonEmitter
::
stderr
(
None
,
Lrc
::
new
(
SourceMap
::
new
(
file_path_mapping
)),
pretty
,
json_rendered
)
pretty
,
json_rendered
,
external_macro_backtrace
)
}
pub
fn
new
(
...
...
@@ -63,6 +70,7 @@ pub fn new(
source_map
:
Lrc
<
SourceMap
>
,
pretty
:
bool
,
json_rendered
:
HumanReadableErrorType
,
external_macro_backtrace
:
bool
,
)
->
JsonEmitter
{
JsonEmitter
{
dst
,
...
...
@@ -71,6 +79,7 @@ pub fn new(
pretty
,
ui_testing
:
false
,
json_rendered
,
external_macro_backtrace
,
}
}
...
...
@@ -80,8 +89,8 @@ pub fn ui_testing(self, ui_testing: bool) -> Self {
}
impl
Emitter
for
JsonEmitter
{
fn
emit_diagnostic
(
&
mut
self
,
db
:
&
DiagnosticBuilder
<
'_
>
)
{
let
data
=
Diagnostic
::
from_
diagnostic_builder
(
db
,
self
);
fn
emit_diagnostic
(
&
mut
self
,
db
:
&
errors
::
Diagnostic
)
{
let
data
=
Diagnostic
::
from_
errors_diagnostic
(
db
,
self
);
let
result
=
if
self
.pretty
{
writeln!
(
&
mut
self
.dst
,
"{}"
,
as_pretty_json
(
&
data
))
}
else
{
...
...
@@ -189,7 +198,7 @@ struct ArtifactNotification<'a> {
}
impl
Diagnostic
{
fn
from_
diagnostic_builder
(
db
:
&
DiagnosticBuilder
<
'_
>
,
fn
from_
errors_diagnostic
(
db
:
&
errors
::
Diagnostic
,
je
:
&
JsonEmitter
)
->
Diagnostic
{
let
sugg
=
db
.suggestions
.iter
()
.map
(|
sugg
|
{
...
...
@@ -219,8 +228,9 @@ fn flush(&mut self) -> io::Result<()> {
}
let
buf
=
BufWriter
::
default
();
let
output
=
buf
.clone
();
je
.json_rendered
.new_emitter
(
Box
::
new
(
buf
),
Some
(
je
.sm
.clone
()),
false
,
None
)
.ui_testing
(
je
.ui_testing
)
.emit_diagnostic
(
db
);
je
.json_rendered
.new_emitter
(
Box
::
new
(
buf
),
Some
(
je
.sm
.clone
()),
false
,
None
,
je
.external_macro_backtrace
)
.ui_testing
(
je
.ui_testing
)
.emit_diagnostic
(
db
);
let
output
=
Arc
::
try_unwrap
(
output
.0
)
.unwrap
()
.into_inner
()
.unwrap
();
let
output
=
String
::
from_utf8
(
output
)
.unwrap
();
...
...
src/libsyntax/parse/lexer/tests.rs
浏览文件 @
cdd80550
...
...
@@ -18,6 +18,7 @@ fn mk_sess(sm: Lrc<SourceMap>) -> ParseSess {
false
,
false
,
None
,
false
,
);
ParseSess
::
with_span_handler
(
Handler
::
with_emitter
(
true
,
None
,
Box
::
new
(
emitter
)),
sm
)
}
...
...
src/libsyntax/tests.rs
浏览文件 @
cdd80550
...
...
@@ -147,6 +147,7 @@ fn test_harness(file_text: &str, span_labels: Vec<SpanLabel>, expected_output: &
false
,
false
,
None
,
false
,
);
let
handler
=
Handler
::
with_emitter
(
true
,
None
,
Box
::
new
(
emitter
));
handler
.span_err
(
msp
,
"foo"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录