mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +00:00
Add enum, reference, array and slice to render_const_scalar
This commit is contained in:
parent
4458e7f190
commit
f9e3b180b7
9 changed files with 561 additions and 115 deletions
|
@ -35,7 +35,10 @@ mod tests;
|
|||
#[cfg(test)]
|
||||
mod test_db;
|
||||
|
||||
use std::{collections::HashMap, hash::Hash};
|
||||
use std::{
|
||||
collections::{hash_map::Entry, HashMap},
|
||||
hash::Hash,
|
||||
};
|
||||
|
||||
use chalk_ir::{
|
||||
fold::{Shift, TypeFoldable},
|
||||
|
@ -160,7 +163,16 @@ pub struct MemoryMap {
|
|||
|
||||
impl MemoryMap {
|
||||
fn insert(&mut self, addr: usize, x: Vec<u8>) {
|
||||
self.memory.insert(addr, x);
|
||||
match self.memory.entry(addr) {
|
||||
Entry::Occupied(mut e) => {
|
||||
if e.get().len() < x.len() {
|
||||
e.insert(x);
|
||||
}
|
||||
}
|
||||
Entry::Vacant(e) => {
|
||||
e.insert(x);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// This functions convert each address by a function `f` which gets the byte intervals and assign an address
|
||||
|
@ -172,6 +184,14 @@ impl MemoryMap {
|
|||
) -> Result<HashMap<usize, usize>, MirEvalError> {
|
||||
self.memory.iter().map(|x| Ok((*x.0, f(x.1)?))).collect()
|
||||
}
|
||||
|
||||
fn get<'a>(&'a self, addr: usize, size: usize) -> Option<&'a [u8]> {
|
||||
if size == 0 {
|
||||
Some(&[])
|
||||
} else {
|
||||
self.memory.get(&addr)?.get(0..size)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A concrete constant value
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue