about summary refs log tree commit diff
path: root/compiler/rustc_infer
AgeCommit message (Collapse)AuthorLines
2025-04-04Auto merge of #138785 - lcnr:typing-mode-borrowck, r=compiler-errors,oli-obkbors-4/+37
add `TypingMode::Borrowck` Shares the first commit with #138499, doesn't really matter which PR to land first :blush: :grin: Introduces `TypingMode::Borrowck` which unlike `TypingMode::Analysis`, uses the hidden type computed by HIR typeck as the initial value of opaques instead of an unconstrained infer var. This is a part of https://github.com/rust-lang/types-team/issues/129. Using this new `TypingMode` is unfortunately a breaking change for now, see tests/ui/impl-trait/non-defining-uses/as-projection-term.rs. Using an inference variable as the initial value results in non-defining uses in the defining scope. We therefore only enable it if with `-Znext-solver=globally` or `-Ztyping-mode-borrowck` To do that the PR contains the following changes: - `TypeckResults::concrete_opaque_type` are already mapped to the definition of the opaque type - writeback now checks that the non-lifetime parameters of the opaque are universal - for this, `fn check_opaque_type_parameter_valid` is moved from `rustc_borrowck` to `rustc_trait_selection` - we add a new `query type_of_opaque_hir_typeck` which, using the same visitors as MIR typeck, attempts to merge the hidden types from HIR typeck from all defining scopes - done by adding a `DefiningScopeKind` flag to toggle between using borrowck and HIR typeck - the visitors stop checking that the MIR type matches the HIR type. This is trivial as the HIR type are now used as the initial hidden types of the opaque. This check is useful as a safeguard when not using `TypingMode::Borrowck`, but adding it to the new structure is annoying and it's not soundness critical, so I intend to not add it back. - add a `TypingMode::Borrowck` which behaves just like `TypingMode::Analysis` except when normalizing opaque types - it uses `type_of_opaque_hir_typeck(opaque)` as the initial value after replacing its regions with new inference vars - it uses structural lookup in the new solver fixes #112201, fixes #132335, fixes #137751 r? `@compiler-errors` `@oli-obk`
2025-04-03Pass correct param-env to error_impliesMichael Goulet-1/+2
2025-04-03add `TypingMode::Borrowck`lcnr-4/+37
2025-04-01simplify Interner opaque types APIlcnr-4/+3
2025-03-23Obligation::as_goalMichael Goulet-8/+7
2025-03-15Fold visit into tyMichael Goulet-13/+10
2025-03-15Squash fold into tyMichael Goulet-30/+26
2025-03-11Remove `#![warn(unreachable_pub)]` from all `compiler/` crates.Nicholas Nethercote-1/+0
It's no longer necessary now that `-Wunreachable_pub` is being passed.
2025-03-10Revert "Use workspace lints for crates in `compiler/` #138084"许杰友 Jieyou Xu (Joe)-3/+1
Revert <https://github.com/rust-lang/rust/pull/138084> to buy time to consider options that avoids breaking downstream usages of cargo on distributed `rustc-src` artifacts, where such cargo invocations fail due to inability to inherit `lints` from workspace root manifest's `workspace.lints` (this is only valid for the source rust-lang/rust workspace, but not really the distributed `rustc-src` artifacts). This breakage was reported in <https://github.com/rust-lang/rust/issues/138304>. This reverts commit 48caf81484b50dca5a5cebb614899a3df81ca898, reversing changes made to c6662879b27f5161e95f39395e3c9513a7b97028.
2025-03-08Remove `#![warn(unreachable_pub)]` from all `compiler/` crates.Nicholas Nethercote-1/+0
(Except for `rustc_codegen_cranelift`.) It's no longer necessary now that `unreachable_pub` is in the workspace lints.
2025-03-08Specify rust lints for `compiler/` crates via Cargo.Nicholas Nethercote-0/+3
By naming them in `[workspace.lints.rust]` in the top-level `Cargo.toml`, and then making all `compiler/` crates inherit them with `[lints] workspace = true`. (I omitted `rustc_codegen_{cranelift,gcc}`, because they're a bit different.) The advantages of this over the current approach: - It uses a standard Cargo feature, rather than special handling in bootstrap. So, easier to understand, and less likely to get accidentally broken in the future. - It works for proc macro crates. It's a shame it doesn't work for rustc-specific lints, as the comments explain.
2025-02-26Use Binder<Vec<T>> instead of Vec<Binder<T>> in new solverMichael Goulet-2/+4
2025-02-24Rollup merge of #136610 - Jarcho:range_idx, r=NoratriebJacob Pratt-1/+1
Allow `IndexSlice` to be indexed by ranges. This comes with some annoyances as the index type can no longer inferred from indexing expressions. The biggest offender for this is `IndexVec::from_fn_n(|idx| ..., n)` where the index type won't be inferred from the call site or any index expressions inside the closure. My main use case for this is mapping a `Place` to `Range<Idx>` for value tracking where the range represents all the values the place contains.
2025-02-22Greatly simplify lifetime captures in edition 2024Michael Goulet-14/+10
2025-02-22Upgrade the compiler to edition 2024Michael Goulet-1/+1
2025-02-21Allow SliceIndex to be indexed by ranges.Jason Newcomb-1/+1
2025-02-21Rollup merge of #137305 - nnethercote:rustc_middle-2, r=lcnrMatthias Krüger-1/+0
Tweaks in and around `rustc_middle` A bunch of tiny improvements I found while working on bigger things. r? ```@lcnr```
2025-02-21Rollup merge of #137302 - compiler-errors:stray-drop-regions, r=matthewjasperMatthias Krüger-1/+1
Use a probe to avoid registering stray region obligations when re-checking drops in MIR typeck Fixes #137288. See the comment I left on the probe. I'm not totally sure why this depends on *both* an unconstrained type parameter in the impl and a type error for the self type, but I think the fix is at least theoretically well motivated. r? ```@matthewjasper```
2025-02-21Remove an unnecessary re-export.Nicholas Nethercote-1/+0
It's a bit weird.
2025-02-20Use a probe to avoid registering stray region obligations when re-checking ↵Michael Goulet-1/+1
drops in MIR typeck
2025-02-19Make fewer crates depend on rustc_ast_irMichael Goulet-3/+1
2025-02-08Rustfmtbjorn3-32/+39
2025-02-06Add opt_alias_variances and use it in outlives codeMichael Goulet-13/+11
2025-02-05Pass spans around new solverMichael Goulet-11/+26
2025-02-02Move `unify_key` module.Nicholas Nethercote-5/+176
From `rustc_middle::infer` to `rustc_infer::infer`. Because everything in it is only used within `rustc_infer`, and no longer needs to be `pub`. Plus it's always good to make the huge `rustc_middle` crate smaller.
2025-01-31Auto merge of #135318 - compiler-errors:vtable-fixes, r=lcnrbors-0/+24
Fix deduplication mismatches in vtables leading to upcasting unsoundness We currently have two cases where subtleties in supertraits can trigger disagreements in the vtable layout, e.g. leading to a different vtable layout being accessed at a callsite compared to what was prepared during unsizing. Namely: ### #135315 In this example, we were not normalizing supertraits when preparing vtables. In the example, ``` trait Supertrait<T> { fn _print_numbers(&self, mem: &[usize; 100]) { println!("{mem:?}"); } } impl<T> Supertrait<T> for () {} trait Identity { type Selff; } impl<Selff> Identity for Selff { type Selff = Selff; } trait Middle<T>: Supertrait<()> + Supertrait<T> { fn say_hello(&self, _: &usize) { println!("Hello!"); } } impl<T> Middle<T> for () {} trait Trait: Middle<<() as Identity>::Selff> {} impl Trait for () {} fn main() { (&() as &dyn Trait as &dyn Middle<()>).say_hello(&0); } ``` When we prepare `dyn Trait`, we see a supertrait of `Middle<<() as Identity>::Selff>`, which itself has two supertraits `Supertrait<()>` and `Supertrait<<() as Identity>::Selff>`. These two supertraits are identical, but they are not duplicated because we were using structural equality and *not* considering normalization. This leads to a vtable layout with two trait pointers. When we upcast to `dyn Middle<()>`, those two supertraits are now the same, leading to a vtable layout with only one trait pointer. This leads to an offset error, and we call the wrong method. ### #135316 This one is a bit more interesting, and is the bulk of the changes in this PR. It's a bit similar, except it uses binder equality instead of normalization to make the compiler get confused about two vtable layouts. In the example, ``` trait Supertrait<T> { fn _print_numbers(&self, mem: &[usize; 100]) { println!("{mem:?}"); } } impl<T> Supertrait<T> for () {} trait Trait<T, U>: Supertrait<T> + Supertrait<U> { fn say_hello(&self, _: &usize) { println!("Hello!"); } } impl<T, U> Trait<T, U> for () {} fn main() { (&() as &'static dyn for<'a> Trait<&'static (), &'a ()> as &'static dyn Trait<&'static (), &'static ()>) .say_hello(&0); } ``` When we prepare the vtable for `dyn for<'a> Trait<&'static (), &'a ()>`, we currently consider the PolyTraitRef of the vtable as the key for a supertrait. This leads two two supertraits -- `Supertrait<&'static ()>` and `for<'a> Supertrait<&'a ()>`. However, we can upcast[^up] without offsetting the vtable from `dyn for<'a> Trait<&'static (), &'a ()>` to `dyn Trait<&'static (), &'static ()>`. This is just instantiating the principal trait ref for a specific `'a = 'static`. However, when considering those supertraits, we now have only one distinct supertrait -- `Supertrait<&'static ()>` (which is deduplicated since there are two supertraits with the same substitutions). This leads to similar offsetting issues, leading to the wrong method being called. [^up]: I say upcast but this is a cast that is allowed on stable, since it's not changing the vtable at all, just instantiating the binder of the principal trait ref for some lifetime. The solution here is to recognize that a vtable isn't really meaningfully higher ranked, and to just treat a vtable as corresponding to a `TraitRef` so we can do this deduplication more faithfully. That is to say, the vtable for `dyn for<'a> Tr<'a>` and `dyn Tr<'x>` are always identical, since they both would correspond to a set of free regions on an impl... Do note that `Tr<for<'a> fn(&'a ())>` and `Tr<fn(&'static ())>` are still distinct. ---- There's a bit more that can be cleaned up. In codegen, we can stop using `PolyExistentialTraitRef` basically everywhere. We can also fix SMIR to stop storing `PolyExistentialTraitRef` in its vtable allocations. As for testing, it's difficult to actually turn this into something that can be tested with `rustc_dump_vtable`, since having multiple supertraits that are identical is a recipe for ambiguity errors. Maybe someone else is more creative with getting that attr to work, since the tests I added being run-pass tests is a bit unsatisfying. Miri also doesn't help here, since it doesn't really generate vtables that are offset by an index in the same way as codegen. r? `@lcnr` for the vibe check? Or reassign, idk. Maybe let's talk about whether this makes sense. <sup>(I guess an alternative would also be to not do any deduplication of vtable supertraits (or only a really conservative subset) rather than trying to normalize and deduplicate more faithfully here. Not sure if that works and is sufficient tho.)</sup> cc `@steffahn` -- ty for the minimizations cc `@WaffleLapkin` -- since you're overseeing the feature stabilization :3 Fixes #135315 Fixes #135316
2025-01-30introduce `ty::Value`Lukas Markeffsky-2/+2
Co-authored-by: FedericoBruzzone <federico.bruzzone.i@gmail.com>
2025-01-30Normalize vtable entries before walking and deduplicating themMichael Goulet-0/+24
2025-01-30Auto merge of #136038 - compiler-errors:outlives, r=lcnrbors-50/+16
Simplify and consolidate the way we handle construct `OutlivesEnvironment` for lexical region resolution This is best reviewed commit-by-commit. I tried to consolidate the API for lexical region resolution *first*, then change the API when it was finally behind a single surface. r? lcnr or reassign
2025-01-28Move param env bound deep normalization to OutlivesEnvironment buildingMichael Goulet-44/+16
2025-01-28Make item self/non-self bound naming less whackMichael Goulet-1/+1
2025-01-28Move outlives env computation into methodsMichael Goulet-6/+0
2025-01-22Remove `Copy` bound from `enter_forall`Boxy-4/+4
2025-01-18Get rid of `ToPolyTraitRef`Michael Goulet-3/+3
2025-01-13rm unnecessary `OpaqueTypeDecl` wrapperlcnr-24/+16
2025-01-02Simplify declared_generic_bounds_from_envMichael Goulet-32/+23
2025-01-02Make it clearer that the only infers we expect to see when processing ↵Michael Goulet-1/+8
outlives are regions
2025-01-02Remove hack for filtering out param-env outlives that match item-bound outlivesMichael Goulet-18/+1
2024-12-30fix a couple nitsRémy Rakic-1/+1
- remove unneeded type ascription - fix variable name - fix typo in comment - fix `var_origins` var and function name: these are `VarInfos`
2024-12-26nit: Remove redundant functionMichael Goulet-4/+0
2024-12-22Begin to implement type system layer of unsafe bindersMichael Goulet-0/+1
2024-12-20remove non-borrowck member constraintslcnr-353/+5
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-4/+2
`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-17`fn member_constraint` to `add_member_constraint`lcnr-4/+4
2024-12-02Assert that obligations are empty before deeply normalizingMichael Goulet-0/+2
2024-11-28support revealing defined opaque post borrowcklcnr-5/+19
2024-11-28uplift fold_regions to rustc_type_irlcnr-4/+4
2024-11-23Auto merge of #133242 - lcnr:questionable-uwu, r=compiler-errors,BoxyUwUbors-39/+15
finish `Reveal` removal After #133212 changed the `TypingMode` to be the only source of truth, this entirely rips out `Reveal`. cc #132279 r? `@compiler-errors`
2024-11-23global old solver cache: use `TypingEnv`lcnr-4/+5
2024-11-23no more Reveal :(lcnr-35/+10