Commit Graph

135 Commits

Author SHA1 Message Date
Nicholas Nethercote c12ab08c14 Move Spanned.
It's defined in `rustc_span::source_map` which doesn't make any sense
because it has nothing to do with source maps. This commit moves it to
the crate root, a more sensible spot for something this basic.
2026-03-11 06:25:23 +11:00
Urgau 8cbfb26383 Overhaul filename handling for cross-compiler consistency
This commit refactors `SourceMap` and most importantly `RealFileName` to
make it self-contained in order to achieve cross-compiler consistency.

This is achieved:
 - by making `RealFileName` immutable
 - by only having `SourceMap::to_real_filename` create `RealFileName`
 - by also making `RealFileName` holds it's working directory,
   it's embeddable name and the remapped scopes
 - by making most `FileName` and `RealFileName` methods take a scope as
   an argument

In order for `SourceMap::to_real_filename` to know which scopes to apply
`FilePathMapping` now takes the current remapping scopes to apply, which
makes `FileNameDisplayPreference` and company useless and are removed.

The scopes type `RemapPathScopeComponents` was moved from
`rustc_session::config` to `rustc_span`.

The previous system for scoping the local/remapped filenames
`RemapFileNameExt::for_scope` is no longer useful as it's replaced by
methods on `FileName` and `RealFileName`.
2025-12-12 07:33:09 +01:00
Urgau b7b0007bf0 Add current working to source map and FileLoader
This is preparation for the filename handling overhaul where having
access to the working directory is mandatory.
2025-12-12 07:32:25 +01:00
Weihang Lo cf57b9b292 fix(span): track unnormalized source len for dep-info
Add `unnormalized_source_len` field to track the byte length
of source files before normalization (the original length).

`unnormalized_source_len` is for writing the correct file length
to dep-info for `-Zchecksum-hash-algorithm`
2025-11-15 09:05:08 -05:00
Weihang Lo 5f385829e2 refactor(span): rename source_len to normalized_source_len
This is a preparation for introducing a unnormalized source length field
2025-11-15 09:05:08 -05:00
Jakub Beránek 3145c06431 Do not open every source file twice when reading it 2025-08-25 20:40:11 +02:00
Camille Gillot 1460cfe8ea Only unpack span data once. 2025-08-16 18:09:26 +00:00
Kivooeo b8eb046e6e use let chains in mir, resolve, target 2025-07-28 06:10:36 +05:00
Urgau 6a7996e303 Take into-account -Zremap-path-scope when embedding filenames 2025-05-05 19:45:34 +02:00
Makai 95ad6dfeab add span_extend_to_prev_char_before() to SourceMap 2025-04-10 20:12:26 +08:00
Askar Safin 0a21f1d0a2 tree-wide: parallel: Fully removed all Lrc, replaced with Arc 2025-02-03 13:25:57 +03:00
bors ab3cf268b5 Auto merge of #132791 - tyilo:big-file-fail-fast, r=compiler-errors
rustc: Fail fast when compiling a source file larger than 4 GiB

Currently if you try to compile a file that is larger than 4 GiB, `rustc` will first read the whole into memory before failing.

If we can read the metadata of the file, we can fail before reading the file.
2024-11-24 07:37:32 +00:00
Asger Hautop Drewsen 5caf516cd0 rustc: Fail fast when compiling a source file larger than 4 GiB - 1 B
Fixes #132862
2024-11-23 00:25:03 +01:00
Zalathar 3c30fe3423 coverage: Restrict empty-span expansion to only cover { and } 2024-11-08 20:43:08 +11:00
klensy 746b675c5a fix clippy::clone_on_ref_ptr for compiler 2024-10-28 18:05:08 +03:00
Jacob Kiesel bb5a8276be add unstable support for outputting file checksums for use in cargo 2024-10-01 21:23:20 -06:00
Eduardo Sánchez Muñoz 0b20ffcb63 Remove needless returns detected by clippy in the compiler 2024-09-09 13:32:22 +02:00
Nicholas Nethercote 84ac80f192 Reformat use declarations.
The previous commit updated `rustfmt.toml` appropriately. This commit is
the outcome of running `x fmt --all` with the new formatting options.
2024-07-29 08:26:52 +10:00
Esteban Küber 2d7795dfb9 Be more accurate about calculating display_col from a BytePos
No longer track "zero-width" chars in `SourceMap`, read directly from the line when calculating the `display_col` of a `BytePos`. Move `char_width` to `rustc_span` and use it from the emitter.

This change allows the following to properly align in terminals (depending on the font, the replaced control codepoints are rendered as 1 or 2 width, on my terminal they are rendered as 1, on VSCode text they are rendered as 2):

```
error: this file contains an unclosed delimiter
  --> $DIR/issue-68629.rs:5:17
   |
LL | ␜␟ts␀![{i
   |       -- unclosed delimiter
   |       |
   |       unclosed delimiter
LL | ␀␀  fn rݻoa>rݻm
   |                ^
```
2024-07-18 20:08:38 +00:00
Nicholas Nethercote e60c1916e0 Remove #[macro_use] extern crate tracing from rustc_span`.
Because explicit macro imports are better than implicit macro imports.
2024-05-22 16:03:48 +10:00
Nicholas Nethercote 4814fd0a4b Remove extern crate rustc_macros from numerous crates. 2024-04-29 10:21:54 +10:00
León Orell Valerian Liehr e15d6f9d85 Rollup merge of #123993 - compiler-errors:coroutine-obl, r=lcnr
Do `check_coroutine_obligations` once per typeck root

