Skip to content

Commit cef44f5

Browse files
committed
Auto merge of #105166 - matthiaskrgr:rollup-s9l6vt2, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #104614 (Add `type_ascribe!` macro as placeholder syntax for type ascription) - #105126 (Make `VecDeque::new_in` unstably const) - #105132 (Migrate summary toggle filter to CSS variable) - #105136 (clarify comment on Deref promotion) - #105137 (Add tracking issue number for `file_create_new` feature) - #105143 (rustdoc: use simpler CSS for setting the font on scraped examples) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 11663b1 + 8e059d5 commit cef44f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+337
-243
lines changed

compiler/rustc_builtin_macros/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ mod log_syntax;
4545
mod source_util;
4646
mod test;
4747
mod trace_macros;
48+
mod type_ascribe;
4849
mod util;
4950

5051
pub mod asm;
@@ -92,6 +93,7 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
9293
unreachable: edition_panic::expand_unreachable,
9394
stringify: source_util::expand_stringify,
9495
trace_macros: trace_macros::expand_trace_macros,
96+
type_ascribe: type_ascribe::expand_type_ascribe,
9597
}
9698

9799
register_attr! {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
use rustc_ast::ptr::P;
2+
use rustc_ast::tokenstream::TokenStream;
3+
use rustc_ast::{token, Expr, ExprKind, Ty};
4+
use rustc_errors::PResult;
5+
use rustc_expand::base::{self, DummyResult, ExtCtxt, MacEager};
6+
use rustc_span::Span;
7+
8+
pub fn expand_type_ascribe(
9+
cx: &mut ExtCtxt<'_>,
10+
span: Span,
11+
tts: TokenStream,
12+
) -> Box<dyn base::MacResult + 'static> {
13+
let (expr, ty) = match parse_ascribe(cx, tts) {
14+
Ok(parsed) => parsed,
15+
Err(mut err) => {
16+
err.emit();
17+
return DummyResult::any(span);
18+
}
19+
};
20+
21+
let asc_expr = cx.expr(span, ExprKind::Type(expr, ty));
22+
23+
return MacEager::expr(asc_expr);
24+
}
25+
26+
fn parse_ascribe<'a>(cx: &mut ExtCtxt<'a>, stream: TokenStream) -> PResult<'a, (P<Expr>, P<Ty>)> {
27+
let mut parser = cx.new_parser_from_tts(stream);
28+
29+
let expr = parser.parse_expr()?;
30+
parser.expect(&token::Comma)?;
31+
32+
let ty = parser.parse_ty()?;
33+
34+
Ok((expr, ty))
35+
}

