pub struct SearchPath { /* private fields */ }Expand description
The directories a header is looked for in, in order.
GCC’s order, because a different one produces header shadowing bugs that are miserable to
diagnose: -iquote first and only for a quoted include, then -I, then -isystem, then
the configured system directories, then -idirafter. The directory of the including file
comes before all of it for a quoted include, and it is not part of the numbered list
because #include_next must not be able to land back on it.
Implementations§
Source§impl SearchPath
impl SearchPath
Sourcepub fn new() -> SearchPath
pub fn new() -> SearchPath
An empty search path.
Sourcepub fn push_quote(&mut self, dir: impl Into<PathBuf>)
pub fn push_quote(&mut self, dir: impl Into<PathBuf>)
Adds a -iquote directory, searched only for a quoted include.
Sourcepub fn push_bracket(&mut self, dir: impl Into<PathBuf>)
pub fn push_bracket(&mut self, dir: impl Into<PathBuf>)
Adds a -I directory.
Sourcepub fn push_system(&mut self, dir: impl Into<PathBuf>)
pub fn push_system(&mut self, dir: impl Into<PathBuf>)
Adds a -isystem directory, or one of the target’s configured system directories.
Sourcepub fn push_after(&mut self, dir: impl Into<PathBuf>)
pub fn push_after(&mut self, dir: impl Into<PathBuf>)
Adds a -idirafter directory, which is searched after everything else.
Sourcepub fn start(&self, form: IncludeForm) -> usize
pub fn start(&self, form: IncludeForm) -> usize
The first entry an include of this form looks at.
An angled include skips the -iquote directories, which is the only difference
between the two chains once the including file’s own directory is out of the way.
Sourcepub fn resolve(
&self,
fs: &dyn FileSystem,
name: &str,
form: IncludeForm,
relative_to: Option<&Path>,
from: usize,
) -> Option<Found>
pub fn resolve( &self, fs: &dyn FileSystem, name: &str, form: IncludeForm, relative_to: Option<&Path>, from: usize, ) -> Option<Found>
Finds name, starting at entry from of the search path.
relative_to is the directory of the file doing the including, tried first for a
quoted include and ignored otherwise. Pass None for an #include_next, which is
defined as continuing past the directory the current file was found in and so must not
look next to it again.
An absolute name is opened directly and the search path is not consulted, which is what every C compiler does and what a generated header with an absolute path needs.
Sourcepub fn tried(
&self,
name: &str,
form: IncludeForm,
relative_to: Option<&Path>,
from: usize,
) -> Vec<PathBuf>
pub fn tried( &self, name: &str, form: IncludeForm, relative_to: Option<&Path>, from: usize, ) -> Vec<PathBuf>
The directories a failed SearchPath::resolve with the same arguments looked in.
spec/05-preprocessor.md section 5.7 makes printing this the required behaviour for a
failed include, because “file not found” without the list of places that were tried is
the diagnostic that wastes the most time in this part of the compiler.
Trait Implementations§
Source§impl Clone for SearchPath
impl Clone for SearchPath
Source§fn clone(&self) -> SearchPath
fn clone(&self) -> SearchPath
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more