Skip to content

Commit 283db70

Browse files
committed
Auto merge of #141545 - GuillaumeGomez:rollup-myrvuqq, r=GuillaumeGomez
Rollup of 6 pull requests Successful merges: - #141413 (Make #[cfg(version)] respect RUSTC_OVERRIDE_VERSION_STRING) - #141443 (make teach_help message for cast-before-pass-to-variadic more precise) - #141508 (bootstrap: clippy: set TESTNAME based on given paths) - #141512 (Avoid extra path trimming in method not found error) - #141530 (Added unstable feature doc comments to unstable book) - #141541 (Random nits) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 88b3b52 + 43cb506 commit 283db70

38 files changed

+197
-62
lines changed

compiler/rustc_attr_data_structures/src/version.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use std::fmt::{self, Display};
2+
use std::sync::OnceLock;
23

34
use rustc_macros::{
45
Decodable, Encodable, HashStable_Generic, PrintAttribute, current_rustc_version,
@@ -16,8 +17,29 @@ pub struct RustcVersion {
1617

1718
impl RustcVersion {
1819
pub const CURRENT: Self = current_rustc_version!();
20+
pub fn current_overridable() -> Self {
21+
*CURRENT_OVERRIDABLE.get_or_init(|| {
22+
if let Ok(override_var) = std::env::var("RUSTC_OVERRIDE_VERSION_STRING")
23+
&& let Some(override_) = Self::parse_str(&override_var)
24+
{
25+
override_
26+
} else {
27+
Self::CURRENT
28+
}
29+
})
30+
}
31+
fn parse_str(value: &str) -> Option<Self> {
32+
// Ignore any suffixes such as "-dev" or "-nightly".
33+
let mut components = value.split('-').next().unwrap().splitn(3, '.');
34+
let major = components.next()?.parse().ok()?;
35+
let minor = components.next()?.parse().ok()?;
36+
let patch = components.next().unwrap_or("0").parse().ok()?;
37+
Some(RustcVersion { major, minor, patch })
38+
}
1939
}
2040

41+
static CURRENT_OVERRIDABLE: OnceLock<RustcVersion> = OnceLock::new();
42+
2143
impl Display for RustcVersion {
2244
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
2345
write!(formatter, "{}.{}.{}", self.major, self.minor, self.patch)

compiler/rustc_attr_parsing/src/attributes/cfg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ pub fn eval_condition(
129129

130130
// See https://github.com/rust-lang/rust/issues/64796#issuecomment-640851454 for details
131131
if sess.psess.assume_incomplete_release {
132-
RustcVersion::CURRENT > min_version
132+
RustcVersion::current_overridable() > min_version
133133
} else {
134-
RustcVersion::CURRENT >= min_version
134+
RustcVersion::current_overridable() >= min_version
135135
}
136136
}
137137
MetaItemKind::List(mis) => {

compiler/rustc_hir_typeck/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ hir_typeck_option_result_copied = use `{$def_path}::copied` to copy the value in
169169
170170
hir_typeck_pass_to_variadic_function = can't pass `{$ty}` to variadic function
171171
.suggestion = cast the value to `{$cast_ty}`
172-
.teach_help = certain types, like `{$ty}`, must be casted before passing them to a variadic function, because of arcane ABI rules dictated by the C standard
172+
.teach_help = certain types, like `{$ty}`, must be cast before passing them to a variadic function to match the implicit cast that a C compiler would perform as part of C's numeric promotion rules
173173
174174
hir_typeck_ptr_cast_add_auto_to_object = cannot add {$traits_len ->
175175
[1] auto trait {$traits}

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
599599
let tcx = self.tcx;
600600
let rcvr_ty = self.resolve_vars_if_possible(rcvr_ty);
601601
let mut ty_file = None;
602-
let (mut ty_str, short_ty_str) =
602+
let (ty_str, short_ty_str) =
603603
if trait_missing_method && let ty::Dynamic(predicates, _, _) = rcvr_ty.kind() {
604604
(predicates.to_string(), with_forced_trimmed_paths!(predicates.to_string()))
605605
} else {
@@ -738,10 +738,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
738738
err.span_label(within_macro_span, "due to this macro variable");
739739
}
740740

741-
if short_ty_str.len() < ty_str.len() && ty_str.len() > 10 {
742-
ty_str = short_ty_str;
743-
}
744-
745741
if rcvr_ty.references_error() {
746742
err.downgrade_to_delayed_bug();
747743
}

compiler/rustc_infer/src/infer/canonical/query_response.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use crate::infer::canonical::{
2323
QueryOutlivesConstraint, QueryRegionConstraints, QueryResponse,
2424
};
2525
use crate::infer::region_constraints::{Constraint, RegionConstraintData};
26-
use crate::infer::{DefineOpaqueTypes, InferCtxt, InferOk, InferResult};
26+
use crate::infer::{DefineOpaqueTypes, InferCtxt, InferOk, InferResult, SubregionOrigin};
2727
use crate::traits::query::NoSolution;
2828
use crate::traits::{
2929
Obligation, ObligationCause, PredicateObligation, PredicateObligations, ScrubbedTraitError,
@@ -593,10 +593,10 @@ impl<'tcx> InferCtxt<'tcx> {
593593
// no action needed
594594
}
595595
(GenericArgKind::Lifetime(v1), GenericArgKind::Lifetime(v2)) => {
596-
obligations.extend(
597-
self.at(cause, param_env)
598-
.eq(DefineOpaqueTypes::Yes, v1, v2)?
599-
.into_obligations(),
596+
self.inner.borrow_mut().unwrap_region_constraints().make_eqregion(
597+
SubregionOrigin::RelateRegionParamBound(cause.span, None),
598+
v1,
599+
v2,
600600
);
601601
}
602602
(GenericArgKind::Const(v1), GenericArgKind::Const(v2)) => {

compiler/rustc_trait_selection/src/solve/select.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::solve::inspect::{self, ProofTreeInferCtxtExt};
1515

1616
#[extension(pub trait InferCtxtSelectExt<'tcx>)]
1717
impl<'tcx> InferCtxt<'tcx> {
18+
/// Do not use this directly. This is called from [`crate::traits::SelectionContext::select`].
1819
fn select_in_new_trait_solver(
1920
&self,
2021
obligation: &TraitObligation<'tcx>,

src/bootstrap/src/core/build_steps/test.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ impl Step for Clippy {
739739
const DEFAULT: bool = false;
740740

741741
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
742-
run.path("src/tools/clippy")
742+
run.suite_path("src/tools/clippy/tests").path("src/tools/clippy")
743743
}
744744

745745
fn make_run(run: RunConfig<'_>) {
@@ -783,6 +783,23 @@ impl Step for Clippy {
783783
let host_libs = builder.stage_out(compiler, Mode::ToolRustc).join(builder.cargo_dir());
784784
cargo.env("HOST_LIBS", host_libs);
785785

786+
// Collect paths of tests to run
787+
'partially_test: {
788+
let paths = &builder.config.paths[..];
789+
let mut test_names = Vec::new();
790+
for path in paths {
791+
if let Some(path) =
792+
helpers::is_valid_test_suite_arg(path, "src/tools/clippy/tests", builder)
793+
{
794+
test_names.push(path);
795+
} else if path.ends_with("src/tools/clippy") {
796+
// When src/tools/clippy is called directly, all tests should be run.
797+
break 'partially_test;
798+
}
799+
}
800+
cargo.env("TESTNAME", test_names.join(","));
801+
}
802+
786803
cargo.add_rustc_lib_path(builder);
787804
let cargo = prepare_cargo_test(cargo, &[], &[], host, builder);
788805

src/tools/tidy/src/features.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub struct Feature {
5454
pub tracking_issue: Option<NonZeroU32>,
5555
pub file: PathBuf,
5656
pub line: usize,
57+
pub description: Option<String>,
5758
}
5859
impl Feature {
5960
fn tracking_issue_display(&self) -> impl fmt::Display {
@@ -296,6 +297,7 @@ fn collect_lang_features_in(features: &mut Features, base: &Path, file: &str, ba
296297
let mut prev_names = vec![];
297298

298299
let lines = contents.lines().zip(1..);
300+
let mut doc_comments: Vec<String> = Vec::new();
299301
for (line, line_number) in lines {
300302
let line = line.trim();
301303

@@ -332,6 +334,13 @@ fn collect_lang_features_in(features: &mut Features, base: &Path, file: &str, ba
332334
continue;
333335
}
334336

337+
if in_feature_group {
338+
if let Some(doc_comment) = line.strip_prefix("///") {
339+
doc_comments.push(doc_comment.trim().to_string());
340+
continue;
341+
}
342+
}
343+
335344
let mut parts = line.split(',');
336345
let level = match parts.next().map(|l| l.trim().trim_start_matches('(')) {
337346
Some("unstable") => Status::Unstable,
@@ -438,9 +447,15 @@ fn collect_lang_features_in(features: &mut Features, base: &Path, file: &str, ba
438447
tracking_issue,
439448
file: path.to_path_buf(),
440449
line: line_number,
450+
description: if doc_comments.is_empty() {
451+
None
452+
} else {
453+
Some(doc_comments.join(" "))
454+
},
441455
});
442456
}
443457
}
458+
doc_comments.clear();
444459
}
445460
}
446461

@@ -564,6 +579,7 @@ fn map_lib_features(
564579
tracking_issue: find_attr_val(line, "issue").and_then(handle_issue_none),
565580
file: file.to_path_buf(),
566581
line: i + 1,
582+
description: None,
567583
};
568584
mf(Ok((feature_name, feature)), file, i + 1);
569585
continue;
@@ -600,6 +616,7 @@ fn map_lib_features(
600616
tracking_issue,
601617
file: file.to_path_buf(),
602618
line: i + 1,
619+
description: None,
603620
};
604621
if line.contains(']') {
605622
mf(Ok((feature_name, feature)), file, i + 1);

src/tools/unstable-book-gen/src/main.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@ use tidy::unstable_book::{
1212
collect_unstable_feature_names,
1313
};
1414

15-
fn generate_stub_issue(path: &Path, name: &str, issue: u32) {
16-
let content = format!(include_str!("stub-issue.md"), name = name, issue = issue);
15+
fn generate_stub_issue(path: &Path, name: &str, issue: u32, description: &str) {
16+
let content = format!(
17+
include_str!("stub-issue.md"),
18+
name = name,
19+
issue = issue,
20+
description = description
21+
);
1722
t!(write(path, content), path);
1823
}
1924

20-
fn generate_stub_no_issue(path: &Path, name: &str) {
21-
let content = format!(include_str!("stub-no-issue.md"), name = name);
25+
fn generate_stub_no_issue(path: &Path, name: &str, description: &str) {
26+
let content = format!(include_str!("stub-no-issue.md"), name = name, description = description);
2227
t!(write(path, content), path);
2328
}
2429

@@ -58,11 +63,17 @@ fn generate_unstable_book_files(src: &Path, out: &Path, features: &Features) {
5863
let file_name = format!("{feature_name}.md");
5964
let out_file_path = out.join(&file_name);
6065
let feature = &features[&feature_name_underscore];
66+
let description = feature.description.as_deref().unwrap_or_default();
6167

6268
if let Some(issue) = feature.tracking_issue {
63-
generate_stub_issue(&out_file_path, &feature_name_underscore, issue.get());
69+
generate_stub_issue(
70+
&out_file_path,
71+
&feature_name_underscore,
72+
issue.get(),
73+
&description,
74+
);
6475
} else {
65-
generate_stub_no_issue(&out_file_path, &feature_name_underscore);
76+
generate_stub_no_issue(&out_file_path, &feature_name_underscore, &description);
6677
}
6778
}
6879
}

src/tools/unstable-book-gen/src/stub-issue.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# `{name}`
22

3+
{description}
4+
35
The tracking issue for this feature is: [#{issue}]
46

57
[#{issue}]: https://github.com/rust-lang/rust/issues/{issue}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# `{name}`
22

3+
{description}
4+
35
This feature has no tracking issue, and is therefore likely internal to the compiler, not being intended for general use.
46

57
------------------------

tests/run-make/crate-loading/multiple-dep-versions.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ error[E0599]: no method named `foo` found for struct `dep_2_reexport::Type` in t
3939
--> replaced
4040
|
4141
LL | Type.foo();
42-
| ^^^ method not found in `Type`
42+
| ^^^ method not found in `dep_2_reexport::Type`
4343
|
4444
note: there are multiple different versions of crate `dependency` in the dependency graph
4545
--> replaced
@@ -63,7 +63,7 @@ error[E0599]: no function or associated item named `bar` found for struct `dep_2
6363
--> replaced
6464
|
6565
LL | Type::bar();
66-
| ^^^ function or associated item not found in `Type`
66+
| ^^^ function or associated item not found in `dep_2_reexport::Type`
6767
|
6868
note: there are multiple different versions of crate `dependency` in the dependency graph
6969
--> replaced

tests/ui/associated-types/issue-43924.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ error[E0599]: no function or associated item named `default` found for trait obj
1414
--> $DIR/issue-43924.rs:14:39
1515
|
1616
LL | assert_eq!(<() as Foo<u32>>::Out::default().to_string(), "false");
17-
| ^^^^^^^ function or associated item not found in `dyn ToString`
17+
| ^^^^^^^ function or associated item not found in `(dyn ToString + 'static)`
1818

1919
error: aborting due to 2 previous errors
2020

tests/ui/attributes/rustc_confusables.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ error[E0599]: no method named `foo` found for struct `rustc_confusables_across_c
4242
--> $DIR/rustc_confusables.rs:15:7
4343
|
4444
LL | x.foo();
45-
| ^^^ method not found in `BTreeSet`
45+
| ^^^ method not found in `rustc_confusables_across_crate::BTreeSet`
4646

4747
error[E0599]: no method named `push` found for struct `rustc_confusables_across_crate::BTreeSet` in the current scope
4848
--> $DIR/rustc_confusables.rs:17:7
4949
|
5050
LL | x.push();
51-
| ^^^^ method not found in `BTreeSet`
51+
| ^^^^ method not found in `rustc_confusables_across_crate::BTreeSet`
5252
|
5353
help: you might have meant to use `insert`
5454
|
@@ -60,7 +60,7 @@ error[E0599]: no method named `test` found for struct `rustc_confusables_across_
6060
--> $DIR/rustc_confusables.rs:20:7
6161
|
6262
LL | x.test();
63-
| ^^^^ method not found in `BTreeSet`
63+
| ^^^^ method not found in `rustc_confusables_across_crate::BTreeSet`
6464

6565
error[E0599]: no method named `pulled` found for struct `rustc_confusables_across_crate::BTreeSet` in the current scope
6666
--> $DIR/rustc_confusables.rs:22:7
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//@ run-pass
2+
//@ rustc-env:RUSTC_OVERRIDE_VERSION_STRING=1.50.3
3+
4+
#![feature(cfg_version)]
5+
6+
#[cfg(version("1.49.0"))]
7+
const ON_1_49_0: bool = true;
8+
#[cfg(version("1.50"))]
9+
const ON_1_50_0: bool = true;
10+
#[cfg(not(version("1.51")))]
11+
const ON_1_51_0: bool = false;
12+
13+
// This one uses the wrong syntax, so doesn't eval to true
14+
#[warn(unexpected_cfgs)]
15+
#[cfg(not(version = "1.48.0"))] //~ WARN unexpected `cfg` condition name: `version`
16+
const ON_1_48_0: bool = false;
17+
18+
fn main() {
19+
assert!(!ON_1_48_0);
20+
assert!(ON_1_49_0);
21+
assert!(ON_1_50_0);
22+
assert!(!ON_1_51_0);
23+
assert!(cfg!(version("1.1")));
24+
assert!(cfg!(version("1.49")));
25+
assert!(cfg!(version("1.50.0")));
26+
assert!(cfg!(version("1.50.3")));
27+
assert!(!cfg!(version("1.50.4")));
28+
assert!(!cfg!(version("1.51")));
29+
assert!(!cfg!(version("1.100")));
30+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
warning: unexpected `cfg` condition name: `version`
2+
--> $DIR/cfg-version-expand.rs:15:11
3+
|
4+
LL | #[cfg(not(version = "1.48.0"))]
5+
| ^^^^^^^^^^^^^^^^^^
6+
|
7+
= help: to expect this configuration use `--check-cfg=cfg(version, values("1.48.0"))`
8+
= note: see <https://doc.rust-lang.org/nightly/rustc/check-cfg.html> for more information about checking conditional configuration
9+
= note: `#[warn(unexpected_cfgs)]` on by default
10+
help: there is a similar config predicate: `version("..")`
11+
|
12+
LL - #[cfg(not(version = "1.48.0"))]
13+
LL + #[cfg(not(version("1.48.0")))]
14+
|
15+
16+
warning: 1 warning emitted
17+

tests/ui/empty/empty-struct-braces-expr.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ error[E0599]: no variant or associated item named `Empty3` found for enum `empty
121121
--> $DIR/empty-struct-braces-expr.rs:25:19
122122
|
123123
LL | let xe3 = XE::Empty3;
124-
| ^^^^^^ variant or associated item not found in `XE`
124+
| ^^^^^^ variant or associated item not found in `empty_struct::XE`
125125
|
126126
help: there is a variant with a similar name
127127
|
@@ -132,7 +132,7 @@ error[E0599]: no variant or associated item named `Empty3` found for enum `empty
132132
--> $DIR/empty-struct-braces-expr.rs:26:19
133133
|
134134
LL | let xe3 = XE::Empty3();
135-
| ^^^^^^ variant or associated item not found in `XE`
135+
| ^^^^^^ variant or associated item not found in `empty_struct::XE`
136136
|
137137
help: there is a variant with a similar name
138138
|

0 commit comments

Comments
 (0)