Skip to content

Commit 163adf2

Browse files
committed
Auto merge of #53699 - oli-obk:promotion_stability_hole, r=nikomatsakis
Fix promotion stability hole in old borrowck r? @nikomatsakis I screwed up the promotion stability checks. Big time. They were basically nonexistant. We had tests for it. I also screwed up said tests. This is in stable already :( Basically stability checks of promotion only worked if you tried to use a const fn defined in the same crate. cc @eddyb
2 parents c2afca3 + 2d2b69d commit 163adf2

9 files changed

+93
-7
lines changed

src/librustc_mir/transform/qualify_consts.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> {
127127
mir: &'a Mir<'tcx>,
128128
mode: Mode)
129129
-> Qualifier<'a, 'tcx, 'tcx> {
130+
assert!(def_id.is_local());
130131
let mut rpo = traversal::reverse_postorder(mir);
131132
let temps = promote_consts::collect_temps(mir, &mut rpo);
132133
rpo.reset();
@@ -927,9 +928,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
927928
.iter()
928929
.any(|&(ref sym, _)| sym == feature_name) &&
929930

930-
// this doesn't come from a crate with the feature-gate enabled,
931-
self.def_id.is_local() &&
932-
933931
// this doesn't come from a macro that has #[allow_internal_unstable]
934932
!self.span.allows_unstable()
935933
{

src/librustc_passes/rvalue_promotion.rs

-3
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,6 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
189189
.iter()
190190
.any(|&(ref sym, _)| sym == feature_name) ||
191191

192-
// this comes from a crate with the feature-gate enabled,
193-
!def_id.is_local() ||
194-
195192
// this comes from a macro that has #[allow_internal_unstable]
196193
span.allows_unstable();
197194
if !stable_check {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Crate that exports a const fn. Used for testing cross-crate.
12+
13+
#![crate_type="rlib"]
14+
#![stable(feature = "rust1", since = "1.0.0")]
15+
16+
#![feature(rustc_const_unstable, const_fn)]
17+
#![feature(staged_api)]
18+
19+
#[stable(feature = "rust1", since = "1.0.0")]
20+
#[rustc_const_unstable(feature="foo")]
21+
pub const fn foo() -> u32 { 42 }

src/test/ui/consts/const-eval/dont_promote_unstable_const_fn.nll.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ error[E0597]: borrowed value does not live long enough
1111
|
1212
LL | let x: &'static _ = &std::time::Duration::from_millis(42).subsec_millis();
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
14+
LL | //~^ does not live long enough
1415
LL | }
1516
| - temporary value only lives until here
1617
|

src/test/ui/consts/const-eval/dont_promote_unstable_const_fn.rs

+1
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ fn a() {
3131
fn main() {
3232
let _: &'static u32 = &meh(); //~ ERROR does not live long enough
3333
let x: &'static _ = &std::time::Duration::from_millis(42).subsec_millis();
34+
//~^ does not live long enough
3435
}

src/test/ui/consts/const-eval/dont_promote_unstable_const_fn.stderr

+12-1
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,23 @@ error[E0597]: borrowed value does not live long enough
2121
|
2222
LL | let _: &'static u32 = &meh(); //~ ERROR does not live long enough
2323
| ^^^^^ temporary value does not live long enough
24+
...
25+
LL | }
26+
| - temporary value only lives until here
27+
|
28+
= note: borrowed value must be valid for the static lifetime...
29+
30+
error[E0597]: borrowed value does not live long enough
31+
--> $DIR/dont_promote_unstable_const_fn.rs:33:26
32+
|
2433
LL | let x: &'static _ = &std::time::Duration::from_millis(42).subsec_millis();
34+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough
35+
LL | //~^ does not live long enough
2536
LL | }
2637
| - temporary value only lives until here
2738
|
2839
= note: borrowed value must be valid for the static lifetime...
2940

30-
error: aborting due to 3 previous errors
41+
error: aborting due to 4 previous errors
3142

3243
For more information about this error, try `rustc --explain E0597`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0597]: borrowed value does not live long enough
2+
--> $DIR/dont_promote_unstable_const_fn_cross_crate.rs:19:29
3+
|
4+
LL | let _x: &'static u32 = &foo(); //~ ERROR does not live long enough
5+
| ^^^^^ temporary value does not live long enough
6+
LL | }
7+
| - temporary value only lives until here
8+
|
9+
= note: borrowed value must be valid for the static lifetime...
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0597`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// aux-build:stability.rs
12+
13+
extern crate stability;
14+
15+
use stability::foo;
16+
17+
fn main() {
18+
let _: &'static u32 = &foo(); //~ ERROR does not live long enough
19+
let _x: &'static u32 = &foo(); //~ ERROR does not live long enough
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error[E0597]: borrowed value does not live long enough
2+
--> $DIR/dont_promote_unstable_const_fn_cross_crate.rs:18:28
3+
|
4+
LL | let _: &'static u32 = &foo(); //~ ERROR does not live long enough
5+
| ^^^^^ temporary value does not live long enough
6+
LL | let _x: &'static u32 = &foo(); //~ ERROR does not live long enough
7+
LL | }
8+
| - temporary value only lives until here
9+
|
10+
= note: borrowed value must be valid for the static lifetime...
11+
12+
error[E0597]: borrowed value does not live long enough
13+
--> $DIR/dont_promote_unstable_const_fn_cross_crate.rs:19:29
14+
|
15+
LL | let _x: &'static u32 = &foo(); //~ ERROR does not live long enough
16+
| ^^^^^ temporary value does not live long enough
17+
LL | }
18+
| - temporary value only lives until here
19+
|
20+
= note: borrowed value must be valid for the static lifetime...
21+
22+
error: aborting due to 2 previous errors
23+
24+
For more information about this error, try `rustc --explain E0597`.

0 commit comments

Comments
 (0)