compiletest/directives/
file.rs1use camino::Utf8Path;
2
3use crate::directives::LineNumber;
4use crate::directives::line::{DirectiveLine, line_directive};
5
6pub(crate) struct FileDirectives<'a> {
7 pub(crate) path: &'a Utf8Path,
8 pub(crate) lines: Vec<DirectiveLine<'a>>,
9
10 pub(crate) has_explicit_no_std_core_attribute: bool,
12}
13
14impl<'a> FileDirectives<'a> {
15 pub(crate) fn from_file_contents(path: &'a Utf8Path, file_contents: &'a str) -> Self {
16 let mut lines = vec![];
17 let mut has_explicit_no_std_core_attribute = false;
18
19 for (line_number, ln) in LineNumber::enumerate().zip(file_contents.lines()) {
20 let ln = ln.trim();
21
22 if ln.starts_with("#![no_std]") || ln.starts_with("#![no_core]") {
31 has_explicit_no_std_core_attribute = true;
32 continue;
33 }
34
35 if let Some(directive_line) = line_directive(path, line_number, ln) {
36 lines.push(directive_line);
37 }
38 }
39
40 Self { path, lines, has_explicit_no_std_core_attribute }
41 }
42}