about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection
AgeCommit message (Collapse)AuthorLines
2022-04-05Rollup merge of #95525 - ohno418:suggest-derivable-trait-E0277, ↵Dylan DPC-0/+70
r=compiler-errors Suggest derivable trait on E0277 error Closes https://github.com/rust-lang/rust/issues/95099 .
2022-04-05errors: implement fallback diagnostic translationDavid Wood-7/+4
This commit updates the signatures of all diagnostic functions to accept types that can be converted into a `DiagnosticMessage`. This enables existing diagnostic calls to continue to work as before and Fluent identifiers to be provided. The `SessionDiagnostic` derive just generates normal diagnostic calls, so these APIs had to be modified to accept Fluent identifiers. In addition, loading of the "fallback" Fluent bundle, which contains the built-in English messages, has been implemented. Each diagnostic now has "arguments" which correspond to variables in the Fluent messages (necessary to render a Fluent message) but no API for adding arguments has been added yet. Therefore, diagnostics (that do not require interpolation) can be converted to use Fluent identifiers and will be output as before.
2022-04-05span: move `MultiSpan`David Wood-6/+6
`MultiSpan` contains labels, which are more complicated with the introduction of diagnostic translation and will use types from `rustc_errors` - however, `rustc_errors` depends on `rustc_span` so `rustc_span` cannot use types like `DiagnosticMessage` without dependency cycles. Introduce a new `rustc_error_messages` crate that can contain `DiagnosticMessage` and `MultiSpan`. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05errors: introduce `DiagnosticMessage`David Wood-1/+2
Introduce a `DiagnosticMessage` type that will enable diagnostic messages to be simple strings or Fluent identifiers. `DiagnosticMessage` is now used in the implementation of the standard `DiagnosticBuilder` APIs. Signed-off-by: David Wood <david.wood@huawei.com>
2022-04-05Suggest only when all fields impl the traitohno418-18/+50
2022-04-05Suggest only when Rhs for PartialEq and PartialOrd is the same type as selfohno418-29/+31
2022-04-05Suggest derivable trait on E0277ohno418-0/+36
2022-04-04diagnostics: give a special note for unsafe fn / Fn/FnOnce/FnMutMichael Howell-0/+9
Fixes #90073
2022-04-05Rollup merge of #95603 - compiler-errors:dyn-return, r=oli-obkDylan DPC-55/+79
Fix late-bound ICE in `dyn` return type suggestion This fixes the root-cause of the attached issues -- the root problem is that we're using the return type from a signature with late-bound instead of early-bound regions. The change on line 1087 (`let Some(liberated_sig) = typeck_results.liberated_fn_sigs().get(fn_hir_id) else { return false; };`) makes sure we're grabbing the _right_ return type for this suggestion to check the `dyn` predicates with. Fixes #91801 Fixes #91803 This fix also includes some drive-by changes, specifically: 1. Don't suggest boxing when we have `-> dyn Trait` and are already returning `Box<T>` where `T: Trait` (before we always boxed the value). 2. Suggestion applies even when the return type is a type alias (e.g. `type Foo = dyn Trait`). This does cause the suggestion to expand to the aliased type, but I think it's still beneficial. 3. Split up the multipart suggestion because there's a 6-line max in the printed output... I am open to splitting out the above changes, if we just want to fix the ICE first. cc: ```@terrarier2111``` and #92289
2022-04-05Rollup merge of #91873 - estebank:mention-impls-for-unsatisfied-trait, ↵Dylan DPC-83/+272
r=davidtwco Mention implementers of unsatisfied trait When encountering an unsatisfied trait bound, if there are no other suggestions, mention all the types that *do* implement that trait: ``` error[E0277]: the trait bound `f32: Foo` is not satisfied --> $DIR/impl_wf.rs:22:6 | LL | impl Baz<f32> for f32 { } | ^^^^^^^^ the trait `Foo` is not implemented for `f32` | = help: the trait `Foo` is implemented for `i32` note: required by a bound in `Baz` --> $DIR/impl_wf.rs:18:31 | LL | trait Baz<U: ?Sized> where U: Foo { } | ^^^ required by this bound in `Baz` ``` ``` error[E0277]: the trait bound `u32: Foo` is not satisfied --> $DIR/associated-types-path-2.rs:29:5 | LL | f1(2u32, 4u32); | ^^ the trait `Foo` is not implemented for `u32` | = help: the trait `Foo` is implemented for `i32` note: required by a bound in `f1` --> $DIR/associated-types-path-2.rs:13:14 | LL | pub fn f1<T: Foo>(a: T, x: T::A) {} | ^^^ required by this bound in `f1` ``` Suggest dereferencing in more cases. Fix #87437, fix #90970.
2022-04-04Remove hack, fix fmt and testsEsteban Kuber-6/+3
2022-04-04Highlight `is` in the message for emphasisEsteban Kuber-4/+3
2022-04-04Refer to the TraitRef::identity in the message to be clearerEsteban Kuber-2/+2
2022-04-04Dedup logic and improve output for other types that impl traitEsteban Kuber-63/+65
2022-04-04Fix list lengthEsteban Kuber-1/+1
2022-04-04Suggest dereferncing when possible in E0277, fix #87437Esteban Kuber-38/+66
2022-04-04Fix #90970, doesn't address #87437Esteban Kuber-6/+73
2022-04-04Mention implementers of unsatisfied traitEsteban Kuber-37/+133
When encountering an unsatisfied trait bound, if there are no other suggestions, mention all the types that *do* implement that trait: ``` error[E0277]: the trait bound `f32: Foo` is not satisfied --> $DIR/impl_wf.rs:22:6 | LL | impl Baz<f32> for f32 { } | ^^^^^^^^ the trait `Foo` is not implemented for `f32` | = help: the following other types implement trait `Foo`: Option<T> i32 str note: required by a bound in `Baz` --> $DIR/impl_wf.rs:18:31 | LL | trait Baz<U: ?Sized> where U: Foo { } | ^^^ required by this bound in `Baz` ``` Mention implementers of traits in `ImplObligation`s. Do not mention other `impl`s for closures, ranges and `?`.
2022-04-04Rollup merge of #95609 - compiler-errors:borrow-unsized-to-dyn, r=nagisaDylan DPC-0/+43
Suggest borrowing when trying to coerce unsized type into `dyn Trait` A helpful error in response to #95598, since we can't coerce e.g. `&str` into `&dyn Display`, but we can coerce `&&str` into `&dyn Display` :) Not sure if the suggestion message needs some help. Let me know, and I can refine this PR.
2022-04-04Auto merge of #95031 - compiler-errors:param-env-cache, r=Aaron1011bors-8/+8
Do not use `ParamEnv::and` when building a cache key from a param-env and trait eval candidate Do not use `ParamEnv::and` to cache a param-env with a selection/evaluation candidate. This is because if the param-env is `RevealAll` mode, and the candidate looks global (i.e. it has erased regions, which can show up when we normalize a projection type under a binder<sup>1</sup>), then when we use `ParamEnv::and` to pair the candidate and the param-env for use as a cache key, we will throw away the param-env's caller bounds, and we'll end up caching a candidate that we inferred from the param-env with a empty param-env, which may cause cache-hit later when we have an empty param-env, and possibly mess with normalization like we see in the referenced issue during codegen. Not sure how to trigger this with a more structured test, but changing `check-pass` to `build-pass` triggers the case that https://github.com/rust-lang/rust/issues/94903 detected. <sup>1.</sup> That is, we will replace the late-bound region with a placeholder, which gets canonicalized and turned into an infererence variable, which gets erased during region freshening right before we cache the result. Sorry, it's quite a few steps. Fixes #94903 r? `@Aaron1011` (or reassign as you see fit)
2022-04-02Suggest borrowing when trying to coerce unsized type into dyn TraitMichael Goulet-0/+43
2022-04-02Fix late-bound ICE in unsized return suggestionMichael Goulet-55/+79
2022-04-02Auto merge of #94911 - jackh726:gats_extended_2, r=compiler-errorsbors-14/+78
Make GATs object safe under generic_associated_types_extended feature Based on #94869 Let's say we have ```rust trait StreamingIterator { type Item<'a> where Self: 'a; } ``` And `dyn for<'a> StreamingIterator<Item<'a> = &'a i32>`. If we ask `(dyn for<'a> StreamingIterator<Item<'a> = &'a i32>): StreamingIterator`, then we have to prove that `for<'x> (&'x i32): Sized`. So, we generate *new* bound vars to subst for the GAT generics. Importantly, this doesn't fully verify that these are usable and sound. r? `@nikomatsakis`
2022-04-02Make GATs object safe under generic_associated_types_extended featureJack Huey-14/+78
2022-04-02rebase and use ty::Const in patterns againb-naber-53/+1
2022-04-02do use ty::Const in patterns and abstract constsb-naber-14/+9
2022-04-02change thir to use mir::ConstantKind instead of ty::Constb-naber-5/+67
2022-04-02Rollup merge of #95560 - lcnr:obligation-cause, r=oli-obkDylan DPC-7/+8
convert more `DefId`s to `LocalDefId`
2022-04-01convert more `DefId`s to `LocalDefId`lcnr-7/+8
2022-04-01Rollup merge of #95260 - compiler-errors:fn, r=davidtwcoMatthias Krüger-5/+121
Better suggestions for `Fn`-family trait selection errors 1. Suppress suggestions to add `std::ops::Fn{,Mut,Once}` bounds when a type already implements `Fn{,Mut,Once}` 2. Add a note that points out that a type does in fact implement `Fn{,Mut,Once}`, but the arguments vary (either by number or by actual arguments) 3. Add a note that points out that a type does in fact implement `Fn{,Mut,Once}`, but not the right one (e.g. implements `FnMut`, but `Fn` is required). Fixes #95147
2022-03-31Rollup merge of #95517 - lcnr:rustc_borrowck-misc, r=jackh726Dylan DPC-1/+1
small rustc_borrowck cleanup r? `@jackh726` because of the second commit, seems like that comment was missed in #91243
2022-03-31address comments, add test for shadowed Box typeMichael Goulet-7/+3
2022-03-31Specialize suggestion for Option<T>Michael Goulet-11/+52
2022-03-31obligation cause: `RepeatVec` -> `RepeatValueCopy`lcnr-1/+1
2022-03-31Rollup merge of #95497 - nyurik:compiler-spell-comments, r=compiler-errorsDylan DPC-20/+20
Spellchecking compiler comments This PR cleans up the rest of the spelling mistakes in the compiler comments. This PR does not change any literal or code spelling issues.
2022-03-31Rollup merge of #95471 - oli-obk:tait_ice, r=estebankDylan DPC-13/+6
Don't ICE when opaque types get their hidden type constrained again. Contrary to popular belief, `codegen_fulfill_obligation` does not get used solely in codegen, so we cannot rely on `param_env` being set to RevealAll and thus revealing the hidden types instead of constraining them. Fixes #89312 (for real this time)
2022-03-31Rollup merge of #94869 - jackh726:gats_extended, r=compiler-errorsDylan DPC-33/+73
Add the generic_associated_types_extended feature Right now, this only ignore obligations that reference new placeholders in `poly_project_and_unify_type`. In the future, this might do other things, like allowing object-safe GATs. **This feature is *incomplete* and quite likely unsound. This is mostly just for testing out potential future APIs using a "relaxed" set of rules until we figure out *proper* rules.** Also drive by cleanup of adding a `ProjectAndUnifyResult` enum instead of using a `Result<Result<Option>>`. r? `@nikomatsakis`
2022-03-30Add the generic_associated_types_extended featureJack Huey-33/+73
2022-03-30Spellchecking compiler commentsYuri Astrakhan-20/+20
This PR cleans up the rest of the spelling mistakes in the compiler comments. This PR does not change any literal or code spelling issues.
2022-03-30Don't ICE when opaque types get their hidden type constrained again.Oli Scherer-13/+6
Contrary to popular belief, `codegen_fulfill_obligation` does not get used solely in codegen, so we cannot rely on `param_env` being set to RevealAll and thus revealing the hidden types instead of constraining them.
2022-03-30Auto merge of #95466 - Dylan-DPC:rollup-g7ddr8y, r=Dylan-DPCbors-5/+5
Rollup of 5 pull requests Successful merges: - #95294 (Document Linux kernel handoff in std::io::copy and std::fs::copy) - #95443 (Clarify how `src/tools/x` searches for python) - #95452 (fix since field version for termination stabilization) - #95460 (Spellchecking compiler code) - #95461 (Spellchecking some comments) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-03-30Rollup merge of #95461 - nyurik:spelling, r=lcnrDylan DPC-4/+4
Spellchecking some comments This PR attempts to clean up some minor spelling mistakes in comments
2022-03-30Spellchecking compiler codeYuri Astrakhan-1/+1
Address some spelling mistakes in strings, private function names, and function params.
2022-03-30Spellchecking some commentsYuri Astrakhan-4/+4
This PR attempts to clean up some minor spelling mistakes in comments
2022-03-28Also use the RPIT back compat hack in trait projectionOli Scherer-4/+15
2022-03-28Remove opaque type obligation and just register opaque types as they are ↵Oli Scherer-42/+0
encountered. This also registers obligations for the hidden type immediately.
2022-03-28Have the spans of TAIT type conflict errors point to the actual site instead ↵Oli Scherer-8/+6
of the owning function
2022-03-28Don't bind hidden types when searching for matching implsOli Scherer-0/+1
2022-03-28Fail more aggressivelyOli Scherer-4/+5
2022-03-28Revert "Auto merge of #93893 - oli-obk:sad_revert, r=oli-obk"Oli Scherer-37/+109
This reverts commit 6499c5e7fc173a3f55b7a3bd1e6a50e9edef782d, reversing changes made to 78450d2d602b06d9b94349aaf8cece1a4acaf3a8.