Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
caecb76f
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,发现更多精彩内容 >>
提交
caecb76f
编写于
5月 21, 2017
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Turn sufficiently old compatibility lints into hard errors
上级
f89d8d18
变更
30
隐藏空白更改
内联
并排
Showing
30 changed file
with
102 addition
and
250 deletion
+102
-250
src/librustc/lint/builtin.rs
src/librustc/lint/builtin.rs
+0
-65
src/librustc_const_eval/pattern.rs
src/librustc_const_eval/pattern.rs
+6
-15
src/librustc_lint/lib.rs
src/librustc_lint/lib.rs
+30
-43
src/librustc_passes/ast_validation.rs
src/librustc_passes/ast_validation.rs
+7
-18
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+5
-12
src/librustc_resolve/resolve_imports.rs
src/librustc_resolve/resolve_imports.rs
+8
-17
src/librustc_typeck/collect.rs
src/librustc_typeck/collect.rs
+2
-7
src/libsyntax/test.rs
src/libsyntax/test.rs
+0
-8
src/test/compile-fail/associated-types/bound-lifetime-constrained.rs
...mpile-fail/associated-types/bound-lifetime-constrained.rs
+0
-1
src/test/compile-fail/associated-types/bound-lifetime-in-return-only.rs
...le-fail/associated-types/bound-lifetime-in-return-only.rs
+0
-1
src/test/compile-fail/extern-crate-visibility.rs
src/test/compile-fail/extern-crate-visibility.rs
+0
-6
src/test/compile-fail/future-incompatible-lint-group.rs
src/test/compile-fail/future-incompatible-lint-group.rs
+6
-13
src/test/compile-fail/generic-impl-less-params-with-defaults.rs
...st/compile-fail/generic-impl-less-params-with-defaults.rs
+1
-1
src/test/compile-fail/generic-impl-more-params-with-defaults.rs
...st/compile-fail/generic-impl-more-params-with-defaults.rs
+1
-1
src/test/compile-fail/issue-1920-1.rs
src/test/compile-fail/issue-1920-1.rs
+1
-1
src/test/compile-fail/issue-1920-3.rs
src/test/compile-fail/issue-1920-3.rs
+1
-1
src/test/compile-fail/issue-6804.rs
src/test/compile-fail/issue-6804.rs
+0
-2
src/test/compile-fail/lifetime-underscore.rs
src/test/compile-fail/lifetime-underscore.rs
+0
-4
src/test/compile-fail/match-argm-statics-2.rs
src/test/compile-fail/match-argm-statics-2.rs
+2
-0
src/test/compile-fail/privacy/restricted/struct-literal-field.rs
...t/compile-fail/privacy/restricted/struct-literal-field.rs
+0
-1
src/test/compile-fail/privacy/restricted/test.rs
src/test/compile-fail/privacy/restricted/test.rs
+0
-1
src/test/compile-fail/private-in-public-lint.rs
src/test/compile-fail/private-in-public-lint.rs
+0
-2
src/test/compile-fail/private-variant-reexport.rs
src/test/compile-fail/private-variant-reexport.rs
+0
-11
src/test/compile-fail/pub-reexport-priv-extern-crate.rs
src/test/compile-fail/pub-reexport-priv-extern-crate.rs
+31
-0
src/test/compile-fail/resolve-self-in-impl.rs
src/test/compile-fail/resolve-self-in-impl.rs
+0
-1
src/test/compile-fail/rfc1445/feature-gate.rs
src/test/compile-fail/rfc1445/feature-gate.rs
+1
-2
src/test/compile-fail/rfc1445/match-forbidden-without-eq.rs
src/test/compile-fail/rfc1445/match-forbidden-without-eq.rs
+0
-5
src/test/compile-fail/rfc1445/match-requires-both-partialeq-and-eq.rs
...pile-fail/rfc1445/match-requires-both-partialeq-and-eq.rs
+0
-4
src/test/compile-fail/type-parameter-invalid-lint.rs
src/test/compile-fail/type-parameter-invalid-lint.rs
+0
-5
src/test/compile-fail/use-super-global-path.rs
src/test/compile-fail/use-super-global-path.rs
+0
-2
未找到文件。
src/librustc/lint/builtin.rs
浏览文件 @
caecb76f
...
...
@@ -130,68 +130,12 @@
"detect private items in public interfaces not caught by the old implementation"
}
declare_lint!
{
pub
INACCESSIBLE_EXTERN_CRATE
,
Deny
,
"use of inaccessible extern crate erroneously allowed"
}
declare_lint!
{
pub
INVALID_TYPE_PARAM_DEFAULT
,
Deny
,
"type parameter default erroneously allowed in invalid location"
}
declare_lint!
{
pub
ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN
,
Deny
,
"floating-point constants cannot be used in patterns"
}
declare_lint!
{
pub
ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN
,
Deny
,
"constants of struct or enum type can only be used in a pattern if
\
the struct or enum has `#[derive(PartialEq, Eq)]`"
}
declare_lint!
{
pub
RAW_POINTER_DERIVE
,
Warn
,
"uses of #[derive] with raw pointers are rarely correct"
}
declare_lint!
{
pub
HR_LIFETIME_IN_ASSOC_TYPE
,
Deny
,
"binding for associated type references higher-ranked lifetime
\
that does not appear in the trait input types"
}
declare_lint!
{
pub
OVERLAPPING_INHERENT_IMPLS
,
Deny
,
"two overlapping inherent impls define an item with the same name were erroneously allowed"
}
declare_lint!
{
pub
RENAMED_AND_REMOVED_LINTS
,
Warn
,
"lints that have been renamed or removed"
}
declare_lint!
{
pub
SUPER_OR_SELF_IN_GLOBAL_PATH
,
Deny
,
"detects super or self keywords at the beginning of global path"
}
declare_lint!
{
pub
LIFETIME_UNDERSCORE
,
Deny
,
"lifetimes or labels named `'_` were erroneously allowed"
}
declare_lint!
{
pub
RESOLVE_TRAIT_ON_DEFAULTED_UNIT
,
Warn
,
...
...
@@ -280,17 +224,8 @@ fn get_lints(&self) -> LintArray {
TRIVIAL_CASTS
,
TRIVIAL_NUMERIC_CASTS
,
PRIVATE_IN_PUBLIC
,
INACCESSIBLE_EXTERN_CRATE
,
INVALID_TYPE_PARAM_DEFAULT
,
ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN
,
ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN
,
CONST_ERR
,
RAW_POINTER_DERIVE
,
OVERLAPPING_INHERENT_IMPLS
,
RENAMED_AND_REMOVED_LINTS
,
SUPER_OR_SELF_IN_GLOBAL_PATH
,
HR_LIFETIME_IN_ASSOC_TYPE
,
LIFETIME_UNDERSCORE
,
RESOLVE_TRAIT_ON_DEFAULTED_UNIT
,
SAFE_EXTERN_STATICS
,
PATTERNS_IN_FNS_WITHOUT_BODY
,
...
...
src/librustc_const_eval/pattern.rs
浏览文件 @
caecb76f
...
...
@@ -10,7 +10,6 @@
use
eval
;
use
rustc
::
lint
;
use
rustc
::
middle
::
const_val
::{
ConstEvalErr
,
ConstVal
};
use
rustc
::
mir
::{
Field
,
BorrowKind
,
Mutability
};
use
rustc
::
ty
::{
self
,
TyCtxt
,
AdtDef
,
Ty
,
TypeVariants
,
Region
};
...
...
@@ -644,11 +643,7 @@ fn lower_const_expr(&mut self,
debug!
(
"expr={:?} pat_ty={:?} pat_id={}"
,
expr
,
pat_ty
,
pat_id
);
match
pat_ty
.sty
{
ty
::
TyFloat
(
_
)
=>
{
self
.tcx.sess
.add_lint
(
lint
::
builtin
::
ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN
,
pat_id
,
span
,
format!
(
"floating point constants cannot be used in patterns"
));
self
.tcx.sess
.span_err
(
span
,
"floating point constants cannot be used in patterns"
);
}
ty
::
TyAdt
(
adt_def
,
_
)
if
adt_def
.is_union
()
=>
{
// Matching on union fields is unsafe, we can't hide it in constants
...
...
@@ -656,15 +651,11 @@ fn lower_const_expr(&mut self,
}
ty
::
TyAdt
(
adt_def
,
_
)
=>
{
if
!
self
.tcx
.has_attr
(
adt_def
.did
,
"structural_match"
)
{
self
.tcx.sess
.add_lint
(
lint
::
builtin
::
ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN
,
pat_id
,
span
,
format!
(
"to use a constant of type `{}`
\
in a pattern,
\
`{}` must be annotated with `#[derive(PartialEq, Eq)]`"
,
self
.tcx
.item_path_str
(
adt_def
.did
),
self
.tcx
.item_path_str
(
adt_def
.did
)));
let
msg
=
format!
(
"to use a constant of type `{}` in a pattern,
\
`{}` must be annotated with `#[derive(PartialEq, Eq)]`"
,
self
.tcx
.item_path_str
(
adt_def
.did
),
self
.tcx
.item_path_str
(
adt_def
.did
));
self
.tcx.sess
.span_err
(
span
,
&
msg
);
}
}
_
=>
{
}
...
...
src/librustc_lint/lib.rs
浏览文件 @
caecb76f
...
...
@@ -179,7 +179,7 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
// - Create a lint defaulting to warn as normal, with ideally the same error
// message you would normally give
// - Add a suitable reference, typically an RFC or tracking issue. Go ahead
// and include the full URL.
// and include the full URL
, sort items in ascending order of issue numbers
.
// - Later, change lint to error
// - Eventually, remove lint
store
.register_future_incompatible
(
sess
,
...
...
@@ -189,48 +189,12 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
reference
:
"issue #34537 <https://github.com/rust-lang/rust/issues/34537>"
,
},
FutureIncompatibleInfo
{
id
:
LintId
::
of
(
INACCESSIBLE_EXTERN_CRATE
),
reference
:
"issue #36886 <https://github.com/rust-lang/rust/issues/36886>"
,
},
FutureIncompatibleInfo
{
id
:
LintId
::
of
(
INVALID_TYPE_PARAM_DEFAULT
),
reference
:
"issue #36887 <https://github.com/rust-lang/rust/issues/36887>"
,
},
FutureIncompatibleInfo
{
id
:
LintId
::
of
(
SUPER_OR_SELF_IN_GLOBAL_PATH
),
reference
:
"issue #36888 <https://github.com/rust-lang/rust/issues/36888>"
,
},
FutureIncompatibleInfo
{
id
:
LintId
::
of
(
ILLEGAL_FLOATING_POINT_CONSTANT_PATTERN
),
reference
:
"issue #36890 <https://github.com/rust-lang/rust/issues/36890>"
,
},
FutureIncompatibleInfo
{
id
:
LintId
::
of
(
ILLEGAL_FLOATING_POINT_LITERAL_PATTERN
),
reference
:
"issue #41620 <https://github.com/rust-lang/rust/issues/41620>"
,
},
FutureIncompatibleInfo
{
id
:
LintId
::
of
(
ILLEGAL_STRUCT_OR_ENUM_CONSTANT_PATTERN
),
reference
:
"issue #36891 <https://github.com/rust-lang/rust/issues/36891>"
,
},
FutureIncompatibleInfo
{
id
:
LintId
::
of
(
HR_LIFETIME_IN_ASSOC_TYPE
),
reference
:
"issue #33685 <https://github.com/rust-lang/rust/issues/33685>"
,
},
FutureIncompatibleInfo
{
id
:
LintId
::
of
(
LIFETIME_UNDERSCORE
),
reference
:
"issue #36892 <https://github.com/rust-lang/rust/issues/36892>"
,
},
FutureIncompatibleInfo
{
id
:
LintId
::
of
(
RESOLVE_TRAIT_ON_DEFAULTED_UNIT
),
reference
:
"issue #39216 <https://github.com/rust-lang/rust/issues/39216>"
,
id
:
LintId
::
of
(
PATTERNS_IN_FNS_WITHOUT_BODY
),
reference
:
"issue #35203 <https://github.com/rust-lang/rust/issues/35203>"
,
},
FutureIncompatibleInfo
{
id
:
LintId
::
of
(
SAFE_EXTERN_STATICS
),
reference
:
"issue #36247 <https://github.com/rust-lang/rust/issues/35112>"
,
},
FutureIncompatibleInfo
{
id
:
LintId
::
of
(
PATTERNS_IN_FNS_WITHOUT_BODY
),
reference
:
"issue #35203 <https://github.com/rust-lang/rust/issues/35203>"
,
reference
:
"issue #36247 <https://github.com/rust-lang/rust/issues/36247>"
,
},
FutureIncompatibleInfo
{
id
:
LintId
::
of
(
EXTRA_REQUIREMENT_IN_IMPL
),
...
...
@@ -248,18 +212,26 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
id
:
LintId
::
of
(
LEGACY_CONSTRUCTOR_VISIBILITY
),
reference
:
"issue #39207 <https://github.com/rust-lang/rust/issues/39207>"
,
},
FutureIncompatibleInfo
{
id
:
LintId
::
of
(
RESOLVE_TRAIT_ON_DEFAULTED_UNIT
),
reference
:
"issue #39216 <https://github.com/rust-lang/rust/issues/39216>"
,
},
FutureIncompatibleInfo
{
id
:
LintId
::
of
(
MISSING_FRAGMENT_SPECIFIER
),
reference
:
"issue #40107 <https://github.com/rust-lang/rust/issues/40107>"
,
},
FutureIncompatibleInfo
{
id
:
LintId
::
of
(
PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES
),
reference
:
"issue #4
2238 <https://github.com/rust-lang/rust/issues/42238
>"
,
id
:
LintId
::
of
(
ILLEGAL_FLOATING_POINT_LITERAL_PATTERN
),
reference
:
"issue #4
1620 <https://github.com/rust-lang/rust/issues/41620
>"
,
},
FutureIncompatibleInfo
{
id
:
LintId
::
of
(
ANONYMOUS_PARAMETERS
),
reference
:
"issue #41686 <https://github.com/rust-lang/rust/issues/41686>"
,
},
FutureIncompatibleInfo
{
id
:
LintId
::
of
(
PARENTHESIZED_PARAMS_IN_TYPES_AND_MODULES
),
reference
:
"issue #42238 <https://github.com/rust-lang/rust/issues/42238>"
,
}
]);
// Register renamed and removed lints
...
...
@@ -275,5 +247,20 @@ pub fn register_builtins(store: &mut lint::LintStore, sess: Option<&Session>) {
store
.register_removed
(
"drop_with_repr_extern"
,
"drop flags have been removed"
);
store
.register_removed
(
"transmute_from_fn_item_types"
,
"always cast functions before transmuting them"
);
store
.register_removed
(
"overlapping_inherent_impls"
,
"converted into hard error, see #36889"
);
store
.register_removed
(
"hr_lifetime_in_assoc_type"
,
"converted into hard error, see https://github.com/rust-lang/rust/issues/33685"
);
store
.register_removed
(
"inaccessible_extern_crate"
,
"converted into hard error, see https://github.com/rust-lang/rust/issues/36886"
);
store
.register_removed
(
"invalid_type_param_default"
,
"converted into hard error, see https://github.com/rust-lang/rust/issues/36887"
);
store
.register_removed
(
"super_or_self_in_global_path"
,
"converted into hard error, see https://github.com/rust-lang/rust/issues/36888"
);
store
.register_removed
(
"overlapping_inherent_impls"
,
"converted into hard error, see https://github.com/rust-lang/rust/issues/36889"
);
store
.register_removed
(
"illegal_floating_point_constant_pattern"
,
"converted into hard error, see https://github.com/rust-lang/rust/issues/36890"
);
store
.register_removed
(
"illegal_struct_or_enum_constant_pattern"
,
"converted into hard error, see https://github.com/rust-lang/rust/issues/36891"
);
store
.register_removed
(
"lifetime_underscore"
,
"converted into hard error, see https://github.com/rust-lang/rust/issues/36892"
);
}
src/librustc_passes/ast_validation.rs
浏览文件 @
caecb76f
...
...
@@ -36,16 +36,10 @@ fn err_handler(&self) -> &errors::Handler {
&
self
.session.parse_sess.span_diagnostic
}
fn
check_label
(
&
self
,
label
:
Ident
,
span
:
Span
,
id
:
NodeId
)
{
if
label
.name
==
keywords
::
StaticLifetime
.name
()
{
fn
check_label
(
&
self
,
label
:
Ident
,
span
:
Span
)
{
if
label
.name
==
keywords
::
StaticLifetime
.name
()
||
label
.name
==
"'_"
{
self
.err_handler
()
.span_err
(
span
,
&
format!
(
"invalid label name `{}`"
,
label
.name
));
}
if
label
.name
==
"'_"
{
self
.session
.add_lint
(
lint
::
builtin
::
LIFETIME_UNDERSCORE
,
id
,
span
,
format!
(
"invalid label name `{}`"
,
label
.name
));
}
}
fn
invalid_visibility
(
&
self
,
vis
:
&
Visibility
,
span
:
Span
,
note
:
Option
<&
str
>
)
{
...
...
@@ -104,10 +98,7 @@ fn no_questions_in_bounds(&self, bounds: &TyParamBounds, where_: &str, is_trait:
impl
<
'a
>
Visitor
<
'a
>
for
AstValidator
<
'a
>
{
fn
visit_lifetime
(
&
mut
self
,
lt
:
&
'a
Lifetime
)
{
if
lt
.ident.name
==
"'_"
{
self
.session
.add_lint
(
lint
::
builtin
::
LIFETIME_UNDERSCORE
,
lt
.id
,
lt
.span
,
format!
(
"invalid lifetime name `{}`"
,
lt
.ident
));
self
.err_handler
()
.span_err
(
lt
.span
,
&
format!
(
"invalid lifetime name `{}`"
,
lt
.ident
));
}
visit
::
walk_lifetime
(
self
,
lt
)
...
...
@@ -121,7 +112,7 @@ fn visit_expr(&mut self, expr: &'a Expr) {
ExprKind
::
ForLoop
(
..
,
Some
(
ident
))
|
ExprKind
::
Break
(
Some
(
ident
),
_
)
|
ExprKind
::
Continue
(
Some
(
ident
))
=>
{
self
.check_label
(
ident
.node
,
ident
.span
,
expr
.id
);
self
.check_label
(
ident
.node
,
ident
.span
);
}
_
=>
{}
}
...
...
@@ -169,14 +160,12 @@ fn visit_ty(&mut self, ty: &'a Ty) {
visit
::
walk_ty
(
self
,
ty
)
}
fn
visit_path
(
&
mut
self
,
path
:
&
'a
Path
,
id
:
NodeId
)
{
fn
visit_path
(
&
mut
self
,
path
:
&
'a
Path
,
_
:
NodeId
)
{
if
path
.segments
.len
()
>=
2
&&
path
.is_global
()
{
let
ident
=
path
.segments
[
1
]
.identifier
;
if
token
::
Ident
(
ident
)
.is_path_segment_keyword
()
{
self
.session
.add_lint
(
lint
::
builtin
::
SUPER_OR_SELF_IN_GLOBAL_PATH
,
id
,
path
.span
,
format!
(
"global paths cannot start with `{}`"
,
ident
));
self
.err_handler
()
.span_err
(
path
.span
,
&
format!
(
"global paths cannot start with `{}`"
,
ident
));
}
}
...
...
src/librustc_resolve/lib.rs
浏览文件 @
caecb76f
...
...
@@ -1069,6 +1069,10 @@ fn is_macro_def(&self) -> bool {
_
=>
false
,
}
}
fn
descr
(
&
self
)
->
&
'static
str
{
if
self
.is_extern_crate
()
{
"extern crate"
}
else
{
self
.def
()
.kind_name
()
}
}
}
/// Interns the names of the primitive types.
...
...
@@ -3424,18 +3428,7 @@ fn report_errors(&mut self) {
for
&
PrivacyError
(
span
,
name
,
binding
)
in
&
self
.privacy_errors
{
if
!
reported_spans
.insert
(
span
)
{
continue
}
if
binding
.is_extern_crate
()
{
// Warn when using an inaccessible extern crate.
let
node_id
=
match
binding
.kind
{
NameBindingKind
::
Import
{
directive
,
..
}
=>
directive
.id
,
_
=>
unreachable!
(),
};
let
msg
=
format!
(
"extern crate `{}` is private"
,
name
);
self
.session
.add_lint
(
lint
::
builtin
::
INACCESSIBLE_EXTERN_CRATE
,
node_id
,
span
,
msg
);
}
else
{
let
def
=
binding
.def
();
self
.session
.span_err
(
span
,
&
format!
(
"{} `{}` is private"
,
def
.kind_name
(),
name
));
}
self
.session
.span_err
(
span
,
&
format!
(
"{} `{}` is private"
,
binding
.descr
(),
name
));
}
}
...
...
src/librustc_resolve/resolve_imports.rs
浏览文件 @
caecb76f
...
...
@@ -18,7 +18,6 @@
use
{
resolve_error
,
ResolutionError
};
use
rustc
::
ty
;
use
rustc
::
lint
::
builtin
::
PRIVATE_IN_PUBLIC
;
use
rustc
::
hir
::
def_id
::
DefId
;
use
rustc
::
hir
::
def
::
*
;
use
rustc
::
util
::
nodemap
::
FxHashMap
;
...
...
@@ -295,8 +294,7 @@ pub fn add_import_directive(&mut self,
// return the corresponding binding defined by the import directive.
pub
fn
import
(
&
self
,
binding
:
&
'a
NameBinding
<
'a
>
,
directive
:
&
'a
ImportDirective
<
'a
>
)
->
&
'a
NameBinding
<
'a
>
{
let
vis
=
if
binding
.pseudo_vis
()
.is_at_least
(
directive
.vis
.get
(),
self
)
||
!
directive
.is_glob
()
&&
binding
.is_extern_crate
()
{
// c.f. `PRIVATE_IN_PUBLIC`
let
vis
=
if
binding
.pseudo_vis
()
.is_at_least
(
directive
.vis
.get
(),
self
)
{
directive
.vis
.get
()
}
else
{
binding
.pseudo_vis
()
...
...
@@ -720,13 +718,7 @@ fn finalize_import(&mut self, directive: &'b ImportDirective<'b>) -> Option<Stri
// All namespaces must be re-exported with extra visibility for an error to occur.
if
!
any_successful_reexport
{
let
(
ns
,
binding
)
=
reexport_error
.unwrap
();
if
ns
==
TypeNS
&&
binding
.is_extern_crate
()
{
let
msg
=
format!
(
"extern crate `{}` is private, and cannot be reexported
\
(error E0364), consider declaring with `pub`"
,
ident
);
self
.session
.add_lint
(
PRIVATE_IN_PUBLIC
,
directive
.id
,
directive
.span
,
msg
);
}
else
if
ns
==
TypeNS
{
if
reexport_error
.unwrap
()
.0
==
TypeNS
{
struct_span_err!
(
self
.session
,
directive
.span
,
E0365
,
"`{}` is private, and cannot be reexported"
,
ident
)
.span_label
(
directive
.span
,
format!
(
"reexport of private `{}`"
,
ident
))
...
...
@@ -792,8 +784,8 @@ fn resolve_glob_import(&mut self, directive: &'b ImportDirective<'b>) {
self
.record_def
(
directive
.id
,
PathResolution
::
new
(
module
.def
()
.unwrap
()));
}
// Miscellaneous post-processing, including recording reexports,
reporting conflicts,
// reporting
the PRIVATE_IN_PUBLIC lint
, and reporting unresolved imports.
// Miscellaneous post-processing, including recording reexports,
// reporting
conflicts
, and reporting unresolved imports.
fn
finalize_resolutions_in
(
&
mut
self
,
module
:
Module
<
'b
>
)
{
// Since import resolution is finished, globs will not define any more names.
*
module
.globs
.borrow_mut
()
=
Vec
::
new
();
...
...
@@ -838,13 +830,12 @@ fn finalize_resolutions_in(&mut self, module: Module<'b>) {
}
match
binding
.kind
{
NameBindingKind
::
Import
{
binding
:
orig_binding
,
directive
,
..
}
=>
{
NameBindingKind
::
Import
{
binding
:
orig_binding
,
..
}
=>
{
if
ns
==
TypeNS
&&
orig_binding
.is_variant
()
&&
!
orig_binding
.vis
.is_at_least
(
binding
.vis
,
&*
self
)
{
let
msg
=
format!
(
"variant `{}` is private, and cannot be reexported
\
(error E0364), consider declaring its enum as `pub`"
,
ident
);
self
.session
.add_lint
(
PRIVATE_IN_PUBLIC
,
directive
.id
,
binding
.span
,
msg
);
let
msg
=
format!
(
"variant `{}` is private, and cannot be reexported,
\
consider declaring its enum as `pub`"
,
ident
);
self
.session
.span_err
(
binding
.span
,
&
msg
);
}
}
NameBindingKind
::
Ambiguity
{
b1
,
b2
,
..
}
...
...
src/librustc_typeck/collect.rs
浏览文件 @
caecb76f
...
...
@@ -54,7 +54,6 @@
*/
use
astconv
::{
AstConv
,
Bounds
};
use
lint
;
use
constrained_type_params
as
ctp
;
use
middle
::
lang_items
::
SizedTraitLangItem
;
use
middle
::
const_val
::
ConstVal
;
...
...
@@ -897,12 +896,8 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
if
!
allow_defaults
&&
p
.default
.is_some
()
{
if
!
tcx
.sess.features
.borrow
()
.default_type_parameter_fallback
{
tcx
.sess
.add_lint
(
lint
::
builtin
::
INVALID_TYPE_PARAM_DEFAULT
,
p
.id
,
p
.span
,
format!
(
"defaults for type parameters are only allowed in `struct`,
\
`enum`, `type`, or `trait` definitions."
));
tcx
.sess
.span_err
(
p
.span
,
"defaults for type parameters are only allowed in
\
`struct`, `enum`, `type`, or `trait` definitions."
);
}
}
...
...
src/libsyntax/test.rs
浏览文件 @
caecb76f
...
...
@@ -231,20 +231,12 @@ fn mk_reexport_mod(cx: &mut TestCtxt,
->
(
P
<
ast
::
Item
>
,
Ident
)
{
let
super_
=
Ident
::
from_str
(
"super"
);
// Generate imports with `#[allow(private_in_public)]` to work around issue #36768.
let
allow_private_in_public
=
cx
.ext_cx
.attribute
(
DUMMY_SP
,
cx
.ext_cx
.meta_list
(
DUMMY_SP
,
Symbol
::
intern
(
"allow"
),
vec!
[
cx
.ext_cx
.meta_list_item_word
(
DUMMY_SP
,
Symbol
::
intern
(
"private_in_public"
))],
));
let
items
=
tests
.into_iter
()
.map
(|
r
|
{
cx
.ext_cx
.item_use_simple
(
DUMMY_SP
,
ast
::
Visibility
::
Public
,
cx
.ext_cx
.path
(
DUMMY_SP
,
vec!
[
super_
,
r
]))
.map_attrs
(|
_
|
vec!
[
allow_private_in_public
.clone
()])
})
.chain
(
tested_submods
.into_iter
()
.map
(|(
r
,
sym
)|
{
let
path
=
cx
.ext_cx
.path
(
DUMMY_SP
,
vec!
[
super_
,
r
,
sym
]);
cx
.ext_cx
.item_use_simple_
(
DUMMY_SP
,
ast
::
Visibility
::
Public
,
r
,
path
)
.map_attrs
(|
_
|
vec!
[
allow_private_in_public
.clone
()])
}))
.collect
();
let
reexport_mod
=
ast
::
Mod
{
...
...
src/test/compile-fail/associated-types/bound-lifetime-constrained.rs
浏览文件 @
caecb76f
...
...
@@ -12,7 +12,6 @@
#![allow(dead_code)]
#![feature(rustc_attrs)]
#![allow(hr_lifetime_in_assoc_type)]
trait
Foo
<
'a
>
{
type
Item
;
...
...
src/test/compile-fail/associated-types/bound-lifetime-in-return-only.rs
浏览文件 @
caecb76f
...
...
@@ -13,7 +13,6 @@
#![allow(dead_code)]
#![feature(rustc_attrs)]
#![feature(unboxed_closures)]
#![deny(hr_lifetime_in_assoc_type)]
trait
Foo
{
type
Item
;
...
...
src/test/compile-fail/extern-crate-visibility.rs
浏览文件 @
caecb76f
...
...
@@ -8,21 +8,15 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![allow(unused)]
mod
foo
{
extern
crate
core
;
}
// Check that private crates can be used from outside their modules, albeit with warnings
use
foo
::
core
;
//~ WARN extern crate `core` is private
//~^ WARN this was previously accepted by the compiler but is being phased out
use
foo
::
core
::
cell
;
//~ ERROR extern crate `core` is private
//~^ WARN this was previously accepted by the compiler but is being phased out
fn
f
()
{
foo
::
core
::
cell
::
Cell
::
new
(
0
);
//~ ERROR extern crate `core` is private
//~^ WARN this was previously accepted by the compiler but is being phased out
use
foo
::
*
;
mod
core
{}
// Check that private crates are not glob imported
...
...
src/test/
run-pass/issue-37020
.rs
→
src/test/
compile-fail/future-incompatible-lint-group
.rs
浏览文件 @
caecb76f
// Copyright 201
6
The Rust Project Developers. See the COPYRIGHT
// Copyright 201
7
The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
...
...
@@ -8,18 +8,11 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![
allow(private_in_public
)]
#![
deny(future_incompatible
)]
mod
foo
{
pub
mod
bar
{
extern
crate
core
;
}
trait
Tr
{
fn
f
(
u8
)
{}
//~ ERROR use of deprecated anonymous parameter
//~^ WARN this was previously accepted
}
mod
baz
{
pub
use
foo
::
bar
::
core
;
}
fn
main
()
{
baz
::
core
::
cell
::
Cell
::
new
(
0u32
);
}
fn
main
()
{}
src/test/compile-fail/generic-impl-less-params-with-defaults.rs
浏览文件 @
caecb76f
...
...
@@ -13,7 +13,7 @@
struct
Foo
<
A
,
B
,
C
=
(
A
,
B
)
>
(
marker
::
PhantomData
<
(
A
,
B
,
C
)
>
);
impl
<
A
,
B
,
C
=
(
A
,
B
)
>
Foo
<
A
,
B
,
C
>
{
impl
<
A
,
B
,
C
>
Foo
<
A
,
B
,
C
>
{
fn
new
()
->
Foo
<
A
,
B
,
C
>
{
Foo
(
marker
::
PhantomData
)}
}
...
...
src/test/compile-fail/generic-impl-more-params-with-defaults.rs
浏览文件 @
caecb76f
...
...
@@ -15,7 +15,7 @@
struct
Vec
<
T
,
A
=
Heap
>
(
marker
::
PhantomData
<
(
T
,
A
)
>
);
impl
<
T
,
A
=
Heap
>
Vec
<
T
,
A
>
{
impl
<
T
,
A
>
Vec
<
T
,
A
>
{
fn
new
()
->
Vec
<
T
,
A
>
{
Vec
(
marker
::
PhantomData
)}
}
...
...
src/test/compile-fail/issue-1920-1.rs
浏览文件 @
caecb76f
...
...
@@ -11,7 +11,7 @@
//! Test that absolute path names are correct when a crate is not linked into the root namespace
mod
foo
{
extern
crate
core
;
pub
extern
crate
core
;
}
fn
assert_clone
<
T
>
()
where
T
:
Clone
{
}
...
...
src/test/compile-fail/issue-1920-3.rs
浏览文件 @
caecb76f
...
...
@@ -11,7 +11,7 @@
//! Test that when a crate is linked multiple times that the shortest absolute path name is used
mod
foo
{
extern
crate
core
;
pub
extern
crate
core
;
}
extern
crate
core
;
...
...
src/test/compile-fail/issue-6804.rs
浏览文件 @
caecb76f
...
...
@@ -19,13 +19,11 @@ fn main() {
let
x
=
NAN
;
match
x
{
NAN
=>
{},
//~ ERROR floating point constants cannot be used
//~| WARNING hard error
_
=>
{},
};
match
[
x
,
1.0
]
{
[
NAN
,
_
]
=>
{},
//~ ERROR floating point constants cannot be used
//~| WARNING hard error
_
=>
{},
};
}
src/test/compile-fail/lifetime-underscore.rs
浏览文件 @
caecb76f
...
...
@@ -9,17 +9,13 @@
// except according to those terms.
fn
_
f
<
'_
>
()
//~ ERROR invalid lifetime name `'_`
//~^ WARN this was previously accepted
->
&
'_
u8
//~ ERROR invalid lifetime name `'_`
//~^ WARN this was previously accepted
{
panic!
();
}
fn
main
()
{
'_
:
loop
{
//~ ERROR invalid label name `'_`
//~^ WARN this was previously accepted
break
'_
//~ ERROR invalid label name `'_`
//~^ WARN this was previously accepted
}
}
src/test/compile-fail/match-argm-statics-2.rs
浏览文件 @
caecb76f
...
...
@@ -10,8 +10,10 @@
use
self
::
Direction
::{
North
,
East
,
South
,
West
};
#[derive(PartialEq,
Eq)]
struct
NewBool
(
bool
);
#[derive(PartialEq,
Eq)]
enum
Direction
{
North
,
East
,
...
...
src/test/compile-fail/privacy/restricted/struct-literal-field.rs
浏览文件 @
caecb76f
...
...
@@ -8,7 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![deny(private_in_public)]
#![allow(warnings)]
mod
foo
{
...
...
src/test/compile-fail/privacy/restricted/test.rs
浏览文件 @
caecb76f
...
...
@@ -10,7 +10,6 @@
// aux-build:pub_restricted.rs
#![deny(private_in_public)]
#![allow(warnings)]
extern
crate
pub_restricted
;
...
...
src/test/compile-fail/private-in-public-lint.rs
浏览文件 @
caecb76f
...
...
@@ -18,8 +18,6 @@ pub fn f() -> Priv {Priv} //~ ERROR private type `m1::Priv` in public interface
}
mod
m2
{
#![deny(future_incompatible)]
pub
struct
Pub
;
struct
Priv
;
...
...
src/test/compile-fail/private-variant-
and-crate-
reexport.rs
→
src/test/compile-fail/private-variant-reexport.rs
浏览文件 @
caecb76f
...
...
@@ -8,31 +8,20 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![deny(private_in_public)]
#![allow(dead_code)]
extern
crate
core
;
pub
use
core
as
reexported_core
;
//~ ERROR extern crate `core` is private, and cannot be reexported
//~^ WARNING hard error
mod
m1
{
pub
use
::
E
::
V
;
//~ ERROR variant `V` is private, and cannot be reexported
//~^ WARNING hard error
}
mod
m2
{
pub
use
::
E
::{
V
};
//~ ERROR variant `V` is private, and cannot be reexported
//~^ WARNING hard error
}
mod
m3
{
pub
use
::
E
::
V
::{
self
};
//~ ERROR variant `V` is private, and cannot be reexported
//~^ WARNING hard error
}
mod
m4
{
pub
use
::
E
::
*
;
//~ ERROR variant `V` is private, and cannot be reexported
//~^ WARNING hard error
}
enum
E
{
V
}
...
...
src/test/compile-fail/pub-reexport-priv-extern-crate.rs
0 → 100644
浏览文件 @
caecb76f
// Copyright 2017 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)]
extern
crate
core
;
pub
use
core
as
reexported_core
;
//~ ERROR `core` is private, and cannot be reexported
mod
foo1
{
extern
crate
core
;
}
mod
foo2
{
use
foo1
::
core
;
//~ ERROR `core` is private, and cannot be reexported
pub
mod
bar
{
extern
crate
core
;
}
}
mod
baz
{
pub
use
foo2
::
bar
::
core
;
//~ ERROR `core` is private, and cannot be reexported
}
fn
main
()
{}
src/test/compile-fail/resolve-self-in-impl.rs
浏览文件 @
caecb76f
...
...
@@ -17,7 +17,6 @@ trait Tr<T = u8> {
impl
Tr
<
Self
>
for
S
{}
// OK
impl
<
T
:
Tr
<
Self
>>
Tr
<
T
>
for
S
{}
// OK
impl
<
T
=
Self
>
Tr
<
T
>
for
S
{}
// OK
impl
Tr
for
S
where
Self
:
Copy
{}
// OK
impl
Tr
for
S
where
S
<
Self
>
:
Copy
{}
// OK
impl
Tr
for
S
where
Self
::
A
:
Copy
{}
// OK
...
...
src/test/compile-fail/rfc1445/feature-gate.rs
浏览文件 @
caecb76f
...
...
@@ -16,8 +16,7 @@
// gate-test-structural_match
#![allow(dead_code)]
#![deny(future_incompatible)]
#![allow(unused)]
#![feature(rustc_attrs)]
#![cfg_attr(with_gate,
feature(structural_match))]
...
...
src/test/compile-fail/rfc1445/match-forbidden-without-eq.rs
浏览文件 @
caecb76f
...
...
@@ -8,9 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![allow(dead_code)]
#![deny(future_incompatible)]
use
std
::
f32
;
#[derive(PartialEq)]
...
...
@@ -25,7 +22,6 @@ fn main() {
match
y
{
FOO
=>
{
}
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
//~| WARNING will become a hard error
_
=>
{
}
}
...
...
@@ -33,7 +29,6 @@ fn main() {
match
x
{
f32
::
INFINITY
=>
{
}
//~^ ERROR floating point constants cannot be used in patterns
//~| WARNING will become a hard error
_
=>
{
}
}
}
src/test/compile-fail/rfc1445/match-requires-both-partialeq-and-eq.rs
浏览文件 @
caecb76f
...
...
@@ -8,9 +8,6 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![allow(dead_code)]
#![deny(future_incompatible)]
#[derive(Eq)]
struct
Foo
{
x
:
u32
...
...
@@ -29,7 +26,6 @@ fn main() {
match
y
{
FOO
=>
{
}
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
//~| WARNING will become a hard error
_
=>
{
}
}
}
src/test/compile-fail/type-parameter-invalid-lint.rs
浏览文件 @
caecb76f
...
...
@@ -10,16 +10,11 @@
// gate-test-default_type_parameter_fallback
#![deny(future_incompatible)]
#![allow(dead_code)]
fn
avg
<
T
=
i32
>
(
_
:
T
)
{}
//~^ ERROR defaults for type parameters are only allowed
//~| WARNING hard error
struct
S
<
T
>
(
T
);
impl
<
T
=
i32
>
S
<
T
>
{}
//~^ ERROR defaults for type parameters are only allowed
//~| WARNING hard error
fn
main
()
{}
src/test/compile-fail/use-super-global-path.rs
浏览文件 @
caecb76f
...
...
@@ -15,11 +15,9 @@
mod
foo
{
use
::
super
::{
S
,
Z
};
//~ ERROR global paths cannot start with `super`
//~^ WARN this was previously accepted by the compiler but is being phased out
pub
fn
g
()
{
use
::
super
::
main
;
//~ ERROR global paths cannot start with `super`
//~^ WARN this was previously accepted by the compiler but is being phased out
main
();
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录