Skip to content

Commit 7eb65df

Browse files
committed
Auto merge of #64108 - estebank:issue-36836, r=Centril
Do not complain about unconstrained params when Self is Ty Error Fix #36836.
2 parents a6624ed + c44ffaf commit 7eb65df

File tree

4 files changed

+42
-11
lines changed

4 files changed

+42
-11
lines changed

src/librustc_typeck/constrained_generic_params.rs

+8-10
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ impl From<ty::ParamConst> for Parameter {
2020
}
2121

2222
/// Returns the set of parameters constrained by the impl header.
23-
pub fn parameters_for_impl<'tcx>(impl_self_ty: Ty<'tcx>,
24-
impl_trait_ref: Option<ty::TraitRef<'tcx>>)
25-
-> FxHashSet<Parameter>
26-
{
23+
pub fn parameters_for_impl<'tcx>(
24+
impl_self_ty: Ty<'tcx>,
25+
impl_trait_ref: Option<ty::TraitRef<'tcx>>,
26+
) -> FxHashSet<Parameter> {
2727
let vec = match impl_trait_ref {
2828
Some(tr) => parameters_for(&tr, false),
2929
None => parameters_for(&impl_self_ty, false),
@@ -36,12 +36,10 @@ pub fn parameters_for_impl<'tcx>(impl_self_ty: Ty<'tcx>,
3636
/// uniquely determined by `t` (see RFC 447). If it is true, return the list
3737
/// of parameters whose values are needed in order to constrain `ty` - these
3838
/// differ, with the latter being a superset, in the presence of projections.
39-
pub fn parameters_for<'tcx, T>(t: &T,
40-
include_nonconstraining: bool)
41-
-> Vec<Parameter>
42-
where T: TypeFoldable<'tcx>
43-
{
44-
39+
pub fn parameters_for<'tcx>(
40+
t: &impl TypeFoldable<'tcx>,
41+
include_nonconstraining: bool,
42+
) -> Vec<Parameter> {
4543
let mut collector = ParameterCollector {
4644
parameters: vec![],
4745
include_nonconstraining,

src/librustc_typeck/impl_wf_check.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::constrained_generic_params as cgp;
1212
use rustc::hir;
1313
use rustc::hir::itemlikevisit::ItemLikeVisitor;
1414
use rustc::hir::def_id::DefId;
15-
use rustc::ty::{self, TyCtxt};
15+
use rustc::ty::{self, TyCtxt, TypeFoldable};
1616
use rustc::ty::query::Providers;
1717
use rustc::util::nodemap::{FxHashMap, FxHashSet};
1818
use std::collections::hash_map::Entry::{Occupied, Vacant};
@@ -99,6 +99,15 @@ fn enforce_impl_params_are_constrained(
9999
) {
100100
// Every lifetime used in an associated type must be constrained.
101101
let impl_self_ty = tcx.type_of(impl_def_id);
102+
if impl_self_ty.references_error() {
103+
// Don't complain about unconstrained type params when self ty isn't known due to errors.
104+
// (#36836)
105+
tcx.sess.delay_span_bug(
106+
tcx.def_span(impl_def_id),
107+
"potentially unconstrained type parameters weren't evaluated",
108+
);
109+
return;
110+
}
102111
let impl_generics = tcx.generics_of(impl_def_id);
103112
let impl_predicates = tcx.predicates_of(impl_def_id);
104113
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id);

src/test/ui/issues/issue-36836.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Previously, in addition to the real cause of the problem as seen below,
2+
// the compiler would tell the user:
3+
//
4+
// ```
5+
// error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or
6+
// predicates
7+
// ```
8+
//
9+
// With this test, we check that only the relevant error is emitted.
10+
11+
trait Foo {}
12+
13+
impl<T> Foo for Bar<T> {} //~ ERROR cannot find type `Bar` in this scope
14+
15+
fn main() {}

src/test/ui/issues/issue-36836.stderr

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

0 commit comments

Comments
 (0)