Skip to content

don't suggest borrowing the Borrow::borrow function item #109804

@programmerjake

Description

@programmerjake

Code

use std::borrow::Borrow;
const F: for<'a> fn(&'a &'static String) -> &'a str = <&'static String as Borrow<str>>::borrow;

Current output

Compiling playground v0.0.1 (/playground)
error[E0277]: the trait bound `&'static String: Borrow<str>` is not satisfied
 --> src/lib.rs:2:55
  |
2 | const F: for<'a> fn(&'a &'static String) -> &'a str = <&'static String as Borrow<str>>::borrow;
  |                                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Borrow<str>` is not implemented for `&'static String`
  |
help: consider borrowing here
  |
2 | const F: for<'a> fn(&'a &'static String) -> &'a str = &<&'static String as Borrow<str>>::borrow;
  |                                                       +

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` due to previous error

Desired output

Compiling playground v0.0.1 (/playground)
error[E0277]: the trait bound `&'static String: Borrow<str>` is not satisfied
 --> src/lib.rs:2:55
  |
2 | const F: for<'a> fn(&'a &'static String) -> &'a str = <&'static String as Borrow<str>>::borrow;
  |                                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Borrow<str>` is not implemented for `&'static String`

For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` due to previous error

Rationale and extra context

borrowing the Borrow::borrow function item won't ever fix the missing trait bound.

Other cases

No response

Anything else?

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=936662eafc8d3c0e04f880536d242015

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions