Skip to content

Commit

Permalink
Rollup merge of rust-lang#105230 - cjgillot:issue-104312, r=petrochenkov
Browse files Browse the repository at this point in the history
Skip recording resolution for duplicated generic params.

Turns out the fix was simpler than I thought.

Fixes rust-lang#104312
  • Loading branch information
matthiaskrgr authored Dec 5, 2022
2 parents 66a4cb5 + b151410 commit 4ebbb20
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2360,8 +2360,8 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
if let GenericParamKind::Lifetime = param.kind {
// Record lifetime res, so lowering knows there is something fishy.
self.record_lifetime_param(param.id, LifetimeRes::Error);
continue;
}
continue;
}
Entry::Vacant(entry) => {
entry.insert(param.ident.span);
Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/const-generics/defaults/self-referential.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
trait Foo<const M: u8, const M: u8 = M> {}
//~^ ERROR the name `M` is already used for a generic parameter in this item's generic parameters
impl Foo<2> for () {}
fn main() {}
11 changes: 11 additions & 0 deletions src/test/ui/const-generics/defaults/self-referential.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0403]: the name `M` is already used for a generic parameter in this item's generic parameters
--> $DIR/self-referential.rs:1:30
|
LL | trait Foo<const M: u8, const M: u8 = M> {}
| - ^ already used
| |
| first use of `M`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0403`.
4 changes: 2 additions & 2 deletions src/test/ui/duplicate/duplicate-type-parameter.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ LL | impl<T,T> Qux<T,T> for Option<T> {}
| first use of `T`

error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
--> $DIR/duplicate-type-parameter.rs:24:6
--> $DIR/duplicate-type-parameter.rs:24:8
|
LL | impl<T,T> Qux<T,T> for Option<T> {}
| ^ unconstrained type parameter
| ^ unconstrained type parameter

error: aborting due to 8 previous errors

Expand Down

0 comments on commit 4ebbb20

Please sign in to comment.