Skip to content

Commit

Permalink
Rollup merge of rust-lang#63095 - Centril:incomplete-features-lint, r…
Browse files Browse the repository at this point in the history
…=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
  • Loading branch information
Centril authored Jul 30, 2019
2 parents 9fb8f1b + 24a178e commit dbf54ad
Show file tree
Hide file tree
Showing 65 changed files with 204 additions and 70 deletions.
1 change: 1 addition & 0 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#![warn(missing_debug_implementations)]
#![deny(intra_doc_link_resolution_failure)] // rustdoc is run without -D warnings
#![allow(explicit_outlives_requirements)]
#![cfg_attr(not(bootstrap), allow(incomplete_features))]

#![cfg_attr(not(test), feature(generator_trait))]
#![cfg_attr(test, feature(test))]
Expand Down
1 change: 1 addition & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#![warn(missing_debug_implementations)]
#![deny(intra_doc_link_resolution_failure)] // rustdoc is run without -D warnings
#![allow(explicit_outlives_requirements)]
#![cfg_attr(not(bootstrap), allow(incomplete_features))]

#![feature(allow_internal_unstable)]
#![feature(arbitrary_self_types)]
Expand Down
37 changes: 34 additions & 3 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@ use lint::{LintPass, LateLintPass, EarlyLintPass, EarlyContext};
use rustc::util::nodemap::FxHashSet;

use syntax::tokenstream::{TokenTree, TokenStream};
use syntax::ast;
use syntax::ast::{self, Expr};
use syntax::ptr::P;
use syntax::ast::Expr;
use syntax::attr::{self, HasAttrs, AttributeTemplate};
use syntax::source_map::Spanned;
use syntax::edition::Edition;
use syntax::feature_gate::{AttributeGate, AttributeType};
use syntax::feature_gate::{self, AttributeGate, AttributeType};
use syntax::feature_gate::{Stability, deprecated_attributes};
use syntax_pos::{BytePos, Span, SyntaxContext};
use syntax::symbol::{Symbol, kw, sym};
Expand Down Expand Up @@ -1831,3 +1830,35 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ExplicitOutlivesRequirements {
}
}
}

declare_lint! {
pub INCOMPLETE_FEATURES,
Warn,
"incomplete features that may function improperly in some or all cases"
}

declare_lint_pass!(
/// Check for used feature gates in `INCOMPLETE_FEATURES` in `feature_gate.rs`.
IncompleteFeatures => [INCOMPLETE_FEATURES]
);

impl EarlyLintPass for IncompleteFeatures {
fn check_crate(&mut self, cx: &EarlyContext<'_>, _: &ast::Crate) {
let features = cx.sess.features_untracked();
features.declared_lang_features
.iter().map(|(name, span, _)| (name, span))
.chain(features.declared_lib_features.iter().map(|(name, span)| (name, span)))
.filter(|(name, _)| feature_gate::INCOMPLETE_FEATURES.iter().any(|f| name == &f))
.for_each(|(name, &span)| {
cx.struct_span_lint(
INCOMPLETE_FEATURES,
span,
&format!(
"the feature `{}` is incomplete and may cause the compiler to crash",
name,
)
)
.emit();
});
}
}
1 change: 1 addition & 0 deletions src/librustc_lint/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ macro_rules! early_lint_passes {
DeprecatedAttr: DeprecatedAttr::new(),
WhileTrue: WhileTrue,
NonAsciiIdents: NonAsciiIdents,
IncompleteFeatures: IncompleteFeatures,
]);
)
}
Expand Down
17 changes: 4 additions & 13 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,10 +565,10 @@ declare_features! (
// -------------------------------------------------------------------------
);

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

let name = mi.name_or_empty();
if INCOMPLETE_FEATURES.iter().any(|f| name == *f) {
span_handler.struct_span_warn(
mi.span(),
&format!(
"the feature `{}` is incomplete and may cause the compiler to crash",
name
)
).emit();
}

