Skip to content

Commit 8eb5ab7

Browse files
committed
rebase fixes, do not review
1 parent 1860f4f commit 8eb5ab7

File tree

3 files changed

+63
-46
lines changed

3 files changed

+63
-46
lines changed

src/compile.rs

+13-7
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ pub fn validate_fs_context_duplicates(
362362
match rule.fscontext_type {
363363
// If we ever see a duplicate of xattr task or trans we know something is wrong
364364
FSContextType::XAttr | FSContextType::Task | FSContextType::Trans => {
365-
let mut range: Range<usize> = 0..0;
365+
let mut range: Range<usize> = 1..1;
366366
for arg in &rule.func_call.args {
367367
if let Argument::Quote(cas_arg) = &arg.0 {
368368
if *cas_arg == rule.fs_name {
@@ -393,7 +393,8 @@ pub fn validate_fs_context_duplicates(
393393
// need to add a new error message
394394
if let Some(unwrapped_error) = error {
395395
error = Some(unwrapped_error.add_additional_message(&inner_rule.file,
396-
inner_range.unwrap_or_default(),
396+
// The unwrap in the unwrap_or is safe since we know we have a function call w/ range at this point
397+
inner_range.unwrap_or_else(||inner_rule.func_call.get_name_range().unwrap()),
397398
&format!("Found duplicate genfscon rules for filesystem {} with differing contexts: {}", inner_rule.fs_name, inner_rule.context)));
398399
} else {
399400
let outer_range: Option<Range<usize>> =
@@ -402,11 +403,13 @@ pub fn validate_fs_context_duplicates(
402403
error = Some(CompileError::new(
403404
"Duplicate genfscon contexts",
404405
&rule.file,
405-
outer_range.unwrap_or_default(),
406+
// The unwrap in the unwrap_or is safe since we know we have a function call w/ range at this point
407+
outer_range.unwrap_or_else(||rule.func_call.get_name_range().unwrap()),
406408
&format!("Found duplicate genfscon rules for filesystem {} with differing contexts: {}", rule.fs_name, rule.context)));
407409
// We just made the error we are okay to unwrap it
408410
error = Some(error.unwrap().add_additional_message(&inner_rule.file,
409-
inner_range.unwrap_or_default(),
411+
// The unwrap in the unwrap_or is safe since we know we have a function call w/ range at this point
412+
inner_range.unwrap_or_else(||inner_rule.func_call.get_name_range().unwrap()),
410413
&format!("Found duplicate genfscon rules for filesystem {} with differing contexts: {}", inner_rule.fs_name, inner_rule.context)));
411414
}
412415
// Our paths are the same but our file types differ, we must also have a file type.
@@ -432,7 +435,8 @@ pub fn validate_fs_context_duplicates(
432435
// need to add a new error message
433436
if let Some(unwrapped_error) = error {
434437
error = Some(unwrapped_error.add_additional_message(&inner_rule.file,
435-
inner_range.unwrap_or_default(),
438+
// The unwrap in the unwrap_or is safe since we know we have a function call w/ range at this point
439+
inner_range.unwrap_or_else(||inner_rule.func_call.get_name_range().unwrap()),
436440
&format!("Found duplicate genfscon rules for filesystem {} with differing file types", inner_rule.fs_name)));
437441
} else {
438442
// Just like above we need to look through the outer function's args to get the correct range
@@ -453,11 +457,13 @@ pub fn validate_fs_context_duplicates(
453457
error = Some(CompileError::new(
454458
"Duplicate genfscon file types",
455459
&inner_rule.file,
456-
outer_range.unwrap_or_default(),
460+
// The unwrap in the unwrap_or is safe since we know we have a function call w/ range at this point
461+
outer_range.unwrap_or_else(||rule.func_call.get_name_range().unwrap()),
457462
&format!("Found duplicate genfscon rules for filesystem {} with differing file types", rule.fs_name)));
458463
// We just made the error we are safe to unwrap
459464
error = Some(error.unwrap().add_additional_message(&inner_rule.file,
460-
inner_range.unwrap_or_default(),
465+
// The unwrap in the unwrap_or is safe since we know we have a function call w/ range at this point
466+
inner_range.unwrap_or_else(||inner_rule.func_call.get_name_range().unwrap()),
461467
&format!("Found duplicate genfscon rules for filesystem {} with differing file types", inner_rule.fs_name)));
462468
}
463469
}

src/error.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub fn add_or_create_compile_error(
9494
error: Option<CompileError>,
9595
msg: &str,
9696
file: &SimpleFile<String, String>,
97-
range: Option<Range<usize>>,
97+
range: Range<usize>,
9898
help: &str,
9999
) -> CompileError {
100100
if let Some(unwrapped_error) = error {
@@ -406,8 +406,7 @@ mod tests {
406406
"This is the word 'of' in file 1",
407407
);
408408

409-
error =
410-
error.add_additional_message(&file2, 12..16, "This is the word file in file 2");
409+
error = error.add_additional_message(&file2, 12..16, "This is the word file in file 2");
411410

412411
let labels = error.diagnostic.inner.labels;
413412
assert_eq!(labels.len(), 2);

src/internal_rep.rs

+48-36
Original file line numberDiff line numberDiff line change
@@ -1746,12 +1746,14 @@ fn call_to_fsc_rules<'a>(
17461746
let fs_context = match Context::try_from(context_str.to_string()) {
17471747
Ok(c) => c,
17481748
Err(_) => {
1749-
return Err(CascadeErrors::from(ErrorItem::make_compile_or_internal_error(
1750-
"Invalid context",
1751-
Some(file),
1752-
context_str.get_range(),
1753-
"Cannot parse this into a context",
1754-
)))
1749+
return Err(CascadeErrors::from(
1750+
ErrorItem::make_compile_or_internal_error(
1751+
"Invalid context",
1752+
Some(file),
1753+
context_str.get_range(),
1754+
"Cannot parse this into a context",
1755+
),
1756+
))
17551757
}
17561758
};
17571759
let fs_name = args_iter
@@ -1766,12 +1768,14 @@ fn call_to_fsc_rules<'a>(
17661768
let fscontext_type = match fscontext_str.to_string().parse::<FSContextType>() {
17671769
Ok(f) => f,
17681770
Err(_) => {
1769-
return Err(CascadeErrors::from(ErrorItem::make_compile_or_internal_error(
1770-
"Not a valid file system type",
1771-
Some(file),
1772-
fscontext_str.get_range(),
1773-
"File system type must be 'xattr', 'task', 'trans', or 'genfscon'",
1774-
)));
1771+
return Err(CascadeErrors::from(
1772+
ErrorItem::make_compile_or_internal_error(
1773+
"Not a valid file system type",
1774+
Some(file),
1775+
fscontext_str.get_range(),
1776+
"File system type must be 'xattr', 'task', 'trans', or 'genfscon'",
1777+
),
1778+
));
17751779
}
17761780
};
17771781
let regex_string_arg = args_iter
@@ -1802,20 +1806,24 @@ fn call_to_fsc_rules<'a>(
18021806
}
18031807
let mut errors = CascadeErrors::new();
18041808
if !file_types.is_empty() {
1805-
errors.append(CascadeErrors::from(ErrorItem::make_compile_or_internal_error(
1806-
"File types can only be provided for 'genfscon'",
1807-
Some(file),
1808-
file_types_arg.get_range(),
1809-
"",
1810-
)));
1809+
errors.append(CascadeErrors::from(
1810+
ErrorItem::make_compile_or_internal_error(
1811+
"File types can only be provided for 'genfscon'",
1812+
Some(file),
1813+
file_types_arg.get_range(),
1814+
"",
1815+
),
1816+
));
18111817
}
18121818
if regex_string_arg.get_range().is_some() {
1813-
errors.append(CascadeErrors::from(ErrorItem::make_compile_or_internal_error(
1814-
"File path can only be provided for 'genfscon'",
1815-
Some(file),
1816-
regex_string_arg.get_range(),
1817-
"",
1818-
)));
1819+
errors.append(CascadeErrors::from(
1820+
ErrorItem::make_compile_or_internal_error(
1821+
"File path can only be provided for 'genfscon'",
1822+
Some(file),
1823+
regex_string_arg.get_range(),
1824+
"",
1825+
),
1826+
));
18191827
}
18201828
if !errors.is_empty() {
18211829
return Err(errors);
@@ -1837,12 +1845,14 @@ fn call_to_fsc_rules<'a>(
18371845
let file_type = match file_type.to_string().parse::<FileType>() {
18381846
Ok(f) => f,
18391847
Err(_) => {
1840-
return Err(CascadeErrors::from(ErrorItem::make_compile_or_internal_error(
1841-
"Not a valid file type",
1842-
Some(file),
1843-
file_type.get_range(),
1844-
"",
1845-
)))
1848+
return Err(CascadeErrors::from(
1849+
ErrorItem::make_compile_or_internal_error(
1850+
"Not a valid file type",
1851+
Some(file),
1852+
file_type.get_range(),
1853+
"",
1854+
),
1855+
))
18461856
}
18471857
};
18481858

@@ -2546,12 +2556,14 @@ impl<'a> ValidatedStatement<'a> {
25462556
.map(ValidatedStatement::FscRule)
25472557
.collect())
25482558
} else {
2549-
Err(CascadeErrors::from(ErrorItem::make_compile_or_internal_error(
2550-
"fs_context() calls are only allowed in resources",
2551-
Some(file),
2552-
c.name.get_range(),
2553-
"Not allowed here",
2554-
)))
2559+
Err(CascadeErrors::from(
2560+
ErrorItem::make_compile_or_internal_error(
2561+
"fs_context() calls are only allowed in resources",
2562+
Some(file),
2563+
c.name.get_range(),
2564+
"Not allowed here",
2565+
),
2566+
))
25552567
}
25562568
}
25572569
Some(BuiltIns::DomainTransition) => {

0 commit comments

Comments
 (0)