Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit a1c28d1

Browse files
committed
Auto merge of rust-lang#122959 - matthiaskrgr:rollup-f7cx6dd, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#116016 (Soft-destabilize `RustcEncodable` & `RustcDecodable`, remove from prelude in next edition) - rust-lang#121281 (regression test for rust-lang#103626) - rust-lang#122168 (Fix validation on substituted callee bodies in MIR inliner) - rust-lang#122217 (Handle str literals written with `'` lexed as lifetime) - rust-lang#122379 (transmute: caution against int2ptr transmutation) - rust-lang#122907 (Uniquify `ReError` on input mode in canonicalizer) - rust-lang#122942 (Add test in higher ranked subtype) - rust-lang#122943 (add a couple more ice tests) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 2f090c3 + 5f5362d commit a1c28d1

File tree

65 files changed

+1700
-130
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1700
-130
lines changed

compiler/rustc_const_eval/src/transform/validate.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl<'tcx> MirPass<'tcx> for Validator {
8585
cfg_checker.check_cleanup_control_flow();
8686

8787
// Also run the TypeChecker.
88-
for (location, msg) in validate_types(tcx, self.mir_phase, param_env, body) {
88+
for (location, msg) in validate_types(tcx, self.mir_phase, param_env, body, body) {
8989
cfg_checker.fail(location, msg);
9090
}
9191

@@ -541,19 +541,25 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> {
541541

542542
/// A faster version of the validation pass that only checks those things which may break when
543543
/// instantiating any generic parameters.
544+
///
545+
/// `caller_body` is used to detect cycles in MIR inlining and MIR validation before
546+
/// `optimized_mir` is available.
544547
pub fn validate_types<'tcx>(
545548
tcx: TyCtxt<'tcx>,
546549
mir_phase: MirPhase,
547550
param_env: ty::ParamEnv<'tcx>,
548551
body: &Body<'tcx>,
552+
caller_body: &Body<'tcx>,
549553
) -> Vec<(Location, String)> {
550-
let mut type_checker = TypeChecker { body, tcx, param_env, mir_phase, failures: Vec::new() };
554+
let mut type_checker =
555+
TypeChecker { body, caller_body, tcx, param_env, mir_phase, failures: Vec::new() };
551556
type_checker.visit_body(body);
552557
type_checker.failures
553558
}
554559

555560
struct TypeChecker<'a, 'tcx> {
556561
body: &'a Body<'tcx>,
562+
caller_body: &'a Body<'tcx>,
557563
tcx: TyCtxt<'tcx>,
558564
param_env: ParamEnv<'tcx>,
559565
mir_phase: MirPhase,
@@ -705,8 +711,13 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
705711
}
706712
&ty::Coroutine(def_id, args) => {
707713
let f_ty = if let Some(var) = parent_ty.variant_index {
708-
let gen_body = if def_id == self.body.source.def_id() {
709-
self.body
714+
// If we're currently validating an inlined copy of this body,
715+
// then it will no longer be parameterized over the original
716+
// args of the coroutine. Otherwise, we prefer to use this body
717+
// since we may be in the process of computing this MIR in the
718+
// first place.
719+
let gen_body = if def_id == self.caller_body.source.def_id() {
720+
self.caller_body
710721
} else {
711722
self.tcx.optimized_mir(def_id)
712723
};

compiler/rustc_infer/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ infer_lifetime_param_suggestion_elided = each elided lifetime in input position
169169
170170
infer_meant_byte_literal = if you meant to write a byte literal, prefix with `b`
171171
infer_meant_char_literal = if you meant to write a `char` literal, use single quotes
172-
infer_meant_str_literal = if you meant to write a `str` literal, use double quotes
172+
infer_meant_str_literal = if you meant to write a string literal, use double quotes
173173
infer_mismatched_static_lifetime = incompatible lifetime on type
174174
infer_more_targeted = {$has_param_name ->
175175
[true] `{$param_name}`

compiler/rustc_infer/src/errors/mod.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1339,15 +1339,12 @@ pub enum TypeErrorAdditionalDiags {
13391339
span: Span,
13401340
code: String,
13411341
},
1342-
#[suggestion(
1343-
infer_meant_str_literal,
1344-
code = "\"{code}\"",
1345-
applicability = "machine-applicable"
1346-
)]
1342+
#[multipart_suggestion(infer_meant_str_literal, applicability = "machine-applicable")]
13471343
MeantStrLiteral {
1348-
#[primary_span]
1349-
span: Span,
1350-
code: String,
1344+
#[suggestion_part(code = "\"")]
1345+
start: Span,
1346+
#[suggestion_part(code = "\"")]
1347+
end: Span,
13511348
},
13521349
#[suggestion(
13531350
infer_consider_specifying_length,

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2079,16 +2079,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
20792079
// If a string was expected and the found expression is a character literal,
20802080
// perhaps the user meant to write `"s"` to specify a string literal.
20812081
(ty::Ref(_, r, _), ty::Char) if r.is_str() => {
2082-
if let Ok(code) = self.tcx.sess().source_map().span_to_snippet(span) {
2083-
if let Some(code) =
2084-
code.strip_prefix('\'').and_then(|s| s.strip_suffix('\''))
2085-
{
2086-
suggestions.push(TypeErrorAdditionalDiags::MeantStrLiteral {
2087-
span,
2088-
code: escape_literal(code),
2089-
})
2090-
}
2091-
}
2082+
suggestions.push(TypeErrorAdditionalDiags::MeantStrLiteral {
2083+
start: span.with_hi(span.lo() + BytePos(1)),
2084+
end: span.with_lo(span.hi() - BytePos(1)),
2085+
})
20922086
}
20932087
// For code `if Some(..) = expr `, the type mismatch may be expected `bool` but found `()`,
20942088
// we try to suggest to add the missing `let` for `if let Some(..) = expr`

compiler/rustc_lexer/src/cursor.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl<'a> Cursor<'a> {
4646
/// If requested position doesn't exist, `EOF_CHAR` is returned.
4747
/// However, getting `EOF_CHAR` doesn't always mean actual end of file,
4848
/// it should be checked with `is_eof` method.
49-
pub(crate) fn first(&self) -> char {
49+
pub fn first(&self) -> char {
5050
// `.next()` optimizes better than `.nth(0)`
5151
self.chars.clone().next().unwrap_or(EOF_CHAR)
5252
}
@@ -59,6 +59,15 @@ impl<'a> Cursor<'a> {
5959
iter.next().unwrap_or(EOF_CHAR)
6060
}
6161

62+
/// Peeks the third symbol from the input stream without consuming it.
63+
pub fn third(&self) -> char {
64+
// `.next()` optimizes better than `.nth(1)`
65+
let mut iter = self.chars.clone();
66+
iter.next();
67+
iter.next();
68+
iter.next().unwrap_or(EOF_CHAR)
69+
}
70+
6271
/// Checks if there is nothing more to consume.
6372
pub(crate) fn is_eof(&self) -> bool {
6473
self.chars.as_str().is_empty()

compiler/rustc_mir_transform/src/coroutine/by_move_body.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,9 @@ impl<'tcx> MirPass<'tcx> for ByMoveBody {
6464
let mut by_move_body = body.clone();
6565
MakeByMoveBody { tcx, by_ref_fields, by_move_coroutine_ty }.visit_body(&mut by_move_body);
6666
dump_mir(tcx, false, "coroutine_by_move", &0, &by_move_body, |_, _| Ok(()));
67-
by_move_body.source = mir::MirSource {
68-
instance: InstanceDef::CoroutineKindShim {
69-
coroutine_def_id: coroutine_def_id.to_def_id(),
70-
},
71-
promoted: None,
72-
};
67+
by_move_body.source = mir::MirSource::from_instance(InstanceDef::CoroutineKindShim {
68+
coroutine_def_id: coroutine_def_id.to_def_id(),
69+
});
7370
body.coroutine.as_mut().unwrap().by_move_body = Some(by_move_body);
7471
}
7572
}

compiler/rustc_mir_transform/src/inline.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ impl<'tcx> Inliner<'tcx> {
213213
MirPhase::Runtime(RuntimePhase::Optimized),
214214
self.param_env,
215215
&callee_body,
216+
&caller_body,
216217
)
217218
.is_empty()
218219
{

compiler/rustc_next_trait_solver/src/canonicalizer.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ impl<Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeFolder<I>
239239
// FIXME: We should investigate the perf implications of not uniquifying
240240
// `ReErased`. We may be able to short-circuit registering region
241241
// obligations if we encounter a `ReErased` on one side, for example.
242-
ty::ReStatic | ty::ReErased => match self.canonicalize_mode {
242+
ty::ReStatic | ty::ReErased | ty::ReError(_) => match self.canonicalize_mode {
243243
CanonicalizeMode::Input => CanonicalVarKind::Region(ty::UniverseIndex::ROOT),
244244
CanonicalizeMode::Response { .. } => return r,
245245
},
@@ -277,7 +277,6 @@ impl<Infcx: InferCtxtLike<Interner = I>, I: Interner> TypeFolder<I>
277277
}
278278
}
279279
}
280-
ty::ReError(_) => return r,
281280
};
282281

283282
let existing_bound_var = match self.canonicalize_mode {

compiler/rustc_parse/messages.ftl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ parse_more_than_one_char = character literal may only contain one codepoint
568568
.remove_non = consider removing the non-printing characters
569569
.use_double_quotes = if you meant to write a {$is_byte ->
570570
[true] byte string
571-
*[false] `str`
571+
*[false] string
572572
} literal, use double quotes
573573
574574
parse_multiple_skipped_lines = multiple lines skipped by escaped newline
@@ -833,6 +833,7 @@ parse_unknown_prefix = prefix `{$prefix}` is unknown
833833
.label = unknown prefix
834834
.note = prefixed identifiers and literals are reserved since Rust 2021
835835
.suggestion_br = use `br` for a raw byte string
836+
.suggestion_str = if you meant to write a string literal, use double quotes
836837
.suggestion_whitespace = consider inserting whitespace here
837838
838839
parse_unknown_start_of_token = unknown start of token: {$escaped}

compiler/rustc_parse/src/errors.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1987,6 +1987,17 @@ pub enum UnknownPrefixSugg {
19871987
style = "verbose"
19881988
)]
19891989
Whitespace(#[primary_span] Span),
1990+
#[multipart_suggestion(
1991+
parse_suggestion_str,
1992+
applicability = "maybe-incorrect",
1993+
style = "verbose"
1994+
)]
1995+
MeantStr {
1996+
#[suggestion_part(code = "\"")]
1997+
start: Span,
1998+
#[suggestion_part(code = "\"")]
1999+
end: Span,
2000+
},
19902001
}
19912002

19922003
#[derive(Diagnostic)]
@@ -2198,12 +2209,21 @@ pub enum MoreThanOneCharSugg {
21982209
ch: String,
21992210
},
22002211
#[suggestion(parse_use_double_quotes, code = "{sugg}", applicability = "machine-applicable")]
2201-
Quotes {
2212+
QuotesFull {
22022213
#[primary_span]
22032214
span: Span,
22042215
is_byte: bool,
22052216
sugg: String,
22062217
},
2218+
#[multipart_suggestion(parse_use_double_quotes, applicability = "machine-applicable")]
2219+
Quotes {
2220+
#[suggestion_part(code = "{prefix}\"")]
2221+
start: Span,
2222+
#[suggestion_part(code = "\"")]
2223+
end: Span,
2224+
is_byte: bool,
2225+
prefix: &'static str,
2226+
},
22072227
}
22082228

22092229
#[derive(Subdiagnostic)]

0 commit comments

Comments
 (0)