Skip to content

Rollup of 5 pull requests #105909

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

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2554,10 +2554,9 @@ pub enum AttrStyle {
}

rustc_index::newtype_index! {
pub struct AttrId {
ENCODABLE = custom
DEBUG_FORMAT = "AttrId({})"
}
#[custom_encodable]
#[debug_format = "AttrId({})]"]
pub struct AttrId {}
}

impl<S: Encoder> Encodable<S> for AttrId {
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_ast/src/node_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ rustc_index::newtype_index! {
/// This is later turned into [`DefId`] and `HirId` for the HIR.
///
/// [`DefId`]: rustc_span::def_id::DefId
pub struct NodeId {
DEBUG_FORMAT = "NodeId({})"
}
#[debug_format = "NodeId({})"]
pub struct NodeId {}
}

rustc_data_structures::define_id_collections!(NodeMap, NodeSet, NodeMapEntry, NodeId);
Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_borrowck/src/constraints/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,11 @@ impl<'tcx> fmt::Debug for OutlivesConstraint<'tcx> {
}

rustc_index::newtype_index! {
pub struct OutlivesConstraintIndex {
DEBUG_FORMAT = "OutlivesConstraintIndex({})"
}
#[debug_format = "OutlivesConstraintIndex({})"]
pub struct OutlivesConstraintIndex {}
}

rustc_index::newtype_index! {
pub struct ConstraintSccIndex {
DEBUG_FORMAT = "ConstraintSccIndex({})"
}
#[debug_format = "ConstraintSccIndex({})"]
pub struct ConstraintSccIndex {}
}
5 changes: 2 additions & 3 deletions compiler/rustc_borrowck/src/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ impl_visitable! {
}

rustc_index::newtype_index! {
pub struct BorrowIndex {
DEBUG_FORMAT = "bw{}"
}
#[debug_format = "bw{}"]
pub struct BorrowIndex {}
}

/// `Borrows` stores the data used in the analyses that track the flow
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_borrowck/src/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ pub struct LocationTable {
}

rustc_index::newtype_index! {
pub struct LocationIndex {
DEBUG_FORMAT = "LocationIndex({})"
}
#[debug_format = "LocationIndex({})"]
pub struct LocationIndex {}
}

#[derive(Copy, Clone, Debug)]
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_borrowck/src/member_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ pub(crate) struct NllMemberConstraint<'tcx> {
}

rustc_index::newtype_index! {
pub(crate) struct NllMemberConstraintIndex {
DEBUG_FORMAT = "MemberConstraintIndex({})"
}
#[debug_format = "MemberConstraintIndex({})"]
pub(crate) struct NllMemberConstraintIndex {}
}

impl Default for MemberConstraintSet<'_, ty::RegionVid> {
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_borrowck/src/region_infer/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,14 @@ impl RegionValueElements {
rustc_index::newtype_index! {
/// A single integer representing a `Location` in the MIR control-flow
/// graph. Constructed efficiently from `RegionValueElements`.
pub struct PointIndex { DEBUG_FORMAT = "PointIndex({})" }
#[debug_format = "PointIndex({})"]
pub struct PointIndex {}
}

rustc_index::newtype_index! {
/// A single integer representing a `ty::Placeholder`.
pub struct PlaceholderIndex { DEBUG_FORMAT = "PlaceholderIndex({})" }
#[debug_format = "PlaceholderIndex({})"]
pub struct PlaceholderIndex {}
}

/// An individual element in a region value -- the value of a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct Appearance {
}

rustc_index::newtype_index! {
pub struct AppearanceIndex { .. }
pub struct AppearanceIndex {}
}

