diff options
| author | Inokentiy Babushkin <twk@twki.de> | 2017-06-12 15:37:26 +0200 |
|---|---|---|
| committer | Inokentiy Babushkin <twk@twki.de> | 2017-06-12 15:37:26 +0200 |
| commit | 271133b03ee5da57334670f50cd8a6ebbc35d140 (patch) | |
| tree | 4401cf452b68d5962427a0e1fb4057a590231e27 /src/libsyntax_pos | |
| parent | afe841587df0d20b344b576641d0a32d32b87f54 (diff) | |
| download | rust-271133b03ee5da57334670f50cd8a6ebbc35d140.tar.gz rust-271133b03ee5da57334670f50cd8a6ebbc35d140.zip | |
External spans: address review.
* The lazy loading mechanism has been moved to a more appropriate place. * Return values from the functions invoked there are properly used. * Documentation has gotten some minor improvements. * Possibly some larger restructuring will need to take place still.
Diffstat (limited to 'src/libsyntax_pos')
| -rw-r--r-- | src/libsyntax_pos/lib.rs | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index 719c25e2410..94656b3aea7 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -604,28 +604,33 @@ impl FileMap { lines.push(pos); } - /// add externally loaded source. - /// if the hash of the input doesn't match or no input is supplied via None, + /// Add externally loaded source. + /// If the hash of the input doesn't match or no input is supplied via None, /// it is interpreted as an error and the corresponding enum variant is set. + /// The return value signifies whether some kind of source is present. pub fn add_external_src(&self, src: Option<String>) -> bool { - let mut external_src = self.external_src.borrow_mut(); - if let Some(src) = src { - let mut hasher: StableHasher<u128> = StableHasher::new(); - hasher.write(src.as_bytes()); - - if hasher.finish() == self.src_hash { - *external_src = ExternalSource::Present(src); - return true; + if *self.external_src.borrow() == ExternalSource::AbsentOk { + let mut external_src = self.external_src.borrow_mut(); + if let Some(src) = src { + let mut hasher: StableHasher<u128> = StableHasher::new(); + hasher.write(src.as_bytes()); + + if hasher.finish() == self.src_hash { + *external_src = ExternalSource::Present(src); + return true; + } + } else { + *external_src = ExternalSource::AbsentErr; } + + false } else { - *external_src = ExternalSource::AbsentErr; + self.src.is_some() || self.external_src.borrow().get_source().is_some() } - - false } - /// get a line from the list of pre-computed line-beginnings. - /// line-number here is 0-based. + /// Get a line from the list of pre-computed line-beginnings. + /// The line number here is 0-based. pub fn get_line(&self, line_number: usize) -> Option<Cow<str>> { fn get_until_newline(src: &str, begin: usize) -> &str { // We can't use `lines.get(line_number+1)` because we might |
