From 6225e980bf0376986c10943216fb0b7779d29e58 Mon Sep 17 00:00:00 2001 From: Ellen Date: Thu, 5 May 2022 12:23:42 +0100 Subject: handle mismatched generic parameter kinds --- .../defaults/mismatched_ty_const_in_trait_impl.rs | 25 +++++++++++ .../mismatched_ty_const_in_trait_impl.stderr | 52 ++++++++++++++++++++++ .../const_params_have_right_type.rs | 12 +++++ .../const_params_have_right_type.stderr | 15 +++++++ 4 files changed, 104 insertions(+) create mode 100644 src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.rs create mode 100644 src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.stderr create mode 100644 src/test/ui/generic-associated-types/const_params_have_right_type.rs create mode 100644 src/test/ui/generic-associated-types/const_params_have_right_type.stderr (limited to 'src') diff --git a/src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.rs b/src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.rs new file mode 100644 index 00000000000..0c6669fa9b6 --- /dev/null +++ b/src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.rs @@ -0,0 +1,25 @@ +trait Trait { + fn foo() {} +} +impl Trait for () { + fn foo() {} + //~^ error: method `foo` has an incompatble generic parameter for trait +} + +trait Other { + fn bar() {} +} +impl Other for () { + fn bar() {} + //~^ error: method `bar` has an incompatible generic parameter for trait +} + +trait Uwu { + fn baz() {} +} +impl Uwu for () { + fn baz() {} + //~^ error: method `baz` has an incompatible generic parameter for trait +} + +fn main() {} diff --git a/src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.stderr b/src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.stderr new file mode 100644 index 00000000000..d400c216590 --- /dev/null +++ b/src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.stderr @@ -0,0 +1,52 @@ +error[E0049]: method `foo` has 0 type parameters but its trait declaration has 1 type parameter + --> $DIR/mismatched_ty_const_in_trait_impl.rs:5:12 + | +LL | fn foo() {} + | - expected 1 type parameter +... +LL | fn foo() {} + | ^^^^^^^^^^^^ found 0 type parameters + +error[E0049]: method `foo` has 1 const parameter but its trait declaration has 0 const parameters + --> $DIR/mismatched_ty_const_in_trait_impl.rs:5:12 + | +LL | fn foo() {} + | - expected 0 const parameters +... +LL | fn foo() {} + | ^^^^^^^^^^^^ found 1 const parameter + +error[E0049]: method `bar` has 1 type parameter but its trait declaration has 0 type parameters + --> $DIR/mismatched_ty_const_in_trait_impl.rs:13:12 + | +LL | fn bar() {} + | ----------- expected 0 type parameters +... +LL | fn bar() {} + | ^ found 1 type parameter + +error[E0049]: method `bar` has 0 const parameters but its trait declaration has 1 const parameter + --> $DIR/mismatched_ty_const_in_trait_impl.rs:13:12 + | +LL | fn bar() {} + | ----------- expected 1 const parameter +... +LL | fn bar() {} + | ^ found 0 const parameters + +error[E0053]: method `baz` has an incompatible const parameter type for trait + --> $DIR/mismatched_ty_const_in_trait_impl.rs:21:12 + | +LL | fn baz() {} + | ^^^^^^^^^^^^ + | +note: the const parameter `N` has type `i32`, but the declaration in trait `Uwu::baz` has type `u32` + --> $DIR/mismatched_ty_const_in_trait_impl.rs:18:12 + | +LL | fn baz() {} + | ^^^^^^^^^^^^ + +error: aborting due to 5 previous errors + +Some errors have detailed explanations: E0049, E0053. +For more information about an error, try `rustc --explain E0049`. diff --git a/src/test/ui/generic-associated-types/const_params_have_right_type.rs b/src/test/ui/generic-associated-types/const_params_have_right_type.rs new file mode 100644 index 00000000000..675132587bf --- /dev/null +++ b/src/test/ui/generic-associated-types/const_params_have_right_type.rs @@ -0,0 +1,12 @@ +#![feature(generic_associated_types)] + +trait Trait { + type Foo; +} + +impl Trait for () { + type Foo = u32; + //~^ error: associated type `Foo` has an incompatible const parameter type +} + +fn main() {} diff --git a/src/test/ui/generic-associated-types/const_params_have_right_type.stderr b/src/test/ui/generic-associated-types/const_params_have_right_type.stderr new file mode 100644 index 00000000000..62353180c67 --- /dev/null +++ b/src/test/ui/generic-associated-types/const_params_have_right_type.stderr @@ -0,0 +1,15 @@ +error[E0053]: associated type `Foo` has an incompatible const parameter type for trait + --> $DIR/const_params_have_right_type.rs:8:14 + | +LL | type Foo = u32; + | ^^^^^^^^^^^^ + | +note: the const parameter `N` has type `u64`, but the declaration in trait `Trait::Foo` has type `u8` + --> $DIR/const_params_have_right_type.rs:4:14 + | +LL | type Foo; + | ^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0053`. -- cgit 1.4.1-3-g733a5 From 4208c53ed695ddb822b6510e3faa0a46e591060e Mon Sep 17 00:00:00 2001 From: Ellen Date: Thu, 5 May 2022 12:41:43 +0100 Subject: exit out of `compare_number_of_generics` early --- compiler/rustc_typeck/src/check/compare_method.rs | 30 ++++++++++++++++ .../defaults/mismatched_ty_const_in_trait_impl.rs | 4 +-- .../mismatched_ty_const_in_trait_impl.stderr | 41 ++++++++-------------- .../const_params_have_right_type.rs | 2 +- .../const_params_have_right_type.stderr | 2 +- 5 files changed, 48 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/compiler/rustc_typeck/src/check/compare_method.rs b/compiler/rustc_typeck/src/check/compare_method.rs index c42280a8208..c810be16bf8 100644 --- a/compiler/rustc_typeck/src/check/compare_method.rs +++ b/compiler/rustc_typeck/src/check/compare_method.rs @@ -579,6 +579,27 @@ fn compare_self_type<'tcx>( Ok(()) } +/// Checks that the number of generics on a given assoc item in a trait impl is the same +/// as the number of generics on the respective assoc item in the trait definition. +/// +/// For example this code emits the errors in the following code: +/// ``` +/// trait Trait { +/// fn foo(); +/// type Assoc; +/// } +/// +/// impl Trait for () { +/// fn foo() {} +/// //~^ error +/// type Assoc = u32; +/// //~^ error +/// } +/// ``` +/// +/// Notably this does not error on `foo` implemented as `foo` or +/// `foo` implemented as `foo`. This is handled in +/// [`compare_generic_param_kinds`]. This function also does not handle lifetime parameters fn compare_number_of_generics<'tcx>( tcx: TyCtxt<'tcx>, impl_: &ty::AssocItem, @@ -589,6 +610,15 @@ fn compare_number_of_generics<'tcx>( let trait_own_counts = tcx.generics_of(trait_.def_id).own_counts(); let impl_own_counts = tcx.generics_of(impl_.def_id).own_counts(); + // This avoids us erroring on `foo` implemented as `foo` as this is implemented + // in `compare_generic_param_kinds` which will give a nicer error message than something like: + // "expected 1 type parameter, found 0 type parameters" + if (trait_own_counts.types + trait_own_counts.consts) + == (impl_own_counts.types + impl_own_counts.consts) + { + return Ok(()); + } + let matchings = [ ("type", trait_own_counts.types, impl_own_counts.types), ("const", trait_own_counts.consts, impl_own_counts.consts), diff --git a/src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.rs b/src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.rs index 0c6669fa9b6..fd57060d5e7 100644 --- a/src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.rs +++ b/src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.rs @@ -3,7 +3,7 @@ trait Trait { } impl Trait for () { fn foo() {} - //~^ error: method `foo` has an incompatble generic parameter for trait + //~^ error: method `foo` has an incompatible generic parameter for trait } trait Other { @@ -19,7 +19,7 @@ trait Uwu { } impl Uwu for () { fn baz() {} - //~^ error: method `baz` has an incompatible generic parameter for trait + //~^ error: method `baz` has an incompatible const parameter type for trait } fn main() {} diff --git a/src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.stderr b/src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.stderr index d400c216590..cea8f4e50b0 100644 --- a/src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.stderr +++ b/src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.stderr @@ -1,38 +1,26 @@ -error[E0049]: method `foo` has 0 type parameters but its trait declaration has 1 type parameter +error[E0053]: method `foo` has an incompatible generic parameter for trait --> $DIR/mismatched_ty_const_in_trait_impl.rs:5:12 | -LL | fn foo() {} - | - expected 1 type parameter -... LL | fn foo() {} - | ^^^^^^^^^^^^ found 0 type parameters - -error[E0049]: method `foo` has 1 const parameter but its trait declaration has 0 const parameters - --> $DIR/mismatched_ty_const_in_trait_impl.rs:5:12 + | ^^^^^^^^^^^^ + | +note: the trait impl specifies `M` is a const parameter of type `u64`, but the declaration in trait `Trait::foo` requires it is a type parameter + --> $DIR/mismatched_ty_const_in_trait_impl.rs:2:12 | LL | fn foo() {} - | - expected 0 const parameters -... -LL | fn foo() {} - | ^^^^^^^^^^^^ found 1 const parameter + | ^ -error[E0049]: method `bar` has 1 type parameter but its trait declaration has 0 type parameters +error[E0053]: method `bar` has an incompatible generic parameter for trait --> $DIR/mismatched_ty_const_in_trait_impl.rs:13:12 | -LL | fn bar() {} - | ----------- expected 0 type parameters -... LL | fn bar() {} - | ^ found 1 type parameter - -error[E0049]: method `bar` has 0 const parameters but its trait declaration has 1 const parameter - --> $DIR/mismatched_ty_const_in_trait_impl.rs:13:12 + | ^ + | +note: the trait impl specifies `T` is a type parameter, but the declaration in trait `Other::bar` requires it is a const parameter of type `u8` + --> $DIR/mismatched_ty_const_in_trait_impl.rs:10:12 | LL | fn bar() {} - | ----------- expected 1 const parameter -... -LL | fn bar() {} - | ^ found 0 const parameters + | ^^^^^^^^^^^ error[E0053]: method `baz` has an incompatible const parameter type for trait --> $DIR/mismatched_ty_const_in_trait_impl.rs:21:12 @@ -46,7 +34,6 @@ note: the const parameter `N` has type `i32`, but the declaration in trait `Uwu: LL | fn baz() {} | ^^^^^^^^^^^^ -error: aborting due to 5 previous errors +error: aborting due to 3 previous errors -Some errors have detailed explanations: E0049, E0053. -For more information about an error, try `rustc --explain E0049`. +For more information about this error, try `rustc --explain E0053`. diff --git a/src/test/ui/generic-associated-types/const_params_have_right_type.rs b/src/test/ui/generic-associated-types/const_params_have_right_type.rs index 675132587bf..138d332eed4 100644 --- a/src/test/ui/generic-associated-types/const_params_have_right_type.rs +++ b/src/test/ui/generic-associated-types/const_params_have_right_type.rs @@ -6,7 +6,7 @@ trait Trait { impl Trait for () { type Foo = u32; - //~^ error: associated type `Foo` has an incompatible const parameter type + //~^ error: type `Foo` has an incompatible const parameter type } fn main() {} diff --git a/src/test/ui/generic-associated-types/const_params_have_right_type.stderr b/src/test/ui/generic-associated-types/const_params_have_right_type.stderr index 62353180c67..4ec6c19f54b 100644 --- a/src/test/ui/generic-associated-types/const_params_have_right_type.stderr +++ b/src/test/ui/generic-associated-types/const_params_have_right_type.stderr @@ -1,4 +1,4 @@ -error[E0053]: associated type `Foo` has an incompatible const parameter type for trait +error[E0053]: type `Foo` has an incompatible const parameter type for trait --> $DIR/const_params_have_right_type.rs:8:14 | LL | type Foo = u32; -- cgit 1.4.1-3-g733a5 From fea1d765033eada386ffc1684d47c00a48d104f1 Mon Sep 17 00:00:00 2001 From: Ellen Date: Thu, 5 May 2022 17:44:54 +0100 Subject: make `compare_generic_param_kinds` errors consistent --- compiler/rustc_typeck/src/check/compare_method.rs | 166 ++++++--------------- .../defaults/mismatched_ty_const_in_trait_impl.rs | 18 ++- .../mismatched_ty_const_in_trait_impl.stderr | 75 +++++++--- src/test/ui/const-generics/issues/issue-86820.rs | 9 +- .../ui/const-generics/issues/issue-86820.stderr | 21 +-- .../const_params_have_right_type.rs | 2 +- .../const_params_have_right_type.stderr | 17 ++- 7 files changed, 142 insertions(+), 166 deletions(-) (limited to 'src') diff --git a/compiler/rustc_typeck/src/check/compare_method.rs b/compiler/rustc_typeck/src/check/compare_method.rs index c810be16bf8..590131e4f6a 100644 --- a/compiler/rustc_typeck/src/check/compare_method.rs +++ b/compiler/rustc_typeck/src/check/compare_method.rs @@ -7,10 +7,10 @@ use rustc_hir::intravisit; use rustc_hir::{GenericParamKind, ImplItemKind, TraitItemKind}; use rustc_infer::infer::{self, InferOk, TyCtxtInferExt}; use rustc_infer::traits::util; -use rustc_middle::ty; use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::subst::{InternalSubsts, Subst}; use rustc_middle::ty::util::ExplicitSelf; +use rustc_middle::ty::{self, DefIdTree}; use rustc_middle::ty::{GenericParamDefKind, ToPredicate, TyCtxt}; use rustc_span::Span; use rustc_trait_selection::traits::error_reporting::InferCtxtExt; @@ -48,7 +48,7 @@ crate fn compare_impl_method<'tcx>( return; } - if let Err(_) = compare_generic_param_kinds(tcx, impl_m, trait_m, trait_item_span) { + if let Err(_) = compare_generic_param_kinds(tcx, impl_m, trait_m) { return; } @@ -973,7 +973,6 @@ fn compare_generic_param_kinds<'tcx>( tcx: TyCtxt<'tcx>, impl_item: &ty::AssocItem, trait_item: &ty::AssocItem, - trait_item_span: Option, ) -> Result<(), ErrorGuaranteed> { assert_eq!(impl_item.kind, trait_item.kind); @@ -986,123 +985,54 @@ fn compare_generic_param_kinds<'tcx>( }) }; - let get_param_span = |param: &ty::GenericParamDef| match tcx.hir().get_if_local(param.def_id) { - Some(hir::Node::GenericParam(hir::GenericParam { span, .. })) => Some(span), - _ => None, - }; + for (param_impl, param_trait) in + iter::zip(ty_const_params_of(impl_item.def_id), ty_const_params_of(trait_item.def_id)) + { + use GenericParamDefKind::*; + if match (¶m_impl.kind, ¶m_trait.kind) { + (Const { .. }, Const { .. }) + if tcx.type_of(param_impl.def_id) != tcx.type_of(param_trait.def_id) => + { + true + } + (Const { .. }, Type { .. }) | (Type { .. }, Const { .. }) => true, + // this is exhaustive so that anyone adding new generic param kinds knows + // to make sure this error is reported for them. + (Const { .. }, Const { .. }) | (Type { .. }, Type { .. }) => false, + (Lifetime { .. }, _) | (_, Lifetime { .. }) => unreachable!(), + } { + let make_param_message = |prefix: &str, param: &ty::GenericParamDef| match param.kind { + Const { .. } => { + format!("{} const parameter with type `{}`", prefix, tcx.type_of(param.def_id)) + } + Type { .. } => format!("{} type parameter", prefix), + Lifetime { .. } => unreachable!(), + }; - let get_param_ident = |param: &ty::GenericParamDef| match tcx.hir().get_if_local(param.def_id) { - Some(hir::Node::GenericParam(hir::GenericParam { name, .. })) => match name { - hir::ParamName::Plain(ident) => Some(ident), - _ => None, - }, - other => bug!( - "expected GenericParam, found {:?}", - other.map_or_else(|| "nothing".to_string(), |n| format!("{:?}", n)) - ), - }; + let param_impl_span = tcx.def_span(param_impl.def_id); + let param_trait_span = tcx.def_span(param_trait.def_id); - let ty_const_params_impl = ty_const_params_of(impl_item.def_id); - let ty_const_params_trait = ty_const_params_of(trait_item.def_id); - let assoc_item_str = assoc_item_kind_str(&impl_item); + let mut err = struct_span_err!( + tcx.sess, + param_impl_span, + E0053, + "{} `{}` has an incompatible generic parameter for trait: `{}`", + assoc_item_kind_str(&impl_item), + trait_item.name, + &tcx.def_path_str(tcx.parent(trait_item.def_id)) + ); - for (param_impl, param_trait) in iter::zip(ty_const_params_impl, ty_const_params_trait) { - use GenericParamDefKind::*; - match (¶m_impl.kind, ¶m_trait.kind) { - (Const { .. }, Const { .. }) => { - let impl_ty = tcx.type_of(param_impl.def_id); - let trait_ty = tcx.type_of(param_trait.def_id); - if impl_ty != trait_ty { - let param_impl_span = get_param_span(param_impl).unwrap(); - let param_impl_ident = get_param_ident(param_impl); - let param_trait_span = get_param_span(param_trait); - - let mut err = struct_span_err!( - tcx.sess, - *param_impl_span, - E0053, - "{} `{}` has an incompatible const parameter type for trait", - assoc_item_str, - trait_item.name, - ); - err.span_note( - param_trait_span.map_or_else( - || trait_item_span.unwrap_or(*param_impl_span), - |span| *span, - ), - &format!( - "the const parameter{} has type `{}`, but the declaration \ - in trait `{}` has type `{}`", - ¶m_impl_ident - .map_or_else(|| "".to_string(), |ident| format!(" `{ident}`")), - impl_ty, - tcx.def_path_str(trait_item.def_id), - trait_ty - ), - ); - let reported = err.emit(); - return Err(reported); - } - } - (Const { .. }, Type { .. }) => { - let impl_ty = tcx.type_of(param_impl.def_id); - let param_impl_span = get_param_span(param_impl).unwrap(); - let param_impl_ident = get_param_ident(param_impl); - let param_trait_span = get_param_span(param_trait); - - let mut err = struct_span_err!( - tcx.sess, - *param_impl_span, - E0053, - "{} `{}` has an incompatible generic parameter for trait", - assoc_item_str, - trait_item.name, - ); - err.span_note( - param_trait_span - .map_or_else(|| trait_item_span.unwrap_or(*param_impl_span), |span| *span), - &format!( - "the trait impl specifies{} a const parameter of type `{}`, but the declaration \ - in trait `{}` requires it is a type parameter", - ¶m_impl_ident - .map_or_else(|| "".to_string(), |ident| format!(" `{ident}` is")), - impl_ty, - tcx.def_path_str(trait_item.def_id), - ), - ); - let reported = err.emit(); - return Err(reported); - } - (Type { .. }, Const { .. }) => { - let trait_ty = tcx.type_of(param_trait.def_id); - let param_impl_span = get_param_span(param_impl).unwrap(); - let param_impl_ident = get_param_ident(param_impl); - let param_trait_span = get_param_span(param_trait); - - let mut err = struct_span_err!( - tcx.sess, - *param_impl_span, - E0053, - "{} `{}` has an incompatible generic parameter for trait", - assoc_item_str, - trait_item.name, - ); - err.span_note( - param_trait_span - .map_or_else(|| trait_item_span.unwrap_or(*param_impl_span), |span| *span), - &format!( - "the trait impl specifies{} a type parameter, but the declaration \ - in trait `{}` requires it is a const parameter of type `{}`", - ¶m_impl_ident - .map_or_else(|| "".to_string(), |ident| format!(" `{ident}` is")), - tcx.def_path_str(trait_item.def_id), - trait_ty, - ), - ); - let reported = err.emit(); - return Err(reported); - } - _ => (), + let trait_header_span = tcx.def_ident_span(tcx.parent(trait_item.def_id)).unwrap(); + err.span_label(trait_header_span, ""); + err.span_label(param_trait_span, make_param_message("expected", param_trait)); + + let impl_header_span = + tcx.sess.source_map().guess_head_span(tcx.def_span(tcx.parent(impl_item.def_id))); + err.span_label(impl_header_span, ""); + err.span_label(param_impl_span, make_param_message("found", param_impl)); + + let reported = err.emit(); + return Err(reported); } } @@ -1228,7 +1158,7 @@ crate fn compare_ty_impl<'tcx>( let _: Result<(), ErrorGuaranteed> = (|| { compare_number_of_generics(tcx, impl_ty, impl_ty_span, trait_ty, trait_item_span)?; - compare_generic_param_kinds(tcx, impl_ty, trait_ty, trait_item_span)?; + compare_generic_param_kinds(tcx, impl_ty, trait_ty)?; let sp = tcx.def_span(impl_ty.def_id); compare_type_predicate_entailment(tcx, impl_ty, sp, trait_ty, impl_trait_ref)?; diff --git a/src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.rs b/src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.rs index fd57060d5e7..5c9323261a9 100644 --- a/src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.rs +++ b/src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.rs @@ -19,7 +19,23 @@ trait Uwu { } impl Uwu for () { fn baz() {} - //~^ error: method `baz` has an incompatible const parameter type for trait + //~^ error: method `baz` has an incompatible generic parameter for trait +} + +trait Aaaaaa { + fn bbbb() {} +} +impl Aaaaaa for () { + fn bbbb() {} + //~^ error: method `bbbb` has an incompatible generic parameter for trait +} + +trait Names { + fn abcd() {} +} +impl Names for () { + fn abcd() {} + //~^ error: method `abcd` has an incompatible generic parameter for trait } fn main() {} diff --git a/src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.stderr b/src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.stderr index cea8f4e50b0..a1ec8adec76 100644 --- a/src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.stderr +++ b/src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.stderr @@ -1,39 +1,68 @@ -error[E0053]: method `foo` has an incompatible generic parameter for trait +error[E0053]: method `foo` has an incompatible generic parameter for trait: `Trait` --> $DIR/mismatched_ty_const_in_trait_impl.rs:5:12 | -LL | fn foo() {} - | ^^^^^^^^^^^^ - | -note: the trait impl specifies `M` is a const parameter of type `u64`, but the declaration in trait `Trait::foo` requires it is a type parameter - --> $DIR/mismatched_ty_const_in_trait_impl.rs:2:12 - | +LL | trait Trait { + | ----- LL | fn foo() {} - | ^ + | - expected type parameter +LL | } +LL | impl Trait for () { + | ----------------- +LL | fn foo() {} + | ^^^^^^^^^^^^ found const parameter with type `u64` -error[E0053]: method `bar` has an incompatible generic parameter for trait +error[E0053]: method `bar` has an incompatible generic parameter for trait: `Other` --> $DIR/mismatched_ty_const_in_trait_impl.rs:13:12 | -LL | fn bar() {} - | ^ - | -note: the trait impl specifies `T` is a type parameter, but the declaration in trait `Other::bar` requires it is a const parameter of type `u8` - --> $DIR/mismatched_ty_const_in_trait_impl.rs:10:12 - | +LL | trait Other { + | ----- LL | fn bar() {} - | ^^^^^^^^^^^ + | ----------- expected const parameter with type `u8` +LL | } +LL | impl Other for () { + | ----------------- +LL | fn bar() {} + | ^ found type parameter -error[E0053]: method `baz` has an incompatible const parameter type for trait +error[E0053]: method `baz` has an incompatible generic parameter for trait: `Uwu` --> $DIR/mismatched_ty_const_in_trait_impl.rs:21:12 | +LL | trait Uwu { + | --- +LL | fn baz() {} + | ------------ expected const parameter with type `u32` +LL | } +LL | impl Uwu for () { + | --------------- LL | fn baz() {} - | ^^^^^^^^^^^^ + | ^^^^^^^^^^^^ found const parameter with type `i32` + +error[E0053]: method `bbbb` has an incompatible generic parameter for trait: `Aaaaaa` + --> $DIR/mismatched_ty_const_in_trait_impl.rs:29:13 | -note: the const parameter `N` has type `i32`, but the declaration in trait `Uwu::baz` has type `u32` - --> $DIR/mismatched_ty_const_in_trait_impl.rs:18:12 +LL | trait Aaaaaa { + | ------ +LL | fn bbbb() {} + | ------------ expected const parameter with type `u32` +LL | } +LL | impl Aaaaaa for () { + | ------------------ +LL | fn bbbb() {} + | ^ found type parameter + +error[E0053]: method `abcd` has an incompatible generic parameter for trait: `Names` + --> $DIR/mismatched_ty_const_in_trait_impl.rs:37:13 | -LL | fn baz() {} - | ^^^^^^^^^^^^ +LL | trait Names { + | ----- +LL | fn abcd() {} + | - expected type parameter +LL | } +LL | impl Names for () { + | ----------------- +LL | fn abcd() {} + | ^^^^^^^^^^^^ found const parameter with type `u32` -error: aborting due to 3 previous errors +error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0053`. diff --git a/src/test/ui/const-generics/issues/issue-86820.rs b/src/test/ui/const-generics/issues/issue-86820.rs index 04650403c6b..9bcb8e1aeed 100644 --- a/src/test/ui/const-generics/issues/issue-86820.rs +++ b/src/test/ui/const-generics/issues/issue-86820.rs @@ -1,6 +1,6 @@ // Regression test for the ICE described in #86820. -#![allow(unused,dead_code)] +#![allow(unused, dead_code)] use std::ops::BitAnd; const C: fn() = || is_set(); @@ -9,13 +9,12 @@ fn is_set() { } trait Bits { - fn bit(self) -> bool; - //~^ NOTE: the const parameter `I` has type `usize`, but the declaration in trait `Bits::bit` has type `u8` + fn bit(self) -> bool; } impl Bits for u8 { - fn bit(self) -> bool { - //~^ ERROR: method `bit` has an incompatible const parameter type for trait [E0053] + fn bit(self) -> bool { + //~^ ERROR: method `bit` has an incompatible generic parameter for trait: `Bits` [E0053] let i = 1 << I; let mask = u8::from(i); mask & self == mask diff --git a/src/test/ui/const-generics/issues/issue-86820.stderr b/src/test/ui/const-generics/issues/issue-86820.stderr index f7b8d80eeca..4d54d654c12 100644 --- a/src/test/ui/const-generics/issues/issue-86820.stderr +++ b/src/test/ui/const-generics/issues/issue-86820.stderr @@ -1,14 +1,15 @@ -error[E0053]: method `bit` has an incompatible const parameter type for trait - --> $DIR/issue-86820.rs:17:12 +error[E0053]: method `bit` has an incompatible generic parameter for trait: `Bits` + --> $DIR/issue-86820.rs:16:12 | -LL | fn bit(self) -> bool { - | ^^^^^^^^^^^^^^^ - | -note: the const parameter `I` has type `usize`, but the declaration in trait `Bits::bit` has type `u8` - --> $DIR/issue-86820.rs:12:12 - | -LL | fn bit(self) -> bool; - | ^^^^^^^^^^^^ +LL | trait Bits { + | ---- +LL | fn bit(self) -> bool; + | ----------- expected const parameter with type `u8` +... +LL | impl Bits for u8 { + | ---------------- +LL | fn bit(self) -> bool { + | ^^^^^^^^^^^^^^ found const parameter with type `usize` error: aborting due to previous error diff --git a/src/test/ui/generic-associated-types/const_params_have_right_type.rs b/src/test/ui/generic-associated-types/const_params_have_right_type.rs index 138d332eed4..6bed8e3aff9 100644 --- a/src/test/ui/generic-associated-types/const_params_have_right_type.rs +++ b/src/test/ui/generic-associated-types/const_params_have_right_type.rs @@ -6,7 +6,7 @@ trait Trait { impl Trait for () { type Foo = u32; - //~^ error: type `Foo` has an incompatible const parameter type + //~^ error: type `Foo` has an incompatible generic parameter for trait } fn main() {} diff --git a/src/test/ui/generic-associated-types/const_params_have_right_type.stderr b/src/test/ui/generic-associated-types/const_params_have_right_type.stderr index 4ec6c19f54b..9b8eddaff41 100644 --- a/src/test/ui/generic-associated-types/const_params_have_right_type.stderr +++ b/src/test/ui/generic-associated-types/const_params_have_right_type.stderr @@ -1,14 +1,15 @@ -error[E0053]: type `Foo` has an incompatible const parameter type for trait +error[E0053]: type `Foo` has an incompatible generic parameter for trait: `Trait` --> $DIR/const_params_have_right_type.rs:8:14 | -LL | type Foo = u32; - | ^^^^^^^^^^^^ - | -note: the const parameter `N` has type `u64`, but the declaration in trait `Trait::Foo` has type `u8` - --> $DIR/const_params_have_right_type.rs:4:14 - | +LL | trait Trait { + | ----- LL | type Foo; - | ^^^^^^^^^^^ + | ----------- expected const parameter with type `u8` +... +LL | impl Trait for () { + | ----------------- +LL | type Foo = u32; + | ^^^^^^^^^^^^ found const parameter with type `u64` error: aborting due to previous error -- cgit 1.4.1-3-g733a5 From 2819b2d8c91ac7d3b366c3c76dca37d2b7b2b5d5 Mon Sep 17 00:00:00 2001 From: Ellen Date: Fri, 6 May 2022 11:37:22 +0100 Subject: wording tweaks --- compiler/rustc_typeck/src/check/compare_method.rs | 4 ++-- .../mismatched_ty_const_in_trait_impl.stderr | 22 +++++++++++----------- src/test/ui/const-generics/issues/issue-86820.rs | 2 +- .../ui/const-generics/issues/issue-86820.stderr | 6 +++--- .../const_params_have_right_type.stderr | 6 +++--- 5 files changed, 20 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/compiler/rustc_typeck/src/check/compare_method.rs b/compiler/rustc_typeck/src/check/compare_method.rs index 590131e4f6a..3e15079552c 100644 --- a/compiler/rustc_typeck/src/check/compare_method.rs +++ b/compiler/rustc_typeck/src/check/compare_method.rs @@ -1003,7 +1003,7 @@ fn compare_generic_param_kinds<'tcx>( } { let make_param_message = |prefix: &str, param: &ty::GenericParamDef| match param.kind { Const { .. } => { - format!("{} const parameter with type `{}`", prefix, tcx.type_of(param.def_id)) + format!("{} const parameter of type `{}`", prefix, tcx.type_of(param.def_id)) } Type { .. } => format!("{} type parameter", prefix), Lifetime { .. } => unreachable!(), @@ -1016,7 +1016,7 @@ fn compare_generic_param_kinds<'tcx>( tcx.sess, param_impl_span, E0053, - "{} `{}` has an incompatible generic parameter for trait: `{}`", + "{} `{}` has an incompatible generic parameter for trait `{}`", assoc_item_kind_str(&impl_item), trait_item.name, &tcx.def_path_str(tcx.parent(trait_item.def_id)) diff --git a/src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.stderr b/src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.stderr index a1ec8adec76..3455f2c8ea9 100644 --- a/src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.stderr +++ b/src/test/ui/const-generics/defaults/mismatched_ty_const_in_trait_impl.stderr @@ -1,4 +1,4 @@ -error[E0053]: method `foo` has an incompatible generic parameter for trait: `Trait` +error[E0053]: method `foo` has an incompatible generic parameter for trait `Trait` --> $DIR/mismatched_ty_const_in_trait_impl.rs:5:12 | LL | trait Trait { @@ -9,48 +9,48 @@ LL | } LL | impl Trait for () { | ----------------- LL | fn foo() {} - | ^^^^^^^^^^^^ found const parameter with type `u64` + | ^^^^^^^^^^^^ found const parameter of type `u64` -error[E0053]: method `bar` has an incompatible generic parameter for trait: `Other` +error[E0053]: method `bar` has an incompatible generic parameter for trait `Other` --> $DIR/mismatched_ty_const_in_trait_impl.rs:13:12 | LL | trait Other { | ----- LL | fn bar() {} - | ----------- expected const parameter with type `u8` + | ----------- expected const parameter of type `u8` LL | } LL | impl Other for () { | ----------------- LL | fn bar() {} | ^ found type parameter -error[E0053]: method `baz` has an incompatible generic parameter for trait: `Uwu` +error[E0053]: method `baz` has an incompatible generic parameter for trait `Uwu` --> $DIR/mismatched_ty_const_in_trait_impl.rs:21:12 | LL | trait Uwu { | --- LL | fn baz() {} - | ------------ expected const parameter with type `u32` + | ------------ expected const parameter of type `u32` LL | } LL | impl Uwu for () { | --------------- LL | fn baz() {} - | ^^^^^^^^^^^^ found const parameter with type `i32` + | ^^^^^^^^^^^^ found const parameter of type `i32` -error[E0053]: method `bbbb` has an incompatible generic parameter for trait: `Aaaaaa` +error[E0053]: method `bbbb` has an incompatible generic parameter for trait `Aaaaaa` --> $DIR/mismatched_ty_const_in_trait_impl.rs:29:13 | LL | trait Aaaaaa { | ------ LL | fn bbbb() {} - | ------------ expected const parameter with type `u32` + | ------------ expected const parameter of type `u32` LL | } LL | impl Aaaaaa for () { | ------------------ LL | fn bbbb() {} | ^ found type parameter -error[E0053]: method `abcd` has an incompatible generic parameter for trait: `Names` +error[E0053]: method `abcd` has an incompatible generic parameter for trait `Names` --> $DIR/mismatched_ty_const_in_trait_impl.rs:37:13 | LL | trait Names { @@ -61,7 +61,7 @@ LL | } LL | impl Names for () { | ----------------- LL | fn abcd() {} - | ^^^^^^^^^^^^ found const parameter with type `u32` + | ^^^^^^^^^^^^ found const parameter of type `u32` error: aborting due to 5 previous errors diff --git a/src/test/ui/const-generics/issues/issue-86820.rs b/src/test/ui/const-generics/issues/issue-86820.rs index 9bcb8e1aeed..ae4bd943fd4 100644 --- a/src/test/ui/const-generics/issues/issue-86820.rs +++ b/src/test/ui/const-generics/issues/issue-86820.rs @@ -14,7 +14,7 @@ trait Bits { impl Bits for u8 { fn bit(self) -> bool { - //~^ ERROR: method `bit` has an incompatible generic parameter for trait: `Bits` [E0053] + //~^ ERROR: method `bit` has an incompatible generic parameter for trait `Bits` [E0053] let i = 1 << I; let mask = u8::from(i); mask & self == mask diff --git a/src/test/ui/const-generics/issues/issue-86820.stderr b/src/test/ui/const-generics/issues/issue-86820.stderr index 4d54d654c12..3a9cd957f35 100644 --- a/src/test/ui/const-generics/issues/issue-86820.stderr +++ b/src/test/ui/const-generics/issues/issue-86820.stderr @@ -1,15 +1,15 @@ -error[E0053]: method `bit` has an incompatible generic parameter for trait: `Bits` +error[E0053]: method `bit` has an incompatible generic parameter for trait `Bits` --> $DIR/issue-86820.rs:16:12 | LL | trait Bits { | ---- LL | fn bit(self) -> bool; - | ----------- expected const parameter with type `u8` + | ----------- expected const parameter of type `u8` ... LL | impl Bits for u8 { | ---------------- LL | fn bit(self) -> bool { - | ^^^^^^^^^^^^^^ found const parameter with type `usize` + | ^^^^^^^^^^^^^^ found const parameter of type `usize` error: aborting due to previous error diff --git a/src/test/ui/generic-associated-types/const_params_have_right_type.stderr b/src/test/ui/generic-associated-types/const_params_have_right_type.stderr index 9b8eddaff41..89c993dee5e 100644 --- a/src/test/ui/generic-associated-types/const_params_have_right_type.stderr +++ b/src/test/ui/generic-associated-types/const_params_have_right_type.stderr @@ -1,15 +1,15 @@ -error[E0053]: type `Foo` has an incompatible generic parameter for trait: `Trait` +error[E0053]: type `Foo` has an incompatible generic parameter for trait `Trait` --> $DIR/const_params_have_right_type.rs:8:14 | LL | trait Trait { | ----- LL | type Foo; - | ----------- expected const parameter with type `u8` + | ----------- expected const parameter of type `u8` ... LL | impl Trait for () { | ----------------- LL | type Foo = u32; - | ^^^^^^^^^^^^ found const parameter with type `u64` + | ^^^^^^^^^^^^ found const parameter of type `u64` error: aborting due to previous error -- cgit 1.4.1-3-g733a5 From 3ddac0f675cd036b82c0050b87e5ec03de5fe47a Mon Sep 17 00:00:00 2001 From: Caio Date: Sun, 8 May 2022 17:31:05 -0300 Subject: Move some tests to more reasonable places --- src/test/ui/borrowck/issue-28934.rs | 25 ++++++++++++++++++ src/test/ui/closures/issue-6801.rs | 21 +++++++++++++++ src/test/ui/closures/issue-6801.stderr | 16 ++++++++++++ src/test/ui/continue-after-missing-main.nll.stderr | 9 ------- src/test/ui/continue-after-missing-main.rs | 30 ---------------------- src/test/ui/continue-after-missing-main.stderr | 19 -------------- src/test/ui/issues/issue-14940.rs | 19 -------------- src/test/ui/issues/issue-28934.rs | 25 ------------------ src/test/ui/issues/issue-38715.rs | 7 ----- src/test/ui/issues/issue-38715.stderr | 14 ---------- src/test/ui/issues/issue-48803.rs | 13 ---------- src/test/ui/issues/issue-48803.stderr | 15 ----------- src/test/ui/issues/issue-52533-1.nll.stderr | 11 -------- src/test/ui/issues/issue-52533-1.rs | 11 -------- src/test/ui/issues/issue-52533-1.stderr | 22 ---------------- src/test/ui/issues/issue-6801.rs | 21 --------------- src/test/ui/issues/issue-6801.stderr | 16 ------------ src/test/ui/macros/issue-38715.rs | 7 +++++ src/test/ui/macros/issue-38715.stderr | 14 ++++++++++ .../ui/nll/continue-after-missing-main.nll.stderr | 9 +++++++ src/test/ui/nll/continue-after-missing-main.rs | 30 ++++++++++++++++++++++ src/test/ui/nll/continue-after-missing-main.stderr | 19 ++++++++++++++ src/test/ui/nll/issue-48803.rs | 13 ++++++++++ src/test/ui/nll/issue-48803.stderr | 15 +++++++++++ src/test/ui/nll/issue-52533-1.nll.stderr | 11 ++++++++ src/test/ui/nll/issue-52533-1.rs | 11 ++++++++ src/test/ui/nll/issue-52533-1.stderr | 22 ++++++++++++++++ src/test/ui/process/issue-14940.rs | 19 ++++++++++++++ src/tools/tidy/src/ui_tests.rs | 4 +-- 29 files changed, 234 insertions(+), 234 deletions(-) create mode 100644 src/test/ui/borrowck/issue-28934.rs create mode 100644 src/test/ui/closures/issue-6801.rs create mode 100644 src/test/ui/closures/issue-6801.stderr delete mode 100644 src/test/ui/continue-after-missing-main.nll.stderr delete mode 100644 src/test/ui/continue-after-missing-main.rs delete mode 100644 src/test/ui/continue-after-missing-main.stderr delete mode 100644 src/test/ui/issues/issue-14940.rs delete mode 100644 src/test/ui/issues/issue-28934.rs delete mode 100644 src/test/ui/issues/issue-38715.rs delete mode 100644 src/test/ui/issues/issue-38715.stderr delete mode 100644 src/test/ui/issues/issue-48803.rs delete mode 100644 src/test/ui/issues/issue-48803.stderr delete mode 100644 src/test/ui/issues/issue-52533-1.nll.stderr delete mode 100644 src/test/ui/issues/issue-52533-1.rs delete mode 100644 src/test/ui/issues/issue-52533-1.stderr delete mode 100644 src/test/ui/issues/issue-6801.rs delete mode 100644 src/test/ui/issues/issue-6801.stderr create mode 100644 src/test/ui/macros/issue-38715.rs create mode 100644 src/test/ui/macros/issue-38715.stderr create mode 100644 src/test/ui/nll/continue-after-missing-main.nll.stderr create mode 100644 src/test/ui/nll/continue-after-missing-main.rs create mode 100644 src/test/ui/nll/continue-after-missing-main.stderr create mode 100644 src/test/ui/nll/issue-48803.rs create mode 100644 src/test/ui/nll/issue-48803.stderr create mode 100644 src/test/ui/nll/issue-52533-1.nll.stderr create mode 100644 src/test/ui/nll/issue-52533-1.rs create mode 100644 src/test/ui/nll/issue-52533-1.stderr create mode 100644 src/test/ui/process/issue-14940.rs (limited to 'src') diff --git a/src/test/ui/borrowck/issue-28934.rs b/src/test/ui/borrowck/issue-28934.rs new file mode 100644 index 00000000000..1e48878f632 --- /dev/null +++ b/src/test/ui/borrowck/issue-28934.rs @@ -0,0 +1,25 @@ +// Regression test: issue had to do with "givens" in region inference, +// which were not being considered during the contraction phase. + +// run-fail +// error-pattern:explicit panic +// ignore-emscripten no processes + +struct Parser<'i: 't, 't>(&'i u8, &'t u8); + +impl<'i, 't> Parser<'i, 't> { + fn parse_nested_block(&mut self, parse: F) -> Result + where for<'tt> F: FnOnce(&mut Parser<'i, 'tt>) -> T + { + panic!() + } + + fn expect_exhausted(&mut self) -> Result<(), ()> { + Ok(()) + } +} + +fn main() { + let x = 0u8; + Parser(&x, &x).parse_nested_block(|input| input.expect_exhausted()).unwrap(); +} diff --git a/src/test/ui/closures/issue-6801.rs b/src/test/ui/closures/issue-6801.rs new file mode 100644 index 00000000000..694d86feb5a --- /dev/null +++ b/src/test/ui/closures/issue-6801.rs @@ -0,0 +1,21 @@ +// Creating a stack closure which references a box and then +// transferring ownership of the box before invoking the stack +// closure results in a crash. + +#![feature(box_syntax)] + +fn twice(x: Box) -> usize { + *x * 2 +} + +fn invoke(f: F) where F: FnOnce() -> usize { + f(); +} + +fn main() { + let x : Box = box 9; + let sq = || { *x * *x }; + + twice(x); //~ ERROR: cannot move out of + invoke(sq); +} diff --git a/src/test/ui/closures/issue-6801.stderr b/src/test/ui/closures/issue-6801.stderr new file mode 100644 index 00000000000..48c6acd1f49 --- /dev/null +++ b/src/test/ui/closures/issue-6801.stderr @@ -0,0 +1,16 @@ +error[E0505]: cannot move out of `x` because it is borrowed + --> $DIR/issue-6801.rs:19:13 + | +LL | let sq = || { *x * *x }; + | -- -- borrow occurs due to use in closure + | | + | borrow of `x` occurs here +LL | +LL | twice(x); + | ^ move out of `x` occurs here +LL | invoke(sq); + | -- borrow later used here + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0505`. diff --git a/src/test/ui/continue-after-missing-main.nll.stderr b/src/test/ui/continue-after-missing-main.nll.stderr deleted file mode 100644 index ebebabe349b..00000000000 --- a/src/test/ui/continue-after-missing-main.nll.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0601]: `main` function not found in crate `continue_after_missing_main` - --> $DIR/continue-after-missing-main.rs:30:2 - | -LL | } - | ^ consider adding a `main` function to `$DIR/continue-after-missing-main.rs` - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0601`. diff --git a/src/test/ui/continue-after-missing-main.rs b/src/test/ui/continue-after-missing-main.rs deleted file mode 100644 index 1019cacce64..00000000000 --- a/src/test/ui/continue-after-missing-main.rs +++ /dev/null @@ -1,30 +0,0 @@ -#![allow(dead_code)] - -struct Tableau<'a, MP> { - provider: &'a MP, -} - -impl<'adapted_matrix_provider, 'original_data, MP> - Tableau<'adapted_matrix_provider, AdaptedMatrixProvider<'original_data, MP>> -{ - fn provider(&self) -> &'adapted_matrix_provider AdaptedMatrixProvider { - self.provider - } -} - -struct AdaptedMatrixProvider<'a, T> { - original_problem: &'a T, -} - -impl<'a, T> AdaptedMatrixProvider<'a, T> { - fn clone_with_extra_bound(&self) -> Self { - AdaptedMatrixProvider { original_problem: self.original_problem } - } -} - -fn create_and_solve_subproblems<'data_provider, 'original_data, MP>( - tableau: Tableau<'data_provider, AdaptedMatrixProvider<'original_data, MP>>, -) { - let _: AdaptedMatrixProvider<'original_data, MP> = tableau.provider().clone_with_extra_bound(); - //~^ ERROR lifetime mismatch -} //~ ERROR `main` function not found in crate diff --git a/src/test/ui/continue-after-missing-main.stderr b/src/test/ui/continue-after-missing-main.stderr deleted file mode 100644 index 29e7dc1e56c..00000000000 --- a/src/test/ui/continue-after-missing-main.stderr +++ /dev/null @@ -1,19 +0,0 @@ -error[E0601]: `main` function not found in crate `continue_after_missing_main` - --> $DIR/continue-after-missing-main.rs:30:2 - | -LL | } - | ^ consider adding a `main` function to `$DIR/continue-after-missing-main.rs` - -error[E0623]: lifetime mismatch - --> $DIR/continue-after-missing-main.rs:28:56 - | -LL | tableau: Tableau<'data_provider, AdaptedMatrixProvider<'original_data, MP>>, - | ------------------------------------------------------------------ these two types are declared with different lifetimes... -LL | ) { -LL | let _: AdaptedMatrixProvider<'original_data, MP> = tableau.provider().clone_with_extra_bound(); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...but data from `tableau` flows into `tableau` here - -error: aborting due to 2 previous errors - -Some errors have detailed explanations: E0601, E0623. -For more information about an error, try `rustc --explain E0601`. diff --git a/src/test/ui/issues/issue-14940.rs b/src/test/ui/issues/issue-14940.rs deleted file mode 100644 index 98a4af0c467..00000000000 --- a/src/test/ui/issues/issue-14940.rs +++ /dev/null @@ -1,19 +0,0 @@ -// run-pass -// ignore-emscripten no processes -// ignore-sgx no processes - -use std::env; -use std::process::Command; -use std::io::{self, Write}; - -fn main() { - let mut args = env::args(); - if args.len() > 1 { - let mut out = io::stdout(); - out.write(&['a' as u8; 128 * 1024]).unwrap(); - } else { - let out = Command::new(&args.next().unwrap()).arg("child").output(); - let out = out.unwrap(); - assert!(out.status.success()); - } -} diff --git a/src/test/ui/issues/issue-28934.rs b/src/test/ui/issues/issue-28934.rs deleted file mode 100644 index 1e48878f632..00000000000 --- a/src/test/ui/issues/issue-28934.rs +++ /dev/null @@ -1,25 +0,0 @@ -// Regression test: issue had to do with "givens" in region inference, -// which were not being considered during the contraction phase. - -// run-fail -// error-pattern:explicit panic -// ignore-emscripten no processes - -struct Parser<'i: 't, 't>(&'i u8, &'t u8); - -impl<'i, 't> Parser<'i, 't> { - fn parse_nested_block(&mut self, parse: F) -> Result - where for<'tt> F: FnOnce(&mut Parser<'i, 'tt>) -> T - { - panic!() - } - - fn expect_exhausted(&mut self) -> Result<(), ()> { - Ok(()) - } -} - -fn main() { - let x = 0u8; - Parser(&x, &x).parse_nested_block(|input| input.expect_exhausted()).unwrap(); -} diff --git a/src/test/ui/issues/issue-38715.rs b/src/test/ui/issues/issue-38715.rs deleted file mode 100644 index 9a9a501cae1..00000000000 --- a/src/test/ui/issues/issue-38715.rs +++ /dev/null @@ -1,7 +0,0 @@ -#[macro_export] -macro_rules! foo { ($i:ident) => {} } - -#[macro_export] -macro_rules! foo { () => {} } //~ ERROR the name `foo` is defined multiple times - -fn main() {} diff --git a/src/test/ui/issues/issue-38715.stderr b/src/test/ui/issues/issue-38715.stderr deleted file mode 100644 index c87d9f7360b..00000000000 --- a/src/test/ui/issues/issue-38715.stderr +++ /dev/null @@ -1,14 +0,0 @@ -error[E0428]: the name `foo` is defined multiple times - --> $DIR/issue-38715.rs:5:1 - | -LL | macro_rules! foo { ($i:ident) => {} } - | ---------------- previous definition of the macro `foo` here -... -LL | macro_rules! foo { () => {} } - | ^^^^^^^^^^^^^^^^ `foo` redefined here - | - = note: `foo` must be defined only once in the macro namespace of this module - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0428`. diff --git a/src/test/ui/issues/issue-48803.rs b/src/test/ui/issues/issue-48803.rs deleted file mode 100644 index f7fd04179f2..00000000000 --- a/src/test/ui/issues/issue-48803.rs +++ /dev/null @@ -1,13 +0,0 @@ -fn flatten<'a, 'b, T>(x: &'a &'b T) -> &'a T { - x -} - -fn main() { - let mut x = "original"; - let y = &x; - let z = &y; - let w = flatten(z); - x = "modified"; - //~^ ERROR cannot assign to `x` because it is borrowed [E0506] - println!("{}", w); // prints "modified" -} diff --git a/src/test/ui/issues/issue-48803.stderr b/src/test/ui/issues/issue-48803.stderr deleted file mode 100644 index 2f94039c0c3..00000000000 --- a/src/test/ui/issues/issue-48803.stderr +++ /dev/null @@ -1,15 +0,0 @@ -error[E0506]: cannot assign to `x` because it is borrowed - --> $DIR/issue-48803.rs:10:5 - | -LL | let y = &x; - | -- borrow of `x` occurs here -... -LL | x = "modified"; - | ^^^^^^^^^^^^^^ assignment to borrowed `x` occurs here -LL | -LL | println!("{}", w); // prints "modified" - | - borrow later used here - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0506`. diff --git a/src/test/ui/issues/issue-52533-1.nll.stderr b/src/test/ui/issues/issue-52533-1.nll.stderr deleted file mode 100644 index 20f19b25967..00000000000 --- a/src/test/ui/issues/issue-52533-1.nll.stderr +++ /dev/null @@ -1,11 +0,0 @@ -error: lifetime may not live long enough - --> $DIR/issue-52533-1.rs:9:18 - | -LL | gimme(|x, y| y) - | - - ^ closure was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` - | | | - | | has type `&Foo<'_, '1, u32>` - | has type `&Foo<'_, '2, u32>` - -error: aborting due to previous error - diff --git a/src/test/ui/issues/issue-52533-1.rs b/src/test/ui/issues/issue-52533-1.rs deleted file mode 100644 index c80f43237fc..00000000000 --- a/src/test/ui/issues/issue-52533-1.rs +++ /dev/null @@ -1,11 +0,0 @@ -#![allow(warnings)] - -struct Foo<'a, 'b, T: 'a + 'b> { x: &'a T, y: &'b T } - -fn gimme(_: impl for<'a, 'b, 'c> FnOnce(&'a Foo<'a, 'b, u32>, - &'a Foo<'a, 'c, u32>) -> &'a Foo<'a, 'b, u32>) { } - -fn main() { - gimme(|x, y| y) - //~^ ERROR mismatched types [E0308] -} diff --git a/src/test/ui/issues/issue-52533-1.stderr b/src/test/ui/issues/issue-52533-1.stderr deleted file mode 100644 index 475c7d0b48b..00000000000 --- a/src/test/ui/issues/issue-52533-1.stderr +++ /dev/null @@ -1,22 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/issue-52533-1.rs:9:18 - | -LL | gimme(|x, y| y) - | ^ lifetime mismatch - | - = note: expected reference `&Foo<'_, '_, u32>` - found reference `&Foo<'_, '_, u32>` -note: the anonymous lifetime #3 defined here... - --> $DIR/issue-52533-1.rs:9:11 - | -LL | gimme(|x, y| y) - | ^^^^^^^^ -note: ...does not necessarily outlive the anonymous lifetime #2 defined here - --> $DIR/issue-52533-1.rs:9:11 - | -LL | gimme(|x, y| y) - | ^^^^^^^^ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/issues/issue-6801.rs b/src/test/ui/issues/issue-6801.rs deleted file mode 100644 index 694d86feb5a..00000000000 --- a/src/test/ui/issues/issue-6801.rs +++ /dev/null @@ -1,21 +0,0 @@ -// Creating a stack closure which references a box and then -// transferring ownership of the box before invoking the stack -// closure results in a crash. - -#![feature(box_syntax)] - -fn twice(x: Box) -> usize { - *x * 2 -} - -fn invoke(f: F) where F: FnOnce() -> usize { - f(); -} - -fn main() { - let x : Box = box 9; - let sq = || { *x * *x }; - - twice(x); //~ ERROR: cannot move out of - invoke(sq); -} diff --git a/src/test/ui/issues/issue-6801.stderr b/src/test/ui/issues/issue-6801.stderr deleted file mode 100644 index 48c6acd1f49..00000000000 --- a/src/test/ui/issues/issue-6801.stderr +++ /dev/null @@ -1,16 +0,0 @@ -error[E0505]: cannot move out of `x` because it is borrowed - --> $DIR/issue-6801.rs:19:13 - | -LL | let sq = || { *x * *x }; - | -- -- borrow occurs due to use in closure - | | - | borrow of `x` occurs here -LL | -LL | twice(x); - | ^ move out of `x` occurs here -LL | invoke(sq); - | -- borrow later used here - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0505`. diff --git a/src/test/ui/macros/issue-38715.rs b/src/test/ui/macros/issue-38715.rs new file mode 100644 index 00000000000..9a9a501cae1 --- /dev/null +++ b/src/test/ui/macros/issue-38715.rs @@ -0,0 +1,7 @@ +#[macro_export] +macro_rules! foo { ($i:ident) => {} } + +#[macro_export] +macro_rules! foo { () => {} } //~ ERROR the name `foo` is defined multiple times + +fn main() {} diff --git a/src/test/ui/macros/issue-38715.stderr b/src/test/ui/macros/issue-38715.stderr new file mode 100644 index 00000000000..c87d9f7360b --- /dev/null +++ b/src/test/ui/macros/issue-38715.stderr @@ -0,0 +1,14 @@ +error[E0428]: the name `foo` is defined multiple times + --> $DIR/issue-38715.rs:5:1 + | +LL | macro_rules! foo { ($i:ident) => {} } + | ---------------- previous definition of the macro `foo` here +... +LL | macro_rules! foo { () => {} } + | ^^^^^^^^^^^^^^^^ `foo` redefined here + | + = note: `foo` must be defined only once in the macro namespace of this module + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0428`. diff --git a/src/test/ui/nll/continue-after-missing-main.nll.stderr b/src/test/ui/nll/continue-after-missing-main.nll.stderr new file mode 100644 index 00000000000..ebebabe349b --- /dev/null +++ b/src/test/ui/nll/continue-after-missing-main.nll.stderr @@ -0,0 +1,9 @@ +error[E0601]: `main` function not found in crate `continue_after_missing_main` + --> $DIR/continue-after-missing-main.rs:30:2 + | +LL | } + | ^ consider adding a `main` function to `$DIR/continue-after-missing-main.rs` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0601`. diff --git a/src/test/ui/nll/continue-after-missing-main.rs b/src/test/ui/nll/continue-after-missing-main.rs new file mode 100644 index 00000000000..1019cacce64 --- /dev/null +++ b/src/test/ui/nll/continue-after-missing-main.rs @@ -0,0 +1,30 @@ +#![allow(dead_code)] + +struct Tableau<'a, MP> { + provider: &'a MP, +} + +impl<'adapted_matrix_provider, 'original_data, MP> + Tableau<'adapted_matrix_provider, AdaptedMatrixProvider<'original_data, MP>> +{ + fn provider(&self) -> &'adapted_matrix_provider AdaptedMatrixProvider { + self.provider + } +} + +struct AdaptedMatrixProvider<'a, T> { + original_problem: &'a T, +} + +impl<'a, T> AdaptedMatrixProvider<'a, T> { + fn clone_with_extra_bound(&self) -> Self { + AdaptedMatrixProvider { original_problem: self.original_problem } + } +} + +fn create_and_solve_subproblems<'data_provider, 'original_data, MP>( + tableau: Tableau<'data_provider, AdaptedMatrixProvider<'original_data, MP>>, +) { + let _: AdaptedMatrixProvider<'original_data, MP> = tableau.provider().clone_with_extra_bound(); + //~^ ERROR lifetime mismatch +} //~ ERROR `main` function not found in crate diff --git a/src/test/ui/nll/continue-after-missing-main.stderr b/src/test/ui/nll/continue-after-missing-main.stderr new file mode 100644 index 00000000000..29e7dc1e56c --- /dev/null +++ b/src/test/ui/nll/continue-after-missing-main.stderr @@ -0,0 +1,19 @@ +error[E0601]: `main` function not found in crate `continue_after_missing_main` + --> $DIR/continue-after-missing-main.rs:30:2 + | +LL | } + | ^ consider adding a `main` function to `$DIR/continue-after-missing-main.rs` + +error[E0623]: lifetime mismatch + --> $DIR/continue-after-missing-main.rs:28:56 + | +LL | tableau: Tableau<'data_provider, AdaptedMatrixProvider<'original_data, MP>>, + | ------------------------------------------------------------------ these two types are declared with different lifetimes... +LL | ) { +LL | let _: AdaptedMatrixProvider<'original_data, MP> = tableau.provider().clone_with_extra_bound(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...but data from `tableau` flows into `tableau` here + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0601, E0623. +For more information about an error, try `rustc --explain E0601`. diff --git a/src/test/ui/nll/issue-48803.rs b/src/test/ui/nll/issue-48803.rs new file mode 100644 index 00000000000..f7fd04179f2 --- /dev/null +++ b/src/test/ui/nll/issue-48803.rs @@ -0,0 +1,13 @@ +fn flatten<'a, 'b, T>(x: &'a &'b T) -> &'a T { + x +} + +fn main() { + let mut x = "original"; + let y = &x; + let z = &y; + let w = flatten(z); + x = "modified"; + //~^ ERROR cannot assign to `x` because it is borrowed [E0506] + println!("{}", w); // prints "modified" +} diff --git a/src/test/ui/nll/issue-48803.stderr b/src/test/ui/nll/issue-48803.stderr new file mode 100644 index 00000000000..2f94039c0c3 --- /dev/null +++ b/src/test/ui/nll/issue-48803.stderr @@ -0,0 +1,15 @@ +error[E0506]: cannot assign to `x` because it is borrowed + --> $DIR/issue-48803.rs:10:5 + | +LL | let y = &x; + | -- borrow of `x` occurs here +... +LL | x = "modified"; + | ^^^^^^^^^^^^^^ assignment to borrowed `x` occurs here +LL | +LL | println!("{}", w); // prints "modified" + | - borrow later used here + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0506`. diff --git a/src/test/ui/nll/issue-52533-1.nll.stderr b/src/test/ui/nll/issue-52533-1.nll.stderr new file mode 100644 index 00000000000..20f19b25967 --- /dev/null +++ b/src/test/ui/nll/issue-52533-1.nll.stderr @@ -0,0 +1,11 @@ +error: lifetime may not live long enough + --> $DIR/issue-52533-1.rs:9:18 + | +LL | gimme(|x, y| y) + | - - ^ closure was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` + | | | + | | has type `&Foo<'_, '1, u32>` + | has type `&Foo<'_, '2, u32>` + +error: aborting due to previous error + diff --git a/src/test/ui/nll/issue-52533-1.rs b/src/test/ui/nll/issue-52533-1.rs new file mode 100644 index 00000000000..c80f43237fc --- /dev/null +++ b/src/test/ui/nll/issue-52533-1.rs @@ -0,0 +1,11 @@ +#![allow(warnings)] + +struct Foo<'a, 'b, T: 'a + 'b> { x: &'a T, y: &'b T } + +fn gimme(_: impl for<'a, 'b, 'c> FnOnce(&'a Foo<'a, 'b, u32>, + &'a Foo<'a, 'c, u32>) -> &'a Foo<'a, 'b, u32>) { } + +fn main() { + gimme(|x, y| y) + //~^ ERROR mismatched types [E0308] +} diff --git a/src/test/ui/nll/issue-52533-1.stderr b/src/test/ui/nll/issue-52533-1.stderr new file mode 100644 index 00000000000..475c7d0b48b --- /dev/null +++ b/src/test/ui/nll/issue-52533-1.stderr @@ -0,0 +1,22 @@ +error[E0308]: mismatched types + --> $DIR/issue-52533-1.rs:9:18 + | +LL | gimme(|x, y| y) + | ^ lifetime mismatch + | + = note: expected reference `&Foo<'_, '_, u32>` + found reference `&Foo<'_, '_, u32>` +note: the anonymous lifetime #3 defined here... + --> $DIR/issue-52533-1.rs:9:11 + | +LL | gimme(|x, y| y) + | ^^^^^^^^ +note: ...does not necessarily outlive the anonymous lifetime #2 defined here + --> $DIR/issue-52533-1.rs:9:11 + | +LL | gimme(|x, y| y) + | ^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/process/issue-14940.rs b/src/test/ui/process/issue-14940.rs new file mode 100644 index 00000000000..98a4af0c467 --- /dev/null +++ b/src/test/ui/process/issue-14940.rs @@ -0,0 +1,19 @@ +// run-pass +// ignore-emscripten no processes +// ignore-sgx no processes + +use std::env; +use std::process::Command; +use std::io::{self, Write}; + +fn main() { + let mut args = env::args(); + if args.len() > 1 { + let mut out = io::stdout(); + out.write(&['a' as u8; 128 * 1024]).unwrap(); + } else { + let out = Command::new(&args.next().unwrap()).arg("child").output(); + let out = out.unwrap(); + assert!(out.status.success()); + } +} diff --git a/src/tools/tidy/src/ui_tests.rs b/src/tools/tidy/src/ui_tests.rs index 6b715f727b2..5712e84adbc 100644 --- a/src/tools/tidy/src/ui_tests.rs +++ b/src/tools/tidy/src/ui_tests.rs @@ -7,8 +7,8 @@ use std::path::Path; const ENTRY_LIMIT: usize = 1000; // FIXME: The following limits should be reduced eventually. -const ROOT_ENTRY_LIMIT: usize = 977; -const ISSUES_ENTRY_LIMIT: usize = 2278; +const ROOT_ENTRY_LIMIT: usize = 974; +const ISSUES_ENTRY_LIMIT: usize = 2248; fn check_entries(path: &Path, bad: &mut bool) { let dirs = walkdir::WalkDir::new(&path.join("test/ui")) -- cgit 1.4.1-3-g733a5 From 360d6e4b7ddcfbb203dced9883532bc4f39137e0 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 9 May 2022 11:46:24 -0700 Subject: rustdoc: search result ranking fix --- src/librustdoc/html/static/js/search.js | 2 +- src/test/rustdoc-js/path-ordering.js | 14 ++++++++++++++ src/test/rustdoc-js/path-ordering.rs | 9 +++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 src/test/rustdoc-js/path-ordering.js create mode 100644 src/test/rustdoc-js/path-ordering.rs (limited to 'src') diff --git a/src/librustdoc/html/static/js/search.js b/src/librustdoc/html/static/js/search.js index 1e3894c1fcd..5a2ca145ac7 100644 --- a/src/librustdoc/html/static/js/search.js +++ b/src/librustdoc/html/static/js/search.js @@ -1323,7 +1323,6 @@ window.initSearch = rawSearchIndex => { } } lev = levenshtein(searchWord, elem.pathLast); - lev += lev_add; if (lev > 0 && elem.pathLast.length > 2 && searchWord.indexOf(elem.pathLast) > -1) { if (elem.pathLast.length < 6) { @@ -1332,6 +1331,7 @@ window.initSearch = rawSearchIndex => { lev = 0; } } + lev += lev_add; if (lev > MAX_LEV_DISTANCE) { return; } else if (index !== -1 && elem.fullPath.length < 2) { diff --git a/src/test/rustdoc-js/path-ordering.js b/src/test/rustdoc-js/path-ordering.js new file mode 100644 index 00000000000..4aee569b0f4 --- /dev/null +++ b/src/test/rustdoc-js/path-ordering.js @@ -0,0 +1,14 @@ +// exact-check + +const QUERY = 'b::ccccccc'; + +const EXPECTED = { + 'others': [ + // `ccccccc` is an exact match for all three of these. + // However `b` is a closer match for `bb` than for any + // of the others, so it ought to go first. + { 'path': 'path_ordering::bb', 'name': 'Ccccccc' }, + { 'path': 'path_ordering::aa', 'name': 'Ccccccc' }, + { 'path': 'path_ordering::dd', 'name': 'Ccccccc' }, + ], +}; diff --git a/src/test/rustdoc-js/path-ordering.rs b/src/test/rustdoc-js/path-ordering.rs new file mode 100644 index 00000000000..7843cf7f9dc --- /dev/null +++ b/src/test/rustdoc-js/path-ordering.rs @@ -0,0 +1,9 @@ +pub mod dd { + pub struct Ccccccc; +} +pub mod aa { + pub struct Ccccccc; +} +pub mod bb { + pub struct Ccccccc; +} -- cgit 1.4.1-3-g733a5 From a9a90d450d11a06dff8bc49a89352e733e904fcf Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Mon, 9 May 2022 12:17:47 -0700 Subject: Add test case for `hashset::insert` ranking --- src/test/rustdoc-js-std/path-ordering.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/test/rustdoc-js-std/path-ordering.js (limited to 'src') diff --git a/src/test/rustdoc-js-std/path-ordering.js b/src/test/rustdoc-js-std/path-ordering.js new file mode 100644 index 00000000000..7dcdd402312 --- /dev/null +++ b/src/test/rustdoc-js-std/path-ordering.js @@ -0,0 +1,12 @@ +const QUERY = 'hashset::insert'; + +const EXPECTED = { + 'others': [ + // ensure hashset::insert comes first + { 'path': 'std::collections::hash_set::HashSet', 'name': 'insert' }, + { 'path': 'std::collections::hash_set::HashSet', 'name': 'get_or_insert' }, + { 'path': 'std::collections::hash_set::HashSet', 'name': 'get_or_insert_with' }, + { 'path': 'std::collections::hash_set::HashSet', 'name': 'get_or_insert_owned' }, + { 'path': 'std::collections::hash_map::HashMap', 'name': 'insert' }, + ], +}; -- cgit 1.4.1-3-g733a5