feat(semantic): Warn when an extern type/function is declared outside the corelib.#10147
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
PR SummaryLow Risk Overview Test and fixture code that intentionally declares externs outside corelib is updated with that attribute, and allow-lint tests cover both the warning and suppression. Reviewed by Cursor Bugbot for commit 01c3432. Bugbot is set up for automated code reviews on this repo. Configure here. |
TomerStarkware
left a comment
There was a problem hiding this comment.
@TomerStarkware reviewed 78 files and all commit messages, and made 1 comment.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on eytan-starkware).
… the corelib. Adds the `extern_outside_corelib` warning (E2201), emitted on any `extern type` or `extern fn` declared outside the core crate. Silenceable per-item with `#[allow(extern_outside_corelib)]`; internal tests that declare externs are annotated accordingly.
f8af227 to
01c3432
Compare

Summary
Introduces a new
extern_outside_coreliblint (warningE2201) that fires whenextern fnorextern typeitems are declared outside the core library. The warning message reads: "Extern types and functions should only be declared in the core library." It can be suppressed with#[allow(extern_outside_corelib)].The lint is registered as a known
allow-able lint indeclared_allows, and the check is implemented inreport_extern_item_outside_corelib, which is called from bothextern_function.rsandextern_type.rsduring semantic analysis. The constantEXTERN_OUTSIDE_CORELIBis added tocairo-lang-syntax's attribute consts.All existing test fixtures that declare
extern fnorextern typeoutside the corelib have been updated with#[allow(extern_outside_corelib)]to suppress the new warning, and line numbers in expected diagnostics have been adjusted accordingly. New test cases indiagnostic_test_data/allowverify that the warning is emitted without the attribute and suppressed with it.Type of change
Please check one:
Why is this change needed?
Declaring
extern fnandextern typeoutside the core library is an advanced, low-level operation that bypasses Cairo's type system guarantees and directly names Sierra libfuncs. Allowing this silently in user code makes it easy to accidentally introduce unsound or non-portable declarations. The lint surfaces this as a warning so developers are aware of the risk, while still allowing it when explicitly opted in.What was the behavior or documentation before?
extern fnandextern typecould be declared anywhere without any diagnostic.What is the behavior or documentation after?
Declaring
extern fnorextern typeoutside the core library emits warningE2201. The warning is silenced by annotating the item with#[allow(extern_outside_corelib)].Related issue or discussion (if any)
Additional context
The error code
E2201is assigned to this diagnostic. The severity isWarning, consistent with other lint-style diagnostics such asunused_variablesandunused_imports.