Skip to content

Commit dc6b6d3

Browse files
authored
Rollup merge of rust-lang#63095 - Centril:incomplete-features-lint, r=varkor
Turn `INCOMPLETE_FEATURES` into lint We do this because it is annoying to see the warning when building rustc and because this is better from a "separation of concerns" POV. The drawback to this change is that this will respect `--cap-lints`. Also note that this is not a buffered lint so if there are fatal parser errors then the lint will not trigger. r? @varkor
2 parents 14eddad + 24a178e commit dc6b6d3

File tree

65 files changed

+204
-70
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+204
-70
lines changed

src/liballoc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#![warn(missing_debug_implementations)]
6464
#![deny(intra_doc_link_resolution_failure)] // rustdoc is run without -D warnings
6565
#![allow(explicit_outlives_requirements)]
66+
#![cfg_attr(not(bootstrap), allow(incomplete_features))]
6667

6768
#![cfg_attr(not(test), feature(generator_trait))]
6869
#![cfg_attr(test, feature(test))]

src/libcore/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
#![warn(missing_debug_implementations)]
6464
#![deny(intra_doc_link_resolution_failure)] // rustdoc is run without -D warnings
6565
#![allow(explicit_outlives_requirements)]
66+
#![cfg_attr(not(bootstrap), allow(incomplete_features))]
6667

6768
#![feature(allow_internal_unstable)]
6869
#![feature(arbitrary_self_types)]

src/librustc_lint/builtin.rs

+34-3
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@ use lint::{LintPass, LateLintPass, EarlyLintPass, EarlyContext};
3333
use rustc::util::nodemap::FxHashSet;
3434

3535
use syntax::tokenstream::{TokenTree, TokenStream};
36-
use syntax::ast;
36+
use syntax::ast::{self, Expr};
3737
use syntax::ptr::P;
38-
use syntax::ast::Expr;
3938
use syntax::attr::{self, HasAttrs, AttributeTemplate};
4039
use syntax::source_map::Spanned;
4140
use syntax::edition::Edition;
42-
use syntax::feature_gate::{AttributeGate, AttributeType};
41+
use syntax::feature_gate::{self, AttributeGate, AttributeType};
4342
use syntax::feature_gate::{Stability, deprecated_attributes};
4443
use syntax_pos::{BytePos, Span, SyntaxContext};
4544
use syntax::symbol::{Symbol, kw, sym};
@@ -1831,3 +1830,35 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitOutlivesRequirements {
18311830
}
18321831
}
18331832
}
1833+
1834+
declare_lint! {
1835+
pub INCOMPLETE_FEATURES,
1836+
Warn,
1837+
"incomplete features that may function improperly in some or all cases"
1838+
}
1839+
1840+
declare_lint_pass!(
1841+
/// Check for used feature gates in `INCOMPLETE_FEATURES` in `feature_gate.rs`.
1842+
IncompleteFeatures => [INCOMPLETE_FEATURES]
1843+
);
1844+
1845+
impl EarlyLintPass for IncompleteFeatures {
1846+
fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &ast::Crate) {
1847+
let features = cx.sess.features_untracked();
1848+
features.declared_lang_features
1849+
.iter().map(|(name, span, _)| (name, span))
1850+
.chain(features.declared_lib_features.iter().map(|(name, span)| (name, span)))
1851+
.filter(|(name, _)| feature_gate::INCOMPLETE_FEATURES.iter().any(|f| name == &f))
1852+
.for_each(|(name, &span)| {
1853+
cx.struct_span_lint(
1854+
INCOMPLETE_FEATURES,
1855+
span,
1856+
&format!(
1857+
"the feature `{}` is incomplete and may cause the compiler to crash",
1858+
name,
1859+
)
1860+
)
1861+
.emit();
1862+
});
1863+
}
1864+
}

src/librustc_lint/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ macro_rules! early_lint_passes {
9797
DeprecatedAttr: DeprecatedAttr::new(),
9898
WhileTrue: WhileTrue,
9999
NonAsciiIdents: NonAsciiIdents,
100+
IncompleteFeatures: IncompleteFeatures,
100101
]);
101102
)
102103
}

src/libsyntax/feature_gate.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -569,10 +569,10 @@ declare_features! (
569569
// -------------------------------------------------------------------------
570570
);
571571

