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

Rustdoc-Json: Reference to missing item with 2 glob imports #100973

Closed
aDotInTheVoid opened this issue Aug 24, 2022 · 4 comments · Fixed by #101106
Closed

Rustdoc-Json: Reference to missing item with 2 glob imports #100973

aDotInTheVoid opened this issue Aug 24, 2022 · 4 comments · Fixed by #101106
Assignees
Labels
A-rustdoc-json Area: Rustdoc JSON backend T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@aDotInTheVoid
Copy link
Member

aDotInTheVoid commented Aug 24, 2022

#![feature(no_core)]
#![no_core]
mod m1 {
    pub fn f() {}
}
mod m2 {
    pub fn f(_: u8) {}
}
pub use m2::*;
pub use m1::*;

Produces an output with references to non existant items: 0:3:1564 and 0:1:1563

{
  "crate_version": null,
  "external_crates": {},
  "format_version": 18,
  "includes_private": false,
  "index": {
    "0:0:1565": {
      "crate_id": 0,
      "id": "0:0:1565",
      "inner": {"is_crate": true, "is_stripped": false, "items": ["0:5", "0:6"]},
      "kind": "module",
      "name": "glob_private_simple",
      "visibility": "public"
    },
    "0:5": {
      "crate_id": 0,
      "id": "0:5",
      "inner": {"glob": true, "id": "0:3:1564", "name": "m2", "source": "m2"},
      "kind": "import",
      "name": null,
      "visibility": "public"
    },
    "0:6": {
      "crate_id": 0,
      "id": "0:6",
      "inner": {"glob": true, "id": "0:1:1563", "name": "m1", "source": "m1"},
      "kind": "import",
      "name": null,
      "visibility": "public"
    }
  },
  "root": "0:0:1565"
}
Full
{
  "crate_version": null,
  "external_crates": {},
  "format_version": 18,
  "includes_private": false,
  "index": {
    "0:0:1565": {
      "attrs": ["#![feature(no_core)]", "#![no_core]"],
      "crate_id": 0,
      "deprecation": null,
      "docs": null,
      "id": "0:0:1565",
      "inner": {"is_crate": true, "is_stripped": false, "items": ["0:5", "0:6"]},
      "kind": "module",
      "links": {},
      "name": "glob_private_simple",
      "span": {
        "begin": [1, 0],
        "end": [12, 14],
        "filename": "/home/nixon/dev/rust/rust/src/test/rustdoc-json/reexport/glob_private_simple.rs"
      },
      "visibility": "public"
    },
    "0:5": {
      "attrs": [],
      "crate_id": 0,
      "deprecation": null,
      "docs": null,
      "id": "0:5",
      "inner": {"glob": true, "id": "0:3:1564", "name": "m2", "source": "m2"},
      "kind": "import",
      "links": {},
      "name": null,
      "span": {
        "begin": [11, 0],
        "end": [11, 14],
        "filename": "/home/nixon/dev/rust/rust/src/test/rustdoc-json/reexport/glob_private_simple.rs"
      },
      "visibility": "public"
    },
    "0:6": {
      "attrs": [],
      "crate_id": 0,
      "deprecation": null,
      "docs": null,
      "id": "0:6",
      "inner": {"glob": true, "id": "0:1:1563", "name": "m1", "source": "m1"},
      "kind": "import",
      "links": {},
      "name": null,
      "span": {
        "begin": [12, 0],
        "end": [12, 14],
        "filename": "/home/nixon/dev/rust/rust/src/test/rustdoc-json/reexport/glob_private_simple.rs"
      },
      "visibility": "public"
    }
  },
  "paths": {"0:0:1565": {"crate_id": 0, "kind": "module", "path": ["glob_private_simple"]}},
  "root": "0:0:1565"
}

If you remove one of the imports, everything is fine

