about summary refs log tree commit diff
path: root/compiler/rustc_passes
AgeCommit message (Collapse)AuthorLines
2024-01-29Make duplicate lang items fatalNilstrieb-1/+3
Prevents terminal spam.
2024-01-29Rollup merge of #120428 - petrochenkov:somehir2, r=compiler-errorsDylan DPC-5/+0
hir: Two preparatory changes for #120206 cc https://github.com/rust-lang/rust/pull/120206 r? ```@compiler-errors```
2024-01-29Supress unhelpful diagnostics for unresolved top level attributesyukang-1/+11
2024-01-29Stop using `String` for error codes.Nicholas Nethercote-50/+50
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-28hir: Remove unnecessary `HirId` from `hir::Let`Vadim Petrochenkov-5/+0
It has 1-to-1 correspondence to its expression id. Also remove mostly useless `visit_let_expr`.
2024-01-25Rebase slice_group_by stabilization PRDavid Tolnay-2/+1
2024-01-19Rollup merge of #120107 - shepmaster:dead-code-repr-transparent, r=NilstriebMatthias Krüger-8/+10
dead_code treats #[repr(transparent)] the same as #[repr(C)] In #92972 we enabled linting on unused fields in tuple structs. In #118297 that lint was enabled by default. That exposed issues like #119659, where the fields of a struct marked `#[repr(transparent)]` were reported by the `dead_code` lint. The language team [decided](https://github.com/rust-lang/rust/issues/119659#issuecomment-1885172045) that the lint should treat `repr(transparent)` the same as `#[repr(C)]`. Fixes #119659
2024-01-18`dead_code` treats `#[repr(transparent)]` the same as `#[repr(C)]`Jake Goulding-8/+10
Fixes #119659
2024-01-18Rollup merge of #119967 - ShE3py:patkind-err, r=WaffleLapkinMatthias Krüger-2/+4
Add `PatKind::Err` to AST/HIR #116715 added `thir::PatKind::Error`; this PR adds `hir::PatKind::Err` and `ast::PatKind::Err` (see https://github.com/rust-lang/rust/pull/118625#discussion_r1446587901.) --- ``@rustbot`` label +A-patterns r? WaffleLapkin
2024-01-17Rollup merge of #120020 - oli-obk:long_const_eval_err_taint, r=compiler-errorsMatthias Krüger-1/+4
Gracefully handle missing typeck information if typeck errored fixes #116893 I created some logs and the typeck of `fn main` is exactly the same, no matter whether the constant's body is what it is, or if it is replaced with `panic!()`. The latter will cause the ICE not to be emitted though. The reason for that is that we abort compilation if *errors* were emitted, but not if *lint errors* were emitted. This took me way too long to debug, and is another reason why I would have liked https://github.com/rust-lang/compiler-team/issues/633
2024-01-17Add `PatKind::Err`Lieselotte-2/+4
2024-01-16Skip dead code checks on items that failed typeckOli Scherer-1/+4
2024-01-14Rework how diagnostic lints are stored.Nicholas Nethercote-2/+2
`Diagnostic::code` has the type `DiagnosticId`, which has `Error` and `Lint` variants. Plus `Diagnostic::is_lint` is a bool, which should be redundant w.r.t. `Diagnostic::code`. Seems simple. Except it's possible for a lint to have an error code, in which case its `code` field is recorded as `Error`, and `is_lint` is required to indicate that it's a lint. This is what happens with `derive(LintDiagnostic)` lints. Which means those lints don't have a lint name or a `has_future_breakage` field because those are stored in the `DiagnosticId::Lint`. It's all a bit messy and confused and seems unintentional. This commit: - removes `DiagnosticId`; - changes `Diagnostic::code` to `Option<String>`, which means both errors and lints can straightforwardly have an error code; - changes `Diagnostic::is_lint` to `Option<IsLint>`, where `IsLint` is a new type containing a lint name and a `has_future_breakage` bool, so all lints can have those, error code or not.
2024-01-13Add check for ui_testing via promoting parameters from `ParseSess` to `Session`George-lewis-12/+11
2024-01-12Delegation implementation: step 1Bryanskiy-21/+28
2024-01-10Stop mentioning internal lang items in no_std binary errorsNilstrieb-1/+16
When writing a no_std binary, you'll be greeted with nonsensical errors mentioning lang items like eh_personality and start. That's pretty bad because it makes you think that you need to define them somewhere! But oh no, now you're getting the `internal_features` lint telling you that you shouldn't use them! But you need a no_std binary! What now? No problem! Writing a no_std binary is super easy. Just use panic=abort and supply your own platform specific entrypoint symbol (like `main`) and you're good to go. Would be nice if the compiler told you that, right? This makes it so that it does do that.
2024-01-10Add `DiagCtxt::delayed_bug`.Nicholas Nethercote-3/+2
We have `span_delayed_bug` and often pass it a `DUMMY_SP`. This commit adds `delayed_bug`, which matches pairs like `err`/`span_err` and `warn`/`span_warn`.
2024-01-10Rename `{create,emit}_warning` as `{create,emit}_warn`.Nicholas Nethercote-1/+1
For consistency with `warn`/`struct_warn`, and also `{create,emit}_err`, all of which use an abbreviated form.
2024-01-08Remove `DiagnosticBuilder::delay_as_bug_without_consuming`.Nicholas Nethercote-1/+1
The existing uses are replaced in one of three ways. - In a function that also has calls to `emit`, just rearrange the code so that exactly one of `delay_as_bug` or `emit` is called on every path. - In a function returning a `DiagnosticBuilder`, use `downgrade_to_delayed_bug`. That's good enough because it will get emitted later anyway. - In `unclosed_delim_err`, one set of errors is being replaced with another set, so just cancel the original errors.
2024-01-08Make `DiagnosticBuilder::emit` consuming.Nicholas Nethercote-2/+2
This works for most of its call sites. This is nice, because `emit` very much makes sense as a consuming operation -- indeed, `DiagnosticBuilderState` exists to ensure no diagnostic is emitted twice, but it uses runtime checks. For the small number of call sites where a consuming emit doesn't work, the commit adds `DiagnosticBuilder::emit_without_consuming`. (This will be removed in subsequent commits.) Likewise, `emit_unless` becomes consuming. And `delay_as_bug` becomes consuming, while `delay_as_bug_without_consuming` is added (which will also be removed in subsequent commits.) All this requires significant changes to `DiagnosticBuilder`'s chaining methods. Currently `DiagnosticBuilder` method chaining uses a non-consuming `&mut self -> &mut Self` style, which allows chaining to be used when the chain ends in `emit()`, like so: ``` struct_err(msg).span(span).emit(); ``` But it doesn't work when producing a `DiagnosticBuilder` value, requiring this: ``` let mut err = self.struct_err(msg); err.span(span); err ``` This style of chaining won't work with consuming `emit` though. For that, we need to use to a `self -> Self` style. That also would allow `DiagnosticBuilder` production to be chained, e.g.: ``` self.struct_err(msg).span(span) ``` However, removing the `&mut self -> &mut Self` style would require that individual modifications of a `DiagnosticBuilder` go from this: ``` err.span(span); ``` to this: ``` err = err.span(span); ``` There are *many* such places. I have a high tolerance for tedious refactorings, but even I gave up after a long time trying to convert them all. Instead, this commit has it both ways: the existing `&mut self -> Self` chaining methods are kept, and new `self -> Self` chaining methods are added, all of which have a `_mv` suffix (short for "move"). Changes to the existing `forward!` macro lets this happen with very little additional boilerplate code. I chose to add the suffix to the new chaining methods rather than the existing ones, because the number of changes required is much smaller that way. This doubled chainging is a bit clumsy, but I think it is worthwhile because it allows a *lot* of good things to subsequently happen. In this commit, there are many `mut` qualifiers removed in places where diagnostics are emitted without being modified. In subsequent commits: - chaining can be used more, making the code more concise; - more use of chaining also permits the removal of redundant diagnostic APIs like `struct_err_with_code`, which can be replaced easily with `struct_err` + `code_mv`; - `emit_without_diagnostic` can be removed, which simplifies a lot of machinery, removing the need for `DiagnosticBuilderState`.
2024-01-06Auto merge of #119531 - petrochenkov:cmpctxt, r=cjgillotbors-1/+1
rustc_span: Optimize syntax context comparisons Including comparisons with root context. - `eq_ctxt` doesn't require retrieving full `SpanData`, or taking the span interner lock twice. - Checking `SyntaxContext` for "rootness" is cheaper than extracting a full outer `ExpnData` for it and checking *it* for rootness. The internal lint for `eq_ctxt` is also tweaked to detect `a.ctxt() != b.ctxt()` in addition to `a.ctxt() == b.ctxt()`.
2024-01-06rustc_span: Optimize syntax context comparisonsVadim Petrochenkov-1/+1
Including comparisons with root context
2024-01-05Auto merge of #119634 - matthiaskrgr:rollup-v2xt7et, r=matthiaskrgrbors-15/+6
Rollup of 8 pull requests Successful merges: - #119151 (Hide foreign `#[doc(hidden)]` paths in import suggestions) - #119350 (Imply outlives-bounds on lazy type aliases) - #119354 (Make `negative_bounds` internal & fix some of its issues) - #119506 (Use `resolutions(()).effective_visiblities` to avoid cycle errors in `report_object_error`) - #119554 (Fix scoping for let chains in match guards) - #119563 (Check yield terminator's resume type in borrowck) - #119589 (cstore: Remove unnecessary locking from `CrateMetadata`) - #119622 (never patterns: Document behavior of never patterns with macros-by-example) r? `@ghost` `@rustbot` modify labels: rollup
2024-01-05Rollup merge of #119554 - matthewjasper:remove-guard-distinction, ↵Matthias Krüger-15/+6
r=compiler-errors Fix scoping for let chains in match guards If let guards were previously represented as a different type of guard in HIR and THIR. This meant that let chains in match guards were not handled correctly because they were treated exactly like normal guards. - Remove `hir::Guard` and `thir::Guard`. - Make the scoping different between normal guards and if let guards also check for let chains. closes #118593
2024-01-05Auto merge of #119192 - michaelwoerister:mcp533-push, r=cjgillotbors-10/+9
Replace a number of FxHashMaps/Sets with stable-iteration-order alternatives This PR replaces almost all of the remaining `FxHashMap`s in query results with either `FxIndexMap` or `UnordMap`. The only case that is missing is the `EffectiveVisibilities` struct which turned out to not be straightforward to transform. Once that is done too, we can remove the `HashStable` implementation from `HashMap`. The first commit adds the `StableCompare` trait which is a companion trait to `StableOrd`. Some types like `Symbol` can be compared in a cross-session stable way, but their `Ord` implementation is not stable. In such cases, a `StableCompare` implementation can be provided to offer a lightweight way for stable sorting. The more heavyweight option is to sort via `ToStableHashKey`, but then sorting needs to have access to a stable hashing context and `ToStableHashKey` can also be expensive as in the case of `Symbol` where it has to allocate a `String`. The rest of the commits are rather mechanical and don't overlap, so they are best reviewed individually. Part of [MCP 533](https://github.com/rust-lang/compiler-team/issues/533).
2024-01-05Rollup merge of #119538 - nnethercote:cleanup-errors-5, r=compiler-errorsMichael Goulet-22/+22
Cleanup error handlers: round 5 More rustc_errors cleanups. A sequel to https://github.com/rust-lang/rust/pull/119171. r? ````@compiler-errors````
2024-01-05Remove `hir::Guard`Matthew Jasper-15/+6
Use Expr instead. Use `ExprKind::Let` to represent if let guards.
2024-01-05Auto merge of #118297 - shepmaster:warn-dead-tuple-fields, r=WaffleLapkinbors-23/+35
Merge `unused_tuple_struct_fields` into `dead_code` This implicitly upgrades the lint from `allow` to `warn` and places it into the `unused` lint group. [Discussion on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Moving.20.60unused_tuple_struct_fields.60.20from.20allow.20to.20warn)
2024-01-04Address review comments and add back some #[inline] attrs from removed commits.Michael Woerister-2/+0
2024-01-04Replace a number of FxHashMaps/Sets with stable-iteration-order alternatives.Michael Woerister-8/+9
2024-01-03Rename some `Diagnostic` setters.Nicholas Nethercote-22/+22
`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.
2024-01-02Merge `unused_tuple_struct_fields` into `dead_code`Jake Goulding-23/+35
This implicitly upgrades the lint from `allow` to `warn` and places it into the `unused` lint group.
2023-12-30is_coroutine -> is_coroutine_or_closureMichael Goulet-1/+1
2023-12-29Rollup merge of #119402 - est31:fix_if_guard_unused, r=compiler-errorsMatthias Krüger-0/+3
Also walk bindings created by if-let guards This change makes the `unused_variables` lint pick up unused bindings created by if-let guards. Fixes #119383
2023-12-29Also walk bindings created by if-let guardsest31-0/+3
2023-12-28Use `Pat::walk_always` instead of manual walkNilstrieb-29/+6
2023-12-27move walk_expr outside of every match branchzetanumbers-8/+2
2023-12-26Rollup merge of #119297 - cjgillot:issue-119267, r=petrochenkovMichael Goulet-62/+46
Pass DeadItem and lint as consistent group in dead-code. Fixes https://github.com/rust-lang/rust/issues/119267
2023-12-26Auto merge of #119258 - compiler-errors:closure-kind, r=eholkbors-10/+9
Make closures carry their own ClosureKind Right now, we use the "`movability`" field of `hir::Closure` to distinguish a closure and a coroutine. This is paired together with the `CoroutineKind`, which is located not in the `hir::Closure`, but the `hir::Body`. This is strange and redundant. This PR introduces `ClosureKind` with two variants -- `Closure` and `Coroutine`, which is put into `hir::Closure`. The `CoroutineKind` is thus removed from `hir::Body`, and `Option<Movability>` no longer needs to be a stand-in for "is this a closure or a coroutine". r? eholk
2023-12-25Only regular coroutines have movabilityMichael Goulet-7/+4
2023-12-25Make closures carry their own ClosureKind, rather than deducing what it is ↵Michael Goulet-10/+12
from movability
2023-12-25Pass DeadItem and lint as consistent group in dead-code.Camille GILLOT-62/+46
2023-12-24Remove more `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-1/+1
2023-12-24Remove `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-153/+168
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access.
2023-12-22Auto merge of #119097 - nnethercote:fix-EmissionGuarantee, r=compiler-errorsbors-46/+28
Fix `EmissionGuarantee` There are some problems with the `DiagCtxt` API related to `EmissionGuarantee`. This PR fixes them. r? `@compiler-errors`
2023-12-19Add `level` arg to `into_diagnostic`.Nicholas Nethercote-46/+28
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-18Replace some instances of FxHashMap/FxHashSet with stable alternatives ↵Michael Woerister-3/+0
(mostly in rustc_hir and rustc_ast_lowering) Part of https://github.com/rust-lang/compiler-team/issues/533
2023-12-18Rename many `DiagCtxt` arguments.Nicholas Nethercote-10/+10
2023-12-18Rename `Handler` as `DiagCtxt`.Nicholas Nethercote-5/+5
2023-12-15Fix enforcement of generics for associated itemsMichael Goulet-19/+27