Skip to content

Commit

Permalink
Make sure feature gate errors are recoverable (take 2)
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Jan 6, 2019
1 parent af2c159 commit 10a00e1
Show file tree
Hide file tree
Showing 54 changed files with 244 additions and 128 deletions.
4 changes: 1 addition & 3 deletions src/librustc/ty/mod.rs
Expand Up @@ -2839,16 +2839,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
self.impl_polarity(def_id1) == self.impl_polarity(def_id2)
&& trait1_is_empty
&& trait2_is_empty
} else if self.features().marker_trait_attr {
} else {
let is_marker_impl = |def_id: DefId| -> bool {
let trait_ref = self.impl_trait_ref(def_id);
trait_ref.map_or(false, |tr| self.trait_def(tr.def_id).is_marker)
};
self.impl_polarity(def_id1) == self.impl_polarity(def_id2)
&& is_marker_impl(def_id1)
&& is_marker_impl(def_id2)
} else {
false
};

if is_legit {
Expand Down
23 changes: 10 additions & 13 deletions src/librustc_driver/driver.rs
Expand Up @@ -1098,23 +1098,20 @@ where
ast_validation::check_crate(sess, &krate)
});

time(sess, "name resolution", || -> CompileResult {
time(sess, "name resolution", || {
resolver.resolve_crate(&krate);
Ok(())
})?;
});

// Needs to go *after* expansion to be able to check the results of macro expansion.
time(sess, "complete gated feature checking", || {
sess.track_errors(|| {
syntax::feature_gate::check_crate(
&krate,
&sess.parse_sess,
&sess.features_untracked(),
&attributes,
sess.opts.unstable_features,
);
})
})?;
syntax::feature_gate::check_crate(
&krate,
&sess.parse_sess,
&sess.features_untracked(),
&attributes,
sess.opts.unstable_features,
);
});

// Lower ast -> hir.
// First, we need to collect the dep_graph.
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/conditional-compilation/cfg-attr-crate-2.rs
@@ -1,8 +1,8 @@
//
// compile-flags: --cfg broken

// https://github.com/rust-lang/rust/issues/21833#issuecomment-72353044

// compile-flags: --cfg broken

#![crate_type = "lib"]
#![cfg_attr(broken, no_core)] //~ ERROR no_core is experimental

fn main() { }
pub struct S {}
@@ -1,7 +1,7 @@
//
// compile-flags: --cfg broken

#![feature(cfg_attr_multi)]
#![crate_type = "lib"]
#![cfg_attr(broken, no_core, no_std)] //~ ERROR no_core is experimental

fn main() { }
pub struct S {}
@@ -1,7 +1,7 @@
//
// compile-flags: --cfg broken

#![feature(cfg_attr_multi)]
#![crate_type = "lib"]
#![cfg_attr(broken, no_std, no_core)] //~ ERROR no_core is experimental

fn main() { }
pub struct S {}
3 changes: 3 additions & 0 deletions src/test/ui/feature-gates/feature-gate-alloc-error-handler.rs
Expand Up @@ -9,3 +9,6 @@ use core::alloc::Layout;
fn oom(info: Layout) -> ! {
loop {}
}

#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! { loop {} }
1 change: 1 addition & 0 deletions src/test/ui/feature-gates/feature-gate-allow_fail.rs
Expand Up @@ -5,3 +5,4 @@ fn ok_to_fail() {
assert!(false);
}

fn main() {}
Expand Up @@ -6,5 +6,5 @@ async fn foo() {} //~ ERROR async fn is unstable

fn main() {
let _ = async {}; //~ ERROR cannot find struct, variant or union type `async`
let _ = async || {}; //~ ERROR cannot find value `async` in this scope
let _ = async || { true }; //~ ERROR cannot find value `async` in this scope
}
Expand Up @@ -7,7 +7,7 @@ LL | let _ = async {}; //~ ERROR cannot find struct, variant or union type `
error[E0425]: cannot find value `async` in this scope
--> $DIR/feature-gate-async-await-2015-edition.rs:9:13
|
LL | let _ = async || {}; //~ ERROR cannot find value `async` in this scope
LL | let _ = async || { true }; //~ ERROR cannot find value `async` in this scope
| ^^^^^ not found in this scope

