-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Explain why we do not overwrite qualification of locals
- Loading branch information
Showing
5 changed files
with
34 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
// compile-pass | ||
|
||
#![feature(const_let)] | ||
|
||
use std::cell::Cell; | ||
|
||
// this is overly conservative. The reset to `None` should clear `a` of all qualifications | ||
// while we could fix this, it would be inconsistent with `qualif_overwrite_2.rs`. | ||
// We can fix this properly in the future by allowing constants that do not depend on generics | ||
// to be checked by an analysis on the final value instead of looking at the body. | ||
const FOO: &Option<Cell<usize>> = { | ||
let mut a = Some(Cell::new(0)); | ||
a = None; // resets `qualif(a)` to `qualif(None)` | ||
&{a} | ||
a = None; // sets `qualif(a)` to `qualif(a) | qualif(None)` | ||
&{a} //~ ERROR cannot borrow a constant which may contain interior mutability | ||
}; | ||
|
||
fn main() {} |
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,13 @@ | ||
#![feature(const_let)] | ||
|
||
use std::cell::Cell; | ||
|
||
// const qualification is not smart enough to know about fields and always assumes that there might | ||
// be other fields that caused the qualification | ||
const FOO: &Option<Cell<usize>> = { | ||
let mut a = (Some(Cell::new(0)),); | ||
a.0 = None; // sets `qualif(a)` to `qualif(a) | qualif(None)` | ||
&{a.0} //~ ERROR cannot borrow a constant which may contain interior mutability | ||
}; | ||
|
||
fn main() {} |
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,9 @@ | ||
error[E0492]: cannot borrow a constant which may contain interior mutability, create a static instead | ||
--> $DIR/qualif_overwrite_2.rs:10:5 | ||
| | ||
LL | &{a.0} //~ ERROR cannot borrow a constant which may contain interior mutability | ||
| ^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0492`. |