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

Rollup of 6 pull requests #105166

Merged
merged 16 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions compiler/rustc_builtin_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ mod log_syntax;
mod source_util;
mod test;
mod trace_macros;
mod type_ascribe;
mod util;

pub mod asm;
Expand Down Expand Up @@ -92,6 +93,7 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
unreachable: edition_panic::expand_unreachable,
stringify: source_util::expand_stringify,
trace_macros: trace_macros::expand_trace_macros,
type_ascribe: type_ascribe::expand_type_ascribe,
}

register_attr! {
Expand Down
35 changes: 35 additions & 0 deletions compiler/rustc_builtin_macros/src/type_ascribe.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
use rustc_ast::ptr::P;
use rustc_ast::tokenstream::TokenStream;
use rustc_ast::{token, Expr, ExprKind, Ty};
use rustc_errors::PResult;
use rustc_expand::base::{self, DummyResult, ExtCtxt, MacEager};
use rustc_span::Span;

pub fn expand_type_ascribe(
cx: &mut ExtCtxt<'_>,
span: Span,
tts: TokenStream,
) -> Box<dyn base::MacResult + 'static> {
let (expr, ty) = match parse_ascribe(cx, tts) {
Ok(parsed) => parsed,
Err(mut err) => {
err.emit();
return DummyResult::any(span);
}
};

let asc_expr = cx.expr(span, ExprKind::Type(expr, ty));

return MacEager::expr(asc_expr);
}

fn parse_ascribe<'a>(cx: &mut ExtCtxt<'a>, stream: TokenStream) -> PResult<'a, (P<Expr>, P<Ty>)> {
let mut parser = cx.new_parser_from_tts(stream);

let expr = parser.parse_expr()?;
parser.expect(&token::Comma)?;

let ty = parser.parse_ty()?;

Ok((expr, ty))
}
8 changes: 4 additions & 4 deletions compiler/rustc_const_eval/src/transform/promote_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,14 @@ impl<'tcx> Validator<'_, 'tcx> {
match elem {
ProjectionElem::Deref => {
let mut promotable = false;
// When a static is used by-value, that gets desugared to `*STATIC_ADDR`,
// and we need to be able to promote this. So check if this deref matches
// that specific pattern.

// We need to make sure this is a `Deref` of a local with no further projections.
// Discussion can be found at
// https://github.com/rust-lang/rust/pull/74945#discussion_r463063247
if let Some(local) = place_base.as_local() {
// This is a special treatment for cases like *&STATIC where STATIC is a
// global static variable.
// This pattern is generated only when global static variables are directly
// accessed and is qualified for promotion safely.
if let TempState::Defined { location, .. } = self.temps[local] {
let def_stmt = self.body[location.block]
.statements
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1488,6 +1488,7 @@ symbols! {
ty,
type_alias_enum_variants,
type_alias_impl_trait,
type_ascribe,
type_ascription,
type_changing_struct_update,
type_id,
Expand Down
5 changes: 2 additions & 3 deletions library/alloc/src/collections/vec_deque/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,10 +566,9 @@ impl<T, A: Allocator> VecDeque<T, A> {
///
/// let deque: VecDeque<u32> = VecDeque::new();
/// ```
// FIXME: This should probably be const
#[inline]
#[unstable(feature = "allocator_api", issue = "32838")]
pub fn new_in(alloc: A) -> VecDeque<T, A> {
pub const fn new_in(alloc: A) -> VecDeque<T, A> {
VecDeque { head: 0, len: 0, buf: RawVec::new_in(alloc) }
}

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

self.head = tail;
} else {
// ´free` is smaller than both `head_len` and `tail_len`.
// `free` is smaller than both `head_len` and `tail_len`.
// the general algorithm for this first moves the slices
// right next to each other and then uses `slice::rotate`
// to rotate them into place:
Expand Down
12 changes: 12 additions & 0 deletions library/core/src/macros/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,18 @@ pub(crate) mod builtin {
/* compiler built-in */
}

/// Unstable placeholder for type ascription.
#[rustc_builtin_macro]
#[unstable(
feature = "type_ascription",
issue = "23416",
reason = "placeholder syntax for type ascription"
)]
#[cfg(not(bootstrap))]
pub macro type_ascribe($expr:expr, $ty:ty) {
/* compiler built-in */
}

/// Unstable implementation detail of the `rustc` compiler, do not use.
#[rustc_builtin_macro]
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
8 changes: 8 additions & 0 deletions library/core/src/prelude/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,11 @@ pub use crate::macros::builtin::cfg_accessible;
reason = "`cfg_eval` is a recently implemented feature"
)]
pub use crate::macros::builtin::cfg_eval;

#[unstable(
feature = "type_ascription",
issue = "23416",
reason = "placeholder syntax for type ascription"
)]
#[cfg(not(bootstrap))]
pub use crate::macros::builtin::type_ascribe;
2 changes: 1 addition & 1 deletion library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ impl File {
/// Ok(())
/// }
/// ```
#[unstable(feature = "file_create_new", issue = "none")]
#[unstable(feature = "file_create_new", issue = "105135")]
pub fn create_new<P: AsRef<Path>>(path: P) -> io::Result<File> {
OpenOptions::new().read(true).write(true).create_new(true).open(path.as_ref())
}
Expand Down
9 changes: 9 additions & 0 deletions library/std/src/prelude/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ pub use core::prelude::v1::cfg_accessible;
)]
pub use core::prelude::v1::cfg_eval;

