Commit Graph

27 Commits

Author SHA1 Message Date
Oli Scherer
fd9ef69adf Avoid a track_errors by bubbling up most errors from check_well_formed 2023-10-20 08:46:27 +00:00
Esteban Küber
890e92feed Unify suggestion wording 2023-10-17 17:33:55 +00:00
Matthias Krüger
535cd8d511
Rollup merge of #114654 - estebank:suggest-pin-macro, r=davidtwco
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-10-03 16:24:15 +02:00
Esteban Küber
81bca5f5cf When suggesting self.x for S { x }, use S { x: self.x }
Tweak output.

Fix #115992.
2023-09-25 15:56:36 +00:00
Esteban Küber
ac5e18756a Tweak wording and logic 2023-09-23 01:54:05 +00:00
Esteban Küber
6b58fbfd7e rebase and review comments 2023-08-14 21:40:11 +00:00
Esteban Küber
f7486ffd18 Add tests for #57994 2023-08-04 16:19:55 +00:00
Esteban Küber
6d11b2f2af Detect method not found on arbitrary self type with different mutability
```
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-08-04 16:05:59 +00:00
Michael Goulet
05c5caa500 Don't ICE if method receiver fails to unify with arbitrary_self_types 2023-05-23 03:23:52 +00:00
Camille GILLOT
33ec632381 Add test. 2023-05-14 12:48:57 +00:00
Camille GILLOT
343819d33f Revert "Validate resolution for SelfCtor too."
This reverts commit 83453408a0.
2023-05-14 12:48:32 +00:00
Michael Goulet
14bf909e71 Note base types of coercion 2023-05-12 00:10:52 +00:00
Matthias Krüger
8d66f01ab5
Rollup merge of #110982 - cjgillot:elided-self-const, r=petrochenkov
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-04 19:18:20 +02:00
Camille GILLOT
8972a23f48 Do not recurse into const generic args when resolving self lifetime elision. 2023-05-03 18:07:53 +00:00
Camille GILLOT
83453408a0 Validate resolution for SelfCtor too. 2023-05-03 17:55:27 +00:00
Esteban Küber
9fadcc143a Special-case item attributes in the suggestion output 2023-04-12 22:50:10 +00:00
Esteban Küber
5b40aa5eb4 Tweak output for 'add line' suggestion 2023-04-12 22:50:10 +00:00
Matthias Krüger
fbc121fdfd
Rollup merge of #104363 - WaffleLapkin:bonk_box_new, r=Nilstrieb
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 🤷

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-11 15:43:11 +01:00
Maybe Waffle
214e65c2eb Add unuseless #[allow(unused_allocation)] 2023-03-03 17:47:48 +00:00
Michael Goulet
4b23a224ab Label opaque type for 'captures lifetime' error message 2023-03-03 05:02:34 +00:00
Michael Howell
3f374128ee diagnostics: update test cases to refer to assoc fn with self as method 2023-02-22 08:40:47 -07:00
Esteban Küber
62ba3e70a1 Modify primary span label for E0308
The previous output was unintuitive to users.
2023-01-30 20:12:19 +00:00
Matthias Krüger
e0d71f500c
Rollup merge of #97373 - dimpolo:cell_dispatch_from_dyn, r=dtolnay
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-26 07:53:21 +01:00
dimi
a2d1cb2c22 impl DispatchFromDyn for Cell and UnsafeCell 2023-01-24 12:06:12 +01:00
Esteban Küber
656db98bd9 Tweak E0597
CC #99430
2023-01-15 19:46:20 +00:00
Esteban Küber
12ddf77811 When suggesting writing a fully qualified path probe for appropriate types
Fix #46585.
2023-01-11 21:30:10 +00:00
Albert Larsan
cf2dff2b1e
Move /src/test to /tests 2023-01-11 09:32:08 +00:00