Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 4 pull requests #63134

Closed
wants to merge 12 commits into from
Closed
148 changes: 65 additions & 83 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/liballoc/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))]

#![cfg_attr(not(test), feature(generator_trait))]
#![cfg_attr(test, feature(test))]
Expand Down
3 changes: 2 additions & 1 deletion src/libcore/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,8 @@ impl TypeId {
/// The current implementation uses the same infrastructure as compiler
/// diagnostics and debuginfo, but this is not guaranteed.
#[stable(feature = "type_name", since = "1.38.0")]
pub fn type_name<T: ?Sized>() -> &'static str {
#[rustc_const_unstable(feature = "const_type_name")]
pub const fn type_name<T: ?Sized>() -> &'static str {
#[cfg(bootstrap)]
unsafe {
intrinsics::type_name::<T>()
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 @@ -569,10 +569,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 @@ -2338,15 +2338,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
128 changes: 128 additions & 0 deletions src/test/ui/array-slice-vec/subslice-patterns-pass.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// This test comprehensively checks the passing static and dynamic semantics
// of subslice patterns `..`, `x @ ..`, `ref x @ ..`, and `ref mut @ ..`
// in slice patterns `[$($pat), $(,)?]` .

// run-pass

#![feature(slice_patterns)]

#![allow(unreachable_patterns)]

use std::convert::identity;

#[derive(PartialEq, Debug, Clone)]
struct N(u8);

macro_rules! n {
($($e:expr),* $(,)?) => {
[$(N($e)),*]
}
}

macro_rules! c {
($inp:expr, $typ:ty, $out:expr $(,)?) => {
assert_eq!($out, identity::<$typ>($inp));
}
}

macro_rules! m {
($e:expr, $p:pat => $b:expr) => {
match $e {
$p => $b,
_ => panic!(),
}
}
}

fn main() {
slices();
arrays();
}

fn slices() {
// Matching slices using `ref` patterns:
let mut v = vec![N(0), N(1), N(2), N(3), N(4)];
let mut vc = (0..=4).collect::<Vec<u8>>();

let [..] = v[..]; // Always matches.
m!(v[..], [N(0), ref sub @ .., N(4)] => c!(sub, &[N], n![1, 2, 3]));
m!(v[..], [N(0), ref sub @ ..] => c!(sub, &[N], n![1, 2, 3, 4]));
m!(v[..], [ref sub @ .., N(4)] => c!(sub, &[N], n![0, 1, 2, 3]));
m!(v[..], [ref sub @ .., _, _, _, _, _] => c!(sub, &[N], &n![] as &[N]));
m!(v[..], [_, _, _, _, _, ref sub @ ..] => c!(sub, &[N], &n![] as &[N]));
m!(vc[..], [x, .., y] => c!((x, y), (u8, u8), (0, 4)));

// Matching slices using `ref mut` patterns:
let [..] = v[..]; // Always matches.
m!(v[..], [N(0), ref mut sub @ .., N(4)] => c!(sub, &mut [N], n![1, 2, 3]));
m!(v[..], [N(0), ref mut sub @ ..] => c!(sub, &mut [N], n![1, 2, 3, 4]));
m!(v[..], [ref mut sub @ .., N(4)] => c!(sub, &mut [N], n![0, 1, 2, 3]));
m!(v[..], [ref mut sub @ .., _, _, _, _, _] => c!(sub, &mut [N], &mut n![] as &mut [N]));
m!(v[..], [_, _, _, _, _, ref mut sub @ ..] => c!(sub, &mut [N], &mut n![] as &mut [N]));
m!(vc[..], [x, .., y] => c!((x, y), (u8, u8), (0, 4)));

// Matching slices using default binding modes (&):
let [..] = &v[..]; // Always matches.
m!(&v[..], [N(0), sub @ .., N(4)] => c!(sub, &[N], n![1, 2, 3]));
m!(&v[..], [N(0), sub @ ..] => c!(sub, &[N], n![1, 2, 3, 4]));
m!(&v[..], [sub @ .., N(4)] => c!(sub, &[N], n![0, 1, 2, 3]));
m!(&v[..], [sub @ .., _, _, _, _, _] => c!(sub, &[N], &n![] as &[N]));
m!(&v[..], [_, _, _, _, _, sub @ ..] => c!(sub, &[N], &n![] as &[N]));
m!(&vc[..], [x, .., y] => c!((x, y), (&u8, &u8), (&0, &4)));

// Matching slices using default binding modes (&mut):
let [..] = &mut v[..]; // Always matches.
m!(&mut v[..], [N(0), sub @ .., N(4)] => c!(sub, &mut [N], n![1, 2, 3]));
m!(&mut v[..], [N(0), sub @ ..] => c!(sub, &mut [N], n![1, 2, 3, 4]));
m!(&mut v[..], [sub @ .., N(4)] => c!(sub, &mut [N], n![0, 1, 2, 3]));
m!(&mut v[..], [sub @ .., _, _, _, _, _] => c!(sub, &mut [N], &mut n![] as &mut [N]));
m!(&mut v[..], [_, _, _, _, _, sub @ ..] => c!(sub, &mut [N], &mut n![] as &mut [N]));
m!(&mut vc[..], [x, .., y] => c!((x, y), (&mut u8, &mut u8), (&mut 0, &mut 4)));
}

fn arrays() {
let mut v = n![0, 1, 2, 3, 4];
let vc = [0, 1, 2, 3, 4];

// Matching arrays by value:
m!(v.clone(), [N(0), sub @ .., N(4)] => c!(sub, [N; 3], n![1, 2, 3]));
m!(v.clone(), [N(0), sub @ ..] => c!(sub, [N; 4], n![1, 2, 3, 4]));
m!(v.clone(), [sub @ .., N(4)] => c!(sub, [N; 4], n![0, 1, 2, 3]));
m!(v.clone(), [sub @ .., _, _, _, _, _] => c!(sub, [N; 0], n![] as [N; 0]));
m!(v.clone(), [_, _, _, _, _, sub @ ..] => c!(sub, [N; 0], n![] as [N; 0]));
m!(v.clone(), [x, .., y] => c!((x, y), (N, N), (N(0), N(4))));
m!(v.clone(), [..] => ());

// Matching arrays by ref patterns:
m!(v, [N(0), ref sub @ .., N(4)] => c!(sub, &[N; 3], &n![1, 2, 3]));
m!(v, [N(0), ref sub @ ..] => c!(sub, &[N; 4], &n![1, 2, 3, 4]));
m!(v, [ref sub @ .., N(4)] => c!(sub, &[N; 4], &n![0, 1, 2, 3]));
m!(v, [ref sub @ .., _, _, _, _, _] => c!(sub, &[N; 0], &n![] as &[N; 0]));
m!(v, [_, _, _, _, _, ref sub @ ..] => c!(sub, &[N; 0], &n![] as &[N; 0]));
m!(vc, [x, .., y] => c!((x, y), (u8, u8), (0, 4)));

// Matching arrays by ref mut patterns:
m!(v, [N(0), ref mut sub @ .., N(4)] => c!(sub, &mut [N; 3], &mut n![1, 2, 3]));
m!(v, [N(0), ref mut sub @ ..] => c!(sub, &mut [N; 4], &mut n![1, 2, 3, 4]));
m!(v, [ref mut sub @ .., N(4)] => c!(sub, &mut [N; 4], &mut n![0, 1, 2, 3]));
m!(v, [ref mut sub @ .., _, _, _, _, _] => c!(sub, &mut [N; 0], &mut n![] as &mut [N; 0]));
m!(v, [_, _, _, _, _, ref mut sub @ ..] => c!(sub, &mut [N; 0], &mut n![] as &mut [N; 0]));

// Matching arrays by default binding modes (&):
m!(&v, [N(0), sub @ .., N(4)] => c!(sub, &[N; 3], &n![1, 2, 3]));
m!(&v, [N(0), sub @ ..] => c!(sub, &[N; 4], &n![1, 2, 3, 4]));
m!(&v, [sub @ .., N(4)] => c!(sub, &[N; 4], &n![0, 1, 2, 3]));
m!(&v, [sub @ .., _, _, _, _, _] => c!(sub, &[N; 0], &n![] as &[N; 0]));
m!(&v, [_, _, _, _, _, sub @ ..] => c!(sub, &[N; 0], &n![] as &[N; 0]));
m!(&v, [..] => ());
m!(&v, [x, .., y] => c!((x, y), (&N, &N), (&N(0), &N(4))));

// Matching arrays by default binding modes (&mut):
m!(&mut v, [N(0), sub @ .., N(4)] => c!(sub, &mut [N; 3], &mut n![1, 2, 3]));
m!(&mut v, [N(0), sub @ ..] => c!(sub, &mut [N; 4], &mut n![1, 2, 3, 4]));
m!(&mut v, [sub @ .., N(4)] => c!(sub, &mut [N; 4], &mut n![0, 1, 2, 3]));
m!(&mut v, [sub @ .., _, _, _, _, _] => c!(sub, &mut [N; 0], &mut n![] as &[N; 0]));
m!(&mut v, [_, _, _, _, _, sub @ ..] => c!(sub, &mut [N; 0], &mut n![] as &[N; 0]));
m!(&mut v, [..] => ());
m!(&mut v, [x, .., y] => c!((x, y), (&mut N, &mut N), (&mut N(0), &mut N(4))));
}
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
Loading