compiler/rustc_const_eval/src/transform/promote_consts.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,14 @@ impl<'tcx> Validator<'_, 'tcx> {
318318
match elem {
319319
ProjectionElem::Deref => {
320320
let mut promotable = false;
321+
// When a static is used by-value, that gets desugared to `*STATIC_ADDR`,
322+
// and we need to be able to promote this. So check if this deref matches
323+
// that specific pattern.
324+
321325
// We need to make sure this is a `Deref` of a local with no further projections.
322326
// Discussion can be found at
323327
// https://github.com/rust-lang/rust/pull/74945#discussion_r463063247
324328
if let Some(local) = place_base.as_local() {
325-
// This is a special treatment for cases like *&STATIC where STATIC is a
326-
// global static variable.
327-
// This pattern is generated only when global static variables are directly
328-
// accessed and is qualified for promotion safely.
329329
if let TempState::Defined { location, .. } = self.temps[local] {
330330
let def_stmt = self.body[location.block]
331331
.statements

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1488,6 +1488,7 @@ symbols! {
14881488
ty,
14891489
type_alias_enum_variants,
14901490
type_alias_impl_trait,
1491+
type_ascribe,
14911492
type_ascription,
14921493
type_changing_struct_update,
14931494
type_id,

library/alloc/src/collections/vec_deque/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -566,10 +566,9 @@ impl<T, A: Allocator> VecDeque<T, A> {
566566
///
567567
/// let deque: VecDeque<u32> = VecDeque::new();
568568
/// ```
569-
// FIXME: This should probably be const
570569
#[inline]
571570
#[unstable(feature = "allocator_api", issue = "32838")]
572-
pub fn new_in(alloc: A) -> VecDeque<T, A> {
571+
pub const fn new_in(alloc: A) -> VecDeque<T, A> {
573572
VecDeque { head: 0, len: 0, buf: RawVec::new_in(alloc) }
574573
}
575574

@@ -2152,7 +2151,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
21522151

21532152
self.head = tail;
21542153
} else {
2155-
// ´free` is smaller than both `head_len` and `tail_len`.
2154+
// `free` is smaller than both `head_len` and `tail_len`.
21562155
// the general algorithm for this first moves the slices
21572156
// right next to each other and then uses `slice::rotate`
21582157
// to rotate them into place:

library/core/src/macros/mod.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1546,6 +1546,18 @@ pub(crate) mod builtin {
15461546
/* compiler built-in */
15471547
}
15481548

1549+
/// Unstable placeholder for type ascription.
1550+
#[rustc_builtin_macro]
1551+
#[unstable(
1552+
feature = "type_ascription",
1553+
issue = "23416",
1554+
reason = "placeholder syntax for type ascription"
1555+
)]
1556+
#[cfg(not(bootstrap))]
1557+
pub macro type_ascribe($expr:expr, $ty:ty) {
1558+
/* compiler built-in */
1559+
}
1560+
15491561
/// Unstable implementation detail of the `rustc` compiler, do not use.
15501562
#[rustc_builtin_macro]
15511563
#[stable(feature = "rust1", since = "1.0.0")]

library/core/src/prelude/v1.rs

+8
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,11 @@ pub use crate::macros::builtin::cfg_accessible;
9898
reason = "`cfg_eval` is a recently implemented feature"
9999
)]
100100
pub use crate::macros::builtin::cfg_eval;
101+
102+
#[unstable(
103+
feature = "type_ascription",
104+
issue = "23416",
105+
reason = "placeholder syntax for type ascription"
106+
)]
107+
#[cfg(not(bootstrap))]
108+
pub use crate::macros::builtin::type_ascribe;

library/std/src/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ impl File {
401401
/// Ok(())
402402
/// }
403403
/// ```
404-
#[unstable(feature = "file_create_new", issue = "none")]
404+
#[unstable(feature = "file_create_new", issue = "105135")]
405405
pub fn create_new<P: AsRef<Path>>(path: P) -> io::Result<File> {
406406
OpenOptions::new().read(true).write(true).create_new(true).open(path.as_ref())
407407
}

library/std/src/prelude/v1.rs

+9
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ pub use core::prelude::v1::cfg_accessible;
8585
)]
8686
pub use core::prelude::v1::cfg_eval;
8787

88+
// Do not `doc(no_inline)` either.
89+
#[unstable(
90+
feature = "type_ascription",
91+
issue = "23416",
92+
reason = "placeholder syntax for type ascription"
93+
)]
94+
#[cfg(not(bootstrap))]
95+
pub use core::prelude::v1::type_ascribe;
96+
8897
// The file so far is equivalent to src/libcore/prelude/v1.rs,
8998
// and below to src/liballoc/prelude.rs.
9099
// Those files are duplicated rather than using glob imports

src/librustdoc/html/static/css/rustdoc.css

