summary refs log tree commit diff
path: root/compiler/rustc_middle/src/ty
AgeCommit message (Collapse)AuthorLines
2021-11-25Rollup merge of #91096 - compiler-errors:elaborate_opaque_trait, r=estebankMatthias Krüger-75/+230
Print associated types on opaque `impl Trait` types This PR generalizes #91021, printing associated types for all opaque `impl Trait` types instead of just special-casing for future. before: ``` error[E0271]: type mismatch resolving `<impl Iterator as Iterator>::Item == u32` ``` after: ``` error[E0271]: type mismatch resolving `<impl Iterator<Item = usize> as Iterator>::Item == u32` ``` --- Questions: 1. I'm kinda lost in binders hell with this one. Is all of the `rebind`ing necessary? 2. Is there a map collection type that will give me a stable iteration order? Doesn't seem like TraitRef is Ord, so I can't just sort later.. 3. I removed the logic that suppresses printing generator projection types. It creates outputs like this [gist](https://gist.github.com/compiler-errors/d6f12fb30079feb1ad1d5f1ab39a3a8d). Should I put that back? 4. I also added spaces between traits, `impl A+B` -> `impl A + B`. I quite like this change, but is there a good reason to keep it like that? r? ````@estebank````
2021-11-23Fix printing unit return ty, don't elaborate FnOnce unless we see itMichael Goulet-7/+16
2021-11-23Suppress noisy generator associated typeMichael Goulet-4/+14
2021-11-23Elaborate trait generics and associated typesMichael Goulet-74/+210
2021-11-23Derive Ord and PartialOrd for TraitRefMichael Goulet-1/+1
2021-11-22Use `derive_default_enum` in the compilerJacob Pratt-7/+2
2021-11-20Add space in opaque `impl Trait`Michael Goulet-3/+3
2021-11-20Rollup merge of #91021 - compiler-errors:print_future_output, r=estebankMatthias Krüger-11/+55
Elaborate `Future::Output` when printing opaque `impl Future` type I would love to see the `Output =` type when printing type errors involving opaque `impl Future`. [Test code](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=a800b481edd31575fbcaf5771a9c3678) Before (cut relevant part of output): ``` note: while checking the return type of the `async fn` --> /home/michael/test.rs:5:19 | 5 | async fn bar() -> usize { | ^^^^^ checked the `Output` of this `async fn`, found opaque type = note: expected type `usize` found opaque type `impl Future` ``` After: ``` note: while checking the return type of the `async fn` --> /home/michael/test.rs:5:19 | 5 | async fn bar() -> usize { | ^^^^^ checked the `Output` of this `async fn`, found opaque type = note: expected type `usize` found opaque type `impl Future<Output = usize>` ``` Note the "found opaque type `impl Future<Output = usize>`" in the new output. ---- Questions: 1. We skip printing the output type when it's a projection, since I have been seeing some types like `impl Future<Output = <[static generator@/home/michael/test.rs:2:11: 2:21] as Generator<ResumeTy>>::Return>` which are not particularly helpful and leak implementation detail. * Am I able to normalize this type within `rustc_middle::ty::print::pretty`? Alternatively, can we normalize it when creating the diagnostic? Otherwise, I'm fine with skipping it and falling back to the old output. * Should I suppress any other types? I didn't encounter anything other than this generator projection type. 2. Not sure what the formatting of this should be. Do I include spaces in `Output = `?
2021-11-20Rollup merge of #90999 - RalfJung:miri_simd, r=oli-obkMatthias Krüger-0/+5
fix CTFE/Miri simd_insert/extract on array-style repr(simd) types The changed test would previously fail since `place_index` would just return the only field of `f32x4`, i.e., the array -- rather than *indexing into* the array which is what we have to do. The new helper methods will also be needed for https://github.com/rust-lang/miri/issues/1912. r? ``````@oli-obk``````
2021-11-19Rollup merge of #90990 - nnethercote:arenas-cleanup, r=oli-obkYuki Okushi-9/+9
Arenas cleanup I was looking closely at the arenas code and here are some small improvement to readability.
2021-11-18Print output ty for opaque future tyMichael Goulet-11/+55
2021-11-18fix CTFE/Miri simd_insert/extract on array-style repr(simd) typesRalf Jung-0/+5
2021-11-18rustc: Remove `#[rustc_synthetic]`Vadim Petrochenkov-18/+3
This function parameter attribute was introduced in https://github.com/rust-lang/rust/pull/44866 as an intermediate step in implementing `impl Trait`, it's not necessary or used anywhere by itself.
2021-11-17Remove unnecessary lifetime argument from arena macros.Nicholas Nethercote-9/+9
Because it's always `'tcx`. In fact, some of them use a mixture of passed-in `$tcx` and hard-coded `'tcx`, so no other lifetime would even work. This makes the code easier to read.
2021-11-16Rollup merge of #90910 - RalfJung:const-discriminant-empty-enum, r=petrochenkovYuki Okushi-1/+3
fix getting the discriminant of a zero-variant enum Fixes https://github.com/rust-lang/rust/issues/89765
2021-11-14fix getting the discriminant of a zero-variant enumRalf Jung-1/+3
2021-11-11Use `associated_item_def_ids` moreMatthew Jasper-6/+6
2021-11-09Add `ty::Visibility::is_public()`inquisitivecrystal-1/+5
2021-11-09Rollup merge of #90035 - SparrowLii:rfc2528, r=jackh726Matthias Krüger-0/+4
implement rfc-2528 type_changing-struct-update This PR implement rfc2528-type_changing-struct-update. The main change process is as follows: 1. Move the processing part of `base_expr` into `check_expr_struct_fields` to avoid returning `remaining_fields` (a relatively complex hash table) 2. Before performing the type consistency check(`check_expr_has_type_or_error`), if the `type_changing_struct_update` feature is set, enter a different processing flow, otherwise keep the original flow 3. In the case of the same structure definition, check each field in `remaining_fields`. If the field in `base_expr` is not the suptype of the field in `adt_ty`, an error(`FeildMisMatch`) will be reported. The MIR part does not need to be changed, because only the items contained in `remaining_fields` will be extracted from `base_expr` when MIR is generated. This means that fields with different types in `base_expr` will not be used Updates #86618 cc `@nikomatsakis`
2021-11-07Rename functions reflect that inline const is also "typeck_child"Gary Guo-9/+10
2021-11-07Implement type inference for inline constsGary Guo-21/+158
In most cases it is handled in the same way as closures.
2021-11-07Give inline const separate DefKindGary Guo-1/+2
2021-11-06type error go brrrrrrrrEllen-2/+6
2021-11-06Auto merge of #88441 - jackh726:closure_norm, r=nikomatsakisbors-0/+1
Normalize obligations for closure confirmation Based on #90017 Fixes #74261 Fixes #71955 Fixes #88459 r? `@nikomatsakis`
2021-11-05Update LLVM comments around NoAliasMutRefJosh Stone-3/+4
2021-10-28implement type-changing-struct-updateSparrowLii-0/+4
put the test dir in test/ui/rfcs
2021-10-25Avoid a branch on key being local for queries that use the same local and ↵bjorn3-0/+50
extern providers
2021-10-23Auto merge of #90104 - spastorino:coherence-for-negative-trait, r=nikomatsakisbors-9/+93
Implement coherence checks for negative trait impls The main purpose of this PR is to be able to [move Error trait to core](https://github.com/rust-lang/project-error-handling/issues/3). This feature is necessary to handle the following from impl on box. ```rust impl From<&str> for Box<dyn Error> { ... } ``` Without having negative traits affect coherence moving the error trait into `core` and moving that `From` impl to `alloc` will cause the from impl to no longer compiler because of a potential future incompatibility. The compiler indicates that `&str` _could_ introduce an `Error` impl in the future, and thus prevents the `From` impl in `alloc` that would cause overlap with `From<E: Error> for Box<dyn Error>`. Adding `impl !Error for &str {}` with the negative trait coherence feature will disable this error by encoding a stability guarantee that `&str` will never implement `Error`, making the `From` impl compile. We would have this in `alloc`: ```rust impl From<&str> for Box<dyn Error> {} // A impl<E> From<E> for Box<dyn Error> where E: Error {} // B ``` and this in `core`: ```rust trait Error {} impl !Error for &str {} ``` r? `@nikomatsakis` This PR was built on top of `@yaahc` PR #85764. Language team proposal: to https://github.com/rust-lang/lang-team/issues/96
2021-10-22Document flip polaritySantiago Pastorino-0/+4
2021-10-20Build jump table at runtime.Camille GILLOT-1/+1
2021-10-20Merge two query callbacks arrays.Camille GILLOT-1/+8
2021-10-20Move def_path_hash_to_def_id to rustc_middle.Camille GILLOT-5/+21
2021-10-20Avoid trivial lambdas.Camille GILLOT-4/+6
2021-10-20Add polarity to TraitPredicateSantiago Pastorino-9/+89
2021-10-19Auto merge of #89933 - est31:let_else, r=michaelwoeristerbors-12/+5
Adopt let_else across the compiler This performs a substitution of code following the pattern: ``` let <id> = if let <pat> = ... { identity } else { ... : ! }; ``` To simplify it to: ``` let <pat> = ... { identity } else { ... : ! }; ``` By adopting the `let_else` feature (cc #87335). The PR also updates the syn crate because the currently used version of the crate doesn't support `let_else` syntax yet. Note: Generally I'm the person who *removes* usages of unstable features from the compiler, not adds more usages of them, but in this instance I think it hopefully helps the feature get stabilized sooner and in a better state. I have written a [comment](https://github.com/rust-lang/rust/issues/87335#issuecomment-944846205) on the tracking issue about my experience and what I feel could be improved before stabilization of `let_else`.
2021-10-18Auto merge of #89124 - cjgillot:owner-info, r=michaelwoeristerbors-7/+3
Index and hash HIR as part of lowering Part of https://github.com/rust-lang/rust/pull/88186 ~Based on https://github.com/rust-lang/rust/pull/88880 (see merge commit).~ Once HIR is lowered, it is later indexed by the `index_hir` query and hashed for `crate_hash`. This PR moves those post-processing steps to lowering itself. As a side objective, the HIR crate data structure is refactored as an `IndexVec<LocalDefId, Option<OwnerInfo<'hir>>>` where `OwnerInfo` stores all the relevant information for an HIR owner. r? `@michaelwoerister` cc `@petrochenkov`
2021-10-18Normalize obligations for closure confirmationjackh726-0/+1
2021-10-17Rollup merge of #89946 - JohnTitor:fix-89686, r=petrochenkovMatthias Krüger-5/+10
Fix an ICE with TAITs and Future Fixes #89686
2021-10-17Rollup merge of #89738 - eddyb:extern-crate-recursion, r=nagisaMatthias Krüger-10/+18
ty::pretty: prevent infinite recursion for `extern crate` paths. Fixes #55779, fixes #87932. This fix is based on `@estebank's` idea in https://github.com/rust-lang/rust/issues/55779#issuecomment-614758510 - but instead of trying to get `try_print_visible_def_path_recur`'s cycle detection to work in this case, this PR "just" disables the "visible path" feature when printing the path to an `extern crate`, so that the old recursion chain of `try_print_visible_def_path -> print_def_path -> try_print_visible_def_path`, is now impossible. Both tests have been confirmed to crash `rustc` because of a stack overflow, without the fix.
2021-10-17Auto merge of #89514 - davidtwco:polymorphize-shims-and-predicates, r=lcnrbors-12/+33
polymorphization: shims and predicates Supersedes #75737 and #75414. This pull request includes up some changes to polymorphization which hadn't landed previously and gets stage2 bootstrapping and the test suite passing when polymorphization is enabled. There are still issues with `type_id` and polymorphization to investigate but this should get polymorphization in a reasonable state to work on. - #75737 and #75414 both worked but were blocked on having the rest of the test suite pass (with polymorphization enabled) with and without the PRs. It makes more sense to just land these so that the changes are in. - #75737's changes remove the restriction of `InstanceDef::Item` on polymorphization, so that shims can now be polymorphized. This won't have much of an effect until polymorphization's analysis is more advanced, but it doesn't hurt. - #75414's changes remove all logic which marks parameters as used based on their presence in predicates - given #75675, this will enable more polymorphization and avoid the symbol clashes that predicate logic previously sidestepped. - Polymorphization now explicitly checks (and skips) foreign items, this is necessary for stage2 bootstrapping to work when polymorphization is enabled. - The conditional determining the emission of a note adding context to a post-monomorphization error has been modified. Polymorphization results in `optimized_mir` running for shims during collection where that wouldn't happen previously, some errors are emitted during `optimized_mir` and these were considered post-monomorphization errors with the existing logic (more errors and shims have a `DefId` coming from the std crate, not the local crate), adding a note that resulted in tests failing. It isn't particularly feasible to change where polymorphization runs or prevent it from using `optimized_mir`, so it seemed more reasonable to not change the conditional. - `characteristic_def_id_of_type` was being invoked during partitioning for self types of impl blocks which had projections that depended on the value of unused generic parameters of a function - this caused a ICE in a debuginfo test. If partitioning is enabled and the instance needs substitution then this is skipped. That test still fails for me locally, but not with an ICE, but it fails in a fresh checkout too, so 🤷‍♂️. r? `@lcnr`
2021-10-16Fix an ICE with TAITs and FutureYuki Okushi-5/+10
2021-10-16Adopt let_else across the compilerest31-12/+5
This performs a substitution of code following the pattern: let <id> = if let <pat> = ... { identity } else { ... : ! }; To simplify it to: let <pat> = ... { identity } else { ... : ! }; By adopting the let_else feature.
2021-10-15Move push_outlives_components to rustc_inferjackh726-214/+0
2021-10-12Filter unstable and doc hidden variants in usefulness checkingDevin Ragotzy-1/+9
Add test cases for unstable variants Add test cases for doc hidden variants Move is_doc_hidden to method on TyCtxt Add unstable variants test to reachable-patterns ui test Rename reachable-patterns -> omitted-patterns
2021-10-10ty::pretty: prevent infinite recursion for `extern crate` paths.Eduard-Mihai Burtescu-1/+8
2021-10-10ty::pretty: document "dummy Span extern crate" special-case in ↵Eduard-Mihai Burtescu-10/+11
`try_print_visible_def_path_recur`.
2021-10-10Auto merge of #88952 - skrap:add-armv7-uclibc, r=nagisabors-2/+2
Add new tier-3 target: armv7-unknown-linux-uclibceabihf This change adds a new tier-3 target: armv7-unknown-linux-uclibceabihf This target is primarily used in embedded linux devices where system resources are slim and glibc is deemed too heavyweight. Cross compilation C toolchains are available [here](https://toolchains.bootlin.com/) or via [buildroot](https://buildroot.org). The change is based largely on a previous PR #79380 with a few minor modifications. The author of that PR was unable to push the PR forward, and graciously allowed me to take it over. Per the [target tier 3 policy](https://github.com/rust-lang/rfcs/blob/master/text/2803-target-tier-policy.md), I volunteer to be the "target maintainer". This is my first PR to Rust itself, so I apologize if I've missed things!
2021-10-09Forbid hashing HIR outside of indexing.Camille GILLOT-6/+1
2021-10-09Store lowering outputs per owner.Camille GILLOT-1/+2
2021-10-08Rollup merge of #89649 - matthiaskrgr:clippycompl, r=jyn514Guillaume Gomez-2/+2
clippy::complexity fixes