rust icon indicating copy to clipboard operation
rust copied to clipboard

Prevent auto-application of associated functions with placeholders

Open clubby789 opened this issue 2 years ago • 1 comments

Fixes #101920

clubby789 avatar Sep 18 '22 17:09 clubby789

r? @compiler-errors

(rust-highfive has picked a reviewer for you, use r? to override)

rust-highfive avatar Sep 18 '22 17:09 rust-highfive

I notice that even when the type is known and this isn't an issue (e.g)

fn main() {
        let b = Box::new("abc");
        let ptr = b.into_raw();
}

Applying the fix results in incorrect code: Box::<&str>::into_raw() Should the fix instead transform this to Box::<&str>::into_raw(b)?

clubby789 avatar Sep 18 '22 23:09 clubby789

Should the fix instead transform this to Box::<&str>::into_raw(b)?

I think so, yes.

compiler-errors avatar Sep 23 '22 02:09 compiler-errors

Currently working on automatically adjusting the arguments, but not sure how to handle the case of

struct GenericAssocMethod<T>(T);
impl<T> GenericAssocMethod<T> {
  fn default_hello() {}
}
let x = GenericAssocMethod(33);
x.default_hello();

Where the generic arguments can't be inferred in the GenericAssocMethod::<_>::default_hello form. Applying this or leaving it results in invalid code which causes cargo to print a bug message.

clubby789 avatar Sep 23 '22 15:09 clubby789

I've temporarily commented out the problematic test case since this seems like incorrect behaviour from Cargo

clubby789 avatar Sep 23 '22 16:09 clubby789

Where the generic arguments can't be inferred in the GenericAssocMethod::<_>::default_hello form. Applying this or leaving it results in invalid code which causes cargo to print a bug message.

Then this suggestion should probably not be MachineApplicable, and we shouldn't have a test case that has // run-rustfix for it, but just a regular error test case for it.

compiler-errors avatar Sep 25 '22 23:09 compiler-errors

Marking this as S-waiting-on-author so it can be adjusted to make it not MachineApplicable if it doesn't actually fit the criteria for MachineApplicable, namely that it should produce code that compiles when applied.

compiler-errors avatar Sep 25 '22 23:09 compiler-errors

:umbrella: The latest upstream changes (presumably #102306) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Sep 27 '22 14:09 bors

@rustbot label -S-waiting-on-author +S-waiting-on-review

clubby789 avatar Sep 28 '22 13:09 clubby789

:umbrella: The latest upstream changes (presumably #102875) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Oct 10 '22 12:10 bors

Some changes occurred in src/tools/cargo

cc @ehuss

rustbot avatar Oct 10 '22 12:10 rustbot

🤔 Sorry about the ping, I think I might have made a mistake while rebasing

clubby789 avatar Oct 10 '22 12:10 clubby789

The job x86_64-gnu-llvm-13 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

---- [ui] src/test/ui/suggestions/inner_type2.rs stdout ----
diff of stderr:

17 LL |     item.method();
18    |          ^^^^^^ method not found in `MaybeUninit<Struct<u32>>`
19    |
-    = help: if this `MaybeUninit::<Struct<u32>>` has been initialized, use one of the `assume_init` methods to access the inner value
+    = help: if this `MaybeUninit<Struct<u32>>` has been initialized, use one of the `assume_init` methods to access the inner value
21 note: the method `method` exists on the type `Struct<u32>`
23    |


The actual stderr differed from the expected stderr.
The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/suggestions/inner_type2/inner_type2.stderr
Some tests failed in compiletest suite=ui mode=ui host=x86_64-unknown-linux-gnu target=x86_64-unknown-linux-gnu
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args suggestions/inner_type2.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/src/test/ui/suggestions/inner_type2.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/suggestions/inner_type2" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/suggestions/inner_type2/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0599]: no method named `method` found for struct `LocalKey` in the current scope
   |
   |
LL |     STRUCT.method();
   |            ^^^^^^ method not found in `LocalKey<Struct<u32>>`
   |
   = help: use `with` or `try_with` to access thread local storage
note: the method `method` exists on the type `Struct<u32>`
   |
LL |     pub fn method(&self) {}
   |     ^^^^^^^^^^^^^^^^^^^^


error[E0599]: no method named `method` found for union `MaybeUninit` in the current scope
   |
   |
LL |     item.method();
   |          ^^^^^^ method not found in `MaybeUninit<Struct<u32>>`
   |
   = help: if this `MaybeUninit<Struct<u32>>` has been initialized, use one of the `assume_init` methods to access the inner value
note: the method `method` exists on the type `Struct<u32>`
   |
LL |     pub fn method(&self) {}
   |     ^^^^^^^^^^^^^^^^^^^^

rust-log-analyzer avatar Oct 10 '22 13:10 rust-log-analyzer

:umbrella: The latest upstream changes (presumably #103310) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Oct 21 '22 13:10 bors

:umbrella: The latest upstream changes (presumably #103978) made this pull request unmergeable. Please resolve the merge conflicts.

bors avatar Nov 04 '22 22:11 bors

@bors r+

compiler-errors avatar Nov 08 '22 18:11 compiler-errors

Why didn't bors respond, lol

@bors r+

compiler-errors avatar Nov 10 '22 01:11 compiler-errors

:pushpin: Commit 7df4b0b66252748108b5d7edee27ee5776222f64 has been approved by compiler-errors

It is now in the queue for this repository.

bors avatar Nov 10 '22 01:11 bors

:hourglass: Testing commit 7df4b0b66252748108b5d7edee27ee5776222f64 with merge 5eef9b2c50ddd4e445c10043908f785b08456489...

bors avatar Nov 10 '22 02:11 bors

:sunny: Test successful - checks-actions Approved by: compiler-errors Pushing 5eef9b2c50ddd4e445c10043908f785b08456489 to master...

bors avatar Nov 10 '22 04:11 bors

:sunny: Test successful - checks-actions Approved by: compiler-errors Pushing 5eef9b2c50ddd4e445c10043908f785b08456489 to master...

bors avatar Nov 10 '22 04:11 bors

Finished benchmarking commit (5eef9b2c50ddd4e445c10043908f785b08456489): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.2% [1.2%, 1.2%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.6% [-3.5%, -1.3%] 3
All ❌✅ (primary) - - 0

Cycles

This benchmark run did not return any relevant results for this metric.

rust-timer avatar Nov 10 '22 06:11 rust-timer