summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src/traits
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-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-5/+1
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-17Add needs_normalizationjackh726-4/+21
2021-07-17Some perf optimizations and loggingjackh726-10/+16
2021-07-16Add initial implementation of HIR-based WF checking for diagnosticsAaron Hill-17/+49
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-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-42/+4
2021-07-05Auto merge of #86674 - Aaron1011:new-querify-limits, r=michaelwoeristerbors-5/+5
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-5/+5
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-5/+5
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-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-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-03don't suggest unsized indirection in where-clausesTaylor Yu-0/+4
Skip where-clauses when suggesting using indirection in combination with `?Sized` bounds on type parameters.
2021-06-02Restrict access to crate_name.Camille GILLOT-1/+3
Also remove original_crate_name, which had the exact same implementation
2021-06-01Revert "Reduce the amount of untracked state in TyCtxt"Camille Gillot-3/+1
2021-05-30Restrict access to crate_name.Camille GILLOT-1/+3
Also remove original_crate_name, which had the exact same implementation
2021-05-25Auto merge of #85481 - lcnr:const-equate, r=matthewjasperbors-3/+34
deal with `const_evaluatable_checked` in `ConstEquate` Failing to evaluate two constants which do not contain inference variables should not result in ambiguity.
2021-05-24Auto merge of #85596 - scottmcm:more-on-unimplemented, r=estebankbors-0/+9
Extend `rustc_on_implemented` to improve more `?` error messages `_Self` could match the generic definition; this adds that functionality for matching the generic definition of type parameters too. Your advice welcome on the wording of all these messages, and which things belong in the message/label/note. r? `@estebank`
2021-05-23Extend rustc_on_implemented to improve a ?-on-ControlFlow error messageScott McMurray-0/+9
2021-05-21Auto merge of #85382 - Aaron1011:project-eval, r=nikomatsakisbors-9/+1
Always produce sub-obligations when using cached projection result See https://github.com/rust-lang/rust/issues/85360 When we skip adding the sub-obligations to the `obligation` list, we can affect whether or not the final result is `EvaluatedToOk` or `EvaluatedToOkModuloObligations`. This creates problems for incremental compilation, since the projection cache is untracked shared state. To solve this issue, we unconditionally process the sub-obligations. Surprisingly, this is a slight performance *win* in many cases.
2021-05-19deal with `const_evaluatable_checked` in `ConstEquate`lcnr-3/+34
2021-05-18Rollup merge of #85369 - FabianWolff:issue-84973, r=jackh726Guillaume Gomez-13/+68
Suggest borrowing if a trait implementation is found for &/&mut <type> This pull request fixes #84973 by suggesting to borrow if a trait is not implemented for some type `T`, but it is for `&T` or `&mut T`. For instance: ```rust trait Ti {} impl<T> Ti for &T {} fn foo<T: Ti>(_: T) {} trait Tm {} impl<T> Tm for &mut T {} fn bar<T: Tm>(_: T) {} fn main() { let a: i32 = 5; foo(a); let b: Box<i32> = Box::new(42); bar(b); } ``` gives, on current nightly: ``` error[E0277]: the trait bound `i32: Ti` is not satisfied --> t2.rs:11:9 | 3 | fn foo<T: Ti>(_: T) {} | -- required by this bound in `foo` ... 11 | foo(a); | ^ the trait `Ti` is not implemented for `i32` error[E0277]: the trait bound `Box<i32>: Tm` is not satisfied --> t2.rs:14:9 | 7 | fn bar<T: Tm>(_: T) {} | -- required by this bound in `bar` ... 14 | bar(b); | ^ the trait `Tm` is not implemented for `Box<i32>` error: aborting due to 2 previous errors ``` whereas with my changes, I get: ``` error[E0277]: the trait bound `i32: Ti` is not satisfied --> t2.rs:11:9 | 3 | fn foo<T: Ti>(_: T) {} | -- required by this bound in `foo` ... 11 | foo(a); | ^ | | | expected an implementor of trait `Ti` | help: consider borrowing here: `&a` error[E0277]: the trait bound `Box<i32>: Tm` is not satisfied --> t2.rs:14:9 | 7 | fn bar<T: Tm>(_: T) {} | -- required by this bound in `bar` ... 14 | bar(b); | ^ | | | expected an implementor of trait `Tm` | help: consider borrowing mutably here: `&mut b` error: aborting due to 2 previous errors ``` In my implementation, I have added a "blacklist" to make these suggestions flexible. In particular, suggesting to borrow can interfere with other suggestions, such as to add another trait bound to a generic argument. I have tried to configure this blacklist to cause the least amount of test case failures, i.e. to model the current behavior as closely as possible (I only had to change one existing test case, and this change was quite clearly an improvement).
2021-05-17Implement jackh726's suggestionsFabian Wolff-12/+6
2021-05-17Auto merge of #85178 - cjgillot:local-crate, r=oli-obkbors-2/+2
Remove CrateNum parameter for queries that only work on local crate The pervasive `CrateNum` parameter is a remnant of the multi-crate rustc idea. Using `()` as query key in those cases avoids having to worry about the validity of the query key.
2021-05-16Always produce sub-obligations when using cached projection resultAaron Hill-9/+1