Rollup merge of #117645 - compiler-errors:auto-trait-subst, r=petrochenkov
Extend builtin/auto trait args with error when they have >1 argument Reuse `extend_with_error` to add error args to any auto trait (or built-in trait like `Copy` that is defined incorrectly) that has additional non-`Self` args. Fixes #117628
This commit is contained in:
commit
4cc549811f
@ -2389,12 +2389,21 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
|
|||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let obligation = Obligation::new(
|
let tcx = self.tcx();
|
||||||
self.tcx(),
|
let trait_ref = if tcx.generics_of(trait_def_id).params.len() == 1 {
|
||||||
cause.clone(),
|
ty::TraitRef::new(tcx, trait_def_id, [normalized_ty])
|
||||||
param_env,
|
} else {
|
||||||
ty::TraitRef::new(self.tcx(), trait_def_id, [normalized_ty]),
|
// If this is an ill-formed auto/built-in trait, then synthesize
|
||||||
|
// new error args for the missing generics.
|
||||||
|
let err_args = ty::GenericArgs::extend_with_error(
|
||||||
|
tcx,
|
||||||
|
trait_def_id,
|
||||||
|
&[normalized_ty.into()],
|
||||||
);
|
);
|
||||||
|
ty::TraitRef::new(tcx, trait_def_id, err_args)
|
||||||
|
};
|
||||||
|
|
||||||
|
let obligation = Obligation::new(self.tcx(), cause.clone(), param_env, trait_ref);
|
||||||
obligations.push(obligation);
|
obligations.push(obligation);
|
||||||
obligations
|
obligations
|
||||||
})
|
})
|
||||||
|
10
tests/ui/auto-traits/has-arguments.rs
Normal file
10
tests/ui/auto-traits/has-arguments.rs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#![feature(auto_traits)]
|
||||||
|
|
||||||
|
auto trait Trait1<'outer> {}
|
||||||
|
//~^ ERROR auto traits cannot have generic parameters
|
||||||
|
|
||||||
|
fn f<'a>(x: impl Trait1<'a>) {}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
f("");
|
||||||
|
}
|
11
tests/ui/auto-traits/has-arguments.stderr
Normal file
11
tests/ui/auto-traits/has-arguments.stderr
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
error[E0567]: auto traits cannot have generic parameters
|
||||||
|
--> $DIR/has-arguments.rs:3:18
|
||||||
|
|
|
||||||
|
LL | auto trait Trait1<'outer> {}
|
||||||
|
| ------^^^^^^^^ help: remove the parameters
|
||||||
|
| |
|
||||||
|
| auto trait cannot have generic parameters
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0567`.
|
Loading…
x
Reference in New Issue
Block a user