#![feature(no_core)]
#![no_core]
mod m1 {
    pub fn f() {}
}
mod m2 {
    pub fn f(_: u8) {}
}
pub use m2::*;
{
  "crate_version": null,
  "external_crates": {},
  "format_version": 18,
  "includes_private": false,
  "index": {
    "0:0:1565": {
      "crate_id": 0,
      "id": "0:0:1565",
      "inner": {"is_crate": true, "is_stripped": false, "items": ["0:5"]},
      "kind": "module",
      "name": "glob_private_simple",
      "visibility": "public"
    },
    "0:3:1564": {
      "crate_id": 0,
      "id": "0:3:1564",
      "inner": {"is_crate": false, "is_stripped": true, "items": ["0:4:630"]},
      "kind": "module",
      "name": "m2",
      "visibility": "crate"
    },
    "0:4:630": {
      "crate_id": 0,
      "id": "0:4:630",
      "inner": { ... },
      "kind": "function",
      "name": "f",
      "visibility": "public"
    },
    "0:5": {
      "crate_id": 0,
      "id": "0:5",
      "inner": {"glob": true, "id": "0:3:1564", "name": "m2", "source": "m2"},
      "kind": "import",
      "name": null,
      "visibility": "public"
    }
  },
  "root": "0:0:1565"
}
Full
{
  "crate_version": null,
  "external_crates": {},
  "format_version": 18,
  "includes_private": false,
  "index": {
    "0:0:1565": {
      "attrs": ["#![feature(no_core)]", "#![no_core]"],
      "crate_id": 0,
      "deprecation": null,
      "docs": null,
      "id": "0:0:1565",
      "inner": {"is_crate": true, "is_stripped": false, "items": ["0:5"]},
      "kind": "module",
      "links": {},
      "name": "glob_private_simple",
      "span": {
        "begin": [1, 0],
        "end": [11, 14],
        "filename": "/home/nixon/dev/rust/rust/src/test/rustdoc-json/reexport/glob_private_simple.rs"
      },
      "visibility": "public"
    },
    "0:3:1564": {
      "attrs": [],
      "crate_id": 0,
      "deprecation": null,
      "docs": null,
      "id": "0:3:1564",
      "inner": {"is_crate": false, "is_stripped": true, "items": ["0:4:630"]},
      "kind": "module",
      "links": {},
      "name": "m2",
      "span": {
        "begin": [7, 0],
        "end": [7, 6],
        "filename": "/home/nixon/dev/rust/rust/src/test/rustdoc-json/reexport/glob_private_simple.rs"
      },
      "visibility": "crate"
    },
    "0:4:630": {
      "attrs": [],
      "crate_id": 0,
      "deprecation": null,
      "docs": null,
      "id": "0:4:630",
      "inner": {
        "decl": {
          "c_variadic": false,
          "inputs": [["_", {"inner": "u8", "kind": "primitive"}]],
          "output": null
        },
        "generics": {"params": [], "where_predicates": []},
        "header": {"abi": "Rust", "async": false, "const": false, "unsafe": false}
      },
      "kind": "function",
      "links": {},
      "name": "f",
      "span": {
        "begin": [8, 4],
        "end": [8, 22],
        "filename": "/home/nixon/dev/rust/rust/src/test/rustdoc-json/reexport/glob_private_simple.rs"
      },
      "visibility": "public"
    },
    "0:5": {
      "attrs": [],
      "crate_id": 0,
      "deprecation": null,
      "docs": null,
      "id": "0:5",
      "inner": {"glob": true, "id": "0:3:1564", "name": "m2", "source": "m2"},
      "kind": "import",
      "links": {},
      "name": null,
      "span": {
        "begin": [11, 0],
        "end": [11, 14],
        "filename": "/home/nixon/dev/rust/rust/src/test/rustdoc-json/reexport/glob_private_simple.rs"
      },
      "visibility": "public"
    }
  },
  "paths": {"0:0:1565": {"crate_id": 0, "kind": "module", "path": ["glob_private_simple"]}},
  "root": "0:0:1565"
}

This should have been caught by check_missing_items.py, but wasn't. Instead is was caught by jsondoclint, a rust based replacement (PR soon).

@rustbot modify labels: +A-rustdoc-json +T-rustdoc

@rustbot rustbot added A-rustdoc-json Area: Rustdoc JSON backend T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Aug 24, 2022
@Urgau
Copy link
Member

Urgau commented Aug 24, 2022

Seems like a duplicate of #99513

@aDotInTheVoid
Copy link
Member Author

I don't thinks so, as that occors with just 1 import, whereas this requires 2. Also thats for importing foreign items, whereas this happens for local items.

@aDotInTheVoid
Copy link
Member Author

Smaller version:

#![feature(no_core)]
#![no_core]

mod m2 {}
pub use m2::*;
{
  "crate_version": null,
  "external_crates": {},
  "format_version": 18,
  "includes_private": false,
  "index": {
    "0:0:1567": {
      "crate_id": 0,
      "id": "0:0:1567",
      "inner": {"is_crate": true, "is_stripped": false, "items": ["0:2"]},
      "kind": "module",
      "name": "bug"
    },
    "0:2": {
      "crate_id": 0,
      "id": "0:2",
      "inner": {"glob": true, "id": "0:1:1566", "name": "m2", "source": "m2"},
      "kind": "import",
      "name": null
    }
  },
  "root": "0:0:1567"
}

It looks like empty modules are being stripped. This also happens in the above example because both functions are named f, so because the name clashes none are callable. renaming one of them, or adding items with non classing names to both modules fixes this

@aDotInTheVoid
Copy link
Member Author

Caused by

clean::ModuleItem(m) if !m.items.is_empty() => from_clean_item(item, self.tcx),

