about summary refs log tree commit diff
path: root/compiler/rustc_middle
AgeCommit message (Collapse)AuthorLines
2023-05-29EarlyBinder::new -> EarlyBinder::bindlcnr-13/+13
2023-05-29Auto merge of #111748 - nnethercote:Cow-DiagnosticMessage, r=WaffleLapkinbors-17/+18
Use `Cow` in `{D,Subd}iagnosticMessage`. Each of `{D,Subd}iagnosticMessage::{Str,Eager}` has a comment: ``` // FIXME(davidtwco): can a `Cow<'static, str>` be used here? ``` This commit answers that question in the affirmative. It's not the most compelling change ever, but it might be worth merging. This requires changing the `impl<'a> From<&'a str>` impls to `impl From<&'static str>`, which involves a bunch of knock-on changes that require/result in call sites being a little more precise about exactly what kind of string they use to create errors, and not just `&str`. This will result in fewer unnecessary allocations, though this will not have any notable perf effects given that these are error paths. Note that I was lazy within Clippy, using `to_string` in a few places to preserve the existing string imprecision. I could have used `impl Into<{D,Subd}iagnosticMessage>` in various places as is done in the compiler, but that would have required changes to *many* call sites (mostly changing `&format("...")` to `format!("...")`) which didn't seem worthwhile. r? `@WaffleLapkin`
2023-05-29Use `Cow` in `{D,Subd}iagnosticMessage`.Nicholas Nethercote-17/+18
Each of `{D,Subd}iagnosticMessage::{Str,Eager}` has a comment: ``` // FIXME(davidtwco): can a `Cow<'static, str>` be used here? ``` This commit answers that question in the affirmative. It's not the most compelling change ever, but it might be worth merging. This requires changing the `impl<'a> From<&'a str>` impls to `impl From<&'static str>`, which involves a bunch of knock-on changes that require/result in call sites being a little more precise about exactly what kind of string they use to create errors, and not just `&str`. This will result in fewer unnecessary allocations, though this will not have any notable perf effects given that these are error paths. Note that I was lazy within Clippy, using `to_string` in a few places to preserve the existing string imprecision. I could have used `impl Into<{D,Subd}iagnosticMessage>` in various places as is done in the compiler, but that would have required changes to *many* call sites (mostly changing `&format("...")` to `format!("...")`) which didn't seem worthwhile.
2023-05-28Auto merge of #111813 - scottmcm:pretty-mir, r=cjgillotbors-14/+14
MIR: opt-in normalization of `BasicBlock` and `Local` numbering This doesn't matter at all for actual codegen, but after spending some time reading pre-codegen MIR, I was wishing I didn't have to jump around so much in reading post-inlining code. So this add two passes that are off by default for every mir level, but can be enabled (`-Zmir-enable-passes=+ReorderBasicBlocks,+ReorderLocals`) for humans.
2023-05-28Add documentation on skip_binder on how to get &T from &EarlyBinder<T>Kyle Matsuda-0/+3
2023-05-28Make EarlyBinder's inner value private; and fix all of the resulting errorsKyle Matsuda-3/+3
2023-05-28Replace EarlyBinder(x) with EarlyBinder::new(x)Kyle Matsuda-12/+16
2023-05-28Auto merge of #111378 - jieyouxu:local-shadows-glob-reexport, r=petrochenkovbors-1/+1
Add warn-by-default lint when local binding shadows exported glob re-export item This PR introduces a warn-by-default rustc lint for when a local binding (a use statement, or a type declaration) produces a name which shadows an exported glob re-export item, causing the name from the exported glob re-export to be hidden (see #111336). ### Unresolved Questions - [x] ~~Is this approach correct? While it passes the UI tests, I'm not entirely convinced it is correct.~~ Seems to be ok now. - [x] ~~What should the lint be called / how should it be worded? I don't like calling `use x::*;` or `struct Foo;` a "local binding" but they are `NameBinding`s internally if I'm not mistaken.~~ ~~The lint is called `local_binding_shadows_glob_reexport` for now, unless a better name is suggested.~~ `hidden_glob_reexports`. Fixes #111336.
2023-05-27Rollup merge of #111952 - cjgillot:drop-replace, r=WaffleLapkinGuillaume Gomez-1/+6
Remove DesugaringKind::Replace. A simple boolean flag is enough.
2023-05-27Add warn-by-default lint for local binding shadowing exported glob re-export ↵许杰友 Jieyou Xu (Joe)-1/+1
item
2023-05-26better `TyKind::Debug`Boxy-52/+84
2023-05-26print const and type errors in braces not square bracketsBoxy-3/+3
2023-05-26Wait until type_of to remap HIR opaques back to their defn paramsMichael Goulet-1/+1
2023-05-26Auto merge of #111984 - matthiaskrgr:rollup-6u7ynyv, r=matthiaskrgrbors-4/+1
Rollup of 5 pull requests Successful merges: - #111384 (Fix linking Mac Catalyst by including LC_BUILD_VERSION in object files) - #111899 (CGU cleanups) - #111940 (Clarify safety concern of `io::Read::read` is only relevant in unsafe code) - #111947 (Add test for RPIT defined with different hidden types with different substs) - #111951 (Correct comment on privately uninhabited pattern.) Failed merges: - #111954 (improve error message for calling a method on a raw pointer with an unknown pointee) r? `@ghost` `@rustbot` modify labels: rollup
2023-05-26Rollup merge of #111899 - nnethercote:cgu-cleanups, r=wesleywiserMatthias Krüger-4/+1
CGU cleanups Some code clarity improvements I found when reading this code closely. r? ``@wesleywiser``
2023-05-26Auto merge of #111918 - compiler-errors:custom-type-ops-err, r=lcnrbors-2/+0
Use `ErrorGuaranteed` more in MIR type ops Delay bugs more eagerly and pass them through type op infra instead of delaying them at all the usage-sites. Follow up to: https://github.com/rust-lang/rust/pull/111741#discussion_r1203840588 r? `@lcnr`
2023-05-26Auto merge of #111858 - clubby789:fluent-alphabetical, r=jyn514,compiler-errorsbors-24/+24
Ensure Fluent messages are in alphabetical order Fixes #111847 This adds a tidy check to ensure Fluent messages are in alphabetical order, as well as sorting all existing messages. I think the error could be worded better, would appreciate suggestions. <details> <summary>Script used to sort files</summary> ```py import sys import re fn = sys.argv[1] with open(fn, 'r') as f: data = f.read().split("\n") chunks = [] cur = "" for line in data: if re.match(r"^([a-zA-Z0-9_]+)\s*=\s*", line): chunks.append(cur) cur = "" cur += line + "\n" chunks.append(cur) chunks.sort() with open(fn, 'w') as f: f.write(''.join(chunks).strip("\n\n") + "\n") ``` </details>
2023-05-25Ensure Fluent messages are in alphabetical orderclubby789-24/+24
2023-05-25Remove DesugaringKind::Replace.Camille GILLOT-1/+6
2023-05-25Fallible<_> -> Result<_, NoSolution>Michael Goulet-2/+0
2023-05-25Remove ExpnKind::Inlined.Camille GILLOT-5/+2
2023-05-25Use De Morgan's law to simplify logicMichael Howell-6/+6
Co-authored-by: Camille Gillot <gillot.camille@gmail.com>
2023-05-25remove outdated comment from `is_user_visible_dep` docsMichael Howell-4/+0
2023-05-25diagnostics: don't crash if an injected crate shows up in suggestionsMichael Howell-1/+4
2023-05-25diagnostics: exclude indirect private deps from trait impl suggestMichael Howell-1/+22
Fixes #88696
2023-05-25Auto merge of #111473 - compiler-errors:opaques, r=lcnrbors-14/+123
Handle opaques in the new solver (take 2?) Implement a new strategy for handling opaques in the new solver. First, queries now carry both their defining anchor and the opaques that were defined in the inference context at the time of canonicalization. These are both used to pre-populate the inference context used by the canonical query. Second, use the normalizes-to goal to handle opaque types in the new solver. This means that opaques are handled like projection aliases, but with their own rules: * Can only define opaques if they're "defining uses" (i.e. have unique params in all their substs). * Can only define opaques that are from the anchor. * Opaque type definitions are modulo regions. So that means `Opaque<'?0r> = HiddenTy1` and `Opaque<?'1r> = HiddenTy2` equate `HiddenTy1` and `HiddenTy2` instead of defining them as different opaque type keys.
2023-05-25Rollup merge of #111875 - WaffleLapkin:defer_on_drop, r=NilstriebMatthias Krüger-1/+1
Don't leak the function that is called on drop It probably wasn't causing problems anyway, but still, a `// this leaks, please don't pass anything that owns memory` is not sustainable. I could implement a version which does not require `Option`, but it would require `unsafe`, at which point it's probably not worth it.
2023-05-25Streamline `modify_size_estimate`.Nicholas Nethercote-4/+1
2023-05-25Check that opaque is a defining use, prefer pre-defined opaquesMichael Goulet-0/+36
2023-05-25Prepopulate opaques in canonical inputMichael Goulet-4/+72
2023-05-25Move DefiningAnchorMichael Goulet-0/+11
2023-05-25Pull out logic from #111131, plus some new logic in ↵Michael Goulet-10/+4
EvalCtxt::normalize_opaque_type Co-authored-by: lcnr <rust@lcnr.de>
2023-05-24Rollup merge of #111912 - WaffleLapkin:is_some_and_in_the_compiler, ↵Manish Goregaokar-12/+11
r=petrochenkov Use `Option::is_some_and` and `Result::is_ok_and` in the compiler `.is_some_and(..)`/`.is_ok_and(..)` replace `.map_or(false, ..)` and `.map(..).unwrap_or(false)`, making the code more readable. This PR is a sibling of https://github.com/rust-lang/rust/pull/111873#issuecomment-1561316515
2023-05-24Auto merge of #111673 - cjgillot:dominator-preprocess, r=cjgillot,tmiaskobors-2/+3
Preprocess and cache dominator tree Preprocessing dominators has a very strong effect for https://github.com/rust-lang/rust/pull/111344. That pass checks that assignments dominate their uses repeatedly. Using the unprocessed dominator tree caused a quadratic runtime (number of bbs x depth of the dominator tree). This PR also caches the dominator tree and the pre-processed dominators in the MIR cfg cache. Rebase of https://github.com/rust-lang/rust/pull/107157 cc `@tmiasko`
2023-05-24Use `Option::is_some_and` and `Result::is_ok_and` in the compilerMaybe Waffle-12/+11
2023-05-24Rollup merge of #111870 - WaffleLapkin:just_🌟traits🌟_query, ↵Matthias Krüger-10/+12
r=compiler-errors Rename `traits_in_crate` query to `traits` > NOTE: Not named just `traits` due to a naming conflict. This can, in fact, be easily avoided.
2023-05-23Rename `traits_in_crate` query to `traits`Maybe Waffle-10/+12
2023-05-23Rollup merge of #111486 - fmease:pp-inh-proj, r=petrochenkovMatthias Krüger-1/+21
Pretty-print inherent projections correctly Previously, we were trying to pretty-print inherent projections with `Printer::print_def_path` which is incorrect since it expects the substitutions to be of a certain format (parents substs followed by own substs) which doesn't hold for inherent projections (self type subst followed by own substs). Now we print inherent projections manually. Fixes #111390. Fixes #111397. Lacking tests! Is there a test suite / compiletest flags for the pretty-printer? In most if not all cases, inherent projections are normalized away before they get the chance to appear in diagnostics. If I were to create regression tests for linked issues, they would need to be `mir-opt` tests to exercise `-Zdump-mir=all` (right?) which doesn't feel quite adequate to me. `@rustbot` label F-inherent_associated_types
2023-05-23Don't leak the function that is called on dropMaybe Waffle-1/+1
2023-05-23Rollup merge of #111853 - compiler-errors:opaque-check, r=oli-obkDylan DPC-7/+23
Check opaques for mismatch during writeback Revive #111705. I realized that we don't need to put any substs in the writeback results since all of the hidden types have already been remapped. See the comment in `compiler/rustc_middle/src/ty/typeck_results.rs`, which should make that clear for other explorers of the codebase. Additionally, we need to do some diagnostic stashing because the diagnostics we produce during HIR typeck is very poor and we should prefer the diagnostic that comes from MIR, if we have one. r? `@oli-obk`
2023-05-22Check opaques for mismatch during writebackMichael Goulet-7/+23
2023-05-22properly pretty-print inherent projectionsLeón Orell Valerian Liehr-1/+21
2023-05-22Auto merge of #111848 - Dylan-DPC:rollup-7jqydzg, r=Dylan-DPCbors-0/+23
Rollup of 6 pull requests Successful merges: - #111501 (MIR drive-by cleanups) - #111609 (Mark internal functions and traits unsafe to reflect preconditions) - #111612 (Give better error when collecting into `&[T]`) - #111756 (Rename `{drop,forget}_{copy,ref}` lints to more consistent naming) - #111843 (move lcnr to only review types stuff) - #111844 (Migrate GUI colors test to original CSS color format) r? `@ghost` `@rustbot` modify labels: rollup
2023-05-23Rollup merge of #111501 - WaffleLapkin:drivebycleanupuwu, r=oli-obkDylan DPC-0/+23
MIR drive-by cleanups Some random drive-by cleanups I did while working with MIR/THIR.
2023-05-22Auto merge of #111754 - lcnr:recursion-depth, r=matthewjasperbors-3/+20
fix recursion depth handling after confirmation fixes #111729 I think having to use `Obligation::with_depth` correctly everywhere is very hard because e.g. the nested obligations from `eq` currently do not have the correct obligation depth. The new solver [completely removes `recursion_depth` from obligations](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/traits/solve/struct.Goal.html) and instead tracks the depth in the solver itself which is far easier to get right. Moving the old solver towards this shouldn't be that hard but is probably somewhat annoying. r? `@matthewjasper`
2023-05-22Auto merge of #111775 - compiler-errors:triple-check, r=Nilstriebbors-5/+44
Add extra debug assertions for equality for Adt/Variant/FieldDef Would've made it easier to both catch and test https://github.com/rust-lang/rust/pull/111494. Maybe not worth it, since it does mean that the compiler is doing extra work when debug-assertions are enabled, but also that's what debug assertions are for :^) This is a revival of #111523 because I think I pushed an empty branch and bors got a bit too excited it closed the PR.
2023-05-21Tweak the post-order for multi-successor blocksScott McMurray-14/+14
2023-05-21Replace `QueryStruct` with arrays local to `rustc_query_impl`John Kåre Alsaker-13/+3
2023-05-20Rollup merge of #111450 - compiler-errors:opaque-ty-key, r=oli-obkGuillaume Gomez-2/+2
Use `OpaqueTypeKey` in query response Makes it a bit clearer that at least one of the types being returned from a canonical query is an opaque.
2023-05-20Rollup merge of #111619 - cjgillot:profile-pass, r=WaffleLapkinDylan DPC-1/+1
Add timings for MIR passes to profiling report This will help identify which pass is responsible for a regression.