mirror of https://github.com/rust-lang/rust.git
Rollup merge of #86355 - JohnTitor:issue-82158, r=estebank
Remove invalid suggestions for assoc consts on placeholder type error Fixes #82158 This also moves some tests to typeck. r? ``@estebank``
This commit is contained in:
commit
aff7994740
|
@ -179,8 +179,7 @@ crate fn placeholder_type_error(
|
||||||
// Suggest, but only if it is not a function in const or static
|
// Suggest, but only if it is not a function in const or static
|
||||||
if suggest {
|
if suggest {
|
||||||
let mut is_fn = false;
|
let mut is_fn = false;
|
||||||
let mut is_const = false;
|
let mut is_const_or_static = false;
|
||||||
let mut is_static = false;
|
|
||||||
|
|
||||||
if let Some(hir_ty) = hir_ty {
|
if let Some(hir_ty) = hir_ty {
|
||||||
if let hir::TyKind::BareFn(_) = hir_ty.kind {
|
if let hir::TyKind::BareFn(_) = hir_ty.kind {
|
||||||
|
@ -190,19 +189,26 @@ crate fn placeholder_type_error(
|
||||||
let parent_id = tcx.hir().get_parent_node(hir_ty.hir_id);
|
let parent_id = tcx.hir().get_parent_node(hir_ty.hir_id);
|
||||||
let parent_node = tcx.hir().get(parent_id);
|
let parent_node = tcx.hir().get(parent_id);
|
||||||
|
|
||||||
if let hir::Node::Item(item) = parent_node {
|
is_const_or_static = match parent_node {
|
||||||
if let hir::ItemKind::Const(_, _) = item.kind {
|
Node::Item(&hir::Item {
|
||||||
is_const = true;
|
kind: hir::ItemKind::Const(..) | hir::ItemKind::Static(..),
|
||||||
} else if let hir::ItemKind::Static(_, _, _) = item.kind {
|
..
|
||||||
is_static = true;
|
})
|
||||||
}
|
| 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,
|
// if function is wrapped around a const or static,
|
||||||
// then don't show the suggestion
|
// then don't show the suggestion
|
||||||
if !(is_fn && (is_const || is_static)) {
|
if !(is_fn && is_const_or_static) {
|
||||||
err.multipart_suggestion(
|
err.multipart_suggestion(
|
||||||
"use type parameters instead",
|
"use type parameters instead",
|
||||||
sugg,
|
sugg,
|
||||||
|
|
|
@ -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() {}
|
|
@ -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…
Reference in New Issue