about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src
AgeCommit message (Collapse)AuthorLines
2024-06-14Correctly consider depth when visiting WF goalsMichael Goulet-3/+18
2024-06-14Use is_lang_item more aggressivelyMichael Goulet-78/+77
2024-06-14Add TyCtxt::is_lang_itemMichael Goulet-39/+37
2024-06-14Make proof tree probing genericMichael Goulet-38/+45
2024-06-14Make Candidate generic over internerMichael Goulet-106/+107
2024-06-14Use a consistent way to filter out bounds instead of splitting it into three ↵Oli Scherer-11/+6
places
2024-06-13Address nitsMichael Goulet-23/+30
- Remove the ValuePairs glob import - Make DummyPairs -> ValuePairs::Dummy and make it bug more - Fix WC - Make interner return `impl IntoIterator`s
2024-06-13Fix some TODOsMichael Goulet-5/+4
2024-06-13Finish uplifting all of structural_traitsMichael Goulet-187/+156
2024-06-13Rework most of structural_traits to be Interner-agnosticMichael Goulet-103/+114
2024-06-13LangItem-ify Coroutine trait in solversMichael Goulet-9/+13
2024-06-13Check that alias-relate terms are WF if reporting an error in alias-relateMichael Goulet-0/+24
2024-06-12Rollup merge of #126353 - compiler-errors:move-match, r=lcnrJubilee-2/+123
Move `MatchAgainstFreshVars` to old solver Small change I noticed when trying to uplift the relations to the new trait solver.
2024-06-12Rollup merge of #126142 - compiler-errors:trait-ref-split, r=jackh726Jubilee-99/+98
Harmonize using root or leaf obligation in trait error reporting When #121826 changed the error reporting to use root obligation and not the leafmost obligation, it didn't actually make sure that all the other diagnostics helper functions used the right obligation. Specifically, when reporting similar impl candidates we are looking for impls of the root obligation, but trying to match them against the trait ref of the leaf obligation. This does a few other miscellaneous changes. There's a lot more clean-up that could be done here, but working with this code is really grief-inducing due to how messy it has become over the years. Someone really needs to show it love. 😓 r? ``@estebank`` Fixes #126129
2024-06-12Rebase falloutMichael Goulet-7/+8
2024-06-12Stop passing traitref/traitpredicate by refMichael Goulet-30/+26
2024-06-12Stop passing both trait pred and trait refMichael Goulet-16/+18
2024-06-12Harmonize use of leaf and root obligation in trait error reportingMichael Goulet-53/+53
2024-06-12Also passthrough for projection clausesMichael Goulet-1/+3
2024-06-12better error message for normalizes-to ambiguitiesMichael Goulet-0/+16
2024-06-12Walk into alias-eq nested goals even if normalization failsMichael Goulet-7/+15
2024-06-12Use Variance glob import everywhereMichael Goulet-4/+4
2024-06-12Move MatchAgainstFreshVars to old solverMichael Goulet-2/+123
2024-06-12Spell out other trait diagnosticAlex Macleod-1/+1
2024-06-12Rollup merge of #126301 - nnethercote:sort-crate-attributes, r=davidtwcoJubilee-3/+5
Use `tidy` to sort crate attributes for all compiler crates. We already do this for a number of crates, e.g. `rustc_middle`, `rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`. For the ones we don't, in many cases the attributes are a mess. - There is no consistency about order of attribute kinds (e.g. `allow`/`deny`/`feature`). - Within attribute kind groups (e.g. the `feature` attributes), sometimes the order is alphabetical, and sometimes there is no particular order. - Sometimes the attributes of a particular kind aren't even grouped all together, e.g. there might be a `feature`, then an `allow`, then another `feature`. This commit extends the existing sorting to all compiler crates, increasing consistency. If any new attribute line is added there is now only one place it can go -- no need for arbitrary decisions. Exceptions: - `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`, because they have no crate attributes. - `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's ignored in `rustfmt.toml`). r? `@davidtwco`
2024-06-12Rollup merge of #126187 - surechen:fix_125997, r=oli-obkJubilee-0/+45
For E0277 suggest adding `Result` return type for function when using QuestionMark `?` in the body. Adding suggestions for following function in E0277. ```rust fn main() { let mut _file = File::create("foo.txt")?; } ``` to ```rust fn main() -> Result<(), Box<dyn std::error::Error>> { let mut _file = File::create("foo.txt")?; return Ok(()); } ``` According to the issue #125997, only the code examples in the issue are targeted, but the issue covers a wider range of situations. <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r​? <reviewer name> -->
2024-06-12Use `tidy` to sort crate attributes for all compiler crates.Nicholas Nethercote-3/+5
We already do this for a number of crates, e.g. `rustc_middle`, `rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`. For the ones we don't, in many cases the attributes are a mess. - There is no consistency about order of attribute kinds (e.g. `allow`/`deny`/`feature`). - Within attribute kind groups (e.g. the `feature` attributes), sometimes the order is alphabetical, and sometimes there is no particular order. - Sometimes the attributes of a particular kind aren't even grouped all together, e.g. there might be a `feature`, then an `allow`, then another `feature`. This commit extends the existing sorting to all compiler crates, increasing consistency. If any new attribute line is added there is now only one place it can go -- no need for arbitrary decisions. Exceptions: - `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`, because they have no crate attributes. - `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's ignored in `rustfmt.toml`).
2024-06-12Auto merge of #126130 - compiler-errors:goal-relations, r=lcnrbors-14/+11
Make `ObligationEmittingRelation`s emit `Goal` rather than `Obligation` Helps avoid needing to uplift `Obligation` into the solver. We still can't get rid of `ObligationCause`, but we can keep it as an associated type for `InferCtxtLike` and just give it a `dummy` function. There's some shuttling between `Goal` and `Obligation` that may be perf-sensitive... Let's see what rust-timer says. r? lcnr
2024-06-12For E0277 suggest adding `Result` return type for function which using ↵surechen-0/+45
QuesionMark `?` in the body.
2024-06-11Rollup merge of #126055 - lengrongfu:master, r=pnkfelix许杰友 Jieyou Xu (Joe)-2/+6
Expand list of trait implementers in E0277 when calling rustc with --verbose Fixes: https://github.com/rust-lang/rust/issues/125984 - Build `rustc` use `./x build`. - Test result <img width="634" alt="image" src="https://github.com/rust-lang/rust/assets/15009201/89377059-2316-492b-a38a-fa33adfc9793"> - vim test.rs ```rust trait Reconcile { fn reconcile(&self); } // Implementing the trait for some types impl Reconcile for bool { fn reconcile(&self) { println!("Reconciling bool"); } } impl Reconcile for i8 { fn reconcile(&self) { println!("Reconciling i8"); } } impl Reconcile for i16 { fn reconcile(&self) { println!("Reconciling i16"); } } impl Reconcile for i32 { fn reconcile(&self) { println!("Reconciling i32"); } } impl Reconcile for i64 { fn reconcile(&self) { println!("Reconciling i64"); } } impl Reconcile for u8 { fn reconcile(&self) { println!("Reconciling u8"); } } impl Reconcile for u16 { fn reconcile(&self) { println!("Reconciling u16"); } } impl Reconcile for u32 { fn reconcile(&self) { println!("Reconciling u32"); } } impl Reconcile for i128 { fn reconcile(&self) { println!("Reconciling u32"); } } impl Reconcile for u128 { fn reconcile(&self) { println!("Reconciling u32"); } } fn process<T: Reconcile>(item: T) { item.reconcile(); } fn main() { let value = String::from("This will cause an error"); process(value); // This line will cause a compilation error } ```
2024-06-11Try not to make obligations in handle_opaque_typeMichael Goulet-8/+7
2024-06-11Get rid of PredicateObligationsMichael Goulet-6/+4
2024-06-11Rollup merge of #126258 - oli-obk:recursive_rpit, r=lcnr许杰友 Jieyou Xu (Joe)-1/+1
Do not define opaque types when selecting impls fixes #126117 r? `@lcnr` for inconsistency with next solver
2024-06-11Revert "When checking whether an impl applies, constrain hidden types of ↵Oli Scherer-1/+1
opaque types." This reverts commit 29a630eb72ffb94c3708947afae1e948ad3cb189.
2024-06-11Auto merge of #126139 - compiler-errors:specializes, r=lcnrbors-25/+18
Only compute `specializes` query if (min)specialization is enabled in the crate of the specializing impl Fixes (after backport) https://github.com/rust-lang/rust/issues/125197 ### What https://github.com/rust-lang/rust/pull/122791 makes it so that inductive cycles are no longer hard errors. That means that when we are testing, for example, whether these impls overlap: ```rust impl PartialEq<Self> for AnyId { fn eq(&self, _: &Self) -> bool { todo!() } } impl<T: Identifier> PartialEq<T> for AnyId { fn eq(&self, _: &T) -> bool { todo!() } } ``` ...given... ```rust pub trait Identifier: Display + 'static {} impl<T> Identifier for T where T: PartialEq + Display + 'static {} ``` Then we try to see if the second impl holds given `T = AnyId`. That requires `AnyId: Identifier`, which requires that `AnyId: PartialEq`, which is satisfied by these two impl candidates... The `PartialEq<T>` impl is a cycle, and we used to winnow it when we used to treat inductive cycles as errors. However, now that we don't winnow it, this means that we *now* try calling `candidate_should_be_dropped_in_favor_of`, which tries to check whether one of the impls specializes the other: the `specializes` query. In that query, we currently bail early if the impl is local. However, in a foreign crate, we try to compute if the two impls specialize each other by doing trait solving. This may itself lead to the same situation where we call `specializes`, which will lead to a query cycle. ### How does this fix the problem We now record whether specialization is enabled in foreign crates, and extend this early-return behavior to foreign impls too. This means that we can only encounter these cycles if we truly have a specializing impl from a crate with specialization enabled. ----- r? `@oli-obk` or `@lcnr`
2024-06-07Only compute specializes query if specialization is enabled in the crate of ↵Michael Goulet-25/+18
the specialized impl
2024-06-07Rollup merge of #126089 - wutchzone:option_take_if, r=scottmcmMatthias Krüger-1/+0
Stabilize Option::take_if Closes #98934 ed: FCP complete in https://github.com/rust-lang/rust/issues/98934#issuecomment-2104627082
2024-06-06Stabilize Option::take_ifDaniel Sedlak-1/+0
2024-06-06Uplift TypeRelation and RelateMichael Goulet-6/+6
2024-06-06Uplift TypeErrorMichael Goulet-6/+7
2024-06-06Auto merge of #125958 - BoxyUwU:remove_const_ty, r=lcnrbors-155/+144
Remove the `ty` field from type system `Const`s Fixes #125556 Fixes #122908 Part of the work on `adt_const_params`/`generic_const_param_types`/`min_generic_const_exprs`/generally making the compiler nicer. cc rust-lang/project-const-generics#44 Please review commit-by-commit otherwise I wasted a lot of time not just squashing this into a giant mess (and also it'll be SO much nicer because theres a lot of fluff changes mixed in with other more careful changes if looking via File Changes --- Why do this? - The `ty` field keeps causing ICEs and weird behaviour due to it either being treated as "part of the const" or it being forgotten about leading to ICEs. - As we move forward with `adt_const_params` and a potential `min_generic_const_exprs` it's going to become more complex to actually lower the correct `Ty<'tcx>` - It muddles the idea behind how we check `Const` arguments have the correct type. By having the `ty` field it may seem like we ought to be relating it when we relate two types, or that its generally important information about the `Const`. - Brings the compiler more in line with `a-mir-formality` as that also tracks the type of type system `Const`s via `ConstArgHasType` bounds in the env instead of on the `Const` itself. - A lot of stuff is a lot nicer when you dont have to pass around the type of a const lol. Everywhere we construct `Const` is now significantly nicer :sweat_smile: See #125671's description for some more information about the `ty` field --- General summary of changes in this PR: - Add `Ty` to `ConstKind::Value` as otherwise there is no way to implement `ConstArgHasType` to ensure that const arguments are correctly typed for the parameter when we stop creating anon consts for all const args. It's also just incredibly difficult/annoying to thread the correct `Ty` around to a bunch of ctfe functions otherwise. - Fully implement `ConstArgHasType` in both the old and new solver. Since it now has no reliance on the `ty` field it serves its originally intended purpose of being able to act as a double check that trait vs impls have correctly typed const parameters. It also will now be able to be responsible for checking types of const arguments to parameters under `min_generic_const_exprs`. - Add `Ty` to `mir::Const::Ty`. I dont have a great understanding of why mir constants are setup like this to be honest. Regardless they need to be able to determine the type of the const and the easiest way to make this happen was to simply store the `Ty` along side the `ty::Const`. Maybe we can do better here in the future but I'd have to spend way more time looking at everywhere we use `mir::Const`. - rustdoc has its own `Const` which also has a `ty` field. It was relatively easy to remove this. --- r? `@lcnr` `@compiler-errors`
2024-06-06Expand list of trait implementers in E0277 when calling rustc with --verboserongfu.leng-2/+6
Signed-off-by: rongfu.leng <lenronfu@gmail.com>
2024-06-05Fully implement `ConstArgHasType`Boxy-103/+110
2024-06-05Add `Ty` to `ConstKind::Value`Boxy-6/+12
2024-06-05Basic removal of `Ty` from places (boring)Boxy-59/+35
2024-06-05Auto merge of #126038 - matthiaskrgr:rollup-h4rm3x2, r=matthiaskrgrbors-35/+24
Rollup of 9 pull requests Successful merges: - #124840 (resolve: mark it undetermined if single import is not has any bindings) - #125622 (Winnow private method candidates instead of assuming any candidate of the right name will apply) - #125648 (Remove unused(?) `~/rustsrc` folder from docker script) - #125672 (Add more ABI test cases to miri (RFC 3391)) - #125800 (Fix `mut` static task queue in SGX target) - #125871 (Orphanck[old solver]: Consider opaque types to never cover type parameters) - #125893 (Handle all GVN binops in a single place.) - #126008 (Port `tests/run-make-fulldeps/issue-19371` to ui-fulldeps) - #126032 (Update description of the `IsTerminal` example) r? `@ghost` `@rustbot` modify labels: rollup
2024-06-05Rollup merge of #125871 - fmease:fix-orphanck-opaques, r=lcnrMatthias Krüger-35/+24
Orphanck[old solver]: Consider opaque types to never cover type parameters This fixes an oversight of mine in #117164. The change itself has already been FCP'ed. This only affects the old solver, the next solver already correctly rejects the added test since #117164. r? ``@lcnr``
2024-06-05Rollup merge of #125792 - compiler-errors:dont-drop-upcast-cand, r=lcnrMatthias Krüger-0/+6
Don't drop `Unsize` candidate in intercrate mode Fixes #125767
2024-06-04Orphanck: Consider opaque types to never cover type parametersLeón Orell Valerian Liehr-35/+24
2024-06-04Rollup merge of #125717 - ↵Michael Goulet-8/+18
weiznich:move/do_not_recommend_to_diganostic_namespace, r=compiler-errors Refactor `#[diagnostic::do_not_recommend]` support This commit refactors the `#[do_not_recommend]` support in the old parser to also apply to projection errors and not only to selection errors. This allows the attribute to be used more widely. Part of #51992 r? `@compiler-errors` <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r​? <reviewer name> -->