Skip to content

Commit 6e7cf2e

Browse files
authored
Rollup merge of rust-lang#91243 - jackh726:issue-91068, r=nikomatsakis
Don't treat unnormalized function arguments as well-formed Partial revert of rust-lang#88312 r? ``@pnkfelix`` cc ``@nikomatsakis``
2 parents 4c94896 + 692e96c commit 6e7cf2e

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
@@ -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
@@ -264,14 +264,9 @@ fn compare_predicate_entailment<'tcx>(
264264
// First liberate late bound regions and subst placeholders
265265
let trait_sig = tcx.liberate_late_bound_regions(impl_m.def_id, tcx.fn_sig(trait_m.def_id));
266266
let trait_sig = trait_sig.subst(tcx, trait_to_placeholder_substs);
267-
// Next, add all inputs and output as well-formed tys. Importantly,
268-
// we have to do this before normalization, since the normalized ty may
269-
// not contain the input parameters. See issue #87748.
270-
wf_tys.extend(trait_sig.inputs_and_output.iter());
271267
let trait_sig =
272268
inh.normalize_associated_types_in(impl_m_span, impl_m_hir_id, param_env, trait_sig);
273-
// Also add the resulting inputs and output as well-formed.
274-
// This probably isn't strictly necessary.
269+
// Add the resulting inputs and output as well-formed.
275270
wf_tys.extend(trait_sig.inputs_and_output.iter());
276271
let trait_fty = tcx.mk_fn_ptr(ty::Binder::dummy(trait_sig));
277272

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
@@ -1334,11 +1334,6 @@ fn check_fn_or_method<'fcx, 'tcx>(
13341334
) {
13351335
let sig = fcx.tcx.liberate_late_bound_regions(def_id, sig);
13361336

1337-
// Unnormalized types in signature are WF too
1338-
implied_bounds.extend(sig.inputs());
1339-
// FIXME(#27579) return types should not be implied bounds
1340-
implied_bounds.insert(sig.output());
1341-
13421337
// Normalize the input and output types one at a time, using a different
13431338
// `WellFormedLoc` for each. We cannot call `normalize_associated_types`
13441339
// 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)