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 7 pull requests #97897

Closed
wants to merge 14 commits into from
Closed
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
61 changes: 57 additions & 4 deletions compiler/rustc_parse/src/parser/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,10 +360,7 @@ impl<'a> Parser<'a> {
let mutbl = self.parse_mutability();
self.parse_pat_ident(BindingMode::ByRef(mutbl))?
} else if self.eat_keyword(kw::Box) {
// Parse `box pat`
let pat = self.parse_pat_with_range_pat(false, None)?;
self.sess.gated_spans.gate(sym::box_patterns, lo.to(self.prev_token.span));
PatKind::Box(pat)
self.parse_pat_box()?
} else if self.check_inline_const(0) {
// Parse `const pat`
let const_expr = self.parse_const_block(lo.to(self.token.span), true)?;
Expand Down Expand Up @@ -915,6 +912,62 @@ impl<'a> Parser<'a> {
Ok(PatKind::TupleStruct(qself, path, fields))
}

/// Are we sure this could not possibly be the start of a pattern?
///
/// Currently, this only accounts for tokens that can follow identifiers
/// in patterns, but this can be extended as necessary.
fn isnt_pattern_start(&self) -> bool {
[
token::Eq,
token::Colon,
token::Comma,
token::Semi,
token::At,
token::OpenDelim(Delimiter::Brace),
token::CloseDelim(Delimiter::Brace),
token::CloseDelim(Delimiter::Parenthesis),
]
.contains(&self.token.kind)
}

/// Parses `box pat`
fn parse_pat_box(&mut self) -> PResult<'a, PatKind> {
let box_span = self.prev_token.span;

if self.isnt_pattern_start() {
self.struct_span_err(
self.token.span,
format!("expected pattern, found {}", super::token_descr(&self.token)),
)
.span_note(box_span, "`box` is a reserved keyword")
.span_suggestion_verbose(
box_span.shrink_to_lo(),
"escape `box` to use it as an identifier",
"r#",
Applicability::MaybeIncorrect,
)
.emit();

// We cannot use `parse_pat_ident()` since it will complain `box`
// is not an identifier.
let sub = if self.eat(&token::At) {
Some(self.parse_pat_no_top_alt(Some("binding pattern"))?)
} else {
None
};

Ok(PatKind::Ident(
BindingMode::ByValue(Mutability::Not),
Ident::new(kw::Box, box_span),
sub,
))
} else {
let pat = self.parse_pat_with_range_pat(false, None)?;
self.sess.gated_spans.gate(sym::box_patterns, box_span.to(self.prev_token.span));
Ok(PatKind::Box(pat))
}
}

