Skip to content

Commit fb30562

Browse files
committed
Auto merge of #68321 - cuviper:beta-next, r=Dylan-DPC
Beta backports - expect `fn` after `const unsafe` / `const extern` #68073 - Do not ICE on unicode next point #68084 - rustdoc: Don't allow `#![feature(...)]` on stable or beta #67989 r? @Mark-Simulacrum
2 parents 965ce16 + 076095b commit fb30562

21 files changed

+116
-23
lines changed

src/librustc_errors/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ impl CodeSuggestion {
181181

182182
// Find the bounding span.
183183
let lo = substitution.parts.iter().map(|part| part.span.lo()).min().unwrap();
184-
let hi = substitution.parts.iter().map(|part| part.span.hi()).min().unwrap();
184+
let hi = substitution.parts.iter().map(|part| part.span.hi()).max().unwrap();
185185
let bounding_span = Span::with_root_ctxt(lo, hi);
186186
let lines = cm.span_to_lines(bounding_span).unwrap();
187187
assert!(!lines.lines.is_empty());

src/librustc_parse/parser/diagnostics.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -300,15 +300,13 @@ impl<'a> Parser<'a> {
300300
expect.clone()
301301
};
302302
(format!("expected one of {}, found {}", expect, actual),
303-
(self.sess.source_map().next_point(self.prev_span),
304-
format!("expected one of {}", short_expect)))
303+
(self.prev_span.shrink_to_hi(), format!("expected one of {}", short_expect)))
305304
} else if expected.is_empty() {
306305
(format!("unexpected token: {}", actual),
307306
(self.prev_span, "unexpected token after this".to_string()))
308307
} else {
309308
(format!("expected {}, found {}", expect, actual),
310-
(self.sess.source_map().next_point(self.prev_span),
311-
format!("expected {}", expect)))
309+
(self.prev_span.shrink_to_hi(), format!("expected {}", expect)))
312310
};
313311
self.last_unexpected_token_span = Some(self.token.span);
314312
let mut err = self.fatal(&msg_exp);
@@ -871,7 +869,7 @@ impl<'a> Parser<'a> {
871869
_ if self.prev_span == DUMMY_SP => (self.token.span, self.token.span),
872870
// EOF, don't want to point at the following char, but rather the last token.
873871
(token::Eof, None) => (self.prev_span, self.token.span),
874-
_ => (self.sess.source_map().next_point(self.prev_span), self.token.span),
872+
_ => (self.prev_span.shrink_to_hi(), self.token.span),
875873
};
876874
let msg = format!(
877875
"expected `{}`, found {}",
@@ -1179,7 +1177,7 @@ impl<'a> Parser<'a> {
11791177
err.span_label(sp, "unclosed delimiter");
11801178
}
11811179
err.span_suggestion_short(
1182-
self.sess.source_map().next_point(self.prev_span),
1180+
self.prev_span.shrink_to_hi(),
11831181
&format!("{} may belong here", delim.to_string()),
11841182
delim.to_string(),
11851183
Applicability::MaybeIncorrect,

src/librustc_parse/parser/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1647,7 +1647,7 @@ impl<'a> Parser<'a> {
16471647
// | |
16481648
// | parsed until here as `"y" & X`
16491649
err.span_suggestion_short(
1650-
cm.next_point(arm_start_span),
1650+
arm_start_span.shrink_to_hi(),
16511651
"missing a comma here to end this `match` arm",
16521652
",".to_owned(),
16531653
Applicability::MachineApplicable

src/librustc_parse/parser/item.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl<'a> Parser<'a> {
144144
self.sess.gated_spans.gate(sym::const_extern_fn, lo.to(self.token.span));
145145
}
146146
let ext = self.parse_extern()?;
147-
self.bump(); // `fn`
147+
self.expect_keyword(kw::Fn)?;
148148

149149
let header = FnHeader {
150150
unsafety,
@@ -1572,7 +1572,7 @@ impl<'a> Parser<'a> {
15721572
}
15731573
}
15741574
_ => {
1575-
let sp = self.sess.source_map().next_point(self.prev_span);
1575+
let sp = self.prev_span.shrink_to_hi();
15761576
let mut err = self.struct_span_err(sp, &format!("expected `,`, or `}}`, found {}",
15771577
self.this_token_descr()));
15781578
if self.token.is_ident() {
@@ -1706,7 +1706,7 @@ impl<'a> Parser<'a> {
17061706
// it's safe to peel off one character only when it has the close delim
17071707
self.prev_span.with_lo(self.prev_span.hi() - BytePos(1))
17081708
} else {
1709-
self.sess.source_map().next_point(self.prev_span)
1709+
self.prev_span.shrink_to_hi()
17101710
};
17111711

17121712
self.struct_span_err(
@@ -1720,7 +1720,7 @@ impl<'a> Parser<'a> {
17201720
],
17211721
Applicability::MaybeIncorrect,
17221722
).span_suggestion(
1723-
self.sess.source_map().next_point(self.prev_span),
1723+
self.prev_span.shrink_to_hi(),
17241724
"add a semicolon",
17251725
';'.to_string(),
17261726
Applicability::MaybeIncorrect,

src/librustc_parse/parser/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ impl<'a> Parser<'a> {
803803
break;
804804
}
805805
Err(mut expect_err) => {
806-
let sp = self.sess.source_map().next_point(self.prev_span);
806+
let sp = self.prev_span.shrink_to_hi();
807807
let token_str = pprust::token_kind_to_string(t);
808808

809809
// Attempt to keep parsing if it was a similar separator.

src/librustc_typeck/check/callee.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
254254
hir::ExprKind::Block(..),
255255
) = (parent_node, callee_node) {
256256
let start = sp.shrink_to_lo();
257-
let end = self.tcx.sess.source_map().next_point(callee_span);
257+
let end = callee_span.shrink_to_hi();
258258
err.multipart_suggestion(
259259
"if you meant to create this closure and immediately call it, surround the \
260260
closure with parenthesis",
@@ -332,9 +332,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
332332
let call_is_multiline =
333333
self.tcx.sess.source_map().is_multiline(call_expr.span);
334334
if call_is_multiline {
335-
let span = self.tcx.sess.source_map().next_point(callee.span);
336335
err.span_suggestion(
337-
span,
336+
callee.span.shrink_to_hi(),
338337
"try adding a semicolon",
339338
";".to_owned(),
340339
Applicability::MaybeIncorrect,

src/librustc_typeck/check/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -4834,9 +4834,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
48344834
ExprKind::Loop(..) |
48354835
ExprKind::Match(..) |
48364836
ExprKind::Block(..) => {
4837-
let sp = self.tcx.sess.source_map().next_point(cause_span);
48384837
err.span_suggestion(
4839-
sp,
4838+
cause_span.shrink_to_hi(),
48404839
"try adding a semicolon",
48414840
";".to_string(),
48424841
Applicability::MachineApplicable);

src/librustdoc/core.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,7 @@ pub fn run_core(options: RustdocOptions) -> (clean::Crate, RenderInfo, RenderOpt
318318
cg: codegen_options,
319319
externs,
320320
target_triple: target,
321-
// Ensure that rustdoc works even if rustc is feature-staged
322-
unstable_features: UnstableFeatures::Allow,
321+
unstable_features: UnstableFeatures::from_environment(),
323322
actually_rustdoc: true,
324323
debugging_opts: debugging_options,
325324
error_format,

src/libsyntax_expand/mbe/macro_parser.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ pub(super) fn parse(
708708
Token::new(token::Eof, if parser.token.span.is_dummy() {
709709
parser.token.span
710710
} else {
711-
sess.source_map().next_point(parser.token.span)
711+
parser.token.span.shrink_to_hi()
712712
}),
713713
"missing tokens in macro arguments",
714714
);

src/libsyntax_ext/assert.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn parse_assert<'a>(
105105
let custom_message = if let token::Literal(token::Lit { kind: token::Str, .. })
106106
= parser.token.kind {
107107
let mut err = cx.struct_span_warn(parser.token.span, "unexpected string literal");
108-
let comma_span = cx.source_map().next_point(parser.prev_span);
108+
let comma_span = parser.prev_span.shrink_to_hi();
109109
err.span_suggestion_short(
110110
comma_span,
111111
"try adding a comma",

src/libsyntax_pos/source_map.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ impl SourceMap {
739739
pub fn next_point(&self, sp: Span) -> Span {
740740
let start_of_next_point = sp.hi().0;
741741

742-
let width = self.find_width_of_character_at_span(sp, true);
742+
let width = self.find_width_of_character_at_span(sp.shrink_to_hi(), true);
743743
// If the width is 1, then the next span should point to the same `lo` and `hi`. However,
744744
// in the case of a multibyte character, where the width != 1, the next span should
745745
// span multiple bytes to include the whole character.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn main() {}
2+
3+
#[cfg(FALSE)]
4+
fn container() {
5+
const unsafe WhereIsFerris Now() {}
6+
//~^ ERROR expected one of `extern` or `fn`
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected one of `extern` or `fn`, found `WhereIsFerris`
2+
--> $DIR/issue-68062-const-extern-fns-dont-need-fn-specifier-2.rs:5:18
3+
|
4+
LL | const unsafe WhereIsFerris Now() {}
5+
| ^^^^^^^^^^^^^ expected one of `extern` or `fn`
6+
7+
error: aborting due to previous error
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn main() {}
2+
3+
#[cfg(FALSE)]
4+
fn container() {
5+
const extern "Rust" PUT_ANYTHING_YOU_WANT_HERE bug() -> usize { 1 }
6+
//~^ ERROR expected `fn`
7+
//~| ERROR `const extern fn` definitions are unstable
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: expected `fn`, found `PUT_ANYTHING_YOU_WANT_HERE`
2+
--> $DIR/issue-68062-const-extern-fns-dont-need-fn-specifier.rs:5:25
3+
|
4+
LL | const extern "Rust" PUT_ANYTHING_YOU_WANT_HERE bug() -> usize { 1 }
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `fn`
6+
7+
error[E0658]: `const extern fn` definitions are unstable
8+
--> $DIR/issue-68062-const-extern-fns-dont-need-fn-specifier.rs:5:5
9+
|
10+
LL | const extern "Rust" PUT_ANYTHING_YOU_WANT_HERE bug() -> usize { 1 }
11+
| ^^^^^^^^^^^^
12+
|
13+
= note: for more information, see https://github.com/rust-lang/rust/issues/64926
14+
= help: add `#![feature(const_extern_fn)]` to the crate attributes to enable
15+
16+
error: aborting due to 2 previous errors
17+
18+
For more information about this error, try `rustc --explain E0658`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pub struct Foo {
2+
pub bar: Vec<i32>ö
3+
//~^ ERROR expected `,`, or `}`, found `ö`
4+
} //~ ERROR expected `:`, found `}`
5+
6+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
error: expected `,`, or `}`, found `ö`
2+
--> $DIR/issue-68000-unicode-ident-after-missing-comma.rs:2:22
3+
|
4+
LL | pub bar: Vec<i32>ö
5+
| ^ help: try adding a comma: `,`
6+
7+
error: expected `:`, found `}`
8+
--> $DIR/issue-68000-unicode-ident-after-missing-comma.rs:4:1
9+
|
10+
LL | pub bar: Vec<i32>ö
11+
| - expected `:`
12+
LL |
13+
LL | }
14+
| ^ unexpected token
15+
16+
error: aborting due to 2 previous errors
17+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
macro_rules! x {
2+
($($c:tt)*) => {
3+
$($c)ö* {} //~ ERROR missing condition for `if` expression
4+
};
5+
}
6+
7+
fn main() {
8+
x!(if);
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: missing condition for `if` expression
2+
--> $DIR/issue-68091-unicode-ident-after-if.rs:3:14
3+
|
4+
LL | $($c)ö* {}
5+
| ^ expected if condition here
6+
7+
error: aborting due to previous error
8+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
macro_rules! x {
2+
($($c:tt)*) => {
3+
$($c)ö* //~ ERROR macro expansion ends with an incomplete expression: expected expression
4+
};
5+
}
6+
7+
fn main() {
8+
x!(!);
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: macro expansion ends with an incomplete expression: expected expression
2+
--> $DIR/issue-68092-unicode-ident-after-incomplete-expr.rs:3:14
3+
|
4+
LL | $($c)ö*
5+
| ^ expected expression
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)