572-
// Some features are known to be incomplete and using them is likely to have
573-
// unanticipated results, such as compiler crashes. We warn the user about these
574-
// to alert them.
575-
const INCOMPLETE_FEATURES: &[Symbol] = &[
572+
/// Some features are known to be incomplete and using them is likely to have
573+
/// unanticipated results, such as compiler crashes. We warn the user about these
574+
/// to alert them.
575+
pub const INCOMPLETE_FEATURES: &[Symbol] = &[
576576
sym::impl_trait_in_bindings,
577577
sym::generic_associated_types,
578578
sym::const_generics,
@@ -2338,15 +2338,6 @@ pub fn get_features(span_handler: &Handler, krate_attrs: &[ast::Attribute],
23382338
}
23392339

23402340
let name = mi.name_or_empty();
2341-
if INCOMPLETE_FEATURES.iter().any(|f| name == *f) {
2342-
span_handler.struct_span_warn(
2343-
mi.span(),
2344-
&format!(
2345-
"the feature `{}` is incomplete and may cause the compiler to crash",
2346-
name
2347-
)
2348-
).emit();
2349-
}
23502341

23512342
if let Some(edition) = ALL_EDITIONS.iter().find(|e| name == e.feature_name()) {
23522343
if *edition <= crate_edition {

src/test/ui/associated-type-bounds/duplicate.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ warning: the feature `impl_trait_in_bindings` is incomplete and may cause the co
33
|
44
LL | #![feature(impl_trait_in_bindings)]
55
| ^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
68

79
error[E0719]: the value of the associated type `Item` (from the trait `std::iter::Iterator`) is already specified
810
--> $DIR/duplicate.rs:12:36

src/test/ui/associated-type-bounds/dyn-lcsit.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ warning: the feature `impl_trait_in_bindings` is incomplete and may cause the co
33
|
44
LL | #![feature(impl_trait_in_bindings)]
55
| ^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
68

src/test/ui/associated-type-bounds/lcsit.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ warning: the feature `impl_trait_in_bindings` is incomplete and may cause the co
33
|
44
LL | #![feature(impl_trait_in_bindings)]
55
| ^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
68

src/test/ui/const-generics/apit-with-const-param.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
33
|
44
LL | #![feature(const_generics)]
55
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
68

src/test/ui/const-generics/array-wrapper-struct-ctor.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
33
|
44
LL | #![feature(const_generics)]
55
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
68

src/test/ui/const-generics/broken-mir-1.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
33
|
44
LL | #![feature(const_generics)]
55
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
68

src/test/ui/const-generics/broken-mir-2.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
33
|
44
LL | #![feature(const_generics)]
55
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
68

79
error[E0277]: arrays only have std trait implementations for lengths 0..=32
810
--> $DIR/broken-mir-2.rs:7:36

src/test/ui/const-generics/cannot-infer-const-args.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
33
|
44
LL | #![feature(const_generics)]
55
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
68

79
error[E0282]: type annotations needed
810
--> $DIR/cannot-infer-const-args.rs:9:5

src/test/ui/const-generics/cannot-infer-type-for-const-param.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
33
|
44
LL | #![feature(const_generics)]
55
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
68

src/test/ui/const-generics/concrete-const-as-fn-arg.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
33
|
44
LL | #![feature(const_generics)]
55
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
68

src/test/ui/const-generics/concrete-const-impl-method.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
33
|
44
LL | #![feature(const_generics)]
55
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
68

src/test/ui/const-generics/condition-in-trait-const-arg.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
33
|
44
LL | #![feature(const_generics)]
55
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
68

src/test/ui/const-generics/const-arg-in-fn.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
33
|
44
LL | #![feature(const_generics)]
55
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
68

src/test/ui/const-generics/const-expression-parameter.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
99
|
1010
LL | #![feature(const_generics)]
1111
| ^^^^^^^^^^^^^^
12+
|
13+
= note: `#[warn(incomplete_features)]` on by default
1214

1315
error: aborting due to previous error
1416

Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
2-
--> $DIR/const-fn-with-const-param.rs:1:12
3-
|
4-
LL | #![feature(const_generics)]
5-
| ^^^^^^^^^^^^^^
6-
71
error: const parameters are not permitted in `const fn`
82
--> $DIR/const-fn-with-const-param.rs:4:1
93
|
@@ -13,5 +7,13 @@ LL | | X
137
LL | | }
148
| |_^
159

10+
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
11+
--> $DIR/const-fn-with-const-param.rs:1:12
12+
|
13+
LL | #![feature(const_generics)]
14+
| ^^^^^^^^^^^^^^
15+
|
16+
= note: `#[warn(incomplete_features)]` on by default
17+
1618
error: aborting due to previous error
1719

src/test/ui/const-generics/const-generic-array-wrapper.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
33
|
44
LL | #![feature(const_generics)]
55
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
68

src/test/ui/const-generics/const-param-before-other-params.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![feature(const_generics)]
2-
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
32

43
fn bar<const X: (), 'a>(_: &'a ()) {
54
//~^ ERROR lifetime parameters must be declared prior to const parameters

src/test/ui/const-generics/const-param-before-other-params.stderr

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
2-
--> $DIR/const-param-before-other-params.rs:1:12
3-
|
4-
LL | #![feature(const_generics)]
5-
| ^^^^^^^^^^^^^^
6-
71
error: lifetime parameters must be declared prior to const parameters
8-
--> $DIR/const-param-before-other-params.rs:4:21
2+
--> $DIR/const-param-before-other-params.rs:3:21
93
|
104
LL | fn bar<const X: (), 'a>(_: &'a ()) {
115
| --------------^^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, const X: ()>`
126

137
error: type parameters must be declared prior to const parameters
14-
--> $DIR/const-param-before-other-params.rs:8:21
8+
--> $DIR/const-param-before-other-params.rs:7:21
159
|
1610
LL | fn foo<const X: (), T>(_: &T) {
1711
| --------------^- help: reorder the parameters: lifetimes, then types, then consts: `<T, const X: ()>`
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
2-
--> $DIR/const-param-from-outer-fn.rs:1:12
3-
|
4-
LL | #![feature(const_generics)]
5-
| ^^^^^^^^^^^^^^
6-
71
error[E0401]: can't use generic parameters from outer function
82
--> $DIR/const-param-from-outer-fn.rs:6:9
93
|
@@ -14,6 +8,14 @@ LL | fn bar() -> u32 {
148
LL | X
159
| ^ use of generic parameter from outer function
1610

11+
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
12+
--> $DIR/const-param-from-outer-fn.rs:1:12
13+
|
14+
LL | #![feature(const_generics)]
15+
| ^^^^^^^^^^^^^^
16+
|
17+
= note: `#[warn(incomplete_features)]` on by default
18+
1719
error: aborting due to previous error
1820

1921
For more information about this error, try `rustc --explain E0401`.

src/test/ui/const-generics/const-param-in-trait.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
33
|
44
LL | #![feature(const_generics)]
55
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
68

src/test/ui/const-generics/const-param-type-depends-on-type-param.stderr

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
error[E0671]: const parameters cannot depend on type parameters
2+
--> $DIR/const-param-type-depends-on-type-param.rs:9:34
3+
|
4+
LL | pub struct Dependent<T, const X: T>([(); X]);
5+
| ^ const parameter depends on type parameter
6+
17
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
28
--> $DIR/const-param-type-depends-on-type-param.rs:1:12
39
|
410
LL | #![feature(const_generics)]
511
| ^^^^^^^^^^^^^^
6-
7-
error[E0671]: const parameters cannot depend on type parameters
8-
--> $DIR/const-param-type-depends-on-type-param.rs:9:34
912
|
10-
LL | pub struct Dependent<T, const X: T>([(); X]);
11-
| ^ const parameter depends on type parameter
13+
= note: `#[warn(incomplete_features)]` on by default
1214

1315
error[E0392]: parameter `T` is never used
1416
--> $DIR/const-param-type-depends-on-type-param.rs:9:22

src/test/ui/const-generics/const-parameter-uppercase-lint.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
33
|
44
LL | #![feature(const_generics)]
55
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
68

79
error: const parameter `x` should have an upper case name
810
--> $DIR/const-parameter-uppercase-lint.rs:6:15

src/test/ui/const-generics/const-types.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
33
|
44
LL | #![feature(const_generics)]
55
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
68

src/test/ui/const-generics/derive-debug-array-wrapper.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
33
|
44
LL | #![feature(const_generics)]
55
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
68

79
error[E0277]: arrays only have std trait implementations for lengths 0..=32
810
--> $DIR/derive-debug-array-wrapper.rs:6:5

src/test/ui/const-generics/fn-taking-const-generic-array.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
33
|
44
LL | #![feature(const_generics)]
55
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
68

src/test/ui/const-generics/impl-const-generic-struct.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
33
|
44
LL | #![feature(const_generics)]
55
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
68

src/test/ui/const-generics/incorrect-number-of-const-args.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
33
|
44
LL | #![feature(const_generics)]
55
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
68

79
error[E0107]: wrong number of const arguments: expected 2, found 1
810
--> $DIR/incorrect-number-of-const-args.rs:9:5

src/test/ui/const-generics/issue-60818-struct-constructors.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
33
|
44
LL | #![feature(const_generics)]
55
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
68

src/test/ui/const-generics/issue-61336-1.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
33
|
44
LL | #![feature(const_generics)]
55
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
68

79
error: array lengths can't depend on generic parameters
810
--> $DIR/issue-61336-1.rs:5:9

src/test/ui/const-generics/issue-61336-2.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
33
|
44
LL | #![feature(const_generics)]
55
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
68

79
error: array lengths can't depend on generic parameters
810
--> $DIR/issue-61336-2.rs:5:9

0 commit comments

Comments
 (0)