summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src
AgeCommit message (Collapse)AuthorLines
2025-01-23add cache to `AmbiguityCausesVisitor`lcnr-2/+12
(cherry picked from commit 94bf8f04f402a2410ab85a6e6b9e542e3942b2a2)
2025-01-23avoid running the overlap check twicelcnr-22/+33
(cherry picked from commit ebbcfd4e7721aaf3211f0e8d3d6e304400c80f78)
2025-01-02Remove unused fields from RepeatElementCopy obligationTaylor Cramer-6/+1
2025-01-01Rollup merge of #133292 - dianne:e0277-suggest-deref, r=estebankStuart Cook-113/+85
E0277: suggest dereferencing function arguments in more cases This unifies and generalizes some of the logic in `TypeErrCtxt::suggest_dereferences` so that it will suggest dereferencing arguments to function/method calls in order to satisfy trait bounds in more cases. Previously it would only fire on reference types, and it had two separate cases (one specifically to get through custom `Deref` impls when passing by-reference, and one specifically to catch #87437). I've based the new checks loosely on what's done for `E0308` in `FnCtxt::suggest_deref_or_ref`: it will suggest dereferences to satisfy trait bounds whenever the referent is `Copy`, is boxed (& so can be moved out of the boxes), or is being passed by reference. This doesn't make the suggestion fire in contexts other than function arguments or binary operators (which are in a separate case that this doesn't touch), and doesn't make it suggest a combination of `&`-removal and dereferences. Those would require a bit more restructuring, so I figured just doing this would be a decent first step. Closes #90997
2024-12-31Rollup merge of #134949 - compiler-errors:froms, r=jieyouxuStuart Cook-6/+6
Convert some `Into` impls into `From` impls From the [`From`](https://doc.rust-lang.org/std/convert/trait.From.html) docs: > One should always prefer implementing `From` over [`Into`](https://doc.rust-lang.org/std/convert/trait.Into.html) because implementing `From` automatically provides one with an implementation of [`Into`](https://doc.rust-lang.org/std/convert/trait.Into.html) thanks to the blanket implementation in the standard library. > > Only implement [`Into`](https://doc.rust-lang.org/std/convert/trait.Into.html) when targeting a version prior to Rust 1.41 and converting to a type outside the current crate. `From` was not able to do these types of conversions in earlier versions because of Rust’s orphaning rules. See [Into](https://doc.rust-lang.org/std/convert/trait.Into.html) for more details. Some of these impls are likely from before 1.41, and then some others were probably just mistakes. Building nightly rust is definitely not supported on 1.41, so let's modernize these impls :D
2024-12-31Convert some Into impls into From implsMichael Goulet-6/+6
2024-12-31Make sure we check the future type is Sized in AsyncFn*Michael Goulet-3/+20
2024-12-27Rollup merge of #134827 - compiler-errors:borrowck-nits, r=lqdDavid Tolnay-2/+1
Some random region tweaks Remove a redundant function and add an assertion that I think is useful
2024-12-27Rollup merge of #134823 - chloefeal:fix, r=tgross35,dtolnayDavid Tolnay-1/+1
Fix typos This PR focuses on correcting typos and improving clarity in documentation files. Thank you.
2024-12-27Fix typoschloefeal-1/+1
Signed-off-by: chloefeal <188809157+chloefeal@users.noreply.github.com>
2024-12-26Make ty::Error implement auto traitsMichael Goulet-1/+3
2024-12-26nit: Remove redundant functionMichael Goulet-2/+1
2024-12-24Auto merge of #134716 - Zalathar:rollup-1h4q8cc, r=Zalatharbors-28/+137
Rollup of 5 pull requests Successful merges: - #134638 (Fix effect predicates from item bounds in old solver) - #134662 (Fix safety docs for `dyn Any + Send {+ Sync}`) - #134689 (core: fix const ptr::swap_nonoverlapping when there are pointers at odd offsets) - #134699 (Belay new reviews for workingjubilee) - #134701 (Correctly note item kind in `NonConstFunctionCall` error message) r? `@ghost` `@rustbot` modify labels: rollup
2024-12-24Rollup merge of #134638 - compiler-errors:fx-item-bounds, r=lcnrStuart Cook-28/+137
Fix effect predicates from item bounds in old solver r? lcnr
2024-12-22Begin to implement type system layer of unsafe bindersMichael Goulet-3/+33
2024-12-22Rollup merge of #134639 - compiler-errors:negative-ambiguity-causes, r=oli-obkMatthias Krüger-9/+13
Make sure we note ambiguity causes on positive/negative impl conflicts Fixes https://github.com/rust-lang/rust/issues/134632 by explaining why the error must be
2024-12-22Make sure we note ambiguity causes on positive/negative impl conflictsMichael Goulet-9/+13
2024-12-22Fix item bounds in old solverMichael Goulet-28/+137
2024-12-21Auto merge of #134501 - lcnr:member-constraints-yeet, r=oli-obkbors-15/+5
handle member constraints directly in the mir type checker cleaner, faster, easier to change going forward :> fixes #109654 r? `@oli-obk` `@compiler-errors`
2024-12-20Reduce the amount of explicit FatalError.raise()bjorn3-5/+2
Instead use dcx.abort_if_error() or guar.raise_fatal() instead. These guarantee that an error actually happened previously and thus we don't silently abort.
2024-12-20remove non-borrowck member constraintslcnr-15/+5
2024-12-19Auto merge of #133961 - lcnr:borrowck-cleanup, r=jackh726bors-17/+17
cleanup region handling: add `LateParamRegionKind` The second commit is to enable a split between `BoundRegionKind` and `LateParamRegionKind`, by avoiding `BoundRegionKind` where it isn't necessary. The third comment then adds `LateParamRegionKind` to avoid having the same late-param region for separate bound regions. This fixes #124021. r? `@compiler-errors`
2024-12-18chore: fix some typosacceptacross-1/+1
Signed-off-by: acceptacross <csqcqs@gmail.com>
2024-12-18introduce `LateParamRegionKind`lcnr-17/+17
2024-12-18Auto merge of #134243 - nnethercote:re-export-more-rustc_span, r=jieyouxubors-23/+15
Re-export more `rustc_span::symbol` things from `rustc_span`. `rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers to `rustc_span::`. This is a 300+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one. r? `@jieyouxu`
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-23/+15
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-12-17Rollup merge of #133265 - the8472:extract-if-ranges, r=cuviperMatthias Krüger-1/+1
Add a range argument to vec.extract_if tracking issue: #43244 This adds the range argument requested in https://github.com/rust-lang/rust/issues/43244#issuecomment-2486160659
2024-12-17Auto merge of #134381 - jdonszelmann:move-attribute-types, r=oli-obkbors-1/+1
Split up attribute parsing code and move data types to `rustc_attr_data_structures` This change renames `rustc_attr` to `rustc_attr_parsing`, and splits up the parsing code. At the same time, all the data types used move to `rustc_attr_data_structures`. This is in preparation of also having a third crate: `rustc_attr_validation` I initially envisioned this as two separate PRs, but I think doing it in one go reduces the number of ways others would have to rebase their changes on this. However, I can still split them. r? `@oli-obk` (we already discussed how this is a first step in a larger plan) For a more detailed plan on how attributes are going to change, see https://github.com/rust-lang/rust/issues/131229 Edit: this looks like a giant PR, but the changes are actually rather trivial. Each commit is reviewable on its own, and mostly moves code around. No new logic is added.
2024-12-17Auto merge of #134414 - jhpratt:rollup-4gtfd1h, r=jhprattbors-130/+101
Rollup of 10 pull requests Successful merges: - #134202 (Remove `rustc::existing_doc_keyword` lint) - #134354 (Handle fndef rendering together with signature rendering) - #134365 (Rename `rustc_mir_build::build` to `builder`) - #134368 (Use links to edition guide for edition migrations) - #134397 (rustc_borrowck: Suggest changing `&raw const` to `&raw mut` if applicable) - #134398 (AIX: add alignment info for test) - #134400 (Fix some comments related to upvars handling) - #134406 (Fix `-Z input-stats` ordering) - #134409 (bootstrap: fix a comment) - #134412 (small borrowck cleanup) r? `@ghost` `@rustbot` modify labels: rollup
2024-12-17Rollup merge of #134412 - lcnr:borrowck-cleanup-trivial, r=jackh726Jacob Pratt-110/+75
small borrowck cleanup the already approved parts of #133909 and #133961 r? `@jackh726`
2024-12-17Rollup merge of #134354 - oli-obk:push-nlrxswvpqnuk, r=compiler-errorsJacob Pratt-20/+26
Handle fndef rendering together with signature rendering Pulled out of https://github.com/rust-lang/rust/pull/134353 Changes some highlighting in type mismatch errors around fndefs
2024-12-17small refactor to region error handlinglcnr-110/+75
2024-12-17consistently handle global where-boundslcnr-305/+242
2024-12-16update uses of extract_if in the compilerThe 8472-1/+1
2024-12-16rename rustc_attr to rustc_attr_parsing and create rustc_attr_data_structuresJonathan Dönszelmann-1/+1
2024-12-16Avoid wrapping fn sig in a fn pointer when we want to just print the sigOli Scherer-13/+13
2024-12-16Deduplicate some pretty printing logicOli Scherer-20/+15
2024-12-16Avoid wrapping a trivially defaultable type in `Option`Oli Scherer-16/+11
2024-12-16Properly name a def id variableOli Scherer-4/+4
2024-12-16Avoid creating a fn sig type just to unwrap it again to get at its signatureOli Scherer-14/+18
2024-12-16Handle fndef rendering together with signature renderingOli Scherer-20/+26
2024-12-15Add hir::AttributeJonathan Dönszelmann-3/+4
2024-12-15Rename `value` field to `expr` to simplify later commits' diffsOli Scherer-1/+1
2024-12-15Rollup merge of #134285 - oli-obk:push-vwrqsqlwnuxo, r=UrgauStuart Cook-1/+1
Add some convenience helper methods on `hir::Safety` Makes a lot of call sites simpler and should make any refactorings needed for https://github.com/rust-lang/rust/pull/134090#issuecomment-2541332415 simpler, as fewer sites have to be touched in case we end up storing some information in the variants of `hir::Safety`
2024-12-14Rollup merge of #132939 - uellenberg:suggest-deref, r=oli-obkMatthias Krüger-30/+98
Suggest using deref in patterns Fixes #132784 This changes the following code: ```rs use std::sync::Arc; fn main() { let mut x = Arc::new(Some(1)); match x { Some(_) => {} None => {} } } ``` to output ```rs error[E0308]: mismatched types --> src/main.rs:5:9 | LL | match x { | - this expression has type `Arc<Option<{integer}>>` ... LL | Some(_) => {} | ^^^^^^^ expected `Arc<Option<{integer}>>`, found `Option<_>` | = note: expected struct `Arc<Option<{integer}>>` found enum `Option<_>` help: consider dereferencing to access the inner value using the Deref trait | LL | match *x { | ~~ ``` instead of ```rs error[E0308]: mismatched types --> src/main.rs:5:9 | 4 | match x { | - this expression has type `Arc<Option<{integer}>>` 5 | Some(_) => {} | ^^^^^^^ expected `Arc<Option<{integer}>>`, found `Option<_>` | = note: expected struct `Arc<Option<{integer}>>` found enum `Option<_>` ``` This makes it more obvious that a Deref is available, and gives a suggestion on how to use it in order to fix the issue at hand.
2024-12-14Add some convenience helper methods on `hir::Safety`Oli Scherer-1/+1
2024-12-14(Re-)Implement impl_trait_in_bindingsMichael Goulet-0/+6
2024-12-14Split UserTypeAnnotation to have a kindMichael Goulet-4/+4
2024-12-13Suggest using deref in patternsuellenberg-30/+98
Fixes #132784
2024-12-13Auto merge of #134122 - oli-obk:push-zqnyznxtpnll, r=petrochenkovbors-1/+3
Move impl constness into impl trait header This PR is kind of the opposite of the rejected https://github.com/rust-lang/rust/pull/134114 Instead of moving more things into the `constness` query, we want to keep them where their corresponding hir nodes are lowered. So I gave this a spin for impls, which have an obvious place to be (the impl trait header). And surprisingly it's also a perf improvement (likely just slightly better query & cache usage). The issue was that removing anything from the `constness` query makes it just return `NotConst`, which is wrong. So I had to change it to `bug!` out if used wrongly, and only then remove the impl blocks from the `constness` query. I think this change is good in general, because it makes using `constness` more robust (as can be seen by how few sites that had to be changed, so it was almost solely used specifically for the purpose of asking for functions' constness). The main thing where this change was not great was in clippy, which was using the `constness` query as a general DefId -> constness map. I added a `DefKind` filter in front of that. If it becomes a more common pattern we can always move that helper into rustc.