Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend builtin/auto trait args with error when they have >1 argument #117645

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2389,12 +2389,21 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
)
});

let obligation = Obligation::new(
self.tcx(),
cause.clone(),
param_env,
ty::TraitRef::new(self.tcx(), trait_def_id, [normalized_ty]),
);
let tcx = self.tcx();
let trait_ref = if tcx.generics_of(trait_def_id).params.len() == 1 {
ty::TraitRef::new(tcx, trait_def_id, [normalized_ty])
} else {
// 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
})
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/auto-traits/has-arguments.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 11 additions & 0 deletions tests/ui/auto-traits/has-arguments.stderr
Original file line number Diff line number Diff line change
@@ -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