Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
42d0b363
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
42d0b363
编写于
5月 22, 2018
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
handle fully qualified paths properly when linting
fixes #50970
上级
be2bb808
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
261 addition
and
8 deletion
+261
-8
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+48
-8
src/test/ui/rust-2018/edition-lint-fully-qualified-paths.fixed
...est/ui/rust-2018/edition-lint-fully-qualified-paths.fixed
+37
-0
src/test/ui/rust-2018/edition-lint-fully-qualified-paths.rs
src/test/ui/rust-2018/edition-lint-fully-qualified-paths.rs
+37
-0
src/test/ui/rust-2018/edition-lint-fully-qualified-paths.stderr
...st/ui/rust-2018/edition-lint-fully-qualified-paths.stderr
+25
-0
src/test/ui/rust-2018/edition-lint-nested-empty-paths.fixed
src/test/ui/rust-2018/edition-lint-nested-empty-paths.fixed
+40
-0
src/test/ui/rust-2018/edition-lint-nested-empty-paths.rs
src/test/ui/rust-2018/edition-lint-nested-empty-paths.rs
+40
-0
src/test/ui/rust-2018/edition-lint-nested-empty-paths.stderr
src/test/ui/rust-2018/edition-lint-nested-empty-paths.stderr
+34
-0
未找到文件。
src/librustc_resolve/lib.rs
浏览文件 @
42d0b363
...
...
@@ -2222,7 +2222,7 @@ fn resolve_item(&mut self, item: &Item) {
segments
:
use_tree
.prefix
.make_root
()
.into_iter
()
.collect
(),
span
:
use_tree
.span
,
};
self
.resolve_use_tree
(
item
.id
,
use_tree
,
&
path
);
self
.resolve_use_tree
(
item
.id
,
use_tree
.span
,
item
.id
,
use_tree
,
&
path
);
}
ItemKind
::
ExternCrate
(
_
)
|
ItemKind
::
MacroDef
(
..
)
|
ItemKind
::
GlobalAsm
(
_
)
=>
{
...
...
@@ -2233,7 +2233,18 @@ fn resolve_item(&mut self, item: &Item) {
}
}
fn
resolve_use_tree
(
&
mut
self
,
id
:
NodeId
,
use_tree
:
&
ast
::
UseTree
,
prefix
:
&
Path
)
{
/// For the most part, use trees are desugared into `ImportDirective` instances
/// when building the reduced graph (see `build_reduced_graph_for_use_tree`). But
/// there is one special case we handle here: an empty nested import like
/// `a::{b::{}}`, which desugares into...no import directives.
fn
resolve_use_tree
(
&
mut
self
,
root_id
:
NodeId
,
root_span
:
Span
,
id
:
NodeId
,
use_tree
:
&
ast
::
UseTree
,
prefix
:
&
Path
,
)
{
match
use_tree
.kind
{
ast
::
UseTreeKind
::
Nested
(
ref
items
)
=>
{
let
path
=
Path
{
...
...
@@ -2252,11 +2263,11 @@ fn resolve_use_tree(&mut self, id: NodeId, use_tree: &ast::UseTree, prefix: &Pat
None
,
&
path
,
PathSource
::
ImportPrefix
,
CrateLint
::
SimplePath
(
id
),
// TODO seems wrong
CrateLint
::
UsePath
{
root_id
,
root_span
},
);
}
else
{
for
&
(
ref
tree
,
nested_id
)
in
items
{
self
.resolve_use_tree
(
nested_id
,
tree
,
&
path
);
self
.resolve_use_tree
(
root_id
,
root_span
,
nested_id
,
tree
,
&
path
);
}
}
}
...
...
@@ -3188,12 +3199,28 @@ fn resolve_qpath(&mut self,
if
let
Some
(
qself
)
=
qself
{
if
qself
.position
==
0
{
// FIXME: Create some fake resolution that can't possibly be a type.
// This is a case like `<T>::B`, where there is no
// trait to resolve. In that case, we leave the `B`
// segment to be resolved by type-check.
return
Some
(
PathResolution
::
with_unresolved_segments
(
Def
::
Mod
(
DefId
::
local
(
CRATE_DEF_INDEX
)),
path
.len
()
));
}
// Make sure `A::B` in `<T as A>::B::C` is a trait item.
// Make sure `A::B` in `<T as A::B>::C` is a trait item.
//
// Currently, `path` names the full item (`A::B::C`, in
// our example). so we extract the prefix of that that is
// the trait (the slice upto and including
// `qself.position`). And then we recursively resolve that,
// but with `qself` set to `None`.
//
// However, setting `qself` to none (but not changing the
// span) loses the information about where this path
// *actually* appears, so for the purposes of the crate
// lint we pass along information that this is the trait
// name from a fully qualified path, and this also
// contains the full span (the `CrateLint::QPathTrait`).
let
ns
=
if
qself
.position
+
1
==
path
.len
()
{
ns
}
else
{
TypeNS
};
let
res
=
self
.smart_resolve_path_fragment
(
id
,
...
...
@@ -3201,8 +3228,15 @@ fn resolve_qpath(&mut self,
&
path
[
..
qself
.position
+
1
],
span
,
PathSource
::
TraitItem
(
ns
),
crate_lint
,
// TODO wrong
CrateLint
::
QPathTrait
{
qpath_id
:
id
,
qpath_span
:
qself
.path_span
,
},
);
// The remaining segments (the `C` in our example) will
// have to be resolved by type-check, since that requires doing
// trait resolution.
return
Some
(
PathResolution
::
with_unresolved_segments
(
res
.base_def
(),
res
.unresolved_segments
()
+
path
.len
()
-
qself
.position
-
1
));
...
...
@@ -3213,7 +3247,7 @@ fn resolve_qpath(&mut self,
Some
(
ns
),
true
,
span
,
CrateLint
::
SimplePath
(
id
)
,
crate_lint
,
)
{
PathResult
::
NonModule
(
path_res
)
=>
path_res
,
PathResult
::
Module
(
module
)
if
!
module
.is_normal
()
=>
{
...
...
@@ -3468,6 +3502,7 @@ fn lint_if_path_starts_with_module(
CrateLint
::
No
=>
return
,
CrateLint
::
SimplePath
(
id
)
=>
(
id
,
path_span
),
CrateLint
::
UsePath
{
root_id
,
root_span
}
=>
(
root_id
,
root_span
),
CrateLint
::
QPathTrait
{
qpath_id
,
qpath_span
}
=>
(
qpath_id
,
qpath_span
),
};
let
first_name
=
match
path
.get
(
0
)
{
...
...
@@ -4536,6 +4571,11 @@ enum CrateLint {
/// have nested things like `use a::{b, c}`, we care about the
/// `use a` part.
UsePath
{
root_id
:
NodeId
,
root_span
:
Span
},
/// This is the "trait item" from a fully qualified path. For example,
/// we might be resolving `X::Y::Z` from a path like `<T as X::Y>::Z`.
/// The `path_span` is the span of the to the trait itself (`X::Y`).
QPathTrait
{
qpath_id
:
NodeId
,
qpath_span
:
Span
},
}
__
build_diagnostic_array!
{
librustc_resolve
,
DIAGNOSTICS
}
src/test/ui/rust-2018/edition-lint-fully-qualified-paths.fixed
0 → 100644
浏览文件 @
42d0b363
// 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.
// run-rustfix
#![feature(rust_2018_preview)]
#![deny(absolute_path_not_starting_with_crate)]
mod foo {
crate trait Foo {
type Bar;
}
crate struct Baz { }
impl Foo for Baz {
type Bar = ();
}
}
fn main() {
let _: <foo::Baz as crate::foo::Foo>::Bar = ();
//~^ ERROR absolute paths must start with
//~| this was previously accepted
let _: <crate::foo::Baz as foo::Foo>::Bar = ();
//~^ ERROR absolute paths must start with
//~| this was previously accepted
}
src/test/ui/rust-2018/edition-lint-fully-qualified-paths.rs
0 → 100644
浏览文件 @
42d0b363
// 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.
// run-rustfix
#![feature(rust_2018_preview)]
#![deny(absolute_path_not_starting_with_crate)]
mod
foo
{
crate
trait
Foo
{
type
Bar
;
}
crate
struct
Baz
{
}
impl
Foo
for
Baz
{
type
Bar
=
();
}
}
fn
main
()
{
let
_
:
<
foo
::
Baz
as
::
foo
::
Foo
>
::
Bar
=
();
//~^ ERROR absolute paths must start with
//~| this was previously accepted
let
_
:
<
::
foo
::
Baz
as
foo
::
Foo
>
::
Bar
=
();
//~^ ERROR absolute paths must start with
//~| this was previously accepted
}
src/test/ui/rust-2018/edition-lint-fully-qualified-paths.stderr
0 → 100644
浏览文件 @
42d0b363
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
--> $DIR/edition-lint-fully-qualified-paths.rs:30:25
|
LL | let _: <foo::Baz as ::foo::Foo>::Bar = ();
| ^^^^^^^^^^ help: use `crate`: `crate::foo::Foo`
|
note: lint level defined here
--> $DIR/edition-lint-fully-qualified-paths.rs:14:9
|
LL | #![deny(absolute_path_not_starting_with_crate)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
= note: for more information, see issue TBD
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
--> $DIR/edition-lint-fully-qualified-paths.rs:34:13
|
LL | let _: <::foo::Baz as foo::Foo>::Bar = ();
| ^^^^^^^^^^ help: use `crate`: `crate::foo::Baz`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
= note: for more information, see issue TBD
error: aborting due to 2 previous errors
src/test/ui/rust-2018/edition-lint-nested-empty-paths.fixed
0 → 100644
浏览文件 @
42d0b363
// 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.
// run-rustfix
#![feature(rust_2018_preview)]
#![deny(absolute_path_not_starting_with_crate)]
#![allow(unused_imports)]
#![allow(dead_code)]
crate mod foo {
crate mod bar {
crate mod baz { }
crate mod baz1 { }
crate struct XX;
}
}
use crate::foo::{bar::{baz::{}}};
//~^ ERROR absolute paths must start with
//~| WARN this was previously accepted
use crate::foo::{bar::{XX, baz::{}}};
//~^ ERROR absolute paths must start with
//~| WARN this was previously accepted
use crate::foo::{bar::{baz::{}, baz1::{}}};
//~^ ERROR absolute paths must start with
//~| WARN this was previously accepted
fn main() {
}
src/test/ui/rust-2018/edition-lint-nested-empty-paths.rs
0 → 100644
浏览文件 @
42d0b363
// 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.
// run-rustfix
#![feature(rust_2018_preview)]
#![deny(absolute_path_not_starting_with_crate)]
#![allow(unused_imports)]
#![allow(dead_code)]
crate
mod
foo
{
crate
mod
bar
{
crate
mod
baz
{
}
crate
mod
baz1
{
}
crate
struct
XX
;
}
}
use
foo
::{
bar
::{
baz
::{}}};
//~^ ERROR absolute paths must start with
//~| WARN this was previously accepted
use
foo
::{
bar
::{
XX
,
baz
::{}}};
//~^ ERROR absolute paths must start with
//~| WARN this was previously accepted
use
foo
::{
bar
::{
baz
::{},
baz1
::{}}};
//~^ ERROR absolute paths must start with
//~| WARN this was previously accepted
fn
main
()
{
}
src/test/ui/rust-2018/edition-lint-nested-empty-paths.stderr
0 → 100644
浏览文件 @
42d0b363
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
--> $DIR/edition-lint-nested-empty-paths.rs:27:5
|
LL | use foo::{bar::{baz::{}}};
| ^^^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::foo::{bar::{baz::{}}}`
|
note: lint level defined here
--> $DIR/edition-lint-nested-empty-paths.rs:14:9
|
LL | #![deny(absolute_path_not_starting_with_crate)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
= note: for more information, see issue TBD
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
--> $DIR/edition-lint-nested-empty-paths.rs:31:5
|
LL | use foo::{bar::{XX, baz::{}}};
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::foo::{bar::{XX, baz::{}}}`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
= note: for more information, see issue TBD
error: absolute paths must start with `self`, `super`, `crate`, or an external crate name in the 2018 edition
--> $DIR/edition-lint-nested-empty-paths.rs:35:5
|
LL | use foo::{bar::{baz::{}, baz1::{}}};
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `crate`: `crate::foo::{bar::{baz::{}, baz1::{}}}`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in the 2018 edition!
= note: for more information, see issue TBD
error: aborting due to 3 previous errors
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录