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

librustc: Check structure constructors against their types. #15938

Conversation

pcwalton
Copy link
Contributor

This breaks code like:

struct Point<T> {
    x: T,
    y: T,
}

let pt = Point::<bool> {
    x: 1,
    y: 2,
};

Change this code to not contain a type error. For example:

let pt = Point::<int> {
    x: 1,
    y: 2,
};

Closes #15875.

[breaking-change]

r? @huonw

/// parameters.
///
/// If the path has no type parameters and the corresponding type has no
/// type parameters, `None` is returned. If the path has type parameters and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First sentence here, I assume you mean "and the corresponding type has no type parameters".

@pcwalton
Copy link
Contributor Author

@kballard Fixed.

path.span,
format!("structure constructor specifies a \
structure of type `{}`, but this \
structure has type `{}`: {}",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we use the full word "structure" in other errors, instead of "struct"? Similarly, do we have precedent for the phrase "structure constructor"? My inclination is to call it a "struct literal".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we use "structure" in other errors.

@pcwalton
Copy link
Contributor Author

I realized this doesn't handle some edge cases. Going to rework a bit.

@lilyball
Copy link
Contributor

Just yesterday I was wondering if Point::<int> { ... } actually worked. So I'm happy to see you fixing this :) But I'll let someone else review for correctness, I don't know this section of the code.

@huonw
Copy link
Member

huonw commented Jul 24, 2014

I assume this closes #9620 too.

@pcwalton
Copy link
Contributor Author

re-r? @huonw

x: 3i,
y: 4i,
};

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Travis says this line has trailing whitespace.

This breaks code like:

    struct Point<T> {
        x: T,
        y: T,
    }

    let pt = Point::<bool> {
        x: 1,
        y: 2,
    };

Change this code to not contain a type error. For example:

    let pt = Point::<int> {
        x: 1,
        y: 2,
    };

Closes rust-lang#9620.
Closes rust-lang#15875.

[breaking-change]
@pcwalton
Copy link
Contributor Author

@huonw Fixed.

matthiaskrgr pushed a commit to matthiaskrgr/rust that referenced this pull request Mar 10, 2024
…over, r=Veykril

feat: add hover display for trait assoc items

This PR enable preview assoc items when hover on `trait`

![image](https://github.com/rust-lang/rust-analyzer/assets/71162630/d9c3949c-33cf-4a32-aa97-3af46b28033a)

inspired by rust-lang/rust-analyzer#15847
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.

Struct literal constructors don't check type parameters on typedefs
3 participants