Do not complain about unconstrained params when Self is Ty Error

This commit is contained in:
Esteban Küber 2019-09-02 18:03:54 -07:00
parent dfd43f0fdd
commit 37f5cc2239
4 changed files with 26 additions and 10 deletions

View File

@ -20,10 +20,10 @@ impl From<ty::ParamConst> for Parameter {
}
/// Returns the set of parameters constrained by the impl header.
pub fn parameters_for_impl<'tcx>(impl_self_ty: Ty<'tcx>,
impl_trait_ref: Option<ty::TraitRef<'tcx>>)
-> FxHashSet<Parameter>
{
pub fn parameters_for_impl<'tcx>(
impl_self_ty: Ty<'tcx>,
impl_trait_ref: Option<ty::TraitRef<'tcx>>,
) -> FxHashSet<Parameter> {
let vec = match impl_trait_ref {
Some(tr) => parameters_for(&tr, false),
None => parameters_for(&impl_self_ty, false),
@ -36,12 +36,10 @@ pub fn parameters_for_impl<'tcx>(impl_self_ty: Ty<'tcx>,
/// uniquely determined by `t` (see RFC 447). If it is true, return the list
/// of parameters whose values are needed in order to constrain `ty` - these
/// differ, with the latter being a superset, in the presence of projections.
pub fn parameters_for<'tcx, T>(t: &T,
include_nonconstraining: bool)
-> Vec<Parameter>
where T: TypeFoldable<'tcx>
{
pub fn parameters_for<'tcx, T: TypeFoldable<'tcx>>(
t: &T,
include_nonconstraining: bool,
) -> Vec<Parameter> {
let mut collector = ParameterCollector {
parameters: vec![],
include_nonconstraining,

View File

@ -99,6 +99,10 @@ fn enforce_impl_params_are_constrained(
) {
// Every lifetime used in an associated type must be constrained.
let impl_self_ty = tcx.type_of(impl_def_id);
if impl_self_ty.sty == ty::Error {
// Don't complain about unconstrained type params when self ty doesn't exist. (#36836)
return;
}
let impl_generics = tcx.generics_of(impl_def_id);
let impl_predicates = tcx.predicates_of(impl_def_id);
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id);

View File

@ -0,0 +1,5 @@
trait Foo {}
impl<T> Foo for Bar<T> {} //~ ERROR cannot find type `Bar` in this scope
fn main() {}

View File

@ -0,0 +1,9 @@
error[E0412]: cannot find type `Bar` in this scope
--> $DIR/issue-36836.rs:3:17
|
LL | impl<T> Foo for Bar<T> {}
| ^^^ not found in this scope
error: aborting due to previous error
For more information about this error, try `rustc --explain E0412`.