f33
map. If you have it, can you send it to me please? struct Foo<'a> {
u: &'a usize,
}
impl<'a> Foo<'a> {
fn new() -> Self {
Self { u: &10 }
}
fn test(&'a self) {}
}
fn main() {
let foo = Foo::new();
foo.test();
drop(foo);
}
But if method test
is changed to fn test(&'a mut self)
it doesn't work, it says it can't move out foo
because it's borrowed, isn't it also borrowed without mut
? :\pub fn build_object() {
let mut builder = build::elf::Builder::new(object::Endianness::Little, true);
builder.header.e_type = elf::ET_REL;
builder.header.e_machine = elf::EM_X86_64;
builder.header.e_phoff = 0x40;
let section = builder.sections.add();
section.name = b".shstrtab"[..].into();
section.sh_type = elf::SHT_STRTAB;
section.data = build::elf::SectionData::SectionString;
let section = builder.sections.add();
section.name = b".strtab"[..].into();
section.sh_type = elf::SHT_STRTAB;
section.data = build::elf::SectionData::String;
let section = builder.sections.add();
section.name = b".text"[..].into();
section.sh_type = elf::SHT_PROGBITS;
section.sh_flags = (elf::SHF_ALLOC | elf::SHF_EXECINSTR) as u64;
section.sh_addralign = 16;
// program data goes here.
let my_func_data: Vec<u8> = vec![
0xf3, 0x0f, 0x1e, 0xfa, // endbr64
0x55, // push %rbp
0x48, 0x89, 0xe5, // mov %rsp,%rbp
0xc7, 0x45, 0xfc, 0x00, 0x00, 0x00, 0x00, // movl $0x0,-0x4(%rbp)
0xb8, 0x02, 0x00, 0x00, 0x00, // mov $0x2,%eax
0x5d, // pop %rbp
0xc3, // ret
];
let my_func_data_size = my_func_data.len();
section.data = build::elf::SectionData::Data(my_func_data.into());
let text_id = section.id();
let section = builder.sections.add();
section.name = b".symtab"[..].into();
section.sh_type = elf::SHT_SYMTAB;
section.sh_flags = elf::SHF_ALLOC as u64;
section.sh_addralign = 8;
section.data = build::elf::SectionData::Symbol;
let symbol = builder.symbols.add();
symbol.name = b".text"[..].into();
symbol.set_st_info(elf::STB_LOCAL, elf::STT_SECTION);
symbol.section = Some(text_id);
// Add symbols
let symbol = builder.symbols.add();
symbol.name = b"main"[..].into();
symbol.set_st_info(elf::STB_GLOBAL, elf::STT_FUNC);
symbol.st_size = my_func_data_size as u64;
symbol.section = Some(text_id);
// offset to the function within .text
// Note: i think it needs to be 16 byte aligned
symbol.st_value = 0;
builder.set_section_sizes();
let mut file = StreamingBuffer::new(BufWriter::new(File::create("out.o").unwrap()));
builder.write(&mut file).unwrap();
}
f33
map. If you have it, can you send it to me please? f33
map there, search for f33_
struct Foo<'a> {
u: &'a usize,
}
impl<'a> Foo<'a> {
fn new() -> Self {
Self { u: &10 }
}
fn test(&'a self) {}
}
fn main() {
let foo = Foo::new();
foo.test();
drop(foo);
}
But if method test
is changed to fn test(&'a mut self)
it doesn't work, it says it can't move out foo
because it's borrowed, isn't it also borrowed without mut
? :\ self
referenceself
, I tried to read about this invariant stuff and I don't get what changes when type is invariant, covariant or contravariant&'a i32
reference, the rust compiler also allows you to pass a reference that lives longer&'static i32
&'static mut &'a i32
, rust mustn't allow you to pass a &'static mut &'static i32
. why?&'a i32
, one that actually only lives for 'a
into that outer &'static mut
&'static mut &'static i32
, but the inner reference actually only lives for 'a
&'static mut &'a i32
, rust mustn't allow you to pass a &'static mut &'static i32
. why? &'static mut T
variable? let x: &'static mut i32 = Box::leak(Box::new(0));
&'static mut &'a i32
, rust mustn't allow you to pass a &'static mut &'static i32
. why? fn foo<'a>(_: &'static mut &'a i32) {}
fn main() {
let x: &'static mut i32 = Box::leak(Box::new(0));
let y: &'static mut &'static i32 = Box::leak(Box::new(x));
foo(y);
}
'a = 'static
, so it worksfn foo<'a>(_: &'static mut &'a i32, _: &'a i32) {}
fn main() {
let a = 0;
let x: &'static mut i32 = Box::leak(Box::new(0));
let y: &'static mut &'static i32 = Box::leak(Box::new(x));
foo(y, &a);
}
'a
cannot be 'static
&'a mut Foo<'a>
foo
as fn foo<'a>(_: &'a mut &'a i32)
, then you'll get the same, I thinkdata
folder instead. See also #3758, where this happened seemingly with a default storage.cfg
.
Also, we could check if the config directory is writeable when launching. We had a report from rrrost on Discord that map download did not work, which was seemingly cau...#include "pretty.h"
int main (int argc, string argv[])
{
if (argc above 1)
with (f, fclose, fopen(argv[1], "r"))
fortimes (line, 10)
with (buf, free, vector(200, char, 0))
when (fgets(buf, 200, f))
then print(buf)
otherwise 0;
else
println("Please provide an input file");
return EXIT_SUCCESS;
}
fn foo_mut<'a>(_: &'a mut &'a String) {
// This function signature means take an exclusive reference for the entire rest of it's validity
}
fn foo<'a>(_: &'a &'a String) {}
fn main() {
let x = String::new();
let y: &String = &x;
foo(&y);
foo(&y); // It's passes something like &'smol &'big and &T is covariant so it can downgrade(?) 'big to 'smol, and with that you can call it as many times as you want
drop(x);
let i = String::new();
let mut j: &String = &i;
foo_mut(&mut i);
// Reference is eaten and still in use, so it's not possible to use `y`
// Something about &mut T being invariant over T but covariant over 'a
drop(y);
}
(edited)