if let Some(edition) = ALL_EDITIONS.iter().find(|e| name == e.feature_name()) {
if *edition <= crate_edition {
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/associated-type-bounds/duplicate.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ warning: the feature `impl_trait_in_bindings` is incomplete and may cause the co
|
LL | #![feature(impl_trait_in_bindings)]
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

error[E0719]: the value of the associated type `Item` (from the trait `std::iter::Iterator`) is already specified
--> $DIR/duplicate.rs:12:36
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/associated-type-bounds/dyn-lcsit.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ warning: the feature `impl_trait_in_bindings` is incomplete and may cause the co
|
LL | #![feature(impl_trait_in_bindings)]
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

2 changes: 2 additions & 0 deletions src/test/ui/associated-type-bounds/lcsit.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ warning: the feature `impl_trait_in_bindings` is incomplete and may cause the co
|
LL | #![feature(impl_trait_in_bindings)]
| ^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

2 changes: 2 additions & 0 deletions src/test/ui/const-generics/apit-with-const-param.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

2 changes: 2 additions & 0 deletions src/test/ui/const-generics/array-wrapper-struct-ctor.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

2 changes: 2 additions & 0 deletions src/test/ui/const-generics/broken-mir-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

2 changes: 2 additions & 0 deletions src/test/ui/const-generics/broken-mir-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

error[E0277]: arrays only have std trait implementations for lengths 0..=32
--> $DIR/broken-mir-2.rs:7:36
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/const-generics/cannot-infer-const-args.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

error[E0282]: type annotations needed
--> $DIR/cannot-infer-const-args.rs:9:5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

2 changes: 2 additions & 0 deletions src/test/ui/const-generics/concrete-const-as-fn-arg.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

2 changes: 2 additions & 0 deletions src/test/ui/const-generics/concrete-const-impl-method.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

2 changes: 2 additions & 0 deletions src/test/ui/const-generics/const-arg-in-fn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

2 changes: 2 additions & 0 deletions src/test/ui/const-generics/const-expression-parameter.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

error: aborting due to previous error

14 changes: 8 additions & 6 deletions src/test/ui/const-generics/const-fn-with-const-param.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
--> $DIR/const-fn-with-const-param.rs:1:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^

error: const parameters are not permitted in `const fn`
--> $DIR/const-fn-with-const-param.rs:4:1
|
Expand All @@ -13,5 +7,13 @@ LL | | X
LL | | }
| |_^

warning: the feature `const_generics` is incomplete and may cause the compiler to crash
--> $DIR/const-fn-with-const-param.rs:1:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

error: aborting due to previous error

2 changes: 2 additions & 0 deletions src/test/ui/const-generics/const-generic-array-wrapper.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

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

fn bar<const X: (), 'a>(_: &'a ()) {
//~^ ERROR lifetime parameters must be declared prior to const parameters
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
--> $DIR/const-param-before-other-params.rs:1:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^

error: lifetime parameters must be declared prior to const parameters
--> $DIR/const-param-before-other-params.rs:4:21
--> $DIR/const-param-before-other-params.rs:3:21
|
LL | fn bar<const X: (), 'a>(_: &'a ()) {
| --------------^^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, const X: ()>`

error: type parameters must be declared prior to const parameters
--> $DIR/const-param-before-other-params.rs:8:21
--> $DIR/const-param-before-other-params.rs:7:21
|
LL | fn foo<const X: (), T>(_: &T) {
| --------------^- help: reorder the parameters: lifetimes, then types, then consts: `<T, const X: ()>`
Expand Down
14 changes: 8 additions & 6 deletions src/test/ui/const-generics/const-param-from-outer-fn.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
--> $DIR/const-param-from-outer-fn.rs:1:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^

error[E0401]: can't use generic parameters from outer function
--> $DIR/const-param-from-outer-fn.rs:6:9
|
Expand All @@ -14,6 +8,14 @@ LL | fn bar() -> u32 {
LL | X
| ^ use of generic parameter from outer function

warning: the feature `const_generics` is incomplete and may cause the compiler to crash
--> $DIR/const-param-from-outer-fn.rs:1:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

error: aborting due to previous error

For more information about this error, try `rustc --explain E0401`.
2 changes: 2 additions & 0 deletions src/test/ui/const-generics/const-param-in-trait.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
error[E0671]: const parameters cannot depend on type parameters
--> $DIR/const-param-type-depends-on-type-param.rs:9:34
|
LL | pub struct Dependent<T, const X: T>([(); X]);
| ^ const parameter depends on type parameter

warning: the feature `const_generics` is incomplete and may cause the compiler to crash
--> $DIR/const-param-type-depends-on-type-param.rs:1:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^

error[E0671]: const parameters cannot depend on type parameters
--> $DIR/const-param-type-depends-on-type-param.rs:9:34
|
LL | pub struct Dependent<T, const X: T>([(); X]);
| ^ const parameter depends on type parameter
= note: `#[warn(incomplete_features)]` on by default

error[E0392]: parameter `T` is never used
--> $DIR/const-param-type-depends-on-type-param.rs:9:22
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

error: const parameter `x` should have an upper case name
--> $DIR/const-parameter-uppercase-lint.rs:6:15
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/const-generics/const-types.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

2 changes: 2 additions & 0 deletions src/test/ui/const-generics/derive-debug-array-wrapper.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

error[E0277]: arrays only have std trait implementations for lengths 0..=32
--> $DIR/derive-debug-array-wrapper.rs:6:5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

2 changes: 2 additions & 0 deletions src/test/ui/const-generics/impl-const-generic-struct.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

error[E0107]: wrong number of const arguments: expected 2, found 1
--> $DIR/incorrect-number-of-const-args.rs:9:5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

2 changes: 2 additions & 0 deletions src/test/ui/const-generics/issue-61336-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

error: array lengths can't depend on generic parameters
--> $DIR/issue-61336-1.rs:5:9
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/const-generics/issue-61336-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ warning: the feature `const_generics` is incomplete and may cause the compiler t
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default

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

0 comments on commit dbf54ad

Please sign in to comment.