diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index e7f19f06ebef5..ac69fa2020250 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -278,7 +278,7 @@ impl ParenthesizedArgs { .cloned() .map(|input| AngleBracketedArg::Arg(GenericArg::Type(input))) .collect(); - AngleBracketedArgs { span: self.span, args } + AngleBracketedArgs { span: self.inputs_span, args } } } diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 32320130b677c..fe4459ccdc0df 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -62,7 +62,7 @@ use rustc_span::edition::Edition; use rustc_span::hygiene::ExpnId; use rustc_span::source_map::{respan, DesugaringKind}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; -use rustc_span::Span; +use rustc_span::{Span, DUMMY_SP}; use rustc_target::spec::abi::Abi; use smallvec::{smallvec, SmallVec}; @@ -2084,6 +2084,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { args: &[], bindings: arena_vec![self; self.output_ty_binding(span, output_ty)], parenthesized: false, + span_ext: DUMMY_SP, }); hir::GenericBound::LangItemTrait( @@ -2788,6 +2789,7 @@ struct GenericArgsCtor<'hir> { args: SmallVec<[hir::GenericArg<'hir>; 4]>, bindings: &'hir [hir::TypeBinding<'hir>], parenthesized: bool, + span: Span, } impl<'hir> GenericArgsCtor<'hir> { @@ -2800,6 +2802,7 @@ impl<'hir> GenericArgsCtor<'hir> { args: arena.alloc_from_iter(self.args), bindings: self.bindings, parenthesized: self.parenthesized, + span_ext: self.span, } } } diff --git a/compiler/rustc_ast_lowering/src/path.rs b/compiler/rustc_ast_lowering/src/path.rs index 82a0983e2a1a3..fe9f1fb20f056 100644 --- a/compiler/rustc_ast_lowering/src/path.rs +++ b/compiler/rustc_ast_lowering/src/path.rs @@ -10,7 +10,7 @@ use rustc_hir::GenericArg; use rustc_session::lint::builtin::ELIDED_LIFETIMES_IN_PATHS; use rustc_session::lint::BuiltinLintDiagnostics; use rustc_span::symbol::Ident; -use rustc_span::Span; +use rustc_span::{BytePos, Span, DUMMY_SP}; use smallvec::smallvec; use tracing::debug; @@ -267,23 +267,34 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { }, } } else { - self.lower_angle_bracketed_parameter_data(&Default::default(), param_mode, itctx) + ( + GenericArgsCtor { + args: Default::default(), + bindings: &[], + parenthesized: false, + span: path_span.shrink_to_hi(), + }, + param_mode == ParamMode::Optional, + ) }; let has_lifetimes = generic_args.args.iter().any(|arg| matches!(arg, GenericArg::Lifetime(_))); - let first_generic_span = generic_args - .args - .iter() - .map(|a| a.span()) - .chain(generic_args.bindings.iter().map(|b| b.span)) - .next(); if !generic_args.parenthesized && !has_lifetimes { + // Note: these spans are used for diagnostics when they can't be inferred. + // See rustc_resolve::late::lifetimes::LifetimeContext::add_missing_lifetime_specifiers_label + let elided_lifetime_span = if generic_args.span.is_empty() { + // If there are no brackets, use the identifier span. + segment.ident.span + } else if generic_args.is_empty() { + // If there are brackets, but not generic arguments, then use the opening bracket + generic_args.span.with_hi(generic_args.span.lo() + BytePos(1)) + } else { + // Else use an empty span right after the opening bracket. + generic_args.span.with_lo(generic_args.span.lo() + BytePos(1)).shrink_to_lo() + }; generic_args.args = self - .elided_path_lifetimes( - first_generic_span.map_or(segment.ident.span, |s| s.shrink_to_lo()), - expected_lifetimes, - ) + .elided_path_lifetimes(elided_lifetime_span, expected_lifetimes) .map(GenericArg::Lifetime) .chain(generic_args.args.into_iter()) .collect(); @@ -292,15 +303,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let no_non_lt_args = generic_args.args.len() == expected_lifetimes; let no_bindings = generic_args.bindings.is_empty(); let (incl_angl_brckt, insertion_sp, suggestion) = if no_non_lt_args && no_bindings { - // If there are no (non-implicit) generic args or associated type - // bindings, our suggestion includes the angle brackets. + // If there are no generic args, our suggestion can include the angle brackets. (true, path_span.shrink_to_hi(), format!("<{}>", anon_lt_suggestion)) } else { - // Otherwise (sorry, this is kind of gross) we need to infer the - // place to splice in the `'_, ` from the generics that do exist. - let first_generic_span = first_generic_span - .expect("already checked that non-lifetime args or bindings exist"); - (false, first_generic_span.shrink_to_lo(), format!("{}, ", anon_lt_suggestion)) + // Otherwise we'll insert a `'_, ` right after the opening bracket. + let span = generic_args + .span + .with_lo(generic_args.span.lo() + BytePos(1)) + .shrink_to_lo(); + (false, span, format!("{}, ", anon_lt_suggestion)) }; match self.anonymous_lifetime_mode { // In create-parameter mode we error here because we don't want to support @@ -362,7 +373,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { hir_id: Some(id), res: Some(self.lower_res(res)), infer_args, - args: if generic_args.is_empty() { + args: if generic_args.is_empty() && generic_args.span.is_empty() { None } else { Some(self.arena.alloc(generic_args.into_generic_args(self.arena))) @@ -395,7 +406,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { } AngleBracketedArg::Arg(_) => None, })); - let ctor = GenericArgsCtor { args, bindings, parenthesized: false }; + let ctor = GenericArgsCtor { args, bindings, parenthesized: false, span: data.span }; (ctor, !has_non_lt_args && param_mode == ParamMode::Optional) } @@ -420,7 +431,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let args = smallvec![GenericArg::Type(this.ty_tup(*inputs_span, inputs))]; let binding = this.output_ty_binding(output_ty.span, output_ty); ( - GenericArgsCtor { args, bindings: arena_vec![this; binding], parenthesized: true }, + GenericArgsCtor { + args, + bindings: arena_vec![this; binding], + parenthesized: true, + span: data.inputs_span, + }, false, ) }) @@ -436,7 +452,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let kind = hir::TypeBindingKind::Equality { ty }; let args = arena_vec![self;]; let bindings = arena_vec![self;]; - let gen_args = self.arena.alloc(hir::GenericArgs { args, bindings, parenthesized: false }); + let gen_args = self.arena.alloc(hir::GenericArgs { + args, + bindings, + parenthesized: false, + span_ext: DUMMY_SP, + }); hir::TypeBinding { hir_id: self.next_id(), gen_args, span, ident, kind } } } diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 5baaaad7370fc..e689ae4d81db7 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -12,7 +12,7 @@ pub use rustc_ast::{CaptureBy, Movability, Mutability}; use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece}; use rustc_data_structures::sync::{par_for_each_in, Send, Sync}; use rustc_macros::HashStable_Generic; -use rustc_span::source_map::{SourceMap, Spanned}; +use rustc_span::source_map::Spanned; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{def_id::LocalDefId, BytePos}; use rustc_span::{MultiSpan, Span, DUMMY_SP}; @@ -314,11 +314,18 @@ pub struct GenericArgs<'hir> { /// This is required mostly for pretty-printing and diagnostics, /// but also for changing lifetime elision rules to be "function-like". pub parenthesized: bool, + /// The span encompassing arguments and the surrounding brackets `<>` or `()` + /// Foo Fn(T, U, V) -> W + /// ^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^ + /// Note that this may be: + /// - empty, if there are no generic brackets (but there may be hidden lifetimes) + /// - dummy, if this was generated while desugaring + pub span_ext: Span, } impl GenericArgs<'_> { pub const fn none() -> Self { - Self { args: &[], bindings: &[], parenthesized: false } + Self { args: &[], bindings: &[], parenthesized: false, span_ext: DUMMY_SP } } pub fn inputs(&self) -> &[Ty<'_>] { @@ -356,33 +363,17 @@ impl GenericArgs<'_> { own_counts } + /// The span encompassing the text inside the surrounding brackets. + /// It will also include bindings if they aren't in the form `-> Ret` + /// Returns `None` if the span is empty (e.g. no brackets) or dummy pub fn span(&self) -> Option { - self.args - .iter() - .filter(|arg| !arg.is_synthetic()) - .map(|arg| arg.span()) - .reduce(|span1, span2| span1.to(span2)) + let span_ext = self.span_ext()?; + Some(span_ext.with_lo(span_ext.lo() + BytePos(1)).with_hi(span_ext.hi() - BytePos(1))) } /// Returns span encompassing arguments and their surrounding `<>` or `()` - pub fn span_ext(&self, sm: &SourceMap) -> Option { - let mut span = self.span()?; - - let (o, c) = if self.parenthesized { ('(', ')') } else { ('<', '>') }; - - if let Ok(snippet) = sm.span_to_snippet(span) { - let snippet = snippet.as_bytes(); - - if snippet[0] != (o as u8) || snippet[snippet.len() - 1] != (c as u8) { - span = sm.span_extend_to_prev_char(span, o, true); - span = span.with_lo(span.lo() - BytePos(1)); - - span = sm.span_extend_to_next_char(span, c, true); - span = span.with_hi(span.hi() + BytePos(1)); - } - } - - Some(span) + pub fn span_ext(&self) -> Option { + Some(self.span_ext).filter(|span| !span.is_empty()) } pub fn is_empty(&self) -> bool { diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index fdde687d4866c..13e457507cf32 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -1821,7 +1821,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { crate fn add_missing_lifetime_specifiers_label( &self, err: &mut DiagnosticBuilder<'_>, - spans_with_counts: Vec<(Span, usize)>, + mut spans_with_counts: Vec<(Span, usize)>, lifetime_names: &FxHashSet, lifetime_spans: Vec, params: &[ElisionFailureInfo], @@ -1831,13 +1831,21 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { .map(|(span, _)| self.tcx.sess.source_map().span_to_snippet(*span).ok()) .collect(); - for (span, count) in &spans_with_counts { + // Empty generics are marked with a span of "<", but since from now on + // that information is in the snippets it can be removed from the spans. + for ((span, _), snippet) in spans_with_counts.iter_mut().zip(&snippets) { + if snippet.as_deref() == Some("<") { + *span = span.shrink_to_hi(); + } + } + + for &(span, count) in &spans_with_counts { err.span_label( - *span, + span, format!( "expected {} lifetime parameter{}", - if *count == 1 { "named".to_string() } else { count.to_string() }, - pluralize!(*count), + if count == 1 { "named".to_string() } else { count.to_string() }, + pluralize!(count), ), ); } @@ -1982,6 +1990,14 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { .collect::>() .join(", "), ) + } else if snippet == "<" || snippet == "(" { + ( + span.shrink_to_hi(), + std::iter::repeat("'static") + .take(count) + .collect::>() + .join(", "), + ) } else { ( span.shrink_to_hi(), @@ -1990,7 +2006,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { std::iter::repeat("'static") .take(count) .collect::>() - .join(", ") + .join(", "), ), ) } @@ -2045,6 +2061,9 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { Some("&") => Some(Box::new(|name| format!("&{} ", name))), Some("'_") => Some(Box::new(|n| n.to_string())), Some("") => Some(Box::new(move |n| format!("{}, ", n).repeat(count))), + Some("<") => Some(Box::new(move |n| { + std::iter::repeat(n).take(count).collect::>().join(", ") + })), Some(snippet) if !snippet.ends_with('>') => Some(Box::new(move |name| { format!( "{}<{}>", @@ -2071,6 +2090,9 @@ impl<'tcx> LifetimeContext<'_, 'tcx> { Some("") => { Some(std::iter::repeat("'a, ").take(count).collect::>().join("")) } + Some("<") => { + Some(std::iter::repeat("'a").take(count).collect::>().join(", ")) + } Some(snippet) => Some(format!( "{}<{}>", snippet, diff --git a/compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs b/compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs index c533ca28321a1..56f288ff051c2 100644 --- a/compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs +++ b/compiler/rustc_typeck/src/structured_errors/wrong_number_of_generic_args.rs @@ -94,14 +94,10 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { gen_args: &'a hir::GenericArgs<'a>, def_id: DefId, ) -> Self { - let angle_brackets = if gen_args.is_empty() { - AngleBrackets::Missing + let angle_brackets = if gen_args.span_ext().is_none() { + if gen_args.is_empty() { AngleBrackets::Missing } else { AngleBrackets::Implied } } else { - if gen_args.span().is_none() { - AngleBrackets::Implied - } else { - AngleBrackets::Available - } + AngleBrackets::Available }; Self { @@ -337,7 +333,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { ), }; - if self.gen_args.span().is_some() { + if self.gen_args.span_ext().is_some() { format!( "this {} takes {}{} {} argument{} but {} {} supplied", def_kind, @@ -579,27 +575,32 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { err.span_suggestion_verbose(span, &msg, sugg, Applicability::HasPlaceholders); } AngleBrackets::Available => { - // angle brackets exist, so we just insert missing arguments after the existing - // type or const args - - let index_last_provided_arg = - self.get_lifetime_args_offset() + self.num_provided_type_or_const_args() - 1; - if index_last_provided_arg < self.gen_args.args.len() { - let first_arg_span = - self.gen_args.args[index_last_provided_arg].span().shrink_to_hi(); - let source_map = self.tcx.sess.source_map(); - if let Ok(first_gen_arg) = source_map.span_to_snippet(first_arg_span) { - let sugg = format!("{}, {}", first_gen_arg, suggested_args); - debug!("sugg: {:?}", sugg); + let gen_args_span = self.gen_args.span().unwrap(); + let sugg_offset = + self.get_lifetime_args_offset() + self.num_provided_type_or_const_args(); - err.span_suggestion_verbose( - first_arg_span, - &msg, - sugg, - Applicability::HasPlaceholders, - ); - } - } + let (sugg_span, is_first) = if sugg_offset == 0 { + (gen_args_span.shrink_to_lo(), true) + } else { + let arg_span = self.gen_args.args[sugg_offset - 1].span(); + // If we came here then inferred lifetimes's spans can only point + // to either the opening bracket or to the space right after. + // Both of these spans have an `hi` lower than or equal to the span + // of the generics excluding the brackets. + // This allows us to check if `arg_span` is the artificial span of + // an inferred lifetime, in which case the generic we're suggesting to + // add will be the first visible, even if it isn't the actual first generic. + (arg_span.shrink_to_hi(), arg_span.hi() <= gen_args_span.lo()) + }; + + let sugg_prefix = if is_first { "" } else { ", " }; + let sugg_suffix = + if is_first && !self.gen_args.bindings.is_empty() { ", " } else { "" }; + + let sugg = format!("{}{}{}", sugg_prefix, suggested_args, sugg_suffix); + debug!("sugg: {:?}", sugg); + + err.span_suggestion_verbose(sugg_span, &msg, sugg, Applicability::HasPlaceholders); } } } @@ -695,13 +696,11 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { }; if remove_entire_generics { - let sm = self.tcx.sess.source_map(); - let span = self .path_segment .args .unwrap() - .span_ext(sm) + .span_ext() .unwrap() .with_lo(self.path_segment.ident.span.hi()); diff --git a/src/test/ui/generic-associated-types/gat-trait-path-parenthesised-args.stderr b/src/test/ui/generic-associated-types/gat-trait-path-parenthesised-args.stderr index 72855a742561c..400600a086c0c 100644 --- a/src/test/ui/generic-associated-types/gat-trait-path-parenthesised-args.stderr +++ b/src/test/ui/generic-associated-types/gat-trait-path-parenthesised-args.stderr @@ -49,7 +49,7 @@ error[E0107]: this associated type takes 0 generic arguments but 1 generic argum --> $DIR/gat-trait-path-parenthesised-args.rs:8:27 | LL | fn foo<'a>(arg: Box>) {} - | ^-------------- help: remove these generics + | ^---- help: remove these generics | | | expected 0 generic arguments | diff --git a/src/test/ui/generics/wrong-number-of-args.rs b/src/test/ui/generics/wrong-number-of-args.rs index f061c5814594e..ec2ed9926e2aa 100644 --- a/src/test/ui/generics/wrong-number-of-args.rs +++ b/src/test/ui/generics/wrong-number-of-args.rs @@ -36,6 +36,10 @@ mod type_and_type { type D = Ty; //~^ ERROR this struct takes 2 generic arguments but 3 generic arguments //~| HELP remove this + + type E = Ty<>; + //~^ ERROR this struct takes 2 generic arguments but 0 generic arguments were supplied + //~| HELP add missing } mod lifetime_and_type { @@ -56,6 +60,12 @@ mod lifetime_and_type { //~| HELP consider introducing type D = Ty<'static, usize>; + + type E = Ty<>; + //~^ ERROR this struct takes 1 generic argument but 0 generic arguments + //~| ERROR missing lifetime specifier + //~| HELP consider introducing + //~| HELP add missing } mod type_and_type_and_type { @@ -76,6 +86,10 @@ mod type_and_type_and_type { type E = Ty; //~^ ERROR this struct takes at most 3 //~| HELP remove + + type F = Ty<>; + //~^ ERROR this struct takes at least 2 generic arguments but 0 generic arguments + //~| HELP add missing } // Traits have an implicit `Self` type - these tests ensure we don't accidentally return it @@ -112,6 +126,166 @@ mod r#trait { type E = Box>; //~^ ERROR this trait takes 1 generic argument but 2 generic arguments //~| HELP remove + + type F = Box>; + //~^ ERROR missing lifetime specifier + //~| HELP consider introducing + + type G = Box>; + //~^ ERROR this trait takes 1 generic argument but 0 generic arguments + //~| HELP add missing +} + +mod associated_item { + mod non_generic { + trait NonGenericAT { + type AssocTy; + } + + type A = Box>; + //~^ ERROR this trait takes 0 generic arguments but 1 generic argument + //~| HELP remove + } + + mod lifetime { + trait GenericLifetimeAT<'a> { + type AssocTy; + } + + type A = Box>; + //~^ ERROR missing lifetime specifier + //~| HELP consider introducing + + type B = Box>; + //~^ ERROR this trait takes 1 lifetime argument but 2 lifetime arguments were supplied + //~| HELP remove + + type C = Box>; + //~^ ERROR missing lifetime specifier + //~| HELP consider introducing + //~| ERROR this trait takes 0 generic arguments but 1 generic argument + //~| HELP remove + } + + mod r#type { + trait GenericTypeAT { + type AssocTy; + } + + type A = Box>; + //~^ ERROR this trait takes 1 generic argument but 0 generic arguments + //~| HELP add missing + + type B = Box>; + //~^ ERROR this trait takes 1 generic argument but 2 generic arguments + //~| HELP remove + + type C = Box>; + //~^ ERROR this trait takes 1 generic argument but 0 generic arguments + //~| HELP add missing + //~| ERROR this trait takes 0 lifetime arguments but 1 lifetime argument was supplied + //~| HELP remove + } + + mod lifetime_and_type { + trait GenericLifetimeTypeAT<'a, A> { + type AssocTy; + } + + type A = Box>; + //~^ ERROR this trait takes 1 generic argument but 0 generic arguments + //~| HELP add missing + //~| ERROR missing lifetime specifier + //~| HELP consider introducing + + type B = Box>; + //~^ ERROR this trait takes 1 generic argument but 0 generic arguments were supplied + //~| HELP add missing + + type C = Box>; + //~^ ERROR this trait takes 1 lifetime argument but 2 lifetime arguments were supplied + //~| HELP remove + //~| ERROR this trait takes 1 generic argument but 0 generic arguments + //~| HELP add missing + + type D = Box>; + //~^ ERROR missing lifetime specifier + //~| HELP consider introducing + + type E = Box>; + //~^ ERROR missing lifetime specifier + //~| HELP consider introducing + //~| ERROR this trait takes 1 generic argument but 2 generic arguments + //~| HELP remove + + type F = Box>; + //~^ ERROR this trait takes 1 lifetime argument but 2 lifetime arguments were supplied + //~| HELP remove + + type G = Box>; + //~^ ERROR this trait takes 1 generic argument but 2 generic arguments + //~| HELP remove + + type H = Box>; + //~^ ERROR this trait takes 1 lifetime argument but 2 lifetime arguments were supplied + //~| HELP remove + //~| ERROR this trait takes 1 generic argument but 2 generic arguments + //~| HELP remove + } + + mod type_and_type { + trait GenericTypeTypeAT { + type AssocTy; + } + + type A = Box>; + //~^ ERROR this trait takes 2 generic arguments but 0 generic arguments + //~| HELP add missing + + type B = Box>; + //~^ ERROR this trait takes 2 generic arguments but 1 generic argument + //~| HELP add missing + + type C = Box>; + //~^ ERROR this trait takes 2 generic arguments but 3 generic arguments + //~| HELP remove + } + + mod lifetime_and_lifetime { + trait GenericLifetimeLifetimeAT<'a, 'b> { + type AssocTy; + } + + type A = Box>; + //~^ ERROR missing lifetime specifier + //~| HELP consider introducing + + type B = Box>; + //~^ ERROR this trait takes 2 lifetime arguments but 1 lifetime argument was supplied + //~| HELP add missing lifetime argument + } + + mod lifetime_and_lifetime_and_type { + trait GenericLifetimeLifetimeTypeAT<'a, 'b, A> { + type AssocTy; + } + + type A = Box>; + //~^ ERROR missing lifetime specifier + //~| HELP consider introducing + //~| ERROR this trait takes 1 generic argument but 0 generic arguments + //~| HELP add missing + + type B = Box>; + //~^ ERROR this trait takes 2 lifetime arguments but 1 lifetime argument was supplied + //~| HELP add missing lifetime argument + //~| ERROR this trait takes 1 generic argument but 0 generic arguments + //~| HELP add missing + + type C = Box>; + //~^ ERROR this trait takes 2 lifetime arguments but 1 lifetime argument was supplied + //~| HELP add missing lifetime argument + } } mod stdlib { @@ -135,6 +309,10 @@ mod stdlib { type D = HashMap; //~^ ERROR this struct takes at most 3 //~| HELP remove this + + type E = HashMap<>; + //~^ ERROR this struct takes at least 2 generic arguments but 0 generic arguments + //~| HELP add missing } mod result { @@ -155,6 +333,10 @@ mod stdlib { type D = Result; //~^ ERROR this enum takes 2 generic arguments but 3 generic arguments //~| HELP remove + + type E = Result<>; + //~^ ERROR this enum takes 2 generic arguments but 0 generic arguments + //~| HELP add missing } } diff --git a/src/test/ui/generics/wrong-number-of-args.stderr b/src/test/ui/generics/wrong-number-of-args.stderr index 45bde4163d0fe..17a924cedad2c 100644 --- a/src/test/ui/generics/wrong-number-of-args.stderr +++ b/src/test/ui/generics/wrong-number-of-args.stderr @@ -116,14 +116,30 @@ note: struct defined here, with 2 generic parameters: `A`, `B` LL | struct Ty; | ^^ - - +error[E0107]: this struct takes 2 generic arguments but 0 generic arguments were supplied + --> $DIR/wrong-number-of-args.rs:40:14 + | +LL | type E = Ty<>; + | ^^ expected 2 generic arguments + | +note: struct defined here, with 2 generic parameters: `A`, `B` + --> $DIR/wrong-number-of-args.rs:24:12 + | +LL | struct Ty; + | ^^ - - +help: add missing generic arguments + | +LL | type E = Ty; + | ^^^^ + error[E0107]: missing generics for struct `lifetime_and_type::Ty` - --> $DIR/wrong-number-of-args.rs:44:14 + --> $DIR/wrong-number-of-args.rs:48:14 | LL | type A = Ty; | ^^ expected 1 generic argument | note: struct defined here, with 1 generic parameter: `T` - --> $DIR/wrong-number-of-args.rs:42:12 + --> $DIR/wrong-number-of-args.rs:46:12 | LL | struct Ty<'a, T>; | ^^ - @@ -133,7 +149,7 @@ LL | type A = Ty; | ^^^^^ error[E0106]: missing lifetime specifier - --> $DIR/wrong-number-of-args.rs:44:14 + --> $DIR/wrong-number-of-args.rs:48:14 | LL | type A = Ty; | ^^ expected named lifetime parameter @@ -144,13 +160,13 @@ LL | type A<'a> = Ty<'a>; | ^^^^ ^^^^^^ error[E0107]: this struct takes 1 generic argument but 0 generic arguments were supplied - --> $DIR/wrong-number-of-args.rs:50:14 + --> $DIR/wrong-number-of-args.rs:54:14 | LL | type B = Ty<'static>; | ^^ expected 1 generic argument | note: struct defined here, with 1 generic parameter: `T` - --> $DIR/wrong-number-of-args.rs:42:12 + --> $DIR/wrong-number-of-args.rs:46:12 | LL | struct Ty<'a, T>; | ^^ - @@ -160,7 +176,7 @@ LL | type B = Ty<'static, T>; | ^^^ error[E0106]: missing lifetime specifier - --> $DIR/wrong-number-of-args.rs:54:17 + --> $DIR/wrong-number-of-args.rs:58:17 | LL | type C = Ty; | ^ expected named lifetime parameter @@ -170,14 +186,41 @@ help: consider introducing a named lifetime parameter LL | type C<'a> = Ty<'a, usize>; | ^^^^ ^^^ -error[E0107]: missing generics for struct `type_and_type_and_type::Ty` +error[E0107]: this struct takes 1 generic argument but 0 generic arguments were supplied --> $DIR/wrong-number-of-args.rs:64:14 | +LL | type E = Ty<>; + | ^^ expected 1 generic argument + | +note: struct defined here, with 1 generic parameter: `T` + --> $DIR/wrong-number-of-args.rs:46:12 + | +LL | struct Ty<'a, T>; + | ^^ - +help: add missing generic argument + | +LL | type E = Ty; + | ^ + +error[E0106]: missing lifetime specifier + --> $DIR/wrong-number-of-args.rs:64:16 + | +LL | type E = Ty<>; + | ^- expected named lifetime parameter + | +help: consider introducing a named lifetime parameter + | +LL | type E<'a> = Ty<'a>; + | ^^^^ ^^ + +error[E0107]: missing generics for struct `type_and_type_and_type::Ty` + --> $DIR/wrong-number-of-args.rs:74:14 + | LL | type A = Ty; | ^^ expected at least 2 generic arguments | note: struct defined here, with at least 2 generic parameters: `A`, `B` - --> $DIR/wrong-number-of-args.rs:62:12 + --> $DIR/wrong-number-of-args.rs:72:12 | LL | struct Ty; | ^^ - - @@ -187,7 +230,7 @@ LL | type A = Ty; | ^^^^^^^^ error[E0107]: this struct takes at least 2 generic arguments but 1 generic argument was supplied - --> $DIR/wrong-number-of-args.rs:68:14 + --> $DIR/wrong-number-of-args.rs:78:14 | LL | type B = Ty; | ^^ ----- supplied 1 generic argument @@ -195,7 +238,7 @@ LL | type B = Ty; | expected at least 2 generic arguments | note: struct defined here, with at least 2 generic parameters: `A`, `B` - --> $DIR/wrong-number-of-args.rs:62:12 + --> $DIR/wrong-number-of-args.rs:72:12 | LL | struct Ty; | ^^ - - @@ -205,7 +248,7 @@ LL | type B = Ty; | ^^^ error[E0107]: this struct takes at most 3 generic arguments but 4 generic arguments were supplied - --> $DIR/wrong-number-of-args.rs:76:14 + --> $DIR/wrong-number-of-args.rs:86:14 | LL | type E = Ty; | ^^ --- help: remove this generic argument @@ -213,13 +256,29 @@ LL | type E = Ty; | expected at most 3 generic arguments | note: struct defined here, with at most 3 generic parameters: `A`, `B`, `C` - --> $DIR/wrong-number-of-args.rs:62:12 + --> $DIR/wrong-number-of-args.rs:72:12 | LL | struct Ty; | ^^ - - - +error[E0107]: this struct takes at least 2 generic arguments but 0 generic arguments were supplied + --> $DIR/wrong-number-of-args.rs:90:14 + | +LL | type F = Ty<>; + | ^^ expected at least 2 generic arguments + | +note: struct defined here, with at least 2 generic parameters: `A`, `B` + --> $DIR/wrong-number-of-args.rs:72:12 + | +LL | struct Ty; + | ^^ - - +help: add missing generic arguments + | +LL | type F = Ty; + | ^^^^ + error[E0107]: this trait takes 0 generic arguments but 1 generic argument was supplied - --> $DIR/wrong-number-of-args.rs:96:22 + --> $DIR/wrong-number-of-args.rs:110:22 | LL | type A = Box>; | ^^^^^^^^^^------- help: remove these generics @@ -227,13 +286,13 @@ LL | type A = Box>; | expected 0 generic arguments | note: trait defined here, with 0 generic parameters - --> $DIR/wrong-number-of-args.rs:84:11 + --> $DIR/wrong-number-of-args.rs:98:11 | LL | trait NonGeneric { | ^^^^^^^^^^ error[E0106]: missing lifetime specifier - --> $DIR/wrong-number-of-args.rs:100:22 + --> $DIR/wrong-number-of-args.rs:114:22 | LL | type B = Box; | ^^^^^^^^^^^^^^^ expected named lifetime parameter @@ -244,7 +303,7 @@ LL | type B<'a> = Box>; | ^^^^ ^^^^^^^^^^^^^^^^^^^ error[E0107]: this trait takes 1 lifetime argument but 2 lifetime arguments were supplied - --> $DIR/wrong-number-of-args.rs:104:22 + --> $DIR/wrong-number-of-args.rs:118:22 | LL | type C = Box>; | ^^^^^^^^^^^^^^^ ------- help: remove this lifetime argument @@ -252,19 +311,19 @@ LL | type C = Box>; | expected 1 lifetime argument | note: trait defined here, with 1 lifetime parameter: `'a` - --> $DIR/wrong-number-of-args.rs:88:11 + --> $DIR/wrong-number-of-args.rs:102:11 | LL | trait GenericLifetime<'a> { | ^^^^^^^^^^^^^^^ -- error[E0107]: missing generics for trait `GenericType` - --> $DIR/wrong-number-of-args.rs:108:22 + --> $DIR/wrong-number-of-args.rs:122:22 | LL | type D = Box; | ^^^^^^^^^^^ expected 1 generic argument | note: trait defined here, with 1 generic parameter: `A` - --> $DIR/wrong-number-of-args.rs:92:11 + --> $DIR/wrong-number-of-args.rs:106:11 | LL | trait GenericType { | ^^^^^^^^^^^ - @@ -274,7 +333,7 @@ LL | type D = Box>; | ^^^^^^^^^^^^^^ error[E0107]: this trait takes 1 generic argument but 2 generic arguments were supplied - --> $DIR/wrong-number-of-args.rs:112:22 + --> $DIR/wrong-number-of-args.rs:126:22 | LL | type E = Box>; | ^^^^^^^^^^^ ----- help: remove this generic argument @@ -282,13 +341,485 @@ LL | type E = Box>; | expected 1 generic argument | note: trait defined here, with 1 generic parameter: `A` - --> $DIR/wrong-number-of-args.rs:92:11 + --> $DIR/wrong-number-of-args.rs:106:11 | LL | trait GenericType { | ^^^^^^^^^^^ - +error[E0106]: missing lifetime specifier + --> $DIR/wrong-number-of-args.rs:130:37 + | +LL | type F = Box>; + | ^- expected named lifetime parameter + | +help: consider introducing a named lifetime parameter + | +LL | type F<'a> = Box>; + | ^^^^ ^^ + +error[E0107]: this trait takes 1 generic argument but 0 generic arguments were supplied + --> $DIR/wrong-number-of-args.rs:134:22 + | +LL | type G = Box>; + | ^^^^^^^^^^^ expected 1 generic argument + | +note: trait defined here, with 1 generic parameter: `A` + --> $DIR/wrong-number-of-args.rs:106:11 + | +LL | trait GenericType { + | ^^^^^^^^^^^ - +help: add missing generic argument + | +LL | type G = Box>; + | ^ + +error[E0107]: this trait takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/wrong-number-of-args.rs:145:26 + | +LL | type A = Box>; + | ^^^^^^^^^^^^------------------- help: remove these generics + | | + | expected 0 generic arguments + | +note: trait defined here, with 0 generic parameters + --> $DIR/wrong-number-of-args.rs:141:15 + | +LL | trait NonGenericAT { + | ^^^^^^^^^^^^ + +error[E0106]: missing lifetime specifier + --> $DIR/wrong-number-of-args.rs:155:44 + | +LL | type A = Box>; + | ^ expected named lifetime parameter + | +help: consider introducing a named lifetime parameter + | +LL | type A<'a> = Box>; + | ^^^^ ^^^ + +error[E0107]: this trait takes 1 lifetime argument but 2 lifetime arguments were supplied + --> $DIR/wrong-number-of-args.rs:159:26 + | +LL | type B = Box>; + | ^^^^^^^^^^^^^^^^^ ------- help: remove this lifetime argument + | | + | expected 1 lifetime argument + | +note: trait defined here, with 1 lifetime parameter: `'a` + --> $DIR/wrong-number-of-args.rs:151:15 + | +LL | trait GenericLifetimeAT<'a> { + | ^^^^^^^^^^^^^^^^^ -- + +error[E0106]: missing lifetime specifier + --> $DIR/wrong-number-of-args.rs:163:44 + | +LL | type C = Box>; + | ^ expected named lifetime parameter + | +help: consider introducing a named lifetime parameter + | +LL | type C<'a> = Box>; + | ^^^^ ^^^ + +error[E0107]: this trait takes 0 generic arguments but 1 generic argument was supplied + --> $DIR/wrong-number-of-args.rs:163:26 + | +LL | type C = Box>; + | ^^^^^^^^^^^^^^^^^ -- help: remove this generic argument + | | + | expected 0 generic arguments + | +note: trait defined here, with 0 generic parameters + --> $DIR/wrong-number-of-args.rs:151:15 + | +LL | trait GenericLifetimeAT<'a> { + | ^^^^^^^^^^^^^^^^^ + +error[E0107]: this trait takes 1 generic argument but 0 generic arguments were supplied + --> $DIR/wrong-number-of-args.rs:175:26 + | +LL | type A = Box>; + | ^^^^^^^^^^^^^ expected 1 generic argument + | +note: trait defined here, with 1 generic parameter: `A` + --> $DIR/wrong-number-of-args.rs:171:15 + | +LL | trait GenericTypeAT { + | ^^^^^^^^^^^^^ - +help: add missing generic argument + | +LL | type A = Box>; + | ^^ + +error[E0107]: this trait takes 1 generic argument but 2 generic arguments were supplied + --> $DIR/wrong-number-of-args.rs:179:26 + | +LL | type B = Box>; + | ^^^^^^^^^^^^^ -- help: remove this generic argument + | | + | expected 1 generic argument + | +note: trait defined here, with 1 generic parameter: `A` + --> $DIR/wrong-number-of-args.rs:171:15 + | +LL | trait GenericTypeAT { + | ^^^^^^^^^^^^^ - + +error[E0107]: this trait takes 0 lifetime arguments but 1 lifetime argument was supplied + --> $DIR/wrong-number-of-args.rs:183:26 + | +LL | type C = Box>; + | ^^^^^^^^^^^^^--------------------- help: remove these generics + | | + | expected 0 lifetime arguments + | +note: trait defined here, with 0 lifetime parameters + --> $DIR/wrong-number-of-args.rs:171:15 + | +LL | trait GenericTypeAT { + | ^^^^^^^^^^^^^ + +error[E0107]: this trait takes 1 generic argument but 0 generic arguments were supplied + --> $DIR/wrong-number-of-args.rs:183:26 + | +LL | type C = Box>; + | ^^^^^^^^^^^^^ expected 1 generic argument + | +note: trait defined here, with 1 generic parameter: `A` + --> $DIR/wrong-number-of-args.rs:171:15 + | +LL | trait GenericTypeAT { + | ^^^^^^^^^^^^^ - +help: add missing generic argument + | +LL | type C = Box>; + | ^^^ + +error[E0106]: missing lifetime specifier + --> $DIR/wrong-number-of-args.rs:195:48 + | +LL | type A = Box>; + | ^ expected named lifetime parameter + | +help: consider introducing a named lifetime parameter + | +LL | type A<'a> = Box>; + | ^^^^ ^^^ + +error[E0107]: this trait takes 1 generic argument but 0 generic arguments were supplied + --> $DIR/wrong-number-of-args.rs:195:26 + | +LL | type A = Box>; + | ^^^^^^^^^^^^^^^^^^^^^ expected 1 generic argument + | +note: trait defined here, with 1 generic parameter: `A` + --> $DIR/wrong-number-of-args.rs:191:15 + | +LL | trait GenericLifetimeTypeAT<'a, A> { + | ^^^^^^^^^^^^^^^^^^^^^ - +help: add missing generic argument + | +LL | type A = Box>; + | ^^ + +error[E0107]: this trait takes 1 generic argument but 0 generic arguments were supplied + --> $DIR/wrong-number-of-args.rs:201:26 + | +LL | type B = Box>; + | ^^^^^^^^^^^^^^^^^^^^^ expected 1 generic argument + | +note: trait defined here, with 1 generic parameter: `A` + --> $DIR/wrong-number-of-args.rs:191:15 + | +LL | trait GenericLifetimeTypeAT<'a, A> { + | ^^^^^^^^^^^^^^^^^^^^^ - +help: add missing generic argument + | +LL | type B = Box>; + | ^^^ + +error[E0107]: this trait takes 1 lifetime argument but 2 lifetime arguments were supplied + --> $DIR/wrong-number-of-args.rs:205:26 + | +LL | type C = Box>; + | ^^^^^^^^^^^^^^^^^^^^^ ------- help: remove this lifetime argument + | | + | expected 1 lifetime argument + | +note: trait defined here, with 1 lifetime parameter: `'a` + --> $DIR/wrong-number-of-args.rs:191:15 + | +LL | trait GenericLifetimeTypeAT<'a, A> { + | ^^^^^^^^^^^^^^^^^^^^^ -- + +error[E0107]: this trait takes 1 generic argument but 0 generic arguments were supplied + --> $DIR/wrong-number-of-args.rs:205:26 + | +LL | type C = Box>; + | ^^^^^^^^^^^^^^^^^^^^^ expected 1 generic argument + | +note: trait defined here, with 1 generic parameter: `A` + --> $DIR/wrong-number-of-args.rs:191:15 + | +LL | trait GenericLifetimeTypeAT<'a, A> { + | ^^^^^^^^^^^^^^^^^^^^^ - +help: add missing generic argument + | +LL | type C = Box>; + | ^^^ + +error[E0106]: missing lifetime specifier + --> $DIR/wrong-number-of-args.rs:211:48 + | +LL | type D = Box>; + | ^ expected named lifetime parameter + | +help: consider introducing a named lifetime parameter + | +LL | type D<'a> = Box>; + | ^^^^ ^^^ + +error[E0106]: missing lifetime specifier + --> $DIR/wrong-number-of-args.rs:215:48 + | +LL | type E = Box>; + | ^ expected named lifetime parameter + | +help: consider introducing a named lifetime parameter + | +LL | type E<'a> = Box>; + | ^^^^ ^^^ + +error[E0107]: this trait takes 1 generic argument but 2 generic arguments were supplied + --> $DIR/wrong-number-of-args.rs:215:26 + | +LL | type E = Box>; + | ^^^^^^^^^^^^^^^^^^^^^ -- help: remove this generic argument + | | + | expected 1 generic argument + | +note: trait defined here, with 1 generic parameter: `A` + --> $DIR/wrong-number-of-args.rs:191:15 + | +LL | trait GenericLifetimeTypeAT<'a, A> { + | ^^^^^^^^^^^^^^^^^^^^^ - + +error[E0107]: this trait takes 1 lifetime argument but 2 lifetime arguments were supplied + --> $DIR/wrong-number-of-args.rs:221:26 + | +LL | type F = Box>; + | ^^^^^^^^^^^^^^^^^^^^^ ------- help: remove this lifetime argument + | | + | expected 1 lifetime argument + | +note: trait defined here, with 1 lifetime parameter: `'a` + --> $DIR/wrong-number-of-args.rs:191:15 + | +LL | trait GenericLifetimeTypeAT<'a, A> { + | ^^^^^^^^^^^^^^^^^^^^^ -- + +error[E0107]: this trait takes 1 generic argument but 2 generic arguments were supplied + --> $DIR/wrong-number-of-args.rs:225:26 + | +LL | type G = Box>; + | ^^^^^^^^^^^^^^^^^^^^^ -- help: remove this generic argument + | | + | expected 1 generic argument + | +note: trait defined here, with 1 generic parameter: `A` + --> $DIR/wrong-number-of-args.rs:191:15 + | +LL | trait GenericLifetimeTypeAT<'a, A> { + | ^^^^^^^^^^^^^^^^^^^^^ - + +error[E0107]: this trait takes 1 lifetime argument but 2 lifetime arguments were supplied + --> $DIR/wrong-number-of-args.rs:229:26 + | +LL | type H = Box>; + | ^^^^^^^^^^^^^^^^^^^^^ ------- help: remove this lifetime argument + | | + | expected 1 lifetime argument + | +note: trait defined here, with 1 lifetime parameter: `'a` + --> $DIR/wrong-number-of-args.rs:191:15 + | +LL | trait GenericLifetimeTypeAT<'a, A> { + | ^^^^^^^^^^^^^^^^^^^^^ -- + +error[E0107]: this trait takes 1 generic argument but 2 generic arguments were supplied + --> $DIR/wrong-number-of-args.rs:229:26 + | +LL | type H = Box>; + | ^^^^^^^^^^^^^^^^^^^^^ -- help: remove this generic argument + | | + | expected 1 generic argument + | +note: trait defined here, with 1 generic parameter: `A` + --> $DIR/wrong-number-of-args.rs:191:15 + | +LL | trait GenericLifetimeTypeAT<'a, A> { + | ^^^^^^^^^^^^^^^^^^^^^ - + +error[E0107]: this trait takes 2 generic arguments but 0 generic arguments were supplied + --> $DIR/wrong-number-of-args.rs:241:26 + | +LL | type A = Box>; + | ^^^^^^^^^^^^^^^^^ expected 2 generic arguments + | +note: trait defined here, with 2 generic parameters: `A`, `B` + --> $DIR/wrong-number-of-args.rs:237:15 + | +LL | trait GenericTypeTypeAT { + | ^^^^^^^^^^^^^^^^^ - - +help: add missing generic arguments + | +LL | type A = Box>; + | ^^^^^ + +error[E0107]: this trait takes 2 generic arguments but 1 generic argument was supplied + --> $DIR/wrong-number-of-args.rs:245:26 + | +LL | type B = Box>; + | ^^^^^^^^^^^^^^^^^ -- supplied 1 generic argument + | | + | expected 2 generic arguments + | +note: trait defined here, with 2 generic parameters: `A`, `B` + --> $DIR/wrong-number-of-args.rs:237:15 + | +LL | trait GenericTypeTypeAT { + | ^^^^^^^^^^^^^^^^^ - - +help: add missing generic argument + | +LL | type B = Box>; + | ^^^ + +error[E0107]: this trait takes 2 generic arguments but 3 generic arguments were supplied + --> $DIR/wrong-number-of-args.rs:249:26 + | +LL | type C = Box>; + | ^^^^^^^^^^^^^^^^^ -- help: remove this generic argument + | | + | expected 2 generic arguments + | +note: trait defined here, with 2 generic parameters: `A`, `B` + --> $DIR/wrong-number-of-args.rs:237:15 + | +LL | trait GenericTypeTypeAT { + | ^^^^^^^^^^^^^^^^^ - - + +error[E0106]: missing lifetime specifiers + --> $DIR/wrong-number-of-args.rs:259:52 + | +LL | type A = Box>; + | ^ expected 2 lifetime parameters + | +help: consider introducing a named lifetime parameter + | +LL | type A<'a> = Box>; + | ^^^^ ^^^^^^^ + +error[E0107]: this trait takes 2 lifetime arguments but 1 lifetime argument was supplied + --> $DIR/wrong-number-of-args.rs:263:26 + | +LL | type B = Box>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^ ------- supplied 1 lifetime argument + | | + | expected 2 lifetime arguments + | +note: trait defined here, with 2 lifetime parameters: `'a`, `'b` + --> $DIR/wrong-number-of-args.rs:255:15 + | +LL | trait GenericLifetimeLifetimeAT<'a, 'b> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ -- -- +help: add missing lifetime argument + | +LL | type B = Box>; + | ^^^^ + +error[E0106]: missing lifetime specifiers + --> $DIR/wrong-number-of-args.rs:273:56 + | +LL | type A = Box>; + | ^ expected 2 lifetime parameters + | +help: consider introducing a named lifetime parameter + | +LL | type A<'a> = Box>; + | ^^^^ ^^^^^^^ + +error[E0107]: this trait takes 1 generic argument but 0 generic arguments were supplied + --> $DIR/wrong-number-of-args.rs:273:26 + | +LL | type A = Box>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 generic argument + | +note: trait defined here, with 1 generic parameter: `A` + --> $DIR/wrong-number-of-args.rs:269:15 + | +LL | trait GenericLifetimeLifetimeTypeAT<'a, 'b, A> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - +help: add missing generic argument + | +LL | type A = Box>; + | ^^ + +error[E0107]: this trait takes 2 lifetime arguments but 1 lifetime argument was supplied + --> $DIR/wrong-number-of-args.rs:279:26 + | +LL | type B = Box>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ------- supplied 1 lifetime argument + | | + | expected 2 lifetime arguments + | +note: trait defined here, with 2 lifetime parameters: `'a`, `'b` + --> $DIR/wrong-number-of-args.rs:269:15 + | +LL | trait GenericLifetimeLifetimeTypeAT<'a, 'b, A> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -- -- +help: add missing lifetime argument + | +LL | type B = Box>; + | ^^^^ + +error[E0107]: this trait takes 1 generic argument but 0 generic arguments were supplied + --> $DIR/wrong-number-of-args.rs:279:26 + | +LL | type B = Box>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 1 generic argument + | +note: trait defined here, with 1 generic parameter: `A` + --> $DIR/wrong-number-of-args.rs:269:15 + | +LL | trait GenericLifetimeLifetimeTypeAT<'a, 'b, A> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - +help: add missing generic argument + | +LL | type B = Box>; + | ^^^ + +error[E0107]: this trait takes 2 lifetime arguments but 1 lifetime argument was supplied + --> $DIR/wrong-number-of-args.rs:285:26 + | +LL | type C = Box>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ------- supplied 1 lifetime argument + | | + | expected 2 lifetime arguments + | +note: trait defined here, with 2 lifetime parameters: `'a`, `'b` + --> $DIR/wrong-number-of-args.rs:269:15 + | +LL | trait GenericLifetimeLifetimeTypeAT<'a, 'b, A> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -- -- +help: add missing lifetime argument + | +LL | type C = Box>; + | ^^^^ + error[E0107]: missing generics for struct `HashMap` - --> $DIR/wrong-number-of-args.rs:121:18 + --> $DIR/wrong-number-of-args.rs:295:18 | LL | type A = HashMap; | ^^^^^^^ expected at least 2 generic arguments @@ -304,7 +835,7 @@ LL | type A = HashMap; | ^^^^^^^^^^^^^ error[E0107]: this struct takes at least 2 generic arguments but 1 generic argument was supplied - --> $DIR/wrong-number-of-args.rs:125:18 + --> $DIR/wrong-number-of-args.rs:299:18 | LL | type B = HashMap; | ^^^^^^^ ------ supplied 1 generic argument @@ -322,7 +853,7 @@ LL | type B = HashMap; | ^^^ error[E0107]: this struct takes 0 lifetime arguments but 1 lifetime argument was supplied - --> $DIR/wrong-number-of-args.rs:129:18 + --> $DIR/wrong-number-of-args.rs:303:18 | LL | type C = HashMap<'static>; | ^^^^^^^--------- help: remove these generics @@ -336,7 +867,7 @@ LL | pub struct HashMap { | ^^^^^^^ error[E0107]: this struct takes at least 2 generic arguments but 0 generic arguments were supplied - --> $DIR/wrong-number-of-args.rs:129:18 + --> $DIR/wrong-number-of-args.rs:303:18 | LL | type C = HashMap<'static>; | ^^^^^^^ expected at least 2 generic arguments @@ -352,7 +883,7 @@ LL | type C = HashMap<'static, K, V>; | ^^^^^^ error[E0107]: this struct takes at most 3 generic arguments but 4 generic arguments were supplied - --> $DIR/wrong-number-of-args.rs:135:18 + --> $DIR/wrong-number-of-args.rs:309:18 | LL | type D = HashMap; | ^^^^^^^ --- help: remove this generic argument @@ -365,8 +896,24 @@ note: struct defined here, with at most 3 generic parameters: `K`, `V`, `S` LL | pub struct HashMap { | ^^^^^^^ - - - +error[E0107]: this struct takes at least 2 generic arguments but 0 generic arguments were supplied + --> $DIR/wrong-number-of-args.rs:313:18 + | +LL | type E = HashMap<>; + | ^^^^^^^ expected at least 2 generic arguments + | +note: struct defined here, with at least 2 generic parameters: `K`, `V` + --> $SRC_DIR/std/src/collections/hash/map.rs:LL:COL + | +LL | pub struct HashMap { + | ^^^^^^^ - - +help: add missing generic arguments + | +LL | type E = HashMap; + | ^^^^ + error[E0107]: missing generics for enum `Result` - --> $DIR/wrong-number-of-args.rs:141:18 + --> $DIR/wrong-number-of-args.rs:319:18 | LL | type A = Result; | ^^^^^^ expected 2 generic arguments @@ -382,7 +929,7 @@ LL | type A = Result; | ^^^^^^^^^^^^ error[E0107]: this enum takes 2 generic arguments but 1 generic argument was supplied - --> $DIR/wrong-number-of-args.rs:145:18 + --> $DIR/wrong-number-of-args.rs:323:18 | LL | type B = Result; | ^^^^^^ ------ supplied 1 generic argument @@ -400,7 +947,7 @@ LL | type B = Result; | ^^^ error[E0107]: this enum takes 0 lifetime arguments but 1 lifetime argument was supplied - --> $DIR/wrong-number-of-args.rs:149:18 + --> $DIR/wrong-number-of-args.rs:327:18 | LL | type C = Result<'static>; | ^^^^^^--------- help: remove these generics @@ -414,7 +961,7 @@ LL | pub enum Result { | ^^^^^^ error[E0107]: this enum takes 2 generic arguments but 0 generic arguments were supplied - --> $DIR/wrong-number-of-args.rs:149:18 + --> $DIR/wrong-number-of-args.rs:327:18 | LL | type C = Result<'static>; | ^^^^^^ expected 2 generic arguments @@ -430,7 +977,7 @@ LL | type C = Result<'static, T, E>; | ^^^^^^ error[E0107]: this enum takes 2 generic arguments but 3 generic arguments were supplied - --> $DIR/wrong-number-of-args.rs:155:18 + --> $DIR/wrong-number-of-args.rs:333:18 | LL | type D = Result; | ^^^^^^ ---- help: remove this generic argument @@ -443,7 +990,23 @@ note: enum defined here, with 2 generic parameters: `T`, `E` LL | pub enum Result { | ^^^^^^ - - -error: aborting due to 30 previous errors +error[E0107]: this enum takes 2 generic arguments but 0 generic arguments were supplied + --> $DIR/wrong-number-of-args.rs:337:18 + | +LL | type E = Result<>; + | ^^^^^^ expected 2 generic arguments + | +note: enum defined here, with 2 generic parameters: `T`, `E` + --> $SRC_DIR/core/src/result.rs:LL:COL + | +LL | pub enum Result { + | ^^^^^^ - - +help: add missing generic arguments + | +LL | type E = Result; + | ^^^^ + +error: aborting due to 69 previous errors Some errors have detailed explanations: E0106, E0107. For more information about an error, try `rustc --explain E0106`. diff --git a/src/test/ui/unboxed-closures/unboxed-closure-sugar-used-on-struct-1.rs b/src/test/ui/unboxed-closures/unboxed-closure-sugar-used-on-struct-1.rs index a82856add5942..462f6fb7b8720 100644 --- a/src/test/ui/unboxed-closures/unboxed-closure-sugar-used-on-struct-1.rs +++ b/src/test/ui/unboxed-closures/unboxed-closure-sugar-used-on-struct-1.rs @@ -7,7 +7,7 @@ struct Bar { fn bar() { let x: Box = panic!(); //~^ ERROR parenthesized type parameters may only be used with a `Fn` trait - //~| ERROR missing generics for struct `Bar` + //~| ERROR this struct takes 1 generic argument but 0 generic arguments } fn main() { } diff --git a/src/test/ui/unboxed-closures/unboxed-closure-sugar-used-on-struct-1.stderr b/src/test/ui/unboxed-closures/unboxed-closure-sugar-used-on-struct-1.stderr index d0d27a5b75955..90bef7ba11808 100644 --- a/src/test/ui/unboxed-closures/unboxed-closure-sugar-used-on-struct-1.stderr +++ b/src/test/ui/unboxed-closures/unboxed-closure-sugar-used-on-struct-1.stderr @@ -4,7 +4,7 @@ error[E0214]: parenthesized type parameters may only be used with a `Fn` trait LL | let x: Box = panic!(); | ^^^^^ only `Fn` traits may use parentheses -error[E0107]: missing generics for struct `Bar` +error[E0107]: this struct takes 1 generic argument but 0 generic arguments were supplied --> $DIR/unboxed-closure-sugar-used-on-struct-1.rs:8:16 | LL | let x: Box = panic!(); @@ -17,8 +17,8 @@ LL | struct Bar { | ^^^ - help: add missing generic argument | -LL | let x: Box()> = panic!(); - | ^^^^^^ +LL | let x: Box = panic!(); + | ^ error: aborting due to 2 previous errors diff --git a/src/test/ui/unboxed-closures/unboxed-closure-sugar-used-on-struct.rs b/src/test/ui/unboxed-closures/unboxed-closure-sugar-used-on-struct.rs index b44505f8a4133..bd61cbd80220e 100644 --- a/src/test/ui/unboxed-closures/unboxed-closure-sugar-used-on-struct.rs +++ b/src/test/ui/unboxed-closures/unboxed-closure-sugar-used-on-struct.rs @@ -6,7 +6,7 @@ struct Bar { fn foo(b: Box) { //~^ ERROR parenthesized type parameters may only be used with a `Fn` trait - //~| ERROR missing generics for struct `Bar` + //~| ERROR this struct takes 1 generic argument but 0 generic arguments } fn main() { } diff --git a/src/test/ui/unboxed-closures/unboxed-closure-sugar-used-on-struct.stderr b/src/test/ui/unboxed-closures/unboxed-closure-sugar-used-on-struct.stderr index 0abf46cee9269..931675afd83f0 100644 --- a/src/test/ui/unboxed-closures/unboxed-closure-sugar-used-on-struct.stderr +++ b/src/test/ui/unboxed-closures/unboxed-closure-sugar-used-on-struct.stderr @@ -4,7 +4,7 @@ error[E0214]: parenthesized type parameters may only be used with a `Fn` trait LL | fn foo(b: Box) { | ^^^^^ only `Fn` traits may use parentheses -error[E0107]: missing generics for struct `Bar` +error[E0107]: this struct takes 1 generic argument but 0 generic arguments were supplied --> $DIR/unboxed-closure-sugar-used-on-struct.rs:7:15 | LL | fn foo(b: Box) { @@ -17,8 +17,8 @@ LL | struct Bar { | ^^^ - help: add missing generic argument | -LL | fn foo(b: Box()>) { - | ^^^^^^ +LL | fn foo(b: Box) { + | ^ error: aborting due to 2 previous errors