Skip to content

Commit

Permalink
Rollup merge of rust-lang#64108 - estebank:issue-36836, r=Centril
Browse files Browse the repository at this point in the history
Do not complain about unconstrained params when Self is Ty Error

Fix rust-lang#36836.
  • Loading branch information
Centril committed Sep 5, 2019
2 parents ca88a5b + c44ffaf commit 63e51fc
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 11 deletions.
18 changes: 8 additions & 10 deletions src/librustc_typeck/constrained_generic_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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: &impl TypeFoldable<'tcx>,
include_nonconstraining: bool,
) -> Vec<Parameter> {
let mut collector = ParameterCollector {
parameters: vec![],
include_nonconstraining,
Expand Down
11 changes: 10 additions & 1 deletion src/librustc_typeck/impl_wf_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::constrained_generic_params as cgp;
use rustc::hir;
use rustc::hir::itemlikevisit::ItemLikeVisitor;
use rustc::hir::def_id::DefId;
use rustc::ty::{self, TyCtxt};
use rustc::ty::{self, TyCtxt, TypeFoldable};
use rustc::ty::query::Providers;
use rustc::util::nodemap::{FxHashMap, FxHashSet};
use std::collections::hash_map::Entry::{Occupied, Vacant};
Expand Down Expand Up @@ -99,6 +99,15 @@ 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.references_error() {
// Don't complain about unconstrained type params when self ty isn't known due to errors.
// (#36836)
tcx.sess.delay_span_bug(
tcx.def_span(impl_def_id),
"potentially unconstrained type parameters weren't evaluated",
);
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);
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/issues/issue-36836.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Previously, in addition to the real cause of the problem as seen below,
// the compiler would tell the user:
//
// ```
// error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or
// predicates
// ```
//
// With this test, we check that only the relevant error is emitted.

trait Foo {}

impl<T> Foo for Bar<T> {} //~ ERROR cannot find type `Bar` in this scope

fn main() {}
9 changes: 9 additions & 0 deletions src/test/ui/issues/issue-36836.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
error[E0412]: cannot find type `Bar` in this scope
--> $DIR/issue-36836.rs:13: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`.

0 comments on commit 63e51fc

Please sign in to comment.