Skip to content

Commit b454012

Browse files
committed
Auto merge of #127296 - matthiaskrgr:rollup-1t1isa7, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #127092 (Change return-type-notation to use `(..)`) - #127184 (More refactorings to rustc_interface) - #127190 (Update LLVM submodule) - #127253 (Fix incorrect suggestion for extra argument with a type error) - #127280 (Disable rmake test rustdoc-io-error on riscv64gc-gnu) - #127294 (Less magic number for corountine) r? `@ghost` `@rustbot` modify labels: rollup
2 parents aa1d4f6 + 79bdb89 commit b454012

File tree

63 files changed

+478
-235
lines changed

Some content is hidden

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

63 files changed

+478
-235
lines changed

compiler/rustc_ast/src/ast.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ pub enum GenericArgs {
176176
AngleBracketed(AngleBracketedArgs),
177177
/// The `(A, B)` and `C` in `Foo(A, B) -> C`.
178178
Parenthesized(ParenthesizedArgs),
179+
/// `(..)` in return type notation
180+
ParenthesizedElided(Span),
179181
}
180182

181183
impl GenericArgs {
@@ -187,6 +189,7 @@ impl GenericArgs {
187189
match self {
188190
AngleBracketed(data) => data.span,
189191
Parenthesized(data) => data.span,
192+
ParenthesizedElided(span) => *span,
190193
}
191194
}
192195
}
@@ -2051,7 +2054,7 @@ impl UintTy {
20512054
/// * the `A: Bound` in `Trait<A: Bound>`
20522055
/// * the `RetTy` in `Trait(ArgTy, ArgTy) -> RetTy`
20532056
/// * the `C = { Ct }` in `Trait<C = { Ct }>` (feature `associated_const_equality`)
2054-
/// * the `f(): Bound` in `Trait<f(): Bound>` (feature `return_type_notation`)
2057+
/// * the `f(..): Bound` in `Trait<f(..): Bound>` (feature `return_type_notation`)
20552058
#[derive(Clone, Encodable, Decodable, Debug)]
20562059
pub struct AssocItemConstraint {
20572060
pub id: NodeId,

compiler/rustc_ast/src/mut_visit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ fn noop_visit_generic_args<T: MutVisitor>(generic_args: &mut GenericArgs, vis: &
582582
match generic_args {
583583
GenericArgs::AngleBracketed(data) => vis.visit_angle_bracketed_parameter_data(data),
584584
GenericArgs::Parenthesized(data) => vis.visit_parenthesized_parameter_data(data),
585+
GenericArgs::ParenthesizedElided(span) => vis.visit_span(span),
585586
}
586587
}
587588

compiler/rustc_ast/src/util/classify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,6 @@ fn path_return_type(path: &ast::Path) -> Option<&ast::Ty> {
311311
ast::FnRetTy::Default(_) => None,
312312
ast::FnRetTy::Ty(ret) => Some(ret),
313313
},
314-
ast::GenericArgs::AngleBracketed(_) => None,
314+
ast::GenericArgs::AngleBracketed(_) | ast::GenericArgs::ParenthesizedElided(_) => None,
315315
}
316316
}

compiler/rustc_ast/src/visit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ where
609609
walk_list!(visitor, visit_ty, inputs);
610610
try_visit!(visitor.visit_fn_ret_ty(output));
611611
}
612+
GenericArgs::ParenthesizedElided(_span) => {}
612613
}
613614
V::Result::output()
614615
}

compiler/rustc_ast_lowering/messages.ftl

+5
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,15 @@ ast_lowering_bad_return_type_notation_inputs =
3636
argument types not allowed with return type notation
3737
.suggestion = remove the input types
3838
39+
ast_lowering_bad_return_type_notation_needs_dots = return type notation arguments must be elided with `..`
40+
.suggestion = add `..`
41+
3942
ast_lowering_bad_return_type_notation_output =
4043
return type not allowed with return type notation
4144
.suggestion = remove the return type
4245
46+
ast_lowering_bad_return_type_notation_position = return type notation not allowed in this position yet
47+
4348
ast_lowering_base_expression_double_dot =
4449
base expression required after `..`
4550
.suggestion = add a base expression here

compiler/rustc_ast_lowering/src/errors.rs

