The `from_str` implementation from the example had an `unwrap` that would make it panic on invalid input strings. Instead of panicking, it nows returns an error to better reflect the intented behavior of the `FromStr` trait.
Matthias Krüger [Sat, 1 Oct 2022 14:45:05 +0000 (16:45 +0200)]
Rollup merge of #102533 - notriddle:notriddle/a-source, r=Dylan-DPC
rustdoc: remove unused CSS selector `a.source`
The link with this class attribute was removed in https://github.com/rust-lang/rust/commit/4d16de01d0beb84dc4a351022ea5cb587b4ab557#diff-3fe025bd3bd6b48044d0bd8d8c3122de5ecdb1dcd72a9dbe3c24430883595012L1281-R1324
Matthias Krüger [Sat, 1 Oct 2022 14:45:04 +0000 (16:45 +0200)]
Rollup merge of #101675 - beetrees:set-times-no-panic, r=joshtriplett
Improve `File::set_times` error handling
Makes `File::set_times` return an error if the `SystemTime` cannot fit into the required type instead of panicking in `FileTimes::set_{accessed,modified}`. Also makes `File::set_times` return an error on Windows if either of the passed times are `0xFFFF_FFFF_FFFF_FFFF`, as [the documentation for `SetFileTime`](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-setfiletime) states that this will prevent operations on the file handle from updating the corresponding file time instead of setting the corresponding file time to that value.
bors [Sat, 1 Oct 2022 14:15:29 +0000 (14:15 +0000)]
Auto merge of #102519 - Alexendoo:format-args-macro-str, r=m-ou-se
Fix `format_args` capture for macro expanded format strings
Since #100996 `format_args` capture for macro expanded strings aren't prevented when the span of the expansion points to a string literal, e.g.
```rust
// not a terribly realistic example, but also happens for proc_macros that set
// the span of the output to an input str literal, such as indoc
macro_rules! x {
($e:expr) => { $e }
}
fn main() {
let a = 1;
println!(x!("{a}"));
}
```
The tests didn't catch it as the span of `concat!()` points to the macro invocation
bors [Sat, 1 Oct 2022 10:44:25 +0000 (10:44 +0000)]
Auto merge of #101986 - WaffleLapkin:move_lint_note_to_the_bottom, r=estebank
Move lint level source explanation to the bottom
So, uhhhhh
r? `@estebank`
## User-facing change
"note: `#[warn(...)]` on by default" and such are moved to the bottom of the diagnostic:
```diff
- = note: `#[warn(unsupported_calling_conventions)]` on by default
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #87678 <https://github.com/rust-lang/rust/issues/87678>
+ = note: `#[warn(unsupported_calling_conventions)]` on by default
```
Why warning is enabled is the least important thing, so it shouldn't be the first note the user reads, IMO.
## Developer-facing change
`struct_span_lint` and similar methods have a different signature.
The reason for this is that `struct_span_lint` needs to edit the diagnostic _after_ `decorate` closure is called. This also makes lint code a little bit nicer in my opinion.
Another option is to use `impl for<'a> FnOnce(LintDiagnosticBuilder<'a, ()>) -> DiagnosticBuilder<'a, ()>` altough I don't _really_ see reasons to do `let lint = lint.build(message)` everywhere.
## Subtle problem
By moving the message outside of the closure (that may not be called if the lint is disabled) `format!(...)` is executed earlier, possibly formatting `Ty` which may call a query that trims paths that crashes the compiler if there were no warnings...
I don't think it's that big of a deal, considering that we move from `format!(...)` to `fluent` (which is lazy by-default) anyway, however this required adding a workaround which is unfortunate.
## P.S.
I'm sorry, I do not how to make this PR smaller/easier to review. Changes to the lint API affect SO MUCH 😢
bors [Sat, 1 Oct 2022 08:14:25 +0000 (08:14 +0000)]
Auto merge of #102237 - GuillaumeGomez:sidebar-links-color, r=notriddle
Migrate sidebar links color to CSS variables and unify themes with ayu
Part of https://github.com/rust-lang/rust/pull/98460.
This PR does two things:
1. Migrate more theme CSS rules toward CSS variables.
2. Remove `a.current` specific colors depending on the kind of the item behind the link. The `ayu` theme was already doing it this way and I think it makes much more sense like this.
You can test it [here](https://rustdoc.crud.net/imperio/sidebar-links-color/lib2/struct.Foo.html) by hovering other module's items in the sidebar (or check the selector `a.current`).
bors [Sat, 1 Oct 2022 03:56:21 +0000 (03:56 +0000)]
Auto merge of #102526 - matthiaskrgr:rollup-9o6p98c, r=matthiaskrgr
Rollup of 7 pull requests
Successful merges:
- #102361 (Fix ICE in const_trait check code)
- #102373 (Flush delayed bugs before codegen)
- #102483 (create def ids for impl traits during ast lowering)
- #102490 (Generate synthetic region from `impl` even in closure body within an associated fn)
- #102492 (Don't lower assoc bindings just to deny them)
- #102493 (Group together more size assertions.)
- #102521 (rustdoc: add missing margin to no-docblock methods)
Rollup merge of #102521 - notriddle:notriddle/impl-items-section, r=GuillaumeGomez
rustdoc: add missing margin to no-docblock methods
Fixes another regression caused by 8846c0853d8687fda0e5f23f6687b03b243980ee, this time fixing the appearance of methods that have no docblock (we didn't notice this one because libstd docs *always* have docblocks).
See how it looks at https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc/clean/types/enum.Type.html#implementations
Rollup merge of #102373 - Nilstrieb:cannot-get-layout-of-branch-error, r=cjgillot
Flush delayed bugs before codegen
Sometimes it can happen that invalid code like a TyKind::Error makes its way through the compiler without triggering any errors (this is always a bug in rustc but bugs do happen sometimes :)). These ICEs will manifest in the backend like as cg_llvm not being able to get the layout of `[type error]`, which makes it hard to debug. By flushing before codegen, we display all the delayed bugs, making it easier to trace it to the root of the problem.
I tried this on #102366 and it showed tons of of delayed bugs and no error in cg_llvm, so it seems to be working.
Auto merge of #102520 - matthiaskrgr:rollup-7nreat0, r=matthiaskrgr
Rollup of 6 pull requests
Successful merges:
- #102276 (Added more const_closure functionality)
- #102382 (Manually order `DefId` on 64-bit big-endian)
- #102421 (remove the unused :: between trait and type to give user correct diag…)
- #102495 (Reinstate `hir-stats.rs` test for stage 1.)
- #102505 (rustdoc: remove no-op CSS `h3.variant, .sub-variant h4 { border-bottom: none }`)
- #102506 (Specify `DynKind::Dyn`)
Michael Howell [Fri, 30 Sep 2022 17:15:59 +0000 (10:15 -0700)]
rustdoc: add missing margin to no-docblock trait items
Fixes another regression caused by 8846c0853d8687fda0e5f23f6687b03b243980ee,
this time fixing the appearance of methods that have no docblock (we didn't
notice this one because libstd docs *always* have docblocks).
See how it looks at https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc/clean/types/trait.AttributesExt.html
Rollup merge of #102495 - nnethercote:reinstate-hir-stats, r=lqd
Reinstate `hir-stats.rs` test for stage 1.
It was disabled in #94075 for stage 1 because that PR changed type layouts such that the results for this test were different for stage 1 and stage 2. But now that #94075 is in beta, the results for this test are now the same for stage 1 and stage 2.
Rollup merge of #102421 - lyming2007:issue-101866, r=lcnr
remove the unused :: between trait and type to give user correct diag…
…nostic information
modified: compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
new file: src/test/ui/type/issue-101866.rs
new file: src/test/ui/type/issue-101866.stderr
Rollup merge of #102382 - cuviper:defid-order, r=fee1-dead
Manually order `DefId` on 64-bit big-endian
`DefId` uses different field orders on 64-bit big-endian vs. others, in
order to optimize its `Hash` implementation. However, that also made it
derive different lexical ordering for `PartialOrd` and `Ord`. That
caused spurious differences wherever `DefId`s are sorted, like the
candidate sources list in `report_method_error`.
Now we manually implement `PartialOrd` and `Ord` on 64-bit big-endian to
match the same lexical ordering as other targets, fixing at least one
test, `src/test/ui/methods/method-ambig-two-traits-cross-crate.rs`.
Michael Howell [Fri, 30 Sep 2022 16:42:07 +0000 (09:42 -0700)]
rustdoc: add missing margin to no-docblock methods
Fixes another regression caused by 8846c0853d8687fda0e5f23f6687b03b243980ee,
this time fixing the appearance of methods that have no docblock (we didn't
notice this one because libstd docs *always* have docblocks).
See how it looks without the fix at https://doc.rust-lang.org/nightly/nightly-rustc/rustdoc/clean/types/enum.Type.html#implementations
Auto merge of #102484 - beetrees:duration-debug-bug-fix, r=scottmcm
Fix integer overflow in `format!("{:.0?}", Duration::MAX)`
Currently `format!("{:.0?}", Duration::MAX)` causes an integer overflow in the `Duration` `Debug` impl ([playground link](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=67675c6895bdb2e37ee727f0ed7622b2)). This is because the carry from the rounding of the fractional_part into the integer_part will cause the integer_part to overflow as it is already `u64::MAX`. This PR uses a larger integer type to avoid that issue, and adds a test for the correct behaviour.
Rollup merge of #102491 - notriddle:notriddle/sidebar-opacity, r=GuillaumeGomez
rustdoc: remove no-op source sidebar `opacity`
These rules were added in dc2c9723343c985740be09919236a6e96c4e4433 to work with CSS transitions. They're otherwise redundant, since the `visibility` property already hides everything.
```
Compiling playground v0.0.1 (/playground)
error: functions are not allowed in struct definitions
--> src/main.rs:4:5
|
4 | fn
| ^^
|
= help: unlike in C++, Java, and C#, functions are declared in `impl` blocks
= help: see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information
error: could not compile `playground` due to previous error
```
In this case, rustc should suggest escaping `fn` to use it as an identifier.
It was disabled in #94075 for stage 1 because that PR changed type
layouts such that the results for this test were different for stage 1
and stage 2. But now that #94075 is in beta, the results for this test
are now the same for stage 1 and stage 2.
Michael Howell [Thu, 29 Sep 2022 22:33:02 +0000 (15:33 -0700)]
rustdoc: remove no-op source sidebar `opacity`
These rules were added in dc2c9723343c985740be09919236a6e96c4e4433 to work
with CSS transitions. They're otherwise redundant, since the `visibility`
property already hides everything.
Yiming Lei [Wed, 28 Sep 2022 16:59:03 +0000 (09:59 -0700)]
remove the unused :: between trait and type to give user correct diagnostic information
modified: compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs
new file: src/test/ui/type/issue-101866.rs
new file: src/test/ui/type/issue-101866.stderr
Auto merge of #102482 - notriddle:rollup-fjm618g, r=notriddle
Rollup of 7 pull requests
Successful merges:
- #102214 (Fix span of byte-escaped left format args brace)
- #102426 (Don't export `__wasm_init_memory` on WebAssembly.)
- #102437 (rustdoc: cut margin-top from first header in docblock)
- #102442 (rustdoc: remove bad CSS font-weight on `.impl`, `.method`, etc)
- #102447 (rustdoc: add method spacing to trait methods)
- #102468 (tidy: make rustc dependency error less confusing)
- #102476 (Split out the error reporting logic into a separate function)
Michael Howell [Thu, 29 Sep 2022 17:15:20 +0000 (10:15 -0700)]
Rollup merge of #102476 - oli-obk:split_error_path, r=cjgillot
Split out the error reporting logic into a separate function
I was trying to read the function and got distracted by the huge block of code in the middle of it. Turns out it only reports diagnostics and all paths within it end in an error. The main function is now more readable imo.
Michael Howell [Thu, 29 Sep 2022 17:15:20 +0000 (10:15 -0700)]
Rollup merge of #102468 - RalfJung:tidy, r=jyn514
tidy: make rustc dependency error less confusing
The current wording leads to very confusing messages:
```
tidy error: Dependencies for main workspace not explicitly permitted:
* unicode-ident 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)
```
Miri is part of that workspace, and there never was a problem adding Miri dependencies. The actual error is that due to a crate bump this now showed up as a rustc dependency, and *those* are restricted.
Michael Howell [Thu, 29 Sep 2022 17:15:19 +0000 (10:15 -0700)]
Rollup merge of #102442 - notriddle:notriddle/header-weight, r=GuillaumeGomez
rustdoc: remove bad CSS font-weight on `.impl`, `.method`, etc
This line was added in c494a06064017f307a8d9dc4797e614d2ed99143, because at the time, the headers had these classes on them. Now, the headers are children of the `<section>` with the class on it.
This commit also adds a test case, to make sure the srclink font weight does not regress again.
Michael Howell [Thu, 29 Sep 2022 17:15:17 +0000 (10:15 -0700)]
Rollup merge of #102214 - cassaundra:fix-format-args-span, r=cjgillot
Fix span of byte-escaped left format args brace
Fix #102057 (see issue for example).
Previously, the use of escaped left braces (`\x7B`) in format args resulted in an incorrectly offset span. This patch fixes that by considering any escaped characters within the string instead of using a constant offset.
Auto merge of #101893 - oli-obk:lift_derive, r=lcnr
Fix perf regression from TypeVisitor changes
Regression occurred in https://github.com/rust-lang/rust/pull/101858#issuecomment-1248732579
Instead of just reverting, we only fixed part of the regression. The main regression was due to actually correctly visiting a type that contains types and consts and should therefor be visited. This is not actually observable (yet?), but we should still do it correctly instead of risking major bugs in the future.
Auto merge of #102471 - Dylan-DPC:rollup-ij3okjt, r=Dylan-DPC
Rollup of 7 pull requests
Successful merges:
- #102336 (Fix associated type bindings with anon const in GAT position)
- #102342 (Add negation methods for signed non-zero integers.)
- #102385 (Don't export `__heap_base` and `__data_end` on wasm32-wasi.)
- #102435 (Improve example of Iterator::reduce)
- #102436 (rustdoc: clean up "normalize.css 8" input override CSS)
- #102452 (fix minor ungrammatical sentence)
- #102455 (Use let-chaining in `WhileTrue::check_expr`.)
Rollup merge of #102436 - notriddle:notriddle/normalize-form, r=GuillaumeGomez
rustdoc: clean up "normalize.css 8" input override CSS
These rules were copied from normalize.css 3, and are mostly redundant.
* `optgroup` isn't used in rustdoc at all
* `textarea` is only used for the "copy" button, so it's not visible
* The remaining buttons and inputs mostly have styles set anyway.
* We should never be setting `color` without also setting the background to something. Otherwise, you get white-on-gray text. That seems to be [the reason] why `normalize.css` changed this.
Rollup merge of #102385 - sunfishcode:sunfishcode/wasm-no-export-heap-base, r=davidtwco
Don't export `__heap_base` and `__data_end` on wasm32-wasi.
`__heap_base` and `__data_end` are exported for use by wasm-bindgen, which uses the wasm32-unknown-unknown target. On wasm32-wasi, as a step toward implementing the Canonical ABI, and as an aid to building speicalized WASI API polyfill wrappers, don't export `__heap_base` and `__data_end` on wasm32-wasi.
Rollup merge of #102342 - jmillikin:nonzero-negation, r=scottmcm
Add negation methods for signed non-zero integers.
Performing negation with defined wrapping semantics (such as `wrapping_neg()`) on a non-zero integer currently requires unpacking to a primitive and re-wrapping. Since negation of non-zero signed integers always produces a non-zero result, it is safe to implement the various `*_neg()` methods for `NonZeroI{N}`.
I'm not sure what to do about the `#[unstable(..., issue = "none")]` here -- should I file a tracking issue, or is that handled by the Rust dev team?
Rollup merge of #102336 - compiler-errors:issue-102333, r=jackh726
Fix associated type bindings with anon const in GAT position
The first commit formats `type_of.rs`, which is really hard to maintain since it uses a bunch of features like `let`-chains and `if let` match arm bindings. Best if you just review the second two diffs.