Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
004f2ed2
R
Rust
项目概览
int
/
Rust
12 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
004f2ed2
编写于
3月 04, 2022
作者:
E
Esteban Kuber
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Do not recover from `Ty?` in macro parsing
Follow up to #92746. Address #94510.
上级
32cbc763
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
50 addition
and
15 deletion
+50
-15
compiler/rustc_parse/src/parser/diagnostics.rs
compiler/rustc_parse/src/parser/diagnostics.rs
+3
-3
compiler/rustc_parse/src/parser/nonterminal.rs
compiler/rustc_parse/src/parser/nonterminal.rs
+1
-1
compiler/rustc_parse/src/parser/ty.rs
compiler/rustc_parse/src/parser/ty.rs
+23
-11
src/test/ui/parser/trailing-question-in-macro-type.rs
src/test/ui/parser/trailing-question-in-macro-type.rs
+14
-0
src/test/ui/parser/trailing-question-in-macro-type.stderr
src/test/ui/parser/trailing-question-in-macro-type.stderr
+9
-0
未找到文件。
compiler/rustc_parse/src/parser/diagnostics.rs
浏览文件 @
004f2ed2
use
super
::
pat
::
Expected
;
use
super
::
ty
::{
AllowPlus
,
IsAsCast
};
use
super
::
ty
::{
AllowPlus
,
RecoverQuestionMark
};
use
super
::{
BlockMode
,
CommaRecoveryMode
,
Parser
,
PathStyle
,
RecoverColon
,
RecoverComma
,
Restrictions
,
SemiColonMode
,
SeqSep
,
TokenExpectType
,
TokenType
,
...
...
@@ -1049,9 +1049,9 @@ pub(super) fn maybe_report_ambiguous_plus(
pub
(
super
)
fn
maybe_recover_from_question_mark
(
&
mut
self
,
ty
:
P
<
Ty
>
,
is_as_cast
:
IsAsCast
,
recover_question_mark
:
RecoverQuestionMark
,
)
->
P
<
Ty
>
{
if
let
IsAsCast
::
Yes
=
is_as_cast
{
if
let
RecoverQuestionMark
::
No
=
recover_question_mark
{
return
ty
;
}
if
self
.token
==
token
::
Question
{
...
...
compiler/rustc_parse/src/parser/nonterminal.rs
浏览文件 @
004f2ed2
...
...
@@ -140,7 +140,7 @@ pub fn parse_nonterminal(&mut self, kind: NonterminalKind) -> PResult<'a, Nonter
}
NonterminalKind
::
Ty
=>
{
token
::
NtTy
(
self
.collect_tokens_no_attrs
(|
this
|
this
.parse_
ty
())
?
)
token
::
NtTy
(
self
.collect_tokens_no_attrs
(|
this
|
this
.parse_
no_question_mark_recover
())
?
)
}
// this could be handled like a token, since it is one
NonterminalKind
::
Ident
...
...
compiler/rustc_parse/src/parser/ty.rs
浏览文件 @
004f2ed2
...
...
@@ -44,7 +44,7 @@ pub(super) enum RecoverQPath {
No
,
}
pub
(
super
)
enum
IsAsCast
{
pub
(
super
)
enum
RecoverQuestionMark
{
Yes
,
No
,
}
...
...
@@ -105,7 +105,7 @@ pub fn parse_ty(&mut self) -> PResult<'a, P<Ty>> {
RecoverQPath
::
Yes
,
RecoverReturnSign
::
Yes
,
None
,
IsAsCast
::
No
,
RecoverQuestionMark
::
Yes
,
)
}
...
...
@@ -119,7 +119,7 @@ pub(super) fn parse_ty_with_generics_recovery(
RecoverQPath
::
Yes
,
RecoverReturnSign
::
Yes
,
Some
(
ty_params
),
IsAsCast
::
No
,
RecoverQuestionMark
::
Yes
,
)
}
...
...
@@ -133,7 +133,7 @@ pub(super) fn parse_ty_for_param(&mut self) -> PResult<'a, P<Ty>> {
RecoverQPath
::
Yes
,
RecoverReturnSign
::
Yes
,
None
,
IsAsCast
::
No
,
RecoverQuestionMark
::
Yes
,
)
}
...
...
@@ -150,7 +150,7 @@ pub(super) fn parse_ty_no_plus(&mut self) -> PResult<'a, P<Ty>> {
RecoverQPath
::
Yes
,
RecoverReturnSign
::
Yes
,
None
,
IsAsCast
::
No
,
RecoverQuestionMark
::
Yes
,
)
}
...
...
@@ -163,9 +163,21 @@ pub(super) fn parse_as_cast_ty(&mut self) -> PResult<'a, P<Ty>> {
RecoverQPath
::
Yes
,
RecoverReturnSign
::
Yes
,
None
,
IsAsCast
::
Yes
,
RecoverQuestionMark
::
No
,
)
}
pub
(
super
)
fn
parse_no_question_mark_recover
(
&
mut
self
)
->
PResult
<
'a
,
P
<
Ty
>>
{
self
.parse_ty_common
(
AllowPlus
::
Yes
,
AllowCVariadic
::
No
,
RecoverQPath
::
Yes
,
RecoverReturnSign
::
Yes
,
None
,
RecoverQuestionMark
::
No
,
)
}
/// Parse a type without recovering `:` as `->` to avoid breaking code such as `where fn() : for<'a>`
pub
(
super
)
fn
parse_ty_for_where_clause
(
&
mut
self
)
->
PResult
<
'a
,
P
<
Ty
>>
{
self
.parse_ty_common
(
...
...
@@ -174,7 +186,7 @@ pub(super) fn parse_ty_for_where_clause(&mut self) -> PResult<'a, P<Ty>> {
RecoverQPath
::
Yes
,
RecoverReturnSign
::
OnlyFatArrow
,
None
,
IsAsCast
::
No
,
RecoverQuestionMark
::
Yes
,
)
}
...
...
@@ -193,7 +205,7 @@ pub(super) fn parse_ret_ty(
recover_qpath
,
recover_return_sign
,
None
,
IsAsCast
::
No
,
RecoverQuestionMark
::
Yes
,
)
?
;
FnRetTy
::
Ty
(
ty
)
}
else
if
recover_return_sign
.can_recover
(
&
self
.token.kind
)
{
...
...
@@ -214,7 +226,7 @@ pub(super) fn parse_ret_ty(
recover_qpath
,
recover_return_sign
,
None
,
IsAsCast
::
No
,
RecoverQuestionMark
::
Yes
,
)
?
;
FnRetTy
::
Ty
(
ty
)
}
else
{
...
...
@@ -229,7 +241,7 @@ fn parse_ty_common(
recover_qpath
:
RecoverQPath
,
recover_return_sign
:
RecoverReturnSign
,
ty_generics
:
Option
<&
Generics
>
,
is_as_cast
:
IsAsCast
,
recover_question_mark
:
RecoverQuestionMark
,
)
->
PResult
<
'a
,
P
<
Ty
>>
{
let
allow_qpath_recovery
=
recover_qpath
==
RecoverQPath
::
Yes
;
maybe_recover_from_interpolated_ty_qpath!
(
self
,
allow_qpath_recovery
);
...
...
@@ -305,7 +317,7 @@ fn parse_ty_common(
// Try to recover from use of `+` with incorrect priority.
self
.maybe_report_ambiguous_plus
(
allow_plus
,
impl_dyn_multi
,
&
ty
);
self
.maybe_recover_from_bad_type_plus
(
allow_plus
,
&
ty
)
?
;
let
ty
=
self
.maybe_recover_from_question_mark
(
ty
,
is_as_cast
);
let
ty
=
self
.maybe_recover_from_question_mark
(
ty
,
recover_question_mark
);
self
.maybe_recover_from_bad_qpath
(
ty
,
allow_qpath_recovery
)
}
...
...
src/test/ui/parser/trailing-question-in-macro-type.rs
0 → 100644
浏览文件 @
004f2ed2
macro_rules!
fn_expr
{
(
$return_type:ty
:
$body:expr
)
=>
{
(||
->
$return_type
{
$body
})()
};
(
$body:expr
)
=>
{
(||
$body
)()
};
}
fn
main
()
{
fn_expr!
{
o
?
.when
(|
&
i
|
i
>
0
)
?
.when
(|
&
i
|
i
%
2
==
0
)
};
//~^ ERROR cannot find value `o` in this scope
}
src/test/ui/parser/trailing-question-in-macro-type.stderr
0 → 100644
浏览文件 @
004f2ed2
error[E0425]: cannot find value `o` in this scope
--> $DIR/trailing-question-in-macro-type.rs:12:15
|
LL | fn_expr!{ o?.when(|&i| i > 0)?.when(|&i| i%2 == 0) };
| ^ not found in this scope
error: aborting due to previous error
For more information about this error, try `rustc --explain E0425`.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录