+11
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,17 @@ pub enum BadReturnTypeNotation {
393393
#[suggestion(code = "", applicability = "maybe-incorrect")]
394394
span: Span,
395395
},
396+
#[diag(ast_lowering_bad_return_type_notation_needs_dots)]
397+
NeedsDots {
398+
#[primary_span]
399+
#[suggestion(code = "(..)", applicability = "maybe-incorrect")]
400+
span: Span,
401+
},
402+
#[diag(ast_lowering_bad_return_type_notation_position)]
403+
Position {
404+
#[primary_span]
405+
span: Span,
406+
},
396407
}
397408

398409
#[derive(Diagnostic)]

compiler/rustc_ast_lowering/src/lib.rs

+10-15
Original file line numberDiff line numberDiff line change
@@ -985,20 +985,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
985985
self.lower_angle_bracketed_parameter_data(data, ParamMode::Explicit, itctx).0
986986
}
987987
GenericArgs::Parenthesized(data) => {
988-
if data.inputs.is_empty() && matches!(data.output, FnRetTy::Default(..)) {
989-
let parenthesized = if self.tcx.features().return_type_notation {
990-
hir::GenericArgsParentheses::ReturnTypeNotation
991-
} else {
992-
self.emit_bad_parenthesized_trait_in_assoc_ty(data);
993-
hir::GenericArgsParentheses::No
994-
};
995-
GenericArgsCtor {
996-
args: Default::default(),
997-
constraints: &[],
998-
parenthesized,
999-
span: data.inputs_span,
1000-
}
1001-
} else if let Some(first_char) = constraint.ident.as_str().chars().next()
988+
if let Some(first_char) = constraint.ident.as_str().chars().next()
1002989
&& first_char.is_ascii_lowercase()
1003990
{
1004991
let mut err = if !data.inputs.is_empty() {
@@ -1010,7 +997,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1010997
span: data.inputs_span.shrink_to_hi().to(ty.span),
1011998
})
1012999
} else {
1013-
unreachable!("inputs are empty and return type is not provided")
1000+
self.dcx().create_err(errors::BadReturnTypeNotation::NeedsDots {
1001+
span: data.inputs_span,
1002+
})
10141003
};
10151004
if !self.tcx.features().return_type_notation
10161005
&& self.tcx.sess.is_nightly_build()
@@ -1040,6 +1029,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10401029
.0
10411030
}
10421031
}
1032+
GenericArgs::ParenthesizedElided(span) => GenericArgsCtor {
1033+
args: Default::default(),
1034+
constraints: &[],
1035+
parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
1036+
span: *span,
1037+
},
10431038
};
10441039
gen_args_ctor.into_generic_args(self)
10451040
} else {

compiler/rustc_ast_lowering/src/path.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use crate::ImplTraitPosition;
22

33
use super::errors::{
4-
AsyncBoundNotOnTrait, AsyncBoundOnlyForFnTraits, GenericTypeWithParentheses, UseAngleBrackets,
4+
AsyncBoundNotOnTrait, AsyncBoundOnlyForFnTraits, BadReturnTypeNotation,
5+
GenericTypeWithParentheses, UseAngleBrackets,
56
};
67
use super::ResolverAstLoweringExt;
78
use super::{GenericArgsCtor, LifetimeRes, ParenthesizedGenericArgs};
@@ -271,6 +272,18 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
271272
)
272273
}
273274
},
275+
GenericArgs::ParenthesizedElided(span) => {
276+
self.dcx().emit_err(BadReturnTypeNotation::Position { span: *span });
277+
(
278+
GenericArgsCtor {
279+
args: Default::default(),
280+
constraints: &[],
281+
parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
282+
span: *span,
283+
},
284+
false,
285+
)
286+
}
274287
}
275288
} else {
276289
(

compiler/rustc_ast_passes/src/ast_validation.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1312,6 +1312,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
13121312
self.with_impl_trait(None, |this| this.visit_ty(ty));
13131313
}
13141314
}
1315+
GenericArgs::ParenthesizedElided(_span) => {}
13151316
}
13161317
}
13171318

