Skip to content
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

Tracking issue for RFC 2397, "#[do_not_recommend]" #51992

Open
1 of 3 tasks
Centril opened this issue Jul 2, 2018 · 11 comments
Open
1 of 3 tasks

Tracking issue for RFC 2397, "#[do_not_recommend]" #51992

Centril opened this issue Jul 2, 2018 · 11 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-traits Area: Trait system B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. S-tracking-unimplemented Status: The feature has not been implemented. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. WG-diagnostics Working group: Diagnostics

Comments

@Centril
Copy link
Contributor

Centril commented Jul 2, 2018

This is a tracking issue for the RFC "Introduce #[do_not_recommend] to control errors for trait impls" (rust-lang/rfcs#2397).

Steps:

Unresolved questions:

  • What other names could we go with besides #[do_not_recommend]? (See RFC for some suggestions)

implementation history:

@Centril Centril added A-diagnostics Area: Messages for errors, warnings, and lints A-traits Area: Trait system B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. T-lang Relevant to the language team, which will review and decide on the PR/issue. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. WG-traits Working group: Traits, https://internals.rust-lang.org/t/announcing-traits-working-group/6804 labels Jul 2, 2018
@cramertj cramertj added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 2, 2018
@nagisa
Copy link
Member

nagisa commented Jul 2, 2018

Minor question. Presuming we implement this, and later change diagnostics in ways that make this attribute unnecessary/harmful, what would the plan of action be then?

Does this attribute essentially encode some particular format of these specific errors?

@Centril
Copy link
Contributor Author

Centril commented Jul 2, 2018

@nagisa in that hypothetical situation, deprecate the attribute perhaps?

@scottmcm
Copy link
Member

This came up in T-lang's backlog bonanza today. With no progress on this for years, it's not clear to us that this is still the right way forward here.

@estebank, do you have any thoughts on this one? Perhaps it would be better rolled into the idea you brought up in https://internals.rust-lang.org/t/stable-diagnostic-affecting-attribute-with-unstable-api/16368?u=scottmcm?

@jackh726 jackh726 added WG-diagnostics Working group: Diagnostics and removed WG-traits Working group: Traits, https://internals.rust-lang.org/t/announcing-traits-working-group/6804 labels Jun 24, 2022
JohnTitor pushed a commit to JohnTitor/rust that referenced this issue Jan 11, 2023
[RFC 2397] Initial implementation

cc rust-lang#51992

Because of previous experiences where ppl didn't have the time to review large PRs (or any at all), the implementation of this feature will be delivered in small chunks to hopefully make things faster.

In this initial PR, only the attribute is being declared and gated with ordinary tests.
JohnTitor pushed a commit to JohnTitor/rust that referenced this issue Jan 13, 2023
[RFC 2397] Deny incorrect locations

cc rust-lang#51992

As declared in the RFC, `#[do_not_recommend]` should only be applicable on trait implementations.
@c410-f3r
Copy link
Contributor

@rustbot claim

@estebank
Copy link
Contributor

If the proposal for #[diagnostics:*] is indeed accepted (which I'm confident now it will be), I strongly believe this should live under that namespace.

@weiznich
Copy link
Contributor

@estebank It should be fine to implement this as unstable feature without waiting for the #[diagnostics] RFC to be accepted. I would guess that the attribute can be moved afterwards easily, as long as it is not part of any stable release yet?

@estebank
Copy link
Contributor

@weiznich that's my understanding too.

@alice-i-cecile
Copy link

Now that #119888 is merged, what's the next step forward for this?

@c410-f3r
Copy link
Contributor

c410-f3r commented Mar 8, 2024

This feature had to be temporarily paused due to concerns around possible refactors and the new solver. https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/.E2.9C.94.20RFC-2397

If @lcnr thinks that the new solver is in a good state, then I can resume my activities with or without the diagnostic namespace.

@lcnr
Copy link
Contributor

lcnr commented Apr 6, 2024

Sorry for taking so long to reply to this issue.

The solver is not yet in a good enough state to support work on that attribute. However, looking at the old solver again, we already track where nested obligations come from:

for (index, (predicate, span)) in predicates.into_iter().enumerate() {
let cause =
if Some(parent_trait_pred.def_id()) == tcx.lang_items().coerce_unsized_trait() {
cause.clone()
} else {
cause.clone().derived_cause(parent_trait_pred, |derived| {
ImplDerivedObligation(Box::new(ImplDerivedObligationCause {
derived,
impl_or_alias_def_id: def_id,
impl_def_predicate_index: Some(index),
span,
}))
})
};
let clause = normalize_with_depth_to(
self,
param_env,
cause.clone(),
recursion_depth,
predicate,
&mut obligations,
);
obligations.push(Obligation {
cause,
recursion_depth,
param_env,
predicate: clause.as_predicate(),
});
}

This info could be used to implement it in the old solver without requiring any additional tracking: if the cause of an FUlfillmentError contains a impl_or_alias_def_id with the #[diagnostics::do_not_recommend] attribute, simply use the root obligation. This isn't perfect, as #[do_not_recommend] hides non-root parent goals we may actually have wanted to recommend.

It will take at least another few months until the "proof tree visitor" in the new solver is at a state where it can be used for diagnostics. Right now we still have to change that code to fix the happy path behavior and I don't want to slow down progress on this by having to migrate diagnostics code each time we do so.

@c410-f3r
Copy link
Contributor

c410-f3r commented Apr 6, 2024

Thank you @lcnr

compiler-errors added a commit to compiler-errors/rust that referenced this issue Jun 4, 2024
…diganostic_namespace, r=compiler-errors

Refactor `#[diagnostic::do_not_recommend]` support

This commit refactors the `#[do_not_recommend]` support in the old parser to also apply to projection errors and not only to selection errors. This allows the attribute to be used more widely.

Part of rust-lang#51992

r? `@compiler-errors`

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jun 4, 2024
Rollup merge of rust-lang#125717 - weiznich:move/do_not_recommend_to_diganostic_namespace, r=compiler-errors

Refactor `#[diagnostic::do_not_recommend]` support

This commit refactors the `#[do_not_recommend]` support in the old parser to also apply to projection errors and not only to selection errors. This allows the attribute to be used more widely.

Part of rust-lang#51992

r? `@compiler-errors`

<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.

This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using

    r​? <reviewer name>
-->
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 11, 2024
…nd_also_skips_help, r=compiler-errors

Allows `#[diagnostic::do_not_recommend]` to supress trait impls in suggestions as well

This commit changes the error reporting mechanism for not implemented traits to skip impl marked as `#[diagnostic::do_not_recommend]` in the help part of the error message ("the following other types implement trait `Foo`:"). The main use case here is to allow crate authors to skip non-meaningful confusing suggestions. A common example for this are fully generic impls on tuples.

Related to rust-lang#51992

r? `@compiler-errors`
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jul 12, 2024
Rollup merge of rust-lang#127598 - weiznich:diagnostic_do_not_recommend_also_skips_help, r=compiler-errors

Allows `#[diagnostic::do_not_recommend]` to supress trait impls in suggestions as well

This commit changes the error reporting mechanism for not implemented traits to skip impl marked as `#[diagnostic::do_not_recommend]` in the help part of the error message ("the following other types implement trait `Foo`:"). The main use case here is to allow crate authors to skip non-meaningful confusing suggestions. A common example for this are fully generic impls on tuples.

Related to rust-lang#51992

r? `@compiler-errors`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-traits Area: Trait system B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. S-tracking-unimplemented Status: The feature has not been implemented. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue. WG-diagnostics Working group: Diagnostics
Projects
None yet
Development

No branches or pull requests