Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
df55cee0
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,发现更多精彩内容 >>
提交
df55cee0
编写于
1月 25, 2018
作者:
G
Guillaume Gomez
提交者:
GitHub
1月 25, 2018
浏览文件
操作
浏览文件
下载
差异文件
Rollup merge of #47691 - estebank:unknown-lang-item-sp, r=rkruppe
Point at unknown lang item attribute
上级
bbdc5b96
e6af9ebe
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
41 addition
and
10 deletion
+41
-10
src/librustc/middle/lang_items.rs
src/librustc/middle/lang_items.rs
+9
-7
src/librustc/middle/weak_lang_items.rs
src/librustc/middle/weak_lang_items.rs
+2
-2
src/test/compile-fail/E0522.rs
src/test/compile-fail/E0522.rs
+2
-1
src/test/ui/unknown-language-item.rs
src/test/ui/unknown-language-item.rs
+20
-0
src/test/ui/unknown-language-item.stderr
src/test/ui/unknown-language-item.stderr
+8
-0
未找到文件。
src/librustc/middle/lang_items.rs
浏览文件 @
df55cee0
...
...
@@ -28,6 +28,7 @@
use
syntax
::
ast
;
use
syntax
::
symbol
::
Symbol
;
use
syntax_pos
::
Span
;
use
hir
::
itemlikevisit
::
ItemLikeVisitor
;
use
hir
;
...
...
@@ -104,17 +105,18 @@ struct LanguageItemCollector<'a, 'tcx: 'a> {
impl
<
'a
,
'v
,
'tcx
>
ItemLikeVisitor
<
'v
>
for
LanguageItemCollector
<
'a
,
'tcx
>
{
fn
visit_item
(
&
mut
self
,
item
:
&
hir
::
Item
)
{
if
let
Some
(
value
)
=
extract
(
&
item
.attrs
)
{
if
let
Some
(
(
value
,
span
)
)
=
extract
(
&
item
.attrs
)
{
let
item_index
=
self
.item_refs
.get
(
&*
value
.as_str
())
.cloned
();
if
let
Some
(
item_index
)
=
item_index
{
let
def_id
=
self
.tcx.hir
.local_def_id
(
item
.id
);
self
.collect_item
(
item_index
,
def_id
);
}
else
{
let
span
=
self
.tcx.hir
.span
(
item
.id
);
span_err!
(
self
.tcx.sess
,
span
,
E0522
,
"definition of an unknown language item: `{}`."
,
value
);
let
mut
err
=
struct_span_err!
(
self
.tcx.sess
,
span
,
E0522
,
"definition of an unknown language item: `{}`"
,
value
);
err
.span_label
(
span
,
format!
(
"definition of unknown language item `{}`"
,
value
));
err
.emit
();
}
}
}
...
...
@@ -177,11 +179,11 @@ fn collect_item(&mut self, item_index: usize, item_def_id: DefId) {
}
}
pub
fn
extract
(
attrs
:
&
[
ast
::
Attribute
])
->
Option
<
Symbol
>
{
pub
fn
extract
(
attrs
:
&
[
ast
::
Attribute
])
->
Option
<
(
Symbol
,
Span
)
>
{
for
attribute
in
attrs
{
if
attribute
.check_name
(
"lang"
)
{
if
let
Some
(
value
)
=
attribute
.value_str
()
{
return
Some
(
value
)
return
Some
(
(
value
,
attribute
.span
));
}
}
}
...
...
src/librustc/middle/weak_lang_items.rs
浏览文件 @
df55cee0
...
...
@@ -55,7 +55,7 @@ pub fn check_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}
pub
fn
link_name
(
attrs
:
&
[
ast
::
Attribute
])
->
Option
<
Symbol
>
{
lang_items
::
extract
(
attrs
)
.and_then
(|
name
|
{
lang_items
::
extract
(
attrs
)
.and_then
(|
(
name
,
_
)
|
{
$
(
if
name
==
stringify!
(
$name
)
{
Some
(
Symbol
::
intern
(
stringify!
(
$sym
)))
}
else
)
*
{
...
...
@@ -129,7 +129,7 @@ fn nested_visit_map<'this>(&'this mut self) -> NestedVisitorMap<'this, 'v> {
}
fn
visit_foreign_item
(
&
mut
self
,
i
:
&
hir
::
ForeignItem
)
{
if
let
Some
(
lang_item
)
=
lang_items
::
extract
(
&
i
.attrs
)
{
if
let
Some
(
(
lang_item
,
_
)
)
=
lang_items
::
extract
(
&
i
.attrs
)
{
self
.register
(
&
lang_item
.as_str
(),
i
.span
);
}
intravisit
::
walk_foreign_item
(
self
,
i
)
...
...
src/test/compile-fail/E0522.rs
浏览文件 @
df55cee0
...
...
@@ -11,6 +11,7 @@
#![feature(lang_items)]
#[lang
=
"cookie"
]
fn
cookie
()
->
!
{
//~ E0522
fn
cookie
()
->
!
{
//~^^ ERROR definition of an unknown language item: `cookie` [E0522]
loop
{}
}
src/test/ui/unknown-language-item.rs
0 → 100644
浏览文件 @
df55cee0
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![allow(unused)]
#![feature(lang_items)]
#[lang
=
"foo"
]
fn
bar
()
->
!
{
//~^^ ERROR definition of an unknown language item: `foo`
loop
{}
}
fn
main
()
{}
src/test/ui/unknown-language-item.stderr
0 → 100644
浏览文件 @
df55cee0
error[E0522]: definition of an unknown language item: `foo`
--> $DIR/unknown-language-item.rs:14:1
|
14 | #[lang = "foo"]
| ^^^^^^^^^^^^^^^ definition of unknown language item `foo`
error: aborting due to previous error
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录