Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
1f421d64
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,发现更多精彩内容 >>
提交
1f421d64
编写于
8月 25, 2018
作者:
J
Joseph Post
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
call span_suggestion with applicability
上级
d95f078f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
60 addition
and
27 deletion
+60
-27
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+41
-21
src/librustc_typeck/structured_errors.rs
src/librustc_typeck/structured_errors.rs
+7
-4
src/libsyntax/parse/parser.rs
src/libsyntax/parse/parser.rs
+12
-2
未找到文件。
src/librustc_resolve/lib.rs
浏览文件 @
1f421d64
...
...
@@ -69,7 +69,7 @@
use
syntax
::
ptr
::
P
;
use
syntax_pos
::{
Span
,
DUMMY_SP
,
MultiSpan
};
use
errors
::{
DiagnosticBuilder
,
DiagnosticId
};
use
errors
::{
Applicability
,
DiagnosticBuilder
,
DiagnosticId
};
use
std
::
cell
::{
Cell
,
RefCell
};
use
std
::
cmp
;
...
...
@@ -220,9 +220,12 @@ fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver,
let
sugg_msg
=
"try using a local type parameter instead"
;
if
let
Some
((
sugg_span
,
new_snippet
))
=
cm
.generate_local_type_param_snippet
(
span
)
{
// Suggest the modification to the user
err
.span_suggestion
(
sugg_span
,
sugg_msg
,
new_snippet
);
err
.span_suggestion_with_applicability
(
sugg_span
,
sugg_msg
,
new_snippet
,
Applicability
::
MachineApplicable
,
);
}
else
if
let
Some
(
sp
)
=
cm
.generate_fn_name_span
(
span
)
{
err
.span_label
(
sp
,
"try adding a local type parameter in this method instead"
);
}
else
{
...
...
@@ -2998,8 +3001,12 @@ fn smart_resolve_path_fragment(&mut self,
enum_path
);
err
.help
(
&
msg
);
}
else
{
err
.span_suggestion
(
span
,
"you can try using the variant's enum"
,
enum_path
);
err
.span_suggestion_with_applicability
(
span
,
"you can try using the variant's enum"
,
enum_path
,
Applicability
::
MachineApplicable
,
);
}
}
}
...
...
@@ -3008,20 +3015,32 @@ fn smart_resolve_path_fragment(&mut self,
let
self_is_available
=
this
.self_value_is_available
(
path
[
0
]
.span
,
span
);
match
candidate
{
AssocSuggestion
::
Field
=>
{
err
.span_suggestion
(
span
,
"try"
,
format!
(
"self.{}"
,
path_str
));
err
.span_suggestion_with_applicability
(
span
,
"try"
,
format!
(
"self.{}"
,
path_str
),
Applicability
::
MachineApplicable
,
);
if
!
self_is_available
{
err
.span_label
(
span
,
format!
(
"`self` value is only available in
\
methods with `self` parameter"
));
}
}
AssocSuggestion
::
MethodWithSelf
if
self_is_available
=>
{
err
.span_suggestion
(
span
,
"try"
,
format!
(
"self.{}"
,
path_str
));
err
.span_suggestion_with_applicability
(
span
,
"try"
,
format!
(
"self.{}"
,
path_str
),
Applicability
::
MachineApplicable
,
);
}
AssocSuggestion
::
MethodWithSelf
|
AssocSuggestion
::
AssocItem
=>
{
err
.span_suggestion
(
span
,
"try"
,
format!
(
"Self::{}"
,
path_str
));
err
.span_suggestion_with_applicability
(
span
,
"try"
,
format!
(
"Self::{}"
,
path_str
),
Applicability
::
MachineApplicable
,
);
}
}
return
(
err
,
candidates
);
...
...
@@ -4617,15 +4636,16 @@ fn report_conflict<'b>(&mut self,
format!
(
"other_{}"
,
name
)
};
err
.span_suggestion
(
binding
.span
,
rename_msg
,
if
snippet
.ends_with
(
';'
)
{
format!
(
"{} as {};"
,
&
snippet
[
..
snippet
.len
()
-
1
],
suggested_name
)
}
else
{
format!
(
"{} as {}"
,
snippet
,
suggested_name
)
});
err
.span_suggestion_with_applicability
(
binding
.span
,
rename_msg
,
if
snippet
.ends_with
(
';'
)
{
format!
(
"{} as {};"
,
&
snippet
[
..
snippet
.len
()
-
1
],
suggested_name
)
}
else
{
format!
(
"{} as {}"
,
snippet
,
suggested_name
)
},
Applicability
::
MachineApplicable
,
);
}
else
{
err
.span_label
(
binding
.span
,
rename_msg
);
}
...
...
src/librustc_typeck/structured_errors.rs
浏览文件 @
1f421d64
...
...
@@ -10,7 +10,7 @@
use
rustc
::
session
::
Session
;
use
syntax_pos
::
Span
;
use
errors
::{
DiagnosticId
,
DiagnosticBuilder
};
use
errors
::{
Applicability
,
DiagnosticId
,
DiagnosticBuilder
};
use
rustc
::
ty
::{
Ty
,
TypeFoldable
};
pub
trait
StructuredDiagnostic
<
'tcx
>
{
...
...
@@ -73,9 +73,12 @@ fn common(&self) -> DiagnosticBuilder<'tcx> {
)
};
if
let
Ok
(
snippet
)
=
self
.sess
.source_map
()
.span_to_snippet
(
self
.span
)
{
err
.span_suggestion
(
self
.span
,
&
format!
(
"cast the value to `{}`"
,
self
.cast_ty
),
format!
(
"{} as {}"
,
snippet
,
self
.cast_ty
));
err
.span_suggestion_with_applicability
(
self
.span
,
&
format!
(
"cast the value to `{}`"
,
self
.cast_ty
),
format!
(
"{} as {}"
,
snippet
,
self
.cast_ty
),
Applicability
::
MachineApplicable
,
);
}
else
{
err
.help
(
&
format!
(
"cast the value to `{}`"
,
self
.cast_ty
));
}
...
...
src/libsyntax/parse/parser.rs
浏览文件 @
1f421d64
...
...
@@ -786,7 +786,12 @@ fn expected_ident_found(&self) -> DiagnosticBuilder<'a> {
}
else
{
err
.span_label
(
self
.span
,
"expected identifier"
);
if
self
.token
==
token
::
Comma
&&
self
.look_ahead
(
1
,
|
t
|
t
.is_ident
())
{
err
.span_suggestion
(
self
.span
,
"remove this comma"
,
String
::
new
());
err
.span_suggestion_with_applicability
(
self
.span
,
"remove this comma"
,
String
::
new
(),
Applicability
::
MachineApplicable
,
);
}
}
err
...
...
@@ -6077,7 +6082,12 @@ fn parse_single_struct_field(&mut self,
self
.this_token_to_string
()));
if
self
.token
.is_ident
()
{
// This is likely another field; emit the diagnostic and keep going
err
.span_suggestion
(
sp
,
"try adding a comma"
,
","
.into
());
err
.span_suggestion_with_applicability
(
sp
,
"try adding a comma"
,
","
.into
(),
Applicability
::
MachineApplicable
,
);
err
.emit
();
}
else
{
return
Err
(
err
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录