Skip to content

Commit 75ad441

Browse files
authored
Document speculative crate loading (rust-lang#859)
1 parent 677a95f commit 75ad441

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/name-resolution.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,23 @@ the code can be processed.
145145

146146
Therefore, the resolution is performed in multiple stages.
147147

148+
## Speculative crate loading
149+
150+
To give useful errors, rustc suggests importing paths into scope if they're
151+
not found. How does it do this? It looks through every module of every crate
152+
and looks for possible matches. This even includes crates that haven't yet
153+
been loaded!
154+
155+
Loading crates for import suggestions that haven't yet been loaded is called
156+
_speculative crate loading_, because any errors it encounters shouldn't be
157+
reported: resolve decided to load them, not the user. The function that does
158+
this is `lookup_import_candidates` and lives in
159+
`rustc_resolve/src/diagnostics.rs`.
160+
161+
To tell the difference between speculative loads and loads initiated by the
162+
user, resolve passes around a `record_used` parameter, which is `false` when
163+
the load is speculative.
164+
148165
## TODO:
149166

150167
This is a result of the first pass of learning the code. It is definitely

0 commit comments

Comments
 (0)