Check the well-formed-ness of type aliases.
Currently, these compile:
struct Foo<T: Copy>(T);
type X = Foo<String>;
type Y = <() as Iterator>::Item;
Using them does produce an error at the use site, but not in the definition.
If we do check WF for type aliases, can we also easily check if there's bounds not used to satisfy well-formed-ness rules? Because those bounds we current ignore where the type alias is used. cc @nikomatsakis @arielb1
Eduard-Mihai Burtescu at 2017-08-24 20:44:07
@eddyb not super easily
Niko Matsakis at 2017-08-24 22:37:51
For the record, it's actually easy. This is what it looks like on the current compiler:
let user_predicates = fcx.param_env.caller_bounds; let wf_predicates = ty::wf::obligations( &fcx.infcx, fcx.param_env, fcx.body_id, item_ty, item.span, ).into_iter().flatten().map(|o| o.predicate).collect(); let wf_predicates = traits::elaborate_predicates(fcx.tcx, wf_predicates); let wf_param_env = ty::ParamEnv { caller_bounds: fcx.tcx.mk_predicates(wf_predicates), reveal: fcx.param_env.reveal, }; fcx.register_predicates(user_predicates.iter().map(|&predicate| { let code = ObligationCauseCode::MiscObligation; let cause = traits::ObligationCause::new(item.span, fcx.body_id, code); traits::Obligation::new(cause, wf_param_env, predicate) }));Of course, proper reporting is more work, but it's a shame we didn't figure out we can do these checks, in the first place, last year, instead of so close to the edition release (https://github.com/rust-lang/rust/issues/49441#issuecomment-414470068).
Eduard-Mihai Burtescu at 2018-09-09 18:06:30