about summary refs log tree commit diff
path: root/compiler/rustc_middle/src
AgeCommit message (Collapse)AuthorLines
2023-12-31Remove almost all uses of specialization from the metadata encoding codebjorn3-93/+65
2023-12-31Avoid specialization for the Span Encodable and Decodable implsbjorn3-32/+33
2023-12-31rustc_lint: Make `LintLevelsProvider::current_specs()` return `&FxIndexMap`Martin Nordholts-2/+2
So that lint iteration order becomes predicitable. Discovered with `rustc::potential_query_instability`.
2023-12-31Auto merge of #119447 - Nilstrieb:STACKOVERFLOW, r=compiler-errorsbors-1/+2
Fix `<BoundConstness as Display>` There was infinite recursion, which is not very good. I'm not sure what the best way to implement this is, I just did something that felt right. r? `@fmease`
2023-12-31Inline utils.Camille GILLOT-0/+19
2023-12-31Inline successor_within_block.Camille GILLOT-0/+1
2023-12-31Inline dominator check.Camille GILLOT-0/+2
2023-12-30Update to bitflags 2 in the compilerNilstrieb-6/+12
This involves lots of breaking changes. There are two big changes that force changes. The first is that the bitflag types now don't automatically implement normal derive traits, so we need to derive them manually. Additionally, bitflags now have a hidden inner type by default, which breaks our custom derives. The bitflags docs recommend using the impl form in these cases, which I did.
2023-12-30Use the right type for upvarsMichael Goulet-6/+4
2023-12-30Fix `<BoundConstness as Display>`Nilstrieb-1/+2
There was infinite recursion, which is not very good. I'm not sure what the best way to implement this is, I just did something that felt right.
2023-12-30is_coroutine -> is_coroutine_or_closureMichael Goulet-7/+10
2023-12-29Auto merge of #119392 - compiler-errors:args-parts, r=Nilstriebbors-58/+48
make `ClosureArgsParts` and `CoroutineArgsParts` not generic I hope a few extra calls to `expect_ty` will not affect perf...
2023-12-28make ClosureArgsParts not genericMichael Goulet-58/+48
2023-12-28Movability doesn't need to be a query anymoreMichael Goulet-9/+8
2023-12-28Remove movability from TyKind::CoroutineMichael Goulet-35/+33
2023-12-28rustc_middle: Pretty-print negative bounds correctlyLeón Orell Valerian Liehr-21/+51
2023-12-27Auto merge of #119099 - fmease:always-const-trait-bounds, r=fee1-deadbors-11/+10
Introduce `const Trait` (always-const trait bounds) Feature `const_trait_impl` currently lacks a way to express “always const” trait bounds. This makes it impossible to define generic items like fns or structs which contain types that depend on const method calls (\*). While the final design and esp. the syntax of effects / keyword generics isn't set in stone, some version of “always const” trait bounds will very likely form a part of it. Further, their implementation is trivial thanks to the `effects` backbone. Not sure if this needs t-lang sign-off though. (\*): ```rs #![feature(const_trait_impl, effects, generic_const_exprs)] fn compute<T: const Trait>() -> Type<{ T::generate() }> { /*…*/ } struct Store<T: const Trait> where Type<{ T::generate() }>:, { field: Type<{ T::generate() }>, } ``` Lastly, “always const” trait bounds are a perfect fit for `generic_const_items`. ```rs #![feature(const_trait_impl, effects, generic_const_items)] const DEFAULT<T: const Default>: T = T::default(); ``` Previously, we (oli, fee1-dead and I) wanted to reinterpret `~const Trait` as `const Trait` in generic const items which would've been quite surprising and not very generalizable. Supersedes #117530. --- cc `@oli-obk` As discussed r? fee1-dead (or compiler)
2023-12-27Introduce `const Trait` (always-const trait bounds)León Orell Valerian Liehr-11/+10
2023-12-26Auto merge of #118431 - sjwang05:issue-44695, r=estebankbors-1/+18
Emit better suggestions for `&T == T` and `T == &T` Fixes #40660 Fixes #44695
2023-12-26Rollup merge of #119307 - compiler-errors:pat-lifetimes, r=NadrierilMichael Goulet-12/+27
Clean up some lifetimes in `rustc_pattern_analysis` This PR removes some redundant lifetimes. I figured out that we were shortening the lifetime of an arena-allocated `&'p DeconstructedPat<'p>` to `'a DeconstructedPat<'p>`, which forced us to carry both lifetimes when we could otherwise carry just one. This PR also removes and elides some unnecessary lifetimes. I also cherry-picked 0292eb9bb9b897f5c0926c6a8530877f67e7cc9b, and then simplified more lifetimes in `MatchVisitor`, which should make #119233 a very simple PR! r? Nadrieril
2023-12-26Auto merge of #119129 - jyn514:verbose, r=compiler-errors,estebankbors-10/+18
rework `-Zverbose` implements the changes described in https://github.com/rust-lang/compiler-team/issues/706 the first commit is only a name change from `-Zverbose` to `-Zverbose-internals` and does not change behavior. the second commit changes diagnostics. possible follow up work: - `ty::pretty` could print more info with `--verbose` than it does currently. `-Z verbose-internals` shows too much info in a way that's not helpful to users. michael had ideas about this i didn't fully understand: https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/uplift.20some.20-Zverbose.20calls.20and.20rename.20to.E2.80.A6.20compiler-team.23706/near/408984200 - `--verbose` should imply `-Z write-long-types-to-disk=no`. the code in `ty_string_with_limit` should take `--verbose` into account (apparently this affects `Ty::sort_string`, i'm not familiar with this code). writing a file to disk should suggest passing `--verbose`. r? `@compiler-errors` cc `@estebank`
2023-12-26Auto merge of #119258 - compiler-errors:closure-kind, r=eholkbors-23/+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-26`thir::Visitor` only needs to visit `&'thir` dataNadrieril-12/+27
2023-12-26Auto merge of #119146 - nnethercote:rm-DiagCtxt-api-duplication, ↵bors-39/+44
r=compiler-errors Remove `DiagCtxt` API duplication `DiagCtxt` defines the internal API for creating and emitting diagnostics: methods like `struct_err`, `struct_span_warn`, `note`, `create_fatal`, `emit_bug`. There are over 50 methods. Some of these methods are then duplicated across several other types: `Session`, `ParseSess`, `Parser`, `ExtCtxt`, and `MirBorrowckCtxt`. `Session` duplicates the most, though half the ones it does are unused. Each duplicated method just calls forward to the corresponding method in `DiagCtxt`. So this duplication exists to (in the best case) shorten chains like `ecx.tcx.sess.parse_sess.dcx.emit_err()` to `ecx.emit_err()`. This API duplication is ugly and has been bugging me for a while. And it's inconsistent: there's no real logic about which methods are duplicated, and the use of `#[rustc_lint_diagnostic]` and `#[track_caller]` attributes vary across the duplicates. This PR removes the duplicated API methods and makes all diagnostic creation and emission go through `DiagCtxt`. It also adds `dcx` getter methods to several types to shorten chains. This approach scales *much* better than API duplication; indeed, the PR adds `dcx()` to numerous types that didn't have API duplication: `TyCtxt`, `LoweringCtxt`, `ConstCx`, `FnCtxt`, `TypeErrCtxt`, `InferCtxt`, `CrateLoader`, `CheckAttrVisitor`, and `Resolver`. These result in a lot of changes from `foo.tcx.sess.emit_err()` to `foo.dcx().emit_err()`. (You could do this with more types, but it gets into diminishing returns territory for types that don't emit many diagnostics.) After all these changes, some call sites are more verbose, some are less verbose, and many are the same. The total number of lines is reduced, mostly because of the removed API duplication. And consistency is increased, because calls to `emit_err` and friends are always preceded with `.dcx()` or `.dcx`. r? `@compiler-errors`
2023-12-25Only regular coroutines have movabilityMichael Goulet-9/+9
2023-12-25Remove unnecessary body_expr_countMichael Goulet-14/+0
2023-12-24Auto merge of #119139 - michaelwoerister:cleanup-stable-source-file-id, ↵bors-23/+16
r=cjgillot Unify SourceFile::name_hash and StableSourceFileId This PR adapts the existing `StableSourceFileId` type so that it can be used instead of the `name_hash` field of `SourceFile`. This simplifies a few things that were kind of duplicated before. The PR should also fix issues https://github.com/rust-lang/rust/issues/112700 and https://github.com/rust-lang/rust/issues/115835, but I was not able to reproduce these issues in a regression test. As far as I can tell, the root cause of these issues is that the id of the originating crate is not hashed in the `HashStable` impl of `Span` and thus cache entries that should have been considered invalidated were loaded. After this PR, the `stable_id` field of `SourceFile` includes information about the originating crate, so that ICE should not occur anymore.
2023-12-23Auto merge of #119218 - Nadrieril:nested-opaque-reveal, r=compiler-errorsbors-18/+73
Exhaustiveness: Reveal empty opaques in depth Follow-up to https://github.com/rust-lang/rust/pull/116821. As noted [there](https://github.com/rust-lang/rust/pull/116821#discussion_r1376673420), the current implementation doesn't detect emptiness of opaques when the opaque is nested inside a type. This doesn't matter for stable behavior (which ignores nested empty types anyway) but does matter for the [`exhaustive_patterns`](https://github.com/rust-lang/rust/issues/51085)/[`min_exhaustive_patterns`](https://github.com/rust-lang/rust/pull/118803) features. This PR fixes this behavior by adding `InhabitedPredicate::apply_reveal_opaque` that considers opaque types when determining inhabitedness. r? `@compiler-errors`
2023-12-24Remove more `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-2/+2
2023-12-24Remove `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-37/+42
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access.
2023-12-23Remove an unused diagnostic structDeadbeef-8/+0
this is used at `rustc_middle::error`, is duplicated here somehow
2023-12-23Reveal empty opaques in depthNadrieril-18/+73
2023-12-22Rollup merge of #119198 - compiler-errors:desugaring, r=eholkMichael Goulet-24/+53
Split coroutine desugaring kind from source What a coroutine is desugared from (gen/async gen/async) should be separate from where it comes (fn/block/closure).
2023-12-22Rollup merge of #119171 - nnethercote:cleanup-errors-4, r=compiler-errorsMichael Goulet-28/+15
Cleanup error handlers: round 4 More `rustc_errors` cleanups. A sequel to #118933. r? `@compiler-errors`
2023-12-23Give `DiagnosticBuilder` a default type.Nicholas Nethercote-5/+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-23Streamline `struct_lint_level`.Nicholas Nethercote-23/+13
We can just get the error level in the `match` and then use `DiagnosticBuilder::new`. This then means a number of `DiagCtxt` functions are no longer needed, because this was the one place that used them. Note: the commit changes the treatment of spans for `Expect`, which was different to all the other cases, but this has no apparent effect.
2023-12-22Split coroutine desugaring kind from sourceMichael Goulet-24/+53
2023-12-22update cfg(bootstrap)sPietro Albini-1/+0
2023-12-22Auto merge of #119097 - nnethercote:fix-EmissionGuarantee, r=compiler-errorsbors-5/+6
Fix `EmissionGuarantee` There are some problems with the `DiagCtxt` API related to `EmissionGuarantee`. This PR fixes them. r? `@compiler-errors`
2023-12-20Auto merge of #119136 - petrochenkov:feedvis3, r=WaffleLapkinbors-4/+21
resolve: Eagerly feed closure visibilities Also factor out all tcx-dependent operations performed for every created definition into `TyCtxt::create_def`. Addresses https://github.com/rust-lang/rust/pull/118657#discussion_r1421424277
2023-12-20resolve: Eagerly feed closure visibilitiesVadim Petrochenkov-4/+21
Also factor out all tcx-dependent operations performed for every created definition into `TyCtxt::create_def`
2023-12-20Rollup merge of #119071 - lcnr:overflowo, r=compiler-errorsMatthias Krüger-4/+31
-Znext-solver: adapt overflow rules to avoid breakage Do not erase overflow constraints if they are from equating the impl header when normalizing[^1]. This should be the minimal change to not break crates depending on the old project behavior of "apply impl constraints while only lazily evaluating any nested goals". Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/70, see https://hackmd.io/ATf4hN0NRY-w2LIVgeFsVg for the reasoning behind this. Only keeping constraints on overflow for `normalize-to` goals as that's the only thing needed for backcompat. It also allows us to not track the origin of root obligations. The issue with root goals would be something like the following: ```rust trait Foo {} trait Bar {} trait FooBar {} impl<T: Foo + Bar> FooBar for T {} // These two should behave the same, rn we can drop constraints for both, // but if we don't drop `Misc` goals we would only drop the constraints for // `FooBar` unless we track origins of root obligations. fn func1<T: Foo + Bar>() {} fn func2<T: FooBaz>() {} ``` [^1]: mostly, the actual rules are slightly different r? ``@compiler-errors``
2023-12-20Hide foreign `#[doc(hidden)]` paths in import suggestionsJules Bertholet-1/+1
2023-12-19Unify SourceFile::name_hash and StableSourceFileIdMichael Woerister-23/+16
2023-12-19rename to verbose-internalsjyn-10/+18
2023-12-19Remove param env from relation altogetherMichael Goulet-6/+0
2023-12-19Remove unnecessary param-env from lexical region resolution and fully ↵Michael Goulet-4/+5
structural relations
2023-12-19Do not evaluate in structurally_relate_tysMichael Goulet-7/+3
2023-12-19Auto merge of #119093 - michaelwoerister:mcp533-18, r=petrochenkovbors-3/+3
Replace some instances of FxHashMap/FxHashSet with stable alternatives (mostly in rustc_hir and rustc_ast_lowering) Part of https://github.com/rust-lang/compiler-team/issues/533. We should be getting close to being able to remove the HashStable impl of HashMap.
2023-12-19Add `level` arg to `into_diagnostic`.Nicholas Nethercote-5/+6
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.