mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Deduplicate some logic and reword output
This commit is contained in:
parent
b59bd7fd16
commit
28c028737d
@ -1427,6 +1427,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
let tcx = self.tcx;
|
||||
let def_kind = similar_candidate.kind.as_def_kind();
|
||||
let an = self.tcx.def_kind_descr_article(def_kind, similar_candidate.def_id);
|
||||
let msg = format!(
|
||||
"there is {an} {} `{}` with a similar name",
|
||||
self.tcx.def_kind_descr(def_kind, similar_candidate.def_id),
|
||||
similar_candidate.name,
|
||||
);
|
||||
// Methods are defined within the context of a struct and their first parameter
|
||||
// is always `self`, which represents the instance of the struct the method is
|
||||
// being called on Associated functions don’t take self as a parameter and they are
|
||||
@ -1443,7 +1448,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
// call expression the user wrote.
|
||||
err.span_suggestion_verbose(
|
||||
span,
|
||||
format!("there is {an} method with a similar name"),
|
||||
msg,
|
||||
similar_candidate.name,
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
@ -1453,8 +1458,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
err.span_help(
|
||||
tcx.def_span(similar_candidate.def_id),
|
||||
format!(
|
||||
"there is {an} method `{}` with a similar name{}",
|
||||
similar_candidate.name,
|
||||
"{msg}{}",
|
||||
if let None = args { "" } else { ", but with different arguments" },
|
||||
),
|
||||
);
|
||||
@ -1466,22 +1470,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
// function we found.
|
||||
err.span_suggestion_verbose(
|
||||
span,
|
||||
format!(
|
||||
"there is {an} {} with a similar name",
|
||||
self.tcx.def_kind_descr(def_kind, similar_candidate.def_id)
|
||||
),
|
||||
msg,
|
||||
similar_candidate.name,
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
} else {
|
||||
err.span_help(
|
||||
tcx.def_span(similar_candidate.def_id),
|
||||
format!(
|
||||
"there is {an} {} `{}` with a similar name",
|
||||
self.tcx.def_kind_descr(def_kind, similar_candidate.def_id),
|
||||
similar_candidate.name,
|
||||
),
|
||||
);
|
||||
err.span_help(tcx.def_span(similar_candidate.def_id), msg);
|
||||
}
|
||||
} else if let Mode::Path = mode
|
||||
&& args.unwrap_or(&[]).is_empty()
|
||||
@ -1489,24 +1483,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
// We have an associated item syntax and we found something that isn't an fn.
|
||||
err.span_suggestion_verbose(
|
||||
span,
|
||||
format!(
|
||||
"there is {an} {} with a similar name",
|
||||
self.tcx.def_kind_descr(def_kind, similar_candidate.def_id)
|
||||
),
|
||||
msg,
|
||||
similar_candidate.name,
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
} else {
|
||||
// The expression is a function or method call, but the item we found is an
|
||||
// associated const or type.
|
||||
err.span_help(
|
||||
tcx.def_span(similar_candidate.def_id),
|
||||
format!(
|
||||
"there is {an} {} `{}` with a similar name",
|
||||
self.tcx.def_kind_descr(def_kind, similar_candidate.def_id),
|
||||
similar_candidate.name,
|
||||
),
|
||||
);
|
||||
err.span_help(tcx.def_span(similar_candidate.def_id), msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ LL | enum Enum { Variant }
|
||||
LL | Enum::mispellable();
|
||||
| ^^^^^^^^^^^ variant or associated item not found in `Enum`
|
||||
|
|
||||
help: there is an associated function with a similar name
|
||||
help: there is an associated function `misspellable` with a similar name
|
||||
|
|
||||
LL | Enum::misspellable();
|
||||
| ~~~~~~~~~~~~
|
||||
@ -21,7 +21,7 @@ LL | enum Enum { Variant }
|
||||
LL | Enum::mispellable_trait();
|
||||
| ^^^^^^^^^^^^^^^^^ variant or associated item not found in `Enum`
|
||||
|
|
||||
help: there is an associated function with a similar name
|
||||
help: there is an associated function `misspellable_trait` with a similar name
|
||||
|
|
||||
LL | Enum::misspellable_trait();
|
||||
| ~~~~~~~~~~~~~~~~~~
|
||||
@ -35,7 +35,7 @@ LL | enum Enum { Variant }
|
||||
LL | Enum::MISPELLABLE;
|
||||
| ^^^^^^^^^^^ variant or associated item not found in `Enum`
|
||||
|
|
||||
help: there is an associated constant with a similar name
|
||||
help: there is an associated constant `MISSPELLABLE` with a similar name
|
||||
|
|
||||
LL | Enum::MISSPELLABLE;
|
||||
| ~~~~~~~~~~~~
|
||||
|
@ -11,7 +11,7 @@ fn main() {
|
||||
let x = BTreeSet {};
|
||||
x.inser();
|
||||
//~^ ERROR no method named
|
||||
//~| HELP there is a method with a similar name
|
||||
//~| HELP there is a method `insert` with a similar name
|
||||
x.foo();
|
||||
//~^ ERROR no method named
|
||||
x.push();
|
||||
|
@ -33,7 +33,7 @@ error[E0599]: no method named `inser` found for struct `rustc_confusables_across
|
||||
LL | x.inser();
|
||||
| ^^^^^
|
||||
|
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `insert` with a similar name
|
||||
|
|
||||
LL | x.insert();
|
||||
| ~~~~~~
|
||||
|
@ -4,7 +4,7 @@ error[E0599]: no method named `b` found for reference `&Self` in the current sco
|
||||
LL | || self.b()
|
||||
| ^
|
||||
|
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `a` with a similar name
|
||||
|
|
||||
LL | || self.a()
|
||||
| ~
|
||||
|
@ -8,7 +8,7 @@ help: to call the function stored in `closure`, surround the field access with p
|
||||
|
|
||||
LL | (p.closure)();
|
||||
| + +
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `clone` with a similar name
|
||||
|
|
||||
LL | p.clone();
|
||||
| ~~~~~
|
||||
|
@ -15,7 +15,7 @@ LL + use no_method_suggested_traits::foo::PubPub;
|
||||
|
|
||||
LL + use no_method_suggested_traits::qux::PrivPub;
|
||||
|
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `method2` with a similar name
|
||||
|
|
||||
LL | 1u32.method2();
|
||||
| ~~~~~~~
|
||||
@ -37,7 +37,7 @@ LL + use no_method_suggested_traits::foo::PubPub;
|
||||
|
|
||||
LL + use no_method_suggested_traits::qux::PrivPub;
|
||||
|
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `method2` with a similar name
|
||||
|
|
||||
LL | std::rc::Rc::new(&mut Box::new(&1u32)).method2();
|
||||
| ~~~~~~~
|
||||
@ -56,7 +56,7 @@ help: trait `Bar` which provides `method` is implemented but not in scope; perha
|
||||
|
|
||||
LL + use foo::Bar;
|
||||
|
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `method2` with a similar name
|
||||
|
|
||||
LL | 'a'.method2();
|
||||
| ~~~~~~~
|
||||
@ -72,7 +72,7 @@ help: trait `Bar` which provides `method` is implemented but not in scope; perha
|
||||
|
|
||||
LL + use foo::Bar;
|
||||
|
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `method2` with a similar name
|
||||
|
|
||||
LL | std::rc::Rc::new(&mut Box::new(&'a')).method2();
|
||||
| ~~~~~~~
|
||||
@ -93,7 +93,7 @@ help: trait `PubPub` which provides `method` is implemented but not in scope; pe
|
||||
|
|
||||
LL + use no_method_suggested_traits::foo::PubPub;
|
||||
|
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `method3` with a similar name
|
||||
|
|
||||
LL | 1i32.method3();
|
||||
| ~~~~~~~
|
||||
@ -109,7 +109,7 @@ help: trait `PubPub` which provides `method` is implemented but not in scope; pe
|
||||
|
|
||||
LL + use no_method_suggested_traits::foo::PubPub;
|
||||
|
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `method3` with a similar name
|
||||
|
|
||||
LL | std::rc::Rc::new(&mut Box::new(&1i32)).method3();
|
||||
| ~~~~~~~
|
||||
|
@ -14,7 +14,7 @@ help: trait `Trait` which provides `trait_method` is implemented but not in scop
|
||||
|
|
||||
LL + use reexported_trait::Trait;
|
||||
|
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `trait_method_b` with a similar name
|
||||
|
|
||||
LL | reexported_trait::FooStruct.trait_method_b();
|
||||
| ~~~~~~~~~~~~~~
|
||||
@ -35,7 +35,7 @@ help: trait `TraitB` which provides `trait_method_b` is implemented but not in s
|
||||
|
|
||||
LL + use reexported_trait::TraitBRename;
|
||||
|
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `trait_method` with a similar name
|
||||
|
|
||||
LL | reexported_trait::FooStruct.trait_method();
|
||||
| ~~~~~~~~~~~~
|
||||
|
@ -12,7 +12,7 @@ error[E0599]: no method named `g` found for reference `&Self` in the current sco
|
||||
LL | self.g();
|
||||
| ^
|
||||
|
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `f` with a similar name
|
||||
|
|
||||
LL | self.f();
|
||||
| ~
|
||||
|
@ -7,7 +7,7 @@ LL | struct Foo;
|
||||
LL | Foo.quux();
|
||||
| ^^^^
|
||||
|
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `bar` with a similar name
|
||||
|
|
||||
LL | Foo.bar();
|
||||
| ~~~
|
||||
|
@ -7,7 +7,7 @@ LL | fn owned(self: Box<Self>);
|
||||
LL | x.owned();
|
||||
| ^^^^^
|
||||
|
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `to_owned` with a similar name
|
||||
|
|
||||
LL | x.to_owned();
|
||||
| ~~~~~~~~
|
||||
|
@ -78,7 +78,7 @@ note: if you're trying to build a new `👀`, consider using `👀::full_of_✨`
|
||||
|
|
||||
LL | fn full_of_✨() -> 👀 {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
help: there is an associated function with a similar name
|
||||
help: there is an associated function `full_of_✨` with a similar name
|
||||
|
|
||||
LL | 👀::full_of_✨()
|
||||
| ~~~~~~~~~~
|
||||
|
@ -16,7 +16,7 @@ LL | struct Struct;
|
||||
LL | Struct::fob();
|
||||
| ^^^ function or associated item not found in `Struct`
|
||||
|
|
||||
help: there is an associated function with a similar name
|
||||
help: there is an associated function `foo` with a similar name
|
||||
|
|
||||
LL | Struct::foo();
|
||||
| ~~~
|
||||
|
@ -12,7 +12,7 @@ help: trait `Foobar` which provides `foobar` is implemented but not in scope; pe
|
||||
|
|
||||
LL + use crate::foo::foobar::Foobar;
|
||||
|
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `bar` with a similar name
|
||||
|
|
||||
LL | x.bar();
|
||||
| ~~~
|
||||
@ -31,7 +31,7 @@ help: trait `Bar` which provides `bar` is implemented but not in scope; perhaps
|
||||
|
|
||||
LL + use crate::foo::Bar;
|
||||
|
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `foobar` with a similar name
|
||||
|
|
||||
LL | x.foobar();
|
||||
| ~~~~~~
|
||||
@ -42,7 +42,7 @@ error[E0599]: no method named `baz` found for type `u32` in the current scope
|
||||
LL | x.baz();
|
||||
| ^^^
|
||||
|
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `bar` with a similar name
|
||||
|
|
||||
LL | x.bar();
|
||||
| ~~~
|
||||
@ -58,7 +58,7 @@ help: trait `FromStr` which provides `from_str` is implemented but not in scope;
|
||||
|
|
||||
LL + use std::str::FromStr;
|
||||
|
|
||||
help: there is an associated function with a similar name
|
||||
help: there is an associated function `from` with a similar name
|
||||
|
|
||||
LL | let y = u32::from("33");
|
||||
| ~~~~
|
||||
|
@ -12,7 +12,7 @@ LL + use crate::m::TryIntoU32;
|
||||
|
|
||||
LL + use std::convert::TryInto;
|
||||
|
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `into` with a similar name
|
||||
|
|
||||
LL | let _: u32 = 3u8.into().unwrap();
|
||||
| ~~~~
|
||||
|
@ -9,7 +9,7 @@ note: method is available for `Pin<&mut S>`
|
||||
|
|
||||
LL | fn x(self: Pin<&mut Self>) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `y` with a similar name
|
||||
|
|
||||
LL | Pin::new(&S).y();
|
||||
| ~
|
||||
@ -25,7 +25,7 @@ note: method is available for `Pin<&S>`
|
||||
|
|
||||
LL | fn y(self: Pin<&Self>) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `x` with a similar name
|
||||
|
|
||||
LL | Pin::new(&mut S).x();
|
||||
| ~
|
||||
|
@ -10,7 +10,7 @@ note: if you're trying to build a new `Backtrace` consider using one of the foll
|
||||
Backtrace::disabled
|
||||
Backtrace::create
|
||||
--> $SRC_DIR/std/src/backtrace.rs:LL:COL
|
||||
help: there is an associated function with a similar name
|
||||
help: there is an associated function `force_capture` with a similar name
|
||||
|
|
||||
LL | println!("Custom backtrace: {}", std::backtrace::Backtrace::force_capture());
|
||||
| ~~~~~~~~~~~~~
|
||||
|
@ -19,7 +19,7 @@ error[E0599]: no method named `is_emtpy` found for struct `String` in the curren
|
||||
LL | let _ = s.is_emtpy();
|
||||
| ^^^^^^^^
|
||||
|
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `is_empty` with a similar name
|
||||
|
|
||||
LL | let _ = s.is_empty();
|
||||
| ~~~~~~~~
|
||||
@ -30,7 +30,7 @@ error[E0599]: no method named `count_eos` found for type `u32` in the current sc
|
||||
LL | let _ = 63u32.count_eos();
|
||||
| ^^^^^^^^^
|
||||
|
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `count_zeros` with a similar name
|
||||
|
|
||||
LL | let _ = 63u32.count_zeros();
|
||||
| ~~~~~~~~~~~
|
||||
@ -41,7 +41,7 @@ error[E0599]: no method named `count_o` found for type `u32` in the current scop
|
||||
LL | let _ = 63u32.count_o();
|
||||
| ^^^^^^^
|
||||
|
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `count_ones` with a similar name
|
||||
|
|
||||
LL | let _ = 63u32.count_ones();
|
||||
| ~~~~~~~~~~
|
||||
|
@ -62,7 +62,7 @@ help: trait `TryInto` which provides `try_into` is implemented but not in scope;
|
||||
|
|
||||
LL + use std::convert::TryInto;
|
||||
|
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `into` with a similar name
|
||||
|
|
||||
LL | let _i: i16 = 0_i32.into().unwrap();
|
||||
| ~~~~
|
||||
|
@ -12,7 +12,7 @@ help: trait `A` which provides `a` is implemented but not in scope; perhaps you
|
||||
|
|
||||
LL + use method::A;
|
||||
|
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `b` with a similar name
|
||||
|
|
||||
LL | S.b();
|
||||
| ~
|
||||
@ -34,7 +34,7 @@ help: trait `B` which provides `b` is implemented but not in scope; perhaps you
|
||||
|
|
||||
LL + use method::B;
|
||||
|
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `c` with a similar name
|
||||
|
|
||||
LL | S.c();
|
||||
| ~
|
||||
@ -111,7 +111,7 @@ help: trait `A` which provides `A` is implemented but not in scope; perhaps you
|
||||
|
|
||||
LL + use assoc_const::A;
|
||||
|
|
||||
help: there is an associated constant with a similar name
|
||||
help: there is an associated constant `B` with a similar name
|
||||
|
|
||||
LL | S::B;
|
||||
| ~
|
||||
@ -130,7 +130,7 @@ help: trait `B` which provides `B` is implemented but not in scope; perhaps you
|
||||
|
|
||||
LL + use assoc_const::B;
|
||||
|
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `b` with a similar name
|
||||
|
|
||||
LL | S::b;
|
||||
| ~
|
||||
|
@ -10,7 +10,7 @@ note: `Baz` defines an item `c`, perhaps you need to implement it
|
||||
|
|
||||
LL | trait Baz: Bar {
|
||||
| ^^^^^^^^^^^^^^
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `a` with a similar name
|
||||
|
|
||||
LL | bar.a();
|
||||
| ~
|
||||
@ -27,7 +27,7 @@ note: `Bar` defines an item `b`, perhaps you need to implement it
|
||||
|
|
||||
LL | trait Bar: Foo {
|
||||
| ^^^^^^^^^^^^^^
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `a` with a similar name
|
||||
|
|
||||
LL | foo.a();
|
||||
| ~
|
||||
@ -44,7 +44,7 @@ note: `Baz` defines an item `c`, perhaps you need to implement it
|
||||
|
|
||||
LL | trait Baz: Bar {
|
||||
| ^^^^^^^^^^^^^^
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `a` with a similar name
|
||||
|
|
||||
LL | foo.a();
|
||||
| ~
|
||||
@ -61,7 +61,7 @@ note: `Bar` defines an item `b`, perhaps you need to implement it
|
||||
|
|
||||
LL | trait Bar: Foo {
|
||||
| ^^^^^^^^^^^^^^
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `a` with a similar name
|
||||
|
|
||||
LL | foo.a();
|
||||
| ~
|
||||
@ -78,7 +78,7 @@ note: `Baz` defines an item `c`, perhaps you need to implement it
|
||||
|
|
||||
LL | trait Baz: Bar {
|
||||
| ^^^^^^^^^^^^^^
|
||||
help: there is a method with a similar name
|
||||
help: there is a method `a` with a similar name
|
||||
|
|
||||
LL | foo.a();
|
||||
| ~
|
||||
|
Loading…
Reference in New Issue
Block a user