Skip to content

Commit a9174cf

Browse files
jackh726Mark-Simulacrum
authored andcommitted
Don't treat unnormalized function arguments as well-formed
1 parent 7f56b9a commit a9174cf

File tree

8 files changed

+52
-46
lines changed

8 files changed

+52
-46
lines changed

compiler/rustc_borrowck/src/type_check/free_region_relations.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,6 @@ impl UniversalRegionRelationsBuilder<'cx, 'tcx> {
258258
debug!("build: input_or_output={:?}", ty);
259259
// We add implied bounds from both the unnormalized and normalized ty
260260
// See issue #87748
261-
let constraints_implied_1 = self.add_implied_bounds(ty);
262261
let TypeOpOutput { output: norm_ty, constraints: constraints1, .. } = self
263262
.param_env
264263
.and(type_op::normalize::Normalize::new(ty))
@@ -286,10 +285,9 @@ impl UniversalRegionRelationsBuilder<'cx, 'tcx> {
286285
// }
287286
// ```
288287
// Both &Self::Bar and &() are WF
289-
let constraints_implied_2 =
290-
if ty != norm_ty { self.add_implied_bounds(norm_ty) } else { None };
288+
let constraints_implied = self.add_implied_bounds(norm_ty);
291289
normalized_inputs_and_output.push(norm_ty);
292-
constraints1.into_iter().chain(constraints_implied_1).chain(constraints_implied_2)
290+
constraints1.into_iter().chain(constraints_implied)
293291
})
294292
.collect();
295293

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
@@ -960,11 +960,6 @@ fn check_fn_or_method<'fcx, 'tcx>(
960960
) {
961961
let sig = fcx.tcx.liberate_late_bound_regions(def_id, sig);
962962

963-
// Unnormalized types in signature are WF too
964-
implied_bounds.extend(sig.inputs());
965-
// FIXME(#27579) return types should not be implied bounds
966-
implied_bounds.insert(sig.output());
967-
968963
// Normalize the input and output types one at a time, using a different
969964
// `WellFormedLoc` for each. We cannot call `normalize_associated_types`
970965
// on the entire `FnSig`, since this would use the same `WellFormedLoc`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: lifetime may not live long enough
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+
| -- -- lifetime `'b` defined here
6+
| |
7+
| lifetime `'a` defined here
8+
LL | s
9+
| ^ returning this value requires that `'b` must outlive `'a`
10+
|
11+
= help: consider adding the following bound: `'b: 'a`
12+
13+
error: aborting due to previous error
14+
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)