Rollup merge of #117645 - compiler-errors:auto-trait-subst, r=petroch… · rust-lang/rust@4cc5498 (original) (raw)

File tree

3 files changed

lines changed

3 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -2389,12 +2389,21 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
2389 2389 )
2390 2390 });
2391 2391
2392 -let obligation = Obligation::new(
2393 -self.tcx(),
2394 - cause.clone(),
2395 - param_env,
2396 - ty::TraitRef::new(self.tcx(), trait_def_id, [normalized_ty]),
2397 -);
2392 +let tcx = self.tcx();
2393 +let trait_ref = if tcx.generics_of(trait_def_id).params.len() == 1 {
2394 + ty::TraitRef::new(tcx, trait_def_id, [normalized_ty])
2395 +} else {
2396 +// If this is an ill-formed auto/built-in trait, then synthesize
2397 +// new error args for the missing generics.
2398 +let err_args = ty::GenericArgs::extend_with_error(
2399 + tcx,
2400 + trait_def_id,
2401 +&[normalized_ty.into()],
2402 +);
2403 + ty::TraitRef::new(tcx, trait_def_id, err_args)
2404 +};
2405 +
2406 +let obligation = Obligation::new(self.tcx(), cause.clone(), param_env, trait_ref);
2398 2407 obligations.push(obligation);
2399 2408 obligations
2400 2409 })
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
1 +#![feature(auto_traits)]
2 +
3 +auto trait Trait1<'outer> {}
4 +//~^ ERROR auto traits cannot have generic parameters
5 +
6 +fn f<'a>(x: impl Trait1<'a>) {}
7 +
8 +fn main() {
9 +f("");
10 +}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
1 +error[E0567]: auto traits cannot have generic parameters
2 + --> $DIR/has-arguments.rs:3:18
3 + |
4 +LL | auto trait Trait1<'outer> {}
5 + | ------^^^^^^^^ help: remove the parameters
6 + |
7 + | auto trait cannot have generic parameters
8 +
9 +error: aborting due to previous error
10 +
11 +For more information about this error, try `rustc --explain E0567`.