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

Cleanup substitutions and treatment of generics around traits in a number of ways #5802

Closed

Conversation

nikomatsakis
Copy link
Contributor

Cleanup substitutions and treatment of generics around traits in a number of ways

  • In a TraitRef, use the self type consistently to refer to the Self type:
    • trait ref in impl Trait<A,B,C> for S has a self type of S.
    • trait ref in A:Trait has the self type A
    • trait ref associated with a trait decl has self type Self
    • trait ref associated with a supertype has self type Self
    • trait ref in an object type @Trait has no self type
  • Rewrite each_bound_traits_and_supertraits to perform
    substitutions as it goes, and thus yield a series of trait refs
    that are always in the same 'namespace' as the type parameter
    bound given as input. Before, we left this to the caller, but
    this doesn't work because the caller lacks adequare information
    to perform the type substitutions correctly.
  • For provided methods, substitute the generics involved in the provided
    method correctly.
  • Introduce TypeParameterDef, which tracks the bounds declared on a type
    parameter and brings them together with the def_id and (in the future)
    other information (maybe even the parameter's name!).
  • Introduce Subst trait, which helps to cleanup a lot of the
    repetitive code involved with doing type substitution.
  • Introduce Repr trait, which makes debug printouts far more convenient.

Fixes #4183. Needed for #5656.

r? @catamorphism

…mber of ways.

- In a TraitRef, use the self type consistently to refer to the Self type:
  - trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
  - trait ref in `A:Trait` has the self type `A`
  - trait ref associated with a trait decl has self type `Self`
  - trait ref associated with a supertype has self type `Self`
  - trait ref in an object type `@Trait` has no self type

- Rewrite `each_bound_traits_and_supertraits` to perform
  substitutions as it goes, and thus yield a series of trait refs
  that are always in the same 'namespace' as the type parameter
  bound given as input.  Before, we left this to the caller, but
  this doesn't work because the caller lacks adequare information
  to perform the type substitutions correctly.

- For provided methods, substitute the generics involved in the provided
  method correctly.

- Introduce TypeParameterDef, which tracks the bounds declared on a type
  parameter and brings them together with the def_id and (in the future)
  other information (maybe even the parameter's name!).

- Introduce Subst trait, which helps to cleanup a lot of the
  repetitive code involved with doing type substitution.

- Introduce Repr trait, which makes debug printouts far more convenient.

Fixes rust-lang#4183.  Needed for rust-lang#5656.
@nikomatsakis
Copy link
Contributor Author

@catamorphism btw when we discuss I'll explain the logic of how the substitution works...

bors added a commit that referenced this pull request Apr 10, 2013
…komatsakis

Cleanup substitutions and treatment of generics around traits in a number of ways

- In a TraitRef, use the self type consistently to refer to the Self type:
  - trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
  - trait ref in `A:Trait` has the self type `A`
  - trait ref associated with a trait decl has self type `Self`
  - trait ref associated with a supertype has self type `Self`
  - trait ref in an object type `@Trait` has no self type

- Rewrite `each_bound_traits_and_supertraits` to perform
  substitutions as it goes, and thus yield a series of trait refs
  that are always in the same 'namespace' as the type parameter
  bound given as input.  Before, we left this to the caller, but
  this doesn't work because the caller lacks adequare information
  to perform the type substitutions correctly.

- For provided methods, substitute the generics involved in the provided
  method correctly.

- Introduce TypeParameterDef, which tracks the bounds declared on a type
  parameter and brings them together with the def_id and (in the future)
  other information (maybe even the parameter's name!).

- Introduce Subst trait, which helps to cleanup a lot of the
  repetitive code involved with doing type substitution.

- Introduce Repr trait, which makes debug printouts far more convenient.

Fixes #4183.  Needed for #5656.

r? @catamorphism
@bors bors closed this Apr 10, 2013
@nikomatsakis nikomatsakis deleted the issue-4183-trait-substs branch March 30, 2016 16:15
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jul 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants