Skip to content

Commit 4a101b4

Browse files
committed
Auto merge of rust-lang#129758 - cuviper:beta-next, r=cuviper
[beta] backports - Emit specific message for `time<0.3.35` inference failure rust-lang#129343 - Use a reduced recursion limit in the MIR inliner's cycle breaker rust-lang#129714 - rustdoc: do not run doctests with invalid langstrings rust-lang#128838 r? cuviper
2 parents 4a765c0 + a4461df commit 4a101b4

14 files changed

+135
-14
lines changed

compiler/rustc_infer/messages.ftl

+2
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,8 @@ infer_type_annotations_needed = {$source_kind ->
388388
}
389389
.label = type must be known at this point
390390
391+
infer_type_annotations_needed_error_time = this is an inference error on crate `time` caused by an API change in Rust 1.80.0; update `time` to version `>=0.3.35` by calling `cargo update`
392+
391393
infer_types_declared_different = these two types are declared with different lifetimes...
392394
393395
infer_warn_removing_apit_params = you could use a `use<...>` bound to explicitly capture `{$new_lifetime}`, but argument-position `impl Trait`s are not nameable

compiler/rustc_infer/src/errors/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ pub struct AnnotationRequired<'a> {
5454
#[note(infer_full_type_written)]
5555
pub was_written: Option<()>,
5656
pub path: PathBuf,
57+
#[note(infer_type_annotations_needed_error_time)]
58+
pub time_version: bool,
5759
}
5860

5961
// Copy of `AnnotationRequired` for E0283

compiler/rustc_infer/src/infer/need_type_info.rs

+44-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_errors::{codes::*, Diag, IntoDiagArg};
88
use rustc_hir as hir;
99
use rustc_hir::def::Res;
1010
use rustc_hir::def::{CtorOf, DefKind, Namespace};
11-
use rustc_hir::def_id::{DefId, LocalDefId};
11+
use rustc_hir::def_id::{DefId, LocalDefId, LOCAL_CRATE};
1212
use rustc_hir::intravisit::{self, Visitor};
1313
use rustc_hir::{Body, Closure, Expr, ExprKind, FnRetTy, HirId, LetStmt, LocalSource};
1414
use rustc_middle::bug;
@@ -21,7 +21,7 @@ use rustc_middle::ty::{
2121
TypeFoldable, TypeFolder, TypeSuperFoldable, TypeckResults,
2222
};
2323
use rustc_span::symbol::{sym, Ident};
24-
use rustc_span::{BytePos, Span, DUMMY_SP};
24+
use rustc_span::{BytePos, FileName, Span, DUMMY_SP};
2525
use std::borrow::Cow;
2626
use std::iter;
2727
use std::path::PathBuf;
@@ -409,6 +409,7 @@ impl<'tcx> InferCtxt<'tcx> {
409409
bad_label,
410410
was_written: None,
411411
path: Default::default(),
412+
time_version: false,
412413
}),
413414
TypeAnnotationNeeded::E0283 => self.dcx().create_err(AmbiguousImpl {
414415
span,
@@ -604,6 +605,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
604605
}
605606
}
606607
}
608+
609+
let time_version =
610+
self.detect_old_time_crate_version(failure_span, &kind, &mut infer_subdiags);
611+
607612
match error_code {
608613
TypeAnnotationNeeded::E0282 => self.dcx().create_err(AnnotationRequired {
609614
span,
@@ -615,6 +620,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
615620
bad_label: None,
616621
was_written: path.as_ref().map(|_| ()),
617622
path: path.unwrap_or_default(),
623+
time_version,
618624
}),
619625
TypeAnnotationNeeded::E0283 => self.dcx().create_err(AmbiguousImpl {
620626
span,
@@ -640,6 +646,42 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
640646
}),
641647
}
642648
}
649+
650+
/// Detect the inference regression on crate `time` <= 0.3.35 and emit a more targeted error.
651+
/// <https://github.com/rust-lang/rust/issues/127343>
652+
// FIXME: we should figure out a more generic version of doing this, ideally in cargo itself.
653+
fn detect_old_time_crate_version(
654+
&self,
655+
span: Option<Span>,
656+
kind: &InferSourceKind<'_>,
657+
// We will clear the non-actionable suggestion from the error to reduce noise.
658+
infer_subdiags: &mut Vec<SourceKindSubdiag<'_>>,
659+
) -> bool {
660+
// FIXME(#129461): We are time-boxing this code in the compiler. It'll start failing
661+
// compilation once we promote 1.89 to beta, which will happen in 9 months from now.
662+
#[cfg(not(version("1.89")))]
663+
const fn version_check() {}
664+
#[cfg(version("1.89"))]
665+
const fn version_check() {
666+
panic!("remove this check as presumably the ecosystem has moved from needing it");
667+
}
668+
const { version_check() };
669+
// Only relevant when building the `time` crate.
670+
if self.infcx.tcx.crate_name(LOCAL_CRATE) == sym::time
671+
&& let Some(span) = span
672+
&& let InferSourceKind::LetBinding { pattern_name, .. } = kind
673+
&& let Some(name) = pattern_name
674+
&& name.as_str() == "items"
675+
&& let FileName::Real(file) = self.infcx.tcx.sess.source_map().span_to_filename(span)
676+
{
677+
let path = file.local_path_if_available().to_string_lossy();
678+
if path.contains("format_description") && path.contains("parse") {
679+
infer_subdiags.clear();
680+
return true;
681+
}
682+
}
683+
false
684+
}
643685
}
644686

645687
#[derive(Debug)]

compiler/rustc_infer/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
2020
#![doc(rust_logo)]
2121
#![feature(box_patterns)]
22+
#![feature(cfg_version)]
2223
#![feature(control_flow_enum)]
2324
#![feature(extend_one)]
2425
#![feature(if_let_guard)]

compiler/rustc_mir_transform/src/inline/cycle.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,14 @@ pub(crate) fn mir_callgraph_reachable<'tcx>(
137137
}
138138
false
139139
}
140+
// FIXME(-Znext-solver): Remove this hack when trait solver overflow can return an error.
141+
// In code like that pointed out in #128887, the type complexity we ask the solver to deal with
142+
// grows as we recurse into the call graph. If we use the same recursion limit here and in the
143+
// solver, the solver hits the limit first and emits a fatal error. But if we use a reduced
144+
// limit, we will hit the limit first and give up on looking for inlining. And in any case,
145+
// the default recursion limits are quite generous for us. If we need to recurse 64 times
146+
// into the call graph, we're probably not going to find any useful MIR inlining.
147+
let recursion_limit = tcx.recursion_limit() / 2;
140148
process(
141149
tcx,
142150
param_env,
@@ -145,7 +153,7 @@ pub(crate) fn mir_callgraph_reachable<'tcx>(
145153
&mut Vec::new(),
146154
&mut FxHashSet::default(),
147155
&mut FxHashMap::default(),
148-
tcx.recursion_limit(),
156+
recursion_limit,
149157
)
150158
}
151159

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1883,6 +1883,7 @@ symbols! {
18831883
three_way_compare,
18841884
thumb2,
18851885
thumb_mode: "thumb-mode",
1886+
time,
18861887
tmm_reg,
18871888
to_owned_method,
18881889
to_string,

src/ci/scripts/select-xcode.sh

+17
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
#!/bin/bash
22
# This script selects the Xcode instance to use.
3+
# It also tries to do some cleanup in CI jobs of unused Xcodes.
34

45
set -euo pipefail
56
IFS=$'\n\t'
67

78
source "$(cd "$(dirname "$0")" && pwd)/../shared.sh"
89

910
if isMacOS; then
11+
# This additional step is to try to remove an Xcode we aren't using because each one is HUGE
12+
old_xcode="$(xcode-select --print-path)"
13+
old_xcode="${old_xcode%/*}" # pop a dir
14+
old_xcode="${old_xcode%/*}" # twice
15+
if [[ $old_xcode =~ $SELECT_XCODE ]]; then
16+
echo "xcode-select.sh's brutal hack may not be necessary?"
17+
exit 1
18+
elif [[ $SELECT_XCODE =~ "16" ]]; then
19+
echo "Using Xcode 16? Please fix xcode-select.sh"
20+
exit 1
21+
fi
22+
if [ $CI ]; then # just in case someone sources this on their real computer
23+
sudo rm -rf "${old_xcode}"
24+
xcode_16="${old_xcode%/*}/Xcode-16.0.0.app"
25+
sudo rm -rf "${xcode_16}"
26+
fi
1027
sudo xcode-select -s "${SELECT_XCODE}"
1128
fi

src/ci/scripts/upload-artifacts.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ fi
1919
if [[ "${DEPLOY-0}" -eq "1" ]] || [[ "${DEPLOY_ALT-0}" -eq "1" ]]; then
2020
dist_dir="${build_dir}/dist"
2121
rm -rf "${dist_dir}/doc"
22-
cp -r "${dist_dir}"/* "${upload_dir}"
22+
mv "${dist_dir}"/* "${upload_dir}"
2323
fi
2424

2525
# CPU usage statistics.
26-
cp build/cpu-usage.csv "${upload_dir}/cpu-${CI_JOB_NAME}.csv"
26+
mv build/cpu-usage.csv "${upload_dir}/cpu-${CI_JOB_NAME}.csv"
2727

2828
# Build metrics generated by x.py.
29-
cp "${build_dir}/metrics.json" "${upload_dir}/metrics-${CI_JOB_NAME}.json"
29+
mv "${build_dir}/metrics.json" "${upload_dir}/metrics-${CI_JOB_NAME}.json"
3030

3131
# Toolstate data.
3232
if [[ -n "${DEPLOY_TOOLSTATES_JSON+x}" ]]; then
33-
cp /tmp/toolstate/toolstates.json "${upload_dir}/${DEPLOY_TOOLSTATES_JSON}"
33+
mv /tmp/toolstate/toolstates.json "${upload_dir}/${DEPLOY_TOOLSTATES_JSON}"
3434
fi
3535

3636
echo "Files that will be uploaded:"

src/librustdoc/html/markdown.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,7 @@ pub(crate) struct TagIterator<'a, 'tcx> {
925925
data: &'a str,
926926
is_in_attribute_block: bool,
927927
extra: Option<&'a ExtraInfo<'tcx>>,
928+
is_error: bool,
928929
}
929930

930931
#[derive(Clone, Debug, Eq, PartialEq)]
@@ -951,13 +952,20 @@ struct Indices {
951952

952953
impl<'a, 'tcx> TagIterator<'a, 'tcx> {
953954
pub(crate) fn new(data: &'a str, extra: Option<&'a ExtraInfo<'tcx>>) -> Self {
954-
Self { inner: data.char_indices().peekable(), data, is_in_attribute_block: false, extra }
955+
Self {
956+
inner: data.char_indices().peekable(),
957+
data,
958+
is_in_attribute_block: false,
959+
extra,
960+
is_error: false,
961+
}
955962
}
956963

957-
fn emit_error(&self, err: impl Into<DiagMessage>) {
964+
fn emit_error(&mut self, err: impl Into<DiagMessage>) {
958965
if let Some(extra) = self.extra {
959966
extra.error_invalid_codeblock_attr(err);
960967
}
968+
self.is_error = true;
961969
}
962970

963971
fn skip_separators(&mut self) -> Option<usize> {
@@ -1155,6 +1163,9 @@ impl<'a, 'tcx> Iterator for TagIterator<'a, 'tcx> {
11551163
type Item = LangStringToken<'a>;
11561164

11571165
fn next(&mut self) -> Option<Self::Item> {
1166+
if self.is_error {
1167+
return None;
1168+
}
11581169
let Some(start) = self.skip_separators() else {
11591170
if self.is_in_attribute_block {
11601171
self.emit_error("unclosed attribute block (`{}`): missing `}` at the end");
@@ -1343,14 +1354,15 @@ impl LangString {
13431354
}
13441355
};
13451356

1346-
call(&mut TagIterator::new(string, extra));
1357+
let mut tag_iter = TagIterator::new(string, extra);
1358+
call(&mut tag_iter);
13471359

13481360
// ignore-foo overrides ignore
13491361
if !ignores.is_empty() {
13501362
data.ignore = Ignore::Some(ignores);
13511363
}
13521364

1353-
data.rust &= !seen_custom_tag && (!seen_other_tags || seen_rust_tags);
1365+
data.rust &= !seen_custom_tag && (!seen_other_tags || seen_rust_tags) && !tag_iter.is_error;
13541366

13551367
data
13561368
}

src/librustdoc/html/markdown/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn test_lang_string_parse() {
6161
..Default::default()
6262
});
6363
// error
64-
t(LangString { original: "{rust}".into(), rust: true, ..Default::default() });
64+
t(LangString { original: "{rust}".into(), rust: false, ..Default::default() });
6565
t(LangString {
6666
original: "{.rust}".into(),
6767
rust: true,
@@ -233,7 +233,7 @@ fn test_lang_string_parse() {
233233
..Default::default()
234234
});
235235
// error
236-
t(LangString { original: "{class=first=second}".into(), rust: true, ..Default::default() });
236+
t(LangString { original: "{class=first=second}".into(), rust: false, ..Default::default() });
237237
// error
238238
t(LangString {
239239
original: "{class=first.second}".into(),
@@ -261,7 +261,7 @@ fn test_lang_string_parse() {
261261
..Default::default()
262262
});
263263
// error
264-
t(LangString { original: r#"{class=f"irst"}"#.into(), rust: true, ..Default::default() });
264+
t(LangString { original: r#"{class=f"irst"}"#.into(), rust: false, ..Default::default() });
265265
}
266266

267267
#[test]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ compile-flags:--test
2+
//@ check-pass
3+
#![allow(rustdoc::invalid_codeblock_attributes)]
4+
5+
// https://github.com/rust-lang/rust/pull/124577#issuecomment-2276034737
6+
7+
// Test that invalid langstrings don't get run.
8+
9+
/// ```{rust,ignore}
10+
/// panic!();
11+
/// ```
12+
pub struct Foo;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
running 0 tests
3+
4+
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
5+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#![crate_name = "time"]
2+
3+
fn main() {
4+
let items = Box::new(vec![]); //~ ERROR E0282
5+
//~^ NOTE type must be known at this point
6+
//~| NOTE this is an inference error on crate `time` caused by an API change in Rust 1.80.0; update `time` to version `>=0.3.35`
7+
items.into();
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0282]: type annotations needed for `Box<Vec<_>>`
2+
--> $DIR/detect-old-time-version-format_description-parse.rs:4:9
3+
|
4+
LL | let items = Box::new(vec![]);
5+
| ^^^^^ ---------------- type must be known at this point
6+
|
7+
= note: this is an inference error on crate `time` caused by an API change in Rust 1.80.0; update `time` to version `>=0.3.35` by calling `cargo update`
8+
9+
error: aborting due to 1 previous error
10+
11+
For more information about this error, try `rustc --explain E0282`.

0 commit comments

Comments
 (0)