summary refs log tree commit diff
path: root/compiler/rustc_hir_analysis/src/coherence
AgeCommit message (Collapse)AuthorLines
2024-08-30Remove `#[macro_use] extern crate tracing` from `rustc_hir_analysis`.Nicholas Nethercote-0/+4
2024-08-27Add `warn(unreachable_pub)` to `rustc_hir_analysis`.Nicholas Nethercote-6/+12
2024-08-14Auto merge of #128812 - nnethercote:shrink-TyKind-FnPtr, r=compiler-errorsbors-1/+1
Shrink `TyKind::FnPtr`. By splitting the `FnSig` within `TyKind::FnPtr` into `FnSigTys` and `FnHeader`, which can be packed more efficiently. This reduces the size of the hot `TyKind` type from 32 bytes to 24 bytes on 64-bit platforms. This reduces peak memory usage by a few percent on some benchmarks. It also reduces cache misses and page faults similarly, though this doesn't translate to clear cycles or wall-time improvements on CI. r? `@compiler-errors`
2024-08-11Use assert_matches around the compilerMichael Goulet-1/+2
2024-08-09Shrink `TyKind::FnPtr`.Nicholas Nethercote-1/+1
By splitting the `FnSig` within `TyKind::FnPtr` into `FnSigTys` and `FnHeader`, which can be packed more efficiently. This reduces the size of the hot `TyKind` type from 32 bytes to 24 bytes on 64-bit platforms. This reduces peak memory usage by a few percent on some benchmarks. It also reduces cache misses and page faults similarly, though this doesn't translate to clear cycles or wall-time improvements on CI.
2024-07-29Reformat `use` declarations.Nicholas Nethercote-20/+25
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-21Move all error reporting into rustc_trait_selectionMichael Goulet-1/+1
2024-07-21Make type_var_origin take a vidMichael Goulet-2/+4
2024-07-17Split part of `adt_const_params` into `unsized_const_params`Boxy-6/+15
2024-07-17Forbid `!Sized` types and referencesBoxy-8/+34
2024-07-08Move trait selection error reporting to its own top-level moduleMichael Goulet-1/+1
2024-07-07Uplift trait_ref_is_knowable and friendsMichael Goulet-8/+7
2024-06-21Rename a bunch of thingsMichael Goulet-1/+1
2024-06-18Remove redundant argument from `subdiagnostic` methodOli Scherer-46/+28
2024-06-14Use is_lang_item more aggressivelyMichael Goulet-2/+3
2024-06-04Auto merge of #125380 - compiler-errors:wc-obj-safety, r=oli-obkbors-1/+1
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-03Nits and formattingMichael Goulet-11/+7
2024-06-03check_is_object_safe -> is_object_safeMichael Goulet-1/+1
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-2/+2
2024-06-03Make TraitEngines generic over errorMichael Goulet-2/+3
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-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-17Rename Unsafe to SafetySantiago Pastorino-10/+10
2024-05-13Remove `extern crate rustc_middle` from `rustc_hir_analysis`.Nicholas Nethercote-0/+2
2024-05-10Lift `TraitRef` into `rustc_type_ir`Michael Goulet-0/+2
2024-05-09Rename Generics::params to Generics::own_paramsMichael Goulet-2/+2
2024-05-02shallow resolve in orphan checklcnr-0/+1
2024-04-30Normalize trait ref before orphan check & consider ty params in alias types ↵León Orell Valerian Liehr-67/+245
to be uncovered
2024-04-16Prefer identity equality over equating types during coercion.Oli Scherer-22/+13
These types are always generic only over their own generic parameters with no inference variables involved.
2024-04-08Actually create ranged int types in the type system.Oli Scherer-1/+12
2024-03-29Stop doing so much to handle subdiagnosticsMichael Goulet-94/+68
2024-03-29Stop removing substs from Adt type in coherenceMichael Goulet-12/+16
2024-03-22Auto merge of #122900 - matthiaskrgr:rollup-nls90mb, r=matthiaskrgrbors-1/+1
Rollup of 8 pull requests Successful merges: - #114009 (compiler: allow transmute of ZST arrays with generics) - #122195 (Note that the caller chooses a type for type param) - #122651 (Suggest `_` for missing generic arguments in turbofish) - #122784 (Add `tag_for_variant` query) - #122839 (Split out `PredicatePolarity` from `ImplPolarity`) - #122873 (Merge my contributor emails into one using mailmap) - #122885 (Adjust better spastorino membership to triagebot's adhoc_groups) - #122888 (add a couple more tests) r? `@ghost` `@rustbot` modify labels: rollup
2024-03-22Split out ImplPolarity and PredicatePolarityMichael Goulet-1/+1
2024-03-22Make RawPtr take Ty and Mutbl separatelyMichael Goulet-13/+16
2024-03-22Programmatically convert some of the pat ctorsMichael Goulet-1/+1
2024-03-11Rollup merge of #121840 - oli-obk:freeze, r=dtolnayJacob Pratt-0/+14
Expose the Freeze trait again (unstably) and forbid implementing it manually non-emoji version of https://github.com/rust-lang/rust/pull/121501 cc #60715 This trait is useful for generic constants (associated consts of generic traits). See the test (`tests/ui/associated-consts/freeze.rs`) added in this PR for a usage example. The builtin `Freeze` trait is the only way to do it, users cannot work around this issue. It's also a useful trait for building some very specific abstrations, as shown by the usage by the `zerocopy` crate: https://github.com/google/zerocopy/issues/941 cc ```@RalfJung``` T-lang signed off on reexposing this unstably: https://github.com/rust-lang/rust/pull/121501#issuecomment-1969827742
2024-03-07Apply `EarlyBinder` only to `TraitRef` in `ImplTraitHeader`Yoshitomo Nakanishi-12/+12
2024-02-29Forbid implementing `Freeze` even if the trait is stabilizedOli Scherer-0/+14
2024-02-25Auto merge of #120393 - Urgau:rfc3373-non-local-defs, r=WaffleLapkinbors-5/+5
Implement RFC 3373: Avoid non-local definitions in functions This PR implements [RFC 3373: Avoid non-local definitions in functions](https://github.com/rust-lang/rust/issues/120363).
2024-02-25Rollup merge of #121060 - clubby789:bool-newtypes, r=cjgillotMatthias Krüger-5/+5
Add newtypes for bool fields/params/return types Fixed all the cases of this found with some simple searches for `*/ bool` and `bool /*`; probably many more
2024-02-20Move the peeling function for weak alias typesLeón Orell Valerian Liehr-28/+1
2024-02-20Add newtype for first input typeclubby789-5/+5
2024-02-19Inline do_orphan_check_implSantiago Pastorino-17/+9
2024-02-19Remove suspicious auto trait lintSantiago Pastorino-160/+4
2024-02-18Auto merge of #120780 - fmease:lta-in-impls, r=oli-obkbors-1/+30
Properly deal with weak alias types as self types of impls Fixes #114216. Fixes #116100. Not super happy about the two ad hoc “normalization” implementations for weak alias types: 1. In `inherent_impls`: The “peeling”, normalization to [“WHNF”][whnf]: Semantically that's exactly what we want (neither proper normalization nor shallow normalization would be correct here). Basically a weak alias type is “nominal” (well...^^) if the WHNF is nominal. [#97974](https://github.com/rust-lang/rust/pull/97974) followed the same approach. 2. In `constrained_generic_params`: Generic parameters are constrained by a weak alias type if the corresp. “normalized” type constrains them (where we only normalize *weak* alias types not arbitrary ones). Weak alias types are injective if the corresp. “normalized” type is injective. Both have ad hoc overflow detection mechanisms. **Coherence** is handled in #117164. r? `@oli-obk` or types [whnf]: https://en.wikipedia.org/wiki/Lambda_calculus_definition#Weak_head_normal_form
2024-02-17Fix non_local_definitions lint in rustc_hir_analysisUrgau-5/+5