summary refs log tree commit diff
path: root/compiler/rustc_middle/src
AgeCommit message (Collapse)AuthorLines
2022-02-19Rollup merge of #94086 - tmiasko:char-try-from-scalar-int, r=davidtwcoMatthias Krüger-4/+14
Fix ScalarInt to char conversion to avoid panic for invalid Unicode scalar values
2022-02-19Rollup merge of #94006 - pierwill:upvar-field, r=nikomatsakisMatthias Krüger-2/+2
Use a `Field` in `ConstraintCategory::ClosureUpvar` As part of #90317, we do not want `HirId` to implement `Ord`, `PartialOrd`. This line of code has made that difficult https://github.com/rust-lang/rust/blob/1b27144afc77031ba9c05d86c06c64485589775a/compiler/rustc_borrowck/src/region_infer/mod.rs#L2184 since it sorts a [`ConstraintCategory::ClosureUpvar(HirId)`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/enum.ConstraintCategory.html#variant.ClosureUpvar). This PR makes that variant take a [`Field`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/struct.Field.html) instead. r? `@nikomatsakis`
2022-02-19Rollup merge of #93990 - lcnr:pre-89862-cleanup, r=estebankMatthias Krüger-8/+56
pre #89862 cleanup changes used in #89862 which can be landed without the rest of this PR being finished. r? `@estebank`
2022-02-18Rollup merge of #89892 - Nilstrieb:suggest-return-impl-trait, r=jackh726Matthias Krüger-2/+22
Suggest `impl Trait` return type when incorrectly using a generic return type Address #85991 When there is a type mismatch error and the return type is generic, and that generic parameter is not used in the function parameters, suggest replacing that generic with the `impl Trait` syntax. r? `@estebank`
2022-02-18Suggest `impl Trait` return typeNilstrieb-2/+22
Address #85991 Suggest the `impl Trait` return type syntax if the user tried to return a generic parameter and we get a type mismatch The suggestion is not emitted if the param appears in the function parameters, and only get the bounds that actually involve `T: ` directly It also checks whether the generic param is contained in any where bound (where it isn't the self type), and if one is found (like `Option<T>: Send`), it is not suggested. This also adds `TyS::contains`, which recursively vistits the type and looks if the other type is contained anywhere
2022-02-18Rollup merge of #93634 - matthiaskrgr:clippy_complexity_jan_2022, r=oli-obkMatthias Krüger-3/+3
compiler: clippy::complexity fixes useless_format map_flatten useless_conversion needless_bool filter_next clone_on_copy needless_option_as_deref
2022-02-18Rollup merge of #92683 - jackh726:issue-92033, r=estebankMatthias Krüger-0/+6
Suggest copying trait associated type bounds on lifetime error Closes #92033 Kind of the most simple suggestion to make - we don't try to be fancy. Turns out, it's still pretty useful (the couple existing tests that trigger this error end up fixed - for this error - upon applying the fix). r? ``@estebank`` cc ``@nikomatsakis``
2022-02-17Rollup merge of #94011 - est31:let_else, r=lcnrMatthias Krüger-1/+1
Even more let_else adoptions Continuation of #89933, #91018, #91481, #93046, #93590.
2022-02-17Rollup merge of #93758 - nnethercote:improve-folding-comments, r=BoxyUwUMatthias Krüger-77/+113
Improve comments about type folding/visiting. I have found this code confusing for years. I've always roughly understood it, but never exactly. I just made my fourth(?) attempt and finally cracked it. This commit improves the comments. In particular, it explicitly describes how you can't do a custom fold/visit of any type; there are actually a handful of "types of interest" (e.g. `Ty`, `Predicate`, `Region`, `Const`) that can be custom folded/visted, and all other types just get a generic traversal. I think this was the part that eluded me on all my prior attempts at understanding. The commit also updates comments to account for some newer changes such as the fallible/infallible folding distinction, does some minor reorderings, and moves one `impl` to a better place. r? `@BoxyUwU`
2022-02-17Suggest copying trait associated type bounds on lifetime errorJack Huey-0/+6
2022-02-17Fix ScalarInt to char conversionTomasz Miąsko-4/+14
to avoid panic for invalid Unicode scalar values
2022-02-17Improve comments about type folding/visiting.Nicholas Nethercote-77/+113
I have found this code confusing for years. I've always roughly understood it, but never exactly. I just made my fourth(?) attempt and finally cracked it. This commit improves the comments. In particular, it explicitly describes how you can't do a custom fold/visit of any type; there are actually a handful of "types of interest" (e.g. `Ty`, `Predicate`, `Region`, `Const`) that can be custom folded/visted, and all other types just get a generic traversal. I think this was the part that eluded me on all my prior attempts at understanding. The commit also updates comments to account for some newer changes such as the fallible/infallible folding distinction, does some minor reorderings, and moves one `impl` to a better place.
2022-02-16Use a `Field` in `ConstraintCategory::ClosureUpvar`pierwill-2/+2
2022-02-16Adopt let_else in even more placesest31-1/+1
2022-02-16Rollup merge of #94037 - tmiasko:verbose, r=Mark-SimulacrumMatthias Krüger-5/+0
Fix inconsistent symbol mangling with -Zverbose Always skip arguments that are the defaults of their respective parameters, to avoid generating inconsistent symbols for builds with `-Zverbose` flag and without it.
2022-02-16Rollup merge of #94020 - tmiasko:pp, r=oli-obkMatthias Krüger-7/+25
Support pretty printing of invalid constants Make it possible to pretty print invalid constants by introducing a fallible variant of `destructure_const` and falling back to debug formatting when it fails. Closes #93688.
2022-02-16Rollup merge of #94017 - fee1-dead:unub, r=bjorn3Matthias Krüger-2/+4
Clarify confusing UB statement in MIR
2022-02-16allow special behavior when printing const inferlcnr-7/+24
2022-02-16extract Res to `generics_of` def_id conversionlcnr-1/+32
2022-02-16Auto merge of #93800 - b-naber:static-initializers-mir-val, r=oli-obkbors-9/+23
Treat static refs as `mir::ConstantKind::Val` With the upcoming introduction of Valtrees we want to treat more values as `mir::ConstantKind::Val` directly. r? `@lcnr` cc `@oli-obk`
2022-02-16Fix inconsistent symbol mangling with -ZverboseTomasz Miąsko-5/+0
Always skip arguments that are the defaults of their respective parameters, to avoid generating inconsistent symbols for builds with `-Zverbose` flag and without it.
2022-02-16Support pretty printing of invalid constantsTomasz Miąsko-7/+25
Make it possible to pretty print invalid constants by introducing a fallible variant of `destructure_const` and falling back to debug formatting when it fails.
2022-02-15try to bless 32bit mir tests manuallyb-naber-8/+4
2022-02-15use AllocId and Ty in ExprKind::StaticRef and delay ConstValue constructionb-naber-3/+9
2022-02-15use mir::Visitor when collecting alloc_ids in pretty printingb-naber-7/+19
2022-02-15treat mir::ConstantKind::Val correctly in check_static_ptrb-naber-1/+1
2022-02-15Inline GenericArg conversion functionsTomasz Miąsko-0/+4
2022-02-15Inline UnifyKey::index and UnifyKey::from_indexTomasz Miąsko-0/+4
2022-02-15Clarify confusing UB statement in MIRDeadbeef-2/+4
2022-02-15Overhaul `Const`.Nicholas Nethercote-243/+273
Specifically, rename the `Const` struct as `ConstS` and re-introduce `Const` as this: ``` pub struct Const<'tcx>(&'tcx Interned<ConstS>); ``` This now matches `Ty` and `Predicate` more closely, including using pointer-based `eq` and `hash`. Notable changes: - `mk_const` now takes a `ConstS`. - `Const` was copy, despite being 48 bytes. Now `ConstS` is not, so need a we need separate arena for it, because we can't use the `Dropless` one any more. - Many `&'tcx Const<'tcx>`/`&Const<'tcx>` to `Const<'tcx>` changes - Many `ct.ty` to `ct.ty()` and `ct.val` to `ct.val()` changes. - Lots of tedious sigil fiddling.
2022-02-15Remove unnecessary `RegionKind::` quals.Nicholas Nethercote-11/+11
The variant names are exported, so we can use them directly (possibly with a `ty::` qualifier). Lots of places already do this, this commit just increases consistency.
2022-02-15Overhaul `RegionKind` and `Region`.Nicholas Nethercote-59/+155
Specifically, change `Region` from this: ``` pub type Region<'tcx> = &'tcx RegionKind; ``` to this: ``` pub struct Region<'tcx>(&'tcx Interned<RegionKind>); ``` This now matches `Ty` and `Predicate` more closely. Things to note - Regions have always been interned, but we haven't been using pointer-based `Eq` and `Hash`. This is now happening. - I chose to impl `Deref` for `Region` because it makes pattern matching a lot nicer, and `Region` can be viewed as just a smart wrapper for `RegionKind`. - Various methods are moved from `RegionKind` to `Region`. - There is a lot of tedious sigil changes. - A couple of types like `HighlightBuilder`, `RegionHighlightMode` now have a `'tcx` lifetime because they hold a `Ty<'tcx>`, so they can call `mk_region`. - A couple of test outputs change slightly, I'm not sure why, but the new outputs are a little better.
2022-02-15Overhaul `PredicateInner` and `Predicate`.Nicholas Nethercote-63/+62
Specifically, change `Ty` from this: ``` pub struct Predicate<'tcx> { inner: &'tcx PredicateInner<'tcx> } ``` to this: ``` pub struct Predicate<'tcx>(&'tcx Interned<PredicateS<'tcx>>) ``` where `PredicateInner` is renamed as `PredicateS`. This (plus a few other minor changes) makes the parallels with `Ty` and `TyS` much clearer, and makes the uniqueness more explicit.
2022-02-15Overhaul `TyS` and `Ty`.Nicholas Nethercote-253/+255
Specifically, change `Ty` from this: ``` pub type Ty<'tcx> = &'tcx TyS<'tcx>; ``` to this ``` pub struct Ty<'tcx>(Interned<'tcx, TyS<'tcx>>); ``` There are two benefits to this. - It's now a first class type, so we can define methods on it. This means we can move a lot of methods away from `TyS`, leaving `TyS` as a barely-used type, which is appropriate given that it's not meant to be used directly. - The uniqueness requirement is now explicit, via the `Interned` type. E.g. the pointer-based `Eq` and `Hash` comes from `Interned`, rather than via `TyS`, which wasn't obvious at all. Much of this commit is boring churn. The interesting changes are in these files: - compiler/rustc_middle/src/arena.rs - compiler/rustc_middle/src/mir/visit.rs - compiler/rustc_middle/src/ty/context.rs - compiler/rustc_middle/src/ty/mod.rs Specifically: - Most mentions of `TyS` are removed. It's very much a dumb struct now; `Ty` has all the smarts. - `TyS` now has `crate` visibility instead of `pub`. - `TyS::make_for_test` is removed in favour of the static `BOOL_TY`, which just works better with the new structure. - The `Eq`/`Ord`/`Hash` impls are removed from `TyS`. `Interned`s impls of `Eq`/`Hash` now suffice. `Ord` is now partly on `Interned` (pointer-based, for the `Equal` case) and partly on `TyS` (contents-based, for the other cases). - There are many tedious sigil adjustments, i.e. adding or removing `*` or `&`. They seem to be unavoidable.
2022-02-15Rename `Interned` as `InternedInSet`.Nicholas Nethercote-35/+36
This will let us introduce a more widely-used `Interned` type in the next commit.
2022-02-14Auto merge of #93298 - lcnr:issue-92113, r=cjgillotbors-27/+5
make `find_similar_impl_candidates` even fuzzier continues the good work of `@BGR360` in #92223. I might have overshot a bit and we're now slightly too fuzzy :sweat_smile: with this we can now also simplify `simplify_type`, which is nice :3
2022-02-14Auto merge of #93938 - BoxyUwU:fix_res_self_ty, r=lcnrbors-1/+1
Make `Res::SelfTy` a struct variant and update docs I found pattern matching on a `(Option<DefId>, Option<(DefId, bool)>)` to not be super readable, additionally the doc comments on the types in a tuple variant aren't visible anywhere at use sites as far as I can tell (using rust analyzer + vscode) The docs incorrectly assumed that the `DefId` in `Option<(DefId, bool)>` would only ever be for an impl item and I also found the code examples to be somewhat unclear about which `DefId` was being talked about. r? `@lcnr` since you reviewed the last PR changing these docs
2022-02-14fast_reject: remove `StripReferences`lcnr-27/+5
2022-02-13Rollup merge of #93810 - matthewjasper:chalk-and-canonical-universes, r=jackh726Matthias Krüger-3/+3
Improve chalk integration - Support subtype bounds in chalk lowering - Handle universes in canonicalization - Handle type parameters in chalk responses - Use `chalk_ir::LifetimeData::Empty` for `ty::ReEmpty` - Remove `ignore-compare-mode-chalk` for tests that no longer hang (they may still fail or ICE) This is enough to get a hello world program to compile with `-Zchalk` now. Some of the remaining issues that are needed to get Chalk integration working on larger programs are: - rust-lang/chalk#234 - rust-lang/chalk#548 - rust-lang/chalk#734 - Generators are handled differently in chalk and rustc r? `@jackh726`
2022-02-13Auto merge of #93670 - erikdesjardins:noundef, r=nikicbors-1/+7
Apply noundef attribute to &T, &mut T, Box<T>, bool This doesn't handle `char` because it's a bit awkward to distinguish it from `u32` at this point in codegen. Note that this _does not_ change whether or not it is UB for `&`, `&mut`, or `Box` to point to undef. It only applies to the pointer itself, not the pointed-to memory. Fixes (partially) #74378. r? `@nikic` cc `@RalfJung`
2022-02-12change to a struct variantEllen-1/+1
2022-02-11Renumber universes when canonicalizing for ChalkMatthew Jasper-3/+3
This is required to avoid creating large numbers of universes from each Chalk query, while still having enough universe information for lifetime errors.
2022-02-11use body.tainted_by_error to skip loading MIRMichael Goulet-2/+1
2022-02-11add tainted_by_errors to mir::BodyMichael Goulet-1/+8
2022-02-11rework borrowck errors so that it's harder to not set taintedMichael Goulet-1/+1
2022-02-11always cache result from mir_borrowckMichael Goulet-1/+2
2022-02-11skip const eval if we have an error in borrowckMichael Goulet-1/+14
2022-02-11implement tainted_by_errors in mir borrowckMichael Goulet-0/+1
2022-02-11Auto merge of #93893 - oli-obk:sad_revert, r=oli-obkbors-75/+27
Revert lazy TAIT PR Revert https://github.com/rust-lang/rust/pull/92306 (sorry `@Aaron1011,` will include your changes in the fix PR) Revert https://github.com/rust-lang/rust/pull/93783 Revert https://github.com/rust-lang/rust/pull/92007 fixes https://github.com/rust-lang/rust/issues/93788 fixes https://github.com/rust-lang/rust/issues/93794 fixes https://github.com/rust-lang/rust/issues/93821 fixes https://github.com/rust-lang/rust/issues/93831 fixes https://github.com/rust-lang/rust/issues/93841
2022-02-11Revert "Auto merge of #92007 - oli-obk:lazy_tait2, r=nikomatsakis"Oli Scherer-75/+27
This reverts commit e7cc3bddbe0d0e374d05e7003e662bba1742dbae, reversing changes made to 734368a200904ef9c21db86c595dc04263c87be0.