-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Too much kw::Empty
usage
#137978
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
Comments
#137977 is the first step here. The backstory: I grepped for |
…try> Move `hir::Item::ident` into `hir::ItemKind`. `hir::Item` has an `ident` field. - It's always non-empty for these item kinds: `ExternCrate`, `Static`, `Const`, `Fn`, `Macro`, `Mod`, `TyAlias`, `Enum`, `Struct`, `Union`, Trait`, TraitAalis`. - It's always empty for these item kinds: `ForeignMod`, `GlobalAsm`, `Impl`. - For `Use`, it is non-empty for `UseKind::Single` and empty for `UseKind::{Glob,ListStem}`. All of this is quite non-obvious; the only documentation is a single comment saying "The name might be a dummy name in case of anonymous items". Some sites that handle items check for an empty ident, some don't. This is a very C-like way of doing things, but this is Rust, we have sum types, we can do this properly and never forget to check for the exceptional case and never YOLO possibly empty identifiers (or possibly dummy spans) around and hope that things will work out. This is step towards `kw::Empty` elimination (rust-lang#137978). r? `@ghost`
#138482 fixed some HIR printing bugs. That PR didn't reduce |
…=fmease Move `hir::Item::ident` into `hir::ItemKind`. `hir::Item` has an `ident` field. - It's always non-empty for these item kinds: `ExternCrate`, `Static`, `Const`, `Fn`, `Macro`, `Mod`, `TyAlias`, `Enum`, `Struct`, `Union`, Trait`, TraitAalis`. - It's always empty for these item kinds: `ForeignMod`, `GlobalAsm`, `Impl`. - For `Use`, it is non-empty for `UseKind::Single` and empty for `UseKind::{Glob,ListStem}`. All of this is quite non-obvious; the only documentation is a single comment saying "The name might be a dummy name in case of anonymous items". Some sites that handle items check for an empty ident, some don't. This is a very C-like way of doing things, but this is Rust, we have sum types, we can do this properly and never forget to check for the exceptional case and never YOLO possibly empty identifiers (or possibly dummy spans) around and hope that things will work out. This is step towards `kw::Empty` elimination (rust-lang#137978). r? `@fmease`
Rollup merge of rust-lang#138384 - nnethercote:hir-ItemKind-idents, r=fmease Move `hir::Item::ident` into `hir::ItemKind`. `hir::Item` has an `ident` field. - It's always non-empty for these item kinds: `ExternCrate`, `Static`, `Const`, `Fn`, `Macro`, `Mod`, `TyAlias`, `Enum`, `Struct`, `Union`, Trait`, TraitAalis`. - It's always empty for these item kinds: `ForeignMod`, `GlobalAsm`, `Impl`. - For `Use`, it is non-empty for `UseKind::Single` and empty for `UseKind::{Glob,ListStem}`. All of this is quite non-obvious; the only documentation is a single comment saying "The name might be a dummy name in case of anonymous items". Some sites that handle items check for an empty ident, some don't. This is a very C-like way of doing things, but this is Rust, we have sum types, we can do this properly and never forget to check for the exceptional case and never YOLO possibly empty identifiers (or possibly dummy spans) around and hope that things will work out. This is step towards `kw::Empty` elimination (rust-lang#137978). r? `@fmease`
#138685 removes some more |
#138384 removed some dubious use of |
…piler-errors Reduce `kw::Empty` usage, part 3 Remove some more `kw::Empty` uses, in support of rust-lang#137978. r? `@davidtwco`
Rollup merge of rust-lang#138924 - nnethercote:less-kw-Empty-3, r=compiler-errors Reduce `kw::Empty` usage, part 3 Remove some more `kw::Empty` uses, in support of rust-lang#137978. r? `@davidtwco`
…, r=GuillaumeGomez rustdoc: remove useless `Symbol::is_empty` checks. There are a number of `is_empty` checks that can never fail. This commit removes them, in support of rust-lang#137978. r? `@GuillaumeGomez`
Rollup merge of rust-lang#138917 - nnethercote:rustdoc-remove-useless, r=GuillaumeGomez rustdoc: remove useless `Symbol::is_empty` checks. There are a number of `is_empty` checks that can never fail. This commit removes them, in support of rust-lang#137978. r? `@GuillaumeGomez`
Another notable one. |
…me, r=lcnr Remove `kw::Empty` uses from `hir::Lifetime::ident` `hir::Lifetime::ident` is sometimes set to `kw::Empty` and it's really confusing. This PR stops that. Helps with rust-lang#137978. r? `@lcnr`
Add new `PatKind::Missing` variants To avoid some ugly uses of `kw::Empty` when handling "missing" patterns, e.g. in bare fn tys. Helps with rust-lang#137978. Details in the individual commits. r? `@ghost`
…rochenkov Reduce kw::Empty usage, part 4 Another step towards rust-lang#137978. r? `@petrochenkov`
Rollup merge of rust-lang#139039 - nnethercote:less-kw-Empty-4, r=petrochenkov Reduce kw::Empty usage, part 4 Another step towards rust-lang#137978. r? `@petrochenkov`
…-obk Add new `PatKind::Missing` variants To avoid some ugly uses of `kw::Empty` when handling "missing" patterns, e.g. in bare fn tys. Helps with rust-lang#137978. Details in the individual commits. r? `@oli-obk`
…mpiler-errors Don't use empty trait names Helps with rust-lang#137978. Details in individual commits. r? ``@davidtwco``
#139615 fixes some cases where empty identifiers leaked through to some error messages such as this:
|
…mpiler-errors Don't use empty trait names Helps with rust-lang#137978. Details in individual commits. r? ```@davidtwco```
Rollup merge of rust-lang#139568 - nnethercote:empty-trait-name, r=compiler-errors Don't use empty trait names Helps with rust-lang#137978. Details in individual commits. r? ```@davidtwco```
This contributes towards rust-lang/rust#137978. changelog: none
To accurately reflect that RPITIT assoc items don't have a name. This avoids the use of `kw::Empty` to mean "no name", which is error prone. Helps with rust-lang#137978.
To accurately reflect that RPITIT assoc items don't have a name. This avoids the use of `kw::Empty` to mean "no name", which is error prone. Helps with rust-lang#137978.
These were low value even before rust-lang#137978 resulted in empty names being used much less. (Why check for non-emptiness in these three places? There are thousands of places in the compiler you could check.)
Remove `kw::Empty` uses in rustdoc Helps with rust-lang#137978. r? `@GuillaumeGomez`
…-errors Reduce kw::Empty usage, part 5 Another step towards rust-lang#137978. r? `@davidtwco`
Rollup merge of rust-lang#139848 - nnethercote:kw-Empty-5, r=compiler-errors Reduce kw::Empty usage, part 5 Another step towards rust-lang#137978. r? `@davidtwco`
…onszelmann Remove `name_or_empty` Another step towards rust-lang#137978. r? `@jdonszelmann`
…illaumeGomez Remove `kw::Empty` uses in rustdoc Helps with rust-lang#137978. r? `@GuillaumeGomez`
…illaumeGomez Remove `kw::Empty` uses in rustdoc Helps with rust-lang#137978. r? ``@GuillaumeGomez``
Rollup merge of rust-lang#139846 - nnethercote:kw-Empty-rustdoc, r=GuillaumeGomez Remove `kw::Empty` uses in rustdoc Helps with rust-lang#137978. r? ``@GuillaumeGomez``
…onszelmann Remove `name_or_empty` Another step towards rust-lang#137978. r? `@jdonszelmann`
…ng, r=GuillaumeGomez rustdoc/clean: Fix lowering of fn params (fixes correctness & HIR vs. middle parity regressions) **(0)** PR rust-lang#136411 aimed to stop rendering unnamed params of fn ptr types as underscores in the common case (e.g., `fn(_: i32)` → `fn(i32)`) to make the rendered output stylistically more conventional. **(0.a)** However, since the cleaning fn that the PR modified is also used for lowering the HIR params of foreign fns and required assoc fns in traits, it accidentally butchered the rendering of the latter two: ```rs pub trait Trait { fn assoc_fn(_: i32); } // as well as (Rust 2015 only): fn assoc_fn(i32); unsafe extern "C" { pub fn foreign_fn(_: i32); } // Since 1.86 the fns above gets mis-rendered as: pub fn assoc_fn(: i32) // <-- BUTCHERED pub unsafe extern "C" fn foreign_fn(: i32) // <-- BUTCHERED ``` **(0.b)** Furthermore, it broke parity with middle cleaning (which includes inlined cross-crate re-exports) re-regressing parts of rust-lang#44306 I once fixed in PR rust-lang#103885. **(1)** Lastly, PR rust-lang#139035 introduced an ICE triggered by the following input file: ```rs trait Trait { fn anon(()) {} } // internal error: entered unreachable code ``` --- This PR fixes all of these regressions and in the first commit renames several types and fns to be more ~~correct~~ descriptive and legible. ~~It also refactors `Param.name` to be of type `Option<Symbol>` instead `Symbol` (where `None` ~ `kw::Empty`), so rendering mistakes like that can no longer creep in like that (ignoring tests). CC rust-lang#137978.~~ Independently done in PR rust-lang#139846 a day prior.
…onszelmann Remove `name_or_empty` Another step towards rust-lang#137978. r? `@jdonszelmann`
…ng, r=GuillaumeGomez rustdoc/clean: Fix lowering of fn params (fixes correctness & HIR vs. middle parity regressions) **(0)** PR rust-lang#136411 aimed to stop rendering unnamed params of fn ptr types as underscores in the common case (e.g., `fn(_: i32)` → `fn(i32)`) to make the rendered output stylistically more conventional. **(0.a)** However, since the cleaning fn that the PR modified is also used for lowering the HIR params of foreign fns and required assoc fns in traits, it accidentally butchered the rendering of the latter two: ```rs pub trait Trait { fn assoc_fn(_: i32); } // as well as (Rust 2015 only): fn assoc_fn(i32); unsafe extern "C" { pub fn foreign_fn(_: i32); } // Since 1.86 the fns above gets mis-rendered as: pub fn assoc_fn(: i32) // <-- BUTCHERED pub unsafe extern "C" fn foreign_fn(: i32) // <-- BUTCHERED ``` **(0.b)** Furthermore, it broke parity with middle cleaning (which includes inlined cross-crate re-exports) re-regressing parts of rust-lang#44306 I once fixed in PR rust-lang#103885. **(1)** Lastly, PR rust-lang#139035 introduced an ICE triggered by the following input file: ```rs trait Trait { fn anon(()) {} } // internal error: entered unreachable code ``` --- This PR fixes all of these regressions and in the first commit renames several types and fns to be more ~~correct~~ descriptive and legible. ~~It also refactors `Param.name` to be of type `Option<Symbol>` instead `Symbol` (where `None` ~ `kw::Empty`), so rendering mistakes like that can no longer creep in like that (ignoring tests). CC rust-lang#137978.~~ Independently done in PR rust-lang#139846 a day prior.
…onszelmann Remove `name_or_empty` Another step towards rust-lang#137978. r? ``@jdonszelmann``
…ng, r=GuillaumeGomez rustdoc/clean: Fix lowering of fn params (fixes correctness & HIR vs. middle parity regressions) **(0)** PR rust-lang#136411 aimed to stop rendering unnamed params of fn ptr types as underscores in the common case (e.g., `fn(_: i32)` → `fn(i32)`) to make the rendered output stylistically more conventional. **(0.a)** However, since the cleaning fn that the PR modified is also used for lowering the HIR params of foreign fns and required assoc fns in traits, it accidentally butchered the rendering of the latter two: ```rs pub trait Trait { fn assoc_fn(_: i32); } // as well as (Rust 2015 only): fn assoc_fn(i32); unsafe extern "C" { pub fn foreign_fn(_: i32); } // Since 1.86 the fns above gets mis-rendered as: pub fn assoc_fn(: i32) // <-- BUTCHERED pub unsafe extern "C" fn foreign_fn(: i32) // <-- BUTCHERED ``` **(0.b)** Furthermore, it broke parity with middle cleaning (which includes inlined cross-crate re-exports) re-regressing parts of rust-lang#44306 I once fixed in PR rust-lang#103885. **(1)** Lastly, PR rust-lang#139035 introduced an ICE triggered by the following input file: ```rs trait Trait { fn anon(()) {} } // internal error: entered unreachable code ``` --- This PR fixes all of these regressions and in the first commit renames several types and fns to be more ~~correct~~ descriptive and legible. ~~It also refactors `Param.name` to be of type `Option<Symbol>` instead `Symbol` (where `None` ~ `kw::Empty`), so rendering mistakes like that can no longer creep in like that (ignoring tests). CC rust-lang#137978.~~ Independently done in PR rust-lang#139846 a day prior.
Rollup merge of rust-lang#139913 - fmease:rustdoc-fix-fn-param-handling, r=GuillaumeGomez rustdoc/clean: Fix lowering of fn params (fixes correctness & HIR vs. middle parity regressions) **(0)** PR rust-lang#136411 aimed to stop rendering unnamed params of fn ptr types as underscores in the common case (e.g., `fn(_: i32)` → `fn(i32)`) to make the rendered output stylistically more conventional. **(0.a)** However, since the cleaning fn that the PR modified is also used for lowering the HIR params of foreign fns and required assoc fns in traits, it accidentally butchered the rendering of the latter two: ```rs pub trait Trait { fn assoc_fn(_: i32); } // as well as (Rust 2015 only): fn assoc_fn(i32); unsafe extern "C" { pub fn foreign_fn(_: i32); } // Since 1.86 the fns above gets mis-rendered as: pub fn assoc_fn(: i32) // <-- BUTCHERED pub unsafe extern "C" fn foreign_fn(: i32) // <-- BUTCHERED ``` **(0.b)** Furthermore, it broke parity with middle cleaning (which includes inlined cross-crate re-exports) re-regressing parts of rust-lang#44306 I once fixed in PR rust-lang#103885. **(1)** Lastly, PR rust-lang#139035 introduced an ICE triggered by the following input file: ```rs trait Trait { fn anon(()) {} } // internal error: entered unreachable code ``` --- This PR fixes all of these regressions and in the first commit renames several types and fns to be more ~~correct~~ descriptive and legible. ~~It also refactors `Param.name` to be of type `Option<Symbol>` instead `Symbol` (where `None` ~ `kw::Empty`), so rendering mistakes like that can no longer creep in like that (ignoring tests). CC rust-lang#137978.~~ Independently done in PR rust-lang#139846 a day prior.
Rollup merge of rust-lang#139615 - nnethercote:rm-name_or_empty, r=jdonszelmann Remove `name_or_empty` Another step towards rust-lang#137978. r? ``@jdonszelmann``
…onszelmann Remove `name_or_empty` Another step towards rust-lang#137978. r? ``@jdonszelmann``
kw::Empty
is the name of the emptySymbol
. It's used a lot. Most places it's used, it's hard to tell if it means "empty symbol" or "no symbol". I.e. it more or less reinvents the null pointer, something that Rust was supposed to get rid of.I think a lot of the uses could be removed by using
Option<Symbol>
instead ofSymbol
, making the "no symbol" cases much clearer.The text was updated successfully, but these errors were encountered: