Skip to content

Commit 39e02f1

Browse files
committed
Auto merge of #125379 - matthiaskrgr:rollup-6149w01, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #123122 (Fix incorrect suggestion for undeclared hrtb lifetimes in where clauses.) - #123492 (add pull request template asking for relevant tracking issues) - #125276 (Fix parsing of erroneously placed semicolons) - #125310 (Move ~100 tests from tests/ui to subdirs) - #125357 (Migrate `run-make/rustdoc-scrape-examples-multiple` to `rmake.rs`) - #125369 (Don't do cc detection for synthetic targets) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5065123 + d04e2e2 commit 39e02f1

File tree

143 files changed

+308
-97
lines changed

Some content is hidden

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

143 files changed

+308
-97
lines changed

.github/pull_request_template.md

+10

compiler/rustc_parse/src/parser/item.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,15 @@ impl<'a> Parser<'a> {
5858
let attrs = self.parse_inner_attributes()?;
5959

6060
let post_attr_lo = self.token.span;
61-
let mut items = ThinVec::new();
62-
while let Some(item) = self.parse_item(ForceCollect::No)? {
63-
self.maybe_consume_incorrect_semicolon(Some(&item));
61+
let mut items: ThinVec<P<_>> = ThinVec::new();
62+
63+
// There shouldn't be any stray semicolons before or after items.
64+
// `parse_item` consumes the appropriate semicolons so any leftover is an error.
65+
loop {
66+
while self.maybe_consume_incorrect_semicolon(items.last().map(|x| &**x)) {} // Eat all bad semicolons
67+
let Some(item) = self.parse_item(ForceCollect::No)? else {
68+
break;
69+
};
6470
items.push(item);
6571
}
6672

compiler/rustc_resolve/src/late/diagnostics.rs

+87-14
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc_ast::{
1717
};
1818
use rustc_ast_pretty::pprust::where_bound_predicate_to_string;
1919
use rustc_data_structures::fx::FxHashSet;
20+
use rustc_data_structures::fx::FxIndexSet;
2021
use rustc_errors::{
2122
codes::*, pluralize, struct_span_code_err, Applicability, Diag, ErrorGuaranteed, MultiSpan,
2223
SuggestionStyle,
@@ -31,7 +32,7 @@ use rustc_span::edit_distance::find_best_match_for_name;
3132
use rustc_span::edition::Edition;
3233
use rustc_span::hygiene::MacroKind;
3334
use rustc_span::symbol::{kw, sym, Ident, Symbol};
34-
use rustc_span::Span;
35+
use rustc_span::{Span, DUMMY_SP};
3536

3637
use rustc_middle::ty;
3738

@@ -2714,8 +2715,17 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
27142715
self.suggest_introducing_lifetime(
27152716
&mut err,
27162717
Some(lifetime_ref.ident.name.as_str()),
2717-
|err, _, span, message, suggestion| {
2718-
err.span_suggestion(span, message, suggestion, Applicability::MaybeIncorrect);
2718+
|err, _, span, message, suggestion, span_suggs| {
2719+
err.multipart_suggestion_with_style(
2720+
message,
2721+
std::iter::once((span, suggestion)).chain(span_suggs.clone()).collect(),
2722+
Applicability::MaybeIncorrect,
2723+
if span_suggs.is_empty() {
2724+
SuggestionStyle::ShowCode
2725+
} else {
2726+
SuggestionStyle::ShowAlways
2727+
},
2728+
);
27192729
true
27202730
},
27212731
);
@@ -2726,13 +2736,20 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
27262736
&self,
27272737
err: &mut Diag<'_>,
27282738
name: Option<&str>,
2729-
suggest: impl Fn(&mut Diag<'_>, bool, Span, Cow<'static, str>, String) -> bool,
2739+
suggest: impl Fn(
2740+
&mut Diag<'_>,
2741+
bool,
2742+
Span,
2743+
Cow<'static, str>,
2744+
String,
2745+
Vec<(Span, String)>,
2746+
) -> bool,
27302747
) {
27312748
let mut suggest_note = true;
27322749
for rib in self.lifetime_ribs.iter().rev() {
27332750
let mut should_continue = true;
27342751
match rib.kind {
2735-
LifetimeRibKind::Generics { binder: _, span, kind } => {
2752+
LifetimeRibKind::Generics { binder, span, kind } => {
27362753
// Avoid suggesting placing lifetime parameters on constant items unless the relevant
27372754
// feature is enabled. Suggest the parent item as a possible location if applicable.
27382755
if let LifetimeBinderKind::ConstItem = kind
@@ -2761,11 +2778,53 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
27612778
| LifetimeBinderKind::PolyTrait
27622779
| LifetimeBinderKind::WhereBound
27632780
);
2781+
2782+
let mut rm_inner_binders: FxIndexSet<Span> = Default::default();
27642783
let (span, sugg) = if span.is_empty() {
2784+
let mut binder_idents: FxIndexSet<Ident> = Default::default();
2785+
binder_idents.insert(Ident::from_str(name.unwrap_or("'a")));
2786+
2787+
// We need to special case binders in the following situation:
2788+
// Change `T: for<'a> Trait<T> + 'b` to `for<'a, 'b> T: Trait<T> + 'b`
2789+
// T: for<'a> Trait<T> + 'b
2790+
// ^^^^^^^ remove existing inner binder `for<'a>`
2791+
// for<'a, 'b> T: Trait<T> + 'b
2792+
// ^^^^^^^^^^^ suggest outer binder `for<'a, 'b>`
2793+
if let LifetimeBinderKind::WhereBound = kind
2794+
&& let Some(ast::WherePredicate::BoundPredicate(
2795+
ast::WhereBoundPredicate { bounded_ty, bounds, .. },
2796+
)) = self.diag_metadata.current_where_predicate
2797+
&& bounded_ty.id == binder
2798+
{
2799+
for bound in bounds {
2800+
if let ast::GenericBound::Trait(poly_trait_ref, _) = bound
2801+
&& let span = poly_trait_ref
2802+
.span
2803+
.with_hi(poly_trait_ref.trait_ref.path.span.lo())
2804+
&& !span.is_empty()
2805+
{
2806+
rm_inner_binders.insert(span);
2807+
poly_trait_ref.bound_generic_params.iter().for_each(|v| {
2808+
binder_idents.insert(v.ident);
2809+
});
2810+
}
2811+
}
2812+
}
2813+
2814+
let binders_sugg = binder_idents.into_iter().enumerate().fold(
2815+
"".to_string(),
2816+
|mut binders, (i, x)| {
2817+
if i != 0 {
2818+
binders += ", ";
2819+
}
2820+
binders += x.as_str();
2821+
binders
2822+
},
2823+
);
27652824
let sugg = format!(
27662825
"{}<{}>{}",
27672826
if higher_ranked { "for" } else { "" },
2768-
name.unwrap_or("'a"),
2827+
binders_sugg,
27692828
if higher_ranked { " " } else { "" },
27702829
);
27712830
(span, sugg)
@@ -2780,24 +2839,39 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
27802839
let sugg = format!("{}, ", name.unwrap_or("'a"));
27812840
(span, sugg)
27822841
};
2842+
27832843
if higher_ranked {
27842844
let message = Cow::from(format!(
27852845
"consider making the {} lifetime-generic with a new `{}` lifetime",
27862846
kind.descr(),
27872847
name.unwrap_or("'a"),
27882848
));
2789-
should_continue = suggest(err, true, span, message, sugg);
2849+
should_continue = suggest(
2850+
err,
2851+
true,
2852+
span,
2853+
message,
2854+
sugg,
2855+
if !rm_inner_binders.is_empty() {
2856+
rm_inner_binders
2857+
.into_iter()
2858+
.map(|v| (v, "".to_string()))
2859+
.collect::<Vec<_>>()
2860+
} else {
2861+
vec![]
2862+
},
2863+
);
27902864
err.note_once(
27912865
"for more information on higher-ranked polymorphism, visit \
27922866
https://doc.rust-lang.org/nomicon/hrtb.html",
27932867
);
27942868
} else if let Some(name) = name {
27952869
let message =
27962870
Cow::from(format!("consider introducing lifetime `{name}` here"));
2797-
should_continue = suggest(err, false, span, message, sugg);
2871+
should_continue = suggest(err, false, span, message, sugg, vec![]);
27982872
} else {
27992873
let message = Cow::from("consider introducing a named lifetime parameter");
2800-
should_continue = suggest(err, false, span, message, sugg);
2874+
should_continue = suggest(err, false, span, message, sugg, vec![]);
28012875
}
28022876
}
28032877
LifetimeRibKind::Item | LifetimeRibKind::ConstParamTy => break,
@@ -3033,11 +3107,11 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
30333107
self.suggest_introducing_lifetime(
30343108
err,
30353109
None,
3036-
|err, higher_ranked, span, message, intro_sugg| {
3110+
|err, higher_ranked, span, message, intro_sugg, _| {
30373111
err.multipart_suggestion_verbose(
30383112
message,
30393113
std::iter::once((span, intro_sugg))
3040-
.chain(spans_suggs.iter().cloned())
3114+
.chain(spans_suggs.clone())
30413115
.collect(),
30423116
Applicability::MaybeIncorrect,
30433117
);
@@ -3161,11 +3235,11 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
31613235
self.suggest_introducing_lifetime(
31623236
err,
31633237
None,
3164-
|err, higher_ranked, span, message, intro_sugg| {
3238+
|err, higher_ranked, span, message, intro_sugg, _| {
31653239
err.multipart_suggestion_verbose(
31663240
message,
31673241
std::iter::once((span, intro_sugg))
3168-
.chain(spans_suggs.iter().cloned())
3242+
.chain(spans_suggs.clone())
31693243
.collect(),
31703244
Applicability::MaybeIncorrect,
31713245
);
@@ -3309,7 +3383,6 @@ fn mk_where_bound_predicate(
33093383
poly_trait_ref: &ast::PolyTraitRef,
33103384
ty: &Ty,
33113385
) -> Option<ast::WhereBoundPredicate> {
3312-
use rustc_span::DUMMY_SP;
33133386
let modified_segments = {
33143387
let mut segments = path.segments.clone();
33153388
let [preceding @ .., second_last, last] = segments.as_mut_slice() else {

src/bootstrap/src/core/build_steps/synthetic_targets.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,5 @@ fn create_synthetic_target(
8080
customize(spec_map);
8181

8282
std::fs::write(&path, serde_json::to_vec_pretty(&spec).unwrap()).unwrap();
83-
let target = TargetSelection::create_synthetic(&name, path.to_str().unwrap());
84-
crate::utils::cc_detect::find_target(builder, target);
85-
86-
target
83+
TargetSelection::create_synthetic(&name, path.to_str().unwrap())
8784
}

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ run-make/rmeta-preferred/Makefile
234234
run-make/rustc-macro-dep-files/Makefile
235235
run-make/rustdoc-io-error/Makefile
236236
run-make/rustdoc-scrape-examples-macros/Makefile
237-
run-make/rustdoc-scrape-examples-multiple/Makefile
238237
run-make/rustdoc-verify-output-files/Makefile
239238
run-make/rustdoc-with-output-option/Makefile
240239
run-make/rustdoc-with-short-out-dir-option/Makefile

src/tools/tidy/src/ui_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const ENTRY_LIMIT: usize = 900;
1616
// FIXME: The following limits should be reduced eventually.
1717

1818
const ISSUES_ENTRY_LIMIT: usize = 1676;
19-
const ROOT_ENTRY_LIMIT: usize = 859;
19+
const ROOT_ENTRY_LIMIT: usize = 757;
2020

2121
const EXPECTED_TEST_FILE_EXTENSIONS: &[&str] = &[
2222
"rs", // test source files

tests/run-make/rustdoc-scrape-examples-multiple/Makefile

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[path = "../rustdoc-scrape-examples-remap/scrape.rs"]
2+
mod scrape;
3+
4+
fn main() {
5+
scrape::scrape(&[]);
6+
}

tests/run-make/rustdoc-scrape-examples-multiple/scrape.mk

-21
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/ui/xcrate/xcrate-private-by-default.stderr tests/ui/cross-crate/private-by-default.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0603]: static `j` is private
2-
--> $DIR/xcrate-private-by-default.rs:23:29
2+
--> $DIR/private-by-default.rs:23:29
33
|
44
LL | static_priv_by_default::j;
55
| ^ private static
@@ -11,7 +11,7 @@ LL | static j: isize = 0;
1111
| ^^^^^^^^^^^^^^^
1212

1313
error[E0603]: function `k` is private
14-
--> $DIR/xcrate-private-by-default.rs:25:29
14+
--> $DIR/private-by-default.rs:25:29
1515
|
1616
LL | static_priv_by_default::k;
1717
| ^ private function
@@ -23,7 +23,7 @@ LL | fn k() {}
2323
| ^^^^^^
2424

2525
error[E0603]: unit struct `l` is private
26-
--> $DIR/xcrate-private-by-default.rs:27:29
26+
--> $DIR/private-by-default.rs:27:29
2727
|
2828
LL | static_priv_by_default::l;
2929
| ^ private unit struct
@@ -35,7 +35,7 @@ LL | struct l;
3535
| ^^^^^^^^
3636

3737
error[E0603]: enum `m` is private
38-
--> $DIR/xcrate-private-by-default.rs:29:35
38+
--> $DIR/private-by-default.rs:29:35
3939
|
4040
LL | foo::<static_priv_by_default::m>();
4141
| ^ private enum
@@ -47,7 +47,7 @@ LL | enum m {}
4747
| ^^^^^^
4848

4949
error[E0603]: type alias `n` is private
50-
--> $DIR/xcrate-private-by-default.rs:31:35
50+
--> $DIR/private-by-default.rs:31:35
5151
|
5252
LL | foo::<static_priv_by_default::n>();
5353
| ^ private type alias
@@ -59,7 +59,7 @@ LL | type n = isize;
5959
| ^^^^^^
6060

6161
error[E0603]: module `foo` is private
62-
--> $DIR/xcrate-private-by-default.rs:35:29
62+
--> $DIR/private-by-default.rs:35:29
6363
|
6464
LL | static_priv_by_default::foo::a;
6565
| ^^^ - static `a` is not publicly re-exported
@@ -73,7 +73,7 @@ LL | mod foo {
7373
| ^^^^^^^
7474

7575
error[E0603]: module `foo` is private
76-
--> $DIR/xcrate-private-by-default.rs:37:29
76+
--> $DIR/private-by-default.rs:37:29
7777
|
7878
LL | static_priv_by_default::foo::b;
7979
| ^^^ - function `b` is not publicly re-exported
@@ -87,7 +87,7 @@ LL | mod foo {
8787
| ^^^^^^^
8888

8989
error[E0603]: module `foo` is private
90-
--> $DIR/xcrate-private-by-default.rs:39:29
90+
--> $DIR/private-by-default.rs:39:29
9191
|
9292
LL | static_priv_by_default::foo::c;
9393
| ^^^ - unit struct `c` is not publicly re-exported
@@ -101,7 +101,7 @@ LL | mod foo {
101101
| ^^^^^^^
102102

103103
error[E0603]: module `foo` is private
104-
--> $DIR/xcrate-private-by-default.rs:41:35
104+
--> $DIR/private-by-default.rs:41:35
105105
|
106106
LL | foo::<static_priv_by_default::foo::d>();
107107
| ^^^ - enum `d` is not publicly re-exported
@@ -115,7 +115,7 @@ LL | mod foo {
115115
| ^^^^^^^
116116

117117
error[E0603]: module `foo` is private
118-
--> $DIR/xcrate-private-by-default.rs:43:35
118+
--> $DIR/private-by-default.rs:43:35
119119
|
120120
LL | foo::<static_priv_by_default::foo::e>();
121121
| ^^^ - type alias `e` is not publicly re-exported
File renamed without changes.
File renamed without changes.

tests/ui/xcrate/xcrate-unit-struct.stderr tests/ui/cross-crate/unit-struct.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0423]: expected value, found struct `xcrate_unit_struct::StructWithFields`
2-
--> $DIR/xcrate-unit-struct.rs:9:13
2+
--> $DIR/unit-struct.rs:9:13
33
|
44
LL | let _ = xcrate_unit_struct::StructWithFields;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use struct literal syntax instead: `xcrate_unit_struct::StructWithFields { foo: val }`
@@ -10,7 +10,7 @@ LL | pub struct StructWithFields {
1010
| --------------------------- `xcrate_unit_struct::StructWithFields` defined here
1111

1212
error[E0423]: expected value, found struct `xcrate_unit_struct::StructWithPrivFields`
13-
--> $DIR/xcrate-unit-struct.rs:11:13
13+
--> $DIR/unit-struct.rs:11:13
1414
|
1515
LL | let _ = xcrate_unit_struct::StructWithPrivFields;
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)