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

ICE when using generic newtypes cross-crate #9155

Closed
sfackler opened this issue Sep 13, 2013 · 3 comments · Fixed by #9697
Closed

ICE when using generic newtypes cross-crate #9155

sfackler opened this issue Sep 13, 2013 · 3 comments · Fixed by #9697
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@sfackler
Copy link
Member

Turns out it's impossible to use generic newtypes across crates:

test.rs:

pub struct Foo<T>(T);

impl<T> Foo<T> {
    pub fn new(t: T) -> Foo<T> {
        Foo(t)
    }
}

test2.rs:

extern mod test;

use test::{Foo};

struct Baz;

fn main() {
    Foo::new(Baz);
}
~ ❯ env RUST_LOG=rustc=1 rustc -L. test2.rs
task <unnamed> failed at 'assertion failed: `(left == right) && (right == left)` (left: `2`, right: `0`)', /build/rust-git/src/rust/src/librustc/middle/trans/callee.rs:385
error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug
note: try running with RUST_LOG=rustc=1 to get further details and report the results to github.com/mozilla/rust/issues
task <unnamed> failed at 'explicit failure', /build/rust-git/src/rust/src/librustc/rustc.rs:377

This makes it impossible to use std::rt::io::buffered::BufferedStream.

@huonw
Copy link
Member

huonw commented Sep 13, 2013

Related to #7899 (but not identical).

sfackler added a commit to sfackler/rust that referenced this issue Sep 13, 2013
This is a workaround for rust-lang#9155. Currently, any uses of BufferedStream
outside of libstd ICE.
bors added a commit that referenced this issue Sep 14, 2013
This is a workaround for #9155. Currently, any uses of BufferedStream
outside of libstd ICE.
@bluss
Copy link
Member

bluss commented Oct 2, 2013

This particular case seems to be fixed by the PR #9560 by pcwalton!

However, there are compiler errors on trying to use the test::Foo constructor directly..

@alexcrichton
Copy link
Member

Flagging as needstest.

sfackler added a commit to sfackler/rust that referenced this issue Oct 3, 2013
Add a test to make sure it works and switch a private struct over to a
newtype.

Closes rust-lang#9155
thestinger added a commit that referenced this issue Oct 3, 2013
flip1995 pushed a commit to flip1995/rust that referenced this issue Jun 30, 2023
…, r=xFrednet

Add redundant type annotations lint

Hello, I'm trying to add the `redundat_type_annotations` lint.

It's still WIP but I'd like to start gathering some feedbacks to be sure that I'm not doing things 100% wrong :)

Right now it still misses lints like:

- [x] `let foo: u32 = 5_u32`,
- [x] `let foo: String = STest2::func()`
- [x] `let foo: String = self.func()` (`MethodCall`)
- [x] refs
- [ ] Generics

I've some problems regarding the second example above, in the `init` part of the `Local` I have:

```rust
init: Some(
                Expr {
                    hir_id: HirId(DefId(0:24 ~ playground[e1bd]::main).58),
                    kind: Call(
                        Expr {
                            hir_id: HirId(DefId(0:24 ~ playground[e1bd]::main).59),
                            kind: Path(
                                TypeRelative(
                                    Ty {
                                        hir_id: HirId(DefId(0:24 ~ playground[e1bd]::main).61),
                                        kind: Path(
                                            Resolved(
                                                None,
                                                Path {
                                                    span: src/main.rs:77:21: 77:27 (#0),
                                                    res: Def(
                                                        Struct,
                                                        DefId(0:17 ~ playground[e1bd]::STest2),
                                                    ),
                                                    segments: [
                                                        PathSegment {
                                                            ident: STest2#0,
                                                            hir_id: HirId(DefId(0:24 ~ playground[e1bd]::main).60),
                                                            res: Def(
                                                                Struct,
                                                                DefId(0:17 ~ playground[e1bd]::STest2),
                                                            ),
                                                            args: None,
                                                            infer_args: true,
                                                        },
                                                    ],
                                                },
                                            ),
                                        ),
                                        span: src/main.rs:77:21: 77:27 (#0),
                                    },
                                    PathSegment {
                                        ident: get_numb#0,
                                        hir_id: HirId(DefId(0:24 ~ playground[e1bd]::main).62),
                                        res: Err,
                                        args: None,
                                        infer_args: true,
                                    },
                                ),
                            ),
                            span: src/main.rs:77:21: 77:37 (#0),
                        },
                        [],
                    ),
                    span: src/main.rs:77:21: 77:39 (#0),
                },
            ),
```

And I'm not sure how to get the return type of the function `STest2::func()` since the resolved path `DefId` points to the struct itself and not the function. Do you have any idea on how I could get this information in this case?

Thanks!

changelog: changelog: [`redundant_type_annotations`]: New lint to warn on redundant type annotations

fixes rust-lang#9155
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants