Skip to content

Commit c2a9756

Browse files
committed
[IMP] core: upgrade Rust to 2024 edition
1 parent 3cb23d0 commit c2a9756

File tree

12 files changed

+48
-49
lines changed

12 files changed

+48
-49
lines changed

server/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "odoo_ls_server"
33
version = "0.12.0"
4-
edition = "2021"
4+
edition = "2024"
55
authors = ["Odoo"]
66
readme = "../README.md"
77
repository = "https://github.com/odoo/odoo-ls"

server/benches/iai_profiler.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ run cargo install --version 0.14.0 iai-callgrind-runner
2323

2424
#[library_benchmark]
2525
fn iai_main() {
26-
env::set_var("RUST_BACKTRACE", "full");
26+
// TODO: Audit that the environment access only happens in single-threaded code.
27+
unsafe { env::set_var("RUST_BACKTRACE", "full") };
2728

2829
let log_level = LogLevel::INFO;
2930
let log_level = match log_level {

server/src/allocator.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,27 @@ pub struct TrackingAllocator;
66
pub static ALLOCATED: AtomicUsize = AtomicUsize::new(0);
77

88
unsafe impl GlobalAlloc for TrackingAllocator {
9-
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
9+
unsafe fn alloc(&self, layout: Layout) -> *mut u8 { unsafe {
1010
let size = layout.size();
1111
ALLOCATED.fetch_add(size, Ordering::SeqCst);
1212
System.alloc(layout)
13-
}
13+
}}
1414

15-
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
15+
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { unsafe {
1616
let size = layout.size();
1717
ALLOCATED.fetch_sub(size, Ordering::SeqCst);
1818
System.dealloc(ptr, layout)
19-
}
19+
}}
2020

2121
unsafe fn realloc(
2222
&self,
2323
ptr: *mut u8,
2424
old_layout: Layout,
2525
new_size: usize,
26-
) -> *mut u8 {
26+
) -> *mut u8 { unsafe {
2727
let old_size = old_layout.size();
2828
ALLOCATED.fetch_sub(old_size, Ordering::SeqCst);
2929
ALLOCATED.fetch_add(new_size, Ordering::SeqCst);
3030
System.realloc(ptr, old_layout, new_size)
31-
}
31+
}}
3232
}

server/src/core/config.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ pub struct DiagnosticFilter {
105105
}
106106