@@ -1468,7 +1469,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
14681469
span: args.span,
14691470
});
14701471
}
1471-
None => {}
1472+
Some(ast::GenericArgs::ParenthesizedElided(_)) | None => {}
14721473
}
14731474
}
14741475
}
@@ -1716,7 +1717,9 @@ fn deny_equality_constraints(
17161717
// Add `<Bar = RhsTy>` to `Foo`.
17171718
match &mut assoc_path.segments[len].args {
17181719
Some(args) => match args.deref_mut() {
1719-
GenericArgs::Parenthesized(_) => continue,
1720+
GenericArgs::Parenthesized(_) | GenericArgs::ParenthesizedElided(..) => {
1721+
continue;
1722+
}
17201723
GenericArgs::AngleBracketed(args) => {
17211724
args.args.push(arg);
17221725
}

compiler/rustc_ast_passes/src/feature_gate.rs

+2-22
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_ast as ast;
22
use rustc_ast::visit::{self, AssocCtxt, FnCtxt, FnKind, Visitor};
3-
use rustc_ast::{attr, AssocItemConstraint, AssocItemConstraintKind, NodeId};
3+
use rustc_ast::{attr, NodeId};
44
use rustc_ast::{token, PatKind};
55
use rustc_feature::{AttributeGate, BuiltinAttribute, Features, GateIssue, BUILTIN_ATTRIBUTE_MAP};
66
use rustc_session::parse::{feature_err, feature_err_issue, feature_warn};
@@ -445,23 +445,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
445445
visit::walk_fn(self, fn_kind)
446446
}
447447

448-
fn visit_assoc_item_constraint(&mut self, constraint: &'a AssocItemConstraint) {
449-
if let AssocItemConstraintKind::Bound { .. } = constraint.kind
450-
&& let Some(ast::GenericArgs::Parenthesized(args)) = constraint.gen_args.as_ref()
451-
&& args.inputs.is_empty()
452-
&& let ast::FnRetTy::Default(..) = args.output
453-
{
454-
gate!(
455-
&self,
456-
return_type_notation,
457-
constraint.span,
458-
"return type notation is experimental"
459-
);
460-
}
461-
462-
visit::walk_assoc_item_constraint(self, constraint)
463-
}
464-
465448
fn visit_assoc_item(&mut self, i: &'a ast::AssocItem, ctxt: AssocCtxt) {
466449
let is_fn = match &i.kind {
467450
ast::AssocItemKind::Fn(_) => true,
@@ -566,6 +549,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
566549
unsafe_extern_blocks,
567550
"`unsafe extern {}` blocks and `safe` keyword are experimental"
568551
);
552+
gate_all!(return_type_notation, "return type notation is experimental");
569553

570554
if !visitor.features.never_patterns {
571555
if let Some(spans) = spans.get(&sym::never_patterns) {
@@ -611,10 +595,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
611595

612596
gate_all_legacy_dont_use!(box_patterns, "box pattern syntax is experimental");
613597
gate_all_legacy_dont_use!(trait_alias, "trait aliases are experimental");
614-
// Despite being a new feature, `where T: Trait<Assoc(): Sized>`, which is RTN syntax now,
615-
// used to be gated under associated_type_bounds, which are right above, so RTN needs to
616-
// be too.
617-
gate_all_legacy_dont_use!(return_type_notation, "return type notation is experimental");
618598
gate_all_legacy_dont_use!(decl_macro, "`macro` is experimental");
619599
gate_all_legacy_dont_use!(try_blocks, "`try` blocks are unstable");
620600
gate_all_legacy_dont_use!(auto_traits, "`auto` traits are unstable");

compiler/rustc_ast_pretty/src/pprust/state.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,11 @@ impl<'a> PrintState<'a> for State<'a> {
10601060
self.word(")");
10611061
self.print_fn_ret_ty(&data.output);
10621062
}
1063+
ast::GenericArgs::ParenthesizedElided(_) => {
1064+
self.word("(");
1065+
self.word("..");
1066+
self.word(")");
1067+
}
10631068
}
10641069
}
10651070
}

compiler/rustc_driver_impl/src/lib.rs

+4-17
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use rustc_errors::{
3030
};
3131
use rustc_feature::find_gated_cfg;
3232
use rustc_interface::util::{self, get_codegen_backend};
33-
use rustc_interface::{interface, passes, Queries};
33+
use rustc_interface::{interface, passes, Linker, Queries};
3434
use rustc_lint::unerased_lint_store;
3535
use rustc_metadata::creader::MetadataLoader;
3636
use rustc_metadata::locator;
@@ -41,7 +41,6 @@ use rustc_session::getopts::{self, Matches};
4141
use rustc_session::lint::{Lint, LintId};
4242
use rustc_session::output::collect_crate_types;
4343
use rustc_session::{config, filesearch, EarlyDiagCtxt, Session};
44-
use rustc_span::def_id::LOCAL_CRATE;
4544
use rustc_span::source_map::FileLoader;
4645
use rustc_span::symbol::sym;
4746
use rustc_span::FileName;
@@ -448,21 +447,9 @@ fn run_compiler(
448447
return early_exit();
449448
}
450449

451-
let linker = queries.codegen_and_build_linker()?;
452-
453-
// This must run after monomorphization so that all generic types
454-
// have been instantiated.
455-
if sess.opts.unstable_opts.print_type_sizes {
456-
sess.code_stats.print_type_sizes();
457-
}
458-
459-
if sess.opts.unstable_opts.print_vtable_sizes {
460-
let crate_name = queries.global_ctxt()?.enter(|tcx| tcx.crate_name(LOCAL_CRATE));
461-
462-
sess.code_stats.print_vtable_sizes(crate_name);
463-
}
464-
465-
Ok(Some(linker))
450+
queries.global_ctxt()?.enter(|tcx| {
451+
Ok(Some(Linker::codegen_and_build_linker(tcx, &*compiler.codegen_backend)?))
452+
})
466453
})?;
467454

