about summary refs log tree commit diff
path: root/src/test/ui/traits
AgeCommit message (Collapse)AuthorLines
2022-04-06don't report int/float ambiguity when we have previous errorsMichael Goulet-32/+29
2022-04-05Rollup merge of #95525 - ohno418:suggest-derivable-trait-E0277, ↵Dylan DPC-0/+8
r=compiler-errors Suggest derivable trait on E0277 error Closes https://github.com/rust-lang/rust/issues/95099 .
2022-04-05Suggest derivable trait on E0277ohno418-0/+8
2022-04-04Remove hack, fix fmt and testsEsteban Kuber-2/+0
2022-04-04Refer to the TraitRef::identity in the message to be clearerEsteban Kuber-3/+3
2022-04-04Dedup logic and improve output for other types that impl traitEsteban Kuber-10/+14
2022-04-04Suggest dereferncing when possible in E0277, fix #87437Esteban Kuber-3/+55
2022-04-04Fix #90970, doesn't address #87437Esteban Kuber-0/+35
2022-04-04Mention implementers of unsatisfied traitEsteban Kuber-15/+16
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-03-30Auto merge of #94081 - oli-obk:lazy_tait_take_two, r=nikomatsakisbors-7/+7
Lazy type-alias-impl-trait take two ### user visible change 1: RPIT inference from recursive call sites Lazy TAIT has an insta-stable change. The following snippet now compiles, because opaque types can now have their hidden type set from wherever the opaque type is mentioned. ```rust fn bar(b: bool) -> impl std::fmt::Debug { if b { return 42 } let x: u32 = bar(false); // this errors on stable 99 } ``` The return type of `bar` stays opaque, you can't do `bar(false) + 42`, you need to actually mention the hidden type. ### user visible change 2: divergence between RPIT and TAIT in return statements Note that `return` statements and the trailing return expression are special with RPIT (but not TAIT). So ```rust #![feature(type_alias_impl_trait)] type Foo = impl std::fmt::Debug; fn foo(b: bool) -> Foo { if b { return vec![42]; } std::iter::empty().collect() //~ ERROR `Foo` cannot be built from an iterator } fn bar(b: bool) -> impl std::fmt::Debug { if b { return vec![42] } std::iter::empty().collect() // Works, magic (accidentally stabilized, not intended) } ``` But when we are working with the return value of a recursive call, the behavior of RPIT and TAIT is the same: ```rust type Foo = impl std::fmt::Debug; fn foo(b: bool) -> Foo { if b { return vec![]; } let mut x = foo(false); x = std::iter::empty().collect(); //~ ERROR `Foo` cannot be built from an iterator vec![] } fn bar(b: bool) -> impl std::fmt::Debug { if b { return vec![]; } let mut x = bar(false); x = std::iter::empty().collect(); //~ ERROR `impl Debug` cannot be built from an iterator vec![] } ``` ### user visible change 3: TAIT does not merge types across branches In contrast to RPIT, TAIT does not merge types across branches, so the following does not compile. ```rust type Foo = impl std::fmt::Debug; fn foo(b: bool) -> Foo { if b { vec![42_i32] } else { std::iter::empty().collect() //~^ ERROR `Foo` cannot be built from an iterator over elements of type `_` } } ``` It is easy to support, but we should make an explicit decision to include the additional complexity in the implementation (it's not much, see a721052457cf513487fb4266e3ade65c29b272d2 which needs to be reverted to enable this). ### PR formalities previous attempt: #92007 This PR also includes #92306 and #93783, as they were reverted along with #92007 in #93893 fixes #93411 fixes #88236 fixes #89312 fixes #87340 fixes #86800 fixes #86719 fixes #84073 fixes #83919 fixes #82139 fixes #77987 fixes #74282 fixes #67830 fixes #62742 fixes #54895
2022-03-28Revert "Auto merge of #93893 - oli-obk:sad_revert, r=oli-obk"Oli Scherer-7/+7
This reverts commit 6499c5e7fc173a3f55b7a3bd1e6a50e9edef782d, reversing changes made to 78450d2d602b06d9b94349aaf8cece1a4acaf3a8.
2022-03-27resolve: Simplify some diagnostic code to avoid an ICEVadim Petrochenkov-2/+24
2022-03-25when checking pointee metadata, canonicalize the Sized queryMichael Goulet-0/+19
2022-03-24Properly track `ImplObligation`sEsteban Kuber-1/+7
Instead of probing for all possible impls that could have caused an `ImplObligation`, keep track of its `DefId` and obligation spans for accurate error reporting. Follow up to #89580. Addresses #89418. Remove some unnecessary clones. Tweak output for auto trait impl obligations.
2022-03-15Auto merge of #92285 - compiler-errors:dyn-proj-bounds, r=nikomatsakisbors-11/+85
check ~Projection~ all supertrait bounds when confirming dyn candidate I'm pretty sure Projection is the only other PredicateKind that we care about enforcing here. Fixes #80800
2022-03-14check all dyn obligations, actuallyMichael Goulet-11/+35
2022-03-14check Projection supertrait bounds when confirming dyn candidateMichael Goulet-0/+50
2022-03-03add tests for metadata for unsized generics and opaquesMichael Goulet-0/+62
2022-03-03opaque types may also be sizedMichael Goulet-3/+20
2022-03-03type parameters have unit metadata if they are sizedMichael Goulet-0/+12
2022-02-24better ObligationCause for normalization errors in can_type_implement_copyMichael Goulet-0/+39
2022-02-14Auto merge of #93652 - spastorino:fix-negative-overlap-check-regions, ↵bors-4/+6
r=nikomatsakis Fix negative overlap check regions r? `@nikomatsakis`
2022-02-14Properly check regions on negative overlap checkSantiago Pastorino-4/+6
2022-02-14further update `fuzzy_match_tys`lcnr-4/+5
2022-02-14fuzzify `fuzzy_match_tys`lcnr-0/+6
2022-02-14Make `find_similar_impl_candidates` a little fuzzier.Ben Reeves-0/+2
2022-02-11Rollup merge of #93909 - saschanaz:patch-2, r=petrochenkovMatthias Krüger-8/+8
Fix typo: explicitely -> explicitly
2022-02-11Fix typo: explicitely->explicitlyKagami Sascha Rosylight-8/+8
2022-02-11Revert "Auto merge of #92007 - oli-obk:lazy_tait2, r=nikomatsakis"Oli Scherer-3/+3
This reverts commit e7cc3bddbe0d0e374d05e7003e662bba1742dbae, reversing changes made to 734368a200904ef9c21db86c595dc04263c87be0.
2022-02-07Print opaque types from type aliases via their pathOli Scherer-3/+3
2022-02-01Auto merge of #93386 - ↵bors-1/+27
WaffleLapkin:rustc_must_implement_one_of_check_target, r=nagisa Check that `#[rustc_must_implement_one_of]` is applied to a trait `#[rustc_must_implement_one_of]` only makes sense when applied to a trait, so it's sensible to emit an error otherwise.
2022-01-28Add test for old ICE in #91594Ben Reeves-0/+34
2022-01-27Check that `#[rustc_must_implement_one_of]` is applied to a traitMaybe Waffle-1/+27
2022-01-17Rollup merge of #92164 - WaffleLapkin:rustc_must_implement_one_of_attr, ↵Matthias Krüger-0/+256
r=Aaron1011 Implement `#[rustc_must_implement_one_of]` attribute This PR adds a new attribute — `#[rustc_must_implement_one_of]` that allows changing the "minimal complete definition" of a trait. It's similar to GHC's minimal `{-# MINIMAL #-}` pragma, though `#[rustc_must_implement_one_of]` is weaker atm. Such attribute was long wanted. It can be, for example, used in `Read` trait to make transitions to recently added `read_buf` easier: ```rust #[rustc_must_implement_one_of(read, read_buf)] pub trait Read { fn read(&mut self, buf: &mut [u8]) -> Result<usize> { let mut buf = ReadBuf::new(buf); self.read_buf(&mut buf)?; Ok(buf.filled_len()) } fn read_buf(&mut self, buf: &mut ReadBuf<'_>) -> Result<()> { default_read_buf(|b| self.read(b), buf) } } impl Read for Ty0 {} //^ This will fail to compile even though all `Read` methods have default implementations // Both of these will compile just fine impl Read for Ty1 { fn read(&mut self, buf: &mut [u8]) -> Result<usize> { /* ... */ } } impl Read for Ty2 { fn read_buf(&mut self, buf: &mut ReadBuf<'_>) -> Result<()> { /* ... */ } } ``` For now, this is implemented as an internal attribute to start experimenting on the design of this feature. In the future we may want to extend it: - Allow arbitrary requirements like `a | (b & c)` - Allow multiple requirements like - ```rust #[rustc_must_implement_one_of(a, b)] #[rustc_must_implement_one_of(c, d)] ``` - Make it appear in rustdoc documentation - Change the syntax? - Etc Eventually, we should make an RFC and make this (or rather similar) attribute public. --- I'm fairly new to compiler development and not at all sure if the implementation makes sense, but at least it passes tests :)
2022-01-14Do not use `HashSet` for `#[rustc_must_implement_one_of]`Maybe Waffle-3/+3
2022-01-14Check for duplicate arguments in `#[rustc_must_implement_one_of]`Maybe Waffle-0/+53
2022-01-11Add a test for ungated `#[rustc_must_implement_one_of]`Maybe Waffle-0/+24
This test checks that `#[rustc_must_implement_one_of]` is gated behind `#![feature(rustc_attrs)]`.
2022-01-10Rollup merge of #92248 - compiler-errors:normalize-type-for-pointee, r=jackh726Matthias Krüger-0/+22
Normalize struct tail type when checking Pointee trait Let's go ahead and implement the FIXMEs by properly normalizing the struct-tail type when satisfying a Pointee obligation. This should fix the ICE when we try to calculate a layout depending on `<Ty as Pointee>::Metadata` later. Fixes #92128 Fixes #92577 Additionally, mark the obligation as ambiguous if there are any infer types in that struct-tail type. This has the effect of causing `<_ as Pointee>::Metadata` to be properly replaced with an infer variable ([here](https://github.com/rust-lang/rust/blob/master/compiler/rustc_trait_selection/src/traits/project.rs#L813)) and registered as an obligation... this turns out to be very important in unifying function parameters with formals that are assoc types. Fixes #91446
2022-01-09Apply suggestions from code reviewWaffle Maybe-17/+17
Use "(associated) function" terminology instead of "method". Co-authored-by: Daniel Henry-Mantilla <daniel.henry.mantilla@gmail.com>
2022-01-09Move `#[rustc_must_implement_one_of]` tests to fix tidy checkMaybe Waffle-0/+179
2021-12-29Add UI test for #92292Wang Ruochen-0/+32
Closes #92292
2021-12-24Normalize struct tail type when checking Pointee traitMichael Goulet-0/+22
2021-12-20Auto merge of #92041 - Aaron1011:remove-speculative-evaluation, r=jackh726bors-0/+34
Remove 'speculative evaluation' of predicates Performing 'speculative evaluation' introduces caching bugs that cannot be fixed without invasive changes to projection. Hopefully, we can win back most of the performance lost by re-adding 'cache completion' Fixes #90662
2021-12-18Rollup merge of #89090 - cjgillot:bare-dyn, r=jackh726Matthias Krüger-1/+6
Lint bare traits in AstConv. Removing the lint from lowering allows to: - make lowering querification easier; - have the lint implementation in only one place. r? `@estebank`
2021-12-17Remove 'speculative evaluation' of predicatesAaron Hill-0/+34
Performing 'speculative evaluation' introduces caching bugs that cannot be fixed without invasive changes to projection. Hopefully, we can win back most of the performance lost by re-adding 'cache completion' Fixes #90662
2021-12-13Fix HashStable implementation on InferTyMichael Goulet-0/+17
2021-12-11Auto merge of #91769 - estebank:type-trait-bound-span-2, r=oli-obkbors-10/+23
Tweak assoc type obligation spans * Point at RHS of associated type in obligation span * Point at `impl` assoc type on projection error * Reduce verbosity of recursive obligations * Point at source of binding lifetime obligation * Tweak "required bound" note * Tweak "expected... found opaque (return) type" labels * Point at set type in impl assoc type WF errors r? `@oli-obk` This is a(n uncontroversial) subset of #85799.
2021-12-11Tweak assoc type obligation spansEsteban Kuber-10/+23
* Point at RHS of associated type in obligation span * Point at `impl` assoc type on projection error * Reduce verbosity of recursive obligations * Point at source of binding lifetime obligation * Tweak "required bound" note * Tweak "expected... found opaque (return) type" labels * Point at set type in impl assoc type WF errors
2021-12-10Tweak wordingEsteban Kuber-7/+7
2021-12-10Use a more accurate `Span` for `'static` obligation from return typeEsteban Kuber-8/+8