Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions compiler/rustc_hir_typeck/src/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1177,15 +1177,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let is_method = mode == Mode::MethodCall;
let item_kind = if is_method {
"method"
} else if rcvr_ty.is_enum() {
"variant or associated item"
} else if rcvr_ty.is_enum() || rcvr_ty.is_fresh_ty() {
"variant, associated function, or constant"
} else {
match (item_ident.as_str().chars().next(), rcvr_ty.is_fresh_ty()) {
(Some(name), false) if name.is_lowercase() => "function or associated item",
(Some(_), false) => "associated item",
(Some(_), true) | (None, false) => "variant or associated item",
(None, true) => "variant",
}
"associated function or constant"
};

if let Err(guar) = self.report_failed_method_call_on_numerical_infer_var(
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/associated-consts/associated-const-no-item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ trait Foo {
}

const X: i32 = <i32>::ID;
//~^ ERROR no associated item named `ID` found
//~^ ERROR no associated function or constant named `ID` found

fn main() {
assert_eq!(1, X);
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/associated-consts/associated-const-no-item.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0599]: no associated item named `ID` found for type `i32` in the current scope
error[E0599]: no associated function or constant named `ID` found for type `i32` in the current scope
--> $DIR/associated-const-no-item.rs:5:23
|
LL | const X: i32 = <i32>::ID;
| ^^ associated item not found in `i32`
| ^^ associated function or constant not found in `i32`
|
= help: items from traits can only be used if the trait is implemented and in scope
note: `Foo` defines an item `ID`, perhaps you need to implement it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ impl Fail<i32> {

fn main() {
Fail::<()>::C
//~^ ERROR no associated item named `C` found for struct `Fail<()>` in the current scope
//~^ ERROR no associated function or constant named `C` found for struct `Fail<()>` in the current scope
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ LL | struct Fail<T>;
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
= help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead

error[E0599]: no associated item named `C` found for struct `Fail<()>` in the current scope
error[E0599]: no associated function or constant named `C` found for struct `Fail<()>` in the current scope
--> $DIR/wrong-projection-self-ty-invalid-bivariant-arg.rs:9:17
|
LL | struct Fail<T>;
| -------------- associated item `C` not found for this struct
| -------------- associated function or constant `C` not found for this struct
...
LL | Fail::<()>::C
| ^ associated item not found in `Fail<()>`
| ^ associated function or constant not found in `Fail<()>`
|
= note: the associated item was found for
= note: the associated function or constant was found for
- `Fail<i32>`

error: aborting due to 2 previous errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ impl Fail<i32, i32> {
fn main() {
Fail::<i32, u32>::C
//~^ ERROR: type mismatch
//~| ERROR no associated item named `C` found for struct `Fail<i32, u32>` in the current scope
//~| ERROR no associated function or constant named `C` found for struct `Fail<i32, u32>` in the current scope
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ note: required by a bound in `Fail`
LL | struct Fail<T: Proj<Assoc = U>, U>(T);
| ^^^^^^^^^ required by this bound in `Fail`

error[E0599]: no associated item named `C` found for struct `Fail<i32, u32>` in the current scope
error[E0599]: no associated function or constant named `C` found for struct `Fail<i32, u32>` in the current scope
--> $DIR/wrong-projection-self-ty-invalid-bivariant-arg2.rs:15:23
|
LL | struct Fail<T: Proj<Assoc = U>, U>(T);
| ---------------------------------- associated item `C` not found for this struct
| ---------------------------------- associated function or constant `C` not found for this struct
...
LL | Fail::<i32, u32>::C
| ^ associated item not found in `Fail<i32, u32>`
| ^ associated function or constant not found in `Fail<i32, u32>`
|
= note: the associated item was found for
= note: the associated function or constant was found for
- `Fail<i32, i32>`

error: aborting due to 2 previous errors
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/associated-item/associated-item-enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ impl Trait for Enum {
}

fn main() {
Enum::mispellable(); //~ ERROR no variant or associated item
Enum::mispellable_trait(); //~ ERROR no variant or associated item
Enum::MISPELLABLE; //~ ERROR no variant or associated item
Enum::mispellable(); //~ ERROR no variant, associated function, or constant
Enum::mispellable_trait(); //~ ERROR no variant, associated function, or constant
Enum::MISPELLABLE; //~ ERROR no variant, associated function, or constant
}
18 changes: 9 additions & 9 deletions tests/ui/associated-item/associated-item-enum.stderr
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
error[E0599]: no variant or associated item named `mispellable` found for enum `Enum` in the current scope
error[E0599]: no variant, associated function, or constant named `mispellable` found for enum `Enum` in the current scope
--> $DIR/associated-item-enum.rs:17:11
|
LL | enum Enum { Variant }
| --------- variant or associated item `mispellable` not found for this enum
| --------- variant, associated function, or constant `mispellable` not found for this enum
...
LL | Enum::mispellable();
| ^^^^^^^^^^^ variant or associated item not found in `Enum`
| ^^^^^^^^^^^ variant, associated function, or constant not found in `Enum`
|
help: there is an associated function `misspellable` with a similar name
|
LL | Enum::misspellable();
| +

error[E0599]: no variant or associated item named `mispellable_trait` found for enum `Enum` in the current scope
error[E0599]: no variant, associated function, or constant named `mispellable_trait` found for enum `Enum` in the current scope
--> $DIR/associated-item-enum.rs:18:11
|
LL | enum Enum { Variant }
| --------- variant or associated item `mispellable_trait` not found for this enum
| --------- variant, associated function, or constant `mispellable_trait` not found for this enum
...
LL | Enum::mispellable_trait();
| ^^^^^^^^^^^^^^^^^ variant or associated item not found in `Enum`
| ^^^^^^^^^^^^^^^^^ variant, associated function, or constant not found in `Enum`
|
help: there is an associated function `misspellable_trait` with a similar name
|
LL | Enum::misspellable_trait();
| +

error[E0599]: no variant or associated item named `MISPELLABLE` found for enum `Enum` in the current scope
error[E0599]: no variant, associated function, or constant named `MISPELLABLE` found for enum `Enum` in the current scope
--> $DIR/associated-item-enum.rs:19:11
|
LL | enum Enum { Variant }
| --------- variant or associated item `MISPELLABLE` not found for this enum
| --------- variant, associated function, or constant `MISPELLABLE` not found for this enum
...
LL | Enum::MISPELLABLE;
| ^^^^^^^^^^^ variant or associated item not found in `Enum`
| ^^^^^^^^^^^ variant, associated function, or constant not found in `Enum`
|
help: there is an associated constant `MISSPELLABLE` with a similar name
|
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// issue: <https://github.com/rust-lang/rust/issues/142797>

struct SomeStruct {
some_field: u64,
}

trait SomeTrait {
type SomeType;
fn foo();
}

impl SomeTrait for bool {
type SomeType = SomeStruct;

fn foo() {
let ss = Self::SomeType;
//~^ ERROR no associated function or constant named `SomeType` found for type `bool` in the current scope
}
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0599]: no associated function or constant named `SomeType` found for type `bool` in the current scope
--> $DIR/associated-type-as-value-in-impl-issue-142797.rs:16:24
|
LL | let ss = Self::SomeType;
| ^^^^^^^^ associated function or constant not found in `bool`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0599`.
2 changes: 1 addition & 1 deletion tests/ui/associated-types/associated-type-as-value.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! regression test for <https://github.com/rust-lang/rust/issues/38919>

fn foo<T: Iterator>() {
T::Item; //~ ERROR no associated item named `Item` found
T::Item; //~ ERROR no associated function or constant named `Item` found
}

fn main() { }
6 changes: 3 additions & 3 deletions tests/ui/associated-types/associated-type-as-value.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
error[E0599]: no associated item named `Item` found for type parameter `T` in the current scope
error[E0599]: no associated function or constant named `Item` found for type parameter `T` in the current scope
--> $DIR/associated-type-as-value.rs:4:8
|
LL | fn foo<T: Iterator>() {
| - associated item `Item` not found for this type parameter
| - associated function or constant `Item` not found for this type parameter
LL | T::Item;
| ^^^^ associated item not found in `T`
| ^^^^ associated function or constant not found in `T`

error: aborting due to 1 previous error

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/associated-types/associated-type-call.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl Trait for () {

fn f() {
T();
//~^ ERROR no associated item named `Assoc` found for unit type `()` in the current scope
//~^ ERROR no associated function or constant named `Assoc` found for unit type `()` in the current scope
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/associated-types/associated-type-call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl Trait for () {

fn f() {
<Self>::Assoc();
//~^ ERROR no associated item named `Assoc` found for unit type `()` in the current scope
//~^ ERROR no associated function or constant named `Assoc` found for unit type `()` in the current scope
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/associated-types/associated-type-call.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0599]: no associated item named `Assoc` found for unit type `()` in the current scope
error[E0599]: no associated function or constant named `Assoc` found for unit type `()` in the current scope
--> $DIR/associated-type-call.rs:17:17
|
LL | <Self>::Assoc();
| ^^^^^ associated item not found in `()`
| ^^^^^ associated function or constant not found in `()`
|
help: to construct a value of type `T`, use the explicit path
|
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/associated-types/invalid-ctor.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl Trait for () {

fn mk() -> Self::Out {
Constructor(1)
//~^ ERROR no associated item named `Out` found for unit type `()`
//~^ ERROR no associated function or constant named `Out` found for unit type `()`
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/associated-types/invalid-ctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl Trait for () {

fn mk() -> Self::Out {
Self::Out(1)
//~^ ERROR no associated item named `Out` found for unit type `()`
//~^ ERROR no associated function or constant named `Out` found for unit type `()`
}
}

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/associated-types/invalid-ctor.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error[E0599]: no associated item named `Out` found for unit type `()` in the current scope
error[E0599]: no associated function or constant named `Out` found for unit type `()` in the current scope
--> $DIR/invalid-ctor.rs:17:15
|
LL | Self::Out(1)
| ^^^ associated item not found in `()`
| ^^^ associated function or constant not found in `()`
|
help: to construct a value of type `Constructor`, use the explicit path
|
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/associated-types/issue-43924.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ impl Foo<u64> for () {}

fn main() {
assert_eq!(<() as Foo<u32>>::Out::default().to_string(), "false");
//~^ ERROR no function or associated item named `default` found for trait object
//~^ ERROR no associated function or constant named `default` found for trait object
}
4 changes: 2 additions & 2 deletions tests/ui/associated-types/issue-43924.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ note: required by a bound in `Foo::Out`
LL | type Out: Default + ToString + ?Sized = dyn ToString;
| ^^^^^^^ required by this bound in `Foo::Out`

error[E0599]: no function or associated item named `default` found for trait object `(dyn ToString + 'static)` in the current scope
error[E0599]: no associated function or constant named `default` found for trait object `(dyn ToString + 'static)` in the current scope
--> $DIR/issue-43924.rs:15:39
|
LL | assert_eq!(<() as Foo<u32>>::Out::default().to_string(), "false");
| ^^^^^^^ function or associated item not found in `(dyn ToString + 'static)`
| ^^^^^^^ associated function or constant not found in `(dyn ToString + 'static)`

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ impl Wrapper<{ bar() }> {

fn main() {
Wrapper::<function>::call;
//~^ ERROR: the function or associated item `call` exists for struct `Wrapper<function>`,
//~^ ERROR: the associated function or constant `call` exists for struct `Wrapper<function>`,
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ error[E0741]: using function pointers as const generic parameters is forbidden
LL | struct Wrapper<const F: fn()>;
| ^^^^

error[E0599]: the function or associated item `call` exists for struct `Wrapper<function>`, but its trait bounds were not satisfied
error[E0599]: the associated function or constant `call` exists for struct `Wrapper<function>`, but its trait bounds were not satisfied
--> $DIR/non_valtreeable_const_arg-2.rs:17:26
|
LL | struct Wrapper<const F: fn()>;
| ----------------------------- function or associated item `call` not found for this struct because it doesn't satisfy `Wrapper<function>: Fn<_>`
| ----------------------------- associated function or constant `call` not found for this struct because it doesn't satisfy `Wrapper<function>: Fn<_>`
...
LL | Wrapper::<function>::call;
| ^^^^ function or associated item cannot be called on `Wrapper<function>` due to unsatisfied trait bounds
| ^^^^ associated function or constant cannot be called on `Wrapper<function>` due to unsatisfied trait bounds
|
= note: the following trait bounds were not satisfied:
`Wrapper<function>: Fn<_>`
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/const-generics/generic_const_exprs/issue-69654.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ where

fn main() {
Foo::foo();
//~^ ERROR the function or associated item
//~^ ERROR the associated function or constant
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ help: you might have meant to write a const parameter here
LL | impl<const T: /* Type */> Bar<T> for [u8; T] {}
| +++++ ++++++++++++

error[E0599]: the function or associated item `foo` exists for struct `Foo<_>`, but its trait bounds were not satisfied
error[E0599]: the associated function or constant `foo` exists for struct `Foo<_>`, but its trait bounds were not satisfied
--> $DIR/issue-69654.rs:17:10
|
LL | struct Foo<const N: usize> {}
| -------------------------- function or associated item `foo` not found for this struct
| -------------------------- associated function or constant `foo` not found for this struct
...
LL | Foo::foo();
| ^^^ function or associated item cannot be called on `Foo<_>` due to unsatisfied trait bounds
| ^^^ associated function or constant cannot be called on `Foo<_>` due to unsatisfied trait bounds
|
note: trait bound `[u8; _]: Bar<[(); _]>` was not satisfied
--> $DIR/issue-69654.rs:11:14
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/const-generics/generic_const_exprs/issue-80742.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ where
fn main() {
let dst = Inline::<dyn Debug>::new(0);
//~^ ERROR the size for values of type `dyn Debug` cannot be known at compilation time
//~| ERROR the function or associated item `new` exists for struct `Inline<dyn Debug>`
//~| ERROR the associated function or constant `new` exists for struct `Inline<dyn Debug>`
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ help: consider relaxing the implicit `Sized` restriction
LL | struct Inline<T: ?Sized>
| ++++++++

error[E0599]: the function or associated item `new` exists for struct `Inline<dyn Debug>`, but its trait bounds were not satisfied
error[E0599]: the associated function or constant `new` exists for struct `Inline<dyn Debug>`, but its trait bounds were not satisfied
--> $DIR/issue-80742.rs:28:36
|
LL | struct Inline<T>
| ---------------- function or associated item `new` not found for this struct
| ---------------- associated function or constant `new` not found for this struct
...
LL | let dst = Inline::<dyn Debug>::new(0);
| ^^^ function or associated item cannot be called on `Inline<dyn Debug>` due to unsatisfied trait bounds
| ^^^ associated function or constant cannot be called on `Inline<dyn Debug>` due to unsatisfied trait bounds
|
note: trait bound `dyn Debug: Sized` was not satisfied
--> $DIR/issue-80742.rs:18:6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ where
fn main() {
let dst = Inline::<dyn Debug>::new(0);
//~^ ERROR the size for values of type `dyn Debug` cannot be known at compilation time
//~| ERROR no function or associated item named `new` found for struct `Inline<T>`
//~| ERROR no associated function or constant named `new` found for struct `Inline<T>`
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ help: consider relaxing the implicit `Sized` restriction
LL | struct Inline<T: ?Sized>
| ++++++++

error[E0599]: no function or associated item named `new` found for struct `Inline<T>` in the current scope
error[E0599]: no associated function or constant named `new` found for struct `Inline<T>` in the current scope
--> $DIR/size_of-dyn-trait-3.rs:18:36
|
LL | struct Inline<T>
| ---------------- function or associated item `new` not found for this struct
| ---------------- associated function or constant `new` not found for this struct
...
LL | let dst = Inline::<dyn Debug>::new(0);
| ^^^ function or associated item not found in `Inline<dyn Debug>`
| ^^^ associated function or constant not found in `Inline<dyn Debug>`

error: aborting due to 2 previous errors

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/consts/const-needs_drop-monomorphic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ impl Bool<true> {
}
fn f<T>() {
Bool::<{ std::mem::needs_drop::<T>() }>::assert();
//~^ ERROR no function or associated item named `assert` found
//~^ ERROR no associated function or constant named `assert` found
//~| ERROR unconstrained generic constant
}
fn main() {
Expand Down
Loading
Loading