468455
// Linking is done outside the `compiler.enter()` so that the

compiler/rustc_hir/src/hir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2414,7 +2414,7 @@ pub enum ImplItemKind<'hir> {
24142414
/// * the `A: Bound` in `Trait<A: Bound>`
24152415
/// * the `RetTy` in `Trait(ArgTy, ArgTy) -> RetTy`
24162416
/// * the `C = { Ct }` in `Trait<C = { Ct }>` (feature `associated_const_equality`)
2417-
/// * the `f(): Bound` in `Trait<f(): Bound>` (feature `return_type_notation`)
2417+
/// * the `f(..): Bound` in `Trait<f(..): Bound>` (feature `return_type_notation`)
24182418
#[derive(Debug, Clone, Copy, HashStable_Generic)]
24192419
pub struct AssocItemConstraint<'hir> {
24202420
pub hir_id: HirId,

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+26
Original file line numberDiff line numberDiff line change
@@ -951,6 +951,32 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
951951
return err.emit();
952952
}
953953

954+
// Special case, we found an extra argument is provided, which is very common in practice.
955+
// but there is a obviously better removing suggestion compared to the current one,
956+
// try to find the argument with Error type, if we removed it all the types will become good,
957+
// then we will replace the current suggestion.
958+
if let [Error::Extra(provided_idx)] = &errors[..] {
959+
let remove_idx_is_perfect = |idx: usize| -> bool {
960+
let removed_arg_tys = provided_arg_tys
961+
.iter()
962+
.enumerate()
963+
.filter_map(|(j, arg)| if idx == j { None } else { Some(arg) })
964+
.collect::<IndexVec<ProvidedIdx, _>>();
965+
std::iter::zip(formal_and_expected_inputs.iter(), removed_arg_tys.iter()).all(
966+
|((expected_ty, _), (provided_ty, _))| {
967+
!provided_ty.references_error()
968+
&& self.can_coerce(*provided_ty, *expected_ty)
969+
},
970+
)
971+
};
972+
973+
if !remove_idx_is_perfect(provided_idx.as_usize()) {
974+
if let Some(i) = (0..provided_args.len()).find(|&i| remove_idx_is_perfect(i)) {
975+
errors = vec![Error::Extra(ProvidedIdx::from_usize(i))];
976+
}
977+
}
978+
}
979+
954980
let mut err = if formal_and_expected_inputs.len() == provided_args.len() {
955981
struct_span_code_err!(
956982
self.dcx(),

compiler/rustc_interface/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub mod util;
1616
pub use callbacks::setup_callbacks;
1717
pub use interface::{run_compiler, Config};
1818
pub use passes::DEFAULT_QUERY_PROVIDERS;
19-
pub use queries::Queries;
19+
pub use queries::{Linker, Queries};
2020

2121
#[cfg(test)]
2222
mod tests;

0 commit comments

Comments
 (0)