Skip to content

Commit 946a1da

Browse files
committed
Skip auto traits with generic parameters when linting auto trait impls
1 parent 6f308b8 commit 946a1da

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

compiler/rustc_hir_analysis/src/coherence/orphan.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub(crate) fn orphan_check_impl(
2727
trait_ref.error_reported()?;
2828

2929
let ret = do_orphan_check_impl(tcx, trait_ref, impl_def_id);
30-
if tcx.trait_is_auto(trait_ref.def_id) {
30+
if tcx.trait_is_auto(trait_ref.def_id) && trait_ref.args.len() == 1 {
3131
lint_auto_trait_impl(tcx, trait_ref, impl_def_id);
3232
}
3333

@@ -452,7 +452,6 @@ fn lint_auto_trait_impl<'tcx>(
452452
trait_ref: ty::TraitRef<'tcx>,
453453
impl_def_id: LocalDefId,
454454
) {
455-
assert_eq!(trait_ref.args.len(), 1);
456455
let self_ty = trait_ref.self_ty();
457456
let (self_type_did, args) = match self_ty.kind() {
458457
ty::Adt(def, args) => (def.did(), args),

tests/ui/auto-traits/issue-117789.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#![deny(suspicious_auto_trait_impls)]
2+
3+
auto trait Trait<P> {} //~ ERROR auto traits cannot have generic parameters
4+
//~^ ERROR auto traits are experimental and possibly buggy
5+
impl<P> Trait<P> for () {}
6+
7+
fn main() {}
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0567]: auto traits cannot have generic parameters
2+
--> $DIR/issue-117789.rs:3:17
3+
|
4+
LL | auto trait Trait<P> {}
5+
| -----^^^ help: remove the parameters
6+
| |
7+
| auto trait cannot have generic parameters
8+
9+
error[E0658]: auto traits are experimental and possibly buggy
10+
--> $DIR/issue-117789.rs:3:1
11+
|
12+
LL | auto trait Trait<P> {}
13+
| ^^^^^^^^^^^^^^^^^^^^^^
14+
|
15+
= note: see issue #13231 <https://github.com/rust-lang/rust/issues/13231> for more information
16+
= help: add `#![feature(auto_traits)]` to the crate attributes to enable
17+
18+
error: aborting due to 2 previous errors
19+
20+
Some errors have detailed explanations: E0567, E0658.
21+
For more information about an error, try `rustc --explain E0567`.

0 commit comments

Comments
 (0)