mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-23 04:57:37 +00:00
Suppress unused type parameter error when type has error field
This commit is contained in:
parent
7580534c3a
commit
03652157f9
@ -182,6 +182,21 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
|
|||||||
pat_util::arm_contains_ref_binding(arm)
|
pat_util::arm_contains_ref_binding(arm)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn has_error_field(self, ty: Ty<'tcx>) -> bool {
|
||||||
|
match ty.sty {
|
||||||
|
ty::TyStruct(def, substs) | ty::TyEnum(def, substs) => {
|
||||||
|
for field in def.all_fields() {
|
||||||
|
let field_ty = field.ty(self, substs);
|
||||||
|
if let TyError = field_ty.sty {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => ()
|
||||||
|
}
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns the type of element at index `i` in tuple or tuple-like type `t`.
|
/// Returns the type of element at index `i` in tuple or tuple-like type `t`.
|
||||||
/// For an enum `t`, `variant` is None only if `t` is a univariant enum.
|
/// For an enum `t`, `variant` is None only if `t` is a univariant enum.
|
||||||
pub fn positional_element_ty(self,
|
pub fn positional_element_ty(self,
|
||||||
|
@ -454,6 +454,11 @@ impl<'ccx, 'gcx> CheckTypeWellFormedVisitor<'ccx, 'gcx> {
|
|||||||
item: &hir::Item,
|
item: &hir::Item,
|
||||||
ast_generics: &hir::Generics)
|
ast_generics: &hir::Generics)
|
||||||
{
|
{
|
||||||
|
let ty = self.tcx().node_id_to_type(item.id);
|
||||||
|
if self.tcx().has_error_field(ty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let item_def_id = self.tcx().map.local_def_id(item.id);
|
let item_def_id = self.tcx().map.local_def_id(item.id);
|
||||||
let ty_predicates = self.tcx().lookup_predicates(item_def_id);
|
let ty_predicates = self.tcx().lookup_predicates(item_def_id);
|
||||||
let variances = self.tcx().item_variances(item_def_id);
|
let variances = self.tcx().item_variances(item_def_id);
|
||||||
|
19
src/test/compile-fail/issue-35075.rs
Normal file
19
src/test/compile-fail/issue-35075.rs
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||||
|
// file at the top-level directory of this distribution and at
|
||||||
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
|
//
|
||||||
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
|
// option. This file may not be copied, modified, or distributed
|
||||||
|
// except according to those terms.
|
||||||
|
|
||||||
|
struct Bar<T> {
|
||||||
|
inner: Foo<T> //~ ERROR type name `Foo` is undefined or not in scope
|
||||||
|
}
|
||||||
|
|
||||||
|
enum Baz<T> {
|
||||||
|
Foo(Foo<T>) //~ ERROR type name `Foo` is undefined or not in scope
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
@ -13,9 +13,8 @@
|
|||||||
// scope (in this case, the enum).
|
// scope (in this case, the enum).
|
||||||
|
|
||||||
trait TraitA<A> {
|
trait TraitA<A> {
|
||||||
fn outer(self) {
|
fn outer(&self) {
|
||||||
enum Foo<B> {
|
enum Foo<B> {
|
||||||
//~^ ERROR parameter `B` is never used
|
|
||||||
Variance(A)
|
Variance(A)
|
||||||
//~^ ERROR can't use type parameters from outer function
|
//~^ ERROR can't use type parameters from outer function
|
||||||
}
|
}
|
||||||
@ -23,23 +22,21 @@ trait TraitA<A> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
trait TraitB<A> {
|
trait TraitB<A> {
|
||||||
fn outer(self) {
|
fn outer(&self) {
|
||||||
struct Foo<B>(A);
|
struct Foo<B>(A);
|
||||||
//~^ ERROR can't use type parameters from outer function
|
//~^ ERROR can't use type parameters from outer function
|
||||||
//~^^ ERROR parameter `B` is never used
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trait TraitC<A> {
|
trait TraitC<A> {
|
||||||
fn outer(self) {
|
fn outer(&self) {
|
||||||
struct Foo<B> { a: A }
|
struct Foo<B> { a: A }
|
||||||
//~^ ERROR can't use type parameters from outer function
|
//~^ ERROR can't use type parameters from outer function
|
||||||
//~^^ ERROR parameter `B` is never used
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trait TraitD<A> {
|
trait TraitD<A> {
|
||||||
fn outer(self) {
|
fn outer(&self) {
|
||||||
fn foo<B>(a: A) { }
|
fn foo<B>(a: A) { }
|
||||||
//~^ ERROR can't use type parameters from outer function
|
//~^ ERROR can't use type parameters from outer function
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user