// Do not `doc(no_inline)` either.
#[unstable(
feature = "type_ascription",
issue = "23416",
reason = "placeholder syntax for type ascription"
)]
#[cfg(not(bootstrap))]
pub use core::prelude::v1::type_ascribe;

// The file so far is equivalent to src/libcore/prelude/v1.rs,
// and below to src/liballoc/prelude.rs.
// Those files are duplicated rather than using glob imports
Expand Down
5 changes: 2 additions & 3 deletions src/librustdoc/html/static/css/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,7 @@ a.srclink,
#help-button > a,
details.rustdoc-toggle.top-doc > summary,
details.rustdoc-toggle.non-exhaustive > summary,
.scraped-example-title,
.more-examples-toggle summary, .more-examples-toggle .hide-more,
.example-links a,
.scraped-example-list,
/* This selector is for the items listed in the "all items" page. */
ul.all-items {
font-family: "Fira Sans", Arial, NanumBarunGothic, sans-serif;
Expand Down Expand Up @@ -1516,6 +1514,7 @@ details.rustdoc-toggle > summary::before {
display: inline-block;
vertical-align: middle;
opacity: .5;
filter: var(--toggle-filter);
}

details.rustdoc-toggle > summary.hideme > span,
Expand Down
5 changes: 1 addition & 4 deletions src/librustdoc/html/static/css/themes/ayu.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Original by Dempfi (https://github.com/dempfi/ayu)
--right-side-color: grey;
--code-attribute-color: #999;
--toggles-color: #999;
--toggle-filter: invert(100%);
--search-input-focused-border-color: #5c6773; /* Same as `--border-color`. */
--copy-path-button-color: #fff;
--copy-path-img-filter: invert(70%);
Expand Down Expand Up @@ -158,10 +159,6 @@ body.source .example-wrap pre.rust a {
background: #333;
}

details.rustdoc-toggle > summary::before {
filter: invert(100%);
}

.module-item .stab,
.import-item .stab {
color: #000;
Expand Down
5 changes: 1 addition & 4 deletions src/librustdoc/html/static/css/themes/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
--right-side-color: grey;
--code-attribute-color: #999;
--toggles-color: #999;
--toggle-filter: invert(100%);
--search-input-focused-border-color: #008dfd;
--copy-path-button-color: #999;
--copy-path-img-filter: invert(50%);
Expand Down Expand Up @@ -89,10 +90,6 @@ body.source .example-wrap pre.rust a {
background: #333;
}

details.rustdoc-toggle > summary::before {
filter: invert(100%);
}

#titles > button:not(.selected) {
background-color: #252525;
border-top-color: #252525;
Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/html/static/css/themes/light.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
--right-side-color: grey;
--code-attribute-color: #999;
--toggles-color: #999;
--toggle-filter: none;
--search-input-focused-border-color: #66afe9;
--copy-path-button-color: #999;
--copy-path-img-filter: invert(50%);
Expand Down
8 changes: 8 additions & 0 deletions src/test/rustdoc-gui/scrape-examples-fonts.goml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
goto: "file://" + |DOC_PATH| + "/scrape_examples/fn.test_many.html"

store-value: (font, '"Fira Sans", Arial, NanumBarunGothic, sans-serif')

wait-for-css: (".scraped-example-title", {"font-family": |font|})
wait-for-css: (".more-examples-toggle summary", {"font-family": |font|})
wait-for-css: (".more-examples-toggle .hide-more", {"font-family": |font|})
wait-for-css: (".example-links a", {"font-family": |font|})
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
scrape_examples::test_many();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
scrape_examples::test_many();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
scrape_examples::test_many();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
scrape_examples::test_many();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
scrape_examples::test_many();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
scrape_examples::test_many();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
scrape_examples::test_many();
}
2 changes: 2 additions & 0 deletions src/test/rustdoc-gui/src/scrape_examples/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
/// test();
/// ```
pub fn test() {}

pub fn test_many() {}
29 changes: 29 additions & 0 deletions src/test/rustdoc-gui/toggle-docs.goml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,32 @@ assert-attribute-false: (
click: "#toggle-all-docs"
wait-for-text: ("#toggle-all-docs", "[−]")
assert-attribute: ("details.rustdoc-toggle", {"open": ""}, ALL)

// Checking the toggles style.
show-text: true
define-function: (
"check-color",
(theme, filter),
[
// Setting the theme.
("local-storage", {"rustdoc-theme": |theme|, "rustdoc-use-system-theme": "false"}),
// We reload the page so the local storage settings are being used.
("reload"),

("assert-css", ("details.rustdoc-toggle > summary::before", {
"opacity": "0.5",
"filter": |filter|,
}, ALL)),
("move-cursor-to", "details.rustdoc-toggle summary"),
("assert-css", ("details.rustdoc-toggle > summary:hover::before", {
"opacity": "1",
"filter": |filter|,
})),
// moving the cursor somewhere else to not mess with next function calls.
("move-cursor-to", ".search-input"),
]
)

call-function: ("check-color", {"theme": "ayu", "filter": "invert(1)"})
call-function: ("check-color", {"theme": "dark", "filter": "invert(1)"})
call-function: ("check-color", {"theme": "light", "filter": "none"})
8 changes: 5 additions & 3 deletions src/test/ui/associated-consts/issue-93835.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#![feature(type_ascription)]

fn e() {
p:a<p:p<e=6>>
//~^ ERROR comparison operators
type_ascribe!(p, a<p:p<e=6>>);
//~^ ERROR cannot find type `a` in this scope
//~| ERROR cannot find value
//~| ERROR associated const equality
//~| ERROR associated const equality
//~| ERROR cannot find trait `p` in this scope
//~| ERROR associated type bounds
}

Expand Down
65 changes: 20 additions & 45 deletions src/test/ui/associated-consts/issue-93835.stderr
Original file line number Diff line number Diff line change
@@ -1,65 +1,40 @@
error: comparison operators cannot be chained
--> $DIR/issue-93835.rs:2:8
|
LL | fn e() {
| - while parsing this struct
LL | p:a<p:p<e=6>>
| ^ ^
|
= help: use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments
= help: or use `(...)` if you meant to specify fn arguments

error[E0425]: cannot find value `p` in this scope
--> $DIR/issue-93835.rs:2:5
|
LL | p:a<p:p<e=6>>
| ^ not found in this scope
|
help: you might have meant to write a `struct` literal
|
LL ~ fn e() { SomeStruct {
LL | p:a<p:p<e=6>>
...
LL |
LL ~ }}
--> $DIR/issue-93835.rs:4:19
|
help: maybe you meant to write a path separator here
|
LL | p::a<p:p<e=6>>
| ~~
help: maybe you meant to write an assignment here
|
LL | let p:a<p:p<e=6>>
| ~~~~~
LL | type_ascribe!(p, a<p:p<e=6>>);
| ^ not found in this scope

error[E0658]: associated const equality is incomplete
--> $DIR/issue-93835.rs:2:13
error[E0412]: cannot find type `a` in this scope
--> $DIR/issue-93835.rs:4:22
|
LL | p:a<p:p<e=6>>
| ^^^
LL | type_ascribe!(p, a<p:p<e=6>>);
| ^ not found in this scope

error[E0405]: cannot find trait `p` in this scope
--> $DIR/issue-93835.rs:4:26
|
= note: see issue #92827 <https://github.com/rust-lang/rust/issues/92827> for more information
= help: add `#![feature(associated_const_equality)]` to the crate attributes to enable
LL | type_ascribe!(p, a<p:p<e=6>>);
| ^ not found in this scope

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

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

error: aborting due to 5 previous errors

Some errors have detailed explanations: E0425, E0658.
For more information about an error, try `rustc --explain E0425`.
Some errors have detailed explanations: E0405, E0412, E0425, E0658.
For more information about an error, try `rustc --explain E0405`.
Loading