Skip to main content

SearchPath

Struct SearchPath 

Source
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

Source

pub fn new() -> SearchPath

An empty search path.

Source

pub fn push_quote(&mut self, dir: impl Into<PathBuf>)

Adds a -iquote directory, searched only for a quoted include.

Source

pub fn push_bracket(&mut self, dir: impl Into<PathBuf>)

Adds a -I directory.

Source

pub fn push_system(&mut self, dir: impl Into<PathBuf>)

Adds a -isystem directory, or one of the target’s configured system directories.

Source

pub fn push_after(&mut self, dir: impl Into<PathBuf>)

Adds a -idirafter directory, which is searched after everything else.

Source

pub fn dirs(&self) -> &[Dir]

Every directory, in search order.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> SearchPath

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SearchPath

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SearchPath

Source§

fn default() -> SearchPath

Returns the “default value” for a type. Read more
Source§

impl Eq for SearchPath

Source§

impl PartialEq for SearchPath

Source§

fn eq(&self, other: &SearchPath) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for SearchPath

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.