Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
a03fbfe2
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,发现更多精彩内容 >>
提交
a03fbfe2
编写于
7月 31, 2021
作者:
A
Anton Golov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Warn when an escaped newline skips multiple lines
上级
d488de82
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
19 addition
and
0 deletion
+19
-0
compiler/rustc_lexer/src/unescape.rs
compiler/rustc_lexer/src/unescape.rs
+9
-0
compiler/rustc_lexer/src/unescape/tests.rs
compiler/rustc_lexer/src/unescape/tests.rs
+5
-0
compiler/rustc_parse/src/lexer/unescape_error_reporting.rs
compiler/rustc_parse/src/lexer/unescape_error_reporting.rs
+5
-0
未找到文件。
compiler/rustc_lexer/src/unescape.rs
浏览文件 @
a03fbfe2
...
...
@@ -60,6 +60,9 @@ pub enum EscapeError {
/// After a line ending with '\', the next line contains whitespace
/// characters that are not skipped.
UnskippedWhitespaceWarning
,
/// After a line ending with '\', multiple lines are skipped.
MultipleSkippedLinesWarning
,
}
impl
EscapeError
{
...
...
@@ -67,6 +70,7 @@ impl EscapeError {
pub
fn
is_fatal
(
&
self
)
->
bool
{
match
self
{
EscapeError
::
UnskippedWhitespaceWarning
=>
false
,
EscapeError
::
MultipleSkippedLinesWarning
=>
false
,
_
=>
true
,
}
}
...
...
@@ -320,6 +324,11 @@ fn skip_ascii_whitespace<F>(chars: &mut Chars<'_>, start: usize, callback: &mut
.bytes
()
.position
(|
b
|
b
!=
b
' '
&&
b
!=
b
'\t'
&&
b
!=
b
'\n'
&&
b
!=
b
'\r'
)
.unwrap_or
(
str
.len
());
if
str
[
1
..
first_non_space
]
.contains
(
'\n'
)
{
// The +1 accounts for the escaping slash.
let
end
=
start
+
first_non_space
+
1
;
callback
(
start
..
end
,
Err
(
EscapeError
::
MultipleSkippedLinesWarning
));
}
let
tail
=
&
str
[
first_non_space
..
];
if
let
Some
(
c
)
=
tail
.chars
()
.nth
(
0
)
{
// For error reporting, we would like the span to contain the character that was not
...
...
compiler/rustc_lexer/src/unescape/tests.rs
浏览文件 @
a03fbfe2
...
...
@@ -106,6 +106,10 @@ fn check(literal: &str, expected: &[(Range<usize>, Result<char, EscapeError>)])
assert_eq!
(
unescaped
,
expected
);
}
// Check we can handle escaped newlines at the end of a file.
check
(
"
\\\n
"
,
&
[]);
check
(
"
\\\n
"
,
&
[]);
check
(
"
\\\n
\
u{a0} x"
,
&
[
...
...
@@ -115,6 +119,7 @@ fn check(literal: &str, expected: &[(Range<usize>, Result<char, EscapeError>)])
(
6
..
7
,
Ok
(
'x'
)),
],
);
check
(
"
\\\n
\n
x"
,
&
[(
0
..
7
,
Err
(
EscapeError
::
MultipleSkippedLinesWarning
)),
(
7
..
8
,
Ok
(
'x'
))]);
}
#[test]
...
...
compiler/rustc_parse/src/lexer/unescape_error_reporting.rs
浏览文件 @
a03fbfe2
...
...
@@ -280,6 +280,11 @@ pub(crate) fn emit_unescape_error(
format!
(
"non-ASCII whitespace symbol '{}' is not skipped"
,
c
.escape_unicode
());
handler
.struct_span_warn
(
span
,
&
msg
)
.span_label
(
char_span
,
&
msg
)
.emit
();
}
EscapeError
::
MultipleSkippedLinesWarning
=>
{
let
msg
=
"multiple lines skipped by escaped newline"
;
let
bottom_msg
=
"skipping everything up to and including this point"
;
handler
.struct_span_warn
(
span
,
msg
)
.span_label
(
span
,
bottom_msg
)
.emit
();
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录