about summary refs log tree commit diff
path: root/tests/ui/self
AgeCommit message (Collapse)AuthorLines
2023-12-12Rollup merge of #117914 - estebank:issue-85843, r=wesleywiserMatthias Krüger-1/+10
On borrow return type, suggest borrowing from arg or owned return type When we encounter a function with a return type that has an anonymous lifetime with no argument to borrow from, besides suggesting the `'static` lifetime we now also suggest changing the arguments to be borrows or changing the return type to be an owned type. ``` error[E0106]: missing lifetime specifier --> $DIR/variadic-ffi-6.rs:7:6 | LL | ) -> &usize { | ^ expected named lifetime parameter | = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static` | LL | ) -> &'static usize { | +++++++ help: instead, you are more likely to want to change one of the arguments to be borrowed... | LL | x: &usize, | + help: ...or alternatively, to want to return an owned value | LL - ) -> &usize { LL + ) -> usize { | ``` Fix #85843.
2023-11-24Show number in error message even for one errorNilstrieb-10/+10
Co-authored-by: Adrian <adrian.iosdev@gmail.com>
2023-11-20Tweak wordingEsteban Küber-1/+1
2023-11-20On borrow return type, suggest borrowing from arg or owned return typeEsteban Küber-1/+10
When we encounter a function with a return type that has an anonymous lifetime with no argument to borrow from, besides suggesting the `'static` lifetime we now also suggest changing the arguments to be borrows or changing the return type to be an owned type. ``` error[E0106]: missing lifetime specifier --> $DIR/variadic-ffi-6.rs:7:6 | LL | ) -> &usize { | ^ expected named lifetime parameter | = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static` | LL | ) -> &'static usize { | +++++++ help: instead, you are more likely to want to change one of the arguments to be borrowed... | LL | x: &usize, | + help: ...or alternatively, to want to return an owned value | LL - ) -> &usize { LL + ) -> usize { | ``` Fix #85843.
2023-11-16Smaller span for unnessary `mut` suggestionEsteban Küber-1/+1
2023-10-30Auto merge of #117415 - matthiaskrgr:rollup-jr2p1t2, r=matthiaskrgrbors-4/+19
Rollup of 7 pull requests Successful merges: - #116862 (Detect when trait is implemented for type and suggest importing it) - #117389 (Some diagnostics improvements of `gen` blocks) - #117396 (Don't treat closures/coroutine types as part of the public API) - #117398 (Correctly handle nested or-patterns in exhaustiveness) - #117403 (Poison check_well_formed if method receivers are invalid to prevent typeck from running on it) - #117411 (Improve some diagnostics around `?Trait` bounds) - #117414 (Don't normalize to an un-revealed opaque when we hit the recursion limit) r? `@ghost` `@rustbot` modify labels: rollup
2023-10-30Poison check_well_formed if method receivers are invalid to prevent typeck ↵Oli Scherer-4/+19
from running on it
2023-10-29On object safety error, mention new enum as alternativeEsteban Küber-0/+3
When we encounter a `dyn Trait` that isn't object safe, look for its implementors. If there's one, mention using it directly If there are less than 9, mention the possibility of creating a new enum and using that instead. Account for object unsafe `impl Trait on dyn Trait {}`. Make a distinction between public and sealed traits. Fix #80194.
2023-10-20Avoid a `track_errors` by bubbling up most errors from `check_well_formed`Oli Scherer-6/+23
2023-10-17Unify suggestion wordingEsteban Küber-2/+2
2023-10-03Rollup merge of #114654 - estebank:suggest-pin-macro, r=davidtwcoMatthias Krüger-7/+6
Suggest `pin!()` instead of `Pin::new()` when appropriate When encountering a type that needs to be pinned but that is `!Unpin`, suggest using the `pin!()` macro. Fix #57994.
2023-09-25When suggesting `self.x` for `S { x }`, use `S { x: self.x }`Esteban Küber-1/+6
Tweak output. Fix #115992.
2023-09-23Tweak wording and logicEsteban Küber-1/+1
2023-08-14rebase and review commentsEsteban Küber-7/+6
2023-08-04Add tests for #57994Esteban Küber-0/+167
2023-08-04Detect method not found on arbitrary self type with different mutabilityEsteban Küber-0/+40
``` error[E0599]: no method named `x` found for struct `Pin<&S>` in the current scope --> $DIR/arbitrary_self_type_mut_difference.rs:11:18 | LL | Pin::new(&S).x(); | ^ help: there is a method with a similar name: `y` | note: method is available for `Pin<&mut S>` --> $DIR/arbitrary_self_type_mut_difference.rs:6:5 | LL | fn x(self: Pin<&mut Self>) {} | ^^^^^^^^^^^^^^^^^^^^^^^^^^ ``` Related to #57994, as one of the presented cases can lead to code like this.
2023-05-23Don't ICE if method receiver fails to unify with arbitrary_self_typesMichael Goulet-0/+25
2023-05-14Add test.Camille GILLOT-0/+15
2023-05-14Revert "Validate resolution for SelfCtor too."Camille GILLOT-50/+0
This reverts commit 83453408a0ce91b9e3d3ae6e7f117b1fd28b487d.
2023-05-12Note base types of coercionMichael Goulet-4/+2
2023-05-04Rollup merge of #110982 - cjgillot:elided-self-const, r=petrochenkovMatthias Krüger-0/+51
Do not recurse into const generic args when resolving self lifetime elision. Fixes https://github.com/rust-lang/rust/issues/110899 r? `@petrochenkov`
2023-05-03Do not recurse into const generic args when resolving self lifetime elision.Camille GILLOT-0/+51
2023-05-03Validate resolution for SelfCtor too.Camille GILLOT-0/+50
2023-04-12Special-case item attributes in the suggestion outputEsteban Küber-1/+0
2023-04-12Tweak output for 'add line' suggestionEsteban Küber-1/+2
2023-03-11Rollup merge of #104363 - WaffleLapkin:bonk_box_new, r=NilstriebMatthias Krüger-2/+3
Make `unused_allocation` lint against `Box::new` too Previously it only linted against `box` syntax, which likely won't ever be stabilized, which is pretty useless. Even now I'm not sure if it's a meaningful lint, but it's at least something :shrug: This means that code like the following will be linted against: ```rust Box::new([1, 2, 3]).len(); f(&Box::new(1)); // where f : &i32 -> () ``` The lint works by checking if a `Box::new` (or `box`) expression has an a borrow adjustment, meaning that the code that first stores the box in a variable won't be linted against: ```rust let boxed = Box::new([1, 2, 3]); // no lint boxed.len(); ```
2023-03-03Add unuseless `#[allow(unused_allocation)]`Maybe Waffle-2/+3
2023-03-03Label opaque type for 'captures lifetime' error messageMichael Goulet-4/+6
2023-02-22diagnostics: update test cases to refer to assoc fn with `self` as methodMichael Howell-64/+64
2023-01-30Modify primary span label for E0308Esteban Küber-1/+1
The previous output was unintuitive to users.
2023-01-26Rollup merge of #97373 - dimpolo:cell_dispatch_from_dyn, r=dtolnayMatthias Krüger-0/+22
impl DispatchFromDyn for Cell and UnsafeCell After some fruitful discussion on [Internals](https://internals.rust-lang.org/t/impl-dispatchfromdyn-for-cell-2/16520) here's my first PR to rust-lang/rust 🎉 Please let me know if there's something I missed. This adds `DispatchFromDyn` impls for `Cell`, `UnsafeCell` and `SyncUnsafeCell`. An existing test is also expanded to test the `Cell` impl (which requires the `UnsafeCell` impl) The different `RefCell` types can not implement `DispatchFromDyn` since they have more than one (non ZST) field. &nbsp; **Edit:** ### What: These changes allow one to make types like `MyRc`(code below), to be object safe method receivers after implementing `DispatchFromDyn` and `Deref` for them. This allows for code like this: ```rust struct MyRc<T: ?Sized>(Cell<NonNull<RcBox<T>>>); /* impls for DispatchFromDyn, CoerceUnsized and Deref for MyRc*/ trait Trait { fn foo(self: MyRc<Self>); } let impls_trait = ...; let rc = MyRc::new(impls_trait) as MyRc<dyn Trait>; rc.foo(); ``` Note: `Cell` and `UnsafeCell` won't directly become valid method receivers since they don't implement `Deref`. Making use of these changes requires a wrapper type and nightly features. ### Why: A custom pointer type with interior mutability allows one to store extra information in the pointer itself. These changes allow for such a type to be a method receiver. ### Examples: My use case is a cycle aware custom `Rc` implementation that when dropping a cycle marks some references dangling. On the [forum](https://internals.rust-lang.org/t/impl-dispatchfromdyn-for-cell/14762/8) andersk mentioned that they track if a `Gc` reference is rooted with an extra bit in the reference itself.
2023-01-24impl DispatchFromDyn for Cell and UnsafeCelldimi-0/+22
2023-01-15Tweak E0597Esteban Küber-0/+2
CC #99430
2023-01-11When suggesting writing a fully qualified path probe for appropriate typesEsteban Küber-2/+2
Fix #46585.
2023-01-11Move /src/test to /testsAlbert Larsan-0/+4352