107107
/// Serialize the schema as Vec<String> and adds the default
108-
fn regex_vec_schema(gen: &mut SchemaGenerator) -> Schema {
109-
let mut schema = <Vec<String>>::json_schema(gen);
108+
fn regex_vec_schema(generator: &mut SchemaGenerator) -> Schema {
109+
let mut schema = <Vec<String>>::json_schema(generator);
110110
schema.insert("default".into(), serde_json::json!([]));
111111
schema
112112
}
@@ -1404,7 +1404,7 @@ fn merge_all_workspaces(
14041404
pub fn get_configuration(ws_folders: &HashMap<String, String>, cli_config_file: &Option<String>) -> Result<(ConfigNew, ConfigFile), String> {
14051405
let mut ws_confs: Vec<HashMap<String, ConfigEntryRaw>> = Vec::new();
14061406

1407-
if let Some(ref path) = cli_config_file {
1407+
if let Some(path) = cli_config_file {
14081408
let config_from_file = load_config_from_file(path.clone(), ws_folders)?;
14091409
ws_confs.push(config_from_file);
14101410
}

server/src/core/evaluation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1675,7 +1675,7 @@ impl EvaluationSymbol {
16751675

16761676
pub fn get_weak_mut(&mut self) -> &mut EvaluationSymbolWeak {
16771677
match &mut self.sym {
1678-
EvaluationSymbolPtr::WEAK(ref mut w) => w,
1678+
EvaluationSymbolPtr::WEAK(w) => w,
16791679
_ => panic!("Not an EvaluationSymbolWeak")
16801680
}
16811681
}

server/src/core/python_arch_builder.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -105,24 +105,21 @@ impl PythonArchBuilder {
105105
let file_info = file_info_rc.borrow();
106106
if file_info.file_info_ast.borrow().indexed_module.is_some() {
107107
let file_info_ast= file_info.file_info_ast.borrow();
108-
let ast = match self.file_mode {
109-
true => {
110-
file_info_ast.get_stmts().as_ref().unwrap()
111-
},
112-
false => {
113-
let ast_index = self.sym_stack[0].borrow().node_index().unwrap().load();
114-
if ast_index.as_u32() != u32::MAX {
115-
let func = file_info_ast.indexed_module.as_ref().unwrap().get_by_index(ast_index);
116-
match func {
117-
AnyRootNodeRef::Stmt(Stmt::FunctionDef(func_stmt)) => {
118-
&func_stmt.body
119-
},
120-
_ => panic!("Expected function definition")
121-
}
122-
} else {
123-
//if ast_index is empty, this is because the function has been added manually and do not belong to the ast. Skip it's building
124-
&vec![]
108+
let ast = if self.file_mode {
109+
file_info_ast.get_stmts().unwrap()
110+
} else {
111+
let ast_index = self.sym_stack[0].borrow().node_index().unwrap().load();
112+
if ast_index.as_u32() != u32::MAX {
113+
let func = file_info_ast.indexed_module.as_ref().unwrap().get_by_index(ast_index);
114+
match func {
115+
AnyRootNodeRef::Stmt(Stmt::FunctionDef(func_stmt)) => {
116+
&func_stmt.body
117+
},
118+
_ => panic!("Expected function definition")
125119
}
120+
} else {
121+
//if ast_index is empty, this is because the function has been added manually and do not belong to the ast. Skip it's building
122+
&vec![]
126123
}
127124
};
128125
let old_stack_noqa = session.noqas_stack.clone();

server/src/core/python_arch_eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ impl PythonArchEval {
974974
);
975975
for eval in evaluations.iter_mut() { //as this is an evaluation, we need to set the instance to true
976976
match eval.symbol.get_mut_symbol_ptr() {
977-
EvaluationSymbolPtr::WEAK(ref mut sym_weak) => {
977+
EvaluationSymbolPtr::WEAK(sym_weak) => {
978978
sym_weak.instance = Some(true);
979979
},
980980
_ => {}

server/src/core/symbols/symbol.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2137,7 +2137,7 @@ impl Symbol {
21372137
if !get_result.weak.is_expired() {
21382138
let mut eval = Evaluation::eval_from_symbol(&get_result.weak, get_result.instance);
21392139
match eval.symbol.get_mut_symbol_ptr() {
2140-
EvaluationSymbolPtr::WEAK(ref mut weak) => {
2140+
EvaluationSymbolPtr::WEAK(weak) => {
21412141
if let Some(eval_sym_rc) = weak.weak.upgrade(){
21422142
if Rc::ptr_eq(&eval_sym_rc, &symbol_rc){
21432143
continue;
@@ -2308,7 +2308,7 @@ impl Symbol {
23082308
}
23092309
}
23102310

2311-
pub fn all_symbols(&self) -> impl Iterator<Item= Rc<RefCell<Symbol>>> {
2311+
pub fn all_symbols(&self) -> impl Iterator<Item= Rc<RefCell<Symbol>>> + use<> {
23122312
//return an iterator on all symbols of self. only symbols in symbols and module_symbols will
23132313
//be returned.
23142314
let mut iter: Vec<Rc<RefCell<Symbol>>> = Vec::new();
@@ -2545,7 +2545,7 @@ impl Symbol {
25452545
}
25462546
}
25472547

2548-
pub fn get_sorted_symbols(&self) -> impl Iterator<Item = Rc<RefCell<Symbol>>> {
2548+
pub fn get_sorted_symbols(&self) -> impl Iterator<Item = Rc<RefCell<Symbol>>> + use<> {
25492549
let mut symbols: Vec<Rc<RefCell<Symbol>>> = Vec::new();
25502550
match self {
25512551
Symbol::Class(_) | Symbol::Function(_) | Symbol::File(_) | Symbol::Package(PackageSymbol::Module(_)) |

server/src/core/xml_data.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,27 +56,27 @@ impl OdooData {
5656

5757
pub fn set_file_symbol(&mut self, xml_symbol: &Rc<RefCell<Symbol>>) {
5858
match self {
59-
OdooData::RECORD(ref mut record) => {
59+
OdooData::RECORD(record) => {
6060
record.file_symbol = Rc::downgrade(xml_symbol);
6161
},
62-
OdooData::MENUITEM(ref mut menu_item) => {
62+
OdooData::MENUITEM(menu_item) => {
6363
menu_item.file_symbol = Rc::downgrade(xml_symbol);
6464
},
65-
OdooData::TEMPLATE(ref mut template) => {
65+
OdooData::TEMPLATE(template) => {
6666
template.file_symbol = Rc::downgrade(xml_symbol);
6767
},
68-
OdooData::DELETE(ref mut delete) => {
68+
OdooData::DELETE(delete) => {
6969
delete.file_symbol = Rc::downgrade(xml_symbol);
7070
},
7171
}
7272
}
7373

7474
pub fn get_range(&self) -> Range<usize> {
7575
match self {
76-
OdooData::RECORD(ref record) => record.range.clone(),
77-
OdooData::MENUITEM(ref menu_item) => menu_item.range.clone(),
78-
OdooData::TEMPLATE(ref template) => template.range.clone(),
79-
OdooData::DELETE(ref delete) => delete.range.clone(),
76+
OdooData::RECORD(record) => record.range.clone(),
77+
OdooData::MENUITEM(menu_item) => menu_item.range.clone(),
78+
OdooData::TEMPLATE(template) => template.range.clone(),
79+
OdooData::DELETE(delete) => delete.range.clone(),
8080
}
8181
}
8282

@@ -93,16 +93,16 @@ impl OdooData {
9393
/* Warning: the returned symbol can of a different type than an XML_SYMBOL */
9494
pub fn get_file_symbol(&self) -> Option<Weak<RefCell<Symbol>>> {
9595
match self {
96-
OdooData::RECORD(ref record) => {
96+
OdooData::RECORD(record) => {
9797
Some(record.file_symbol.clone())
9898
},
99-
OdooData::MENUITEM(ref menu_item) => {
99+
OdooData::MENUITEM(menu_item) => {
100100
Some(menu_item.file_symbol.clone())
101101
},
102-
OdooData::TEMPLATE(ref template) => {
102+
OdooData::TEMPLATE(template) => {
103103
Some(template.file_symbol.clone())
104104
},
105-
OdooData::DELETE(ref delete) => {
105+
OdooData::DELETE(delete) => {
106106
Some(delete.file_symbol.clone())
107107
}
108108
}

server/src/features/ast_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl<'a> Visitor<'a> for ExprFinderVisitor<'a> {
194194
_ => &None
195195
};
196196

197-
if let Some(ref ident) = ident {
197+
if let Some(ident) = ident {
198198
if ident.range().contains(self.offset) {
199199
self.expr = Some(ExprOrIdent::Ident(ident));
200200
}

0 commit comments

Comments
 (0)