error[E0658]: async fn is unstable (see issue #50547)
Expand Down
10 changes: 6 additions & 4 deletions src/test/ui/feature-gates/feature-gate-const_fn.rs
Expand Up @@ -9,14 +9,16 @@ trait Foo {
//~| ERROR trait fns cannot be declared const
}

impl Foo {
const fn baz() -> u32 { 0 } // ok
}

impl Foo for u32 {
const fn foo() -> u32 { 0 } //~ ERROR trait fns cannot be declared const
}

trait Bar {}

impl dyn Bar {
const fn baz() -> u32 { 0 } // ok
}

static FOO: usize = foo();
const BAR: usize = foo();

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/feature-gates/feature-gate-const_fn.stderr
Expand Up @@ -11,7 +11,7 @@ LL | const fn bar() -> u32 { 0 } //~ ERROR const fn is unstable
| ^^^^^ trait fns cannot be const

error[E0379]: trait fns cannot be declared const
--> $DIR/feature-gate-const_fn.rs:17:5
--> $DIR/feature-gate-const_fn.rs:13:5
|
LL | const fn foo() -> u32 { 0 } //~ ERROR trait fns cannot be declared const
| ^^^^^ trait fns cannot be const
Expand Down
2 changes: 2 additions & 0 deletions src/test/ui/feature-gates/feature-gate-doc_keyword.rs
@@ -1,3 +1,5 @@
#[doc(keyword = "match")] //~ ERROR: #[doc(keyword = "...")] is experimental
/// wonderful
mod foo{}

fn main() {}
5 changes: 1 addition & 4 deletions src/test/ui/feature-gates/feature-gate-dropck-ugeh.rs
@@ -1,14 +1,11 @@
// gate-test-dropck_parametricity

// Ensure that attempts to use the unsafe attribute are feature-gated.

// Example adapted from RFC 1238 text (just left out the feature gate).

// https://github.com/rust-lang/rfcs/blob/master/text/1238-nonparametric-dropck.md
// #example-of-the-unguarded-escape-hatch

// #![feature(dropck_parametricity)]

use std::cell::Cell;

struct Concrete<'a>(u32, Cell<Option<&'a Concrete<'a>>>);
Expand All @@ -18,6 +15,7 @@ struct Foo<T> { data: Vec<T> }
impl<T> Drop for Foo<T> {
#[unsafe_destructor_blind_to_params] // This is the UGEH attribute
//~^ ERROR unsafe_destructor_blind_to_params has been replaced
//~| WARN use of deprecated attribute `dropck_parametricity`
fn drop(&mut self) { }
}

Expand All @@ -29,4 +27,3 @@ fn main() {
foo.data[0].1.set(Some(&foo.data[1]));
foo.data[1].1.set(Some(&foo.data[0]));
}

10 changes: 9 additions & 1 deletion src/test/ui/feature-gates/feature-gate-dropck-ugeh.stderr
@@ -1,11 +1,19 @@
error[E0658]: unsafe_destructor_blind_to_params has been replaced by may_dangle and will be removed in the future (see issue #28498)
--> $DIR/feature-gate-dropck-ugeh.rs:19:5
--> $DIR/feature-gate-dropck-ugeh.rs:16:5
|
LL | #[unsafe_destructor_blind_to_params] // This is the UGEH attribute
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(dropck_parametricity)] to the crate attributes to enable

warning: use of deprecated attribute `dropck_parametricity`: unsafe_destructor_blind_to_params has been replaced by may_dangle and will be removed in the future. See https://github.com/rust-lang/rust/issues/34761
--> $DIR/feature-gate-dropck-ugeh.rs:16:5
|
LL | #[unsafe_destructor_blind_to_params] // This is the UGEH attribute
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace this attribute with `#[may_dangle]`
|
= note: #[warn(deprecated)] on by default

error: aborting due to previous error

For more information about this error, try `rustc --explain E0658`.
6 changes: 4 additions & 2 deletions src/test/ui/feature-gates/feature-gate-existential-type.rs
@@ -1,15 +1,17 @@
// Check that existential types must be ungated to use the `existential` keyword



existential type Foo: std::fmt::Debug; //~ ERROR existential types are unstable

trait Bar {
type Baa: std::fmt::Debug;
fn define() -> Self::Baa;
}

impl Bar for () {
existential type Baa: std::fmt::Debug; //~ ERROR existential types are unstable
fn define() -> Self::Baa { 0 }
}

fn define() -> Foo { 0 }

fn main() {}
@@ -1,13 +1,13 @@
error[E0658]: existential types are unstable (see issue #34511)
--> $DIR/feature-gate-existential-type.rs:5:1
--> $DIR/feature-gate-existential-type.rs:3:1
|
LL | existential type Foo: std::fmt::Debug; //~ ERROR existential types are unstable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(existential_type)] to the crate attributes to enable

error[E0658]: existential types are unstable (see issue #34511)
--> $DIR/feature-gate-existential-type.rs:12:5
--> $DIR/feature-gate-existential-type.rs:11:5
|
LL | existential type Baa: std::fmt::Debug; //~ ERROR existential types are unstable
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/feature-gates/feature-gate-generators.rs
@@ -1,3 +1,4 @@
fn main() {
yield true; //~ ERROR yield syntax is experimental
//~^ ERROR yield statement outside of generator literal
}
11 changes: 9 additions & 2 deletions src/test/ui/feature-gates/feature-gate-generators.stderr
Expand Up @@ -6,6 +6,13 @@ LL | yield true; //~ ERROR yield syntax is experimental
|
= help: add #![feature(generators)] to the crate attributes to enable

error: aborting due to previous error
error[E0627]: yield statement outside of generator literal
--> $DIR/feature-gate-generators.rs:2:5
|
LL | yield true; //~ ERROR yield syntax is experimental
| ^^^^^^^^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0658`.
Some errors occurred: E0627, E0658.
For more information about an error, try `rustc --explain E0627`.
Expand Up @@ -11,9 +11,9 @@ trait PointerFamily<U> {
struct Foo;

impl PointerFamily<u32> for Foo {
type Pointer<usize> = Box<usize>;
type Pointer<Usize> = Box<Usize>;
//~^ ERROR generic associated types are unstable
type Pointer2<u32> = Box<u32>;
type Pointer2<U32> = Box<U32>;
//~^ ERROR generic associated types are unstable
}

Expand Down
Expand Up @@ -25,15 +25,15 @@ LL | type Pointer2<T>: Deref<Target = T> where T: Clone, U: Clone;
error[E0658]: generic associated types are unstable (see issue #44265)
--> $DIR/feature-gate-generic_associated_types.rs:14:5
|
LL | type Pointer<usize> = Box<usize>;
LL | type Pointer<Usize> = Box<Usize>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(generic_associated_types)] to the crate attributes to enable

error[E0658]: generic associated types are unstable (see issue #44265)
--> $DIR/feature-gate-generic_associated_types.rs:16:5
|
LL | type Pointer2<u32> = Box<u32>;
LL | type Pointer2<U32> = Box<U32>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(generic_associated_types)] to the crate attributes to enable
Expand Down
8 changes: 3 additions & 5 deletions src/test/ui/feature-gates/feature-gate-intrinsics.rs
@@ -1,9 +1,7 @@
extern "rust-intrinsic" { //~ ERROR intrinsics are subject to change
fn bar();
fn bar(); //~ ERROR unrecognized intrinsic function: `bar`
}

extern "rust-intrinsic" fn baz() { //~ ERROR intrinsics are subject to change
}
extern "rust-intrinsic" fn baz() {} //~ ERROR intrinsics are subject to change

fn main() {
}
fn main() {}
18 changes: 12 additions & 6 deletions src/test/ui/feature-gates/feature-gate-intrinsics.stderr
Expand Up @@ -2,7 +2,7 @@ error[E0658]: intrinsics are subject to change
--> $DIR/feature-gate-intrinsics.rs:1:1
|
LL | / extern "rust-intrinsic" { //~ ERROR intrinsics are subject to change
LL | | fn bar();
LL | | fn bar(); //~ ERROR unrecognized intrinsic function: `bar`
LL | | }
| |_^
|
Expand All @@ -11,12 +11,18 @@ LL | | }
error[E0658]: intrinsics are subject to change
--> $DIR/feature-gate-intrinsics.rs:5:1
|
LL | / extern "rust-intrinsic" fn baz() { //~ ERROR intrinsics are subject to change
LL | | }
| |_^
LL | extern "rust-intrinsic" fn baz() {} //~ ERROR intrinsics are subject to change
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(intrinsics)] to the crate attributes to enable

error: aborting due to 2 previous errors
error[E0093]: unrecognized intrinsic function: `bar`
--> $DIR/feature-gate-intrinsics.rs:2:5
|
LL | fn bar(); //~ ERROR unrecognized intrinsic function: `bar`
| ^^^^^^^^^ unrecognized intrinsic

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0658`.
Some errors occurred: E0093, E0658.
For more information about an error, try `rustc --explain E0093`.
6 changes: 3 additions & 3 deletions src/test/ui/feature-gates/feature-gate-lang-items.rs
@@ -1,5 +1,5 @@
#[lang="foo"] //~ ERROR language items are subject to change
#[lang = "foo"] //~ ERROR language items are subject to change
//~^ ERROR definition of an unknown language item: `foo`
trait Foo {}

fn main() {
}
fn main() {}
15 changes: 11 additions & 4 deletions src/test/ui/feature-gates/feature-gate-lang-items.stderr
@@ -1,11 +1,18 @@
error[E0658]: language items are subject to change
--> $DIR/feature-gate-lang-items.rs:1:1
|
LL | #[lang="foo"] //~ ERROR language items are subject to change
| ^^^^^^^^^^^^^
LL | #[lang = "foo"] //~ ERROR language items are subject to change
| ^^^^^^^^^^^^^^^
|
= help: add #![feature(lang_items)] to the crate attributes to enable

error: aborting due to previous error
error[E0522]: definition of an unknown language item: `foo`
--> $DIR/feature-gate-lang-items.rs:1:1
|
LL | #[lang = "foo"] //~ ERROR language items are subject to change
| ^^^^^^^^^^^^^^^ definition of unknown language item `foo`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0658`.
Some errors occurred: E0522, E0658.
For more information about an error, try `rustc --explain E0522`.
2 changes: 2 additions & 0 deletions src/test/ui/feature-gates/feature-gate-linkage.rs
Expand Up @@ -2,3 +2,5 @@ extern {
#[linkage = "extern_weak"] static foo: isize;
//~^ ERROR: the `linkage` attribute is experimental and not portable
}

fn main() {}
4 changes: 3 additions & 1 deletion src/test/ui/feature-gates/feature-gate-may-dangle.rs
Expand Up @@ -3,7 +3,9 @@
// Check that `may_dangle` is rejected if `dropck_eyepatch` feature gate is absent.

struct Pt<A>(A);
impl<#[may_dangle] A> Drop for Pt<A> {
unsafe impl<#[may_dangle] A> Drop for Pt<A> {
//~^ ERROR may_dangle has unstable semantics and may be removed in the future
fn drop(&mut self) { }
}

fn main() {}
6 changes: 3 additions & 3 deletions src/test/ui/feature-gates/feature-gate-may-dangle.stderr
@@ -1,8 +1,8 @@
error[E0658]: may_dangle has unstable semantics and may be removed in the future (see issue #34761)
--> $DIR/feature-gate-may-dangle.rs:6:6
--> $DIR/feature-gate-may-dangle.rs:6:13
|
LL | impl<#[may_dangle] A> Drop for Pt<A> {
| ^^^^^^^^^^^^^
LL | unsafe impl<#[may_dangle] A> Drop for Pt<A> {
| ^^^^^^^^^^^^^
|
= help: add #![feature(dropck_eyepatch)] to the crate attributes to enable

Expand Down

0 comments on commit 10a00e1

Please sign in to comment.