Skip to content

Commit 8bebfe5

Browse files
committed
Auto merge of #87480 - GuillaumeGomez:rollup-3ly8t5d, r=GuillaumeGomez
Rollup of 8 pull requests Successful merges: - #87436 (Suggest `;` on parse error where applicable) - #87444 (Flatten nested `format!` calls) - #87447 (Miri: santiy check that null pointer can never have an AllocId) - #87457 (freebsd remove compiler workaround.) - #87458 (Fix help message for modification to &T created by &{t}) - #87464 (Remove unnecessary `structhead` parameter from `render_union`) - #87473 (Notify the Rust 2021 edition working group in zulip of edition bugs) - #87474 (Add missing whitespace after attribute in HTML template) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 08095fc + 12c2092 commit 8bebfe5

File tree

15 files changed

+174
-81
lines changed

15 files changed

+174
-81
lines changed

Diff for: compiler/rustc_mir/src/borrow_check/diagnostics/mutability_errors.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -905,16 +905,16 @@ fn suggest_ampmut<'tcx>(
905905
Some(c) if c.is_whitespace() => true,
906906
// e.g. `&mut(x)`
907907
Some('(') => true,
908+
// e.g. `&mut{x}`
909+
Some('{') => true,
908910
// e.g. `&mutablevar`
909911
_ => false,
910912
}
911913
} else {
912914
false
913915
}
914916
};
915-
if let (true, Some(ws_pos)) =
916-
(src.starts_with("&'"), src.find(|c: char| -> bool { c.is_whitespace() }))
917-
{
917+
if let (true, Some(ws_pos)) = (src.starts_with("&'"), src.find(char::is_whitespace)) {
918918
let lt_name = &src[1..ws_pos];
919919
let ty = src[ws_pos..].trim_start();
920920
if !is_mutbl(ty) {
@@ -940,9 +940,7 @@ fn suggest_ampmut<'tcx>(
940940
};
941941

942942
if let Ok(src) = tcx.sess.source_map().span_to_snippet(highlight_span) {
943-
if let (true, Some(ws_pos)) =
944-
(src.starts_with("&'"), src.find(|c: char| -> bool { c.is_whitespace() }))
945-
{
943+
if let (true, Some(ws_pos)) = (src.starts_with("&'"), src.find(char::is_whitespace)) {
946944
let lt_name = &src[1..ws_pos];
947945
let ty = &src[ws_pos..];
948946
return (highlight_span, format!("&{} mut{}", lt_name, ty));

Diff for: compiler/rustc_mir/src/interpret/memory.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
11421142
Err(ptr) => ptr.into(),
11431143
Ok(bits) => {
11441144
let addr = u64::try_from(bits).unwrap();
1145-
M::ptr_from_addr(&self, addr)
1145+
let ptr = M::ptr_from_addr(&self, addr);
1146+
if addr == 0 {
1147+
assert!(ptr.provenance.is_none(), "null pointer can never have an AllocId");
1148+
}
1149+
ptr
11461150
}
11471151
}
11481152
}

Diff for: compiler/rustc_parse/src/parser/diagnostics.rs

+57-57
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,63 @@ impl<'a> Parser<'a> {
242242
expected.sort_by_cached_key(|x| x.to_string());
243243
expected.dedup();
244244

245+
let sm = self.sess.source_map();
246+
let msg = format!("expected `;`, found {}", super::token_descr(&self.token));
247+
let appl = Applicability::MachineApplicable;
248+
if expected.contains(&TokenType::Token(token::Semi)) {
249+
if self.token.span == DUMMY_SP || self.prev_token.span == DUMMY_SP {
250+
// Likely inside a macro, can't provide meaningful suggestions.
251+
} else if !sm.is_multiline(self.prev_token.span.until(self.token.span)) {
252+
// The current token is in the same line as the prior token, not recoverable.
253+
} else if [token::Comma, token::Colon].contains(&self.token.kind)
254+
&& self.prev_token.kind == token::CloseDelim(token::Paren)
255+
{
256+
// Likely typo: The current token is on a new line and is expected to be
257+
// `.`, `;`, `?`, or an operator after a close delimiter token.
258+
//
259+
// let a = std::process::Command::new("echo")
260+
// .arg("1")
261+
// ,arg("2")
262+
// ^
263+
// https://github.com/rust-lang/rust/issues/72253
264+
} else if self.look_ahead(1, |t| {
265+
t == &token::CloseDelim(token::Brace)
266+
|| t.can_begin_expr() && t.kind != token::Colon
267+
}) && [token::Comma, token::Colon].contains(&self.token.kind)
268+
{
269+
// Likely typo: `,` → `;` or `:` → `;`. This is triggered if the current token is
270+
// either `,` or `:`, and the next token could either start a new statement or is a
271+
// block close. For example:
272+
//
273+
// let x = 32:
274+
// let y = 42;
275+
self.bump();
276+
let sp = self.prev_token.span;
277+
self.struct_span_err(sp, &msg)
278+
.span_suggestion_short(sp, "change this to `;`", ";".to_string(), appl)
279+
.emit();
280+
return Ok(false);
281+
} else if self.look_ahead(0, |t| {
282+
t == &token::CloseDelim(token::Brace)
283+
|| (
284+
t.can_begin_expr() && t != &token::Semi && t != &token::Pound
285+
// Avoid triggering with too many trailing `#` in raw string.
286+
)
287+
}) {
288+
// Missing semicolon typo. This is triggered if the next token could either start a
289+
// new statement or is a block close. For example:
290+
//
291+
// let x = 32
292+
// let y = 42;
293+
let sp = self.prev_token.span.shrink_to_hi();
294+
self.struct_span_err(sp, &msg)
295+
.span_label(self.token.span, "unexpected token")
296+
.span_suggestion_short(sp, "add `;` here", ";".to_string(), appl)
297+
.emit();
298+
return Ok(false);
299+
}
300+
}
301+
245302
let expect = tokens_to_string(&expected[..]);
246303
let actual = super::token_descr(&self.token);
247304
let (msg_exp, (label_sp, label_exp)) = if expected.len() > 1 {
@@ -303,7 +360,6 @@ impl<'a> Parser<'a> {
303360
return Err(err);
304361
}
305362

306-
let sm = self.sess.source_map();
307363
if self.prev_token.span == DUMMY_SP {
308364
// Account for macro context where the previous span might not be
309365
// available to avoid incorrect output (#54841).
@@ -1144,62 +1200,6 @@ impl<'a> Parser<'a> {
11441200
if self.eat(&token::Semi) {
11451201
return Ok(());
11461202
}
1147-
let sm = self.sess.source_map();
1148-
let msg = format!("expected `;`, found {}", super::token_descr(&self.token));
1149-
let appl = Applicability::MachineApplicable;
1150-
if self.token.span == DUMMY_SP || self.prev_token.span == DUMMY_SP {
1151-
// Likely inside a macro, can't provide meaningful suggestions.
1152-
return self.expect(&token::Semi).map(drop);
1153-
} else if !sm.is_multiline(self.prev_token.span.until(self.token.span)) {
1154-
// The current token is in the same line as the prior token, not recoverable.
1155-
} else if [token::Comma, token::Colon].contains(&self.token.kind)
1156-
&& self.prev_token.kind == token::CloseDelim(token::Paren)
1157-
{
1158-
// Likely typo: The current token is on a new line and is expected to be
1159-
// `.`, `;`, `?`, or an operator after a close delimiter token.
1160-
//
1161-
// let a = std::process::Command::new("echo")
1162-
// .arg("1")
1163-
// ,arg("2")
1164-
// ^
1165-
// https://github.com/rust-lang/rust/issues/72253
1166-
self.expect(&token::Semi)?;
1167-
return Ok(());
1168-
} else if self.look_ahead(1, |t| {
1169-
t == &token::CloseDelim(token::Brace) || t.can_begin_expr() && t.kind != token::Colon
1170-
}) && [token::Comma, token::Colon].contains(&self.token.kind)
1171-
{
1172-
// Likely typo: `,` → `;` or `:` → `;`. This is triggered if the current token is
1173-
// either `,` or `:`, and the next token could either start a new statement or is a
1174-
// block close. For example:
1175-
//
1176-
// let x = 32:
1177-
// let y = 42;
1178-
self.bump();
1179-
let sp = self.prev_token.span;
1180-
self.struct_span_err(sp, &msg)
1181-
.span_suggestion_short(sp, "change this to `;`", ";".to_string(), appl)
1182-
.emit();
1183-
return Ok(());
1184-
} else if self.look_ahead(0, |t| {
1185-
t == &token::CloseDelim(token::Brace)
1186-
|| (
1187-
t.can_begin_expr() && t != &token::Semi && t != &token::Pound
1188-
// Avoid triggering with too many trailing `#` in raw string.
1189-
)
1190-
}) {
1191-
// Missing semicolon typo. This is triggered if the next token could either start a
1192-
// new statement or is a block close. For example:
1193-
//
1194-
// let x = 32
1195-
// let y = 42;
1196-
let sp = self.prev_token.span.shrink_to_hi();
1197-
self.struct_span_err(sp, &msg)
1198-
.span_label(self.token.span, "unexpected token")
1199-
.span_suggestion_short(sp, "add `;` here", ";".to_string(), appl)
1200-
.emit();
1201-
return Ok(());
1202-
}
12031203
self.expect(&token::Semi).map(drop) // Error unconditionally
12041204
}
12051205

Diff for: compiler/rustc_target/src/spec/freebsd_base.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::spec::{FramePointer, RelroLevel, TargetOptions};
1+
use crate::spec::{RelroLevel, TargetOptions};
22

33
pub fn opts() -> TargetOptions {
44
TargetOptions {
@@ -8,7 +8,6 @@ pub fn opts() -> TargetOptions {
88
families: vec!["unix".to_string()],
99
has_rpath: true,
1010
position_independent_executables: true,
11-
frame_pointer: FramePointer::Always, // FIXME 43575: should be MayOmit...
1211
relro_level: RelroLevel::Full,
1312
abi_return_struct_as_int: true,
1413
dwarf_version: Some(2),

Diff for: src/librustdoc/html/markdown.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,9 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> {
234234
return Some(Event::Html(
235235
format!(
236236
"<div class=\"example-wrap\">\
237-
<pre{}>{}</pre>\
237+
<pre class=\"language-{}\">{}</pre>\
238238
</div>",
239-
format!(" class=\"language-{}\"", lang),
239+
lang,
240240
Escape(&text),
241241
)
242242
.into(),

Diff for: src/librustdoc/html/render/print_item.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni
888888
wrap_into_docblock(w, |w| {
889889
w.write_str("<pre class=\"rust union\">");
890890
render_attributes_in_pre(w, it, "");
891-
render_union(w, it, Some(&s.generics), &s.fields, "", true, cx);
891+
render_union(w, it, Some(&s.generics), &s.fields, "", cx);
892892
w.write_str("</pre>")
893893
});
894894

@@ -1380,14 +1380,12 @@ fn render_union(
13801380
g: Option<&clean::Generics>,
13811381
fields: &[clean::Item],
13821382
tab: &str,
1383-
structhead: bool,
13841383
cx: &Context<'_>,
13851384
) {
13861385
write!(
13871386
w,
1388-
"{}{}{}",
1387+
"{}union {}",
13891388
it.visibility.print_with_space(it.def_id, cx),
1390-
if structhead { "union " } else { "" },
13911389
it.name.as_ref().unwrap()
13921390
);
13931391
if let Some(g) = g {

Diff for: src/librustdoc/html/templates/page.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
</select> {#- -#}
8484
{%- endif -%}
8585
<input {# -#}
86-
class="search-input"{# -#}
86+
class="search-input" {# -#}
8787
name="search" {# -#}
8888
disabled {# -#}
8989
autocomplete="off" {# -#}

Diff for: src/test/ui/borrowck/issue-85765.rs

+14
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,18 @@ fn main() {
1212
*r = 0;
1313
//~^ ERROR cannot assign to `*r`, which is behind a `&` reference
1414
//~| NOTE `r` is a `&` reference, so the data it refers to cannot be written
15+
16+
#[rustfmt::skip]
17+
let x: &usize = &mut{0};
18+
//~^ HELP consider changing this to be a mutable reference
19+
*x = 1;
20+
//~^ ERROR cannot assign to `*x`, which is behind a `&` reference
21+
//~| NOTE `x` is a `&` reference, so the data it refers to cannot be written
22+
23+
#[rustfmt::skip]
24+
let y: &usize = &mut(0);
25+
//~^ HELP consider changing this to be a mutable reference
26+
*y = 1;
27+
//~^ ERROR cannot assign to `*y`, which is behind a `&` reference
28+
//~| NOTE `y` is a `&` reference, so the data it refers to cannot be written
1529
}

Diff for: src/test/ui/borrowck/issue-85765.stderr

+19-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,25 @@ LL |
1616
LL | *r = 0;
1717
| ^^^^^^ `r` is a `&` reference, so the data it refers to cannot be written
1818

19-
error: aborting due to 2 previous errors
19+
error[E0594]: cannot assign to `*x`, which is behind a `&` reference
20+
--> $DIR/issue-85765.rs:19:5
21+
|
22+
LL | let x: &usize = &mut{0};
23+
| - help: consider changing this to be a mutable reference: `&mut usize`
24+
LL |
25+
LL | *x = 1;
26+
| ^^^^^^ `x` is a `&` reference, so the data it refers to cannot be written
27+
28+
error[E0594]: cannot assign to `*y`, which is behind a `&` reference
29+
--> $DIR/issue-85765.rs:26:5
30+
|
31+
LL | let y: &usize = &mut(0);
32+
| - help: consider changing this to be a mutable reference: `&mut usize`
33+
LL |
34+
LL | *y = 1;
35+
| ^^^^^^ `y` is a `&` reference, so the data it refers to cannot be written
36+
37+
error: aborting due to 4 previous errors
2038

2139
Some errors have detailed explanations: E0594, E0596.
2240
For more information about an error, try `rustc --explain E0594`.
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// run-rustfix
2+
// Parser should know when a semicolon is missing.
3+
// https://github.com/rust-lang/rust/issues/87197
4+
5+
fn main() {
6+
let x = 100; //~ ERROR: expected `;`
7+
println!("{}", x); //~ ERROR: expected `;`
8+
let y = 200; //~ ERROR: expected `;`
9+
println!("{}", y);
10+
}

Diff for: src/test/ui/parser/issue-87197-missing-semicolon.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// run-rustfix
2+
// Parser should know when a semicolon is missing.
3+
// https://github.com/rust-lang/rust/issues/87197
4+
5+
fn main() {
6+
let x = 100 //~ ERROR: expected `;`
7+
println!("{}", x) //~ ERROR: expected `;`
8+
let y = 200 //~ ERROR: expected `;`
9+
println!("{}", y);
10+
}
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: expected `;`, found `println`
2+
--> $DIR/issue-87197-missing-semicolon.rs:6:16
3+
|
4+
LL | let x = 100
5+
| ^ help: add `;` here
6+
LL | println!("{}", x)
7+
| ------- unexpected token
8+
9+
error: expected `;`, found keyword `let`
10+
--> $DIR/issue-87197-missing-semicolon.rs:7:22
11+
|
12+
LL | println!("{}", x)
13+
| ^ help: add `;` here
14+
LL | let y = 200
15+
| --- unexpected token
16+
17+
error: expected `;`, found `println`
18+
--> $DIR/issue-87197-missing-semicolon.rs:8:16
19+
|
20+
LL | let y = 200
21+
| ^ help: add `;` here
22+
LL | println!("{}", y);
23+
| ------- unexpected token
24+
25+
error: aborting due to 3 previous errors
26+

Diff for: src/test/ui/parser/macros-no-semicolon.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
fn main() {
2-
assert_eq!(1, 2)
3-
assert_eq!(3, 4) //~ ERROR expected one of `.`, `;`, `?`, `}`, or an operator, found `assert_eq`
2+
assert_eq!(1, 2) //~ ERROR: expected `;`
3+
assert_eq!(3, 4) //~ ERROR: expected `;`
44
println!("hello");
55
}

Diff for: src/test/ui/parser/macros-no-semicolon.stderr

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
error: expected one of `.`, `;`, `?`, `}`, or an operator, found `assert_eq`
2-
--> $DIR/macros-no-semicolon.rs:3:5
1+
error: expected `;`, found `assert_eq`
2+
--> $DIR/macros-no-semicolon.rs:2:21
33
|
44
LL | assert_eq!(1, 2)
5-
| - expected one of `.`, `;`, `?`, `}`, or an operator
5+
| ^ help: add `;` here
66
LL | assert_eq!(3, 4)
7-
| ^^^^^^^^^ unexpected token
7+
| --------- unexpected token
88

9-
error: aborting due to previous error
9+
error: expected `;`, found `println`
10+
--> $DIR/macros-no-semicolon.rs:3:21
11+
|
12+
LL | assert_eq!(3, 4)
13+
| ^ help: add `;` here
14+
LL | println!("hello");
15+
| ------- unexpected token
16+
17+
error: aborting due to 2 previous errors
1018

Diff for: triagebot.toml

+8
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@ message_on_add = """\
112112
"""
113113
message_on_remove = "Issue #{number}'s nomination request has been removed."
114114

115+
[notify-zulip."A-edition-2021"]
116+
required_labels = ["C-bug"]
117+
zulip_stream = 268952 # #edition 2021
118+
topic = "Edition Bugs"
119+
message_on_add = """\
120+
Issue #{number} "{title}" has been added.
121+
"""
122+
115123
[github-releases]
116124
format = "rustc"
117125
project-name = "Rust"

0 commit comments

Comments
 (0)