impl vll::LinkElem for Appearance {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/graph/dominators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct PreOrderFrame<Iter> {
}

rustc_index::newtype_index! {
struct PreorderIndex { .. }
struct PreorderIndex {}
}

pub fn dominators<G: ControlFlowGraph>(graph: G) -> Dominators<G::Node> {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_error_codes/src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,10 @@ E0452: include_str!("./error_codes/E0452.md"),
E0453: include_str!("./error_codes/E0453.md"),
E0454: include_str!("./error_codes/E0454.md"),
E0455: include_str!("./error_codes/E0455.md"),
E0457: include_str!("./error_codes/E0457.md"),
E0458: include_str!("./error_codes/E0458.md"),
E0459: include_str!("./error_codes/E0459.md"),
E0460: include_str!("./error_codes/E0460.md"),
E0463: include_str!("./error_codes/E0463.md"),
E0464: include_str!("./error_codes/E0464.md"),
E0466: include_str!("./error_codes/E0466.md"),
Expand Down Expand Up @@ -592,8 +594,6 @@ E0791: include_str!("./error_codes/E0791.md"),
// E0421, // merged into 531
// E0427, // merged into 530
// E0456, // plugin `..` is not available for triple `..`
E0457, // plugin `..` only found in rlib format, but must be available...
E0460, // found possibly newer version of crate `..`
E0461, // couldn't find crate `..` with expected target triple ..
E0462, // found staticlib `..` instead of rlib or dylib
E0465, // multiple .. candidates for `..` found
Expand Down
36 changes: 36 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0457.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Plugin `..` only found in rlib format, but must be available in dylib format.

Erroronous code example:

`rlib-plugin.rs`
```ignore (needs-linkage-with-other-tests)
#![crate_type = "rlib"]
#![feature(rustc_private)]

extern crate rustc_middle;
extern crate rustc_driver;

use rustc_driver::plugin::Registry;

#[no_mangle]
fn __rustc_plugin_registrar(_: &mut Registry) {}
```

`main.rs`
```ignore (needs-linkage-with-other-tests)
#![feature(plugin)]
#![plugin(rlib_plugin)] // error: plugin `rlib_plugin` only found in rlib
// format, but must be available in dylib

fn main() {}
```

The compiler exposes a plugin interface to allow altering the compile process
(adding lints, etc). Plugins must be defined in their own crates (similar to
[proc-macro](../reference/procedural-macros.html) isolation) and then compiled
and linked to another crate. Plugin crates *must* be compiled to the
dynamically-linked dylib format, and not the statically-linked rlib format.
Learn more about different output types in
[this section](../reference/linkage.html) of the Rust reference.

This error is easily fixed by recompiling the plugin crate in the dylib format.
71 changes: 71 additions & 0 deletions compiler/rustc_error_codes/src/error_codes/E0460.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
Found possibly newer version of crate `..` which `..` depends on.

Consider these erroneous files:

`a1.rs`
```ignore (needs-linkage-with-other-tests)
#![crate_name = "a"]

pub fn foo<T>() {}
```

`a2.rs`
```ignore (needs-linkage-with-other-tests)
#![crate_name = "a"]

pub fn foo<T>() {
println!("foo<T>()");
}
```

`b.rs`
```ignore (needs-linkage-with-other-tests)
#![crate_name = "b"]

extern crate a; // linked with `a1.rs`

pub fn foo() {
a::foo::<isize>();
}
```

`main.rs`
```ignore (needs-linkage-with-other-tests)
extern crate a; // linked with `a2.rs`
extern crate b; // error: found possibly newer version of crate `a` which `b`
// depends on

fn main() {}
```

The dependency graph of this program can be represented as follows:
```text
crate `main`
|
+-------------+
| |
| v
depends: | crate `b`
`a` v1 | |
| | depends:
| | `a` v2
v |
crate `a` <------+
```

Crate `main` depends on crate `a` (version 1) and crate `b` which in turn
depends on crate `a` (version 2); this discrepancy in versions cannot be
reconciled. This difference in versions typically occurs when one crate is
compiled and linked, then updated and linked to another crate. The crate
"version" is a SVH (Strict Version Hash) of the crate in an
implementation-specific way. Note that this error can *only* occur when
directly compiling and linking with `rustc`; [Cargo] automatically resolves
dependencies, without using the compiler's own dependency management that
causes this issue.

This error can be fixed by:
* Using [Cargo], the Rust package manager, automatically fixing this issue.
* Recompiling crate `a` so that both crate `b` and `main` have a uniform
version to depend on.

[Cargo]: ../cargo/index.html
2 changes: 1 addition & 1 deletion compiler/rustc_hir/src/hir_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ rustc_index::newtype_index! {
/// an "item-like" to something else can be implemented by a `Vec` instead of a
/// tree or hash map.
#[derive(HashStable_Generic)]
pub struct ItemLocalId { .. }
pub struct ItemLocalId {}
}

impl ItemLocalId {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
// entire graph when there are many connected regions.

rustc_index::newtype_index! {
pub struct RegionId {
ENCODABLE = custom
}
#[custom_encodable]
pub struct RegionId {}
}

struct ConnectedRegion {
idents: SmallVec<[Symbol; 8]>,
impl_blocks: FxHashSet<usize>,
Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_hir_typeck/src/fn_ctxt/arg_matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ use rustc_index::vec::IndexVec;
use rustc_middle::ty::error::TypeError;

rustc_index::newtype_index! {
pub(crate) struct ExpectedIdx {
DEBUG_FORMAT = "ExpectedIdx({})",
}
#[debug_format = "ExpectedIdx({})"]
pub(crate) struct ExpectedIdx {}
}

rustc_index::newtype_index! {
pub(crate) struct ProvidedIdx {
DEBUG_FORMAT = "ProvidedIdx({})",
}
#[debug_format = "ProvidedIdx({})"]
pub(crate) struct ProvidedIdx {}
}

impl ExpectedIdx {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,13 @@ fn for_each_consumable<'tcx>(hir: Map<'tcx>, place: TrackedValue, mut f: impl Fn
}

rustc_index::newtype_index! {
pub struct PostOrderId {
DEBUG_FORMAT = "id({})",
}
#[debug_format = "id({})"]
pub struct PostOrderId {}
}

rustc_index::newtype_index! {
pub struct TrackedValueIndex {
DEBUG_FORMAT = "hidx({})",
}
#[debug_format = "hidx({})"]
pub struct TrackedValueIndex {}
}

/// Identifies a value whose drop state we need to track.
Expand Down
5 changes: 4 additions & 1 deletion compiler/rustc_index/src/vec/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
// Allows the macro invocation below to work
use crate as rustc_index;

rustc_macros::newtype_index!(struct MyIdx { MAX = 0xFFFF_FFFA });
rustc_macros::newtype_index! {
#[max = 0xFFFF_FFFA]
struct MyIdx {}
}

#[test]
fn index_size_is_optimized() {
Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_infer/src/infer/region_constraints/leak_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,15 +357,13 @@ impl<'tcx> SccUniverse<'tcx> {
}

rustc_index::newtype_index! {
struct LeakCheckNode {
DEBUG_FORMAT = "LeakCheckNode({})"
}
#[debug_format = "LeakCheckNode({})"]
struct LeakCheckNode {}
}

rustc_index::newtype_index! {
struct LeakCheckScc {
DEBUG_FORMAT = "LeakCheckScc({})"
}
#[debug_format = "LeakCheckScc({})"]
struct LeakCheckScc {}
}

/// Represents the graph of constraints. For each `R1: R2` constraint we create
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_lint/src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ struct LintLevelSets {
}

rustc_index::newtype_index! {
#[custom_encodable] // we don't need encoding
struct LintStackIndex {
ENCODABLE = custom, // we don't need encoding
const COMMAND_LINE = 0,
const COMMAND_LINE = 0;
}
}

Expand Down
Loading