Skip to main content

SourceFile

Struct SourceFile 

Source
pub struct SourceFile { /* private fields */ }
Expand description

A single file of C source together with its Rust-token anchors.

Implementations§

Source§

impl SourceFile

Source

pub fn id(&self) -> FileId

This file’s id.

Source

pub fn name(&self) -> &str

A human readable name, used in diagnostics.

Source

pub fn base(&self) -> Pos

The global offset at which this file’s text starts.

Source

pub fn text(&self) -> &str

The recovered C source text.

Source

pub fn range(&self) -> SourceRange

The range this file occupies in the global offset space.

Source

pub fn precise(&self) -> bool

Whether diagnostics in this file can point at an exact position.

Source

pub fn mode(&self) -> InputMode

How this file’s text was captured.

Source

pub fn line_count(&self) -> usize

Number of lines in the file (at least 1).

Source

pub fn rust_path(&self) -> Option<&str>

The .rs file this text was written in, when the compiler knows it.

This is what the preprocessor’s __FILE__ expands to; it is None outside a real macro expansion (a unit test building a TokenStream from a string) and for #included files, which name themselves.

Source

pub fn first_line(&self) -> usize

The 1-based line of the enclosing .rs file that this file’s line 1 sits on; 1 when nothing better is known.

The preprocessor adds this to a position’s own line to make __LINE__ a number that matches what an editor shows.

Source

pub fn is_included(&self) -> bool

Whether this file is one whose diagnostics name it themselves: an #included header, or the .c file of an include_c99!.

Neither has a span of its own — the caret lands on the #include or on the macro invocation — so file:line:column goes into the message instead; see SourceMap::header_position.

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> 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, 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, !>

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.