Skip to content

Commit 2a02d6d

Browse files
committed
Make sure feature gate errors are recoverable (take 2)
1 parent a36b960 commit 2a02d6d

File tree

54 files changed

+244
-128
lines changed

Some content is hidden

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

54 files changed

+244
-128
lines changed

src/librustc/ty/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2801,16 +2801,14 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
28012801
self.impl_polarity(def_id1) == self.impl_polarity(def_id2)
28022802
&& trait1_is_empty
28032803
&& trait2_is_empty
2804-
} else if self.features().marker_trait_attr {
2804+
} else {
28052805
let is_marker_impl = |def_id: DefId| -> bool {
28062806
let trait_ref = self.impl_trait_ref(def_id);
28072807
trait_ref.map_or(false, |tr| self.trait_def(tr.def_id).is_marker)
28082808
};
28092809
self.impl_polarity(def_id1) == self.impl_polarity(def_id2)
28102810
&& is_marker_impl(def_id1)
28112811
&& is_marker_impl(def_id2)
2812-
} else {
2813-
false
28142812
}
28152813
}
28162814

src/librustc_driver/driver.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -1101,23 +1101,20 @@ where
11011101
ast_validation::check_crate(sess, &krate)
11021102
});
11031103

1104-
time(sess, "name resolution", || -> CompileResult {
1104+
time(sess, "name resolution", || {
11051105
resolver.resolve_crate(&krate);
1106-
Ok(())
1107-
})?;
1106+
});
11081107

11091108
// Needs to go *after* expansion to be able to check the results of macro expansion.
11101109
time(sess, "complete gated feature checking", || {
1111-
sess.track_errors(|| {
1112-
syntax::feature_gate::check_crate(
1113-
&krate,
1114-
&sess.parse_sess,
1115-
&sess.features_untracked(),
1116-
&attributes,
1117-
sess.opts.unstable_features,
1118-
);
1119-
})
1120-
})?;
1110+
syntax::feature_gate::check_crate(
1111+
&krate,
1112+
&sess.parse_sess,
1113+
&sess.features_untracked(),
1114+
&attributes,
1115+
sess.opts.unstable_features,
1116+
);
1117+
});
11211118

11221119
// Lower ast -> hir.
11231120
// First, we need to collect the dep_graph.
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
//
2-
// compile-flags: --cfg broken
3-
41
// https://github.com/rust-lang/rust/issues/21833#issuecomment-72353044
52

3+
// compile-flags: --cfg broken
4+
5+
#![crate_type = "lib"]
66
#![cfg_attr(broken, no_core)] //~ ERROR no_core is experimental
77

8-
fn main() { }
8+
pub struct S {}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
//
21
// compile-flags: --cfg broken
32

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

7-
fn main() { }
7+
pub struct S {}
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
//
21
// compile-flags: --cfg broken
32

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

7-
fn main() { }
7+
pub struct S {}

src/test/ui/feature-gates/feature-gate-alloc-error-handler.rs

+3
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ use core::alloc::Layout;
99
fn oom(info: Layout) -> ! {
1010
loop {}
1111
}
12+
13+
#[panic_handler]
14+
fn panic(_: &core::panic::PanicInfo) -> ! { loop {} }

src/test/ui/feature-gates/feature-gate-allow_fail.rs

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ fn ok_to_fail() {
55
assert!(false);
66
}
77

8+
fn main() {}

src/test/ui/feature-gates/feature-gate-async-await-2015-edition.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ async fn foo() {} //~ ERROR async fn is unstable
66

77
fn main() {
88
let _ = async {}; //~ ERROR cannot find struct, variant or union type `async`
9-
let _ = async || {}; //~ ERROR cannot find value `async` in this scope
9+
let _ = async || { true }; //~ ERROR cannot find value `async` in this scope
1010
}

src/test/ui/feature-gates/feature-gate-async-await-2015-edition.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | let _ = async {}; //~ ERROR cannot find struct, variant or union type `
77
error[E0425]: cannot find value `async` in this scope
88
--> $DIR/feature-gate-async-await-2015-edition.rs:9:13
99
|
10-
LL | let _ = async || {}; //~ ERROR cannot find value `async` in this scope
10+
LL | let _ = async || { true }; //~ ERROR cannot find value `async` in this scope
1111
| ^^^^^ not found in this scope
1212

