-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Expand list of trait implementers in E0277 when calling rustc with --verbose #126055
Conversation
…verbose Signed-off-by: rongfu.leng <lenronfu@gmail.com>
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pnkfelix (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
r? @estebank |
r? @pnkfelix |
@@ -2082,12 +2082,16 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { | |||
}) | |||
.collect(); | |||
|
|||
let end = if candidates.len() <= 9 { candidates.len() } else { 8 }; | |||
let end = if candidates.len() <= 9 || self.tcx.sess.opts.verbose { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't help but point out that this original logic was/is a little goofy, in that it says: "if the length is 9 or less, keep it. If its greater than 9, then cut it to length 8."
Why wouldn't you cut it to length 9? (Or use "8 or less" as the relevant threshold.)
(My current guess is that it was an off-by-one error in some past person's end in terms of whether candidates[..end]
would include or exclude the end
itself; otherwise I cannot explain why someone would have written the code like this.)
this has the effect, I think, that will won't actually cut to length 8 until you have 10 elements; a 9-element list is printed in full.
This is not really relevant to this PR though, apart from the fact that reviewing this code tempted me to go in and rewrite it all. But I'm not going to do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think they might've wanted to avoid a message like and 1 others
which would've needed some rewording such as and 1 other
(lacking an s
ending), so then avoid the more complicated logic with that extra s
.
Thus, show 8 + the 2 others msg if above 9, or show all 9 or less with no msg. Makes some sense :D and is kinda clever.
error[E0277]: the trait bound `String: Reconcile` is not satisfied
--> src/main.rs:72:13
|
72 | process(value); // This line will cause a compilation error
| ------- ^^^^^ the trait `Reconcile` is not implemented for `String`
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait `Reconcile`:
bool
i128
i16
i32
i64
i8
u128
u16
and 2 others
note: required by a bound in `process`
rror[E0277]: the trait bound `String: Reconcile` is not satisfied
--> /home/user/sandbox/rust/05_sandbox/error/and_17_others/src/main.rs:72:13
|
72 | process(value); // This line will cause a compilation error
| ------- ^^^^^ the trait `Reconcile` is not implemented for `String`
| |
| required by a bound introduced by this call
|
= help: the following other types implement trait `Reconcile`:
bool
i8
i16
i32
i64
i128
u8
u16
u32
u128
note: required by a bound in `process`
oh and btw, I had the exact same thought as you initially, but I wasn't satisfied with the off-by one so I had to search for another reason but still without actually looking at the relevant PR or blame because I was kinda lazy, admittedly (I still haven't looked, I wonder tho, if they did mention it), ok wth, I'm gonna look now...will edit later
EDIT: tracking this down isn't easy lol, but here's the result so far:
It might appear that the source of this is this commit: 3aac307
but it seems it was only improving on something that was originally from this commit: ca54fc76ae30 and thus this PR #39804
So, given the above then, we can conclude that it was even more than just worrying about the extra s
, but rather, showing that line, replaced one possible type being listed, so it was useless, thus showing 2 or more was needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It wasn't to avoid the "1 others" message, but rather if we're already "wasting" a line to say there's another one, then just print it.
@bors r+ rollup |
Expand list of trait implementers in E0277 when calling rustc with --verbose Fixes: rust-lang#125984 - Build `rustc` use `./x build`. - Test result <img width="634" alt="image" src="https://github.com/rust-lang/rust/assets/15009201/89377059-2316-492b-a38a-fa33adfc9793"> - vim test.rs ```rust trait Reconcile { fn reconcile(&self); } // Implementing the trait for some types impl Reconcile for bool { fn reconcile(&self) { println!("Reconciling bool"); } } impl Reconcile for i8 { fn reconcile(&self) { println!("Reconciling i8"); } } impl Reconcile for i16 { fn reconcile(&self) { println!("Reconciling i16"); } } impl Reconcile for i32 { fn reconcile(&self) { println!("Reconciling i32"); } } impl Reconcile for i64 { fn reconcile(&self) { println!("Reconciling i64"); } } impl Reconcile for u8 { fn reconcile(&self) { println!("Reconciling u8"); } } impl Reconcile for u16 { fn reconcile(&self) { println!("Reconciling u16"); } } impl Reconcile for u32 { fn reconcile(&self) { println!("Reconciling u32"); } } impl Reconcile for i128 { fn reconcile(&self) { println!("Reconciling u32"); } } impl Reconcile for u128 { fn reconcile(&self) { println!("Reconciling u32"); } } fn process<T: Reconcile>(item: T) { item.reconcile(); } fn main() { let value = String::from("This will cause an error"); process(value); // This line will cause a compilation error } ```
Rollup of 7 pull requests Successful merges: - rust-lang#115974 (Split core's PanicInfo and std's PanicInfo) - rust-lang#125659 (Remove usage of `isize` in example) - rust-lang#125669 (CI: Update riscv64gc-linux job to Ubuntu 22.04, rename to riscv64gc-gnu) - rust-lang#125684 (Account for existing bindings when suggesting `pin!()`) - rust-lang#126055 (Expand list of trait implementers in E0277 when calling rustc with --verbose) - rust-lang#126174 (Migrate `tests/run-make/prefer-dylib` to `rmake.rs`) - rust-lang#126256 (Add {{target}} substitution to compiletest) r? `@ghost` `@rustbot` modify labels: rollup
Expand list of trait implementers in E0277 when calling rustc with --verbose Fixes: rust-lang#125984 - Build `rustc` use `./x build`. - Test result <img width="634" alt="image" src="https://github.com/rust-lang/rust/assets/15009201/89377059-2316-492b-a38a-fa33adfc9793"> - vim test.rs ```rust trait Reconcile { fn reconcile(&self); } // Implementing the trait for some types impl Reconcile for bool { fn reconcile(&self) { println!("Reconciling bool"); } } impl Reconcile for i8 { fn reconcile(&self) { println!("Reconciling i8"); } } impl Reconcile for i16 { fn reconcile(&self) { println!("Reconciling i16"); } } impl Reconcile for i32 { fn reconcile(&self) { println!("Reconciling i32"); } } impl Reconcile for i64 { fn reconcile(&self) { println!("Reconciling i64"); } } impl Reconcile for u8 { fn reconcile(&self) { println!("Reconciling u8"); } } impl Reconcile for u16 { fn reconcile(&self) { println!("Reconciling u16"); } } impl Reconcile for u32 { fn reconcile(&self) { println!("Reconciling u32"); } } impl Reconcile for i128 { fn reconcile(&self) { println!("Reconciling u32"); } } impl Reconcile for u128 { fn reconcile(&self) { println!("Reconciling u32"); } } fn process<T: Reconcile>(item: T) { item.reconcile(); } fn main() { let value = String::from("This will cause an error"); process(value); // This line will cause a compilation error } ```
Rollup of 6 pull requests Successful merges: - rust-lang#115974 (Split core's PanicInfo and std's PanicInfo) - rust-lang#125659 (Remove usage of `isize` in example) - rust-lang#125669 (CI: Update riscv64gc-linux job to Ubuntu 22.04, rename to riscv64gc-gnu) - rust-lang#125684 (Account for existing bindings when suggesting `pin!()`) - rust-lang#126055 (Expand list of trait implementers in E0277 when calling rustc with --verbose) - rust-lang#126174 (Migrate `tests/run-make/prefer-dylib` to `rmake.rs`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#126055 - lengrongfu:master, r=pnkfelix Expand list of trait implementers in E0277 when calling rustc with --verbose Fixes: rust-lang#125984 - Build `rustc` use `./x build`. - Test result <img width="634" alt="image" src="https://github.com/rust-lang/rust/assets/15009201/89377059-2316-492b-a38a-fa33adfc9793"> - vim test.rs ```rust trait Reconcile { fn reconcile(&self); } // Implementing the trait for some types impl Reconcile for bool { fn reconcile(&self) { println!("Reconciling bool"); } } impl Reconcile for i8 { fn reconcile(&self) { println!("Reconciling i8"); } } impl Reconcile for i16 { fn reconcile(&self) { println!("Reconciling i16"); } } impl Reconcile for i32 { fn reconcile(&self) { println!("Reconciling i32"); } } impl Reconcile for i64 { fn reconcile(&self) { println!("Reconciling i64"); } } impl Reconcile for u8 { fn reconcile(&self) { println!("Reconciling u8"); } } impl Reconcile for u16 { fn reconcile(&self) { println!("Reconciling u16"); } } impl Reconcile for u32 { fn reconcile(&self) { println!("Reconciling u32"); } } impl Reconcile for i128 { fn reconcile(&self) { println!("Reconciling u32"); } } impl Reconcile for u128 { fn reconcile(&self) { println!("Reconciling u32"); } } fn process<T: Reconcile>(item: T) { item.reconcile(); } fn main() { let value = String::from("This will cause an error"); process(value); // This line will cause a compilation error } ```
Fixes: #125984
rustc
use./x build
.