8000 Account for bounds and asociated items when denying `_` by estebank · Pull Request #69148 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Account for bounds and asociated items when denying _ #69148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Account for associated items when denying _
  • Loading branch information
estebank committed Feb 27, 2020
commit c6cfcf999a53e5656f412c64f5e97e7a4840e072
34 changes: 26 additions & 8 deletions src/librustc_typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,13 +715,21 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::HirId) {
tcx.generics_of(def_id);

match trait_item.kind {
hir::TraitItemKind::Const(..)
| hir::TraitItemKind::Type(_, Some(_))
| hir::TraitItemKind::Method(..) => {
hir::TraitItemKind::Method(..) => {
tcx.type_of(def_id);
if let hir::TraitItemKind::Method(..) = trait_item.kind {
tcx.fn_sig(def_id);
}
tcx.fn_sig(def_id);
}

hir::TraitItemKind::Const(.., Some(_)) => {
tcx.type_of(def_id);
}

hir::TraitItemKind::Const(..) | hir::TraitItemKind::Type(_, Some(_)) => {
tcx.type_of(def_id);
// Account for `const C: _;` and `type T = _;`.
let mut visitor = PlaceholderHirTyCollector::default();
visitor.visit_trait_item(trait_item);
placeholder_type_error(tcx, DUMMY_SP, &[], visitor.0, false);
}

hir::TraitItemKind::Type(_, None) => {}
Expand All @@ -735,8 +743,18 @@ fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::HirId) {
tcx.generics_of(def_id);
tcx.type_of(def_id);
tcx.predicates_of(def_id);
if let hir::ImplItemKind::Method(..) = tcx.hir().expect_impl_item(impl_item_id).kind {
tcx.fn_sig(def_id);
let impl_item = tcx.hir().expect_impl_item(impl_item_id);
match impl_item.kind {
hir::ImplItemKind::Method(..) => {
tcx.fn_sig(def_id);
}
hir::ImplItemKind::TyAlias(_) | hir::ImplItemKind::OpaqueTy(_) => {
// Account for `type T = _;`
let mut visitor = PlaceholderHirTyCollector::default();
visitor.visit_impl_item(impl_item);
placeholder_type_error(tcx, DUMMY_SP, &[], visitor.0, false);
}
hir::ImplItemKind::Const(..) => {}
}
}

Expand Down
25 changes: 24 additions & 1 deletion src/test/ui/typeck/typeck_type_placeholder_item.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![feature(type_alias_impl_trait)] // Needed for single test `type Y = impl Trait<_>`
// Needed for `type Y = impl Trait<_>` and `type B = _;`
#![feature(type_alias_impl_trait, associated_type_defaults)]
// This test checks that it is not possible to enable global type
// inference by using the `_` type placeholder.

Expand Down Expand Up @@ -188,3 +189,25 @@ type Y = impl Trait<_>;
fn foo() -> Y {
Struct
}

trait Qux {
type A;
type B = _;
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
const C: _;
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
const D: _ = 42;
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
// type E: _; // FIXME: make the parser propagate the existence of `B`
}
impl Qux for Struct {
type A = _;
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
type B = _;
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
const C: _;
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
//~| ERROR associated constant in `impl` without body
const D: _ = 42;
//~^ ERROR the type placeholder `_` is not allowed within types on item signatures
}
Loading
0