Skip to content

Commit 5ea6668

Browse files
committed
Auto merge of rust-lang#113102 - matthiaskrgr:rollup-wpkbsw1, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - rust-lang#112518 (Detect actual span for getting unexpected token from parsing macros) - rust-lang#112978 (Add suggestion for bad block fragment error) - rust-lang#113068 (bootstrap: rename 'user' profile to 'dist') - rust-lang#113079 (Use `CoverageKind::as_operand_id` instead of manually reimplementing it) - rust-lang#113089 (Export AnalysisResults trait in rustc_mir_dataflow) - rust-lang#113093 (`thir`: Add `Become` expression kind) - rust-lang#113096 (Remove unused struct and tweak format macro uses) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 3c554f5 + adc3ae2 commit 5ea6668

File tree

30 files changed

+143
-50
lines changed

30 files changed

+143
-50
lines changed

compiler/rustc_ast_passes/src/errors.rs

-7
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,6 @@ pub struct ForbiddenLifetimeBound {
7777
pub spans: Vec<Span>,
7878
}
7979

80-
#[derive(Diagnostic)]
81-
#[diag(ast_passes_forbidden_non_lifetime_param)]
82-
pub struct ForbiddenNonLifetimeParam {
83-
#[primary_span]
84-
pub spans: Vec<Span>,
85-
}
86-
8780
#[derive(Diagnostic)]
8881
#[diag(ast_passes_fn_param_too_many)]
8982
pub struct FnParamTooMany {

compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
139139
tcx,
140140
generics,
141141
diag,
142-
&format!("{}", proj.self_ty()),
142+
&proj.self_ty().to_string(),
143143
&path,
144144
None,
145145
matching_span,
@@ -153,7 +153,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
153153
tcx,
154154
generics,
155155
diag,
156-
&format!("{}", proj.self_ty()),
156+
&proj.self_ty().to_string(),
157157
&path,
158158
None,
159159
matching_span,

compiler/rustc_middle/src/thir.rs

+4
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,10 @@ pub enum ExprKind<'tcx> {
410410
Return {
411411
value: Option<ExprId>,
412412
},
413+
/// A `become` expression.
414+
Become {
415+
value: ExprId,
416+
},
413417
/// An inline `const` block, e.g. `const {}`.
414418
ConstBlock {
415419
did: DefId,

compiler/rustc_middle/src/thir/visit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp
100100
visitor.visit_expr(&visitor.thir()[value])
101101
}
102102
}
103+
Become { value } => visitor.visit_expr(&visitor.thir()[value]),
103104
ConstBlock { did: _, substs: _ } => {}
104105
Repeat { value, count: _ } => {
105106
visitor.visit_expr(&visitor.thir()[value]);

compiler/rustc_mir_build/src/build/expr/as_place.rs

+1
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
549549
| ExprKind::Break { .. }
550550
| ExprKind::Continue { .. }
551551
| ExprKind::Return { .. }
552+
| ExprKind::Become { .. }
552553
| ExprKind::Literal { .. }
553554
| ExprKind::NamedConst { .. }
554555
| ExprKind::NonHirLiteral { .. }

compiler/rustc_mir_build/src/build/expr/as_rvalue.rs

+1
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
532532
| ExprKind::Break { .. }
533533
| ExprKind::Continue { .. }
534534
| ExprKind::Return { .. }
535+
| ExprKind::Become { .. }
535536
| ExprKind::InlineAsm { .. }
536537
| ExprKind::PlaceTypeAscription { .. }
537538
| ExprKind::ValueTypeAscription { .. } => {

compiler/rustc_mir_build/src/build/expr/category.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ impl Category {
8282
| ExprKind::Block { .. }
8383
| ExprKind::Break { .. }
8484
| ExprKind::Continue { .. }
85-
| ExprKind::Return { .. } =>
85+
| ExprKind::Return { .. }
86+
| ExprKind::Become { .. } =>
8687
// FIXME(#27840) these probably want their own
8788
// category, like "nonterminating"
8889
{

compiler/rustc_mir_build/src/build/expr/into.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
493493
block.unit()
494494
}
495495

496-
ExprKind::Continue { .. } | ExprKind::Break { .. } | ExprKind::Return { .. } => {
496+
ExprKind::Continue { .. }
497+
| ExprKind::Break { .. }
498+
| ExprKind::Return { .. }
499+
| ExprKind::Become { .. } => {
497500
unpack!(block = this.stmt_expr(block, expr, None));
498501
// No assign, as these have type `!`.
499502
block.unit()

compiler/rustc_mir_build/src/build/expr/stmt.rs

+7
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
9999
BreakableTarget::Return,
100100
source_info,
101101
),
102+
// FIXME(explicit_tail_calls): properly lower tail calls here
103+
ExprKind::Become { value } => this.break_scope(
104+
block,
105+
Some(&this.thir[value]),
106+
BreakableTarget::Return,
107+
source_info,
108+
),
102109
_ => {
103110
assert!(
104111
statement_scope.is_some(),

compiler/rustc_mir_build/src/check_unsafety.rs

+1
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
316316
| ExprKind::Closure { .. }
317317
| ExprKind::Continue { .. }
318318
| ExprKind::Return { .. }
319+
| ExprKind::Become { .. }
319320
| ExprKind::Yield { .. }
320321
| ExprKind::Loop { .. }
321322
| ExprKind::Let { .. }

compiler/rustc_mir_build/src/thir/cx/expr.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -694,12 +694,8 @@ impl<'tcx> Cx<'tcx> {
694694

695695
ExprKind::Repeat { value: self.mirror_expr(v), count: *count }
696696
}
697-
hir::ExprKind::Ret(ref v) => ExprKind::Return { value: v.map(|v| self.mirror_expr(v)) },
698-
hir::ExprKind::Become(call) => {
699-
// FIXME(explicit_tail_calls): use `ExprKind::Become` once we implemented it
700-
// Temporary transform `become` into a `return`, so we can write tests for code before this stage
701-
ExprKind::Return { value: Some(self.mirror_expr(call)) }
702-
}
697+
hir::ExprKind::Ret(v) => ExprKind::Return { value: v.map(|v| self.mirror_expr(v)) },
698+
hir::ExprKind::Become(call) => ExprKind::Become { value: self.mirror_expr(call) },
703699
hir::ExprKind::Break(dest, ref value) => match dest.target_id {
704700
Ok(target_id) => ExprKind::Break {
705701
label: region::Scope { id: target_id.local_id, data: region::ScopeData::Node },

compiler/rustc_mir_build/src/thir/print.rs

+6
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,12 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> {
421421

422422
print_indented!(self, "}", depth_lvl);
423423
}
424+
Become { value } => {
425+
print_indented!(self, "Become {", depth_lvl);
426+
print_indented!(self, "value:", depth_lvl + 1);
427+
self.print_expr(*value, depth_lvl + 2);
428+
print_indented!(self, "}", depth_lvl);
429+
}
424430
ConstBlock { did, substs } => {
425431
print_indented!(self, "ConstBlock {", depth_lvl);
426432
print_indented!(self, format!("did: {:?}", did), depth_lvl + 1);

compiler/rustc_mir_dataflow/src/framework/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub mod graphviz;
4545
pub mod lattice;
4646
mod visitor;
4747

48-
pub use self::cursor::{ResultsClonedCursor, ResultsCursor, ResultsRefCursor};
48+
pub use self::cursor::{AnalysisResults, ResultsClonedCursor, ResultsCursor, ResultsRefCursor};
4949
pub use self::direction::{Backward, Direction, Forward};
5050
pub use self::engine::{Engine, EntrySets, Results, ResultsCloned};
5151
pub use self::lattice::{JoinSemiLattice, MeetSemiLattice};

compiler/rustc_mir_dataflow/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ pub use self::drop_flag_effects::{
2727
on_lookup_result_bits,
2828
};
2929
pub use self::framework::{
30-
fmt, graphviz, lattice, visit_results, Analysis, AnalysisDomain, Backward, CallReturnPlaces,
31-
CloneAnalysis, Direction, Engine, Forward, GenKill, GenKillAnalysis, JoinSemiLattice, Results,
32-
ResultsCloned, ResultsClonedCursor, ResultsCursor, ResultsRefCursor, ResultsVisitable,
33-
ResultsVisitor, SwitchIntEdgeEffects,
30+
fmt, graphviz, lattice, visit_results, Analysis, AnalysisDomain, AnalysisResults, Backward,
31+
CallReturnPlaces, CloneAnalysis, Direction, Engine, Forward, GenKill, GenKillAnalysis,
32+
JoinSemiLattice, Results, ResultsCloned, ResultsClonedCursor, ResultsCursor, ResultsRefCursor,
33+
ResultsVisitable, ResultsVisitor, SwitchIntEdgeEffects,
3434
};
3535

3636
use self::move_paths::MoveData;

compiler/rustc_mir_transform/src/coverage/debug.rs

+2-15
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,7 @@ impl DebugCounters {
277277

278278
pub fn add_counter(&mut self, counter_kind: &CoverageKind, some_block_label: Option<String>) {
279279
if let Some(counters) = &mut self.some_counters {
280-
let id: ExpressionOperandId = match *counter_kind {
281-
CoverageKind::Counter { id, .. } => id.into(),
282-
CoverageKind::Expression { id, .. } => id.into(),
283-
_ => bug!(
284-
"the given `CoverageKind` is not an counter or expression: {:?}",
285-
counter_kind
286-
),
287-
};
280+
let id = counter_kind.as_operand_id();
288281
counters
289282
.try_insert(id, DebugCounter::new(counter_kind.clone(), some_block_label))
290283
.expect("attempt to add the same counter_kind to DebugCounters more than once");
@@ -330,13 +323,7 @@ impl DebugCounters {
330323
}
331324
}
332325

333-
let id: ExpressionOperandId = match *counter_kind {
334-
CoverageKind::Counter { id, .. } => id.into(),
335-
CoverageKind::Expression { id, .. } => id.into(),
336-
_ => {
337-
bug!("the given `CoverageKind` is not an counter or expression: {:?}", counter_kind)
338-
}
339-
};
326+
let id = counter_kind.as_operand_id();
340327
if self.some_counters.is_some() && (counter_format.block || !counter_format.id) {
341328
let counters = self.some_counters.as_ref().unwrap();
342329
if let Some(DebugCounter { some_block_label: Some(block_label), .. }) =

compiler/rustc_parse/messages.ftl

+1
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ parse_int_literal_too_large = integer literal is too large
353353
354354
parse_invalid_block_macro_segment = cannot use a `block` macro fragment here
355355
.label = the `block` fragment is within this context
356+
.suggestion = wrap this in another block
356357
357358
parse_invalid_char_in_escape = {parse_invalid_char_in_escape_msg}: `{$ch}`
358359
.label = {parse_invalid_char_in_escape_msg}

compiler/rustc_parse/src/errors.rs

+11
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,17 @@ pub(crate) struct InvalidBlockMacroSegment {
333333
pub span: Span,
334334
#[label]
335335
pub context: Span,
336+
#[subdiagnostic]
337+
pub wrap: WrapInExplicitBlock,
338+
}
339+
340+
#[derive(Subdiagnostic)]
341+
#[multipart_suggestion(parse_suggestion, applicability = "machine-applicable")]
342+
pub(crate) struct WrapInExplicitBlock {
343+
#[suggestion_part(code = "{{ ")]
344+
pub lo: Span,
345+
#[suggestion_part(code = " }}")]
346+
pub hi: Span,
336347
}
337348

338349
#[derive(Diagnostic)]

compiler/rustc_parse/src/parser/expr.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -1013,9 +1013,15 @@ impl<'a> Parser<'a> {
10131013
}
10141014

10151015
fn error_unexpected_after_dot(&self) {
1016-
// FIXME Could factor this out into non_fatal_unexpected or something.
10171016
let actual = pprust::token_to_string(&self.token);
1018-
self.sess.emit_err(errors::UnexpectedTokenAfterDot { span: self.token.span, actual });
1017+
let span = self.token.span;
1018+
let sm = self.sess.source_map();
1019+
let (span, actual) = match (&self.token.kind, self.subparser_name) {
1020+
(token::Eof, Some(_)) if let Ok(actual) = sm.span_to_snippet(sm.next_point(span)) =>
1021+
(span.shrink_to_hi(), actual.into()),
1022+
_ => (span, actual),
1023+
};
1024+
self.sess.emit_err(errors::UnexpectedTokenAfterDot { span, actual });
10191025
}
10201026

10211027
// We need an identifier or integer, but the next token is a float.
@@ -2186,6 +2192,10 @@ impl<'a> Parser<'a> {
21862192
self.sess.emit_err(errors::InvalidBlockMacroSegment {
21872193
span: self.token.span,
21882194
context: lo.to(self.token.span),
2195+
wrap: errors::WrapInExplicitBlock {
2196+
lo: self.token.span.shrink_to_lo(),
2197+
hi: self.token.span.shrink_to_hi(),
2198+
},
21892199
});
21902200
}
21912201

compiler/rustc_ty_utils/src/consts.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ fn recurse_build<'tcx>(
241241
ExprKind::Assign { .. } | ExprKind::AssignOp { .. } => {
242242
error(GenericConstantTooComplexSub::AssignNotSupported(node.span))?
243243
}
244-
ExprKind::Closure { .. } | ExprKind::Return { .. } => {
244+
// FIXME(explicit_tail_calls): maybe get `become` a new error
245+
ExprKind::Closure { .. } | ExprKind::Return { .. } | ExprKind::Become { .. } => {
245246
error(GenericConstantTooComplexSub::ClosureAndReturnNotSupported(node.span))?
246247
}
247248
// let expressions imply control flow
@@ -337,6 +338,7 @@ impl<'a, 'tcx> IsThirPolymorphic<'a, 'tcx> {
337338
| thir::ExprKind::Break { .. }
338339
| thir::ExprKind::Continue { .. }
339340
| thir::ExprKind::Return { .. }
341+
| thir::ExprKind::Become { .. }
340342
| thir::ExprKind::Array { .. }
341343
| thir::ExprKind::Tuple { .. }
342344
| thir::ExprKind::Adt(_)

src/bootstrap/bootstrap.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,13 @@ def bootstrap(args):
10521052

10531053
profile = RustBuild.get_toml_static(config_toml, 'profile')
10541054
if profile is not None:
1055-
include_file = 'config.{}.toml'.format(profile)
1055+
# Allows creating alias for profile names, allowing
1056+
# profiles to be renamed while maintaining back compatibility
1057+
# Keep in sync with `profile_aliases` in config.rs
1058+
profile_aliases = {
1059+
"user": "dist"
1060+
}
1061+
include_file = 'config.{}.toml'.format(profile_aliases.get(profile) or profile)
10561062
include_dir = os.path.join(rust_root, 'src', 'bootstrap', 'defaults')
10571063
include_path = os.path.join(include_dir, include_file)
10581064
# HACK: This works because `self.get_toml()` returns the first match it finds for a

src/bootstrap/bootstrap_test.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class GenerateAndParseConfig(unittest.TestCase):
9898
def test_no_args(self):
9999
build = serialize_and_parse([])
100100
self.assertEqual(build.get_toml("changelog-seen"), '2')
101-
self.assertEqual(build.get_toml("profile"), 'user')
101+
self.assertEqual(build.get_toml("profile"), 'dist')
102102
self.assertIsNone(build.get_toml("llvm.download-ci-llvm"))
103103

104104
def test_set_section(self):

src/bootstrap/config.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,14 @@ impl Config {
11291129
};
11301130

11311131
if let Some(include) = &toml.profile {
1132+
// Allows creating alias for profile names, allowing
1133+
// profiles to be renamed while maintaining back compatibility
1134+
// Keep in sync with `profile_aliases` in bootstrap.py
1135+
let profile_aliases = HashMap::from([("user", "dist")]);
1136+
let include = match profile_aliases.get(include.as_str()) {
1137+
Some(alias) => alias,
1138+
None => include.as_str(),
1139+
};
11321140
let mut include_path = config.src.clone();
11331141
include_path.push("src");
11341142
include_path.push("bootstrap");

src/bootstrap/config/tests.rs

+19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
use crate::config::TomlConfig;
2+
13
use super::{Config, Flags};
24
use clap::CommandFactory;
5+
use serde::Deserialize;
36
use std::{env, path::Path};
47

58
fn parse(config: &str) -> Config {
@@ -159,3 +162,19 @@ fn override_toml_duplicate() {
159162
|&_| toml::from_str("changelog-seen = 0").unwrap(),
160163
);
161164
}
165+
166+
#[test]
167+
fn profile_user_dist() {
168+
fn get_toml(file: &Path) -> TomlConfig {
169+
let contents = if file.ends_with("config.toml") {
170+
"profile = \"user\"".to_owned()
171+
} else {
172+
assert!(file.ends_with("config.dist.toml"));
173+
std::fs::read_to_string(dbg!(file)).unwrap()
174+
};
175+
toml::from_str(&contents)
176+
.and_then(|table: toml::Value| TomlConfig::deserialize(table))
177+
.unwrap()
178+
}
179+
Config::parse_inner(&["check".to_owned()], get_toml);
180+
}

src/bootstrap/configure.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ def parse_example_config(known_args, config):
437437
targets[target][0] = targets[target][0].replace("x86_64-unknown-linux-gnu", "'{}'".format(target) if "." in target else target)
438438

439439
if 'profile' not in config:
440-
set('profile', 'user', config)
440+
set('profile', 'dist', config)
441441
configure_file(sections, top_level_keys, targets, config)
442442
return section_order, sections, targets
443443

0 commit comments

Comments
 (0)