Skip to content

Commit eeaa215

Browse files
committed
Don't treat unnormalized function arguments as well-formed
1 parent eee8b9c commit eeaa215

File tree

7 files changed

+38
-46
lines changed

7 files changed

+38
-46
lines changed

compiler/rustc_borrowck/src/type_check/free_region_relations.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ impl UniversalRegionRelationsBuilder<'cx, 'tcx> {
256256
debug!("build: input_or_output={:?}", ty);
257257
// We add implied bounds from both the unnormalized and normalized ty
258258
// See issue #87748
259-
let constraints_implied_1 = self.add_implied_bounds(ty);
260259
let TypeOpOutput { output: norm_ty, constraints: constraints1, .. } = self
261260
.param_env
262261
.and(type_op::normalize::Normalize::new(ty))
@@ -284,10 +283,9 @@ impl UniversalRegionRelationsBuilder<'cx, 'tcx> {
284283
// }
285284
// ```
286285
// Both &Self::Bar and &() are WF
287-
let constraints_implied_2 =
288-
if ty != norm_ty { self.add_implied_bounds(norm_ty) } else { None };
286+
let constraints_implied = self.add_implied_bounds(norm_ty);
289287
normalized_inputs_and_output.push(norm_ty);
290-
constraints1.into_iter().chain(constraints_implied_1).chain(constraints_implied_2)
288+
constraints1.into_iter().chain(constraints_implied)
291289
})
292290
.collect();
293291

compiler/rustc_typeck/src/check/compare_method.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,9 @@ fn compare_predicate_entailment<'tcx>(
266266
// First liberate late bound regions and subst placeholders
267267
let trait_sig = tcx.liberate_late_bound_regions(impl_m.def_id, tcx.fn_sig(trait_m.def_id));
268268
let trait_sig = trait_sig.subst(tcx, trait_to_placeholder_substs);
269-
// Next, add all inputs and output as well-formed tys. Importantly,
270-
// we have to do this before normalization, since the normalized ty may
271-
// not contain the input parameters. See issue #87748.
272-
wf_tys.extend(trait_sig.inputs_and_output.iter());
273269
let trait_sig =
274270
inh.normalize_associated_types_in(impl_m_span, impl_m_hir_id, param_env, trait_sig);
275-
// Also add the resulting inputs and output as well-formed.
276-
// This probably isn't strictly necessary.
271+
// Add the resulting inputs and output as well-formed.
277272
wf_tys.extend(trait_sig.inputs_and_output.iter());
278273
let trait_fty = tcx.mk_fn_ptr(ty::Binder::dummy(trait_sig));
279274

compiler/rustc_typeck/src/check/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ fn typeck_with_fallback<'tcx>(
391391
let mut wf_tys = FxHashSet::default();
392392
// Compute the fty from point of view of inside the fn.
393393
let fn_sig = tcx.liberate_late_bound_regions(def_id.to_def_id(), fn_sig);
394-
wf_tys.extend(fn_sig.inputs_and_output.iter());
395394
let fn_sig = inh.normalize_associated_types_in(
396395
body.value.span,
397396
body_id.hir_id,

compiler/rustc_typeck/src/check/wfcheck.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1322,11 +1322,6 @@ fn check_fn_or_method<'fcx, 'tcx>(
13221322
) {
13231323
let sig = fcx.tcx.liberate_late_bound_regions(def_id, sig);
13241324

1325-
// Unnormalized types in signature are WF too
1326-
implied_bounds.extend(sig.inputs());
1327-
// FIXME(#27579) return types should not be implied bounds
1328-
implied_bounds.insert(sig.output());
1329-
13301325
// Normalize the input and output types one at a time, using a different
13311326
// `WellFormedLoc` for each. We cannot call `normalize_associated_types`
13321327
// on the entire `FnSig`, since this would use the same `WellFormedLoc`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// check-fail
2+
// See issue #91068. Types in the substs of an associated type can't be implied
3+
// to be WF, since they don't actually have to be constructed.
4+
5+
trait Trait {
6+
type Type;
7+
}
8+
9+
impl<T> Trait for T {
10+
type Type = ();
11+
}
12+
13+
fn f<'a, 'b>(s: &'b str, _: <&'a &'b () as Trait>::Type) -> &'a str {
14+
s //~ ERROR lifetime mismatch [E0623]
15+
}
16+
17+
fn main() {
18+
let x = String::from("Hello World!");
19+
let y = f(&x, ());
20+
drop(x);
21+
println!("{}", y);
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0623]: lifetime mismatch
2+
--> $DIR/implied-bounds-unnorm-associated-type.rs:14:5
3+
|
4+
LL | fn f<'a, 'b>(s: &'b str, _: <&'a &'b () as Trait>::Type) -> &'a str {
5+
| ------- ----------
6+
| |
7+
| these two types are declared with different lifetimes...
8+
LL | s
9+
| ^ ...but data from `s` flows here
10+
11+
error: aborting due to previous error
12+
13+
For more information about this error, try `rustc --explain E0623`.

src/test/ui/generic-associated-types/issue-87748.rs

-30
This file was deleted.

0 commit comments

Comments
 (0)