Skip to content

Commit

Permalink
Auto merge of #125379 - matthiaskrgr:rollup-6149w01, r=matthiaskrgr
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed May 21, 2024
2 parents 5065123 + d04e2e2 commit 39e02f1
Show file tree
Hide file tree
Showing 143 changed files with 308 additions and 97 deletions.
10 changes: 10 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!--
If this PR is related to an unstable feature or an otherwise tracked effort,
please link to the relevant tracking issue here. If you don't know of a related
tracking issue or there are none, feel free to ignore this.
This PR will get automatically assigned to a reviewer. In case you would like
a specific user to review your work, you can assign it to them by using
r​? <reviewer name>
-->
12 changes: 9 additions & 3 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,15 @@ impl<'a> Parser<'a> {
let attrs = self.parse_inner_attributes()?;

let post_attr_lo = self.token.span;
let mut items = ThinVec::new();
while let Some(item) = self.parse_item(ForceCollect::No)? {
self.maybe_consume_incorrect_semicolon(Some(&item));
let mut items: ThinVec<P<_>> = ThinVec::new();

// There shouldn't be any stray semicolons before or after items.
// `parse_item` consumes the appropriate semicolons so any leftover is an error.
loop {
while self.maybe_consume_incorrect_semicolon(items.last().map(|x| &**x)) {} // Eat all bad semicolons
let Some(item) = self.parse_item(ForceCollect::No)? else {
break;
};
items.push(item);
}

Expand Down
101 changes: 87 additions & 14 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use rustc_ast::{
};
use rustc_ast_pretty::pprust::where_bound_predicate_to_string;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::fx::FxIndexSet;
use rustc_errors::{
codes::*, pluralize, struct_span_code_err, Applicability, Diag, ErrorGuaranteed, MultiSpan,
SuggestionStyle,
Expand All @@ -31,7 +32,7 @@ use rustc_span::edit_distance::find_best_match_for_name;
use rustc_span::edition::Edition;
use rustc_span::hygiene::MacroKind;
use rustc_span::symbol::{kw, sym, Ident, Symbol};
use rustc_span::Span;
use rustc_span::{Span, DUMMY_SP};

use rustc_middle::ty;

Expand Down Expand Up @@ -2714,8 +2715,17 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
self.suggest_introducing_lifetime(
&mut err,
Some(lifetime_ref.ident.name.as_str()),
|err, _, span, message, suggestion| {
err.span_suggestion(span, message, suggestion, Applicability::MaybeIncorrect);
|err, _, span, message, suggestion, span_suggs| {
err.multipart_suggestion_with_style(
message,
std::iter::once((span, suggestion)).chain(span_suggs.clone()).collect(),
Applicability::MaybeIncorrect,
if span_suggs.is_empty() {
SuggestionStyle::ShowCode
} else {
SuggestionStyle::ShowAlways
},
);
true
},
);
Expand All @@ -2726,13 +2736,20 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
&self,
err: &mut Diag<'_>,
name: Option<&str>,
suggest: impl Fn(&mut Diag<'_>, bool, Span, Cow<'static, str>, String) -> bool,
suggest: impl Fn(
&mut Diag<'_>,
bool,
Span,
Cow<'static, str>,
String,
Vec<(Span, String)>,
) -> bool,
) {
let mut suggest_note = true;
for rib in self.lifetime_ribs.iter().rev() {
let mut should_continue = true;
match rib.kind {
LifetimeRibKind::Generics { binder: _, span, kind } => {
LifetimeRibKind::Generics { binder, span, kind } => {
// Avoid suggesting placing lifetime parameters on constant items unless the relevant
// feature is enabled. Suggest the parent item as a possible location if applicable.
if let LifetimeBinderKind::ConstItem = kind
Expand Down Expand Up @@ -2761,11 +2778,53 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
| LifetimeBinderKind::PolyTrait
| LifetimeBinderKind::WhereBound
);

let mut rm_inner_binders: FxIndexSet<Span> = Default::default();
let (span, sugg) = if span.is_empty() {
let mut binder_idents: FxIndexSet<Ident> = Default::default();
binder_idents.insert(Ident::from_str(name.unwrap_or("'a")));

// We need to special case binders in the following situation:
// Change `T: for<'a> Trait<T> + 'b` to `for<'a, 'b> T: Trait<T> + 'b`
// T: for<'a> Trait<T> + 'b
// ^^^^^^^ remove existing inner binder `for<'a>`
// for<'a, 'b> T: Trait<T> + 'b
// ^^^^^^^^^^^ suggest outer binder `for<'a, 'b>`
if let LifetimeBinderKind::WhereBound = kind
&& let Some(ast::WherePredicate::BoundPredicate(
ast::WhereBoundPredicate { bounded_ty, bounds, .. },
)) = self.diag_metadata.current_where_predicate
&& bounded_ty.id == binder
{
for bound in bounds {
if let ast::GenericBound::Trait(poly_trait_ref, _) = bound
&& let span = poly_trait_ref
.span
.with_hi(poly_trait_ref.trait_ref.path.span.lo())
&& !span.is_empty()
{
rm_inner_binders.insert(span);
poly_trait_ref.bound_generic_params.iter().for_each(|v| {
binder_idents.insert(v.ident);
});
}
}
}

let binders_sugg = binder_idents.into_iter().enumerate().fold(
"".to_string(),
|mut binders, (i, x)| {
if i != 0 {
binders += ", ";
}
binders += x.as_str();
binders
},
);
let sugg = format!(
"{}<{}>{}",
if higher_ranked { "for" } else { "" },
name.unwrap_or("'a"),
binders_sugg,
if higher_ranked { " " } else { "" },
);
(span, sugg)
Expand All @@ -2780,24 +2839,39 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
let sugg = format!("{}, ", name.unwrap_or("'a"));
(span, sugg)
};

if higher_ranked {
let message = Cow::from(format!(
"consider making the {} lifetime-generic with a new `{}` lifetime",
kind.descr(),
name.unwrap_or("'a"),
));
should_continue = suggest(err, true, span, message, sugg);
should_continue = suggest(
err,
true,
span,
message,
sugg,
if !rm_inner_binders.is_empty() {
rm_inner_binders
.into_iter()
.map(|v| (v, "".to_string()))
.collect::<Vec<_>>()
} else {
vec![]
},
);
err.note_once(
"for more information on higher-ranked polymorphism, visit \
https://doc.rust-lang.org/nomicon/hrtb.html",
);
} else if let Some(name) = name {
let message =
Cow::from(format!("consider introducing lifetime `{name}` here"));
should_continue = suggest(err, false, span, message, sugg);
should_continue = suggest(err, false, span, message, sugg, vec![]);
} else {
let message = Cow::from("consider introducing a named lifetime parameter");
should_continue = suggest(err, false, span, message, sugg);
should_continue = suggest(err, false, span, message, sugg, vec![]);
}
}
LifetimeRibKind::Item | LifetimeRibKind::ConstParamTy => break,
Expand Down Expand Up @@ -3033,11 +3107,11 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
self.suggest_introducing_lifetime(
err,
None,
|err, higher_ranked, span, message, intro_sugg| {
|err, higher_ranked, span, message, intro_sugg, _| {
err.multipart_suggestion_verbose(
message,
std::iter::once((span, intro_sugg))
.chain(spans_suggs.iter().cloned())
.chain(spans_suggs.clone())
.collect(),
Applicability::MaybeIncorrect,
);
Expand Down Expand Up @@ -3161,11 +3235,11 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
self.suggest_introducing_lifetime(
err,
None,
|err, higher_ranked, span, message, intro_sugg| {
|err, higher_ranked, span, message, intro_sugg, _| {
err.multipart_suggestion_verbose(
message,
std::iter::once((span, intro_sugg))
.chain(spans_suggs.iter().cloned())
.chain(spans_suggs.clone())
.collect(),
Applicability::MaybeIncorrect,
);
Expand Down Expand Up @@ -3309,7 +3383,6 @@ fn mk_where_bound_predicate(
poly_trait_ref: &ast::PolyTraitRef,
ty: &Ty,
) -> Option<ast::WhereBoundPredicate> {
use rustc_span::DUMMY_SP;
let modified_segments = {
let mut segments = path.segments.clone();
let [preceding @ .., second_last, last] = segments.as_mut_slice() else {
Expand Down
5 changes: 1 addition & 4 deletions src/bootstrap/src/core/build_steps/synthetic_targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,5 @@ fn create_synthetic_target(
customize(spec_map);

std::fs::write(&path, serde_json::to_vec_pretty(&spec).unwrap()).unwrap();
let target = TargetSelection::create_synthetic(&name, path.to_str().unwrap());
crate::utils::cc_detect::find_target(builder, target);

target
TargetSelection::create_synthetic(&name, path.to_str().unwrap())
}
1 change: 0 additions & 1 deletion src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ run-make/rmeta-preferred/Makefile
run-make/rustc-macro-dep-files/Makefile
run-make/rustdoc-io-error/Makefile
run-make/rustdoc-scrape-examples-macros/Makefile
run-make/rustdoc-scrape-examples-multiple/Makefile
run-make/rustdoc-verify-output-files/Makefile
run-make/rustdoc-with-output-option/Makefile
run-make/rustdoc-with-short-out-dir-option/Makefile
Expand Down
2 changes: 1 addition & 1 deletion src/tools/tidy/src/ui_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const ENTRY_LIMIT: usize = 900;
// FIXME: The following limits should be reduced eventually.

const ISSUES_ENTRY_LIMIT: usize = 1676;
const ROOT_ENTRY_LIMIT: usize = 859;
const ROOT_ENTRY_LIMIT: usize = 757;

const EXPECTED_TEST_FILE_EXTENSIONS: &[&str] = &[
"rs", // test source files
Expand Down
5 changes: 0 additions & 5 deletions tests/run-make/rustdoc-scrape-examples-multiple/Makefile

This file was deleted.

6 changes: 6 additions & 0 deletions tests/run-make/rustdoc-scrape-examples-multiple/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[path = "../rustdoc-scrape-examples-remap/scrape.rs"]
mod scrape;

fn main() {
scrape::scrape(&[]);
}
21 changes: 0 additions & 21 deletions tests/run-make/rustdoc-scrape-examples-multiple/scrape.mk

This file was deleted.

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.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0603]: static `j` is private
--> $DIR/xcrate-private-by-default.rs:23:29
--> $DIR/private-by-default.rs:23:29
|
LL | static_priv_by_default::j;
| ^ private static
Expand All @@ -11,7 +11,7 @@ LL | static j: isize = 0;
| ^^^^^^^^^^^^^^^

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

error[E0603]: unit struct `l` is private
--> $DIR/xcrate-private-by-default.rs:27:29
--> $DIR/private-by-default.rs:27:29
|
LL | static_priv_by_default::l;
| ^ private unit struct
Expand All @@ -35,7 +35,7 @@ LL | struct l;
| ^^^^^^^^

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

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

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

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

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

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

error[E0603]: module `foo` is private
--> $DIR/xcrate-private-by-default.rs:43:35
--> $DIR/private-by-default.rs:43:35
|
LL | foo::<static_priv_by_default::foo::e>();
| ^^^ - type alias `e` is not publicly re-exported
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0423]: expected value, found struct `xcrate_unit_struct::StructWithFields`
--> $DIR/xcrate-unit-struct.rs:9:13
--> $DIR/unit-struct.rs:9:13
|
LL | let _ = xcrate_unit_struct::StructWithFields;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use struct literal syntax instead: `xcrate_unit_struct::StructWithFields { foo: val }`
Expand All @@ -10,7 +10,7 @@ LL | pub struct StructWithFields {
| --------------------------- `xcrate_unit_struct::StructWithFields` defined here

error[E0423]: expected value, found struct `xcrate_unit_struct::StructWithPrivFields`
--> $DIR/xcrate-unit-struct.rs:11:13
--> $DIR/unit-struct.rs:11:13
|
LL | let _ = xcrate_unit_struct::StructWithPrivFields;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
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.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 39e02f1

Please sign in to comment.