Remove invalid suggestions for assoc consts on placeholder type error
This commit is contained in:
parent
52b22869db
commit
d828eadd7a
@ -180,8 +180,7 @@ crate fn placeholder_type_error(
|
||||
// Suggest, but only if it is not a function in const or static
|
||||
if suggest {
|
||||
let mut is_fn = false;
|
||||
let mut is_const = false;
|
||||
let mut is_static = false;
|
||||
let mut is_const_or_static = false;
|
||||
|
||||
if let Some(hir_ty) = hir_ty {
|
||||
if let hir::TyKind::BareFn(_) = hir_ty.kind {
|
||||
@ -191,19 +190,26 @@ crate fn placeholder_type_error(
|
||||
let parent_id = tcx.hir().get_parent_node(hir_ty.hir_id);
|
||||
let parent_node = tcx.hir().get(parent_id);
|
||||
|
||||
if let hir::Node::Item(item) = parent_node {
|
||||
if let hir::ItemKind::Const(_, _) = item.kind {
|
||||
is_const = true;
|
||||
} else if let hir::ItemKind::Static(_, _, _) = item.kind {
|
||||
is_static = true;
|
||||
}
|
||||
}
|
||||
is_const_or_static = match parent_node {
|
||||
Node::Item(&hir::Item {
|
||||
kind: hir::ItemKind::Const(..) | hir::ItemKind::Static(..),
|
||||
..
|
||||
})
|
||||
| Node::TraitItem(&hir::TraitItem {
|
||||
kind: hir::TraitItemKind::Const(..),
|
||||
..
|
||||
})
|
||||
| Node::ImplItem(&hir::ImplItem {
|
||||
kind: hir::ImplItemKind::Const(..), ..
|
||||
}) => true,
|
||||
_ => false,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// if function is wrapped around a const or static,
|
||||
// then don't show the suggestion
|
||||
if !(is_fn && (is_const || is_static)) {
|
||||
if !(is_fn && is_const_or_static) {
|
||||
err.multipart_suggestion(
|
||||
"use type parameters instead",
|
||||
sugg,
|
||||
|
14
src/test/ui/typeck/type-placeholder-fn-in-const.rs
Normal file
14
src/test/ui/typeck/type-placeholder-fn-in-const.rs
Normal file
@ -0,0 +1,14 @@
|
||||
struct MyStruct;
|
||||
|
||||
trait Test {
|
||||
const TEST: fn() -> _;
|
||||
//~^ ERROR: the type placeholder `_` is not allowed within types on item signatures [E0121]
|
||||
//~| ERROR: the type placeholder `_` is not allowed within types on item signatures [E0121]
|
||||
}
|
||||
|
||||
impl Test for MyStruct {
|
||||
const TEST: fn() -> _ = 42;
|
||||
//~^ ERROR: the type placeholder `_` is not allowed within types on item signatures [E0121]
|
||||
}
|
||||
|
||||
fn main() {}
|
21
src/test/ui/typeck/type-placeholder-fn-in-const.stderr
Normal file
21
src/test/ui/typeck/type-placeholder-fn-in-const.stderr
Normal file
@ -0,0 +1,21 @@
|
||||
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
|
||||
--> $DIR/type-placeholder-fn-in-const.rs:4:25
|
||||
|
|
||||
LL | const TEST: fn() -> _;
|
||||
| ^ not allowed in type signatures
|
||||
|
||||
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
|
||||
--> $DIR/type-placeholder-fn-in-const.rs:4:25
|
||||
|
|
||||
LL | const TEST: fn() -> _;
|
||||
| ^ not allowed in type signatures
|
||||
|
||||
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
|
||||
--> $DIR/type-placeholder-fn-in-const.rs:10:25
|
||||
|
|
||||
LL | const TEST: fn() -> _ = 42;
|
||||
| ^ not allowed in type signatures
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0121`.
|
Loading…
x
Reference in New Issue
Block a user