Comments (3)
closing as not a bug
from rust.
This code is trying to execute UB. It happened to work as you wanted before, by sheer luck. The problem is reported by running the code in Miri, which you can do via the playground or locally. The error is this:
error: Undefined Behavior: trying to retag from <2677> for Unique permission at alloc1188[0x0], but that tag only grants SharedReadOnly permission for this location
--> src/main.rs:15:15
|
15 | f(&mut *self.0);
| ^^^^^^^^^^^^
| |
| trying to retag from <2677> for Unique permission at alloc1188[0x0], but that tag only grants SharedReadOnly permission for this location
| this error occurs as part of retag at alloc1188[0x0..0x1]
|
= help: this indicates a potential bug in the program: it performed an invalid operation, but the Stacked Borrows rules it violated are still experimental
= help: see https://github.com/rust-lang/unsafe-code-guidelines/blob/master/wip/stacked-borrows.md for further information
help: <2677> was created by a SharedReadOnly retag at offsets [0x0..0x1]
--> src/main.rs:7:14
|
7 | Self(t as *const T as *mut T)
| ^
= note: BACKTRACE (of the first span):
= note: inside `ResMut::<A>::patch_by::<{closure@src/main.rs:45:19: 45:22}>` at src/main.rs:15:15: 15:27
note: inside `foo`
--> src/main.rs:44:5
|
44 | / ResMut::new(&v[0])
45 | | .patch_by(|x| x.a = B::Bar).unwrap();
| |___________________________________^
note: inside `main`
--> src/main.rs:39:5
|
39 | foo(&v);
| ^^^^^^^
from rust.
Well, in more simple terms, you're just modifying immutable data - that is instant UB in Rust.
Maybe what you're looking for is UnsafeCell or some kind of its derivative (RefCell, Mutex, RwLock)
from rust.
Related Issues (20)
- PhantomData confusing documentation
- Performance regression between v1.76.0 and v1.77.2 HOT 4
- Nightly rustc panic when compiling a simple no_std program HOT 2
- Wrong import hint HOT 1
- add a custom diagnostic for type mismatches of constants
- Compilation bug while using Diesel framework HOT 4
- ICE: `could not resolve upvar: LocalVarId(HirId(DefId)))`
- Compiler creates unnecessary pointer to the value on ownership transfering. HOT 7
- ICE: coherence: `assertion failed: obligations.is_empty()` HOT 1
- unused_associated_type_bounds are usable and useful
- ICE: cannot convert `'{erased}` to a region vid HOT 2
- Bootstrap build fails: found crate `serde_derive` compiled by an incompatible version of rustc HOT 6
- long literal expressions should be truncated HOT 17
- Clean out old msys2/mingw stuff in CI HOT 10
- We should document what external dependencies we assume for our test suites
- Tracking issue for `-Zterminal-urls` HOT 2
- We should document more clearly env vars used between bootstrap <-> compiletest <-> test suites
- Decide which methods to add to new `Range` types HOT 2
- error: --remap-path-prefix must contain '=' between FROM and TO because path contains spaces HOT 7
- Incorrectly suggests replacing end characters of function call with double quotes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rust.