@rustbot claim

aDotInTheVoid added a commit to aDotInTheVoid/rust that referenced this issue Aug 28, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Aug 28, 2022
…GuillaumeGomez

Rustdoc-Json: Retain Stripped Modules when they are imported, not when they have items

Fixes rust-lang#101103
Fixes rust-lang#100973

r? `@GuillaumeGomez`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Aug 28, 2022
…GuillaumeGomez

Rustdoc-Json: Retain Stripped Modules when they are imported, not when they have items

Fixes rust-lang#101103
Fixes rust-lang#100973

r? ``@GuillaumeGomez``
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Aug 29, 2022
…GuillaumeGomez

Rustdoc-Json: Retain Stripped Modules when they are imported, not when they have items

Fixes rust-lang#101103
Fixes rust-lang#100973

r? `@GuillaumeGomez`
@bors bors closed this as completed in 8050c19 Aug 30, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Sep 15, 2022
…aumeGomez

Replace `check_missing_items.py` with `jsondoclint`

[zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/check_missing_items.2Epy.20Replacement.2E)

check_missing_items.py was a python script that checked rustdoc json output to make sure all the Id's referenced existed in the JSON index. This PR replaces that with a rust binary (`jsondoclint`) that does the same thing.

### Motivation

1. Easier to change when `rustdoc-json-types` changes, as `jsondoclint` uses the types directly.
2. Better Errors:
    - Multiple Errors can be emited for a single crate
    - Errors can say where in JSON they occored
        ```
        2:2889:408 not in index or paths, but refered to at '.index."2:2888:104".inner.items[0]'
        2:2890:410 not in index or paths, but refered to at '.index."2:2888:104".inner.items[1]'
        ```
3. Catches more bugs.
    - Because matches are exaustive, all posible variants considered for enums
    - All Id's checked
    - Has already found rust-lang#101770, rust-lang#101199 and rust-lang#100973
    - Id type is also checked, so the Id's in a structs fields can only be field items.
4. Allows the possibility of running from `rustdoc::json`, which we should do in a crator run at some point.

cc `@CraftSpider`

r? `@GuillaumeGomez`
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Sep 15, 2022
…aumeGomez

Replace `check_missing_items.py` with `jsondoclint`

[zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/check_missing_items.2Epy.20Replacement.2E)

check_missing_items.py was a python script that checked rustdoc json output to make sure all the Id's referenced existed in the JSON index. This PR replaces that with a rust binary (`jsondoclint`) that does the same thing.

### Motivation

1. Easier to change when `rustdoc-json-types` changes, as `jsondoclint` uses the types directly.
2. Better Errors:
    - Multiple Errors can be emited for a single crate
    - Errors can say where in JSON they occored
        ```
        2:2889:408 not in index or paths, but refered to at '.index."2:2888:104".inner.items[0]'
        2:2890:410 not in index or paths, but refered to at '.index."2:2888:104".inner.items[1]'
        ```
3. Catches more bugs.
    - Because matches are exaustive, all posible variants considered for enums
    - All Id's checked
    - Has already found rust-lang#101770, rust-lang#101199 and rust-lang#100973
    - Id type is also checked, so the Id's in a structs fields can only be field items.
4. Allows the possibility of running from `rustdoc::json`, which we should do in a crator run at some point.

cc `@CraftSpider`

r? `@GuillaumeGomez`
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this issue Sep 16, 2022
…aumeGomez

Replace `check_missing_items.py` with `jsondoclint`

[zulip discussion](https://rust-lang.zulipchat.com/#narrow/stream/266220-rustdoc/topic/check_missing_items.2Epy.20Replacement.2E)

check_missing_items.py was a python script that checked rustdoc json output to make sure all the Id's referenced existed in the JSON index. This PR replaces that with a rust binary (`jsondoclint`) that does the same thing.

### Motivation

1. Easier to change when `rustdoc-json-types` changes, as `jsondoclint` uses the types directly.
2. Better Errors:
    - Multiple Errors can be emited for a single crate
    - Errors can say where in JSON they occored
        ```
        2:2889:408 not in index or paths, but refered to at '.index."2:2888:104".inner.items[0]'
        2:2890:410 not in index or paths, but refered to at '.index."2:2888:104".inner.items[1]'
        ```
3. Catches more bugs.
    - Because matches are exaustive, all posible variants considered for enums
    - All Id's checked
    - Has already found rust-lang#101770, rust-lang#101199 and rust-lang#100973
    - Id type is also checked, so the Id's in a structs fields can only be field items.
4. Allows the possibility of running from `rustdoc::json`, which we should do in a crator run at some point.

cc ``@CraftSpider``

r? ``@GuillaumeGomez``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-json Area: Rustdoc JSON backend T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
3 participants