We only need to do `check_coroutine_obligations` once per typeck root, especially since the new solver can't really (easily) associate which obligations correspond to which coroutines.

This requires us to move the checks for sized coroutine fields into `mir_coroutine_witnesses`, but that's fine imo.

r? lcnr
2024-04-23 17:25:16 +02:00
Nicholas Nethercote 62c32aeeab Construct SourceMap at the same time as SessionGlobals.
Currently `SourceMap` is constructed slightly later than
`SessionGlobals`, and inserted. This commit changes things so they are
done at the same time.

Benefits:
- `SessionGlobals::source_map` changes from
  `Lock<Option<Lrc<SourceMap>>>` to `Option<Lrc<SourceMap>>`. It's still
  optional, but mutability isn't required because it's initialized at
  construction.
- `set_source_map` is removed, simplifying `run_compiler`, which is
  good because that's a critical function and it's nice to make it
  simpler.

This requires moving things around a bit, so the necessary inputs are
available when `SessionGlobals` is created, in particular the `loader`
and `hash_kind`, which are no longer computed by `build_session`. These
inputs are captured by the new `SourceMapInputs` type, which is threaded
through various places.
2024-04-16 13:02:53 +10:00
Michael Goulet 06501156d1 redundant ::{self} 2024-04-15 19:54:51 -04:00
Matthias Krüger ffea7e2a9b Rollup merge of #123204 - notriddle:notriddle/include-str-span, r=pnkfelix
rustdoc: point at span in `include_str!`-ed md file

Fixes #118549
2024-04-12 17:41:32 +02:00
Michael Goulet 3253c021cb Add a helper for extending a span to include any trailing whitespace 2024-04-09 14:06:09 -04:00
Michael Howell 98642da6a9 rustdoc: point at span in include_str!-ed md file 2024-03-29 13:31:35 -07:00
Urgau 4f4fa42b0e Introduce FileNameMapping::to_real_filename and use it everywhere 2024-03-28 18:47:26 +01:00
Mark Rousskov 510fcd318b Use UnhashMap for a few more maps
This avoids hashing data that's already hashed.
2024-01-17 17:09:55 -05:00
Martin Nordholts 16ba56c242 compiler: Lower fn call arg spans down to MIR
To enable improved accuracy of diagnostics in upcoming commits.
2024-01-15 19:07:11 +01:00
Vadim Petrochenkov 90d11d6448 rustc_span: Optimize syntax context comparisons
Including comparisons with root context
2024-01-06 01:25:20 +03:00
Michael Woerister fa8ef25372 Unify SourceFile::name_hash and StableSourceFileId 2023-12-19 22:34:26 +01:00
surechen 40ae34194c remove redundant imports
detects redundant imports that can be eliminated.

for #117772 :

In order to facilitate review and modification, split the checking code and
removing redundant imports code into two PR.
2023-12-10 10:56:22 +08:00
Nicholas Nethercote f405ce86c2 Minimize pub usage in source_map.rs.
Most notably, this commit changes the `pub use crate::*;` in that file
to `use crate::*;`. This requires a lot of `use` items in other crates
to be adjusted, because everything defined within `rustc_span::*` was
also available via `rustc_span::source_map::*`, which is bizarre.

The commit also removes `SourceMap::span_to_relative_line_string`, which
is unused.
2023-11-02 19:35:00 +11:00
Urgau eccc9e6628 [RFC 3127 - Trim Paths]: Condition remapped filepath on remap scopes 2023-10-17 10:11:30 +02:00
Ben Kimock 272cd384e8 Fall back to an unoptimized implementation in read_binary_file if File::metadata lies 2023-09-12 19:32:43 -04:00
John Kåre Alsaker f49382c050 Use Freeze for SourceFile.lines 2023-09-07 13:05:05 +02:00
John Kåre Alsaker c5996b80be Use Freeze for SourceFile.external_src 2023-09-07 13:04:23 +02:00
Camille GILLOT 3edeac06a5 Pass StableSourceFileId. 2023-09-04 16:02:46 +00:00
Camille GILLOT 4a87a44451 Compute address space from previous file. 2023-09-03 15:02:47 +00:00
Camille GILLOT 548ba13265 Register the file while computing its start position. 2023-09-03 15:02:46 +00:00
Camille GILLOT 258ace613d Use relative positions inside a SourceFile. 2023-09-03 12:56:10 +00:00
Ben Kimock f26293dca4 Load include_bytes! directly into an Lrc 2023-08-27 20:16:19 -04:00
yukang eb0fcc5ad1 refactor on span_look_ahead 2023-08-06 22:44:11 +08:00
Nicholas Nethercote 45fcd1d0c5 Use partition_point in SourceMap::lookup_source_file_idx.
This makes it (a) a little simpler, and (b) more similar to
`SourceFile::lookup_line`.
2023-06-29 11:36:09 +10:00
yukang e3071eaa60 reword the message to suggest surrounding with parentheses 2023-06-10 06:28:35 +08:00
yukang 3983881d4e take care module name for suggesting surround the struct literal in parentheses 2023-06-10 06:28:35 +08:00
Maybe Waffle fb0f74a8c9 Use Option::is_some_and and Result::is_ok_and in the compiler 2023-05-24 14:20:41 +00:00
Mara Bos 6289c57dc0 Simplify find_width_of_character_at_span. 2023-05-14 16:24:11 +02:00
SparrowLii 089a38880b correct literals for dyn thread safe 2023-05-06 09:34:53 +08:00