summary refs log tree commit diff
path: root/compiler/rustc_session/src/errors.rs
AgeCommit message (Collapse)AuthorLines
2024-01-29Stop using `String` for error codes.Nicholas Nethercote-4/+2
Error codes are integers, but `String` is used everywhere to represent them. Gross! This commit introduces `ErrCode`, an integral newtype for error codes, replacing `String`. It also introduces a constant for every error code, e.g. `E0123`, and removes the `error_code!` macro. The constants are imported wherever used with `use rustc_errors::codes::*`. With the old code, we have three different ways to specify an error code at a use point: ``` error_code!(E0123) // macro call struct_span_code_err!(dcx, span, E0123, "msg"); // bare ident arg to macro call \#[diag(name, code = "E0123")] // string struct Diag; ``` With the new code, they all use the `E0123` constant. ``` E0123 // constant struct_span_code_err!(dcx, span, E0123, "msg"); // constant \#[diag(name, code = E0123)] // constant struct Diag; ``` The commit also changes the structure of the error code definitions: - `rustc_error_codes` now just defines a higher-order macro listing the used error codes and nothing else. - Because that's now the only thing in the `rustc_error_codes` crate, I moved it into the `lib.rs` file and removed the `error_codes.rs` file. - `rustc_errors` uses that macro to define everything, e.g. the error code constants and the `DIAGNOSTIC_TABLES`. This is in its new `codes.rs` file.
2024-01-18Rollup merge of #119172 - nnethercote:earlier-NulInCStr, r=petrochenkovMatthias Krüger-14/+1
Detect `NulInCStr` error earlier. By making it an `EscapeError` instead of a `LitError`. This makes it like the other errors produced when checking string literals contents, e.g. for invalid escape sequences or bare CR chars. NOTE: this means these errors are issued earlier, before expansion, which changes behaviour. It will be possible to move the check back to the later point if desired. If that happens, it's likely that all the string literal contents checks will be delayed together. One nice thing about this: the old approach had some code in `report_lit_error` to calculate the span of the nul char from a range. This code used a hardwired `+2` to account for the `c"` at the start of a C string literal, but this should have changed to a `+3` for raw C string literals to account for the `cr"`, which meant that the caret in `cr"` nul error messages was one short of where it should have been. The new approach doesn't need any of this and avoids the off-by-one error. r? ```@fee1-dead```
2024-01-13Add check for ui_testing via promoting parameters from `ParseSess` to `Session`George-lewis-6/+9
2024-01-13Add suggestion to upgrade the compilerGeorge-lewis-0/+16
2024-01-12Detect `NulInCStr` error earlier.Nicholas Nethercote-14/+1
By making it an `EscapeError` instead of a `LitError`. This makes it like the other errors produced when checking string literals contents, e.g. for invalid escape sequences or bare CR chars. NOTE: this means these errors are issued earlier, before expansion, which changes behaviour. It will be possible to move the check back to the later point if desired. If that happens, it's likely that all the string literal contents checks will be delayed together. One nice thing about this: the old approach had some code in `report_lit_error` to calculate the span of the nul char from a range. This code used a hardwired `+2` to account for the `c"` at the start of a C string literal, but this should have changed to a `+3` for raw C string literals to account for the `cr"`, which meant that the caret in `cr"` nul error messages was one short of where it should have been. The new approach doesn't need any of this and avoids the off-by-one error.
2024-01-10Rename consuming chaining methods on `DiagnosticBuilder`.Nicholas Nethercote-2/+2
In #119606 I added them and used a `_mv` suffix, but that wasn't great. A `with_` prefix has three different existing uses. - Constructors, e.g. `Vec::with_capacity`. - Wrappers that provide an environment to execute some code, e.g. `with_session_globals`. - Consuming chaining methods, e.g. `Span::with_{lo,hi,ctxt}`. The third case is exactly what we want, so this commit changes `DiagnosticBuilder::foo_mv` to `DiagnosticBuilder::with_foo`. Thanks to @compiler-errors for the suggestion.
2024-01-08Use chaining in `DiagnosticBuilder` construction.Nicholas Nethercote-4/+3
To avoid the use of a mutable local variable, and because it reads more nicely.
2024-01-03Rename some `Diagnostic` setters.Nicholas Nethercote-1/+1
`Diagnostic` has 40 methods that return `&mut Self` and could be considered setters. Four of them have a `set_` prefix. This doesn't seem necessary for a type that implements the builder pattern. This commit removes the `set_` prefixes on those four methods.
2023-12-24Remove `ParseSess` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-11/+12
Also add missing `#[track_caller]` attributes to `DiagCtxt` methods as necessary to keep tests working.
2023-12-23Give `DiagnosticBuilder` a default type.Nicholas Nethercote-7/+2
`IntoDiagnostic` defaults to `ErrorGuaranteed`, because errors are the most common diagnostic level. It makes sense to do likewise for the closely-related (and much more widely used) `DiagnosticBuilder` type, letting us write `DiagnosticBuilder<'a, ErrorGuaranteed>` as just `DiagnosticBuilder<'a>`. This cuts over 200 lines of code due to many multi-line things becoming single line things.
2023-12-19Add `level` arg to `into_diagnostic`.Nicholas Nethercote-4/+8
And make all hand-written `IntoDiagnostic` impls generic, by using `DiagnosticBuilder::new(dcx, level, ...)` instead of e.g. `dcx.struct_err(...)`. This means the `create_*` functions are the source of the error level. This change will let us remove `struct_diagnostic`. Note: `#[rustc_lint_diagnostics]` is added to `DiagnosticBuilder::new`, it's necessary to pass diagnostics tests now that it's used in `into_diagnostic` functions.
2023-12-18Rename many `DiagCtxt` arguments.Nicholas Nethercote-2/+2
2023-12-18Rename `Handler` as `DiagCtxt`.Nicholas Nethercote-1/+1
2023-12-14Avoid `struct_diagnostic` where possible.Nicholas Nethercote-1/+1
It's necessary for `derive(Diagnostic)`, but is best avoided elsewhere because there are clearer alternatives. This required adding `Handler::struct_almost_fatal`.
2023-12-07Auto merge of #118635 - nnethercote:fewer-early-errors, r=davidtwcobors-0/+6
Fewer early errors r? `@davidtwco`
2023-12-06Fewer early errors.Nicholas Nethercote-0/+6
`build_session` is passed an `EarlyErrorHandler` and then constructs a `Handler`. But the `EarlyErrorHandler` is still used for some time after that. This commit changes `build_session` so it consumes the passed `EarlyErrorHandler`, and also drops it as soon as the `Handler` is built. As a result, `parse_cfg` and `parse_check_cfg` now take a `Handler` instead of an `EarlyErrorHandler`.
2023-12-04De-genericize some `IntoDiagnostic` impls.Nicholas Nethercote-3/+3
These impls are all needed for just a single `IntoDiagnostic` type, not a family of them. Note that `ErrorGuaranteed` is the default type parameter for `IntoDiagnostic`.
2023-12-04Always use `G` for `EmissionGuarantee` type variables.Nicholas Nethercote-2/+2
That's what is mostly used. This commit changes a few `EM` and `E` and `T` type variables to `G`.
2023-11-30Add `-Zfunction-return={keep,thunk-extern}` optionMiguel Ojeda-0/+8
This is intended to be used for Linux kernel RETHUNK builds. With this commit (optionally backported to Rust 1.73.0), plus a patched Linux kernel to pass the flag, I get a RETHUNK build with Rust enabled that is `objtool`-warning-free and is able to boot in QEMU and load a sample Rust kernel module. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2023-10-09Remove cgu_reuse_tracker from Sessionbjorn3-19/+0
This removes a bit of global mutable state
2023-08-22unknown unstable lint command linemojave2-0/+6
fix ##113702 fix #113702 unknown unstable lint command lint improve impelementation
2023-08-08Rollup merge of #113593 - rcvalle:rust-cfi-fix-90546, r=wesleywiserMatthias Krüger-0/+4
CFI: Fix error compiling core with LLVM CFI enabled Fix #90546 by filtering out global value function pointer types from the type tests, and adding the LowerTypeTests pass to the rustc LTO optimization pipelines.
2023-08-07CFI: Fix error compiling core with LLVM CFI enabledRamon de C Valle-0/+4
Fix #90546 by filtering out global value function pointer types from the type tests, and adding the LowerTypeTests pass to the rustc LTO optimization pipelines.
2023-07-26Add help for crate arg when crate name is invalidyukang-0/+8
2023-07-20Move OutFileName writing into rustc_sessionDavid Tolnay-0/+7
2023-05-29linker: Report linker flavors incompatible with the current targetVadim Petrochenkov-0/+8
Previously they would be reported as link time errors about unknown linker options
2023-05-05Rollup merge of #108801 - fee1-dead-contrib:c-str, r=compiler-errorsDylan DPC-1/+14
Implement RFC 3348, `c"foo"` literals RFC: https://github.com/rust-lang/rfcs/pull/3348 Tracking issue: #105723
2023-05-03Add cross-language LLVM CFI support to the Rust compilerRamon de C Valle-2/+18
This commit adds cross-language LLVM Control Flow Integrity (CFI) support to the Rust compiler by adding the `-Zsanitizer-cfi-normalize-integers` option to be used with Clang `-fsanitize-cfi-icall-normalize-integers` for normalizing integer types (see https://reviews.llvm.org/D139395). It provides forward-edge control flow protection for C or C++ and Rust -compiled code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code share the same virtual address space). For more information about LLVM CFI and cross-language LLVM CFI support for the Rust compiler, see design document in the tracking issue #89653. Cross-language LLVM CFI can be enabled with -Zsanitizer=cfi and -Zsanitizer-cfi-normalize-integers, and requires proper (i.e., non-rustc) LTO (i.e., -Clinker-plugin-lto).
2023-05-02make it semantic errorDeadbeef-1/+14
2023-02-17Rollup merge of #107489 - compiler-errors:non_lifetime_binders, r=cjgillotMatthias Krüger-6/+16
Implement partial support for non-lifetime binders This implements support for non-lifetime binders. It's pretty useless currently, but I wanted to put this up so the implementation can be discussed. Specifically, this piggybacks off of the late-bound lifetime collection code in `rustc_hir_typeck::collect::lifetimes`. This seems like a necessary step given the fact we don't resolve late-bound regions until this point, and binders are sometimes merged. Q: I'm not sure if I should go along this route, or try to modify the earlier nameres code to compute the right bound var indices for type and const binders eagerly... If so, I'll need to rename all these queries to something more appropriate (I've done this for `resolve_lifetime::Region` -> `resolve_lifetime::ResolvedArg`) cc rust-lang/types-team#81 r? `@ghost`
2023-02-16`if $c:expr { Some($r:expr) } else { None }` =>> `$c.then(|| $r)`Maybe Waffle-5/+1
2023-02-16Add feature gate for non_lifetime_bindersMichael Goulet-6/+16
2023-02-09Emit an error if -Z instrument-xray is not supportedOleksii Lozovskyi-0/+6
This is somewhat important because LLVM enables the pass based on target architecture, but support by the target OS also matters. For example, XRay attributes are processed by codegen for macOS targets, but Apple linker fails to process relocations in XRay data sections, so the feature as a whole is not supported there for the time being.
2023-01-30session: diagnostic migration lint on more fnsDavid Wood-0/+6
Apply the diagnostic migration lint to more functions on `Session`. Signed-off-by: David Wood <david.wood@huawei.com>
2023-01-02Print correct base for too-large literalsclubby789-2/+10
Also update tests
2023-01-02Note maximum integer literal for `IntLiteralTooLarge`clubby789-0/+1
2022-12-17Auto merge of #105421 - jacobbramley:jb/branch-prot-check, r=nagisabors-0/+4
Check AArch64 branch-protection earlier in the pipeline. As suggested in #93516. r? `@nagisa`
2022-12-14Auto merge of #105233 - mejrs:always_eager, r=estebankbors-1/+1
Always evaluate vecs of subdiagnostics eagerly See https://rust-lang.zulipchat.com/#narrow/stream/336883-i18n/topic/.23100717.20lists!/near/310186705 for context
2022-12-14Rollup merge of #105161 - cassaundra:numeric-literal-error, r=nnethercoteMatthias Krüger-10/+23
Refine when invalid prefix case error arises Fix cases where the "invalid base prefix for number literal" error arises with suffixes that look erroneously capitalized but which are actually invalid.
2022-12-12Refine when invalid prefix case error arisesCassaundra Smith-10/+23
Fix cases where the "invalid base prefix for number literal" error arises with suffixes that look erroneously capitalized but which are in fact invalid.
2022-12-07Use `Symbol` for the crate name instead of `String`/`str`Oli Scherer-4/+4
2022-12-06Check AArch64 branch-protection earlier in the pipeline.Jacob Bramley-0/+4
As suggested in #93516.
2022-12-04Always evaluate vecs of subdiagnostics eagerlymejrs-1/+1
2022-12-03Rollup merge of #105050 - WaffleLapkin:uselessrefign, r=jyn514Matthias Krüger-1/+1
Remove useless borrows and derefs They are nothing more than noise. <sub>These are not all of them, but my clippy started crashing (stack overflow), so rip :(</sub>
2022-12-01Remove useless borrows and derefsMaybe Waffle-1/+1
2022-11-30avoid an unnecessary `&str` to `String` conversionTakayuki Maeda-7/+3
2022-11-21Match crate and slug namesmejrs-13/+13
2022-11-16Use `token::Lit` in `ast::ExprKind::Lit`.Nicholas Nethercote-0/+162
Instead of `ast::Lit`. Literal lowering now happens at two different times. Expression literals are lowered when HIR is crated. Attribute literals are lowered during parsing. This commit changes the language very slightly. Some programs that used to not compile now will compile. This is because some invalid literals that are removed by `cfg` or attribute macros will no longer trigger errors. See this comment for more details: https://github.com/rust-lang/rust/pull/102944#issuecomment-1277476773
2022-10-23Migrate all diagnosticsNilstrieb-28/+28
2022-10-17session: use derive moreDavid Wood-15/+26
Signed-off-by: David Wood <david.wood@huawei.com>