Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
6d947e6d
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,发现更多精彩内容 >>
提交
6d947e6d
编写于
10月 16, 2022
作者:
C
Camille GILLOT
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Account for hygiene when suggesting typos.
上级
9b0a099d
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
51 addition
and
23 deletion
+51
-23
compiler/rustc_resolve/src/diagnostics.rs
compiler/rustc_resolve/src/diagnostics.rs
+8
-5
compiler/rustc_resolve/src/late/diagnostics.rs
compiler/rustc_resolve/src/late/diagnostics.rs
+21
-4
src/test/ui/hygiene/globs.stderr
src/test/ui/hygiene/globs.stderr
+16
-2
src/test/ui/hygiene/rustc-macro-transparency.stderr
src/test/ui/hygiene/rustc-macro-transparency.stderr
+1
-7
src/test/ui/macros/macro-context.stderr
src/test/ui/macros/macro-context.stderr
+1
-1
src/test/ui/proc-macro/gen-macro-rules-hygiene.stderr
src/test/ui/proc-macro/gen-macro-rules-hygiene.stderr
+2
-2
src/test/ui/proc-macro/mixed-site-span.stderr
src/test/ui/proc-macro/mixed-site-span.stderr
+2
-2
未找到文件。
compiler/rustc_resolve/src/diagnostics.rs
浏览文件 @
6d947e6d
...
...
@@ -24,7 +24,7 @@
use
rustc_span
::
lev_distance
::
find_best_match_for_name
;
use
rustc_span
::
source_map
::
SourceMap
;
use
rustc_span
::
symbol
::{
kw
,
sym
,
Ident
,
Symbol
};
use
rustc_span
::{
BytePos
,
Span
};
use
rustc_span
::{
BytePos
,
Span
,
SyntaxContext
};
use
crate
::
imports
::{
Import
,
ImportKind
,
ImportResolver
};
use
crate
::
late
::{
PatternSource
,
Rib
};
...
...
@@ -47,6 +47,7 @@
/// similarly named label and whether or not it is reachable.
pub
(
crate
)
type
LabelSuggestion
=
(
Ident
,
bool
);
#[derive(Debug)]
pub
(
crate
)
enum
SuggestionTarget
{
/// The target has a similar name as the name used by the programmer (probably a typo)
SimilarlyNamed
,
...
...
@@ -54,6 +55,7 @@ pub(crate) enum SuggestionTarget {
SingleItem
,
}
#[derive(Debug)]
pub
(
crate
)
struct
TypoSuggestion
{
pub
candidate
:
Symbol
,
pub
res
:
Res
,
...
...
@@ -482,11 +484,12 @@ pub(crate) fn add_module_candidates(
module
:
Module
<
'a
>
,
names
:
&
mut
Vec
<
TypoSuggestion
>
,
filter_fn
:
&
impl
Fn
(
Res
)
->
bool
,
ctxt
:
Option
<
SyntaxContext
>
,
)
{
for
(
key
,
resolution
)
in
self
.resolutions
(
module
)
.borrow
()
.iter
()
{
if
let
Some
(
binding
)
=
resolution
.borrow
()
.binding
{
let
res
=
binding
.res
();
if
filter_fn
(
res
)
{
if
filter_fn
(
res
)
&&
ctxt
.map_or
(
true
,
|
ctxt
|
ctxt
==
key
.ident.span
.ctxt
())
{
names
.push
(
TypoSuggestion
::
typo_from_res
(
key
.ident.name
,
res
));
}
}
...
...
@@ -1181,10 +1184,10 @@ fn early_lookup_typo_candidate(
Scope
::
CrateRoot
=>
{
let
root_ident
=
Ident
::
new
(
kw
::
PathRoot
,
ident
.span
);
let
root_module
=
this
.resolve_crate_root
(
root_ident
);
this
.add_module_candidates
(
root_module
,
&
mut
suggestions
,
filter_fn
);
this
.add_module_candidates
(
root_module
,
&
mut
suggestions
,
filter_fn
,
None
);
}
Scope
::
Module
(
module
,
_
)
=>
{
this
.add_module_candidates
(
module
,
&
mut
suggestions
,
filter_fn
);
this
.add_module_candidates
(
module
,
&
mut
suggestions
,
filter_fn
,
None
);
}
Scope
::
MacroUsePrelude
=>
{
suggestions
.extend
(
this
.macro_use_prelude
.iter
()
.filter_map
(
...
...
@@ -1221,7 +1224,7 @@ fn early_lookup_typo_candidate(
Scope
::
StdLibPrelude
=>
{
if
let
Some
(
prelude
)
=
this
.prelude
{
let
mut
tmp_suggestions
=
Vec
::
new
();
this
.add_module_candidates
(
prelude
,
&
mut
tmp_suggestions
,
filter_fn
);
this
.add_module_candidates
(
prelude
,
&
mut
tmp_suggestions
,
filter_fn
,
None
);
suggestions
.extend
(
tmp_suggestions
.into_iter
()
...
...
compiler/rustc_resolve/src/late/diagnostics.rs
浏览文件 @
6d947e6d
...
...
@@ -131,6 +131,7 @@ pub(super) enum LifetimeElisionCandidate {
}
/// Only used for diagnostics.
#[derive(Debug)]
struct
BaseError
{
msg
:
String
,
fallback_label
:
String
,
...
...
@@ -1584,19 +1585,35 @@ fn lookup_typo_candidate(
)
->
Option
<
TypoSuggestion
>
{
let
mut
names
=
Vec
::
new
();
if
path
.len
()
==
1
{
let
mut
ctxt
=
path
.last
()
.unwrap
()
.ident.span
.ctxt
();
// Search in lexical scope.
// Walk backwards up the ribs in scope and collect candidates.
for
rib
in
self
.ribs
[
ns
]
.iter
()
.rev
()
{
let
rib_ctxt
=
if
rib
.kind
.contains_params
()
{
ctxt
.normalize_to_macros_2_0
()
}
else
{
ctxt
.normalize_to_macro_rules
()
};
// Locals and type parameters
for
(
ident
,
&
res
)
in
&
rib
.bindings
{
if
filter_fn
(
res
)
{
if
filter_fn
(
res
)
&&
ident
.span
.ctxt
()
==
rib_ctxt
{
names
.push
(
TypoSuggestion
::
typo_from_res
(
ident
.name
,
res
));
}
}
if
let
RibKind
::
MacroDefinition
(
def
)
=
rib
.kind
&&
def
==
self
.r
.macro_def
(
ctxt
)
{
// If an invocation of this macro created `ident`, give up on `ident`
// and switch to `ident`'s source from the macro definition.
ctxt
.remove_mark
();
continue
;
}
// Items in scope
if
let
RibKind
::
ModuleRibKind
(
module
)
=
rib
.kind
{
// Items from this module
self
.r
.add_module_candidates
(
module
,
&
mut
names
,
&
filter_fn
);
self
.r
.add_module_candidates
(
module
,
&
mut
names
,
&
filter_fn
,
Some
(
ctxt
)
);
if
let
ModuleKind
::
Block
=
module
.kind
{
// We can see through blocks
...
...
@@ -1622,7 +1639,7 @@ fn lookup_typo_candidate(
}));
if
let
Some
(
prelude
)
=
self
.r.prelude
{
self
.r
.add_module_candidates
(
prelude
,
&
mut
names
,
&
filter_fn
);
self
.r
.add_module_candidates
(
prelude
,
&
mut
names
,
&
filter_fn
,
None
);
}
}
break
;
...
...
@@ -1641,7 +1658,7 @@ fn lookup_typo_candidate(
if
let
PathResult
::
Module
(
ModuleOrUniformRoot
::
Module
(
module
))
=
self
.resolve_path
(
mod_path
,
Some
(
TypeNS
),
None
)
{
self
.r
.add_module_candidates
(
module
,
&
mut
names
,
&
filter_fn
);
self
.r
.add_module_candidates
(
module
,
&
mut
names
,
&
filter_fn
,
None
);
}
}
...
...
src/test/ui/hygiene/globs.stderr
浏览文件 @
6d947e6d
error[E0425]: cannot find function `f` in this scope
--> $DIR/globs.rs:22:9
|
LL | pub fn g() {}
| ---------- similarly named function `g` defined here
...
LL | f();
| ^ not found in this scope
| ^
|
help: a function with a similar name exists
|
LL | g();
| ~
help: consider importing this function
|
LL | use foo::f;
...
...
@@ -12,8 +19,11 @@ LL | use foo::f;
error[E0425]: cannot find function `g` in this scope
--> $DIR/globs.rs:15:5
|
LL | pub fn f() {}
| ---------- similarly named function `f` defined here
...
LL | g();
| ^
not found in this scope
| ^
...
LL | / m! {
LL | | use bar::*;
...
...
@@ -23,6 +33,10 @@ LL | | }
| |_____- in this macro invocation
|
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
help: a function with a similar name exists
|
LL | f();
| ~
help: consider importing this function
|
LL | use bar::g;
...
...
src/test/ui/hygiene/rustc-macro-transparency.stderr
浏览文件 @
6d947e6d
...
...
@@ -19,14 +19,8 @@ LL | semitransparent;
error[E0423]: expected value, found macro `opaque`
--> $DIR/rustc-macro-transparency.rs:30:5
|
LL | struct Opaque;
| -------------- similarly named unit struct `Opaque` defined here
...
LL | opaque;
| ^^^^^^
| |
| not a value
| help: a unit struct with a similar name exists (notice the capitalization): `Opaque`
| ^^^^^^ not a value
error: aborting due to 3 previous errors
...
...
src/test/ui/macros/macro-context.stderr
浏览文件 @
6d947e6d
...
...
@@ -57,7 +57,7 @@ error[E0425]: cannot find value `i` in this scope
--> $DIR/macro-context.rs:3:13
|
LL | () => ( i ; typeof );
| ^
help: a local variable with a similar name exists: `a`
| ^
not found in this scope
...
LL | let i = m!();
| ---- in this macro invocation
...
...
src/test/ui/proc-macro/gen-macro-rules-hygiene.stderr
浏览文件 @
6d947e6d
...
...
@@ -13,7 +13,7 @@ error[E0425]: cannot find value `local_use` in this scope
--> $DIR/gen-macro-rules-hygiene.rs:12:1
|
LL | gen_macro_rules!();
| ^^^^^^^^^^^^^^^^^^
not found in this scope
| ^^^^^^^^^^^^^^^^^^
help: a local variable with a similar name exists: `local_def`
...
LL | generated!();
| ------------ in this macro invocation
...
...
@@ -24,7 +24,7 @@ error[E0425]: cannot find value `local_def` in this scope
--> $DIR/gen-macro-rules-hygiene.rs:21:9
|
LL | local_def;
| ^^^^^^^^^
not found in this scope
| ^^^^^^^^^
help: a local variable with a similar name exists: `local_use`
error: aborting due to 3 previous errors
...
...
src/test/ui/proc-macro/mixed-site-span.stderr
浏览文件 @
6d947e6d
...
...
@@ -10,7 +10,7 @@ error[E0425]: cannot find value `local_use` in this scope
--> $DIR/mixed-site-span.rs:13:9
|
LL | proc_macro_rules!();
| ^^^^^^^^^^^^^^^^^^^
not found in this scope
| ^^^^^^^^^^^^^^^^^^^
help: a local variable with a similar name exists: `local_def`
|
= note: this error originates in the macro `proc_macro_rules` (in Nightly builds, run with -Z macro-backtrace for more info)
...
...
@@ -18,7 +18,7 @@ error[E0425]: cannot find value `local_def` in this scope
--> $DIR/mixed-site-span.rs:17:9
|
LL | local_def;
| ^^^^^^^^^
not found in this scope
| ^^^^^^^^^
help: a local variable with a similar name exists: `local_use`
error[E0412]: cannot find type `ItemUse` in crate `$crate`
--> $DIR/mixed-site-span.rs:24:1
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录