From 39054339c17f283cdb34183cc615a448baa108a3 Mon Sep 17 00:00:00 2001 From: Ellen Date: Sat, 1 May 2021 18:35:56 +0100 Subject: [PATCH] test: *sneezes* --- compiler/rustc_typeck/src/astconv/generics.rs | 6 ++--- .../rustc_typeck/src/check/fn_ctxt/_impl.rs | 16 +++++++++----- .../ui/const-generics/issues/issue-83466.rs | 17 ++++++++++++++ .../const-generics/issues/issue-83466.stderr | 22 +++++++++++++++++++ 4 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 src/test/ui/const-generics/issues/issue-83466.rs create mode 100644 src/test/ui/const-generics/issues/issue-83466.stderr diff --git a/compiler/rustc_typeck/src/astconv/generics.rs b/compiler/rustc_typeck/src/astconv/generics.rs index 7a297f2c65f13..a4b3652d21450 100644 --- a/compiler/rustc_typeck/src/astconv/generics.rs +++ b/compiler/rustc_typeck/src/astconv/generics.rs @@ -264,9 +264,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // another. This is an error. However, if we already know that // the arguments don't match up with the parameters, we won't issue // an additional error, as the user already knows what's wrong. - if arg_count.correct.is_ok() - && arg_count.explicit_late_bound == ExplicitLateBound::No - { + if arg_count.correct.is_ok() { // We're going to iterate over the parameters to sort them out, and // show that order to the user as a possible order for the parameters let mut param_types_present = defs @@ -446,7 +444,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } if silent { - return false; + return true; } if provided > expected_max { diff --git a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs index 9ace455042103..ded6f901e77c4 100644 --- a/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs +++ b/compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs @@ -1282,6 +1282,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let mut infer_args_for_err = FxHashSet::default(); + let mut explicit_late_bound = ExplicitLateBound::No; for &PathSeg(def_id, index) in &path_segs { let seg = &segments[index]; let generics = tcx.generics_of(def_id); @@ -1290,17 +1291,20 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // parameter internally, but we don't allow users to specify the // parameter's value explicitly, so we have to do some error- // checking here. - if let GenericArgCountResult { - correct: Err(GenericArgCountMismatch { reported: Some(_), .. }), - .. - } = >::check_generic_arg_count_for_call( + let arg_count = >::check_generic_arg_count_for_call( tcx, span, def_id, &generics, seg, IsMethodCall::No, - ) { + ); + + if let ExplicitLateBound::Yes = arg_count.explicit_late_bound { + explicit_late_bound = ExplicitLateBound::Yes; + } + + if let Err(GenericArgCountMismatch { reported: Some(_), .. }) = arg_count.correct { infer_args_for_err.insert(index); self.set_tainted_by_errors(); // See issue #53251. } @@ -1357,7 +1361,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let ty = tcx.type_of(def_id); let arg_count = GenericArgCountResult { - explicit_late_bound: ExplicitLateBound::No, + explicit_late_bound, correct: if infer_args_for_err.is_empty() { Ok(()) } else { diff --git a/src/test/ui/const-generics/issues/issue-83466.rs b/src/test/ui/const-generics/issues/issue-83466.rs new file mode 100644 index 0000000000000..c488a663fbb00 --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-83466.rs @@ -0,0 +1,17 @@ +// regression test for #83466- tests that generic arg mismatch errors between +// consts and types are not supressed when there are explicit late bound lifetimes + +struct S; +impl S { + fn func<'a, U>(self) -> U { + todo!() + } +} +fn dont_crash<'a, U>() { + S.func::<'a, 10_u32>() + //~^ WARNING cannot specify lifetime arguments explicitly if late bound lifetime parameters are present + //~^^ WARNING this was previously accepted by + //~^^^ ERROR constant provided when a type was expected [E0747] +} + +fn main() {} diff --git a/src/test/ui/const-generics/issues/issue-83466.stderr b/src/test/ui/const-generics/issues/issue-83466.stderr new file mode 100644 index 0000000000000..a60f71ea61420 --- /dev/null +++ b/src/test/ui/const-generics/issues/issue-83466.stderr @@ -0,0 +1,22 @@ +warning: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present + --> $DIR/issue-83466.rs:11:14 + | +LL | fn func<'a, U>(self) -> U { + | -- the late bound lifetime parameter is introduced here +... +LL | S.func::<'a, 10_u32>() + | ^^ + | + = note: `#[warn(late_bound_lifetime_arguments)]` on by default + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #42868 + +error[E0747]: constant provided when a type was expected + --> $DIR/issue-83466.rs:11:18 + | +LL | S.func::<'a, 10_u32>() + | ^^^^^^ + +error: aborting due to previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0747`.