+2-3
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,7 @@ a.srclink,
197197
#help-button > a,
198198
details.rustdoc-toggle.top-doc > summary,
199199
details.rustdoc-toggle.non-exhaustive > summary,
200-
.scraped-example-title,
201-
.more-examples-toggle summary, .more-examples-toggle .hide-more,
202-
.example-links a,
200+
.scraped-example-list,
203201
/* This selector is for the items listed in the "all items" page. */
204202
ul.all-items {
205203
font-family: "Fira Sans", Arial, NanumBarunGothic, sans-serif;
@@ -1516,6 +1514,7 @@ details.rustdoc-toggle > summary::before {
15161514
display: inline-block;
15171515
vertical-align: middle;
15181516
opacity: .5;
1517+
filter: var(--toggle-filter);
15191518
}
15201519

15211520
details.rustdoc-toggle > summary.hideme > span,

src/librustdoc/html/static/css/themes/ayu.css

+1-4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Original by Dempfi (https://github.com/dempfi/ayu)
2121
--right-side-color: grey;
2222
--code-attribute-color: #999;
2323
--toggles-color: #999;
24+
--toggle-filter: invert(100%);
2425
--search-input-focused-border-color: #5c6773; /* Same as `--border-color`. */
2526
--copy-path-button-color: #fff;
2627
--copy-path-img-filter: invert(70%);
@@ -158,10 +159,6 @@ body.source .example-wrap pre.rust a {
158159
background: #333;
159160
}
160161

161-
details.rustdoc-toggle > summary::before {
162-
filter: invert(100%);
163-
}
164-
165162
.module-item .stab,
166163
.import-item .stab {
167164
color: #000;

src/librustdoc/html/static/css/themes/dark.css

+1-4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
--right-side-color: grey;
1717
--code-attribute-color: #999;
1818
--toggles-color: #999;
19+
--toggle-filter: invert(100%);
1920
--search-input-focused-border-color: #008dfd;
2021
--copy-path-button-color: #999;
2122
--copy-path-img-filter: invert(50%);
@@ -89,10 +90,6 @@ body.source .example-wrap pre.rust a {
8990
background: #333;
9091
}
9192

92-
details.rustdoc-toggle > summary::before {
93-
filter: invert(100%);
94-
}
95-
9693
#titles > button:not(.selected) {
9794
background-color: #252525;
9895
border-top-color: #252525;

src/librustdoc/html/static/css/themes/light.css

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
--right-side-color: grey;
1717
--code-attribute-color: #999;
1818
--toggles-color: #999;
19+
--toggle-filter: none;
1920
--search-input-focused-border-color: #66afe9;
2021
--copy-path-button-color: #999;
2122
--copy-path-img-filter: invert(50%);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
goto: "file://" + |DOC_PATH| + "/scrape_examples/fn.test_many.html"
2+
3+
store-value: (font, '"Fira Sans", Arial, NanumBarunGothic, sans-serif')
4+
5+
wait-for-css: (".scraped-example-title", {"font-family": |font|})
6+
wait-for-css: (".more-examples-toggle summary", {"font-family": |font|})
7+
wait-for-css: (".more-examples-toggle .hide-more", {"font-family": |font|})
8+
wait-for-css: (".example-links a", {"font-family": |font|})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
scrape_examples::test_many();
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
scrape_examples::test_many();
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
scrape_examples::test_many();
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
scrape_examples::test_many();
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
scrape_examples::test_many();
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
scrape_examples::test_many();
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
fn main() {
2+
scrape_examples::test_many();
3+
}

src/test/rustdoc-gui/src/scrape_examples/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@
55
/// test();
66
/// ```
77
pub fn test() {}
8+
9+
pub fn test_many() {}

src/test/rustdoc-gui/toggle-docs.goml

+29
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,32 @@ assert-attribute-false: (
4040
click: "#toggle-all-docs"
4141
wait-for-text: ("#toggle-all-docs", "[−]")
4242
assert-attribute: ("details.rustdoc-toggle", {"open": ""}, ALL)
43+
44+
// Checking the toggles style.
45+
show-text: true
46+
define-function: (
47+
"check-color",
48+
(theme, filter),
49+
[
50+
// Setting the theme.
51+
("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}),
52+
// We reload the page so the local storage settings are being used.
53+
("reload"),
54+
55+
("assert-css", ("details.rustdoc-toggle > summary::before", {
56+
"opacity": "0.5",
57+
"filter": |filter|,
58+
}, ALL)),
59+
("move-cursor-to", "details.rustdoc-toggle summary"),
60+
("assert-css", ("details.rustdoc-toggle > summary:hover::before", {
61+
"opacity": "1",
62+
"filter": |filter|,
63+
})),
64+
// moving the cursor somewhere else to not mess with next function calls.
65+
("move-cursor-to", ".search-input"),
66+
]
67+
)
68+
69+
call-function: ("check-color", {"theme": "ayu", "filter": "invert(1)"})
70+
call-function: ("check-color", {"theme": "dark", "filter": "invert(1)"})
71+
call-function: ("check-color", {"theme": "light", "filter": "none"})

src/test/ui/associated-consts/issue-93835.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
#![feature(type_ascription)]
2+
13
fn e() {
2-
p:a<p:p<e=6>>
3-
//~^ ERROR comparison operators
4+
type_ascribe!(p, a<p:p<e=6>>);
5+
//~^ ERROR cannot find type `a` in this scope
46
//~| ERROR cannot find value
57
//~| ERROR associated const equality
6-
//~| ERROR associated const equality
8+
//~| ERROR cannot find trait `p` in this scope
79
//~| ERROR associated type bounds
810
}
911

Original file line numberDiff line numberDiff line change
@@ -1,65 +1,40 @@
1-
error: comparison operators cannot be chained
2-
--> $DIR/issue-93835.rs:2:8
3-
|
4-
LL | fn e() {
5-
| - while parsing this struct
6-
LL | p:a<p:p<e=6>>
7-
| ^ ^
8-
|
9-
= help: use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments
10-
= help: or use `(...)` if you meant to specify fn arguments
11-
121
error[E0425]: cannot find value `p` in this scope
13-
--> $DIR/issue-93835.rs:2:5
14-
|
15-
LL | p:a<p:p<e=6>>
16-
| ^ not found in this scope
17-
|
18-
help: you might have meant to write a `struct` literal
19-
|
20-
LL ~ fn e() { SomeStruct {
21-
LL | p:a<p:p<e=6>>
22-
...
23-
LL |
24-
LL ~ }}
2+
--> $DIR/issue-93835.rs:4:19
253
|
26-
help: maybe you meant to write a path separator here
27-
|
28-
LL | p::a<p:p<e=6>>
29-
| ~~
30-
help: maybe you meant to write an assignment here
31-
|
32-
LL | let p:a<p:p<e=6>>
33-
| ~~~~~
4+
LL | type_ascribe!(p, a<p:p<e=6>>);
5+
| ^ not found in this scope
346

35-
error[E0658]: associated const equality is incomplete
36-
--> $DIR/issue-93835.rs:2:13
7+
error[E0412]: cannot find type `a` in this scope
8+
--> $DIR/issue-93835.rs:4:22
379
|
38-
LL | p:a<p:p<e=6>>
39-
| ^^^
10+
LL | type_ascribe!(p, a<p:p<e=6>>);
11+
| ^ not found in this scope
12+
13+
error[E0405]: cannot find trait `p` in this scope
14+
--> $DIR/issue-93835.rs:4:26
4015
|
41-
= note: see issue #92827 <https://github.com/rust-lang/rust/issues/92827> for more information
42-
= help: add `#![feature(associated_const_equality)]` to the crate attributes to enable
16+
LL | type_ascribe!(p, a<p:p<e=6>>);
17+
| ^ not found in this scope
4318

4419
error[E0658]: associated const equality is incomplete
45-
--> $DIR/issue-93835.rs:2:13
20+
--> $DIR/issue-93835.rs:4:28
4621
|
47-
LL | p:a<p:p<e=6>>
48-
| ^^^
22+
LL | type_ascribe!(p, a<p:p<e=6>>);
23+
| ^^^
4924
|
5025
= note: see issue #92827 <https://github.com/rust-lang/rust/issues/92827> for more information
5126
= help: add `#![feature(associated_const_equality)]` to the crate attributes to enable
5227

5328
error[E0658]: associated type bounds are unstable
54-
--> $DIR/issue-93835.rs:2:9
29+
--> $DIR/issue-93835.rs:4:24
5530
|
56-
LL | p:a<p:p<e=6>>
57-
| ^^^^^^^^
31+
LL | type_ascribe!(p, a<p:p<e=6>>);
32+
| ^^^^^^^^
5833
|
5934
= note: see issue #52662 <https://github.com/rust-lang/rust/issues/52662> for more information
6035
= help: add `#![feature(associated_type_bounds)]` to the crate attributes to enable
6136

6237
error: aborting due to 5 previous errors
6338

64-
Some errors have detailed explanations: E0425, E0658.
65-
For more information about an error, try `rustc --explain E0425`.
39+
Some errors have detailed explanations: E0405, E0412, E0425, E0658.
40+
For more information about an error, try `rustc --explain E0405`.

0 commit comments

Comments
 (0)