-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Refactor #[diagnostic::do_not_recommend]
support
#125717
Merged
bors
merged 1 commit into
rust-lang:master
from
weiznich:move/do_not_recommend_to_diganostic_namespace
Jun 4, 2024
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
tests/ui/diagnostic_namespace/do_not_recommend/type_mismatch.current.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error[E0277]: Very important message! | ||
--> $DIR/type_mismatch.rs:25:14 | ||
| | ||
LL | verify::<u8>(); | ||
| ^^ the trait `TheImportantOne` is not implemented for `u8` | ||
| | ||
note: required by a bound in `verify` | ||
--> $DIR/type_mismatch.rs:22:14 | ||
| | ||
LL | fn verify<T: TheImportantOne>() {} | ||
| ^^^^^^^^^^^^^^^ required by this bound in `verify` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
15 changes: 15 additions & 0 deletions
15
tests/ui/diagnostic_namespace/do_not_recommend/type_mismatch.next.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error[E0277]: Very important message! | ||
--> $DIR/type_mismatch.rs:25:14 | ||
| | ||
LL | verify::<u8>(); | ||
| ^^ the trait `TheImportantOne` is not implemented for `u8` | ||
| | ||
note: required by a bound in `verify` | ||
--> $DIR/type_mismatch.rs:22:14 | ||
| | ||
LL | fn verify<T: TheImportantOne>() {} | ||
| ^^^^^^^^^^^^^^^ required by this bound in `verify` | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
27 changes: 27 additions & 0 deletions
27
tests/ui/diagnostic_namespace/do_not_recommend/type_mismatch.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//@ revisions: current next | ||
//@ ignore-compare-mode-next-solver (explicit revisions) | ||
//@[next] compile-flags: -Znext-solver | ||
|
||
#![feature(do_not_recommend)] | ||
|
||
#[diagnostic::on_unimplemented(message = "Very important message!")] | ||
trait TheImportantOne {} | ||
|
||
trait ImplementationDetail { | ||
type Restriction; | ||
} | ||
|
||
#[diagnostic::do_not_recommend] | ||
impl<T: ImplementationDetail<Restriction = ()>> TheImportantOne for T {} | ||
|
||
// Comment out this `impl` to show the expected error message. | ||
impl ImplementationDetail for u8 { | ||
type Restriction = u8; | ||
} | ||
|
||
fn verify<T: TheImportantOne>() {} | ||
|
||
pub fn main() { | ||
verify::<u8>(); | ||
//~^ERROR: Very important message! [E0277] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 don't think this is correct
Select(Unimplemented)
is only meant for trait goals, and only if the goal is truly unimplemented (e.g. not ambiguity, not overflow, not a cycle).I think we need to look at the
obligation
to re-derive theFulfillmentErrorCode
-- perhaps look at how theFulfillmentErrorCode
is created in the first place in the old solver?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.
For the record, I haven't looked deep enough to see if this is possible to turn into a weird diagnostic (or an ICE), so you may need to do a bit of research yourself.
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'm not sure if that is easily possible with the old solver. As far as I understand these
FulfillmentErrorCode
are produced somewhat ad hoc in the code here that does the actual solving:rust/compiler/rustc_trait_selection/src/traits/fulfill.rs
Lines 745 to 750 in f2e1a3a
At this point we know the following things about the passed obligation:
#[do_not_recommend]
an only applied to trait impls (That's asserted at other places).FulfillmentErrorCode::Project
orFulfillmentErrorCode::Project
. In both cases it will change it to the a trait requirement not implemented obligation due to wheredo_not_recommend
can be placed.Maybe it's a good idea to just explicitly check the
FulfillmentErrorCode
before if itsFulfillmentErrorCode::Select(Unimplementd)
orFulfillmentErrorCode::Project
so that it always matches that assumptions?At least all of the compiler test suite (via
./x.py test
) runs fine with this change. That said I will try to produce a few edge cases with the#[do_not_recommend]
attribute added and add them as well to the tests.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've tried to think about potential edge cases in the last few days, but I did not came up with something interesting with the current set of restrictions.
We only walk the tree now for
FulfillmentErrorCode::Select(Unimplementd)
orFulfillmentErrorCode::Project
. We only change anything if we hit a trait impl that is marked as#[do_not_recommend]
at all. As these are enforced to be on impls I cannot see a different case than just having an Obligation that just says that a certain trait is not implemented.@rustbot ready