From 0fe54d46509abbbe54292d0ff85f8429301be002 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Sat, 3 Sep 2022 07:15:08 +0100 Subject: [PATCH 01/11] Restore old behaviour on broken UNC paths --- library/std/src/sys/windows/path.rs | 9 +------ library/std/src/sys/windows/path/tests.rs | 29 +++++++++++++++-------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/library/std/src/sys/windows/path.rs b/library/std/src/sys/windows/path.rs index a0f822070992f..beeca1917a9af 100644 --- a/library/std/src/sys/windows/path.rs +++ b/library/std/src/sys/windows/path.rs @@ -198,14 +198,7 @@ fn parse_next_component(path: &OsStr, verbatim: bool) -> (&OsStr, &OsStr) { match path.bytes().iter().position(|&x| separator(x)) { Some(separator_start) => { - let mut separator_end = separator_start + 1; - - // a series of multiple separator characters is treated as a single separator, - // except in verbatim paths - while !verbatim && separator_end < path.len() && separator(path.bytes()[separator_end]) - { - separator_end += 1; - } + let separator_end = separator_start + 1; let component = &path.bytes()[..separator_start]; diff --git a/library/std/src/sys/windows/path/tests.rs b/library/std/src/sys/windows/path/tests.rs index a71175069052f..623c6236166da 100644 --- a/library/std/src/sys/windows/path/tests.rs +++ b/library/std/src/sys/windows/path/tests.rs @@ -31,16 +31,6 @@ fn test_parse_next_component() { parse_next_component(OsStr::new(r"servershare"), false), (OsStr::new(r"servershare"), OsStr::new("")) ); - - assert_eq!( - parse_next_component(OsStr::new(r"server/\//\/\\\\/////\/share"), false), - (OsStr::new(r"server"), OsStr::new(r"share")) - ); - - assert_eq!( - parse_next_component(OsStr::new(r"server\\\\\\\\\\\\\\share"), true), - (OsStr::new(r"server"), OsStr::new(r"\\\\\\\\\\\\\share")) - ); } #[test] @@ -126,3 +116,22 @@ fn test_windows_prefix_components() { assert_eq!(drive.as_os_str(), OsStr::new("C:")); assert_eq!(components.as_path(), Path::new("")); } + +/// See #101358. +/// +/// Note that the exact behaviour here may change in the future. +/// In which case this test will need to adjusted. +#[test] +fn broken_unc_path() { + use crate::path::Component; + + let mut components = Path::new(r"\\foo\\bar\\").components(); + assert_eq!(components.next(), Some(Component::RootDir)); + assert_eq!(components.next(), Some(Component::Normal("foo".as_ref()))); + assert_eq!(components.next(), Some(Component::Normal("bar".as_ref()))); + + let mut components = Path::new("//foo//bar//").components(); + assert_eq!(components.next(), Some(Component::RootDir)); + assert_eq!(components.next(), Some(Component::Normal("foo".as_ref()))); + assert_eq!(components.next(), Some(Component::Normal("bar".as_ref()))); +} From 1e384423a9cfd678f976cf0183c81a770da2a325 Mon Sep 17 00:00:00 2001 From: Takayuki Maeda Date: Wed, 7 Sep 2022 02:37:18 +0900 Subject: [PATCH 02/11] suggest adding array lengths to references to arrays --- compiler/rustc_hir/src/hir.rs | 8 +++ compiler/rustc_typeck/src/check/expr.rs | 47 ++++++------- .../suggest-array-length.fixed | 12 ++++ .../array-slice-vec/suggest-array-length.rs | 12 ++++ .../suggest-array-length.stderr | 70 +++++++++++++++++-- 5 files changed, 120 insertions(+), 29 deletions(-) diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 9535ccfe8b69d..c17702d624a7d 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -2396,6 +2396,14 @@ impl<'hir> Ty<'hir> { _ => None, } } + + pub fn peel_refs(&self) -> &Self { + let mut final_ty = self; + while let TyKind::Rptr(_, MutTy { ty, .. }) = &final_ty.kind { + final_ty = &ty; + } + final_ty + } } /// Not represented directly in the AST; referred to by name through a `ty_path`. diff --git a/compiler/rustc_typeck/src/check/expr.rs b/compiler/rustc_typeck/src/check/expr.rs index e4141647d7d2d..44f845bde6154 100644 --- a/compiler/rustc_typeck/src/check/expr.rs +++ b/compiler/rustc_typeck/src/check/expr.rs @@ -1305,31 +1305,30 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } fn suggest_array_len(&self, expr: &'tcx hir::Expr<'tcx>, array_len: u64) { - if let Some(parent_hir_id) = self.tcx.hir().find_parent_node(expr.hir_id) { - let ty = match self.tcx.hir().find(parent_hir_id) { - Some( - hir::Node::Local(hir::Local { ty: Some(ty), .. }) - | hir::Node::Item(hir::Item { kind: hir::ItemKind::Const(ty, _), .. }), - ) => Some(ty), - _ => None, - }; - if let Some(ty) = ty - && let hir::TyKind::Array(_, length) = ty.kind - && let hir::ArrayLen::Body(hir::AnonConst { hir_id, .. }) = length - && let Some(span) = self.tcx.hir().opt_span(hir_id) - { - match self.tcx.sess.diagnostic().steal_diagnostic(span, StashKey::UnderscoreForArrayLengths) { - Some(mut err) => { - err.span_suggestion( - span, - "consider specifying the array length", - array_len, - Applicability::MaybeIncorrect, - ); - err.emit(); - } - None => () + let parent_node = self.tcx.hir().parent_iter(expr.hir_id).find(|(_, node)| { + !matches!(node, hir::Node::Expr(hir::Expr { kind: hir::ExprKind::AddrOf(..), .. })) + }); + let Some((_, + hir::Node::Local(hir::Local { ty: Some(ty), .. }) + | hir::Node::Item(hir::Item { kind: hir::ItemKind::Const(ty, _), .. })) + ) = parent_node else { + return + }; + if let hir::TyKind::Array(_, length) = ty.peel_refs().kind + && let hir::ArrayLen::Body(hir::AnonConst { hir_id, .. }) = length + && let Some(span) = self.tcx.hir().opt_span(hir_id) + { + match self.tcx.sess.diagnostic().steal_diagnostic(span, StashKey::UnderscoreForArrayLengths) { + Some(mut err) => { + err.span_suggestion( + span, + "consider specifying the array length", + array_len, + Applicability::MaybeIncorrect, + ); + err.emit(); } + None => () } } } diff --git a/src/test/ui/array-slice-vec/suggest-array-length.fixed b/src/test/ui/array-slice-vec/suggest-array-length.fixed index bae3ab74af676..867c18a7d5e6b 100644 --- a/src/test/ui/array-slice-vec/suggest-array-length.fixed +++ b/src/test/ui/array-slice-vec/suggest-array-length.fixed @@ -5,10 +5,22 @@ fn main() { const Foo: [i32; 3] = [1, 2, 3]; //~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment //~| ERROR using `_` for array lengths is unstable + const REF_FOO: &[u8; 1] = &[1]; + //~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment + //~| ERROR using `_` for array lengths is unstable let foo: [i32; 3] = [1, 2, 3]; //~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment //~| ERROR using `_` for array lengths is unstable let bar: [i32; 3] = [0; 3]; //~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment //~| ERROR using `_` for array lengths is unstable + let ref_foo: &[i32; 3] = &[1, 2, 3]; + //~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment + //~| ERROR using `_` for array lengths is unstable + let ref_bar: &[i32; 3] = &[0; 3]; + //~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment + //~| ERROR using `_` for array lengths is unstable + let multiple_ref_foo: &&[i32; 3] = &&[1, 2, 3]; + //~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment + //~| ERROR using `_` for array lengths is unstable } diff --git a/src/test/ui/array-slice-vec/suggest-array-length.rs b/src/test/ui/array-slice-vec/suggest-array-length.rs index b0867f4e39676..f66b3d4a89991 100644 --- a/src/test/ui/array-slice-vec/suggest-array-length.rs +++ b/src/test/ui/array-slice-vec/suggest-array-length.rs @@ -5,10 +5,22 @@ fn main() { const Foo: [i32; _] = [1, 2, 3]; //~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment //~| ERROR using `_` for array lengths is unstable + const REF_FOO: &[u8; _] = &[1]; + //~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment + //~| ERROR using `_` for array lengths is unstable let foo: [i32; _] = [1, 2, 3]; //~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment //~| ERROR using `_` for array lengths is unstable let bar: [i32; _] = [0; 3]; //~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment //~| ERROR using `_` for array lengths is unstable + let ref_foo: &[i32; _] = &[1, 2, 3]; + //~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment + //~| ERROR using `_` for array lengths is unstable + let ref_bar: &[i32; _] = &[0; 3]; + //~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment + //~| ERROR using `_` for array lengths is unstable + let multiple_ref_foo: &&[i32; _] = &&[1, 2, 3]; + //~^ ERROR in expressions, `_` can only be used on the left-hand side of an assignment + //~| ERROR using `_` for array lengths is unstable } diff --git a/src/test/ui/array-slice-vec/suggest-array-length.stderr b/src/test/ui/array-slice-vec/suggest-array-length.stderr index 9000f71602850..16c90a04784d0 100644 --- a/src/test/ui/array-slice-vec/suggest-array-length.stderr +++ b/src/test/ui/array-slice-vec/suggest-array-length.stderr @@ -1,21 +1,45 @@ error: in expressions, `_` can only be used on the left-hand side of an assignment - --> $DIR/suggest-array-length.rs:8:20 + --> $DIR/suggest-array-length.rs:11:20 | LL | let foo: [i32; _] = [1, 2, 3]; | ^ `_` not allowed here error: in expressions, `_` can only be used on the left-hand side of an assignment - --> $DIR/suggest-array-length.rs:11:20 + --> $DIR/suggest-array-length.rs:14:20 | LL | let bar: [i32; _] = [0; 3]; | ^ `_` not allowed here +error: in expressions, `_` can only be used on the left-hand side of an assignment + --> $DIR/suggest-array-length.rs:17:25 + | +LL | let ref_foo: &[i32; _] = &[1, 2, 3]; + | ^ `_` not allowed here + +error: in expressions, `_` can only be used on the left-hand side of an assignment + --> $DIR/suggest-array-length.rs:20:25 + | +LL | let ref_bar: &[i32; _] = &[0; 3]; + | ^ `_` not allowed here + +error: in expressions, `_` can only be used on the left-hand side of an assignment + --> $DIR/suggest-array-length.rs:23:35 + | +LL | let multiple_ref_foo: &&[i32; _] = &&[1, 2, 3]; + | ^ `_` not allowed here + error: in expressions, `_` can only be used on the left-hand side of an assignment --> $DIR/suggest-array-length.rs:5:22 | LL | const Foo: [i32; _] = [1, 2, 3]; | ^ `_` not allowed here +error: in expressions, `_` can only be used on the left-hand side of an assignment + --> $DIR/suggest-array-length.rs:8:26 + | +LL | const REF_FOO: &[u8; _] = &[1]; + | ^ `_` not allowed here + error[E0658]: using `_` for array lengths is unstable --> $DIR/suggest-array-length.rs:5:22 | @@ -26,7 +50,16 @@ LL | const Foo: [i32; _] = [1, 2, 3]; = help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable error[E0658]: using `_` for array lengths is unstable - --> $DIR/suggest-array-length.rs:8:20 + --> $DIR/suggest-array-length.rs:8:26 + | +LL | const REF_FOO: &[u8; _] = &[1]; + | ^ help: consider specifying the array length: `1` + | + = note: see issue #85077 for more information + = help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable + +error[E0658]: using `_` for array lengths is unstable + --> $DIR/suggest-array-length.rs:11:20 | LL | let foo: [i32; _] = [1, 2, 3]; | ^ help: consider specifying the array length: `3` @@ -35,7 +68,7 @@ LL | let foo: [i32; _] = [1, 2, 3]; = help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable error[E0658]: using `_` for array lengths is unstable - --> $DIR/suggest-array-length.rs:11:20 + --> $DIR/suggest-array-length.rs:14:20 | LL | let bar: [i32; _] = [0; 3]; | ^ help: consider specifying the array length: `3` @@ -43,6 +76,33 @@ LL | let bar: [i32; _] = [0; 3]; = note: see issue #85077 for more information = help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable -error: aborting due to 6 previous errors +error[E0658]: using `_` for array lengths is unstable + --> $DIR/suggest-array-length.rs:17:25 + | +LL | let ref_foo: &[i32; _] = &[1, 2, 3]; + | ^ help: consider specifying the array length: `3` + | + = note: see issue #85077 for more information + = help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable + +error[E0658]: using `_` for array lengths is unstable + --> $DIR/suggest-array-length.rs:20:25 + | +LL | let ref_bar: &[i32; _] = &[0; 3]; + | ^ help: consider specifying the array length: `3` + | + = note: see issue #85077 for more information + = help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable + +error[E0658]: using `_` for array lengths is unstable + --> $DIR/suggest-array-length.rs:23:35 + | +LL | let multiple_ref_foo: &&[i32; _] = &&[1, 2, 3]; + | ^ help: consider specifying the array length: `3` + | + = note: see issue #85077 for more information + = help: add `#![feature(generic_arg_infer)]` to the crate attributes to enable + +error: aborting due to 14 previous errors For more information about this error, try `rustc --explain E0658`. From 1dac6da408dac324e51e2e615483c72e358d9725 Mon Sep 17 00:00:00 2001 From: Maurits van Riezen <12109031+mousetail@users.noreply.github.com> Date: Wed, 7 Sep 2022 14:01:30 +0200 Subject: [PATCH 03/11] This example was broken The provided example to the `sign_plus` method on `fmt` is broken, it displays the `-` sign twice for negative numbers. --- library/core/src/fmt/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index 9d3e9abf55779..0d370e3843174 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -1819,7 +1819,7 @@ impl<'a> Formatter<'a> { /// write!(formatter, /// "Foo({}{})", /// if self.0 < 0 { '-' } else { '+' }, - /// self.0) + /// self.0.abs()) /// } else { /// write!(formatter, "Foo({})", self.0) /// } From 0a9b49c794a4179a4dcfd5fc07cea76321e51ad0 Mon Sep 17 00:00:00 2001 From: Maurits van Riezen <12109031+mousetail@users.noreply.github.com> Date: Wed, 7 Sep 2022 16:36:32 +0200 Subject: [PATCH 04/11] Add doctest --- library/core/src/fmt/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index 0d370e3843174..1abb729a4c007 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -1827,6 +1827,7 @@ impl<'a> Formatter<'a> { /// } /// /// assert_eq!(&format!("{:+}", Foo(23)), "Foo(+23)"); + /// assert_eq!(&format!("{:+}", Foo(-32)), "Foo(-23)"); /// assert_eq!(&format!("{}", Foo(23)), "Foo(23)"); /// ``` #[must_use] From 5fbe485ecca977e3981d9dbcc5370183528d50a7 Mon Sep 17 00:00:00 2001 From: Maurits van Riezen <12109031+mousetail@users.noreply.github.com> Date: Wed, 7 Sep 2022 17:53:47 +0200 Subject: [PATCH 05/11] Typo --- library/core/src/fmt/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index 1abb729a4c007..905212eb372b1 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -1827,7 +1827,7 @@ impl<'a> Formatter<'a> { /// } /// /// assert_eq!(&format!("{:+}", Foo(23)), "Foo(+23)"); - /// assert_eq!(&format!("{:+}", Foo(-32)), "Foo(-23)"); + /// assert_eq!(&format!("{:+}", Foo(-23)), "Foo(-23)"); /// assert_eq!(&format!("{}", Foo(23)), "Foo(23)"); /// ``` #[must_use] From b79a2b3f73f0710150a8ccc71b72e847d6c1c7c2 Mon Sep 17 00:00:00 2001 From: lcnr Date: Thu, 8 Sep 2022 15:10:49 +0200 Subject: [PATCH 06/11] update `ParamKindOrd` --- compiler/rustc_ast/src/ast.rs | 36 ++----------------- .../rustc_ast_passes/src/ast_validation.rs | 4 +-- compiler/rustc_hir/src/hir.rs | 6 ++-- compiler/rustc_middle/src/ty/generics.rs | 5 +-- compiler/rustc_typeck/src/collect/type_of.rs | 4 +-- 5 files changed, 13 insertions(+), 42 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index e38572f609b31..6c7670378fd4f 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -33,7 +33,6 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use rustc_span::source_map::{respan, Spanned}; use rustc_span::symbol::{kw, sym, Ident, Symbol}; use rustc_span::{Span, DUMMY_SP}; -use std::cmp::Ordering; use std::convert::TryFrom; use std::fmt; use std::mem; @@ -324,46 +323,17 @@ pub type GenericBounds = Vec; /// Specifies the enforced ordering for generic parameters. In the future, /// if we wanted to relax this order, we could override `PartialEq` and /// `PartialOrd`, to allow the kinds to be unordered. -#[derive(Hash, Clone, Copy)] +#[derive(Hash, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] pub enum ParamKindOrd { Lifetime, - Type, - Const, - // `Infer` is not actually constructed directly from the AST, but is implicitly constructed - // during HIR lowering, and `ParamKindOrd` will implicitly order inferred variables last. - Infer, -} - -impl Ord for ParamKindOrd { - fn cmp(&self, other: &Self) -> Ordering { - use ParamKindOrd::*; - let to_int = |v| match v { - Lifetime => 0, - Infer | Type | Const => 1, - }; - - to_int(*self).cmp(&to_int(*other)) - } -} -impl PartialOrd for ParamKindOrd { - fn partial_cmp(&self, other: &Self) -> Option { - Some(self.cmp(other)) - } -} -impl PartialEq for ParamKindOrd { - fn eq(&self, other: &Self) -> bool { - self.cmp(other) == Ordering::Equal - } + TypeOrConst, } -impl Eq for ParamKindOrd {} impl fmt::Display for ParamKindOrd { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { ParamKindOrd::Lifetime => "lifetime".fmt(f), - ParamKindOrd::Type => "type".fmt(f), - ParamKindOrd::Const { .. } => "const".fmt(f), - ParamKindOrd::Infer => "infer".fmt(f), + ParamKindOrd::TypeOrConst => "type or const".fmt(f), } } } diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index d6d8881a53a14..26813f2c19c71 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -845,10 +845,10 @@ fn validate_generic_param_order( let (kind, bounds, span) = (¶m.kind, ¶m.bounds, ident.span); let (ord_kind, ident) = match ¶m.kind { GenericParamKind::Lifetime => (ParamKindOrd::Lifetime, ident.to_string()), - GenericParamKind::Type { default: _ } => (ParamKindOrd::Type, ident.to_string()), + GenericParamKind::Type { default: _ } => (ParamKindOrd::TypeOrConst, ident.to_string()), GenericParamKind::Const { ref ty, kw_span: _, default: _ } => { let ty = pprust::ty_to_string(ty); - (ParamKindOrd::Const, format!("const {}: {}", ident, ty)) + (ParamKindOrd::TypeOrConst, format!("const {}: {}", ident, ty)) } }; param_idents.push((kind, ord_kind, bounds, idx, ident)); diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index a668c0e95ce4b..ce60bab9e0275 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -300,9 +300,9 @@ impl GenericArg<'_> { pub fn to_ord(&self) -> ast::ParamKindOrd { match self { GenericArg::Lifetime(_) => ast::ParamKindOrd::Lifetime, - GenericArg::Type(_) => ast::ParamKindOrd::Type, - GenericArg::Const(_) => ast::ParamKindOrd::Const, - GenericArg::Infer(_) => ast::ParamKindOrd::Infer, + GenericArg::Type(_) | GenericArg::Const(_) | GenericArg::Infer(_) => { + ast::ParamKindOrd::TypeOrConst + } } } diff --git a/compiler/rustc_middle/src/ty/generics.rs b/compiler/rustc_middle/src/ty/generics.rs index 8631ee91fa456..0c8bdde9c8bce 100644 --- a/compiler/rustc_middle/src/ty/generics.rs +++ b/compiler/rustc_middle/src/ty/generics.rs @@ -27,8 +27,9 @@ impl GenericParamDefKind { pub fn to_ord(&self) -> ast::ParamKindOrd { match self { GenericParamDefKind::Lifetime => ast::ParamKindOrd::Lifetime, - GenericParamDefKind::Type { .. } => ast::ParamKindOrd::Type, - GenericParamDefKind::Const { .. } => ast::ParamKindOrd::Const, + GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => { + ast::ParamKindOrd::TypeOrConst + } } } diff --git a/compiler/rustc_typeck/src/collect/type_of.rs b/compiler/rustc_typeck/src/collect/type_of.rs index a0280ddca4bd8..dd894dc709bd6 100644 --- a/compiler/rustc_typeck/src/collect/type_of.rs +++ b/compiler/rustc_typeck/src/collect/type_of.rs @@ -65,8 +65,8 @@ pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option< let ty = item_ctxt.ast_ty_to_ty(hir_ty); // Iterate through the generics of the projection to find the one that corresponds to - // the def_id that this query was called with. We filter to only const args here as a - // precaution for if it's ever allowed to elide lifetimes in GAT's. It currently isn't + // the def_id that this query was called with. We filter to only type and const args here + // as a precaution for if it's ever allowed to elide lifetimes in GAT's. It currently isn't // but it can't hurt to be safe ^^ if let ty::Projection(projection) = ty.kind() { let generics = tcx.generics_of(projection.item_def_id); From dcf30047defdc946578709f1cb26d9b73a18be22 Mon Sep 17 00:00:00 2001 From: lcnr Date: Thu, 8 Sep 2022 15:53:22 +0200 Subject: [PATCH 07/11] update ui tests --- src/test/ui/const-generics/argument_order.stderr | 4 ++-- .../ui/const-generics/const-param-before-other-params.rs | 2 +- .../const-generics/const-param-before-other-params.stderr | 2 +- .../ui/const-generics/defaults/intermixed-lifetime.rs | 4 ++-- .../ui/const-generics/defaults/intermixed-lifetime.stderr | 4 ++-- .../defaults/param-order-err-pretty-prints-default.rs | 2 +- .../defaults/param-order-err-pretty-prints-default.stderr | 2 +- src/test/ui/generics/issue-59508-1.rs | 2 +- src/test/ui/generics/issue-59508-1.stderr | 2 +- src/test/ui/generics/issue-59508.fixed | 2 +- src/test/ui/generics/issue-59508.rs | 2 +- src/test/ui/generics/issue-59508.stderr | 2 +- .../issue-80512-param-reordering-with-defaults.rs | 2 +- .../issue-80512-param-reordering-with-defaults.stderr | 2 +- src/test/ui/generics/lifetime-before-type-params.rs | 8 ++++---- src/test/ui/generics/lifetime-before-type-params.stderr | 8 ++++---- src/test/ui/parser/issues/issue-14303-enum.rs | 2 +- src/test/ui/parser/issues/issue-14303-enum.stderr | 2 +- src/test/ui/parser/issues/issue-14303-fn-def.rs | 2 +- src/test/ui/parser/issues/issue-14303-fn-def.stderr | 2 +- src/test/ui/parser/issues/issue-14303-impl.rs | 2 +- src/test/ui/parser/issues/issue-14303-impl.stderr | 2 +- src/test/ui/parser/issues/issue-14303-struct.rs | 2 +- src/test/ui/parser/issues/issue-14303-struct.stderr | 2 +- src/test/ui/parser/issues/issue-14303-trait.rs | 2 +- src/test/ui/parser/issues/issue-14303-trait.stderr | 2 +- src/test/ui/suggestions/suggest-move-lifetimes.stderr | 8 ++++---- src/test/ui/suggestions/suggest-move-types.stderr | 4 ++-- 28 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/test/ui/const-generics/argument_order.stderr b/src/test/ui/const-generics/argument_order.stderr index 6b33dffb434e7..a3a54b497a76e 100644 --- a/src/test/ui/const-generics/argument_order.stderr +++ b/src/test/ui/const-generics/argument_order.stderr @@ -1,4 +1,4 @@ -error: lifetime parameters must be declared prior to const parameters +error: lifetime parameters must be declared prior to type or const parameters --> $DIR/argument_order.rs:6:32 | LL | struct AlsoBad { @@ -11,7 +11,7 @@ LL | let _: AlsoBad<7, 'static, u32, 'static, 17, u16>; | ^^^^^^^ | = note: lifetime arguments must be provided before type arguments - = help: reorder the arguments: lifetimes, then consts: `<'a, 'b, N, T, M, U>` + = help: reorder the arguments: lifetimes, then type or consts: `<'a, 'b, N, T, M, U>` error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/const-param-before-other-params.rs b/src/test/ui/const-generics/const-param-before-other-params.rs index da06aca308e18..b481000bb7f57 100644 --- a/src/test/ui/const-generics/const-param-before-other-params.rs +++ b/src/test/ui/const-generics/const-param-before-other-params.rs @@ -1,5 +1,5 @@ fn bar(_: &'a ()) { - //~^ ERROR lifetime parameters must be declared prior to const parameters + //~^ ERROR lifetime parameters must be declared prior to type or const parameters } fn foo(_: &T) {} diff --git a/src/test/ui/const-generics/const-param-before-other-params.stderr b/src/test/ui/const-generics/const-param-before-other-params.stderr index 607d20c4a25f2..049c58ba4fae8 100644 --- a/src/test/ui/const-generics/const-param-before-other-params.stderr +++ b/src/test/ui/const-generics/const-param-before-other-params.stderr @@ -1,4 +1,4 @@ -error: lifetime parameters must be declared prior to const parameters +error: lifetime parameters must be declared prior to type or const parameters --> $DIR/const-param-before-other-params.rs:1:21 | LL | fn bar(_: &'a ()) { diff --git a/src/test/ui/const-generics/defaults/intermixed-lifetime.rs b/src/test/ui/const-generics/defaults/intermixed-lifetime.rs index 578938db4c43e..9e4a32121bb38 100644 --- a/src/test/ui/const-generics/defaults/intermixed-lifetime.rs +++ b/src/test/ui/const-generics/defaults/intermixed-lifetime.rs @@ -1,9 +1,9 @@ // Checks that lifetimes cannot be interspersed between consts and types. struct Foo(&'a (), T); -//~^ Error lifetime parameters must be declared prior to const parameters +//~^ ERROR lifetime parameters must be declared prior to type or const parameters struct Bar(&'a (), T); -//~^ Error lifetime parameters must be declared prior to type parameters +//~^ ERROR lifetime parameters must be declared prior to type or const parameters fn main() {} diff --git a/src/test/ui/const-generics/defaults/intermixed-lifetime.stderr b/src/test/ui/const-generics/defaults/intermixed-lifetime.stderr index e27976deb2b56..b8aa18c942bc9 100644 --- a/src/test/ui/const-generics/defaults/intermixed-lifetime.stderr +++ b/src/test/ui/const-generics/defaults/intermixed-lifetime.stderr @@ -1,10 +1,10 @@ -error: lifetime parameters must be declared prior to const parameters +error: lifetime parameters must be declared prior to type or const parameters --> $DIR/intermixed-lifetime.rs:3:28 | LL | struct Foo(&'a (), T); | -----------------^^---------- help: reorder the parameters: lifetimes, then consts and types: `<'a, const N: usize, T = u32>` -error: lifetime parameters must be declared prior to type parameters +error: lifetime parameters must be declared prior to type or const parameters --> $DIR/intermixed-lifetime.rs:6:37 | LL | struct Bar(&'a (), T); diff --git a/src/test/ui/const-generics/defaults/param-order-err-pretty-prints-default.rs b/src/test/ui/const-generics/defaults/param-order-err-pretty-prints-default.rs index da087ffc3c4af..ae897e59a9742 100644 --- a/src/test/ui/const-generics/defaults/param-order-err-pretty-prints-default.rs +++ b/src/test/ui/const-generics/defaults/param-order-err-pretty-prints-default.rs @@ -1,4 +1,4 @@ struct Foo(&'a u32); -//~^ Error lifetime parameters must be declared prior to const parameters +//~^ ERROR lifetime parameters must be declared prior to type or const parameters fn main() {} diff --git a/src/test/ui/const-generics/defaults/param-order-err-pretty-prints-default.stderr b/src/test/ui/const-generics/defaults/param-order-err-pretty-prints-default.stderr index 55f5a53538537..b4bfc5410390d 100644 --- a/src/test/ui/const-generics/defaults/param-order-err-pretty-prints-default.stderr +++ b/src/test/ui/const-generics/defaults/param-order-err-pretty-prints-default.stderr @@ -1,4 +1,4 @@ -error: lifetime parameters must be declared prior to const parameters +error: lifetime parameters must be declared prior to type or const parameters --> $DIR/param-order-err-pretty-prints-default.rs:1:33 | LL | struct Foo(&'a u32); diff --git a/src/test/ui/generics/issue-59508-1.rs b/src/test/ui/generics/issue-59508-1.rs index 7e1dd77070441..646ece33ca341 100644 --- a/src/test/ui/generics/issue-59508-1.rs +++ b/src/test/ui/generics/issue-59508-1.rs @@ -8,7 +8,7 @@ struct A; impl A { pub fn do_things() { - //~^ ERROR lifetime parameters must be declared prior to type parameters + //~^ ERROR lifetime parameters must be declared prior to type or const parameters println!("panic"); } } diff --git a/src/test/ui/generics/issue-59508-1.stderr b/src/test/ui/generics/issue-59508-1.stderr index d162365ea4bff..1ca99c6ab76cd 100644 --- a/src/test/ui/generics/issue-59508-1.stderr +++ b/src/test/ui/generics/issue-59508-1.stderr @@ -1,4 +1,4 @@ -error: lifetime parameters must be declared prior to type parameters +error: lifetime parameters must be declared prior to type or const parameters --> $DIR/issue-59508-1.rs:10:25 | LL | pub fn do_things() { diff --git a/src/test/ui/generics/issue-59508.fixed b/src/test/ui/generics/issue-59508.fixed index b5c60a1626f53..557bcc1f716cd 100644 --- a/src/test/ui/generics/issue-59508.fixed +++ b/src/test/ui/generics/issue-59508.fixed @@ -8,7 +8,7 @@ struct A; impl A { pub fn do_things<'a, 'b: 'a, T>() { - //~^ ERROR lifetime parameters must be declared prior to type parameters + //~^ ERROR lifetime parameters must be declared prior to type or const parameters println!("panic"); } } diff --git a/src/test/ui/generics/issue-59508.rs b/src/test/ui/generics/issue-59508.rs index 0b39c5d8f2aec..0b290a6085f96 100644 --- a/src/test/ui/generics/issue-59508.rs +++ b/src/test/ui/generics/issue-59508.rs @@ -8,7 +8,7 @@ struct A; impl A { pub fn do_things() { - //~^ ERROR lifetime parameters must be declared prior to type parameters + //~^ ERROR lifetime parameters must be declared prior to type or const parameters println!("panic"); } } diff --git a/src/test/ui/generics/issue-59508.stderr b/src/test/ui/generics/issue-59508.stderr index c52ae4182b86b..e8926c13a1132 100644 --- a/src/test/ui/generics/issue-59508.stderr +++ b/src/test/ui/generics/issue-59508.stderr @@ -1,4 +1,4 @@ -error: lifetime parameters must be declared prior to type parameters +error: lifetime parameters must be declared prior to type or const parameters --> $DIR/issue-59508.rs:10:25 | LL | pub fn do_things() { diff --git a/src/test/ui/generics/issue-80512-param-reordering-with-defaults.rs b/src/test/ui/generics/issue-80512-param-reordering-with-defaults.rs index fe3e4fbc7e0b6..598f95d9a0bae 100644 --- a/src/test/ui/generics/issue-80512-param-reordering-with-defaults.rs +++ b/src/test/ui/generics/issue-80512-param-reordering-with-defaults.rs @@ -1,4 +1,4 @@ #![crate_type = "lib"] struct S(&'a T); -//~^ ERROR lifetime parameters must be declared prior to type parameters +//~^ ERROR lifetime parameters must be declared prior to type or const parameters diff --git a/src/test/ui/generics/issue-80512-param-reordering-with-defaults.stderr b/src/test/ui/generics/issue-80512-param-reordering-with-defaults.stderr index 119b1a0d2070e..69680a8010194 100644 --- a/src/test/ui/generics/issue-80512-param-reordering-with-defaults.stderr +++ b/src/test/ui/generics/issue-80512-param-reordering-with-defaults.stderr @@ -1,4 +1,4 @@ -error: lifetime parameters must be declared prior to type parameters +error: lifetime parameters must be declared prior to type or const parameters --> $DIR/issue-80512-param-reordering-with-defaults.rs:3:18 | LL | struct S(&'a T); diff --git a/src/test/ui/generics/lifetime-before-type-params.rs b/src/test/ui/generics/lifetime-before-type-params.rs index 5a71d6efeda62..4904ae61caaf1 100644 --- a/src/test/ui/generics/lifetime-before-type-params.rs +++ b/src/test/ui/generics/lifetime-before-type-params.rs @@ -1,11 +1,11 @@ #![allow(unused)] fn first() {} -//~^ ERROR lifetime parameters must be declared prior to type parameters +//~^ ERROR lifetime parameters must be declared prior to type or const parameters fn second<'a, T, 'b>() {} -//~^ ERROR lifetime parameters must be declared prior to type parameters +//~^ ERROR lifetime parameters must be declared prior to type or const parameters fn third() {} -//~^ ERROR lifetime parameters must be declared prior to type parameters +//~^ ERROR lifetime parameters must be declared prior to type or const parameters fn fourth<'a, T, 'b, U, 'c, V>() {} -//~^ ERROR lifetime parameters must be declared prior to type parameters +//~^ ERROR lifetime parameters must be declared prior to type or const parameters fn main() {} diff --git a/src/test/ui/generics/lifetime-before-type-params.stderr b/src/test/ui/generics/lifetime-before-type-params.stderr index 62d95e45329f9..7bb4f826409bc 100644 --- a/src/test/ui/generics/lifetime-before-type-params.stderr +++ b/src/test/ui/generics/lifetime-before-type-params.stderr @@ -1,22 +1,22 @@ -error: lifetime parameters must be declared prior to type parameters +error: lifetime parameters must be declared prior to type or const parameters --> $DIR/lifetime-before-type-params.rs:2:13 | LL | fn first() {} | ----^^--^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, T>` -error: lifetime parameters must be declared prior to type parameters +error: lifetime parameters must be declared prior to type or const parameters --> $DIR/lifetime-before-type-params.rs:4:18 | LL | fn second<'a, T, 'b>() {} | --------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, T>` -error: lifetime parameters must be declared prior to type parameters +error: lifetime parameters must be declared prior to type or const parameters --> $DIR/lifetime-before-type-params.rs:6:16 | LL | fn third() {} | -------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, T, U>` -error: lifetime parameters must be declared prior to type parameters +error: lifetime parameters must be declared prior to type or const parameters --> $DIR/lifetime-before-type-params.rs:8:18 | LL | fn fourth<'a, T, 'b, U, 'c, V>() {} diff --git a/src/test/ui/parser/issues/issue-14303-enum.rs b/src/test/ui/parser/issues/issue-14303-enum.rs index a6106159805b2..c5f510da89323 100644 --- a/src/test/ui/parser/issues/issue-14303-enum.rs +++ b/src/test/ui/parser/issues/issue-14303-enum.rs @@ -1,5 +1,5 @@ enum X<'a, T, 'b> { -//~^ ERROR lifetime parameters must be declared prior to type parameters +//~^ ERROR lifetime parameters must be declared prior to type or const parameters A(&'a &'b T) } diff --git a/src/test/ui/parser/issues/issue-14303-enum.stderr b/src/test/ui/parser/issues/issue-14303-enum.stderr index 55cef4cabacfe..6bb7b623a4e3e 100644 --- a/src/test/ui/parser/issues/issue-14303-enum.stderr +++ b/src/test/ui/parser/issues/issue-14303-enum.stderr @@ -1,4 +1,4 @@ -error: lifetime parameters must be declared prior to type parameters +error: lifetime parameters must be declared prior to type or const parameters --> $DIR/issue-14303-enum.rs:1:15 | LL | enum X<'a, T, 'b> { diff --git a/src/test/ui/parser/issues/issue-14303-fn-def.rs b/src/test/ui/parser/issues/issue-14303-fn-def.rs index 221bd311e7479..558efe488abcb 100644 --- a/src/test/ui/parser/issues/issue-14303-fn-def.rs +++ b/src/test/ui/parser/issues/issue-14303-fn-def.rs @@ -1,4 +1,4 @@ fn foo<'a, T, 'b>(x: &'a T) {} -//~^ ERROR lifetime parameters must be declared prior to type parameters +//~^ ERROR lifetime parameters must be declared prior to type or const parameters fn main() {} diff --git a/src/test/ui/parser/issues/issue-14303-fn-def.stderr b/src/test/ui/parser/issues/issue-14303-fn-def.stderr index bacc922969d91..87f9e446c2791 100644 --- a/src/test/ui/parser/issues/issue-14303-fn-def.stderr +++ b/src/test/ui/parser/issues/issue-14303-fn-def.stderr @@ -1,4 +1,4 @@ -error: lifetime parameters must be declared prior to type parameters +error: lifetime parameters must be declared prior to type or const parameters --> $DIR/issue-14303-fn-def.rs:1:15 | LL | fn foo<'a, T, 'b>(x: &'a T) {} diff --git a/src/test/ui/parser/issues/issue-14303-impl.rs b/src/test/ui/parser/issues/issue-14303-impl.rs index 4dc2c66601807..0e86ae4823316 100644 --- a/src/test/ui/parser/issues/issue-14303-impl.rs +++ b/src/test/ui/parser/issues/issue-14303-impl.rs @@ -1,6 +1,6 @@ struct X(T); impl<'a, T, 'b> X {} -//~^ ERROR lifetime parameters must be declared prior to type parameters +//~^ ERROR lifetime parameters must be declared prior to type or const parameters fn main() {} diff --git a/src/test/ui/parser/issues/issue-14303-impl.stderr b/src/test/ui/parser/issues/issue-14303-impl.stderr index d6be02f70fd2e..f2117d626fdfb 100644 --- a/src/test/ui/parser/issues/issue-14303-impl.stderr +++ b/src/test/ui/parser/issues/issue-14303-impl.stderr @@ -1,4 +1,4 @@ -error: lifetime parameters must be declared prior to type parameters +error: lifetime parameters must be declared prior to type or const parameters --> $DIR/issue-14303-impl.rs:3:13 | LL | impl<'a, T, 'b> X {} diff --git a/src/test/ui/parser/issues/issue-14303-struct.rs b/src/test/ui/parser/issues/issue-14303-struct.rs index 0bd10b4d08516..ea5e3317ddde1 100644 --- a/src/test/ui/parser/issues/issue-14303-struct.rs +++ b/src/test/ui/parser/issues/issue-14303-struct.rs @@ -1,5 +1,5 @@ struct X<'a, T, 'b> { -//~^ ERROR lifetime parameters must be declared prior to type parameters +//~^ ERROR lifetime parameters must be declared prior to type or const parameters x: &'a &'b T } diff --git a/src/test/ui/parser/issues/issue-14303-struct.stderr b/src/test/ui/parser/issues/issue-14303-struct.stderr index fa62a39f2416c..2dcbeffefebc5 100644 --- a/src/test/ui/parser/issues/issue-14303-struct.stderr +++ b/src/test/ui/parser/issues/issue-14303-struct.stderr @@ -1,4 +1,4 @@ -error: lifetime parameters must be declared prior to type parameters +error: lifetime parameters must be declared prior to type or const parameters --> $DIR/issue-14303-struct.rs:1:17 | LL | struct X<'a, T, 'b> { diff --git a/src/test/ui/parser/issues/issue-14303-trait.rs b/src/test/ui/parser/issues/issue-14303-trait.rs index f253de92d92de..a736ffdfa151e 100644 --- a/src/test/ui/parser/issues/issue-14303-trait.rs +++ b/src/test/ui/parser/issues/issue-14303-trait.rs @@ -1,4 +1,4 @@ trait Foo<'a, T, 'b> {} -//~^ ERROR lifetime parameters must be declared prior to type parameters +//~^ ERROR lifetime parameters must be declared prior to type or const parameters fn main() {} diff --git a/src/test/ui/parser/issues/issue-14303-trait.stderr b/src/test/ui/parser/issues/issue-14303-trait.stderr index 75cd67a9ded82..ddaa7b12c2fcc 100644 --- a/src/test/ui/parser/issues/issue-14303-trait.stderr +++ b/src/test/ui/parser/issues/issue-14303-trait.stderr @@ -1,4 +1,4 @@ -error: lifetime parameters must be declared prior to type parameters +error: lifetime parameters must be declared prior to type or const parameters --> $DIR/issue-14303-trait.rs:1:18 | LL | trait Foo<'a, T, 'b> {} diff --git a/src/test/ui/suggestions/suggest-move-lifetimes.stderr b/src/test/ui/suggestions/suggest-move-lifetimes.stderr index f52631caed173..f7ff3697e1dac 100644 --- a/src/test/ui/suggestions/suggest-move-lifetimes.stderr +++ b/src/test/ui/suggestions/suggest-move-lifetimes.stderr @@ -1,22 +1,22 @@ -error: lifetime parameters must be declared prior to type parameters +error: lifetime parameters must be declared prior to type or const parameters --> $DIR/suggest-move-lifetimes.rs:1:13 | LL | struct A { | ----^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, T>` -error: lifetime parameters must be declared prior to type parameters +error: lifetime parameters must be declared prior to type or const parameters --> $DIR/suggest-move-lifetimes.rs:5:13 | LL | struct B { | ----^^---- help: reorder the parameters: lifetimes, then consts and types: `<'a, T, U>` -error: lifetime parameters must be declared prior to type parameters +error: lifetime parameters must be declared prior to type or const parameters --> $DIR/suggest-move-lifetimes.rs:10:16 | LL | struct C { | -------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, T, U>` -error: lifetime parameters must be declared prior to type parameters +error: lifetime parameters must be declared prior to type or const parameters --> $DIR/suggest-move-lifetimes.rs:15:16 | LL | struct D { diff --git a/src/test/ui/suggestions/suggest-move-types.stderr b/src/test/ui/suggestions/suggest-move-types.stderr index 1a6032db0010a..3037b7f92ed64 100644 --- a/src/test/ui/suggestions/suggest-move-types.stderr +++ b/src/test/ui/suggestions/suggest-move-types.stderr @@ -121,7 +121,7 @@ LL | struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime` + = help: reorder the arguments: lifetimes, then type or consts: `<'a, 'b, 'c, T, U, V>` error[E0747]: lifetime provided when a type was expected --> $DIR/suggest-move-types.rs:82:56 @@ -130,7 +130,7 @@ LL | struct Dl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime` + = help: reorder the arguments: lifetimes, then type or consts: `<'a, 'b, 'c, T, U, V>` error: aborting due to 12 previous errors From 4c75b32e9965acae7e9f7efa20fc505b1ca7a2a0 Mon Sep 17 00:00:00 2001 From: lcnr Date: Thu, 8 Sep 2022 15:56:32 +0200 Subject: [PATCH 08/11] merge tests --- src/test/ui/parser/issues/issue-14303-enum.rs | 6 --- .../ui/parser/issues/issue-14303-enum.stderr | 8 ---- .../ui/parser/issues/issue-14303-fn-def.rs | 4 -- .../parser/issues/issue-14303-fn-def.stderr | 8 ---- src/test/ui/parser/issues/issue-14303-impl.rs | 6 --- .../ui/parser/issues/issue-14303-impl.stderr | 8 ---- src/test/ui/parser/issues/issue-14303-path.rs | 13 ------- .../ui/parser/issues/issue-14303-path.stderr | 9 ----- .../ui/parser/issues/issue-14303-struct.rs | 6 --- .../parser/issues/issue-14303-struct.stderr | 8 ---- .../ui/parser/issues/issue-14303-trait.rs | 4 -- .../ui/parser/issues/issue-14303-trait.stderr | 8 ---- src/test/ui/parser/issues/issue-14303.rs | 33 ++++++++++++++++ src/test/ui/parser/issues/issue-14303.stderr | 39 +++++++++++++++++++ 14 files changed, 72 insertions(+), 88 deletions(-) delete mode 100644 src/test/ui/parser/issues/issue-14303-enum.rs delete mode 100644 src/test/ui/parser/issues/issue-14303-enum.stderr delete mode 100644 src/test/ui/parser/issues/issue-14303-fn-def.rs delete mode 100644 src/test/ui/parser/issues/issue-14303-fn-def.stderr delete mode 100644 src/test/ui/parser/issues/issue-14303-impl.rs delete mode 100644 src/test/ui/parser/issues/issue-14303-impl.stderr delete mode 100644 src/test/ui/parser/issues/issue-14303-path.rs delete mode 100644 src/test/ui/parser/issues/issue-14303-path.stderr delete mode 100644 src/test/ui/parser/issues/issue-14303-struct.rs delete mode 100644 src/test/ui/parser/issues/issue-14303-struct.stderr delete mode 100644 src/test/ui/parser/issues/issue-14303-trait.rs delete mode 100644 src/test/ui/parser/issues/issue-14303-trait.stderr create mode 100644 src/test/ui/parser/issues/issue-14303.rs create mode 100644 src/test/ui/parser/issues/issue-14303.stderr diff --git a/src/test/ui/parser/issues/issue-14303-enum.rs b/src/test/ui/parser/issues/issue-14303-enum.rs deleted file mode 100644 index c5f510da89323..0000000000000 --- a/src/test/ui/parser/issues/issue-14303-enum.rs +++ /dev/null @@ -1,6 +0,0 @@ -enum X<'a, T, 'b> { -//~^ ERROR lifetime parameters must be declared prior to type or const parameters - A(&'a &'b T) -} - -fn main() {} diff --git a/src/test/ui/parser/issues/issue-14303-enum.stderr b/src/test/ui/parser/issues/issue-14303-enum.stderr deleted file mode 100644 index 6bb7b623a4e3e..0000000000000 --- a/src/test/ui/parser/issues/issue-14303-enum.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: lifetime parameters must be declared prior to type or const parameters - --> $DIR/issue-14303-enum.rs:1:15 - | -LL | enum X<'a, T, 'b> { - | --------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, T>` - -error: aborting due to previous error - diff --git a/src/test/ui/parser/issues/issue-14303-fn-def.rs b/src/test/ui/parser/issues/issue-14303-fn-def.rs deleted file mode 100644 index 558efe488abcb..0000000000000 --- a/src/test/ui/parser/issues/issue-14303-fn-def.rs +++ /dev/null @@ -1,4 +0,0 @@ -fn foo<'a, T, 'b>(x: &'a T) {} -//~^ ERROR lifetime parameters must be declared prior to type or const parameters - -fn main() {} diff --git a/src/test/ui/parser/issues/issue-14303-fn-def.stderr b/src/test/ui/parser/issues/issue-14303-fn-def.stderr deleted file mode 100644 index 87f9e446c2791..0000000000000 --- a/src/test/ui/parser/issues/issue-14303-fn-def.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: lifetime parameters must be declared prior to type or const parameters - --> $DIR/issue-14303-fn-def.rs:1:15 - | -LL | fn foo<'a, T, 'b>(x: &'a T) {} - | --------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, T>` - -error: aborting due to previous error - diff --git a/src/test/ui/parser/issues/issue-14303-impl.rs b/src/test/ui/parser/issues/issue-14303-impl.rs deleted file mode 100644 index 0e86ae4823316..0000000000000 --- a/src/test/ui/parser/issues/issue-14303-impl.rs +++ /dev/null @@ -1,6 +0,0 @@ -struct X(T); - -impl<'a, T, 'b> X {} -//~^ ERROR lifetime parameters must be declared prior to type or const parameters - -fn main() {} diff --git a/src/test/ui/parser/issues/issue-14303-impl.stderr b/src/test/ui/parser/issues/issue-14303-impl.stderr deleted file mode 100644 index f2117d626fdfb..0000000000000 --- a/src/test/ui/parser/issues/issue-14303-impl.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: lifetime parameters must be declared prior to type or const parameters - --> $DIR/issue-14303-impl.rs:3:13 - | -LL | impl<'a, T, 'b> X {} - | --------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, T>` - -error: aborting due to previous error - diff --git a/src/test/ui/parser/issues/issue-14303-path.rs b/src/test/ui/parser/issues/issue-14303-path.rs deleted file mode 100644 index 89ef914aba238..0000000000000 --- a/src/test/ui/parser/issues/issue-14303-path.rs +++ /dev/null @@ -1,13 +0,0 @@ -mod foo { - pub struct X<'a, 'b, 'c, T> { - a: &'a str, - b: &'b str, - c: &'c str, - t: T, - } -} - -fn bar<'a, 'b, 'c, T>(x: foo::X<'a, T, 'b, 'c>) {} -//~^ ERROR type provided when a lifetime was expected - -fn main() {} diff --git a/src/test/ui/parser/issues/issue-14303-path.stderr b/src/test/ui/parser/issues/issue-14303-path.stderr deleted file mode 100644 index 841e63ecbe9d5..0000000000000 --- a/src/test/ui/parser/issues/issue-14303-path.stderr +++ /dev/null @@ -1,9 +0,0 @@ -error[E0747]: type provided when a lifetime was expected - --> $DIR/issue-14303-path.rs:10:37 - | -LL | fn bar<'a, 'b, 'c, T>(x: foo::X<'a, T, 'b, 'c>) {} - | ^ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0747`. diff --git a/src/test/ui/parser/issues/issue-14303-struct.rs b/src/test/ui/parser/issues/issue-14303-struct.rs deleted file mode 100644 index ea5e3317ddde1..0000000000000 --- a/src/test/ui/parser/issues/issue-14303-struct.rs +++ /dev/null @@ -1,6 +0,0 @@ -struct X<'a, T, 'b> { -//~^ ERROR lifetime parameters must be declared prior to type or const parameters - x: &'a &'b T -} - -fn main() {} diff --git a/src/test/ui/parser/issues/issue-14303-struct.stderr b/src/test/ui/parser/issues/issue-14303-struct.stderr deleted file mode 100644 index 2dcbeffefebc5..0000000000000 --- a/src/test/ui/parser/issues/issue-14303-struct.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: lifetime parameters must be declared prior to type or const parameters - --> $DIR/issue-14303-struct.rs:1:17 - | -LL | struct X<'a, T, 'b> { - | --------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, T>` - -error: aborting due to previous error - diff --git a/src/test/ui/parser/issues/issue-14303-trait.rs b/src/test/ui/parser/issues/issue-14303-trait.rs deleted file mode 100644 index a736ffdfa151e..0000000000000 --- a/src/test/ui/parser/issues/issue-14303-trait.rs +++ /dev/null @@ -1,4 +0,0 @@ -trait Foo<'a, T, 'b> {} -//~^ ERROR lifetime parameters must be declared prior to type or const parameters - -fn main() {} diff --git a/src/test/ui/parser/issues/issue-14303-trait.stderr b/src/test/ui/parser/issues/issue-14303-trait.stderr deleted file mode 100644 index ddaa7b12c2fcc..0000000000000 --- a/src/test/ui/parser/issues/issue-14303-trait.stderr +++ /dev/null @@ -1,8 +0,0 @@ -error: lifetime parameters must be declared prior to type or const parameters - --> $DIR/issue-14303-trait.rs:1:18 - | -LL | trait Foo<'a, T, 'b> {} - | --------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, T>` - -error: aborting due to previous error - diff --git a/src/test/ui/parser/issues/issue-14303.rs b/src/test/ui/parser/issues/issue-14303.rs new file mode 100644 index 0000000000000..e44b57746605e --- /dev/null +++ b/src/test/ui/parser/issues/issue-14303.rs @@ -0,0 +1,33 @@ +enum Enum<'a, T, 'b> { +//~^ ERROR lifetime parameters must be declared prior to type or const parameters + A(&'a &'b T) +} + +struct Struct<'a, T, 'b> { +//~^ ERROR lifetime parameters must be declared prior to type or const parameters + x: &'a &'b T +} + +trait Trait<'a, T, 'b> {} +//~^ ERROR lifetime parameters must be declared prior to type or const parameters + +fn foo<'a, T, 'b>(x: &'a T) {} +//~^ ERROR lifetime parameters must be declared prior to type or const parameters + +struct Y(T); +impl<'a, T, 'b> Y {} +//~^ ERROR lifetime parameters must be declared prior to type or const parameters + +mod bar { + pub struct X<'a, 'b, 'c, T> { + a: &'a str, + b: &'b str, + c: &'c str, + t: T, + } +} + +fn bar<'a, 'b, 'c, T>(x: bar::X<'a, T, 'b, 'c>) {} +//~^ ERROR type provided when a lifetime was expected + +fn main() {} diff --git a/src/test/ui/parser/issues/issue-14303.stderr b/src/test/ui/parser/issues/issue-14303.stderr new file mode 100644 index 0000000000000..3579159245ac6 --- /dev/null +++ b/src/test/ui/parser/issues/issue-14303.stderr @@ -0,0 +1,39 @@ +error: lifetime parameters must be declared prior to type or const parameters + --> $DIR/issue-14303.rs:1:18 + | +LL | enum Enum<'a, T, 'b> { + | --------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, T>` + +error: lifetime parameters must be declared prior to type or const parameters + --> $DIR/issue-14303.rs:6:22 + | +LL | struct Struct<'a, T, 'b> { + | --------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, T>` + +error: lifetime parameters must be declared prior to type or const parameters + --> $DIR/issue-14303.rs:11:20 + | +LL | trait Trait<'a, T, 'b> {} + | --------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, T>` + +error: lifetime parameters must be declared prior to type or const parameters + --> $DIR/issue-14303.rs:14:15 + | +LL | fn foo<'a, T, 'b>(x: &'a T) {} + | --------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, T>` + +error: lifetime parameters must be declared prior to type or const parameters + --> $DIR/issue-14303.rs:18:13 + | +LL | impl<'a, T, 'b> Y {} + | --------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, T>` + +error[E0747]: type provided when a lifetime was expected + --> $DIR/issue-14303.rs:30:37 + | +LL | fn bar<'a, 'b, 'c, T>(x: bar::X<'a, T, 'b, 'c>) {} + | ^ + +error: aborting due to 6 previous errors + +For more information about this error, try `rustc --explain E0747`. From 5db69074988b0edf6751192336398d0673ee81a2 Mon Sep 17 00:00:00 2001 From: lcnr Date: Fri, 9 Sep 2022 14:28:57 +0200 Subject: [PATCH 09/11] review --- compiler/rustc_ast/src/ast.rs | 2 +- src/test/ui/const-generics/argument_order.stderr | 4 ++-- .../const-generics/const-param-before-other-params.rs | 2 +- .../const-param-before-other-params.stderr | 2 +- .../ui/const-generics/defaults/intermixed-lifetime.rs | 4 ++-- .../const-generics/defaults/intermixed-lifetime.stderr | 4 ++-- .../defaults/param-order-err-pretty-prints-default.rs | 2 +- .../param-order-err-pretty-prints-default.stderr | 2 +- src/test/ui/generics/issue-59508-1.rs | 2 +- src/test/ui/generics/issue-59508-1.stderr | 2 +- src/test/ui/generics/issue-59508.fixed | 2 +- src/test/ui/generics/issue-59508.rs | 2 +- src/test/ui/generics/issue-59508.stderr | 2 +- .../issue-80512-param-reordering-with-defaults.rs | 2 +- .../issue-80512-param-reordering-with-defaults.stderr | 2 +- src/test/ui/generics/lifetime-before-type-params.rs | 8 ++++---- .../ui/generics/lifetime-before-type-params.stderr | 8 ++++---- src/test/ui/parser/issues/issue-14303.rs | 10 +++++----- src/test/ui/parser/issues/issue-14303.stderr | 10 +++++----- src/test/ui/suggestions/suggest-move-lifetimes.stderr | 8 ++++---- src/test/ui/suggestions/suggest-move-types.stderr | 4 ++-- 21 files changed, 42 insertions(+), 42 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 6c7670378fd4f..75cc5b72582e1 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -333,7 +333,7 @@ impl fmt::Display for ParamKindOrd { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { ParamKindOrd::Lifetime => "lifetime".fmt(f), - ParamKindOrd::TypeOrConst => "type or const".fmt(f), + ParamKindOrd::TypeOrConst => "type and const".fmt(f), } } } diff --git a/src/test/ui/const-generics/argument_order.stderr b/src/test/ui/const-generics/argument_order.stderr index a3a54b497a76e..99122c6f5e362 100644 --- a/src/test/ui/const-generics/argument_order.stderr +++ b/src/test/ui/const-generics/argument_order.stderr @@ -1,4 +1,4 @@ -error: lifetime parameters must be declared prior to type or const parameters +error: lifetime parameters must be declared prior to type and const parameters --> $DIR/argument_order.rs:6:32 | LL | struct AlsoBad { @@ -11,7 +11,7 @@ LL | let _: AlsoBad<7, 'static, u32, 'static, 17, u16>; | ^^^^^^^ | = note: lifetime arguments must be provided before type arguments - = help: reorder the arguments: lifetimes, then type or consts: `<'a, 'b, N, T, M, U>` + = help: reorder the arguments: lifetimes, then type and consts: `<'a, 'b, N, T, M, U>` error: aborting due to 2 previous errors diff --git a/src/test/ui/const-generics/const-param-before-other-params.rs b/src/test/ui/const-generics/const-param-before-other-params.rs index b481000bb7f57..cb1cebe1f68a1 100644 --- a/src/test/ui/const-generics/const-param-before-other-params.rs +++ b/src/test/ui/const-generics/const-param-before-other-params.rs @@ -1,5 +1,5 @@ fn bar(_: &'a ()) { - //~^ ERROR lifetime parameters must be declared prior to type or const parameters + //~^ ERROR lifetime parameters must be declared prior to type and const parameters } fn foo(_: &T) {} diff --git a/src/test/ui/const-generics/const-param-before-other-params.stderr b/src/test/ui/const-generics/const-param-before-other-params.stderr index 049c58ba4fae8..2c7a47bbc78cd 100644 --- a/src/test/ui/const-generics/const-param-before-other-params.stderr +++ b/src/test/ui/const-generics/const-param-before-other-params.stderr @@ -1,4 +1,4 @@ -error: lifetime parameters must be declared prior to type or const parameters +error: lifetime parameters must be declared prior to type and const parameters --> $DIR/const-param-before-other-params.rs:1:21 | LL | fn bar(_: &'a ()) { diff --git a/src/test/ui/const-generics/defaults/intermixed-lifetime.rs b/src/test/ui/const-generics/defaults/intermixed-lifetime.rs index 9e4a32121bb38..beaf7fc6001a9 100644 --- a/src/test/ui/const-generics/defaults/intermixed-lifetime.rs +++ b/src/test/ui/const-generics/defaults/intermixed-lifetime.rs @@ -1,9 +1,9 @@ // Checks that lifetimes cannot be interspersed between consts and types. struct Foo(&'a (), T); -//~^ ERROR lifetime parameters must be declared prior to type or const parameters +//~^ ERROR lifetime parameters must be declared prior to type and const parameters struct Bar(&'a (), T); -//~^ ERROR lifetime parameters must be declared prior to type or const parameters +//~^ ERROR lifetime parameters must be declared prior to type and const parameters fn main() {} diff --git a/src/test/ui/const-generics/defaults/intermixed-lifetime.stderr b/src/test/ui/const-generics/defaults/intermixed-lifetime.stderr index b8aa18c942bc9..5cff61dd9fb91 100644 --- a/src/test/ui/const-generics/defaults/intermixed-lifetime.stderr +++ b/src/test/ui/const-generics/defaults/intermixed-lifetime.stderr @@ -1,10 +1,10 @@ -error: lifetime parameters must be declared prior to type or const parameters +error: lifetime parameters must be declared prior to type and const parameters --> $DIR/intermixed-lifetime.rs:3:28 | LL | struct Foo(&'a (), T); | -----------------^^---------- help: reorder the parameters: lifetimes, then consts and types: `<'a, const N: usize, T = u32>` -error: lifetime parameters must be declared prior to type or const parameters +error: lifetime parameters must be declared prior to type and const parameters --> $DIR/intermixed-lifetime.rs:6:37 | LL | struct Bar(&'a (), T); diff --git a/src/test/ui/const-generics/defaults/param-order-err-pretty-prints-default.rs b/src/test/ui/const-generics/defaults/param-order-err-pretty-prints-default.rs index ae897e59a9742..f928fc9e75b73 100644 --- a/src/test/ui/const-generics/defaults/param-order-err-pretty-prints-default.rs +++ b/src/test/ui/const-generics/defaults/param-order-err-pretty-prints-default.rs @@ -1,4 +1,4 @@ struct Foo(&'a u32); -//~^ ERROR lifetime parameters must be declared prior to type or const parameters +//~^ ERROR lifetime parameters must be declared prior to type and const parameters fn main() {} diff --git a/src/test/ui/const-generics/defaults/param-order-err-pretty-prints-default.stderr b/src/test/ui/const-generics/defaults/param-order-err-pretty-prints-default.stderr index b4bfc5410390d..ba08b4646d0f4 100644 --- a/src/test/ui/const-generics/defaults/param-order-err-pretty-prints-default.stderr +++ b/src/test/ui/const-generics/defaults/param-order-err-pretty-prints-default.stderr @@ -1,4 +1,4 @@ -error: lifetime parameters must be declared prior to type or const parameters +error: lifetime parameters must be declared prior to type and const parameters --> $DIR/param-order-err-pretty-prints-default.rs:1:33 | LL | struct Foo(&'a u32); diff --git a/src/test/ui/generics/issue-59508-1.rs b/src/test/ui/generics/issue-59508-1.rs index 646ece33ca341..8e27749e8fc6b 100644 --- a/src/test/ui/generics/issue-59508-1.rs +++ b/src/test/ui/generics/issue-59508-1.rs @@ -8,7 +8,7 @@ struct A; impl A { pub fn do_things() { - //~^ ERROR lifetime parameters must be declared prior to type or const parameters + //~^ ERROR lifetime parameters must be declared prior to type and const parameters println!("panic"); } } diff --git a/src/test/ui/generics/issue-59508-1.stderr b/src/test/ui/generics/issue-59508-1.stderr index 1ca99c6ab76cd..1c510044f806f 100644 --- a/src/test/ui/generics/issue-59508-1.stderr +++ b/src/test/ui/generics/issue-59508-1.stderr @@ -1,4 +1,4 @@ -error: lifetime parameters must be declared prior to type or const parameters +error: lifetime parameters must be declared prior to type and const parameters --> $DIR/issue-59508-1.rs:10:25 | LL | pub fn do_things() { diff --git a/src/test/ui/generics/issue-59508.fixed b/src/test/ui/generics/issue-59508.fixed index 557bcc1f716cd..de8f47d4cff89 100644 --- a/src/test/ui/generics/issue-59508.fixed +++ b/src/test/ui/generics/issue-59508.fixed @@ -8,7 +8,7 @@ struct A; impl A { pub fn do_things<'a, 'b: 'a, T>() { - //~^ ERROR lifetime parameters must be declared prior to type or const parameters + //~^ ERROR lifetime parameters must be declared prior to type and const parameters println!("panic"); } } diff --git a/src/test/ui/generics/issue-59508.rs b/src/test/ui/generics/issue-59508.rs index 0b290a6085f96..a4c7d4ff26266 100644 --- a/src/test/ui/generics/issue-59508.rs +++ b/src/test/ui/generics/issue-59508.rs @@ -8,7 +8,7 @@ struct A; impl A { pub fn do_things() { - //~^ ERROR lifetime parameters must be declared prior to type or const parameters + //~^ ERROR lifetime parameters must be declared prior to type and const parameters println!("panic"); } } diff --git a/src/test/ui/generics/issue-59508.stderr b/src/test/ui/generics/issue-59508.stderr index e8926c13a1132..fd23b6276f92b 100644 --- a/src/test/ui/generics/issue-59508.stderr +++ b/src/test/ui/generics/issue-59508.stderr @@ -1,4 +1,4 @@ -error: lifetime parameters must be declared prior to type or const parameters +error: lifetime parameters must be declared prior to type and const parameters --> $DIR/issue-59508.rs:10:25 | LL | pub fn do_things() { diff --git a/src/test/ui/generics/issue-80512-param-reordering-with-defaults.rs b/src/test/ui/generics/issue-80512-param-reordering-with-defaults.rs index 598f95d9a0bae..0e208818ed459 100644 --- a/src/test/ui/generics/issue-80512-param-reordering-with-defaults.rs +++ b/src/test/ui/generics/issue-80512-param-reordering-with-defaults.rs @@ -1,4 +1,4 @@ #![crate_type = "lib"] struct S(&'a T); -//~^ ERROR lifetime parameters must be declared prior to type or const parameters +//~^ ERROR lifetime parameters must be declared prior to type and const parameters diff --git a/src/test/ui/generics/issue-80512-param-reordering-with-defaults.stderr b/src/test/ui/generics/issue-80512-param-reordering-with-defaults.stderr index 69680a8010194..70793a9c92084 100644 --- a/src/test/ui/generics/issue-80512-param-reordering-with-defaults.stderr +++ b/src/test/ui/generics/issue-80512-param-reordering-with-defaults.stderr @@ -1,4 +1,4 @@ -error: lifetime parameters must be declared prior to type or const parameters +error: lifetime parameters must be declared prior to type and const parameters --> $DIR/issue-80512-param-reordering-with-defaults.rs:3:18 | LL | struct S(&'a T); diff --git a/src/test/ui/generics/lifetime-before-type-params.rs b/src/test/ui/generics/lifetime-before-type-params.rs index 4904ae61caaf1..d64b1b0b44f65 100644 --- a/src/test/ui/generics/lifetime-before-type-params.rs +++ b/src/test/ui/generics/lifetime-before-type-params.rs @@ -1,11 +1,11 @@ #![allow(unused)] fn first() {} -//~^ ERROR lifetime parameters must be declared prior to type or const parameters +//~^ ERROR lifetime parameters must be declared prior to type and const parameters fn second<'a, T, 'b>() {} -//~^ ERROR lifetime parameters must be declared prior to type or const parameters +//~^ ERROR lifetime parameters must be declared prior to type and const parameters fn third() {} -//~^ ERROR lifetime parameters must be declared prior to type or const parameters +//~^ ERROR lifetime parameters must be declared prior to type and const parameters fn fourth<'a, T, 'b, U, 'c, V>() {} -//~^ ERROR lifetime parameters must be declared prior to type or const parameters +//~^ ERROR lifetime parameters must be declared prior to type and const parameters fn main() {} diff --git a/src/test/ui/generics/lifetime-before-type-params.stderr b/src/test/ui/generics/lifetime-before-type-params.stderr index 7bb4f826409bc..84825eb4ceb21 100644 --- a/src/test/ui/generics/lifetime-before-type-params.stderr +++ b/src/test/ui/generics/lifetime-before-type-params.stderr @@ -1,22 +1,22 @@ -error: lifetime parameters must be declared prior to type or const parameters +error: lifetime parameters must be declared prior to type and const parameters --> $DIR/lifetime-before-type-params.rs:2:13 | LL | fn first() {} | ----^^--^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, T>` -error: lifetime parameters must be declared prior to type or const parameters +error: lifetime parameters must be declared prior to type and const parameters --> $DIR/lifetime-before-type-params.rs:4:18 | LL | fn second<'a, T, 'b>() {} | --------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, T>` -error: lifetime parameters must be declared prior to type or const parameters +error: lifetime parameters must be declared prior to type and const parameters --> $DIR/lifetime-before-type-params.rs:6:16 | LL | fn third() {} | -------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, T, U>` -error: lifetime parameters must be declared prior to type or const parameters +error: lifetime parameters must be declared prior to type and const parameters --> $DIR/lifetime-before-type-params.rs:8:18 | LL | fn fourth<'a, T, 'b, U, 'c, V>() {} diff --git a/src/test/ui/parser/issues/issue-14303.rs b/src/test/ui/parser/issues/issue-14303.rs index e44b57746605e..82850d77aa921 100644 --- a/src/test/ui/parser/issues/issue-14303.rs +++ b/src/test/ui/parser/issues/issue-14303.rs @@ -1,22 +1,22 @@ enum Enum<'a, T, 'b> { -//~^ ERROR lifetime parameters must be declared prior to type or const parameters +//~^ ERROR lifetime parameters must be declared prior to type and const parameters A(&'a &'b T) } struct Struct<'a, T, 'b> { -//~^ ERROR lifetime parameters must be declared prior to type or const parameters +//~^ ERROR lifetime parameters must be declared prior to type and const parameters x: &'a &'b T } trait Trait<'a, T, 'b> {} -//~^ ERROR lifetime parameters must be declared prior to type or const parameters +//~^ ERROR lifetime parameters must be declared prior to type and const parameters fn foo<'a, T, 'b>(x: &'a T) {} -//~^ ERROR lifetime parameters must be declared prior to type or const parameters +//~^ ERROR lifetime parameters must be declared prior to type and const parameters struct Y(T); impl<'a, T, 'b> Y {} -//~^ ERROR lifetime parameters must be declared prior to type or const parameters +//~^ ERROR lifetime parameters must be declared prior to type and const parameters mod bar { pub struct X<'a, 'b, 'c, T> { diff --git a/src/test/ui/parser/issues/issue-14303.stderr b/src/test/ui/parser/issues/issue-14303.stderr index 3579159245ac6..f121107c0958f 100644 --- a/src/test/ui/parser/issues/issue-14303.stderr +++ b/src/test/ui/parser/issues/issue-14303.stderr @@ -1,28 +1,28 @@ -error: lifetime parameters must be declared prior to type or const parameters +error: lifetime parameters must be declared prior to type and const parameters --> $DIR/issue-14303.rs:1:18 | LL | enum Enum<'a, T, 'b> { | --------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, T>` -error: lifetime parameters must be declared prior to type or const parameters +error: lifetime parameters must be declared prior to type and const parameters --> $DIR/issue-14303.rs:6:22 | LL | struct Struct<'a, T, 'b> { | --------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, T>` -error: lifetime parameters must be declared prior to type or const parameters +error: lifetime parameters must be declared prior to type and const parameters --> $DIR/issue-14303.rs:11:20 | LL | trait Trait<'a, T, 'b> {} | --------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, T>` -error: lifetime parameters must be declared prior to type or const parameters +error: lifetime parameters must be declared prior to type and const parameters --> $DIR/issue-14303.rs:14:15 | LL | fn foo<'a, T, 'b>(x: &'a T) {} | --------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, T>` -error: lifetime parameters must be declared prior to type or const parameters +error: lifetime parameters must be declared prior to type and const parameters --> $DIR/issue-14303.rs:18:13 | LL | impl<'a, T, 'b> Y {} diff --git a/src/test/ui/suggestions/suggest-move-lifetimes.stderr b/src/test/ui/suggestions/suggest-move-lifetimes.stderr index f7ff3697e1dac..b1a49447d4601 100644 --- a/src/test/ui/suggestions/suggest-move-lifetimes.stderr +++ b/src/test/ui/suggestions/suggest-move-lifetimes.stderr @@ -1,22 +1,22 @@ -error: lifetime parameters must be declared prior to type or const parameters +error: lifetime parameters must be declared prior to type and const parameters --> $DIR/suggest-move-lifetimes.rs:1:13 | LL | struct A { | ----^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, T>` -error: lifetime parameters must be declared prior to type or const parameters +error: lifetime parameters must be declared prior to type and const parameters --> $DIR/suggest-move-lifetimes.rs:5:13 | LL | struct B { | ----^^---- help: reorder the parameters: lifetimes, then consts and types: `<'a, T, U>` -error: lifetime parameters must be declared prior to type or const parameters +error: lifetime parameters must be declared prior to type and const parameters --> $DIR/suggest-move-lifetimes.rs:10:16 | LL | struct C { | -------^^- help: reorder the parameters: lifetimes, then consts and types: `<'a, T, U>` -error: lifetime parameters must be declared prior to type or const parameters +error: lifetime parameters must be declared prior to type and const parameters --> $DIR/suggest-move-lifetimes.rs:15:16 | LL | struct D { diff --git a/src/test/ui/suggestions/suggest-move-types.stderr b/src/test/ui/suggestions/suggest-move-types.stderr index 3037b7f92ed64..b222e8142bab5 100644 --- a/src/test/ui/suggestions/suggest-move-types.stderr +++ b/src/test/ui/suggestions/suggest-move-types.stderr @@ -121,7 +121,7 @@ LL | struct Cl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime` + = help: reorder the arguments: lifetimes, then type and consts: `<'a, 'b, 'c, T, U, V>` error[E0747]: lifetime provided when a type was expected --> $DIR/suggest-move-types.rs:82:56 @@ -130,7 +130,7 @@ LL | struct Dl<'a, 'b, 'c, T, U, V, M: ThreeWithLifetime` + = help: reorder the arguments: lifetimes, then type and consts: `<'a, 'b, 'c, T, U, V>` error: aborting due to 12 previous errors From 72791061666c45e830dade2445354a6f60699d69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Fri, 9 Sep 2022 00:00:00 +0000 Subject: [PATCH 10/11] Introduce a fallible variant of LLVMConstIntGetZExtValue which verifies that a constant bit width is within 64 bits or fails. --- compiler/rustc_codegen_llvm/src/common.rs | 6 +++++- compiler/rustc_codegen_llvm/src/llvm/ffi.rs | 2 +- compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp | 8 ++++++++ src/test/ui/codegen/issue-101585-128bit-repeat.rs | 14 ++++++++++++++ 4 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 src/test/ui/codegen/issue-101585-128bit-repeat.rs diff --git a/compiler/rustc_codegen_llvm/src/common.rs b/compiler/rustc_codegen_llvm/src/common.rs index 488ea72c3b779..acee9134fb96e 100644 --- a/compiler/rustc_codegen_llvm/src/common.rs +++ b/compiler/rustc_codegen_llvm/src/common.rs @@ -215,7 +215,11 @@ impl<'ll, 'tcx> ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> { } fn const_to_opt_uint(&self, v: &'ll Value) -> Option { - try_as_const_integral(v).map(|v| unsafe { llvm::LLVMConstIntGetZExtValue(v) }) + try_as_const_integral(v).and_then(|v| unsafe { + let mut i = 0u64; + let success = llvm::LLVMRustConstIntGetZExtValue(v, &mut i); + success.then_some(i) + }) } fn const_to_opt_u128(&self, v: &'ll Value, sign_ext: bool) -> Option { diff --git a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs index 172684414fc55..ce27dc5a5d1ea 100644 --- a/compiler/rustc_codegen_llvm/src/llvm/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/llvm/ffi.rs @@ -1096,7 +1096,7 @@ extern "C" { pub fn LLVMConstInt(IntTy: &Type, N: c_ulonglong, SignExtend: Bool) -> &Value; pub fn LLVMConstIntOfArbitraryPrecision(IntTy: &Type, Wn: c_uint, Ws: *const u64) -> &Value; pub fn LLVMConstReal(RealTy: &Type, N: f64) -> &Value; - pub fn LLVMConstIntGetZExtValue(ConstantVal: &ConstantInt) -> c_ulonglong; + pub fn LLVMRustConstIntGetZExtValue(ConstantVal: &ConstantInt, Value: &mut u64) -> bool; pub fn LLVMRustConstInt128Get( ConstantVal: &ConstantInt, SExt: bool, diff --git a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp index 931ce78721cb8..6ee3c7d68213e 100644 --- a/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp @@ -1618,6 +1618,14 @@ extern "C" LLVMValueRef LLVMRustConstInBoundsGEP2(LLVMTypeRef Ty, return wrap(ConstantExpr::getInBoundsGetElementPtr(unwrap(Ty), Val, IdxList)); } +extern "C" bool LLVMRustConstIntGetZExtValue(LLVMValueRef CV, uint64_t *value) { + auto C = unwrap(CV); + if (C->getBitWidth() > 64) + return false; + *value = C->getZExtValue(); + return true; +} + // Returns true if both high and low were successfully set. Fails in case constant wasn’t any of // the common sizes (1, 8, 16, 32, 64, 128 bits) extern "C" bool LLVMRustConstInt128Get(LLVMValueRef CV, bool sext, uint64_t *high, uint64_t *low) diff --git a/src/test/ui/codegen/issue-101585-128bit-repeat.rs b/src/test/ui/codegen/issue-101585-128bit-repeat.rs new file mode 100644 index 0000000000000..c6a686597e9c8 --- /dev/null +++ b/src/test/ui/codegen/issue-101585-128bit-repeat.rs @@ -0,0 +1,14 @@ +// Regression test for issue 101585. +// run-pass + +fn main() { + fn min_array_ok() -> [i128; 1] { + [i128::MIN] + } + assert_eq!(min_array_ok(), [-170141183460469231731687303715884105728i128]); + + fn min_array_nok() -> [i128; 1] { + [i128::MIN; 1] + } + assert_eq!(min_array_nok(), [-170141183460469231731687303715884105728i128]); +} From e4d3abfe7720c05f0f2e752d3054236341cd5e9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Fri, 9 Sep 2022 00:00:00 +0000 Subject: [PATCH 11/11] Use memset when repeating 128bit zero value --- compiler/rustc_codegen_ssa/src/mir/rvalue.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs index 26b9fbf442846..574746e340b7b 100644 --- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs +++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs @@ -87,7 +87,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let size = bx.const_usize(dest.layout.size.bytes()); // Use llvm.memset.p0i8.* to initialize all zero arrays - if bx.cx().const_to_opt_uint(v) == Some(0) { + if bx.cx().const_to_opt_u128(v, false) == Some(0) { let fill = bx.cx().const_u8(0); bx.memset(start, fill, size, dest.align, MemFlags::empty()); return bx;