summary refs log tree commit diff
path: root/compiler/rustc_hir_analysis/src
AgeCommit message (Collapse)AuthorLines
2023-11-09check binders with bound vars for global bounds that don't holdRémy Rakic-1/+2
(instead of just late bound vars) (cherry picked from commit 2beca157c96329da93320de83bdb7192bf02fa96)
2023-09-30Auto merge of #115933 - oli-obk:simd_shuffle_const, r=workingjubileebors-21/+23
Prototype using const generic for simd_shuffle IDX array cc https://github.com/rust-lang/rust/issues/85229 r? `@workingjubilee` on the design TLDR: there is now a `fn simd_shuffle_generic<T, U, const IDX: &'static [u32]>(x: T, y: T) -> U;` intrinsic that allows replacing ```rust simd_shuffle(a, b, const { stuff }) ``` with ```rust simd_shuffle_generic::<_, _, {&stuff}>(a, b) ``` which makes the compiler implementations much simpler, if we manage to at some point eliminate `simd_shuffle`. There are some issues with this today though (can't do math without bubbling it up in the generic arguments). With this change, we can start porting the simple cases and get better data on the others.
2023-09-29Rollup merge of #112123 - bvanjoi:fix-98562, r=compiler-errorsMatthias Krüger-28/+39
fix(suggestion): insert projection to associated types Fixes #98562 This PR has fixed some help suggestions for unsupported syntax, such as `fn f<T>(_:T) where T: IntoIterator, std::iter::IntoIterator::Item = () {}` to `fn f<T: IntoIterator<Item = ()>>(_T) {}`.
2023-09-29fix(suggestion): insert projection to associated typesbohan-28/+39
2023-09-29Rollup merge of #116253 - asquared31415:adt_const_params_feature, ↵Matthias Krüger-32/+57
r=compiler-errors Make `adt_const_params` feature suggestion consistent with other features and improve when it is emitted Makes the suggestion to add `adt_const_params` formatted like every other feature gate (notably this makes it such that the playground recognizes it). Additionally improves the situations in which that help is emitted so that it's only emitted when the type would be valid or the type *could* be valid (using a slightly incorrect heuristic that favors suggesting the feature over not) instead of, for example, implying that adding the feature would allow the use of `String`. Also adds the "the only supported types are integers, `bool` and `char`" note to the errors on fn and raw pointers. r? `@compiler-errors`
2023-09-29Auto merge of #115821 - obeis:hir-analysis-migrate-diagnostics-5, ↵bors-122/+202
r=compiler-errors Migrate `rustc_hir_analysis` to session diagnostic [Part 5] Finishing `coherence/builtin.rs` file
2023-09-28make adt_const_params feature suggestion more consistent with others and ↵asquared31415-32/+57
only suggest it when the type can probably work
2023-09-28Auto merge of #115659 - compiler-errors:itp, r=cjgillotbors-132/+3
Stabilize `impl_trait_projections` Closes #115659 ## TL;DR: This allows us to mention `Self` and `T::Assoc` in async fn and return-position `impl Trait`, as you would expect you'd be able to. Some examples: ```rust #![feature(return_position_impl_trait_in_trait, async_fn_in_trait)] // (just needed for final tests below) // ---------------------------------------- // struct Wrapper<'a, T>(&'a T); impl Wrapper<'_, ()> { async fn async_fn() -> Self { //^ Previously rejected because it returns `-> Self`, not `-> Wrapper<'_, ()>`. Wrapper(&()) } fn impl_trait() -> impl Iterator<Item = Self> { //^ Previously rejected because it mentions `Self`, not `Wrapper<'_, ()>`. std::iter::once(Wrapper(&())) } } // ---------------------------------------- // trait Trait<'a> { type Assoc; fn new() -> Self::Assoc; } impl Trait<'_> for () { type Assoc = (); fn new() {} } impl<'a, T: Trait<'a>> Wrapper<'a, T> { async fn mk_assoc() -> T::Assoc { //^ Previously rejected because `T::Assoc` doesn't mention `'a` in the HIR, // but ends up resolving to `<T as Trait<'a>>::Assoc`, which does rely on `'a`. // That's the important part -- the elided trait. T::new() } fn a_few_assocs() -> impl Iterator<Item = T::Assoc> { //^ Previously rejected for the same reason [T::new(), T::new(), T::new()].into_iter() } } // ---------------------------------------- // trait InTrait { async fn async_fn() -> Self; fn impl_trait() -> impl Iterator<Item = Self>; } impl InTrait for &() { async fn async_fn() -> Self { &() } //^ Previously rejected just like inherent impls fn impl_trait() -> impl Iterator<Item = Self> { //^ Previously rejected just like inherent impls [&()].into_iter() } } ``` ## Technical: Lifetimes in return-position `impl Trait` (and `async fn`) are duplicated as early-bound generics local to the opaque in order to make sure we are able to substitute any late-bound lifetimes from the function in the opaque's hidden type. (The [dev guide](https://rustc-dev-guide.rust-lang.org/return-position-impl-trait-in-trait.html#aside-opaque-lifetime-duplication) has a small section about why this is necessary -- this was written for RPITITs, but it applies to all RPITs) Prior to #103491, all of the early-bound lifetimes not local to the opaque were replaced with `'static` to avoid issues where relating opaques caused their *non-captured* lifetimes to be related. This `'static` replacement led to strange and possibly unsound behaviors (https://github.com/rust-lang/rust/issues/61949#issuecomment-508836314) (https://github.com/rust-lang/rust/issues/53613) when referencing the `Self` type alias in an impl or indirectly referencing a lifetime parameter via a projection type (via a `T::Assoc` projection without an explicit trait), since lifetime resolution is performed on the HIR, when neither `T::Assoc`-style projections or `Self` in impls are expanded. Therefore an error was implemented in #62849 to deny this subtle behavior as a known limitation of the compiler. It was attempted by `@cjgillot` to fix this in #91403, which was subsequently unlanded. Then it was re-attempted to much success (🎉) in #103491, which is where we currently are in the compiler. The PR above (#103491) fixed this issue technically by *not* replacing the opaque's parent lifetimes with `'static`, but instead using variance to properly track which lifetimes are captured and are not. The PR gated any of the "side-effects" of the PR behind a feature gate (`impl_trait_projections`) presumably to avoid having to involve T-lang or T-types in the PR as well. `@cjgillot` can clarify this if I'm misunderstanding what their intention was with the feature gate. Since we're not replacing (possibly *invariant*!) lifetimes with `'static` anymore, there are no more soundness concerns here. Therefore, this PR removes the feature gate. Tests: * `tests/ui/async-await/feature-self-return-type.rs` * `tests/ui/impl-trait/feature-self-return-type.rs` * `tests/ui/async-await/issues/issue-78600.rs` * `tests/ui/impl-trait/capture-lifetime-not-in-hir.rs` --- r? cjgillot on the impl (not much, just removing the feature gate) I'm gonna mark this as FCP for T-lang and T-types.
2023-09-28don't clone copy typesMatthias Krüger-1/+1
2023-09-27Rollup merge of #116149 - compiler-errors:anonymize, r=lcnrMatthias Krüger-4/+25
Anonymize binders for `refining_impl_trait` check We're naively using the equality impl for `ty::Clause` in the refinement check, which is okay *except* for binders, which carry some information about where they come from in the AST. Those locations are not gonna be equal between traits and impls, so anonymize those clauses so that this doesn't matter. Fixes #116135
2023-09-27Auto merge of #116163 - compiler-errors:lazyness, r=oli-obkbors-36/+42
Don't store lazyness in `DefKind::TyAlias` 1. Don't store lazyness of a type alias in its `DefKind`, but instead via a query. 2. This allows us to treat type aliases as lazy if `#[feature(lazy_type_alias)]` *OR* if the alias contains a TAIT, rather than having checks for both in separate parts of the codebase. r? `@oli-obk` cc `@fmease`
2023-09-26Auto merge of #116144 - lcnr:subst-less, r=oli-obkbors-11/+12
subst -> instantiate continues #110793, there are still quite a few uses of `subst` and `substitute`, but changing them all in the same PR was a bit too much, so I've stopped here for now.
2023-09-26Anonymize binders for refining_impl_trait checkMichael Goulet-4/+25
2023-09-26subst -> instantiatelcnr-11/+12
2023-09-26Don't store lazyness in DefKindMichael Goulet-36/+42
2023-09-26Auto merge of #116072 - compiler-errors:rpitit-implied-bounds, r=aliemjaybors-8/+88
Use placeholders to prevent using inferred RPITIT types to imply their own well-formedness The issue here is that we use the same signature to do RPITIT inference as we do to compute implied bounds. To fix this, when gathering the assumed wf types for the method, we replace all of the infer vars (that will be eventually used to infer RPITIT types) with type placeholders, which imply nothing about lifetime bounds. This solution kind of sucks, but I'm not certain there's another feasible way to fix this. If anyone has a better solution, I'd be glad to hear it. My naive first solution was, instead of using placeholders, to replace the signature with the RPITIT projections that it originally started out with. But turns out that we can't just use the unnormalized signature of the trait method in `implied_outlives_bounds` since we normalize during WF computation -- that would cause a query cycle in `collect_return_position_impl_trait_in_trait_tys`. idk who to request review... r? `@lcnr` or `@aliemjay` i guess. Fixes #116060
2023-09-24Added additional visit steps to visit_generic_param() in order to avoid ICE ↵Lenko Donchev-16/+15
on no bound vars.
2023-09-24Remove span from BrAnon.Camille GILLOT-6/+6
2023-09-24Rollup merge of #116073 - compiler-errors:poly-sigs, r=b-naberMatthias Krüger-8/+8
Allow higher-ranked fn sigs in `ValuePairs` For better bookkeeping -- only affects diagnostic path. Allow reporting signature mismatches like "signature"s and not "fn pointer"s. Improves https://github.com/rust-lang/rust/pull/115897#discussion_r1331940846
2023-09-23Remove GeneratorWitness and rename GeneratorWitnessMIR.Camille GILLOT-7/+1
2023-09-23Enable drop_tracking_mir by default.Camille GILLOT-8/+1
2023-09-23Auto merge of #116081 - compiler-errors:closure-captures-sized, r=cjgillotbors-1/+20
Check that closure/generator's interior/capture types are sized check that closure upvars and generator interiors are sized. this check is only necessary when `unsized_fn_params` or `unsized_locals` is enabled, so only check if those are active. Fixes #93622 Fixes #61335 Fixes #68543
2023-09-23Auto merge of #116045 - notriddle:notriddle/issue-83556, r=cjgillotbors-3/+19
diagnostics: avoid mismatch between variance index and hir generic This happens because variances are constructed from ty generics, and ty generics are always constructed with lifetimes first. https://github.com/rust-lang/rust/blob/b3aa8e7168a3d940122db3561289ffbf3f587262/compiler/rustc_hir_analysis/src/collect/generics_of.rs#L248-L269 Fixes #83556
2023-09-22diagnostics: simpler 83556 handling by bailing outMichael Howell-8/+3
2023-09-23Check types live across yields in generators tooMichael Goulet-1/+20
2023-09-22Allow higher-ranked fn sigs in ValuePairsMichael Goulet-8/+8
2023-09-22Need to use hybrid param-env to make sure implication is not circularMichael Goulet-2/+13
2023-09-22Use placeholders to prevent using inferred RPITIT types to imply their own ↵Michael Goulet-6/+75
WF-ness
2023-09-22Rollup merge of #116039 - estebank:nested-tait, r=compiler-errorsMatthias Krüger-2/+7
Account for nested `impl Trait` in TAIT Fix #116031. r? `@compiler-errors`
2023-09-21diagnostics: avoid mismatch between variance index and hir genericMichael Howell-3/+24
This happens because variances are constructed from ty generics, and ty generics are always constructed with lifetimes first. See compiler/rustc_hir_analysis/src/collect/generics_of.rs:248-269 Fixes #83556
2023-09-21Auto merge of #115897 - eduardosm:check-fn-sig, r=compiler-errorsbors-64/+117
rustc_hir_analysis: add a helper to check function the signature mismatches This function is now used to check `#[panic_handler]`, `start` lang item, `main`, `#[start]` and intrinsic functions. The diagnosis produced are now closer to the ones produced by trait/impl method signature mismatch. This is the first time I do anything with rustc_hir_analysis/rustc_hir_typeck, so comments and suggestions about things I did wrong or that could be improved will be appreciated.
2023-09-21Record asyncness span in HIRMichael Goulet-4/+4
2023-09-21Account for nested `impl Trait` in TAITEsteban Küber-2/+7
Fix #116031.
2023-09-20Rollup merge of #115566 - ↵Guillaume Gomez-5/+5
zirconium-n:issue-107250-clean-up-unused-to-predicate, r=oli-obk clean up unneeded `ToPredicate` impls Part of #107250. Removed all totally unused impls. And inlined two impls not need to satisify trait bound. r? `@oli-obk`
2023-09-20Migrate `rustc_hir_analysis` to session diagnosticObei Sideg-122/+202
Part 5: Finishing `coherence/builtin.rs` file
2023-09-20Auto merge of #115486 - compiler-errors:dont-capture-late-pls, r=cjgillotbors-26/+65
Correctly deny late-bound lifetimes from parent in anon consts and TAITs Reuse the `AnonConstBoundary` scope (introduced in #108553, renamed in this PR to `LateBoundary`) to deny late-bound vars of *all* kinds (ty/const/lifetime) in anon consts and TAITs. Side-note, but I would like to consolidate this with the error reporting for RPITs (E0657): https://github.com/rust-lang/rust/blob/c4f25777a08cd64b710e8a9a6159e67cbb35e6f5/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs#L733-L754 but the semantics about what we're allowed to capture there are slightly different, so I'm leaving that untouched. Fixes #115474
2023-09-20remove `impl<'tcx> ToPredicate<'tcx, Clause<'tcx>> for ↵Ziru Niu-5/+5
PolyProjectionPredicate<'tcx>`
2023-09-19wrap fn sig binders in fn ptrEduardo Sánchez Muñoz-10/+7
2023-09-19rustc_hir_analysis: add a helper to check function the signature mismatchesEduardo Sánchez Muñoz-64/+120
This function is now used to check `#[panic_handler]`, `start` lang item, `main`, `#[start]` and intrinsic functions. The diagnosis produced are now closer to the ones produced by trait/impl method signature mismatch.
2023-09-19Don't complain on a single non-exhaustive 1-zstMichael Goulet-19/+29
2023-09-18Prototype using const generic for simd_shuffle IDX arrayOli Scherer-21/+23
2023-09-17Auto merge of #115334 - RalfJung:transparent-aligned-zst, r=compiler-errorsbors-37/+21
repr(transparent): it's fine if the one non-1-ZST field is a ZST This code currently gets rejected: ```rust #[repr(transparent)] struct MyType([u16; 0]) ``` That clearly seems like a bug to me: `repr(transparent)` [got defined ](https://github.com/rust-lang/rust/issues/77841#issuecomment-716575747) as having any number of 1-ZST fields plus optionally one more field; `MyType` clearly satisfies that definition. This PR changes the `repr(transparent)` logic to actually match that definition.
2023-09-16Rollup merge of #115860 - Soveu:varargs2, r=WaffleLapkinMatthias Krüger-1/+1
Enable varargs support for AAPCS calling convention Welp, I was looking for a reason why this shouldn't be stabilized after so long... and here it is.
2023-09-15Auto merge of #115853 - obeis:hir-analysis-migrate-diagnostics-6, ↵bors-77/+88
r=compiler-errors Migrate `rustc_hir_analysis` to session diagnostic [Part 6] Part 6: Finish `coherence/inherent_impls.rs` file
2023-09-14Enable varargs support for AAPCS calling conventionSoveu-1/+1
This is the default calling convention for ARM - it is used for extern "C", therefore it supports varargs.
2023-09-14Auto merge of #115677 - matthewjasper:let-expr-recovery, r=b-naberbors-1/+5
Improve invalid let expression handling - Move all of the checks for valid let expression positions to parsing. - Add a field to ExprKind::Let in AST/HIR to mark whether it's in a valid location. - Suppress some later errors and MIR construction for invalid let expressions. - Fix a (drop) scope issue that was also responsible for #104172. Fixes #104172 Fixes #104868
2023-09-14Migrate `rustc_hir_analysis` to session diagnosticObei Sideg-77/+88
Part 6: Finish `coherence/inherent_impls.rs`
2023-09-14Paper over an accidental regressionOli Scherer-1/+9
2023-09-12Auto merge of #115699 - RalfJung:interpret-abi-compat, r=oli-obkbors-0/+8
interpret: change ABI-compat test to be type-based This makes the test consistent across targets. Otherwise the chances are very high that ABI mismatches get accepted on x86_64 but still fail on many other targets with more complicated ABIs. This implements (most of) the rules described in https://github.com/rust-lang/rust/pull/115476.
2023-09-11Move let expression checking to parsingMatthew Jasper-1/+1
There was an incomplete version of the check in parsing and a second version in AST validation. This meant that some, but not all, invalid uses were allowed inside macros/disabled cfgs. It also means that later passes have a hard time knowing when the let expression is in a valid location, sometimes causing ICEs. - Add a field to ExprKind::Let in AST/HIR to mark whether it's in a valid location. - Suppress later errors and MIR construction for invalid let expressions.