Skip to content

Commit

Permalink
Resolve possible inference disruption by removing unneeded From impl
Browse files Browse the repository at this point in the history
This impl breaks some code in rust-analyzer's ra_hir_def crate.

https://github.com/rust-analyzer/rust-analyzer/blob/1dba84019e0f3e7175f204624629a52013332e52/crates/ra_hir_def/src/path.rs#L273-L307

    $ cargo check --manifest-path crates/ra_hir_def/Cargo.toml
        Checking ra_hir_def v0.1.0
        Finished dev [unoptimized] target(s) in 0.75s

    $ cargo check --manifest-path crates/ra_hir_def/Cargo.toml --features log/kv_unstable
        Checking ra_hir_def v0.1.0
    error[E0282]: type annotations needed for the closure `fn(&str) -> std::result::Result<(), _>`
       --> crates/ra_hir_def/src/path.rs:278:17
        |
    278 |                 f.write_str("::")?;
        |                 ^^^^^^^^^^^^^^^^^^ cannot infer type
        |
    help: give this closure an explicit return type without `_` placeholders
        |
    276 |         let mut add_segment = |s| -> std::result::Result<(), _> {
        |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  • Loading branch information
dtolnay committed Jun 4, 2020
1 parent 4fb398b commit f3cce30
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 9 deletions.
6 changes: 0 additions & 6 deletions src/kv/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,6 @@ impl From<fmt::Error> for Error {
}
}

impl From<Error> for fmt::Error {
fn from(_: Error) -> Self {
fmt::Error
}
}

#[cfg(feature = "std")]
mod std_support {
use super::*;
Expand Down
4 changes: 2 additions & 2 deletions src/kv/value/internal/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ pub(in kv::value) use self::fmt::{Arguments, Debug, Display};

impl<'v> fmt::Debug for kv::Value<'v> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.visit(&mut FmtVisitor(f))?;
self.visit(&mut FmtVisitor(f)).map_err(|_| fmt::Error)?;

Ok(())
}
}

impl<'v> fmt::Display for kv::Value<'v> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.visit(&mut FmtVisitor(f))?;
self.visit(&mut FmtVisitor(f)).map_err(|_| fmt::Error)?;

Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ struct KeyValues<'a>(&'a dyn kv::Source);
impl<'a> fmt::Debug for KeyValues<'a> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut visitor = f.debug_map();
self.0.visit(&mut visitor)?;
self.0.visit(&mut visitor).map_err(|_| fmt::Error)?;
visitor.finish()
}
}
Expand Down

0 comments on commit f3cce30

Please sign in to comment.