Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
3f3fc52b
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,发现更多精彩内容 >>
提交
3f3fc52b
编写于
9月 05, 2019
作者:
M
Matthew Jasper
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplify std lib injection
上级
e552840e
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
52 addition
and
126 deletion
+52
-126
src/librustc_interface/passes.rs
src/librustc_interface/passes.rs
+1
-1
src/librustc_resolve/diagnostics.rs
src/librustc_resolve/diagnostics.rs
+8
-0
src/librustc_resolve/macros.rs
src/librustc_resolve/macros.rs
+2
-3
src/librustc_resolve/resolve_imports.rs
src/librustc_resolve/resolve_imports.rs
+5
-2
src/libsyntax_ext/proc_macro_harness.rs
src/libsyntax_ext/proc_macro_harness.rs
+5
-27
src/libsyntax_ext/standard_library_imports.rs
src/libsyntax_ext/standard_library_imports.rs
+31
-93
未找到文件。
src/librustc_interface/passes.rs
浏览文件 @
3f3fc52b
...
...
@@ -366,8 +366,8 @@ fn configure_and_expand_inner<'a>(
let
(
krate
,
name
)
=
syntax_ext
::
standard_library_imports
::
inject
(
krate
,
&
mut
resolver
,
&
sess
.parse_sess
,
alt_std_name
,
sess
.edition
(),
);
if
let
Some
(
name
)
=
name
{
sess
.parse_sess.injected_crate_name
.set
(
name
);
...
...
src/librustc_resolve/diagnostics.rs
浏览文件 @
3f3fc52b
...
...
@@ -604,6 +604,14 @@ fn lookup_import_candidates_from_module<FilterFn>(&mut self,
if
lookup_ident
.span
.rust_2018
()
{
let
extern_prelude_names
=
self
.extern_prelude
.clone
();
for
(
ident
,
_
)
in
extern_prelude_names
.into_iter
()
{
if
ident
.span
.from_expansion
()
{
// Idents are adjusted to the root context before being
// resolved in the extern prelude, so reporting this to the
// user is no help. This skips the injected
// `extern crate std` in the 2018 edition, which would
// otherwise cause duplicate suggestions.
continue
;
}
if
let
Some
(
crate_id
)
=
self
.crate_loader
.maybe_process_path_extern
(
ident
.name
,
ident
.span
)
{
let
crate_root
=
self
.get_module
(
DefId
{
...
...
src/librustc_resolve/macros.rs
浏览文件 @
3f3fc52b
...
...
@@ -128,9 +128,8 @@ fn register_builtin_macro(&mut self, ident: ast::Ident, ext: SyntaxExtension) {
}
}
// Create a Span with modern hygiene with a definition site of the provided
// module, or a fake empty `#[no_implicit_prelude]` module if no module is
// provided.
// Create a new Expansion with a definition site of the provided module, or
// a fake empty `#[no_implicit_prelude]` module if no module is provided.
fn
expansion_for_ast_pass
(
&
mut
self
,
call_site
:
Span
,
...
...
src/librustc_resolve/resolve_imports.rs
浏览文件 @
3f3fc52b
...
...
@@ -1307,8 +1307,11 @@ fn finalize_resolutions_in(&mut self, module: Module<'b>) {
None
=>
continue
,
};
// Filter away ambiguous imports.
let
is_good_import
=
binding
.is_import
()
&&
!
binding
.is_ambiguity
();
// Filter away ambiguous imports and anything that has def-site
// hygiene.
// FIXME: Implement actual cross-crate hygiene.
let
is_good_import
=
binding
.is_import
()
&&
!
binding
.is_ambiguity
()
&&
!
ident
.span
.modern
()
.from_expansion
();
if
is_good_import
||
binding
.is_macro_def
()
{
let
res
=
binding
.res
();
if
res
!=
Res
::
Err
{
...
...
src/libsyntax_ext/proc_macro_harness.rs
浏览文件 @
3f3fc52b
...
...
@@ -392,41 +392,19 @@ fn mk_decls(
i
});
let
block
=
P
(
ast
::
Expr
{
id
:
ast
::
DUMMY_NODE_ID
,
attrs
:
syntax
::
ThinVec
::
new
(),
node
:
ast
::
ExprKind
::
Block
(
P
(
ast
::
Block
{
id
:
ast
::
DUMMY_NODE_ID
,
rules
:
ast
::
BlockCheckMode
::
Default
,
stmts
:
vec!
[
ast
::
Stmt
{
id
:
ast
::
DUMMY_NODE_ID
,
node
:
ast
::
StmtKind
::
Item
(
krate
),
span
,
},
ast
::
Stmt
{
id
:
ast
::
DUMMY_NODE_ID
,
node
:
ast
::
StmtKind
::
Item
(
decls_static
),
span
,
}
],
span
,
}),
None
),
let
block
=
cx
.expr_block
(
cx
.block
(
span
,
});
vec!
[
cx
.stmt_item
(
span
,
krate
),
cx
.stmt_item
(
span
,
decls_static
)],
));
let
anon_constant
=
cx
.item_const
(
span
,
ast
::
Ident
::
new
(
kw
::
Underscore
,
span
),
P
(
ast
::
Ty
{
id
:
ast
::
DUMMY_NODE_ID
,
node
:
ast
::
TyKind
::
Tup
(
Vec
::
new
()),
span
,
}),
cx
.ty
(
span
,
ast
::
TyKind
::
Tup
(
Vec
::
new
())),
block
,
);
// Integrate the new
module
into existing module structures.
// Integrate the new
item
into existing module structures.
let
items
=
AstFragment
::
Items
(
smallvec!
[
anon_constant
]);
cx
.monotonic_expander
()
.fully_expand_fragment
(
items
)
.make_items
()
.pop
()
.unwrap
()
}
src/libsyntax_ext/standard_library_imports.rs
浏览文件 @
3f3fc52b
use
syntax
::{
ast
,
attr
};
use
syntax
::
edition
::
Edition
;
use
syntax
::
ext
::
expand
::
ExpansionConfig
;
use
syntax
::
ext
::
hygiene
::
AstPass
;
use
syntax
::
ext
::
base
::
Resolver
;
use
syntax
::
ext
::
base
::{
ExtCtxt
,
Resolver
};
use
syntax
::
parse
::
ParseSess
;
use
syntax
::
ptr
::
P
;
use
syntax
::
source_map
::
respan
;
use
syntax
::
symbol
::{
Ident
,
Symbol
,
kw
,
sym
};
use
syntax_pos
::
DUMMY_SP
;
pub
fn
inject
(
mut
krate
:
ast
::
Crate
,
resolver
:
&
mut
dyn
Resolver
,
sess
:
&
ParseSess
,
alt_std_name
:
Option
<
Symbol
>
,
edition
:
Edition
,
)
->
(
ast
::
Crate
,
Option
<
Symbol
>
)
{
let
rust_2018
=
edition
>=
Edition
::
Edition2018
;
let
rust_2018
=
sess
.
edition
>=
Edition
::
Edition2018
;
// the first name in this list is the crate name of the crate with the prelude
let
names
:
&
[
Symbol
]
=
if
attr
::
contains_name
(
&
krate
.attrs
,
sym
::
no_core
)
{
...
...
@@ -37,112 +38,49 @@ pub fn inject(
let
span
=
DUMMY_SP
.with_def_site_ctxt
(
expn_id
);
let
call_site
=
DUMMY_SP
.with_call_site_ctxt
(
expn_id
);
let
ecfg
=
ExpansionConfig
::
default
(
"std_lib_injection"
.to_string
());
let
cx
=
ExtCtxt
::
new
(
sess
,
ecfg
,
resolver
);
// .rev() to preserve ordering above in combination with insert(0, ...)
for
&
orig_name_sym
in
names
.iter
()
.rev
()
{
let
(
rename
,
orig_name
)
=
if
rust_2018
{
(
Ident
::
new
(
kw
::
Underscore
,
span
),
Some
(
orig_name_sym
)
)
for
&
name
in
names
.iter
()
.rev
()
{
let
ident
=
if
rust_2018
{
Ident
::
new
(
name
,
span
)
}
else
{
(
Ident
::
new
(
orig_name_sym
,
call_site
),
Non
e
)
Ident
::
new
(
name
,
call_sit
e
)
};
krate
.module.items
.insert
(
0
,
P
(
ast
::
Item
{
attrs
:
vec!
[
attr
::
mk_attr_outer
(
attr
::
mk_word_item
(
ast
::
Ident
::
new
(
sym
::
macro_use
,
span
))
)],
vis
:
respan
(
span
,
ast
::
VisibilityKind
::
Inherited
),
node
:
ast
::
ItemKind
::
ExternCrate
(
alt_std_name
.or
(
orig_name
)),
ident
:
rename
,
id
:
ast
::
DUMMY_NODE_ID
,
krate
.module.items
.insert
(
0
,
cx
.item
(
span
,
tokens
:
None
,
}));
ident
,
vec!
[
cx
.attribute
(
cx
.meta_word
(
span
,
sym
::
macro_use
))],
ast
::
ItemKind
::
ExternCrate
(
alt_std_name
),
));
}
//
the crates have been injected, the assumption is that the first one is the one with
// the prelude.
//
The crates have been injected, the assumption is that the first one is
// the
one with the
prelude.
let
name
=
names
[
0
];
let
segments
=
if
rust_2018
{
let
import_path
=
if
rust_2018
{
[
name
,
sym
::
prelude
,
sym
::
v1
]
.iter
()
.map
(|
symbol
|
ast
::
PathSegment
::
from_ident
(
ast
::
Ident
::
new
(
*
symbol
,
span
)))
.collect
()
.map
(|
symbol
|
ast
::
Ident
::
new
(
*
symbol
,
span
))
.collect
()
}
else
{
[
kw
::
PathRoot
,
name
,
sym
::
prelude
,
sym
::
v1
]
.iter
()
.map
(|
symbol
|
ast
::
PathSegment
::
from_ident
(
ast
::
Ident
::
new
(
*
symbol
,
call_site
)))
.collect
()
.map
(|
symbol
|
ast
::
Ident
::
new
(
*
symbol
,
span
))
.collect
()
};
let
use_item
=
P
(
ast
::
Item
{
attrs
:
vec!
[
attr
::
mk_attr_outer
(
attr
::
mk_word_item
(
ast
::
Ident
::
new
(
sym
::
prelude_import
,
span
)))]
,
v
is
:
respan
(
span
.shrink_to_lo
(),
ast
::
VisibilityKind
::
Inherited
)
,
node
:
ast
::
ItemKind
::
Use
(
P
(
ast
::
UseTree
{
prefix
:
ast
::
Path
{
segments
,
span
}
,
let
use_item
=
cx
.item
(
span
,
ast
::
Ident
::
invalid
()
,
v
ec!
[
cx
.attribute
(
cx
.meta_word
(
span
,
sym
::
prelude_import
))]
,
ast
::
ItemKind
::
Use
(
P
(
ast
::
UseTree
{
prefix
:
cx
.path
(
span
,
import_path
)
,
kind
:
ast
::
UseTreeKind
::
Glob
,
span
,
})),
id
:
ast
::
DUMMY_NODE_ID
,
ident
:
ast
::
Ident
::
invalid
(),
span
,
tokens
:
None
,
});
let
prelude_import_item
=
if
rust_2018
{
let
hygienic_extern_crate
=
P
(
ast
::
Item
{
attrs
:
vec!
[],
vis
:
respan
(
span
,
ast
::
VisibilityKind
::
Inherited
),
node
:
ast
::
ItemKind
::
ExternCrate
(
alt_std_name
),
ident
:
ast
::
Ident
::
new
(
name
,
span
),
id
:
ast
::
DUMMY_NODE_ID
,
span
,
tokens
:
None
,
});
// Use an anonymous const to hide `extern crate std as hygienic_std`
// FIXME: Once inter-crate hygiene exists, this can just be `use_item`.
P
(
ast
::
Item
{
attrs
:
Vec
::
new
(),
vis
:
respan
(
span
.shrink_to_lo
(),
ast
::
VisibilityKind
::
Inherited
),
node
:
ast
::
ItemKind
::
Const
(
P
(
ast
::
Ty
{
id
:
ast
::
DUMMY_NODE_ID
,
node
:
ast
::
TyKind
::
Tup
(
Vec
::
new
()),
span
,
}),
P
(
ast
::
Expr
{
id
:
ast
::
DUMMY_NODE_ID
,
attrs
:
syntax
::
ThinVec
::
new
(),
node
:
ast
::
ExprKind
::
Block
(
P
(
ast
::
Block
{
id
:
ast
::
DUMMY_NODE_ID
,
rules
:
ast
::
BlockCheckMode
::
Default
,
stmts
:
vec!
[
ast
::
Stmt
{
id
:
ast
::
DUMMY_NODE_ID
,
node
:
ast
::
StmtKind
::
Item
(
use_item
),
span
,
},
ast
::
Stmt
{
id
:
ast
::
DUMMY_NODE_ID
,
node
:
ast
::
StmtKind
::
Item
(
hygienic_extern_crate
),
span
,
}
],
span
,
}),
None
),
span
,
})
),
id
:
ast
::
DUMMY_NODE_ID
,
ident
:
ast
::
Ident
::
new
(
kw
::
Underscore
,
span
),
span
,
tokens
:
None
,
})
}
else
{
// Have `extern crate std` at the root, so don't need to create a named
// extern crate item.
use_item
};
);
krate
.module.items
.insert
(
0
,
prelude_import
_item
);
krate
.module.items
.insert
(
0
,
use
_item
);
(
krate
,
Some
(
name
))
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录