1313
error[E0658]: async fn is unstable (see issue #50547)

src/test/ui/feature-gates/feature-gate-const_fn.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,16 @@ trait Foo {
99
//~| ERROR trait fns cannot be declared const
1010
}
1111

12-
impl Foo {
13-
const fn baz() -> u32 { 0 } // ok
14-
}
15-
1612
impl Foo for u32 {
1713
const fn foo() -> u32 { 0 } //~ ERROR trait fns cannot be declared const
1814
}
1915

16+
trait Bar {}
17+
18+
impl dyn Bar {
19+
const fn baz() -> u32 { 0 } // ok
20+
}
21+
2022
static FOO: usize = foo();
2123
const BAR: usize = foo();
2224

src/test/ui/feature-gates/feature-gate-const_fn.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LL | const fn bar() -> u32 { 0 } //~ ERROR const fn is unstable
1111
| ^^^^^ trait fns cannot be const
1212

1313
error[E0379]: trait fns cannot be declared const
14-
--> $DIR/feature-gate-const_fn.rs:17:5
14+
--> $DIR/feature-gate-const_fn.rs:13:5
1515
|
1616
LL | const fn foo() -> u32 { 0 } //~ ERROR trait fns cannot be declared const
1717
| ^^^^^ trait fns cannot be const
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
#[doc(keyword = "match")] //~ ERROR: #[doc(keyword = "...")] is experimental
22
/// wonderful
33
mod foo{}
4+
5+
fn main() {}

src/test/ui/feature-gates/feature-gate-dropck-ugeh.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
// gate-test-dropck_parametricity
22

33
// Ensure that attempts to use the unsafe attribute are feature-gated.
4-
54
// Example adapted from RFC 1238 text (just left out the feature gate).
65

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

10-
// #![feature(dropck_parametricity)]
11-
129
use std::cell::Cell;
1310

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

@@ -29,4 +27,3 @@ fn main() {
2927
foo.data[0].1.set(Some(&foo.data[1]));
3028
foo.data[1].1.set(Some(&foo.data[0]));
3129
}
32-
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
error[E0658]: unsafe_destructor_blind_to_params has been replaced by may_dangle and will be removed in the future (see issue #28498)
2-
--> $DIR/feature-gate-dropck-ugeh.rs:19:5
2+
--> $DIR/feature-gate-dropck-ugeh.rs:16:5
33
|
44
LL | #[unsafe_destructor_blind_to_params] // This is the UGEH attribute
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= help: add #![feature(dropck_parametricity)] to the crate attributes to enable
88

9+
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
10+
--> $DIR/feature-gate-dropck-ugeh.rs:16:5
11+
|
12+
LL | #[unsafe_destructor_blind_to_params] // This is the UGEH attribute
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace this attribute with `#[may_dangle]`
14+
|
15+
= note: #[warn(deprecated)] on by default
16+
917
error: aborting due to previous error
1018

1119
For more information about this error, try `rustc --explain E0658`.
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
// Check that existential types must be ungated to use the `existential` keyword
22

3-
4-
53
existential type Foo: std::fmt::Debug; //~ ERROR existential types are unstable
64

75
trait Bar {
86
type Baa: std::fmt::Debug;
7+
fn define() -> Self::Baa;
98
}
109

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

15+
fn define() -> Foo { 0 }
16+
1517
fn main() {}

src/test/ui/feature-gates/feature-gate-existential-type.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0658]: existential types are unstable (see issue #34511)
2-
--> $DIR/feature-gate-existential-type.rs:5:1
2+
--> $DIR/feature-gate-existential-type.rs:3:1
33
|
44
LL | existential type Foo: std::fmt::Debug; //~ ERROR existential types are unstable
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= help: add #![feature(existential_type)] to the crate attributes to enable
88

99
error[E0658]: existential types are unstable (see issue #34511)
10-
--> $DIR/feature-gate-existential-type.rs:12:5
10+
--> $DIR/feature-gate-existential-type.rs:11:5
1111
|
1212
LL | existential type Baa: std::fmt::Debug; //~ ERROR existential types are unstable
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
fn main() {
22
yield true; //~ ERROR yield syntax is experimental
3+
//~^ ERROR yield statement outside of generator literal
34
}

src/test/ui/feature-gates/feature-gate-generators.stderr

+9-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ LL | yield true; //~ ERROR yield syntax is experimental
66
|
77
= help: add #![feature(generators)] to the crate attributes to enable
88

9-
error: aborting due to previous error
9+
error[E0627]: yield statement outside of generator literal
10+
--> $DIR/feature-gate-generators.rs:2:5
11+
|
12+
LL | yield true; //~ ERROR yield syntax is experimental
13+
| ^^^^^^^^^^
14+
15+
error: aborting due to 2 previous errors
1016

11-
For more information about this error, try `rustc --explain E0658`.
17+
Some errors occurred: E0627, E0658.
18+
For more information about an error, try `rustc --explain E0627`.

src/test/ui/feature-gates/feature-gate-generic_associated_types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ trait PointerFamily<U> {
1111
struct Foo;
1212

1313
impl PointerFamily<u32> for Foo {
14-
type Pointer<usize> = Box<usize>;
14+
type Pointer<Usize> = Box<Usize>;
1515
//~^ ERROR generic associated types are unstable
16-
type Pointer2<u32> = Box<u32>;
16+
type Pointer2<U32> = Box<U32>;
1717
//~^ ERROR generic associated types are unstable
1818
}
1919

src/test/ui/feature-gates/feature-gate-generic_associated_types.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ LL | type Pointer2<T>: Deref<Target = T> where T: Clone, U: Clone;
2525
error[E0658]: generic associated types are unstable (see issue #44265)
2626
--> $DIR/feature-gate-generic_associated_types.rs:14:5
2727
|
28-
LL | type Pointer<usize> = Box<usize>;
28+
LL | type Pointer<Usize> = Box<Usize>;
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3030
|
3131
= help: add #![feature(generic_associated_types)] to the crate attributes to enable
3232

3333
error[E0658]: generic associated types are unstable (see issue #44265)
3434
--> $DIR/feature-gate-generic_associated_types.rs:16:5
3535
|
36-
LL | type Pointer2<u32> = Box<u32>;
36+
LL | type Pointer2<U32> = Box<U32>;
3737
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3838
|
3939
= help: add #![feature(generic_associated_types)] to the crate attributes to enable
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
extern "rust-intrinsic" { //~ ERROR intrinsics are subject to change
2-
fn bar();
2+
fn bar(); //~ ERROR unrecognized intrinsic function: `bar`
33
}
44

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

8-
fn main() {
9-
}
7+
fn main() {}

src/test/ui/feature-gates/feature-gate-intrinsics.stderr

+12-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0658]: intrinsics are subject to change
22
--> $DIR/feature-gate-intrinsics.rs:1:1
33
|
44
LL | / extern "rust-intrinsic" { //~ ERROR intrinsics are subject to change
5-
LL | | fn bar();
5+
LL | | fn bar(); //~ ERROR unrecognized intrinsic function: `bar`
66
LL | | }
77
| |_^
88
|
@@ -11,12 +11,18 @@ LL | | }
1111
error[E0658]: intrinsics are subject to change
1212
--> $DIR/feature-gate-intrinsics.rs:5:1
1313
|
14-
LL | / extern "rust-intrinsic" fn baz() { //~ ERROR intrinsics are subject to change
15-
LL | | }
16-
| |_^
14+
LL | extern "rust-intrinsic" fn baz() {} //~ ERROR intrinsics are subject to change
15+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1716
|
1817
= help: add #![feature(intrinsics)] to the crate attributes to enable
1918

20-
error: aborting due to 2 previous errors
19+
error[E0093]: unrecognized intrinsic function: `bar`
20+
--> $DIR/feature-gate-intrinsics.rs:2:5
21+
|
22+
LL | fn bar(); //~ ERROR unrecognized intrinsic function: `bar`
23+
| ^^^^^^^^^ unrecognized intrinsic
24+
25+
error: aborting due to 3 previous errors
2126

22-
For more information about this error, try `rustc --explain E0658`.
27+
Some errors occurred: E0093, E0658.
28+
For more information about an error, try `rustc --explain E0093`.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#[lang="foo"] //~ ERROR language items are subject to change
1+
#[lang = "foo"] //~ ERROR language items are subject to change
2+
//~^ ERROR definition of an unknown language item: `foo`
23
trait Foo {}
34

4-
fn main() {
5-
}
5+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
error[E0658]: language items are subject to change
22
--> $DIR/feature-gate-lang-items.rs:1:1
33
|
4-
LL | #[lang="foo"] //~ ERROR language items are subject to change
5-
| ^^^^^^^^^^^^^
4+
LL | #[lang = "foo"] //~ ERROR language items are subject to change
5+
| ^^^^^^^^^^^^^^^
66
|
77
= help: add #![feature(lang_items)] to the crate attributes to enable
88

9-
error: aborting due to previous error
9+
error[E0522]: definition of an unknown language item: `foo`
10+
--> $DIR/feature-gate-lang-items.rs:1:1
11+
|
12+
LL | #[lang = "foo"] //~ ERROR language items are subject to change
13+
| ^^^^^^^^^^^^^^^ definition of unknown language item `foo`
14+
15+
error: aborting due to 2 previous errors
1016

11-
For more information about this error, try `rustc --explain E0658`.
17+
Some errors occurred: E0522, E0658.
18+
For more information about an error, try `rustc --explain E0522`.

src/test/ui/feature-gates/feature-gate-linkage.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ extern {
22
#[linkage = "extern_weak"] static foo: isize;
33
//~^ ERROR: the `linkage` attribute is experimental and not portable
44
}
5+
6+
fn main() {}

src/test/ui/feature-gates/feature-gate-may-dangle.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
// Check that `may_dangle` is rejected if `dropck_eyepatch` feature gate is absent.
44

55
struct Pt<A>(A);
6-
impl<#[may_dangle] A> Drop for Pt<A> {
6+
unsafe impl<#[may_dangle] A> Drop for Pt<A> {
77
//~^ ERROR may_dangle has unstable semantics and may be removed in the future
88
fn drop(&mut self) { }
99
}
10+
11+
fn main() {}

src/test/ui/feature-gates/feature-gate-may-dangle.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0658]: may_dangle has unstable semantics and may be removed in the future (see issue #34761)
2-
--> $DIR/feature-gate-may-dangle.rs:6:6
2+
--> $DIR/feature-gate-may-dangle.rs:6:13
33
|
4-
LL | impl<#[may_dangle] A> Drop for Pt<A> {
5-
| ^^^^^^^^^^^^^
4+
LL | unsafe impl<#[may_dangle] A> Drop for Pt<A> {
5+
| ^^^^^^^^^^^^^
66
|
77
= help: add #![feature(dropck_eyepatch)] to the crate attributes to enable
88

0 commit comments

Comments
 (0)