Skip to content

improve tip for inaccessible traits - #125852

Merged
bors merged 1 commit into
rust-lang:masterfrom
bvanjoi:improve-tip-for-invisible-trait
Jun 19, 2024
Merged

improve tip for inaccessible traits#125852
bors merged 1 commit into
rust-lang:masterfrom
bvanjoi:improve-tip-for-invisible-trait

Conversation

@bvanjoi

@bvanjoibvanjoi commented Jun 1, 2024

Copy link
Copy Markdown
Contributor

Improve the tips when the candidate method is from an inaccessible trait.

For example:

mod m {traitTrait{fnf(){}}impl<T>TraitforT{}}fnmain(){structS;S::f();}

The difference between before and now is:

error[E0599]: no function or associated item named `f` found for struct `S` in the current scope
--> ./src/main.rs:88:6
|
LL | struct S;
| -------- function or associated item `f` not found for this struct
LL | S::f();
| ^ function or associated item not found in `S`
|
= help: items from traits can only be used if the trait is implemented and in scope
- help: trait `Trait` which provides `f` is implemented but not in scope; perhaps you want to import it+ help: trait `crate::m::Trait` which provides `f` is implemented but not reachable
|
- LL + use crate::m::Trait;
|

@rustbot

Copy link
Copy Markdown
Collaborator

r? @pnkfelix

rustbot has assigned @pnkfelix.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbotrustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 1, 2024
Comment threadtests/ui/traits/item-privacy.stderr Outdated
Comment threadtests/ui/traits/item-privacy.stderr Outdated
Comment threadcompiler/rustc_hir_typeck/src/method/suggest.rs Outdated
@bvanjoi
bvanjoiforce-pushed the improve-tip-for-invisible-trait branch from 3cabf61 to 3bd6f62CompareJune 2, 2024 08:08
Comment threadtests/ui/traits/item-privacy.stderr Outdated
Comment threadtests/ui/traits/item-privacy.stderr Outdated
@bvanjoi
bvanjoiforce-pushed the improve-tip-for-invisible-trait branch from 3bd6f62 to 586821eCompareJune 3, 2024 07:12
@compiler-errors

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Jun 18, 2024

Copy link
Copy Markdown
Collaborator

📌 Commit 586821e has been approved by compiler-errors

It is now in the queue for this repository.

@borsbors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 18, 2024
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jun 18, 2024
…trait, r=compiler-errors
improve tip for inaccessible traits
Improve the tips when the candidate method is from an inaccessible trait.
For example:
```rs
mod m {
trait Trait {
fn f() {}
}
impl<T> Trait for T {}
}
fn main() {
struct S;
S::f();
}
```
The difference between before and now is:
```diff
error[E0599]: no function or associated item named `f` found for struct `S` in the current scope
--> ./src/main.rs:88:6
|
LL | struct S;
| -------- function or associated item `f` not found for this struct
LL | S::f();
| ^ function or associated item not found in `S`
|
= help: items from traits can only be used if the trait is implemented and in scope
- help: trait `Trait` which provides `f` is implemented but not in scope; perhaps you want to import it
+ help: trait `crate::m::Trait` which provides `f` is implemented but not reachable
|
- LL + use crate::m::Trait;
|
```
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jun 18, 2024
…trait, r=compiler-errors
improve tip for inaccessible traits
Improve the tips when the candidate method is from an inaccessible trait.
For example:
```rs
mod m {
trait Trait {
fn f() {}
}
impl<T> Trait for T {}
}
fn main() {
struct S;
S::f();
}
```
The difference between before and now is:
```diff
error[E0599]: no function or associated item named `f` found for struct `S` in the current scope
--> ./src/main.rs:88:6
|
LL | struct S;
| -------- function or associated item `f` not found for this struct
LL | S::f();
| ^ function or associated item not found in `S`
|
= help: items from traits can only be used if the trait is implemented and in scope
- help: trait `Trait` which provides `f` is implemented but not in scope; perhaps you want to import it
+ help: trait `crate::m::Trait` which provides `f` is implemented but not reachable
|
- LL + use crate::m::Trait;
|
```
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 18, 2024
…llaumeGomez
Rollup of 9 pull requests
Successful merges:
- rust-lang#123782 (Test that opaque types can't have themselves as a hidden type with incompatible lifetimes)
- rust-lang#124580 (Suggest removing unused tuple fields if they are the last fields)
- rust-lang#125852 (improve tip for inaccessible traits)
- rust-lang#126422 (Suggest using a standalone doctest for non-local impl defs)
- rust-lang#126427 (Rewrite `intrinsic-unreachable`, `sepcomp-cci-copies`, `sepcomp-inlining` and `sepcomp-separate` `run-make` tests to rmake.rs)
- rust-lang#126493 (safe transmute: support non-ZST, variantful, uninhabited enums)
- rust-lang#126572 (override user defined channel when using precompiled rustc)
- rust-lang#126615 (Add `rustc-ice*` to `.gitignore`)
- rust-lang#126632 (Replace `move||` with `move ||`)
Failed merges:
- rust-lang#126558 (hir_typeck: be more conservative in making "note caller chooses ty param" note)
r? `@ghost`
`@rustbot` modify labels: rollup
jieyouxu added a commit to jieyouxu/rust that referenced this pull request Jun 19, 2024
…trait, r=compiler-errors
improve tip for inaccessible traits
Improve the tips when the candidate method is from an inaccessible trait.
For example:
```rs
mod m {
trait Trait {
fn f() {}
}
impl<T> Trait for T {}
}
fn main() {
struct S;
S::f();
}
```
The difference between before and now is:
```diff
error[E0599]: no function or associated item named `f` found for struct `S` in the current scope
--> ./src/main.rs:88:6
|
LL | struct S;
| -------- function or associated item `f` not found for this struct
LL | S::f();
| ^ function or associated item not found in `S`
|
= help: items from traits can only be used if the trait is implemented and in scope
- help: trait `Trait` which provides `f` is implemented but not in scope; perhaps you want to import it
+ help: trait `crate::m::Trait` which provides `f` is implemented but not reachable
|
- LL + use crate::m::Trait;
|
```
@jieyouxujieyouxu mentioned this pull request Jun 19, 2024
@bors

bors commented Jun 19, 2024

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 586821e with merge 3c0f019...

@bors

bors commented Jun 19, 2024

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing 3c0f019 to master...

@borsbors added the merged-by-bors This PR was explicitly merged by bors. label Jun 19, 2024
@bors
bors merged commit 3c0f019 into rust-lang:masterJun 19, 2024
@rustbotrustbot added this to the 1.81.0 milestone Jun 19, 2024
@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (3c0f019): 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.

meanrangecount
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
1.7%[1.7%, 1.7%]1
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
--0
All ❌✅ (primary)--0

Max RSS (memory usage)

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

Cycles

Results (primary 2.1%, secondary -2.8%)

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.

meanrangecount
Regressions ❌
(primary)
2.1%[2.1%, 2.1%]1
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
-2.8%[-2.8%, -2.8%]1
All ❌✅ (primary)2.1%[2.1%, 2.1%]1

Binary size

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

Bootstrap: 690.768s -> 689.514s (-0.18%)
Artifact size: 323.76 MiB -> 323.13 MiB (-0.19%)

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-borsThis PR was explicitly merged by bors.S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@bvanjoi@rustbot@compiler-errors@bors@rust-timer@pnkfelix