Skip to content
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
13 changes: 9 additions & 4 deletions compiler/rustc_parse/src/parser/cfg_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,19 @@ use crate::exp;
use crate::parser::{AttrWrapper, ForceCollect, Parser, Restrictions, Trailing, UsePreAttrPos};

impl<'a> Parser<'a> {
/// Parses a `TokenTree` consisting either of `{ /* ... */ }` (and strip the braces) or an
/// expression followed by a comma (and strip the comma).
/// Parses a `TokenTree` consisting either of `{ /* ... */ }` optionally followed by a comma
/// (and strip the braces and the optional comma) or an expression followed by a comma
/// (and strip the comma).
pub fn parse_delimited_token_tree(&mut self) -> PResult<'a, TokenStream> {
if self.token == token::OpenBrace {
// Strip the outer '{' and '}'.
match self.parse_token_tree() {
TokenTree::Token(..) => unreachable!("because of the expect above"),
TokenTree::Delimited(.., tts) => return Ok(tts),
TokenTree::Token(..) => unreachable!("because the current token is a '{{'"),
TokenTree::Delimited(.., tts) => {
// Optionally end with a comma.
let _ = self.eat(exp!(Comma));
return Ok(tts);
}
}
}
let expr = self.collect_tokens(None, AttrWrapper::empty(), ForceCollect::Yes, |p, _| {
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_trait_selection/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ impl Subdiagnostic for AdjustSignatureBorrow {
fn add_to_diag<G: EmissionGuarantee>(self, diag: &mut Diag<'_, G>) {
match self {
AdjustSignatureBorrow::Borrow { to_borrow } => {
diag.arg("len", to_borrow.len());
diag.arg("borrow_len", to_borrow.len());
diag.multipart_suggestion_verbose(
inline_fluent!(
"consider adjusting the signature so it borrows its {$len ->
"consider adjusting the signature so it borrows its {$borrow_len ->
[one] argument
*[other] arguments
}"
Expand All @@ -166,10 +166,10 @@ impl Subdiagnostic for AdjustSignatureBorrow {
);
}
AdjustSignatureBorrow::RemoveBorrow { remove_borrow } => {
diag.arg("len", remove_borrow.len());
diag.arg("remove_borrow_len", remove_borrow.len());
diag.multipart_suggestion_verbose(
inline_fluent!(
"consider adjusting the signature so it does not borrow its {$len ->
"consider adjusting the signature so it does not borrow its {$remove_borrow_len ->
[one] argument
*[other] arguments
}"
Expand Down
10 changes: 10 additions & 0 deletions tests/ui/closures/closure-arg-borrow-ice-issue-152331.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
fn main() {
h2(|_: (), _: (), _: (), x: &_| {});
//~^ ERROR type mismatch in closure arguments
}

fn h2<F>(_: F)
where
F: for<'t0> Fn(&(), Box<dyn Fn(&())>, &'t0 (), fn(&(), &())),
{
}
32 changes: 32 additions & 0 deletions tests/ui/closures/closure-arg-borrow-ice-issue-152331.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
error[E0631]: type mismatch in closure arguments
--> $DIR/closure-arg-borrow-ice-issue-152331.rs:2:5
|
LL | h2(|_: (), _: (), _: (), x: &_| {});
| ^^^----------------------------^^^^
| | |
| | found signature defined here
| expected due to this
|
= note: expected closure signature `for<'a, 't0> fn(&'a (), Box<(dyn for<'a> Fn(&'a ()) + 'static)>, &'t0 (), for<'a, 'b> fn(&'a (), &'b ())) -> _`
found closure signature `fn((), (), (), &_) -> _`
note: required by a bound in `h2`
--> $DIR/closure-arg-borrow-ice-issue-152331.rs:8:8
|
LL | fn h2<F>(_: F)
| -- required by a bound in this function
LL | where
LL | F: for<'t0> Fn(&(), Box<dyn Fn(&())>, &'t0 (), fn(&(), &())),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `h2`
help: consider adjusting the signature so it borrows its arguments
|
LL | h2(|_: &(), _: (), _: &(), x: &_| {});
| + +
help: consider adjusting the signature so it does not borrow its argument
|
LL - h2(|_: (), _: (), _: (), x: &_| {});
LL + h2(|_: (), _: (), _: (), x: _| {});
|

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0631`.
7 changes: 4 additions & 3 deletions tests/ui/macros/cfg_select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fn arm_rhs_expr_3() -> i32 {
any(true) => 1,
any(false) => 2,
any(true) => { 42 }
any(true) => { 42 },
any(false) => -1 as i32,
any(true) => 2 + 2,
any(false) => "",
Expand Down Expand Up @@ -62,7 +63,7 @@ fn expand_to_statements() -> i32 {
}

type ExpandToType = cfg_select! {
unix => u32,
unix => { u32 },
_ => i32,
};

Expand Down Expand Up @@ -113,7 +114,7 @@ impl T for S {
cfg_select! {
false => {
fn a() {}
}
},
_ => {
fn b() {}
}
Expand Down Expand Up @@ -145,7 +146,7 @@ cfg_select! {

cfg_select! {
unix => {}
not(unix) => {}
not(unix) => {},
_ => {}
//~^ WARN unreachable configuration predicate
}
Expand Down
32 changes: 16 additions & 16 deletions tests/ui/macros/cfg_select.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: none of the predicates in this `cfg_select` evaluated to true
--> $DIR/cfg_select.rs:161:1
--> $DIR/cfg_select.rs:162:1
|
LL | / cfg_select! {
LL | |
Expand All @@ -8,55 +8,55 @@ LL | | }
| |_^

error: none of the predicates in this `cfg_select` evaluated to true
--> $DIR/cfg_select.rs:166:1
--> $DIR/cfg_select.rs:167:1
|
LL | cfg_select! {}
| ^^^^^^^^^^^^^^

error: expected a literal (`1u8`, `1.0f32`, `"string"`, etc.) here, found `=>`
--> $DIR/cfg_select.rs:170:5
--> $DIR/cfg_select.rs:171:5
|
LL | => {}
| ^^

error: expected a literal (`1u8`, `1.0f32`, `"string"`, etc.) here, found expression
--> $DIR/cfg_select.rs:175:5
--> $DIR/cfg_select.rs:176:5
|
LL | () => {}
| ^^ expressions are not allowed here

error[E0539]: malformed `cfg_select` macro input
--> $DIR/cfg_select.rs:180:5
--> $DIR/cfg_select.rs:181:5
|
LL | "str" => {}
| ^^^^^ expected a valid identifier here

error[E0539]: malformed `cfg_select` macro input
--> $DIR/cfg_select.rs:185:5
--> $DIR/cfg_select.rs:186:5
|
LL | a::b => {}
| ^^^^ expected a valid identifier here

error[E0537]: invalid predicate `a`
--> $DIR/cfg_select.rs:190:5
--> $DIR/cfg_select.rs:191:5
|
LL | a() => {}
| ^^^

error: expected one of `(`, `::`, `=>`, or `=`, found `+`
--> $DIR/cfg_select.rs:195:7
--> $DIR/cfg_select.rs:196:7
|
LL | a + 1 => {}
| ^ expected one of `(`, `::`, `=>`, or `=`

error: expected one of `(`, `::`, `=>`, or `=`, found `!`
--> $DIR/cfg_select.rs:201:8
--> $DIR/cfg_select.rs:202:8
|
LL | cfg!() => {}
| ^ expected one of `(`, `::`, `=>`, or `=`

warning: unreachable configuration predicate
--> $DIR/cfg_select.rs:136:5
--> $DIR/cfg_select.rs:137:5
|
LL | _ => {}
| - always matches
Expand All @@ -70,33 +70,33 @@ LL | #![warn(unreachable_cfg_select_predicates)] // Unused warnings are disabled
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: unreachable configuration predicate
--> $DIR/cfg_select.rs:142:5
--> $DIR/cfg_select.rs:143:5
|
LL | true => {}
| ---- always matches
LL | _ => {}
| ^ this configuration predicate is never reached

warning: unreachable configuration predicate
--> $DIR/cfg_select.rs:149:5
--> $DIR/cfg_select.rs:150:5
|
LL | _ => {}
| ^ this configuration predicate is never reached

warning: unreachable configuration predicate
--> $DIR/cfg_select.rs:155:5
--> $DIR/cfg_select.rs:156:5
|
LL | test => {}
| ^^^^ this configuration predicate is never reached

warning: unreachable configuration predicate
--> $DIR/cfg_select.rs:157:5
--> $DIR/cfg_select.rs:158:5
|
LL | _ => {}
| ^ this configuration predicate is never reached

warning: unexpected `cfg` condition name: `a`
--> $DIR/cfg_select.rs:195:5
--> $DIR/cfg_select.rs:196:5
|
LL | a + 1 => {}
| ^ help: found config with similar value: `target_feature = "a"`
Expand All @@ -107,7 +107,7 @@ LL | a + 1 => {}
= note: `#[warn(unexpected_cfgs)]` on by default

warning: unexpected `cfg` condition name: `cfg`
--> $DIR/cfg_select.rs:201:5
--> $DIR/cfg_select.rs:202:5
|
LL | cfg!() => {}
| ^^^
Expand Down
Loading