pub(crate) trait PopulateDefaultSymbols<'db> {
// Required method
fn populate_default_symbols(
&self,
db: &'db dyn Db,
scope: &Scope<'_, 'db>,
symbols: &mut SignatureSymbols<'db>,
);
}Expand description
In a few specific places, we add in default permissions. These are always an anonymous symbol, so they don’t impact name resolution (this is important to avoid cycles, see the note below).
This method pushes those default permissions, if any,
into symbols.
§Examples
- Given
class C { fn foo(self) }, theselfhas a default permission - Given
fn foo(x: String), the variablexhas a default permission
Default permissions are only needed for classes and when explicit permissions are not provided
- Given
struct C { fn foo(self) }, theselfdoes NOT have a default permission - Given
fn foo(x: u32), the variablexdoes NOT have a default permission - Given
fn foo(x: my String), the variablexdoes NOT have a default permission - Given
fn foo(x: type T), the variablexdoes NOT have a default permission
§Note on cycles
Given x: Foo, we need to determine if Foo is a struct or a class
to decide whether to give it a default symbol. This requires a name
resolution scope. But creating name resolution scopes required knowing
the symbols in scope, and default permissions would be in scope.
This is a “false cycle” because default permissions are anonymous.
Nonetheless, this is why we separate out populating default symbols
from the primary PopulateSignatureSymbols function.