-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #54424 - RalfJung:sync-promote, r=<try>
WIP: do not borrow non-Sync data in constants We cannot share that data across threads. non-Sync is as bad as non-Freeze in that regard. This is currently WIP because it ignores a test that is broken by #54419. But it is good enough ti get crater going. Fixes #49206. Cc @eddyb @nikomatsakis
- Loading branch information
Showing
18 changed files
with
269 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#![feature(optin_builtin_traits)] | ||
|
||
struct Foo; | ||
impl !Sync for Foo {} | ||
|
||
struct Bar(i32); | ||
impl !Sync for Bar {} | ||
|
||
struct Baz { field: i32 } | ||
impl !Sync for Baz {} | ||
|
||
enum Bla { T(i32), S { field: i32 } } | ||
impl !Sync for Bla {} | ||
|
||
// Known values of the given types | ||
fn mk_foo() -> &'static Foo { &Foo } //~ ERROR does not live long enough | ||
fn mk_bar() -> &'static Bar { &Bar(0) } //~ ERROR does not live long enough | ||
fn mk_baz() -> &'static Baz { &Baz { field: 0 } } //~ ERROR does not live long enough | ||
fn mk_bla_t() -> &'static Bla { &Bla::T(0) } //~ ERROR does not live long enough | ||
fn mk_bla_s() -> &'static Bla { &Bla::S { field: 0 } } //~ ERROR does not live long enough | ||
|
||
// Unknown values of the given types (test a ZST and a non-ZST) | ||
trait FooT { const C: Foo; } | ||
fn mk_foo2<T: FooT>() -> &'static Foo { &T::C } //~ ERROR does not live long enough | ||
|
||
trait BarT { const C: Bar; } | ||
fn mk_bar2<T: BarT>() -> &'static Bar { &T::C } //~ ERROR does not live long enough | ||
|
||
fn main() {} |
73 changes: 73 additions & 0 deletions
73
src/test/ui/consts/const-eval/dont_promote_non_sync.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
error[E0597]: borrowed value does not live long enough | ||
--> $DIR/dont_promote_non_sync.rs:16:32 | ||
| | ||
LL | fn mk_foo() -> &'static Foo { &Foo } //~ ERROR does not live long enough | ||
| ^^^ - temporary value only lives until here | ||
| | | ||
| temporary value does not live long enough | ||
| | ||
= note: borrowed value must be valid for the static lifetime... | ||
|
||
error[E0597]: borrowed value does not live long enough | ||
--> $DIR/dont_promote_non_sync.rs:17:32 | ||
| | ||
LL | fn mk_bar() -> &'static Bar { &Bar(0) } //~ ERROR does not live long enough | ||
| ^^^^^^ - temporary value only lives until here | ||
| | | ||
| temporary value does not live long enough | ||
| | ||
= note: borrowed value must be valid for the static lifetime... | ||
|
||
error[E0597]: borrowed value does not live long enough | ||
--> $DIR/dont_promote_non_sync.rs:18:32 | ||
| | ||
LL | fn mk_baz() -> &'static Baz { &Baz { field: 0 } } //~ ERROR does not live long enough | ||
| ^^^^^^^^^^^^^^^^ - temporary value only lives until here | ||
| | | ||
| temporary value does not live long enough | ||
| | ||
= note: borrowed value must be valid for the static lifetime... | ||
|
||
error[E0597]: borrowed value does not live long enough | ||
--> $DIR/dont_promote_non_sync.rs:19:34 | ||
| | ||
LL | fn mk_bla_t() -> &'static Bla { &Bla::T(0) } //~ ERROR does not live long enough | ||
| ^^^^^^^^^ - temporary value only lives until here | ||
| | | ||
| temporary value does not live long enough | ||
| | ||
= note: borrowed value must be valid for the static lifetime... | ||
|
||
error[E0597]: borrowed value does not live long enough | ||
--> $DIR/dont_promote_non_sync.rs:20:34 | ||
| | ||
LL | fn mk_bla_s() -> &'static Bla { &Bla::S { field: 0 } } //~ ERROR does not live long enough | ||
| ^^^^^^^^^^^^^^^^^^^ - temporary value only lives until here | ||
| | | ||
| temporary value does not live long enough | ||
| | ||
= note: borrowed value must be valid for the static lifetime... | ||
|
||
error[E0597]: borrowed value does not live long enough | ||
--> $DIR/dont_promote_non_sync.rs:24:42 | ||
| | ||
LL | fn mk_foo2<T: FooT>() -> &'static Foo { &T::C } //~ ERROR does not live long enough | ||
| ^^^^ - temporary value only lives until here | ||
| | | ||
| temporary value does not live long enough | ||
| | ||
= note: borrowed value must be valid for the static lifetime... | ||
|
||
error[E0597]: borrowed value does not live long enough | ||
--> $DIR/dont_promote_non_sync.rs:27:42 | ||
| | ||
LL | fn mk_bar2<T: BarT>() -> &'static Bar { &T::C } //~ ERROR does not live long enough | ||
| ^^^^ - temporary value only lives until here | ||
| | | ||
| temporary value does not live long enough | ||
| | ||
= note: borrowed value must be valid for the static lifetime... | ||
|
||
error: aborting due to 7 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0597`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#![feature(optin_builtin_traits)] | ||
|
||
struct Foo; | ||
impl !Sync for Foo {} | ||
|
||
struct Bar(i32); | ||
impl !Sync for Bar {} | ||
|
||
const FOO : &Foo = &Foo; //~ ERROR cannot borrow | ||
const FOO2 : Option<&Foo> = Some(&Foo); //~ ERROR cannot borrow | ||
//~^ ERROR borrowed value does not live long enough | ||
const FOO3 : &Option<Foo> = &Some(Foo); //~ ERROR cannot borrow | ||
|
||
const BAR : &Bar = &Bar(42); //~ ERROR cannot borrow | ||
const BAR2 : Option<&Bar> = Some(&Bar(42)); //~ ERROR cannot borrow | ||
//~^ ERROR borrowed value does not live long enough | ||
const BAR3 : &Option<Bar> = &Some(Bar(42)); //~ ERROR cannot borrow | ||
|
||
fn main() {} |
Oops, something went wrong.