about summary refs log tree commit diff
path: root/compiler/rustc_interface/src/interface.rs
AgeCommit message (Collapse)AuthorLines
2022-03-03Add support for values() with --check-cfgLoïc BRANSTETT-0/+3
2022-03-02rename ErrorReported -> ErrorGuaranteedmark-2/+2
2022-02-25Auto merge of #93368 - eddyb:diagbld-guarantee, r=estebankbors-4/+4
rustc_errors: let `DiagnosticBuilder::emit` return a "guarantee of emission". That is, `DiagnosticBuilder` is now generic over the return type of `.emit()`, so we'll now have: * `DiagnosticBuilder<ErrorReported>` for error (incl. fatal/bug) diagnostics * can only be created via a `const L: Level`-generic constructor, that limits allowed variants via a `where` clause, so not even `rustc_errors` can accidentally bypass this limitation * asserts `diagnostic.is_error()` on emission, just in case the construction restriction was bypassed (e.g. by replacing the whole `Diagnostic` inside `DiagnosticBuilder`) * `.emit()` returns `ErrorReported`, as a "proof" token that `.emit()` was called (though note that this isn't a real guarantee until after completing the work on #69426) * `DiagnosticBuilder<()>` for everything else (warnings, notes, etc.) * can also be obtained from other `DiagnosticBuilder`s by calling `.forget_guarantee()` This PR is a companion to other ongoing work, namely: * #69426 and it's ongoing implementation: #93222 the API changes in this PR are needed to get statically-checked "only errors produce `ErrorReported` from `.emit()`", but doesn't itself provide any really strong guarantees without those other `ErrorReported` changes * #93244 would make the choices of API changes (esp. naming) in this PR fit better overall In order to be able to let `.emit()` return anything trustable, several changes had to be made: * `Diagnostic`'s `level` field is now private to `rustc_errors`, to disallow arbitrary "downgrade"s from "some kind of error" to "warning" (or anything else that doesn't cause compilation to fail) * it's still possible to replace the whole `Diagnostic` inside the `DiagnosticBuilder`, sadly, that's harder to fix, but it's unlikely enough that we can paper over it with asserts on `.emit()` * `.cancel()` now consumes `DiagnosticBuilder`, preventing `.emit()` calls on a cancelled diagnostic * it's also now done internally, through `DiagnosticBuilder`-private state, instead of having a `Level::Cancelled` variant that can be read (or worse, written) by the user * this removes a hazard of calling `.cancel()` on an error then continuing to attach details to it, and even expect to be able to `.emit()` it * warnings were switched to *only* `can_emit_warnings` on emission (instead of pre-cancelling early) * `struct_dummy` was removed (as it relied on a pre-`Cancelled` `Diagnostic`) * since `.emit()` doesn't consume the `DiagnosticBuilder` <sub>(I tried and gave up, it's much more work than this PR)</sub>, we have to make `.emit()` idempotent wrt the guarantees it returns * thankfully, `err.emit(); err.emit();` can return `ErrorReported` both times, as the second `.emit()` call has no side-effects *only* because the first one did do the appropriate emission * `&mut Diagnostic` is now used in a lot of function signatures, which used to take `&mut DiagnosticBuilder` (in the interest of not having to make those functions generic) * the APIs were already mostly identical, allowing for low-effort porting to this new setup * only some of the suggestion methods needed some rework, to have the extra `DiagnosticBuilder` functionality on the `Diagnostic` methods themselves (that change is also present in #93259) * `.emit()`/`.cancel()` aren't available, but IMO calling them from an "error decorator/annotator" function isn't a good practice, and can lead to strange behavior (from the caller's perspective) * `.downgrade_to_delayed_bug()` was added, letting you convert any `.is_error()` diagnostic into a `delay_span_bug` one (which works because in both cases the guarantees available are the same) This PR should ideally be reviewed commit-by-commit, since there is a lot of fallout in each. r? `@estebank` cc `@Manishearth` `@nikomatsakis` `@mark-i-m`
2022-02-23Continue improvements on the --check-cfg implementationLoïc BRANSTETT-9/+5
- Test the combinations of --check-cfg with partial values() and --cfg - Test that we detect unexpected value when none are expected
2022-02-23rustc_errors: take `self` by value in `DiagnosticBuilder::cancel`.Eduard-Mihai Burtescu-4/+4
2022-02-22Improve CheckCfg internal representationLoïc BRANSTETT-6/+16
2022-02-18Rollup merge of #93915 - Urgau:rfc-3013, r=petrochenkovMatthias Krüger-2/+89
Implement --check-cfg option (RFC 3013), take 2 This pull-request implement RFC 3013: Checking conditional compilation at compile time (https://github.com/rust-lang/rfcs/pull/3013) and is based on the previous attempt https://github.com/rust-lang/rust/pull/89346 by `@mwkmwkmwk` that was closed due to inactivity. I have address all the review comments from the previous attempt and added some more tests. cc https://github.com/rust-lang/rust/issues/82450 r? `@petrochenkov`
2022-02-16Implement --check-cfg option (RFC 3013)Loïc BRANSTETT-2/+89
Co-authored-by: Urgau <lolo.branstett@numericable.fr> Co-authored-by: Marcelina Kościelnicka <mwk@0x04.net>
2022-02-13Remove Config::stderrbjorn3-7/+1
1. It captured stdout and not stderr 2. It isn't used anywhere 3. All error messages should go to the DiagnosticOutput instead 4. It modifies thread local state
2022-02-12Move setup_callbacks call to create_compiler_and_runbjorn3-1/+3
This ensures that it is called even when run_in_thread_pool_with_globals is avoided and reduces code duplication between the parallel and non-parallel version of run_in_thread_pool_with_globals
2022-02-03clippy::perf fixesMatthias Krüger-1/+1
single_char_pattern and to_string_in_format_args
2022-01-16Limit scope of the hint about escaping.Ivor Wanders-4/+10
2022-01-12Improve error message for cfg arguments.Ivor Wanders-1/+4
This provides the user with a helpful error message in case a key="value" message was specified but couldn't be parsed.
2022-01-01Emit an error for `--cfg=)`Jakub Kądziołka-19/+19
Fixes #73026 See also: #64467, #89468 The issue stems from a `FatalError` being silently raised in `panictry_buffer`. Normally this is not a problem, because `panictry_buffer` emits the causes of the error, but they are not themselves fatal, so they get filtered out by the silent emitter. To fix this, we use a parser entrypoint which doesn't use `panictry_buffer`, and we handle the error ourselves.
2021-11-07Made temps-dir an unstable option.Tor Hovland-2/+3
2021-11-02Added the --temps-dir option.Tor Hovland-1/+14
2021-10-25Avoid a branch on key being local for queries that use the same local and ↵bjorn3-2/+2
extern providers
2021-10-23Rollup merge of #89468 - FabianWolff:issue-89358, r=jackh726Matthias Krüger-1/+4
Report fatal lexer errors in `--cfg` command line arguments Fixes #89358. The erroneous behavior was apparently introduced by `@Mark-Simulacrum` in https://github.com/rust-lang/rust/commit/a678e3191197f145451c97c6cc884e15cae38186; the idea is to silence individual parser errors and instead emit one catch-all error message after parsing. However, for the example in #89358, a fatal lexer error is created here: https://github.com/rust-lang/rust/blob/edebf77e0090195bf80c0d8cda821e1bf9d03053/compiler/rustc_parse/src/lexer/mod.rs#L340-L349 This fatal error aborts the compilation, and so the call to `new_parser_from_source_str()` never returns and the catch-all error message is never emitted. I have therefore changed the `SilentEmitter` to silence only non-fatal errors; with my changes, for the rustc invocation described in #89358: ```sh rustc --cfg "abc\"" ``` I get the following output: ``` error[E0765]: unterminated double quote string | = note: this error occurred on the command line: `--cfg=abc"` ```
2021-10-02Report fatal lexer errors in `--cfg` command line argumentsFabian Wolff-1/+4
2021-10-01Fix clippy lintsGuillaume Gomez-7/+1
2021-07-18Move OnDiskCache to rustc_query_impl.Camille GILLOT-1/+2
2021-07-08Rework SESSION_GLOBALS API to prevent overwriting itGuillaume Gomez-1/+1
2021-03-15Change the `.unwrap` to `.expect` with a helpful messagehyd-dev-1/+5
2021-03-15Add `rustc_interface::interface::Config::parse_sess_created`hyd-dev-1/+8
2021-02-19Move try_print_query_stack to rustc_interface.Camille GILLOT-1/+22
2020-12-22Add some intra-doc links to compiler docsJoshua Nelson-1/+2
2020-12-01Fix `unknown-crate` when using self-profile with rustdocJoshua Nelson-3/+0
... by removing a duplicate `crate_name` field in `interface::Config`, making it clear that rustdoc should be passing it to `config::Options` instead.
2020-11-24Add method to get the register_lints function from the compilerflip1995-0/+3
2020-09-27Add option to pass a custom codegen backend from a driverbjorn3-0/+5
2020-08-30mv compiler to compiler/mark-0/+209