summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src
AgeCommit message (Collapse)AuthorLines
2021-08-27Do not ICE on HIR based WF check when involving lifetimesEsteban Küber-3/+4
Fix #87549.
2021-07-24Rollup merge of #87322 - chazkiker2:fix/suggestion-ref-sync-send, r=estebankYuki Okushi-5/+30
fix: clarify suggestion that `&T` must refer to `T: Sync` for `&T: Send` ### Description - [x] fix #86507 - [x] add UI test for relevant code from issue - [x] change `rustc_trait_selection/src/traits/error_reporting/suggestions.rs` to include a more clear suggestion when `&T` fails to satisfy `Send` bounds due to the fact that `T` fails to implement `Sync` - [x] update UI test in Clippy: `src/tools/tests/ui/future_not_send.stderr`
2021-07-22Squash all commits.chaz-kiker-5/+30
add test for issue 86507 add stderr for issue 86507 update issue-86507 UI test add comment for the expected error in UI test file add proper 'refers to <ref_type>' in suggestion update diagnostic phrasing; update test to match new phrasing; re-organize logic for checking T: Sync evaluate additional obligation to figure out if T is Sync run './x.py test tidy --bless' incorporate changes from review; reorganize logic for readability
2021-07-22Use instrument debugging for more readable logsOli Scherer-13/+9
2021-07-22Auto merge of #87265 - Aaron1011:hir-wf-fn, r=estebankbors-2/+2
Support HIR wf checking for function signatures During function type-checking, we normalize any associated types in the function signature (argument types + return type), and then create WF obligations for each of the normalized types. The HIR wf code does not currently support this case, so any errors that we get have imprecise spans. This commit extends `ObligationCauseCode::WellFormed` to support recording a function parameter, allowing us to get the corresponding HIR type if an error occurs. Function typechecking is modified to pass this information during signature normalization and WF checking. The resulting code is fairly verbose, due to the fact that we can no longer normalize the entire signature with a single function call. As part of the refactoring, we now perform HIR-based WF checking for several other 'typed items' (statics, consts, and inherent impls). As a result, WF and projection errors in a function signature now have a precise span, which points directly at the responsible type. If a function signature is constructed via a macro, this will allow the error message to point at the code 'most responsible' for the error (e.g. a user-supplied macro argument).
2021-07-21Improve caching during trait evaluationAaron Hill-10/+27
Previously, we would 'forget' that we had `'static` regions in some place during trait evaluation. This lead to us producing `EvaluatedToOkModuloRegions` when we could have produced `EvaluatedToOk`, causing us to perform unnecessary work. This PR preserves `'static` regions when we canonicalize a predicate for `evaluate_obligation`, and when we 'freshen' a predicate during trait evaluation. Thie ensures that evaluating a predicate containing `'static` regions can produce `EvaluatedToOk` (assuming that we don't end up introducing any region dependencies during evaluation). Building off of this improved caching, we use `predicate_must_hold_considering_regions` during fulfillment of projection predicates to see if we can skip performing additional work. We already do this for trait predicates, but doing this for projection predicates lead to mixed performance results without the above caching improvements.
2021-07-20Support HIR wf checking for function signaturesAaron Hill-2/+2
During function type-checking, we normalize any associated types in the function signature (argument types + return type), and then create WF obligations for each of the normalized types. The HIR wf code does not currently support this case, so any errors that we get have imprecise spans. This commit extends `ObligationCauseCode::WellFormed` to support recording a function parameter, allowing us to get the corresponding HIR type if an error occurs. Function typechecking is modified to pass this information during signature normalization and WF checking. The resulting code is fairly verbose, due to the fact that we can no longer normalize the entire signature with a single function call. As part of the refactoring, we now perform HIR-based WF checking for several other 'typed items' (statics, consts, and inherent impls). As a result, WF and projection errors in a function signature now have a precise span, which points directly at the responsible type. If a function signature is constructed via a macro, this will allow the error message to point at the code 'most responsible' for the error (e.g. a user-supplied macro argument).
2021-07-20Auto merge of #87244 - jackh726:issue-71883, r=estebankbors-2/+9
Better diagnostics with mismatched types due to implicit static lifetime Fixes #78113 I think this is my first diagnostics PR...definitely happy to hear thoughts on the direction/implementation here. I was originally just trying to solve the error above, where the lifetime on a GAT was causing a cryptic "mismatched types" error. But as I was writing this, I realized that this (unintentionally) also applied to a different case: `wf-in-foreign-fn-decls-issue-80468.rs`. I'm not sure if this diagnostic should get a new error code, or even reuse an existing one. And, there might be some ways to make this even more generalized. Also, the error is a bit more lengthy and verbose than probably needed. So thoughts there are welcome too. This PR essentially ended up adding a new nice region error pass that triggers if a type doesn't match the self type of an impl which is selected because of a predicate because of an implicit static bound on that self type. r? `@estebank`
2021-07-20Auto merge of #87141 - spastorino:remove_impl_trait_in_bindings, r=oli-obkbors-9/+3
Remove impl trait in bindings Closes #86729 r? `@oli-obk`
2021-07-19Better diagnostics when mismatched types due to implict static lifetimejackh726-2/+9
2021-07-19Auto merge of #87225 - estebank:cleanup, r=oli-obkbors-12/+20
Various diagnostics clean ups/tweaks * Always point at macros, including derive macros * Point at non-local items that introduce a trait requirement * On private associated item, point at definition
2021-07-19Various diagnostics clean ups/tweaksEsteban Küber-12/+20
* Always point at macros, including derive macros * Point at non-local items that introduce a trait requirement * On private associated item, point at definition
2021-07-18Revert "structural_match: non-structural-match ty closures"Santiago Pastorino-5/+1
Reverts #73353
2021-07-18Remove OpaqueTyOrigin::Misc, use TyAlias insteadSantiago Pastorino-2/+2
2021-07-17Remove OpaqueTyOrigin::BindingSantiago Pastorino-3/+1
2021-07-17Add needs_normalizationjackh726-4/+21
2021-07-17Some perf optimizations and loggingjackh726-10/+16
2021-07-16Auto merge of #83898 - Aaron1011:feature/hir-wf, r=estebankbors-25/+57
Add initial implementation of HIR-based WF checking for diagnostics During well-formed checking, we walk through all types 'nested' in generic arguments. For example, WF-checking `Option<MyStruct<u8>>` will cause us to check `MyStruct<u8>` and `u8`. However, this is done on a `rustc_middle::ty::Ty`, which has no span information. As a result, any errors that occur will have a very general span (e.g. the definintion of an associated item). This becomes a problem when macros are involved. In general, an associated type like `type MyType = Option<MyStruct<u8>>;` may have completely different spans for each nested type in the HIR. Using the span of the entire associated item might end up pointing to a macro invocation, even though a user-provided span is available in one of the nested types. This PR adds a framework for HIR-based well formed checking. This check is only run during error reporting, and is used to obtain a more precise span for an existing error. This is accomplished by individually checking each 'nested' type in the HIR for the type, allowing us to find the most-specific type (and span) that produces a given error. The majority of the changes are to the error-reporting code. However, some of the general trait code is modified to pass through more information. Since this has no soundness implications, I've implemented a minimal version to begin with, which can be extended over time. In particular, this only works for HIR items with a corresponding `DefId` (e.g. it will not work for WF-checking performed within function bodies).
2021-07-16Add initial implementation of HIR-based WF checking for diagnosticsAaron Hill-25/+57
During well-formed checking, we walk through all types 'nested' in generic arguments. For example, WF-checking `Option<MyStruct<u8>>` will cause us to check `MyStruct<u8>` and `u8`. However, this is done on a `rustc_middle::ty::Ty`, which has no span information. As a result, any errors that occur will have a very general span (e.g. the definintion of an associated item). This becomes a problem when macros are involved. In general, an associated type like `type MyType = Option<MyStruct<u8>>;` may have completely different spans for each nested type in the HIR. Using the span of the entire associated item might end up pointing to a macro invocation, even though a user-provided span is available in one of the nested types. This PR adds a framework for HIR-based well formed checking. This check is only run during error reporting, and is used to obtain a more precise span for an existing error. This is accomplished by individually checking each 'nested' type in the HIR for the type, allowing us to find the most-specific type (and span) that produces a given error. The majority of the changes are to the error-reporting code. However, some of the general trait code is modified to pass through more information. Since this has no soundness implications, I've implemented a minimal version to begin with, which can be extended over time. In particular, this only works for HIR items with a corresponding `DefId` (e.g. it will not work for WF-checking performed within function bodies).
2021-07-16Rollup merge of #87200 - oli-obk:fixup_fixup_opaque_types, r=nikomatsakisGuillaume Gomez-8/+6
TAIT: Infer all inference variables in opaque type substitutions via InferCx The previous algorithm was correct for the example given in its documentation, but when the TAIT was declared as a free item instead of an associated item, the generic parameters were the wrong ones. cc `@spastorino` r? `@nikomatsakis`
2021-07-16Add some more tracing instrumentationOli Scherer-8/+6
2021-07-15Remove failed and review commentsjackh726-99/+69
2021-07-13WIP partial apply fixjackh726-104/+193
2021-07-09Replace associated item bound vars with placeholders when projecting.jackh726-0/+365
2021-07-08Rollup merge of #86726 - ↵Guillaume Gomez-5/+7
sexxi-goose:use-diagnostic-item-for-rfc2229-migration, r=nikomatsakis Use diagnostic items instead of lang items for rfc2229 migrations This PR removes the `Send`, `UnwindSafe` and `RefUnwindSafe` lang items introduced in https://github.com/rust-lang/rust/pull/84730, and uses diagnostic items instead to check for `Send`, `UnwindSafe` and `RefUnwindSafe` traits for RFC2229 migrations. r? ```@nikomatsakis```
2021-07-06Make type_implements_trait not a queryAman Arora-43/+48
2021-07-05Auto merge of #86674 - Aaron1011:new-querify-limits, r=michaelwoeristerbors-7/+7
Query-ify global limit attribute handling Currently, we read various 'global limits' from inner attributes the crate root (`recursion_limit`, `move_size_limit`, `type_length_limit`, `const_eval_limit`). These limits are then stored in `Sessions`, allowing them to be access from a `TyCtxt` without registering a dependency on the crate root attributes. This PR moves the calculation of these global limits behind queries, so that we properly track dependencies on crate root attributes. During the setup of macro expansion (before we've created a `TyCtxt`), we need to access the recursion limit, which is now done by directly calling into the code shared by the normal query implementations.
2021-07-04Combine individual limit queries into single `limits` queryAaron Hill-7/+7
2021-07-04Auto merge of #86866 - nikomatsakis:issue-84841, r=oli-obkbors-5/+15
Hack: Ignore inference variables in certain queries Fixes #84841 Fixes #86753 Some queries are not built to accept types with inference variables, which can lead to ICEs. These queries probably ought to be converted to canonical form, but as a quick workaround, we can return conservative results in the case that inference variables are found. We should file a follow-up issue (and update the FIXMEs...) to do the proper refactoring. cc `@arora-aman` r? `@oli-obk`
2021-07-04Query-ify global limit attribute handlingAaron Hill-7/+7
2021-07-04tag issues with FIXMENiko Matsakis-1/+1
2021-07-04allow inference vars in type_implements_traitNiko Matsakis-5/+15
2021-07-03Auto merge of #85090 - Aaron1011:type-outlives-global, r=matthewjasper,jackh726bors-1/+9
Return `EvaluatedToOk` when type in outlives predicate is global A global type doesn't reference any local regions or types, so it's guaranteed to outlive any region.
2021-07-03Remove `ty::Binder::bind()`Yuki Okushi-1/+1
Co-authored-by: Noah Lev <camelidcamel@gmail.com>
2021-06-29Rename variableRoxane-5/+5
2021-06-29Return `EvaluatedToOk` when type in outlives predicate is globalAaron Hill-1/+9
A global type doesn't reference any local regions or types, so it's guaranteed to outlive any region.
2021-06-29Use diagnostic items to check for Send, UnwindSafe and RefUnwindSafe traitsRoxane Fruytier-2/+4
2021-06-23Auto merge of #86386 - ↵bors-0/+24
inquisitivecrystal:better-errors-for-display-traits-v3, r=estebank Better errors for Debug and Display traits Currently, if someone tries to pass value that does not implement `Debug` or `Display` to a formatting macro, they get a very verbose and confusing error message. This PR changes the error messages for missing `Debug` and `Display` impls to be less overwhelming in this case, as suggested by #85844. I was a little less aggressive in changing the error message than that issue proposed. Still, this implementation would be enough to reduce the number of messages to be much more manageable. After this PR, information on the cause of an error involving a `Debug` or `Display` implementation would suppressed if the requirement originated within a standard library macro. My reasoning was that errors originating from within a macro are confusing when they mention details that the programmer can't see, and this is particularly problematic for `Debug` and `Display`, which are most often used via macros. It is possible that either a broader or a narrower criterion would be better. I'm quite open to any feedback. Fixes #85844.
2021-06-18add various coments to explain how the code worksNiko Matsakis-9/+3
2021-06-16Improve errors for missing Debug and Display implsAris Merchant-0/+24
2021-06-15Refactor to make interpreter and codegen backend neutral to vtable internal ↵Charles Lew-63/+89
representation.
2021-06-12Auto merge of #86130 - BoxyUwU:abstract_const_as_cast, r=oli-obkbors-1/+30
const_eval_checked: Support as casts in abstract consts
2021-06-10support `as _` and add testsEllen-1/+3
2021-06-09Add more tests + visit_ty in some placesEllen-12/+21
2021-06-08Support as casts in abstract constsEllen-9/+27
2021-06-07Differentiate different defining uses of taits when they reference distinct ↵Santiago Pastorino-10/+7
generic parameters
2021-06-07Remove substs from OpaqueTypeDecl, use the one in OpaqueTypeKeySantiago Pastorino-27/+25
2021-06-07Use substs from opaque type key instead of using it from opaque_declSantiago Pastorino-2/+1
2021-06-07Make opaque type map key be of type OpaqueTypeKeySantiago Pastorino-4/+10
2021-06-07Make OpaqueTypeKey the key of opaque types mapSantiago Pastorino-5/+5