/// Parses the fields of a struct-like pattern.
fn parse_pat_fields(&mut self) -> PResult<'a, (Vec<PatField>, bool)> {
let mut fields = Vec::new();
Expand Down
4 changes: 4 additions & 0 deletions library/core/src/iter/traits/iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ fn _assert_is_object_safe(_: &dyn Iterator<Item = ()>) {}
label = "`{Self}` is not an iterator; try calling `.into_iter()` or `.iter()`"
),
on(_Self = "&[]", label = "`{Self}` is not an iterator; try calling `.iter()`"),
on(
_Self = "std::vec::Vec<T, A>",
label = "`{Self}` is not an iterator; try calling `.into_iter()` or `.iter()`"
),
on(
_Self = "&str",
label = "`{Self}` is not an iterator; try calling `.chars()` or `.bytes()`"
Expand Down
14 changes: 14 additions & 0 deletions library/std/src/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,20 @@ static HOOK: AtomicPtr<()> = AtomicPtr::new(ptr::null_mut());
/// about the allocation that failed.
///
/// The allocation error hook is a global resource.
///
/// # Examples
///
/// ```
/// #![feature(alloc_error_hook)]
///
/// use std::alloc::{Layout, set_alloc_error_hook};
///
/// fn custom_alloc_error_hook(layout: Layout) {
/// panic!("memory allocation of {} bytes failed", layout.size());
/// }
///
/// set_alloc_error_hook(custom_alloc_error_hook);
/// ```
#[unstable(feature = "alloc_error_hook", issue = "51245")]
pub fn set_alloc_error_hook(hook: fn(Layout)) {
HOOK.store(hook as *mut (), Ordering::SeqCst);
Expand Down
2 changes: 1 addition & 1 deletion src/doc/book
Submodule book updated 240 files
2 changes: 1 addition & 1 deletion src/doc/embedded-book
2 changes: 1 addition & 1 deletion src/doc/reference
Submodule reference updated 1 files
+2 −3 src/const_eval.md
4 changes: 4 additions & 0 deletions src/test/ui/iterators/vec-on-unimplemented.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fn main() {
vec![true, false].map(|v| !v).collect::<Vec<_>>();
//~^ ERROR `Vec<bool>` is not an iterator
}
20 changes: 20 additions & 0 deletions src/test/ui/iterators/vec-on-unimplemented.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
error[E0599]: `Vec<bool>` is not an iterator
--> $DIR/vec-on-unimplemented.rs:2:23
|
LL | vec![true, false].map(|v| !v).collect::<Vec<_>>();
| ^^^ `Vec<bool>` is not an iterator; try calling `.into_iter()` or `.iter()`
|
::: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
|
LL | pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
| ------------------------------------------------------------------------------------------------ doesn't satisfy `Vec<bool>: Iterator`
|
= note: the following trait bounds were not satisfied:
`Vec<bool>: Iterator`
which is required by `&mut Vec<bool>: Iterator`
`[bool]: Iterator`
which is required by `&mut [bool]: Iterator`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0599`.
1 change: 0 additions & 1 deletion src/test/ui/json-multiple.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// build-pass
// ignore-pass (different metadata emitted in different modes)
// compile-flags: --json=diagnostic-short --json artifacts --error-format=json
// ignore-compare-mode-nll

#![crate_type = "lib"]
1 change: 0 additions & 1 deletion src/test/ui/json-options.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// build-pass
// ignore-pass (different metadata emitted in different modes)
// compile-flags: --json=diagnostic-short,artifacts --error-format=json
// ignore-compare-mode-nll

#![crate_type = "lib"]
21 changes: 21 additions & 0 deletions src/test/ui/lifetimes/issue-67498.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// check-pass

// Regression test for #67498.

pub fn f<'a, 'b, 'd, 'e> (
x: for<'c> fn(
fn(&'c fn(&'c ())),
fn(&'c fn(&'c ())),
fn(&'c fn(&'c ())),
fn(&'c fn(&'c ())),
)
) -> fn(
fn(&'a fn(&'d ())),
fn(&'b fn(&'d ())),
fn(&'a fn(&'e ())),
fn(&'b fn(&'e ())),
) {
x
}

fn main() {}
9 changes: 8 additions & 1 deletion src/test/ui/parser/keyword-box-as-identifier.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
fn main() {
let box = "foo"; //~ error: expected pattern, found `=`
let box = 0;
//~^ ERROR expected pattern, found `=`
let box: bool;
//~^ ERROR expected pattern, found `:`
let mut box = 0;
//~^ ERROR expected pattern, found `=`
let (box,) = (0,);
//~^ ERROR expected pattern, found `,`
}
64 changes: 61 additions & 3 deletions src/test/ui/parser/keyword-box-as-identifier.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,66 @@
error: expected pattern, found `=`
--> $DIR/keyword-box-as-identifier.rs:2:13
|
LL | let box = "foo";
| ^ expected pattern
LL | let box = 0;
| ^
|
note: `box` is a reserved keyword
--> $DIR/keyword-box-as-identifier.rs:2:9
|
LL | let box = 0;
| ^^^
help: escape `box` to use it as an identifier
|
LL | let r#box = 0;
| ++

error: expected pattern, found `:`
--> $DIR/keyword-box-as-identifier.rs:4:12
|
LL | let box: bool;
| ^
|
note: `box` is a reserved keyword
--> $DIR/keyword-box-as-identifier.rs:4:9
|
LL | let box: bool;
| ^^^
help: escape `box` to use it as an identifier
|
LL | let r#box: bool;
| ++

error: expected pattern, found `=`
--> $DIR/keyword-box-as-identifier.rs:6:17
|
LL | let mut box = 0;
| ^
|
note: `box` is a reserved keyword
--> $DIR/keyword-box-as-identifier.rs:6:13
|
LL | let mut box = 0;
| ^^^
help: escape `box` to use it as an identifier
|
LL | let mut r#box = 0;
| ++

error: expected pattern, found `,`
--> $DIR/keyword-box-as-identifier.rs:8:13
|
LL | let (box,) = (0,);
| ^
|
note: `box` is a reserved keyword
--> $DIR/keyword-box-as-identifier.rs:8:10
|
LL | let (box,) = (0,);
| ^^^
help: escape `box` to use it as an identifier
|
LL | let (r#box,) = (0,);
| ++

error: aborting due to previous error
error: aborting due to 4 previous errors

1 change: 0 additions & 1 deletion src/test/ui/rmeta/emit-artifact-notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// build-pass
// ignore-pass
// ^-- needed because `--pass check` does not emit the output needed.
// ignore-compare-mode-nll

// A very basic test for the emission of artifact notifications in JSON output.

Expand Down
1 change: 0 additions & 1 deletion src/test/ui/save-analysis/emit-notifications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
// compile-flags: --crate-type rlib --error-format=json
// ignore-pass
// ^-- needed because otherwise, the .stderr file changes with --pass check
// ignore-compare-mode-nll

pub fn foo() {}
2 changes: 1 addition & 1 deletion src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1939,7 +1939,7 @@ impl<'test> TestCx<'test> {

match self.config.compare_mode {
Some(CompareMode::Polonius) => {
rustc.args(&["-Zpolonius", "-Zborrowck=mir"]);
rustc.args(&["-Zpolonius"]);
}
Some(CompareMode::Chalk) => {
rustc.args(&["-Zchalk"]);
Expand Down