about summary refs log tree commit diff
path: root/compiler/rustc_hir_analysis/src
AgeCommit message (Collapse)AuthorLines
2023-05-08Auto merge of #106621 - ozkanonur:enable-elided-lifetimes-for-doctests, ↵bors-18/+30
r=Mark-Simulacrum enable `rust_2018_idioms` lint group for doctests With this change, `rust_2018_idioms` lint group will be enabled for compiler/libstd doctests. Resolves #106086 Resolves #99144 Signed-off-by: ozkanonur <work@onurozkan.dev>
2023-05-07Auto merge of #111161 - compiler-errors:rtn-super, r=cjgillotbors-38/+101
Support return-type bounds on associated methods from supertraits Support `T: Trait<method(): Bound>` when `method` comes from a supertrait, aligning it with the behavior of associated type bounds (both equality and trait bounds). The only wrinkle is that I have to extend `super_predicates_that_define_assoc_type` to look for *all* items, not just `AssocKind::Ty`. This will also be needed to support `feature(associated_const_equality)` as well, which is subtly broken when it comes to supertraits, though this PR does not fix those yet. There's a slight chance there's a perf regression here, in which case I guess I could split it out into a separate query.
2023-05-07use implied bounds when checking opaque typesAli MJ Al-Nasrawy-3/+14
2023-05-07enable `rust_2018_idioms` for doctestsozkanonur-18/+30
Signed-off-by: ozkanonur <work@onurozkan.dev>
2023-05-06Rollup merge of #110577 - compiler-errors:drop-impl-fulfill, r=lcnrMatthias Krüger-233/+91
Use fulfillment to check `Drop` impl compatibility Use an `ObligationCtxt` to ensure that a `Drop` impl does not have stricter requirements than the ADT that it's implemented for, rather than using a `SimpleEqRelation` to (more or less) syntactically equate predicates on an ADT with predicates on an impl. r? types ### Some background The old code reads: ```rust // An earlier version of this code attempted to do this checking // via the traits::fulfill machinery. However, it ran into trouble // since the fulfill machinery merely turns outlives-predicates // 'a:'b and T:'b into region inference constraints. It is simpler // just to look for all the predicates directly. ``` I'm not sure what this means, but perhaps in the 8 years since that this comment was written (cc #23638) it's gotten easier to process region constraints after doing fulfillment? I don't know how this logic differs from anything we do in the `compare_impl_item` module. Ironically, later on it says: ```rust // However, it may be more efficient in the future to batch // the analysis together via the fulfill (see comment above regarding // the usage of the fulfill machinery), rather than the // repeated `.iter().any(..)` calls. ``` Also: * Removes `SimpleEqRelation` which was far too syntactical in its relation. * Fixes #110557
2023-05-05Report nicer lifetime errors for specializationMatthew Jasper-3/+16
Add an obligation cause for these error so that the error points to the implementations that caused the error.
2023-05-05misc nameres changes for anon constsBoxy-14/+17
2023-05-05Disallow (min) specialization imps with no itemsMatthew Jasper-1/+23
Such implementations are usually mistakes and are not used in the compiler or standard library (after this commit) so forbid them with `min_specialization`.
2023-05-05remove unnecessary attribute from a diagnosticTakayuki Maeda-1/+0
2023-05-04Use fulfillment to check Drop impl compatibilityMichael Goulet-233/+91
2023-05-04Don't compute trait super bounds unless they're positiveMichael Goulet-5/+6
2023-05-04IAT: Introduce AliasKind::InherentLeón Orell Valerian Liehr-29/+54
2023-05-04Auto merge of #111174 - matthiaskrgr:rollup-ncnqivh, r=matthiaskrgrbors-1/+30
Rollup of 8 pull requests Successful merges: - #110859 (Explicitly reject negative and reservation drop impls) - #111020 (Validate resolution for SelfCtor too.) - #111024 (Use the full Fingerprint when stringifying Svh) - #111027 (Remove `allow(rustc::potential_query_instability)` for `builtin_macros`) - #111039 (Encode def span for foreign return-position `impl Trait` in trait) - #111070 (Don't suffix `RibKind` variants) - #111094 (Add needs-unwind annotations to tests that need stack unwinding) - #111103 (correctly recurse when expanding anon consts) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2023-05-04Rollup merge of #110859 - compiler-errors:no-negative-drop-impls, r=oli-obkMatthias Krüger-1/+30
Explicitly reject negative and reservation drop impls Fixes #110858 It doesn't really make sense for a type to have a `!Drop` impl. Or at least, I don't want us to implicitly assign a meaning to it by the way the compiler *currently* handles it (incompletely), and rather I would like to see a PR (or an RFC...) assign a meaning to `!Drop` if we actually wanted one for it.
2023-05-04Auto merge of #110806 - WaffleLapkin:unmkI, r=lcnrbors-10/+15
Replace `tcx.mk_trait_ref` with `TraitRef::new` First step in implementing https://github.com/rust-lang/compiler-team/issues/616 r? `@lcnr`
2023-05-03Error message for ambiguous RTN from super boundsMichael Goulet-3/+23
2023-05-03Rename things to reflect that they're not item specificMichael Goulet-11/+11
2023-05-03Support RTN on associated methods from supertraitsMichael Goulet-27/+70
2023-05-04Rollup merge of #110791 - compiler-errors:negative-bounds, r=oli-obkDylan DPC-6/+37
Implement negative bounds for internal testing purposes Implements partial support the `!` negative polarity on trait bounds. This is incomplete, but should allow us to at least be able to play with the feature. Not even gonna consider them as a public-facing feature, but I'm implementing them because would've been nice to have in UI tests, for example in #110671.
2023-05-03Restrict `From<S>` for `{D,Subd}iagnosticMessage`.Nicholas Nethercote-115/+112
Currently a `{D,Subd}iagnosticMessage` can be created from any type that impls `Into<String>`. That includes `&str`, `String`, and `Cow<'static, str>`, which are reasonable. It also includes `&String`, which is pretty weird, and results in many places making unnecessary allocations for patterns like this: ``` self.fatal(&format!(...)) ``` This creates a string with `format!`, takes a reference, passes the reference to `fatal`, which does an `into()`, which clones the reference, doing a second allocation. Two allocations for a single string, bleh. This commit changes the `From` impls so that you can only create a `{D,Subd}iagnosticMessage` from `&str`, `String`, or `Cow<'static, str>`. This requires changing all the places that currently create one from a `&String`. Most of these are of the `&format!(...)` form described above; each one removes an unnecessary static `&`, plus an allocation when executed. There are also a few places where the existing use of `&String` was more reasonable; these now just use `clone()` at the call site. As well as making the code nicer and more efficient, this is a step towards possibly using `Cow<'static, str>` in `{D,Subd}iagnosticMessage::{Str,Eager}`. That would require changing the `From<&'a str>` impls to `From<&'static str>`, which is doable, but I'm not yet sure if it's worthwhile.
2023-05-02Make negative trait bounds work with the old trait solverMichael Goulet-0/+10
2023-05-02Disallow associated type constraints on negative boundsMichael Goulet-2/+0
2023-05-02Implement negative boundsMichael Goulet-6/+29
2023-05-02Rollup merge of #110512 - ↵Dylan DPC-73/+111
compiler-errors:fix-elaboration-with-associated-type-bounds, r=spastorino Fix elaboration with associated type bounds When computing a trait's supertrait predicates, do not add any associated type *trait* bounds to that list of supertrait predicates. This is because supertrait predicates are expected to have the same `Self` type as the trait. For example, given: ```rust trait Foo: Bar<Assoc: Send> ``` Before, we would compute that the supertrait predicates of `T: Foo` are `T: Bar` and `<T as Bar>::Assoc: Send`. However, the last bound is a trait predicate for a totally different type than `T`, and existing code that uses supertrait bounds such as vtable construction, closure fn signature deduction, etc. all rely on the invariant that we have a list of predicates for self type `T`. Fixes #76593 The reason for all the extra diagnostic noise is that we're recomputing predicates with a different filter now. These diagnostics should be deduplicated for any end-user though. --- This does bring up an interesting question -- is the predicate `<T as Bar>::Assoc: Send` an implied bound of `T: Foo`? Because currently the only bounds implied by a (non-alias) trait are its supertraits. I guess I could fix this too, but it would require even more changes, and I'm inclined to punt this question along.
2023-05-02Rollup merge of #108161 - WaffleLapkin:const_param_ty, r=BoxyUwUDylan DPC-107/+156
Add `ConstParamTy` trait This is a bit sketch, but idk. r? `@BoxyUwU` Yet to be done: - [x] ~~Figure out if it's okay to implement `StructuralEq` for primitives / possibly remove their special casing~~ (it should be okay, but maybe not in this PR...) - [ ] Maybe refactor the code a little bit - [x] Use a macro to make impls a bit nicer Future work: - [ ] Actually™ use the trait when checking if a `const` generic type is allowed - [ ] _Really_ refactor the surrounding code - [ ] Refactor `marker.rs` into multiple modules for each "theme" of markers
2023-05-01Don't use implied trait predicates in gather_explicit_predicates_ofMichael Goulet-6/+11
2023-05-01Do not consider associated type bounds for ↵Michael Goulet-16/+68
super_predicates_that_define_assoc_type
2023-05-01Simplify type_parameter_bounds_in_genericsMichael Goulet-53/+34
2023-04-30Codegen fewer instructions in `mem::replace`Scott McMurray-0/+1
2023-04-28remove unused `mut`sLukas Markeffsky-1/+1
2023-04-28Auto merge of #110837 - scottmcm:offset-for-add, r=compiler-errorsbors-1/+2
Use MIR's `Offset` for pointer `add` too ~~Status: draft while waiting for #110822 to land, since this is built atop that.~~ ~~r? `@ghost~~` Canonical Rust code has mostly moved to `add`/`sub` on pointers, which take `usize`, instead of `offset` which takes `isize`. (And, relatedly, when `sub_ptr` was added it turned out it replaced every single in-tree use of `offset_from`, because `usize` is just so much more useful than `isize` in Rust.) Unfortunately, `intrinsics::offset` could only accept `*const` and `isize`, so there's a *huge* amount of type conversions back and forth being done. They're identity conversions in the backend, but still end up producing quite a lot of unhelpful MIR. This PR changes `intrinsics::offset` to accept `*const` *and* `*mut` along with `isize` *and* `usize`. Conveniently, the backends and CTFE already handle this, since MIR's `BinOp::Offset` [already supports all four combinations](https://github.com/rust-lang/rust/blob/adaac6b166df57ea5a20d56e4cce503b55aca927/compiler/rustc_const_eval/src/transform/validate.rs#L523-L528). To demonstrate the difference, I added some `mir-opt/pre-codegen/` tests around slice indexing. Here's the difference to `[T]::get_mut`, since it uses `<*mut _>::add` internally: ```diff `@@` -79,30 +70,21 `@@` fn slice_get_mut_usize(_1: &mut [u32], _2: usize) -> Option<&mut u32> { StorageLive(_12); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL StorageLive(_9); // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL _9 = _8 as *mut u32 (PtrToPtr); // scope 11 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - StorageLive(_13); // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - _13 = _2 as isize (IntToInt); // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - StorageLive(_14); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - StorageLive(_15); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - _15 = _9 as *const u32 (Pointer(MutToConstPointer)); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - _14 = Offset(move _15, _13); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - StorageDead(_15); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - _7 = move _14 as *mut u32 (PtrToPtr); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - StorageDead(_14); // scope 15 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL - StorageDead(_13); // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL + _7 = Offset(_9, _2); // scope 13 at $SRC_DIR/core/src/ptr/mut_ptr.rs:LL:COL StorageDead(_9); // scope 6 at $SRC_DIR/core/src/slice/index.rs:LL:COL StorageDead(_12); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL StorageDead(_11); // scope 3 at $SRC_DIR/core/src/slice/index.rs:LL:COL ``` https://github.com/rust-lang/rust/pull/110837/commits/1c1c8e442add0f46905a57a25a6cba52b8b0c54d#diff-a841b6a4538657add3f39bc895744331453d0625e7aace128b1f604f0b63c8fdR80
2023-04-27Also use `mir::Offset` for pointer `add`Scott McMurray-1/+2
2023-04-27Explicitly reject negative and reservation drop implsMichael Goulet-1/+30
2023-04-27Add a `ConstParamTy` traitMaybe Waffle-107/+156
2023-04-27rename `needs_subst` to `has_param`Boxy-6/+6
2023-04-27rename `needs_infer` to `has_infer`Boxy-4/+4
2023-04-26Rollup merge of #110835 - nnethercote:strict-region-folders-2, r=compiler-errorsMatthias Krüger-13/+8
Make some region folders a little stricter. Because certain regions cannot occur in them. r? ``@compiler-errors``
2023-04-26Rollup merge of #108760 - clubby789:autolintstuff, r=wesleywiserMatthias Krüger-23/+56
Add lint to deny diagnostics composed of static strings r? ghost I'm hoping to have a lint that semi-automatically converts simple diagnostics such as `struct_span_err(span, "msg").help("msg").span_note(span2, "msg").emit()` to typed session diagnostics. It's quite hacky and not entirely working because of problems with `x fix` but should hopefully help reduce some of the work. I'm going to start trying to apply what I can from this, but opening this as a draft in case anyone wants to develop on it. cc #100717
2023-04-26Add new `ToPredicate` impls and `TraitRef` methods to remove some ↵Maybe Waffle-1/+1
`ty::Binber::dummy` calls
2023-04-26Make some region folders a little stricter.Nicholas Nethercote-13/+8
Because certain regions cannot occur in them.
2023-04-25Rollup merge of #110556 - kylematsuda:earlybinder-explicit-item-bounds, ↵Matthias Krüger-18/+21
r=compiler-errors Switch to `EarlyBinder` for `explicit_item_bounds` Part of the work to finish https://github.com/rust-lang/rust/issues/105779. This PR adds `EarlyBinder` to the return type of the `explicit_item_bounds` query and removes `bound_explicit_item_bounds`. r? `@compiler-errors` (hope it's okay to request you, since you reviewed #110299 and #110498 :smiley:)
2023-04-25Fix static string lintsclubby789-23/+56
2023-04-25Remove some useless `ty::Binder::dummy` callsMaybe Waffle-3/+3
2023-04-25Replace `tcx.mk_trait_ref` with `ty::TraitRef::new`Maybe Waffle-9/+14
2023-04-25Auto merge of #110325 - obeis:hir-analysis-migrate-diagnostics-4, r=davidtwcobors-84/+214
Migrate `rustc_hir_analysis` to session diagnostic [Part 4] Part 4: Finishing `check/mod.rs` file r? `@compiler-errors`
2023-04-25Rollup merge of #110539 - WaffleLapkin:split_index_vec&slice, r=cjgillotYuki Okushi-2/+2
Move around `{Idx, IndexVec, IndexSlice}` adjacent code r? ``@scottmcm``
2023-04-24Split `{Idx, IndexVec, IndexSlice}` into their own modulesMaybe Waffle-2/+2
2023-04-24Auto merge of #110672 - Ezrashaw:allow-array-simd-in-inline-asm, ↵bors-13/+25
r=workingjubilee allow array-style simd in inline asm Required for [MCP#621](https://github.com/rust-lang/compiler-team/issues/621) to be implemented. r? `@workingjubilee`
2023-04-24Rollup merge of #110706 - scottmcm:transmute_unchecked, r=oli-obkMatthias Krüger-1/+1
Add `intrinsics::transmute_unchecked` This takes a whole 3 lines in `compiler/` since it lowers to `CastKind::Transmute` in MIR *exactly* the same as the existing `intrinsics::transmute` does, it just doesn't have the fancy checking in `hir_typeck`. Added to enable experimenting with the request in <https://github.com/rust-lang/rust/pull/106281#issuecomment-1496648190> and because the portable-simd folks might be interested for dependently-sized array-vector conversions. It also simplifies a couple places in `core`. See also https://github.com/rust-lang/rust/pull/108442#issuecomment-1474777273, where `CastKind::Transmute` was added having exactly these semantics before the lang meeting (which I wasn't in) independently expressed interest.
2023-04-23Rollup merge of #110700 - compiler-errors:fn-ret-fn, r=oli-obkMatthias Krüger-11/+20
Don't infer fn return type to return itself Fixes #110687