summary refs log tree commit diff
path: root/compiler/rustc_hir_analysis/src
AgeCommit message (Collapse)AuthorLines
2024-06-07Auto merge of #125918 - oli-obk:const_block_ice, r=compiler-errorsbors-15/+13
Revert: create const block bodies in typeck via query feeding as per the discussion in https://github.com/rust-lang/rust/pull/125806#discussion_r1622563948 It was a mistake to try to shoehorn const blocks and some specific anon consts into the same box and feed them during typeck. It turned out not simplifying anything (my hope was that we could feed `type_of` to start avoiding the huge HIR matcher, but that didn't work out), but instead making a few things more fragile. reverts the const-block-specific parts of https://github.com/rust-lang/rust/pull/124650 `@bors` rollup=never had a small perf impact previously fixes https://github.com/rust-lang/rust/issues/125846 r? `@compiler-errors`
2024-06-07Revert "Create const block DefIds in typeck instead of ast lowering"Oli Scherer-15/+13
This reverts commit ddc5f9b6c1f21da5d4596bf7980185a00984ac42.
2024-06-06Uplift TypeErrorMichael Goulet-0/+1
2024-06-06Auto merge of #124482 - spastorino:unsafe-extern-blocks, r=oli-obkbors-9/+13
Unsafe extern blocks This implements RFC 3484. Tracking issue #123743 and RFC https://github.com/rust-lang/rfcs/pull/3484 This is better reviewed commit by commit.
2024-06-05Misc fixes (pattern type lowering, cfi, pretty printing)Boxy-12/+11
2024-06-05Basic removal of `Ty` from places (boring)Boxy-48/+25
2024-06-05Unify optional param info with object lifetime default boolean into an enum ↵Oli Scherer-32/+48
that exhaustively supports all call sites
2024-06-05Remove `allows_infer` now that every use of it is delegated to `HirTyLowerer`Oli Scherer-7/+0
2024-06-05Only collect infer vars to error about in case infer vars are actually forbiddenOli Scherer-85/+95
2024-06-05Remove an `Option` and instead eagerly create error lifetimesOli Scherer-52/+35
2024-06-05Simplify some code paths and remove an unused fieldOli Scherer-15/+3
`ct_infer` and `lower_ty` will correctly result in an error constant or type respectively, as they go through a `HirTyLowerer` method (just like `HirTyLowerer::allow_infer` is a method implemented by both implementors
2024-06-05Use a `LocalDefId` for `HirTyLowerer::item_def_id`, since we only ever (can) ↵Oli Scherer-13/+11
use it for local items
2024-06-04Add safe/unsafe to static inside extern blocksSantiago Pastorino-1/+2
2024-06-04Handle safety keyword for extern block inner itemsSantiago Pastorino-8/+11
2024-06-04Rollup merge of #125667 - oli-obk:taintify, r=TaKO8KiMichael Goulet-1/+3
Silence follow-up errors directly based on error types and regions During type_of, we used to just return an error type if there were any errors encountered. This is problematic, because it means a struct declared as `struct Foo<'static>` will end up not finding any inherent or trait impls because those impl blocks' `Self` type will be `{type error}` instead of `Foo<'re_error>`. Now it's the latter, silencing nonsensical follow-up errors about `Foo` not having any methods. Unfortunately that now allows for new follow-up errors, because borrowck treats `'re_error` as `'static`, causing nonsensical errors about non-error lifetimes not outliving `'static`. So what I also did was to just strip all outlives bounds that borrowck found, thus never letting it check them. There are probably more nuanced ways to do this, but I worried there would be other nonsensical errors if some outlives bounds were missing. Also from the test changes, it looked like an improvement everywhere.
2024-06-04Rollup merge of #125750 - compiler-errors:expect, r=lcnr许杰友 Jieyou Xu (Joe)-3/+5
Align `Term` methods with `GenericArg` methods, add `Term::expect_*` * `Term::ty` -> `Term::as_type`. * `Term::ct` -> `Term::as_const`. * Adds `Term::expect_type` and `Term::expect_const`, and uses them in favor of `.ty().unwrap()`, etc. I could also shorten these to `as_ty` and then do `GenericArg::as_ty` as well, but I do think the `as_` is important to signal that this is a conversion method, and not a getter, like `Const::ty` is. r? types
2024-06-04Rollup merge of #125608 - oli-obk:subsequent_lifetime_errors, r=BoxyUwU许杰友 Jieyou Xu (Joe)-51/+59
Avoid follow-up errors if the number of generic parameters already doesn't match fixes #125604 best reviewed commit-by-commit
2024-06-04Auto merge of #125380 - compiler-errors:wc-obj-safety, r=oli-obkbors-3/+3
Make `WHERE_CLAUSES_OBJECT_SAFETY` a regular object safety violation #### The issue In #50781, we have known about unsound `where` clauses in function arguments: ```rust trait Impossible {} trait Foo { fn impossible(&self) where Self: Impossible; } impl Foo for &() { fn impossible(&self) where Self: Impossible, {} } // `where` clause satisfied for the object, meaning that the function now *looks* callable. impl Impossible for dyn Foo {} fn main() { let x: &dyn Foo = &&(); x.impossible(); } ``` ... which currently segfaults at runtime because we try to call a method in the vtable that doesn't exist. :( #### What did u change This PR removes the `WHERE_CLAUSES_OBJECT_SAFETY` lint and instead makes it a regular object safety violation. I choose to make this into a hard error immediately rather than a `deny` because of the time that has passed since this lint was authored, and the single (1) regression (see below). That means that it's OK to mention `where Self: Trait` where clauses in your trait, but making such a trait into a `dyn Trait` object will report an object safety violation just like `where Self: Sized`, etc. ```rust trait Impossible {} trait Foo { fn impossible(&self) where Self: Impossible; // <~ This definition is valid, just not object-safe. } impl Foo for &() { fn impossible(&self) where Self: Impossible, {} } fn main() { let x: &dyn Foo = &&(); // <~ THIS is where we emit an error. } ``` #### Regressions From a recent crater run, there's only one crate that relies on this behavior: https://github.com/rust-lang/rust/pull/124305#issuecomment-2122381740. The crate looks unmaintained and there seems to be no dependents. #### Further We may later choose to relax this (e.g. when the where clause is implied by the supertraits of the trait or something), but this is not something I propose to do in this FCP. For example, given: ``` trait Tr { fn f(&self) where Self: Blanket; } impl<T: ?Sized> Blanket for T {} ``` Proving that some placeholder `S` implements `S: Blanket` would be sufficient to prove that the same (blanket) impl applies for both `Concerete: Blanket` and `dyn Trait: Blanket`. Repeating here that I don't think we need to implement this behavior right now. ---- r? lcnr
2024-06-03Align Term methods with GenericArg methodsMichael Goulet-3/+5
2024-06-03Nits and formattingMichael Goulet-18/+11
2024-06-03check_is_object_safe -> is_object_safeMichael Goulet-3/+3
2024-06-03Provide previous generic arguments to `provided_kind`Oli Scherer-17/+4
2024-06-03Always provide previous generic argumentsOli Scherer-30/+20
2024-06-03Explain some code duplicationOli Scherer-0/+4
2024-06-03Add cycle errors to ScrubbedTraitError to remove a couple more calls to ↵Michael Goulet-1/+2
new_with_diagnostics
2024-06-03Use ScrubbedTraitError in more placesMichael Goulet-4/+5
2024-06-03Opt-in diagnostics reporting to avoid doing extra work in the new solverMichael Goulet-25/+34
2024-06-03Make TraitEngines generic over errorMichael Goulet-5/+6
2024-06-03Mark all extraneous generic args as errorsOli Scherer-0/+19
2024-06-03Mark all missing generic args as errorsOli Scherer-9/+30
2024-06-03Store indices of generic args instead of spans, as the actual entries are ↵Oli Scherer-16/+5
unused, just the number of entries is checked. The indices will be used in a follow-up commit
2024-06-03Avoid an `Option` that is always `Some`Oli Scherer-12/+8
2024-06-03Hide some follow-up errorsOli Scherer-0/+2
2024-06-03Auto merge of #125778 - estebank:issue-67100, r=compiler-errorsbors-1/+1
Use parenthetical notation for `Fn` traits Always use the `Fn(T) -> R` format when printing closure traits instead of `Fn<(T,), Output = R>`. Address #67100: ``` error[E0277]: expected a `Fn()` closure, found `F` --> file.rs:6:13 | 6 | call_fn(f) | ------- ^ expected an `Fn()` closure, found `F` | | | required by a bound introduced by this call | = note: wrap the `F` in a closure with no arguments: `|| { /* code */ }` note: required by a bound in `call_fn` --> file.rs:1:15 | 1 | fn call_fn<F: Fn() -> ()>(f: &F) { | ^^^^^^^^^^ required by this bound in `call_fn` help: consider further restricting this bound | 5 | fn call_any<F: std::any::Any + Fn()>(f: &F) { | ++++++ ```
2024-06-01Deduplicate supertrait_def_ids codeMark Rousskov-2/+1
2024-05-31Auto merge of #124662 - zetanumbers:needs_async_drop, r=oli-obkbors-0/+5
Implement `needs_async_drop` in rustc and optimize async drop glue This PR expands on #121801 and implements `Ty::needs_async_drop` which works almost exactly the same as `Ty::needs_drop`, which is needed for #123948. Also made compiler's async drop code to look more like compiler's regular drop code, which enabled me to write an optimization where types which do not use `AsyncDrop` can simply forward async drop glue to `drop_in_place`. This made size of the async block from the [async_drop test](https://github.com/zetanumbers/rust/blob/67980dd6fb11917d23d01a19c2cf4cfc3978aac8/tests/ui/async-await/async-drop.rs) to decrease by 12%.
2024-05-31Rollup merge of #125786 - compiler-errors:fold-item-bounds, r=lcnrMatthias Krüger-2/+27
Fold item bounds before proving them in `check_type_bounds` in new solver Vaguely confident that this is sufficient to prevent rust-lang/trait-system-refactor-initiative#46 and rust-lang/trait-system-refactor-initiative#62. This is not the "correct" solution, but will probably suffice until coinduction, at which point we implement the right solution (`check_type_bounds` must prove `Assoc<...> alias-eq ConcreteType`, normalizing requires proving item bounds). r? lcnr
2024-05-31Rollup merge of #125635 - fmease:mv-type-binding-assoc-item-constraint, ↵Matthias Krüger-172/+173
r=compiler-errors Rename HIR `TypeBinding` to `AssocItemConstraint` and related cleanup Rename `hir::TypeBinding` and `ast::AssocConstraint` to `AssocItemConstraint` and update all items and locals using the old terminology. Motivation: The terminology *type binding* is extremely outdated. "Type bindings" not only include constraints on associated *types* but also on associated *constants* (feature `associated_const_equality`) and on RPITITs of associated *functions* (feature `return_type_notation`). Hence the word *item* in the new name. Furthermore, the word *binding* commonly refers to a mapping from a binder/identifier to a "value" for some definition of "value". Its use in "type binding" made sense when equality constraints (e.g., `AssocTy = Ty`) were the only kind of associated item constraint. Nowadays however, we also have *associated type bounds* (e.g., `AssocTy: Bound`) for which the term *binding* doesn't make sense. --- Old terminology (HIR, rustdoc): ``` `TypeBinding`: (associated) type binding ├── `Constraint`: associated type bound └── `Equality`: (associated) equality constraint (?) ├── `Ty`: (associated) type binding └── `Const`: associated const equality (constraint) ``` Old terminology (AST, abbrev.): ``` `AssocConstraint` ├── `Bound` └── `Equality` ├── `Ty` └── `Const` ``` New terminology (AST, HIR, rustdoc): ``` `AssocItemConstraint`: associated item constraint ├── `Bound`: associated type bound └── `Equality`: associated item equality constraint OR associated item binding (for short) ├── `Ty`: associated type equality constraint OR associated type binding (for short) └── `Const`: associated const equality constraint OR associated const binding (for short) ``` r? compiler-errors
2024-05-30Rename HIR `TypeBinding` to `AssocItemConstraint` and related cleanupLeón Orell Valerian Liehr-172/+173
2024-05-30Fold item bound before checking that they holdMichael Goulet-2/+27
2024-05-30Auto merge of #125711 - oli-obk:const_block_ice2, r=Nadrierilbors-4/+3
Make `body_owned_by` return the `Body` instead of just the `BodyId` fixes #125677 Almost all `body_owned_by` callers immediately called `body`, too, so just return `Body` directly. This makes the inline-const query feeding more robust, as all calls to `body_owned_by` will now yield a body for inline consts, too. I have not yet figured out a good way to make `tcx.hir().body()` return an inline-const body, but that can be done as a follow-up
2024-05-29Use parenthetical notation for `Fn` traitsEsteban Küber-1/+1
Always use the `Fn(T) -> R` format when printing closure traits instead of `Fn<(T,), Output = R>`. Fix #67100: ``` error[E0277]: expected a `Fn()` closure, found `F` --> file.rs:6:13 | 6 | call_fn(f) | ------- ^ expected an `Fn()` closure, found `F` | | | required by a bound introduced by this call | = note: wrap the `F` in a closure with no arguments: `|| { /* code */ }` note: required by a bound in `call_fn` --> file.rs:1:15 | 1 | fn call_fn<F: Fn() -> ()>(f: &F) { | ^^^^^^^^^^ required by this bound in `call_fn` help: consider further restricting this bound | 5 | fn call_any<F: std::any::Any + Fn()>(f: &F) { | ++++++ ```
2024-05-29Add lang item for Future::OutputMichael Goulet-1/+1
2024-05-29Make `body_owned_by` return the body directly.Oli Scherer-3/+2
Almost all callers want this anyway, and now we can use it to also return fed bodies
2024-05-29Don't require `visit_body` to take a lifetime that must outlive the function ↵Oli Scherer-1/+1
call
2024-05-29Start implementing needs_async_drop and relatedDaria Sukhonina-0/+5
2024-05-28Add an intrinsic for `ptr::metadata`Scott McMurray-0/+2
2024-05-28Create const block DefIds in typeck instead of ast loweringOli Scherer-13/+15
2024-05-28Allow type_of to return partially non-error types if the type was already ↵Oli Scherer-1/+3
tainted
2024-05-28Make body-visiting logic reusableOli Scherer-53/+59