diff options
635 files changed, 10432 insertions, 4661 deletions
diff --git a/.editorconfig b/.editorconfig index ef8ed24c52a..1b137cf4ebe 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,9 +7,18 @@ root = true [*] end_of_line = lf charset = utf-8 -trim_trailing_whitespace = true insert_final_newline = true +# some tests need trailing whitespace in output snapshots +[!tests/] +trim_trailing_whitespace = true +# for actual source code files of test, we still don't want trailing whitespace +[tests/**.{rs,js}] +trim_trailing_whitespace = true +# these specific source files need to have trailing whitespace. +[tests/ui/{frontmatter/frontmatter-whitespace-3.rs,parser/shebang/shebang-space.rs}] +trim_trailing_whitespace = false + [!src/llvm-project] indent_style = space indent_size = 4 diff --git a/.github/ISSUE_TEMPLATE/documentation.yaml b/.github/ISSUE_TEMPLATE/documentation.yaml index 712b32759ae..4a79cd4ba97 100644 --- a/.github/ISSUE_TEMPLATE/documentation.yaml +++ b/.github/ISSUE_TEMPLATE/documentation.yaml @@ -1,5 +1,5 @@ name: Documentation problem -description: Create a report for a documentation problem. +description: Report an issue with documentation content. labels: ["A-docs"] body: - type: markdown @@ -19,20 +19,20 @@ body: - [The Rustonomicon](https://github.com/rust-lang/nomicon/issues) - [The Embedded Book](https://github.com/rust-embedded/book/issues) - All other documentation issues should be filed here. + Or, if you find an issue related to rustdoc (e.g. doctest, rustdoc UI), please use the rustdoc issue template instead. - Or, if you find an issue related to rustdoc (e.g. doctest, rustdoc UI), please use the bug report or blank issue template instead. + All other documentation issues should be filed here. - type: textarea id: location attributes: - label: Location + label: Location (URL) validations: - required: true + required: true - type: textarea id: summary attributes: label: Summary validations: - required: true \ No newline at end of file + required: true diff --git a/Cargo.lock b/Cargo.lock index dbb76ada837..4eb246995b1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5284,9 +5284,9 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.36.1" +version = "0.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "252800745060e7b9ffb7b2badbd8b31cfa4aa2e61af879d0a3bf2a317c20217d" +checksum = "07cec4dc2d2e357ca1e610cfb07de2fa7a10fc3e9fe89f72545f3d244ea87753" dependencies = [ "libc", "objc2-core-foundation", diff --git a/bootstrap.example.toml b/bootstrap.example.toml index 31966af3301..89da6eeb531 100644 --- a/bootstrap.example.toml +++ b/bootstrap.example.toml @@ -740,11 +740,19 @@ # result (broken, compiling, testing) into this JSON file. #rust.save-toolstates = <none> (path) -# This is an array of the codegen backends that will be compiled for the rustc -# that's being compiled. The default is to only build the LLVM codegen backend, -# and currently the only standard options supported are `"llvm"`, `"cranelift"` -# and `"gcc"`. The first backend in this list will be used as default by rustc -# when no explicit backend is specified. +# This array serves three distinct purposes: +# - Backends in this list will be automatically compiled and included in the sysroot of each +# rustc compiled by bootstrap. +# - The first backend in this list will be configured as the **default codegen backend** by each +# rustc compiled by bootstrap. In other words, if the first backend is e.g. cranelift, then when +# we build a stage 1 rustc, it will by default compile Rust programs using the Cranelift backend. +# This also means that stage 2 rustc would get built by the Cranelift backend. +# - Running `x dist` (without additional arguments, or with `--include-default-paths`) will produce +# a dist component/tarball for the Cranelift backend if it is included in this array. +# +# Note that the LLVM codegen backend is special and will always be built and distributed. +# +# Currently, the only standard options supported here are `"llvm"`, `"cranelift"` and `"gcc"`. #rust.codegen-backends = ["llvm"] # Indicates whether LLD will be compiled and made available in the sysroot for rustc to execute, and diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index fdff18ffd47..87c9c797ea5 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -35,7 +35,6 @@ use rustc_span::{ByteSymbol, DUMMY_SP, ErrorGuaranteed, Ident, Span, Symbol, kw, use thin_vec::{ThinVec, thin_vec}; pub use crate::format::*; -use crate::ptr::P; use crate::token::{self, CommentKind, Delimiter}; use crate::tokenstream::{DelimSpan, LazyAttrTokenStream, TokenStream}; use crate::util::parser::{ExprPrecedence, Fixity}; @@ -225,7 +224,7 @@ pub struct PathSegment { /// `Some` means that parameter list is supplied (`Path<X, Y>`) /// but it can be empty (`Path<>`). /// `P` is used as a size optimization for the common case with no parameters. - pub args: Option<P<GenericArgs>>, + pub args: Option<Box<GenericArgs>>, } // Succeeds if the path segment is arg-free and matches the given symbol. @@ -286,7 +285,7 @@ pub enum GenericArg { /// `'a` in `Foo<'a>`. Lifetime(#[visitable(extra = LifetimeCtxt::GenericArg)] Lifetime), /// `Bar` in `Foo<Bar>`. - Type(P<Ty>), + Type(Box<Ty>), /// `1` in `Foo<1>`. Const(AnonConst), } @@ -328,15 +327,15 @@ impl AngleBracketedArg { } } -impl From<AngleBracketedArgs> for P<GenericArgs> { +impl From<AngleBracketedArgs> for Box<GenericArgs> { fn from(val: AngleBracketedArgs) -> Self { - P(GenericArgs::AngleBracketed(val)) + Box::new(GenericArgs::AngleBracketed(val)) } } -impl From<ParenthesizedArgs> for P<GenericArgs> { +impl From<ParenthesizedArgs> for Box<GenericArgs> { fn from(val: ParenthesizedArgs) -> Self { - P(GenericArgs::Parenthesized(val)) + Box::new(GenericArgs::Parenthesized(val)) } } @@ -350,7 +349,7 @@ pub struct ParenthesizedArgs { pub span: Span, /// `(A, B)` - pub inputs: ThinVec<P<Ty>>, + pub inputs: ThinVec<Box<Ty>>, /// ```text /// Foo(A, B) -> C @@ -435,10 +434,10 @@ pub enum GenericParamKind { /// A lifetime definition (e.g., `'a: 'b + 'c + 'd`). Lifetime, Type { - default: Option<P<Ty>>, + default: Option<Box<Ty>>, }, Const { - ty: P<Ty>, + ty: Box<Ty>, /// Span of the whole parameter definition, including default. span: Span, /// Optional default value for the const generic param. @@ -526,7 +525,7 @@ pub struct WhereBoundPredicate { /// Any generics from a `for` binding. pub bound_generic_params: ThinVec<GenericParam>, /// The type being bounded. - pub bounded_ty: P<Ty>, + pub bounded_ty: Box<Ty>, /// Trait and lifetime bounds (`Clone + Send + 'static`). #[visitable(extra = BoundKind::Bound)] pub bounds: GenericBounds, @@ -548,8 +547,8 @@ pub struct WhereRegionPredicate { /// E.g., `T = int`. #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct WhereEqPredicate { - pub lhs_ty: P<Ty>, - pub rhs_ty: P<Ty>, + pub lhs_ty: Box<Ty>, + pub rhs_ty: Box<Ty>, } #[derive(Clone, Encodable, Decodable, Debug, Walkable)] @@ -558,7 +557,7 @@ pub struct Crate { /// expansion placeholders or an unassigned value (`DUMMY_NODE_ID`) before that. pub id: NodeId, pub attrs: AttrVec, - pub items: ThinVec<P<Item>>, + pub items: ThinVec<Box<Item>>, pub spans: ModSpans, pub is_placeholder: bool, } @@ -638,7 +637,7 @@ pub struct Pat { impl Pat { /// Attempt reparsing the pattern as a type. /// This is intended for use by diagnostics. - pub fn to_ty(&self) -> Option<P<Ty>> { + pub fn to_ty(&self) -> Option<Box<Ty>> { let kind = match &self.kind { PatKind::Missing => unreachable!(), // In a type expression `_` is an inference variable. @@ -671,7 +670,7 @@ impl Pat { _ => return None, }; - Some(P(Ty { kind, id: self.id, span: self.span, tokens: None })) + Some(Box::new(Ty { kind, id: self.id, span: self.span, tokens: None })) } /// Walk top-down and call `it` in each place where a pattern occurs @@ -764,8 +763,8 @@ impl Pat { } } -impl From<P<Pat>> for Pat { - fn from(value: P<Pat>) -> Self { +impl From<Box<Pat>> for Pat { + fn from(value: Box<Pat>) -> Self { *value } } @@ -780,7 +779,7 @@ pub struct PatField { /// The identifier for the field. pub ident: Ident, /// The pattern the field is destructured to. - pub pat: P<Pat>, + pub pat: Box<Pat>, pub is_shorthand: bool, pub attrs: AttrVec, pub id: NodeId, @@ -865,44 +864,44 @@ pub enum PatKind { /// or a unit struct/variant pattern, or a const pattern (in the last two cases the third /// field must be `None`). Disambiguation cannot be done with parser alone, so it happens /// during name resolution. - Ident(BindingMode, Ident, Option<P<Pat>>), + Ident(BindingMode, Ident, Option<Box<Pat>>), /// A struct or struct variant pattern (e.g., `Variant {x, y, ..}`). - Struct(Option<P<QSelf>>, Path, ThinVec<PatField>, PatFieldsRest), + Struct(Option<Box<QSelf>>, Path, ThinVec<PatField>, PatFieldsRest), /// A tuple struct/variant pattern (`Variant(x, y, .., z)`). - TupleStruct(Option<P<QSelf>>, Path, ThinVec<P<Pat>>), + TupleStruct(Option<Box<QSelf>>, Path, ThinVec<Box<Pat>>), /// An or-pattern `A | B | C`. /// Invariant: `pats.len() >= 2`. - Or(ThinVec<P<Pat>>), + Or(ThinVec<Box<Pat>>), /// A possibly qualified path pattern. /// Unqualified path patterns `A::B::C` can legally refer to variants, structs, constants /// or associated constants. Qualified path patterns `<A>::B::C`/`<A as Trait>::B::C` can /// only legally refer to associated constants. - Path(Option<P<QSelf>>, Path), + Path(Option<Box<QSelf>>, Path), /// A tuple pattern (`(a, b)`). - Tuple(ThinVec<P<Pat>>), + Tuple(ThinVec<Box<Pat>>), /// A `box` pattern. - Box(P<Pat>), + Box(Box<Pat>), /// A `deref` pattern (currently `deref!()` macro-based syntax). - Deref(P<Pat>), + Deref(Box<Pat>), /// A reference pattern (e.g., `&mut (a, b)`). - Ref(P<Pat>, Mutability), + Ref(Box<Pat>, Mutability), /// A literal, const block or path. - Expr(P<Expr>), + Expr(Box<Expr>), /// A range pattern (e.g., `1...2`, `1..2`, `1..`, `..2`, `1..=2`, `..=2`). - Range(Option<P<Expr>>, Option<P<Expr>>, Spanned<RangeEnd>), + Range(Option<Box<Expr>>, Option<Box<Expr>>, Spanned<RangeEnd>), /// A slice pattern `[a, b, c]`. - Slice(ThinVec<P<Pat>>), + Slice(ThinVec<Box<Pat>>), /// A rest pattern `..`. /// @@ -922,13 +921,13 @@ pub enum PatKind { Never, /// A guard pattern (e.g., `x if guard(x)`). - Guard(P<Pat>, P<Expr>), + Guard(Box<Pat>, Box<Expr>), /// Parentheses in patterns used for grouping (i.e., `(PAT)`). - Paren(P<Pat>), + Paren(Box<Pat>), /// A macro pattern; pre-expansion. - MacCall(P<MacCall>), + MacCall(Box<MacCall>), /// Placeholder for a pattern that wasn't syntactically well formed in some way. Err(ErrorGuaranteed), @@ -1223,22 +1222,22 @@ impl Stmt { #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum StmtKind { /// A local (let) binding. - Let(P<Local>), + Let(Box<Local>), /// An item definition. - Item(P<Item>), + Item(Box<Item>), /// Expr without trailing semi-colon. - Expr(P<Expr>), + Expr(Box<Expr>), /// Expr with a trailing semi-colon. - Semi(P<Expr>), + Semi(Box<Expr>), /// Just a trailing semi-colon. Empty, /// Macro. - MacCall(P<MacCallStmt>), + MacCall(Box<MacCallStmt>), } #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct MacCallStmt { - pub mac: P<MacCall>, + pub mac: Box<MacCall>, pub style: MacStmtStyle, pub attrs: AttrVec, pub tokens: Option<LazyAttrTokenStream>, @@ -1262,8 +1261,8 @@ pub enum MacStmtStyle { pub struct Local { pub id: NodeId, pub super_: Option<Span>, - pub pat: P<Pat>, - pub ty: Option<P<Ty>>, + pub pat: Box<Pat>, + pub ty: Option<Box<Ty>>, pub kind: LocalKind, pub span: Span, pub colon_sp: Option<Span>, @@ -1278,10 +1277,10 @@ pub enum LocalKind { Decl, /// Local declaration with an initializer. /// Example: `let x = y;` - Init(P<Expr>), + Init(Box<Expr>), /// Local declaration with an initializer and an `else` clause. /// Example: `let Some(x) = y else { return };` - InitElse(P<Expr>, P<Block>), + InitElse(Box<Expr>, Box<Block>), } impl LocalKind { @@ -1315,11 +1314,11 @@ impl LocalKind { pub struct Arm { pub attrs: AttrVec, /// Match arm pattern, e.g. `10` in `match foo { 10 => {}, _ => {} }`. - pub pat: P<Pat>, + pub pat: Box<Pat>, /// Match arm guard, e.g. `n > 10` in `match foo { n if n > 10 => {}, _ => {} }`. - pub guard: Option<P<Expr>>, + pub guard: Option<Box<Expr>>, /// Match arm body. Omitted if the pattern is a never pattern. - pub body: Option<P<Expr>>, + pub body: Option<Box<Expr>>, pub span: Span, pub id: NodeId, pub is_placeholder: bool, @@ -1332,7 +1331,7 @@ pub struct ExprField { pub id: NodeId, pub span: Span, pub ident: Ident, - pub expr: P<Expr>, + pub expr: Box<Expr>, pub is_shorthand: bool, pub is_placeholder: bool, } @@ -1357,7 +1356,7 @@ pub enum UnsafeSource { #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct AnonConst { pub id: NodeId, - pub value: P<Expr>, + pub value: Box<Expr>, } /// An expression. @@ -1469,7 +1468,7 @@ impl Expr { } /// Attempts to reparse as `Ty` (for diagnostic purposes). - pub fn to_ty(&self) -> Option<P<Ty>> { + pub fn to_ty(&self) -> Option<Box<Ty>> { let kind = match &self.kind { // Trivial conversions. ExprKind::Path(qself, path) => TyKind::Path(qself.clone(), path.clone()), @@ -1511,7 +1510,7 @@ impl Expr { _ => return None, }; - Some(P(Ty { kind, id: self.id, span: self.span, tokens: None })) + Some(Box::new(Ty { kind, id: self.id, span: self.span, tokens: None })) } pub fn precedence(&self) -> ExprPrecedence { @@ -1632,8 +1631,8 @@ impl Expr { } } -impl From<P<Expr>> for Expr { - fn from(value: P<Expr>) -> Self { +impl From<Box<Expr>> for Expr { + fn from(value: Box<Expr>) -> Self { *value } } @@ -1645,8 +1644,8 @@ pub struct Closure { pub constness: Const, pub coroutine_kind: Option<CoroutineKind>, pub movability: Movability, - pub fn_decl: P<FnDecl>, - pub body: P<Expr>, + pub fn_decl: Box<FnDecl>, + pub body: Box<Expr>, /// The span of the declaration block: 'move |...| -> ...' pub fn_decl_span: Span, /// The span of the argument block `|...|` @@ -1677,9 +1676,9 @@ pub struct MethodCall { /// The method name and its generic arguments, e.g. `foo::<Bar, Baz>`. pub seg: PathSegment, /// The receiver, e.g. `x`. - pub receiver: P<Expr>, + pub receiver: Box<Expr>, /// The arguments, e.g. `a, b, c`. - pub args: ThinVec<P<Expr>>, + pub args: ThinVec<Box<Expr>>, /// The span of the function, without the dot and receiver e.g. `foo::<Bar, /// Baz>(a, b, c)`. pub span: Span, @@ -1688,7 +1687,7 @@ pub struct MethodCall { #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum StructRest { /// `..x`. - Base(P<Expr>), + Base(Box<Expr>), /// `..`. Rest(Span), /// No trailing `..` or expression. @@ -1697,7 +1696,7 @@ pub enum StructRest { #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct StructExpr { - pub qself: Option<P<QSelf>>, + pub qself: Option<Box<QSelf>>, pub path: Path, pub fields: ThinVec<ExprField>, pub rest: StructRest, @@ -1707,7 +1706,7 @@ pub struct StructExpr { #[derive(Clone, Encodable, Decodable, Debug)] pub enum ExprKind { /// An array (e.g, `[a, b, c, d]`). - Array(ThinVec<P<Expr>>), + Array(ThinVec<Box<Expr>>), /// Allow anonymous constants from an inline `const` block. ConstBlock(AnonConst), /// A function call. @@ -1716,90 +1715,90 @@ pub enum ExprKind { /// and the second field is the list of arguments. /// This also represents calling the constructor of /// tuple-like ADTs such as tuple structs and enum variants. - Call(P<Expr>, ThinVec<P<Expr>>), + Call(Box<Expr>, ThinVec<Box<Expr>>), /// A method call (e.g., `x.foo::<Bar, Baz>(a, b, c)`). MethodCall(Box<MethodCall>), /// A tuple (e.g., `(a, b, c, d)`). - Tup(ThinVec<P<Expr>>), + Tup(ThinVec<Box<Expr>>), /// A binary operation (e.g., `a + b`, `a * b`). - Binary(BinOp, P<Expr>, P<Expr>), + Binary(BinOp, Box<Expr>, Box<Expr>), /// A unary operation (e.g., `!x`, `*x`). - Unary(UnOp, P<Expr>), + Unary(UnOp, Box<Expr>), /// A literal (e.g., `1`, `"foo"`). Lit(token::Lit), /// A cast (e.g., `foo as f64`). - Cast(P<Expr>, P<Ty>), + Cast(Box<Expr>, Box<Ty>), /// A type ascription (e.g., `builtin # type_ascribe(42, usize)`). /// /// Usually not written directly in user code but /// indirectly via the macro `type_ascribe!(...)`. - Type(P<Expr>, P<Ty>), + Type(Box<Expr>, Box<Ty>), /// A `let pat = expr` expression that is only semantically allowed in the condition /// of `if` / `while` expressions. (e.g., `if let 0 = x { .. }`). /// /// `Span` represents the whole `let pat = expr` statement. - Let(P<Pat>, P<Expr>, Span, Recovered), + Let(Box<Pat>, Box<Expr>, Span, Recovered), /// An `if` block, with an optional `else` block. /// /// `if expr { block } else { expr }` /// /// If present, the "else" expr is always `ExprKind::Block` (for `else`) or /// `ExprKind::If` (for `else if`). - If(P<Expr>, P<Block>, Option<P<Expr>>), + If(Box<Expr>, Box<Block>, Option<Box<Expr>>), /// A while loop, with an optional label. /// /// `'label: while expr { block }` - While(P<Expr>, P<Block>, Option<Label>), + While(Box<Expr>, Box<Block>, Option<Label>), /// A `for` loop, with an optional label. /// /// `'label: for await? pat in iter { block }` /// /// This is desugared to a combination of `loop` and `match` expressions. ForLoop { - pat: P<Pat>, - iter: P<Expr>, - body: P<Block>, + pat: Box<Pat>, + iter: Box<Expr>, + body: Box<Block>, label: Option<Label>, kind: ForLoopKind, }, /// Conditionless loop (can be exited with `break`, `continue`, or `return`). /// /// `'label: loop { block }` - Loop(P<Block>, Option<Label>, Span), + Loop(Box<Block>, Option<Label>, Span), /// A `match` block. - Match(P<Expr>, ThinVec<Arm>, MatchKind), + Match(Box<Expr>, ThinVec<Arm>, MatchKind), /// A closure (e.g., `move |a, b, c| a + b + c`). Closure(Box<Closure>), /// A block (`'label: { ... }`). - Block(P<Block>, Option<Label>), + Block(Box<Block>, Option<Label>), /// An `async` block (`async move { ... }`), /// or a `gen` block (`gen move { ... }`). /// /// The span is the "decl", which is the header before the body `{ }` /// including the `asyng`/`gen` keywords and possibly `move`. - Gen(CaptureBy, P<Block>, GenBlockKind, Span), + Gen(CaptureBy, Box<Block>, GenBlockKind, Span), /// An await expression (`my_future.await`). Span is of await keyword. - Await(P<Expr>, Span), + Await(Box<Expr>, Span), /// A use expression (`x.use`). Span is of use keyword. - Use(P<Expr>, Span), + Use(Box<Expr>, Span), /// A try block (`try { ... }`). - TryBlock(P<Block>), + TryBlock(Box<Block>), /// An assignment (`a = foo()`). /// The `Span` argument is the span of the `=` token. - Assign(P<Expr>, P<Expr>, Span), + Assign(Box<Expr>, Box<Expr>, Span), /// An assignment with an operator. /// /// E.g., `a += 1`. - AssignOp(AssignOp, P<Expr>, P<Expr>), + AssignOp(AssignOp, Box<Expr>, Box<Expr>), /// Access of a named (e.g., `obj.foo`) or unnamed (e.g., `obj.0`) struct field. - Field(P<Expr>, Ident), + Field(Box<Expr>, Ident), /// An indexing operation (e.g., `foo[2]`). /// The span represents the span of the `[2]`, including brackets. - Index(P<Expr>, P<Expr>, Span), + Index(Box<Expr>, Box<Expr>, Span), /// A range (e.g., `1..2`, `1..`, `..2`, `1..=2`, `..=2`; and `..` in destructuring assignment). - Range(Option<P<Expr>>, Option<P<Expr>>, RangeLimits), + Range(Option<Box<Expr>>, Option<Box<Expr>>, RangeLimits), /// An underscore, used in destructuring assignment to ignore a value. Underscore, @@ -1807,57 +1806,57 @@ pub enum ExprKind { /// parameters (e.g., `foo::bar::<baz>`). /// /// Optionally "qualified" (e.g., `<Vec<T> as SomeTrait>::SomeType`). - Path(Option<P<QSelf>>, Path), + Path(Option<Box<QSelf>>, Path), /// A referencing operation (`&a`, `&mut a`, `&raw const a` or `&raw mut a`). - AddrOf(BorrowKind, Mutability, P<Expr>), + AddrOf(BorrowKind, Mutability, Box<Expr>), /// A `break`, with an optional label to break, and an optional expression. - Break(Option<Label>, Option<P<Expr>>), + Break(Option<Label>, Option<Box<Expr>>), /// A `continue`, with an optional label. Continue(Option<Label>), /// A `return`, with an optional value to be returned. - Ret(Option<P<Expr>>), + Ret(Option<Box<Expr>>), /// Output of the `asm!()` macro. - InlineAsm(P<InlineAsm>), + InlineAsm(Box<InlineAsm>), /// An `offset_of` expression (e.g., `builtin # offset_of(Struct, field)`). /// /// Usually not written directly in user code but /// indirectly via the macro `core::mem::offset_of!(...)`. - OffsetOf(P<Ty>, Vec<Ident>), + OffsetOf(Box<Ty>, Vec<Ident>), /// A macro invocation; pre-expansion. - MacCall(P<MacCall>), + MacCall(Box<MacCall>), /// A struct literal expression. /// /// E.g., `Foo {x: 1, y: 2}`, or `Foo {x: 1, .. rest}`. - Struct(P<StructExpr>), + Struct(Box<StructExpr>), /// An array literal constructed from one repeated element. /// /// E.g., `[1; 5]`. The expression is the element to be /// repeated; the constant is the number of times to repeat it. - Repeat(P<Expr>, AnonConst), + Repeat(Box<Expr>, AnonConst), /// No-op: used solely so we can pretty-print faithfully. - Paren(P<Expr>), + Paren(Box<Expr>), /// A try expression (`expr?`). - Try(P<Expr>), + Try(Box<Expr>), /// A `yield`, with an optional value to be yielded. Yield(YieldKind), /// A `do yeet` (aka `throw`/`fail`/`bail`/`raise`/whatever), /// with an optional value to be returned. - Yeet(Option<P<Expr>>), + Yeet(Option<Box<Expr>>), /// A tail call return, with the value to be returned. /// /// While `.0` must be a function call, we check this later, after parsing. - Become(P<Expr>), + Become(Box<Expr>), /// Bytes included via `include_bytes!` /// @@ -1873,9 +1872,9 @@ pub enum ExprKind { IncludedBytes(ByteSymbol), /// A `format_args!()` expression. - FormatArgs(P<FormatArgs>), + FormatArgs(Box<FormatArgs>), - UnsafeBinderCast(UnsafeBinderCastKind, P<Expr>, Option<P<Ty>>), + UnsafeBinderCast(UnsafeBinderCastKind, Box<Expr>, Option<Box<Ty>>), /// Placeholder for an expression that wasn't syntactically well formed in some way. Err(ErrorGuaranteed), @@ -1941,7 +1940,7 @@ pub enum UnsafeBinderCastKind { /// ``` #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct QSelf { - pub ty: P<Ty>, + pub ty: Box<Ty>, /// The span of `a::b::Trait` in a path like `<Vec<T> as /// a::b::Trait>::AssociatedItem`; in the case where `position == @@ -2001,7 +2000,7 @@ pub enum ClosureBinder { #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct MacCall { pub path: Path, - pub args: P<DelimArgs>, + pub args: Box<DelimArgs>, } impl MacCall { @@ -2021,7 +2020,7 @@ pub enum AttrArgs { Eq { /// Span of the `=` token. eq_span: Span, - expr: P<Expr>, + expr: Box<Expr>, }, } @@ -2064,7 +2063,7 @@ impl DelimArgs { /// Represents a macro definition. #[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic, Walkable)] pub struct MacroDef { - pub body: P<DelimArgs>, + pub body: Box<DelimArgs>, /// `true` if macro was defined with `macro_rules`. pub macro_rules: bool, } @@ -2093,16 +2092,16 @@ pub enum MatchKind { #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum YieldKind { /// yield expr { ... } - Prefix(Option<P<Expr>>), + Prefix(Option<Box<Expr>>), /// expr.yield { ... } - Postfix(P<Expr>), + Postfix(Box<Expr>), } impl YieldKind { /// Returns the expression inside the yield expression, if any. /// /// For postfix yields, this is guaranteed to be `Some`. - pub const fn expr(&self) -> Option<&P<Expr>> { + pub const fn expr(&self) -> Option<&Box<Expr>> { match self { YieldKind::Prefix(expr) => expr.as_ref(), YieldKind::Postfix(expr) => Some(expr), @@ -2110,7 +2109,7 @@ impl YieldKind { } /// Returns a mutable reference to the expression being yielded, if any. - pub const fn expr_mut(&mut self) -> Option<&mut P<Expr>> { + pub const fn expr_mut(&mut self) -> Option<&mut Box<Expr>> { match self { YieldKind::Prefix(expr) => expr.as_mut(), YieldKind::Postfix(expr) => Some(expr), @@ -2272,7 +2271,7 @@ impl LitKind { // type structure in `middle/ty.rs` as well. #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct MutTy { - pub ty: P<Ty>, + pub ty: Box<Ty>, pub mutbl: Mutability, } @@ -2281,7 +2280,7 @@ pub struct MutTy { #[derive(Clone, Encodable, Decodable, Debug)] pub struct FnSig { pub header: FnHeader, - pub decl: P<FnDecl>, + pub decl: Box<FnDecl>, pub span: Span, } @@ -2306,12 +2305,12 @@ pub struct AssocItemConstraint { #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum Term { - Ty(P<Ty>), + Ty(Box<Ty>), Const(AnonConst), } -impl From<P<Ty>> for Term { - fn from(v: P<Ty>) -> Self { +impl From<Box<Ty>> for Term { + fn from(v: Box<Ty>) -> Self { Term::Ty(v) } } @@ -2358,8 +2357,8 @@ impl Clone for Ty { } } -impl From<P<Ty>> for Ty { - fn from(value: P<Ty>) -> Self { +impl From<Box<Ty>> for Ty { + fn from(value: Box<Ty>) -> Self { *value } } @@ -2388,7 +2387,7 @@ pub struct FnPtrTy { pub safety: Safety, pub ext: Extern, pub generic_params: ThinVec<GenericParam>, - pub decl: P<FnDecl>, + pub decl: Box<FnDecl>, /// Span of the `[unsafe] [extern] fn(...) -> ...` part, i.e. everything /// after the generic params (if there are any, e.g. `for<'a>`). pub decl_span: Span, @@ -2397,7 +2396,7 @@ pub struct FnPtrTy { #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct UnsafeBinderTy { pub generic_params: ThinVec<GenericParam>, - pub inner_ty: P<Ty>, + pub inner_ty: Box<Ty>, } /// The various kinds of type recognized by the compiler. @@ -2406,9 +2405,9 @@ pub struct UnsafeBinderTy { #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum TyKind { /// A variable-length slice (`[T]`). - Slice(P<Ty>), + Slice(Box<Ty>), /// A fixed length array (`[T; n]`). - Array(P<Ty>, AnonConst), + Array(Box<Ty>, AnonConst), /// A raw pointer (`*const T` or `*mut T`). Ptr(MutTy), /// A reference (`&'a T` or `&'a mut T`). @@ -2418,18 +2417,18 @@ pub enum TyKind { /// Desugars into `Pin<&'a T>` or `Pin<&'a mut T>`. PinnedRef(#[visitable(extra = LifetimeCtxt::Ref)] Option<Lifetime>, MutTy), /// A function pointer type (e.g., `fn(usize) -> bool`). - FnPtr(P<FnPtrTy>), + FnPtr(Box<FnPtrTy>), /// An unsafe existential lifetime binder (e.g., `unsafe<'a> &'a ()`). - UnsafeBinder(P<UnsafeBinderTy>), + UnsafeBinder(Box<UnsafeBinderTy>), /// The never type (`!`). Never, /// A tuple (`(A, B, C, D,...)`). - Tup(ThinVec<P<Ty>>), + Tup(ThinVec<Box<Ty>>), /// A path (`module::module::...::Type`), optionally /// "qualified", e.g., `<Vec<T> as SomeTrait>::SomeType`. /// /// Type parameters are stored in the `Path` itself. - Path(Option<P<QSelf>>, Path), + Path(Option<Box<QSelf>>, Path), /// A trait object type `Bound1 + Bound2 + Bound3` /// where `Bound` is a trait or a lifetime. TraitObject(#[visitable(extra = BoundKind::TraitObject)] GenericBounds, TraitObjectSyntax), @@ -2441,7 +2440,7 @@ pub enum TyKind { /// the generation of opaque `type Foo = impl Trait` items significantly. ImplTrait(NodeId, #[visitable(extra = BoundKind::Impl)] GenericBounds), /// No-op; kept solely so that we can pretty-print faithfully. - Paren(P<Ty>), + Paren(Box<Ty>), /// Unused for now. Typeof(AnonConst), /// This means the type should be inferred instead of it having been @@ -2450,12 +2449,12 @@ pub enum TyKind { /// Inferred type of a `self` or `&self` argument in a method. ImplicitSelf, /// A macro in the type position. - MacCall(P<MacCall>), + MacCall(Box<MacCall>), /// Placeholder for a `va_list`. CVarArgs, /// Pattern types like `pattern_type!(u32 is 1..=)`, which is the same as `NonZero<u32>`, /// just as part of the type system. - Pat(P<Ty>, P<TyPat>), + Pat(Box<Ty>, Box<TyPat>), /// Sometimes we need a dummy value when no error has occurred. Dummy, /// Placeholder for a kind that has failed to be defined. @@ -2531,9 +2530,9 @@ pub struct TyPat { #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum TyPatKind { /// A range pattern (e.g., `1...2`, `1..2`, `1..`, `..2`, `1..=2`, `..=2`). - Range(Option<P<AnonConst>>, Option<P<AnonConst>>, Spanned<RangeEnd>), + Range(Option<Box<AnonConst>>, Option<Box<AnonConst>>, Spanned<RangeEnd>), - Or(ThinVec<P<TyPat>>), + Or(ThinVec<Box<TyPat>>), /// Placeholder for a pattern that wasn't syntactically well formed in some way. Err(ErrorGuaranteed), @@ -2698,7 +2697,7 @@ impl InlineAsmTemplatePiece { #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct InlineAsmSym { pub id: NodeId, - pub qself: Option<P<QSelf>>, + pub qself: Option<Box<QSelf>>, pub path: Path, } @@ -2709,23 +2708,23 @@ pub struct InlineAsmSym { pub enum InlineAsmOperand { In { reg: InlineAsmRegOrRegClass, - expr: P<Expr>, + expr: Box<Expr>, }, Out { reg: InlineAsmRegOrRegClass, late: bool, - expr: Option<P<Expr>>, + expr: Option<Box<Expr>>, }, InOut { reg: InlineAsmRegOrRegClass, late: bool, - expr: P<Expr>, + expr: Box<Expr>, }, SplitInOut { reg: InlineAsmRegOrRegClass, late: bool, - in_expr: P<Expr>, - out_expr: Option<P<Expr>>, + in_expr: Box<Expr>, + out_expr: Option<Box<Expr>>, }, Const { anon_const: AnonConst, @@ -2734,7 +2733,7 @@ pub enum InlineAsmOperand { sym: InlineAsmSym, }, Label { - block: P<Block>, + block: Box<Block>, }, } @@ -2807,8 +2806,8 @@ pub struct InlineAsm { #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct Param { pub attrs: AttrVec, - pub ty: P<Ty>, - pub pat: P<Pat>, + pub ty: Box<Ty>, + pub pat: Box<Pat>, pub id: NodeId, pub span: Span, pub is_placeholder: bool, @@ -2826,7 +2825,7 @@ pub enum SelfKind { /// `&'lt pin const self`, `&'lt pin mut self` Pinned(Option<Lifetime>, Mutability), /// `self: TYPE`, `mut self: TYPE` - Explicit(P<Ty>, Mutability), + Explicit(Box<Ty>, Mutability), } impl SelfKind { @@ -2882,7 +2881,7 @@ impl Param { /// Builds a `Param` object from `ExplicitSelf`. pub fn from_self(attrs: AttrVec, eself: ExplicitSelf, eself_ident: Ident) -> Param { let span = eself.span.to(eself_ident.span); - let infer_ty = P(Ty { + let infer_ty = Box::new(Ty { id: DUMMY_NODE_ID, kind: TyKind::ImplicitSelf, span: eself_ident.span, @@ -2893,7 +2892,7 @@ impl Param { SelfKind::Value(mutbl) => (mutbl, infer_ty), SelfKind::Region(lt, mutbl) => ( Mutability::Not, - P(Ty { + Box::new(Ty { id: DUMMY_NODE_ID, kind: TyKind::Ref(lt, MutTy { ty: infer_ty, mutbl }), span, @@ -2902,7 +2901,7 @@ impl Param { ), SelfKind::Pinned(lt, mutbl) => ( mutbl, - P(Ty { + Box::new(Ty { id: DUMMY_NODE_ID, kind: TyKind::PinnedRef(lt, MutTy { ty: infer_ty, mutbl }), span, @@ -2912,7 +2911,7 @@ impl Param { }; Param { attrs, - pat: P(Pat { + pat: Box::new(Pat { id: DUMMY_NODE_ID, kind: PatKind::Ident(BindingMode(ByRef::No, mutbl), eself_ident, None), span, @@ -3123,7 +3122,7 @@ pub enum FnRetTy { /// Span points to where return type would be inserted. Default(Span), /// Everything else. - Ty(P<Ty>), + Ty(Box<Ty>), } impl FnRetTy { @@ -3148,7 +3147,7 @@ pub enum ModKind { /// or with definition outlined to a separate file `mod foo;` and already loaded from it. /// The inner span is from the first token past `{` to the last token until `}`, /// or from the first to the last token in the loaded file. - Loaded(ThinVec<P<Item>>, Inline, ModSpans, Result<(), ErrorGuaranteed>), + Loaded(ThinVec<Box<Item>>, Inline, ModSpans, Result<(), ErrorGuaranteed>), /// Module with definition outlined to a separate file `mod foo;` but not yet loaded from it. Unloaded, } @@ -3172,7 +3171,7 @@ pub struct ForeignMod { /// semantically by Rust. pub safety: Safety, pub abi: Option<StrLit>, - pub items: ThinVec<P<ForeignItem>>, + pub items: ThinVec<Box<ForeignItem>>, } #[derive(Clone, Encodable, Decodable, Debug, Walkable)] @@ -3267,7 +3266,7 @@ pub struct Attribute { #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum AttrKind { /// A normal attribute. - Normal(P<NormalAttr>), + Normal(Box<NormalAttr>), /// A doc comment (e.g. `/// ...`, `//! ...`, `/** ... */`, `/*! ... */`). /// Doc attributes (e.g. `#[doc="..."]`) are represented with the `Normal` @@ -3381,7 +3380,7 @@ pub struct Visibility { #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum VisibilityKind { Public, - Restricted { path: P<Path>, id: NodeId, shorthand: bool }, + Restricted { path: Box<Path>, id: NodeId, shorthand: bool }, Inherited, } @@ -3403,7 +3402,7 @@ pub struct FieldDef { pub safety: Safety, pub ident: Option<Ident>, - pub ty: P<Ty>, + pub ty: Box<Ty>, pub default: Option<AnonConst>, pub is_placeholder: bool, } @@ -3609,7 +3608,7 @@ pub struct Trait { #[visitable(extra = BoundKind::SuperTraits)] pub bounds: GenericBounds, #[visitable(extra = AssocCtxt::Trait)] - pub items: ThinVec<P<AssocItem>>, + pub items: ThinVec<Box<AssocItem>>, } /// The location of a where clause on a `TyAlias` (`Span`) and whether there was @@ -3657,26 +3656,30 @@ pub struct TyAlias { pub where_clauses: TyAliasWhereClauses, #[visitable(extra = BoundKind::Bound)] pub bounds: GenericBounds, - pub ty: Option<P<Ty>>, + pub ty: Option<Box<Ty>>, } #[derive(Clone, Encodable, Decodable, Debug)] pub struct Impl { + pub generics: Generics, + pub of_trait: Option<Box<TraitImplHeader>>, + pub self_ty: Box<Ty>, + pub items: ThinVec<Box<AssocItem>>, +} + +#[derive(Clone, Encodable, Decodable, Debug)] +pub struct TraitImplHeader { pub defaultness: Defaultness, pub safety: Safety, - pub generics: Generics, pub constness: Const, pub polarity: ImplPolarity, - /// The trait being implemented, if any. - pub of_trait: Option<TraitRef>, - pub self_ty: P<Ty>, - pub items: ThinVec<P<AssocItem>>, + pub trait_ref: TraitRef, } #[derive(Clone, Encodable, Decodable, Debug, Default, Walkable)] pub struct FnContract { - pub requires: Option<P<Expr>>, - pub ensures: Option<P<Expr>>, + pub requires: Option<Box<Expr>>, + pub ensures: Option<Box<Expr>>, } #[derive(Clone, Encodable, Decodable, Debug)] @@ -3685,40 +3688,40 @@ pub struct Fn { pub ident: Ident, pub generics: Generics, pub sig: FnSig, - pub contract: Option<P<FnContract>>, + pub contract: Option<Box<FnContract>>, pub define_opaque: Option<ThinVec<(NodeId, Path)>>, - pub body: Option<P<Block>>, + pub body: Option<Box<Block>>, } #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct Delegation { /// Path resolution id. pub id: NodeId, - pub qself: Option<P<QSelf>>, + pub qself: Option<Box<QSelf>>, pub path: Path, pub ident: Ident, pub rename: Option<Ident>, - pub body: Option<P<Block>>, + pub body: Option<Box<Block>>, /// The item was expanded from a glob delegation item. pub from_glob: bool, } #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct DelegationMac { - pub qself: Option<P<QSelf>>, + pub qself: Option<Box<QSelf>>, pub prefix: Path, // Some for list delegation, and None for glob delegation. pub suffixes: Option<ThinVec<(Ident, Option<Ident>)>>, - pub body: Option<P<Block>>, + pub body: Option<Box<Block>>, } #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct StaticItem { pub ident: Ident, - pub ty: P<Ty>, + pub ty: Box<Ty>, pub safety: Safety, pub mutability: Mutability, - pub expr: Option<P<Expr>>, + pub expr: Option<Box<Expr>>, pub define_opaque: Option<ThinVec<(NodeId, Path)>>, } @@ -3727,8 +3730,8 @@ pub struct ConstItem { pub defaultness: Defaultness, pub ident: Ident, pub generics: Generics, - pub ty: P<Ty>, - pub expr: Option<P<Expr>>, + pub ty: Box<Ty>, + pub expr: Option<Box<Expr>>, pub define_opaque: Option<ThinVec<(NodeId, Path)>>, } @@ -3794,11 +3797,11 @@ pub enum ItemKind { /// An implementation. /// /// E.g., `impl<A> Foo<A> { .. }` or `impl<A> Trait for Foo<A> { .. }`. - Impl(Box<Impl>), + Impl(Impl), /// A macro invocation. /// /// E.g., `foo!(..)`. - MacCall(P<MacCall>), + MacCall(Box<MacCall>), /// A macro definition. MacroDef(Ident, MacroDef), /// A single delegation item (`reuse`). @@ -3881,7 +3884,7 @@ impl ItemKind { | Self::Union(_, generics, _) | Self::Trait(box Trait { generics, .. }) | Self::TraitAlias(_, generics, _) - | Self::Impl(box Impl { generics, .. }) => Some(generics), + | Self::Impl(Impl { generics, .. }) => Some(generics), _ => None, } } @@ -3908,7 +3911,7 @@ pub enum AssocItemKind { /// An associated type. Type(Box<TyAlias>), /// A macro expanding to associated items. - MacCall(P<MacCall>), + MacCall(Box<MacCall>), /// An associated delegation item. Delegation(Box<Delegation>), /// An associated list or glob delegation item. @@ -3978,7 +3981,7 @@ pub enum ForeignItemKind { /// A foreign type. TyAlias(Box<TyAlias>), /// A macro expanding to foreign items. - MacCall(P<MacCall>), + MacCall(Box<MacCall>), } impl ForeignItemKind { @@ -4041,7 +4044,7 @@ mod size_asserts { static_assert_size!(GenericArg, 24); static_assert_size!(GenericBound, 88); static_assert_size!(Generics, 40); - static_assert_size!(Impl, 136); + static_assert_size!(Impl, 64); static_assert_size!(Item, 144); static_assert_size!(ItemKind, 80); static_assert_size!(LitKind, 24); @@ -4054,6 +4057,7 @@ mod size_asserts { static_assert_size!(PathSegment, 24); static_assert_size!(Stmt, 32); static_assert_size!(StmtKind, 16); + static_assert_size!(TraitImplHeader, 80); static_assert_size!(Ty, 64); static_assert_size!(TyKind, 40); // tidy-alphabetical-end diff --git a/compiler/rustc_ast/src/ast_traits.rs b/compiler/rustc_ast/src/ast_traits.rs index 9d91f41d6c7..3d2477e5f03 100644 --- a/compiler/rustc_ast/src/ast_traits.rs +++ b/compiler/rustc_ast/src/ast_traits.rs @@ -5,7 +5,6 @@ use std::fmt; use std::marker::PhantomData; -use crate::ptr::P; use crate::tokenstream::LazyAttrTokenStream; use crate::{ Arm, AssocItem, AttrItem, AttrKind, AttrVec, Attribute, Block, Crate, Expr, ExprField, @@ -53,7 +52,7 @@ impl_has_node_id!( WherePredicate, ); -impl<T: HasNodeId> HasNodeId for P<T> { +impl<T: HasNodeId> HasNodeId for Box<T> { fn node_id(&self) -> NodeId { (**self).node_id() } @@ -119,7 +118,7 @@ impl<T: HasTokens> HasTokens for Option<T> { } } -impl<T: HasTokens> HasTokens for P<T> { +impl<T: HasTokens> HasTokens for Box<T> { fn tokens(&self) -> Option<&LazyAttrTokenStream> { (**self).tokens() } @@ -245,7 +244,7 @@ impl_has_attrs!( ); impl_has_attrs_none!(Attribute, AttrItem, Block, Pat, Path, Ty, Visibility); -impl<T: HasAttrs> HasAttrs for P<T> { +impl<T: HasAttrs> HasAttrs for Box<T> { const SUPPORTS_CUSTOM_INNER_ATTRS: bool = T::SUPPORTS_CUSTOM_INNER_ATTRS; fn attrs(&self) -> &[Attribute] { (**self).attrs() @@ -322,8 +321,8 @@ impl<Wrapped, Tag> AstNodeWrapper<Wrapped, Tag> { } // FIXME: remove after `stmt_expr_attributes` is stabilized. -impl<T, Tag> From<AstNodeWrapper<P<T>, Tag>> for AstNodeWrapper<T, Tag> { - fn from(value: AstNodeWrapper<P<T>, Tag>) -> Self { +impl<T, Tag> From<AstNodeWrapper<Box<T>, Tag>> for AstNodeWrapper<T, Tag> { + fn from(value: AstNodeWrapper<Box<T>, Tag>) -> Self { AstNodeWrapper { wrapped: *value.wrapped, tag: value.tag } } } diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs index 4348a4bb120..6ada93b4c89 100644 --- a/compiler/rustc_ast/src/attr/mod.rs +++ b/compiler/rustc_ast/src/attr/mod.rs @@ -13,7 +13,6 @@ use crate::ast::{ Expr, ExprKind, LitKind, MetaItem, MetaItemInner, MetaItemKind, MetaItemLit, NormalAttr, Path, PathSegment, Safety, }; -use crate::ptr::P; use crate::token::{self, CommentKind, Delimiter, InvisibleOrigin, MetaVarKind, Token}; use crate::tokenstream::{ DelimSpan, LazyAttrTokenStream, Spacing, TokenStream, TokenStreamIter, TokenTree, @@ -660,7 +659,7 @@ pub fn mk_attr_from_item( span: Span, ) -> Attribute { Attribute { - kind: AttrKind::Normal(P(NormalAttr { item, tokens })), + kind: AttrKind::Normal(Box::new(NormalAttr { item, tokens })), id: g.mk_attr_id(), style, span, @@ -710,7 +709,7 @@ pub fn mk_attr_name_value_str( span: Span, ) -> Attribute { let lit = token::Lit::new(token::Str, escape_string_symbol(val), None); - let expr = P(Expr { + let expr = Box::new(Expr { id: DUMMY_NODE_ID, kind: ExprKind::Lit(lit), span, diff --git a/compiler/rustc_ast/src/expand/autodiff_attrs.rs b/compiler/rustc_ast/src/expand/autodiff_attrs.rs index 2f918faaf75..33451f99748 100644 --- a/compiler/rustc_ast/src/expand/autodiff_attrs.rs +++ b/compiler/rustc_ast/src/expand/autodiff_attrs.rs @@ -7,7 +7,6 @@ use std::fmt::{self, Display, Formatter}; use std::str::FromStr; use crate::expand::{Decodable, Encodable, HashStable_Generic}; -use crate::ptr::P; use crate::{Ty, TyKind}; /// Forward and Reverse Mode are well known names for automatic differentiation implementations. @@ -162,7 +161,7 @@ pub fn valid_ret_activity(mode: DiffMode, activity: DiffActivity) -> bool { /// since Duplicated expects a mutable ref/ptr and we would thus end up with a shadow value /// who is an indirect type, which doesn't match the primal scalar type. We can't prevent /// users here from marking scalars as Duplicated, due to type aliases. -pub fn valid_ty_for_activity(ty: &P<Ty>, activity: DiffActivity) -> bool { +pub fn valid_ty_for_activity(ty: &Box<Ty>, activity: DiffActivity) -> bool { use DiffActivity::*; // It's always allowed to mark something as Const, since we won't compute derivatives wrt. it. // Dual variants also support all types. diff --git a/compiler/rustc_ast/src/format.rs b/compiler/rustc_ast/src/format.rs index c2a1de60a98..cadebb2254d 100644 --- a/compiler/rustc_ast/src/format.rs +++ b/compiler/rustc_ast/src/format.rs @@ -3,7 +3,6 @@ use rustc_macros::{Decodable, Encodable, Walkable}; use rustc_span::{Ident, Span, Symbol}; use crate::Expr; -use crate::ptr::P; use crate::token::LitKind; // Definitions: @@ -147,7 +146,7 @@ impl FormatArguments { #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct FormatArgument { pub kind: FormatArgumentKind, - pub expr: P<Expr>, + pub expr: Box<Expr>, } #[derive(Clone, Encodable, Decodable, Debug, Walkable)] diff --git a/compiler/rustc_ast/src/lib.rs b/compiler/rustc_ast/src/lib.rs index 896d1e1148a..f1951049b47 100644 --- a/compiler/rustc_ast/src/lib.rs +++ b/compiler/rustc_ast/src/lib.rs @@ -37,7 +37,6 @@ pub mod expand; pub mod format; pub mod mut_visit; pub mod node_id; -pub mod ptr; pub mod token; pub mod tokenstream; pub mod visit; diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 06708e2e703..be8e1d22c9d 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -17,7 +17,6 @@ use smallvec::{SmallVec, smallvec}; use thin_vec::ThinVec; use crate::ast::*; -use crate::ptr::P; use crate::tokenstream::*; use crate::visit::{AssocCtxt, BoundKind, FnCtxt, LifetimeCtxt, VisitorResult, try_visit}; @@ -41,7 +40,7 @@ pub(crate) trait MutVisitable<V: MutVisitor> { fn visit_mut(&mut self, visitor: &mut V, extra: Self::Extra); } -impl<V: MutVisitor, T: ?Sized> MutVisitable<V> for P<T> +impl<V: MutVisitor, T: ?Sized> MutVisitable<V> for Box<T> where T: MutVisitable<V>, { @@ -293,15 +292,15 @@ macro_rules! generate_flat_map_visitor_fns { } generate_flat_map_visitor_fns! { - visit_items, P<Item>, flat_map_item; - visit_foreign_items, P<ForeignItem>, flat_map_foreign_item; + visit_items, Box<Item>, flat_map_item; + visit_foreign_items, Box<ForeignItem>, flat_map_foreign_item; visit_generic_params, GenericParam, flat_map_generic_param; visit_stmts, Stmt, flat_map_stmt; - visit_exprs, P<Expr>, filter_map_expr; + visit_exprs, Box<Expr>, filter_map_expr; visit_expr_fields, ExprField, flat_map_expr_field; visit_pat_fields, PatField, flat_map_pat_field; visit_variants, Variant, flat_map_variant; - visit_assoc_items, P<AssocItem>, flat_map_assoc_item, ctxt: AssocCtxt; + visit_assoc_items, Box<AssocItem>, flat_map_assoc_item, ctxt: AssocCtxt; visit_where_predicates, WherePredicate, flat_map_where_predicate; visit_params, Param, flat_map_param; visit_field_defs, FieldDef, flat_map_field_def; @@ -333,12 +332,12 @@ generate_walk_flat_map_fns! { walk_flat_map_where_predicate(WherePredicate) => visit_where_predicate; walk_flat_map_field_def(FieldDef) => visit_field_def; walk_flat_map_expr_field(ExprField) => visit_expr_field; - walk_flat_map_item(P<Item>) => visit_item; - walk_flat_map_foreign_item(P<ForeignItem>) => visit_foreign_item; - walk_flat_map_assoc_item(P<AssocItem>, ctxt: AssocCtxt) => visit_assoc_item; + walk_flat_map_item(Box<Item>) => visit_item; + walk_flat_map_foreign_item(Box<ForeignItem>) => visit_foreign_item; + walk_flat_map_assoc_item(Box<AssocItem>, ctxt: AssocCtxt) => visit_assoc_item; } -pub fn walk_filter_map_expr<T: MutVisitor>(vis: &mut T, mut e: P<Expr>) -> Option<P<Expr>> { +pub fn walk_filter_map_expr<T: MutVisitor>(vis: &mut T, mut e: Box<Expr>) -> Option<Box<Expr>> { vis.visit_expr(&mut e); Some(e) } diff --git a/compiler/rustc_ast/src/ptr.rs b/compiler/rustc_ast/src/ptr.rs deleted file mode 100644 index fffeab8bbca..00000000000 --- a/compiler/rustc_ast/src/ptr.rs +++ /dev/null @@ -1,11 +0,0 @@ -/// A pointer type that uniquely owns a heap allocation of type T. -/// -/// This used to be its own type, but now it's just a typedef for `Box` and we are planning to -/// remove it soon. -pub type P<T> = Box<T>; - -/// Construct a `P<T>` from a `T` value. -#[allow(non_snake_case)] -pub fn P<T>(value: T) -> P<T> { - Box::new(value) -} diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index ab15cb28fa1..68b3d2b0368 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -20,7 +20,6 @@ use rustc_span::{Ident, Span, Symbol}; use thin_vec::ThinVec; use crate::ast::*; -use crate::ptr::P; use crate::tokenstream::DelimSpan; #[derive(Copy, Clone, Debug, PartialEq)] @@ -82,7 +81,7 @@ pub(crate) trait Visitable<'a, V: Visitor<'a>> { fn visit(&'a self, visitor: &mut V, extra: Self::Extra) -> V::Result; } -impl<'a, V: Visitor<'a>, T: ?Sized> Visitable<'a, V> for P<T> +impl<'a, V: Visitor<'a>, T: ?Sized> Visitable<'a, V> for Box<T> where T: Visitable<'a, V>, { @@ -322,7 +321,7 @@ macro_rules! common_visitor_and_walkers { Fn(FnCtxt, &'a $($mut)? Visibility, &'a $($mut)? Fn), /// E.g., `|x, y| body`. - Closure(&'a $($mut)? ClosureBinder, &'a $($mut)? Option<CoroutineKind>, &'a $($mut)? P<FnDecl>, &'a $($mut)? P<Expr>), + Closure(&'a $($mut)? ClosureBinder, &'a $($mut)? Option<CoroutineKind>, &'a $($mut)? Box<FnDecl>, &'a $($mut)? Box<Expr>), } impl<'a> FnKind<'a> { @@ -390,9 +389,9 @@ macro_rules! common_visitor_and_walkers { ThinVec<(NodeId, Path)>, ThinVec<PathSegment>, ThinVec<PreciseCapturingArg>, - ThinVec<P<Pat>>, - ThinVec<P<Ty>>, - ThinVec<P<TyPat>>, + ThinVec<Box<Pat>>, + ThinVec<Box<Ty>>, + ThinVec<Box<TyPat>>, ); // This macro generates `impl Visitable` and `impl MutVisitable` that forward to `Walkable` @@ -676,11 +675,11 @@ macro_rules! common_visitor_and_walkers { // Do nothing. } - fn flat_map_foreign_item(&mut self, ni: P<ForeignItem>) -> SmallVec<[P<ForeignItem>; 1]> { + fn flat_map_foreign_item(&mut self, ni: Box<ForeignItem>) -> SmallVec<[Box<ForeignItem>; 1]> { walk_flat_map_foreign_item(self, ni) } - fn flat_map_item(&mut self, i: P<Item>) -> SmallVec<[P<Item>; 1]> { + fn flat_map_item(&mut self, i: Box<Item>) -> SmallVec<[Box<Item>; 1]> { walk_flat_map_item(self, i) } @@ -690,9 +689,9 @@ macro_rules! common_visitor_and_walkers { fn flat_map_assoc_item( &mut self, - i: P<AssocItem>, + i: Box<AssocItem>, ctxt: AssocCtxt, - ) -> SmallVec<[P<AssocItem>; 1]> { + ) -> SmallVec<[Box<AssocItem>; 1]> { walk_flat_map_assoc_item(self, i, ctxt) } @@ -704,7 +703,7 @@ macro_rules! common_visitor_and_walkers { walk_flat_map_arm(self, arm) } - fn filter_map_expr(&mut self, e: P<Expr>) -> Option<P<Expr>> { + fn filter_map_expr(&mut self, e: Box<Expr>) -> Option<Box<Expr>> { walk_filter_map_expr(self, e) } @@ -930,8 +929,13 @@ macro_rules! common_visitor_and_walkers { } impl_walkable!(|&$($mut)? $($lt)? self: Impl, vis: &mut V| { - let Impl { defaultness, safety, generics, constness, polarity, of_trait, self_ty, items } = self; - visit_visitable!($($mut)? vis, defaultness, safety, generics, constness, polarity, of_trait, self_ty); + let Impl { generics, of_trait, self_ty, items } = self; + try_visit!(vis.visit_generics(generics)); + if let Some(box of_trait) = of_trait { + let TraitImplHeader { defaultness, safety, constness, polarity, trait_ref } = of_trait; + visit_visitable!($($mut)? vis, defaultness, safety, constness, polarity, trait_ref); + } + try_visit!(vis.visit_ty(self_ty)); visit_visitable_with!($($mut)? vis, items, AssocCtxt::Impl { of_trait: of_trait.is_some() }); V::Result::output() }); @@ -1144,15 +1148,15 @@ macro_rules! generate_list_visit_fns { } generate_list_visit_fns! { - visit_items, P<Item>, visit_item; - visit_foreign_items, P<ForeignItem>, visit_foreign_item; + visit_items, Box<Item>, visit_item; + visit_foreign_items, Box<ForeignItem>, visit_foreign_item; visit_generic_params, GenericParam, visit_generic_param; visit_stmts, Stmt, visit_stmt; - visit_exprs, P<Expr>, visit_expr; + visit_exprs, Box<Expr>, visit_expr; visit_expr_fields, ExprField, visit_expr_field; visit_pat_fields, PatField, visit_pat_field; visit_variants, Variant, visit_variant; - visit_assoc_items, P<AssocItem>, visit_assoc_item, ctxt: AssocCtxt; + visit_assoc_items, Box<AssocItem>, visit_assoc_item, ctxt: AssocCtxt; visit_where_predicates, WherePredicate, visit_where_predicate; visit_params, Param, visit_param; visit_field_defs, FieldDef, visit_field_def; diff --git a/compiler/rustc_ast_lowering/src/asm.rs b/compiler/rustc_ast_lowering/src/asm.rs index af279e07acc..d44faad017e 100644 --- a/compiler/rustc_ast_lowering/src/asm.rs +++ b/compiler/rustc_ast_lowering/src/asm.rs @@ -48,6 +48,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { | asm::InlineAsmArch::Arm64EC | asm::InlineAsmArch::RiscV32 | asm::InlineAsmArch::RiscV64 + | asm::InlineAsmArch::LoongArch32 | asm::InlineAsmArch::LoongArch64 | asm::InlineAsmArch::S390x ); diff --git a/compiler/rustc_ast_lowering/src/expr.rs b/compiler/rustc_ast_lowering/src/expr.rs index fb42cfea30b..2ddbf083a09 100644 --- a/compiler/rustc_ast_lowering/src/expr.rs +++ b/compiler/rustc_ast_lowering/src/expr.rs @@ -1,7 +1,6 @@ use std::ops::ControlFlow; use std::sync::Arc; -use rustc_ast::ptr::P as AstP; use rustc_ast::*; use rustc_ast_pretty::pprust::expr_to_string; use rustc_data_structures::stack::ensure_sufficient_stack; @@ -53,7 +52,7 @@ impl<'v> rustc_ast::visit::Visitor<'v> for WillCreateDefIdsVisitor { } impl<'hir> LoweringContext<'_, 'hir> { - fn lower_exprs(&mut self, exprs: &[AstP<Expr>]) -> &'hir [hir::Expr<'hir>] { + fn lower_exprs(&mut self, exprs: &[Box<Expr>]) -> &'hir [hir::Expr<'hir>] { self.arena.alloc_from_iter(exprs.iter().map(|x| self.lower_expr_mut(x))) } @@ -455,7 +454,7 @@ impl<'hir> LoweringContext<'_, 'hir> { fn lower_legacy_const_generics( &mut self, mut f: Expr, - args: ThinVec<AstP<Expr>>, + args: ThinVec<Box<Expr>>, legacy_args_idx: &[usize], ) -> hir::ExprKind<'hir> { let ExprKind::Path(None, path) = &mut f.kind else { @@ -495,7 +494,7 @@ impl<'hir> LoweringContext<'_, 'hir> { self.create_def(node_id, None, DefKind::AnonConst, f.span); let mut visitor = WillCreateDefIdsVisitor {}; let const_value = if let ControlFlow::Break(span) = visitor.visit_expr(&arg) { - AstP(Expr { + Box::new(Expr { id: self.next_node_id(), kind: ExprKind::Err(invalid_expr_error(self.tcx, span)), span: f.span, @@ -516,7 +515,7 @@ impl<'hir> LoweringContext<'_, 'hir> { // Add generic args to the last element of the path. let last_segment = path.segments.last_mut().unwrap(); assert!(last_segment.args.is_none()); - last_segment.args = Some(AstP(GenericArgs::AngleBracketed(AngleBracketedArgs { + last_segment.args = Some(Box::new(GenericArgs::AngleBracketed(AngleBracketedArgs { span: DUMMY_SP, args: generic_args, }))); @@ -812,7 +811,7 @@ impl<'hir> LoweringContext<'_, 'hir> { self.lower_attrs( inner_hir_id, &[Attribute { - kind: AttrKind::Normal(ptr::P(NormalAttr::from_ident(Ident::new( + kind: AttrKind::Normal(Box::new(NormalAttr::from_ident(Ident::new( sym::track_caller, span, )))), @@ -1285,7 +1284,7 @@ impl<'hir> LoweringContext<'_, 'hir> { fn extract_tuple_struct_path<'a>( &mut self, expr: &'a Expr, - ) -> Option<(&'a Option<AstP<QSelf>>, &'a Path)> { + ) -> Option<(&'a Option<Box<QSelf>>, &'a Path)> { if let ExprKind::Path(qself, path) = &expr.kind { // Does the path resolve to something disallowed in a tuple struct/variant pattern? if let Some(partial_res) = self.resolver.get_partial_res(expr.id) { @@ -1307,7 +1306,7 @@ impl<'hir> LoweringContext<'_, 'hir> { fn extract_unit_struct_path<'a>( &mut self, expr: &'a Expr, - ) -> Option<(&'a Option<AstP<QSelf>>, &'a Path)> { + ) -> Option<(&'a Option<Box<QSelf>>, &'a Path)> { if let ExprKind::Path(qself, path) = &expr.kind { // Does the path resolve to something disallowed in a unit struct/variant pattern? if let Some(partial_res) = self.resolver.get_partial_res(expr.id) { @@ -1478,7 +1477,7 @@ impl<'hir> LoweringContext<'_, 'hir> { /// Each sub-assignment is recorded in `assignments`. fn destructure_sequence( &mut self, - elements: &[AstP<Expr>], + elements: &[Box<Expr>], ctx: &str, eq_sign_span: Span, assignments: &mut Vec<hir::Stmt<'hir>>, diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index 9f54af57528..235573c96e4 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -1,5 +1,4 @@ use rustc_abi::ExternAbi; -use rustc_ast::ptr::P; use rustc_ast::visit::AssocCtxt; use rustc_ast::*; use rustc_errors::{E0570, ErrorGuaranteed, struct_span_code_err}; @@ -102,7 +101,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> { impl<'hir> LoweringContext<'_, 'hir> { pub(super) fn lower_mod( &mut self, - items: &[P<Item>], + items: &[Box<Item>], spans: &ModSpans, ) -> &'hir hir::Mod<'hir> { self.arena.alloc(hir::Mod { @@ -341,13 +340,9 @@ impl<'hir> LoweringContext<'_, 'hir> { ); hir::ItemKind::Union(ident, generics, vdata) } - ItemKind::Impl(box Impl { - safety, - polarity, - defaultness, - constness, + ItemKind::Impl(Impl { generics: ast_generics, - of_trait: trait_ref, + of_trait, self_ty: ty, items: impl_items, }) => { @@ -365,54 +360,30 @@ impl<'hir> LoweringContext<'_, 'hir> { // lifetime to be added, but rather a reference to a // parent lifetime. let itctx = ImplTraitContext::Universal; - let (generics, (trait_ref, lowered_ty)) = + let (generics, (of_trait, lowered_ty)) = self.lower_generics(ast_generics, id, itctx, |this| { - let modifiers = TraitBoundModifiers { - constness: BoundConstness::Never, - asyncness: BoundAsyncness::Normal, - // we don't use this in bound lowering - polarity: BoundPolarity::Positive, - }; - - let trait_ref = trait_ref.as_ref().map(|trait_ref| { - this.lower_trait_ref( - modifiers, - trait_ref, - ImplTraitContext::Disallowed(ImplTraitPosition::Trait), - ) - }); + let of_trait = of_trait + .as_deref() + .map(|of_trait| this.lower_trait_impl_header(of_trait)); let lowered_ty = this.lower_ty( ty, ImplTraitContext::Disallowed(ImplTraitPosition::ImplSelf), ); - (trait_ref, lowered_ty) + (of_trait, lowered_ty) }); let new_impl_items = self .arena .alloc_from_iter(impl_items.iter().map(|item| self.lower_impl_item_ref(item))); - // `defaultness.has_value()` is never called for an `impl`, always `true` in order - // to not cause an assertion failure inside the `lower_defaultness` function. - let has_val = true; - let (defaultness, defaultness_span) = self.lower_defaultness(*defaultness, has_val); - let polarity = match polarity { - ImplPolarity::Positive => ImplPolarity::Positive, - ImplPolarity::Negative(s) => ImplPolarity::Negative(self.lower_span(*s)), - }; - hir::ItemKind::Impl(self.arena.alloc(hir::Impl { - constness: self.lower_constness(*constness), - safety: self.lower_safety(*safety, hir::Safety::Safe), - polarity, - defaultness, - defaultness_span, + hir::ItemKind::Impl(hir::Impl { generics, - of_trait: trait_ref, + of_trait, self_ty: lowered_ty, items: new_impl_items, - })) + }) } ItemKind::Trait(box Trait { constness, @@ -462,7 +433,7 @@ impl<'hir> LoweringContext<'_, 'hir> { } ItemKind::MacroDef(ident, MacroDef { body, macro_rules }) => { let ident = self.lower_ident(*ident); - let body = P(self.lower_delim_args(body)); + let body = Box::new(self.lower_delim_args(body)); let def_id = self.local_def_id(id); let def_kind = self.tcx.def_kind(def_id); let DefKind::Macro(macro_kind) = def_kind else { @@ -983,6 +954,44 @@ impl<'hir> LoweringContext<'_, 'hir> { self.expr(span, hir::ExprKind::Err(guar)) } + fn lower_trait_impl_header( + &mut self, + trait_impl_header: &TraitImplHeader, + ) -> &'hir hir::TraitImplHeader<'hir> { + let TraitImplHeader { constness, safety, polarity, defaultness, ref trait_ref } = + *trait_impl_header; + let constness = self.lower_constness(constness); + let safety = self.lower_safety(safety, hir::Safety::Safe); + let polarity = match polarity { + ImplPolarity::Positive => ImplPolarity::Positive, + ImplPolarity::Negative(s) => ImplPolarity::Negative(self.lower_span(s)), + }; + // `defaultness.has_value()` is never called for an `impl`, always `true` in order + // to not cause an assertion failure inside the `lower_defaultness` function. + let has_val = true; + let (defaultness, defaultness_span) = self.lower_defaultness(defaultness, has_val); + let modifiers = TraitBoundModifiers { + constness: BoundConstness::Never, + asyncness: BoundAsyncness::Normal, + // we don't use this in bound lowering + polarity: BoundPolarity::Positive, + }; + let trait_ref = self.lower_trait_ref( + modifiers, + trait_ref, + ImplTraitContext::Disallowed(ImplTraitPosition::Trait), + ); + + self.arena.alloc(hir::TraitImplHeader { + constness, + safety, + polarity, + defaultness, + defaultness_span, + trait_ref, + }) + } + fn lower_impl_item( &mut self, i: &AssocItem, diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index d097e3cbaa8..465d9dc82bc 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -296,6 +296,7 @@ enum RelaxedBoundPolicy<'a> { enum RelaxedBoundForbiddenReason { TraitObjectTy, SuperTrait, + AssocTyBounds, LateBoundVarsInScope, } @@ -1109,9 +1110,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { &*self.arena.alloc(self.ty(constraint.span, hir::TyKind::Err(guar))); hir::AssocItemConstraintKind::Equality { term: err_ty.into() } } else { - // FIXME(#135229): These should be forbidden! - let bounds = - self.lower_param_bounds(bounds, RelaxedBoundPolicy::Allowed, itctx); + let bounds = self.lower_param_bounds( + bounds, + RelaxedBoundPolicy::Forbidden(RelaxedBoundForbiddenReason::AssocTyBounds), + itctx, + ); hir::AssocItemConstraintKind::Bound { bounds } } } @@ -1217,7 +1220,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { fn lower_path_ty( &mut self, t: &Ty, - qself: &Option<ptr::P<QSelf>>, + qself: &Option<Box<QSelf>>, path: &Path, param_mode: ParamMode, itctx: ImplTraitContext, @@ -2124,7 +2127,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { diag.emit(); return; } - RelaxedBoundForbiddenReason::LateBoundVarsInScope => {} + RelaxedBoundForbiddenReason::AssocTyBounds + | RelaxedBoundForbiddenReason::LateBoundVarsInScope => {} }; } } diff --git a/compiler/rustc_ast_lowering/src/pat.rs b/compiler/rustc_ast_lowering/src/pat.rs index e4440621048..b6533060a76 100644 --- a/compiler/rustc_ast_lowering/src/pat.rs +++ b/compiler/rustc_ast_lowering/src/pat.rs @@ -1,6 +1,5 @@ use std::sync::Arc; -use rustc_ast::ptr::P; use rustc_ast::*; use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_hir::def::{DefKind, Res}; @@ -154,7 +153,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { fn lower_pat_tuple( &mut self, - pats: &[P<Pat>], + pats: &[Box<Pat>], ctx: &str, ) -> (&'hir [hir::Pat<'hir>], hir::DotDotPos) { let mut elems = Vec::with_capacity(pats.len()); @@ -209,7 +208,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { /// When encountering `($binding_mode $ident @)? ..` (`slice`), /// this is interpreted as a sub-slice pattern semantically. /// Patterns that follow, which are not like `slice` -- or an error occurs, are in `after`. - fn lower_pat_slice(&mut self, pats: &[P<Pat>]) -> hir::PatKind<'hir> { + fn lower_pat_slice(&mut self, pats: &[Box<Pat>]) -> hir::PatKind<'hir> { let mut before = Vec::new(); let mut after = Vec::new(); let mut slice = None; diff --git a/compiler/rustc_ast_lowering/src/path.rs b/compiler/rustc_ast_lowering/src/path.rs index c80ef275c80..3322e0fb66b 100644 --- a/compiler/rustc_ast_lowering/src/path.rs +++ b/compiler/rustc_ast_lowering/src/path.rs @@ -24,7 +24,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { pub(crate) fn lower_qpath( &mut self, id: NodeId, - qself: &Option<ptr::P<QSelf>>, + qself: &Option<Box<QSelf>>, p: &Path, param_mode: ParamMode, allow_return_type_notation: AllowReturnTypeNotation, diff --git a/compiler/rustc_ast_passes/messages.ftl b/compiler/rustc_ast_passes/messages.ftl index 53e64439afc..340a1a239c5 100644 --- a/compiler/rustc_ast_passes/messages.ftl +++ b/compiler/rustc_ast_passes/messages.ftl @@ -175,11 +175,6 @@ ast_passes_generic_default_trailing = generic parameters with a default must be ast_passes_incompatible_features = `{$f1}` and `{$f2}` are incompatible, using them at the same time is not allowed .help = remove one of these features -ast_passes_inherent_cannot_be = inherent impls cannot be {$annotation} - .because = {$annotation} because of this - .type = inherent impl for this type - .only_trait = only trait implementations may be annotated with {$annotation} - ast_passes_item_invalid_safety = items outside of `unsafe extern {"{ }"}` cannot be declared with `safe` safety qualifier .suggestion = remove safe from this item diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index 1c1c5f82f3e..dc2eb17589c 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -22,7 +22,6 @@ use std::str::FromStr; use itertools::{Either, Itertools}; use rustc_abi::{CanonAbi, ExternAbi, InterruptKind}; -use rustc_ast::ptr::P; use rustc_ast::visit::{AssocCtxt, BoundKind, FnCtxt, FnKind, Visitor, walk_list}; use rustc_ast::*; use rustc_ast_pretty::pprust::{self, State}; @@ -719,7 +718,7 @@ impl<'a> AstValidator<'a> { } } - fn deny_items(&self, trait_items: &[P<AssocItem>], ident_span: Span) { + fn deny_items(&self, trait_items: &[Box<AssocItem>], ident_span: Span) { if !trait_items.is_empty() { let spans: Vec<_> = trait_items.iter().map(|i| i.kind.ident().unwrap().span).collect(); let total = trait_items.first().unwrap().span.to(trait_items.last().unwrap().span); @@ -955,13 +954,16 @@ impl<'a> Visitor<'a> for AstValidator<'a> { } match &item.kind { - ItemKind::Impl(box Impl { - safety, - polarity, - defaultness: _, - constness, + ItemKind::Impl(Impl { generics, - of_trait: Some(t), + of_trait: + Some(box TraitImplHeader { + safety, + polarity, + defaultness: _, + constness, + trait_ref: t, + }), self_ty, items, }) => { @@ -993,46 +995,12 @@ impl<'a> Visitor<'a> for AstValidator<'a> { walk_list!(this, visit_assoc_item, items, AssocCtxt::Impl { of_trait: true }); }); } - ItemKind::Impl(box Impl { - safety, - polarity, - defaultness, - constness, - generics, - of_trait: None, - self_ty, - items, - }) => { - let error = |annotation_span, annotation, only_trait| errors::InherentImplCannot { - span: self_ty.span, - annotation_span, - annotation, - self_ty: self_ty.span, - only_trait, - }; - + ItemKind::Impl(Impl { generics, of_trait: None, self_ty, items }) => { self.visit_attrs_vis(&item.attrs, &item.vis); self.visibility_not_permitted( &item.vis, errors::VisibilityNotPermittedNote::IndividualImplItems, ); - if let &Safety::Unsafe(span) = safety { - self.dcx().emit_err(errors::InherentImplCannotUnsafe { - span: self_ty.span, - annotation_span: span, - annotation: "unsafe", - self_ty: self_ty.span, - }); - } - if let &ImplPolarity::Negative(span) = polarity { - self.dcx().emit_err(error(span, "negative", false)); - } - if let &Defaultness::Default(def_span) = defaultness { - self.dcx().emit_err(error(def_span, "`default`", true)); - } - if let &Const::Yes(span) = constness { - self.dcx().emit_err(error(span, "`const`", true)); - } self.with_tilde_const(Some(TildeConstReason::Impl { span: item.span }), |this| { this.visit_generics(generics) diff --git a/compiler/rustc_ast_passes/src/errors.rs b/compiler/rustc_ast_passes/src/errors.rs index 60f47490f12..1cb2493afe8 100644 --- a/compiler/rustc_ast_passes/src/errors.rs +++ b/compiler/rustc_ast_passes/src/errors.rs @@ -465,32 +465,6 @@ pub(crate) struct UnsafeNegativeImpl { } #[derive(Diagnostic)] -#[diag(ast_passes_inherent_cannot_be)] -pub(crate) struct InherentImplCannot<'a> { - #[primary_span] - pub span: Span, - #[label(ast_passes_because)] - pub annotation_span: Span, - pub annotation: &'a str, - #[label(ast_passes_type)] - pub self_ty: Span, - #[note(ast_passes_only_trait)] - pub only_trait: bool, -} - -#[derive(Diagnostic)] -#[diag(ast_passes_inherent_cannot_be, code = E0197)] -pub(crate) struct InherentImplCannotUnsafe<'a> { - #[primary_span] - pub span: Span, - #[label(ast_passes_because)] - pub annotation_span: Span, - pub annotation: &'a str, - #[label(ast_passes_type)] - pub self_ty: Span, -} - -#[derive(Diagnostic)] #[diag(ast_passes_unsafe_item)] pub(crate) struct UnsafeItem { #[primary_span] diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index 662357ce884..c9344a76a7b 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -217,18 +217,18 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { } } - ast::ItemKind::Impl(box ast::Impl { polarity, defaultness, of_trait, .. }) => { - if let &ast::ImplPolarity::Negative(span) = polarity { + ast::ItemKind::Impl(ast::Impl { of_trait: Some(of_trait), .. }) => { + if let ast::ImplPolarity::Negative(span) = of_trait.polarity { gate!( &self, negative_impls, - span.to(of_trait.as_ref().map_or(span, |t| t.path.span)), + span.to(of_trait.trait_ref.path.span), "negative trait bounds are not fully implemented; \ use marker types for now" ); } - if let ast::Defaultness::Default(_) = defaultness { + if let ast::Defaultness::Default(_) = of_trait.defaultness { gate!(&self, specialization, i.span, "specialization is unstable"); } } diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index f0cf0c1487f..85f76036df7 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -10,7 +10,6 @@ use std::borrow::Cow; use std::sync::Arc; use rustc_ast::attr::AttrIdGenerator; -use rustc_ast::ptr::P; use rustc_ast::token::{self, CommentKind, Delimiter, IdentIsRaw, Token, TokenKind}; use rustc_ast::tokenstream::{Spacing, TokenStream, TokenTree}; use rustc_ast::util::classify; @@ -1178,7 +1177,7 @@ impl<'a> State<'a> { self.end(rb); } - fn commasep_exprs(&mut self, b: Breaks, exprs: &[P<ast::Expr>]) { + fn commasep_exprs(&mut self, b: Breaks, exprs: &[Box<ast::Expr>]) { self.commasep_cmnt(b, exprs, |s, e| s.print_expr(e, FixupContext::default()), |e| e.span) } diff --git a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs index 8a2cb64b2a0..bdf73ac32f0 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state/expr.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state/expr.rs @@ -2,7 +2,6 @@ use std::fmt::Write; use ast::{ForLoopKind, MatchKind}; use itertools::{Itertools, Position}; -use rustc_ast::ptr::P; use rustc_ast::util::classify; use rustc_ast::util::literal::escape_byte_str_symbol; use rustc_ast::util::parser::{self, ExprPrecedence, Fixity}; @@ -54,7 +53,7 @@ impl<'a> State<'a> { self.print_else(elseopt) } - fn print_call_post(&mut self, args: &[P<ast::Expr>]) { + fn print_call_post(&mut self, args: &[Box<ast::Expr>]) { self.popen(); self.commasep_exprs(Inconsistent, args); self.pclose() @@ -111,7 +110,7 @@ impl<'a> State<'a> { } } - fn print_expr_vec(&mut self, exprs: &[P<ast::Expr>]) { + fn print_expr_vec(&mut self, exprs: &[Box<ast::Expr>]) { let ib = self.ibox(INDENT_UNIT); self.word("["); self.commasep_exprs(Inconsistent, exprs); @@ -149,7 +148,7 @@ impl<'a> State<'a> { fn print_expr_struct( &mut self, - qself: &Option<P<ast::QSelf>>, + qself: &Option<Box<ast::QSelf>>, path: &ast::Path, fields: &[ast::ExprField], rest: &ast::StructRest, @@ -204,7 +203,7 @@ impl<'a> State<'a> { self.word("}"); } - fn print_expr_tup(&mut self, exprs: &[P<ast::Expr>]) { + fn print_expr_tup(&mut self, exprs: &[Box<ast::Expr>]) { self.popen(); self.commasep_exprs(Inconsistent, exprs); if exprs.len() == 1 { @@ -213,7 +212,7 @@ impl<'a> State<'a> { self.pclose() } - fn print_expr_call(&mut self, func: &ast::Expr, args: &[P<ast::Expr>], fixup: FixupContext) { + fn print_expr_call(&mut self, func: &ast::Expr, args: &[Box<ast::Expr>], fixup: FixupContext) { // Independent of parenthesization related to precedence, we must // parenthesize `func` if this is a statement context in which without // parentheses, a statement boundary would occur inside `func` or @@ -247,7 +246,7 @@ impl<'a> State<'a> { &mut self, segment: &ast::PathSegment, receiver: &ast::Expr, - base_args: &[P<ast::Expr>], + base_args: &[Box<ast::Expr>], fixup: FixupContext, ) { // The fixup here is different than in `print_expr_call` because diff --git a/compiler/rustc_ast_pretty/src/pprust/state/item.rs b/compiler/rustc_ast_pretty/src/pprust/state/item.rs index 11c97a552c6..ab402cbb8dc 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state/item.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state/item.rs @@ -2,7 +2,6 @@ use ast::StaticItem; use itertools::{Itertools, Position}; use rustc_ast as ast; use rustc_ast::ModKind; -use rustc_ast::ptr::P; use rustc_span::Ident; use crate::pp::BoxMarker; @@ -309,39 +308,41 @@ impl<'a> State<'a> { let (cb, ib) = self.head(visibility_qualified(&item.vis, "union")); self.print_struct(struct_def, generics, *ident, item.span, true, cb, ib); } - ast::ItemKind::Impl(box ast::Impl { - safety, - polarity, - defaultness, - constness, - generics, - of_trait, - self_ty, - items, - }) => { + ast::ItemKind::Impl(ast::Impl { generics, of_trait, self_ty, items }) => { let (cb, ib) = self.head(""); self.print_visibility(&item.vis); - self.print_defaultness(*defaultness); - self.print_safety(*safety); - self.word("impl"); - - if generics.params.is_empty() { - self.nbsp(); - } else { - self.print_generic_params(&generics.params); - self.space(); - } - self.print_constness(*constness); + let impl_generics = |this: &mut Self| { + this.word("impl"); - if let ast::ImplPolarity::Negative(_) = polarity { - self.word("!"); - } - - if let Some(t) = of_trait { - self.print_trait_ref(t); + if generics.params.is_empty() { + this.nbsp(); + } else { + this.print_generic_params(&generics.params); + this.space(); + } + }; + + if let Some(box of_trait) = of_trait { + let ast::TraitImplHeader { + defaultness, + safety, + constness, + polarity, + ref trait_ref, + } = *of_trait; + self.print_defaultness(defaultness); + self.print_safety(safety); + impl_generics(self); + self.print_constness(constness); + if let ast::ImplPolarity::Negative(_) = polarity { + self.word("!"); + } + self.print_trait_ref(trait_ref); self.space(); self.word_space("for"); + } else { + impl_generics(self); } self.print_type(self_ty); @@ -628,10 +629,10 @@ impl<'a> State<'a> { &mut self, attrs: &[ast::Attribute], vis: &ast::Visibility, - qself: &Option<P<ast::QSelf>>, + qself: &Option<Box<ast::QSelf>>, path: &ast::Path, kind: DelegationKind<'_>, - body: &Option<P<ast::Block>>, + body: &Option<Box<ast::Block>>, ) { let body_cb_ib = body.as_ref().map(|body| (body, self.head(""))); self.print_visibility(vis); diff --git a/compiler/rustc_attr_parsing/messages.ftl b/compiler/rustc_attr_parsing/messages.ftl index 35ff48cb5f2..de22ea322c7 100644 --- a/compiler/rustc_attr_parsing/messages.ftl +++ b/compiler/rustc_attr_parsing/messages.ftl @@ -132,6 +132,7 @@ attr_parsing_unknown_version_literal = attr_parsing_unrecognized_repr_hint = unrecognized representation hint .help = valid reprs are `Rust` (default), `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize` + .note = for more information, visit <https://doc.rust-lang.org/reference/type-layout.html?highlight=repr#representations> attr_parsing_unstable_cfg_target_compact = compact `cfg(target(..))` is experimental and subject to change diff --git a/compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs b/compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs index 95104b896ac..b3393e93de8 100644 --- a/compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs +++ b/compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs @@ -15,7 +15,7 @@ impl<S: Stage> CombineAttributeParser<S> for AllowInternalUnstableParser { type Item = (Symbol, Span); const CONVERT: ConvertFn<Self::Item> = |items, span| AttributeKind::AllowInternalUnstable(items, span); - const TEMPLATE: AttributeTemplate = template!(Word, List: "feat1, feat2, ..."); + const TEMPLATE: AttributeTemplate = template!(Word, List: &["feat1, feat2, ..."]); fn extend<'c>( cx: &'c mut AcceptContext<'_, '_, S>, @@ -32,7 +32,7 @@ impl<S: Stage> CombineAttributeParser<S> for UnstableFeatureBoundParser { const PATH: &'static [rustc_span::Symbol] = &[sym::unstable_feature_bound]; type Item = (Symbol, Span); const CONVERT: ConvertFn<Self::Item> = |items, _| AttributeKind::UnstableFeatureBound(items); - const TEMPLATE: AttributeTemplate = template!(Word, List: "feat1, feat2, ..."); + const TEMPLATE: AttributeTemplate = template!(Word, List: &["feat1, feat2, ..."]); fn extend<'c>( cx: &'c mut AcceptContext<'_, '_, S>, @@ -53,7 +53,7 @@ impl<S: Stage> CombineAttributeParser<S> for AllowConstFnUnstableParser { type Item = Symbol; const CONVERT: ConvertFn<Self::Item> = |items, first_span| AttributeKind::AllowConstFnUnstable(items, first_span); - const TEMPLATE: AttributeTemplate = template!(Word, List: "feat1, feat2, ..."); + const TEMPLATE: AttributeTemplate = template!(Word, List: &["feat1, feat2, ..."]); fn extend<'c>( cx: &'c mut AcceptContext<'_, '_, S>, diff --git a/compiler/rustc_attr_parsing/src/attributes/cfg.rs b/compiler/rustc_attr_parsing/src/attributes/cfg.rs index 947be28bc95..695ee666476 100644 --- a/compiler/rustc_attr_parsing/src/attributes/cfg.rs +++ b/compiler/rustc_attr_parsing/src/attributes/cfg.rs @@ -16,7 +16,10 @@ use crate::{ CfgMatchesLintEmitter, fluent_generated, parse_version, session_diagnostics, try_gate_cfg, }; -pub const CFG_TEMPLATE: AttributeTemplate = template!(List: "predicate"); +pub const CFG_TEMPLATE: AttributeTemplate = template!( + List: &["predicate"], + "https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute" +); pub fn parse_cfg_attr<'c, S: Stage>( cx: &'c mut AcceptContext<'_, '_, S>, diff --git a/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs index c5fb11dbf6a..a9f77195d1b 100644 --- a/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs +++ b/compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs @@ -17,7 +17,7 @@ impl<S: Stage> SingleAttributeParser<S> for OptimizeParser { const PATH: &[Symbol] = &[sym::optimize]; const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost; const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError; - const TEMPLATE: AttributeTemplate = template!(List: "size|speed|none"); + const TEMPLATE: AttributeTemplate = template!(List: &["size", "speed", "none"]); fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> { let Some(list) = args.list() else { @@ -253,7 +253,7 @@ pub(crate) struct UsedParser { impl<S: Stage> AttributeParser<S> for UsedParser { const ATTRIBUTES: AcceptMapping<Self, S> = &[( &[sym::used], - template!(Word, List: "compiler|linker"), + template!(Word, List: &["compiler", "linker"]), |group: &mut Self, cx, args| { let used_by = match args { ArgParser::NoArgs => UsedBy::Linker, @@ -327,7 +327,7 @@ impl<S: Stage> CombineAttributeParser<S> for TargetFeatureParser { type Item = (Symbol, Span); const PATH: &[Symbol] = &[sym::target_feature]; const CONVERT: ConvertFn<Self::Item> = |items, span| AttributeKind::TargetFeature(items, span); - const TEMPLATE: AttributeTemplate = template!(List: "enable = \"feat1, feat2\""); + const TEMPLATE: AttributeTemplate = template!(List: &["enable = \"feat1, feat2\""]); fn extend<'c>( cx: &'c mut AcceptContext<'_, '_, S>, diff --git a/compiler/rustc_attr_parsing/src/attributes/confusables.rs b/compiler/rustc_attr_parsing/src/attributes/confusables.rs index 7d24c89a6e8..edd22172ca2 100644 --- a/compiler/rustc_attr_parsing/src/attributes/confusables.rs +++ b/compiler/rustc_attr_parsing/src/attributes/confusables.rs @@ -16,7 +16,7 @@ pub(crate) struct ConfusablesParser { impl<S: Stage> AttributeParser<S> for ConfusablesParser { const ATTRIBUTES: AcceptMapping<Self, S> = &[( &[sym::rustc_confusables], - template!(List: r#""name1", "name2", ..."#), + template!(List: &[r#""name1", "name2", ..."#]), |this, cx, args| { let Some(list) = args.list() else { cx.expected_list(cx.attr_span); diff --git a/compiler/rustc_attr_parsing/src/attributes/deprecation.rs b/compiler/rustc_attr_parsing/src/attributes/deprecation.rs index 38ec4bd5645..e57ea8bbb5c 100644 --- a/compiler/rustc_attr_parsing/src/attributes/deprecation.rs +++ b/compiler/rustc_attr_parsing/src/attributes/deprecation.rs @@ -40,7 +40,7 @@ impl<S: Stage> SingleAttributeParser<S> for DeprecationParser { const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error; const TEMPLATE: AttributeTemplate = template!( Word, - List: r#"/*opt*/ since = "version", /*opt*/ note = "reason""#, + List: &[r#"since = "version""#, r#"note = "reason""#, r#"since = "version", note = "reason""#], NameValueStr: "reason" ); diff --git a/compiler/rustc_attr_parsing/src/attributes/inline.rs b/compiler/rustc_attr_parsing/src/attributes/inline.rs index 8437713206e..e9a45f20bff 100644 --- a/compiler/rustc_attr_parsing/src/attributes/inline.rs +++ b/compiler/rustc_attr_parsing/src/attributes/inline.rs @@ -18,7 +18,11 @@ impl<S: Stage> SingleAttributeParser<S> for InlineParser { const PATH: &'static [Symbol] = &[sym::inline]; const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost; const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError; - const TEMPLATE: AttributeTemplate = template!(Word, List: "always|never"); + const TEMPLATE: AttributeTemplate = template!( + Word, + List: &["always", "never"], + "https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute" + ); fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> { match args { @@ -59,7 +63,7 @@ impl<S: Stage> SingleAttributeParser<S> for RustcForceInlineParser { const PATH: &'static [Symbol] = &[sym::rustc_force_inline]; const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost; const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError; - const TEMPLATE: AttributeTemplate = template!(Word, List: "reason", NameValueStr: "reason"); + const TEMPLATE: AttributeTemplate = template!(Word, List: &["reason"], NameValueStr: "reason"); fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> { let reason = match args { diff --git a/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs index 7eab3090870..d406c30b83e 100644 --- a/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs +++ b/compiler/rustc_attr_parsing/src/attributes/link_attrs.rs @@ -16,7 +16,10 @@ impl<S: Stage> SingleAttributeParser<S> for LinkNameParser { const PATH: &[Symbol] = &[sym::link_name]; const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost; const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError; - const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name"); + const TEMPLATE: AttributeTemplate = template!( + NameValueStr: "name", + "https://doc.rust-lang.org/reference/items/external-blocks.html#the-link_name-attribute" + ); fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> { let Some(nv) = args.name_value() else { @@ -38,7 +41,10 @@ impl<S: Stage> SingleAttributeParser<S> for LinkSectionParser { const PATH: &[Symbol] = &[sym::link_section]; const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost; const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError; - const TEMPLATE: AttributeTemplate = template!(NameValueStr: "name"); + const TEMPLATE: AttributeTemplate = template!( + NameValueStr: "name", + "https://doc.rust-lang.org/reference/abi.html#the-link_section-attribute" + ); fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> { let Some(nv) = args.name_value() else { @@ -94,7 +100,10 @@ impl<S: Stage> SingleAttributeParser<S> for LinkOrdinalParser { const PATH: &[Symbol] = &[sym::link_ordinal]; const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost; const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error; - const TEMPLATE: AttributeTemplate = template!(List: "ordinal"); + const TEMPLATE: AttributeTemplate = template!( + List: &["ordinal"], + "https://doc.rust-lang.org/reference/items/external-blocks.html#the-link_ordinal-attribute" + ); fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> { let ordinal = parse_single_integer(cx, args)?; diff --git a/compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs index 886f7a889d3..a1166bf9ac5 100644 --- a/compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs +++ b/compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs @@ -31,7 +31,10 @@ pub(crate) struct MacroUseParser { first_span: Option<Span>, } -const MACRO_USE_TEMPLATE: AttributeTemplate = template!(Word, List: "name1, name2, ..."); +const MACRO_USE_TEMPLATE: AttributeTemplate = template!( + Word, List: &["name1, name2, ..."], + "https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute" +); impl<S: Stage> AttributeParser<S> for MacroUseParser { const ATTRIBUTES: AcceptMapping<Self, S> = &[( @@ -113,3 +116,11 @@ impl<S: Stage> AttributeParser<S> for MacroUseParser { Some(AttributeKind::MacroUse { span: self.first_span?, arguments: self.state }) } } + +pub(crate) struct AllowInternalUnsafeParser; + +impl<S: Stage> NoArgsAttributeParser<S> for AllowInternalUnsafeParser { + const PATH: &[Symbol] = &[sym::allow_internal_unsafe]; + const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Ignore; + const CREATE: fn(Span) -> AttributeKind = |span| AttributeKind::AllowInternalUnsafe(span); +} diff --git a/compiler/rustc_attr_parsing/src/attributes/must_use.rs b/compiler/rustc_attr_parsing/src/attributes/must_use.rs index d767abbc250..c88bb5a69e5 100644 --- a/compiler/rustc_attr_parsing/src/attributes/must_use.rs +++ b/compiler/rustc_attr_parsing/src/attributes/must_use.rs @@ -14,7 +14,10 @@ impl<S: Stage> SingleAttributeParser<S> for MustUseParser { const PATH: &[Symbol] = &[sym::must_use]; const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost; const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError; - const TEMPLATE: AttributeTemplate = template!(Word, NameValueStr: "reason"); + const TEMPLATE: AttributeTemplate = template!( + Word, NameValueStr: "reason", + "https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute" + ); fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> { Some(AttributeKind::MustUse { diff --git a/compiler/rustc_attr_parsing/src/attributes/path.rs b/compiler/rustc_attr_parsing/src/attributes/path.rs index 5700d780d71..c1c3de8cbfc 100644 --- a/compiler/rustc_attr_parsing/src/attributes/path.rs +++ b/compiler/rustc_attr_parsing/src/attributes/path.rs @@ -12,7 +12,10 @@ impl<S: Stage> SingleAttributeParser<S> for PathParser { const PATH: &[Symbol] = &[sym::path]; const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost; const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError; - const TEMPLATE: AttributeTemplate = template!(NameValueStr: "file"); + const TEMPLATE: AttributeTemplate = template!( + NameValueStr: "file", + "https://doc.rust-lang.org/reference/items/modules.html#the-path-attribute" + ); fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> { let Some(nv) = args.name_value() else { diff --git a/compiler/rustc_attr_parsing/src/attributes/proc_macro_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/proc_macro_attrs.rs index b156a7c5845..b267980914c 100644 --- a/compiler/rustc_attr_parsing/src/attributes/proc_macro_attrs.rs +++ b/compiler/rustc_attr_parsing/src/attributes/proc_macro_attrs.rs @@ -28,8 +28,10 @@ impl<S: Stage> SingleAttributeParser<S> for ProcMacroDeriveParser { const PATH: &[Symbol] = &[sym::proc_macro_derive]; const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost; const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error; - const TEMPLATE: AttributeTemplate = - template!(List: "TraitName, /*opt*/ attributes(name1, name2, ...)"); + const TEMPLATE: AttributeTemplate = template!( + List: &["TraitName", "TraitName, attributes(name1, name2, ...)"], + "https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros" + ); fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> { let (trait_name, helper_attrs) = parse_derive_like(cx, args, true)?; @@ -47,7 +49,7 @@ impl<S: Stage> SingleAttributeParser<S> for RustcBuiltinMacroParser { const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost; const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error; const TEMPLATE: AttributeTemplate = - template!(List: "TraitName, /*opt*/ attributes(name1, name2, ...)"); + template!(List: &["TraitName", "TraitName, attributes(name1, name2, ...)"]); fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> { let (builtin_name, helper_attrs) = parse_derive_like(cx, args, false)?; diff --git a/compiler/rustc_attr_parsing/src/attributes/repr.rs b/compiler/rustc_attr_parsing/src/attributes/repr.rs index 6087afe6ded..996d2af5f37 100644 --- a/compiler/rustc_attr_parsing/src/attributes/repr.rs +++ b/compiler/rustc_attr_parsing/src/attributes/repr.rs @@ -26,8 +26,10 @@ impl<S: Stage> CombineAttributeParser<S> for ReprParser { const CONVERT: ConvertFn<Self::Item> = |items, first_span| AttributeKind::Repr { reprs: items, first_span }; // FIXME(jdonszelmann): never used - const TEMPLATE: AttributeTemplate = - template!(List: "C | Rust | align(...) | packed(...) | <integer type> | transparent"); + const TEMPLATE: AttributeTemplate = template!( + List: &["C", "Rust", "transparent", "align(...)", "packed(...)", "<integer type>"], + "https://doc.rust-lang.org/reference/type-layout.html#representations" + ); fn extend<'c>( cx: &'c mut AcceptContext<'_, '_, S>, @@ -275,7 +277,7 @@ pub(crate) struct AlignParser(Option<(Align, Span)>); impl AlignParser { const PATH: &'static [Symbol] = &[sym::rustc_align]; - const TEMPLATE: AttributeTemplate = template!(List: "<alignment in bytes>"); + const TEMPLATE: AttributeTemplate = template!(List: &["<alignment in bytes>"]); fn parse<'c, S: Stage>( &mut self, diff --git a/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs b/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs index b465d2e62ff..1a668b4416f 100644 --- a/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs +++ b/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs @@ -12,7 +12,7 @@ impl<S: Stage> SingleAttributeParser<S> for RustcLayoutScalarValidRangeStart { const PATH: &'static [Symbol] = &[sym::rustc_layout_scalar_valid_range_start]; const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost; const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error; - const TEMPLATE: AttributeTemplate = template!(List: "start"); + const TEMPLATE: AttributeTemplate = template!(List: &["start"]); fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> { parse_single_integer(cx, args) @@ -26,7 +26,7 @@ impl<S: Stage> SingleAttributeParser<S> for RustcLayoutScalarValidRangeEnd { const PATH: &'static [Symbol] = &[sym::rustc_layout_scalar_valid_range_end]; const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost; const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error; - const TEMPLATE: AttributeTemplate = template!(List: "end"); + const TEMPLATE: AttributeTemplate = template!(List: &["end"]); fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> { parse_single_integer(cx, args) diff --git a/compiler/rustc_attr_parsing/src/attributes/stability.rs b/compiler/rustc_attr_parsing/src/attributes/stability.rs index 3c4ec133d51..c6707f5048b 100644 --- a/compiler/rustc_attr_parsing/src/attributes/stability.rs +++ b/compiler/rustc_attr_parsing/src/attributes/stability.rs @@ -48,7 +48,7 @@ impl<S: Stage> AttributeParser<S> for StabilityParser { const ATTRIBUTES: AcceptMapping<Self, S> = &[ ( &[sym::stable], - template!(List: r#"feature = "name", since = "version""#), + template!(List: &[r#"feature = "name", since = "version""#]), |this, cx, args| { reject_outside_std!(cx); if !this.check_duplicate(cx) @@ -60,7 +60,7 @@ impl<S: Stage> AttributeParser<S> for StabilityParser { ), ( &[sym::unstable], - template!(List: r#"feature = "name", reason = "...", issue = "N""#), + template!(List: &[r#"feature = "name", reason = "...", issue = "N""#]), |this, cx, args| { reject_outside_std!(cx); if !this.check_duplicate(cx) @@ -131,7 +131,7 @@ pub(crate) struct BodyStabilityParser { impl<S: Stage> AttributeParser<S> for BodyStabilityParser { const ATTRIBUTES: AcceptMapping<Self, S> = &[( &[sym::rustc_default_body_unstable], - template!(List: r#"feature = "name", reason = "...", issue = "N""#), + template!(List: &[r#"feature = "name", reason = "...", issue = "N""#]), |this, cx, args| { reject_outside_std!(cx); if this.stability.is_some() { @@ -177,29 +177,37 @@ impl ConstStabilityParser { impl<S: Stage> AttributeParser<S> for ConstStabilityParser { const ATTRIBUTES: AcceptMapping<Self, S> = &[ - (&[sym::rustc_const_stable], template!(List: r#"feature = "name""#), |this, cx, args| { - reject_outside_std!(cx); + ( + &[sym::rustc_const_stable], + template!(List: &[r#"feature = "name""#]), + |this, cx, args| { + reject_outside_std!(cx); - if !this.check_duplicate(cx) - && let Some((feature, level)) = parse_stability(cx, args) - { - this.stability = Some(( - PartialConstStability { level, feature, promotable: false }, - cx.attr_span, - )); - } - }), - (&[sym::rustc_const_unstable], template!(List: r#"feature = "name""#), |this, cx, args| { - reject_outside_std!(cx); - if !this.check_duplicate(cx) - && let Some((feature, level)) = parse_unstability(cx, args) - { - this.stability = Some(( - PartialConstStability { level, feature, promotable: false }, - cx.attr_span, - )); - } - }), + if !this.check_duplicate(cx) + && let Some((feature, level)) = parse_stability(cx, args) + { + this.stability = Some(( + PartialConstStability { level, feature, promotable: false }, + cx.attr_span, + )); + } + }, + ), + ( + &[sym::rustc_const_unstable], + template!(List: &[r#"feature = "name""#]), + |this, cx, args| { + reject_outside_std!(cx); + if !this.check_duplicate(cx) + && let Some((feature, level)) = parse_unstability(cx, args) + { + this.stability = Some(( + PartialConstStability { level, feature, promotable: false }, + cx.attr_span, + )); + } + }, + ), (&[sym::rustc_promotable], template!(Word), |this, cx, _| { reject_outside_std!(cx); this.promotable = true; diff --git a/compiler/rustc_attr_parsing/src/attributes/test_attrs.rs b/compiler/rustc_attr_parsing/src/attributes/test_attrs.rs index 77b494328c7..3267855fb0d 100644 --- a/compiler/rustc_attr_parsing/src/attributes/test_attrs.rs +++ b/compiler/rustc_attr_parsing/src/attributes/test_attrs.rs @@ -13,7 +13,10 @@ impl<S: Stage> SingleAttributeParser<S> for IgnoreParser { const PATH: &[Symbol] = &[sym::ignore]; const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost; const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn; - const TEMPLATE: AttributeTemplate = template!(Word, NameValueStr: "reason"); + const TEMPLATE: AttributeTemplate = template!( + Word, NameValueStr: "reason", + "https://doc.rust-lang.org/reference/attributes/testing.html#the-ignore-attribute" + ); fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> { Some(AttributeKind::Ignore { @@ -51,8 +54,10 @@ impl<S: Stage> SingleAttributeParser<S> for ShouldPanicParser { const PATH: &[Symbol] = &[sym::should_panic]; const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost; const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError; - const TEMPLATE: AttributeTemplate = - template!(Word, List: r#"expected = "reason""#, NameValueStr: "reason"); + const TEMPLATE: AttributeTemplate = template!( + Word, List: &[r#"expected = "reason""#], NameValueStr: "reason", + "https://doc.rust-lang.org/reference/attributes/testing.html#the-should_panic-attribute" + ); fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> { Some(AttributeKind::ShouldPanic { diff --git a/compiler/rustc_attr_parsing/src/attributes/traits.rs b/compiler/rustc_attr_parsing/src/attributes/traits.rs index a954617ca57..8514d799aa4 100644 --- a/compiler/rustc_attr_parsing/src/attributes/traits.rs +++ b/compiler/rustc_attr_parsing/src/attributes/traits.rs @@ -16,7 +16,7 @@ impl<S: Stage> SingleAttributeParser<S> for SkipDuringMethodDispatchParser { const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost; const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error; - const TEMPLATE: AttributeTemplate = template!(List: "array, boxed_slice"); + const TEMPLATE: AttributeTemplate = template!(List: &["array, boxed_slice"]); fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> { let mut array = false; diff --git a/compiler/rustc_attr_parsing/src/attributes/transparency.rs b/compiler/rustc_attr_parsing/src/attributes/transparency.rs index 1c57dc1ebe2..d4d68eb8b27 100644 --- a/compiler/rustc_attr_parsing/src/attributes/transparency.rs +++ b/compiler/rustc_attr_parsing/src/attributes/transparency.rs @@ -19,7 +19,7 @@ impl<S: Stage> SingleAttributeParser<S> for TransparencyParser { cx.dcx().span_err(vec![used, unused], "multiple macro transparency attributes"); }); const TEMPLATE: AttributeTemplate = - template!(NameValueStr: "transparent|semitransparent|opaque"); + template!(NameValueStr: ["transparent", "semitransparent", "opaque"]); fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> { let Some(nv) = args.name_value() else { diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index 80dfdffdb55..1420753a44e 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -33,7 +33,9 @@ use crate::attributes::lint_helpers::{ AsPtrParser, AutomaticallyDerivedParser, PassByValueParser, PubTransparentParser, }; use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser}; -use crate::attributes::macro_attrs::{MacroEscapeParser, MacroUseParser}; +use crate::attributes::macro_attrs::{ + AllowInternalUnsafeParser, MacroEscapeParser, MacroUseParser, +}; use crate::attributes::must_use::MustUseParser; use crate::attributes::no_implicit_prelude::NoImplicitPreludeParser; use crate::attributes::non_exhaustive::NonExhaustiveParser; @@ -178,6 +180,7 @@ attribute_parsers!( Single<SkipDuringMethodDispatchParser>, Single<TransparencyParser>, Single<WithoutArgs<AllowIncoherentImplParser>>, + Single<WithoutArgs<AllowInternalUnsafeParser>>, Single<WithoutArgs<AsPtrParser>>, Single<WithoutArgs<AutomaticallyDerivedParser>>, Single<WithoutArgs<CoherenceIsCoreParser>>, diff --git a/compiler/rustc_attr_parsing/src/session_diagnostics.rs b/compiler/rustc_attr_parsing/src/session_diagnostics.rs index 1de25ca252b..41179844152 100644 --- a/compiler/rustc_attr_parsing/src/session_diagnostics.rs +++ b/compiler/rustc_attr_parsing/src/session_diagnostics.rs @@ -498,6 +498,7 @@ pub(crate) struct ReprIdent { #[derive(Diagnostic)] #[diag(attr_parsing_unrecognized_repr_hint, code = E0552)] #[help] +#[note] pub(crate) struct UnrecognizedReprHint { #[primary_span] pub span: Span, @@ -690,6 +691,9 @@ impl<'a, G: EmissionGuarantee> Diagnostic<'a, G> for AttributeParseError { } } + if let Some(link) = self.template.docs { + diag.note(format!("for more information, visit <{link}>")); + } let suggestions = self.template.suggestions(false, &name); diag.span_suggestions( self.attr_span, diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index be8b3f0bc1e..7e20a5133e0 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -410,18 +410,18 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { } let typeck = self.infcx.tcx.typeck(self.mir_def_id()); let parent = self.infcx.tcx.parent_hir_node(expr.hir_id); - let (def_id, call_id, args, offset) = if let hir::Node::Expr(parent_expr) = parent + let (def_id, args, offset) = if let hir::Node::Expr(parent_expr) = parent && let hir::ExprKind::MethodCall(_, _, args, _) = parent_expr.kind { let def_id = typeck.type_dependent_def_id(parent_expr.hir_id); - (def_id, Some(parent_expr.hir_id), args, 1) + (def_id, args, 1) } else if let hir::Node::Expr(parent_expr) = parent && let hir::ExprKind::Call(call, args) = parent_expr.kind && let ty::FnDef(def_id, _) = typeck.node_type(call.hir_id).kind() { - (Some(*def_id), Some(call.hir_id), args, 0) + (Some(*def_id), args, 0) } else { - (None, None, &[][..], 0) + (None, &[][..], 0) }; let ty = place.ty(self.body, self.infcx.tcx).ty; @@ -459,11 +459,12 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { // If the moved place is used generically by the callee and a reference to it // would still satisfy any bounds on its type, suggest borrowing. if let Some(¶m) = arg_param - && let Some(generic_args) = call_id.and_then(|id| typeck.node_args_opt(id)) + && let hir::Node::Expr(call_expr) = parent && let Some(ref_mutability) = self.suggest_borrow_generic_arg( err, + typeck, + call_expr, def_id, - generic_args, param, moved_place, pos + offset, @@ -627,8 +628,9 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { fn suggest_borrow_generic_arg( &self, err: &mut Diag<'_>, + typeck: &ty::TypeckResults<'tcx>, + call_expr: &hir::Expr<'tcx>, callee_did: DefId, - generic_args: ty::GenericArgsRef<'tcx>, param: ty::ParamTy, moved_place: PlaceRef<'tcx>, moved_arg_pos: usize, @@ -639,6 +641,19 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { let sig = tcx.fn_sig(callee_did).instantiate_identity().skip_binder(); let clauses = tcx.predicates_of(callee_did); + let generic_args = match call_expr.kind { + // For method calls, generic arguments are attached to the call node. + hir::ExprKind::MethodCall(..) => typeck.node_args_opt(call_expr.hir_id)?, + // For normal calls, generic arguments are in the callee's type. + // This diagnostic is only run for `FnDef` callees. + hir::ExprKind::Call(callee, _) + if let &ty::FnDef(_, args) = typeck.node_type(callee.hir_id).kind() => + { + args + } + _ => return None, + }; + // First, is there at least one method on one of `param`'s trait bounds? // This keeps us from suggesting borrowing the argument to `mem::drop`, e.g. if !clauses.instantiate_identity(tcx).predicates.iter().any(|clause| { diff --git a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs index 1067f1e40ef..af71db69483 100644 --- a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs @@ -9,7 +9,8 @@ use rustc_middle::bug; use rustc_middle::mir::*; use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_mir_dataflow::move_paths::{LookupResult, MovePathIndex}; -use rustc_span::{BytePos, ExpnKind, MacroKind, Span}; +use rustc_span::def_id::DefId; +use rustc_span::{BytePos, DUMMY_SP, ExpnKind, MacroKind, Span}; use rustc_trait_selection::error_reporting::traits::FindExprBySpan; use rustc_trait_selection::infer::InferCtxtExt; use tracing::debug; @@ -507,12 +508,18 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { ); let closure_span = tcx.def_span(def_id); + self.cannot_move_out_of(span, &place_description) .with_span_label(upvar_span, "captured outer variable") .with_span_label( closure_span, format!("captured by this `{closure_kind}` closure"), ) + .with_span_help( + self.get_closure_bound_clause_span(*def_id), + "`Fn` and `FnMut` closures require captured values to be able to be \ + consumed multiple times, but an `FnOnce` consume them only once", + ) } _ => { let source = self.borrowed_content_source(deref_base); @@ -561,6 +568,47 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { err } + fn get_closure_bound_clause_span(&self, def_id: DefId) -> Span { + let tcx = self.infcx.tcx; + let typeck_result = tcx.typeck(self.mir_def_id()); + // Check whether the closure is an argument to a call, if so, + // get the instantiated where-bounds of that call. + let closure_hir_id = tcx.local_def_id_to_hir_id(def_id.expect_local()); + let hir::Node::Expr(parent) = tcx.parent_hir_node(closure_hir_id) else { return DUMMY_SP }; + + let predicates = match parent.kind { + hir::ExprKind::Call(callee, _) => { + let Some(ty) = typeck_result.node_type_opt(callee.hir_id) else { return DUMMY_SP }; + let ty::FnDef(fn_def_id, args) = ty.kind() else { return DUMMY_SP }; + tcx.predicates_of(fn_def_id).instantiate(tcx, args) + } + hir::ExprKind::MethodCall(..) => { + let Some((_, method)) = typeck_result.type_dependent_def(parent.hir_id) else { + return DUMMY_SP; + }; + let args = typeck_result.node_args(parent.hir_id); + tcx.predicates_of(method).instantiate(tcx, args) + } + _ => return DUMMY_SP, + }; + + // Check whether one of the where-bounds requires the closure to impl `Fn[Mut]`. + for (pred, span) in predicates.predicates.iter().zip(predicates.spans.iter()) { + if let Some(clause) = pred.as_trait_clause() + && let ty::Closure(clause_closure_def_id, _) = clause.self_ty().skip_binder().kind() + && *clause_closure_def_id == def_id + && (tcx.lang_items().fn_mut_trait() == Some(clause.def_id()) + || tcx.lang_items().fn_trait() == Some(clause.def_id())) + { + // Found `<TyOfCapturingClosure as FnMut>` + // We point at the `Fn()` or `FnMut()` bound that coerced the closure, which + // could be changed to `FnOnce()` to avoid the move error. + return *span; + } + } + DUMMY_SP + } + fn add_move_hints(&self, error: GroupedMoveError<'tcx>, err: &mut Diag<'_>, span: Span) { match error { GroupedMoveError::MovesFromPlace { mut binds_to, move_from, .. } => { diff --git a/compiler/rustc_borrowck/src/handle_placeholders.rs b/compiler/rustc_borrowck/src/handle_placeholders.rs index e168b819a8d..34599ac55b8 100644 --- a/compiler/rustc_borrowck/src/handle_placeholders.rs +++ b/compiler/rustc_borrowck/src/handle_placeholders.rs @@ -157,7 +157,7 @@ fn region_definitions<'tcx>( for info in var_infos.iter() { let origin = match info.origin { RegionVariableOrigin::Nll(origin) => origin, - _ => NllRegionVariableOrigin::Existential { from_forall: false, name: None }, + _ => NllRegionVariableOrigin::Existential { name: None }, }; let definition = RegionDefinition { origin, universe: info.universe, external_name: None }; diff --git a/compiler/rustc_borrowck/src/polonius/constraints.rs b/compiler/rustc_borrowck/src/polonius/constraints.rs index 50f59dd0dee..52595757859 100644 --- a/compiler/rustc_borrowck/src/polonius/constraints.rs +++ b/compiler/rustc_borrowck/src/polonius/constraints.rs @@ -7,9 +7,7 @@ use rustc_mir_dataflow::points::PointIndex; /// /// This models two sources of constraints: /// - constraints that traverse the subsets between regions at a given point, `a@p: b@p`. These -/// depend on typeck constraints generated via assignments, calls, etc. (In practice there are -/// subtleties where a statement's effect only starts being visible at the successor point, via -/// the "result" of that statement). +/// depend on typeck constraints generated via assignments, calls, etc. /// - constraints that traverse the CFG via the same region, `a@p: a@q`, where `p` is a predecessor /// of `q`. These depend on the liveness of the regions at these points, as well as their /// variance. diff --git a/compiler/rustc_borrowck/src/polonius/legacy/facts.rs b/compiler/rustc_borrowck/src/polonius/legacy/facts.rs index 64389b11a65..1f8177477e6 100644 --- a/compiler/rustc_borrowck/src/polonius/legacy/facts.rs +++ b/compiler/rustc_borrowck/src/polonius/legacy/facts.rs @@ -184,22 +184,6 @@ where } } -impl<A, B, C, D> FactRow for (A, B, C, D) -where - A: FactCell, - B: FactCell, - C: FactCell, - D: FactCell, -{ - fn write( - &self, - out: &mut dyn Write, - location_table: &PoloniusLocationTable, - ) -> Result<(), Box<dyn Error>> { - write_row(out, location_table, &[&self.0, &self.1, &self.2, &self.3]) - } -} - fn write_row( out: &mut dyn Write, location_table: &PoloniusLocationTable, diff --git a/compiler/rustc_borrowck/src/polonius/liveness_constraints.rs b/compiler/rustc_borrowck/src/polonius/liveness_constraints.rs index 6ab09f731c0..2ba72180d66 100644 --- a/compiler/rustc_borrowck/src/polonius/liveness_constraints.rs +++ b/compiler/rustc_borrowck/src/polonius/liveness_constraints.rs @@ -105,22 +105,14 @@ fn propagate_loans_between_points( }); } - let Some(current_live_regions) = live_regions.row(current_point) else { - // There are no constraints to add: there are no live regions at the current point. - return; - }; let Some(next_live_regions) = live_regions.row(next_point) else { // There are no constraints to add: there are no live regions at the next point. return; }; for region in next_live_regions.iter() { - if !current_live_regions.contains(region) { - continue; - } - - // `region` is indeed live at both points, add a constraint between them, according to - // variance. + // `region` could be live at the current point, and is live at the next point: add a + // constraint between them, according to variance. if let Some(&direction) = live_region_variances.get(®ion) { add_liveness_constraint( region, diff --git a/compiler/rustc_borrowck/src/polonius/loan_liveness.rs b/compiler/rustc_borrowck/src/polonius/loan_liveness.rs index 5cd265e0db9..bdc3047e5ba 100644 --- a/compiler/rustc_borrowck/src/polonius/loan_liveness.rs +++ b/compiler/rustc_borrowck/src/polonius/loan_liveness.rs @@ -1,27 +1,18 @@ -use std::collections::{BTreeMap, BTreeSet}; - use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexSet}; -use rustc_middle::mir::visit::Visitor; -use rustc_middle::mir::{ - Body, Local, Location, Place, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, -}; -use rustc_middle::ty::{RegionVid, TyCtxt}; +use rustc_middle::ty::RegionVid; use rustc_mir_dataflow::points::PointIndex; use super::{LiveLoans, LocalizedOutlivesConstraintSet}; +use crate::BorrowSet; use crate::constraints::OutlivesConstraint; -use crate::dataflow::BorrowIndex; use crate::region_infer::values::LivenessValues; use crate::type_check::Locations; -use crate::{BorrowSet, PlaceConflictBias, places_conflict}; -/// Compute loan reachability, stop at kills, and trace loan liveness throughout the CFG, by +/// Compute loan reachability to approximately trace loan liveness throughout the CFG, by /// traversing the full graph of constraints that combines: /// - the localized constraints (the physical edges), /// - with the constraints that hold at all points (the logical edges). pub(super) fn compute_loan_liveness<'tcx>( - tcx: TyCtxt<'tcx>, - body: &Body<'tcx>, liveness: &LivenessValues, outlives_constraints: impl Iterator<Item = OutlivesConstraint<'tcx>>, borrow_set: &BorrowSet<'tcx>, @@ -29,11 +20,6 @@ pub(super) fn compute_loan_liveness<'tcx>( ) -> LiveLoans { let mut live_loans = LiveLoans::new(borrow_set.len()); - // FIXME: it may be preferable for kills to be encoded in the edges themselves, to simplify and - // likely make traversal (and constraint generation) more efficient. We also display kills on - // edges when visualizing the constraint graph anyways. - let kills = collect_kills(body, tcx, borrow_set); - // Create the full graph with the physical edges we've localized earlier, and the logical edges // of constraints that hold at all points. let logical_constraints = @@ -59,15 +45,15 @@ pub(super) fn compute_loan_liveness<'tcx>( continue; } - // Record the loan as being live on entry to this point. - live_loans.insert(node.point, loan_idx); - - // Here, we have a conundrum. There's currently a weakness in our theory, in that - // we're using a single notion of reachability to represent what used to be _two_ - // different transitive closures. It didn't seem impactful when coming up with the - // single-graph and reachability through space (regions) + time (CFG) concepts, but in - // practice the combination of time-traveling with kills is more impactful than - // initially anticipated. + // Record the loan as being live on entry to this point if it reaches a live region + // there. + // + // This is an approximation of liveness (which is the thing we want), in that we're + // using a single notion of reachability to represent what used to be _two_ different + // transitive closures. It didn't seem impactful when coming up with the single-graph + // and reachability through space (regions) + time (CFG) concepts, but in practice the + // combination of time-traveling with kills is more impactful than initially + // anticipated. // // Kills should prevent a loan from reaching its successor points in the CFG, but not // while time-traveling: we're not actually at that CFG point, but looking for @@ -92,40 +78,20 @@ pub(super) fn compute_loan_liveness<'tcx>( // two-step traversal described above: only kills encountered on exit via a backward // edge are ignored. // - // In our test suite, there are a couple of cases where kills are encountered while - // time-traveling, however as far as we can tell, always in cases where they would be - // unreachable. We have reason to believe that this is a property of the single-graph - // approach (but haven't proved it yet): - // - reachable kills while time-traveling would also be encountered via regular - // traversal - // - it makes _some_ sense to ignore unreachable kills, but subtleties around dead code - // in general need to be better thought through (like they were for NLLs). - // - ignoring kills is a conservative approximation: the loan is still live and could - // cause false positive errors at another place access. Soundness issues in this - // domain should look more like the absence of reachability instead. - // - // This is enough in practice to pass tests, and therefore is what we have implemented - // for now. + // This version of the analysis, however, is enough in practice to pass the tests that + // we care about and NLLs reject, without regressions on crater, and is an actionable + // subset of the full analysis. It also naturally points to areas of improvement that we + // wish to explore later, namely handling kills appropriately during traversal, instead + // of continuing traversal to all the reachable nodes. // - // FIXME: all of the above. Analyze potential unsoundness, possibly in concert with a - // borrowck implementation in a-mir-formality, fuzzing, or manually crafting - // counter-examples. + // FIXME: analyze potential unsoundness, possibly in concert with a borrowck + // implementation in a-mir-formality, fuzzing, or manually crafting counter-examples. - // Continuing traversal will depend on whether the loan is killed at this point, and - // whether we're time-traveling. - let current_location = liveness.location_from_point(node.point); - let is_loan_killed = - kills.get(¤t_location).is_some_and(|kills| kills.contains(&loan_idx)); + if liveness.is_live_at(node.region, liveness.location_from_point(node.point)) { + live_loans.insert(node.point, loan_idx); + } for succ in graph.outgoing_edges(node) { - // If the loan is killed at this point, it is killed _on exit_. But only during - // forward traversal. - if is_loan_killed { - let destination = liveness.location_from_point(succ.point); - if current_location.is_predecessor_of(destination, body) { - continue; - } - } stack.push(succ); } } @@ -192,116 +158,3 @@ impl LocalizedConstraintGraph { physical_edges.chain(materialized_edges) } } - -/// Traverses the MIR and collects kills. -fn collect_kills<'tcx>( - body: &Body<'tcx>, - tcx: TyCtxt<'tcx>, - borrow_set: &BorrowSet<'tcx>, -) -> BTreeMap<Location, BTreeSet<BorrowIndex>> { - let mut collector = KillsCollector { borrow_set, tcx, body, kills: BTreeMap::default() }; - for (block, data) in body.basic_blocks.iter_enumerated() { - collector.visit_basic_block_data(block, data); - } - collector.kills -} - -struct KillsCollector<'a, 'tcx> { - body: &'a Body<'tcx>, - tcx: TyCtxt<'tcx>, - borrow_set: &'a BorrowSet<'tcx>, - - /// The set of loans killed at each location. - kills: BTreeMap<Location, BTreeSet<BorrowIndex>>, -} - -// This visitor has a similar structure to the `Borrows` dataflow computation with respect to kills, -// and the datalog polonius fact generation for the `loan_killed_at` relation. -impl<'tcx> KillsCollector<'_, 'tcx> { - /// Records the borrows on the specified place as `killed`. For example, when assigning to a - /// local, or on a call's return destination. - fn record_killed_borrows_for_place(&mut self, place: Place<'tcx>, location: Location) { - // For the reasons described in graph traversal, we also filter out kills - // unreachable from the loan's introduction point, as they would stop traversal when - // e.g. checking for reachability in the subset graph through invariance constraints - // higher up. - let filter_unreachable_kills = |loan| { - let introduction = self.borrow_set[loan].reserve_location; - let reachable = introduction.is_predecessor_of(location, self.body); - reachable - }; - - let other_borrows_of_local = self - .borrow_set - .local_map - .get(&place.local) - .into_iter() - .flat_map(|bs| bs.iter()) - .copied(); - - // If the borrowed place is a local with no projections, all other borrows of this - // local must conflict. This is purely an optimization so we don't have to call - // `places_conflict` for every borrow. - if place.projection.is_empty() { - if !self.body.local_decls[place.local].is_ref_to_static() { - self.kills - .entry(location) - .or_default() - .extend(other_borrows_of_local.filter(|&loan| filter_unreachable_kills(loan))); - } - return; - } - - // By passing `PlaceConflictBias::NoOverlap`, we conservatively assume that any given - // pair of array indices are not equal, so that when `places_conflict` returns true, we - // will be assured that two places being compared definitely denotes the same sets of - // locations. - let definitely_conflicting_borrows = other_borrows_of_local - .filter(|&i| { - places_conflict( - self.tcx, - self.body, - self.borrow_set[i].borrowed_place, - place, - PlaceConflictBias::NoOverlap, - ) - }) - .filter(|&loan| filter_unreachable_kills(loan)); - - self.kills.entry(location).or_default().extend(definitely_conflicting_borrows); - } - - /// Records the borrows on the specified local as `killed`. - fn record_killed_borrows_for_local(&mut self, local: Local, location: Location) { - if let Some(borrow_indices) = self.borrow_set.local_map.get(&local) { - self.kills.entry(location).or_default().extend(borrow_indices.iter()); - } - } -} - -impl<'tcx> Visitor<'tcx> for KillsCollector<'_, 'tcx> { - fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) { - // Make sure there are no remaining borrows for locals that have gone out of scope. - if let StatementKind::StorageDead(local) = statement.kind { - self.record_killed_borrows_for_local(local, location); - } - - self.super_statement(statement, location); - } - - fn visit_assign(&mut self, place: &Place<'tcx>, rvalue: &Rvalue<'tcx>, location: Location) { - // When we see `X = ...`, then kill borrows of `(*X).foo` and so forth. - self.record_killed_borrows_for_place(*place, location); - self.super_assign(place, rvalue, location); - } - - fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) { - // A `Call` terminator's return value can be a local which has borrows, so we need to record - // those as killed as well. - if let TerminatorKind::Call { destination, .. } = terminator.kind { - self.record_killed_borrows_for_place(destination, location); - } - - self.super_terminator(terminator, location); - } -} diff --git a/compiler/rustc_borrowck/src/polonius/mod.rs b/compiler/rustc_borrowck/src/polonius/mod.rs index 142ef8ba28e..a9092b1981e 100644 --- a/compiler/rustc_borrowck/src/polonius/mod.rs +++ b/compiler/rustc_borrowck/src/polonius/mod.rs @@ -146,8 +146,8 @@ impl PoloniusContext { /// - converting NLL typeck constraints to be localized /// - encoding liveness constraints /// - /// Then, this graph is traversed, and combined with kills, reachability is recorded as loan - /// liveness, to be used by the loan scope and active loans computations. + /// Then, this graph is traversed, reachability is recorded as loan liveness, to be used by the + /// loan scope and active loans computations. /// /// The constraint data will be used to compute errors and diagnostics. pub(crate) fn compute_loan_liveness<'tcx>( @@ -182,8 +182,6 @@ impl PoloniusContext { // Now that we have a complete graph, we can compute reachability to trace the liveness of // loans for the next step in the chain, the NLL loan scope and active loans computations. let live_loans = compute_loan_liveness( - tcx, - body, regioncx.liveness_constraints(), regioncx.outlives_constraints(), borrow_set, diff --git a/compiler/rustc_borrowck/src/polonius/typeck_constraints.rs b/compiler/rustc_borrowck/src/polonius/typeck_constraints.rs index 1289b1899eb..e4e52962bf7 100644 --- a/compiler/rustc_borrowck/src/polonius/typeck_constraints.rs +++ b/compiler/rustc_borrowck/src/polonius/typeck_constraints.rs @@ -47,9 +47,7 @@ pub(super) fn convert_typeck_constraints<'tcx>( tcx, body, stmt, - liveness, &outlives_constraint, - location, point, universal_regions, ) @@ -78,9 +76,7 @@ fn localize_statement_constraint<'tcx>( tcx: TyCtxt<'tcx>, body: &Body<'tcx>, stmt: &Statement<'tcx>, - liveness: &LivenessValues, outlives_constraint: &OutlivesConstraint<'tcx>, - current_location: Location, current_point: PointIndex, universal_regions: &UniversalRegions<'tcx>, ) -> LocalizedOutlivesConstraint { @@ -98,8 +94,8 @@ fn localize_statement_constraint<'tcx>( // - and that should be impossible in MIR // // When we have a more complete implementation in the future, tested with crater, etc, - // we can relax this to a debug assert instead, or remove it. - assert!( + // we can remove this assertion. It's a debug assert because it can be expensive. + debug_assert!( { let mut lhs_regions = FxHashSet::default(); tcx.for_each_free_region(lhs, |region| { @@ -119,16 +115,8 @@ fn localize_statement_constraint<'tcx>( "there should be no common regions between the LHS and RHS of an assignment" ); - // As mentioned earlier, we should be tracking these better upstream but: we want to - // relate the types on entry to the type of the place on exit. That is, outlives - // constraints on the RHS are on entry, and outlives constraints to/from the LHS are on - // exit (i.e. on entry to the successor location). let lhs_ty = body.local_decls[lhs.local].ty; - let successor_location = Location { - block: current_location.block, - statement_index: current_location.statement_index + 1, - }; - let successor_point = liveness.point_from_location(successor_location); + let successor_point = current_point; compute_constraint_direction( tcx, outlives_constraint, @@ -195,6 +183,7 @@ fn localize_terminator_constraint<'tcx>( } } } + /// For a given outlives constraint and CFG edge, returns the localized constraint with the /// appropriate `from`-`to` direction. This is computed according to whether the constraint flows to /// or from a free region in the given `value`, some kind of result for an effectful operation, like diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index dbd245214a2..b0c31ac9601 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -1939,10 +1939,15 @@ impl<'tcx> RegionInferenceContext<'tcx> { // // and here we prefer to blame the source (the y = x statement). let blame_source = match from_region_origin { - NllRegionVariableOrigin::FreeRegion - | NllRegionVariableOrigin::Existential { from_forall: false, name: _ } => true, - NllRegionVariableOrigin::Placeholder(_) - | NllRegionVariableOrigin::Existential { from_forall: true, name: _ } => false, + NllRegionVariableOrigin::FreeRegion => true, + NllRegionVariableOrigin::Placeholder(_) => false, + // `'existential: 'whatever` never results in a region error by itself. + // We may always infer it to `'static` afterall. This means while an error + // path may go through an existential, these existentials are never the + // `from_region`. + NllRegionVariableOrigin::Existential { name: _ } => { + unreachable!("existentials can outlive everything") + } }; // To pick a constraint to blame, we organize constraints by how interesting we expect them diff --git a/compiler/rustc_borrowck/src/renumber.rs b/compiler/rustc_borrowck/src/renumber.rs index 100d30704b9..fa3064afee8 100644 --- a/compiler/rustc_borrowck/src/renumber.rs +++ b/compiler/rustc_borrowck/src/renumber.rs @@ -66,7 +66,7 @@ impl<'a, 'tcx> RegionRenumberer<'a, 'tcx> { T: TypeFoldable<TyCtxt<'tcx>>, F: Fn() -> RegionCtxt, { - let origin = NllRegionVariableOrigin::Existential { from_forall: false, name: None }; + let origin = NllRegionVariableOrigin::Existential { name: None }; fold_regions(self.infcx.tcx, value, |_region, _depth| { self.infcx.next_nll_region_var(origin, || region_ctxt_fn()) }) diff --git a/compiler/rustc_borrowck/src/type_check/relate_tys.rs b/compiler/rustc_borrowck/src/type_check/relate_tys.rs index 393adafea0b..84ca9bad2c1 100644 --- a/compiler/rustc_borrowck/src/type_check/relate_tys.rs +++ b/compiler/rustc_borrowck/src/type_check/relate_tys.rs @@ -216,7 +216,7 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> { *ex_reg_var } else { let ex_reg_var = - self.next_existential_region_var(true, br.kind.get_name(infcx.infcx.tcx)); + self.next_existential_region_var(br.kind.get_name(infcx.infcx.tcx)); debug!(?ex_reg_var); reg_map.insert(br, ex_reg_var); @@ -244,17 +244,9 @@ impl<'a, 'b, 'tcx> NllTypeRelating<'a, 'b, 'tcx> { } #[instrument(skip(self), level = "debug")] - fn next_existential_region_var( - &mut self, - from_forall: bool, - name: Option<Symbol>, - ) -> ty::Region<'tcx> { - let origin = NllRegionVariableOrigin::Existential { name, from_forall }; - - let reg_var = - self.type_checker.infcx.next_nll_region_var(origin, || RegionCtxt::Existential(name)); - - reg_var + fn next_existential_region_var(&mut self, name: Option<Symbol>) -> ty::Region<'tcx> { + let origin = NllRegionVariableOrigin::Existential { name }; + self.type_checker.infcx.next_nll_region_var(origin, || RegionCtxt::Existential(name)) } #[instrument(skip(self), level = "debug")] diff --git a/compiler/rustc_builtin_macros/src/alloc_error_handler.rs b/compiler/rustc_builtin_macros/src/alloc_error_handler.rs index e75bc944d7e..35ef6be095e 100644 --- a/compiler/rustc_builtin_macros/src/alloc_error_handler.rs +++ b/compiler/rustc_builtin_macros/src/alloc_error_handler.rs @@ -1,4 +1,3 @@ -use rustc_ast::ptr::P; use rustc_ast::{ self as ast, Fn, FnHeader, FnSig, Generics, ItemKind, Safety, Stmt, StmtKind, TyKind, }; @@ -46,7 +45,7 @@ pub(crate) fn expand( let const_body = ecx.expr_block(ecx.block(span, stmts)); let const_item = ecx.item_const(span, Ident::new(kw::Underscore, span), const_ty, const_body); let const_item = if is_stmt { - Annotatable::Stmt(P(ecx.stmt_item(span, const_item))) + Annotatable::Stmt(Box::new(ecx.stmt_item(span, const_item))) } else { Annotatable::Item(const_item) }; diff --git a/compiler/rustc_builtin_macros/src/asm.rs b/compiler/rustc_builtin_macros/src/asm.rs index 1fb99817222..86b8e1ff8db 100644 --- a/compiler/rustc_builtin_macros/src/asm.rs +++ b/compiler/rustc_builtin_macros/src/asm.rs @@ -1,5 +1,4 @@ use lint::BuiltinLintDiag; -use rustc_ast::ptr::P; use rustc_ast::tokenstream::TokenStream; use rustc_ast::{AsmMacro, token}; use rustc_data_structures::fx::{FxHashMap, FxIndexMap}; @@ -19,7 +18,7 @@ use crate::{errors, fluent_generated as fluent}; /// Validated assembly arguments, ready for macro expansion. struct ValidatedAsmArgs { - pub templates: Vec<P<ast::Expr>>, + pub templates: Vec<Box<ast::Expr>>, pub operands: Vec<(ast::InlineAsmOperand, Span)>, named_args: FxIndexMap<Symbol, usize>, reg_args: GrowableBitSet<usize>, @@ -600,9 +599,9 @@ pub(super) fn expand_asm<'cx>( return ExpandResult::Retry(()); }; let expr = match mac { - Ok(inline_asm) => P(ast::Expr { + Ok(inline_asm) => Box::new(ast::Expr { id: ast::DUMMY_NODE_ID, - kind: ast::ExprKind::InlineAsm(P(inline_asm)), + kind: ast::ExprKind::InlineAsm(Box::new(inline_asm)), span: sp, attrs: ast::AttrVec::new(), tokens: None, @@ -630,9 +629,9 @@ pub(super) fn expand_naked_asm<'cx>( return ExpandResult::Retry(()); }; let expr = match mac { - Ok(inline_asm) => P(ast::Expr { + Ok(inline_asm) => Box::new(ast::Expr { id: ast::DUMMY_NODE_ID, - kind: ast::ExprKind::InlineAsm(P(inline_asm)), + kind: ast::ExprKind::InlineAsm(Box::new(inline_asm)), span: sp, attrs: ast::AttrVec::new(), tokens: None, @@ -660,7 +659,7 @@ pub(super) fn expand_global_asm<'cx>( return ExpandResult::Retry(()); }; match mac { - Ok(inline_asm) => MacEager::items(smallvec![P(ast::Item { + Ok(inline_asm) => MacEager::items(smallvec![Box::new(ast::Item { attrs: ast::AttrVec::new(), id: ast::DUMMY_NODE_ID, kind: ast::ItemKind::GlobalAsm(Box::new(inline_asm)), diff --git a/compiler/rustc_builtin_macros/src/assert.rs b/compiler/rustc_builtin_macros/src/assert.rs index c659b1cff59..855da5caa31 100644 --- a/compiler/rustc_builtin_macros/src/assert.rs +++ b/compiler/rustc_builtin_macros/src/assert.rs @@ -1,6 +1,5 @@ mod context; -use rustc_ast::ptr::P; use rustc_ast::token::Delimiter; use rustc_ast::tokenstream::{DelimSpan, TokenStream}; use rustc_ast::{DelimArgs, Expr, ExprKind, MacCall, Path, PathSegment, UnOp, token}; @@ -55,9 +54,9 @@ pub(crate) fn expand_assert<'cx>( let expr = if let Some(tokens) = custom_message { let then = cx.expr( call_site_span, - ExprKind::MacCall(P(MacCall { + ExprKind::MacCall(Box::new(MacCall { path: panic_path(), - args: P(DelimArgs { + args: Box::new(DelimArgs { dspan: DelimSpan::from_single(call_site_span), delim: Delimiter::Parenthesis, tokens, @@ -96,7 +95,7 @@ pub(crate) fn expand_assert<'cx>( } struct Assert { - cond_expr: P<Expr>, + cond_expr: Box<Expr>, custom_message: Option<TokenStream>, } @@ -104,10 +103,10 @@ struct Assert { fn expr_if_not( cx: &ExtCtxt<'_>, span: Span, - cond: P<Expr>, - then: P<Expr>, - els: Option<P<Expr>>, -) -> P<Expr> { + cond: Box<Expr>, + then: Box<Expr>, + els: Option<Box<Expr>>, +) -> Box<Expr> { cx.expr_if(span, cx.expr(span, ExprKind::Unary(UnOp::Not, cond)), then, els) } diff --git a/compiler/rustc_builtin_macros/src/assert/context.rs b/compiler/rustc_builtin_macros/src/assert/context.rs index ea7248ca539..31855cbd4e6 100644 --- a/compiler/rustc_builtin_macros/src/assert/context.rs +++ b/compiler/rustc_builtin_macros/src/assert/context.rs @@ -1,4 +1,3 @@ -use rustc_ast::ptr::P; use rustc_ast::token::{self, Delimiter, IdentIsRaw}; use rustc_ast::tokenstream::{DelimSpan, TokenStream, TokenTree}; use rustc_ast::{ @@ -70,7 +69,7 @@ impl<'cx, 'a> Context<'cx, 'a> { /// } /// } /// ``` - pub(super) fn build(mut self, mut cond_expr: P<Expr>, panic_path: Path) -> P<Expr> { + pub(super) fn build(mut self, mut cond_expr: Box<Expr>, panic_path: Path) -> Box<Expr> { let expr_str = pprust::expr_to_string(&cond_expr); self.manage_cond_expr(&mut cond_expr); let initial_imports = self.build_initial_imports(); @@ -129,7 +128,7 @@ impl<'cx, 'a> Context<'cx, 'a> { } /// Takes the conditional expression of `assert!` and then wraps it inside `unlikely` - fn build_unlikely(&self, cond_expr: P<Expr>) -> P<Expr> { + fn build_unlikely(&self, cond_expr: Box<Expr>) -> Box<Expr> { let unlikely_path = self.cx.std_path(&[sym::intrinsics, sym::unlikely]); self.cx.expr_call( self.span, @@ -145,7 +144,7 @@ impl<'cx, 'a> Context<'cx, 'a> { /// __capture0, /// ... /// ); - fn build_panic(&self, expr_str: &str, panic_path: Path) -> P<Expr> { + fn build_panic(&self, expr_str: &str, panic_path: Path) -> Box<Expr> { let escaped_expr_str = escape_to_fmt(expr_str); let initial = [ TokenTree::token_joint( @@ -176,9 +175,9 @@ impl<'cx, 'a> Context<'cx, 'a> { }); self.cx.expr( self.span, - ExprKind::MacCall(P(MacCall { + ExprKind::MacCall(Box::new(MacCall { path: panic_path, - args: P(DelimArgs { + args: Box::new(DelimArgs { dspan: DelimSpan::from_single(self.span), delim: Delimiter::Parenthesis, tokens: initial.into_iter().chain(captures).collect::<TokenStream>(), @@ -190,7 +189,7 @@ impl<'cx, 'a> Context<'cx, 'a> { /// Recursive function called until `cond_expr` and `fmt_str` are fully modified. /// /// See [Self::manage_initial_capture] and [Self::manage_try_capture] - fn manage_cond_expr(&mut self, expr: &mut P<Expr>) { + fn manage_cond_expr(&mut self, expr: &mut Box<Expr>) { match &mut expr.kind { ExprKind::AddrOf(_, mutability, local_expr) => { self.with_is_consumed_management(matches!(mutability, Mutability::Mut), |this| { @@ -331,7 +330,7 @@ impl<'cx, 'a> Context<'cx, 'a> { /// /// `fmt_str`, the formatting string used for debugging, is constructed to show possible /// captured variables. - fn manage_initial_capture(&mut self, expr: &mut P<Expr>, path_ident: Ident) { + fn manage_initial_capture(&mut self, expr: &mut Box<Expr>, path_ident: Ident) { if self.paths.contains(&path_ident) { return; } else { @@ -360,7 +359,12 @@ impl<'cx, 'a> Context<'cx, 'a> { /// (&Wrapper(__local_bindN)).try_capture(&mut __captureN); /// __local_bindN /// } - fn manage_try_capture(&mut self, capture: Ident, curr_capture_idx: usize, expr: &mut P<Expr>) { + fn manage_try_capture( + &mut self, + capture: Ident, + curr_capture_idx: usize, + expr: &mut Box<Expr>, + ) { let local_bind_string = format!("__local_bind{curr_capture_idx}"); let local_bind = Ident::new(Symbol::intern(&local_bind_string), self.span); self.local_bind_decls.push(self.cx.stmt_let( @@ -441,20 +445,20 @@ fn escape_to_fmt(s: &str) -> String { rslt } -fn expr_addr_of_mut(cx: &ExtCtxt<'_>, sp: Span, e: P<Expr>) -> P<Expr> { +fn expr_addr_of_mut(cx: &ExtCtxt<'_>, sp: Span, e: Box<Expr>) -> Box<Expr> { cx.expr(sp, ExprKind::AddrOf(BorrowKind::Ref, Mutability::Mut, e)) } fn expr_method_call( cx: &ExtCtxt<'_>, seg: PathSegment, - receiver: P<Expr>, - args: ThinVec<P<Expr>>, + receiver: Box<Expr>, + args: ThinVec<Box<Expr>>, span: Span, -) -> P<Expr> { +) -> Box<Expr> { cx.expr(span, ExprKind::MethodCall(Box::new(MethodCall { seg, receiver, args, span }))) } -fn expr_paren(cx: &ExtCtxt<'_>, sp: Span, e: P<Expr>) -> P<Expr> { +fn expr_paren(cx: &ExtCtxt<'_>, sp: Span, e: Box<Expr>) -> Box<Expr> { cx.expr(sp, ExprKind::Paren(e)) } diff --git a/compiler/rustc_builtin_macros/src/autodiff.rs b/compiler/rustc_builtin_macros/src/autodiff.rs index c7844778332..a662840eda5 100644 --- a/compiler/rustc_builtin_macros/src/autodiff.rs +++ b/compiler/rustc_builtin_macros/src/autodiff.rs @@ -11,7 +11,6 @@ mod llvm_enzyme { AutoDiffAttrs, DiffActivity, DiffMode, valid_input_activity, valid_ret_activity, valid_ty_for_activity, }; - use rustc_ast::ptr::P; use rustc_ast::token::{Lit, LitKind, Token, TokenKind}; use rustc_ast::tokenstream::*; use rustc_ast::visit::AssocCtxt::*; @@ -27,7 +26,7 @@ mod llvm_enzyme { use crate::errors; pub(crate) fn outer_normal_attr( - kind: &P<rustc_ast::NormalAttr>, + kind: &Box<rustc_ast::NormalAttr>, id: rustc_ast::AttrId, span: Span, ) -> rustc_ast::Attribute { @@ -73,7 +72,7 @@ mod llvm_enzyme { } // Get information about the function the macro is applied to - fn extract_item_info(iitem: &P<ast::Item>) -> Option<(Visibility, FnSig, Ident, Generics)> { + fn extract_item_info(iitem: &Box<ast::Item>) -> Option<(Visibility, FnSig, Ident, Generics)> { match &iitem.kind { ItemKind::Fn(box ast::Fn { sig, ident, generics, .. }) => { Some((iitem.vis.clone(), sig.clone(), ident.clone(), generics.clone())) @@ -346,7 +345,7 @@ mod llvm_enzyme { define_opaque: None, }); let mut rustc_ad_attr = - P(ast::NormalAttr::from_ident(Ident::with_dummy_span(sym::rustc_autodiff))); + Box::new(ast::NormalAttr::from_ident(Ident::with_dummy_span(sym::rustc_autodiff))); let ts2: Vec<TokenTree> = vec![TokenTree::Token( Token::new(TokenKind::Ident(sym::never, false.into()), span), @@ -363,7 +362,7 @@ mod llvm_enzyme { args: ast::AttrArgs::Delimited(never_arg), tokens: None, }; - let inline_never_attr = P(ast::NormalAttr { item: inline_item, tokens: None }); + let inline_never_attr = Box::new(ast::NormalAttr { item: inline_item, tokens: None }); let new_id = ecx.sess.psess.attr_id_generator.mk_attr_id(); let attr = outer_normal_attr(&rustc_ad_attr, new_id, span); let new_id = ecx.sess.psess.attr_id_generator.mk_attr_id(); @@ -433,7 +432,7 @@ mod llvm_enzyme { let d_annotatable = match &item { Annotatable::AssocItem(_, _) => { let assoc_item: AssocItemKind = ast::AssocItemKind::Fn(asdf); - let d_fn = P(ast::AssocItem { + let d_fn = Box::new(ast::AssocItem { attrs: thin_vec![d_attr, inline_never], id: ast::DUMMY_NODE_ID, span, @@ -453,7 +452,7 @@ mod llvm_enzyme { let mut d_fn = ecx.item(span, thin_vec![d_attr, inline_never], ItemKind::Fn(asdf)); d_fn.vis = vis; - Annotatable::Stmt(P(ast::Stmt { + Annotatable::Stmt(Box::new(ast::Stmt { id: ast::DUMMY_NODE_ID, kind: ast::StmtKind::Item(d_fn), span, @@ -506,7 +505,7 @@ mod llvm_enzyme { idents: &[Ident], errored: bool, generics: &Generics, - ) -> (P<ast::Block>, P<ast::Expr>, P<ast::Expr>, P<ast::Expr>) { + ) -> (Box<ast::Block>, Box<ast::Expr>, Box<ast::Expr>, Box<ast::Expr>) { let blackbox_path = ecx.std_path(&[sym::hint, sym::black_box]); let noop = ast::InlineAsm { asm_macro: ast::AsmMacro::Asm, @@ -517,7 +516,7 @@ mod llvm_enzyme { options: ast::InlineAsmOptions::PURE | ast::InlineAsmOptions::NOMEM, line_spans: vec![], }; - let noop_expr = ecx.expr_asm(span, P(noop)); + let noop_expr = ecx.expr_asm(span, Box::new(noop)); let unsf = ast::BlockCheckMode::Unsafe(ast::UnsafeSource::CompilerGenerated); let unsf_block = ast::Block { stmts: thin_vec![ecx.stmt_semi(noop_expr)], @@ -526,7 +525,7 @@ mod llvm_enzyme { rules: unsf, span, }; - let unsf_expr = ecx.expr_block(P(unsf_block)); + let unsf_expr = ecx.expr_block(Box::new(unsf_block)); let blackbox_call_expr = ecx.expr_path(ecx.path(span, blackbox_path)); let primal_call = gen_primal_call(ecx, span, primal, idents, generics); let black_box_primal_call = ecx.expr_call( @@ -578,7 +577,7 @@ mod llvm_enzyme { idents: Vec<Ident>, errored: bool, generics: &Generics, - ) -> P<ast::Block> { + ) -> Box<ast::Block> { let new_decl_span = d_sig.span; // Just adding some default inline-asm and black_box usages to prevent early inlining @@ -634,7 +633,7 @@ mod llvm_enzyme { return body; } - let mut exprs: P<ast::Expr> = primal_call; + let mut exprs: Box<ast::Expr> = primal_call; let d_ret_ty = match d_sig.decl.output { FnRetTy::Ty(ref ty) => ty.clone(), FnRetTy::Default(span) => { @@ -653,7 +652,7 @@ mod llvm_enzyme { } else { let q = QSelf { ty: d_ret_ty, path_span: span, position: 0 }; let y = ExprKind::Path( - Some(P(q)), + Some(Box::new(q)), ecx.path_ident(span, Ident::with_dummy_span(kw::Default)), ); let default_call_expr = ecx.expr(span, y); @@ -703,7 +702,7 @@ mod llvm_enzyme { primal: Ident, idents: &[Ident], generics: &Generics, - ) -> P<ast::Expr> { + ) -> Box<ast::Expr> { let has_self = idents.len() > 0 && idents[0].name == kw::SelfLower; if has_self { @@ -740,7 +739,7 @@ mod llvm_enzyme { }, ); - ast::AngleBracketedArg::Arg(ast::GenericArg::Type(P(ast::Ty { + ast::AngleBracketedArg::Arg(ast::GenericArg::Type(Box::new(ast::Ty { id: type_param.id, span, kind: generic_param, @@ -750,7 +749,7 @@ mod llvm_enzyme { .collect(); function_path.args = - Some(P(ast::GenericArgs::AngleBracketed(ast::AngleBracketedArgs { + Some(Box::new(ast::GenericArgs::AngleBracketed(ast::AngleBracketedArgs { span, args: generated_generic_types, }))); @@ -856,7 +855,7 @@ mod llvm_enzyme { for i in 0..x.width { let mut shadow_arg = arg.clone(); // We += into the shadow in reverse mode. - shadow_arg.ty = P(assure_mut_ref(&arg.ty)); + shadow_arg.ty = Box::new(assure_mut_ref(&arg.ty)); let old_name = if let PatKind::Ident(_, ident, _) = arg.pat.kind { ident.name } else { @@ -866,7 +865,7 @@ mod llvm_enzyme { let name: String = format!("d{}_{}", old_name, i); new_inputs.push(name.clone()); let ident = Ident::from_str_and_span(&name, shadow_arg.pat.span); - shadow_arg.pat = P(ast::Pat { + shadow_arg.pat = Box::new(ast::Pat { id: ast::DUMMY_NODE_ID, kind: PatKind::Ident(BindingMode::NONE, ident, None), span: shadow_arg.pat.span, @@ -898,7 +897,7 @@ mod llvm_enzyme { let name: String = format!("b{}_{}", old_name, i); new_inputs.push(name.clone()); let ident = Ident::from_str_and_span(&name, shadow_arg.pat.span); - shadow_arg.pat = P(ast::Pat { + shadow_arg.pat = Box::new(ast::Pat { id: ast::DUMMY_NODE_ID, kind: PatKind::Ident(BindingMode::NONE, ident, None), span: shadow_arg.pat.span, @@ -942,7 +941,7 @@ mod llvm_enzyme { let shadow_arg = ast::Param { attrs: ThinVec::new(), ty: ty.clone(), - pat: P(ast::Pat { + pat: Box::new(ast::Pat { id: ast::DUMMY_NODE_ID, kind: PatKind::Ident(BindingMode::NONE, ident, None), span: ty.span, @@ -966,7 +965,12 @@ mod llvm_enzyme { FnRetTy::Default(span) => { // We want to return std::hint::black_box(()). let kind = TyKind::Tup(ThinVec::new()); - let ty = P(rustc_ast::Ty { kind, id: ast::DUMMY_NODE_ID, span, tokens: None }); + let ty = Box::new(rustc_ast::Ty { + kind, + id: ast::DUMMY_NODE_ID, + span, + tokens: None, + }); d_decl.output = FnRetTy::Ty(ty.clone()); assert!(matches!(x.ret_activity, DiffActivity::None)); // this won't be used below, so any type would be fine. @@ -987,7 +991,7 @@ mod llvm_enzyme { }; TyKind::Array(ty.clone(), anon_const) }; - let ty = P(rustc_ast::Ty { kind, id: ty.id, span: ty.span, tokens: None }); + let ty = Box::new(rustc_ast::Ty { kind, id: ty.id, span: ty.span, tokens: None }); d_decl.output = FnRetTy::Ty(ty); } if matches!(x.ret_activity, DiffActivity::DualOnly | DiffActivity::DualvOnly) { @@ -1000,7 +1004,8 @@ mod llvm_enzyme { value: ecx.expr_usize(span, x.width as usize), }; let kind = TyKind::Array(ty.clone(), anon_const); - let ty = P(rustc_ast::Ty { kind, id: ty.id, span: ty.span, tokens: None }); + let ty = + Box::new(rustc_ast::Ty { kind, id: ty.id, span: ty.span, tokens: None }); d_decl.output = FnRetTy::Ty(ty); } } @@ -1022,14 +1027,14 @@ mod llvm_enzyme { act_ret.insert(0, ty.clone()); } let kind = TyKind::Tup(act_ret); - P(rustc_ast::Ty { kind, id: ty.id, span: ty.span, tokens: None }) + Box::new(rustc_ast::Ty { kind, id: ty.id, span: ty.span, tokens: None }) } FnRetTy::Default(span) => { if act_ret.len() == 1 { act_ret[0].clone() } else { let kind = TyKind::Tup(act_ret.iter().map(|arg| arg.clone()).collect()); - P(rustc_ast::Ty { kind, id: ast::DUMMY_NODE_ID, span, tokens: None }) + Box::new(rustc_ast::Ty { kind, id: ast::DUMMY_NODE_ID, span, tokens: None }) } } }; diff --git a/compiler/rustc_builtin_macros/src/cfg_accessible.rs b/compiler/rustc_builtin_macros/src/cfg_accessible.rs index 5f203dd5d11..f7d8f4aa783 100644 --- a/compiler/rustc_builtin_macros/src/cfg_accessible.rs +++ b/compiler/rustc_builtin_macros/src/cfg_accessible.rs @@ -44,7 +44,7 @@ impl MultiItemModifier for Expander { item: Annotatable, _is_derive_const: bool, ) -> ExpandResult<Vec<Annotatable>, Annotatable> { - let template = AttributeTemplate { list: Some("path"), ..Default::default() }; + let template = AttributeTemplate { list: Some(&["path"]), ..Default::default() }; validate_attr::check_builtin_meta_item( &ecx.sess.psess, meta_item, diff --git a/compiler/rustc_builtin_macros/src/cfg_eval.rs b/compiler/rustc_builtin_macros/src/cfg_eval.rs index ec3b87467a9..dd770fe5f1a 100644 --- a/compiler/rustc_builtin_macros/src/cfg_eval.rs +++ b/compiler/rustc_builtin_macros/src/cfg_eval.rs @@ -2,7 +2,6 @@ use core::ops::ControlFlow; use rustc_ast as ast; use rustc_ast::mut_visit::MutVisitor; -use rustc_ast::ptr::P; use rustc_ast::visit::{AssocCtxt, Visitor}; use rustc_ast::{Attribute, HasAttrs, HasTokens, NodeId, mut_visit, visit}; use rustc_errors::PResult; @@ -132,7 +131,7 @@ impl CfgEval<'_> { let stmt = parser .parse_stmt_without_recovery(false, ForceCollect::Yes, false)? .unwrap(); - Annotatable::Stmt(P(self.flat_map_stmt(stmt).pop().unwrap())) + Annotatable::Stmt(Box::new(self.flat_map_stmt(stmt).pop().unwrap())) } Annotatable::Expr(_) => { let mut expr = parser.parse_expr_force_collect()?; @@ -166,7 +165,7 @@ impl MutVisitor for CfgEval<'_> { mut_visit::walk_expr(self, expr); } - fn filter_map_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> { + fn filter_map_expr(&mut self, expr: Box<ast::Expr>) -> Option<Box<ast::Expr>> { let mut expr = configure!(self, expr); mut_visit::walk_expr(self, &mut expr); Some(expr) @@ -185,24 +184,24 @@ impl MutVisitor for CfgEval<'_> { mut_visit::walk_flat_map_stmt(self, stmt) } - fn flat_map_item(&mut self, item: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> { + fn flat_map_item(&mut self, item: Box<ast::Item>) -> SmallVec<[Box<ast::Item>; 1]> { let item = configure!(self, item); mut_visit::walk_flat_map_item(self, item) } fn flat_map_assoc_item( &mut self, - item: P<ast::AssocItem>, + item: Box<ast::AssocItem>, ctxt: AssocCtxt, - ) -> SmallVec<[P<ast::AssocItem>; 1]> { + ) -> SmallVec<[Box<ast::AssocItem>; 1]> { let item = configure!(self, item); mut_visit::walk_flat_map_assoc_item(self, item, ctxt) } fn flat_map_foreign_item( &mut self, - foreign_item: P<ast::ForeignItem>, - ) -> SmallVec<[P<ast::ForeignItem>; 1]> { + foreign_item: Box<ast::ForeignItem>, + ) -> SmallVec<[Box<ast::ForeignItem>; 1]> { let foreign_item = configure!(self, foreign_item); mut_visit::walk_flat_map_foreign_item(self, foreign_item) } diff --git a/compiler/rustc_builtin_macros/src/concat_bytes.rs b/compiler/rustc_builtin_macros/src/concat_bytes.rs index fd2d740c020..8885017b930 100644 --- a/compiler/rustc_builtin_macros/src/concat_bytes.rs +++ b/compiler/rustc_builtin_macros/src/concat_bytes.rs @@ -1,4 +1,3 @@ -use rustc_ast::ptr::P; use rustc_ast::tokenstream::TokenStream; use rustc_ast::{ExprKind, LitIntType, LitKind, StrStyle, UintTy, token}; use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpanderResult}; @@ -90,7 +89,7 @@ fn handle_array_element( cx: &ExtCtxt<'_>, guar: &mut Option<ErrorGuaranteed>, missing_literals: &mut Vec<rustc_span::Span>, - expr: &P<rustc_ast::Expr>, + expr: &Box<rustc_ast::Expr>, ) -> Option<u8> { let dcx = cx.dcx(); diff --git a/compiler/rustc_builtin_macros/src/derive.rs b/compiler/rustc_builtin_macros/src/derive.rs index e259f5b3955..a33eca43de5 100644 --- a/compiler/rustc_builtin_macros/src/derive.rs +++ b/compiler/rustc_builtin_macros/src/derive.rs @@ -34,8 +34,10 @@ impl MultiItemModifier for Expander { let (sess, features) = (ecx.sess, ecx.ecfg.features); let result = ecx.resolver.resolve_derives(ecx.current_expansion.id, ecx.force_mode, &|| { - let template = - AttributeTemplate { list: Some("Trait1, Trait2, ..."), ..Default::default() }; + let template = AttributeTemplate { + list: Some(&["Trait1, Trait2, ..."]), + ..Default::default() + }; validate_attr::check_builtin_meta_item( &sess.psess, meta_item, diff --git a/compiler/rustc_builtin_macros/src/deriving/cmp/partial_eq.rs b/compiler/rustc_builtin_macros/src/deriving/cmp/partial_eq.rs index 990835fa277..a0f71a1868b 100644 --- a/compiler/rustc_builtin_macros/src/deriving/cmp/partial_eq.rs +++ b/compiler/rustc_builtin_macros/src/deriving/cmp/partial_eq.rs @@ -1,4 +1,3 @@ -use rustc_ast::ptr::P; use rustc_ast::{BinOpKind, BorrowKind, Expr, ExprKind, MetaItem, Mutability}; use rustc_expand::base::{Annotatable, ExtCtxt}; use rustc_span::{Span, sym}; @@ -119,7 +118,7 @@ fn get_substructure_equality_expr( cx: &ExtCtxt<'_>, span: Span, substructure: &Substructure<'_>, -) -> P<Expr> { +) -> Box<Expr> { use SubstructureFields::*; match substructure.fields { @@ -180,7 +179,7 @@ fn get_substructure_equality_expr( /// /// Panics if there are not exactly two arguments to compare (should be `self` /// and `other`). -fn get_field_equality_expr(cx: &ExtCtxt<'_>, field: &FieldInfo) -> P<Expr> { +fn get_field_equality_expr(cx: &ExtCtxt<'_>, field: &FieldInfo) -> Box<Expr> { let [rhs] = &field.other_selflike_exprs[..] else { cx.dcx().span_bug(field.span, "not exactly 2 arguments in `derive(PartialEq)`"); }; @@ -198,7 +197,7 @@ fn get_field_equality_expr(cx: &ExtCtxt<'_>, field: &FieldInfo) -> P<Expr> { /// This is used to strip away any number of leading `&` from an expression /// (e.g., `&&&T` becomes `T`). Only removes immutable references; mutable /// references are preserved. -fn peel_refs(mut expr: &P<Expr>) -> P<Expr> { +fn peel_refs(mut expr: &Box<Expr>) -> Box<Expr> { while let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner) = &expr.kind { expr = &inner; } @@ -210,7 +209,7 @@ fn peel_refs(mut expr: &P<Expr>) -> P<Expr> { /// /// If the given expression is a block, it is wrapped in parentheses; otherwise, /// it is returned unchanged. -fn wrap_block_expr(cx: &ExtCtxt<'_>, expr: P<Expr>) -> P<Expr> { +fn wrap_block_expr(cx: &ExtCtxt<'_>, expr: Box<Expr>) -> Box<Expr> { if matches!(&expr.kind, ExprKind::Block(..)) { return cx.expr_paren(expr.span, expr); } diff --git a/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs b/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs index 6082e376435..75db5d77783 100644 --- a/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs +++ b/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs @@ -108,11 +108,7 @@ pub(crate) fn expand_deriving_coerce_pointee( cx.item( span, attrs.clone(), - ast::ItemKind::Impl(Box::new(ast::Impl { - safety: ast::Safety::Default, - polarity: ast::ImplPolarity::Positive, - defaultness: ast::Defaultness::Final, - constness: ast::Const::No, + ast::ItemKind::Impl(ast::Impl { generics: Generics { params: generics .params @@ -137,10 +133,16 @@ pub(crate) fn expand_deriving_coerce_pointee( where_clause: generics.where_clause.clone(), span: generics.span, }, - of_trait: Some(trait_ref), + of_trait: Some(Box::new(ast::TraitImplHeader { + safety: ast::Safety::Default, + polarity: ast::ImplPolarity::Positive, + defaultness: ast::Defaultness::Final, + constness: ast::Const::No, + trait_ref, + })), self_ty: self_type.clone(), items: ThinVec::new(), - })), + }), ), )); } @@ -152,16 +154,18 @@ pub(crate) fn expand_deriving_coerce_pointee( let item = cx.item( span, attrs.clone(), - ast::ItemKind::Impl(Box::new(ast::Impl { - safety: ast::Safety::Default, - polarity: ast::ImplPolarity::Positive, - defaultness: ast::Defaultness::Final, - constness: ast::Const::No, + ast::ItemKind::Impl(ast::Impl { generics, - of_trait: Some(trait_ref), + of_trait: Some(Box::new(ast::TraitImplHeader { + safety: ast::Safety::Default, + polarity: ast::ImplPolarity::Positive, + defaultness: ast::Defaultness::Final, + constness: ast::Const::No, + trait_ref, + })), self_ty: self_type.clone(), items: ThinVec::new(), - })), + }), ); push(Annotatable::Item(item)); }; diff --git a/compiler/rustc_builtin_macros/src/deriving/debug.rs b/compiler/rustc_builtin_macros/src/deriving/debug.rs index 1d63ce7d5fd..597af0e09c0 100644 --- a/compiler/rustc_builtin_macros/src/deriving/debug.rs +++ b/compiler/rustc_builtin_macros/src/deriving/debug.rs @@ -94,7 +94,7 @@ fn show_substructure(cx: &ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> field: &FieldInfo, index: usize, len: usize, - ) -> ast::ptr::P<ast::Expr> { + ) -> Box<ast::Expr> { if index < len - 1 { field.self_expr.clone() } else { diff --git a/compiler/rustc_builtin_macros/src/deriving/default.rs b/compiler/rustc_builtin_macros/src/deriving/default.rs index b4e2d27fed3..2462114ec24 100644 --- a/compiler/rustc_builtin_macros/src/deriving/default.rs +++ b/compiler/rustc_builtin_macros/src/deriving/default.rs @@ -56,7 +56,7 @@ pub(crate) fn expand_deriving_default( trait_def.expand(cx, mitem, item, push) } -fn default_call(cx: &ExtCtxt<'_>, span: Span) -> ast::ptr::P<ast::Expr> { +fn default_call(cx: &ExtCtxt<'_>, span: Span) -> Box<ast::Expr> { // Note that `kw::Default` is "default" and `sym::Default` is "Default"! let default_ident = cx.std_path(&[kw::Default, sym::Default, kw::Default]); cx.expr_call_global(span, default_ident, ThinVec::new()) diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index fc9eed24ee0..3fcf9da9450 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -180,7 +180,6 @@ use std::{iter, vec}; pub(crate) use StaticFields::*; pub(crate) use SubstructureFields::*; -use rustc_ast::ptr::P; use rustc_ast::token::{IdentIsRaw, LitKind, Token, TokenKind}; use rustc_ast::tokenstream::{DelimSpan, Spacing, TokenTree}; use rustc_ast::{ @@ -272,7 +271,7 @@ pub(crate) struct Substructure<'a> { pub type_ident: Ident, /// Verbatim access to any non-selflike arguments, i.e. arguments that /// don't have type `&Self`. - pub nonselflike_args: &'a [P<Expr>], + pub nonselflike_args: &'a [Box<Expr>], pub fields: &'a SubstructureFields<'a>, } @@ -284,10 +283,10 @@ pub(crate) struct FieldInfo { pub name: Option<Ident>, /// The expression corresponding to this field of `self` /// (specifically, a reference to it). - pub self_expr: P<Expr>, + pub self_expr: Box<Expr>, /// The expressions corresponding to references to this field in /// the other selflike arguments. - pub other_selflike_exprs: Vec<P<Expr>>, + pub other_selflike_exprs: Vec<Box<Expr>>, pub maybe_scalar: bool, } @@ -323,7 +322,7 @@ pub(crate) enum SubstructureFields<'a> { /// The discriminant of an enum. The first field is a `FieldInfo` for the discriminants, as /// if they were fields. The second field is the expression to combine the /// discriminant expression with; it will be `None` if no match is necessary. - EnumDiscr(FieldInfo, Option<P<Expr>>), + EnumDiscr(FieldInfo, Option<Box<Expr>>), /// A static method where `Self` is a struct. StaticStruct(&'a ast::VariantData, StaticFields), @@ -345,7 +344,7 @@ pub(crate) fn combine_substructure( struct TypeParameter { bound_generic_params: ThinVec<ast::GenericParam>, - ty: P<ast::Ty>, + ty: Box<ast::Ty>, } /// The code snippets built up for derived code are sometimes used as blocks @@ -354,23 +353,23 @@ struct TypeParameter { /// avoiding the insertion of any unnecessary blocks. /// /// The statements come before the expression. -pub(crate) struct BlockOrExpr(ThinVec<ast::Stmt>, Option<P<Expr>>); +pub(crate) struct BlockOrExpr(ThinVec<ast::Stmt>, Option<Box<Expr>>); impl BlockOrExpr { pub(crate) fn new_stmts(stmts: ThinVec<ast::Stmt>) -> BlockOrExpr { BlockOrExpr(stmts, None) } - pub(crate) fn new_expr(expr: P<Expr>) -> BlockOrExpr { + pub(crate) fn new_expr(expr: Box<Expr>) -> BlockOrExpr { BlockOrExpr(ThinVec::new(), Some(expr)) } - pub(crate) fn new_mixed(stmts: ThinVec<ast::Stmt>, expr: Option<P<Expr>>) -> BlockOrExpr { + pub(crate) fn new_mixed(stmts: ThinVec<ast::Stmt>, expr: Option<Box<Expr>>) -> BlockOrExpr { BlockOrExpr(stmts, expr) } // Converts it into a block. - fn into_block(mut self, cx: &ExtCtxt<'_>, span: Span) -> P<ast::Block> { + fn into_block(mut self, cx: &ExtCtxt<'_>, span: Span) -> Box<ast::Block> { if let Some(expr) = self.1 { self.0.push(cx.stmt_expr(expr)); } @@ -378,7 +377,7 @@ impl BlockOrExpr { } // Converts it into an expression. - fn into_expr(self, cx: &ExtCtxt<'_>, span: Span) -> P<Expr> { + fn into_expr(self, cx: &ExtCtxt<'_>, span: Span) -> Box<Expr> { if self.0.is_empty() { match self.1 { None => cx.expr_block(cx.block(span, ThinVec::new())), @@ -432,7 +431,7 @@ fn find_type_parameters( { self.type_params.push(TypeParameter { bound_generic_params: self.bound_generic_params_stack.clone(), - ty: P(ty.clone()), + ty: Box::new(ty.clone()), }); } @@ -544,7 +543,7 @@ impl<'a> TraitDef<'a> { }) .cloned(), ); - push(Annotatable::Item(P(ast::Item { attrs, ..(*newitem).clone() }))) + push(Annotatable::Item(Box::new(ast::Item { attrs, ..(*newitem).clone() }))) } _ => unreachable!(), } @@ -590,15 +589,15 @@ impl<'a> TraitDef<'a> { cx: &ExtCtxt<'_>, type_ident: Ident, generics: &Generics, - field_tys: Vec<P<ast::Ty>>, - methods: Vec<P<ast::AssocItem>>, + field_tys: Vec<Box<ast::Ty>>, + methods: Vec<Box<ast::AssocItem>>, is_packed: bool, - ) -> P<ast::Item> { + ) -> Box<ast::Item> { let trait_path = self.path.to_path(cx, self.span, type_ident, generics); // Transform associated types from `deriving::ty::Ty` into `ast::AssocItem` let associated_types = self.associated_types.iter().map(|&(ident, ref type_def)| { - P(ast::AssocItem { + Box::new(ast::AssocItem { id: ast::DUMMY_NODE_ID, span: self.span, vis: ast::Visibility { @@ -827,21 +826,25 @@ impl<'a> TraitDef<'a> { ) } - let opt_trait_ref = Some(trait_ref); - cx.item( self.span, attrs, - ast::ItemKind::Impl(Box::new(ast::Impl { - safety: ast::Safety::Default, - polarity: ast::ImplPolarity::Positive, - defaultness: ast::Defaultness::Final, - constness: if self.is_const { ast::Const::Yes(DUMMY_SP) } else { ast::Const::No }, + ast::ItemKind::Impl(ast::Impl { generics: trait_generics, - of_trait: opt_trait_ref, + of_trait: Some(Box::new(ast::TraitImplHeader { + safety: ast::Safety::Default, + polarity: ast::ImplPolarity::Positive, + defaultness: ast::Defaultness::Final, + constness: if self.is_const { + ast::Const::Yes(DUMMY_SP) + } else { + ast::Const::No + }, + trait_ref, + })), self_ty: self_type, items: methods.into_iter().chain(associated_types).collect(), - })), + }), ) } @@ -853,8 +856,8 @@ impl<'a> TraitDef<'a> { generics: &Generics, from_scratch: bool, is_packed: bool, - ) -> P<ast::Item> { - let field_tys: Vec<P<ast::Ty>> = + ) -> Box<ast::Item> { + let field_tys: Vec<Box<ast::Ty>> = struct_def.fields().iter().map(|field| field.ty.clone()).collect(); let methods = self @@ -906,7 +909,7 @@ impl<'a> TraitDef<'a> { type_ident: Ident, generics: &Generics, from_scratch: bool, - ) -> P<ast::Item> { + ) -> Box<ast::Item> { let mut field_tys = Vec::new(); for variant in &enum_def.variants { @@ -962,7 +965,7 @@ impl<'a> MethodDef<'a> { cx: &ExtCtxt<'_>, trait_: &TraitDef<'_>, type_ident: Ident, - nonselflike_args: &[P<Expr>], + nonselflike_args: &[Box<Expr>], fields: &SubstructureFields<'_>, ) -> BlockOrExpr { let span = trait_.span; @@ -978,7 +981,7 @@ impl<'a> MethodDef<'a> { trait_: &TraitDef<'_>, generics: &Generics, type_ident: Ident, - ) -> P<ast::Ty> { + ) -> Box<ast::Ty> { self.ret_ty.to_ty(cx, trait_.span, type_ident, generics) } @@ -999,7 +1002,8 @@ impl<'a> MethodDef<'a> { trait_: &TraitDef<'_>, type_ident: Ident, generics: &Generics, - ) -> (Option<ast::ExplicitSelf>, ThinVec<P<Expr>>, Vec<P<Expr>>, Vec<(Ident, P<ast::Ty>)>) { + ) -> (Option<ast::ExplicitSelf>, ThinVec<Box<Expr>>, Vec<Box<Expr>>, Vec<(Ident, Box<ast::Ty>)>) + { let mut selflike_args = ThinVec::new(); let mut nonselflike_args = Vec::new(); let mut nonself_arg_tys = Vec::new(); @@ -1036,9 +1040,9 @@ impl<'a> MethodDef<'a> { type_ident: Ident, generics: &Generics, explicit_self: Option<ast::ExplicitSelf>, - nonself_arg_tys: Vec<(Ident, P<ast::Ty>)>, + nonself_arg_tys: Vec<(Ident, Box<ast::Ty>)>, body: BlockOrExpr, - ) -> P<ast::AssocItem> { + ) -> Box<ast::AssocItem> { let span = trait_.span; // Create the generics that aren't for `Self`. let fn_generics = self.generics.to_generics(cx, span, type_ident, generics); @@ -1065,7 +1069,7 @@ impl<'a> MethodDef<'a> { let defaultness = ast::Defaultness::Final; // Create the method. - P(ast::AssocItem { + Box::new(ast::AssocItem { id: ast::DUMMY_NODE_ID, attrs: self.attributes.clone(), span, @@ -1128,8 +1132,8 @@ impl<'a> MethodDef<'a> { trait_: &TraitDef<'b>, struct_def: &'b VariantData, type_ident: Ident, - selflike_args: &[P<Expr>], - nonselflike_args: &[P<Expr>], + selflike_args: &[Box<Expr>], + nonselflike_args: &[Box<Expr>], is_packed: bool, ) -> BlockOrExpr { assert!(selflike_args.len() == 1 || selflike_args.len() == 2); @@ -1151,7 +1155,7 @@ impl<'a> MethodDef<'a> { trait_: &TraitDef<'_>, struct_def: &VariantData, type_ident: Ident, - nonselflike_args: &[P<Expr>], + nonselflike_args: &[Box<Expr>], ) -> BlockOrExpr { let summary = trait_.summarise_struct(cx, struct_def); @@ -1205,8 +1209,8 @@ impl<'a> MethodDef<'a> { trait_: &TraitDef<'b>, enum_def: &'b EnumDef, type_ident: Ident, - mut selflike_args: ThinVec<P<Expr>>, - nonselflike_args: &[P<Expr>], + mut selflike_args: ThinVec<Box<Expr>>, + nonselflike_args: &[Box<Expr>], ) -> BlockOrExpr { assert!( !selflike_args.is_empty(), @@ -1418,7 +1422,7 @@ impl<'a> MethodDef<'a> { // ... // _ => ::core::intrinsics::unreachable(), // } - let get_match_expr = |mut selflike_args: ThinVec<P<Expr>>| { + let get_match_expr = |mut selflike_args: ThinVec<Box<Expr>>| { let match_arg = if selflike_args.len() == 1 { selflike_args.pop().unwrap() } else { @@ -1454,7 +1458,7 @@ impl<'a> MethodDef<'a> { trait_: &TraitDef<'_>, enum_def: &EnumDef, type_ident: Ident, - nonselflike_args: &[P<Expr>], + nonselflike_args: &[Box<Expr>], ) -> BlockOrExpr { self.call_substructure_method( cx, @@ -1503,7 +1507,7 @@ impl<'a> TraitDef<'a> { struct_def: &'a VariantData, prefixes: &[String], by_ref: ByRef, - ) -> ThinVec<P<ast::Pat>> { + ) -> ThinVec<Box<ast::Pat>> { prefixes .iter() .map(|prefix| { @@ -1558,7 +1562,7 @@ impl<'a> TraitDef<'a> { fn create_fields<F>(&self, struct_def: &'a VariantData, mk_exprs: F) -> Vec<FieldInfo> where - F: Fn(usize, &ast::FieldDef, Span) -> Vec<P<ast::Expr>>, + F: Fn(usize, &ast::FieldDef, Span) -> Vec<Box<ast::Expr>>, { struct_def .fields() @@ -1606,7 +1610,7 @@ impl<'a> TraitDef<'a> { fn create_struct_field_access_fields( &self, cx: &ExtCtxt<'_>, - selflike_args: &[P<Expr>], + selflike_args: &[Box<Expr>], struct_def: &'a VariantData, is_packed: bool, ) -> Vec<FieldInfo> { @@ -1651,7 +1655,7 @@ pub(crate) enum CsFold<'a> { /// The combination of two field expressions. E.g. for `PartialEq::eq` this /// is something like `<field1 equality> && <field2 equality>`. - Combine(Span, P<Expr>, P<Expr>), + Combine(Span, Box<Expr>, Box<Expr>), // The fallback case for a struct or enum variant with no fields. Fieldless, @@ -1665,9 +1669,9 @@ pub(crate) fn cs_fold<F>( trait_span: Span, substructure: &Substructure<'_>, mut f: F, -) -> P<Expr> +) -> Box<Expr> where - F: FnMut(&ExtCtxt<'_>, CsFold<'_>) -> P<Expr>, + F: FnMut(&ExtCtxt<'_>, CsFold<'_>) -> Box<Expr>, { match substructure.fields { EnumMatching(.., all_fields) | Struct(_, all_fields) => { diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs b/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs index f34a6ae1d98..00e70b21cf4 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs @@ -2,7 +2,6 @@ //! when specifying impls to be derived. pub(crate) use Ty::*; -use rustc_ast::ptr::P; use rustc_ast::{self as ast, Expr, GenericArg, GenericParamKind, Generics, SelfKind}; use rustc_expand::base::ExtCtxt; use rustc_span::source_map::respan; @@ -41,7 +40,7 @@ impl Path { span: Span, self_ty: Ident, self_generics: &Generics, - ) -> P<ast::Ty> { + ) -> Box<ast::Ty> { cx.ty_path(self.to_path(cx, span, self_ty, self_generics)) } pub(crate) fn to_path( @@ -90,7 +89,7 @@ impl Ty { span: Span, self_ty: Ident, self_generics: &Generics, - ) -> P<ast::Ty> { + ) -> Box<ast::Ty> { match self { Ref(ty, mutbl) => { let raw_ty = ty.to_ty(cx, span, self_ty, self_generics); @@ -192,7 +191,7 @@ impl Bounds { } } -pub(crate) fn get_explicit_self(cx: &ExtCtxt<'_>, span: Span) -> (P<Expr>, ast::ExplicitSelf) { +pub(crate) fn get_explicit_self(cx: &ExtCtxt<'_>, span: Span) -> (Box<Expr>, ast::ExplicitSelf) { // This constructs a fresh `self` path. let self_path = cx.expr_self(span); let self_ty = respan(span, SelfKind::Region(None, ast::Mutability::Not)); diff --git a/compiler/rustc_builtin_macros/src/deriving/mod.rs b/compiler/rustc_builtin_macros/src/deriving/mod.rs index e45d09b5796..1edc2965def 100644 --- a/compiler/rustc_builtin_macros/src/deriving/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/mod.rs @@ -1,7 +1,6 @@ //! The compiler code necessary to implement the `#[derive]` extensions. use rustc_ast as ast; -use rustc_ast::ptr::P; use rustc_ast::{GenericArg, MetaItem}; use rustc_expand::base::{Annotatable, ExpandResult, ExtCtxt, MultiItemModifier}; use rustc_span::{Span, Symbol, sym}; @@ -66,7 +65,7 @@ impl MultiItemModifier for BuiltinDerive { &mut |a| { // Cannot use 'ecx.stmt_item' here, because we need to pass 'ecx' // to the function - items.push(Annotatable::Stmt(P(ast::Stmt { + items.push(Annotatable::Stmt(Box::new(ast::Stmt { id: ast::DUMMY_NODE_ID, kind: ast::StmtKind::Item(a.expect_item()), span, @@ -91,20 +90,20 @@ fn call_intrinsic( cx: &ExtCtxt<'_>, span: Span, intrinsic: Symbol, - args: ThinVec<P<ast::Expr>>, -) -> P<ast::Expr> { + args: ThinVec<Box<ast::Expr>>, +) -> Box<ast::Expr> { let span = cx.with_def_site_ctxt(span); let path = cx.std_path(&[sym::intrinsics, intrinsic]); cx.expr_call_global(span, path, args) } /// Constructs an expression that calls the `unreachable` intrinsic. -fn call_unreachable(cx: &ExtCtxt<'_>, span: Span) -> P<ast::Expr> { +fn call_unreachable(cx: &ExtCtxt<'_>, span: Span) -> Box<ast::Expr> { let span = cx.with_def_site_ctxt(span); let path = cx.std_path(&[sym::intrinsics, sym::unreachable]); let call = cx.expr_call_global(span, path, ThinVec::new()); - cx.expr_block(P(ast::Block { + cx.expr_block(Box::new(ast::Block { stmts: thin_vec![cx.stmt_expr(call)], id: ast::DUMMY_NODE_ID, rules: ast::BlockCheckMode::Unsafe(ast::CompilerGenerated), @@ -116,7 +115,7 @@ fn call_unreachable(cx: &ExtCtxt<'_>, span: Span) -> P<ast::Expr> { fn assert_ty_bounds( cx: &ExtCtxt<'_>, stmts: &mut ThinVec<ast::Stmt>, - ty: P<ast::Ty>, + ty: Box<ast::Ty>, span: Span, assert_path: &[Symbol], ) { diff --git a/compiler/rustc_builtin_macros/src/edition_panic.rs b/compiler/rustc_builtin_macros/src/edition_panic.rs index ccfcc3079eb..08f555b9e52 100644 --- a/compiler/rustc_builtin_macros/src/edition_panic.rs +++ b/compiler/rustc_builtin_macros/src/edition_panic.rs @@ -1,4 +1,3 @@ -use rustc_ast::ptr::P; use rustc_ast::token::Delimiter; use rustc_ast::tokenstream::{DelimSpan, TokenStream}; use rustc_ast::*; @@ -48,7 +47,7 @@ fn expand<'cx>( ExpandResult::Ready(MacEager::expr( cx.expr( sp, - ExprKind::MacCall(P(MacCall { + ExprKind::MacCall(Box::new(MacCall { path: Path { span: sp, segments: cx @@ -58,7 +57,7 @@ fn expand<'cx>( .collect(), tokens: None, }, - args: P(DelimArgs { + args: Box::new(DelimArgs { dspan: DelimSpan::from_single(sp), delim: Delimiter::Parenthesis, tokens: tts, diff --git a/compiler/rustc_builtin_macros/src/format.rs b/compiler/rustc_builtin_macros/src/format.rs index 6785cb6aef5..ec613b7b710 100644 --- a/compiler/rustc_builtin_macros/src/format.rs +++ b/compiler/rustc_builtin_macros/src/format.rs @@ -1,7 +1,6 @@ use std::ops::Range; use parse::Position::ArgumentNamed; -use rustc_ast::ptr::P; use rustc_ast::tokenstream::TokenStream; use rustc_ast::{ Expr, ExprKind, FormatAlignment, FormatArgPosition, FormatArgPositionKind, FormatArgs, @@ -45,7 +44,7 @@ use PositionUsedAs::*; #[derive(Debug)] struct MacroInput { - fmtstr: P<Expr>, + fmtstr: Box<Expr>, args: FormatArguments, /// Whether the first argument was a string literal or a result from eager macro expansion. /// If it's not a string literal, we disallow implicit argument capturing. @@ -1018,7 +1017,7 @@ fn expand_format_args_impl<'cx>( }; match mac { Ok(format_args) => { - MacEager::expr(ecx.expr(sp, ExprKind::FormatArgs(P(format_args)))) + MacEager::expr(ecx.expr(sp, ExprKind::FormatArgs(Box::new(format_args)))) } Err(guar) => MacEager::expr(DummyResult::raw_expr(sp, Some(guar))), } diff --git a/compiler/rustc_builtin_macros/src/format_foreign.rs b/compiler/rustc_builtin_macros/src/format_foreign.rs index 13d5b42942a..3e5a26c0556 100644 --- a/compiler/rustc_builtin_macros/src/format_foreign.rs +++ b/compiler/rustc_builtin_macros/src/format_foreign.rs @@ -346,18 +346,18 @@ pub(crate) mod printf { // ```regex // (?x) // ^ % - // (?: (?P<parameter> \d+) \$ )? - // (?P<flags> [-+ 0\#']* ) - // (?P<width> \d+ | \* (?: (?P<widtha> \d+) \$ )? )? - // (?: \. (?P<precision> \d+ | \* (?: (?P<precisiona> \d+) \$ )? ) )? - // (?P<length> + // (?: (?Box<parameter> \d+) \$ )? + // (?Box<flags> [-+ 0\#']* ) + // (?Box<width> \d+ | \* (?: (?Box<widtha> \d+) \$ )? )? + // (?: \. (?Box<precision> \d+ | \* (?: (?Box<precisiona> \d+) \$ )? ) )? + // (?Box<length> // # Standard // hh | h | ll | l | L | z | j | t // // # Other // | I32 | I64 | I | q // )? - // (?P<type> . ) + // (?Box<type> . ) // ``` // Used to establish the full span at the end. diff --git a/compiler/rustc_builtin_macros/src/global_allocator.rs b/compiler/rustc_builtin_macros/src/global_allocator.rs index 4b1958bce32..f14b1920722 100644 --- a/compiler/rustc_builtin_macros/src/global_allocator.rs +++ b/compiler/rustc_builtin_macros/src/global_allocator.rs @@ -1,7 +1,6 @@ use rustc_ast::expand::allocator::{ ALLOCATOR_METHODS, AllocatorMethod, AllocatorMethodInput, AllocatorTy, global_fn_name, }; -use rustc_ast::ptr::P; use rustc_ast::{ self as ast, AttrVec, Expr, Fn, FnHeader, FnSig, Generics, ItemKind, Mutability, Param, Safety, Stmt, StmtKind, Ty, TyKind, @@ -51,7 +50,7 @@ pub(crate) fn expand( let const_body = ecx.expr_block(ecx.block(span, stmts)); let const_item = ecx.item_const(span, Ident::new(kw::Underscore, span), const_ty, const_body); let const_item = if is_stmt { - Annotatable::Stmt(P(ecx.stmt_item(span, const_item))) + Annotatable::Stmt(Box::new(ecx.stmt_item(span, const_item))) } else { Annotatable::Item(const_item) }; @@ -90,7 +89,7 @@ impl AllocFnFactory<'_, '_> { self.cx.stmt_item(self.ty_span, item) } - fn call_allocator(&self, method: Symbol, mut args: ThinVec<P<Expr>>) -> P<Expr> { + fn call_allocator(&self, method: Symbol, mut args: ThinVec<Box<Expr>>) -> Box<Expr> { let method = self.cx.std_path(&[sym::alloc, sym::GlobalAlloc, method]); let method = self.cx.expr_path(self.cx.path(self.ty_span, method)); let allocator = self.cx.path_ident(self.ty_span, self.global); @@ -105,7 +104,7 @@ impl AllocFnFactory<'_, '_> { thin_vec![self.cx.attr_word(sym::rustc_std_internal_symbol, self.span)] } - fn arg_ty(&self, input: &AllocatorMethodInput, args: &mut ThinVec<Param>) -> P<Expr> { + fn arg_ty(&self, input: &AllocatorMethodInput, args: &mut ThinVec<Param>) -> Box<Expr> { match input.ty { AllocatorTy::Layout => { // If an allocator method is ever introduced having multiple @@ -148,7 +147,7 @@ impl AllocFnFactory<'_, '_> { } } - fn ret_ty(&self, ty: &AllocatorTy) -> P<Ty> { + fn ret_ty(&self, ty: &AllocatorTy) -> Box<Ty> { match *ty { AllocatorTy::ResultPtr => self.ptr_u8(), @@ -160,12 +159,12 @@ impl AllocFnFactory<'_, '_> { } } - fn usize(&self) -> P<Ty> { + fn usize(&self) -> Box<Ty> { let usize = self.cx.path_ident(self.span, Ident::new(sym::usize, self.span)); self.cx.ty_path(usize) } - fn ptr_u8(&self) -> P<Ty> { + fn ptr_u8(&self) -> Box<Ty> { let u8 = self.cx.path_ident(self.span, Ident::new(sym::u8, self.span)); let ty_u8 = self.cx.ty_path(u8); self.cx.ty_ptr(self.span, ty_u8, Mutability::Mut) diff --git a/compiler/rustc_builtin_macros/src/iter.rs b/compiler/rustc_builtin_macros/src/iter.rs index 7ad83903a1b..e9f340ef119 100644 --- a/compiler/rustc_builtin_macros/src/iter.rs +++ b/compiler/rustc_builtin_macros/src/iter.rs @@ -1,4 +1,3 @@ -use rustc_ast::ptr::P; use rustc_ast::tokenstream::TokenStream; use rustc_ast::{CoroutineKind, DUMMY_NODE_ID, Expr, ast, token}; use rustc_errors::PResult; @@ -24,7 +23,7 @@ fn parse_closure<'a>( cx: &mut ExtCtxt<'a>, span: Span, stream: TokenStream, -) -> PResult<'a, P<Expr>> { +) -> PResult<'a, Box<Expr>> { let mut closure_parser = cx.new_parser_from_tts(stream); let coroutine_kind = Some(CoroutineKind::Gen { diff --git a/compiler/rustc_builtin_macros/src/pattern_type.rs b/compiler/rustc_builtin_macros/src/pattern_type.rs index b61af0b0aaa..34faafdc07c 100644 --- a/compiler/rustc_builtin_macros/src/pattern_type.rs +++ b/compiler/rustc_builtin_macros/src/pattern_type.rs @@ -1,4 +1,3 @@ -use rustc_ast::ptr::P; use rustc_ast::tokenstream::TokenStream; use rustc_ast::{AnonConst, DUMMY_NODE_ID, Ty, TyPat, TyPatKind, ast, token}; use rustc_errors::PResult; @@ -22,7 +21,10 @@ pub(crate) fn expand<'cx>( ExpandResult::Ready(base::MacEager::ty(cx.ty(sp, ast::TyKind::Pat(ty, pat)))) } -fn parse_pat_ty<'a>(cx: &mut ExtCtxt<'a>, stream: TokenStream) -> PResult<'a, (P<Ty>, P<TyPat>)> { +fn parse_pat_ty<'a>( + cx: &mut ExtCtxt<'a>, + stream: TokenStream, +) -> PResult<'a, (Box<Ty>, Box<TyPat>)> { let mut parser = cx.new_parser_from_tts(stream); let ty = parser.parse_ty()?; @@ -45,15 +47,15 @@ fn parse_pat_ty<'a>(cx: &mut ExtCtxt<'a>, stream: TokenStream) -> PResult<'a, (P Ok((ty, pat)) } -fn ty_pat(kind: TyPatKind, span: Span) -> P<TyPat> { - P(TyPat { id: DUMMY_NODE_ID, kind, span, tokens: None }) +fn ty_pat(kind: TyPatKind, span: Span) -> Box<TyPat> { + Box::new(TyPat { id: DUMMY_NODE_ID, kind, span, tokens: None }) } -fn pat_to_ty_pat(cx: &mut ExtCtxt<'_>, pat: ast::Pat) -> P<TyPat> { +fn pat_to_ty_pat(cx: &mut ExtCtxt<'_>, pat: ast::Pat) -> Box<TyPat> { let kind = match pat.kind { ast::PatKind::Range(start, end, include_end) => TyPatKind::Range( - start.map(|value| P(AnonConst { id: DUMMY_NODE_ID, value })), - end.map(|value| P(AnonConst { id: DUMMY_NODE_ID, value })), + start.map(|value| Box::new(AnonConst { id: DUMMY_NODE_ID, value })), + end.map(|value| Box::new(AnonConst { id: DUMMY_NODE_ID, value })), include_end, ), ast::PatKind::Or(variants) => { diff --git a/compiler/rustc_builtin_macros/src/proc_macro_harness.rs b/compiler/rustc_builtin_macros/src/proc_macro_harness.rs index df70c93c1c2..f440adf6cf0 100644 --- a/compiler/rustc_builtin_macros/src/proc_macro_harness.rs +++ b/compiler/rustc_builtin_macros/src/proc_macro_harness.rs @@ -1,6 +1,5 @@ use std::{mem, slice}; -use rustc_ast::ptr::P; use rustc_ast::visit::{self, Visitor}; use rustc_ast::{self as ast, HasNodeId, NodeId, attr}; use rustc_ast_pretty::pprust; @@ -286,7 +285,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> { // // ... // ]; // } -fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> P<ast::Item> { +fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> Box<ast::Item> { let expn_id = cx.resolver.expansion_for_ast_pass( DUMMY_SP, AstPass::ProcMacroHarness, diff --git a/compiler/rustc_builtin_macros/src/source_util.rs b/compiler/rustc_builtin_macros/src/source_util.rs index ecfd46a84ec..37bab5be542 100644 --- a/compiler/rustc_builtin_macros/src/source_util.rs +++ b/compiler/rustc_builtin_macros/src/source_util.rs @@ -3,7 +3,6 @@ use std::rc::Rc; use std::sync::Arc; use rustc_ast as ast; -use rustc_ast::ptr::P; use rustc_ast::tokenstream::TokenStream; use rustc_ast::{join_path_idents, token}; use rustc_ast_pretty::pprust; @@ -144,7 +143,7 @@ pub(crate) fn expand_include<'cx>( node_id: ast::NodeId, } impl<'a> MacResult for ExpandInclude<'a> { - fn make_expr(mut self: Box<ExpandInclude<'a>>) -> Option<P<ast::Expr>> { + fn make_expr(mut self: Box<ExpandInclude<'a>>) -> Option<Box<ast::Expr>> { let expr = parse_expr(&mut self.p).ok()?; if self.p.token != token::Eof { self.p.psess.buffer_lint( @@ -157,7 +156,7 @@ pub(crate) fn expand_include<'cx>( Some(expr) } - fn make_items(mut self: Box<ExpandInclude<'a>>) -> Option<SmallVec<[P<ast::Item>; 1]>> { + fn make_items(mut self: Box<ExpandInclude<'a>>) -> Option<SmallVec<[Box<ast::Item>; 1]>> { let mut ret = SmallVec::new(); loop { match self.p.parse_item(ForceCollect::No) { diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs index 7b57c02b197..7a189ee1f4d 100644 --- a/compiler/rustc_builtin_macros/src/test.rs +++ b/compiler/rustc_builtin_macros/src/test.rs @@ -4,7 +4,6 @@ use std::assert_matches::assert_matches; use std::iter; -use rustc_ast::ptr::P; use rustc_ast::{self as ast, GenericParamKind, HasNodeId, attr, join_path_idents}; use rustc_ast_pretty::pprust; use rustc_attr_parsing::AttributeParser; @@ -78,7 +77,7 @@ pub(crate) fn expand_test_case( } let ret = if is_stmt { - Annotatable::Stmt(P(ecx.stmt_item(item.span, item))) + Annotatable::Stmt(Box::new(ecx.stmt_item(item.span, item))) } else { Annotatable::Item(item) }; @@ -131,7 +130,7 @@ pub(crate) fn expand_test_or_bench( let ast::ItemKind::Fn(fn_) = &item.kind else { not_testable_error(cx, attr_sp, Some(&item)); return if is_stmt { - vec![Annotatable::Stmt(P(cx.stmt_item(item.span, item)))] + vec![Annotatable::Stmt(Box::new(cx.stmt_item(item.span, item)))] } else { vec![Annotatable::Item(item)] }; @@ -155,7 +154,7 @@ pub(crate) fn expand_test_or_bench( }; if check_result.is_err() { return if is_stmt { - vec![Annotatable::Stmt(P(cx.stmt_item(item.span, item)))] + vec![Annotatable::Stmt(Box::new(cx.stmt_item(item.span, item)))] } else { vec![Annotatable::Item(item)] }; @@ -201,7 +200,7 @@ pub(crate) fn expand_test_or_bench( // `-Cinstrument-coverage` builds. // This requires `#[allow_internal_unstable(coverage_attribute)]` on the // corresponding macro declaration in `core::macros`. - let coverage_off = |mut expr: P<ast::Expr>| { + let coverage_off = |mut expr: Box<ast::Expr>| { assert_matches!(expr.kind, ast::ExprKind::Closure(_)); expr.attrs.push(cx.attr_nested_word(sym::coverage, sym::off, sp)); expr @@ -388,11 +387,11 @@ pub(crate) fn expand_test_or_bench( if is_stmt { vec![ // Access to libtest under a hygienic name - Annotatable::Stmt(P(cx.stmt_item(sp, test_extern))), + Annotatable::Stmt(Box::new(cx.stmt_item(sp, test_extern))), // The generated test case - Annotatable::Stmt(P(cx.stmt_item(sp, test_const))), + Annotatable::Stmt(Box::new(cx.stmt_item(sp, test_const))), // The original item - Annotatable::Stmt(P(cx.stmt_item(sp, item))), + Annotatable::Stmt(Box::new(cx.stmt_item(sp, item))), ] } else { vec![ diff --git a/compiler/rustc_builtin_macros/src/test_harness.rs b/compiler/rustc_builtin_macros/src/test_harness.rs index 111c85d49eb..e803f3be82b 100644 --- a/compiler/rustc_builtin_macros/src/test_harness.rs +++ b/compiler/rustc_builtin_macros/src/test_harness.rs @@ -5,7 +5,6 @@ use std::mem; use rustc_ast as ast; use rustc_ast::entry::EntryPointType; use rustc_ast::mut_visit::*; -use rustc_ast::ptr::P; use rustc_ast::visit::Visitor; use rustc_ast::{ModKind, attr}; use rustc_errors::DiagCtxtHandle; @@ -284,7 +283,7 @@ fn generate_test_harness( /// [`TestCtxt::reexport_test_harness_main`] provides a different name for the `main` /// function and [`TestCtxt::test_runner`] provides a path that replaces /// `test::test_main_static`. -fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> { +fn mk_main(cx: &mut TestCtxt<'_>) -> Box<ast::Item> { let sp = cx.def_site; let ecx = &cx.ext_cx; let test_ident = Ident::new(sym::test, sp); @@ -348,7 +347,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> { define_opaque: None, })); - let main = P(ast::Item { + let main = Box::new(ast::Item { attrs: thin_vec![main_attr, coverage_attr, doc_hidden_attr], id: ast::DUMMY_NODE_ID, kind: main, @@ -364,7 +363,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> { /// Creates a slice containing every test like so: /// &[&test1, &test2] -fn mk_tests_slice(cx: &TestCtxt<'_>, sp: Span) -> P<ast::Expr> { +fn mk_tests_slice(cx: &TestCtxt<'_>, sp: Span) -> Box<ast::Expr> { debug!("building test vector from {} tests", cx.test_cases.len()); let ecx = &cx.ext_cx; diff --git a/compiler/rustc_builtin_macros/src/util.rs b/compiler/rustc_builtin_macros/src/util.rs index 38fec2bff14..f00c170e485 100644 --- a/compiler/rustc_builtin_macros/src/util.rs +++ b/compiler/rustc_builtin_macros/src/util.rs @@ -1,4 +1,3 @@ -use rustc_ast::ptr::P; use rustc_ast::tokenstream::TokenStream; use rustc_ast::{self as ast, AttrStyle, Attribute, MetaItem, attr, token}; use rustc_errors::{Applicability, Diag, ErrorGuaranteed}; @@ -83,7 +82,7 @@ type UnexpectedExprKind<'a> = Result<(Diag<'a>, bool /* has_suggestions */), Err #[allow(rustc::untranslatable_diagnostic)] pub(crate) fn expr_to_spanned_string<'a>( cx: &'a mut ExtCtxt<'_>, - expr: P<ast::Expr>, + expr: Box<ast::Expr>, err_msg: &'static str, ) -> ExpandResult<ExprToSpannedStringResult<'a>, ()> { if !cx.force_mode @@ -135,7 +134,7 @@ pub(crate) fn expr_to_spanned_string<'a>( /// compilation on error, merely emits a non-fatal error and returns `Err`. pub(crate) fn expr_to_string( cx: &mut ExtCtxt<'_>, - expr: P<ast::Expr>, + expr: Box<ast::Expr>, err_msg: &'static str, ) -> ExpandResult<Result<(Symbol, ast::StrStyle), ErrorGuaranteed>, ()> { expr_to_spanned_string(cx, expr, err_msg).map(|res| { @@ -158,7 +157,7 @@ pub(crate) fn check_zero_tts(cx: &ExtCtxt<'_>, span: Span, tts: TokenStream, nam } /// Parse an expression. On error, emit it, advancing to `Eof`, and return `Err`. -pub(crate) fn parse_expr(p: &mut parser::Parser<'_>) -> Result<P<ast::Expr>, ErrorGuaranteed> { +pub(crate) fn parse_expr(p: &mut parser::Parser<'_>) -> Result<Box<ast::Expr>, ErrorGuaranteed> { let guar = match p.parse_expr() { Ok(expr) => return Ok(expr), Err(err) => err.emit(), @@ -209,7 +208,7 @@ pub(crate) fn get_single_expr_from_tts( span: Span, tts: TokenStream, name: &str, -) -> ExpandResult<Result<P<ast::Expr>, ErrorGuaranteed>, ()> { +) -> ExpandResult<Result<Box<ast::Expr>, ErrorGuaranteed>, ()> { let mut p = cx.new_parser_from_tts(tts); if p.token == token::Eof { let guar = cx.dcx().emit_err(errors::OnlyOneArgument { span, name }); @@ -232,7 +231,7 @@ pub(crate) fn get_single_expr_from_tts( pub(crate) fn get_exprs_from_tts( cx: &mut ExtCtxt<'_>, tts: TokenStream, -) -> ExpandResult<Result<Vec<P<ast::Expr>>, ErrorGuaranteed>, ()> { +) -> ExpandResult<Result<Vec<Box<ast::Expr>>, ErrorGuaranteed>, ()> { let mut p = cx.new_parser_from_tts(tts); let mut es = Vec::new(); while p.token != token::Eof { diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index 32cdef075e7..917d07e3c61 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -557,13 +557,25 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> { let (size, signed) = ty.int_size_and_signed(self.tcx); let width = size.bits(); - if oop == OverflowOp::Sub && !signed { - // Emit sub and icmp instead of llvm.usub.with.overflow. LLVM considers these - // to be the canonical form. It will attempt to reform llvm.usub.with.overflow - // in the backend if profitable. - let sub = self.sub(lhs, rhs); - let cmp = self.icmp(IntPredicate::IntULT, lhs, rhs); - return (sub, cmp); + if !signed { + match oop { + OverflowOp::Sub => { + // Emit sub and icmp instead of llvm.usub.with.overflow. LLVM considers these + // to be the canonical form. It will attempt to reform llvm.usub.with.overflow + // in the backend if profitable. + let sub = self.sub(lhs, rhs); + let cmp = self.icmp(IntPredicate::IntULT, lhs, rhs); + return (sub, cmp); + } + OverflowOp::Add => { + // Like with sub above, using icmp is the preferred form. See + // <https://rust-lang.zulipchat.com/#narrow/channel/187780-t-compiler.2Fllvm/topic/.60uadd.2Ewith.2Eoverflow.60.20.28again.29/near/533041085> + let add = self.add(lhs, rhs); + let cmp = self.icmp(IntPredicate::IntULT, add, lhs); + return (add, cmp); + } + OverflowOp::Mul => {} + } } let oop_str = match oop { diff --git a/compiler/rustc_codegen_ssa/messages.ftl b/compiler/rustc_codegen_ssa/messages.ftl index 3ca070acc9d..b6cfea88363 100644 --- a/compiler/rustc_codegen_ssa/messages.ftl +++ b/compiler/rustc_codegen_ssa/messages.ftl @@ -401,6 +401,9 @@ codegen_ssa_version_script_write_failure = failed to write version script: {$err codegen_ssa_visual_studio_not_installed = you may need to install Visual Studio build tools with the "C++ build tools" workload +codegen_ssa_xcrun_about = + the SDK is needed by the linker to know where to find symbols in system libraries and for embedding the SDK version in the final object file + codegen_ssa_xcrun_command_line_tools_insufficient = when compiling for iOS, tvOS, visionOS or watchOS, you need a full installation of Xcode diff --git a/compiler/rustc_codegen_ssa/src/back/apple.rs b/compiler/rustc_codegen_ssa/src/back/apple.rs index 2f68bad1695..2274450e20e 100644 --- a/compiler/rustc_codegen_ssa/src/back/apple.rs +++ b/compiler/rustc_codegen_ssa/src/back/apple.rs @@ -160,6 +160,10 @@ pub(super) fn add_version_to_llvm_target( pub(super) fn get_sdk_root(sess: &Session) -> Option<PathBuf> { let sdk_name = sdk_name(&sess.target); + // Attempt to invoke `xcrun` to find the SDK. + // + // Note that when cross-compiling from e.g. Linux, the `xcrun` binary may sometimes be provided + // as a shim by a cross-compilation helper tool. It usually isn't, but we still try nonetheless. match xcrun_show_sdk_path(sdk_name, sess.verbose_internals()) { Ok((path, stderr)) => { // Emit extra stderr, such as if `-verbose` was passed, or if `xcrun` emitted a warning. @@ -169,7 +173,19 @@ pub(super) fn get_sdk_root(sess: &Session) -> Option<PathBuf> { Some(path) } Err(err) => { - let mut diag = sess.dcx().create_err(err); + // Failure to find the SDK is not a hard error, since the user might have specified it + // in a manner unknown to us (moreso if cross-compiling): + // - A compiler driver like `zig cc` which links using an internally bundled SDK. + // - Extra linker arguments (`-Clink-arg=-syslibroot`). + // - A custom linker or custom compiler driver. + // + // Though we still warn, since such cases are uncommon, and it is very hard to debug if + // you do not know the details. + // + // FIXME(madsmtm): Make this a lint, to allow deny warnings to work. + // (Or fix <https://github.com/rust-lang/rust/issues/21204>). + let mut diag = sess.dcx().create_warn(err); + diag.note(fluent::codegen_ssa_xcrun_about); // Recognize common error cases, and give more Rust-specific error messages for those. if let Some(developer_dir) = xcode_select_developer_dir() { @@ -209,6 +225,8 @@ fn xcrun_show_sdk_path( sdk_name: &'static str, verbose: bool, ) -> Result<(PathBuf, String), XcrunError> { + // Intentionally invoke the `xcrun` in PATH, since e.g. nixpkgs provide an `xcrun` shim, so we + // don't want to require `/usr/bin/xcrun`. let mut cmd = Command::new("xcrun"); if verbose { cmd.arg("--verbose"); @@ -280,7 +298,7 @@ fn stdout_to_path(mut stdout: Vec<u8>) -> PathBuf { } #[cfg(unix)] let path = <OsString as std::os::unix::ffi::OsStringExt>::from_vec(stdout); - #[cfg(not(unix))] // Unimportant, this is only used on macOS - let path = OsString::from(String::from_utf8(stdout).unwrap()); + #[cfg(not(unix))] // Not so important, this is mostly used on macOS + let path = OsString::from(String::from_utf8(stdout).expect("stdout must be UTF-8")); PathBuf::from(path) } diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs index 3ec0d900994..4ebe59dc2a7 100644 --- a/compiler/rustc_codegen_ssa/src/back/link.rs +++ b/compiler/rustc_codegen_ssa/src/back/link.rs @@ -3194,39 +3194,60 @@ fn add_apple_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavo } fn add_apple_sdk(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) -> Option<PathBuf> { - let os = &sess.target.os; - if sess.target.vendor != "apple" - || !matches!(os.as_ref(), "ios" | "tvos" | "watchos" | "visionos" | "macos") - || !matches!(flavor, LinkerFlavor::Darwin(..)) - { + if !sess.target.is_like_darwin { return None; } - - if os == "macos" && !matches!(flavor, LinkerFlavor::Darwin(Cc::No, _)) { + let LinkerFlavor::Darwin(cc, _) = flavor else { return None; - } - - let sdk_root = sess.time("get_apple_sdk_root", || get_apple_sdk_root(sess))?; + }; - match flavor { - LinkerFlavor::Darwin(Cc::Yes, _) => { - // Use `-isysroot` instead of `--sysroot`, as only the former - // makes Clang treat it as a platform SDK. - // - // This is admittedly a bit strange, as on most targets - // `-isysroot` only applies to include header files, but on Apple - // targets this also applies to libraries and frameworks. - cmd.cc_arg("-isysroot"); - cmd.cc_arg(&sdk_root); - } - LinkerFlavor::Darwin(Cc::No, _) => { - cmd.link_arg("-syslibroot"); - cmd.link_arg(&sdk_root); - } - _ => unreachable!(), + // The default compiler driver on macOS is at `/usr/bin/cc`. This is a trampoline binary that + // effectively invokes `xcrun cc` internally to look up both the compiler binary and the SDK + // root from the current Xcode installation. When cross-compiling, when `rustc` is invoked + // inside Xcode, or when invoking the linker directly, this default logic is unsuitable, so + // instead we invoke `xcrun` manually. + // + // (Note that this doesn't mean we get a duplicate lookup here - passing `SDKROOT` below will + // cause the trampoline binary to skip looking up the SDK itself). + let sdkroot = sess.time("get_apple_sdk_root", || get_apple_sdk_root(sess))?; + + if cc == Cc::Yes { + // There are a few options to pass the SDK root when linking with a C/C++ compiler: + // - The `--sysroot` flag. + // - The `-isysroot` flag. + // - The `SDKROOT` environment variable. + // + // `--sysroot` isn't actually enough to get Clang to treat it as a platform SDK, you need + // to specify `-isysroot`. This is admittedly a bit strange, as on most targets `-isysroot` + // only applies to include header files, but on Apple targets it also applies to libraries + // and frameworks. + // + // This leaves the choice between `-isysroot` and `SDKROOT`. Both are supported by Clang and + // GCC, though they may not be supported by all compiler drivers. We choose `SDKROOT`, + // primarily because that is the same interface that is used when invoking the tool under + // `xcrun -sdk macosx $tool`. + // + // In that sense, if a given compiler driver does not support `SDKROOT`, the blame is fairly + // clearly in the tool in question, since they also don't support being run under `xcrun`. + // + // Additionally, `SDKROOT` is an environment variable and thus optional. It also has lower + // precedence than `-isysroot`, so a custom compiler driver that does not support it and + // instead figures out the SDK on their own can easily do so by using `-isysroot`. + // + // (This in particular affects Clang built with the `DEFAULT_SYSROOT` CMake flag, such as + // the one provided by some versions of Homebrew's `llvm` package. Those will end up + // ignoring the value we set here, and instead use their built-in sysroot). + cmd.cmd().env("SDKROOT", &sdkroot); + } else { + // When invoking the linker directly, we use the `-syslibroot` parameter. `SDKROOT` is not + // read by the linker, so it's really the only option. + // + // This is also what Clang does. + cmd.link_arg("-syslibroot"); + cmd.link_arg(&sdkroot); } - Some(sdk_root) + Some(sdkroot) } fn get_apple_sdk_root(sess: &Session) -> Option<PathBuf> { @@ -3255,7 +3276,13 @@ fn get_apple_sdk_root(sess: &Session) -> Option<PathBuf> { } "macosx" if sdkroot.contains("iPhoneOS.platform") - || sdkroot.contains("iPhoneSimulator.platform") => {} + || sdkroot.contains("iPhoneSimulator.platform") + || sdkroot.contains("AppleTVOS.platform") + || sdkroot.contains("AppleTVSimulator.platform") + || sdkroot.contains("WatchOS.platform") + || sdkroot.contains("WatchSimulator.platform") + || sdkroot.contains("XROS.platform") + || sdkroot.contains("XRSimulator.platform") => {} "watchos" if sdkroot.contains("WatchSimulator.platform") || sdkroot.contains("MacOSX.platform") => {} diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index 7e124f65324..0494666bda9 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -569,7 +569,7 @@ fn symbol_export_level(tcx: TyCtxt<'_>, sym_def_id: DefId) -> SymbolExportLevel // core/std/allocators/etc. For example symbols used to hook up allocation // are not considered for export let codegen_fn_attrs = tcx.codegen_fn_attrs(sym_def_id); - let is_extern = codegen_fn_attrs.contains_extern_indicator(); + let is_extern = codegen_fn_attrs.contains_extern_indicator(tcx, sym_def_id); let std_internal = codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL); diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index 7f54a47327a..287787eb3d1 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -443,6 +443,27 @@ fn apply_overrides(tcx: TyCtxt<'_>, did: LocalDefId, codegen_fn_attrs: &mut Code if tcx.should_inherit_track_caller(did) { codegen_fn_attrs.flags |= CodegenFnAttrFlags::TRACK_CALLER; } + + // Foreign items by default use no mangling for their symbol name. + if tcx.is_foreign_item(did) { + // There's a few exceptions to this rule though: + if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL) { + // * `#[rustc_std_internal_symbol]` mangles the symbol name in a special way + // both for exports and imports through foreign items. This is handled further, + // during symbol mangling logic. + } else if codegen_fn_attrs.link_name.is_some() { + // * This can be overridden with the `#[link_name]` attribute + } else { + // NOTE: there's one more exception that we cannot apply here. On wasm, + // some items cannot be `no_mangle`. + // However, we don't have enough information here to determine that. + // As such, no_mangle foreign items on wasm that have the same defid as some + // import will *still* be mangled despite this. + // + // if none of the exceptions apply; apply no_mangle + codegen_fn_attrs.flags |= CodegenFnAttrFlags::NO_MANGLE; + } + } } fn check_result( diff --git a/compiler/rustc_const_eval/src/check_consts/ops.rs b/compiler/rustc_const_eval/src/check_consts/ops.rs index 982e640fa92..79e32dcf105 100644 --- a/compiler/rustc_const_eval/src/check_consts/ops.rs +++ b/compiler/rustc_const_eval/src/check_consts/ops.rs @@ -142,7 +142,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> { |err, self_ty, trait_id| { // FIXME(const_trait_impl): Do we need any of this on the non-const codepath? - let trait_ref = TraitRef::from_method(tcx, trait_id, self.args); + let trait_ref = TraitRef::from_assoc(tcx, trait_id, self.args); match self_ty.kind() { Param(param_ty) => { diff --git a/compiler/rustc_const_eval/src/interpret/call.rs b/compiler/rustc_const_eval/src/interpret/call.rs index b8a65369825..b1cc0cc2878 100644 --- a/compiler/rustc_const_eval/src/interpret/call.rs +++ b/compiler/rustc_const_eval/src/interpret/call.rs @@ -346,7 +346,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { destination: &PlaceTy<'tcx, M::Provenance>, mut cont: ReturnContinuation, ) -> InterpResult<'tcx> { - let _span = enter_trace_span!(M, step::init_stack_frame, %instance, tracing_separate_thread = Empty); + let _trace = enter_trace_span!(M, step::init_stack_frame, %instance, tracing_separate_thread = Empty); // Compute callee information. // FIXME: for variadic support, do we have to somehow determine callee's extra_args? @@ -527,7 +527,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { target: Option<mir::BasicBlock>, unwind: mir::UnwindAction, ) -> InterpResult<'tcx> { - let _span = + let _trace = enter_trace_span!(M, step::init_fn_call, tracing_separate_thread = Empty, ?fn_val) .or_if_tracing_disabled(|| trace!("init_fn_call: {:#?}", fn_val)); @@ -732,7 +732,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { let tcx = *self.tcx; let trait_def_id = tcx.trait_of_assoc(def_id).unwrap(); - let virtual_trait_ref = ty::TraitRef::from_method(tcx, trait_def_id, virtual_instance.args); + let virtual_trait_ref = ty::TraitRef::from_assoc(tcx, trait_def_id, virtual_instance.args); let existential_trait_ref = ty::ExistentialTraitRef::erase_self_ty(tcx, virtual_trait_ref); let concrete_trait_ref = existential_trait_ref.with_self_ty(tcx, dyn_ty); diff --git a/compiler/rustc_const_eval/src/interpret/eval_context.rs b/compiler/rustc_const_eval/src/interpret/eval_context.rs index c4b705d7124..d4f2bb8257d 100644 --- a/compiler/rustc_const_eval/src/interpret/eval_context.rs +++ b/compiler/rustc_const_eval/src/interpret/eval_context.rs @@ -113,7 +113,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { /// See [LayoutOf::layout_of] for the original documentation. #[inline(always)] pub fn layout_of(&self, ty: Ty<'tcx>) -> <Self as LayoutOfHelpers<'tcx>>::LayoutOfResult { - let _span = enter_trace_span!(M, layouting::layout_of, ty = ?ty.kind()); + let _trace = enter_trace_span!(M, layouting::layout_of, ty = ?ty.kind()); LayoutOf::layout_of(self, ty) } @@ -126,7 +126,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { sig: ty::PolyFnSig<'tcx>, extra_args: &'tcx ty::List<Ty<'tcx>>, ) -> <Self as FnAbiOfHelpers<'tcx>>::FnAbiOfResult { - let _span = enter_trace_span!(M, layouting::fn_abi_of_fn_ptr, ?sig, ?extra_args); + let _trace = enter_trace_span!(M, layouting::fn_abi_of_fn_ptr, ?sig, ?extra_args); FnAbiOf::fn_abi_of_fn_ptr(self, sig, extra_args) } @@ -139,7 +139,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { instance: ty::Instance<'tcx>, extra_args: &'tcx ty::List<Ty<'tcx>>, ) -> <Self as FnAbiOfHelpers<'tcx>>::FnAbiOfResult { - let _span = enter_trace_span!(M, layouting::fn_abi_of_instance, ?instance, ?extra_args); + let _trace = enter_trace_span!(M, layouting::fn_abi_of_instance, ?instance, ?extra_args); FnAbiOf::fn_abi_of_instance(self, instance, extra_args) } } @@ -322,7 +322,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { frame: &Frame<'tcx, M::Provenance, M::FrameExtra>, value: T, ) -> Result<T, ErrorHandled> { - let _span = enter_trace_span!( + let _trace = enter_trace_span!( M, "instantiate_from_frame_and_normalize_erasing_regions", "{}", diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs index 14541809070..53a440b646b 100644 --- a/compiler/rustc_const_eval/src/interpret/operand.rs +++ b/compiler/rustc_const_eval/src/interpret/operand.rs @@ -773,7 +773,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { mir_place: mir::Place<'tcx>, layout: Option<TyAndLayout<'tcx>>, ) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> { - let _span = enter_trace_span!( + let _trace = enter_trace_span!( M, step::eval_place_to_op, ?mir_place, @@ -823,7 +823,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { mir_op: &mir::Operand<'tcx>, layout: Option<TyAndLayout<'tcx>>, ) -> InterpResult<'tcx, OpTy<'tcx, M::Provenance>> { - let _span = + let _trace = enter_trace_span!(M, step::eval_operand, ?mir_op, tracing_separate_thread = Empty); use rustc_middle::mir::Operand::*; diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs index 45c4edb8503..6ff50dc700f 100644 --- a/compiler/rustc_const_eval/src/interpret/place.rs +++ b/compiler/rustc_const_eval/src/interpret/place.rs @@ -526,7 +526,7 @@ where &self, mir_place: mir::Place<'tcx>, ) -> InterpResult<'tcx, PlaceTy<'tcx, M::Provenance>> { - let _span = + let _trace = enter_trace_span!(M, step::eval_place, ?mir_place, tracing_separate_thread = Empty); let mut place = self.local_to_place(mir_place.local)?; diff --git a/compiler/rustc_const_eval/src/interpret/step.rs b/compiler/rustc_const_eval/src/interpret/step.rs index 9df49c0f4cc..76e470b69dc 100644 --- a/compiler/rustc_const_eval/src/interpret/step.rs +++ b/compiler/rustc_const_eval/src/interpret/step.rs @@ -76,7 +76,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { /// /// This does NOT move the statement counter forward, the caller has to do that! pub fn eval_statement(&mut self, stmt: &mir::Statement<'tcx>) -> InterpResult<'tcx> { - let _span = enter_trace_span!( + let _trace = enter_trace_span!( M, step::eval_statement, stmt = ?stmt.kind, @@ -465,7 +465,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { } fn eval_terminator(&mut self, terminator: &mir::Terminator<'tcx>) -> InterpResult<'tcx> { - let _span = enter_trace_span!( + let _trace = enter_trace_span!( M, step::eval_terminator, terminator = ?terminator.kind, diff --git a/compiler/rustc_const_eval/src/interpret/util.rs b/compiler/rustc_const_eval/src/interpret/util.rs index 71800950faa..72bee345406 100644 --- a/compiler/rustc_const_eval/src/interpret/util.rs +++ b/compiler/rustc_const_eval/src/interpret/util.rs @@ -85,11 +85,11 @@ impl EnteredTraceSpan for tracing::span::EnteredSpan { /// # let my_debug_var = String::new(); /// // logs a span named "hello" with a field named "arg" of value 42 (works only because /// // 42 implements the tracing::Value trait, otherwise use one of the options below) -/// let _span = enter_trace_span!(M, "hello", arg = 42); +/// let _trace = enter_trace_span!(M, "hello", arg = 42); /// // logs a field called "my_display_var" using the Display implementation -/// let _span = enter_trace_span!(M, "hello", %my_display_var); +/// let _trace = enter_trace_span!(M, "hello", %my_display_var); /// // logs a field called "my_debug_var" using the Debug implementation -/// let _span = enter_trace_span!(M, "hello", ?my_debug_var); +/// let _trace = enter_trace_span!(M, "hello", ?my_debug_var); /// ``` /// /// ### `NAME::SUBNAME` syntax @@ -107,8 +107,8 @@ impl EnteredTraceSpan for tracing::span::EnteredSpan { /// # use rustc_const_eval::enter_trace_span; /// # type M = rustc_const_eval::const_eval::CompileTimeMachine<'static>; /// // for example, the first will expand to the second -/// let _span = enter_trace_span!(M, borrow_tracker::on_stack_pop, /* ... */); -/// let _span = enter_trace_span!(M, "borrow_tracker", borrow_tracker = "on_stack_pop", /* ... */); +/// let _trace = enter_trace_span!(M, borrow_tracker::on_stack_pop, /* ... */); +/// let _trace = enter_trace_span!(M, "borrow_tracker", borrow_tracker = "on_stack_pop", /* ... */); /// ``` /// /// ### `tracing_separate_thread` parameter @@ -124,7 +124,7 @@ impl EnteredTraceSpan for tracing::span::EnteredSpan { /// ```rust /// # use rustc_const_eval::enter_trace_span; /// # type M = rustc_const_eval::const_eval::CompileTimeMachine<'static>; -/// let _span = enter_trace_span!(M, step::eval_statement, tracing_separate_thread = tracing::field::Empty); +/// let _trace = enter_trace_span!(M, step::eval_statement, tracing_separate_thread = tracing::field::Empty); /// ``` /// /// ### Executing something else when tracing is disabled @@ -136,7 +136,7 @@ impl EnteredTraceSpan for tracing::span::EnteredSpan { /// # use rustc_const_eval::enter_trace_span; /// # use rustc_const_eval::interpret::EnteredTraceSpan; /// # type M = rustc_const_eval::const_eval::CompileTimeMachine<'static>; -/// let _span = enter_trace_span!(M, step::eval_statement) +/// let _trace = enter_trace_span!(M, step::eval_statement) /// .or_if_tracing_disabled(|| tracing::info!("eval_statement")); /// ``` #[macro_export] diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs index ed48f53c310..ab0c0665d51 100644 --- a/compiler/rustc_const_eval/src/interpret/validity.rs +++ b/compiler/rustc_const_eval/src/interpret/validity.rs @@ -1415,7 +1415,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { recursive: bool, reset_provenance_and_padding: bool, ) -> InterpResult<'tcx> { - let _span = enter_trace_span!( + let _trace = enter_trace_span!( M, "validate_operand", "recursive={recursive}, reset_provenance_and_padding={reset_provenance_and_padding}, val={val:?}" diff --git a/compiler/rustc_errors/src/diagnostic.rs b/compiler/rustc_errors/src/diagnostic.rs index 5a5563c7bb2..98be37fd84b 100644 --- a/compiler/rustc_errors/src/diagnostic.rs +++ b/compiler/rustc_errors/src/diagnostic.rs @@ -847,17 +847,18 @@ impl<'a, G: EmissionGuarantee> Diag<'a, G> { self } + with_fn! { with_span_help, /// Prints the span with some help above it. /// This is like [`Diag::help()`], but it gets its own span. #[rustc_lint_diagnostics] - pub fn span_help<S: Into<MultiSpan>>( + pub fn span_help( &mut self, - sp: S, + sp: impl Into<MultiSpan>, msg: impl Into<SubdiagMessage>, ) -> &mut Self { self.sub(Level::Help, msg, sp.into()); self - } + } } /// Disallow attaching suggestions to this diagnostic. /// Any suggestions attached e.g. with the `span_suggestion_*` methods diff --git a/compiler/rustc_errors/src/emitter.rs b/compiler/rustc_errors/src/emitter.rs index 0c839f94f7f..97c47fa9b9a 100644 --- a/compiler/rustc_errors/src/emitter.rs +++ b/compiler/rustc_errors/src/emitter.rs @@ -3546,7 +3546,7 @@ pub fn detect_confusion_type(sm: &SourceMap, suggested: &str, sp: Span) -> Confu for (f, s) in iter::zip(found.chars(), suggested.chars()) { if f != s { - if f.to_lowercase().to_string() == s.to_lowercase().to_string() { + if f.eq_ignore_ascii_case(&s) { // Check for case differences (any character that differs only in case) if ascii_confusables.contains(&f) || ascii_confusables.contains(&s) { has_case_diff = true; diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 1a9832b2fe2..7da3bf27eb5 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -7,7 +7,6 @@ use std::rc::Rc; use std::sync::Arc; use rustc_ast::attr::{AttributeExt, MarkedAttrs}; -use rustc_ast::ptr::P; use rustc_ast::token::MetaVarKind; use rustc_ast::tokenstream::TokenStream; use rustc_ast::visit::{AssocCtxt, Visitor}; @@ -45,11 +44,11 @@ use crate::stats::MacroStat; // to use `assign_id!` #[derive(Debug, Clone)] pub enum Annotatable { - Item(P<ast::Item>), - AssocItem(P<ast::AssocItem>, AssocCtxt), - ForeignItem(P<ast::ForeignItem>), - Stmt(P<ast::Stmt>), - Expr(P<ast::Expr>), + Item(Box<ast::Item>), + AssocItem(Box<ast::AssocItem>, AssocCtxt), + ForeignItem(Box<ast::ForeignItem>), + Stmt(Box<ast::Stmt>), + Expr(Box<ast::Expr>), Arm(ast::Arm), ExprField(ast::ExprField), PatField(ast::PatField), @@ -141,28 +140,28 @@ impl Annotatable { } } - pub fn expect_item(self) -> P<ast::Item> { + pub fn expect_item(self) -> Box<ast::Item> { match self { Annotatable::Item(i) => i, _ => panic!("expected Item"), } } - pub fn expect_trait_item(self) -> P<ast::AssocItem> { + pub fn expect_trait_item(self) -> Box<ast::AssocItem> { match self { Annotatable::AssocItem(i, AssocCtxt::Trait) => i, _ => panic!("expected Item"), } } - pub fn expect_impl_item(self) -> P<ast::AssocItem> { + pub fn expect_impl_item(self) -> Box<ast::AssocItem> { match self { Annotatable::AssocItem(i, AssocCtxt::Impl { .. }) => i, _ => panic!("expected Item"), } } - pub fn expect_foreign_item(self) -> P<ast::ForeignItem> { + pub fn expect_foreign_item(self) -> Box<ast::ForeignItem> { match self { Annotatable::ForeignItem(i) => i, _ => panic!("expected foreign item"), @@ -176,7 +175,7 @@ impl Annotatable { } } - pub fn expect_expr(self) -> P<ast::Expr> { + pub fn expect_expr(self) -> Box<ast::Expr> { match self { Annotatable::Expr(expr) => expr, _ => panic!("expected expression"), @@ -412,37 +411,37 @@ macro_rules! make_stmts_default { /// methods are spliced into the AST at the callsite of the macro. pub trait MacResult { /// Creates an expression. - fn make_expr(self: Box<Self>) -> Option<P<ast::Expr>> { + fn make_expr(self: Box<Self>) -> Option<Box<ast::Expr>> { None } /// Creates zero or more items. - fn make_items(self: Box<Self>) -> Option<SmallVec<[P<ast::Item>; 1]>> { + fn make_items(self: Box<Self>) -> Option<SmallVec<[Box<ast::Item>; 1]>> { None } /// Creates zero or more impl items. - fn make_impl_items(self: Box<Self>) -> Option<SmallVec<[P<ast::AssocItem>; 1]>> { + fn make_impl_items(self: Box<Self>) -> Option<SmallVec<[Box<ast::AssocItem>; 1]>> { None } /// Creates zero or more impl items. - fn make_trait_impl_items(self: Box<Self>) -> Option<SmallVec<[P<ast::AssocItem>; 1]>> { + fn make_trait_impl_items(self: Box<Self>) -> Option<SmallVec<[Box<ast::AssocItem>; 1]>> { None } /// Creates zero or more trait items. - fn make_trait_items(self: Box<Self>) -> Option<SmallVec<[P<ast::AssocItem>; 1]>> { + fn make_trait_items(self: Box<Self>) -> Option<SmallVec<[Box<ast::AssocItem>; 1]>> { None } /// Creates zero or more items in an `extern {}` block - fn make_foreign_items(self: Box<Self>) -> Option<SmallVec<[P<ast::ForeignItem>; 1]>> { + fn make_foreign_items(self: Box<Self>) -> Option<SmallVec<[Box<ast::ForeignItem>; 1]>> { None } /// Creates a pattern. - fn make_pat(self: Box<Self>) -> Option<P<ast::Pat>> { + fn make_pat(self: Box<Self>) -> Option<Box<ast::Pat>> { None } @@ -454,7 +453,7 @@ pub trait MacResult { make_stmts_default!(self) } - fn make_ty(self: Box<Self>) -> Option<P<ast::Ty>> { + fn make_ty(self: Box<Self>) -> Option<Box<ast::Ty>> { None } @@ -521,38 +520,38 @@ macro_rules! make_MacEager { } make_MacEager! { - expr: P<ast::Expr>, - pat: P<ast::Pat>, - items: SmallVec<[P<ast::Item>; 1]>, - impl_items: SmallVec<[P<ast::AssocItem>; 1]>, - trait_items: SmallVec<[P<ast::AssocItem>; 1]>, - foreign_items: SmallVec<[P<ast::ForeignItem>; 1]>, + expr: Box<ast::Expr>, + pat: Box<ast::Pat>, + items: SmallVec<[Box<ast::Item>; 1]>, + impl_items: SmallVec<[Box<ast::AssocItem>; 1]>, + trait_items: SmallVec<[Box<ast::AssocItem>; 1]>, + foreign_items: SmallVec<[Box<ast::ForeignItem>; 1]>, stmts: SmallVec<[ast::Stmt; 1]>, - ty: P<ast::Ty>, + ty: Box<ast::Ty>, } impl MacResult for MacEager { - fn make_expr(self: Box<Self>) -> Option<P<ast::Expr>> { + fn make_expr(self: Box<Self>) -> Option<Box<ast::Expr>> { self.expr } - fn make_items(self: Box<Self>) -> Option<SmallVec<[P<ast::Item>; 1]>> { + fn make_items(self: Box<Self>) -> Option<SmallVec<[Box<ast::Item>; 1]>> { self.items } - fn make_impl_items(self: Box<Self>) -> Option<SmallVec<[P<ast::AssocItem>; 1]>> { + fn make_impl_items(self: Box<Self>) -> Option<SmallVec<[Box<ast::AssocItem>; 1]>> { self.impl_items } - fn make_trait_impl_items(self: Box<Self>) -> Option<SmallVec<[P<ast::AssocItem>; 1]>> { + fn make_trait_impl_items(self: Box<Self>) -> Option<SmallVec<[Box<ast::AssocItem>; 1]>> { self.impl_items } - fn make_trait_items(self: Box<Self>) -> Option<SmallVec<[P<ast::AssocItem>; 1]>> { + fn make_trait_items(self: Box<Self>) -> Option<SmallVec<[Box<ast::AssocItem>; 1]>> { self.trait_items } - fn make_foreign_items(self: Box<Self>) -> Option<SmallVec<[P<ast::ForeignItem>; 1]>> { + fn make_foreign_items(self: Box<Self>) -> Option<SmallVec<[Box<ast::ForeignItem>; 1]>> { self.foreign_items } @@ -563,13 +562,13 @@ impl MacResult for MacEager { } } - fn make_pat(self: Box<Self>) -> Option<P<ast::Pat>> { + fn make_pat(self: Box<Self>) -> Option<Box<ast::Pat>> { if let Some(p) = self.pat { return Some(p); } if let Some(e) = self.expr { if matches!(e.kind, ast::ExprKind::Lit(_) | ast::ExprKind::IncludedBytes(_)) { - return Some(P(ast::Pat { + return Some(Box::new(ast::Pat { id: ast::DUMMY_NODE_ID, span: e.span, kind: PatKind::Expr(e), @@ -580,7 +579,7 @@ impl MacResult for MacEager { None } - fn make_ty(self: Box<Self>) -> Option<P<ast::Ty>> { + fn make_ty(self: Box<Self>) -> Option<Box<ast::Ty>> { self.ty } } @@ -608,8 +607,8 @@ impl DummyResult { } /// A plain dummy expression. - pub fn raw_expr(sp: Span, guar: Option<ErrorGuaranteed>) -> P<ast::Expr> { - P(ast::Expr { + pub fn raw_expr(sp: Span, guar: Option<ErrorGuaranteed>) -> Box<ast::Expr> { + Box::new(ast::Expr { id: ast::DUMMY_NODE_ID, kind: if let Some(guar) = guar { ast::ExprKind::Err(guar) @@ -624,12 +623,12 @@ impl DummyResult { } impl MacResult for DummyResult { - fn make_expr(self: Box<DummyResult>) -> Option<P<ast::Expr>> { + fn make_expr(self: Box<DummyResult>) -> Option<Box<ast::Expr>> { Some(DummyResult::raw_expr(self.span, self.guar)) } - fn make_pat(self: Box<DummyResult>) -> Option<P<ast::Pat>> { - Some(P(ast::Pat { + fn make_pat(self: Box<DummyResult>) -> Option<Box<ast::Pat>> { + Some(Box::new(ast::Pat { id: ast::DUMMY_NODE_ID, kind: PatKind::Wild, span: self.span, @@ -637,23 +636,23 @@ impl MacResult for DummyResult { })) } - fn make_items(self: Box<DummyResult>) -> Option<SmallVec<[P<ast::Item>; 1]>> { + fn make_items(self: Box<DummyResult>) -> Option<SmallVec<[Box<ast::Item>; 1]>> { Some(SmallVec::new()) } - fn make_impl_items(self: Box<DummyResult>) -> Option<SmallVec<[P<ast::AssocItem>; 1]>> { + fn make_impl_items(self: Box<DummyResult>) -> Option<SmallVec<[Box<ast::AssocItem>; 1]>> { Some(SmallVec::new()) } - fn make_trait_impl_items(self: Box<DummyResult>) -> Option<SmallVec<[P<ast::AssocItem>; 1]>> { + fn make_trait_impl_items(self: Box<DummyResult>) -> Option<SmallVec<[Box<ast::AssocItem>; 1]>> { Some(SmallVec::new()) } - fn make_trait_items(self: Box<DummyResult>) -> Option<SmallVec<[P<ast::AssocItem>; 1]>> { + fn make_trait_items(self: Box<DummyResult>) -> Option<SmallVec<[Box<ast::AssocItem>; 1]>> { Some(SmallVec::new()) } - fn make_foreign_items(self: Box<Self>) -> Option<SmallVec<[P<ast::ForeignItem>; 1]>> { + fn make_foreign_items(self: Box<Self>) -> Option<SmallVec<[Box<ast::ForeignItem>; 1]>> { Some(SmallVec::new()) } @@ -665,11 +664,11 @@ impl MacResult for DummyResult { }]) } - fn make_ty(self: Box<DummyResult>) -> Option<P<ast::Ty>> { + fn make_ty(self: Box<DummyResult>) -> Option<Box<ast::Ty>> { // FIXME(nnethercote): you might expect `ast::TyKind::Dummy` to be used here, but some // values produced here end up being lowered to HIR, which `ast::TyKind::Dummy` does not // support, so we use an empty tuple instead. - Some(P(ast::Ty { + Some(Box::new(ast::Ty { id: ast::DUMMY_NODE_ID, kind: ast::TyKind::Tup(ThinVec::new()), span: self.span, @@ -905,10 +904,7 @@ impl SyntaxExtension { find_attr!(attrs, AttributeKind::AllowInternalUnstable(i, _) => i) .map(|i| i.as_slice()) .unwrap_or_default(); - // FIXME(jdonszelman): allow_internal_unsafe isn't yet new-style - // let allow_internal_unsafe = find_attr!(attrs, AttributeKind::AllowInternalUnsafe); - let allow_internal_unsafe = - ast::attr::find_by_name(attrs, sym::allow_internal_unsafe).is_some(); + let allow_internal_unsafe = find_attr!(attrs, AttributeKind::AllowInternalUnsafe(_)); let local_inner_macros = ast::attr::find_by_name(attrs, sym::macro_export) .and_then(|macro_export| macro_export.meta_item_list()) @@ -1162,7 +1158,7 @@ pub trait LintStoreExpand { registered_tools: &RegisteredTools, node_id: NodeId, attrs: &[Attribute], - items: &[P<Item>], + items: &[Box<Item>], name: Symbol, ); } diff --git a/compiler/rustc_expand/src/build.rs b/compiler/rustc_expand/src/build.rs index 51d6e43ab67..c3e86ec0614 100644 --- a/compiler/rustc_expand/src/build.rs +++ b/compiler/rustc_expand/src/build.rs @@ -1,4 +1,3 @@ -use rustc_ast::ptr::P; use rustc_ast::token::Delimiter; use rustc_ast::tokenstream::TokenStream; use rustc_ast::util::literal; @@ -59,10 +58,10 @@ impl<'a> ExtCtxt<'a> { path: ast::Path, delim: Delimiter, tokens: TokenStream, - ) -> P<ast::MacCall> { - P(ast::MacCall { + ) -> Box<ast::MacCall> { + Box::new(ast::MacCall { path, - args: P(ast::DelimArgs { + args: Box::new(ast::DelimArgs { dspan: tokenstream::DelimSpan { open: span, close: span }, delim, tokens, @@ -70,32 +69,32 @@ impl<'a> ExtCtxt<'a> { }) } - pub fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy { + pub fn ty_mt(&self, ty: Box<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy { ast::MutTy { ty, mutbl } } - pub fn ty(&self, span: Span, kind: ast::TyKind) -> P<ast::Ty> { - P(ast::Ty { id: ast::DUMMY_NODE_ID, span, kind, tokens: None }) + pub fn ty(&self, span: Span, kind: ast::TyKind) -> Box<ast::Ty> { + Box::new(ast::Ty { id: ast::DUMMY_NODE_ID, span, kind, tokens: None }) } - pub fn ty_infer(&self, span: Span) -> P<ast::Ty> { + pub fn ty_infer(&self, span: Span) -> Box<ast::Ty> { self.ty(span, ast::TyKind::Infer) } - pub fn ty_path(&self, path: ast::Path) -> P<ast::Ty> { + pub fn ty_path(&self, path: ast::Path) -> Box<ast::Ty> { self.ty(path.span, ast::TyKind::Path(None, path)) } // Might need to take bounds as an argument in the future, if you ever want // to generate a bounded existential trait type. - pub fn ty_ident(&self, span: Span, ident: Ident) -> P<ast::Ty> { + pub fn ty_ident(&self, span: Span, ident: Ident) -> Box<ast::Ty> { self.ty_path(self.path_ident(span, ident)) } pub fn anon_const(&self, span: Span, kind: ast::ExprKind) -> ast::AnonConst { ast::AnonConst { id: ast::DUMMY_NODE_ID, - value: P(ast::Expr { + value: Box::new(ast::Expr { id: ast::DUMMY_NODE_ID, kind, span, @@ -112,14 +111,14 @@ impl<'a> ExtCtxt<'a> { pub fn ty_ref( &self, span: Span, - ty: P<ast::Ty>, + ty: Box<ast::Ty>, lifetime: Option<ast::Lifetime>, mutbl: ast::Mutability, - ) -> P<ast::Ty> { + ) -> Box<ast::Ty> { self.ty(span, ast::TyKind::Ref(lifetime, self.ty_mt(ty, mutbl))) } - pub fn ty_ptr(&self, span: Span, ty: P<ast::Ty>, mutbl: ast::Mutability) -> P<ast::Ty> { + pub fn ty_ptr(&self, span: Span, ty: Box<ast::Ty>, mutbl: ast::Mutability) -> Box<ast::Ty> { self.ty(span, ast::TyKind::Ptr(self.ty_mt(ty, mutbl))) } @@ -128,7 +127,7 @@ impl<'a> ExtCtxt<'a> { span: Span, ident: Ident, bounds: ast::GenericBounds, - default: Option<P<ast::Ty>>, + default: Option<Box<ast::Ty>>, ) -> ast::GenericParam { ast::GenericParam { ident: ident.with_span_pos(span), @@ -163,7 +162,7 @@ impl<'a> ExtCtxt<'a> { span: Span, ident: Ident, bounds: ast::GenericBounds, - ty: P<ast::Ty>, + ty: Box<ast::Ty>, default: Option<AnonConst>, ) -> ast::GenericParam { ast::GenericParam { @@ -211,11 +210,11 @@ impl<'a> ExtCtxt<'a> { self.lifetime(span, Ident::new(kw::StaticLifetime, span)) } - pub fn stmt_expr(&self, expr: P<ast::Expr>) -> ast::Stmt { + pub fn stmt_expr(&self, expr: Box<ast::Expr>) -> ast::Stmt { ast::Stmt { id: ast::DUMMY_NODE_ID, span: expr.span, kind: ast::StmtKind::Expr(expr) } } - pub fn stmt_let(&self, sp: Span, mutbl: bool, ident: Ident, ex: P<ast::Expr>) -> ast::Stmt { + pub fn stmt_let(&self, sp: Span, mutbl: bool, ident: Ident, ex: Box<ast::Expr>) -> ast::Stmt { self.stmt_let_ty(sp, mutbl, ident, None, ex) } @@ -224,15 +223,15 @@ impl<'a> ExtCtxt<'a> { sp: Span, mutbl: bool, ident: Ident, - ty: Option<P<ast::Ty>>, - ex: P<ast::Expr>, + ty: Option<Box<ast::Ty>>, + ex: Box<ast::Expr>, ) -> ast::Stmt { let pat = if mutbl { self.pat_ident_binding_mode(sp, ident, ast::BindingMode::MUT) } else { self.pat_ident(sp, ident) }; - let local = P(ast::Local { + let local = Box::new(ast::Local { super_: None, pat, ty, @@ -247,8 +246,8 @@ impl<'a> ExtCtxt<'a> { } /// Generates `let _: Type;`, which is usually used for type assertions. - pub fn stmt_let_type_only(&self, span: Span, ty: P<ast::Ty>) -> ast::Stmt { - let local = P(ast::Local { + pub fn stmt_let_type_only(&self, span: Span, ty: Box<ast::Ty>) -> ast::Stmt { + let local = Box::new(ast::Local { super_: None, pat: self.pat_wild(span), ty: Some(ty), @@ -262,19 +261,19 @@ impl<'a> ExtCtxt<'a> { self.stmt_local(local, span) } - pub fn stmt_semi(&self, expr: P<ast::Expr>) -> ast::Stmt { + pub fn stmt_semi(&self, expr: Box<ast::Expr>) -> ast::Stmt { ast::Stmt { id: ast::DUMMY_NODE_ID, span: expr.span, kind: ast::StmtKind::Semi(expr) } } - pub fn stmt_local(&self, local: P<ast::Local>, span: Span) -> ast::Stmt { + pub fn stmt_local(&self, local: Box<ast::Local>, span: Span) -> ast::Stmt { ast::Stmt { id: ast::DUMMY_NODE_ID, kind: ast::StmtKind::Let(local), span } } - pub fn stmt_item(&self, sp: Span, item: P<ast::Item>) -> ast::Stmt { + pub fn stmt_item(&self, sp: Span, item: Box<ast::Item>) -> ast::Stmt { ast::Stmt { id: ast::DUMMY_NODE_ID, kind: ast::StmtKind::Item(item), span: sp } } - pub fn block_expr(&self, expr: P<ast::Expr>) -> P<ast::Block> { + pub fn block_expr(&self, expr: Box<ast::Expr>) -> Box<ast::Block> { self.block( expr.span, thin_vec![ast::Stmt { @@ -284,8 +283,8 @@ impl<'a> ExtCtxt<'a> { }], ) } - pub fn block(&self, span: Span, stmts: ThinVec<ast::Stmt>) -> P<ast::Block> { - P(ast::Block { + pub fn block(&self, span: Span, stmts: ThinVec<ast::Stmt>) -> Box<ast::Block> { + Box::new(ast::Block { stmts, id: ast::DUMMY_NODE_ID, rules: BlockCheckMode::Default, @@ -294,22 +293,28 @@ impl<'a> ExtCtxt<'a> { }) } - pub fn expr(&self, span: Span, kind: ast::ExprKind) -> P<ast::Expr> { - P(ast::Expr { id: ast::DUMMY_NODE_ID, kind, span, attrs: AttrVec::new(), tokens: None }) + pub fn expr(&self, span: Span, kind: ast::ExprKind) -> Box<ast::Expr> { + Box::new(ast::Expr { + id: ast::DUMMY_NODE_ID, + kind, + span, + attrs: AttrVec::new(), + tokens: None, + }) } - pub fn expr_path(&self, path: ast::Path) -> P<ast::Expr> { + pub fn expr_path(&self, path: ast::Path) -> Box<ast::Expr> { self.expr(path.span, ast::ExprKind::Path(None, path)) } - pub fn expr_ident(&self, span: Span, id: Ident) -> P<ast::Expr> { + pub fn expr_ident(&self, span: Span, id: Ident) -> Box<ast::Expr> { self.expr_path(self.path_ident(span, id)) } - pub fn expr_self(&self, span: Span) -> P<ast::Expr> { + pub fn expr_self(&self, span: Span) -> Box<ast::Expr> { self.expr_ident(span, Ident::with_dummy_span(kw::SelfLower)) } - pub fn expr_macro_call(&self, span: Span, call: P<ast::MacCall>) -> P<ast::Expr> { + pub fn expr_macro_call(&self, span: Span, call: Box<ast::MacCall>) -> Box<ast::Expr> { self.expr(span, ast::ExprKind::MacCall(call)) } @@ -317,31 +322,31 @@ impl<'a> ExtCtxt<'a> { &self, sp: Span, op: ast::BinOpKind, - lhs: P<ast::Expr>, - rhs: P<ast::Expr>, - ) -> P<ast::Expr> { + lhs: Box<ast::Expr>, + rhs: Box<ast::Expr>, + ) -> Box<ast::Expr> { self.expr(sp, ast::ExprKind::Binary(Spanned { node: op, span: sp }, lhs, rhs)) } - pub fn expr_deref(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr> { + pub fn expr_deref(&self, sp: Span, e: Box<ast::Expr>) -> Box<ast::Expr> { self.expr(sp, ast::ExprKind::Unary(UnOp::Deref, e)) } - pub fn expr_addr_of(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr> { + pub fn expr_addr_of(&self, sp: Span, e: Box<ast::Expr>) -> Box<ast::Expr> { self.expr(sp, ast::ExprKind::AddrOf(ast::BorrowKind::Ref, ast::Mutability::Not, e)) } - pub fn expr_paren(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr> { + pub fn expr_paren(&self, sp: Span, e: Box<ast::Expr>) -> Box<ast::Expr> { self.expr(sp, ast::ExprKind::Paren(e)) } pub fn expr_method_call( &self, span: Span, - expr: P<ast::Expr>, + expr: Box<ast::Expr>, ident: Ident, - args: ThinVec<P<ast::Expr>>, - ) -> P<ast::Expr> { + args: ThinVec<Box<ast::Expr>>, + ) -> Box<ast::Expr> { let seg = ast::PathSegment::from_ident(ident); self.expr( span, @@ -357,38 +362,38 @@ impl<'a> ExtCtxt<'a> { pub fn expr_call( &self, span: Span, - expr: P<ast::Expr>, - args: ThinVec<P<ast::Expr>>, - ) -> P<ast::Expr> { + expr: Box<ast::Expr>, + args: ThinVec<Box<ast::Expr>>, + ) -> Box<ast::Expr> { self.expr(span, ast::ExprKind::Call(expr, args)) } - pub fn expr_loop(&self, sp: Span, block: P<ast::Block>) -> P<ast::Expr> { + pub fn expr_loop(&self, sp: Span, block: Box<ast::Block>) -> Box<ast::Expr> { self.expr(sp, ast::ExprKind::Loop(block, None, sp)) } - pub fn expr_asm(&self, sp: Span, expr: P<ast::InlineAsm>) -> P<ast::Expr> { + pub fn expr_asm(&self, sp: Span, expr: Box<ast::InlineAsm>) -> Box<ast::Expr> { self.expr(sp, ast::ExprKind::InlineAsm(expr)) } pub fn expr_call_ident( &self, span: Span, id: Ident, - args: ThinVec<P<ast::Expr>>, - ) -> P<ast::Expr> { + args: ThinVec<Box<ast::Expr>>, + ) -> Box<ast::Expr> { self.expr(span, ast::ExprKind::Call(self.expr_ident(span, id), args)) } pub fn expr_call_global( &self, sp: Span, fn_path: Vec<Ident>, - args: ThinVec<P<ast::Expr>>, - ) -> P<ast::Expr> { + args: ThinVec<Box<ast::Expr>>, + ) -> Box<ast::Expr> { let pathexpr = self.expr_path(self.path_global(sp, fn_path)); self.expr_call(sp, pathexpr, args) } - pub fn expr_block(&self, b: P<ast::Block>) -> P<ast::Expr> { + pub fn expr_block(&self, b: Box<ast::Block>) -> Box<ast::Expr> { self.expr(b.span, ast::ExprKind::Block(b, None)) } - pub fn field_imm(&self, span: Span, ident: Ident, e: P<ast::Expr>) -> ast::ExprField { + pub fn field_imm(&self, span: Span, ident: Ident, e: Box<ast::Expr>) -> ast::ExprField { ast::ExprField { ident: ident.with_span_pos(span), expr: e, @@ -404,10 +409,10 @@ impl<'a> ExtCtxt<'a> { span: Span, path: ast::Path, fields: ThinVec<ast::ExprField>, - ) -> P<ast::Expr> { + ) -> Box<ast::Expr> { self.expr( span, - ast::ExprKind::Struct(P(ast::StructExpr { + ast::ExprKind::Struct(Box::new(ast::StructExpr { qself: None, path, fields, @@ -420,61 +425,61 @@ impl<'a> ExtCtxt<'a> { span: Span, id: Ident, fields: ThinVec<ast::ExprField>, - ) -> P<ast::Expr> { + ) -> Box<ast::Expr> { self.expr_struct(span, self.path_ident(span, id), fields) } - pub fn expr_usize(&self, span: Span, n: usize) -> P<ast::Expr> { + pub fn expr_usize(&self, span: Span, n: usize) -> Box<ast::Expr> { let suffix = Some(ast::UintTy::Usize.name()); let lit = token::Lit::new(token::Integer, sym::integer(n), suffix); self.expr(span, ast::ExprKind::Lit(lit)) } - pub fn expr_u32(&self, span: Span, n: u32) -> P<ast::Expr> { + pub fn expr_u32(&self, span: Span, n: u32) -> Box<ast::Expr> { let suffix = Some(ast::UintTy::U32.name()); let lit = token::Lit::new(token::Integer, sym::integer(n), suffix); self.expr(span, ast::ExprKind::Lit(lit)) } - pub fn expr_bool(&self, span: Span, value: bool) -> P<ast::Expr> { + pub fn expr_bool(&self, span: Span, value: bool) -> Box<ast::Expr> { let lit = token::Lit::new(token::Bool, if value { kw::True } else { kw::False }, None); self.expr(span, ast::ExprKind::Lit(lit)) } - pub fn expr_str(&self, span: Span, s: Symbol) -> P<ast::Expr> { + pub fn expr_str(&self, span: Span, s: Symbol) -> Box<ast::Expr> { let lit = token::Lit::new(token::Str, literal::escape_string_symbol(s), None); self.expr(span, ast::ExprKind::Lit(lit)) } - pub fn expr_byte_str(&self, span: Span, bytes: Vec<u8>) -> P<ast::Expr> { + pub fn expr_byte_str(&self, span: Span, bytes: Vec<u8>) -> Box<ast::Expr> { let lit = token::Lit::new(token::ByteStr, literal::escape_byte_str_symbol(&bytes), None); self.expr(span, ast::ExprKind::Lit(lit)) } /// `[expr1, expr2, ...]` - pub fn expr_array(&self, sp: Span, exprs: ThinVec<P<ast::Expr>>) -> P<ast::Expr> { + pub fn expr_array(&self, sp: Span, exprs: ThinVec<Box<ast::Expr>>) -> Box<ast::Expr> { self.expr(sp, ast::ExprKind::Array(exprs)) } /// `&[expr1, expr2, ...]` - pub fn expr_array_ref(&self, sp: Span, exprs: ThinVec<P<ast::Expr>>) -> P<ast::Expr> { + pub fn expr_array_ref(&self, sp: Span, exprs: ThinVec<Box<ast::Expr>>) -> Box<ast::Expr> { self.expr_addr_of(sp, self.expr_array(sp, exprs)) } - pub fn expr_some(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> { + pub fn expr_some(&self, sp: Span, expr: Box<ast::Expr>) -> Box<ast::Expr> { let some = self.std_path(&[sym::option, sym::Option, sym::Some]); self.expr_call_global(sp, some, thin_vec![expr]) } - pub fn expr_none(&self, sp: Span) -> P<ast::Expr> { + pub fn expr_none(&self, sp: Span) -> Box<ast::Expr> { let none = self.std_path(&[sym::option, sym::Option, sym::None]); self.expr_path(self.path_global(sp, none)) } - pub fn expr_tuple(&self, sp: Span, exprs: ThinVec<P<ast::Expr>>) -> P<ast::Expr> { + pub fn expr_tuple(&self, sp: Span, exprs: ThinVec<Box<ast::Expr>>) -> Box<ast::Expr> { self.expr(sp, ast::ExprKind::Tup(exprs)) } - pub fn expr_unreachable(&self, span: Span) -> P<ast::Expr> { + pub fn expr_unreachable(&self, span: Span) -> Box<ast::Expr> { self.expr_macro_call( span, self.macro_call( @@ -489,12 +494,12 @@ impl<'a> ExtCtxt<'a> { ) } - pub fn expr_ok(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> { + pub fn expr_ok(&self, sp: Span, expr: Box<ast::Expr>) -> Box<ast::Expr> { let ok = self.std_path(&[sym::result, sym::Result, sym::Ok]); self.expr_call_global(sp, ok, thin_vec![expr]) } - pub fn expr_try(&self, sp: Span, head: P<ast::Expr>) -> P<ast::Expr> { + pub fn expr_try(&self, sp: Span, head: Box<ast::Expr>) -> Box<ast::Expr> { let ok = self.std_path(&[sym::result, sym::Result, sym::Ok]); let ok_path = self.path_global(sp, ok); let err = self.std_path(&[sym::result, sym::Result, sym::Err]); @@ -523,16 +528,16 @@ impl<'a> ExtCtxt<'a> { self.expr_match(sp, head, thin_vec![ok_arm, err_arm]) } - pub fn pat(&self, span: Span, kind: PatKind) -> P<ast::Pat> { - P(ast::Pat { id: ast::DUMMY_NODE_ID, kind, span, tokens: None }) + pub fn pat(&self, span: Span, kind: PatKind) -> Box<ast::Pat> { + Box::new(ast::Pat { id: ast::DUMMY_NODE_ID, kind, span, tokens: None }) } - pub fn pat_wild(&self, span: Span) -> P<ast::Pat> { + pub fn pat_wild(&self, span: Span) -> Box<ast::Pat> { self.pat(span, PatKind::Wild) } - pub fn pat_lit(&self, span: Span, expr: P<ast::Expr>) -> P<ast::Pat> { + pub fn pat_lit(&self, span: Span, expr: Box<ast::Expr>) -> Box<ast::Pat> { self.pat(span, PatKind::Expr(expr)) } - pub fn pat_ident(&self, span: Span, ident: Ident) -> P<ast::Pat> { + pub fn pat_ident(&self, span: Span, ident: Ident) -> Box<ast::Pat> { self.pat_ident_binding_mode(span, ident, ast::BindingMode::NONE) } @@ -541,19 +546,19 @@ impl<'a> ExtCtxt<'a> { span: Span, ident: Ident, ann: ast::BindingMode, - ) -> P<ast::Pat> { + ) -> Box<ast::Pat> { let pat = PatKind::Ident(ann, ident.with_span_pos(span), None); self.pat(span, pat) } - pub fn pat_path(&self, span: Span, path: ast::Path) -> P<ast::Pat> { + pub fn pat_path(&self, span: Span, path: ast::Path) -> Box<ast::Pat> { self.pat(span, PatKind::Path(None, path)) } pub fn pat_tuple_struct( &self, span: Span, path: ast::Path, - subpats: ThinVec<P<ast::Pat>>, - ) -> P<ast::Pat> { + subpats: ThinVec<Box<ast::Pat>>, + ) -> Box<ast::Pat> { self.pat(span, PatKind::TupleStruct(None, path, subpats)) } pub fn pat_struct( @@ -561,20 +566,20 @@ impl<'a> ExtCtxt<'a> { span: Span, path: ast::Path, field_pats: ThinVec<ast::PatField>, - ) -> P<ast::Pat> { + ) -> Box<ast::Pat> { self.pat(span, PatKind::Struct(None, path, field_pats, ast::PatFieldsRest::None)) } - pub fn pat_tuple(&self, span: Span, pats: ThinVec<P<ast::Pat>>) -> P<ast::Pat> { + pub fn pat_tuple(&self, span: Span, pats: ThinVec<Box<ast::Pat>>) -> Box<ast::Pat> { self.pat(span, PatKind::Tuple(pats)) } - pub fn pat_some(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> { + pub fn pat_some(&self, span: Span, pat: Box<ast::Pat>) -> Box<ast::Pat> { let some = self.std_path(&[sym::option, sym::Option, sym::Some]); let path = self.path_global(span, some); self.pat_tuple_struct(span, path, thin_vec![pat]) } - pub fn arm(&self, span: Span, pat: P<ast::Pat>, expr: P<ast::Expr>) -> ast::Arm { + pub fn arm(&self, span: Span, pat: Box<ast::Pat>, expr: Box<ast::Expr>) -> ast::Arm { ast::Arm { attrs: AttrVec::new(), pat, @@ -590,22 +595,27 @@ impl<'a> ExtCtxt<'a> { self.arm(span, self.pat_wild(span), self.expr_unreachable(span)) } - pub fn expr_match(&self, span: Span, arg: P<ast::Expr>, arms: ThinVec<ast::Arm>) -> P<Expr> { + pub fn expr_match( + &self, + span: Span, + arg: Box<ast::Expr>, + arms: ThinVec<ast::Arm>, + ) -> Box<Expr> { self.expr(span, ast::ExprKind::Match(arg, arms, MatchKind::Prefix)) } pub fn expr_if( &self, span: Span, - cond: P<ast::Expr>, - then: P<ast::Expr>, - els: Option<P<ast::Expr>>, - ) -> P<ast::Expr> { + cond: Box<ast::Expr>, + then: Box<ast::Expr>, + els: Option<Box<ast::Expr>>, + ) -> Box<ast::Expr> { let els = els.map(|x| self.expr_block(self.block_expr(x))); self.expr(span, ast::ExprKind::If(cond, self.block_expr(then), els)) } - pub fn lambda(&self, span: Span, ids: Vec<Ident>, body: P<ast::Expr>) -> P<ast::Expr> { + pub fn lambda(&self, span: Span, ids: Vec<Ident>, body: Box<ast::Expr>) -> Box<ast::Expr> { let fn_decl = self.fn_decl( ids.iter().map(|id| self.param(span, *id, self.ty(span, ast::TyKind::Infer))).collect(), ast::FnRetTy::Default(span), @@ -633,11 +643,11 @@ impl<'a> ExtCtxt<'a> { ) } - pub fn lambda0(&self, span: Span, body: P<ast::Expr>) -> P<ast::Expr> { + pub fn lambda0(&self, span: Span, body: Box<ast::Expr>) -> Box<ast::Expr> { self.lambda(span, Vec::new(), body) } - pub fn lambda1(&self, span: Span, body: P<ast::Expr>, ident: Ident) -> P<ast::Expr> { + pub fn lambda1(&self, span: Span, body: Box<ast::Expr>, ident: Ident) -> Box<ast::Expr> { self.lambda(span, vec![ident], body) } @@ -646,11 +656,11 @@ impl<'a> ExtCtxt<'a> { span: Span, stmts: ThinVec<ast::Stmt>, ident: Ident, - ) -> P<ast::Expr> { + ) -> Box<ast::Expr> { self.lambda1(span, self.expr_block(self.block(span, stmts)), ident) } - pub fn param(&self, span: Span, ident: Ident, ty: P<ast::Ty>) -> ast::Param { + pub fn param(&self, span: Span, ident: Ident, ty: Box<ast::Ty>) -> ast::Param { let arg_pat = self.pat_ident(span, ident); ast::Param { attrs: AttrVec::default(), @@ -663,12 +673,12 @@ impl<'a> ExtCtxt<'a> { } // `self` is unused but keep it as method for the convenience use. - pub fn fn_decl(&self, inputs: ThinVec<ast::Param>, output: ast::FnRetTy) -> P<ast::FnDecl> { - P(ast::FnDecl { inputs, output }) + pub fn fn_decl(&self, inputs: ThinVec<ast::Param>, output: ast::FnRetTy) -> Box<ast::FnDecl> { + Box::new(ast::FnDecl { inputs, output }) } - pub fn item(&self, span: Span, attrs: ast::AttrVec, kind: ast::ItemKind) -> P<ast::Item> { - P(ast::Item { + pub fn item(&self, span: Span, attrs: ast::AttrVec, kind: ast::ItemKind) -> Box<ast::Item> { + Box::new(ast::Item { attrs, id: ast::DUMMY_NODE_ID, kind, @@ -686,10 +696,10 @@ impl<'a> ExtCtxt<'a> { &self, span: Span, ident: Ident, - ty: P<ast::Ty>, + ty: Box<ast::Ty>, mutability: ast::Mutability, - expr: P<ast::Expr>, - ) -> P<ast::Item> { + expr: Box<ast::Expr>, + ) -> Box<ast::Item> { self.item( span, AttrVec::new(), @@ -711,9 +721,9 @@ impl<'a> ExtCtxt<'a> { &self, span: Span, ident: Ident, - ty: P<ast::Ty>, - expr: P<ast::Expr>, - ) -> P<ast::Item> { + ty: Box<ast::Ty>, + expr: Box<ast::Expr>, + ) -> Box<ast::Item> { let defaultness = ast::Defaultness::Final; self.item( span, diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 5504fff519c..00533285fb4 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -4,7 +4,6 @@ use std::sync::Arc; use std::{iter, mem}; use rustc_ast::mut_visit::*; -use rustc_ast::ptr::P; use rustc_ast::tokenstream::TokenStream; use rustc_ast::visit::{self, AssocCtxt, Visitor, VisitorResult, try_visit, walk_list}; use rustc_ast::{ @@ -65,8 +64,8 @@ macro_rules! ast_fragments { /// A fragment of AST that can be produced by a single macro expansion. /// Can also serve as an input and intermediate result for macro expansion operations. pub enum AstFragment { - OptExpr(Option<P<ast::Expr>>), - MethodReceiverExpr(P<ast::Expr>), + OptExpr(Option<Box<ast::Expr>>), + MethodReceiverExpr(Box<ast::Expr>), $($Kind($AstTy),)* } @@ -112,14 +111,14 @@ macro_rules! ast_fragments { } } - pub(crate) fn make_opt_expr(self) -> Option<P<ast::Expr>> { + pub(crate) fn make_opt_expr(self) -> Option<Box<ast::Expr>> { match self { AstFragment::OptExpr(expr) => expr, _ => panic!("AstFragment::make_* called on the wrong kind of fragment"), } } - pub(crate) fn make_method_receiver_expr(self) -> P<ast::Expr> { + pub(crate) fn make_method_receiver_expr(self) -> Box<ast::Expr> { match self { AstFragment::MethodReceiverExpr(expr) => expr, _ => panic!("AstFragment::make_* called on the wrong kind of fragment"), @@ -188,17 +187,17 @@ macro_rules! ast_fragments { } ast_fragments! { - Expr(P<ast::Expr>) { + Expr(Box<ast::Expr>) { "expression"; one fn visit_expr; fn visit_expr; fn pprust::expr_to_string; fn make_expr; } - Pat(P<ast::Pat>) { + Pat(Box<ast::Pat>) { "pattern"; one fn visit_pat; fn visit_pat; fn pprust::pat_to_string; fn make_pat; } - Ty(P<ast::Ty>) { + Ty(Box<ast::Ty>) { "type"; one fn visit_ty; fn visit_ty; fn pprust::ty_to_string; fn make_ty; @@ -208,30 +207,30 @@ ast_fragments! { many fn flat_map_stmt; fn visit_stmt(); fn pprust::stmt_to_string; fn make_stmts; } - Items(SmallVec<[P<ast::Item>; 1]>) { + Items(SmallVec<[Box<ast::Item>; 1]>) { "item"; many fn flat_map_item; fn visit_item(); fn pprust::item_to_string; fn make_items; } - TraitItems(SmallVec<[P<ast::AssocItem>; 1]>) { + TraitItems(SmallVec<[Box<ast::AssocItem>; 1]>) { "trait item"; many fn flat_map_assoc_item; fn visit_assoc_item(AssocCtxt::Trait); fn pprust::assoc_item_to_string; fn make_trait_items; } - ImplItems(SmallVec<[P<ast::AssocItem>; 1]>) { + ImplItems(SmallVec<[Box<ast::AssocItem>; 1]>) { "impl item"; many fn flat_map_assoc_item; fn visit_assoc_item(AssocCtxt::Impl { of_trait: false }); fn pprust::assoc_item_to_string; fn make_impl_items; } - TraitImplItems(SmallVec<[P<ast::AssocItem>; 1]>) { + TraitImplItems(SmallVec<[Box<ast::AssocItem>; 1]>) { "impl item"; many fn flat_map_assoc_item; fn visit_assoc_item(AssocCtxt::Impl { of_trait: true }); fn pprust::assoc_item_to_string; fn make_trait_impl_items; } - ForeignItems(SmallVec<[P<ast::ForeignItem>; 1]>) { + ForeignItems(SmallVec<[Box<ast::ForeignItem>; 1]>) { "foreign item"; many fn flat_map_foreign_item; fn visit_foreign_item(); fn pprust::foreign_item_to_string; fn make_foreign_items; @@ -392,7 +391,7 @@ pub struct Invocation { pub enum InvocationKind { Bang { - mac: P<ast::MacCall>, + mac: Box<ast::MacCall>, span: Span, }, Attr { @@ -409,7 +408,7 @@ pub enum InvocationKind { item: Annotatable, }, GlobDelegation { - item: P<ast::AssocItem>, + item: Box<ast::AssocItem>, /// Whether this is a trait impl or an inherent impl of_trait: bool, }, @@ -948,15 +947,14 @@ impl<'a, 'b> MacroExpander<'a, 'b> { _ => unreachable!(), }; - type Node = AstNodeWrapper<P<ast::AssocItem>, ImplItemTag>; + type Node = AstNodeWrapper<Box<ast::AssocItem>, ImplItemTag>; let single_delegations = build_single_delegations::<Node>( self.cx, deleg, &item, &suffixes, item.span, true, ); // `-Zmacro-stats` ignores these because they don't seem important. - fragment_kind.expect_from_annotatables( - single_delegations - .map(|item| Annotatable::AssocItem(P(item), AssocCtxt::Impl { of_trait })), - ) + fragment_kind.expect_from_annotatables(single_delegations.map(|item| { + Annotatable::AssocItem(Box::new(item), AssocCtxt::Impl { of_trait }) + })) } }) } @@ -1228,7 +1226,7 @@ trait InvocationCollectorNode: HasAttrs + HasNodeId + Sized { fn is_mac_call(&self) -> bool { false } - fn take_mac_call(self) -> (P<ast::MacCall>, ast::AttrVec, AddSemicolon) { + fn take_mac_call(self) -> (Box<ast::MacCall>, ast::AttrVec, AddSemicolon) { unreachable!() } fn delegation(&self) -> Option<(&ast::DelegationMac, &ast::Item<Self::ItemKind>)> { @@ -1269,7 +1267,7 @@ trait InvocationCollectorNode: HasAttrs + HasNodeId + Sized { } } -impl InvocationCollectorNode for P<ast::Item> { +impl InvocationCollectorNode for Box<ast::Item> { const KIND: AstFragmentKind = AstFragmentKind::Items; fn to_annotatable(self) -> Annotatable { Annotatable::Item(self) @@ -1283,7 +1281,7 @@ impl InvocationCollectorNode for P<ast::Item> { fn is_mac_call(&self) -> bool { matches!(self.kind, ItemKind::MacCall(..)) } - fn take_mac_call(self) -> (P<ast::MacCall>, ast::AttrVec, AddSemicolon) { + fn take_mac_call(self) -> (Box<ast::MacCall>, ast::AttrVec, AddSemicolon) { match self.kind { ItemKind::MacCall(mac) => (mac, self.attrs, AddSemicolon::No), _ => unreachable!(), @@ -1299,7 +1297,7 @@ impl InvocationCollectorNode for P<ast::Item> { ItemKind::Delegation(deleg) } fn from_item(item: ast::Item<Self::ItemKind>) -> Self { - P(item) + Box::new(item) } fn flatten_outputs(items: impl Iterator<Item = Self::OutputTy>) -> Self::OutputTy { items.flatten().collect() @@ -1421,8 +1419,8 @@ impl InvocationCollectorNode for P<ast::Item> { } struct TraitItemTag; -impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, TraitItemTag> { - type OutputTy = SmallVec<[P<ast::AssocItem>; 1]>; +impl InvocationCollectorNode for AstNodeWrapper<Box<ast::AssocItem>, TraitItemTag> { + type OutputTy = SmallVec<[Box<ast::AssocItem>; 1]>; type ItemKind = AssocItemKind; const KIND: AstFragmentKind = AstFragmentKind::TraitItems; fn to_annotatable(self) -> Annotatable { @@ -1437,7 +1435,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, TraitItemTag> fn is_mac_call(&self) -> bool { matches!(self.wrapped.kind, AssocItemKind::MacCall(..)) } - fn take_mac_call(self) -> (P<ast::MacCall>, ast::AttrVec, AddSemicolon) { + fn take_mac_call(self) -> (Box<ast::MacCall>, ast::AttrVec, AddSemicolon) { let item = self.wrapped; match item.kind { AssocItemKind::MacCall(mac) => (mac, item.attrs, AddSemicolon::No), @@ -1454,7 +1452,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, TraitItemTag> AssocItemKind::Delegation(deleg) } fn from_item(item: ast::Item<Self::ItemKind>) -> Self { - AstNodeWrapper::new(P(item), TraitItemTag) + AstNodeWrapper::new(Box::new(item), TraitItemTag) } fn flatten_outputs(items: impl Iterator<Item = Self::OutputTy>) -> Self::OutputTy { items.flatten().collect() @@ -1462,8 +1460,8 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, TraitItemTag> } struct ImplItemTag; -impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, ImplItemTag> { - type OutputTy = SmallVec<[P<ast::AssocItem>; 1]>; +impl InvocationCollectorNode for AstNodeWrapper<Box<ast::AssocItem>, ImplItemTag> { + type OutputTy = SmallVec<[Box<ast::AssocItem>; 1]>; type ItemKind = AssocItemKind; const KIND: AstFragmentKind = AstFragmentKind::ImplItems; fn to_annotatable(self) -> Annotatable { @@ -1478,7 +1476,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, ImplItemTag> fn is_mac_call(&self) -> bool { matches!(self.wrapped.kind, AssocItemKind::MacCall(..)) } - fn take_mac_call(self) -> (P<ast::MacCall>, ast::AttrVec, AddSemicolon) { + fn take_mac_call(self) -> (Box<ast::MacCall>, ast::AttrVec, AddSemicolon) { let item = self.wrapped; match item.kind { AssocItemKind::MacCall(mac) => (mac, item.attrs, AddSemicolon::No), @@ -1495,7 +1493,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, ImplItemTag> AssocItemKind::Delegation(deleg) } fn from_item(item: ast::Item<Self::ItemKind>) -> Self { - AstNodeWrapper::new(P(item), ImplItemTag) + AstNodeWrapper::new(Box::new(item), ImplItemTag) } fn flatten_outputs(items: impl Iterator<Item = Self::OutputTy>) -> Self::OutputTy { items.flatten().collect() @@ -1503,8 +1501,8 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, ImplItemTag> } struct TraitImplItemTag; -impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, TraitImplItemTag> { - type OutputTy = SmallVec<[P<ast::AssocItem>; 1]>; +impl InvocationCollectorNode for AstNodeWrapper<Box<ast::AssocItem>, TraitImplItemTag> { + type OutputTy = SmallVec<[Box<ast::AssocItem>; 1]>; type ItemKind = AssocItemKind; const KIND: AstFragmentKind = AstFragmentKind::TraitImplItems; fn to_annotatable(self) -> Annotatable { @@ -1519,7 +1517,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, TraitImplItem fn is_mac_call(&self) -> bool { matches!(self.wrapped.kind, AssocItemKind::MacCall(..)) } - fn take_mac_call(self) -> (P<ast::MacCall>, ast::AttrVec, AddSemicolon) { + fn take_mac_call(self) -> (Box<ast::MacCall>, ast::AttrVec, AddSemicolon) { let item = self.wrapped; match item.kind { AssocItemKind::MacCall(mac) => (mac, item.attrs, AddSemicolon::No), @@ -1536,14 +1534,14 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, TraitImplItem AssocItemKind::Delegation(deleg) } fn from_item(item: ast::Item<Self::ItemKind>) -> Self { - AstNodeWrapper::new(P(item), TraitImplItemTag) + AstNodeWrapper::new(Box::new(item), TraitImplItemTag) } fn flatten_outputs(items: impl Iterator<Item = Self::OutputTy>) -> Self::OutputTy { items.flatten().collect() } } -impl InvocationCollectorNode for P<ast::ForeignItem> { +impl InvocationCollectorNode for Box<ast::ForeignItem> { const KIND: AstFragmentKind = AstFragmentKind::ForeignItems; fn to_annotatable(self) -> Annotatable { Annotatable::ForeignItem(self) @@ -1557,7 +1555,7 @@ impl InvocationCollectorNode for P<ast::ForeignItem> { fn is_mac_call(&self) -> bool { matches!(self.kind, ForeignItemKind::MacCall(..)) } - fn take_mac_call(self) -> (P<ast::MacCall>, ast::AttrVec, AddSemicolon) { + fn take_mac_call(self) -> (Box<ast::MacCall>, ast::AttrVec, AddSemicolon) { match self.kind { ForeignItemKind::MacCall(mac) => (mac, self.attrs, AddSemicolon::No), _ => unreachable!(), @@ -1672,7 +1670,7 @@ impl InvocationCollectorNode for ast::Arm { impl InvocationCollectorNode for ast::Stmt { const KIND: AstFragmentKind = AstFragmentKind::Stmts; fn to_annotatable(self) -> Annotatable { - Annotatable::Stmt(P(self)) + Annotatable::Stmt(Box::new(self)) } fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_stmts() @@ -1689,7 +1687,7 @@ impl InvocationCollectorNode for ast::Stmt { StmtKind::Let(..) | StmtKind::Empty => false, } } - fn take_mac_call(self) -> (P<ast::MacCall>, ast::AttrVec, AddSemicolon) { + fn take_mac_call(self) -> (Box<ast::MacCall>, ast::AttrVec, AddSemicolon) { // We pull macro invocations (both attributes and fn-like macro calls) out of their // `StmtKind`s and treat them as statement macro invocations, not as items or expressions. let (add_semicolon, mac, attrs) = match self.kind { @@ -1726,7 +1724,7 @@ impl InvocationCollectorNode for ast::Stmt { ItemKind::Delegation(deleg) } fn from_item(item: ast::Item<Self::ItemKind>) -> Self { - ast::Stmt { id: ast::DUMMY_NODE_ID, span: item.span, kind: StmtKind::Item(P(item)) } + ast::Stmt { id: ast::DUMMY_NODE_ID, span: item.span, kind: StmtKind::Item(Box::new(item)) } } fn flatten_outputs(items: impl Iterator<Item = Self::OutputTy>) -> Self::OutputTy { items.flatten().collect() @@ -1769,7 +1767,7 @@ impl InvocationCollectorNode for ast::Crate { } impl InvocationCollectorNode for ast::Ty { - type OutputTy = P<ast::Ty>; + type OutputTy = Box<ast::Ty>; const KIND: AstFragmentKind = AstFragmentKind::Ty; fn to_annotatable(self) -> Annotatable { unreachable!() @@ -1793,7 +1791,7 @@ impl InvocationCollectorNode for ast::Ty { fn is_mac_call(&self) -> bool { matches!(self.kind, ast::TyKind::MacCall(..)) } - fn take_mac_call(self) -> (P<ast::MacCall>, ast::AttrVec, AddSemicolon) { + fn take_mac_call(self) -> (Box<ast::MacCall>, ast::AttrVec, AddSemicolon) { match self.kind { TyKind::MacCall(mac) => (mac, AttrVec::new(), AddSemicolon::No), _ => unreachable!(), @@ -1802,7 +1800,7 @@ impl InvocationCollectorNode for ast::Ty { } impl InvocationCollectorNode for ast::Pat { - type OutputTy = P<ast::Pat>; + type OutputTy = Box<ast::Pat>; const KIND: AstFragmentKind = AstFragmentKind::Pat; fn to_annotatable(self) -> Annotatable { unreachable!() @@ -1816,7 +1814,7 @@ impl InvocationCollectorNode for ast::Pat { fn is_mac_call(&self) -> bool { matches!(self.kind, PatKind::MacCall(..)) } - fn take_mac_call(self) -> (P<ast::MacCall>, ast::AttrVec, AddSemicolon) { + fn take_mac_call(self) -> (Box<ast::MacCall>, ast::AttrVec, AddSemicolon) { match self.kind { PatKind::MacCall(mac) => (mac, AttrVec::new(), AddSemicolon::No), _ => unreachable!(), @@ -1825,10 +1823,10 @@ impl InvocationCollectorNode for ast::Pat { } impl InvocationCollectorNode for ast::Expr { - type OutputTy = P<ast::Expr>; + type OutputTy = Box<ast::Expr>; const KIND: AstFragmentKind = AstFragmentKind::Expr; fn to_annotatable(self) -> Annotatable { - Annotatable::Expr(P(self)) + Annotatable::Expr(Box::new(self)) } fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_expr() @@ -1842,7 +1840,7 @@ impl InvocationCollectorNode for ast::Expr { fn is_mac_call(&self) -> bool { matches!(self.kind, ExprKind::MacCall(..)) } - fn take_mac_call(self) -> (P<ast::MacCall>, ast::AttrVec, AddSemicolon) { + fn take_mac_call(self) -> (Box<ast::MacCall>, ast::AttrVec, AddSemicolon) { match self.kind { ExprKind::MacCall(mac) => (mac, self.attrs, AddSemicolon::No), _ => unreachable!(), @@ -1851,8 +1849,8 @@ impl InvocationCollectorNode for ast::Expr { } struct OptExprTag; -impl InvocationCollectorNode for AstNodeWrapper<P<ast::Expr>, OptExprTag> { - type OutputTy = Option<P<ast::Expr>>; +impl InvocationCollectorNode for AstNodeWrapper<Box<ast::Expr>, OptExprTag> { + type OutputTy = Option<Box<ast::Expr>>; const KIND: AstFragmentKind = AstFragmentKind::OptExpr; fn to_annotatable(self) -> Annotatable { Annotatable::Expr(self.wrapped) @@ -1867,7 +1865,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::Expr>, OptExprTag> { fn is_mac_call(&self) -> bool { matches!(self.wrapped.kind, ast::ExprKind::MacCall(..)) } - fn take_mac_call(self) -> (P<ast::MacCall>, ast::AttrVec, AddSemicolon) { + fn take_mac_call(self) -> (Box<ast::MacCall>, ast::AttrVec, AddSemicolon) { let node = self.wrapped; match node.kind { ExprKind::MacCall(mac) => (mac, node.attrs, AddSemicolon::No), @@ -1884,13 +1882,13 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::Expr>, OptExprTag> { struct MethodReceiverTag; impl InvocationCollectorNode for AstNodeWrapper<ast::Expr, MethodReceiverTag> { - type OutputTy = AstNodeWrapper<P<ast::Expr>, MethodReceiverTag>; + type OutputTy = AstNodeWrapper<Box<ast::Expr>, MethodReceiverTag>; const KIND: AstFragmentKind = AstFragmentKind::MethodReceiverExpr; fn descr() -> &'static str { "an expression" } fn to_annotatable(self) -> Annotatable { - Annotatable::Expr(P(self.wrapped)) + Annotatable::Expr(Box::new(self.wrapped)) } fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { AstNodeWrapper::new(fragment.make_method_receiver_expr(), MethodReceiverTag) @@ -1901,7 +1899,7 @@ impl InvocationCollectorNode for AstNodeWrapper<ast::Expr, MethodReceiverTag> { fn is_mac_call(&self) -> bool { matches!(self.wrapped.kind, ast::ExprKind::MacCall(..)) } - fn take_mac_call(self) -> (P<ast::MacCall>, ast::AttrVec, AddSemicolon) { + fn take_mac_call(self) -> (Box<ast::MacCall>, ast::AttrVec, AddSemicolon) { let node = self.wrapped; match node.kind { ExprKind::MacCall(mac) => (mac, node.attrs, AddSemicolon::No), @@ -2038,7 +2036,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { placeholder(fragment_kind, NodeId::placeholder_from_expn_id(expn_id), vis) } - fn collect_bang(&mut self, mac: P<ast::MacCall>, kind: AstFragmentKind) -> AstFragment { + fn collect_bang(&mut self, mac: Box<ast::MacCall>, kind: AstFragmentKind) -> AstFragment { // cache the macro call span so that it can be // easily adjusted for incremental compilation let span = mac.span(); @@ -2056,7 +2054,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { fn collect_glob_delegation( &mut self, - item: P<ast::AssocItem>, + item: Box<ast::AssocItem>, of_trait: bool, kind: AstFragmentKind, ) -> AstFragment { @@ -2329,15 +2327,15 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { } impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { - fn flat_map_item(&mut self, node: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> { + fn flat_map_item(&mut self, node: Box<ast::Item>) -> SmallVec<[Box<ast::Item>; 1]> { self.flat_map_node(node) } fn flat_map_assoc_item( &mut self, - node: P<ast::AssocItem>, + node: Box<ast::AssocItem>, ctxt: AssocCtxt, - ) -> SmallVec<[P<ast::AssocItem>; 1]> { + ) -> SmallVec<[Box<ast::AssocItem>; 1]> { match ctxt { AssocCtxt::Trait => self.flat_map_node(AstNodeWrapper::new(node, TraitItemTag)), AssocCtxt::Impl { of_trait: false } => { @@ -2351,8 +2349,8 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { fn flat_map_foreign_item( &mut self, - node: P<ast::ForeignItem>, - ) -> SmallVec<[P<ast::ForeignItem>; 1]> { + node: Box<ast::ForeignItem>, + ) -> SmallVec<[Box<ast::ForeignItem>; 1]> { self.flat_map_node(node) } @@ -2447,7 +2445,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { self.visit_node(AstNodeWrapper::from_mut(node, MethodReceiverTag)) } - fn filter_map_expr(&mut self, node: P<ast::Expr>) -> Option<P<ast::Expr>> { + fn filter_map_expr(&mut self, node: Box<ast::Expr>) -> Option<Box<ast::Expr>> { self.flat_map_node(AstNodeWrapper::new(node, OptExprTag)) } diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index 37b236a2e26..08b0efb74a0 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -347,7 +347,7 @@ fn expand_macro_attr( if cx.trace_macros() { let msg = format!( - "expanding `$[{name}({})] {}`", + "expanding `#[{name}({})] {}`", pprust::tts_to_string(&args), pprust::tts_to_string(&body), ); diff --git a/compiler/rustc_expand/src/module.rs b/compiler/rustc_expand/src/module.rs index e925052c607..662c67f2d3f 100644 --- a/compiler/rustc_expand/src/module.rs +++ b/compiler/rustc_expand/src/module.rs @@ -1,7 +1,6 @@ use std::iter::once; use std::path::{self, Path, PathBuf}; -use rustc_ast::ptr::P; use rustc_ast::{AttrVec, Attribute, Inline, Item, ModSpans}; use rustc_errors::{Diag, ErrorGuaranteed}; use rustc_parse::{exp, new_parser_from_file, unwrap_or_emit_fatal, validate_attr}; @@ -31,7 +30,7 @@ pub struct ModulePathSuccess { } pub(crate) struct ParsedExternalMod { - pub items: ThinVec<P<Item>>, + pub items: ThinVec<Box<Item>>, pub spans: ModSpans, pub file_path: PathBuf, pub dir_path: PathBuf, diff --git a/compiler/rustc_expand/src/placeholders.rs b/compiler/rustc_expand/src/placeholders.rs index 6e1c6df4bcb..05f9a5aa43f 100644 --- a/compiler/rustc_expand/src/placeholders.rs +++ b/compiler/rustc_expand/src/placeholders.rs @@ -1,5 +1,4 @@ use rustc_ast::mut_visit::*; -use rustc_ast::ptr::P; use rustc_ast::token::Delimiter; use rustc_ast::visit::AssocCtxt; use rustc_ast::{self as ast, Safety}; @@ -15,10 +14,10 @@ pub(crate) fn placeholder( id: ast::NodeId, vis: Option<ast::Visibility>, ) -> AstFragment { - fn mac_placeholder() -> P<ast::MacCall> { - P(ast::MacCall { + fn mac_placeholder() -> Box<ast::MacCall> { + Box::new(ast::MacCall { path: ast::Path { span: DUMMY_SP, segments: ThinVec::new(), tokens: None }, - args: P(ast::DelimArgs { + args: Box::new(ast::DelimArgs { dspan: ast::tokenstream::DelimSpan::dummy(), delim: Delimiter::Parenthesis, tokens: ast::tokenstream::TokenStream::new(Vec::new()), @@ -35,7 +34,7 @@ pub(crate) fn placeholder( }); let span = DUMMY_SP; let expr_placeholder = || { - P(ast::Expr { + Box::new(ast::Expr { id, span, attrs: ast::AttrVec::new(), @@ -43,10 +42,17 @@ pub(crate) fn placeholder( tokens: None, }) }; - let ty = - || P(ast::Ty { id, kind: ast::TyKind::MacCall(mac_placeholder()), span, tokens: None }); - let pat = - || P(ast::Pat { id, kind: ast::PatKind::MacCall(mac_placeholder()), span, tokens: None }); + let ty = || { + Box::new(ast::Ty { id, kind: ast::TyKind::MacCall(mac_placeholder()), span, tokens: None }) + }; + let pat = || { + Box::new(ast::Pat { + id, + kind: ast::PatKind::MacCall(mac_placeholder()), + span, + tokens: None, + }) + }; match kind { AstFragmentKind::Crate => AstFragment::Crate(ast::Crate { @@ -59,7 +65,7 @@ pub(crate) fn placeholder( AstFragmentKind::Expr => AstFragment::Expr(expr_placeholder()), AstFragmentKind::OptExpr => AstFragment::OptExpr(Some(expr_placeholder())), AstFragmentKind::MethodReceiverExpr => AstFragment::MethodReceiverExpr(expr_placeholder()), - AstFragmentKind::Items => AstFragment::Items(smallvec![P(ast::Item { + AstFragmentKind::Items => AstFragment::Items(smallvec![Box::new(ast::Item { id, span, vis, @@ -67,15 +73,17 @@ pub(crate) fn placeholder( kind: ast::ItemKind::MacCall(mac_placeholder()), tokens: None, })]), - AstFragmentKind::TraitItems => AstFragment::TraitItems(smallvec![P(ast::AssocItem { - id, - span, - vis, - attrs, - kind: ast::AssocItemKind::MacCall(mac_placeholder()), - tokens: None, - })]), - AstFragmentKind::ImplItems => AstFragment::ImplItems(smallvec![P(ast::AssocItem { + AstFragmentKind::TraitItems => { + AstFragment::TraitItems(smallvec![Box::new(ast::AssocItem { + id, + span, + vis, + attrs, + kind: ast::AssocItemKind::MacCall(mac_placeholder()), + tokens: None, + })]) + } + AstFragmentKind::ImplItems => AstFragment::ImplItems(smallvec![Box::new(ast::AssocItem { id, span, vis, @@ -84,7 +92,7 @@ pub(crate) fn placeholder( tokens: None, })]), AstFragmentKind::TraitImplItems => { - AstFragment::TraitImplItems(smallvec![P(ast::AssocItem { + AstFragment::TraitImplItems(smallvec![Box::new(ast::AssocItem { id, span, vis, @@ -94,7 +102,7 @@ pub(crate) fn placeholder( })]) } AstFragmentKind::ForeignItems => { - AstFragment::ForeignItems(smallvec![P(ast::ForeignItem { + AstFragment::ForeignItems(smallvec![Box::new(ast::ForeignItem { id, span, vis, @@ -103,20 +111,20 @@ pub(crate) fn placeholder( tokens: None, })]) } - AstFragmentKind::Pat => AstFragment::Pat(P(ast::Pat { + AstFragmentKind::Pat => AstFragment::Pat(Box::new(ast::Pat { id, span, kind: ast::PatKind::MacCall(mac_placeholder()), tokens: None, })), - AstFragmentKind::Ty => AstFragment::Ty(P(ast::Ty { + AstFragmentKind::Ty => AstFragment::Ty(Box::new(ast::Ty { id, span, kind: ast::TyKind::MacCall(mac_placeholder()), tokens: None, })), AstFragmentKind::Stmts => AstFragment::Stmts(smallvec![{ - let mac = P(ast::MacCallStmt { + let mac = Box::new(ast::MacCallStmt { mac: mac_placeholder(), style: ast::MacStmtStyle::Braces, attrs: ast::AttrVec::new(), @@ -297,7 +305,7 @@ impl MutVisitor for PlaceholderExpander { } } - fn flat_map_item(&mut self, item: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> { + fn flat_map_item(&mut self, item: Box<ast::Item>) -> SmallVec<[Box<ast::Item>; 1]> { match item.kind { ast::ItemKind::MacCall(_) => self.remove(item.id).make_items(), _ => walk_flat_map_item(self, item), @@ -306,9 +314,9 @@ impl MutVisitor for PlaceholderExpander { fn flat_map_assoc_item( &mut self, - item: P<ast::AssocItem>, + item: Box<ast::AssocItem>, ctxt: AssocCtxt, - ) -> SmallVec<[P<ast::AssocItem>; 1]> { + ) -> SmallVec<[Box<ast::AssocItem>; 1]> { match item.kind { ast::AssocItemKind::MacCall(_) => { let it = self.remove(item.id); @@ -324,8 +332,8 @@ impl MutVisitor for PlaceholderExpander { fn flat_map_foreign_item( &mut self, - item: P<ast::ForeignItem>, - ) -> SmallVec<[P<ast::ForeignItem>; 1]> { + item: Box<ast::ForeignItem>, + ) -> SmallVec<[Box<ast::ForeignItem>; 1]> { match item.kind { ast::ForeignItemKind::MacCall(_) => self.remove(item.id).make_foreign_items(), _ => walk_flat_map_foreign_item(self, item), @@ -346,7 +354,7 @@ impl MutVisitor for PlaceholderExpander { } } - fn filter_map_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> { + fn filter_map_expr(&mut self, expr: Box<ast::Expr>) -> Option<Box<ast::Expr>> { match expr.kind { ast::ExprKind::MacCall(_) => self.remove(expr.id).make_opt_expr(), _ => walk_filter_map_expr(self, expr), diff --git a/compiler/rustc_expand/src/proc_macro.rs b/compiler/rustc_expand/src/proc_macro.rs index 84fbbbef061..9bfda8764f5 100644 --- a/compiler/rustc_expand/src/proc_macro.rs +++ b/compiler/rustc_expand/src/proc_macro.rs @@ -1,4 +1,3 @@ -use rustc_ast::ptr::P; use rustc_ast::tokenstream::TokenStream; use rustc_errors::ErrorGuaranteed; use rustc_parse::parser::{ForceCollect, Parser}; @@ -161,7 +160,7 @@ impl MultiItemModifier for DeriveProcMacro { Ok(None) => break, Ok(Some(item)) => { if is_stmt { - items.push(Annotatable::Stmt(P(ecx.stmt_item(span, item)))); + items.push(Annotatable::Stmt(Box::new(ecx.stmt_item(span, item)))); } else { items.push(Annotatable::Item(item)); } diff --git a/compiler/rustc_expand/src/stats.rs b/compiler/rustc_expand/src/stats.rs index b4c4eac028f..3e40632275b 100644 --- a/compiler/rustc_expand/src/stats.rs +++ b/compiler/rustc_expand/src/stats.rs @@ -1,6 +1,5 @@ use std::iter; -use rustc_ast::ptr::P; use rustc_ast::{self as ast, DUMMY_NODE_ID, Expr, ExprKind}; use rustc_ast_pretty::pprust; use rustc_span::hygiene::{ExpnKind, MacroKind}; @@ -41,7 +40,7 @@ pub(crate) fn update_bang_macro_stats( ecx: &mut ExtCtxt<'_>, fragment_kind: AstFragmentKind, span: Span, - mac: P<ast::MacCall>, + mac: Box<ast::MacCall>, fragment: &AstFragment, ) { // Does this path match any of the include macros, e.g. `include!`? diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs index 5c63d4808db..ab6b8f92802 100644 --- a/compiler/rustc_feature/src/builtin_attrs.rs +++ b/compiler/rustc_feature/src/builtin_attrs.rs @@ -120,13 +120,15 @@ pub struct AttributeTemplate { /// If `true`, the attribute is allowed to be a bare word like `#[test]`. pub word: bool, /// If `Some`, the attribute is allowed to take a list of items like `#[allow(..)]`. - pub list: Option<&'static str>, + pub list: Option<&'static [&'static str]>, /// If non-empty, the attribute is allowed to take a list containing exactly /// one of the listed words, like `#[coverage(off)]`. pub one_of: &'static [Symbol], /// If `Some`, the attribute is allowed to be a name/value pair where the /// value is a string, like `#[must_use = "reason"]`. - pub name_value_str: Option<&'static str>, + pub name_value_str: Option<&'static [&'static str]>, + /// A link to the document for this attribute. + pub docs: Option<&'static str>, } impl AttributeTemplate { @@ -137,11 +139,15 @@ impl AttributeTemplate { suggestions.push(format!("#{inner}[{name}]")); } if let Some(descr) = self.list { - suggestions.push(format!("#{inner}[{name}({descr})]")); + for descr in descr { + suggestions.push(format!("#{inner}[{name}({descr})]")); + } } suggestions.extend(self.one_of.iter().map(|&word| format!("#{inner}[{name}({word})]"))); if let Some(descr) = self.name_value_str { - suggestions.push(format!("#{inner}[{name} = \"{descr}\"]")); + for descr in descr { + suggestions.push(format!("#{inner}[{name} = \"{descr}\"]")); + } } suggestions.sort(); @@ -205,20 +211,33 @@ pub enum AttributeDuplicates { /// supports forms `#[attr]` and `#[attr(description)]`. #[macro_export] macro_rules! template { - (Word) => { $crate::template!(@ true, None, &[], None) }; - (List: $descr: expr) => { $crate::template!(@ false, Some($descr), &[], None) }; - (OneOf: $one_of: expr) => { $crate::template!(@ false, None, $one_of, None) }; - (NameValueStr: $descr: expr) => { $crate::template!(@ false, None, &[], Some($descr)) }; - (Word, List: $descr: expr) => { $crate::template!(@ true, Some($descr), &[], None) }; - (Word, NameValueStr: $descr: expr) => { $crate::template!(@ true, None, &[], Some($descr)) }; + (Word) => { $crate::template!(@ true, None, &[], None, None) }; + (Word, $link: literal) => { $crate::template!(@ true, None, &[], None, Some($link)) }; + (List: $descr: expr) => { $crate::template!(@ false, Some($descr), &[], None, None) }; + (List: $descr: expr, $link: literal) => { $crate::template!(@ false, Some($descr), &[], None, Some($link)) }; + (OneOf: $one_of: expr) => { $crate::template!(@ false, None, $one_of, None, None) }; + (NameValueStr: [$($descr: literal),* $(,)?]) => { $crate::template!(@ false, None, &[], Some(&[$($descr,)*]), None) }; + (NameValueStr: [$($descr: literal),* $(,)?], $link: literal) => { $crate::template!(@ false, None, &[], Some(&[$($descr,)*]), Some($link)) }; + (NameValueStr: $descr: literal) => { $crate::template!(@ false, None, &[], Some(&[$descr]), None) }; + (NameValueStr: $descr: literal, $link: literal) => { $crate::template!(@ false, None, &[], Some(&[$descr]), Some($link)) }; + (Word, List: $descr: expr) => { $crate::template!(@ true, Some($descr), &[], None, None) }; + (Word, List: $descr: expr, $link: literal) => { $crate::template!(@ true, Some($descr), &[], None, Some($link)) }; + (Word, NameValueStr: $descr: expr) => { $crate::template!(@ true, None, &[], Some(&[$descr]), None) }; + (Word, NameValueStr: $descr: expr, $link: literal) => { $crate::template!(@ true, None, &[], Some(&[$descr]), Some($link)) }; (List: $descr1: expr, NameValueStr: $descr2: expr) => { - $crate::template!(@ false, Some($descr1), &[], Some($descr2)) + $crate::template!(@ false, Some($descr1), &[], Some(&[$descr2]), None) + }; + (List: $descr1: expr, NameValueStr: $descr2: expr, $link: literal) => { + $crate::template!(@ false, Some($descr1), &[], Some(&[$descr2]), Some($link)) }; (Word, List: $descr1: expr, NameValueStr: $descr2: expr) => { - $crate::template!(@ true, Some($descr1), &[], Some($descr2)) + $crate::template!(@ true, Some($descr1), &[], Some(&[$descr2]), None) }; - (@ $word: expr, $list: expr, $one_of: expr, $name_value_str: expr) => { $crate::AttributeTemplate { - word: $word, list: $list, one_of: $one_of, name_value_str: $name_value_str + (Word, List: $descr1: expr, NameValueStr: $descr2: expr, $link: literal) => { + $crate::template!(@ true, Some($descr1), &[], Some(&[$descr2]), Some($link)) + }; + (@ $word: expr, $list: expr, $one_of: expr, $name_value_str: expr, $link: expr) => { $crate::AttributeTemplate { + word: $word, list: $list, one_of: $one_of, name_value_str: $name_value_str, docs: $link, } }; } @@ -391,18 +410,42 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ // ========================================================================== // Conditional compilation: - ungated!(cfg, Normal, template!(List: "predicate"), DuplicatesOk, EncodeCrossCrate::Yes), - ungated!(cfg_attr, Normal, template!(List: "predicate, attr1, attr2, ..."), DuplicatesOk, EncodeCrossCrate::Yes), + ungated!( + cfg, Normal, + template!( + List: &["predicate"], + "https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute" + ), + DuplicatesOk, EncodeCrossCrate::Yes + ), + ungated!( + cfg_attr, Normal, + template!( + List: &["predicate, attr1, attr2, ..."], + "https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute" + ), + DuplicatesOk, EncodeCrossCrate::Yes + ), // Testing: ungated!( - ignore, Normal, template!(Word, NameValueStr: "reason"), WarnFollowing, - EncodeCrossCrate::No, + ignore, Normal, + template!( + Word, + NameValueStr: "reason", + "https://doc.rust-lang.org/reference/attributes/testing.html#the-ignore-attribute" + ), + WarnFollowing, EncodeCrossCrate::No, ), ungated!( should_panic, Normal, - template!(Word, List: r#"expected = "reason""#, NameValueStr: "reason"), FutureWarnFollowing, - EncodeCrossCrate::No, + template!( + Word, + List: &[r#"expected = "reason""#], + NameValueStr: "reason", + "https://doc.rust-lang.org/reference/attributes/testing.html#the-should_panic-attribute" + ), + FutureWarnFollowing, EncodeCrossCrate::No, ), // FIXME(Centril): This can be used on stable but shouldn't. ungated!( @@ -411,46 +454,102 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ ), // Macros: - ungated!(automatically_derived, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes), ungated!( - macro_use, Normal, template!(Word, List: "name1, name2, ..."), WarnFollowingWordOnly, - EncodeCrossCrate::No, + automatically_derived, Normal, + template!( + Word, + "https://doc.rust-lang.org/reference/attributes/derive.html#the-automatically_derived-attribute" + ), + WarnFollowing, EncodeCrossCrate::Yes + ), + ungated!( + macro_use, Normal, + template!( + Word, + List: &["name1, name2, ..."], + "https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute" + ), + WarnFollowingWordOnly, EncodeCrossCrate::No, ), ungated!(macro_escape, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No), // Deprecated synonym for `macro_use`. ungated!( - macro_export, Normal, template!(Word, List: "local_inner_macros"), + macro_export, Normal, + template!( + Word, + List: &["local_inner_macros"], + "https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope" + ), WarnFollowing, EncodeCrossCrate::Yes ), - ungated!(proc_macro, Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::No), ungated!( - proc_macro_derive, Normal, template!(List: "TraitName, /*opt*/ attributes(name1, name2, ...)"), + proc_macro, Normal, + template!( + Word, + "https://doc.rust-lang.org/reference/procedural-macros.html#function-like-procedural-macros"), + ErrorFollowing, EncodeCrossCrate::No + ), + ungated!( + proc_macro_derive, Normal, + template!( + List: &["TraitName", "TraitName, attributes(name1, name2, ...)"], + "https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros" + ), ErrorFollowing, EncodeCrossCrate::No, ), - ungated!(proc_macro_attribute, Normal, template!(Word), ErrorFollowing, EncodeCrossCrate::No), + ungated!( + proc_macro_attribute, Normal, + template!(Word, "https://doc.rust-lang.org/reference/procedural-macros.html#attribute-macros"), + ErrorFollowing, EncodeCrossCrate::No + ), // Lints: ungated!( - warn, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#), + warn, Normal, + template!( + List: &["lint1", "lint1, lint2, ...", r#"lint1, lint2, lint3, reason = "...""#], + "https://doc.rust-lang.org/reference/attributes/diagnostics.html#lint-check-attributes" + ), DuplicatesOk, EncodeCrossCrate::No, ), ungated!( - allow, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#), + allow, Normal, + template!( + List: &["lint1", "lint1, lint2, ...", r#"lint1, lint2, lint3, reason = "...""#], + "https://doc.rust-lang.org/reference/attributes/diagnostics.html#lint-check-attributes" + ), DuplicatesOk, EncodeCrossCrate::No, ), ungated!( - expect, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#), + expect, Normal, + template!( + List: &["lint1", "lint1, lint2, ...", r#"lint1, lint2, lint3, reason = "...""#], + "https://doc.rust-lang.org/reference/attributes/diagnostics.html#lint-check-attributes" + ), DuplicatesOk, EncodeCrossCrate::No, ), ungated!( - forbid, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#), + forbid, Normal, + template!( + List: &["lint1", "lint1, lint2, ...", r#"lint1, lint2, lint3, reason = "...""#], + "https://doc.rust-lang.org/reference/attributes/diagnostics.html#lint-check-attributes" + ), DuplicatesOk, EncodeCrossCrate::No ), ungated!( - deny, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#), + deny, Normal, + template!( + List: &["lint1", "lint1, lint2, ...", r#"lint1, lint2, lint3, reason = "...""#], + "https://doc.rust-lang.org/reference/attributes/diagnostics.html#lint-check-attributes" + ), DuplicatesOk, EncodeCrossCrate::No ), ungated!( - must_use, Normal, template!(Word, NameValueStr: "reason"), + must_use, Normal, + template!( + Word, + NameValueStr: "reason", + "https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute" + ), FutureWarnFollowing, EncodeCrossCrate::Yes ), gated!( @@ -461,52 +560,104 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ deprecated, Normal, template!( Word, - List: r#"/*opt*/ since = "version", /*opt*/ note = "reason""#, - NameValueStr: "reason" + List: &[r#"/*opt*/ since = "version", /*opt*/ note = "reason""#], + NameValueStr: "reason", + "https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute" ), ErrorFollowing, EncodeCrossCrate::Yes ), // Crate properties: ungated!( - crate_name, CrateLevel, template!(NameValueStr: "name"), FutureWarnFollowing, - EncodeCrossCrate::No, + crate_name, CrateLevel, + template!( + NameValueStr: "name", + "https://doc.rust-lang.org/reference/crates-and-source-files.html#the-crate_name-attribute" + ), + FutureWarnFollowing, EncodeCrossCrate::No, ), ungated!( - crate_type, CrateLevel, template!(NameValueStr: "bin|lib|..."), DuplicatesOk, - EncodeCrossCrate::No, + crate_type, CrateLevel, + template!( + NameValueStr: ["bin", "lib", "dylib", "cdylib", "rlib", "staticlib", "sdylib", "proc-macro"], + "https://doc.rust-lang.org/reference/linkage.html" + ), + DuplicatesOk, EncodeCrossCrate::No, ), // ABI, linking, symbols, and FFI ungated!( link, Normal, - template!(List: r#"name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ wasm_import_module = "...", /*opt*/ import_name_type = "decorated|noprefix|undecorated""#), - DuplicatesOk, - EncodeCrossCrate::No, + template!(List: &[ + r#"name = "...""#, + r#"name = "...", kind = "dylib|static|...""#, + r#"name = "...", wasm_import_module = "...""#, + r#"name = "...", import_name_type = "decorated|noprefix|undecorated""#, + r#"name = "...", kind = "dylib|static|...", wasm_import_module = "...", import_name_type = "decorated|noprefix|undecorated""#, + ], "https://doc.rust-lang.org/reference/items/external-blocks.html#the-link-attribute"), + DuplicatesOk, EncodeCrossCrate::No, ), ungated!( - link_name, Normal, template!(NameValueStr: "name"), + link_name, Normal, + template!(NameValueStr: "name", "https://doc.rust-lang.org/reference/items/external-blocks.html#the-link_name-attribute"), FutureWarnPreceding, EncodeCrossCrate::Yes ), - ungated!(no_link, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No), - ungated!(repr, Normal, template!(List: "C"), DuplicatesOk, EncodeCrossCrate::No), + ungated!( + no_link, Normal, + template!(Word, "https://doc.rust-lang.org/reference/items/extern-crates.html#the-no_link-attribute"), + WarnFollowing, EncodeCrossCrate::No + ), + ungated!( + repr, Normal, + template!( + List: &["C", "Rust", "transparent", "align(...)", "packed(...)", "<integer type>"], + "https://doc.rust-lang.org/reference/type-layout.html#representations" + ), + DuplicatesOk, EncodeCrossCrate::No + ), // FIXME(#82232, #143834): temporarily renamed to mitigate `#[align]` nameres ambiguity - gated!(rustc_align, Normal, template!(List: "alignment"), DuplicatesOk, EncodeCrossCrate::No, fn_align, experimental!(rustc_align)), - ungated!(unsafe(Edition2024) export_name, Normal, template!(NameValueStr: "name"), FutureWarnPreceding, EncodeCrossCrate::No), - ungated!(unsafe(Edition2024) link_section, Normal, template!(NameValueStr: "name"), FutureWarnPreceding, EncodeCrossCrate::No), - ungated!(unsafe(Edition2024) no_mangle, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No), - ungated!(used, Normal, template!(Word, List: "compiler|linker"), WarnFollowing, EncodeCrossCrate::No), - ungated!(link_ordinal, Normal, template!(List: "ordinal"), ErrorPreceding, EncodeCrossCrate::Yes), - ungated!(unsafe naked, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No), + gated!(rustc_align, Normal, template!(List: &["alignment"]), DuplicatesOk, EncodeCrossCrate::No, fn_align, experimental!(rustc_align)), + ungated!( + unsafe(Edition2024) export_name, Normal, + template!(NameValueStr: "name", "https://doc.rust-lang.org/reference/abi.html#the-export_name-attribute"), + FutureWarnPreceding, EncodeCrossCrate::No + ), + ungated!( + unsafe(Edition2024) link_section, Normal, + template!(NameValueStr: "name", "https://doc.rust-lang.org/reference/abi.html#the-link_section-attribute"), + FutureWarnPreceding, EncodeCrossCrate::No + ), + ungated!( + unsafe(Edition2024) no_mangle, Normal, + template!(Word, "https://doc.rust-lang.org/reference/abi.html#the-no_mangle-attribute"), + WarnFollowing, EncodeCrossCrate::No + ), + ungated!( + used, Normal, + template!(Word, List: &["compiler", "linker"], "https://doc.rust-lang.org/reference/abi.html#the-used-attribute"), + WarnFollowing, EncodeCrossCrate::No + ), + ungated!( + link_ordinal, Normal, + template!(List: &["ordinal"], "https://doc.rust-lang.org/reference/items/external-blocks.html#the-link_ordinal-attribute"), + ErrorPreceding, EncodeCrossCrate::Yes + ), + ungated!( + unsafe naked, Normal, + template!(Word, "https://doc.rust-lang.org/reference/attributes/codegen.html#the-naked-attribute"), + WarnFollowing, EncodeCrossCrate::No + ), // Limits: ungated!( - recursion_limit, CrateLevel, template!(NameValueStr: "N"), FutureWarnFollowing, - EncodeCrossCrate::No + recursion_limit, CrateLevel, + template!(NameValueStr: "N", "https://doc.rust-lang.org/reference/attributes/limits.html#the-recursion_limit-attribute"), + FutureWarnFollowing, EncodeCrossCrate::No ), ungated!( - type_length_limit, CrateLevel, template!(NameValueStr: "N"), FutureWarnFollowing, - EncodeCrossCrate::No + type_length_limit, CrateLevel, + template!(NameValueStr: "N", "https://doc.rust-lang.org/reference/attributes/limits.html#the-type_length_limit-attribute"), + FutureWarnFollowing, EncodeCrossCrate::No ), gated!( move_size_limit, CrateLevel, template!(NameValueStr: "N"), ErrorFollowing, @@ -514,35 +665,84 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ ), // Entry point: - ungated!(no_main, CrateLevel, template!(Word), WarnFollowing, EncodeCrossCrate::No), + ungated!( + no_main, CrateLevel, + template!(Word, "https://doc.rust-lang.org/reference/crates-and-source-files.html#the-no_main-attribute"), + WarnFollowing, EncodeCrossCrate::No + ), // Modules, prelude, and resolution: - ungated!(path, Normal, template!(NameValueStr: "file"), FutureWarnFollowing, EncodeCrossCrate::No), - ungated!(no_std, CrateLevel, template!(Word), WarnFollowing, EncodeCrossCrate::No), - ungated!(no_implicit_prelude, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No), - ungated!(non_exhaustive, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes), + ungated!( + path, Normal, + template!(NameValueStr: "file", "https://doc.rust-lang.org/reference/items/modules.html#the-path-attribute"), + FutureWarnFollowing, EncodeCrossCrate::No + ), + ungated!( + no_std, CrateLevel, + template!(Word, "https://doc.rust-lang.org/reference/names/preludes.html#the-no_std-attribute"), + WarnFollowing, EncodeCrossCrate::No + ), + ungated!( + no_implicit_prelude, Normal, + template!(Word, "https://doc.rust-lang.org/reference/names/preludes.html#the-no_implicit_prelude-attribute"), + WarnFollowing, EncodeCrossCrate::No + ), + ungated!( + non_exhaustive, Normal, + template!(Word, "https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute"), + WarnFollowing, EncodeCrossCrate::Yes + ), // Runtime ungated!( windows_subsystem, CrateLevel, - template!(NameValueStr: "windows|console"), FutureWarnFollowing, - EncodeCrossCrate::No + template!(NameValueStr: ["windows", "console"], "https://doc.rust-lang.org/reference/runtime.html#the-windows_subsystem-attribute"), + FutureWarnFollowing, EncodeCrossCrate::No + ), + ungated!( // RFC 2070 + panic_handler, Normal, + template!(Word, "https://doc.rust-lang.org/reference/panic.html#the-panic_handler-attribute"), + WarnFollowing, EncodeCrossCrate::Yes ), - ungated!(panic_handler, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes), // RFC 2070 // Code generation: - ungated!(inline, Normal, template!(Word, List: "always|never"), FutureWarnFollowing, EncodeCrossCrate::No), - ungated!(cold, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No), - ungated!(no_builtins, CrateLevel, template!(Word), WarnFollowing, EncodeCrossCrate::Yes), ungated!( - target_feature, Normal, template!(List: r#"enable = "name""#), + inline, Normal, + template!( + Word, + List: &["always", "never"], + "https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute" + ), + FutureWarnFollowing, EncodeCrossCrate::No + ), + ungated!( + cold, Normal, + template!(Word, "https://doc.rust-lang.org/reference/attributes/codegen.html#the-cold-attribute"), + WarnFollowing, EncodeCrossCrate::No + ), + ungated!( + no_builtins, CrateLevel, + template!(Word, "https://doc.rust-lang.org/reference/attributes/codegen.html#the-no_builtins-attribute"), + WarnFollowing, EncodeCrossCrate::Yes + ), + ungated!( + target_feature, Normal, + template!(List: &[r#"enable = "name""#], "https://doc.rust-lang.org/reference/attributes/codegen.html#the-target_feature-attribute"), DuplicatesOk, EncodeCrossCrate::No, ), - ungated!(track_caller, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::Yes), - ungated!(instruction_set, Normal, template!(List: "set"), ErrorPreceding, EncodeCrossCrate::No), + ungated!( + track_caller, Normal, + template!(Word, "https://doc.rust-lang.org/reference/attributes/codegen.html#the-track_caller-attribute"), + WarnFollowing, EncodeCrossCrate::Yes + ), + ungated!( + instruction_set, Normal, + template!(List: &["set"], "https://doc.rust-lang.org/reference/attributes/codegen.html#the-instruction_set-attribute"), + ErrorPreceding, EncodeCrossCrate::No + ), gated!( no_sanitize, Normal, - template!(List: "address, kcfi, memory, thread"), DuplicatesOk, + template!(List: &["address, kcfi, memory, thread"]), DuplicatesOk, EncodeCrossCrate::No, experimental!(no_sanitize) ), gated!( @@ -552,18 +752,31 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ ), ungated!( - doc, Normal, template!(List: "hidden|inline|...", NameValueStr: "string"), DuplicatesOk, - EncodeCrossCrate::Yes + doc, Normal, + template!( + List: &["hidden", "inline"], + NameValueStr: "string", + "https://doc.rust-lang.org/rustdoc/write-documentation/the-doc-attribute.html" + ), + DuplicatesOk, EncodeCrossCrate::Yes ), // Debugging ungated!( debugger_visualizer, Normal, - template!(List: r#"natvis_file = "...", gdb_script_file = "...""#), + template!( + List: &[r#"natvis_file = "...", gdb_script_file = "...""#], + "https://doc.rust-lang.org/reference/attributes/debugger.html#the-debugger_visualizer-attribute" + ), DuplicatesOk, EncodeCrossCrate::No ), - ungated!(collapse_debuginfo, Normal, template!(List: "no|external|yes"), ErrorFollowing, - EncodeCrossCrate::Yes + ungated!( + collapse_debuginfo, Normal, + template!( + List: &["no", "external", "yes"], + "https://doc.rust-lang.org/reference/attributes/debugger.html#the-collapse_debuginfo-attribute" + ), + ErrorFollowing, EncodeCrossCrate::Yes ), // ========================================================================== @@ -578,7 +791,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ // Testing: gated!( - test_runner, CrateLevel, template!(List: "path"), ErrorFollowing, + test_runner, CrateLevel, template!(List: &["path"]), ErrorFollowing, EncodeCrossCrate::Yes, custom_test_frameworks, "custom test frameworks are an unstable feature", ), @@ -597,7 +810,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ ), // RFC 2412 gated!( - optimize, Normal, template!(List: "none|size|speed"), ErrorPreceding, + optimize, Normal, template!(List: &["none", "size", "speed"]), ErrorPreceding, EncodeCrossCrate::No, optimize_attribute, experimental!(optimize) ), @@ -610,7 +823,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ EncodeCrossCrate::No, experimental!(ffi_const) ), gated!( - register_tool, CrateLevel, template!(List: "tool1, tool2, ..."), DuplicatesOk, + register_tool, CrateLevel, template!(List: &["tool1, tool2, ..."]), DuplicatesOk, EncodeCrossCrate::No, experimental!(register_tool), ), @@ -624,7 +837,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ ), // lang-team MCP 147 gated!( - deprecated_safe, Normal, template!(List: r#"since = "version", note = "...""#), ErrorFollowing, + deprecated_safe, Normal, template!(List: &[r#"since = "version", note = "...""#]), ErrorFollowing, EncodeCrossCrate::Yes, experimental!(deprecated_safe), ), @@ -643,7 +856,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ // RFC 3543 // `#[patchable_function_entry(prefix_nops = m, entry_nops = n)]` gated!( - patchable_function_entry, Normal, template!(List: "prefix_nops = m, entry_nops = n"), ErrorPreceding, + patchable_function_entry, Normal, template!(List: &["prefix_nops = m, entry_nops = n"]), ErrorPreceding, EncodeCrossCrate::Yes, experimental!(patchable_function_entry) ), @@ -673,37 +886,37 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ ungated!( feature, CrateLevel, - template!(List: "name1, name2, ..."), DuplicatesOk, EncodeCrossCrate::No, + template!(List: &["name1, name2, ..."]), DuplicatesOk, EncodeCrossCrate::No, ), // DuplicatesOk since it has its own validation ungated!( stable, Normal, - template!(List: r#"feature = "name", since = "version""#), DuplicatesOk, EncodeCrossCrate::No, + template!(List: &[r#"feature = "name", since = "version""#]), DuplicatesOk, EncodeCrossCrate::No, ), ungated!( unstable, Normal, - template!(List: r#"feature = "name", reason = "...", issue = "N""#), DuplicatesOk, + template!(List: &[r#"feature = "name", reason = "...", issue = "N""#]), DuplicatesOk, EncodeCrossCrate::Yes ), ungated!( - unstable_feature_bound, Normal, template!(Word, List: "feat1, feat2, ..."), + unstable_feature_bound, Normal, template!(Word, List: &["feat1, feat2, ..."]), DuplicatesOk, EncodeCrossCrate::No, ), ungated!( - rustc_const_unstable, Normal, template!(List: r#"feature = "name""#), + rustc_const_unstable, Normal, template!(List: &[r#"feature = "name""#]), DuplicatesOk, EncodeCrossCrate::Yes ), ungated!( rustc_const_stable, Normal, - template!(List: r#"feature = "name""#), DuplicatesOk, EncodeCrossCrate::No, + template!(List: &[r#"feature = "name""#]), DuplicatesOk, EncodeCrossCrate::No, ), ungated!( rustc_default_body_unstable, Normal, - template!(List: r#"feature = "name", reason = "...", issue = "N""#), + template!(List: &[r#"feature = "name", reason = "...", issue = "N""#]), DuplicatesOk, EncodeCrossCrate::No ), gated!( - allow_internal_unstable, Normal, template!(Word, List: "feat1, feat2, ..."), + allow_internal_unstable, Normal, template!(Word, List: &["feat1, feat2, ..."]), DuplicatesOk, EncodeCrossCrate::Yes, "allow_internal_unstable side-steps feature gating and stability checks", ), @@ -718,7 +931,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ through unstable paths" ), rustc_attr!( - rustc_deprecated_safe_2024, Normal, template!(List: r#"audit_that = "...""#), + rustc_deprecated_safe_2024, Normal, template!(List: &[r#"audit_that = "...""#]), ErrorFollowing, EncodeCrossCrate::Yes, "`#[rustc_deprecated_safe_2024]` is used to declare functions unsafe across the edition 2024 boundary", ), @@ -743,7 +956,13 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ rustc_attr!( rustc_never_type_options, Normal, - template!(List: r#"/*opt*/ fallback = "unit|niko|never|no""#), + template!(List: &[ + "", + r#"fallback = "unit""#, + r#"fallback = "niko""#, + r#"fallback = "never""#, + r#"fallback = "no""#, + ]), ErrorFollowing, EncodeCrossCrate::No, "`rustc_never_type_options` is used to experiment with never type fallback and work on \ @@ -808,7 +1027,17 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ // ========================================================================== gated!( - linkage, Normal, template!(NameValueStr: "external|internal|..."), + linkage, Normal, template!(NameValueStr: [ + "available_externally", + "common", + "extern_weak", + "external", + "internal", + "linkonce", + "linkonce_odr", + "weak", + "weak_odr", + ], "https://doc.rust-lang.org/reference/linkage.html"), ErrorPreceding, EncodeCrossCrate::No, "the `linkage` attribute is experimental and not portable across platforms", ), @@ -823,7 +1052,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ rustc_attr!( rustc_builtin_macro, Normal, - template!(Word, List: "name, /*opt*/ attributes(name1, name2, ...)"), ErrorFollowing, + template!(Word, List: &["name", "name, /*opt*/ attributes(name1, name2, ...)"]), ErrorFollowing, EncodeCrossCrate::Yes, ), rustc_attr!( @@ -832,12 +1061,12 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ ), rustc_attr!( rustc_macro_transparency, Normal, - template!(NameValueStr: "transparent|semiopaque|opaque"), ErrorFollowing, + template!(NameValueStr: ["transparent", "semiopaque", "opaque"]), ErrorFollowing, EncodeCrossCrate::Yes, "used internally for testing macro hygiene", ), rustc_attr!( rustc_autodiff, Normal, - template!(Word, List: r#""...""#), DuplicatesOk, + template!(Word, List: &[r#""...""#]), DuplicatesOk, EncodeCrossCrate::Yes, ), // Traces that are left when `cfg` and `cfg_attr` attributes are expanded. @@ -860,7 +1089,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ rustc_attr!( rustc_on_unimplemented, Normal, template!( - List: r#"/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...""#, + List: &[r#"/*opt*/ message = "...", /*opt*/ label = "...", /*opt*/ note = "...""#], NameValueStr: "message" ), ErrorFollowing, EncodeCrossCrate::Yes, @@ -868,7 +1097,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ ), rustc_attr!( rustc_confusables, Normal, - template!(List: r#""name1", "name2", ..."#), + template!(List: &[r#""name1", "name2", ..."#]), ErrorFollowing, EncodeCrossCrate::Yes, ), // Enumerates "identity-like" conversion methods to suggest on type mismatch. @@ -909,7 +1138,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ // Used by the `rustc::bad_opt_access` lint on fields // types (as well as any others in future). rustc_attr!( - rustc_lint_opt_deny_field_access, Normal, template!(List: "message"), + rustc_lint_opt_deny_field_access, Normal, template!(List: &["message"]), WarnFollowing, EncodeCrossCrate::Yes, ), @@ -921,7 +1150,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ rustc_promotable, Normal, template!(Word), WarnFollowing, EncodeCrossCrate::No, ), rustc_attr!( - rustc_legacy_const_generics, Normal, template!(List: "N"), ErrorFollowing, + rustc_legacy_const_generics, Normal, template!(List: &["N"]), ErrorFollowing, EncodeCrossCrate::Yes, ), // Do not const-check this function's body. It will always get replaced during CTFE via `hook_special_const_fn`. @@ -946,7 +1175,7 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ ), gated!( rustc_allow_const_fn_unstable, Normal, - template!(Word, List: "feat1, feat2, ..."), DuplicatesOk, EncodeCrossCrate::No, + template!(Word, List: &["feat1, feat2, ..."]), DuplicatesOk, EncodeCrossCrate::No, "rustc_allow_const_fn_unstable side-steps feature gating and stability checks" ), @@ -955,13 +1184,13 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ // ========================================================================== rustc_attr!( - rustc_layout_scalar_valid_range_start, Normal, template!(List: "value"), ErrorFollowing, + rustc_layout_scalar_valid_range_start, Normal, template!(List: &["value"]), ErrorFollowing, EncodeCrossCrate::Yes, "the `#[rustc_layout_scalar_valid_range_start]` attribute is just used to enable \ niche optimizations in the standard library", ), rustc_attr!( - rustc_layout_scalar_valid_range_end, Normal, template!(List: "value"), ErrorFollowing, + rustc_layout_scalar_valid_range_end, Normal, template!(List: &["value"]), ErrorFollowing, EncodeCrossCrate::Yes, "the `#[rustc_layout_scalar_valid_range_end]` attribute is just used to enable \ niche optimizations in the standard library", @@ -1097,14 +1326,14 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ "the `#[rustc_main]` attribute is used internally to specify test entry point function", ), rustc_attr!( - rustc_skip_during_method_dispatch, Normal, template!(List: "array, boxed_slice"), ErrorFollowing, + rustc_skip_during_method_dispatch, Normal, template!(List: &["array, boxed_slice"]), ErrorFollowing, EncodeCrossCrate::No, "the `#[rustc_skip_during_method_dispatch]` attribute is used to exclude a trait \ from method dispatch when the receiver is of the following type, for compatibility in \ editions < 2021 (array) or editions < 2024 (boxed_slice)." ), rustc_attr!( - rustc_must_implement_one_of, Normal, template!(List: "function1, function2, ..."), + rustc_must_implement_one_of, Normal, template!(List: &["function1, function2, ..."]), ErrorFollowing, EncodeCrossCrate::No, "the `#[rustc_must_implement_one_of]` attribute is used to change minimal complete \ definition of a trait. Its syntax and semantics are highly experimental and will be \ @@ -1166,11 +1395,11 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ WarnFollowing, EncodeCrossCrate::No ), rustc_attr!( - TEST, rustc_layout, Normal, template!(List: "field1, field2, ..."), + TEST, rustc_layout, Normal, template!(List: &["field1, field2, ..."]), WarnFollowing, EncodeCrossCrate::Yes ), rustc_attr!( - TEST, rustc_abi, Normal, template!(List: "field1, field2, ..."), + TEST, rustc_abi, Normal, template!(List: &["field1, field2, ..."]), WarnFollowing, EncodeCrossCrate::No ), rustc_attr!( @@ -1191,29 +1420,29 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ EncodeCrossCrate::Yes ), rustc_attr!( - TEST, rustc_if_this_changed, Normal, template!(Word, List: "DepNode"), DuplicatesOk, + TEST, rustc_if_this_changed, Normal, template!(Word, List: &["DepNode"]), DuplicatesOk, EncodeCrossCrate::No ), rustc_attr!( - TEST, rustc_then_this_would_need, Normal, template!(List: "DepNode"), DuplicatesOk, + TEST, rustc_then_this_would_need, Normal, template!(List: &["DepNode"]), DuplicatesOk, EncodeCrossCrate::No ), rustc_attr!( TEST, rustc_clean, Normal, - template!(List: r#"cfg = "...", /*opt*/ label = "...", /*opt*/ except = "...""#), + template!(List: &[r#"cfg = "...", /*opt*/ label = "...", /*opt*/ except = "...""#]), DuplicatesOk, EncodeCrossCrate::No ), rustc_attr!( TEST, rustc_partition_reused, Normal, - template!(List: r#"cfg = "...", module = "...""#), DuplicatesOk, EncodeCrossCrate::No + template!(List: &[r#"cfg = "...", module = "...""#]), DuplicatesOk, EncodeCrossCrate::No ), rustc_attr!( TEST, rustc_partition_codegened, Normal, - template!(List: r#"cfg = "...", module = "...""#), DuplicatesOk, EncodeCrossCrate::No + template!(List: &[r#"cfg = "...", module = "...""#]), DuplicatesOk, EncodeCrossCrate::No ), rustc_attr!( TEST, rustc_expected_cgu_reuse, Normal, - template!(List: r#"cfg = "...", module = "...", kind = "...""#), DuplicatesOk, + template!(List: &[r#"cfg = "...", module = "...", kind = "...""#]), DuplicatesOk, EncodeCrossCrate::No ), rustc_attr!( @@ -1225,11 +1454,11 @@ pub static BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[ WarnFollowing, EncodeCrossCrate::No ), rustc_attr!( - TEST, rustc_mir, Normal, template!(List: "arg1, arg2, ..."), + TEST, rustc_mir, Normal, template!(List: &["arg1, arg2, ..."]), DuplicatesOk, EncodeCrossCrate::Yes ), gated!( - custom_mir, Normal, template!(List: r#"dialect = "...", phase = "...""#), + custom_mir, Normal, template!(List: &[r#"dialect = "...", phase = "...""#]), ErrorFollowing, EncodeCrossCrate::No, "the `#[custom_mir]` attribute is just used for the Rust test suite", ), diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index ae1f57c1ef6..acc21f6c6d2 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -545,7 +545,7 @@ declare_features! ( (incomplete, inherent_associated_types, "1.52.0", Some(8995)), /// Allows using `pointer` and `reference` in intra-doc links (unstable, intra_doc_pointers, "1.51.0", Some(80896)), - // Allows setting the threshold for the `large_assignments` lint. + /// Allows setting the threshold for the `large_assignments` lint. (unstable, large_assignments, "1.52.0", Some(83518)), /// Allow to have type alias types for inter-crate use. (incomplete, lazy_type_alias, "1.72.0", Some(112792)), diff --git a/compiler/rustc_hir/src/attrs/data_structures.rs b/compiler/rustc_hir/src/attrs/data_structures.rs index 5f419315467..e02edf5fe24 100644 --- a/compiler/rustc_hir/src/attrs/data_structures.rs +++ b/compiler/rustc_hir/src/attrs/data_structures.rs @@ -249,6 +249,9 @@ pub enum AttributeKind { /// Represents `#[rustc_allow_incoherent_impl]`. AllowIncoherentImpl(Span), + /// Represents `#[allow_internal_unsafe]`. + AllowInternalUnsafe(Span), + /// Represents `#[allow_internal_unstable]`. AllowInternalUnstable(ThinVec<(Symbol, Span)>, Span), diff --git a/compiler/rustc_hir/src/attrs/encode_cross_crate.rs b/compiler/rustc_hir/src/attrs/encode_cross_crate.rs index e3a7f0b97a8..7ce624dcc55 100644 --- a/compiler/rustc_hir/src/attrs/encode_cross_crate.rs +++ b/compiler/rustc_hir/src/attrs/encode_cross_crate.rs @@ -16,6 +16,7 @@ impl AttributeKind { Align { .. } => No, AllowConstFnUnstable(..) => No, AllowIncoherentImpl(..) => No, + AllowInternalUnsafe(..) => Yes, AllowInternalUnstable(..) => Yes, AsPtr(..) => Yes, AutomaticallyDerived(..) => Yes, diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs index 2201d493f2d..339d4e2eab7 100644 --- a/compiler/rustc_hir/src/def.rs +++ b/compiler/rustc_hir/src/def.rs @@ -306,6 +306,11 @@ impl DefKind { } #[inline] + pub fn is_adt(self) -> bool { + matches!(self, DefKind::Struct | DefKind::Union | DefKind::Enum) + } + + #[inline] pub fn is_fn_like(self) -> bool { matches!( self, @@ -313,6 +318,43 @@ impl DefKind { ) } + /// Whether the corresponding item has generic parameters, ie. the `generics_of` query works. + pub fn has_generics(self) -> bool { + match self { + DefKind::AnonConst + | DefKind::AssocConst + | DefKind::AssocFn + | DefKind::AssocTy + | DefKind::Closure + | DefKind::Const + | DefKind::Ctor(..) + | DefKind::Enum + | DefKind::Field + | DefKind::Fn + | DefKind::ForeignTy + | DefKind::Impl { .. } + | DefKind::InlineConst + | DefKind::OpaqueTy + | DefKind::Static { .. } + | DefKind::Struct + | DefKind::SyntheticCoroutineBody + | DefKind::Trait + | DefKind::TraitAlias + | DefKind::TyAlias + | DefKind::Union + | DefKind::Variant => true, + DefKind::ConstParam + | DefKind::ExternCrate + | DefKind::ForeignMod + | DefKind::GlobalAsm + | DefKind::LifetimeParam + | DefKind::Macro(_) + | DefKind::Mod + | DefKind::TyParam + | DefKind::Use => false, + } + } + /// Whether `query get_codegen_attrs` should be used with this definition. pub fn has_codegen_attrs(self) -> bool { match self { diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 34db6f92d92..b27c223527e 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -1310,6 +1310,7 @@ impl AttributeExt for Attribute { Attribute::Parsed(AttributeKind::Ignore { span, .. }) => *span, Attribute::Parsed(AttributeKind::ShouldPanic { span, .. }) => *span, Attribute::Parsed(AttributeKind::AutomaticallyDerived(span)) => *span, + Attribute::Parsed(AttributeKind::AllowInternalUnsafe(span)) => *span, a => panic!("can't get the span of an arbitrary parsed attribute: {a:?}"), } } @@ -4194,7 +4195,7 @@ impl<'hir> Item<'hir> { expect_trait_alias, (Ident, &'hir Generics<'hir>, GenericBounds<'hir>), ItemKind::TraitAlias(ident, generics, bounds), (*ident, generics, bounds); - expect_impl, &'hir Impl<'hir>, ItemKind::Impl(imp), imp; + expect_impl, &Impl<'hir>, ItemKind::Impl(imp), imp; } } @@ -4372,7 +4373,7 @@ pub enum ItemKind<'hir> { TraitAlias(Ident, &'hir Generics<'hir>, GenericBounds<'hir>), /// An implementation, e.g., `impl<A> Trait for Foo { .. }`. - Impl(&'hir Impl<'hir>), + Impl(Impl<'hir>), } /// Represents an impl block declaration. @@ -4381,6 +4382,14 @@ pub enum ItemKind<'hir> { /// Refer to [`ImplItem`] for an associated item within an impl block. #[derive(Debug, Clone, Copy, HashStable_Generic)] pub struct Impl<'hir> { + pub generics: &'hir Generics<'hir>, + pub of_trait: Option<&'hir TraitImplHeader<'hir>>, + pub self_ty: &'hir Ty<'hir>, + pub items: &'hir [ImplItemId], +} + +#[derive(Debug, Clone, Copy, HashStable_Generic)] +pub struct TraitImplHeader<'hir> { pub constness: Constness, pub safety: Safety, pub polarity: ImplPolarity, @@ -4388,13 +4397,7 @@ pub struct Impl<'hir> { // We do not put a `Span` in `Defaultness` because it breaks foreign crate metadata // decoding as `Span`s cannot be decoded when a `Session` is not available. pub defaultness_span: Option<Span>, - pub generics: &'hir Generics<'hir>, - - /// The trait being implemented, if any. - pub of_trait: Option<TraitRef<'hir>>, - - pub self_ty: &'hir Ty<'hir>, - pub items: &'hir [ImplItemId], + pub trait_ref: TraitRef<'hir>, } impl ItemKind<'_> { @@ -4756,8 +4759,8 @@ impl<'hir> Node<'hir> { /// Get a `hir::Impl` if the node is an impl block for the given `trait_def_id`. pub fn impl_block_of_trait(self, trait_def_id: DefId) -> Option<&'hir Impl<'hir>> { if let Node::Item(Item { kind: ItemKind::Impl(impl_block), .. }) = self - && let Some(trait_ref) = impl_block.of_trait - && let Some(trait_id) = trait_ref.trait_def_id() + && let Some(of_trait) = impl_block.of_trait + && let Some(trait_id) = of_trait.trait_ref.trait_def_id() && trait_id == trait_def_id { Some(impl_block) @@ -4952,7 +4955,7 @@ mod size_asserts { static_assert_size!(GenericArg<'_>, 16); static_assert_size!(GenericBound<'_>, 64); static_assert_size!(Generics<'_>, 56); - static_assert_size!(Impl<'_>, 80); + static_assert_size!(Impl<'_>, 40); static_assert_size!(ImplItem<'_>, 96); static_assert_size!(ImplItemKind<'_>, 40); static_assert_size!(Item<'_>, 88); @@ -4967,6 +4970,7 @@ mod size_asserts { static_assert_size!(Res, 12); static_assert_size!(Stmt<'_>, 32); static_assert_size!(StmtKind<'_>, 16); + static_assert_size!(TraitImplHeader<'_>, 48); static_assert_size!(TraitItem<'_>, 88); static_assert_size!(TraitItemKind<'_>, 48); static_assert_size!(Ty<'_>, 48); diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index 23fa466859a..9b2f8ae75fa 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -590,21 +590,21 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item<'v>) -> V:: try_visit!(visitor.visit_generics(generics)); try_visit!(visitor.visit_enum_def(enum_definition)); } - ItemKind::Impl(Impl { - constness: _, - safety: _, - defaultness: _, - polarity: _, - defaultness_span: _, - generics, - of_trait, - self_ty, - items, - }) => { + ItemKind::Impl(Impl { generics, of_trait, self_ty, items }) => { try_visit!(visitor.visit_generics(generics)); - visit_opt!(visitor, visit_trait_ref, of_trait); + if let Some(TraitImplHeader { + constness: _, + safety: _, + polarity: _, + defaultness: _, + defaultness_span: _, + trait_ref, + }) = of_trait + { + try_visit!(visitor.visit_trait_ref(trait_ref)); + } try_visit!(visitor.visit_ty_unambig(self_ty)); - walk_list!(visitor, visit_impl_item_ref, *items); + walk_list!(visitor, visit_impl_item_ref, items); } ItemKind::Struct(ident, ref generics, ref struct_definition) | ItemKind::Union(ident, ref generics, ref struct_definition) => { diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index a62efed13bc..c642435b989 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -244,48 +244,48 @@ pub(super) fn check_item<'tcx>( // // won't be allowed unless there's an *explicit* implementation of `Send` // for `T` - hir::ItemKind::Impl(impl_) => { - let header = tcx.impl_trait_header(def_id); - let is_auto = header - .is_some_and(|header| tcx.trait_is_auto(header.trait_ref.skip_binder().def_id)); - + hir::ItemKind::Impl(ref impl_) => { crate::impl_wf_check::check_impl_wf(tcx, def_id)?; let mut res = Ok(()); - if let (hir::Defaultness::Default { .. }, true) = (impl_.defaultness, is_auto) { - let sp = impl_.of_trait.as_ref().map_or(item.span, |t| t.path.span); - res = Err(tcx - .dcx() - .struct_span_err(sp, "impls of auto traits cannot be default") - .with_span_labels(impl_.defaultness_span, "default because of this") - .with_span_label(sp, "auto trait") - .emit()); - } - // We match on both `ty::ImplPolarity` and `ast::ImplPolarity` just to get the `!` span. - match header.map(|h| h.polarity) { - // `None` means this is an inherent impl - Some(ty::ImplPolarity::Positive) | None => { - res = res.and(check_impl(tcx, item, impl_.self_ty, &impl_.of_trait)); - } - Some(ty::ImplPolarity::Negative) => { - let ast::ImplPolarity::Negative(span) = impl_.polarity else { - bug!("impl_polarity query disagrees with impl's polarity in HIR"); - }; - // FIXME(#27579): what amount of WF checking do we need for neg impls? - if let hir::Defaultness::Default { .. } = impl_.defaultness { - let mut spans = vec![span]; - spans.extend(impl_.defaultness_span); - res = Err(struct_span_code_err!( - tcx.dcx(), - spans, - E0750, - "negative impls cannot be default impls" - ) + if let Some(of_trait) = impl_.of_trait { + let header = tcx.impl_trait_header(def_id).unwrap(); + let is_auto = tcx.trait_is_auto(header.trait_ref.skip_binder().def_id); + if let (hir::Defaultness::Default { .. }, true) = (of_trait.defaultness, is_auto) { + let sp = of_trait.trait_ref.path.span; + res = Err(tcx + .dcx() + .struct_span_err(sp, "impls of auto traits cannot be default") + .with_span_labels(of_trait.defaultness_span, "default because of this") + .with_span_label(sp, "auto trait") .emit()); - } } - Some(ty::ImplPolarity::Reservation) => { - // FIXME: what amount of WF checking do we need for reservation impls? + match header.polarity { + ty::ImplPolarity::Positive => { + res = res.and(check_impl(tcx, item, impl_)); + } + ty::ImplPolarity::Negative => { + let ast::ImplPolarity::Negative(span) = of_trait.polarity else { + bug!("impl_polarity query disagrees with impl's polarity in HIR"); + }; + // FIXME(#27579): what amount of WF checking do we need for neg impls? + if let hir::Defaultness::Default { .. } = of_trait.defaultness { + let mut spans = vec![span]; + spans.extend(of_trait.defaultness_span); + res = Err(struct_span_code_err!( + tcx.dcx(), + spans, + E0750, + "negative impls cannot be default impls" + ) + .emit()); + } + } + ty::ImplPolarity::Reservation => { + // FIXME: what amount of WF checking do we need for reservation impls? + } } + } else { + res = res.and(check_impl(tcx, item, impl_)); } res } @@ -1258,16 +1258,15 @@ pub(crate) fn check_const_item(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Result<() }) } -#[instrument(level = "debug", skip(tcx, hir_self_ty, hir_trait_ref))] +#[instrument(level = "debug", skip(tcx, impl_))] fn check_impl<'tcx>( tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>, - hir_self_ty: &hir::Ty<'_>, - hir_trait_ref: &Option<hir::TraitRef<'_>>, + impl_: &hir::Impl<'_>, ) -> Result<(), ErrorGuaranteed> { enter_wf_checking_ctxt(tcx, item.owner_id.def_id, |wfcx| { - match hir_trait_ref { - Some(hir_trait_ref) => { + match impl_.of_trait { + Some(of_trait) => { // `#[rustc_reservation_impl]` impls are not real impls and // therefore don't need to be WF (the trait's `Self: Trait` predicate // won't hold). @@ -1275,7 +1274,7 @@ fn check_impl<'tcx>( // Avoid bogus "type annotations needed `Foo: Bar`" errors on `impl Bar for Foo` in case // other `Foo` impls are incoherent. tcx.ensure_ok().coherent_trait(trait_ref.def_id)?; - let trait_span = hir_trait_ref.path.span; + let trait_span = of_trait.trait_ref.path.span; let trait_ref = wfcx.deeply_normalize( trait_span, Some(WellFormedLoc::Ty(item.hir_id().expect_owner().def_id)), @@ -1299,12 +1298,12 @@ fn check_impl<'tcx>( if let Some(pred) = obligation.predicate.as_trait_clause() && pred.skip_binder().self_ty() == trait_ref.self_ty() { - obligation.cause.span = hir_self_ty.span; + obligation.cause.span = impl_.self_ty.span; } if let Some(pred) = obligation.predicate.as_projection_clause() && pred.skip_binder().self_ty() == trait_ref.self_ty() { - obligation.cause.span = hir_self_ty.span; + obligation.cause.span = impl_.self_ty.span; } } @@ -1321,7 +1320,7 @@ fn check_impl<'tcx>( wfcx.register_obligation(Obligation::new( tcx, ObligationCause::new( - hir_self_ty.span, + impl_.self_ty.span, wfcx.body_def_id, ObligationCauseCode::WellFormed(None), ), @@ -1342,7 +1341,7 @@ fn check_impl<'tcx>( self_ty, ); wfcx.register_wf_obligation( - hir_self_ty.span, + impl_.self_ty.span, Some(WellFormedLoc::Ty(item.hir_id().expect_owner().def_id)), self_ty.into(), ); diff --git a/compiler/rustc_hir_analysis/src/coherence/builtin.rs b/compiler/rustc_hir_analysis/src/coherence/builtin.rs index 27948f50a4a..32b175611ce 100644 --- a/compiler/rustc_hir_analysis/src/coherence/builtin.rs +++ b/compiler/rustc_hir_analysis/src/coherence/builtin.rs @@ -531,8 +531,10 @@ pub(crate) fn coerce_unsized_info<'tcx>( })); } else if diff_fields.len() > 1 { let item = tcx.hir_expect_item(impl_did); - let span = if let ItemKind::Impl(hir::Impl { of_trait: Some(t), .. }) = &item.kind { - t.path.span + let span = if let ItemKind::Impl(hir::Impl { of_trait: Some(of_trait), .. }) = + &item.kind + { + of_trait.trait_ref.path.span } else { tcx.def_span(impl_did) }; diff --git a/compiler/rustc_hir_analysis/src/coherence/orphan.rs b/compiler/rustc_hir_analysis/src/coherence/orphan.rs index c75fef9f716..f707196c816 100644 --- a/compiler/rustc_hir_analysis/src/coherence/orphan.rs +++ b/compiler/rustc_hir_analysis/src/coherence/orphan.rs @@ -384,7 +384,7 @@ fn emit_orphan_check_error<'tcx>( traits::OrphanCheckErr::NonLocalInputType(tys) => { let item = tcx.hir_expect_item(impl_def_id); let impl_ = item.expect_impl(); - let hir_trait_ref = impl_.of_trait.as_ref().unwrap(); + let of_trait = impl_.of_trait.unwrap(); let span = tcx.def_span(impl_def_id); let mut diag = tcx.dcx().create_err(match trait_ref.self_ty().kind() { @@ -401,7 +401,7 @@ fn emit_orphan_check_error<'tcx>( impl_.self_ty.span } else { // Point at `C<B>` in `impl<A, B> for C<B> in D<A>` - hir_trait_ref.path.span + of_trait.trait_ref.path.span }; ty = tcx.erase_regions(ty); diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 8ccbfbbb3b4..b72e743f95b 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -1295,18 +1295,22 @@ fn impl_trait_header(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::ImplTrai let icx = ItemCtxt::new(tcx, def_id); let item = tcx.hir_expect_item(def_id); let impl_ = item.expect_impl(); - impl_.of_trait.as_ref().map(|ast_trait_ref| { + let is_rustc_reservation = tcx.has_attr(def_id, sym::rustc_reservation_impl); + if is_rustc_reservation && impl_.of_trait.is_none() { + tcx.dcx().span_err(item.span, "reservation impls can't be inherent"); + } + impl_.of_trait.map(|of_trait| { let selfty = tcx.type_of(def_id).instantiate_identity(); - check_impl_constness(tcx, impl_.constness, ast_trait_ref); + check_impl_constness(tcx, of_trait.constness, &of_trait.trait_ref); - let trait_ref = icx.lowerer().lower_impl_trait_ref(ast_trait_ref, selfty); + let trait_ref = icx.lowerer().lower_impl_trait_ref(&of_trait.trait_ref, selfty); ty::ImplTraitHeader { trait_ref: ty::EarlyBinder::bind(trait_ref), - safety: impl_.safety, - polarity: polarity_of_impl(tcx, def_id, impl_, item.span), - constness: impl_.constness, + safety: of_trait.safety, + polarity: polarity_of_impl(tcx, of_trait, is_rustc_reservation), + constness: of_trait.constness, } }) } @@ -1350,26 +1354,18 @@ fn check_impl_constness( fn polarity_of_impl( tcx: TyCtxt<'_>, - def_id: LocalDefId, - impl_: &hir::Impl<'_>, - span: Span, + of_trait: &hir::TraitImplHeader<'_>, + is_rustc_reservation: bool, ) -> ty::ImplPolarity { - let is_rustc_reservation = tcx.has_attr(def_id, sym::rustc_reservation_impl); - match &impl_ { - hir::Impl { polarity: hir::ImplPolarity::Negative(span), of_trait, .. } => { + match of_trait.polarity { + hir::ImplPolarity::Negative(span) => { if is_rustc_reservation { - let span = span.to(of_trait.as_ref().map_or(*span, |t| t.path.span)); + let span = span.to(of_trait.trait_ref.path.span); tcx.dcx().span_err(span, "reservation impls can't be negative"); } ty::ImplPolarity::Negative } - hir::Impl { polarity: hir::ImplPolarity::Positive, of_trait: None, .. } => { - if is_rustc_reservation { - tcx.dcx().span_err(span, "reservation impls can't be inherent"); - } - ty::ImplPolarity::Positive - } - hir::Impl { polarity: hir::ImplPolarity::Positive, of_trait: Some(_), .. } => { + hir::ImplPolarity::Positive => { if is_rustc_reservation { ty::ImplPolarity::Reservation } else { diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index 8dd13da4fa7..b59dc4bd132 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -158,7 +158,9 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen if let Node::Item(item) = node { match item.kind { ItemKind::Impl(impl_) => { - if impl_.defaultness.is_default() { + if let Some(of_trait) = impl_.of_trait + && of_trait.defaultness.is_default() + { is_default_impl_trait = tcx .impl_trait_ref(def_id) .map(|t| ty::Binder::dummy(t.instantiate_identity())); diff --git a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs index eb3492f5de6..8133f9f6823 100644 --- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs +++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs @@ -604,13 +604,10 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> { #[instrument(level = "debug", skip(self))] fn visit_item(&mut self, item: &'tcx hir::Item<'tcx>) { - match &item.kind { - hir::ItemKind::Impl(hir::Impl { of_trait, .. }) => { - if let Some(of_trait) = of_trait { - self.record_late_bound_vars(of_trait.hir_ref_id, Vec::default()); - } - } - _ => {} + if let hir::ItemKind::Impl(impl_) = item.kind + && let Some(of_trait) = impl_.of_trait + { + self.record_late_bound_vars(of_trait.trait_ref.hir_ref_id, Vec::default()); } match item.kind { hir::ItemKind::Fn { generics, .. } => { @@ -636,7 +633,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> { | hir::ItemKind::Union(_, generics, _) | hir::ItemKind::Trait(_, _, _, _, generics, ..) | hir::ItemKind::TraitAlias(_, generics, ..) - | hir::ItemKind::Impl(&hir::Impl { generics, .. }) => { + | hir::ItemKind::Impl(hir::Impl { generics, .. }) => { // These kinds of items have only early-bound lifetime parameters. self.visit_early(item.hir_id(), generics, |this| intravisit::walk_item(this, item)); } @@ -2106,7 +2103,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> { // If we have a self type alias (in an impl), try to resolve an // associated item from one of the supertraits of the impl's trait. Res::SelfTyAlias { alias_to: impl_def_id, is_trait_impl: true, .. } => { - let hir::ItemKind::Impl(hir::Impl { of_trait: Some(trait_ref), .. }) = self + let hir::ItemKind::Impl(hir::Impl { of_trait: Some(of_trait), .. }) = self .tcx .hir_node_by_def_id(impl_def_id.expect_local()) .expect_item() @@ -2114,7 +2111,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> { else { return; }; - let Some(trait_def_id) = trait_ref.trait_def_id() else { + let Some(trait_def_id) = of_trait.trait_ref.trait_def_id() else { return; }; let Some((bound_vars, assoc_item)) = BoundVarContext::supertrait_hrtb_vars( diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index 22fb02714dd..62125c99d80 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -251,7 +251,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_ .emit_err(crate::errors::SelfInImplSelf { span: spans.into(), note: () }); Ty::new_error(tcx, guar) } - _ => icx.lower_ty(*self_ty), + _ => icx.lower_ty(self_ty), }, ItemKind::Fn { .. } => { let args = ty::GenericArgs::identity_for_item(tcx, def_id); diff --git a/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs b/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs index 835f8e8cdae..8a9f9130fea 100644 --- a/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs +++ b/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs @@ -147,7 +147,11 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { let hir::Node::Item(hir::Item { kind: hir::ItemKind::Impl(hir::Impl { - of_trait: Some(hir::TraitRef { hir_ref_id: id_in_of_trait, .. }), + of_trait: + Some(hir::TraitImplHeader { + trait_ref: hir::TraitRef { hir_ref_id: id_in_of_trait, .. }, + .. + }), .. }), .. diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs index 386e1091ac4..d14aef8ace4 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs @@ -199,12 +199,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { // However, this can easily get out of sync! Ideally, we would perform this step // where we are guaranteed to catch *all* bounds like in // `Self::lower_poly_trait_ref`. List of concrete issues: - // FIXME(more_maybe_bounds): We don't call this for e.g., trait object tys or - // supertrait bounds! + // FIXME(more_maybe_bounds): We don't call this for trait object tys, supertrait + // bounds or associated type bounds (ATB)! // FIXME(trait_alias, #143122): We don't call it for the RHS. Arguably however, - // AST lowering should reject them outright. - // FIXME(associated_type_bounds): We don't call this for them. However, AST - // lowering should reject them outright (#135229). + // AST lowering should reject them outright. let bounds = collect_relaxed_bounds(hir_bounds, self_ty_where_predicates); self.check_and_report_invalid_relaxed_bounds(bounds); } diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs index 646ff3ca08d..56998b5b53c 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/lint.rs @@ -200,7 +200,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { }) = tcx.hir_node_by_def_id(parent_id) && self_ty.hir_id == impl_self_ty.hir_id { - let Some(of_trait_ref) = of_trait else { + let Some(of_trait) = of_trait else { diag.span_suggestion_verbose( impl_self_ty.span.shrink_to_hi(), "you might have intended to implement this trait for a given type", @@ -209,10 +209,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { ); return; }; - if !of_trait_ref.trait_def_id().is_some_and(|def_id| def_id.is_local()) { + if !of_trait.trait_ref.trait_def_id().is_some_and(|def_id| def_id.is_local()) { return; } - let of_trait_span = of_trait_ref.path.span; + let of_trait_span = of_trait.trait_ref.path.span; // make sure that we are not calling unwrap to abort during the compilation let Ok(of_trait_name) = tcx.sess.source_map().span_to_snippet(of_trait_span) else { return; diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index 1675aecd2b8..c7b984d9b25 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -2732,7 +2732,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { }; let i = tcx.parent_hir_node(fn_hir_id).expect_item().expect_impl(); - let trait_ref = self.lower_impl_trait_ref(i.of_trait.as_ref()?, self.lower_ty(i.self_ty)); + let trait_ref = self.lower_impl_trait_ref(&i.of_trait?.trait_ref, self.lower_ty(i.self_ty)); let assoc = tcx.associated_items(trait_ref.def_id).find_by_ident_and_kind( tcx, diff --git a/compiler/rustc_hir_analysis/src/hir_wf_check.rs b/compiler/rustc_hir_analysis/src/hir_wf_check.rs index 3fddaee8cef..d8578970adc 100644 --- a/compiler/rustc_hir_analysis/src/hir_wf_check.rs +++ b/compiler/rustc_hir_analysis/src/hir_wf_check.rs @@ -154,8 +154,9 @@ pub(super) fn diagnostic_hir_wf_check<'tcx>( hir::ItemKind::TyAlias(_, _, ty) | hir::ItemKind::Static(_, _, ty, _) | hir::ItemKind::Const(_, _, ty, _) => vec![ty], - hir::ItemKind::Impl(impl_) => match &impl_.of_trait { - Some(t) => t + hir::ItemKind::Impl(impl_) => match impl_.of_trait { + Some(of_trait) => of_trait + .trait_ref .path .segments .last() diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index 235eec96d74..be5859b57c5 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -690,39 +690,44 @@ impl<'a> State<'a> { let (cb, ib) = self.head("union"); self.print_struct(ident.name, generics, struct_def, item.span, true, cb, ib); } - hir::ItemKind::Impl(&hir::Impl { - constness, - safety, - polarity, - defaultness, - defaultness_span: _, - generics, - ref of_trait, - self_ty, - items, - }) => { + hir::ItemKind::Impl(hir::Impl { generics, of_trait, self_ty, items }) => { let (cb, ib) = self.head(""); - self.print_defaultness(defaultness); - self.print_safety(safety); - self.word_nbsp("impl"); - if let hir::Constness::Const = constness { - self.word_nbsp("const"); - } + let impl_generics = |this: &mut Self| { + this.word_nbsp("impl"); + if !generics.params.is_empty() { + this.print_generic_params(generics.params); + this.space(); + } + }; - if !generics.params.is_empty() { - self.print_generic_params(generics.params); - self.space(); - } + match of_trait { + None => impl_generics(self), + Some(&hir::TraitImplHeader { + constness, + safety, + polarity, + defaultness, + defaultness_span: _, + ref trait_ref, + }) => { + self.print_defaultness(defaultness); + self.print_safety(safety); + + impl_generics(self); + + if let hir::Constness::Const = constness { + self.word_nbsp("const"); + } - if let hir::ImplPolarity::Negative(_) = polarity { - self.word("!"); - } + if let hir::ImplPolarity::Negative(_) = polarity { + self.word("!"); + } - if let Some(t) = of_trait { - self.print_trait_ref(t); - self.space(); - self.word_space("for"); + self.print_trait_ref(trait_ref); + self.space(); + self.word_space("for"); + } } self.print_type(self_ty); diff --git a/compiler/rustc_hir_typeck/src/demand.rs b/compiler/rustc_hir_typeck/src/demand.rs index e5684f8cbe6..fb6ebe066a8 100644 --- a/compiler/rustc_hir_typeck/src/demand.rs +++ b/compiler/rustc_hir_typeck/src/demand.rs @@ -698,7 +698,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ) { match (self.tcx.parent_hir_node(expr.hir_id), error) { (hir::Node::LetStmt(hir::LetStmt { ty: Some(ty), init: Some(init), .. }), _) - if init.hir_id == expr.hir_id => + if init.hir_id == expr.hir_id && !ty.span.source_equal(init.span) => { // Point at `let` assignment type. err.span_label(ty.span, "expected due to this"); diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 36abd7c8555..b80a2af3100 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -1589,26 +1589,64 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // e.g. `reuse HasSelf::method;` should suggest `reuse HasSelf::method($args);`. full_call_span.shrink_to_hi() }; + + // Controls how the arguments should be listed in the suggestion. + enum ArgumentsFormatting { + SingleLine, + Multiline { fallback_indent: String, brace_indent: String }, + } + let arguments_formatting = { + let mut provided_inputs = matched_inputs.iter().filter_map(|a| *a); + if let Some(brace_indent) = source_map.indentation_before(suggestion_span) + && let Some(first_idx) = provided_inputs.by_ref().next() + && let Some(last_idx) = provided_inputs.by_ref().next() + && let (_, first_span) = provided_arg_tys[first_idx] + && let (_, last_span) = provided_arg_tys[last_idx] + && source_map.is_multiline(first_span.to(last_span)) + && let Some(fallback_indent) = source_map.indentation_before(first_span) + { + ArgumentsFormatting::Multiline { fallback_indent, brace_indent } + } else { + ArgumentsFormatting::SingleLine + } + }; + let mut suggestion = "(".to_owned(); let mut needs_comma = false; for (expected_idx, provided_idx) in matched_inputs.iter_enumerated() { if needs_comma { - suggestion += ", "; - } else { - needs_comma = true; + suggestion += ","; + } + match &arguments_formatting { + ArgumentsFormatting::SingleLine if needs_comma => suggestion += " ", + ArgumentsFormatting::SingleLine => {} + ArgumentsFormatting::Multiline { .. } => suggestion += "\n", } - let suggestion_text = if let Some(provided_idx) = provided_idx + needs_comma = true; + let (suggestion_span, suggestion_text) = if let Some(provided_idx) = provided_idx && let (_, provided_span) = provided_arg_tys[*provided_idx] && let Ok(arg_text) = source_map.span_to_snippet(provided_span) { - arg_text + (Some(provided_span), arg_text) } else { // Propose a placeholder of the correct type let (_, expected_ty) = formal_and_expected_inputs[expected_idx]; - ty_to_snippet(expected_ty, expected_idx) + (None, ty_to_snippet(expected_ty, expected_idx)) }; + if let ArgumentsFormatting::Multiline { fallback_indent, .. } = + &arguments_formatting + { + let indent = suggestion_span + .and_then(|span| source_map.indentation_before(span)) + .unwrap_or_else(|| fallback_indent.clone()); + suggestion += &indent; + } suggestion += &suggestion_text; } + if let ArgumentsFormatting::Multiline { brace_indent, .. } = arguments_formatting { + suggestion += ",\n"; + suggestion += &brace_indent; + } suggestion += ")"; err.span_suggestion_verbose( suggestion_span, diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs index 2345cdab208..6013430e1ff 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs @@ -936,7 +936,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { Node::ImplItem(item) => { // If it doesn't impl a trait, we can add a return type let Node::Item(&hir::Item { - kind: hir::ItemKind::Impl(&hir::Impl { of_trait, .. }), + kind: hir::ItemKind::Impl(hir::Impl { of_trait, .. }), .. }) = self.tcx.parent_hir_node(item.hir_id()) else { diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index f7430f7af4e..824d592fa6c 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -1103,7 +1103,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self_ty.span.ctxt().outer_expn_data().kind, ExpnKind::Macro(MacroKind::Derive, _) ) || matches!( - of_trait.as_ref().map(|t| t.path.span.ctxt().outer_expn_data().kind), + of_trait.map(|t| t.trait_ref.path.span.ctxt().outer_expn_data().kind), Some(ExpnKind::Macro(MacroKind::Derive, _)) ) => { @@ -1165,13 +1165,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { entry.0.insert(cause_span); entry.1.insert((cause_span, "unsatisfied trait bound introduced here")); } else { - if let Some(trait_ref) = of_trait { - entry.0.insert(trait_ref.path.span); + if let Some(of_trait) = of_trait { + entry.0.insert(of_trait.trait_ref.path.span); } entry.0.insert(self_ty.span); }; - if let Some(trait_ref) = of_trait { - entry.1.insert((trait_ref.path.span, "")); + if let Some(of_trait) = of_trait { + entry.1.insert((of_trait.trait_ref.path.span, "")); } entry.1.insert((self_ty.span, "")); } diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index bf4611e1e34..7dc736e5e6b 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -1756,7 +1756,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let missing_parentheses = match (expected.kind(), fields, had_err) { // #67037: only do this if we could successfully type-check the expected type against // the tuple struct pattern. Otherwise the args could get out of range on e.g., - // `let P() = U;` where `P != U` with `struct P<T>(T);`. + // `let P() = U;` where `P != U` with `struct Box<T>(T);`. (ty::Adt(_, args), [field], Ok(())) => { let field_ty = self.field_ty(pat_span, field, args); match field_ty.kind() { diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index a2afdc45fa8..82d4856df39 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -485,17 +485,6 @@ pub enum NllRegionVariableOrigin { Existential { name: Option<Symbol>, - /// If this is true, then this variable was created to represent a lifetime - /// bound in a `for` binder. For example, it might have been created to - /// represent the lifetime `'a` in a type like `for<'a> fn(&'a u32)`. - /// Such variables are created when we are trying to figure out if there - /// is any valid instantiation of `'a` that could fit into some scenario. - /// - /// This is used to inform error reporting: in the case that we are trying to - /// determine whether there is any valid instantiation of a `'a` variable that meets - /// some constraint C, we want to blame the "source" of that `for` type, - /// rather than blaming the source of the constraint C. - from_forall: bool, }, } diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index 8bbd0e61492..3ba224723e3 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -108,7 +108,7 @@ impl LintStoreExpand for LintStoreExpandImpl<'_> { registered_tools: &RegisteredTools, node_id: ast::NodeId, attrs: &[ast::Attribute], - items: &[rustc_ast::ptr::P<ast::Item>], + items: &[Box<ast::Item>], name: Symbol, ) { pre_expansion_lint(sess, features, self.0, registered_tools, (node_id, attrs, items), name); diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl index 6a47e236047..c485e6fc849 100644 --- a/compiler/rustc_lint/messages.ftl +++ b/compiler/rustc_lint/messages.ftl @@ -349,6 +349,7 @@ lint_ill_formed_attribute_input = {$num_suggestions -> [1] attribute must be of the form {$suggestions} *[other] valid forms for the attribute are {$suggestions} } + .note = for more information, visit <{$docs}> lint_impl_trait_overcaptures = `{$self_ty}` will capture more lifetimes than possibly intended in edition 2024 .note = specifically, {$num_captured -> diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index c893b723375..8006cfcf30f 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -21,6 +21,7 @@ use rustc_ast::tokenstream::{TokenStream, TokenTree}; use rustc_ast::visit::{FnCtxt, FnKind}; use rustc_ast::{self as ast, *}; use rustc_ast_pretty::pprust::expr_to_string; +use rustc_attr_parsing::AttributeParser; use rustc_errors::{Applicability, LintDiagnostic}; use rustc_feature::GateIssue; use rustc_hir as hir; @@ -248,12 +249,6 @@ impl UnsafeCode { } impl EarlyLintPass for UnsafeCode { - fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &ast::Attribute) { - if attr.has_name(sym::allow_internal_unsafe) { - self.report_unsafe(cx, attr.span, BuiltinUnsafe::AllowInternalUnsafe); - } - } - #[inline] fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) { if let ast::ExprKind::Block(ref blk, _) = e.kind { @@ -270,7 +265,10 @@ impl EarlyLintPass for UnsafeCode { self.report_unsafe(cx, it.span, BuiltinUnsafe::UnsafeTrait); } - ast::ItemKind::Impl(box ast::Impl { safety: ast::Safety::Unsafe(_), .. }) => { + ast::ItemKind::Impl(ast::Impl { + of_trait: Some(box ast::TraitImplHeader { safety: ast::Safety::Unsafe(_), .. }), + .. + }) => { self.report_unsafe(cx, it.span, BuiltinUnsafe::UnsafeImpl); } @@ -312,6 +310,19 @@ impl EarlyLintPass for UnsafeCode { } } + ast::ItemKind::MacroDef(..) => { + if let Some(attr) = AttributeParser::parse_limited( + cx.builder.sess(), + &it.attrs, + sym::allow_internal_unsafe, + it.span, + DUMMY_NODE_ID, + Some(cx.builder.features()), + ) { + self.report_unsafe(cx, attr.span(), BuiltinUnsafe::AllowInternalUnsafe); + } + } + _ => {} } } diff --git a/compiler/rustc_lint/src/deref_into_dyn_supertrait.rs b/compiler/rustc_lint/src/deref_into_dyn_supertrait.rs index dd16117db1c..943fcc0801b 100644 --- a/compiler/rustc_lint/src/deref_into_dyn_supertrait.rs +++ b/compiler/rustc_lint/src/deref_into_dyn_supertrait.rs @@ -61,8 +61,8 @@ impl<'tcx> LateLintPass<'tcx> for DerefIntoDynSupertrait { // `Deref` is being implemented for `t` if let hir::ItemKind::Impl(impl_) = item.kind // the trait is a `Deref` implementation - && let Some(trait_) = &impl_.of_trait - && let Some(did) = trait_.trait_def_id() + && let Some(of_trait) = &impl_.of_trait + && let Some(did) = of_trait.trait_ref.trait_def_id() && tcx.is_lang_item(did, LangItem::Deref) // the self type is `dyn t_principal` && let self_ty = tcx.type_of(item.owner_id).instantiate_identity() diff --git a/compiler/rustc_lint/src/early.rs b/compiler/rustc_lint/src/early.rs index 48e3bbb79fa..58205087def 100644 --- a/compiler/rustc_lint/src/early.rs +++ b/compiler/rustc_lint/src/early.rs @@ -4,7 +4,6 @@ //! resolution, just before AST lowering. These lints are for purely //! syntactical lints. -use rustc_ast::ptr::P; use rustc_ast::visit::{self as ast_visit, Visitor, walk_list}; use rustc_ast::{self as ast, HasAttrs}; use rustc_data_structures::stack::ensure_sufficient_stack; @@ -297,7 +296,7 @@ impl<'a> EarlyCheckNode<'a> for (&'a ast::Crate, &'a [ast::Attribute]) { } } -impl<'a> EarlyCheckNode<'a> for (ast::NodeId, &'a [ast::Attribute], &'a [P<ast::Item>]) { +impl<'a> EarlyCheckNode<'a> for (ast::NodeId, &'a [ast::Attribute], &'a [Box<ast::Item>]) { fn id(self) -> ast::NodeId { self.0 } diff --git a/compiler/rustc_lint/src/early/diagnostics.rs b/compiler/rustc_lint/src/early/diagnostics.rs index 59e806e56d1..678d3d1f8ed 100644 --- a/compiler/rustc_lint/src/early/diagnostics.rs +++ b/compiler/rustc_lint/src/early/diagnostics.rs @@ -453,12 +453,14 @@ pub fn decorate_builtin_lint( BuiltinLintDiag::UnusedCrateDependency { extern_crate, local_crate } => { lints::UnusedCrateDependency { extern_crate, local_crate }.decorate_lint(diag) } - BuiltinLintDiag::IllFormedAttributeInput { suggestions } => { + BuiltinLintDiag::IllFormedAttributeInput { suggestions, docs } => { lints::IllFormedAttributeInput { num_suggestions: suggestions.len(), suggestions: DiagArgValue::StrListSepByAnd( suggestions.into_iter().map(|s| format!("`{s}`").into()).collect(), ), + has_docs: docs.is_some(), + docs: docs.unwrap_or(""), } .decorate_lint(diag) } diff --git a/compiler/rustc_lint/src/internal.rs b/compiler/rustc_lint/src/internal.rs index 7dafcc199a3..016ff17f5d7 100644 --- a/compiler/rustc_lint/src/internal.rs +++ b/compiler/rustc_lint/src/internal.rs @@ -411,11 +411,11 @@ declare_lint_pass!(LintPassImpl => [LINT_PASS_IMPL_WITHOUT_MACRO]); impl EarlyLintPass for LintPassImpl { fn check_item(&mut self, cx: &EarlyContext<'_>, item: &ast::Item) { - if let ast::ItemKind::Impl(box ast::Impl { of_trait: Some(lint_pass), .. }) = &item.kind - && let Some(last) = lint_pass.path.segments.last() + if let ast::ItemKind::Impl(ast::Impl { of_trait: Some(of_trait), .. }) = &item.kind + && let Some(last) = of_trait.trait_ref.path.segments.last() && last.ident.name == sym::LintPass { - let expn_data = lint_pass.path.span.ctxt().outer_expn_data(); + let expn_data = of_trait.trait_ref.path.span.ctxt().outer_expn_data(); let call_site = expn_data.call_site; if expn_data.kind != ExpnKind::Macro(MacroKind::Bang, sym::impl_lint_pass) && call_site.ctxt().outer_expn_data().kind @@ -423,7 +423,7 @@ impl EarlyLintPass for LintPassImpl { { cx.emit_span_lint( LINT_PASS_IMPL_WITHOUT_MACRO, - lint_pass.path.span, + of_trait.trait_ref.path.span, LintPassByHand, ); } @@ -582,8 +582,8 @@ impl Diagnostics { for (_hir_id, parent) in cx.tcx.hir_parent_iter(current_id) { debug!(?parent); if let hir::Node::Item(hir::Item { kind: hir::ItemKind::Impl(impl_), .. }) = parent - && let hir::Impl { of_trait: Some(of_trait), .. } = impl_ - && let Some(def_id) = of_trait.trait_def_id() + && let Some(of_trait) = impl_.of_trait + && let Some(def_id) = of_trait.trait_ref.trait_def_id() && let Some(name) = cx.tcx.get_diagnostic_name(def_id) && matches!(name, sym::Diagnostic | sym::Subdiagnostic | sym::LintDiagnostic) { diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index f1d3d0d19da..a6d59af6900 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -2685,6 +2685,9 @@ pub(crate) struct UnusedCrateDependency { pub(crate) struct IllFormedAttributeInput { pub num_suggestions: usize, pub suggestions: DiagArgValue, + #[note] + pub has_docs: bool, + pub docs: &'static str, } #[derive(LintDiagnostic)] diff --git a/compiler/rustc_lint/src/non_local_def.rs b/compiler/rustc_lint/src/non_local_def.rs index b877f909fc0..2dd3425e66c 100644 --- a/compiler/rustc_lint/src/non_local_def.rs +++ b/compiler/rustc_lint/src/non_local_def.rs @@ -129,8 +129,8 @@ impl<'tcx> LateLintPass<'tcx> for NonLocalDefinitions { // of the `impl` definition let mut collector = PathCollector { paths: Vec::new() }; collector.visit_ty_unambig(&impl_.self_ty); - if let Some(of_trait) = &impl_.of_trait { - collector.visit_trait_ref(of_trait); + if let Some(of_trait) = impl_.of_trait { + collector.visit_trait_ref(&of_trait.trait_ref); } // 1.5. Remove any path that doesn't resolve to a `DefId` or if it resolve to a diff --git a/compiler/rustc_lint/src/nonstandard_style.rs b/compiler/rustc_lint/src/nonstandard_style.rs index 7e5f43ba77f..8fafaa33d0c 100644 --- a/compiler/rustc_lint/src/nonstandard_style.rs +++ b/compiler/rustc_lint/src/nonstandard_style.rs @@ -187,7 +187,7 @@ impl EarlyLintPass for NonCamelCaseTypes { // N.B. This check is only for inherent associated types, so that we don't lint against // trait impls where we should have warned for the trait definition already. - ast::ItemKind::Impl(box ast::Impl { of_trait: None, items, .. }) => { + ast::ItemKind::Impl(ast::Impl { of_trait: None, items, .. }) => { for it in items { // FIXME: this doesn't respect `#[allow(..)]` on the item itself. if let ast::AssocItemKind::Type(alias) = &it.kind { diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index e660b950262..bee80335f74 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -217,6 +217,7 @@ declare_lint! { @future_incompatible = FutureIncompatibleInfo { reason: FutureIncompatibilityReason::FutureReleaseError, reference: "issue #57571 <https://github.com/rust-lang/rust/issues/57571>", + report_in_deps: true, }; crate_level_only } diff --git a/compiler/rustc_lint_defs/src/lib.rs b/compiler/rustc_lint_defs/src/lib.rs index 7bd6078fa10..3bb7bbce567 100644 --- a/compiler/rustc_lint_defs/src/lib.rs +++ b/compiler/rustc_lint_defs/src/lib.rs @@ -794,6 +794,7 @@ pub enum BuiltinLintDiag { }, IllFormedAttributeInput { suggestions: Vec<String>, + docs: Option<&'static str>, }, InnerAttributeUnstable { is_macro: bool, diff --git a/compiler/rustc_llvm/build.rs b/compiler/rustc_llvm/build.rs index 6c740156c4d..1394edcee6b 100644 --- a/compiler/rustc_llvm/build.rs +++ b/compiler/rustc_llvm/build.rs @@ -255,7 +255,7 @@ fn main() { println!("cargo:rustc-link-lib=kstat"); } - if (target.starts_with("arm") && !target.contains("freebsd")) && !target.contains("ohos") + if (target.starts_with("arm") && !target.contains("freebsd") && !target.contains("ohos")) || target.starts_with("mips-") || target.starts_with("mipsel-") || target.starts_with("powerpc-") diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 00c97a2f738..548c56a97bc 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -1530,7 +1530,7 @@ impl<'a> CrateMetadataRef<'a> { let macro_rules = self.root.tables.is_macro_rules.get(self, id); let body = self.root.tables.macro_definition.get(self, id).unwrap().decode((self, sess)); - ast::MacroDef { macro_rules, body: ast::ptr::P(body) } + ast::MacroDef { macro_rules, body: Box::new(body) } } _ => bug!(), } diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index df95ed602cd..11fef3be5d0 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -395,6 +395,7 @@ provide! { tcx, def_id, other, cdata, crate_extern_paths => { cdata.source().paths().cloned().collect() } expn_that_defined => { cdata.get_expn_that_defined(def_id.index, tcx.sess) } + default_field => { cdata.get_default_field(def_id.index) } is_doc_hidden => { cdata.get_attr_flags(def_id.index).contains(AttrFlags::IS_DOC_HIDDEN) } doc_link_resolutions => { tcx.arena.alloc(cdata.get_doc_link_resolutions(def_id.index)) } doc_link_traits_in_scope => { diff --git a/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs b/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs index 94384e64afd..52341df0740 100644 --- a/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs +++ b/compiler/rustc_middle/src/middle/codegen_fn_attrs.rs @@ -3,6 +3,7 @@ use std::borrow::Cow; use rustc_abi::Align; use rustc_ast::expand::autodiff_attrs::AutoDiffAttrs; use rustc_hir::attrs::{InlineAttr, InstructionSetAttr, OptimizeAttr}; +use rustc_hir::def_id::DefId; use rustc_macros::{HashStable, TyDecodable, TyEncodable}; use rustc_span::Symbol; use rustc_target::spec::SanitizerSet; @@ -193,7 +194,11 @@ impl CodegenFnAttrs { /// * `#[linkage]` is present /// /// Keep this in sync with the logic for the unused_attributes for `#[inline]` lint. - pub fn contains_extern_indicator(&self) -> bool { + pub fn contains_extern_indicator(&self, tcx: TyCtxt<'_>, did: DefId) -> bool { + if tcx.is_foreign_item(did) { + return false; + } + self.flags.contains(CodegenFnAttrFlags::NO_MANGLE) || self.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL) || self.export_name.is_some() diff --git a/compiler/rustc_middle/src/mir/mono.rs b/compiler/rustc_middle/src/mir/mono.rs index e5864660575..3afd946b30a 100644 --- a/compiler/rustc_middle/src/mir/mono.rs +++ b/compiler/rustc_middle/src/mir/mono.rs @@ -151,7 +151,7 @@ impl<'tcx> MonoItem<'tcx> { // instantiation: // We emit an unused_attributes lint for this case, which should be kept in sync if possible. let codegen_fn_attrs = tcx.codegen_instance_attrs(instance.def); - if codegen_fn_attrs.contains_extern_indicator() + if codegen_fn_attrs.contains_extern_indicator(tcx, instance.def.def_id()) || codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::NAKED) { return InstantiationMode::GloballyShared { may_conflict: false }; diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index a4589576594..f4d0120a2e7 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1864,6 +1864,12 @@ rustc_queries! { feedable } + /// Returns whether the field corresponding to the `DefId` has a default field value. + query default_field(def_id: DefId) -> Option<DefId> { + desc { |tcx| "looking up the `const` corresponding to the default for `{}`", tcx.def_path_str(def_id) } + separate_provide_extern + } + query check_well_formed(key: LocalDefId) -> Result<(), ErrorGuaranteed> { desc { |tcx| "checking that `{}` is well-formed", tcx.def_path_str(key) } return_result_from_ensure_ok diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index db56082c71a..49a4733de3b 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -290,11 +290,8 @@ impl<'tcx> Interner for TyCtxt<'tcx> { debug_assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::AssocConst); let trait_def_id = self.parent(def_id); debug_assert_matches!(self.def_kind(trait_def_id), DefKind::Trait); - let trait_generics = self.generics_of(trait_def_id); - ( - ty::TraitRef::new_from_args(self, trait_def_id, args.truncate_to(self, trait_generics)), - &args[trait_generics.count()..], - ) + let trait_ref = ty::TraitRef::from_assoc(self, trait_def_id, args); + (trait_ref, &args[trait_ref.args.len()..]) } fn mk_args(self, args: &[Self::GenericArg]) -> ty::GenericArgsRef<'tcx> { diff --git a/compiler/rustc_middle/src/ty/generic_args.rs b/compiler/rustc_middle/src/ty/generic_args.rs index 648709e88e6..3ade3a3ef51 100644 --- a/compiler/rustc_middle/src/ty/generic_args.rs +++ b/compiler/rustc_middle/src/ty/generic_args.rs @@ -585,6 +585,9 @@ impl<'tcx> GenericArgs<'tcx> { tcx.mk_args_from_iter(target_args.iter().chain(self.iter().skip(defs.count()))) } + /// Truncates this list of generic args to have at most the number of args in `generics`. + /// + /// You might be looking for [`TraitRef::from_assoc`](super::TraitRef::from_assoc). pub fn truncate_to(&self, tcx: TyCtxt<'tcx>, generics: &ty::Generics) -> GenericArgsRef<'tcx> { tcx.mk_args(&self[..generics.count()]) } diff --git a/compiler/rustc_mir_transform/src/cross_crate_inline.rs b/compiler/rustc_mir_transform/src/cross_crate_inline.rs index b186c2bd775..03fdf9fbac5 100644 --- a/compiler/rustc_mir_transform/src/cross_crate_inline.rs +++ b/compiler/rustc_mir_transform/src/cross_crate_inline.rs @@ -18,7 +18,7 @@ fn cross_crate_inlinable(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { let codegen_fn_attrs = tcx.codegen_fn_attrs(def_id); // If this has an extern indicator, then this function is globally shared and thus will not // generate cgu-internal copies which would make it cross-crate inlinable. - if codegen_fn_attrs.contains_extern_indicator() { + if codegen_fn_attrs.contains_extern_indicator(tcx, def_id.into()) { return false; } diff --git a/compiler/rustc_next_trait_solver/src/solve/inspect/build.rs b/compiler/rustc_next_trait_solver/src/solve/inspect/build.rs index c8521624ebb..fc56b006d94 100644 --- a/compiler/rustc_next_trait_solver/src/solve/inspect/build.rs +++ b/compiler/rustc_next_trait_solver/src/solve/inspect/build.rs @@ -68,7 +68,7 @@ impl<I: Interner> From<WipCanonicalGoalEvaluationStep<I>> for DebugSolver<I> { } } -#[derive_where(PartialEq, Eq, Debug; I: Interner)] +#[derive_where(PartialEq, Debug; I: Interner)] struct WipGoalEvaluation<I: Interner> { pub uncanonicalized_goal: Goal<I, I::Predicate>, pub orig_values: Vec<I::GenericArg>, @@ -78,6 +78,8 @@ struct WipGoalEvaluation<I: Interner> { pub result: Option<QueryResult<I>>, } +impl<I: Interner> Eq for WipGoalEvaluation<I> {} + impl<I: Interner> WipGoalEvaluation<I> { fn finalize(self) -> inspect::GoalEvaluation<I> { inspect::GoalEvaluation { @@ -98,7 +100,7 @@ impl<I: Interner> WipGoalEvaluation<I> { /// This only exists during proof tree building and does not have /// a corresponding struct in `inspect`. We need this to track a /// bunch of metadata about the current evaluation. -#[derive_where(PartialEq, Eq, Debug; I: Interner)] +#[derive_where(PartialEq, Debug; I: Interner)] struct WipCanonicalGoalEvaluationStep<I: Interner> { /// Unlike `EvalCtxt::var_values`, we append a new /// generic arg here whenever we create a new inference @@ -111,6 +113,8 @@ struct WipCanonicalGoalEvaluationStep<I: Interner> { evaluation: WipProbe<I>, } +impl<I: Interner> Eq for WipCanonicalGoalEvaluationStep<I> {} + impl<I: Interner> WipCanonicalGoalEvaluationStep<I> { fn current_evaluation_scope(&mut self) -> &mut WipProbe<I> { let mut current = &mut self.evaluation; @@ -132,7 +136,7 @@ impl<I: Interner> WipCanonicalGoalEvaluationStep<I> { } } -#[derive_where(PartialEq, Eq, Debug; I: Interner)] +#[derive_where(PartialEq, Debug; I: Interner)] struct WipProbe<I: Interner> { initial_num_var_values: usize, steps: Vec<WipProbeStep<I>>, @@ -140,6 +144,8 @@ struct WipProbe<I: Interner> { final_state: Option<inspect::CanonicalState<I, ()>>, } +impl<I: Interner> Eq for WipProbe<I> {} + impl<I: Interner> WipProbe<I> { fn finalize(self) -> inspect::Probe<I> { inspect::Probe { @@ -150,7 +156,7 @@ impl<I: Interner> WipProbe<I> { } } -#[derive_where(PartialEq, Eq, Debug; I: Interner)] +#[derive_where(PartialEq, Debug; I: Interner)] enum WipProbeStep<I: Interner> { AddGoal(GoalSource, inspect::CanonicalState<I, Goal<I, I::Predicate>>), NestedProbe(WipProbe<I>), @@ -158,6 +164,8 @@ enum WipProbeStep<I: Interner> { RecordImplArgs { impl_args: inspect::CanonicalState<I, I::GenericArgs> }, } +impl<I: Interner> Eq for WipProbeStep<I> {} + impl<I: Interner> WipProbeStep<I> { fn finalize(self) -> inspect::ProbeStep<I> { match self { diff --git a/compiler/rustc_next_trait_solver/src/solve/search_graph.rs b/compiler/rustc_next_trait_solver/src/solve/search_graph.rs index 12cbc7e8f91..84f8eda4f8d 100644 --- a/compiler/rustc_next_trait_solver/src/solve/search_graph.rs +++ b/compiler/rustc_next_trait_solver/src/solve/search_graph.rs @@ -48,7 +48,9 @@ where ) -> QueryResult<I> { match kind { PathKind::Coinductive => response_no_constraints(cx, input, Certainty::Yes), - PathKind::Unknown => response_no_constraints(cx, input, Certainty::overflow(false)), + PathKind::Unknown | PathKind::ForcedAmbiguity => { + response_no_constraints(cx, input, Certainty::overflow(false)) + } // Even though we know these cycles to be unproductive, we still return // overflow during coherence. This is both as we are not 100% confident in // the implementation yet and any incorrect errors would be unsound there. diff --git a/compiler/rustc_parse/messages.ftl b/compiler/rustc_parse/messages.ftl index aaf1b6c05bf..3a21eea3d0a 100644 --- a/compiler/rustc_parse/messages.ftl +++ b/compiler/rustc_parse/messages.ftl @@ -869,6 +869,11 @@ parse_trait_alias_cannot_be_auto = trait aliases cannot be `auto` parse_trait_alias_cannot_be_const = trait aliases cannot be `const` parse_trait_alias_cannot_be_unsafe = trait aliases cannot be `unsafe` +parse_trait_impl_modifier_in_inherent_impl = inherent impls cannot be {$modifier_name} + .because = {$modifier_name} because of this + .type = inherent impl for this type + .note = only trait implementations may be annotated with `{$modifier}` + parse_transpose_dyn_or_impl = `for<...>` expected after `{$kw}`, not before .suggestion = move `{$kw}` before the `for<...>` diff --git a/compiler/rustc_parse/src/errors.rs b/compiler/rustc_parse/src/errors.rs index ddb2c545c78..a07d0606fd0 100644 --- a/compiler/rustc_parse/src/errors.rs +++ b/compiler/rustc_parse/src/errors.rs @@ -71,6 +71,20 @@ pub(crate) struct BadQPathStage2 { pub wrap: WrapType, } +#[derive(Diagnostic)] +#[diag(parse_trait_impl_modifier_in_inherent_impl)] +#[note] +pub(crate) struct TraitImplModifierInInherentImpl { + #[primary_span] + pub span: Span, + pub modifier: &'static str, + pub modifier_name: &'static str, + #[label(parse_because)] + pub modifier_span: Span, + #[label(parse_type)] + pub self_ty: Span, +} + #[derive(Subdiagnostic)] #[multipart_suggestion(parse_suggestion, applicability = "machine-applicable")] pub(crate) struct WrapType { diff --git a/compiler/rustc_parse/src/parser/asm.rs b/compiler/rustc_parse/src/parser/asm.rs index d4d0612a317..41c3b0f0b67 100644 --- a/compiler/rustc_parse/src/parser/asm.rs +++ b/compiler/rustc_parse/src/parser/asm.rs @@ -1,4 +1,3 @@ -use rustc_ast::ptr::P; use rustc_ast::{self as ast, AsmMacro}; use rustc_span::{Span, Symbol, kw}; @@ -14,7 +13,7 @@ pub struct AsmArg { } pub enum AsmArgKind { - Template(P<ast::Expr>), + Template(Box<ast::Expr>), Operand(Option<Symbol>, ast::InlineAsmOperand), Options(Vec<AsmOption>), ClobberAbi(Vec<(Symbol, Span)>), diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index e0f810d8c1e..a32cd33a260 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -3,7 +3,6 @@ use std::ops::{Deref, DerefMut}; use ast::token::IdentIsRaw; use rustc_ast as ast; -use rustc_ast::ptr::P; use rustc_ast::token::{self, Lit, LitKind, Token, TokenKind}; use rustc_ast::util::parser::AssocOp; use rustc_ast::{ @@ -50,7 +49,7 @@ use crate::{exp, fluent_generated as fluent}; /// Creates a placeholder argument. pub(super) fn dummy_arg(ident: Ident, guar: ErrorGuaranteed) -> Param { - let pat = P(Pat { + let pat = Box::new(Pat { id: ast::DUMMY_NODE_ID, kind: PatKind::Ident(BindingMode::NONE, ident, None), span: ident.span, @@ -62,23 +61,23 @@ pub(super) fn dummy_arg(ident: Ident, guar: ErrorGuaranteed) -> Param { id: ast::DUMMY_NODE_ID, pat, span: ident.span, - ty: P(ty), + ty: Box::new(ty), is_placeholder: false, } } pub(super) trait RecoverQPath: Sized + 'static { const PATH_STYLE: PathStyle = PathStyle::Expr; - fn to_ty(&self) -> Option<P<Ty>>; - fn recovered(qself: Option<P<QSelf>>, path: ast::Path) -> Self; + fn to_ty(&self) -> Option<Box<Ty>>; + fn recovered(qself: Option<Box<QSelf>>, path: ast::Path) -> Self; } impl RecoverQPath for Ty { const PATH_STYLE: PathStyle = PathStyle::Type; - fn to_ty(&self) -> Option<P<Ty>> { - Some(P(self.clone())) + fn to_ty(&self) -> Option<Box<Ty>> { + Some(Box::new(self.clone())) } - fn recovered(qself: Option<P<QSelf>>, path: ast::Path) -> Self { + fn recovered(qself: Option<Box<QSelf>>, path: ast::Path) -> Self { Self { span: path.span, kind: TyKind::Path(qself, path), @@ -90,10 +89,10 @@ impl RecoverQPath for Ty { impl RecoverQPath for Pat { const PATH_STYLE: PathStyle = PathStyle::Pat; - fn to_ty(&self) -> Option<P<Ty>> { + fn to_ty(&self) -> Option<Box<Ty>> { self.to_ty() } - fn recovered(qself: Option<P<QSelf>>, path: ast::Path) -> Self { + fn recovered(qself: Option<Box<QSelf>>, path: ast::Path) -> Self { Self { span: path.span, kind: PatKind::Path(qself, path), @@ -104,10 +103,10 @@ impl RecoverQPath for Pat { } impl RecoverQPath for Expr { - fn to_ty(&self) -> Option<P<Ty>> { + fn to_ty(&self) -> Option<Box<Ty>> { self.to_ty() } - fn recovered(qself: Option<P<QSelf>>, path: ast::Path) -> Self { + fn recovered(qself: Option<Box<QSelf>>, path: ast::Path) -> Self { Self { span: path.span, kind: ExprKind::Path(qself, path), @@ -977,7 +976,7 @@ impl<'a> Parser<'a> { lo: Span, s: BlockCheckMode, maybe_struct_name: token::Token, - ) -> Option<PResult<'a, P<Block>>> { + ) -> Option<PResult<'a, Box<Block>>> { if self.token.is_ident() && self.look_ahead(1, |t| t == &token::Colon) { // We might be having a struct literal where people forgot to include the path: // fn foo() -> Foo { @@ -1042,7 +1041,7 @@ impl<'a> Parser<'a> { token: token::Token, lo: Span, decl_hi: Span, - ) -> PResult<'a, P<Expr>> { + ) -> PResult<'a, Box<Expr>> { err.span_label(lo.to(decl_hi), "while parsing the body of this closure"); let guar = match before.kind { token::OpenBrace if token.kind != token::OpenBrace => { @@ -1260,7 +1259,7 @@ impl<'a> Parser<'a> { pub(super) fn check_mistyped_turbofish_with_multiple_type_params( &mut self, mut e: Diag<'a>, - expr: &mut P<Expr>, + expr: &mut Box<Expr>, ) -> PResult<'a, ErrorGuaranteed> { if let ExprKind::Binary(binop, _, _) = &expr.kind && let ast::BinOpKind::Lt = binop.node @@ -1443,7 +1442,7 @@ impl<'a> Parser<'a> { &mut self, inner_op: &Expr, outer_op: &Spanned<AssocOp>, - ) -> PResult<'a, Option<P<Expr>>> { + ) -> PResult<'a, Option<Box<Expr>>> { debug_assert!( outer_op.node.is_comparison(), "check_no_chained_comparison: {:?} is not comparison", @@ -1595,7 +1594,7 @@ impl<'a> Parser<'a> { } /// Swift lets users write `Ty?` to mean `Option<Ty>`. Parse the construct and recover from it. - pub(super) fn maybe_recover_from_question_mark(&mut self, ty: P<Ty>) -> P<Ty> { + pub(super) fn maybe_recover_from_question_mark(&mut self, ty: Box<Ty>) -> Box<Ty> { if self.token == token::Question { self.bump(); let guar = self.dcx().emit_err(QuestionMarkInType { @@ -1690,10 +1689,10 @@ impl<'a> Parser<'a> { pub(super) fn recover_from_prefix_increment( &mut self, - operand_expr: P<Expr>, + operand_expr: Box<Expr>, op_span: Span, start_stmt: bool, - ) -> PResult<'a, P<Expr>> { + ) -> PResult<'a, Box<Expr>> { let standalone = if start_stmt { IsStandalone::Standalone } else { IsStandalone::Subexpr }; let kind = IncDecRecovery { standalone, op: IncOrDec::Inc, fixity: UnaryFixity::Pre }; self.recover_from_inc_dec(operand_expr, kind, op_span) @@ -1701,10 +1700,10 @@ impl<'a> Parser<'a> { pub(super) fn recover_from_postfix_increment( &mut self, - operand_expr: P<Expr>, + operand_expr: Box<Expr>, op_span: Span, start_stmt: bool, - ) -> PResult<'a, P<Expr>> { + ) -> PResult<'a, Box<Expr>> { let kind = IncDecRecovery { standalone: if start_stmt { IsStandalone::Standalone } else { IsStandalone::Subexpr }, op: IncOrDec::Inc, @@ -1715,10 +1714,10 @@ impl<'a> Parser<'a> { pub(super) fn recover_from_postfix_decrement( &mut self, - operand_expr: P<Expr>, + operand_expr: Box<Expr>, op_span: Span, start_stmt: bool, - ) -> PResult<'a, P<Expr>> { + ) -> PResult<'a, Box<Expr>> { let kind = IncDecRecovery { standalone: if start_stmt { IsStandalone::Standalone } else { IsStandalone::Subexpr }, op: IncOrDec::Dec, @@ -1729,10 +1728,10 @@ impl<'a> Parser<'a> { fn recover_from_inc_dec( &mut self, - base: P<Expr>, + base: Box<Expr>, kind: IncDecRecovery, op_span: Span, - ) -> PResult<'a, P<Expr>> { + ) -> PResult<'a, Box<Expr>> { let mut err = self.dcx().struct_span_err( op_span, format!("Rust has no {} {} operator", kind.fixity, kind.op.name()), @@ -1833,8 +1832,8 @@ impl<'a> Parser<'a> { /// tail, and combines them into a `<Ty>::AssocItem` expression/pattern/type. pub(super) fn maybe_recover_from_bad_qpath<T: RecoverQPath>( &mut self, - base: P<T>, - ) -> PResult<'a, P<T>> { + base: Box<T>, + ) -> PResult<'a, Box<T>> { if !self.may_recover() { return Ok(base); } @@ -1853,8 +1852,8 @@ impl<'a> Parser<'a> { pub(super) fn maybe_recover_from_bad_qpath_stage_2<T: RecoverQPath>( &mut self, ty_span: Span, - ty: P<Ty>, - ) -> PResult<'a, P<T>> { + ty: Box<Ty>, + ) -> PResult<'a, Box<T>> { self.expect(exp!(PathSep))?; let mut path = ast::Path { segments: ThinVec::new(), span: DUMMY_SP, tokens: None }; @@ -1867,7 +1866,7 @@ impl<'a> Parser<'a> { }); let path_span = ty_span.shrink_to_hi(); // Use an empty path since `position == 0`. - Ok(P(T::recovered(Some(P(QSelf { ty, path_span, position: 0 })), path))) + Ok(Box::new(T::recovered(Some(Box::new(QSelf { ty, path_span, position: 0 })), path))) } /// This function gets called in places where a semicolon is NOT expected and if there's a @@ -1970,7 +1969,7 @@ impl<'a> Parser<'a> { pub(super) fn recover_incorrect_await_syntax( &mut self, await_sp: Span, - ) -> PResult<'a, P<Expr>> { + ) -> PResult<'a, Box<Expr>> { let (hi, expr, is_question) = if self.token == token::Bang { // Handle `await!(<expr>)`. self.recover_await_macro()? @@ -1982,7 +1981,7 @@ impl<'a> Parser<'a> { self.maybe_recover_from_bad_qpath(expr) } - fn recover_await_macro(&mut self) -> PResult<'a, (Span, P<Expr>, bool)> { + fn recover_await_macro(&mut self) -> PResult<'a, (Span, Box<Expr>, bool)> { self.expect(exp!(Bang))?; self.expect(exp!(OpenParen))?; let expr = self.parse_expr()?; @@ -1990,7 +1989,7 @@ impl<'a> Parser<'a> { Ok((self.prev_token.span, expr, false)) } - fn recover_await_prefix(&mut self, await_sp: Span) -> PResult<'a, (Span, P<Expr>, bool)> { + fn recover_await_prefix(&mut self, await_sp: Span) -> PResult<'a, (Span, Box<Expr>, bool)> { let is_question = self.eat(exp!(Question)); // Handle `await? <expr>`. let expr = if self.token == token::OpenBrace { // Handle `await { <expr> }`. @@ -2052,7 +2051,7 @@ impl<'a> Parser<'a> { } } - pub(super) fn try_macro_suggestion(&mut self) -> PResult<'a, P<Expr>> { + pub(super) fn try_macro_suggestion(&mut self) -> PResult<'a, Box<Expr>> { let is_try = self.token.is_keyword(kw::Try); let is_questionmark = self.look_ahead(1, |t| t == &token::Bang); //check for ! let is_open = self.look_ahead(2, |t| t == &token::OpenParen); //check for ( @@ -2124,7 +2123,7 @@ impl<'a> Parser<'a> { close: ExpTokenPair<'_>, lo: Span, err: Diag<'a>, - ) -> P<Expr> { + ) -> Box<Expr> { let guar = err.emit(); // Recover from parse error, callers expect the closing delim to be consumed. self.consume_block(open, close, ConsumeClosingDelim::Yes); @@ -2244,7 +2243,7 @@ impl<'a> Parser<'a> { pub(super) fn parameter_without_type( &mut self, err: &mut Diag<'_>, - pat: P<ast::Pat>, + pat: Box<ast::Pat>, require_name: bool, first_param: bool, ) -> Option<Ident> { @@ -2346,7 +2345,7 @@ impl<'a> Parser<'a> { None } - pub(super) fn recover_arg_parse(&mut self) -> PResult<'a, (P<ast::Pat>, P<ast::Ty>)> { + pub(super) fn recover_arg_parse(&mut self) -> PResult<'a, (Box<ast::Pat>, Box<ast::Ty>)> { let pat = self.parse_pat_no_top_alt(Some(Expected::ArgumentName), None)?; self.expect(exp!(Colon))?; let ty = self.parse_ty()?; @@ -2354,8 +2353,12 @@ impl<'a> Parser<'a> { self.dcx().emit_err(PatternMethodParamWithoutBody { span: pat.span }); // Pretend the pattern is `_`, to avoid duplicate errors from AST validation. - let pat = - P(Pat { kind: PatKind::Wild, span: pat.span, id: ast::DUMMY_NODE_ID, tokens: None }); + let pat = Box::new(Pat { + kind: PatKind::Wild, + span: pat.span, + id: ast::DUMMY_NODE_ID, + tokens: None, + }); Ok((pat, ty)) } @@ -2506,7 +2509,7 @@ impl<'a> Parser<'a> { /// - Single-segment paths (i.e. standalone generic const parameters). /// All other expressions that can be parsed will emit an error suggesting the expression be /// wrapped in braces. - pub(super) fn handle_unambiguous_unbraced_const_arg(&mut self) -> PResult<'a, P<Expr>> { + pub(super) fn handle_unambiguous_unbraced_const_arg(&mut self) -> PResult<'a, Box<Expr>> { let start = self.token.span; let attrs = self.parse_outer_attributes()?; let (expr, _) = @@ -2688,7 +2691,7 @@ impl<'a> Parser<'a> { pub(crate) fn recover_unbraced_const_arg_that_can_begin_ty( &mut self, mut snapshot: SnapshotParser<'a>, - ) -> Option<P<ast::Expr>> { + ) -> Option<Box<ast::Expr>> { match (|| { let attrs = self.parse_outer_attributes()?; snapshot.parse_expr_res(Restrictions::CONST_EXPR, attrs) @@ -2724,9 +2727,9 @@ impl<'a> Parser<'a> { /// `for` loop, `let`, &c. (in contrast to subpatterns within such). pub(crate) fn maybe_recover_colon_colon_in_pat_typo( &mut self, - mut first_pat: P<Pat>, + mut first_pat: Box<Pat>, expected: Option<Expected>, - ) -> P<Pat> { + ) -> Box<Pat> { if token::Colon != self.token.kind { return first_pat; } diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index cbf6b78431c..d0604f76317 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -6,7 +6,6 @@ use core::ops::{Bound, ControlFlow}; use ast::mut_visit::{self, MutVisitor}; use ast::token::IdentIsRaw; use ast::{CoroutineKind, ForLoopKind, GenBlockKind, MatchKind, Pat, Path, PathSegment, Recovered}; -use rustc_ast::ptr::P; use rustc_ast::token::{self, Delimiter, InvisibleOrigin, MetaVarKind, Token, TokenKind}; use rustc_ast::tokenstream::TokenTree; use rustc_ast::util::case::Case; @@ -56,7 +55,7 @@ pub(super) enum DestructuredFloat { impl<'a> Parser<'a> { /// Parses an expression. #[inline] - pub fn parse_expr(&mut self) -> PResult<'a, P<Expr>> { + pub fn parse_expr(&mut self) -> PResult<'a, Box<Expr>> { self.current_closure.take(); let attrs = self.parse_outer_attributes()?; @@ -64,7 +63,7 @@ impl<'a> Parser<'a> { } /// Parses an expression, forcing tokens to be collected. - pub fn parse_expr_force_collect(&mut self) -> PResult<'a, P<Expr>> { + pub fn parse_expr_force_collect(&mut self) -> PResult<'a, Box<Expr>> { self.current_closure.take(); // If the expression is associative (e.g. `1 + 2`), then any preceding @@ -90,7 +89,10 @@ impl<'a> Parser<'a> { self.parse_expr().map(|value| AnonConst { id: DUMMY_NODE_ID, value }) } - fn parse_expr_catch_underscore(&mut self, restrictions: Restrictions) -> PResult<'a, P<Expr>> { + fn parse_expr_catch_underscore( + &mut self, + restrictions: Restrictions, + ) -> PResult<'a, Box<Expr>> { let attrs = self.parse_outer_attributes()?; match self.parse_expr_res(restrictions, attrs) { Ok((expr, _)) => Ok(expr), @@ -109,7 +111,7 @@ impl<'a> Parser<'a> { } /// Parses a sequence of expressions delimited by parentheses. - fn parse_expr_paren_seq(&mut self) -> PResult<'a, ThinVec<P<Expr>>> { + fn parse_expr_paren_seq(&mut self) -> PResult<'a, ThinVec<Box<Expr>>> { self.parse_paren_comma_seq(|p| p.parse_expr_catch_underscore(Restrictions::empty())) .map(|(r, _)| r) } @@ -120,7 +122,7 @@ impl<'a> Parser<'a> { &mut self, r: Restrictions, attrs: AttrWrapper, - ) -> PResult<'a, (P<Expr>, bool)> { + ) -> PResult<'a, (Box<Expr>, bool)> { self.with_res(r, |this| this.parse_expr_assoc_with(Bound::Unbounded, attrs)) } @@ -131,7 +133,7 @@ impl<'a> Parser<'a> { &mut self, min_prec: Bound<ExprPrecedence>, attrs: AttrWrapper, - ) -> PResult<'a, (P<Expr>, bool)> { + ) -> PResult<'a, (Box<Expr>, bool)> { let lhs = if self.token.is_range_separator() { return self.parse_expr_prefix_range(attrs).map(|res| (res, false)); } else { @@ -147,8 +149,8 @@ impl<'a> Parser<'a> { &mut self, min_prec: Bound<ExprPrecedence>, starts_stmt: bool, - mut lhs: P<Expr>, - ) -> PResult<'a, (P<Expr>, bool)> { + mut lhs: Box<Expr>, + ) -> PResult<'a, (Box<Expr>, bool)> { let mut parsed_something = false; if !self.should_continue_as_assoc_expr(&lhs) { return Ok((lhs, parsed_something)); @@ -414,10 +416,10 @@ impl<'a> Parser<'a> { fn parse_expr_range( &mut self, prec: ExprPrecedence, - lhs: P<Expr>, + lhs: Box<Expr>, limits: RangeLimits, cur_op_span: Span, - ) -> PResult<'a, P<Expr>> { + ) -> PResult<'a, Box<Expr>> { let rhs = if self.is_at_start_of_range_notation_rhs() { let maybe_lt = self.token; let attrs = self.parse_outer_attributes()?; @@ -448,7 +450,7 @@ impl<'a> Parser<'a> { } /// Parses prefix-forms of range notation: `..expr`, `..`, `..=expr`. - fn parse_expr_prefix_range(&mut self, attrs: AttrWrapper) -> PResult<'a, P<Expr>> { + fn parse_expr_prefix_range(&mut self, attrs: AttrWrapper) -> PResult<'a, Box<Expr>> { if !attrs.is_empty() { let err = errors::DotDotRangeAttribute { span: self.token.span }; self.dcx().emit_err(err); @@ -490,7 +492,7 @@ impl<'a> Parser<'a> { } /// Parses a prefix-unary-operator expr. - fn parse_expr_prefix(&mut self, attrs: AttrWrapper) -> PResult<'a, P<Expr>> { + fn parse_expr_prefix(&mut self, attrs: AttrWrapper) -> PResult<'a, Box<Expr>> { let lo = self.token.span; macro_rules! make_it { @@ -564,7 +566,7 @@ impl<'a> Parser<'a> { } } - fn parse_expr_prefix_common(&mut self, lo: Span) -> PResult<'a, (Span, P<Expr>)> { + fn parse_expr_prefix_common(&mut self, lo: Span) -> PResult<'a, (Span, Box<Expr>)> { self.bump(); let attrs = self.parse_outer_attributes()?; let expr = if self.token.is_range_separator() { @@ -653,12 +655,12 @@ impl<'a> Parser<'a> { fn parse_assoc_op_cast( &mut self, - lhs: P<Expr>, + lhs: Box<Expr>, lhs_span: Span, op_span: Span, - expr_kind: fn(P<Expr>, P<Ty>) -> ExprKind, - ) -> PResult<'a, P<Expr>> { - let mk_expr = |this: &mut Self, lhs: P<Expr>, rhs: P<Ty>| { + expr_kind: fn(Box<Expr>, Box<Ty>) -> ExprKind, + ) -> PResult<'a, Box<Expr>> { + let mk_expr = |this: &mut Self, lhs: Box<Expr>, rhs: Box<Ty>| { this.mk_expr(this.mk_expr_sp(&lhs, lhs_span, op_span, rhs.span), expr_kind(lhs, rhs)) }; @@ -873,7 +875,7 @@ impl<'a> Parser<'a> { } /// Parses `a.b` or `a(13)` or `a[4]` or just `a`. - fn parse_expr_dot_or_call(&mut self, attrs: AttrWrapper) -> PResult<'a, P<Expr>> { + fn parse_expr_dot_or_call(&mut self, attrs: AttrWrapper) -> PResult<'a, Box<Expr>> { self.collect_tokens_for_expr(attrs, |this, attrs| { let base = this.parse_expr_bottom()?; let span = this.interpolated_or_expr_span(&base); @@ -884,9 +886,9 @@ impl<'a> Parser<'a> { pub(super) fn parse_expr_dot_or_call_with( &mut self, mut attrs: ast::AttrVec, - mut e: P<Expr>, + mut e: Box<Expr>, lo: Span, - ) -> PResult<'a, P<Expr>> { + ) -> PResult<'a, Box<Expr>> { let mut res = ensure_sufficient_stack(|| { loop { let has_question = @@ -945,8 +947,8 @@ impl<'a> Parser<'a> { pub(super) fn parse_dot_suffix_expr( &mut self, lo: Span, - base: P<Expr>, - ) -> PResult<'a, P<Expr>> { + base: Box<Expr>, + ) -> PResult<'a, Box<Expr>> { // At this point we've consumed something like `expr.` and `self.token` holds the token // after the dot. match self.token.uninterpolate().kind { @@ -1232,10 +1234,10 @@ impl<'a> Parser<'a> { &self, lo: Span, ident_span: Span, - base: P<Expr>, + base: Box<Expr>, field: Symbol, suffix: Option<Symbol>, - ) -> P<Expr> { + ) -> Box<Expr> { if let Some(suffix) = suffix { self.expect_no_tuple_index_suffix(ident_span, suffix); } @@ -1243,7 +1245,7 @@ impl<'a> Parser<'a> { } /// Parse a function call expression, `expr(...)`. - fn parse_expr_fn_call(&mut self, lo: Span, fun: P<Expr>) -> P<Expr> { + fn parse_expr_fn_call(&mut self, lo: Span, fun: Box<Expr>) -> Box<Expr> { let snapshot = if self.token == token::OpenParen { Some((self.create_snapshot_for_diagnostic(), fun.kind.clone())) } else { @@ -1267,9 +1269,9 @@ impl<'a> Parser<'a> { &mut self, lo: Span, open_paren: Span, - seq: PResult<'a, P<Expr>>, + seq: PResult<'a, Box<Expr>>, snapshot: Option<(SnapshotParser<'a>, ExprKind)>, - ) -> PResult<'a, P<Expr>> { + ) -> PResult<'a, Box<Expr>> { match (self.may_recover(), seq, snapshot) { (true, Err(err), Some((mut snapshot, ExprKind::Path(None, path)))) => { snapshot.bump(); // `(` @@ -1325,7 +1327,7 @@ impl<'a> Parser<'a> { } /// Parse an indexing expression `expr[...]`. - fn parse_expr_index(&mut self, lo: Span, base: P<Expr>) -> PResult<'a, P<Expr>> { + fn parse_expr_index(&mut self, lo: Span, base: Box<Expr>) -> PResult<'a, Box<Expr>> { let prev_span = self.prev_token.span; let open_delim_span = self.token.span; self.bump(); // `[` @@ -1339,7 +1341,7 @@ impl<'a> Parser<'a> { } /// Assuming we have just parsed `.`, continue parsing into an expression. - fn parse_dot_suffix(&mut self, self_arg: P<Expr>, lo: Span) -> PResult<'a, P<Expr>> { + fn parse_dot_suffix(&mut self, self_arg: Box<Expr>, lo: Span) -> PResult<'a, Box<Expr>> { if self.token_uninterpolated_span().at_least_rust_2018() && self.eat_keyword(exp!(Await)) { return Ok(self.mk_await_expr(self_arg, lo)); } @@ -1404,7 +1406,7 @@ impl<'a> Parser<'a> { /// /// N.B., this does not parse outer attributes, and is private because it only works /// correctly if called from `parse_expr_dot_or_call`. - fn parse_expr_bottom(&mut self) -> PResult<'a, P<Expr>> { + fn parse_expr_bottom(&mut self) -> PResult<'a, Box<Expr>> { maybe_recover_from_interpolated_ty_qpath!(self, true); let span = self.token.span; @@ -1556,7 +1558,7 @@ impl<'a> Parser<'a> { }) } - fn parse_expr_lit(&mut self) -> PResult<'a, P<Expr>> { + fn parse_expr_lit(&mut self) -> PResult<'a, Box<Expr>> { let lo = self.token.span; match self.parse_opt_token_lit() { Some((token_lit, _)) => { @@ -1567,7 +1569,7 @@ impl<'a> Parser<'a> { } } - fn parse_expr_tuple_parens(&mut self, restrictions: Restrictions) -> PResult<'a, P<Expr>> { + fn parse_expr_tuple_parens(&mut self, restrictions: Restrictions) -> PResult<'a, Box<Expr>> { let lo = self.token.span; self.expect(exp!(OpenParen))?; let (es, trailing_comma) = match self.parse_seq_to_end( @@ -1596,7 +1598,7 @@ impl<'a> Parser<'a> { self.maybe_recover_from_bad_qpath(expr) } - fn parse_expr_array_or_repeat(&mut self, close: ExpTokenPair<'_>) -> PResult<'a, P<Expr>> { + fn parse_expr_array_or_repeat(&mut self, close: ExpTokenPair<'_>) -> PResult<'a, Box<Expr>> { let lo = self.token.span; self.bump(); // `[` or other open delim @@ -1627,7 +1629,7 @@ impl<'a> Parser<'a> { self.maybe_recover_from_bad_qpath(expr) } - fn parse_expr_path_start(&mut self) -> PResult<'a, P<Expr>> { + fn parse_expr_path_start(&mut self) -> PResult<'a, Box<Expr>> { let maybe_eq_tok = self.prev_token; let (qself, path) = if self.eat_lt() { let lt_span = self.prev_token.span; @@ -1653,7 +1655,7 @@ impl<'a> Parser<'a> { self.dcx().emit_err(errors::MacroInvocationWithQualifiedPath(path.span)); } let lo = path.span; - let mac = P(MacCall { path, args: self.parse_delim_args()? }); + let mac = Box::new(MacCall { path, args: self.parse_delim_args()? }); (lo.to(self.prev_token.span), ExprKind::MacCall(mac)) } else if self.check(exp!(OpenBrace)) && let Some(expr) = self.maybe_parse_struct_expr(&qself, &path) @@ -1675,7 +1677,7 @@ impl<'a> Parser<'a> { &mut self, label_: Label, mut consume_colon: bool, - ) -> PResult<'a, P<Expr>> { + ) -> PResult<'a, Box<Expr>> { let lo = label_.ident.span; let label = Some(label_); let ate_colon = self.eat(exp!(Colon)); @@ -1810,7 +1812,7 @@ impl<'a> Parser<'a> { } /// Recover on the syntax `do catch { ... }` suggesting `try { ... }` instead. - fn recover_do_catch(&mut self) -> PResult<'a, P<Expr>> { + fn recover_do_catch(&mut self) -> PResult<'a, Box<Expr>> { let lo = self.token.span; self.bump(); // `do` @@ -1823,12 +1825,12 @@ impl<'a> Parser<'a> { } /// Parse an expression if the token can begin one. - fn parse_expr_opt(&mut self) -> PResult<'a, Option<P<Expr>>> { + fn parse_expr_opt(&mut self) -> PResult<'a, Option<Box<Expr>>> { Ok(if self.token.can_begin_expr() { Some(self.parse_expr()?) } else { None }) } /// Parse `"return" expr?`. - fn parse_expr_return(&mut self) -> PResult<'a, P<Expr>> { + fn parse_expr_return(&mut self) -> PResult<'a, Box<Expr>> { let lo = self.prev_token.span; let kind = ExprKind::Ret(self.parse_expr_opt()?); let expr = self.mk_expr(lo.to(self.prev_token.span), kind); @@ -1836,7 +1838,7 @@ impl<'a> Parser<'a> { } /// Parse `"do" "yeet" expr?`. - fn parse_expr_yeet(&mut self) -> PResult<'a, P<Expr>> { + fn parse_expr_yeet(&mut self) -> PResult<'a, Box<Expr>> { let lo = self.token.span; self.bump(); // `do` @@ -1851,7 +1853,7 @@ impl<'a> Parser<'a> { } /// Parse `"become" expr`, with `"become"` token already eaten. - fn parse_expr_become(&mut self) -> PResult<'a, P<Expr>> { + fn parse_expr_become(&mut self) -> PResult<'a, Box<Expr>> { let lo = self.prev_token.span; let kind = ExprKind::Become(self.parse_expr()?); let span = lo.to(self.prev_token.span); @@ -1868,7 +1870,7 @@ impl<'a> Parser<'a> { /// `break 'lbl: loop {}`); a labeled break with an unlabeled loop as its value /// expression only gets a warning for compatibility reasons; and a labeled break /// with a labeled loop does not even get a warning because there is no ambiguity. - fn parse_expr_break(&mut self) -> PResult<'a, P<Expr>> { + fn parse_expr_break(&mut self) -> PResult<'a, Box<Expr>> { let lo = self.prev_token.span; let mut label = self.eat_label(); let kind = if self.token == token::Colon @@ -1930,7 +1932,7 @@ impl<'a> Parser<'a> { } /// Parse `"continue" label?`. - fn parse_expr_continue(&mut self, lo: Span) -> PResult<'a, P<Expr>> { + fn parse_expr_continue(&mut self, lo: Span) -> PResult<'a, Box<Expr>> { let mut label = self.eat_label(); // Recover `continue label` -> `continue 'label` @@ -1947,7 +1949,7 @@ impl<'a> Parser<'a> { } /// Parse `"yield" expr?`. - fn parse_expr_yield(&mut self) -> PResult<'a, P<Expr>> { + fn parse_expr_yield(&mut self) -> PResult<'a, Box<Expr>> { let lo = self.prev_token.span; let kind = ExprKind::Yield(YieldKind::Prefix(self.parse_expr_opt()?)); let span = lo.to(self.prev_token.span); @@ -1957,7 +1959,7 @@ impl<'a> Parser<'a> { } /// Parse `builtin # ident(args,*)`. - fn parse_expr_builtin(&mut self) -> PResult<'a, P<Expr>> { + fn parse_expr_builtin(&mut self) -> PResult<'a, Box<Expr>> { self.parse_builtin(|this, lo, ident| { Ok(match ident.name { sym::offset_of => Some(this.parse_expr_offset_of(lo)?), @@ -2005,7 +2007,7 @@ impl<'a> Parser<'a> { } /// Built-in macro for `offset_of!` expressions. - pub(crate) fn parse_expr_offset_of(&mut self, lo: Span) -> PResult<'a, P<Expr>> { + pub(crate) fn parse_expr_offset_of(&mut self, lo: Span) -> PResult<'a, Box<Expr>> { let container = self.parse_ty()?; self.expect(exp!(Comma))?; @@ -2033,7 +2035,7 @@ impl<'a> Parser<'a> { } /// Built-in macro for type ascription expressions. - pub(crate) fn parse_expr_type_ascribe(&mut self, lo: Span) -> PResult<'a, P<Expr>> { + pub(crate) fn parse_expr_type_ascribe(&mut self, lo: Span) -> PResult<'a, Box<Expr>> { let expr = self.parse_expr()?; self.expect(exp!(Comma))?; let ty = self.parse_ty()?; @@ -2045,7 +2047,7 @@ impl<'a> Parser<'a> { &mut self, lo: Span, kind: UnsafeBinderCastKind, - ) -> PResult<'a, P<Expr>> { + ) -> PResult<'a, Box<Expr>> { let expr = self.parse_expr()?; let ty = if self.eat(exp!(Comma)) { Some(self.parse_ty()?) } else { None }; let span = lo.to(self.token.span); @@ -2155,7 +2157,7 @@ impl<'a> Parser<'a> { /// Keep this in sync with `Token::can_begin_literal_maybe_minus` and /// `Lit::from_token` (excluding unary negation). fn eat_token_lit(&mut self) -> Option<token::Lit> { - let check_expr = |expr: P<Expr>| { + let check_expr = |expr: Box<Expr>| { if let ast::ExprKind::Lit(token_lit) = expr.kind { Some(token_lit) } else if let ast::ExprKind::Unary(UnOp::Neg, inner) = &expr.kind @@ -2243,7 +2245,7 @@ impl<'a> Parser<'a> { /// Matches `'-' lit | lit` (cf. `ast_validation::AstValidator::check_expr_within_pat`). /// Keep this in sync with `Token::can_begin_literal_maybe_minus`. - pub fn parse_literal_maybe_minus(&mut self) -> PResult<'a, P<Expr>> { + pub fn parse_literal_maybe_minus(&mut self) -> PResult<'a, Box<Expr>> { if let Some(expr) = self.eat_metavar_seq_with_matcher( |mv_kind| matches!(mv_kind, MetaVarKind::Expr { .. }), |this| { @@ -2290,7 +2292,7 @@ impl<'a> Parser<'a> { /// Emits a suggestion if it looks like the user meant an array but /// accidentally used braces, causing the code to be interpreted as a block /// expression. - fn maybe_suggest_brackets_instead_of_braces(&mut self, lo: Span) -> Option<P<Expr>> { + fn maybe_suggest_brackets_instead_of_braces(&mut self, lo: Span) -> Option<Box<Expr>> { let mut snapshot = self.create_snapshot_for_diagnostic(); match snapshot.parse_expr_array_or_repeat(exp!(CloseBrace)) { Ok(arr) => { @@ -2360,7 +2362,7 @@ impl<'a> Parser<'a> { opt_label: Option<Label>, lo: Span, blk_mode: BlockCheckMode, - ) -> PResult<'a, P<Expr>> { + ) -> PResult<'a, Box<Expr>> { if self.may_recover() && self.is_array_like_block() { if let Some(arr) = self.maybe_suggest_brackets_instead_of_braces(lo) { return Ok(arr); @@ -2383,13 +2385,13 @@ impl<'a> Parser<'a> { } /// Parse a block which takes no attributes and has no label - fn parse_simple_block(&mut self) -> PResult<'a, P<Expr>> { + fn parse_simple_block(&mut self) -> PResult<'a, Box<Expr>> { let blk = self.parse_block()?; Ok(self.mk_expr(blk.span, ExprKind::Block(blk, None))) } /// Parses a closure expression (e.g., `move |args| expr`). - fn parse_expr_closure(&mut self) -> PResult<'a, P<Expr>> { + fn parse_expr_closure(&mut self) -> PResult<'a, Box<Expr>> { let lo = self.token.span; let before = self.prev_token; @@ -2494,7 +2496,7 @@ impl<'a> Parser<'a> { } /// If an explicit return type is given, require a block to appear (RFC 968). - fn parse_closure_block_body(&mut self, ret_span: Span) -> PResult<'a, P<Expr>> { + fn parse_closure_block_body(&mut self, ret_span: Span) -> PResult<'a, Box<Expr>> { if self.may_recover() && self.token.can_begin_expr() && self.token.kind != TokenKind::OpenBrace @@ -2565,7 +2567,7 @@ impl<'a> Parser<'a> { } /// Parses the `|arg, arg|` header of a closure. - fn parse_fn_block_decl(&mut self) -> PResult<'a, (P<FnDecl>, Span)> { + fn parse_fn_block_decl(&mut self) -> PResult<'a, (Box<FnDecl>, Span)> { let arg_start = self.token.span.lo(); let inputs = if self.eat(exp!(OrOr)) { @@ -2587,7 +2589,7 @@ impl<'a> Parser<'a> { let output = self.parse_ret_ty(AllowPlus::Yes, RecoverQPath::Yes, RecoverReturnSign::Yes)?; - Ok((P(FnDecl { inputs, output }), arg_span)) + Ok((Box::new(FnDecl { inputs, output }), arg_span)) } /// Parses a parameter in a closure header (e.g., `|arg, arg|`). @@ -2618,7 +2620,7 @@ impl<'a> Parser<'a> { } /// Parses an `if` expression (`if` token already eaten). - fn parse_expr_if(&mut self) -> PResult<'a, P<Expr>> { + fn parse_expr_if(&mut self) -> PResult<'a, Box<Expr>> { let lo = self.prev_token.span; // Scoping code checks the top level edition of the `if`; let's match it here. // The `CondChecker` also checks the edition of the `let` itself, just to make sure. @@ -2627,7 +2629,7 @@ impl<'a> Parser<'a> { self.parse_if_after_cond(lo, cond) } - fn parse_if_after_cond(&mut self, lo: Span, mut cond: P<Expr>) -> PResult<'a, P<Expr>> { + fn parse_if_after_cond(&mut self, lo: Span, mut cond: Box<Expr>) -> PResult<'a, Box<Expr>> { let cond_span = cond.span; // Tries to interpret `cond` as either a missing expression if it's a block, // or as an unfinished expression if it's a binop and the RHS is a block. @@ -2737,7 +2739,10 @@ impl<'a> Parser<'a> { /// i.e. the same span we use to later decide whether the drop behaviour should be that of /// edition `..=2021` or that of `2024..`. // Public because it is used in rustfmt forks such as https://github.com/tucant/rustfmt/blob/30c83df9e1db10007bdd16dafce8a86b404329b2/src/parse/macros/html.rs#L57 for custom if expressions. - pub fn parse_expr_cond(&mut self, let_chains_policy: LetChainsPolicy) -> PResult<'a, P<Expr>> { + pub fn parse_expr_cond( + &mut self, + let_chains_policy: LetChainsPolicy, + ) -> PResult<'a, Box<Expr>> { let attrs = self.parse_outer_attributes()?; let (mut cond, _) = self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL | Restrictions::ALLOW_LET, attrs)?; @@ -2748,7 +2753,7 @@ impl<'a> Parser<'a> { } /// Parses a `let $pat = $expr` pseudo-expression. - fn parse_expr_let(&mut self, restrictions: Restrictions) -> PResult<'a, P<Expr>> { + fn parse_expr_let(&mut self, restrictions: Restrictions) -> PResult<'a, Box<Expr>> { let recovered = if !restrictions.contains(Restrictions::ALLOW_LET) { let err = errors::ExpectedExpressionFoundLet { span: self.token.span, @@ -2790,7 +2795,7 @@ impl<'a> Parser<'a> { } /// Parses an `else { ... }` expression (`else` token already eaten). - fn parse_expr_else(&mut self) -> PResult<'a, P<Expr>> { + fn parse_expr_else(&mut self) -> PResult<'a, Box<Expr>> { let else_span = self.prev_token.span; // `else` let attrs = self.parse_outer_attributes()?; // For recovery. let expr = if self.eat_keyword(exp!(If)) { @@ -2888,7 +2893,7 @@ impl<'a> Parser<'a> { } } - fn error_on_extra_if(&mut self, cond: &P<Expr>) -> PResult<'a, ()> { + fn error_on_extra_if(&mut self, cond: &Box<Expr>) -> PResult<'a, ()> { if let ExprKind::Binary(Spanned { span: binop_span, node: binop }, _, right) = &cond.kind && let BinOpKind::And = binop && let ExprKind::If(cond, ..) = &right.kind @@ -2901,7 +2906,7 @@ impl<'a> Parser<'a> { } } - fn parse_for_head(&mut self) -> PResult<'a, (P<Pat>, P<Expr>)> { + fn parse_for_head(&mut self) -> PResult<'a, (Box<Pat>, Box<Expr>)> { let begin_paren = if self.token == token::OpenParen { // Record whether we are about to parse `for (`. // This is used below for recovery in case of `for ( $stuff ) $block` @@ -2967,7 +2972,7 @@ impl<'a> Parser<'a> { } /// Parses `for await? <src_pat> in <src_expr> <src_loop_block>` (`for` token already eaten). - fn parse_expr_for(&mut self, opt_label: Option<Label>, lo: Span) -> PResult<'a, P<Expr>> { + fn parse_expr_for(&mut self, opt_label: Option<Label>, lo: Span) -> PResult<'a, Box<Expr>> { let is_await = self.token_uninterpolated_span().at_least_rust_2018() && self.eat_keyword(exp!(Await)); @@ -3038,7 +3043,7 @@ impl<'a> Parser<'a> { } /// Parses a `while` or `while let` expression (`while` token already eaten). - fn parse_expr_while(&mut self, opt_label: Option<Label>, lo: Span) -> PResult<'a, P<Expr>> { + fn parse_expr_while(&mut self, opt_label: Option<Label>, lo: Span) -> PResult<'a, Box<Expr>> { let policy = LetChainsPolicy::EditionDependent { current_edition: lo.edition() }; let cond = self.parse_expr_cond(policy).map_err(|mut err| { err.span_label(lo, "while parsing the condition of this `while` expression"); @@ -3066,7 +3071,7 @@ impl<'a> Parser<'a> { } /// Parses `loop { ... }` (`loop` token already eaten). - fn parse_expr_loop(&mut self, opt_label: Option<Label>, lo: Span) -> PResult<'a, P<Expr>> { + fn parse_expr_loop(&mut self, opt_label: Option<Label>, lo: Span) -> PResult<'a, Box<Expr>> { let loop_span = self.prev_token.span; let (attrs, body) = self.parse_inner_attrs_and_block( // Only suggest moving erroneous block label to the loop header @@ -3096,7 +3101,7 @@ impl<'a> Parser<'a> { } /// Parses a `match ... { ... }` expression (`match` token already eaten). - fn parse_expr_match(&mut self) -> PResult<'a, P<Expr>> { + fn parse_expr_match(&mut self) -> PResult<'a, Box<Expr>> { let match_span = self.prev_token.span; let attrs = self.parse_outer_attributes()?; let (scrutinee, _) = self.parse_expr_res(Restrictions::NO_STRUCT_LITERAL, attrs)?; @@ -3110,9 +3115,9 @@ impl<'a> Parser<'a> { &mut self, lo: Span, match_span: Span, - scrutinee: P<Expr>, + scrutinee: Box<Expr>, match_kind: MatchKind, - ) -> PResult<'a, P<Expr>> { + ) -> PResult<'a, Box<Expr>> { if let Err(mut e) = self.expect(exp!(OpenBrace)) { if self.token == token::Semi { e.span_suggestion_short( @@ -3169,7 +3174,7 @@ impl<'a> Parser<'a> { /// Attempt to recover from match arm body with statements and no surrounding braces. fn parse_arm_body_missing_braces( &mut self, - first_expr: &P<Expr>, + first_expr: &Box<Expr>, arrow_span: Span, ) -> Option<(Span, ErrorGuaranteed)> { if self.token != token::Semi { @@ -3441,7 +3446,7 @@ impl<'a> Parser<'a> { }) } - fn parse_match_arm_guard(&mut self) -> PResult<'a, Option<P<Expr>>> { + fn parse_match_arm_guard(&mut self) -> PResult<'a, Option<Box<Expr>>> { // Used to check the `if_let_guard` feature mostly by scanning // `&&` tokens. fn has_let_expr(expr: &Expr) -> bool { @@ -3472,7 +3477,7 @@ impl<'a> Parser<'a> { Ok(Some(cond)) } - fn parse_match_arm_pat_and_guard(&mut self) -> PResult<'a, (P<Pat>, Option<P<Expr>>)> { + fn parse_match_arm_pat_and_guard(&mut self) -> PResult<'a, (Box<Pat>, Option<Box<Expr>>)> { if self.token == token::OpenParen { let left = self.token.span; let pat = self.parse_pat_no_top_guard( @@ -3512,7 +3517,7 @@ impl<'a> Parser<'a> { } } - fn parse_match_guard_condition(&mut self) -> PResult<'a, P<Expr>> { + fn parse_match_guard_condition(&mut self) -> PResult<'a, Box<Expr>> { let attrs = self.parse_outer_attributes()?; match self.parse_expr_res(Restrictions::ALLOW_LET | Restrictions::IN_IF_GUARD, attrs) { Ok((expr, _)) => Ok(expr), @@ -3546,7 +3551,7 @@ impl<'a> Parser<'a> { } /// Parses a `try {...}` expression (`try` token already eaten). - fn parse_try_block(&mut self, span_lo: Span) -> PResult<'a, P<Expr>> { + fn parse_try_block(&mut self, span_lo: Span) -> PResult<'a, Box<Expr>> { let (attrs, body) = self.parse_inner_attrs_and_block(None)?; if self.eat_keyword(exp!(Catch)) { Err(self.dcx().create_err(errors::CatchAfterTry { span: self.prev_token.span })) @@ -3575,7 +3580,7 @@ impl<'a> Parser<'a> { } /// Parses an `async move? {...}` or `gen move? {...}` expression. - fn parse_gen_block(&mut self) -> PResult<'a, P<Expr>> { + fn parse_gen_block(&mut self) -> PResult<'a, Box<Expr>> { let lo = self.token.span; let kind = if self.eat_keyword(exp!(Async)) { if self.eat_keyword(exp!(Gen)) { GenBlockKind::AsyncGen } else { GenBlockKind::Async } @@ -3624,9 +3629,9 @@ impl<'a> Parser<'a> { fn maybe_parse_struct_expr( &mut self, - qself: &Option<P<ast::QSelf>>, + qself: &Option<Box<ast::QSelf>>, path: &ast::Path, - ) -> Option<PResult<'a, P<Expr>>> { + ) -> Option<PResult<'a, Box<Expr>>> { let struct_allowed = !self.restrictions.contains(Restrictions::NO_STRUCT_LITERAL); if struct_allowed || self.is_certainly_not_a_block() { if let Err(err) = self.expect(exp!(OpenBrace)) { @@ -3820,10 +3825,10 @@ impl<'a> Parser<'a> { /// Precondition: already parsed the '{'. pub(super) fn parse_expr_struct( &mut self, - qself: Option<P<ast::QSelf>>, + qself: Option<Box<ast::QSelf>>, pth: ast::Path, recover: bool, - ) -> PResult<'a, P<Expr>> { + ) -> PResult<'a, Box<Expr>> { let lo = pth.span; let (fields, base, recovered_async) = self.parse_struct_fields(pth.clone(), recover, exp!(CloseBrace))?; @@ -3832,7 +3837,7 @@ impl<'a> Parser<'a> { let expr = if let Some(guar) = recovered_async { ExprKind::Err(guar) } else { - ExprKind::Struct(P(ast::StructExpr { qself, path: pth, fields, rest: base })) + ExprKind::Struct(Box::new(ast::StructExpr { qself, path: pth, fields, rest: base })) }; Ok(self.mk_expr(span, expr)) } @@ -3947,14 +3952,14 @@ impl<'a> Parser<'a> { self.dcx().emit_err(errors::LeftArrowOperator { span }); } - fn mk_assign_op(&self, assign_op: AssignOp, lhs: P<Expr>, rhs: P<Expr>) -> ExprKind { + fn mk_assign_op(&self, assign_op: AssignOp, lhs: Box<Expr>, rhs: Box<Expr>) -> ExprKind { ExprKind::AssignOp(assign_op, lhs, rhs) } fn mk_range( &mut self, - start: Option<P<Expr>>, - end: Option<P<Expr>>, + start: Option<Box<Expr>>, + end: Option<Box<Expr>>, limits: RangeLimits, ) -> ExprKind { if end.is_none() && limits == RangeLimits::Closed { @@ -3965,51 +3970,56 @@ impl<'a> Parser<'a> { } } - fn mk_unary(&self, unop: UnOp, expr: P<Expr>) -> ExprKind { + fn mk_unary(&self, unop: UnOp, expr: Box<Expr>) -> ExprKind { ExprKind::Unary(unop, expr) } - fn mk_binary(&self, binop: BinOp, lhs: P<Expr>, rhs: P<Expr>) -> ExprKind { + fn mk_binary(&self, binop: BinOp, lhs: Box<Expr>, rhs: Box<Expr>) -> ExprKind { ExprKind::Binary(binop, lhs, rhs) } - fn mk_index(&self, expr: P<Expr>, idx: P<Expr>, brackets_span: Span) -> ExprKind { + fn mk_index(&self, expr: Box<Expr>, idx: Box<Expr>, brackets_span: Span) -> ExprKind { ExprKind::Index(expr, idx, brackets_span) } - fn mk_call(&self, f: P<Expr>, args: ThinVec<P<Expr>>) -> ExprKind { + fn mk_call(&self, f: Box<Expr>, args: ThinVec<Box<Expr>>) -> ExprKind { ExprKind::Call(f, args) } - fn mk_await_expr(&mut self, self_arg: P<Expr>, lo: Span) -> P<Expr> { + fn mk_await_expr(&mut self, self_arg: Box<Expr>, lo: Span) -> Box<Expr> { let span = lo.to(self.prev_token.span); let await_expr = self.mk_expr(span, ExprKind::Await(self_arg, self.prev_token.span)); self.recover_from_await_method_call(); await_expr } - fn mk_use_expr(&mut self, self_arg: P<Expr>, lo: Span) -> P<Expr> { + fn mk_use_expr(&mut self, self_arg: Box<Expr>, lo: Span) -> Box<Expr> { let span = lo.to(self.prev_token.span); let use_expr = self.mk_expr(span, ExprKind::Use(self_arg, self.prev_token.span)); self.recover_from_use(); use_expr } - pub(crate) fn mk_expr_with_attrs(&self, span: Span, kind: ExprKind, attrs: AttrVec) -> P<Expr> { - P(Expr { kind, span, attrs, id: DUMMY_NODE_ID, tokens: None }) + pub(crate) fn mk_expr_with_attrs( + &self, + span: Span, + kind: ExprKind, + attrs: AttrVec, + ) -> Box<Expr> { + Box::new(Expr { kind, span, attrs, id: DUMMY_NODE_ID, tokens: None }) } - pub(crate) fn mk_expr(&self, span: Span, kind: ExprKind) -> P<Expr> { + pub(crate) fn mk_expr(&self, span: Span, kind: ExprKind) -> Box<Expr> { self.mk_expr_with_attrs(span, kind, AttrVec::new()) } - pub(super) fn mk_expr_err(&self, span: Span, guar: ErrorGuaranteed) -> P<Expr> { + pub(super) fn mk_expr_err(&self, span: Span, guar: ErrorGuaranteed) -> Box<Expr> { self.mk_expr(span, ExprKind::Err(guar)) } /// Create expression span ensuring the span of the parent node /// is larger than the span of lhs and rhs, including the attributes. - fn mk_expr_sp(&self, lhs: &P<Expr>, lhs_span: Span, op_span: Span, rhs_span: Span) -> Span { + fn mk_expr_sp(&self, lhs: &Box<Expr>, lhs_span: Span, op_span: Span, rhs_span: Span) -> Span { lhs.attrs .iter() .find(|a| a.style == AttrStyle::Outer) @@ -4021,8 +4031,8 @@ impl<'a> Parser<'a> { fn collect_tokens_for_expr( &mut self, attrs: AttrWrapper, - f: impl FnOnce(&mut Self, ast::AttrVec) -> PResult<'a, P<Expr>>, - ) -> PResult<'a, P<Expr>> { + f: impl FnOnce(&mut Self, ast::AttrVec) -> PResult<'a, Box<Expr>>, + ) -> PResult<'a, Box<Expr>> { self.collect_tokens(None, attrs, ForceCollect::No, |this, attrs| { let res = f(this, attrs)?; let trailing = Trailing::from( diff --git a/compiler/rustc_parse/src/parser/generics.rs b/compiler/rustc_parse/src/parser/generics.rs index 86326341a75..4a8530a2b38 100644 --- a/compiler/rustc_parse/src/parser/generics.rs +++ b/compiler/rustc_parse/src/parser/generics.rs @@ -308,9 +308,7 @@ impl<'a> Parser<'a> { /// Parses an experimental fn contract /// (`contract_requires(WWW) contract_ensures(ZZZ)`) - pub(super) fn parse_contract( - &mut self, - ) -> PResult<'a, Option<rustc_ast::ptr::P<ast::FnContract>>> { + pub(super) fn parse_contract(&mut self) -> PResult<'a, Option<Box<ast::FnContract>>> { let requires = if self.eat_keyword_noexpect(exp!(ContractRequires).kw) { self.psess.gated_spans.gate(sym::contracts_internals, self.prev_token.span); let precond = self.parse_expr()?; @@ -328,7 +326,7 @@ impl<'a> Parser<'a> { if requires.is_none() && ensures.is_none() { Ok(None) } else { - Ok(Some(rustc_ast::ptr::P(ast::FnContract { requires, ensures }))) + Ok(Some(Box::new(ast::FnContract { requires, ensures }))) } } diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index cb7c5649433..607adaf0829 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -3,7 +3,6 @@ use std::mem; use ast::token::IdentIsRaw; use rustc_ast::ast::*; -use rustc_ast::ptr::P; use rustc_ast::token::{self, Delimiter, InvisibleOrigin, MetaVarKind, TokenKind}; use rustc_ast::tokenstream::{DelimSpan, TokenStream, TokenTree}; use rustc_ast::util::case::Case; @@ -56,12 +55,12 @@ impl<'a> Parser<'a> { pub fn parse_mod( &mut self, term: ExpTokenPair<'_>, - ) -> PResult<'a, (AttrVec, ThinVec<P<Item>>, ModSpans)> { + ) -> PResult<'a, (AttrVec, ThinVec<Box<Item>>, ModSpans)> { let lo = self.token.span; let attrs = self.parse_inner_attributes()?; let post_attr_lo = self.token.span; - let mut items: ThinVec<P<_>> = ThinVec::new(); + let mut items: ThinVec<Box<_>> = ThinVec::new(); // There shouldn't be any stray semicolons before or after items. // `parse_item` consumes the appropriate semicolons so any leftover is an error. @@ -116,9 +115,9 @@ impl<'a> Parser<'a> { } impl<'a> Parser<'a> { - pub fn parse_item(&mut self, force_collect: ForceCollect) -> PResult<'a, Option<P<Item>>> { + pub fn parse_item(&mut self, force_collect: ForceCollect) -> PResult<'a, Option<Box<Item>>> { let fn_parse_mode = FnParseMode { req_name: |_| true, req_body: true }; - self.parse_item_(fn_parse_mode, force_collect).map(|i| i.map(P)) + self.parse_item_(fn_parse_mode, force_collect).map(|i| i.map(Box::new)) } fn parse_item_( @@ -327,7 +326,7 @@ impl<'a> Parser<'a> { self.recover_missing_kw_before_item()?; } // MACRO INVOCATION ITEM - ItemKind::MacCall(P(self.parse_item_macro(vis)?)) + ItemKind::MacCall(Box::new(self.parse_item_macro(vis)?)) } else { return Ok(None); }; @@ -664,20 +663,44 @@ impl<'a> Parser<'a> { }; let trait_ref = TraitRef { path, ref_id: ty_first.id }; - (Some(trait_ref), ty_second) + let of_trait = Some(Box::new(TraitImplHeader { + defaultness, + safety, + constness, + polarity, + trait_ref, + })); + (of_trait, ty_second) + } + None => { + let self_ty = ty_first; + let error = |modifier, modifier_name, modifier_span| { + self.dcx().create_err(errors::TraitImplModifierInInherentImpl { + span: self_ty.span, + modifier, + modifier_name, + modifier_span, + self_ty: self_ty.span, + }) + }; + + if let Safety::Unsafe(span) = safety { + error("unsafe", "unsafe", span).with_code(E0197).emit(); + } + if let ImplPolarity::Negative(span) = polarity { + error("!", "negative", span).emit(); + } + if let Defaultness::Default(def_span) = defaultness { + error("default", "default", def_span).emit(); + } + if let Const::Yes(span) = constness { + error("const", "const", span).emit(); + } + (None, self_ty) } - None => (None, ty_first), // impl Type }; - Ok(ItemKind::Impl(Box::new(Impl { - safety, - polarity, - defaultness, - constness, - generics, - of_trait, - self_ty, - items: impl_items, - }))) + + Ok(ItemKind::Impl(Impl { generics, of_trait, self_ty, items: impl_items })) } fn parse_item_delegation(&mut self) -> PResult<'a, ItemKind> { @@ -951,7 +974,7 @@ impl<'a> Parser<'a> { pub fn parse_impl_item( &mut self, force_collect: ForceCollect, - ) -> PResult<'a, Option<Option<P<AssocItem>>>> { + ) -> PResult<'a, Option<Option<Box<AssocItem>>>> { let fn_parse_mode = FnParseMode { req_name: |_| true, req_body: true }; self.parse_assoc_item(fn_parse_mode, force_collect) } @@ -959,7 +982,7 @@ impl<'a> Parser<'a> { pub fn parse_trait_item( &mut self, force_collect: ForceCollect, - ) -> PResult<'a, Option<Option<P<AssocItem>>>> { + ) -> PResult<'a, Option<Option<Box<AssocItem>>>> { let fn_parse_mode = FnParseMode { req_name: |edition| edition >= Edition::Edition2018, req_body: false }; self.parse_assoc_item(fn_parse_mode, force_collect) @@ -970,7 +993,7 @@ impl<'a> Parser<'a> { &mut self, fn_parse_mode: FnParseMode, force_collect: ForceCollect, - ) -> PResult<'a, Option<Option<P<AssocItem>>>> { + ) -> PResult<'a, Option<Option<Box<AssocItem>>>> { Ok(self.parse_item_(fn_parse_mode, force_collect)?.map( |Item { attrs, id, span, vis, kind, tokens }| { let kind = match AssocItemKind::try_from(kind) { @@ -997,7 +1020,7 @@ impl<'a> Parser<'a> { _ => return self.error_bad_item_kind(span, &kind, "`trait`s or `impl`s"), }, }; - Some(P(Item { attrs, id, span, vis, kind, tokens })) + Some(Box::new(Item { attrs, id, span, vis, kind, tokens })) }, )) } @@ -1237,7 +1260,7 @@ impl<'a> Parser<'a> { pub fn parse_foreign_item( &mut self, force_collect: ForceCollect, - ) -> PResult<'a, Option<Option<P<ForeignItem>>>> { + ) -> PResult<'a, Option<Option<Box<ForeignItem>>>> { let fn_parse_mode = FnParseMode { req_name: |_| true, req_body: false }; Ok(self.parse_item_(fn_parse_mode, force_collect)?.map( |Item { attrs, id, span, vis, kind, tokens }| { @@ -1263,7 +1286,7 @@ impl<'a> Parser<'a> { _ => return self.error_bad_item_kind(span, &kind, "`extern` blocks"), }, }; - Some(P(Item { attrs, id, span, vis, kind, tokens })) + Some(Box::new(Item { attrs, id, span, vis, kind, tokens })) }, )) } @@ -1365,10 +1388,10 @@ impl<'a> Parser<'a> { }; match &mut item_kind { - ItemKind::Impl(box Impl { of_trait: Some(trai), constness, .. }) => { - *constness = Const::Yes(const_span); + ItemKind::Impl(Impl { of_trait: Some(of_trait), .. }) => { + of_trait.constness = Const::Yes(const_span); - let before_trait = trai.path.span.shrink_to_lo(); + let before_trait = of_trait.trait_ref.path.span.shrink_to_lo(); let const_up_to_impl = const_span.with_hi(impl_span.lo()); err.with_multipart_suggestion( "you might have meant to write a const trait impl", @@ -1424,7 +1447,9 @@ impl<'a> Parser<'a> { /// ```ebnf /// Const = "const" ($ident | "_") Generics ":" $ty (= $expr)? WhereClause ";" ; /// ``` - fn parse_const_item(&mut self) -> PResult<'a, (Ident, Generics, P<Ty>, Option<P<ast::Expr>>)> { + fn parse_const_item( + &mut self, + ) -> PResult<'a, (Ident, Generics, Box<Ty>, Option<Box<ast::Expr>>)> { let ident = self.parse_ident_or_underscore()?; let mut generics = self.parse_generics()?; @@ -1517,7 +1542,7 @@ impl<'a> Parser<'a> { &mut self, colon_present: bool, m: Option<Mutability>, - ) -> P<Ty> { + ) -> Box<Ty> { // Construct the error and stash it away with the hope // that typeck will later enrich the error with a type. let kind = match m { @@ -1537,7 +1562,7 @@ impl<'a> Parser<'a> { // The user intended that the type be inferred, // so treat this as if the user wrote e.g. `const A: _ = expr;`. - P(Ty { kind: TyKind::Infer, span, id: ast::DUMMY_NODE_ID, tokens: None }) + Box::new(Ty { kind: TyKind::Infer, span, id: ast::DUMMY_NODE_ID, tokens: None }) } /// Parses an enum declaration. @@ -2207,7 +2232,7 @@ impl<'a> Parser<'a> { let arrow = TokenTree::token_alone(token::FatArrow, pspan.between(bspan)); // `=>` let tokens = TokenStream::new(vec![params, arrow, body]); let dspan = DelimSpan::from_pair(pspan.shrink_to_lo(), bspan.shrink_to_hi()); - P(DelimArgs { dspan, delim: Delimiter::Brace, tokens }) + Box::new(DelimArgs { dspan, delim: Delimiter::Brace, tokens }) } else { self.unexpected_any()? }; @@ -2409,7 +2434,7 @@ impl<'a> Parser<'a> { sig_lo: Span, vis: &Visibility, case: Case, - ) -> PResult<'a, (Ident, FnSig, Generics, Option<P<FnContract>>, Option<P<Block>>)> { + ) -> PResult<'a, (Ident, FnSig, Generics, Option<Box<FnContract>>, Option<Box<Block>>)> { let fn_span = self.token.span; let header = self.parse_fn_front_matter(vis, case, FrontMatterParsingMode::Function)?; // `const ... fn` let ident = self.parse_ident()?; // `foo` @@ -2539,7 +2564,7 @@ impl<'a> Parser<'a> { sig_hi: &mut Span, req_body: bool, fn_params_end: Option<Span>, - ) -> PResult<'a, Option<P<Block>>> { + ) -> PResult<'a, Option<Box<Block>>> { let has_semi = if req_body { self.token == TokenKind::Semi } else { @@ -2939,8 +2964,8 @@ impl<'a> Parser<'a> { req_name: ReqName, ret_allow_plus: AllowPlus, recover_return_sign: RecoverReturnSign, - ) -> PResult<'a, P<FnDecl>> { - Ok(P(FnDecl { + ) -> PResult<'a, Box<FnDecl>> { + Ok(Box::new(FnDecl { inputs: self.parse_fn_params(req_name)?, output: self.parse_ret_ty(ret_allow_plus, RecoverQPath::Yes, recover_return_sign)?, })) diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 90491e53249..0a8a0203013 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -25,7 +25,6 @@ pub(crate) use expr::ForbiddenLetReason; pub(crate) use item::FnParseMode; pub use pat::{CommaRecoveryMode, RecoverColon, RecoverComma}; use path::PathStyle; -use rustc_ast::ptr::P; use rustc_ast::token::{ self, IdentIsRaw, InvisibleOrigin, MetaVarKind, NtExprKind, NtPatKind, Token, TokenKind, }; @@ -1286,7 +1285,7 @@ impl<'a> Parser<'a> { } /// Parses inline const expressions. - fn parse_const_block(&mut self, span: Span, pat: bool) -> PResult<'a, P<Expr>> { + fn parse_const_block(&mut self, span: Span, pat: bool) -> PResult<'a, Box<Expr>> { self.expect_keyword(exp!(Const))?; let (attrs, blk) = self.parse_inner_attrs_and_block(None)?; let anon_const = AnonConst { @@ -1343,9 +1342,9 @@ impl<'a> Parser<'a> { } } - fn parse_delim_args(&mut self) -> PResult<'a, P<DelimArgs>> { + fn parse_delim_args(&mut self) -> PResult<'a, Box<DelimArgs>> { if let Some(args) = self.parse_delim_args_inner() { - Ok(P(args)) + Ok(Box::new(args)) } else { self.unexpected_any() } @@ -1470,7 +1469,7 @@ impl<'a> Parser<'a> { let path = self.parse_path(PathStyle::Mod)?; // `path` self.expect(exp!(CloseParen))?; // `)` let vis = VisibilityKind::Restricted { - path: P(path), + path: Box::new(path), id: ast::DUMMY_NODE_ID, shorthand: false, }; @@ -1487,7 +1486,7 @@ impl<'a> Parser<'a> { let path = self.parse_path(PathStyle::Mod)?; // `crate`/`super`/`self` self.expect(exp!(CloseParen))?; // `)` let vis = VisibilityKind::Restricted { - path: P(path), + path: Box::new(path), id: ast::DUMMY_NODE_ID, shorthand: true, }; @@ -1652,14 +1651,14 @@ pub enum ParseNtResult { Tt(TokenTree), Ident(Ident, IdentIsRaw), Lifetime(Ident, IdentIsRaw), - Item(P<ast::Item>), - Block(P<ast::Block>), - Stmt(P<ast::Stmt>), - Pat(P<ast::Pat>, NtPatKind), - Expr(P<ast::Expr>, NtExprKind), - Literal(P<ast::Expr>), - Ty(P<ast::Ty>), - Meta(P<ast::AttrItem>), - Path(P<ast::Path>), - Vis(P<ast::Visibility>), + Item(Box<ast::Item>), + Block(Box<ast::Block>), + Stmt(Box<ast::Stmt>), + Pat(Box<ast::Pat>, NtPatKind), + Expr(Box<ast::Expr>, NtExprKind), + Literal(Box<ast::Expr>), + Ty(Box<ast::Ty>), + Meta(Box<ast::AttrItem>), + Path(Box<ast::Path>), + Vis(Box<ast::Visibility>), } diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs index 7c83e96c160..42eb07858c2 100644 --- a/compiler/rustc_parse/src/parser/nonterminal.rs +++ b/compiler/rustc_parse/src/parser/nonterminal.rs @@ -1,4 +1,3 @@ -use rustc_ast::ptr::P; use rustc_ast::token::NtExprKind::*; use rustc_ast::token::NtPatKind::*; use rustc_ast::token::{self, InvisibleOrigin, MetaVarKind, NonterminalKind, Token}; @@ -129,7 +128,7 @@ impl<'a> Parser<'a> { Ok(ParseNtResult::Block(self.collect_tokens_no_attrs(|this| this.parse_block())?)) } NonterminalKind::Stmt => match self.parse_stmt(ForceCollect::Yes)? { - Some(stmt) => Ok(ParseNtResult::Stmt(P(stmt))), + Some(stmt) => Ok(ParseNtResult::Stmt(Box::new(stmt))), None => { Err(self.dcx().create_err(UnexpectedNonterminal::Statement(self.token.span))) } @@ -170,16 +169,15 @@ impl<'a> Parser<'a> { })) } } - NonterminalKind::Path => Ok(ParseNtResult::Path(P( - self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))? + NonterminalKind::Path => Ok(ParseNtResult::Path(Box::new( + self.collect_tokens_no_attrs(|this| this.parse_path(PathStyle::Type))?, ))), NonterminalKind::Meta => { - Ok(ParseNtResult::Meta(P(self.parse_attr_item(ForceCollect::Yes)?))) - } - NonterminalKind::Vis => { - Ok(ParseNtResult::Vis(P(self - .collect_tokens_no_attrs(|this| this.parse_visibility(FollowedByType::Yes))?))) + Ok(ParseNtResult::Meta(Box::new(self.parse_attr_item(ForceCollect::Yes)?))) } + NonterminalKind::Vis => Ok(ParseNtResult::Vis(Box::new( + self.collect_tokens_no_attrs(|this| this.parse_visibility(FollowedByType::Yes))?, + ))), NonterminalKind::Lifetime => { // We want to keep `'keyword` parsing, just like `keyword` is still // an ident for nonterminal purposes. diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index 64653ee2a04..a415849b915 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -1,7 +1,6 @@ use std::ops::Bound; use rustc_ast::mut_visit::{self, MutVisitor}; -use rustc_ast::ptr::P; use rustc_ast::token::NtPatKind::*; use rustc_ast::token::{self, IdentIsRaw, MetaVarKind, Token}; use rustc_ast::util::parser::ExprPrecedence; @@ -108,7 +107,7 @@ impl<'a> Parser<'a> { rc: RecoverComma, ra: RecoverColon, rt: CommaRecoveryMode, - ) -> PResult<'a, P<Pat>> { + ) -> PResult<'a, Box<Pat>> { let pat = self.parse_pat_no_top_guard(expected, rc, ra, rt)?; if self.eat_keyword(exp!(If)) { @@ -131,7 +130,7 @@ impl<'a> Parser<'a> { &mut self, expected: Option<Expected>, syntax_loc: Option<PatternLocation>, - ) -> PResult<'a, P<Pat>> { + ) -> PResult<'a, Box<Pat>> { self.parse_pat_with_range_pat(true, expected, syntax_loc) } @@ -150,7 +149,7 @@ impl<'a> Parser<'a> { rc: RecoverComma, ra: RecoverColon, rt: CommaRecoveryMode, - ) -> PResult<'a, P<Pat>> { + ) -> PResult<'a, Box<Pat>> { self.parse_pat_no_top_guard_inner(expected, rc, ra, rt, None).map(|(pat, _)| pat) } @@ -163,7 +162,7 @@ impl<'a> Parser<'a> { ra: RecoverColon, rt: CommaRecoveryMode, syntax_loc: Option<PatternLocation>, - ) -> PResult<'a, (P<Pat>, bool)> { + ) -> PResult<'a, (Box<Pat>, bool)> { // Keep track of whether we recovered from a trailing vert so that we can avoid duplicated // suggestions (which bothers rustfix). // @@ -253,7 +252,7 @@ impl<'a> Parser<'a> { expected: Option<Expected>, rc: RecoverComma, syntax_loc: PatternLocation, - ) -> PResult<'a, (P<Pat>, bool)> { + ) -> PResult<'a, (Box<Pat>, bool)> { // We use `parse_pat_allow_top_alt` regardless of whether we actually want top-level // or-patterns so that we can detect when a user tries to use it. This allows us to print a // better error message. @@ -301,7 +300,7 @@ impl<'a> Parser<'a> { /// /// The return value represents the parsed pattern and `true` if a `Colon` was parsed (`false` /// otherwise). - pub(super) fn parse_fn_param_pat_colon(&mut self) -> PResult<'a, (P<Pat>, bool)> { + pub(super) fn parse_fn_param_pat_colon(&mut self) -> PResult<'a, (Box<Pat>, bool)> { // In order to get good UX, we first recover in the case of a leading vert for an illegal // top-level or-pat. Normally, this means recovering both `|` and `||`, but in this case, // a leading `||` probably doesn't indicate an or-pattern attempt, so we handle that @@ -685,7 +684,7 @@ impl<'a> Parser<'a> { PatVisitor { parser: self, stmt, arm: None, field: None }.visit_stmt(stmt); } - fn eat_metavar_pat(&mut self) -> Option<P<Pat>> { + fn eat_metavar_pat(&mut self) -> Option<Box<Pat>> { // Must try both kinds of pattern nonterminals. if let Some(pat) = self.eat_metavar_seq_with_matcher( |mv_kind| matches!(mv_kind, MetaVarKind::Pat(PatParam { .. })), @@ -713,7 +712,7 @@ impl<'a> Parser<'a> { allow_range_pat: bool, expected: Option<Expected>, syntax_loc: Option<PatternLocation>, - ) -> PResult<'a, P<Pat>> { + ) -> PResult<'a, Box<Pat>> { maybe_recover_from_interpolated_ty_qpath!(self, true); if let Some(pat) = self.eat_metavar_pat() { @@ -909,7 +908,7 @@ impl<'a> Parser<'a> { /// e.g. [F#][and] where they are called AND-patterns. /// /// [and]: https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/pattern-matching - fn recover_intersection_pat(&mut self, lhs: P<Pat>) -> PResult<'a, P<Pat>> { + fn recover_intersection_pat(&mut self, lhs: Box<Pat>) -> PResult<'a, Box<Pat>> { if self.token != token::At { // Next token is not `@` so it's not going to be an intersection pattern. return Ok(lhs); @@ -1091,7 +1090,7 @@ impl<'a> Parser<'a> { /// Turn all by-value immutable bindings in a pattern into mutable bindings. /// Returns `true` if any change was made. - fn make_all_value_bindings_mutable(pat: &mut P<Pat>) -> bool { + fn make_all_value_bindings_mutable(pat: &mut Box<Pat>) -> bool { struct AddMut(bool); impl MutVisitor for AddMut { fn visit_pat(&mut self, pat: &mut Pat) { @@ -1139,7 +1138,7 @@ impl<'a> Parser<'a> { fn parse_pat_mac_invoc(&mut self, path: Path) -> PResult<'a, PatKind> { self.bump(); let args = self.parse_delim_args()?; - let mac = P(MacCall { path, args }); + let mac = Box::new(MacCall { path, args }); Ok(PatKind::MacCall(mac)) } @@ -1147,7 +1146,7 @@ impl<'a> Parser<'a> { &mut self, err: Diag<'a>, expected: Option<Expected>, - ) -> PResult<'a, P<Pat>> { + ) -> PResult<'a, Box<Pat>> { err.cancel(); let expected = Expected::to_string_or_fallback(expected); @@ -1182,7 +1181,7 @@ impl<'a> Parser<'a> { /// `$begin $form` has already been parsed. fn parse_pat_range_begin_with( &mut self, - begin: P<Expr>, + begin: Box<Expr>, re: Spanned<RangeEnd>, ) -> PResult<'a, PatKind> { let end = if self.is_pat_range_end_start(0) { @@ -1262,7 +1261,7 @@ impl<'a> Parser<'a> { } /// Parse a range pattern end bound - fn parse_pat_range_end(&mut self) -> PResult<'a, P<Expr>> { + fn parse_pat_range_end(&mut self) -> PResult<'a, Box<Expr>> { // recover leading `(` let open_paren = (self.may_recover() && self.eat_noexpect(&token::OpenParen)) .then_some(self.prev_token.span); @@ -1380,7 +1379,7 @@ impl<'a> Parser<'a> { } /// Parse a struct ("record") pattern (e.g. `Foo { ... }` or `Foo::Bar { ... }`). - fn parse_pat_struct(&mut self, qself: Option<P<QSelf>>, path: Path) -> PResult<'a, PatKind> { + fn parse_pat_struct(&mut self, qself: Option<Box<QSelf>>, path: Path) -> PResult<'a, PatKind> { if qself.is_some() { // Feature gate the use of qualified paths in patterns self.psess.gated_spans.gate(sym::more_qualified_paths, path.span); @@ -1400,7 +1399,7 @@ impl<'a> Parser<'a> { /// Parse tuple struct or tuple variant pattern (e.g. `Foo(...)` or `Foo::Bar(...)`). fn parse_pat_tuple_struct( &mut self, - qself: Option<P<QSelf>>, + qself: Option<Box<QSelf>>, path: Path, ) -> PResult<'a, PatKind> { let (fields, _) = self.parse_paren_comma_seq(|p| { @@ -1749,11 +1748,11 @@ impl<'a> Parser<'a> { }) } - pub(super) fn mk_pat_ident(&self, span: Span, ann: BindingMode, ident: Ident) -> P<Pat> { + pub(super) fn mk_pat_ident(&self, span: Span, ann: BindingMode, ident: Ident) -> Box<Pat> { self.mk_pat(span, PatKind::Ident(ann, ident, None)) } - pub(super) fn mk_pat(&self, span: Span, kind: PatKind) -> P<Pat> { - P(Pat { kind, span, id: ast::DUMMY_NODE_ID, tokens: None }) + pub(super) fn mk_pat(&self, span: Span, kind: PatKind) -> Box<Pat> { + Box::new(Pat { kind, span, id: ast::DUMMY_NODE_ID, tokens: None }) } } diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index 8e65ab99c5e..a6ec3ea4245 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -1,7 +1,6 @@ use std::mem; use ast::token::IdentIsRaw; -use rustc_ast::ptr::P; use rustc_ast::token::{self, MetaVarKind, Token, TokenKind}; use rustc_ast::{ self as ast, AngleBracketedArg, AngleBracketedArgs, AnonConst, AssocItemConstraint, @@ -75,7 +74,7 @@ impl<'a> Parser<'a> { /// `<T as U>::a` /// `<T as U>::F::a<S>` (without disambiguator) /// `<T as U>::F::a::<S>` (with disambiguator) - pub(super) fn parse_qpath(&mut self, style: PathStyle) -> PResult<'a, (P<QSelf>, Path)> { + pub(super) fn parse_qpath(&mut self, style: PathStyle) -> PResult<'a, (Box<QSelf>, Path)> { let lo = self.prev_token.span; let ty = self.parse_ty()?; @@ -105,7 +104,7 @@ impl<'a> Parser<'a> { self.expect(exp!(PathSep))?; } - let qself = P(QSelf { ty, path_span, position: path.segments.len() }); + let qself = Box::new(QSelf { ty, path_span, position: path.segments.len() }); if !is_import_coupler { self.parse_path_segments(&mut path.segments, style, None)?; } @@ -380,7 +379,7 @@ impl<'a> Parser<'a> { .emit_err(errors::BadReturnTypeNotationOutput { span, suggestion }); } - P(ast::GenericArgs::ParenthesizedElided(span)) + Box::new(ast::GenericArgs::ParenthesizedElided(span)) } else { // `(T, U) -> R` @@ -842,7 +841,7 @@ impl<'a> Parser<'a> { /// - A literal. /// - A numeric literal prefixed by `-`. /// - A single-segment path. - pub(super) fn expr_is_valid_const_arg(&self, expr: &P<rustc_ast::Expr>) -> bool { + pub(super) fn expr_is_valid_const_arg(&self, expr: &Box<rustc_ast::Expr>) -> bool { match &expr.kind { ast::ExprKind::Block(_, _) | ast::ExprKind::Lit(_) diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 2fa6520f2a4..7aacb674253 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -4,7 +4,6 @@ use std::ops::Bound; use ast::Label; use rustc_ast as ast; -use rustc_ast::ptr::P; use rustc_ast::token::{self, Delimiter, InvisibleOrigin, MetaVarKind, TokenKind}; use rustc_ast::util::classify::{self, TrailingBrace}; use rustc_ast::{ @@ -157,7 +156,7 @@ impl<'a> Parser<'a> { FnParseMode { req_name: |_| true, req_body: true }, force_collect, )? { - self.mk_stmt(lo.to(item.span), StmtKind::Item(P(item))) + self.mk_stmt(lo.to(item.span), StmtKind::Item(Box::new(item))) } else if self.eat(exp!(Semi)) { // Do not attempt to parse an expression if we're done here. self.error_outer_attrs(attrs); @@ -246,7 +245,7 @@ impl<'a> Parser<'a> { _ => MacStmtStyle::NoBraces, }; - let mac = P(MacCall { path, args }); + let mac = Box::new(MacCall { path, args }); let kind = if (style == MacStmtStyle::Braces && !matches!(self.token.kind, token::Dot | token::Question)) @@ -256,7 +255,7 @@ impl<'a> Parser<'a> { | token::Eof | token::CloseInvisible(InvisibleOrigin::MetaVar(MetaVarKind::Stmt)) ) { - StmtKind::MacCall(P(MacCallStmt { mac, style, attrs, tokens: None })) + StmtKind::MacCall(Box::new(MacCallStmt { mac, style, attrs, tokens: None })) } else { // Since none of the above applied, this is an expression statement macro. let e = self.mk_expr(lo.to(hi), ExprKind::MacCall(mac)); @@ -307,7 +306,7 @@ impl<'a> Parser<'a> { } /// Parses a local variable declaration. - fn parse_local(&mut self, super_: Option<Span>, attrs: AttrVec) -> PResult<'a, P<Local>> { + fn parse_local(&mut self, super_: Option<Span>, attrs: AttrVec) -> PResult<'a, Box<Local>> { let lo = super_.unwrap_or(self.prev_token.span); if self.token.is_keyword(kw::Const) && self.look_ahead(1, |t| t.is_ident()) { @@ -409,7 +408,7 @@ impl<'a> Parser<'a> { } }; let hi = if self.token == token::Semi { self.token.span } else { self.prev_token.span }; - Ok(P(ast::Local { + Ok(Box::new(ast::Local { super_, ty, pat, @@ -463,7 +462,7 @@ impl<'a> Parser<'a> { } /// Parses the RHS of a local variable declaration (e.g., `= 14;`). - fn parse_initializer(&mut self, eq_optional: bool) -> PResult<'a, Option<P<Expr>>> { + fn parse_initializer(&mut self, eq_optional: bool) -> PResult<'a, Option<Box<Expr>>> { let eq_consumed = match self.token.kind { token::PlusEq | token::MinusEq @@ -494,7 +493,7 @@ impl<'a> Parser<'a> { } /// Parses a block. No inner attributes are allowed. - pub fn parse_block(&mut self) -> PResult<'a, P<Block>> { + pub fn parse_block(&mut self) -> PResult<'a, Box<Block>> { let (attrs, block) = self.parse_inner_attrs_and_block(None)?; if let [.., last] = &*attrs { let suggest_to_outer = match &last.kind { @@ -679,7 +678,7 @@ impl<'a> Parser<'a> { pub(super) fn parse_inner_attrs_and_block( &mut self, loop_header: Option<Span>, - ) -> PResult<'a, (AttrVec, P<Block>)> { + ) -> PResult<'a, (AttrVec, Box<Block>)> { self.parse_block_common(self.token.span, BlockCheckMode::Default, loop_header) } @@ -692,7 +691,7 @@ impl<'a> Parser<'a> { lo: Span, blk_mode: BlockCheckMode, loop_header: Option<Span>, - ) -> PResult<'a, (AttrVec, P<Block>)> { + ) -> PResult<'a, (AttrVec, Box<Block>)> { if let Some(block) = self.eat_metavar_seq(MetaVarKind::Block, |this| this.parse_block()) { return Ok((AttrVec::new(), block)); } @@ -718,7 +717,7 @@ impl<'a> Parser<'a> { lo: Span, s: BlockCheckMode, recover: AttemptLocalParseRecovery, - ) -> PResult<'a, P<Block>> { + ) -> PResult<'a, Box<Block>> { let mut stmts = ThinVec::new(); let mut snapshot = None; while !self.eat(exp!(CloseBrace)) { @@ -1050,8 +1049,8 @@ impl<'a> Parser<'a> { stmts: ThinVec<Stmt>, rules: BlockCheckMode, span: Span, - ) -> P<Block> { - P(Block { stmts, id: DUMMY_NODE_ID, rules, span, tokens: None }) + ) -> Box<Block> { + Box::new(Block { stmts, id: DUMMY_NODE_ID, rules, span, tokens: None }) } pub(super) fn mk_stmt(&self, span: Span, kind: StmtKind) -> Stmt { @@ -1062,7 +1061,7 @@ impl<'a> Parser<'a> { self.mk_stmt(span, StmtKind::Expr(self.mk_expr_err(span, guar))) } - pub(super) fn mk_block_err(&self, span: Span, guar: ErrorGuaranteed) -> P<Block> { + pub(super) fn mk_block_err(&self, span: Span, guar: ErrorGuaranteed) -> Box<Block> { self.mk_block(thin_vec![self.mk_stmt_err(span, guar)], BlockCheckMode::Default, span) } } diff --git a/compiler/rustc_parse/src/parser/tests.rs b/compiler/rustc_parse/src/parser/tests.rs index 43a1d779a75..a6e7266e71b 100644 --- a/compiler/rustc_parse/src/parser/tests.rs +++ b/compiler/rustc_parse/src/parser/tests.rs @@ -8,7 +8,6 @@ use std::sync::{Arc, Mutex}; use std::{io, str}; use ast::token::IdentIsRaw; -use rustc_ast::ptr::P; use rustc_ast::token::{self, Delimiter, Token}; use rustc_ast::tokenstream::{DelimSpacing, DelimSpan, Spacing, TokenStream, TokenTree}; use rustc_ast::{self as ast, PatKind, visit}; @@ -2240,7 +2239,7 @@ fn parse_item_from_source_str( name: FileName, source: String, psess: &ParseSess, -) -> PResult<'_, Option<P<ast::Item>>> { +) -> PResult<'_, Option<Box<ast::Item>>> { unwrap_or_emit_fatal(new_parser_from_source_str(psess, name, source)) .parse_item(ForceCollect::No) } @@ -2251,12 +2250,12 @@ fn sp(a: u32, b: u32) -> Span { } /// Parses a string, return an expression. -fn string_to_expr(source_str: String) -> P<ast::Expr> { +fn string_to_expr(source_str: String) -> Box<ast::Expr> { with_error_checking_parse(source_str, &psess(), |p| p.parse_expr()) } /// Parses a string, returns an item. -fn string_to_item(source_str: String) -> Option<P<ast::Item>> { +fn string_to_item(source_str: String) -> Option<Box<ast::Item>> { with_error_checking_parse(source_str, &psess(), |p| p.parse_item(ForceCollect::No)) } @@ -2520,7 +2519,7 @@ fn ttdelim_span() { name: FileName, source: String, psess: &ParseSess, - ) -> PResult<'_, P<ast::Expr>> { + ) -> PResult<'_, Box<ast::Expr>> { unwrap_or_emit_fatal(new_parser_from_source_str(psess, name, source)).parse_expr() } diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 59048e42e6f..0d479731e73 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -1,4 +1,3 @@ -use rustc_ast::ptr::P; use rustc_ast::token::{self, IdentIsRaw, MetaVarKind, Token, TokenKind}; use rustc_ast::util::case::Case; use rustc_ast::{ @@ -105,7 +104,7 @@ fn can_begin_dyn_bound_in_edition_2015(t: &Token) -> bool { impl<'a> Parser<'a> { /// Parses a type. - pub fn parse_ty(&mut self) -> PResult<'a, P<Ty>> { + pub fn parse_ty(&mut self) -> PResult<'a, Box<Ty>> { // Make sure deeply nested types don't overflow the stack. ensure_sufficient_stack(|| { self.parse_ty_common( @@ -122,7 +121,7 @@ impl<'a> Parser<'a> { pub(super) fn parse_ty_with_generics_recovery( &mut self, ty_params: &Generics, - ) -> PResult<'a, P<Ty>> { + ) -> PResult<'a, Box<Ty>> { self.parse_ty_common( AllowPlus::Yes, AllowCVariadic::No, @@ -136,7 +135,7 @@ impl<'a> Parser<'a> { /// Parse a type suitable for a function or function pointer parameter. /// The difference from `parse_ty` is that this version allows `...` /// (`CVarArgs`) at the top level of the type. - pub(super) fn parse_ty_for_param(&mut self) -> PResult<'a, P<Ty>> { + pub(super) fn parse_ty_for_param(&mut self) -> PResult<'a, Box<Ty>> { self.parse_ty_common( AllowPlus::Yes, AllowCVariadic::Yes, @@ -153,7 +152,7 @@ impl<'a> Parser<'a> { /// `+` is prohibited to maintain operator priority (P(+) < P(&)). /// Example 2: `value1 as TYPE + value2` /// `+` is prohibited to avoid interactions with expression grammar. - pub(super) fn parse_ty_no_plus(&mut self) -> PResult<'a, P<Ty>> { + pub(super) fn parse_ty_no_plus(&mut self) -> PResult<'a, Box<Ty>> { self.parse_ty_common( AllowPlus::No, AllowCVariadic::No, @@ -166,7 +165,7 @@ impl<'a> Parser<'a> { /// Parses a type following an `as` cast. Similar to `parse_ty_no_plus`, but signaling origin /// for better diagnostics involving `?`. - pub(super) fn parse_as_cast_ty(&mut self) -> PResult<'a, P<Ty>> { + pub(super) fn parse_as_cast_ty(&mut self) -> PResult<'a, Box<Ty>> { self.parse_ty_common( AllowPlus::No, AllowCVariadic::No, @@ -177,7 +176,7 @@ impl<'a> Parser<'a> { ) } - pub(super) fn parse_ty_no_question_mark_recover(&mut self) -> PResult<'a, P<Ty>> { + pub(super) fn parse_ty_no_question_mark_recover(&mut self) -> PResult<'a, Box<Ty>> { self.parse_ty_common( AllowPlus::Yes, AllowCVariadic::No, @@ -190,7 +189,7 @@ impl<'a> Parser<'a> { /// Parse a type without recovering `:` as `->` to avoid breaking code such /// as `where fn() : for<'a>`. - pub(super) fn parse_ty_for_where_clause(&mut self) -> PResult<'a, P<Ty>> { + pub(super) fn parse_ty_for_where_clause(&mut self) -> PResult<'a, Box<Ty>> { self.parse_ty_common( AllowPlus::Yes, AllowCVariadic::No, @@ -250,7 +249,7 @@ impl<'a> Parser<'a> { recover_return_sign: RecoverReturnSign, ty_generics: Option<&Generics>, recover_question_mark: RecoverQuestionMark, - ) -> PResult<'a, P<Ty>> { + ) -> PResult<'a, Box<Ty>> { let allow_qpath_recovery = recover_qpath == RecoverQPath::Yes; maybe_recover_from_interpolated_ty_qpath!(self, allow_qpath_recovery); if self.token == token::Pound && self.look_ahead(1, |t| *t == token::OpenBracket) { @@ -425,7 +424,7 @@ impl<'a> Parser<'a> { let span = lo.to(self.prev_token.span); self.psess.gated_spans.gate(sym::unsafe_binders, span); - Ok(TyKind::UnsafeBinder(P(UnsafeBinderTy { generic_params, inner_ty }))) + Ok(TyKind::UnsafeBinder(Box::new(UnsafeBinderTy { generic_params, inner_ty }))) } /// Parses either: @@ -610,7 +609,7 @@ impl<'a> Parser<'a> { /// - `[u8, 5]` → suggests using `;`, return a Array type /// - `[u8 5]` → suggests using `;`, return a Array type /// Consider to add more cases in the future. - fn maybe_recover_array_ty_without_semi(&mut self, elt_ty: P<Ty>) -> PResult<'a, TyKind> { + fn maybe_recover_array_ty_without_semi(&mut self, elt_ty: Box<Ty>) -> PResult<'a, TyKind> { let span = self.token.span; let token_descr = super::token_descr(&self.token); let mut err = @@ -773,7 +772,13 @@ impl<'a> Parser<'a> { let decl = self.parse_fn_decl(|_| false, AllowPlus::No, recover_return_sign)?; let decl_span = span_start.to(self.prev_token.span); - Ok(TyKind::FnPtr(P(FnPtrTy { ext, safety, generic_params: params, decl, decl_span }))) + Ok(TyKind::FnPtr(Box::new(FnPtrTy { + ext, + safety, + generic_params: params, + decl, + decl_span, + }))) } /// Recover from function pointer types with a generic parameter list (e.g. `fn<'a>(&'a str)`). @@ -915,7 +920,7 @@ impl<'a> Parser<'a> { let path = self.parse_path_inner(PathStyle::Type, ty_generics)?; if self.eat(exp!(Bang)) { // Macro invocation in type position - Ok(TyKind::MacCall(P(MacCall { path, args: self.parse_delim_args()? }))) + Ok(TyKind::MacCall(Box::new(MacCall { path, args: self.parse_delim_args()? }))) } else if allow_plus == AllowPlus::Yes && self.check_plus() { // `Trait1 + Trait2 + 'a` self.parse_remaining_bounds_path(ThinVec::new(), path, lo, true, ast::Parens::No) @@ -1015,7 +1020,7 @@ impl<'a> Parser<'a> { let bound = GenericBound::Outlives(lt); if let ast::Parens::Yes = parens { // FIXME(Centril): Consider not erroring here and accepting `('lt)` instead, - // possibly introducing `GenericBound::Paren(P<GenericBound>)`? + // possibly introducing `GenericBound::Paren(Box<GenericBound>)`? self.recover_paren_lifetime(lo)?; } Ok(bound) @@ -1317,12 +1322,14 @@ impl<'a> Parser<'a> { segments: thin_vec![ast::PathSegment { ident: Ident::new(sym::Fn, fn_token_span), id: DUMMY_NODE_ID, - args: Some(P(ast::GenericArgs::Parenthesized(ast::ParenthesizedArgs { - span: args_lo.to(self.prev_token.span), - inputs: decl.inputs.iter().map(|a| a.ty.clone()).collect(), - inputs_span: args_lo.until(decl.output.span()), - output: decl.output.clone(), - }))), + args: Some(Box::new(ast::GenericArgs::Parenthesized( + ast::ParenthesizedArgs { + span: args_lo.to(self.prev_token.span), + inputs: decl.inputs.iter().map(|a| a.ty.clone()).collect(), + inputs_span: args_lo.until(decl.output.span()), + output: decl.output.clone(), + } + ))), }], tokens: None, }) @@ -1464,7 +1471,7 @@ impl<'a> Parser<'a> { } } - pub(super) fn mk_ty(&self, span: Span, kind: TyKind) -> P<Ty> { - P(Ty { kind, span, id: ast::DUMMY_NODE_ID, tokens: None }) + pub(super) fn mk_ty(&self, span: Span, kind: TyKind) -> Box<Ty> { + Box::new(Ty { kind, span, id: ast::DUMMY_NODE_ID, tokens: None }) } } diff --git a/compiler/rustc_parse/src/validate_attr.rs b/compiler/rustc_parse/src/validate_attr.rs index a7f8d3b9139..68ef6d6f32c 100644 --- a/compiler/rustc_parse/src/validate_attr.rs +++ b/compiler/rustc_parse/src/validate_attr.rs @@ -298,35 +298,42 @@ fn emit_malformed_attribute( suggestions.push(format!("#{inner}[{name}]")); } if let Some(descr) = template.list { - suggestions.push(format!("#{inner}[{name}({descr})]")); + for descr in descr { + suggestions.push(format!("#{inner}[{name}({descr})]")); + } } suggestions.extend(template.one_of.iter().map(|&word| format!("#{inner}[{name}({word})]"))); if let Some(descr) = template.name_value_str { - suggestions.push(format!("#{inner}[{name} = \"{descr}\"]")); + for descr in descr { + suggestions.push(format!("#{inner}[{name} = \"{descr}\"]")); + } } if should_warn(name) { psess.buffer_lint( ILL_FORMED_ATTRIBUTE_INPUT, span, ast::CRATE_NODE_ID, - BuiltinLintDiag::IllFormedAttributeInput { suggestions: suggestions.clone() }, + BuiltinLintDiag::IllFormedAttributeInput { + suggestions: suggestions.clone(), + docs: template.docs, + }, ); } else { suggestions.sort(); - psess - .dcx() - .struct_span_err(span, error_msg) - .with_span_suggestions( - span, - if suggestions.len() == 1 { - "must be of the form" - } else { - "the following are the possible correct uses" - }, - suggestions, - Applicability::HasPlaceholders, - ) - .emit(); + let mut err = psess.dcx().struct_span_err(span, error_msg).with_span_suggestions( + span, + if suggestions.len() == 1 { + "must be of the form" + } else { + "the following are the possible correct uses" + }, + suggestions, + Applicability::HasPlaceholders, + ); + if let Some(link) = template.docs { + err.note(format!("for more information, visit <{link}>")); + } + err.emit(); } } diff --git a/compiler/rustc_passes/messages.ftl b/compiler/rustc_passes/messages.ftl index 5654f8f5efc..eb03235de0c 100644 --- a/compiler/rustc_passes/messages.ftl +++ b/compiler/rustc_passes/messages.ftl @@ -29,7 +29,7 @@ passes_allow_incoherent_impl = `rustc_allow_incoherent_impl` attribute should be applied to impl items .label = the only currently supported targets are inherent methods -passes_allow_internal_unstable = +passes_macro_only_attribute = attribute should be applied to a macro .label = not a macro @@ -670,8 +670,8 @@ passes_rustc_std_internal_symbol = .label = not a function or static passes_rustc_unstable_feature_bound = - attribute should be applied to `impl` or free function outside of any `impl` or trait - .label = not an `impl` or free function + attribute should be applied to `impl`, trait or free function + .label = not an `impl`, trait or free function passes_should_be_applied_to_fn = attribute should be applied to a function definition diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index ef9c8dc8b13..165f8fe1995 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -207,6 +207,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> { Attribute::Parsed(AttributeKind::ConstContinue(attr_span)) => { self.check_const_continue(hir_id, *attr_span, target) } + Attribute::Parsed(AttributeKind::AllowInternalUnsafe(attr_span)) => { + self.check_allow_internal_unsafe(hir_id, *attr_span, span, target, attrs) + } Attribute::Parsed(AttributeKind::AllowInternalUnstable(_, first_span)) => { self.check_allow_internal_unstable(hir_id, *first_span, span, target, attrs) } @@ -413,7 +416,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> { // internal | sym::prelude_import | sym::panic_handler - | sym::allow_internal_unsafe | sym::lang | sym::needs_allocator | sym::default_lib_allocator @@ -561,7 +563,24 @@ impl<'tcx> CheckAttrVisitor<'tcx> { match target { Target::Fn | Target::Closure - | Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => {} + | Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => { + // `#[inline]` is ignored if the symbol must be codegened upstream because it's exported. + if let Some(did) = hir_id.as_owner() + && self.tcx.def_kind(did).has_codegen_attrs() + && kind != &InlineAttr::Never + { + let attrs = self.tcx.codegen_fn_attrs(did); + // Not checking naked as `#[inline]` is forbidden for naked functions anyways. + if attrs.contains_extern_indicator(self.tcx, did.into()) { + self.tcx.emit_node_span_lint( + UNUSED_ATTRIBUTES, + hir_id, + attr_span, + errors::InlineIgnoredForExported {}, + ); + } + } + } Target::Method(MethodKind::Trait { body: false }) | Target::ForeignFn => { self.tcx.emit_node_span_lint( UNUSED_ATTRIBUTES, @@ -588,23 +607,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> { self.dcx().emit_err(errors::InlineNotFnOrClosure { attr_span, defn_span }); } } - - // `#[inline]` is ignored if the symbol must be codegened upstream because it's exported. - if let Some(did) = hir_id.as_owner() - && self.tcx.def_kind(did).has_codegen_attrs() - && kind != &InlineAttr::Never - { - let attrs = self.tcx.codegen_fn_attrs(did); - // Not checking naked as `#[inline]` is forbidden for naked functions anyways. - if attrs.contains_extern_indicator() { - self.tcx.emit_node_span_lint( - UNUSED_ATTRIBUTES, - hir_id, - attr_span, - errors::InlineIgnoredForExported {}, - ); - } - } } /// Checks that `#[coverage(..)]` is applied to a function/closure/method, @@ -1155,8 +1157,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { let is_valid = doc_fake_variadic_is_allowed_self_ty(i.self_ty) || if let Some(&[hir::GenericArg::Type(ty)]) = i .of_trait - .as_ref() - .and_then(|trait_ref| trait_ref.path.segments.last()) + .and_then(|of_trait| of_trait.trait_ref.path.segments.last()) .map(|last_segment| last_segment.args().args) { matches!(&ty.kind, hir::TyKind::Tup([_])) @@ -1646,8 +1647,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> { && let parent_hir_id = self.tcx.parent_hir_id(hir_id) && let hir::Node::Item(item) = self.tcx.hir_node(parent_hir_id) && let hir::ItemKind::Impl(impl_) = item.kind - && let Some(trait_) = impl_.of_trait - && let Some(def_id) = trait_.trait_def_id() + && let Some(of_trait) = impl_.of_trait + && let Some(def_id) = of_trait.trait_ref.trait_def_id() && self.tcx.is_lang_item(def_id, hir::LangItem::Drop) { return; @@ -2212,7 +2213,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> { /// Outputs an error for `#[allow_internal_unstable]` which can only be applied to macros. /// (Allows proc_macro functions) - // FIXME(jdonszelmann): if possible, move to attr parsing fn check_allow_internal_unstable( &self, hir_id: HirId, @@ -2221,6 +2221,42 @@ impl<'tcx> CheckAttrVisitor<'tcx> { target: Target, attrs: &[Attribute], ) { + self.check_macro_only_attr( + hir_id, + attr_span, + span, + target, + attrs, + "allow_internal_unstable", + ) + } + + /// Outputs an error for `#[allow_internal_unsafe]` which can only be applied to macros. + /// (Allows proc_macro functions) + fn check_allow_internal_unsafe( + &self, + hir_id: HirId, + attr_span: Span, + span: Span, + target: Target, + attrs: &[Attribute], + ) { + self.check_macro_only_attr(hir_id, attr_span, span, target, attrs, "allow_internal_unsafe") + } + + /// Outputs an error for attributes that can only be applied to macros, such as + /// `#[allow_internal_unsafe]` and `#[allow_internal_unstable]`. + /// (Allows proc_macro functions) + // FIXME(jdonszelmann): if possible, move to attr parsing + fn check_macro_only_attr( + &self, + hir_id: HirId, + attr_span: Span, + span: Span, + target: Target, + attrs: &[Attribute], + attr_name: &str, + ) { match target { Target::Fn => { for attr in attrs { @@ -2238,18 +2274,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> { // erroneously allowed it and some crates used it accidentally, to be compatible // with crates depending on them, we can't throw an error here. Target::Field | Target::Arm => { - self.inline_attr_str_error_without_macro_def( - hir_id, - attr_span, - "allow_internal_unstable", - ); + self.inline_attr_str_error_without_macro_def(hir_id, attr_span, attr_name); return; } // otherwise continue out of the match _ => {} } - self.tcx.dcx().emit_err(errors::AllowInternalUnstable { attr_span, span }); + self.tcx.dcx().emit_err(errors::MacroOnlyAttribute { attr_span, span }); } /// Checks if the items on the `#[debugger_visualizer]` attribute are valid. @@ -2294,7 +2326,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { match target { // FIXME(staged_api): There's no reason we can't support more targets here. We're just // being conservative to begin with. - Target::Fn | Target::Impl { .. } => {} + Target::Fn | Target::Impl { .. } | Target::Trait => {} Target::ExternCrate | Target::Use | Target::Static @@ -2309,7 +2341,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> { | Target::Struct | Target::Field | Target::Union - | Target::Trait | Target::TraitAlias | Target::Expression | Target::Statement diff --git a/compiler/rustc_passes/src/dead.rs b/compiler/rustc_passes/src/dead.rs index fa9d0c7b1b7..de52973acbb 100644 --- a/compiler/rustc_passes/src/dead.rs +++ b/compiler/rustc_passes/src/dead.rs @@ -172,7 +172,6 @@ impl<'tcx> MarkSymbolVisitor<'tcx> { } } - #[allow(dead_code)] // FIXME(81658): should be used + lint reinstated after #83171 relands. fn handle_assign(&mut self, expr: &'tcx hir::Expr<'tcx>) { if self .typeck_results() @@ -189,7 +188,6 @@ impl<'tcx> MarkSymbolVisitor<'tcx> { } } - #[allow(dead_code)] // FIXME(81658): should be used + lint reinstated after #83171 relands. fn check_for_self_assign(&mut self, assign: &'tcx hir::Expr<'tcx>) { fn check_for_self_assign_helper<'tcx>( typeck_results: &'tcx ty::TypeckResults<'tcx>, @@ -576,6 +574,10 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> { hir::ExprKind::OffsetOf(..) => { self.handle_offset_of(expr); } + hir::ExprKind::Assign(ref lhs, ..) => { + self.handle_assign(lhs); + self.check_for_self_assign(expr); + } _ => (), } @@ -701,7 +703,7 @@ fn has_allow_dead_code_or_lang_attr( // #[used], #[no_mangle], #[export_name], etc also keeps the item alive // forcefully, e.g., for placing it in a specific section. - cg_attrs.contains_extern_indicator() + cg_attrs.contains_extern_indicator(tcx, def_id.into()) || cg_attrs.flags.contains(CodegenFnAttrFlags::USED_COMPILER) || cg_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER) } diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index e47181e0931..37216656e57 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -645,8 +645,8 @@ pub(crate) struct UsedStatic { } #[derive(Diagnostic)] -#[diag(passes_allow_internal_unstable)] -pub(crate) struct AllowInternalUnstable { +#[diag(passes_macro_only_attribute)] +pub(crate) struct MacroOnlyAttribute { #[primary_span] pub attr_span: Span, #[label] diff --git a/compiler/rustc_passes/src/input_stats.rs b/compiler/rustc_passes/src/input_stats.rs index 6ee325dce03..c83610da1aa 100644 --- a/compiler/rustc_passes/src/input_stats.rs +++ b/compiler/rustc_passes/src/input_stats.rs @@ -44,11 +44,11 @@ impl Node { /// For example, `ast::Visitor` has `visit_ident`, but `Ident`s are always /// stored inline within other AST nodes, so we don't implement `visit_ident` /// here. In contrast, we do implement `visit_expr` because `ast::Expr` is -/// always stored as `P<ast::Expr>`, and every such expression should be +/// always stored as `Box<ast::Expr>`, and every such expression should be /// measured separately. /// /// In general, a `visit_foo` method should be implemented here if the -/// corresponding `Foo` type is always stored on its own, e.g.: `P<Foo>`, +/// corresponding `Foo` type is always stored on its own, e.g.: `Box<Foo>`, /// `Box<Foo>`, `Vec<Foo>`, `Box<[Foo]>`. /// /// There are some types in the AST and HIR tree that the visitors do not have diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index 2f78c22c748..6cd8a54ecf4 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -183,7 +183,7 @@ impl<'tcx> ReachableContext<'tcx> { } else { CodegenFnAttrs::EMPTY }; - let is_extern = codegen_attrs.contains_extern_indicator(); + let is_extern = codegen_attrs.contains_extern_indicator(self.tcx, search_item.into()); if is_extern { self.reachable_symbols.insert(search_item); } @@ -423,8 +423,9 @@ fn has_custom_linkage(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool { if !tcx.def_kind(def_id).has_codegen_attrs() { return false; } + let codegen_attrs = tcx.codegen_fn_attrs(def_id); - codegen_attrs.contains_extern_indicator() + codegen_attrs.contains_extern_indicator(tcx, def_id.into()) // FIXME(nbdd0121): `#[used]` are marked as reachable here so it's picked up by // `linked_symbols` in cg_ssa. They won't be exported in binary or cdylib due to their // `SymbolExportLevel::Rust` export level but may end up being exported in dylibs. diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index c5056b9df76..71650c6b9b9 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -268,93 +268,51 @@ fn lookup_const_stability(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ConstSt None } -/// A private tree-walker for producing an `Index`. -struct Annotator<'tcx> { - tcx: TyCtxt<'tcx>, - implications: UnordMap<Symbol, Symbol>, -} - -impl<'tcx> Annotator<'tcx> { - /// Determine the stability for a node based on its attributes and inherited stability. The - /// stability is recorded in the index and used as the parent. If the node is a function, - /// `fn_sig` is its signature. - #[instrument(level = "trace", skip(self))] - fn annotate(&mut self, def_id: LocalDefId) { - if !self.tcx.features().staged_api() { - return; - } +fn stability_implications(tcx: TyCtxt<'_>, LocalCrate: LocalCrate) -> UnordMap<Symbol, Symbol> { + let mut implications = UnordMap::default(); - if let Some(stability) = self.tcx.lookup_stability(def_id) + let mut register_implication = |def_id| { + if let Some(stability) = tcx.lookup_stability(def_id) && let StabilityLevel::Unstable { implied_by: Some(implied_by), .. } = stability.level { - self.implications.insert(implied_by, stability.feature); + implications.insert(implied_by, stability.feature); } - if let Some(stability) = self.tcx.lookup_const_stability(def_id) + if let Some(stability) = tcx.lookup_const_stability(def_id) && let StabilityLevel::Unstable { implied_by: Some(implied_by), .. } = stability.level { - self.implications.insert(implied_by, stability.feature); + implications.insert(implied_by, stability.feature); } - } -} - -impl<'tcx> Visitor<'tcx> for Annotator<'tcx> { - /// Because stability levels are scoped lexically, we want to walk - /// nested items in the context of the outer item, so enable - /// deep-walking. - type NestedFilter = nested_filter::All; - - fn maybe_tcx(&mut self) -> Self::MaybeTyCtxt { - self.tcx - } + }; - fn visit_item(&mut self, i: &'tcx Item<'tcx>) { - match i.kind { - hir::ItemKind::Struct(_, _, ref sd) => { - if let Some(ctor_def_id) = sd.ctor_def_id() { - self.annotate(ctor_def_id); + if tcx.features().staged_api() { + register_implication(CRATE_DEF_ID); + for def_id in tcx.hir_crate_items(()).definitions() { + register_implication(def_id); + let def_kind = tcx.def_kind(def_id); + if def_kind.is_adt() { + let adt = tcx.adt_def(def_id); + for variant in adt.variants() { + if variant.def_id != def_id.to_def_id() { + register_implication(variant.def_id.expect_local()); + } + for field in &variant.fields { + register_implication(field.did.expect_local()); + } + if let Some(ctor_def_id) = variant.ctor_def_id() { + register_implication(ctor_def_id.expect_local()) + } + } + } + if def_kind.has_generics() { + for param in tcx.generics_of(def_id).own_params.iter() { + register_implication(param.def_id.expect_local()) } } - _ => {} - } - - self.annotate(i.owner_id.def_id); - intravisit::walk_item(self, i) - } - - fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem<'tcx>) { - self.annotate(ti.owner_id.def_id); - intravisit::walk_trait_item(self, ti); - } - - fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem<'tcx>) { - self.annotate(ii.owner_id.def_id); - intravisit::walk_impl_item(self, ii); - } - - fn visit_variant(&mut self, var: &'tcx Variant<'tcx>) { - self.annotate(var.def_id); - if let Some(ctor_def_id) = var.data.ctor_def_id() { - self.annotate(ctor_def_id); } - - intravisit::walk_variant(self, var) } - fn visit_field_def(&mut self, s: &'tcx FieldDef<'tcx>) { - self.annotate(s.def_id); - intravisit::walk_field_def(self, s); - } - - fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem<'tcx>) { - self.annotate(i.owner_id.def_id); - intravisit::walk_foreign_item(self, i); - } - - fn visit_generic_param(&mut self, p: &'tcx hir::GenericParam<'tcx>) { - self.annotate(p.def_id); - intravisit::walk_generic_param(self, p); - } + implications } struct MissingStabilityAnnotations<'tcx> { @@ -566,13 +524,6 @@ impl<'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'tcx> { } } -fn stability_implications(tcx: TyCtxt<'_>, LocalCrate: LocalCrate) -> UnordMap<Symbol, Symbol> { - let mut annotator = Annotator { tcx, implications: Default::default() }; - annotator.annotate(CRATE_DEF_ID); - tcx.hir_walk_toplevel_module(&mut annotator); - annotator.implications -} - /// Cross-references the feature names of unstable APIs with enabled /// features and possibly prints errors. fn check_mod_unstable_api_usage(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) { @@ -639,9 +590,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { // For implementations of traits, check the stability of each item // individually as it's possible to have a stable trait with unstable // items. - hir::ItemKind::Impl(hir::Impl { - of_trait: Some(t), self_ty, items, constness, .. - }) => { + hir::ItemKind::Impl(hir::Impl { of_trait: Some(of_trait), self_ty, items, .. }) => { let features = self.tcx.features(); if features.staged_api() { let attrs = self.tcx.hir_attrs(item.hir_id()); @@ -677,7 +626,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { { let mut c = CheckTraitImplStable { tcx: self.tcx, fully_stable: true }; c.visit_ty_unambig(self_ty); - c.visit_trait_ref(t); + c.visit_trait_ref(&of_trait.trait_ref); // Skip the lint if the impl is marked as unstable using // #[unstable_feature_bound(..)] @@ -690,7 +639,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { // do not lint when the trait isn't resolved, since resolution error should // be fixed first - if t.path.res != Res::Err + if of_trait.trait_ref.path.res != Res::Err && c.fully_stable && !unstable_feature_bound_in_effect { @@ -704,7 +653,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { } if features.const_trait_impl() - && let hir::Constness::Const = constness + && let hir::Constness::Const = of_trait.constness { let stable_or_implied_stable = match const_stab { None => true, @@ -720,7 +669,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { Some(_) => false, }; - if let Some(trait_id) = t.trait_def_id() + if let Some(trait_id) = of_trait.trait_ref.trait_def_id() && let Some(const_stab) = self.tcx.lookup_const_stability(trait_id) { // the const stability of a trait impl must match the const stability on the trait. @@ -748,14 +697,18 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> { } } - if let hir::Constness::Const = constness - && let Some(def_id) = t.trait_def_id() + if let hir::Constness::Const = of_trait.constness + && let Some(def_id) = of_trait.trait_ref.trait_def_id() { // FIXME(const_trait_impl): Improve the span here. - self.tcx.check_const_stability(def_id, t.path.span, t.path.span); + self.tcx.check_const_stability( + def_id, + of_trait.trait_ref.path.span, + of_trait.trait_ref.path.span, + ); } - for impl_item_ref in *items { + for impl_item_ref in items { let impl_item = self.tcx.associated_item(impl_item_ref.owner_id); if let Some(def_id) = impl_item.trait_item_def_id { diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 5d02c02b23c..1bddbd03cc3 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -1779,7 +1779,8 @@ fn check_mod_privacy(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) { if let DefKind::Impl { of_trait: true } = tcx.def_kind(def_id) { let trait_ref = tcx.impl_trait_ref(def_id).unwrap(); let trait_ref = trait_ref.instantiate_identity(); - visitor.span = tcx.hir_expect_item(def_id).expect_impl().of_trait.unwrap().path.span; + visitor.span = + tcx.hir_expect_item(def_id).expect_impl().of_trait.unwrap().trait_ref.path.span; let _ = visitor.visit_def_id(trait_ref.def_id, "trait", &trait_ref.print_only_trait_path()); } diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 2ad8543bf8c..3fee2ab6afe 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -11,7 +11,7 @@ use std::sync::Arc; use rustc_ast::visit::{self, AssocCtxt, Visitor, WalkItemKind}; use rustc_ast::{ self as ast, AssocItem, AssocItemKind, Block, ConstItem, Delegation, Fn, ForeignItem, - ForeignItemKind, Impl, Item, ItemKind, NodeId, StaticItem, StmtKind, TyAlias, + ForeignItemKind, Item, ItemKind, NodeId, StaticItem, StmtKind, TyAlias, }; use rustc_attr_parsing as attr; use rustc_attr_parsing::AttributeParser; @@ -420,14 +420,18 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> { // The fields are not expanded yet. return; } - let fields = fields + let field_name = |i, field: &ast::FieldDef| { + field.ident.unwrap_or_else(|| Ident::from_str_and_span(&format!("{i}"), field.span)) + }; + let field_names: Vec<_> = + fields.iter().enumerate().map(|(i, field)| field_name(i, field)).collect(); + let defaults = fields .iter() .enumerate() - .map(|(i, field)| { - field.ident.unwrap_or_else(|| Ident::from_str_and_span(&format!("{i}"), field.span)) - }) + .filter_map(|(i, field)| field.default.as_ref().map(|_| field_name(i, field).name)) .collect(); - self.r.field_names.insert(def_id, fields); + self.r.field_names.insert(def_id, field_names); + self.r.field_defaults.insert(def_id, defaults); } fn insert_field_visibilities_local(&mut self, def_id: DefId, fields: &[ast::FieldDef]) { @@ -902,10 +906,7 @@ impl<'a, 'ra, 'tcx> BuildReducedGraphVisitor<'a, 'ra, 'tcx> { } // These items do not add names to modules. - ItemKind::Impl(box Impl { of_trait: Some(..), .. }) - | ItemKind::Impl { .. } - | ItemKind::ForeignMod(..) - | ItemKind::GlobalAsm(..) => {} + ItemKind::Impl { .. } | ItemKind::ForeignMod(..) | ItemKind::GlobalAsm(..) => {} ItemKind::MacroDef(..) | ItemKind::MacCall(_) | ItemKind::DelegationMac(..) => { unreachable!() diff --git a/compiler/rustc_resolve/src/diagnostics.rs b/compiler/rustc_resolve/src/diagnostics.rs index 517e20e0619..210ab72678c 100644 --- a/compiler/rustc_resolve/src/diagnostics.rs +++ b/compiler/rustc_resolve/src/diagnostics.rs @@ -1,4 +1,3 @@ -use rustc_ast::ptr::P; use rustc_ast::visit::{self, Visitor}; use rustc_ast::{ self as ast, CRATE_NODE_ID, Crate, ItemKind, ModKind, NodeId, Path, join_path_idents, @@ -1944,8 +1943,15 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { } fn report_privacy_error(&mut self, privacy_error: &PrivacyError<'ra>) { - let PrivacyError { ident, binding, outermost_res, parent_scope, single_nested, dedup_span } = - *privacy_error; + let PrivacyError { + ident, + binding, + outermost_res, + parent_scope, + single_nested, + dedup_span, + ref source, + } = *privacy_error; let res = binding.res(); let ctor_fields_span = self.ctor_fields_span(binding); @@ -1961,6 +1967,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { let mut err = self.dcx().create_err(errors::IsPrivate { span: ident.span, ident_descr, ident }); + self.mention_default_field_values(source, ident, &mut err); + let mut not_publicly_reexported = false; if let Some((this_res, outer_ident)) = outermost_res { let import_suggestions = self.lookup_import_candidates( @@ -2142,6 +2150,85 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { err.emit(); } + /// When a private field is being set that has a default field value, we suggest using `..` and + /// setting the value of that field implicitly with its default. + /// + /// If we encounter code like + /// ```text + /// struct Priv; + /// pub struct S { + /// pub field: Priv = Priv, + /// } + /// ``` + /// which is used from a place where `Priv` isn't accessible + /// ```text + /// let _ = S { field: m::Priv1 {} }; + /// // ^^^^^ private struct + /// ``` + /// we will suggest instead using the `default_field_values` syntax instead: + /// ```text + /// let _ = S { .. }; + /// ``` + fn mention_default_field_values( + &self, + source: &Option<ast::Expr>, + ident: Ident, + err: &mut Diag<'_>, + ) { + let Some(expr) = source else { return }; + let ast::ExprKind::Struct(struct_expr) = &expr.kind else { return }; + // We don't have to handle type-relative paths because they're forbidden in ADT + // expressions, but that would change with `#[feature(more_qualified_paths)]`. + let Some(Res::Def(_, def_id)) = + self.partial_res_map[&struct_expr.path.segments.iter().last().unwrap().id].full_res() + else { + return; + }; + let Some(default_fields) = self.field_defaults(def_id) else { return }; + if struct_expr.fields.is_empty() { + return; + } + let last_span = struct_expr.fields.iter().last().unwrap().span; + let mut iter = struct_expr.fields.iter().peekable(); + let mut prev: Option<Span> = None; + while let Some(field) = iter.next() { + if field.expr.span.overlaps(ident.span) { + err.span_label(field.ident.span, "while setting this field"); + if default_fields.contains(&field.ident.name) { + let sugg = if last_span == field.span { + vec![(field.span, "..".to_string())] + } else { + vec![ + ( + // Account for trailing commas and ensure we remove them. + match (prev, iter.peek()) { + (_, Some(next)) => field.span.with_hi(next.span.lo()), + (Some(prev), _) => field.span.with_lo(prev.hi()), + (None, None) => field.span, + }, + String::new(), + ), + (last_span.shrink_to_hi(), ", ..".to_string()), + ] + }; + err.multipart_suggestion_verbose( + format!( + "the type `{ident}` of field `{}` is private, but you can construct \ + the default value defined for it in `{}` using `..` in the struct \ + initializer expression", + field.ident, + self.tcx.item_name(def_id), + ), + sugg, + Applicability::MachineApplicable, + ); + break; + } + } + prev = Some(field.span); + } + } + pub(crate) fn find_similarly_named_module_or_crate( &self, ident: Symbol, @@ -3347,7 +3434,7 @@ impl<'tcx> visit::Visitor<'tcx> for UsePlacementFinder { } } -fn search_for_any_use_in_items(items: &[P<ast::Item>]) -> Option<Span> { +fn search_for_any_use_in_items(items: &[Box<ast::Item>]) -> Option<Span> { for item in items { if let ItemKind::Use(..) = item.kind && is_span_suitable_for_use_injection(item.span) diff --git a/compiler/rustc_resolve/src/ident.rs b/compiler/rustc_resolve/src/ident.rs index 092bb6fc4f9..9efcef695b7 100644 --- a/compiler/rustc_resolve/src/ident.rs +++ b/compiler/rustc_resolve/src/ident.rs @@ -1029,6 +1029,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { binding, dedup_span: path_span, outermost_res: None, + source: None, parent_scope: *parent_scope, single_nested: path_span != root_span, }); @@ -1435,7 +1436,16 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { parent_scope: &ParentScope<'ra>, ignore_import: Option<Import<'ra>>, ) -> PathResult<'ra> { - self.resolve_path_with_ribs(path, opt_ns, parent_scope, None, None, None, ignore_import) + self.resolve_path_with_ribs( + path, + opt_ns, + parent_scope, + None, + None, + None, + None, + ignore_import, + ) } #[instrument(level = "debug", skip(self))] pub(crate) fn resolve_path<'r>( @@ -1451,6 +1461,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { path, opt_ns, parent_scope, + None, finalize, None, ignore_binding, @@ -1463,6 +1474,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { path: &[Segment], opt_ns: Option<Namespace>, // `None` indicates a module path in import parent_scope: &ParentScope<'ra>, + source: Option<PathSource<'_, '_, '_>>, finalize: Option<Finalize>, ribs: Option<&PerNS<Vec<Rib<'ra>>>>, ignore_binding: Option<NameBinding<'ra>>, @@ -1645,6 +1657,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { if finalize.is_some() { for error in &mut self.get_mut().privacy_errors[privacy_errors_len..] { error.outermost_res = Some((res, ident)); + error.source = match source { + Some(PathSource::Struct(Some(expr))) + | Some(PathSource::Expr(Some(expr))) => Some(expr.clone()), + _ => None, + }; } } diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index fb6f5725704..e52cbeb733a 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -12,7 +12,6 @@ use std::collections::BTreeSet; use std::collections::hash_map::Entry; use std::mem::{replace, swap, take}; -use rustc_ast::ptr::P; use rustc_ast::visit::{ AssocCtxt, BoundKind, FnCtxt, FnKind, Visitor, try_visit, visit_opt, walk_list, }; @@ -425,7 +424,7 @@ pub(crate) enum PathSource<'a, 'ast, 'ra> { /// Paths in path patterns `Path`. Pat, /// Paths in struct expressions and patterns `Path { .. }`. - Struct, + Struct(Option<&'a Expr>), /// Paths in tuple struct patterns `Path(..)`. TupleStruct(Span, &'ra [Span]), /// `m::A::B` in `<T as m::A>::B::C`. @@ -448,7 +447,7 @@ impl PathSource<'_, '_, '_> { match self { PathSource::Type | PathSource::Trait(_) - | PathSource::Struct + | PathSource::Struct(_) | PathSource::DefineOpaques => TypeNS, PathSource::Expr(..) | PathSource::Pat @@ -465,7 +464,7 @@ impl PathSource<'_, '_, '_> { PathSource::Type | PathSource::Expr(..) | PathSource::Pat - | PathSource::Struct + | PathSource::Struct(_) | PathSource::TupleStruct(..) | PathSource::ReturnTypeNotation => true, PathSource::Trait(_) @@ -482,7 +481,7 @@ impl PathSource<'_, '_, '_> { PathSource::Type => "type", PathSource::Trait(_) => "trait", PathSource::Pat => "unit struct, unit variant or constant", - PathSource::Struct => "struct, variant or union type", + PathSource::Struct(_) => "struct, variant or union type", PathSource::TraitItem(ValueNS, PathSource::TupleStruct(..)) | PathSource::TupleStruct(..) => "tuple struct or tuple variant", PathSource::TraitItem(ns, _) => match ns { @@ -577,7 +576,7 @@ impl PathSource<'_, '_, '_> { || matches!(res, Res::Def(DefKind::Const | DefKind::AssocConst, _)) } PathSource::TupleStruct(..) => res.expected_in_tuple_struct_pat(), - PathSource::Struct => matches!( + PathSource::Struct(_) => matches!( res, Res::Def( DefKind::Struct @@ -617,8 +616,8 @@ impl PathSource<'_, '_, '_> { (PathSource::Trait(_), false) => E0405, (PathSource::Type | PathSource::DefineOpaques, true) => E0573, (PathSource::Type | PathSource::DefineOpaques, false) => E0412, - (PathSource::Struct, true) => E0574, - (PathSource::Struct, false) => E0422, + (PathSource::Struct(_), true) => E0574, + (PathSource::Struct(_), false) => E0422, (PathSource::Expr(..), true) | (PathSource::Delegation, true) => E0423, (PathSource::Expr(..), false) | (PathSource::Delegation, false) => E0425, (PathSource::Pat | PathSource::TupleStruct(..), true) => E0532, @@ -670,7 +669,7 @@ pub(crate) struct UnnecessaryQualification<'ra> { #[derive(Default, Debug)] struct DiagMetadata<'ast> { /// The current trait's associated items' ident, used for diagnostic suggestions. - current_trait_assoc_items: Option<&'ast [P<AssocItem>]>, + current_trait_assoc_items: Option<&'ast [Box<AssocItem>]>, /// The current self type if inside an impl (used for better errors). current_self_type: Option<Ty>, @@ -720,7 +719,7 @@ struct DiagMetadata<'ast> { current_type_path: Option<&'ast Ty>, /// The current impl items (used to suggest). - current_impl_items: Option<&'ast [P<AssocItem>]>, + current_impl_items: Option<&'ast [Box<AssocItem>]>, /// When processing impl trait currently_processing_impl_trait: Option<(TraitRef, Ty)>, @@ -1483,11 +1482,13 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { path: &[Segment], opt_ns: Option<Namespace>, // `None` indicates a module path in import finalize: Option<Finalize>, + source: PathSource<'_, 'ast, 'ra>, ) -> PathResult<'ra> { self.r.cm().resolve_path_with_ribs( path, opt_ns, &self.parent_scope, + Some(source), finalize, Some(&self.ribs), None, @@ -1967,7 +1968,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { &mut self, partial_res: PartialRes, path: &[Segment], - source: PathSource<'_, '_, '_>, + source: PathSource<'_, 'ast, 'ra>, path_span: Span, ) { let proj_start = path.len() - partial_res.unresolved_segments(); @@ -2020,7 +2021,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { | PathSource::ReturnTypeNotation => false, PathSource::Expr(..) | PathSource::Pat - | PathSource::Struct + | PathSource::Struct(_) | PathSource::TupleStruct(..) | PathSource::DefineOpaques | PathSource::Delegation => true, @@ -2619,7 +2620,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { self.resolve_adt(item, generics); } - ItemKind::Impl(box Impl { + ItemKind::Impl(Impl { ref generics, ref of_trait, ref self_ty, @@ -2630,7 +2631,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { self.resolve_implementation( &item.attrs, generics, - of_trait, + of_trait.as_deref(), self_ty, item.id, impl_items, @@ -3038,7 +3039,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { } /// When evaluating a `trait` use its associated types' idents for suggestions in E0412. - fn resolve_trait_items(&mut self, trait_items: &'ast [P<AssocItem>]) { + fn resolve_trait_items(&mut self, trait_items: &'ast [Box<AssocItem>]) { let trait_assoc_items = replace(&mut self.diag_metadata.current_trait_assoc_items, Some(trait_items)); @@ -3176,10 +3177,10 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { &mut self, attrs: &[ast::Attribute], generics: &'ast Generics, - opt_trait_reference: &'ast Option<TraitRef>, + of_trait: Option<&'ast ast::TraitImplHeader>, self_type: &'ast Ty, item_id: NodeId, - impl_items: &'ast [P<AssocItem>], + impl_items: &'ast [Box<AssocItem>], ) { debug!("resolve_implementation"); // If applicable, create a rib for the type parameters. @@ -3200,7 +3201,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { |this| { // Resolve the trait reference, if necessary. this.with_optional_trait_ref( - opt_trait_reference.as_ref(), + of_trait.map(|t| &t.trait_ref), self_type, |this, trait_id| { this.resolve_doc_links(attrs, MaybeExported::Impl(trait_id)); @@ -3223,9 +3224,9 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { is_trait_impl: trait_id.is_some() }; this.with_self_rib(res, |this| { - if let Some(trait_ref) = opt_trait_reference.as_ref() { + if let Some(of_trait) = of_trait { // Resolve type arguments in the trait path. - visit::walk_trait_ref(this, trait_ref); + visit::walk_trait_ref(this, &of_trait.trait_ref); } // Resolve the self type. this.visit_ty(self_type); @@ -3671,7 +3672,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { /// pattern as a whole counts as a never pattern (since it's definitionallly unreachable). fn compute_and_check_or_pat_binding_map( &mut self, - pats: &[P<Pat>], + pats: &[Box<Pat>], ) -> Result<FxIndexMap<Ident, BindingInfo>, IsNeverPattern> { let mut missing_vars = FxIndexMap::default(); let mut inconsistent_vars = FxIndexMap::default(); @@ -3867,7 +3868,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { self.smart_resolve_path(pat.id, qself, path, PathSource::Pat); } PatKind::Struct(ref qself, ref path, ref _fields, ref rest) => { - self.smart_resolve_path(pat.id, qself, path, PathSource::Struct); + self.smart_resolve_path(pat.id, qself, path, PathSource::Struct(None)); self.record_patterns_with_skipped_bindings(pat, rest); } PatKind::Or(ref ps) => { @@ -4109,9 +4110,9 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { fn smart_resolve_path( &mut self, id: NodeId, - qself: &Option<P<QSelf>>, + qself: &Option<Box<QSelf>>, path: &Path, - source: PathSource<'_, 'ast, '_>, + source: PathSource<'_, 'ast, 'ra>, ) { self.smart_resolve_path_fragment( qself, @@ -4126,9 +4127,9 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { #[instrument(level = "debug", skip(self))] fn smart_resolve_path_fragment( &mut self, - qself: &Option<P<QSelf>>, + qself: &Option<Box<QSelf>>, path: &[Segment], - source: PathSource<'_, 'ast, '_>, + source: PathSource<'_, 'ast, 'ra>, finalize: Finalize, record_partial_res: RecordPartialRes, parent_qself: Option<&QSelf>, @@ -4366,7 +4367,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { std_path.push(Segment::from_ident(Ident::with_dummy_span(sym::std))); std_path.extend(path); if let PathResult::Module(_) | PathResult::NonModule(_) = - self.resolve_path(&std_path, Some(ns), None) + self.resolve_path(&std_path, Some(ns), None, source) { // Check if we wrote `str::from_utf8` instead of `std::str::from_utf8` let item_span = @@ -4434,13 +4435,13 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { // Resolve in alternative namespaces if resolution in the primary namespace fails. fn resolve_qpath_anywhere( &mut self, - qself: &Option<P<QSelf>>, + qself: &Option<Box<QSelf>>, path: &[Segment], primary_ns: Namespace, span: Span, defer_to_typeck: bool, finalize: Finalize, - source: PathSource<'_, 'ast, '_>, + source: PathSource<'_, 'ast, 'ra>, ) -> Result<Option<PartialRes>, Spanned<ResolutionError<'ra>>> { let mut fin_res = None; @@ -4485,11 +4486,11 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { /// Handles paths that may refer to associated items. fn resolve_qpath( &mut self, - qself: &Option<P<QSelf>>, + qself: &Option<Box<QSelf>>, path: &[Segment], ns: Namespace, finalize: Finalize, - source: PathSource<'_, 'ast, '_>, + source: PathSource<'_, 'ast, 'ra>, ) -> Result<Option<PartialRes>, Spanned<ResolutionError<'ra>>> { debug!( "resolve_qpath(qself={:?}, path={:?}, ns={:?}, finalize={:?})", @@ -4552,7 +4553,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { ))); } - let result = match self.resolve_path(path, Some(ns), Some(finalize)) { + let result = match self.resolve_path(path, Some(ns), Some(finalize), source) { PathResult::NonModule(path_res) => path_res, PathResult::Module(ModuleOrUniformRoot::Module(module)) if !module.is_normal() => { PartialRes::new(module.res().unwrap()) @@ -4775,7 +4776,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { } ExprKind::Struct(ref se) => { - self.smart_resolve_path(expr.id, &se.qself, &se.path, PathSource::Struct); + self.smart_resolve_path(expr.id, &se.qself, &se.path, PathSource::Struct(parent)); // This is the same as `visit::walk_expr(self, expr);`, but we want to pass the // parent in for accurate suggestions when encountering `Foo { bar }` that should // have been `Foo { bar: self.bar }`. @@ -5182,7 +5183,7 @@ impl<'ast> Visitor<'ast> for ItemInfoCollector<'_, '_, '_> { | ItemKind::Enum(_, generics, _) | ItemKind::Struct(_, generics, _) | ItemKind::Union(_, generics, _) - | ItemKind::Impl(box Impl { generics, .. }) + | ItemKind::Impl(Impl { generics, .. }) | ItemKind::Trait(box Trait { generics, .. }) | ItemKind::TraitAlias(_, generics, _) => { if let ItemKind::Fn(box Fn { sig, .. }) = &item.kind { diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index 19cd45294eb..aca251da71d 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -4,7 +4,6 @@ use std::borrow::Cow; use std::iter; use std::ops::Deref; -use rustc_ast::ptr::P; use rustc_ast::visit::{FnCtxt, FnKind, LifetimeCtxt, Visitor, walk_ty}; use rustc_ast::{ self as ast, AssocItemKind, DUMMY_NODE_ID, Expr, ExprKind, GenericParam, GenericParamKind, @@ -175,7 +174,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { &mut self, path: &[Segment], span: Span, - source: PathSource<'_, '_, '_>, + source: PathSource<'_, 'ast, 'ra>, res: Option<Res>, ) -> BaseError { // Make the base error. @@ -319,7 +318,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { (String::new(), "the crate root".to_string(), Some(CRATE_DEF_ID.to_def_id()), None) } else { let mod_path = &path[..path.len() - 1]; - let mod_res = self.resolve_path(mod_path, Some(TypeNS), None); + let mod_res = self.resolve_path(mod_path, Some(TypeNS), None, source); let mod_prefix = match mod_res { PathResult::Module(ModuleOrUniformRoot::Module(module)) => module.res(), _ => None, @@ -420,7 +419,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { path: &[Segment], following_seg: Option<&Segment>, span: Span, - source: PathSource<'_, '_, '_>, + source: PathSource<'_, 'ast, 'ra>, res: Option<Res>, qself: Option<&QSelf>, ) -> (Diag<'tcx>, Vec<ImportSuggestion>) { @@ -1015,7 +1014,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { fn suggest_typo( &mut self, err: &mut Diag<'_>, - source: PathSource<'_, '_, '_>, + source: PathSource<'_, 'ast, 'ra>, path: &[Segment], following_seg: Option<&Segment>, span: Span, @@ -1334,7 +1333,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { fn suggest_swapping_misplaced_self_ty_and_trait( &mut self, err: &mut Diag<'_>, - source: PathSource<'_, '_, '_>, + source: PathSource<'_, 'ast, 'ra>, res: Option<Res>, span: Span, ) { @@ -1342,7 +1341,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { self.diag_metadata.currently_processing_impl_trait.clone() && let TyKind::Path(_, self_ty_path) = &self_ty.kind && let PathResult::Module(ModuleOrUniformRoot::Module(module)) = - self.resolve_path(&Segment::from_path(self_ty_path), Some(TypeNS), None) + self.resolve_path(&Segment::from_path(self_ty_path), Some(TypeNS), None, source) && let ModuleKind::Def(DefKind::Trait, ..) = module.kind && trait_ref.path.span == span && let PathSource::Trait(_) = source @@ -1450,13 +1449,13 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { fn get_single_associated_item( &mut self, path: &[Segment], - source: &PathSource<'_, '_, '_>, + source: &PathSource<'_, 'ast, 'ra>, filter_fn: &impl Fn(Res) -> bool, ) -> Option<TypoSuggestion> { if let crate::PathSource::TraitItem(_, _) = source { let mod_path = &path[..path.len() - 1]; if let PathResult::Module(ModuleOrUniformRoot::Module(module)) = - self.resolve_path(mod_path, None, None) + self.resolve_path(mod_path, None, None, *source) { let targets: Vec<_> = self .r @@ -1855,7 +1854,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { PathSource::Expr(Some(Expr { kind: ExprKind::Index(..) | ExprKind::Call(..), .. })) - | PathSource::Struct, + | PathSource::Struct(_), ) => { // Don't suggest macro if it's unstable. let suggestable = def_id.is_local() @@ -2150,7 +2149,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { err: &mut Diag<'_>, path_span: Span, call_span: Span, - args: &[P<Expr>], + args: &[Box<Expr>], ) { if def_id.is_local() { // Doing analysis on local `DefId`s would cause infinite recursion. @@ -2503,7 +2502,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { // Search in module. let mod_path = &path[..path.len() - 1]; if let PathResult::Module(ModuleOrUniformRoot::Module(module)) = - self.resolve_path(mod_path, Some(TypeNS), None) + self.resolve_path(mod_path, Some(TypeNS), None, PathSource::Type) { self.r.add_module_candidates(module, &mut names, &filter_fn, None); } @@ -3674,7 +3673,12 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { if let TyKind::Path(None, path) = &ty.kind { // Check if the path being borrowed is likely to be owned. let path: Vec<_> = Segment::from_path(path); - match self.resolve_path(&path, Some(TypeNS), None) { + match self.resolve_path( + &path, + Some(TypeNS), + None, + PathSource::Type, + ) { PathResult::Module(ModuleOrUniformRoot::Module(module)) => { match module.res() { Some(Res::PrimTy(PrimTy::Str)) => { @@ -3788,7 +3792,7 @@ fn mk_where_bound_predicate( ident: last.ident, gen_args: None, kind: ast::AssocItemConstraintKind::Equality { - term: ast::Term::Ty(ast::ptr::P(ast::Ty { + term: ast::Term::Ty(Box::new(ast::Ty { kind: ast::TyKind::Path(None, poly_trait_ref.trait_ref.path.clone()), id: DUMMY_NODE_ID, span: DUMMY_SP, @@ -3805,7 +3809,7 @@ fn mk_where_bound_predicate( Some(_) => return None, None => { second_last.args = - Some(ast::ptr::P(ast::GenericArgs::AngleBracketed(ast::AngleBracketedArgs { + Some(Box::new(ast::GenericArgs::AngleBracketed(ast::AngleBracketedArgs { args: ThinVec::from([added_constraint]), span: DUMMY_SP, }))); @@ -3818,7 +3822,7 @@ fn mk_where_bound_predicate( let new_where_bound_predicate = ast::WhereBoundPredicate { bound_generic_params: ThinVec::new(), - bounded_ty: ast::ptr::P(ty.clone()), + bounded_ty: Box::new(ty.clone()), bounds: vec![ast::GenericBound::Trait(ast::PolyTraitRef { bound_generic_params: ThinVec::new(), modifiers: ast::TraitBoundModifiers::NONE, diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index 23f44ff1658..b43f71913d9 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -822,6 +822,7 @@ struct PrivacyError<'ra> { parent_scope: ParentScope<'ra>, /// Is the format `use a::{b,c}`? single_nested: bool, + source: Option<ast::Expr>, } #[derive(Debug)] @@ -1064,6 +1065,7 @@ pub struct Resolver<'ra, 'tcx> { /// N.B., this is used only for better diagnostics, not name resolution itself. field_names: LocalDefIdMap<Vec<Ident>>, + field_defaults: LocalDefIdMap<Vec<Symbol>>, /// Span of the privacy modifier in fields of an item `DefId` accessible with dot syntax. /// Used for hints during error reporting. @@ -1538,6 +1540,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { extern_prelude, field_names: Default::default(), + field_defaults: Default::default(), field_visibility_spans: FxHashMap::default(), determined_imports: Vec::new(), @@ -2318,6 +2321,21 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> { } } + fn field_defaults(&self, def_id: DefId) -> Option<Vec<Symbol>> { + match def_id.as_local() { + Some(def_id) => self.field_defaults.get(&def_id).cloned(), + None => Some( + self.tcx + .associated_item_def_ids(def_id) + .iter() + .filter_map(|&def_id| { + self.tcx.default_field(def_id).map(|_| self.tcx.item_name(def_id)) + }) + .collect(), + ), + } + } + /// Checks if an expression refers to a function marked with /// `#[rustc_legacy_const_generics]` and returns the argument index list /// from the attribute. diff --git a/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs b/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs index 52717d73b8a..d81fa062e01 100644 --- a/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs +++ b/compiler/rustc_sanitizers/src/cfi/typeid/itanium_cxx_abi/transform.rs @@ -342,7 +342,7 @@ pub(crate) fn transform_instance<'tcx>( let upcast_ty = match tcx.trait_of_assoc(def_id) { Some(trait_id) => trait_object_ty( tcx, - ty::Binder::dummy(ty::TraitRef::from_method(tcx, trait_id, instance.args)), + ty::Binder::dummy(ty::TraitRef::from_assoc(tcx, trait_id, instance.args)), ), // drop_in_place won't have a defining trait, skip the upcast None => instance.args.type_at(0), @@ -481,7 +481,7 @@ fn implemented_method<'tcx>( trait_method = trait_method_bound; method_id = instance.def_id(); trait_id = tcx.trait_of_assoc(method_id)?; - trait_ref = ty::EarlyBinder::bind(TraitRef::from_method(tcx, trait_id, instance.args)); + trait_ref = ty::EarlyBinder::bind(TraitRef::from_assoc(tcx, trait_id, instance.args)); trait_id } else { return None; diff --git a/compiler/rustc_symbol_mangling/src/export.rs b/compiler/rustc_symbol_mangling/src/export.rs index 956c996326b..76ac82cf95a 100644 --- a/compiler/rustc_symbol_mangling/src/export.rs +++ b/compiler/rustc_symbol_mangling/src/export.rs @@ -21,7 +21,7 @@ macro_rules! default_hash_impl { }; } -default_hash_impl! { i8, i16, i32, i64, i128, isize, u8, u16, u32, u64, u128, usize, } +default_hash_impl! { u8, u64, usize, } impl<'tcx> AbiHashStable<'tcx> for bool { #[inline] @@ -37,13 +37,6 @@ impl<'tcx> AbiHashStable<'tcx> for str { } } -impl<'tcx> AbiHashStable<'tcx> for String { - #[inline] - fn abi_hash(&self, tcx: TyCtxt<'tcx>, hasher: &mut StableHasher) { - self[..].abi_hash(tcx, hasher); - } -} - impl<'tcx> AbiHashStable<'tcx> for Symbol { #[inline] fn abi_hash(&self, tcx: TyCtxt<'tcx>, hasher: &mut StableHasher) { diff --git a/compiler/rustc_symbol_mangling/src/lib.rs b/compiler/rustc_symbol_mangling/src/lib.rs index 6bcb7f6e093..f3c96f64190 100644 --- a/compiler/rustc_symbol_mangling/src/lib.rs +++ b/compiler/rustc_symbol_mangling/src/lib.rs @@ -218,32 +218,33 @@ fn compute_symbol_name<'tcx>( } } - // Foreign items by default use no mangling for their symbol name. There's a - // few exceptions to this rule though: - // - // * This can be overridden with the `#[link_name]` attribute - // - // * On the wasm32 targets there is a bug (or feature) in LLD [1] where the - // same-named symbol when imported from different wasm modules will get - // hooked up incorrectly. As a result foreign symbols, on the wasm target, - // with a wasm import module, get mangled. Additionally our codegen will - // deduplicate symbols based purely on the symbol name, but for wasm this - // isn't quite right because the same-named symbol on wasm can come from - // different modules. For these reasons if `#[link(wasm_import_module)]` - // is present we mangle everything on wasm because the demangled form will - // show up in the `wasm-import-name` custom attribute in LLVM IR. - // - // * `#[rustc_std_internal_symbol]` mangles the symbol name in a special way - // both for exports and imports through foreign items. This is handled above. - // [1]: https://bugs.llvm.org/show_bug.cgi?id=44316 - if tcx.is_foreign_item(def_id) - && (!tcx.sess.target.is_like_wasm - || !tcx.wasm_import_module_map(def_id.krate).contains_key(&def_id)) + let wasm_import_module_exception_force_mangling = { + // * On the wasm32 targets there is a bug (or feature) in LLD [1] where the + // same-named symbol when imported from different wasm modules will get + // hooked up incorrectly. As a result foreign symbols, on the wasm target, + // with a wasm import module, get mangled. Additionally our codegen will + // deduplicate symbols based purely on the symbol name, but for wasm this + // isn't quite right because the same-named symbol on wasm can come from + // different modules. For these reasons if `#[link(wasm_import_module)]` + // is present we mangle everything on wasm because the demangled form will + // show up in the `wasm-import-name` custom attribute in LLVM IR. + // + // [1]: https://bugs.llvm.org/show_bug.cgi?id=44316 + // + // So, on wasm if a foreign item loses its `#[no_mangle]`, it might *still* + // be mangled if we're forced to. Note: I don't like this. + // These kinds of exceptions should be added during the `codegen_attrs` query. + // However, we don't have the wasm import module map there yet. + tcx.is_foreign_item(def_id) + && tcx.sess.target.is_like_wasm + && tcx.wasm_import_module_map(LOCAL_CRATE).contains_key(&def_id.into()) + }; + + if let Some(name) = attrs.link_name + && !wasm_import_module_exception_force_mangling { - if let Some(name) = attrs.link_name { - return name.to_string(); - } - return tcx.item_name(def_id).to_string(); + // Use provided name + return name.to_string(); } if let Some(name) = attrs.export_name { @@ -251,7 +252,9 @@ fn compute_symbol_name<'tcx>( return name.to_string(); } - if attrs.flags.contains(CodegenFnAttrFlags::NO_MANGLE) { + if attrs.flags.contains(CodegenFnAttrFlags::NO_MANGLE) + && !wasm_import_module_exception_force_mangling + { // Don't mangle return tcx.item_name(def_id).to_string(); } diff --git a/compiler/rustc_target/src/spec/base/apple/mod.rs b/compiler/rustc_target/src/spec/base/apple/mod.rs index da9f96ce37d..ecc74264160 100644 --- a/compiler/rustc_target/src/spec/base/apple/mod.rs +++ b/compiler/rustc_target/src/spec/base/apple/mod.rs @@ -1,5 +1,4 @@ use std::borrow::Cow; -use std::env; use std::fmt::{Display, from_fn}; use std::num::ParseIntError; use std::str::FromStr; @@ -209,29 +208,10 @@ fn link_env_remove(os: &'static str) -> StaticCow<[StaticCow<str>]> { // that's only applicable to cross-OS compilation. Always leave anything for the // host OS alone though. if os == "macos" { - let mut env_remove = Vec::with_capacity(2); - // Remove the `SDKROOT` environment variable if it's clearly set for the wrong platform, which - // may occur when we're linking a custom build script while targeting iOS for example. - if let Ok(sdkroot) = env::var("SDKROOT") { - if sdkroot.contains("iPhoneOS.platform") - || sdkroot.contains("iPhoneSimulator.platform") - || sdkroot.contains("AppleTVOS.platform") - || sdkroot.contains("AppleTVSimulator.platform") - || sdkroot.contains("WatchOS.platform") - || sdkroot.contains("WatchSimulator.platform") - || sdkroot.contains("XROS.platform") - || sdkroot.contains("XRSimulator.platform") - { - env_remove.push("SDKROOT".into()) - } - } - // Additionally, `IPHONEOS_DEPLOYMENT_TARGET` must not be set when using the Xcode linker at + // `IPHONEOS_DEPLOYMENT_TARGET` must not be set when using the Xcode linker at // "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld", // although this is apparently ignored when using the linker at "/usr/bin/ld". - env_remove.push("IPHONEOS_DEPLOYMENT_TARGET".into()); - env_remove.push("TVOS_DEPLOYMENT_TARGET".into()); - env_remove.push("XROS_DEPLOYMENT_TARGET".into()); - env_remove.into() + cvs!["IPHONEOS_DEPLOYMENT_TARGET", "TVOS_DEPLOYMENT_TARGET", "XROS_DEPLOYMENT_TARGET"] } else { // Otherwise if cross-compiling for a different OS/SDK (including Mac Catalyst), remove any part // of the linking environment that's wrong and reversed. diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs index 1c890821b1d..8551780bcd5 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/mod.rs @@ -459,7 +459,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { span, format!("this is an iterator with items of type `{}`", args.type_at(0)), ); - } else { + } else if !span.overlaps(cause.span) { let expected_ty = self.tcx.short_string(expected_ty, err.long_ty_path()); err.span_label(span, format!("this expression has type `{expected_ty}`")); } diff --git a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs index 374e1f67930..bc8c8a44405 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs @@ -738,7 +738,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { get_name(err, &local.pat.kind) } // Different to previous arm because one is `&hir::Local` and the other - // is `P<hir::Local>`. + // is `Box<hir::Local>`. hir::Node::LetStmt(local) => get_name(err, &local.pat.kind), _ => None, } @@ -3471,8 +3471,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { .. })) => { let mut spans = Vec::with_capacity(2); - if let Some(trait_ref) = of_trait { - spans.push(trait_ref.path.span); + if let Some(of_trait) = of_trait { + spans.push(of_trait.trait_ref.path.span); } spans.push(self_ty.span); let mut spans: MultiSpan = spans.into(); @@ -3480,7 +3480,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { self_ty.span.ctxt().outer_expn_data().kind, ExpnKind::Macro(MacroKind::Derive, _) ) || matches!( - of_trait.as_ref().map(|t| t.path.span.ctxt().outer_expn_data().kind), + of_trait.map(|t| t.trait_ref.path.span.ctxt().outer_expn_data().kind), Some(ExpnKind::Macro(MacroKind::Derive, _)) ) { spans.push_span_label( @@ -3592,7 +3592,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> { .. })) => { let mut spans = vec![self_ty.span]; - spans.extend(of_trait.as_ref().map(|t| t.path.span)); + spans.extend(of_trait.map(|t| t.trait_ref.path.span)); let mut spans: MultiSpan = spans.into(); spans.push_span_label(data.span, "unsatisfied trait bound introduced here"); err.span_note(spans, msg); diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 08315dbd21f..a9fb16b8000 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -763,7 +763,7 @@ fn instantiate_and_check_impossible_predicates<'tcx>( // Specifically check trait fulfillment to avoid an error when trying to resolve // associated items. if let Some(trait_def_id) = tcx.trait_of_assoc(key.0) { - let trait_ref = ty::TraitRef::from_method(tcx, trait_def_id, key.1); + let trait_ref = ty::TraitRef::from_assoc(tcx, trait_def_id, key.1); predicates.push(trait_ref.upcast(tcx)); } diff --git a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs index b1b331d1b61..de404532899 100644 --- a/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs +++ b/compiler/rustc_trait_selection/src/traits/query/dropck_outlives.rs @@ -319,39 +319,65 @@ pub fn dtorck_constraint_for_ty_inner<'tcx>( } ty::Coroutine(def_id, args) => { - // rust-lang/rust#49918: types can be constructed, stored - // in the interior, and sit idle when coroutine yields - // (and is subsequently dropped). + // rust-lang/rust#49918: Locals can be stored across await points in the coroutine, + // called interior/witness types. Since we do not compute these witnesses until after + // building MIR, we consider all coroutines to unconditionally require a drop during + // MIR building. However, considering the coroutine to unconditionally require a drop + // here may unnecessarily require its upvars' regions to be live when they don't need + // to be, leading to borrowck errors: <https://github.com/rust-lang/rust/issues/116242>. // - // It would be nice to descend into interior of a - // coroutine to determine what effects dropping it might - // have (by looking at any drop effects associated with - // its interior). + // Here, we implement a more precise approximation for the coroutine's dtorck constraint + // by considering whether any of the interior types needs drop. Note that this is still + // an approximation because the coroutine interior has its regions erased, so we must add + // *all* of the upvars to live types set if we find that *any* interior type needs drop. + // This is because any of the regions captured in the upvars may be stored in the interior, + // which then has its regions replaced by a binder (conceptually erasing the regions), + // so there's no way to enforce that the precise region in the interior type is live + // since we've lost that information by this point. // - // However, the interior's representation uses things like - // CoroutineWitness that explicitly assume they are not - // traversed in such a manner. So instead, we will - // simplify things for now by treating all coroutines as - // if they were like trait objects, where its upvars must - // all be alive for the coroutine's (potential) - // destructor. + // Note also that this check requires that the coroutine's upvars are use-live, since + // a region from a type that does not have a destructor that was captured in an upvar + // may flow into an interior type with a destructor. This is stronger than requiring + // the upvars are drop-live. // - // In particular, skipping over `_interior` is safe - // because any side-effects from dropping `_interior` can - // only take place through references with lifetimes - // derived from lifetimes attached to the upvars and resume - // argument, and we *do* incorporate those here. + // For example, if we capture two upvar references `&'1 (), &'2 ()` and have some type + // in the interior, `for<'r> { NeedsDrop<'r> }`, we have no way to tell whether the + // region `'r` came from the `'1` or `'2` region, so we require both are live. This + // could even be unnecessary if `'r` was actually a `'static` region or some region + // local to the coroutine! That's why it's an approximation. let args = args.as_coroutine(); - // While we conservatively assume that all coroutines require drop - // to avoid query cycles during MIR building, we can check the actual - // witness during borrowck to avoid unnecessary liveness constraints. + // Note that we don't care about whether the resume type has any drops since this is + // redundant; there is no storage for the resume type, so if it is actually stored + // in the interior, we'll already detect the need for a drop by checking the interior. let typing_env = tcx.erase_regions(typing_env); - if tcx.mir_coroutine_witnesses(def_id).is_some_and(|witness| { + let needs_drop = tcx.mir_coroutine_witnesses(def_id).is_some_and(|witness| { witness.field_tys.iter().any(|field| field.ty.needs_drop(tcx, typing_env)) - }) { + }); + if needs_drop { + // Pushing types directly to `constraints.outlives` is equivalent + // to requiring them to be use-live, since if we were instead to + // recurse on them like we do below, we only end up collecting the + // types that are relevant for drop-liveness. constraints.outlives.extend(args.upvar_tys().iter().map(ty::GenericArg::from)); constraints.outlives.push(args.resume_ty().into()); + } else { + // Even if a witness type doesn't need a drop, we still require that + // the upvars are drop-live. This is only needed if we aren't already + // counting *all* of the upvars as use-live above, since use-liveness + // is a *stronger requirement* than drop-liveness. Recursing here + // unconditionally would just be collecting duplicated types for no + // reason. + for ty in args.upvar_tys() { + dtorck_constraint_for_ty_inner( + tcx, + typing_env, + span, + depth + 1, + ty, + constraints, + ); + } } } diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index 7ea1548f8f2..468c42abf48 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -2333,10 +2333,23 @@ impl<'tcx> SelectionContext<'_, 'tcx> { ty::Coroutine(def_id, args) => { let ty = self.infcx.shallow_resolve(args.as_coroutine().tupled_upvars_ty()); + let tcx = self.tcx(); let witness = Ty::new_coroutine_witness( - self.tcx(), + tcx, def_id, - self.tcx().mk_args(args.as_coroutine().parent_args()), + ty::GenericArgs::for_item(tcx, def_id, |def, _| match def.kind { + // HACK: Coroutine witnesse types are lifetime erased, so they + // never reference any lifetime args from the coroutine. We erase + // the regions here since we may get into situations where a + // coroutine is recursively contained within itself, leading to + // witness types that differ by region args. This means that + // cycle detection in fulfillment will not kick in, which leads + // to unnecessary overflows in async code. See the issue: + // <https://github.com/rust-lang/rust/issues/145151>. + ty::GenericParamDefKind::Lifetime => tcx.lifetimes.re_erased.into(), + ty::GenericParamDefKind::Type { .. } + | ty::GenericParamDefKind::Const { .. } => args[def.index as usize], + }), ); ty::Binder::dummy(AutoImplConstituents { types: [ty].into_iter().chain(iter::once(witness)).collect(), diff --git a/compiler/rustc_ty_utils/src/assoc.rs b/compiler/rustc_ty_utils/src/assoc.rs index 37cb64511c7..e9629e31482 100644 --- a/compiler/rustc_ty_utils/src/assoc.rs +++ b/compiler/rustc_ty_utils/src/assoc.rs @@ -174,10 +174,10 @@ fn associated_types_for_impl_traits_in_trait_or_impl<'tcx>( }) .collect(), ItemKind::Impl(impl_) => { - let Some(trait_ref) = impl_.of_trait else { + let Some(of_trait) = impl_.of_trait else { return Default::default(); }; - let Some(trait_def_id) = trait_ref.trait_def_id() else { + let Some(trait_def_id) = of_trait.trait_ref.trait_def_id() else { return Default::default(); }; let in_trait_def = tcx.associated_types_for_impl_traits_in_trait_or_impl(trait_def_id); diff --git a/compiler/rustc_ty_utils/src/implied_bounds.rs b/compiler/rustc_ty_utils/src/implied_bounds.rs index 6fa763f18ef..cdfb93c4e7d 100644 --- a/compiler/rustc_ty_utils/src/implied_bounds.rs +++ b/compiler/rustc_ty_utils/src/implied_bounds.rs @@ -172,10 +172,12 @@ fn impl_spans(tcx: TyCtxt<'_>, def_id: LocalDefId) -> impl Iterator<Item = Span> let trait_args = impl_ .of_trait .into_iter() - .flat_map(|trait_ref| trait_ref.path.segments.last().unwrap().args().args) + .flat_map(|of_trait| of_trait.trait_ref.path.segments.last().unwrap().args().args) .map(|arg| arg.span()); - let dummy_spans_for_default_args = - impl_.of_trait.into_iter().flat_map(|trait_ref| iter::repeat(trait_ref.path.span)); + let dummy_spans_for_default_args = impl_ + .of_trait + .into_iter() + .flat_map(|of_trait| iter::repeat(of_trait.trait_ref.path.span)); iter::once(impl_.self_ty.span).chain(trait_args).chain(dummy_spans_for_default_args) } else { bug!("unexpected item for impl {def_id:?}: {item:?}") diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index e6c3568620b..5c3f7d491a5 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -109,7 +109,7 @@ fn resolve_associated_item<'tcx>( ) -> Result<Option<Instance<'tcx>>, ErrorGuaranteed> { debug!(?trait_item_id, ?typing_env, ?trait_id, ?rcvr_args, "resolve_associated_item"); - let trait_ref = ty::TraitRef::from_method(tcx, trait_id, rcvr_args); + let trait_ref = ty::TraitRef::from_assoc(tcx, trait_id, rcvr_args); let input = typing_env.as_query_input(trait_ref); let vtbl = match tcx.codegen_select_candidate(input) { @@ -238,7 +238,7 @@ fn resolve_associated_item<'tcx>( Some(ty::Instance::new_raw(leaf_def.item.def_id, args)) } traits::ImplSource::Builtin(BuiltinImplSource::Object(_), _) => { - let trait_ref = ty::TraitRef::from_method(tcx, trait_id, rcvr_args); + let trait_ref = ty::TraitRef::from_assoc(tcx, trait_id, rcvr_args); if trait_ref.has_non_region_infer() || trait_ref.has_non_region_param() { // We only resolve totally substituted vtable entries. None diff --git a/compiler/rustc_ty_utils/src/sig_types.rs b/compiler/rustc_ty_utils/src/sig_types.rs index dc6009116ac..d95660810e5 100644 --- a/compiler/rustc_ty_utils/src/sig_types.rs +++ b/compiler/rustc_ty_utils/src/sig_types.rs @@ -87,7 +87,7 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>( DefKind::InlineConst | DefKind::Closure | DefKind::SyntheticCoroutineBody => {} DefKind::Impl { of_trait } => { if of_trait { - let span = tcx.hir_node_by_def_id(item).expect_item().expect_impl().of_trait.unwrap().path.span; + let span = tcx.hir_node_by_def_id(item).expect_item().expect_impl().of_trait.unwrap().trait_ref.path.span; let args = &tcx.impl_trait_ref(item).unwrap().instantiate_identity().args[1..]; try_visit!(visitor.visit(span, args)); } diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index 2e0b16d9227..b22c326b9f2 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -81,7 +81,11 @@ fn sizedness_constraint_for_ty<'tcx>( fn defaultness(tcx: TyCtxt<'_>, def_id: LocalDefId) -> hir::Defaultness { match tcx.hir_node_by_def_id(def_id) { hir::Node::Item(hir::Item { - kind: hir::ItemKind::Impl(hir::Impl { defaultness, of_trait: Some(_), .. }), + kind: + hir::ItemKind::Impl(hir::Impl { + of_trait: Some(hir::TraitImplHeader { defaultness, .. }), + .. + }), .. }) | hir::Node::ImplItem(hir::ImplItem { defaultness, .. }) diff --git a/compiler/rustc_type_ir/src/binder.rs b/compiler/rustc_type_ir/src/binder.rs index 10d48526fd2..6591d3148cb 100644 --- a/compiler/rustc_type_ir/src/binder.rs +++ b/compiler/rustc_type_ir/src/binder.rs @@ -1,5 +1,3 @@ -use std::fmt::Debug; -use std::hash::Hash; use std::marker::PhantomData; use std::ops::{ControlFlow, Deref}; @@ -23,18 +21,16 @@ use crate::{self as ty, Interner}; /// for more details. /// /// `Decodable` and `Encodable` are implemented for `Binder<T>` using the `impl_binder_encode_decode!` macro. -#[derive_where(Clone; I: Interner, T: Clone)] +#[derive_where(Clone, Hash, PartialEq, Debug; I: Interner, T)] #[derive_where(Copy; I: Interner, T: Copy)] -#[derive_where(Hash; I: Interner, T: Hash)] -#[derive_where(PartialEq; I: Interner, T: PartialEq)] -#[derive_where(Eq; I: Interner, T: Eq)] -#[derive_where(Debug; I: Interner, T: Debug)] #[cfg_attr(feature = "nightly", derive(HashStable_NoContext))] pub struct Binder<I: Interner, T> { value: T, bound_vars: I::BoundVarKinds, } +impl<I: Interner, T: Eq> Eq for Binder<I, T> {} + // FIXME: We manually derive `Lift` because the `derive(Lift_Generic)` doesn't // understand how to turn `T` to `T::Lifted` in the output `type Lifted`. impl<I: Interner, U: Interner, T> Lift<U> for Binder<I, T> @@ -356,14 +352,9 @@ impl<I: Interner> TypeVisitor<I> for ValidateBoundVars<I> { /// `instantiate`. /// /// See <https://rustc-dev-guide.rust-lang.org/ty_module/early_binder.html> for more details. -#[derive_where(Clone; I: Interner, T: Clone)] -#[derive_where(Copy; I: Interner, T: Copy)] -#[derive_where(PartialEq; I: Interner, T: PartialEq)] -#[derive_where(Eq; I: Interner, T: Eq)] -#[derive_where(Ord; I: Interner, T: Ord)] +#[derive_where(Clone, PartialEq, Ord, Hash, Debug; I: Interner, T)] #[derive_where(PartialOrd; I: Interner, T: Ord)] -#[derive_where(Hash; I: Interner, T: Hash)] -#[derive_where(Debug; I: Interner, T: Debug)] +#[derive_where(Copy; I: Interner, T: Copy)] #[cfg_attr( feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) @@ -374,6 +365,8 @@ pub struct EarlyBinder<I: Interner, T> { _tcx: PhantomData<fn() -> I>, } +impl<I: Interner, T: Eq> Eq for EarlyBinder<I, T> {} + /// For early binders, you should first call `instantiate` before using any visitors. #[cfg(feature = "nightly")] impl<I: Interner, T> !TypeFoldable<I> for ty::EarlyBinder<I, T> {} diff --git a/compiler/rustc_type_ir/src/canonical.rs b/compiler/rustc_type_ir/src/canonical.rs index 0cb8d8902c6..de2a9186e7c 100644 --- a/compiler/rustc_type_ir/src/canonical.rs +++ b/compiler/rustc_type_ir/src/canonical.rs @@ -11,11 +11,7 @@ use crate::data_structures::HashMap; use crate::inherent::*; use crate::{self as ty, Interner, TypingMode, UniverseIndex}; -#[derive_where(Clone; I: Interner, V: Clone)] -#[derive_where(Hash; I: Interner, V: Hash)] -#[derive_where(PartialEq; I: Interner, V: PartialEq)] -#[derive_where(Eq; I: Interner, V: Eq)] -#[derive_where(Debug; I: Interner, V: fmt::Debug)] +#[derive_where(Clone, Hash, PartialEq, Debug; I: Interner, V)] #[derive_where(Copy; I: Interner, V: Copy)] #[cfg_attr( feature = "nightly", @@ -26,14 +22,12 @@ pub struct CanonicalQueryInput<I: Interner, V> { pub typing_mode: TypingMode<I>, } +impl<I: Interner, V: Eq> Eq for CanonicalQueryInput<I, V> {} + /// A "canonicalized" type `V` is one where all free inference /// variables have been rewritten to "canonical vars". These are /// numbered starting from 0 in order of first appearance. -#[derive_where(Clone; I: Interner, V: Clone)] -#[derive_where(Hash; I: Interner, V: Hash)] -#[derive_where(PartialEq; I: Interner, V: PartialEq)] -#[derive_where(Eq; I: Interner, V: Eq)] -#[derive_where(Debug; I: Interner, V: fmt::Debug)] +#[derive_where(Clone, Hash, PartialEq, Debug; I: Interner, V)] #[derive_where(Copy; I: Interner, V: Copy)] #[cfg_attr( feature = "nightly", @@ -45,6 +39,8 @@ pub struct Canonical<I: Interner, V> { pub variables: I::CanonicalVarKinds, } +impl<I: Interner, V: Eq> Eq for Canonical<I, V> {} + impl<I: Interner, V> Canonical<I, V> { /// Allows you to map the `value` of a canonical while keeping the /// same set of bound variables. @@ -89,7 +85,7 @@ impl<I: Interner, V: fmt::Display> fmt::Display for Canonical<I, V> { /// canonical value. This is sufficient information for code to create /// a copy of the canonical value in some other inference context, /// with fresh inference variables replacing the canonical values. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] #[cfg_attr( feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext) @@ -116,6 +112,8 @@ pub enum CanonicalVarKind<I: Interner> { PlaceholderConst(I::PlaceholderConst), } +impl<I: Interner> Eq for CanonicalVarKind<I> {} + impl<I: Interner> CanonicalVarKind<I> { pub fn universe(self) -> UniverseIndex { match self { @@ -223,7 +221,7 @@ pub enum CanonicalTyVarKind { /// vectors with the original values that were replaced by canonical /// variables. You will need to supply it later to instantiate the /// canonicalized query response. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] #[cfg_attr( feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) @@ -233,6 +231,8 @@ pub struct CanonicalVarValues<I: Interner> { pub var_values: I::GenericArgs, } +impl<I: Interner> Eq for CanonicalVarValues<I> {} + impl<I: Interner> CanonicalVarValues<I> { pub fn is_identity(&self) -> bool { self.var_values.iter().enumerate().all(|(bv, arg)| match arg.kind() { diff --git a/compiler/rustc_type_ir/src/const_kind.rs b/compiler/rustc_type_ir/src/const_kind.rs index 70a8509b513..6de41b47bde 100644 --- a/compiler/rustc_type_ir/src/const_kind.rs +++ b/compiler/rustc_type_ir/src/const_kind.rs @@ -10,7 +10,7 @@ use rustc_type_ir_macros::{Lift_Generic, TypeFoldable_Generic, TypeVisitable_Gen use crate::{self as ty, DebruijnIndex, Interner}; /// Represents a constant in Rust. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] #[cfg_attr( feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) @@ -45,6 +45,8 @@ pub enum ConstKind<I: Interner> { Expr(I::ExprConst), } +impl<I: Interner> Eq for ConstKind<I> {} + impl<I: Interner> fmt::Debug for ConstKind<I> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { use ConstKind::*; @@ -63,7 +65,7 @@ impl<I: Interner> fmt::Debug for ConstKind<I> { } /// An unevaluated (potentially generic) constant used in the type-system. -#[derive_where(Clone, Copy, Debug, Hash, PartialEq, Eq; I: Interner)] +#[derive_where(Clone, Copy, Debug, Hash, PartialEq; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -74,6 +76,8 @@ pub struct UnevaluatedConst<I: Interner> { pub args: I::GenericArgs, } +impl<I: Interner> Eq for UnevaluatedConst<I> {} + impl<I: Interner> UnevaluatedConst<I> { #[inline] pub fn new(def: I::DefId, args: I::GenericArgs) -> UnevaluatedConst<I> { diff --git a/compiler/rustc_type_ir/src/error.rs b/compiler/rustc_type_ir/src/error.rs index 68b11489ae7..e8840bcfaca 100644 --- a/compiler/rustc_type_ir/src/error.rs +++ b/compiler/rustc_type_ir/src/error.rs @@ -18,7 +18,7 @@ impl<T> ExpectedFound<T> { } // Data structures used in type unification -#[derive_where(Clone, Copy, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, PartialEq, Debug; I: Interner)] #[derive(TypeVisitable_Generic)] #[cfg_attr(feature = "nightly", rustc_pass_by_value)] pub enum TypeError<I: Interner> { @@ -58,6 +58,8 @@ pub enum TypeError<I: Interner> { TargetFeatureCast(I::DefId), } +impl<I: Interner> Eq for TypeError<I> {} + impl<I: Interner> TypeError<I> { pub fn involves_regions(self) -> bool { match self { diff --git a/compiler/rustc_type_ir/src/generic_arg.rs b/compiler/rustc_type_ir/src/generic_arg.rs index c18cade0e39..d6e33f724d0 100644 --- a/compiler/rustc_type_ir/src/generic_arg.rs +++ b/compiler/rustc_type_ir/src/generic_arg.rs @@ -4,7 +4,7 @@ use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContex use crate::Interner; -#[derive_where(Clone, Copy, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, PartialEq, Debug; I: Interner)] #[cfg_attr( feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext) @@ -15,7 +15,9 @@ pub enum GenericArgKind<I: Interner> { Const(I::Const), } -#[derive_where(Clone, Copy, PartialEq, Eq, Debug; I: Interner)] +impl<I: Interner> Eq for GenericArgKind<I> {} + +#[derive_where(Clone, Copy, PartialEq, Debug; I: Interner)] #[cfg_attr( feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext, HashStable_NoContext) @@ -24,3 +26,5 @@ pub enum TermKind<I: Interner> { Ty(I::Ty), Const(I::Const), } + +impl<I: Interner> Eq for TermKind<I> {} diff --git a/compiler/rustc_type_ir/src/infer_ctxt.rs b/compiler/rustc_type_ir/src/infer_ctxt.rs index e6462a97f8a..e39b99e992b 100644 --- a/compiler/rustc_type_ir/src/infer_ctxt.rs +++ b/compiler/rustc_type_ir/src/infer_ctxt.rs @@ -18,7 +18,7 @@ use crate::{self as ty, Interner}; /// /// If neither of these functions are available, feel free to reach out to /// t-types for help. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] #[cfg_attr( feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) @@ -90,6 +90,8 @@ pub enum TypingMode<I: Interner> { PostAnalysis, } +impl<I: Interner> Eq for TypingMode<I> {} + impl<I: Interner> TypingMode<I> { /// Analysis outside of a body does not define any opaque types. pub fn non_body_analysis() -> TypingMode<I> { diff --git a/compiler/rustc_type_ir/src/opaque_ty.rs b/compiler/rustc_type_ir/src/opaque_ty.rs index 416d355fd03..b6fb9f28930 100644 --- a/compiler/rustc_type_ir/src/opaque_ty.rs +++ b/compiler/rustc_type_ir/src/opaque_ty.rs @@ -6,7 +6,7 @@ use rustc_type_ir_macros::{TypeFoldable_Generic, TypeVisitable_Generic}; use crate::inherent::*; use crate::{self as ty, Interner}; -#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", @@ -17,6 +17,8 @@ pub struct OpaqueTypeKey<I: Interner> { pub args: I::GenericArgs, } +impl<I: Interner> Eq for OpaqueTypeKey<I> {} + impl<I: Interner> OpaqueTypeKey<I> { pub fn iter_captured_args(self, cx: I) -> impl Iterator<Item = (usize, I::GenericArg)> { let variances = cx.variances_of(self.def_id.into()); diff --git a/compiler/rustc_type_ir/src/pattern.rs b/compiler/rustc_type_ir/src/pattern.rs index 7e56565917c..d757ac625f2 100644 --- a/compiler/rustc_type_ir/src/pattern.rs +++ b/compiler/rustc_type_ir/src/pattern.rs @@ -5,7 +5,7 @@ use rustc_type_ir_macros::{Lift_Generic, TypeFoldable_Generic, TypeVisitable_Gen use crate::Interner; -#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -15,3 +15,5 @@ pub enum PatternKind<I: Interner> { Range { start: I::Const, end: I::Const }, Or(I::PatList), } + +impl<I: Interner> Eq for PatternKind<I> {} diff --git a/compiler/rustc_type_ir/src/predicate.rs b/compiler/rustc_type_ir/src/predicate.rs index 9e4447ccd99..b53eb099c4b 100644 --- a/compiler/rustc_type_ir/src/predicate.rs +++ b/compiler/rustc_type_ir/src/predicate.rs @@ -15,12 +15,8 @@ use crate::visit::TypeVisitableExt as _; use crate::{self as ty, Interner}; /// `A: 'region` -#[derive_where(Clone; I: Interner, A: Clone)] +#[derive_where(Clone, Hash, PartialEq, Debug; I: Interner, A)] #[derive_where(Copy; I: Interner, A: Copy)] -#[derive_where(Hash; I: Interner, A: Hash)] -#[derive_where(PartialEq; I: Interner, A: PartialEq)] -#[derive_where(Eq; I: Interner, A: Eq)] -#[derive_where(Debug; I: Interner, A: fmt::Debug)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", @@ -28,6 +24,8 @@ use crate::{self as ty, Interner}; )] pub struct OutlivesPredicate<I: Interner, A>(pub A, pub I::Region); +impl<I: Interner, A: Eq> Eq for OutlivesPredicate<I, A> {} + // FIXME: We manually derive `Lift` because the `derive(Lift_Generic)` doesn't // understand how to turn `A` to `A::Lifted` in the output `type Lifted`. impl<I: Interner, U: Interner, A> Lift<U> for OutlivesPredicate<I, A> @@ -53,7 +51,7 @@ where /// /// Trait references also appear in object types like `Foo<U>`, but in /// that case the `Self` parameter is absent from the generic parameters. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -67,6 +65,8 @@ pub struct TraitRef<I: Interner> { _use_trait_ref_new_instead: (), } +impl<I: Interner> Eq for TraitRef<I> {} + impl<I: Interner> TraitRef<I> { pub fn new_from_args(interner: I, trait_def_id: I::DefId, args: I::GenericArgs) -> Self { interner.debug_assert_args_compatible(trait_def_id, args); @@ -82,7 +82,7 @@ impl<I: Interner> TraitRef<I> { Self::new_from_args(interner, trait_def_id, args) } - pub fn from_method(interner: I, trait_id: I::DefId, args: I::GenericArgs) -> TraitRef<I> { + pub fn from_assoc(interner: I, trait_id: I::DefId, args: I::GenericArgs) -> TraitRef<I> { let generics = interner.generics_of(trait_id); TraitRef::new(interner, trait_id, args.iter().take(generics.count())) } @@ -128,7 +128,7 @@ impl<I: Interner> ty::Binder<I, TraitRef<I>> { } } -#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -145,6 +145,8 @@ pub struct TraitPredicate<I: Interner> { pub polarity: PredicatePolarity, } +impl<I: Interner> Eq for TraitPredicate<I> {} + impl<I: Interner> TraitPredicate<I> { pub fn with_replaced_self_ty(self, interner: I, self_ty: I::Ty) -> Self { Self { @@ -271,7 +273,7 @@ impl fmt::Display for PredicatePolarity { } } -#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -286,6 +288,8 @@ pub enum ExistentialPredicate<I: Interner> { AutoTrait(I::DefId), } +impl<I: Interner> Eq for ExistentialPredicate<I> {} + impl<I: Interner> ty::Binder<I, ExistentialPredicate<I>> { /// Given an existential predicate like `?Self: PartialEq<u32>` (e.g., derived from `dyn PartialEq<u32>`), /// and a concrete type `self_ty`, returns a full predicate where the existentially quantified variable `?Self` @@ -319,7 +323,7 @@ impl<I: Interner> ty::Binder<I, ExistentialPredicate<I>> { /// ``` /// The generic parameters don't include the erased `Self`, only trait /// type and lifetime parameters (`[X, Y]` and `['a, 'b]` above). -#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -333,6 +337,8 @@ pub struct ExistentialTraitRef<I: Interner> { _use_existential_trait_ref_new_instead: (), } +impl<I: Interner> Eq for ExistentialTraitRef<I> {} + impl<I: Interner> ExistentialTraitRef<I> { pub fn new_from_args(interner: I, trait_def_id: I::DefId, args: I::GenericArgs) -> Self { interner.debug_assert_existential_args_compatible(trait_def_id, args); @@ -386,7 +392,7 @@ impl<I: Interner> ty::Binder<I, ExistentialTraitRef<I>> { } /// A `ProjectionPredicate` for an `ExistentialTraitRef`. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -402,6 +408,8 @@ pub struct ExistentialProjection<I: Interner> { use_existential_projection_new_instead: (), } +impl<I: Interner> Eq for ExistentialProjection<I> {} + impl<I: Interner> ExistentialProjection<I> { pub fn new_from_args( interner: I, @@ -542,7 +550,7 @@ impl From<ty::AliasTyKind> for AliasTermKind { /// * For a projection, this would be `<Ty as Trait<...>>::N<...>`. /// * For an inherent projection, this would be `Ty::N<...>`. /// * For an opaque type, there is no explicit syntax. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -578,6 +586,8 @@ pub struct AliasTerm<I: Interner> { _use_alias_term_new_instead: (), } +impl<I: Interner> Eq for AliasTerm<I> {} + impl<I: Interner> AliasTerm<I> { pub fn new_from_args(interner: I, def_id: I::DefId, args: I::GenericArgs) -> AliasTerm<I> { interner.debug_assert_args_compatible(def_id, args); @@ -752,7 +762,7 @@ impl<I: Interner> From<ty::UnevaluatedConst<I>> for AliasTerm<I> { /// equality between arbitrary types. Processing an instance of /// Form #2 eventually yields one of these `ProjectionPredicate` /// instances to normalize the LHS. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -763,6 +773,8 @@ pub struct ProjectionPredicate<I: Interner> { pub term: I::Term, } +impl<I: Interner> Eq for ProjectionPredicate<I> {} + impl<I: Interner> ProjectionPredicate<I> { pub fn self_ty(self) -> I::Ty { self.projection_term.self_ty() @@ -813,7 +825,7 @@ impl<I: Interner> fmt::Debug for ProjectionPredicate<I> { /// Used by the new solver to normalize an alias. This always expects the `term` to /// be an unconstrained inference variable which is used as the output. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -824,6 +836,8 @@ pub struct NormalizesTo<I: Interner> { pub term: I::Term, } +impl<I: Interner> Eq for NormalizesTo<I> {} + impl<I: Interner> NormalizesTo<I> { pub fn self_ty(self) -> I::Ty { self.alias.self_ty() @@ -848,7 +862,7 @@ impl<I: Interner> fmt::Debug for NormalizesTo<I> { } } -#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -859,6 +873,8 @@ pub struct HostEffectPredicate<I: Interner> { pub constness: BoundConstness, } +impl<I: Interner> Eq for HostEffectPredicate<I> {} + impl<I: Interner> HostEffectPredicate<I> { pub fn self_ty(self) -> I::Ty { self.trait_ref.self_ty() @@ -892,7 +908,7 @@ impl<I: Interner> ty::Binder<I, HostEffectPredicate<I>> { /// Encodes that `a` must be a subtype of `b`. The `a_is_expected` flag indicates /// whether the `a` type is the type that we should label as "expected" when /// presenting user diagnostics. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -904,8 +920,10 @@ pub struct SubtypePredicate<I: Interner> { pub b: I::Ty, } +impl<I: Interner> Eq for SubtypePredicate<I> {} + /// Encodes that we have to coerce *from* the `a` type to the `b` type. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -916,6 +934,8 @@ pub struct CoercePredicate<I: Interner> { pub b: I::Ty, } +impl<I: Interner> Eq for CoercePredicate<I> {} + #[derive(Clone, Copy, Hash, PartialEq, Eq, Debug)] #[cfg_attr( feature = "nightly", diff --git a/compiler/rustc_type_ir/src/predicate_kind.rs b/compiler/rustc_type_ir/src/predicate_kind.rs index 8bc15ec4ff5..ff92a0070cc 100644 --- a/compiler/rustc_type_ir/src/predicate_kind.rs +++ b/compiler/rustc_type_ir/src/predicate_kind.rs @@ -9,7 +9,7 @@ use crate::{self as ty, Interner}; /// A clause is something that can appear in where bounds or be inferred /// by implied bounds. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", @@ -55,7 +55,9 @@ pub enum ClauseKind<I: Interner> { ), } -#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)] +impl<I: Interner> Eq for ClauseKind<I> {} + +#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", @@ -109,6 +111,8 @@ pub enum PredicateKind<I: Interner> { AliasRelate(I::Term, I::Term, AliasRelationDirection), } +impl<I: Interner> Eq for PredicateKind<I> {} + #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)] #[cfg_attr( feature = "nightly", diff --git a/compiler/rustc_type_ir/src/region_kind.rs b/compiler/rustc_type_ir/src/region_kind.rs index 1b5d04e6025..cca81dcb4a0 100644 --- a/compiler/rustc_type_ir/src/region_kind.rs +++ b/compiler/rustc_type_ir/src/region_kind.rs @@ -125,7 +125,7 @@ rustc_index::newtype_index! { /// [1]: https://smallcultfollowing.com/babysteps/blog/2013/10/29/intermingled-parameter-lists/ /// [2]: https://smallcultfollowing.com/babysteps/blog/2013/11/04/intermingled-parameter-lists/ /// [rustc dev guide]: https://rustc-dev-guide.rust-lang.org/traits/hrtb.html -#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] #[cfg_attr(feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext))] pub enum RegionKind<I: Interner> { /// A region parameter; for example `'a` in `impl<'a> Trait for &'a ()`. @@ -177,6 +177,8 @@ pub enum RegionKind<I: Interner> { ReError(I::ErrorGuaranteed), } +impl<I: Interner> Eq for RegionKind<I> {} + impl<I: Interner> fmt::Debug for RegionKind<I> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { diff --git a/compiler/rustc_type_ir/src/relate.rs b/compiler/rustc_type_ir/src/relate.rs index 3a00fe89360..223230fde9e 100644 --- a/compiler/rustc_type_ir/src/relate.rs +++ b/compiler/rustc_type_ir/src/relate.rs @@ -33,7 +33,7 @@ pub enum StructurallyRelateAliases { /// a miscompilation or unsoundness. /// /// When in doubt, use `VarianceDiagInfo::default()` -#[derive_where(Clone, Copy, PartialEq, Eq, Debug, Default; I: Interner)] +#[derive_where(Clone, Copy, PartialEq, Debug, Default; I: Interner)] pub enum VarianceDiagInfo<I: Interner> { /// No additional information - this is the default. /// We will not add any additional information to error messages. @@ -51,6 +51,8 @@ pub enum VarianceDiagInfo<I: Interner> { }, } +impl<I: Interner> Eq for VarianceDiagInfo<I> {} + impl<I: Interner> VarianceDiagInfo<I> { /// Mirrors `Variance::xform` - used to 'combine' the existing /// and new `VarianceDiagInfo`s when our variance changes. diff --git a/compiler/rustc_type_ir/src/search_graph/mod.rs b/compiler/rustc_type_ir/src/search_graph/mod.rs index 7433c215e6f..daacb4a3e44 100644 --- a/compiler/rustc_type_ir/src/search_graph/mod.rs +++ b/compiler/rustc_type_ir/src/search_graph/mod.rs @@ -21,10 +21,9 @@ use std::marker::PhantomData; use derive_where::derive_where; #[cfg(feature = "nightly")] use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext}; +use rustc_type_ir::data_structures::HashMap; use tracing::{debug, instrument}; -use crate::data_structures::HashMap; - mod stack; use stack::{Stack, StackDepth, StackEntry}; mod global_cache; @@ -137,6 +136,12 @@ pub enum PathKind { Unknown, /// A path with at least one coinductive step. Such cycles hold. Coinductive, + /// A path which is treated as ambiguous. Once a path has this path kind + /// any other segment does not change its kind. + /// + /// This is currently only used when fuzzing to support negative reasoning. + /// For more details, see #143054. + ForcedAmbiguity, } impl PathKind { @@ -149,6 +154,9 @@ impl PathKind { /// to `max(self, rest)`. fn extend(self, rest: PathKind) -> PathKind { match (self, rest) { + (PathKind::ForcedAmbiguity, _) | (_, PathKind::ForcedAmbiguity) => { + PathKind::ForcedAmbiguity + } (PathKind::Coinductive, _) | (_, PathKind::Coinductive) => PathKind::Coinductive, (PathKind::Unknown, _) | (_, PathKind::Unknown) => PathKind::Unknown, (PathKind::Inductive, PathKind::Inductive) => PathKind::Inductive, @@ -187,41 +195,6 @@ impl UsageKind { } } -/// For each goal we track whether the paths from this goal -/// to its cycle heads are coinductive. -/// -/// This is a necessary condition to rebase provisional cache -/// entries. -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum AllPathsToHeadCoinductive { - Yes, - No, -} -impl From<PathKind> for AllPathsToHeadCoinductive { - fn from(path: PathKind) -> AllPathsToHeadCoinductive { - match path { - PathKind::Coinductive => AllPathsToHeadCoinductive::Yes, - _ => AllPathsToHeadCoinductive::No, - } - } -} -impl AllPathsToHeadCoinductive { - #[must_use] - fn merge(self, other: impl Into<Self>) -> Self { - match (self, other.into()) { - (AllPathsToHeadCoinductive::Yes, AllPathsToHeadCoinductive::Yes) => { - AllPathsToHeadCoinductive::Yes - } - (AllPathsToHeadCoinductive::No, _) | (_, AllPathsToHeadCoinductive::No) => { - AllPathsToHeadCoinductive::No - } - } - } - fn and_merge(&mut self, other: impl Into<Self>) { - *self = self.merge(other); - } -} - #[derive(Debug, Clone, Copy)] struct AvailableDepth(usize); impl AvailableDepth { @@ -261,9 +234,9 @@ impl AvailableDepth { /// /// We also track all paths from this goal to that head. This is necessary /// when rebasing provisional cache results. -#[derive(Clone, Debug, PartialEq, Eq, Default)] +#[derive(Clone, Debug, Default)] struct CycleHeads { - heads: BTreeMap<StackDepth, AllPathsToHeadCoinductive>, + heads: BTreeMap<StackDepth, PathsToNested>, } impl CycleHeads { @@ -283,27 +256,16 @@ impl CycleHeads { self.heads.first_key_value().map(|(k, _)| *k) } - fn remove_highest_cycle_head(&mut self) { + fn remove_highest_cycle_head(&mut self) -> PathsToNested { let last = self.heads.pop_last(); - debug_assert_ne!(last, None); - } - - fn insert( - &mut self, - head: StackDepth, - path_from_entry: impl Into<AllPathsToHeadCoinductive> + Copy, - ) { - self.heads.entry(head).or_insert(path_from_entry.into()).and_merge(path_from_entry); + last.unwrap().1 } - fn merge(&mut self, heads: &CycleHeads) { - for (&head, &path_from_entry) in heads.heads.iter() { - self.insert(head, path_from_entry); - debug_assert!(matches!(self.heads[&head], AllPathsToHeadCoinductive::Yes)); - } + fn insert(&mut self, head: StackDepth, path_from_entry: impl Into<PathsToNested> + Copy) { + *self.heads.entry(head).or_insert(path_from_entry.into()) |= path_from_entry.into(); } - fn iter(&self) -> impl Iterator<Item = (StackDepth, AllPathsToHeadCoinductive)> + '_ { + fn iter(&self) -> impl Iterator<Item = (StackDepth, PathsToNested)> + '_ { self.heads.iter().map(|(k, v)| (*k, *v)) } @@ -317,13 +279,7 @@ impl CycleHeads { Ordering::Equal => continue, Ordering::Greater => unreachable!(), } - - let path_from_entry = match step_kind { - PathKind::Coinductive => AllPathsToHeadCoinductive::Yes, - PathKind::Unknown | PathKind::Inductive => path_from_entry, - }; - - self.insert(head, path_from_entry); + self.insert(head, path_from_entry.extend_with(step_kind)); } } } @@ -332,13 +288,14 @@ bitflags::bitflags! { /// Tracks how nested goals have been accessed. This is necessary to disable /// global cache entries if computing them would otherwise result in a cycle or /// access a provisional cache entry. - #[derive(Debug, Clone, Copy)] + #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct PathsToNested: u8 { /// The initial value when adding a goal to its own nested goals. const EMPTY = 1 << 0; const INDUCTIVE = 1 << 1; const UNKNOWN = 1 << 2; const COINDUCTIVE = 1 << 3; + const FORCED_AMBIGUITY = 1 << 4; } } impl From<PathKind> for PathsToNested { @@ -347,6 +304,7 @@ impl From<PathKind> for PathsToNested { PathKind::Inductive => PathsToNested::INDUCTIVE, PathKind::Unknown => PathsToNested::UNKNOWN, PathKind::Coinductive => PathsToNested::COINDUCTIVE, + PathKind::ForcedAmbiguity => PathsToNested::FORCED_AMBIGUITY, } } } @@ -379,10 +337,45 @@ impl PathsToNested { self.insert(PathsToNested::COINDUCTIVE); } } + PathKind::ForcedAmbiguity => { + if self.intersects( + PathsToNested::EMPTY + | PathsToNested::INDUCTIVE + | PathsToNested::UNKNOWN + | PathsToNested::COINDUCTIVE, + ) { + self.remove( + PathsToNested::EMPTY + | PathsToNested::INDUCTIVE + | PathsToNested::UNKNOWN + | PathsToNested::COINDUCTIVE, + ); + self.insert(PathsToNested::FORCED_AMBIGUITY); + } + } } self } + + #[must_use] + fn extend_with_paths(self, path: PathsToNested) -> Self { + let mut new = PathsToNested::empty(); + for p in path.iter_paths() { + new |= self.extend_with(p); + } + new + } + + fn iter_paths(self) -> impl Iterator<Item = PathKind> { + let (PathKind::Inductive + | PathKind::Unknown + | PathKind::Coinductive + | PathKind::ForcedAmbiguity); + [PathKind::Inductive, PathKind::Unknown, PathKind::Coinductive, PathKind::ForcedAmbiguity] + .into_iter() + .filter(move |&p| self.contains(p.into())) + } } /// The nested goals of each stack entry and the path from the @@ -693,7 +686,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> { if let Some((_scope, expected)) = validate_cache { // Do not try to move a goal into the cache again if we're testing // the global cache. - assert_eq!(evaluation_result.result, expected, "input={input:?}"); + assert_eq!(expected, evaluation_result.result, "input={input:?}"); } else if D::inspect_is_noop(inspect) { self.insert_global_cache(cx, input, evaluation_result, dep_node) } @@ -763,14 +756,11 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> { /// provisional cache entry is still applicable. We need to keep the cache entries to /// prevent hangs. /// - /// What we therefore do is check whether the cycle kind of all cycles the goal of a - /// provisional cache entry is involved in would stay the same when computing the - /// goal without its cycle head on the stack. For more details, see the relevant + /// This can be thought of as pretending to reevaluate the popped head as nested goals + /// of this provisional result. For this to be correct, all cycles encountered while + /// we'd reevaluate the cycle head as a nested goal must keep the same cycle kind. /// [rustc-dev-guide chapter](https://rustc-dev-guide.rust-lang.org/solve/caching.html). /// - /// This can be thought of rotating the sub-tree of this provisional result and changing - /// its entry point while making sure that all paths through this sub-tree stay the same. - /// /// In case the popped cycle head failed to reach a fixpoint anything which depends on /// its provisional result is invalid. Actually discarding provisional cache entries in /// this case would cause hangs, so we instead change the result of dependant provisional @@ -782,7 +772,7 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> { stack_entry: &StackEntry<X>, mut mutate_result: impl FnMut(X::Input, X::Result) -> X::Result, ) { - let head = self.stack.next_index(); + let popped_head = self.stack.next_index(); #[allow(rustc::potential_query_instability)] self.provisional_cache.retain(|&input, entries| { entries.retain_mut(|entry| { @@ -792,30 +782,44 @@ impl<D: Delegate<Cx = X>, X: Cx> SearchGraph<D> { path_from_head, result, } = entry; - if heads.highest_cycle_head() == head { + let ep = if heads.highest_cycle_head() == popped_head { heads.remove_highest_cycle_head() } else { return true; - } - - // We only try to rebase if all paths from the cache entry - // to its heads are coinductive. In this case these cycle - // kinds won't change, no matter the goals between these - // heads and the provisional cache entry. - if heads.iter().any(|(_, p)| matches!(p, AllPathsToHeadCoinductive::No)) { - return false; - } + }; - // The same for nested goals of the cycle head. - if stack_entry.heads.iter().any(|(_, p)| matches!(p, AllPathsToHeadCoinductive::No)) - { - return false; + // We're rebasing an entry `e` over a head `p`. This head + // has a number of own heads `h` it depends on. We need to + // make sure that the path kind of all paths `hph` remain the + // same after rebasing. + // + // After rebasing the cycles `hph` will go through `e`. We need to make + // sure that forall possible paths `hep`, `heph` is equal to `hph.` + for (h, ph) in stack_entry.heads.iter() { + let hp = + Self::cycle_path_kind(&self.stack, stack_entry.step_kind_from_parent, h); + + // We first validate that all cycles while computing `p` would stay + // the same if we were to recompute it as a nested goal of `e`. + let he = hp.extend(*path_from_head); + for ph in ph.iter_paths() { + let hph = hp.extend(ph); + for ep in ep.iter_paths() { + let hep = ep.extend(he); + let heph = hep.extend(ph); + if hph != heph { + return false; + } + } + } + + // If so, all paths reached while computing `p` have to get added + // the heads of `e` to make sure that rebasing `e` again also considers + // them. + let eph = ep.extend_with_paths(ph); + heads.insert(h, eph); } - // Merge the cycle heads of the provisional cache entry and the - // popped head. If the popped cycle head was a root, discard all - // provisional cache entries which depend on it. - heads.merge(&stack_entry.heads); let Some(head) = heads.opt_highest_cycle_head() else { return false; }; diff --git a/compiler/rustc_type_ir/src/search_graph/stack.rs b/compiler/rustc_type_ir/src/search_graph/stack.rs index e0fd934df69..a58cd82b023 100644 --- a/compiler/rustc_type_ir/src/search_graph/stack.rs +++ b/compiler/rustc_type_ir/src/search_graph/stack.rs @@ -3,7 +3,7 @@ use std::ops::{Index, IndexMut}; use derive_where::derive_where; use rustc_index::IndexVec; -use super::{AvailableDepth, Cx, CycleHeads, NestedGoals, PathKind, UsageKind}; +use crate::search_graph::{AvailableDepth, Cx, CycleHeads, NestedGoals, PathKind, UsageKind}; rustc_index::newtype_index! { #[orderable] @@ -79,6 +79,9 @@ impl<X: Cx> Stack<X> { } pub(super) fn push(&mut self, entry: StackEntry<X>) -> StackDepth { + if cfg!(debug_assertions) && self.entries.iter().any(|e| e.input == entry.input) { + panic!("pushing duplicate entry on stack: {entry:?} {:?}", self.entries); + } self.entries.push(entry) } diff --git a/compiler/rustc_type_ir/src/solve/inspect.rs b/compiler/rustc_type_ir/src/solve/inspect.rs index 089695d0475..afb4043648f 100644 --- a/compiler/rustc_type_ir/src/solve/inspect.rs +++ b/compiler/rustc_type_ir/src/solve/inspect.rs @@ -17,9 +17,6 @@ //! //! [canonicalized]: https://rustc-dev-guide.rust-lang.org/solve/canonicalization.html -use std::fmt::Debug; -use std::hash::Hash; - use derive_where::derive_where; use rustc_type_ir_macros::{TypeFoldable_Generic, TypeVisitable_Generic}; @@ -32,25 +29,23 @@ use crate::{Canonical, CanonicalVarValues, Interner}; /// This is only ever used as [CanonicalState]. Any type information in proof /// trees used mechanically has to be canonicalized as we otherwise leak /// inference variables from a nested `InferCtxt`. -#[derive_where(Clone; I: Interner, T: Clone)] +#[derive_where(Clone, PartialEq, Hash, Debug; I: Interner, T)] #[derive_where(Copy; I: Interner, T: Copy)] -#[derive_where(PartialEq; I: Interner, T: PartialEq)] -#[derive_where(Eq; I: Interner, T: Eq)] -#[derive_where(Hash; I: Interner, T: Hash)] -#[derive_where(Debug; I: Interner, T: Debug)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic)] pub struct State<I: Interner, T> { pub var_values: CanonicalVarValues<I>, pub data: T, } +impl<I: Interner, T: Eq> Eq for State<I, T> {} + pub type CanonicalState<I, T> = Canonical<I, State<I, T>>; /// When evaluating a goal we also store the original values /// for the `CanonicalVarValues` of the canonicalized goal. /// We use this to map any [CanonicalState] from the local `InferCtxt` /// of the solver query to the `InferCtxt` of the caller. -#[derive_where(PartialEq, Eq, Hash; I: Interner)] +#[derive_where(PartialEq, Hash; I: Interner)] pub struct GoalEvaluation<I: Interner> { pub uncanonicalized_goal: Goal<I, I::Predicate>, pub orig_values: Vec<I::GenericArg>, @@ -58,7 +53,9 @@ pub struct GoalEvaluation<I: Interner> { pub result: QueryResult<I>, } -#[derive_where(PartialEq, Eq, Hash, Debug; I: Interner)] +impl<I: Interner> Eq for GoalEvaluation<I> {} + +#[derive_where(PartialEq, Hash, Debug; I: Interner)] pub enum GoalEvaluationKind<I: Interner> { Overflow, Evaluation { @@ -67,10 +64,12 @@ pub enum GoalEvaluationKind<I: Interner> { }, } +impl<I: Interner> Eq for GoalEvaluationKind<I> {} + /// A self-contained computation during trait solving. This either /// corresponds to a `EvalCtxt::probe(_X)` call or the root evaluation /// of a goal. -#[derive_where(PartialEq, Eq, Hash, Debug; I: Interner)] +#[derive_where(PartialEq, Hash, Debug; I: Interner)] pub struct Probe<I: Interner> { /// What happened inside of this probe in chronological order. pub steps: Vec<ProbeStep<I>>, @@ -78,7 +77,9 @@ pub struct Probe<I: Interner> { pub final_state: CanonicalState<I, ()>, } -#[derive_where(PartialEq, Eq, Hash, Debug; I: Interner)] +impl<I: Interner> Eq for Probe<I> {} + +#[derive_where(PartialEq, Hash, Debug; I: Interner)] pub enum ProbeStep<I: Interner> { /// We added a goal to the `EvalCtxt` which will get proven /// the next time `EvalCtxt::try_evaluate_added_goals` is called. @@ -97,10 +98,12 @@ pub enum ProbeStep<I: Interner> { MakeCanonicalResponse { shallow_certainty: Certainty }, } +impl<I: Interner> Eq for ProbeStep<I> {} + /// What kind of probe we're in. In case the probe represents a candidate, or /// the final result of the current goal - via [ProbeKind::Root] - we also /// store the [QueryResult]. -#[derive_where(Clone, Copy, PartialEq, Eq, Hash, Debug; I: Interner)] +#[derive_where(Clone, Copy, PartialEq, Hash, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic)] pub enum ProbeKind<I: Interner> { /// The root inference context while proving a goal. @@ -125,3 +128,5 @@ pub enum ProbeKind<I: Interner> { /// Checking that a rigid alias is well-formed. RigidAlias { result: QueryResult<I> }, } + +impl<I: Interner> Eq for ProbeKind<I> {} diff --git a/compiler/rustc_type_ir/src/solve/mod.rs b/compiler/rustc_type_ir/src/solve/mod.rs index a6571ef261a..1497236039f 100644 --- a/compiler/rustc_type_ir/src/solve/mod.rs +++ b/compiler/rustc_type_ir/src/solve/mod.rs @@ -1,6 +1,5 @@ pub mod inspect; -use std::fmt; use std::hash::Hash; use derive_where::derive_where; @@ -32,12 +31,8 @@ pub struct NoSolution; /// /// Most of the time the `param_env` contains the `where`-bounds of the function /// we're currently typechecking while the `predicate` is some trait bound. -#[derive_where(Clone; I: Interner, P: Clone)] +#[derive_where(Clone, Hash, PartialEq, Debug; I: Interner, P)] #[derive_where(Copy; I: Interner, P: Copy)] -#[derive_where(Hash; I: Interner, P: Hash)] -#[derive_where(PartialEq; I: Interner, P: PartialEq)] -#[derive_where(Eq; I: Interner, P: Eq)] -#[derive_where(Debug; I: Interner, P: fmt::Debug)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -48,6 +43,8 @@ pub struct Goal<I: Interner, P> { pub predicate: P, } +impl<I: Interner, P: Eq> Eq for Goal<I, P> {} + impl<I: Interner, P> Goal<I, P> { pub fn new(cx: I, param_env: I::ParamEnv, predicate: impl Upcast<I, P>) -> Goal<I, P> { Goal { param_env, predicate: predicate.upcast(cx) } @@ -98,12 +95,8 @@ pub enum GoalSource { NormalizeGoal(PathKind), } -#[derive_where(Clone; I: Interner, Goal<I, P>: Clone)] +#[derive_where(Clone, Hash, PartialEq, Debug; I: Interner, Goal<I, P>)] #[derive_where(Copy; I: Interner, Goal<I, P>: Copy)] -#[derive_where(Hash; I: Interner, Goal<I, P>: Hash)] -#[derive_where(PartialEq; I: Interner, Goal<I, P>: PartialEq)] -#[derive_where(Eq; I: Interner, Goal<I, P>: Eq)] -#[derive_where(Debug; I: Interner, Goal<I, P>: fmt::Debug)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", @@ -114,8 +107,10 @@ pub struct QueryInput<I: Interner, P> { pub predefined_opaques_in_body: I::PredefinedOpaques, } +impl<I: Interner, P: Eq> Eq for QueryInput<I, P> {} + /// Opaques that are defined in the inference context before a query is called. -#[derive_where(Clone, Hash, PartialEq, Eq, Debug, Default; I: Interner)] +#[derive_where(Clone, Hash, PartialEq, Debug, Default; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic)] #[cfg_attr( feature = "nightly", @@ -125,8 +120,10 @@ pub struct PredefinedOpaquesData<I: Interner> { pub opaque_types: Vec<(ty::OpaqueTypeKey<I>, I::Ty)>, } +impl<I: Interner> Eq for PredefinedOpaquesData<I> {} + /// Possible ways the given goal can be proven. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] pub enum CandidateSource<I: Interner> { /// A user written impl. /// @@ -189,6 +186,8 @@ pub enum CandidateSource<I: Interner> { CoherenceUnknowable, } +impl<I: Interner> Eq for CandidateSource<I> {} + #[derive(Clone, Copy, Hash, PartialEq, Eq, Debug)] pub enum ParamEnvSource { /// Preferred eagerly. @@ -217,7 +216,7 @@ pub enum BuiltinImplSource { TraitUpcasting(usize), } -#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic)] #[cfg_attr(feature = "nightly", derive(HashStable_NoContext))] pub struct Response<I: Interner> { @@ -227,8 +226,10 @@ pub struct Response<I: Interner> { pub external_constraints: I::ExternalConstraints, } +impl<I: Interner> Eq for Response<I> {} + /// Additional constraints returned on success. -#[derive_where(Clone, Hash, PartialEq, Eq, Debug, Default; I: Interner)] +#[derive_where(Clone, Hash, PartialEq, Debug, Default; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic)] #[cfg_attr(feature = "nightly", derive(HashStable_NoContext))] pub struct ExternalConstraintsData<I: Interner> { @@ -237,6 +238,8 @@ pub struct ExternalConstraintsData<I: Interner> { pub normalization_nested_goals: NestedNormalizationGoals<I>, } +impl<I: Interner> Eq for ExternalConstraintsData<I> {} + impl<I: Interner> ExternalConstraintsData<I> { pub fn is_empty(&self) -> bool { self.region_constraints.is_empty() @@ -245,11 +248,13 @@ impl<I: Interner> ExternalConstraintsData<I> { } } -#[derive_where(Clone, Hash, PartialEq, Eq, Debug, Default; I: Interner)] +#[derive_where(Clone, Hash, PartialEq, Debug, Default; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic)] #[cfg_attr(feature = "nightly", derive(HashStable_NoContext))] pub struct NestedNormalizationGoals<I: Interner>(pub Vec<(GoalSource, Goal<I, I::Predicate>)>); +impl<I: Interner> Eq for NestedNormalizationGoals<I> {} + impl<I: Interner> NestedNormalizationGoals<I> { pub fn empty() -> Self { NestedNormalizationGoals(vec![]) diff --git a/compiler/rustc_type_ir/src/ty_kind.rs b/compiler/rustc_type_ir/src/ty_kind.rs index 73aeab5092d..bde506ffd93 100644 --- a/compiler/rustc_type_ir/src/ty_kind.rs +++ b/compiler/rustc_type_ir/src/ty_kind.rs @@ -69,7 +69,7 @@ impl AliasTyKind { /// Types written by the user start out as `hir::TyKind` and get /// converted to this representation using `<dyn HirTyLowerer>::lower_ty`. #[cfg_attr(feature = "nightly", rustc_diagnostic_item = "IrTyKind")] -#[derive_where(Clone, Copy, Hash, PartialEq, Eq; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq; I: Interner)] #[cfg_attr( feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) @@ -268,6 +268,8 @@ pub enum TyKind<I: Interner> { Error(I::ErrorGuaranteed), } +impl<I: Interner> Eq for TyKind<I> {} + impl<I: Interner> TyKind<I> { pub fn fn_sig(self, interner: I) -> ty::Binder<I, ty::FnSig<I>> { match self { @@ -404,7 +406,7 @@ impl<I: Interner> fmt::Debug for TyKind<I> { /// * For a projection, this would be `<Ty as Trait<...>>::N<...>`. /// * For an inherent projection, this would be `Ty::N<...>`. /// * For an opaque type, there is no explicit syntax. -#[derive_where(Clone, Copy, Hash, PartialEq, Eq, Debug; I: Interner)] +#[derive_where(Clone, Copy, Hash, PartialEq, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] #[cfg_attr( feature = "nightly", @@ -440,6 +442,8 @@ pub struct AliasTy<I: Interner> { pub(crate) _use_alias_ty_new_instead: (), } +impl<I: Interner> Eq for AliasTy<I> {} + impl<I: Interner> AliasTy<I> { pub fn new_from_args(interner: I, def_id: I::DefId, args: I::GenericArgs) -> AliasTy<I> { interner.debug_assert_args_compatible(def_id, args); @@ -720,7 +724,7 @@ impl fmt::Debug for InferTy { } } -#[derive_where(Clone, Copy, PartialEq, Eq, Hash, Debug; I: Interner)] +#[derive_where(Clone, Copy, PartialEq, Hash, Debug; I: Interner)] #[cfg_attr( feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) @@ -731,7 +735,9 @@ pub struct TypeAndMut<I: Interner> { pub mutbl: Mutability, } -#[derive_where(Clone, Copy, PartialEq, Eq, Hash; I: Interner)] +impl<I: Interner> Eq for TypeAndMut<I> {} + +#[derive_where(Clone, Copy, PartialEq, Hash; I: Interner)] #[cfg_attr( feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) @@ -748,6 +754,8 @@ pub struct FnSig<I: Interner> { pub abi: I::Abi, } +impl<I: Interner> Eq for FnSig<I> {} + impl<I: Interner> FnSig<I> { pub fn inputs(self) -> I::FnInputTys { self.inputs_and_output.inputs() @@ -845,11 +853,13 @@ impl<I: Interner> fmt::Debug for FnSig<I> { // FIXME: this is a distinct type because we need to define `Encode`/`Decode` // impls in this crate for `Binder<I, I::Ty>`. -#[derive_where(Clone, Copy, PartialEq, Eq, Hash; I: Interner)] +#[derive_where(Clone, Copy, PartialEq, Hash; I: Interner)] #[cfg_attr(feature = "nightly", derive(HashStable_NoContext))] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] pub struct UnsafeBinderInner<I: Interner>(ty::Binder<I, I::Ty>); +impl<I: Interner> Eq for UnsafeBinderInner<I> {} + impl<I: Interner> From<ty::Binder<I, I::Ty>> for UnsafeBinderInner<I> { fn from(value: ty::Binder<I, I::Ty>) -> Self { UnsafeBinderInner(value) @@ -906,7 +916,7 @@ where } // This is just a `FnSig` without the `FnHeader` fields. -#[derive_where(Clone, Copy, Debug, PartialEq, Eq, Hash; I: Interner)] +#[derive_where(Clone, Copy, Debug, PartialEq, Hash; I: Interner)] #[cfg_attr( feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) @@ -916,6 +926,8 @@ pub struct FnSigTys<I: Interner> { pub inputs_and_output: I::Tys, } +impl<I: Interner> Eq for FnSigTys<I> {} + impl<I: Interner> FnSigTys<I> { pub fn inputs(self) -> I::FnInputTys { self.inputs_and_output.inputs() @@ -958,7 +970,7 @@ impl<I: Interner> ty::Binder<I, FnSigTys<I>> { } } -#[derive_where(Clone, Copy, Debug, PartialEq, Eq, Hash; I: Interner)] +#[derive_where(Clone, Copy, Debug, PartialEq, Hash; I: Interner)] #[cfg_attr( feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) @@ -970,7 +982,9 @@ pub struct FnHeader<I: Interner> { pub abi: I::Abi, } -#[derive_where(Clone, Copy, Debug, PartialEq, Eq, Hash; I: Interner)] +impl<I: Interner> Eq for FnHeader<I> {} + +#[derive_where(Clone, Copy, Debug, PartialEq, Hash; I: Interner)] #[cfg_attr( feature = "nightly", derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext) @@ -980,3 +994,5 @@ pub struct CoroutineWitnessTypes<I: Interner> { pub types: I::Tys, pub assumptions: I::RegionAssumptions, } + +impl<I: Interner> Eq for CoroutineWitnessTypes<I> {} diff --git a/compiler/rustc_type_ir/src/ty_kind/closure.rs b/compiler/rustc_type_ir/src/ty_kind/closure.rs index c32f8339d0b..a2e16d917a9 100644 --- a/compiler/rustc_type_ir/src/ty_kind/closure.rs +++ b/compiler/rustc_type_ir/src/ty_kind/closure.rs @@ -101,7 +101,7 @@ use crate::{self as ty, Interner}; /// `yield` inside the coroutine. /// * `GR`: The "return type", which is the type of value returned upon /// completion of the coroutine. -#[derive_where(Clone, Copy, PartialEq, Eq, Hash, Debug; I: Interner)] +#[derive_where(Clone, Copy, PartialEq, Hash, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] pub struct ClosureArgs<I: Interner> { /// Lifetime and type parameters from the enclosing function, @@ -112,6 +112,8 @@ pub struct ClosureArgs<I: Interner> { pub args: I::GenericArgs, } +impl<I: Interner> Eq for ClosureArgs<I> {} + /// Struct returned by `split()`. pub struct ClosureArgsParts<I: Interner> { /// This is the args of the typeck root. @@ -203,12 +205,14 @@ impl<I: Interner> ClosureArgs<I> { } } -#[derive_where(Clone, Copy, PartialEq, Eq, Hash, Debug; I: Interner)] +#[derive_where(Clone, Copy, PartialEq, Hash, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] pub struct CoroutineClosureArgs<I: Interner> { pub args: I::GenericArgs, } +impl<I: Interner> Eq for CoroutineClosureArgs<I> {} + /// See docs for explanation of how each argument is used. /// /// See [`CoroutineClosureSignature`] for how these arguments are put together @@ -348,7 +352,7 @@ impl<I: Interner> TypeVisitor<I> for HasRegionsBoundAt { } } -#[derive_where(Clone, Copy, PartialEq, Eq, Hash, Debug; I: Interner)] +#[derive_where(Clone, Copy, PartialEq, Hash, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic)] pub struct CoroutineClosureSignature<I: Interner> { pub tupled_inputs_ty: I::Ty, @@ -371,6 +375,8 @@ pub struct CoroutineClosureSignature<I: Interner> { pub abi: I::Abi, } +impl<I: Interner> Eq for CoroutineClosureSignature<I> {} + impl<I: Interner> CoroutineClosureSignature<I> { /// Construct a coroutine from the closure signature. Since a coroutine signature /// is agnostic to the type of generator that is returned (by-ref/by-move), @@ -541,7 +547,7 @@ impl<I: Interner> TypeFolder<I> for FoldEscapingRegions<I> { } } -#[derive_where(Clone, Copy, PartialEq, Eq, Hash, Debug; I: Interner)] +#[derive_where(Clone, Copy, PartialEq, Hash, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic)] pub struct GenSig<I: Interner> { pub resume_ty: I::Ty, @@ -549,13 +555,16 @@ pub struct GenSig<I: Interner> { pub return_ty: I::Ty, } +impl<I: Interner> Eq for GenSig<I> {} /// Similar to `ClosureArgs`; see the above documentation for more. -#[derive_where(Clone, Copy, PartialEq, Eq, Hash, Debug; I: Interner)] +#[derive_where(Clone, Copy, PartialEq, Hash, Debug; I: Interner)] #[derive(TypeVisitable_Generic, TypeFoldable_Generic, Lift_Generic)] pub struct CoroutineArgs<I: Interner> { pub args: I::GenericArgs, } +impl<I: Interner> Eq for CoroutineArgs<I> {} + pub struct CoroutineArgsParts<I: Interner> { /// This is the args of the typeck root. pub parent_args: I::GenericArgsSlice, diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs index acbbb6df9a5..c4e599222e5 100644 --- a/library/alloc/src/collections/btree/map.rs +++ b/library/alloc/src/collections/btree/map.rs @@ -135,6 +135,8 @@ pub(super) const MIN_LEN: usize = node::MIN_LEN_AFTER_SPLIT; /// ]); /// ``` /// +/// ## `Entry` API +/// /// `BTreeMap` implements an [`Entry API`], which allows for complex /// methods of getting, setting, updating and removing keys and their values: /// diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index 2321aab2c51..8001faf9d20 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -49,7 +49,27 @@ //! v[1] = v[1] + 5; //! ``` //! +//! # Memory layout +//! +//! When the type is non-zero-sized and the capacity is nonzero, [`Vec`] uses the [`Global`] +//! allocator for its allocation. It is valid to convert both ways between such a [`Vec`] and a raw +//! pointer allocated with the [`Global`] allocator, provided that the [`Layout`] used with the +//! allocator is correct for a sequence of `capacity` elements of the type, and the first `len` +//! values pointed to by the raw pointer are valid. More precisely, a `ptr: *mut T` that has been +//! allocated with the [`Global`] allocator with [`Layout::array::<T>(capacity)`][Layout::array] may +//! be converted into a vec using +//! [`Vec::<T>::from_raw_parts(ptr, len, capacity)`](Vec::from_raw_parts). Conversely, the memory +//! backing a `value: *mut T` obtained from [`Vec::<T>::as_mut_ptr`] may be deallocated using the +//! [`Global`] allocator with the same layout. +//! +//! For zero-sized types (ZSTs), or when the capacity is zero, the `Vec` pointer must be non-null +//! and sufficiently aligned. The recommended way to build a `Vec` of ZSTs if [`vec!`] cannot be +//! used is to use [`ptr::NonNull::dangling`]. +//! //! [`push`]: Vec::push +//! [`ptr::NonNull::dangling`]: NonNull::dangling +//! [`Layout`]: crate::alloc::Layout +//! [Layout::array]: crate::alloc::Layout::array #![stable(feature = "rust1", since = "1.0.0")] @@ -523,18 +543,23 @@ impl<T> Vec<T> { /// This is highly unsafe, due to the number of invariants that aren't /// checked: /// - /// * `ptr` must have been allocated using the global allocator, such as via - /// the [`alloc::alloc`] function. - /// * `T` needs to have the same alignment as what `ptr` was allocated with. + /// * If `T` is not a zero-sized type and the capacity is nonzero, `ptr` must have + /// been allocated using the global allocator, such as via the [`alloc::alloc`] + /// function. If `T` is a zero-sized type or the capacity is zero, `ptr` need + /// only be non-null and aligned. + /// * `T` needs to have the same alignment as what `ptr` was allocated with, + /// if the pointer is required to be allocated. /// (`T` having a less strict alignment is not sufficient, the alignment really /// needs to be equal to satisfy the [`dealloc`] requirement that memory must be /// allocated and deallocated with the same layout.) - /// * The size of `T` times the `capacity` (ie. the allocated size in bytes) needs - /// to be the same size as the pointer was allocated with. (Because similar to - /// alignment, [`dealloc`] must be called with the same layout `size`.) + /// * The size of `T` times the `capacity` (ie. the allocated size in bytes), if + /// nonzero, needs to be the same size as the pointer was allocated with. + /// (Because similar to alignment, [`dealloc`] must be called with the same + /// layout `size`.) /// * `length` needs to be less than or equal to `capacity`. /// * The first `length` values must be properly initialized values of type `T`. - /// * `capacity` needs to be the capacity that the pointer was allocated with. + /// * `capacity` needs to be the capacity that the pointer was allocated with, + /// if the pointer is required to be allocated. /// * The allocated size in bytes must be no larger than `isize::MAX`. /// See the safety documentation of [`pointer::offset`]. /// @@ -770,12 +795,16 @@ impl<T> Vec<T> { /// order as the arguments to [`from_raw_parts`]. /// /// After calling this function, the caller is responsible for the - /// memory previously managed by the `Vec`. The only way to do - /// this is to convert the raw pointer, length, and capacity back - /// into a `Vec` with the [`from_raw_parts`] function, allowing - /// the destructor to perform the cleanup. + /// memory previously managed by the `Vec`. Most often, one does + /// this by converting the raw pointer, length, and capacity back + /// into a `Vec` with the [`from_raw_parts`] function; more generally, + /// if `T` is non-zero-sized and the capacity is nonzero, one may use + /// any method that calls [`dealloc`] with a layout of + /// `Layout::array::<T>(capacity)`; if `T` is zero-sized or the + /// capacity is zero, nothing needs to be done. /// /// [`from_raw_parts`]: Vec::from_raw_parts + /// [`dealloc`]: crate::alloc::GlobalAlloc::dealloc /// /// # Examples /// @@ -1755,6 +1784,12 @@ impl<T, A: Allocator> Vec<T, A> { /// may still invalidate this pointer. /// See the second example below for how this guarantee can be used. /// + /// The method also guarantees that, as long as `T` is not zero-sized and the capacity is + /// nonzero, the pointer may be passed into [`dealloc`] with a layout of + /// `Layout::array::<T>(capacity)` in order to deallocate the backing memory. If this is done, + /// be careful not to run the destructor of the `Vec`, as dropping it will result in + /// double-frees. Wrapping the `Vec` in a [`ManuallyDrop`] is the typical way to achieve this. + /// /// # Examples /// /// ``` @@ -1787,9 +1822,24 @@ impl<T, A: Allocator> Vec<T, A> { /// } /// ``` /// + /// Deallocating a vector using [`Box`] (which uses [`dealloc`] internally): + /// + /// ``` + /// use std::mem::{ManuallyDrop, MaybeUninit}; + /// + /// let mut v = ManuallyDrop::new(vec![0, 1, 2]); + /// let ptr = v.as_mut_ptr(); + /// let capacity = v.capacity(); + /// let slice_ptr: *mut [MaybeUninit<i32>] = + /// std::ptr::slice_from_raw_parts_mut(ptr.cast(), capacity); + /// drop(unsafe { Box::from_raw(slice_ptr) }); + /// ``` + /// /// [`as_mut_ptr`]: Vec::as_mut_ptr /// [`as_ptr`]: Vec::as_ptr /// [`as_non_null`]: Vec::as_non_null + /// [`dealloc`]: crate::alloc::GlobalAlloc::dealloc + /// [`ManuallyDrop`]: core::mem::ManuallyDrop #[stable(feature = "vec_as_ptr", since = "1.37.0")] #[rustc_const_stable(feature = "const_vec_string_slice", since = "1.87.0")] #[rustc_never_returns_null_ptr] diff --git a/library/core/src/ascii/ascii_char.rs b/library/core/src/ascii/ascii_char.rs index 054ddf84470..419e4694594 100644 --- a/library/core/src/ascii/ascii_char.rs +++ b/library/core/src/ascii/ascii_char.rs @@ -445,7 +445,15 @@ pub enum AsciiChar { } impl AsciiChar { - /// Creates an ascii character from the byte `b`, + /// The character with the lowest ASCII code. + #[unstable(feature = "ascii_char", issue = "110998")] + pub const MIN: Self = Self::Null; + + /// The character with the highest ASCII code. + #[unstable(feature = "ascii_char", issue = "110998")] + pub const MAX: Self = Self::Delete; + + /// Creates an ASCII character from the byte `b`, /// or returns `None` if it's too large. #[unstable(feature = "ascii_char", issue = "110998")] #[inline] @@ -540,6 +548,608 @@ impl AsciiChar { pub const fn as_str(&self) -> &str { crate::slice::from_ref(self).as_str() } + + /// Makes a copy of the value in its upper case equivalent. + /// + /// Letters 'a' to 'z' are mapped to 'A' to 'Z'. + /// + /// To uppercase the value in-place, use [`make_uppercase`]. + /// + /// # Examples + /// + /// ``` + /// #![feature(ascii_char, ascii_char_variants)] + /// use std::ascii; + /// + /// let lowercase_a = ascii::Char::SmallA; + /// + /// assert_eq!( + /// ascii::Char::CapitalA, + /// lowercase_a.to_uppercase(), + /// ); + /// ``` + /// + /// [`make_uppercase`]: Self::make_uppercase + #[must_use = "to uppercase the value in-place, use `make_uppercase()`"] + #[unstable(feature = "ascii_char", issue = "110998")] + #[inline] + pub const fn to_uppercase(self) -> Self { + let uppercase_byte = self.to_u8().to_ascii_uppercase(); + // SAFETY: Toggling the 6th bit won't convert ASCII to non-ASCII. + unsafe { Self::from_u8_unchecked(uppercase_byte) } + } + + /// Makes a copy of the value in its lower case equivalent. + /// + /// Letters 'A' to 'Z' are mapped to 'a' to 'z'. + /// + /// To lowercase the value in-place, use [`make_lowercase`]. + /// + /// # Examples + /// + /// ``` + /// #![feature(ascii_char, ascii_char_variants)] + /// use std::ascii; + /// + /// let uppercase_a = ascii::Char::CapitalA; + /// + /// assert_eq!( + /// ascii::Char::SmallA, + /// uppercase_a.to_lowercase(), + /// ); + /// ``` + /// + /// [`make_lowercase`]: Self::make_lowercase + #[must_use = "to lowercase the value in-place, use `make_lowercase()`"] + #[unstable(feature = "ascii_char", issue = "110998")] + #[inline] + pub const fn to_lowercase(self) -> Self { + let lowercase_byte = self.to_u8().to_ascii_lowercase(); + // SAFETY: Setting the 6th bit won't convert ASCII to non-ASCII. + unsafe { Self::from_u8_unchecked(lowercase_byte) } + } + + /// Checks that two values are a case-insensitive match. + /// + /// This is equivalent to `to_lowercase(a) == to_lowercase(b)`. + /// + /// # Examples + /// + /// ``` + /// #![feature(ascii_char, ascii_char_variants)] + /// use std::ascii; + /// + /// let lowercase_a = ascii::Char::SmallA; + /// let uppercase_a = ascii::Char::CapitalA; + /// + /// assert!(lowercase_a.eq_ignore_case(uppercase_a)); + /// ``` + #[unstable(feature = "ascii_char", issue = "110998")] + #[inline] + pub const fn eq_ignore_case(self, other: Self) -> bool { + // FIXME(const-hack) `arg.to_u8().to_ascii_lowercase()` -> `arg.to_lowercase()` + // once `PartialEq` is const for `Self`. + self.to_u8().to_ascii_lowercase() == other.to_u8().to_ascii_lowercase() + } + + /// Converts this value to its upper case equivalent in-place. + /// + /// Letters 'a' to 'z' are mapped to 'A' to 'Z'. + /// + /// To return a new uppercased value without modifying the existing one, use + /// [`to_uppercase`]. + /// + /// # Examples + /// + /// ``` + /// #![feature(ascii_char, ascii_char_variants)] + /// use std::ascii; + /// + /// let mut letter_a = ascii::Char::SmallA; + /// + /// letter_a.make_uppercase(); + /// + /// assert_eq!(ascii::Char::CapitalA, letter_a); + /// ``` + /// + /// [`to_uppercase`]: Self::to_uppercase + #[unstable(feature = "ascii_char", issue = "110998")] + #[inline] + pub const fn make_uppercase(&mut self) { + *self = self.to_uppercase(); + } + + /// Converts this value to its lower case equivalent in-place. + /// + /// Letters 'A' to 'Z' are mapped to 'a' to 'z'. + /// + /// To return a new lowercased value without modifying the existing one, use + /// [`to_lowercase`]. + /// + /// # Examples + /// + /// ``` + /// #![feature(ascii_char, ascii_char_variants)] + /// use std::ascii; + /// + /// let mut letter_a = ascii::Char::CapitalA; + /// + /// letter_a.make_lowercase(); + /// + /// assert_eq!(ascii::Char::SmallA, letter_a); + /// ``` + /// + /// [`to_lowercase`]: Self::to_lowercase + #[unstable(feature = "ascii_char", issue = "110998")] + #[inline] + pub const fn make_lowercase(&mut self) { + *self = self.to_lowercase(); + } + + /// Checks if the value is an alphabetic character: + /// + /// - 0x41 'A' ..= 0x5A 'Z', or + /// - 0x61 'a' ..= 0x7A 'z'. + /// + /// # Examples + /// + /// ``` + /// #![feature(ascii_char, ascii_char_variants)] + /// use std::ascii; + /// + /// let uppercase_a = ascii::Char::CapitalA; + /// let uppercase_g = ascii::Char::CapitalG; + /// let a = ascii::Char::SmallA; + /// let g = ascii::Char::SmallG; + /// let zero = ascii::Char::Digit0; + /// let percent = ascii::Char::PercentSign; + /// let space = ascii::Char::Space; + /// let lf = ascii::Char::LineFeed; + /// let esc = ascii::Char::Escape; + /// + /// assert!(uppercase_a.is_alphabetic()); + /// assert!(uppercase_g.is_alphabetic()); + /// assert!(a.is_alphabetic()); + /// assert!(g.is_alphabetic()); + /// assert!(!zero.is_alphabetic()); + /// assert!(!percent.is_alphabetic()); + /// assert!(!space.is_alphabetic()); + /// assert!(!lf.is_alphabetic()); + /// assert!(!esc.is_alphabetic()); + /// ``` + #[must_use] + #[unstable(feature = "ascii_char", issue = "110998")] + #[inline] + pub const fn is_alphabetic(self) -> bool { + self.to_u8().is_ascii_alphabetic() + } + + /// Checks if the value is an uppercase character: + /// 0x41 'A' ..= 0x5A 'Z'. + /// + /// # Examples + /// + /// ``` + /// #![feature(ascii_char, ascii_char_variants)] + /// use std::ascii; + /// + /// let uppercase_a = ascii::Char::CapitalA; + /// let uppercase_g = ascii::Char::CapitalG; + /// let a = ascii::Char::SmallA; + /// let g = ascii::Char::SmallG; + /// let zero = ascii::Char::Digit0; + /// let percent = ascii::Char::PercentSign; + /// let space = ascii::Char::Space; + /// let lf = ascii::Char::LineFeed; + /// let esc = ascii::Char::Escape; + /// + /// assert!(uppercase_a.is_uppercase()); + /// assert!(uppercase_g.is_uppercase()); + /// assert!(!a.is_uppercase()); + /// assert!(!g.is_uppercase()); + /// assert!(!zero.is_uppercase()); + /// assert!(!percent.is_uppercase()); + /// assert!(!space.is_uppercase()); + /// assert!(!lf.is_uppercase()); + /// assert!(!esc.is_uppercase()); + /// ``` + #[must_use] + #[unstable(feature = "ascii_char", issue = "110998")] + #[inline] + pub const fn is_uppercase(self) -> bool { + self.to_u8().is_ascii_uppercase() + } + + /// Checks if the value is a lowercase character: + /// 0x61 'a' ..= 0x7A 'z'. + /// + /// # Examples + /// + /// ``` + /// #![feature(ascii_char, ascii_char_variants)] + /// use std::ascii; + /// + /// let uppercase_a = ascii::Char::CapitalA; + /// let uppercase_g = ascii::Char::CapitalG; + /// let a = ascii::Char::SmallA; + /// let g = ascii::Char::SmallG; + /// let zero = ascii::Char::Digit0; + /// let percent = ascii::Char::PercentSign; + /// let space = ascii::Char::Space; + /// let lf = ascii::Char::LineFeed; + /// let esc = ascii::Char::Escape; + /// + /// assert!(!uppercase_a.is_lowercase()); + /// assert!(!uppercase_g.is_lowercase()); + /// assert!(a.is_lowercase()); + /// assert!(g.is_lowercase()); + /// assert!(!zero.is_lowercase()); + /// assert!(!percent.is_lowercase()); + /// assert!(!space.is_lowercase()); + /// assert!(!lf.is_lowercase()); + /// assert!(!esc.is_lowercase()); + /// ``` + #[must_use] + #[unstable(feature = "ascii_char", issue = "110998")] + #[inline] + pub const fn is_lowercase(self) -> bool { + self.to_u8().is_ascii_lowercase() + } + + /// Checks if the value is an alphanumeric character: + /// + /// - 0x41 'A' ..= 0x5A 'Z', or + /// - 0x61 'a' ..= 0x7A 'z', or + /// - 0x30 '0' ..= 0x39 '9'. + /// + /// # Examples + /// + /// ``` + /// #![feature(ascii_char, ascii_char_variants)] + /// use std::ascii; + /// + /// let uppercase_a = ascii::Char::CapitalA; + /// let uppercase_g = ascii::Char::CapitalG; + /// let a = ascii::Char::SmallA; + /// let g = ascii::Char::SmallG; + /// let zero = ascii::Char::Digit0; + /// let percent = ascii::Char::PercentSign; + /// let space = ascii::Char::Space; + /// let lf = ascii::Char::LineFeed; + /// let esc = ascii::Char::Escape; + /// + /// assert!(uppercase_a.is_alphanumeric()); + /// assert!(uppercase_g.is_alphanumeric()); + /// assert!(a.is_alphanumeric()); + /// assert!(g.is_alphanumeric()); + /// assert!(zero.is_alphanumeric()); + /// assert!(!percent.is_alphanumeric()); + /// assert!(!space.is_alphanumeric()); + /// assert!(!lf.is_alphanumeric()); + /// assert!(!esc.is_alphanumeric()); + /// ``` + #[must_use] + #[unstable(feature = "ascii_char", issue = "110998")] + #[inline] + pub const fn is_alphanumeric(self) -> bool { + self.to_u8().is_ascii_alphanumeric() + } + + /// Checks if the value is a decimal digit: + /// 0x30 '0' ..= 0x39 '9'. + /// + /// # Examples + /// + /// ``` + /// #![feature(ascii_char, ascii_char_variants)] + /// use std::ascii; + /// + /// let uppercase_a = ascii::Char::CapitalA; + /// let uppercase_g = ascii::Char::CapitalG; + /// let a = ascii::Char::SmallA; + /// let g = ascii::Char::SmallG; + /// let zero = ascii::Char::Digit0; + /// let percent = ascii::Char::PercentSign; + /// let space = ascii::Char::Space; + /// let lf = ascii::Char::LineFeed; + /// let esc = ascii::Char::Escape; + /// + /// assert!(!uppercase_a.is_digit()); + /// assert!(!uppercase_g.is_digit()); + /// assert!(!a.is_digit()); + /// assert!(!g.is_digit()); + /// assert!(zero.is_digit()); + /// assert!(!percent.is_digit()); + /// assert!(!space.is_digit()); + /// assert!(!lf.is_digit()); + /// assert!(!esc.is_digit()); + /// ``` + #[must_use] + #[unstable(feature = "ascii_char", issue = "110998")] + #[inline] + pub const fn is_digit(self) -> bool { + self.to_u8().is_ascii_digit() + } + + /// Checks if the value is an octal digit: + /// 0x30 '0' ..= 0x37 '7'. + /// + /// # Examples + /// + /// ``` + /// #![feature(ascii_char, ascii_char_variants, is_ascii_octdigit)] + /// + /// use std::ascii; + /// + /// let uppercase_a = ascii::Char::CapitalA; + /// let a = ascii::Char::SmallA; + /// let zero = ascii::Char::Digit0; + /// let seven = ascii::Char::Digit7; + /// let eight = ascii::Char::Digit8; + /// let percent = ascii::Char::PercentSign; + /// let lf = ascii::Char::LineFeed; + /// let esc = ascii::Char::Escape; + /// + /// assert!(!uppercase_a.is_octdigit()); + /// assert!(!a.is_octdigit()); + /// assert!(zero.is_octdigit()); + /// assert!(seven.is_octdigit()); + /// assert!(!eight.is_octdigit()); + /// assert!(!percent.is_octdigit()); + /// assert!(!lf.is_octdigit()); + /// assert!(!esc.is_octdigit()); + /// ``` + #[must_use] + // This is blocked on two unstable features. Please ensure both are + // stabilized before marking this method as stable. + #[unstable(feature = "ascii_char", issue = "110998")] + // #[unstable(feature = "is_ascii_octdigit", issue = "101288")] + #[inline] + pub const fn is_octdigit(self) -> bool { + self.to_u8().is_ascii_octdigit() + } + + /// Checks if the value is a hexadecimal digit: + /// + /// - 0x30 '0' ..= 0x39 '9', or + /// - 0x41 'A' ..= 0x46 'F', or + /// - 0x61 'a' ..= 0x66 'f'. + /// + /// # Examples + /// + /// ``` + /// #![feature(ascii_char, ascii_char_variants)] + /// use std::ascii; + /// + /// let uppercase_a = ascii::Char::CapitalA; + /// let uppercase_g = ascii::Char::CapitalG; + /// let a = ascii::Char::SmallA; + /// let g = ascii::Char::SmallG; + /// let zero = ascii::Char::Digit0; + /// let percent = ascii::Char::PercentSign; + /// let space = ascii::Char::Space; + /// let lf = ascii::Char::LineFeed; + /// let esc = ascii::Char::Escape; + /// + /// assert!(uppercase_a.is_hexdigit()); + /// assert!(!uppercase_g.is_hexdigit()); + /// assert!(a.is_hexdigit()); + /// assert!(!g.is_hexdigit()); + /// assert!(zero.is_hexdigit()); + /// assert!(!percent.is_hexdigit()); + /// assert!(!space.is_hexdigit()); + /// assert!(!lf.is_hexdigit()); + /// assert!(!esc.is_hexdigit()); + /// ``` + #[must_use] + #[unstable(feature = "ascii_char", issue = "110998")] + #[inline] + pub const fn is_hexdigit(self) -> bool { + self.to_u8().is_ascii_hexdigit() + } + + /// Checks if the value is a punctuation character: + /// + /// - 0x21 ..= 0x2F `! " # $ % & ' ( ) * + , - . /`, or + /// - 0x3A ..= 0x40 `: ; < = > ? @`, or + /// - 0x5B ..= 0x60 `` [ \ ] ^ _ ` ``, or + /// - 0x7B ..= 0x7E `{ | } ~` + /// + /// # Examples + /// + /// ``` + /// #![feature(ascii_char, ascii_char_variants)] + /// use std::ascii; + /// + /// let uppercase_a = ascii::Char::CapitalA; + /// let uppercase_g = ascii::Char::CapitalG; + /// let a = ascii::Char::SmallA; + /// let g = ascii::Char::SmallG; + /// let zero = ascii::Char::Digit0; + /// let percent = ascii::Char::PercentSign; + /// let space = ascii::Char::Space; + /// let lf = ascii::Char::LineFeed; + /// let esc = ascii::Char::Escape; + /// + /// assert!(!uppercase_a.is_punctuation()); + /// assert!(!uppercase_g.is_punctuation()); + /// assert!(!a.is_punctuation()); + /// assert!(!g.is_punctuation()); + /// assert!(!zero.is_punctuation()); + /// assert!(percent.is_punctuation()); + /// assert!(!space.is_punctuation()); + /// assert!(!lf.is_punctuation()); + /// assert!(!esc.is_punctuation()); + /// ``` + #[must_use] + #[unstable(feature = "ascii_char", issue = "110998")] + #[inline] + pub const fn is_punctuation(self) -> bool { + self.to_u8().is_ascii_punctuation() + } + + /// Checks if the value is a graphic character: + /// 0x21 '!' ..= 0x7E '~'. + /// + /// # Examples + /// + /// ``` + /// #![feature(ascii_char, ascii_char_variants)] + /// use std::ascii; + /// + /// let uppercase_a = ascii::Char::CapitalA; + /// let uppercase_g = ascii::Char::CapitalG; + /// let a = ascii::Char::SmallA; + /// let g = ascii::Char::SmallG; + /// let zero = ascii::Char::Digit0; + /// let percent = ascii::Char::PercentSign; + /// let space = ascii::Char::Space; + /// let lf = ascii::Char::LineFeed; + /// let esc = ascii::Char::Escape; + /// + /// assert!(uppercase_a.is_graphic()); + /// assert!(uppercase_g.is_graphic()); + /// assert!(a.is_graphic()); + /// assert!(g.is_graphic()); + /// assert!(zero.is_graphic()); + /// assert!(percent.is_graphic()); + /// assert!(!space.is_graphic()); + /// assert!(!lf.is_graphic()); + /// assert!(!esc.is_graphic()); + /// ``` + #[must_use] + #[unstable(feature = "ascii_char", issue = "110998")] + #[inline] + pub const fn is_graphic(self) -> bool { + self.to_u8().is_ascii_graphic() + } + + /// Checks if the value is a whitespace character: + /// 0x20 SPACE, 0x09 HORIZONTAL TAB, 0x0A LINE FEED, + /// 0x0C FORM FEED, or 0x0D CARRIAGE RETURN. + /// + /// Rust uses the WhatWG Infra Standard's [definition of ASCII + /// whitespace][infra-aw]. There are several other definitions in + /// wide use. For instance, [the POSIX locale][pct] includes + /// 0x0B VERTICAL TAB as well as all the above characters, + /// but—from the very same specification—[the default rule for + /// "field splitting" in the Bourne shell][bfs] considers *only* + /// SPACE, HORIZONTAL TAB, and LINE FEED as whitespace. + /// + /// If you are writing a program that will process an existing + /// file format, check what that format's definition of whitespace is + /// before using this function. + /// + /// [infra-aw]: https://infra.spec.whatwg.org/#ascii-whitespace + /// [pct]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html#tag_07_03_01 + /// [bfs]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05 + /// + /// # Examples + /// + /// ``` + /// #![feature(ascii_char, ascii_char_variants)] + /// use std::ascii; + /// + /// let uppercase_a = ascii::Char::CapitalA; + /// let uppercase_g = ascii::Char::CapitalG; + /// let a = ascii::Char::SmallA; + /// let g = ascii::Char::SmallG; + /// let zero = ascii::Char::Digit0; + /// let percent = ascii::Char::PercentSign; + /// let space = ascii::Char::Space; + /// let lf = ascii::Char::LineFeed; + /// let esc = ascii::Char::Escape; + /// + /// assert!(!uppercase_a.is_whitespace()); + /// assert!(!uppercase_g.is_whitespace()); + /// assert!(!a.is_whitespace()); + /// assert!(!g.is_whitespace()); + /// assert!(!zero.is_whitespace()); + /// assert!(!percent.is_whitespace()); + /// assert!(space.is_whitespace()); + /// assert!(lf.is_whitespace()); + /// assert!(!esc.is_whitespace()); + /// ``` + #[must_use] + #[unstable(feature = "ascii_char", issue = "110998")] + #[inline] + pub const fn is_whitespace(self) -> bool { + self.to_u8().is_ascii_whitespace() + } + + /// Checks if the value is a control character: + /// 0x00 NUL ..= 0x1F UNIT SEPARATOR, or 0x7F DELETE. + /// Note that most whitespace characters are control + /// characters, but SPACE is not. + /// + /// # Examples + /// + /// ``` + /// #![feature(ascii_char, ascii_char_variants)] + /// use std::ascii; + /// + /// let uppercase_a = ascii::Char::CapitalA; + /// let uppercase_g = ascii::Char::CapitalG; + /// let a = ascii::Char::SmallA; + /// let g = ascii::Char::SmallG; + /// let zero = ascii::Char::Digit0; + /// let percent = ascii::Char::PercentSign; + /// let space = ascii::Char::Space; + /// let lf = ascii::Char::LineFeed; + /// let esc = ascii::Char::Escape; + /// + /// assert!(!uppercase_a.is_control()); + /// assert!(!uppercase_g.is_control()); + /// assert!(!a.is_control()); + /// assert!(!g.is_control()); + /// assert!(!zero.is_control()); + /// assert!(!percent.is_control()); + /// assert!(!space.is_control()); + /// assert!(lf.is_control()); + /// assert!(esc.is_control()); + /// ``` + #[must_use] + #[unstable(feature = "ascii_char", issue = "110998")] + #[inline] + pub const fn is_control(self) -> bool { + self.to_u8().is_ascii_control() + } + + /// Returns an iterator that produces an escaped version of a + /// character. + /// + /// The behavior is identical to + /// [`ascii::escape_default`](crate::ascii::escape_default). + /// + /// # Examples + /// + /// ``` + /// #![feature(ascii_char, ascii_char_variants)] + /// use std::ascii; + /// + /// let zero = ascii::Char::Digit0; + /// let tab = ascii::Char::CharacterTabulation; + /// let cr = ascii::Char::CarriageReturn; + /// let lf = ascii::Char::LineFeed; + /// let apostrophe = ascii::Char::Apostrophe; + /// let double_quote = ascii::Char::QuotationMark; + /// let backslash = ascii::Char::ReverseSolidus; + /// + /// assert_eq!("0", zero.escape_ascii().to_string()); + /// assert_eq!("\\t", tab.escape_ascii().to_string()); + /// assert_eq!("\\r", cr.escape_ascii().to_string()); + /// assert_eq!("\\n", lf.escape_ascii().to_string()); + /// assert_eq!("\\'", apostrophe.escape_ascii().to_string()); + /// assert_eq!("\\\"", double_quote.escape_ascii().to_string()); + /// assert_eq!("\\\\", backslash.escape_ascii().to_string()); + /// ``` + #[must_use = "this returns the escaped character as an iterator, \ + without modifying the original"] + #[unstable(feature = "ascii_char", issue = "110998")] + #[inline] + pub fn escape_ascii(self) -> super::EscapeDefault { + super::escape_default(self.to_u8()) + } } macro_rules! into_int_impl { diff --git a/library/core/src/clone.rs b/library/core/src/clone.rs index e315c4fac08..0add77b2bc8 100644 --- a/library/core/src/clone.rs +++ b/library/core/src/clone.rs @@ -139,6 +139,34 @@ mod uninit; /// // Note: With the manual implementations the above line will compile. /// ``` /// +/// ## `Clone` and `PartialEq`/`Eq` +/// `Clone` is intended for the duplication of objects. Consequently, when implementing +/// both `Clone` and [`PartialEq`], the following property is expected to hold: +/// ```text +/// x == x -> x.clone() == x +/// ``` +/// In other words, if an object compares equal to itself, +/// its clone must also compare equal to the original. +/// +/// For types that also implement [`Eq`] – for which `x == x` always holds – +/// this implies that `x.clone() == x` must always be true. +/// Standard library collections such as +/// [`HashMap`], [`HashSet`], [`BTreeMap`], [`BTreeSet`] and [`BinaryHeap`] +/// rely on their keys respecting this property for correct behavior. +/// Furthermore, these collections require that cloning a key preserves the outcome of the +/// [`Hash`] and [`Ord`] methods. Thankfully, this follows automatically from `x.clone() == x` +/// if `Hash` and `Ord` are correctly implemented according to their own requirements. +/// +/// When deriving both `Clone` and [`PartialEq`] using `#[derive(Clone, PartialEq)]` +/// or when additionally deriving [`Eq`] using `#[derive(Clone, PartialEq, Eq)]`, +/// then this property is automatically upheld – provided that it is satisfied by +/// the underlying types. +/// +/// Violating this property is a logic error. The behavior resulting from a logic error is not +/// specified, but users of the trait must ensure that such logic errors do *not* result in +/// undefined behavior. This means that `unsafe` code **must not** rely on this property +/// being satisfied. +/// /// ## Additional implementors /// /// In addition to the [implementors listed below][impls], @@ -152,6 +180,11 @@ mod uninit; /// (even if the referent doesn't), /// while variables captured by mutable reference never implement `Clone`. /// +/// [`HashMap`]: ../../std/collections/struct.HashMap.html +/// [`HashSet`]: ../../std/collections/struct.HashSet.html +/// [`BTreeMap`]: ../../std/collections/struct.BTreeMap.html +/// [`BTreeSet`]: ../../std/collections/struct.BTreeSet.html +/// [`BinaryHeap`]: ../../std/collections/struct.BinaryHeap.html /// [impls]: #implementors #[stable(feature = "rust1", since = "1.0.0")] #[lang = "clone"] diff --git a/library/core/src/internal_macros.rs b/library/core/src/internal_macros.rs index 2aaefba2468..f90818c7969 100644 --- a/library/core/src/internal_macros.rs +++ b/library/core/src/internal_macros.rs @@ -1,13 +1,9 @@ // implements the unary operator "op &T" // based on "op T" where T is expected to be `Copy`able macro_rules! forward_ref_unop { - (impl $imp:ident, $method:ident for $t:ty) => { - forward_ref_unop!(impl $imp, $method for $t, - #[stable(feature = "rust1", since = "1.0.0")]); - }; - (impl $imp:ident, $method:ident for $t:ty, #[$attr:meta]) => { - #[$attr] - impl $imp for &$t { + (impl $imp:ident, $method:ident for $t:ty, $(#[$attr:meta])+) => { + $(#[$attr])+ + impl const $imp for &$t { type Output = <$t as $imp>::Output; #[inline] @@ -21,13 +17,9 @@ macro_rules! forward_ref_unop { // implements binary operators "&T op U", "T op &U", "&T op &U" // based on "T op U" where T and U are expected to be `Copy`able macro_rules! forward_ref_binop { - (impl $imp:ident, $method:ident for $t:ty, $u:ty) => { - forward_ref_binop!(impl $imp, $method for $t, $u, - #[stable(feature = "rust1", since = "1.0.0")]); - }; - (impl $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => { - #[$attr] - impl<'a> $imp<$u> for &'a $t { + (impl $imp:ident, $method:ident for $t:ty, $u:ty, $(#[$attr:meta])+) => { + $(#[$attr])+ + impl const $imp<$u> for &$t { type Output = <$t as $imp<$u>>::Output; #[inline] @@ -37,8 +29,8 @@ macro_rules! forward_ref_binop { } } - #[$attr] - impl $imp<&$u> for $t { + $(#[$attr])+ + impl const $imp<&$u> for $t { type Output = <$t as $imp<$u>>::Output; #[inline] @@ -48,8 +40,8 @@ macro_rules! forward_ref_binop { } } - #[$attr] - impl $imp<&$u> for &$t { + $(#[$attr])+ + impl const $imp<&$u> for &$t { type Output = <$t as $imp<$u>>::Output; #[inline] @@ -64,13 +56,9 @@ macro_rules! forward_ref_binop { // implements "T op= &U", based on "T op= U" // where U is expected to be `Copy`able macro_rules! forward_ref_op_assign { - (impl $imp:ident, $method:ident for $t:ty, $u:ty) => { - forward_ref_op_assign!(impl $imp, $method for $t, $u, - #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")]); - }; - (impl $imp:ident, $method:ident for $t:ty, $u:ty, #[$attr:meta]) => { - #[$attr] - impl $imp<&$u> for $t { + (impl $imp:ident, $method:ident for $t:ty, $u:ty, $(#[$attr:meta])+) => { + $(#[$attr])+ + impl const $imp<&$u> for $t { #[inline] #[track_caller] fn $method(&mut self, other: &$u) { diff --git a/library/core/src/net/ip_addr.rs b/library/core/src/net/ip_addr.rs index 6adeb2aa3fd..87f2110034c 100644 --- a/library/core/src/net/ip_addr.rs +++ b/library/core/src/net/ip_addr.rs @@ -2,7 +2,6 @@ use super::display_buffer::DisplayBuffer; use crate::cmp::Ordering; use crate::fmt::{self, Write}; use crate::hash::{Hash, Hasher}; -use crate::iter; use crate::mem::transmute; use crate::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, Not}; @@ -2348,20 +2347,24 @@ impl const From<[u16; 8]> for IpAddr { } #[stable(feature = "ip_bitops", since = "1.75.0")] -impl Not for Ipv4Addr { +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +impl const Not for Ipv4Addr { type Output = Ipv4Addr; #[inline] fn not(mut self) -> Ipv4Addr { - for octet in &mut self.octets { - *octet = !*octet; + let mut idx = 0; + while idx < 4 { + self.octets[idx] = !self.octets[idx]; + idx += 1; } self } } #[stable(feature = "ip_bitops", since = "1.75.0")] -impl Not for &'_ Ipv4Addr { +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +impl const Not for &'_ Ipv4Addr { type Output = Ipv4Addr; #[inline] @@ -2371,20 +2374,24 @@ impl Not for &'_ Ipv4Addr { } #[stable(feature = "ip_bitops", since = "1.75.0")] -impl Not for Ipv6Addr { +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +impl const Not for Ipv6Addr { type Output = Ipv6Addr; #[inline] fn not(mut self) -> Ipv6Addr { - for octet in &mut self.octets { - *octet = !*octet; + let mut idx = 0; + while idx < 16 { + self.octets[idx] = !self.octets[idx]; + idx += 1; } self } } #[stable(feature = "ip_bitops", since = "1.75.0")] -impl Not for &'_ Ipv6Addr { +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +impl const Not for &'_ Ipv6Addr { type Output = Ipv6Addr; #[inline] @@ -2400,23 +2407,25 @@ macro_rules! bitop_impls { )*) => { $( $(#[$attr])* - impl $BitOpAssign for $ty { + impl const $BitOpAssign for $ty { fn $bitop_assign(&mut self, rhs: $ty) { - for (lhs, rhs) in iter::zip(&mut self.octets, rhs.octets) { - lhs.$bitop_assign(rhs); + let mut idx = 0; + while idx < self.octets.len() { + self.octets[idx].$bitop_assign(rhs.octets[idx]); + idx += 1; } } } $(#[$attr])* - impl $BitOpAssign<&'_ $ty> for $ty { + impl const $BitOpAssign<&'_ $ty> for $ty { fn $bitop_assign(&mut self, rhs: &'_ $ty) { self.$bitop_assign(*rhs); } } $(#[$attr])* - impl $BitOp for $ty { + impl const $BitOp for $ty { type Output = $ty; #[inline] @@ -2427,7 +2436,7 @@ macro_rules! bitop_impls { } $(#[$attr])* - impl $BitOp<&'_ $ty> for $ty { + impl const $BitOp<&'_ $ty> for $ty { type Output = $ty; #[inline] @@ -2438,7 +2447,7 @@ macro_rules! bitop_impls { } $(#[$attr])* - impl $BitOp<$ty> for &'_ $ty { + impl const $BitOp<$ty> for &'_ $ty { type Output = $ty; #[inline] @@ -2450,7 +2459,7 @@ macro_rules! bitop_impls { } $(#[$attr])* - impl $BitOp<&'_ $ty> for &'_ $ty { + impl const $BitOp<&'_ $ty> for &'_ $ty { type Output = $ty; #[inline] @@ -2466,12 +2475,16 @@ macro_rules! bitop_impls { bitop_impls! { #[stable(feature = "ip_bitops", since = "1.75.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] impl (BitAnd, BitAndAssign) for Ipv4Addr = (bitand, bitand_assign); #[stable(feature = "ip_bitops", since = "1.75.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] impl (BitOr, BitOrAssign) for Ipv4Addr = (bitor, bitor_assign); #[stable(feature = "ip_bitops", since = "1.75.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] impl (BitAnd, BitAndAssign) for Ipv6Addr = (bitand, bitand_assign); #[stable(feature = "ip_bitops", since = "1.75.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] impl (BitOr, BitOrAssign) for Ipv6Addr = (bitor, bitor_assign); } diff --git a/library/core/src/num/nonzero.rs b/library/core/src/num/nonzero.rs index 08a66361e6f..308d722f5d5 100644 --- a/library/core/src/num/nonzero.rs +++ b/library/core/src/num/nonzero.rs @@ -310,9 +310,10 @@ where } #[stable(feature = "nonzero_bitor", since = "1.45.0")] -impl<T> BitOr for NonZero<T> +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +impl<T> const BitOr for NonZero<T> where - T: ZeroablePrimitive + BitOr<Output = T>, + T: ZeroablePrimitive + [const] BitOr<Output = T>, { type Output = Self; @@ -324,9 +325,10 @@ where } #[stable(feature = "nonzero_bitor", since = "1.45.0")] -impl<T> BitOr<T> for NonZero<T> +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +impl<T> const BitOr<T> for NonZero<T> where - T: ZeroablePrimitive + BitOr<Output = T>, + T: ZeroablePrimitive + [const] BitOr<Output = T>, { type Output = Self; @@ -338,9 +340,10 @@ where } #[stable(feature = "nonzero_bitor", since = "1.45.0")] -impl<T> BitOr<NonZero<T>> for T +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +impl<T> const BitOr<NonZero<T>> for T where - T: ZeroablePrimitive + BitOr<Output = T>, + T: ZeroablePrimitive + [const] BitOr<Output = T>, { type Output = NonZero<T>; @@ -352,10 +355,11 @@ where } #[stable(feature = "nonzero_bitor", since = "1.45.0")] -impl<T> BitOrAssign for NonZero<T> +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +impl<T> const BitOrAssign for NonZero<T> where T: ZeroablePrimitive, - Self: BitOr<Output = Self>, + Self: [const] BitOr<Output = Self>, { #[inline] fn bitor_assign(&mut self, rhs: Self) { @@ -364,10 +368,11 @@ where } #[stable(feature = "nonzero_bitor", since = "1.45.0")] -impl<T> BitOrAssign<T> for NonZero<T> +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +impl<T> const BitOrAssign<T> for NonZero<T> where T: ZeroablePrimitive, - Self: BitOr<T, Output = Self>, + Self: [const] BitOr<T, Output = Self>, { #[inline] fn bitor_assign(&mut self, rhs: T) { @@ -1239,7 +1244,8 @@ macro_rules! nonzero_integer_signedness_dependent_impls { // Impls for unsigned nonzero types only. (unsigned $Int:ty) => { #[stable(feature = "nonzero_div", since = "1.51.0")] - impl Div<NonZero<$Int>> for $Int { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const Div<NonZero<$Int>> for $Int { type Output = $Int; /// Same as `self / other.get()`, but because `other` is a `NonZero<_>`, @@ -1257,7 +1263,8 @@ macro_rules! nonzero_integer_signedness_dependent_impls { } #[stable(feature = "nonzero_div_assign", since = "1.79.0")] - impl DivAssign<NonZero<$Int>> for $Int { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const DivAssign<NonZero<$Int>> for $Int { /// Same as `self /= other.get()`, but because `other` is a `NonZero<_>`, /// there's never a runtime check for division-by-zero. /// @@ -1270,7 +1277,8 @@ macro_rules! nonzero_integer_signedness_dependent_impls { } #[stable(feature = "nonzero_div", since = "1.51.0")] - impl Rem<NonZero<$Int>> for $Int { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const Rem<NonZero<$Int>> for $Int { type Output = $Int; /// This operation satisfies `n % d == n - (n / d) * d`, and cannot panic. @@ -1283,7 +1291,8 @@ macro_rules! nonzero_integer_signedness_dependent_impls { } #[stable(feature = "nonzero_div_assign", since = "1.79.0")] - impl RemAssign<NonZero<$Int>> for $Int { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const RemAssign<NonZero<$Int>> for $Int { /// This operation satisfies `n % d == n - (n / d) * d`, and cannot panic. #[inline] fn rem_assign(&mut self, other: NonZero<$Int>) { @@ -1323,7 +1332,8 @@ macro_rules! nonzero_integer_signedness_dependent_impls { // Impls for signed nonzero types only. (signed $Int:ty) => { #[stable(feature = "signed_nonzero_neg", since = "1.71.0")] - impl Neg for NonZero<$Int> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const Neg for NonZero<$Int> { type Output = Self; #[inline] @@ -1334,7 +1344,8 @@ macro_rules! nonzero_integer_signedness_dependent_impls { } forward_ref_unop! { impl Neg, neg for NonZero<$Int>, - #[stable(feature = "signed_nonzero_neg", since = "1.71.0")] } + #[stable(feature = "signed_nonzero_neg", since = "1.71.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } }; } diff --git a/library/core/src/num/saturating.rs b/library/core/src/num/saturating.rs index 4460e430aec..c7040721b93 100644 --- a/library/core/src/num/saturating.rs +++ b/library/core/src/num/saturating.rs @@ -109,7 +109,8 @@ impl<T: fmt::UpperHex> fmt::UpperHex for Saturating<T> { // // *self = *self << other; // // } // // } -// // forward_ref_op_assign! { impl ShlAssign, shl_assign for Saturating<$t>, $f } +// // forward_ref_op_assign! { impl ShlAssign, shl_assign for Saturating<$t>, $f, +// // #[unstable(feature = "saturating_int_impl", issue = "87920")] } // // #[unstable(feature = "saturating_int_impl", issue = "87920")] // impl Shr<$f> for Saturating<$t> { @@ -134,7 +135,8 @@ impl<T: fmt::UpperHex> fmt::UpperHex for Saturating<T> { // *self = *self >> other; // } // } -// forward_ref_op_assign! { impl ShrAssign, shr_assign for Saturating<$t>, $f } +// forward_ref_op_assign! { impl ShrAssign, shr_assign for Saturating<$t>, $f, +// #[unstable(feature = "saturating_int_impl", issue = "87920")] } // }; // } // @@ -159,7 +161,8 @@ impl<T: fmt::UpperHex> fmt::UpperHex for Saturating<T> { // *self = *self << other; // } // } -// forward_ref_op_assign! { impl ShlAssign, shl_assign for Saturating<$t>, $f } +// forward_ref_op_assign! { impl ShlAssign, shl_assign for Saturating<$t>, $f, +// #[unstable(feature = "saturating_int_impl", issue = "87920")] } // // #[unstable(feature = "saturating_int_impl", issue = "87920")] // impl Shr<$f> for Saturating<$t> { @@ -180,7 +183,8 @@ impl<T: fmt::UpperHex> fmt::UpperHex for Saturating<T> { // *self = *self >> other; // } // } -// forward_ref_op_assign! { impl ShrAssign, shr_assign for Saturating<$t>, $f } +// forward_ref_op_assign! { impl ShrAssign, shr_assign for Saturating<$t>, $f, +// #[unstable(feature = "saturating_int_impl", issue = "87920")] } // }; // } // @@ -209,7 +213,8 @@ impl<T: fmt::UpperHex> fmt::UpperHex for Saturating<T> { macro_rules! saturating_impl { ($($t:ty)*) => ($( #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl Add for Saturating<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const Add for Saturating<$t> { type Output = Saturating<$t>; #[inline] @@ -218,28 +223,36 @@ macro_rules! saturating_impl { } } forward_ref_binop! { impl Add, add for Saturating<$t>, Saturating<$t>, - #[stable(feature = "saturating_int_impl", since = "1.74.0")] } + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl AddAssign for Saturating<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const AddAssign for Saturating<$t> { #[inline] fn add_assign(&mut self, other: Saturating<$t>) { *self = *self + other; } } - forward_ref_op_assign! { impl AddAssign, add_assign for Saturating<$t>, Saturating<$t> } + forward_ref_op_assign! { impl AddAssign, add_assign for Saturating<$t>, Saturating<$t>, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "saturating_int_assign_impl", since = "1.74.0")] - impl AddAssign<$t> for Saturating<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const AddAssign<$t> for Saturating<$t> { #[inline] fn add_assign(&mut self, other: $t) { *self = *self + Saturating(other); } } - forward_ref_op_assign! { impl AddAssign, add_assign for Saturating<$t>, $t } + forward_ref_op_assign! { impl AddAssign, add_assign for Saturating<$t>, $t, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl Sub for Saturating<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const Sub for Saturating<$t> { type Output = Saturating<$t>; #[inline] @@ -248,28 +261,36 @@ macro_rules! saturating_impl { } } forward_ref_binop! { impl Sub, sub for Saturating<$t>, Saturating<$t>, - #[stable(feature = "saturating_int_impl", since = "1.74.0")] } + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl SubAssign for Saturating<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const SubAssign for Saturating<$t> { #[inline] fn sub_assign(&mut self, other: Saturating<$t>) { *self = *self - other; } } - forward_ref_op_assign! { impl SubAssign, sub_assign for Saturating<$t>, Saturating<$t> } + forward_ref_op_assign! { impl SubAssign, sub_assign for Saturating<$t>, Saturating<$t>, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "saturating_int_assign_impl", since = "1.74.0")] - impl SubAssign<$t> for Saturating<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const SubAssign<$t> for Saturating<$t> { #[inline] fn sub_assign(&mut self, other: $t) { *self = *self - Saturating(other); } } - forward_ref_op_assign! { impl SubAssign, sub_assign for Saturating<$t>, $t } + forward_ref_op_assign! { impl SubAssign, sub_assign for Saturating<$t>, $t, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl Mul for Saturating<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const Mul for Saturating<$t> { type Output = Saturating<$t>; #[inline] @@ -278,25 +299,32 @@ macro_rules! saturating_impl { } } forward_ref_binop! { impl Mul, mul for Saturating<$t>, Saturating<$t>, - #[stable(feature = "saturating_int_impl", since = "1.74.0")] } + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl MulAssign for Saturating<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const MulAssign for Saturating<$t> { #[inline] fn mul_assign(&mut self, other: Saturating<$t>) { *self = *self * other; } } - forward_ref_op_assign! { impl MulAssign, mul_assign for Saturating<$t>, Saturating<$t> } + forward_ref_op_assign! { impl MulAssign, mul_assign for Saturating<$t>, Saturating<$t>, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "saturating_int_assign_impl", since = "1.74.0")] - impl MulAssign<$t> for Saturating<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const MulAssign<$t> for Saturating<$t> { #[inline] fn mul_assign(&mut self, other: $t) { *self = *self * Saturating(other); } } - forward_ref_op_assign! { impl MulAssign, mul_assign for Saturating<$t>, $t } + forward_ref_op_assign! { impl MulAssign, mul_assign for Saturating<$t>, $t, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } /// # Examples /// @@ -314,7 +342,8 @@ macro_rules! saturating_impl { #[doc = concat!("let _ = Saturating(0", stringify!($t), ") / Saturating(0);")] /// ``` #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl Div for Saturating<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const Div for Saturating<$t> { type Output = Saturating<$t>; #[inline] @@ -323,29 +352,36 @@ macro_rules! saturating_impl { } } forward_ref_binop! { impl Div, div for Saturating<$t>, Saturating<$t>, - #[stable(feature = "saturating_int_impl", since = "1.74.0")] } - + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl DivAssign for Saturating<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const DivAssign for Saturating<$t> { #[inline] fn div_assign(&mut self, other: Saturating<$t>) { *self = *self / other; } } - forward_ref_op_assign! { impl DivAssign, div_assign for Saturating<$t>, Saturating<$t> } + forward_ref_op_assign! { impl DivAssign, div_assign for Saturating<$t>, Saturating<$t>, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "saturating_int_assign_impl", since = "1.74.0")] - impl DivAssign<$t> for Saturating<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const DivAssign<$t> for Saturating<$t> { #[inline] fn div_assign(&mut self, other: $t) { *self = *self / Saturating(other); } } - forward_ref_op_assign! { impl DivAssign, div_assign for Saturating<$t>, $t } + forward_ref_op_assign! { impl DivAssign, div_assign for Saturating<$t>, $t, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl Rem for Saturating<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const Rem for Saturating<$t> { type Output = Saturating<$t>; #[inline] @@ -354,28 +390,36 @@ macro_rules! saturating_impl { } } forward_ref_binop! { impl Rem, rem for Saturating<$t>, Saturating<$t>, - #[stable(feature = "saturating_int_impl", since = "1.74.0")] } + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl RemAssign for Saturating<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const RemAssign for Saturating<$t> { #[inline] fn rem_assign(&mut self, other: Saturating<$t>) { *self = *self % other; } } - forward_ref_op_assign! { impl RemAssign, rem_assign for Saturating<$t>, Saturating<$t> } + forward_ref_op_assign! { impl RemAssign, rem_assign for Saturating<$t>, Saturating<$t>, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "saturating_int_assign_impl", since = "1.74.0")] - impl RemAssign<$t> for Saturating<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const RemAssign<$t> for Saturating<$t> { #[inline] fn rem_assign(&mut self, other: $t) { *self = *self % Saturating(other); } } - forward_ref_op_assign! { impl RemAssign, rem_assign for Saturating<$t>, $t } + forward_ref_op_assign! { impl RemAssign, rem_assign for Saturating<$t>, $t, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl Not for Saturating<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const Not for Saturating<$t> { type Output = Saturating<$t>; #[inline] @@ -384,10 +428,12 @@ macro_rules! saturating_impl { } } forward_ref_unop! { impl Not, not for Saturating<$t>, - #[stable(feature = "saturating_int_impl", since = "1.74.0")] } + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl BitXor for Saturating<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const BitXor for Saturating<$t> { type Output = Saturating<$t>; #[inline] @@ -396,28 +442,36 @@ macro_rules! saturating_impl { } } forward_ref_binop! { impl BitXor, bitxor for Saturating<$t>, Saturating<$t>, - #[stable(feature = "saturating_int_impl", since = "1.74.0")] } + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl BitXorAssign for Saturating<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const BitXorAssign for Saturating<$t> { #[inline] fn bitxor_assign(&mut self, other: Saturating<$t>) { *self = *self ^ other; } } - forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for Saturating<$t>, Saturating<$t> } + forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for Saturating<$t>, Saturating<$t>, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "saturating_int_assign_impl", since = "1.74.0")] - impl BitXorAssign<$t> for Saturating<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const BitXorAssign<$t> for Saturating<$t> { #[inline] fn bitxor_assign(&mut self, other: $t) { *self = *self ^ Saturating(other); } } - forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for Saturating<$t>, $t } + forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for Saturating<$t>, $t, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl BitOr for Saturating<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const BitOr for Saturating<$t> { type Output = Saturating<$t>; #[inline] @@ -426,28 +480,36 @@ macro_rules! saturating_impl { } } forward_ref_binop! { impl BitOr, bitor for Saturating<$t>, Saturating<$t>, - #[stable(feature = "saturating_int_impl", since = "1.74.0")] } + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl BitOrAssign for Saturating<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const BitOrAssign for Saturating<$t> { #[inline] fn bitor_assign(&mut self, other: Saturating<$t>) { *self = *self | other; } } - forward_ref_op_assign! { impl BitOrAssign, bitor_assign for Saturating<$t>, Saturating<$t> } + forward_ref_op_assign! { impl BitOrAssign, bitor_assign for Saturating<$t>, Saturating<$t>, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "saturating_int_assign_impl", since = "1.74.0")] - impl BitOrAssign<$t> for Saturating<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const BitOrAssign<$t> for Saturating<$t> { #[inline] fn bitor_assign(&mut self, other: $t) { *self = *self | Saturating(other); } } - forward_ref_op_assign! { impl BitOrAssign, bitor_assign for Saturating<$t>, $t } + forward_ref_op_assign! { impl BitOrAssign, bitor_assign for Saturating<$t>, $t, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl BitAnd for Saturating<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const BitAnd for Saturating<$t> { type Output = Saturating<$t>; #[inline] @@ -456,25 +518,32 @@ macro_rules! saturating_impl { } } forward_ref_binop! { impl BitAnd, bitand for Saturating<$t>, Saturating<$t>, - #[stable(feature = "saturating_int_impl", since = "1.74.0")] } + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl BitAndAssign for Saturating<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const BitAndAssign for Saturating<$t> { #[inline] fn bitand_assign(&mut self, other: Saturating<$t>) { *self = *self & other; } } - forward_ref_op_assign! { impl BitAndAssign, bitand_assign for Saturating<$t>, Saturating<$t> } + forward_ref_op_assign! { impl BitAndAssign, bitand_assign for Saturating<$t>, Saturating<$t>, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "saturating_int_assign_impl", since = "1.74.0")] - impl BitAndAssign<$t> for Saturating<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const BitAndAssign<$t> for Saturating<$t> { #[inline] fn bitand_assign(&mut self, other: $t) { *self = *self & Saturating(other); } } - forward_ref_op_assign! { impl BitAndAssign, bitand_assign for Saturating<$t>, $t } + forward_ref_op_assign! { impl BitAndAssign, bitand_assign for Saturating<$t>, $t, + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } )*) } @@ -931,7 +1000,8 @@ macro_rules! saturating_int_impl_signed { } #[stable(feature = "saturating_int_impl", since = "1.74.0")] - impl Neg for Saturating<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const Neg for Saturating<$t> { type Output = Self; #[inline] fn neg(self) -> Self { @@ -939,7 +1009,8 @@ macro_rules! saturating_int_impl_signed { } } forward_ref_unop! { impl Neg, neg for Saturating<$t>, - #[stable(feature = "saturating_int_impl", since = "1.74.0")] } + #[stable(feature = "saturating_int_impl", since = "1.74.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } )*) } diff --git a/library/core/src/num/wrapping.rs b/library/core/src/num/wrapping.rs index c460f38bd2e..9ccad4b6459 100644 --- a/library/core/src/num/wrapping.rs +++ b/library/core/src/num/wrapping.rs @@ -88,7 +88,8 @@ impl<T: fmt::UpperHex> fmt::UpperHex for Wrapping<T> { macro_rules! sh_impl_signed { ($t:ident, $f:ident) => { #[stable(feature = "rust1", since = "1.0.0")] - impl Shl<$f> for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const Shl<$f> for Wrapping<$t> { type Output = Wrapping<$t>; #[inline] @@ -101,19 +102,24 @@ macro_rules! sh_impl_signed { } } forward_ref_binop! { impl Shl, shl for Wrapping<$t>, $f, - #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] } + #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl ShlAssign<$f> for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const ShlAssign<$f> for Wrapping<$t> { #[inline] fn shl_assign(&mut self, other: $f) { *self = *self << other; } } - forward_ref_op_assign! { impl ShlAssign, shl_assign for Wrapping<$t>, $f } + forward_ref_op_assign! { impl ShlAssign, shl_assign for Wrapping<$t>, $f, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "rust1", since = "1.0.0")] - impl Shr<$f> for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const Shr<$f> for Wrapping<$t> { type Output = Wrapping<$t>; #[inline] @@ -126,23 +132,28 @@ macro_rules! sh_impl_signed { } } forward_ref_binop! { impl Shr, shr for Wrapping<$t>, $f, - #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] } + #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl ShrAssign<$f> for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const ShrAssign<$f> for Wrapping<$t> { #[inline] fn shr_assign(&mut self, other: $f) { *self = *self >> other; } } - forward_ref_op_assign! { impl ShrAssign, shr_assign for Wrapping<$t>, $f } + forward_ref_op_assign! { impl ShrAssign, shr_assign for Wrapping<$t>, $f, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } }; } macro_rules! sh_impl_unsigned { ($t:ident, $f:ident) => { #[stable(feature = "rust1", since = "1.0.0")] - impl Shl<$f> for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const Shl<$f> for Wrapping<$t> { type Output = Wrapping<$t>; #[inline] @@ -151,19 +162,24 @@ macro_rules! sh_impl_unsigned { } } forward_ref_binop! { impl Shl, shl for Wrapping<$t>, $f, - #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] } + #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl ShlAssign<$f> for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const ShlAssign<$f> for Wrapping<$t> { #[inline] fn shl_assign(&mut self, other: $f) { *self = *self << other; } } - forward_ref_op_assign! { impl ShlAssign, shl_assign for Wrapping<$t>, $f } + forward_ref_op_assign! { impl ShlAssign, shl_assign for Wrapping<$t>, $f, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "rust1", since = "1.0.0")] - impl Shr<$f> for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const Shr<$f> for Wrapping<$t> { type Output = Wrapping<$t>; #[inline] @@ -172,16 +188,20 @@ macro_rules! sh_impl_unsigned { } } forward_ref_binop! { impl Shr, shr for Wrapping<$t>, $f, - #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] } + #[stable(feature = "wrapping_ref_ops", since = "1.39.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl ShrAssign<$f> for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const ShrAssign<$f> for Wrapping<$t> { #[inline] fn shr_assign(&mut self, other: $f) { *self = *self >> other; } } - forward_ref_op_assign! { impl ShrAssign, shr_assign for Wrapping<$t>, $f } + forward_ref_op_assign! { impl ShrAssign, shr_assign for Wrapping<$t>, $f, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } }; } @@ -210,7 +230,8 @@ sh_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize } macro_rules! wrapping_impl { ($($t:ty)*) => ($( #[stable(feature = "rust1", since = "1.0.0")] - impl Add for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const Add for Wrapping<$t> { type Output = Wrapping<$t>; #[inline] @@ -219,28 +240,36 @@ macro_rules! wrapping_impl { } } forward_ref_binop! { impl Add, add for Wrapping<$t>, Wrapping<$t>, - #[stable(feature = "wrapping_ref", since = "1.14.0")] } + #[stable(feature = "wrapping_ref", since = "1.14.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl AddAssign for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const AddAssign for Wrapping<$t> { #[inline] fn add_assign(&mut self, other: Wrapping<$t>) { *self = *self + other; } } - forward_ref_op_assign! { impl AddAssign, add_assign for Wrapping<$t>, Wrapping<$t> } + forward_ref_op_assign! { impl AddAssign, add_assign for Wrapping<$t>, Wrapping<$t>, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")] - impl AddAssign<$t> for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const AddAssign<$t> for Wrapping<$t> { #[inline] fn add_assign(&mut self, other: $t) { *self = *self + Wrapping(other); } } - forward_ref_op_assign! { impl AddAssign, add_assign for Wrapping<$t>, $t } + forward_ref_op_assign! { impl AddAssign, add_assign for Wrapping<$t>, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "rust1", since = "1.0.0")] - impl Sub for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const Sub for Wrapping<$t> { type Output = Wrapping<$t>; #[inline] @@ -249,28 +278,36 @@ macro_rules! wrapping_impl { } } forward_ref_binop! { impl Sub, sub for Wrapping<$t>, Wrapping<$t>, - #[stable(feature = "wrapping_ref", since = "1.14.0")] } + #[stable(feature = "wrapping_ref", since = "1.14.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl SubAssign for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const SubAssign for Wrapping<$t> { #[inline] fn sub_assign(&mut self, other: Wrapping<$t>) { *self = *self - other; } } - forward_ref_op_assign! { impl SubAssign, sub_assign for Wrapping<$t>, Wrapping<$t> } + forward_ref_op_assign! { impl SubAssign, sub_assign for Wrapping<$t>, Wrapping<$t>, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")] - impl SubAssign<$t> for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const SubAssign<$t> for Wrapping<$t> { #[inline] fn sub_assign(&mut self, other: $t) { *self = *self - Wrapping(other); } } - forward_ref_op_assign! { impl SubAssign, sub_assign for Wrapping<$t>, $t } + forward_ref_op_assign! { impl SubAssign, sub_assign for Wrapping<$t>, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "rust1", since = "1.0.0")] - impl Mul for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const Mul for Wrapping<$t> { type Output = Wrapping<$t>; #[inline] @@ -279,28 +316,36 @@ macro_rules! wrapping_impl { } } forward_ref_binop! { impl Mul, mul for Wrapping<$t>, Wrapping<$t>, - #[stable(feature = "wrapping_ref", since = "1.14.0")] } + #[stable(feature = "wrapping_ref", since = "1.14.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl MulAssign for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const MulAssign for Wrapping<$t> { #[inline] fn mul_assign(&mut self, other: Wrapping<$t>) { *self = *self * other; } } - forward_ref_op_assign! { impl MulAssign, mul_assign for Wrapping<$t>, Wrapping<$t> } + forward_ref_op_assign! { impl MulAssign, mul_assign for Wrapping<$t>, Wrapping<$t>, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")] - impl MulAssign<$t> for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const MulAssign<$t> for Wrapping<$t> { #[inline] fn mul_assign(&mut self, other: $t) { *self = *self * Wrapping(other); } } - forward_ref_op_assign! { impl MulAssign, mul_assign for Wrapping<$t>, $t } + forward_ref_op_assign! { impl MulAssign, mul_assign for Wrapping<$t>, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "wrapping_div", since = "1.3.0")] - impl Div for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const Div for Wrapping<$t> { type Output = Wrapping<$t>; #[inline] @@ -309,28 +354,36 @@ macro_rules! wrapping_impl { } } forward_ref_binop! { impl Div, div for Wrapping<$t>, Wrapping<$t>, - #[stable(feature = "wrapping_ref", since = "1.14.0")] } + #[stable(feature = "wrapping_ref", since = "1.14.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl DivAssign for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const DivAssign for Wrapping<$t> { #[inline] fn div_assign(&mut self, other: Wrapping<$t>) { *self = *self / other; } } - forward_ref_op_assign! { impl DivAssign, div_assign for Wrapping<$t>, Wrapping<$t> } + forward_ref_op_assign! { impl DivAssign, div_assign for Wrapping<$t>, Wrapping<$t>, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")] - impl DivAssign<$t> for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const DivAssign<$t> for Wrapping<$t> { #[inline] fn div_assign(&mut self, other: $t) { *self = *self / Wrapping(other); } } - forward_ref_op_assign! { impl DivAssign, div_assign for Wrapping<$t>, $t } + forward_ref_op_assign! { impl DivAssign, div_assign for Wrapping<$t>, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "wrapping_impls", since = "1.7.0")] - impl Rem for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const Rem for Wrapping<$t> { type Output = Wrapping<$t>; #[inline] @@ -339,28 +392,36 @@ macro_rules! wrapping_impl { } } forward_ref_binop! { impl Rem, rem for Wrapping<$t>, Wrapping<$t>, - #[stable(feature = "wrapping_ref", since = "1.14.0")] } + #[stable(feature = "wrapping_ref", since = "1.14.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl RemAssign for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const RemAssign for Wrapping<$t> { #[inline] fn rem_assign(&mut self, other: Wrapping<$t>) { *self = *self % other; } } - forward_ref_op_assign! { impl RemAssign, rem_assign for Wrapping<$t>, Wrapping<$t> } + forward_ref_op_assign! { impl RemAssign, rem_assign for Wrapping<$t>, Wrapping<$t>, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")] - impl RemAssign<$t> for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const RemAssign<$t> for Wrapping<$t> { #[inline] fn rem_assign(&mut self, other: $t) { *self = *self % Wrapping(other); } } - forward_ref_op_assign! { impl RemAssign, rem_assign for Wrapping<$t>, $t } + forward_ref_op_assign! { impl RemAssign, rem_assign for Wrapping<$t>, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "rust1", since = "1.0.0")] - impl Not for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const Not for Wrapping<$t> { type Output = Wrapping<$t>; #[inline] @@ -369,10 +430,12 @@ macro_rules! wrapping_impl { } } forward_ref_unop! { impl Not, not for Wrapping<$t>, - #[stable(feature = "wrapping_ref", since = "1.14.0")] } + #[stable(feature = "wrapping_ref", since = "1.14.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "rust1", since = "1.0.0")] - impl BitXor for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const BitXor for Wrapping<$t> { type Output = Wrapping<$t>; #[inline] @@ -381,28 +444,36 @@ macro_rules! wrapping_impl { } } forward_ref_binop! { impl BitXor, bitxor for Wrapping<$t>, Wrapping<$t>, - #[stable(feature = "wrapping_ref", since = "1.14.0")] } + #[stable(feature = "wrapping_ref", since = "1.14.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl BitXorAssign for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const BitXorAssign for Wrapping<$t> { #[inline] fn bitxor_assign(&mut self, other: Wrapping<$t>) { *self = *self ^ other; } } - forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for Wrapping<$t>, Wrapping<$t> } + forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for Wrapping<$t>, Wrapping<$t>, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")] - impl BitXorAssign<$t> for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const BitXorAssign<$t> for Wrapping<$t> { #[inline] fn bitxor_assign(&mut self, other: $t) { *self = *self ^ Wrapping(other); } } - forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for Wrapping<$t>, $t } + forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for Wrapping<$t>, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "rust1", since = "1.0.0")] - impl BitOr for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const BitOr for Wrapping<$t> { type Output = Wrapping<$t>; #[inline] @@ -411,28 +482,36 @@ macro_rules! wrapping_impl { } } forward_ref_binop! { impl BitOr, bitor for Wrapping<$t>, Wrapping<$t>, - #[stable(feature = "wrapping_ref", since = "1.14.0")] } + #[stable(feature = "wrapping_ref", since = "1.14.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl BitOrAssign for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const BitOrAssign for Wrapping<$t> { #[inline] fn bitor_assign(&mut self, other: Wrapping<$t>) { *self = *self | other; } } - forward_ref_op_assign! { impl BitOrAssign, bitor_assign for Wrapping<$t>, Wrapping<$t> } + forward_ref_op_assign! { impl BitOrAssign, bitor_assign for Wrapping<$t>, Wrapping<$t>, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")] - impl BitOrAssign<$t> for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const BitOrAssign<$t> for Wrapping<$t> { #[inline] fn bitor_assign(&mut self, other: $t) { *self = *self | Wrapping(other); } } - forward_ref_op_assign! { impl BitOrAssign, bitor_assign for Wrapping<$t>, $t } + forward_ref_op_assign! { impl BitOrAssign, bitor_assign for Wrapping<$t>, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "rust1", since = "1.0.0")] - impl BitAnd for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const BitAnd for Wrapping<$t> { type Output = Wrapping<$t>; #[inline] @@ -441,28 +520,36 @@ macro_rules! wrapping_impl { } } forward_ref_binop! { impl BitAnd, bitand for Wrapping<$t>, Wrapping<$t>, - #[stable(feature = "wrapping_ref", since = "1.14.0")] } + #[stable(feature = "wrapping_ref", since = "1.14.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl BitAndAssign for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const BitAndAssign for Wrapping<$t> { #[inline] fn bitand_assign(&mut self, other: Wrapping<$t>) { *self = *self & other; } } - forward_ref_op_assign! { impl BitAndAssign, bitand_assign for Wrapping<$t>, Wrapping<$t> } + forward_ref_op_assign! { impl BitAndAssign, bitand_assign for Wrapping<$t>, Wrapping<$t>, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "wrapping_int_assign_impl", since = "1.60.0")] - impl BitAndAssign<$t> for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const BitAndAssign<$t> for Wrapping<$t> { #[inline] fn bitand_assign(&mut self, other: $t) { *self = *self & Wrapping(other); } } - forward_ref_op_assign! { impl BitAndAssign, bitand_assign for Wrapping<$t>, $t } + forward_ref_op_assign! { impl BitAndAssign, bitand_assign for Wrapping<$t>, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } #[stable(feature = "wrapping_neg", since = "1.10.0")] - impl Neg for Wrapping<$t> { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const Neg for Wrapping<$t> { type Output = Self; #[inline] fn neg(self) -> Self { @@ -470,7 +557,8 @@ macro_rules! wrapping_impl { } } forward_ref_unop! { impl Neg, neg for Wrapping<$t>, - #[stable(feature = "wrapping_ref", since = "1.14.0")] } + #[stable(feature = "wrapping_ref", since = "1.14.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } )*) } diff --git a/library/core/src/ops/arith.rs b/library/core/src/ops/arith.rs index 7d44b1733b9..16c719b0c39 100644 --- a/library/core/src/ops/arith.rs +++ b/library/core/src/ops/arith.rs @@ -106,7 +106,9 @@ macro_rules! add_impl { fn add(self, other: $t) -> $t { self + other } } - forward_ref_binop! { impl Add, add for $t, $t } + forward_ref_binop! { impl Add, add for $t, $t, + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } )*) } @@ -218,7 +220,9 @@ macro_rules! sub_impl { fn sub(self, other: $t) -> $t { self - other } } - forward_ref_binop! { impl Sub, sub for $t, $t } + forward_ref_binop! { impl Sub, sub for $t, $t, + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } )*) } @@ -351,7 +355,9 @@ macro_rules! mul_impl { fn mul(self, other: $t) -> $t { self * other } } - forward_ref_binop! { impl Mul, mul for $t, $t } + forward_ref_binop! { impl Mul, mul for $t, $t, + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } )*) } @@ -493,7 +499,9 @@ macro_rules! div_impl_integer { fn div(self, other: $t) -> $t { self / other } } - forward_ref_binop! { impl Div, div for $t, $t } + forward_ref_binop! { impl Div, div for $t, $t, + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } )*)*) } @@ -513,7 +521,9 @@ macro_rules! div_impl_float { fn div(self, other: $t) -> $t { self / other } } - forward_ref_binop! { impl Div, div for $t, $t } + forward_ref_binop! { impl Div, div for $t, $t, + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } )*) } @@ -599,7 +609,9 @@ macro_rules! rem_impl_integer { fn rem(self, other: $t) -> $t { self % other } } - forward_ref_binop! { impl Rem, rem for $t, $t } + forward_ref_binop! { impl Rem, rem for $t, $t, + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } )*)*) } @@ -634,7 +646,9 @@ macro_rules! rem_impl_float { fn rem(self, other: $t) -> $t { self % other } } - forward_ref_binop! { impl Rem, rem for $t, $t } + forward_ref_binop! { impl Rem, rem for $t, $t, + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } )*) } @@ -678,7 +692,9 @@ rem_impl_float! { f16 f32 f64 f128 } /// ``` #[lang = "neg"] #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] #[doc(alias = "-")] +#[const_trait] pub trait Neg { /// The resulting type after applying the `-` operator. #[stable(feature = "rust1", since = "1.0.0")] @@ -701,7 +717,8 @@ pub trait Neg { macro_rules! neg_impl { ($($t:ty)*) => ($( #[stable(feature = "rust1", since = "1.0.0")] - impl Neg for $t { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const Neg for $t { type Output = $t; #[inline] @@ -709,7 +726,9 @@ macro_rules! neg_impl { fn neg(self) -> $t { -self } } - forward_ref_unop! { impl Neg, neg for $t } + forward_ref_unop! { impl Neg, neg for $t, + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } )*) } @@ -746,12 +765,14 @@ neg_impl! { isize i8 i16 i32 i64 i128 f16 f32 f64 f128 } /// ``` #[lang = "add_assign"] #[stable(feature = "op_assign_traits", since = "1.8.0")] +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] #[diagnostic::on_unimplemented( message = "cannot add-assign `{Rhs}` to `{Self}`", label = "no implementation for `{Self} += {Rhs}`" )] #[doc(alias = "+")] #[doc(alias = "+=")] +#[const_trait] pub trait AddAssign<Rhs = Self> { /// Performs the `+=` operation. /// @@ -769,14 +790,17 @@ pub trait AddAssign<Rhs = Self> { macro_rules! add_assign_impl { ($($t:ty)+) => ($( #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl AddAssign for $t { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const AddAssign for $t { #[inline] #[track_caller] #[rustc_inherit_overflow_checks] fn add_assign(&mut self, other: $t) { *self += other } } - forward_ref_op_assign! { impl AddAssign, add_assign for $t, $t } + forward_ref_op_assign! { impl AddAssign, add_assign for $t, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } )+) } @@ -813,12 +837,14 @@ add_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f /// ``` #[lang = "sub_assign"] #[stable(feature = "op_assign_traits", since = "1.8.0")] +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] #[diagnostic::on_unimplemented( message = "cannot subtract-assign `{Rhs}` from `{Self}`", label = "no implementation for `{Self} -= {Rhs}`" )] #[doc(alias = "-")] #[doc(alias = "-=")] +#[const_trait] pub trait SubAssign<Rhs = Self> { /// Performs the `-=` operation. /// @@ -836,14 +862,17 @@ pub trait SubAssign<Rhs = Self> { macro_rules! sub_assign_impl { ($($t:ty)+) => ($( #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl SubAssign for $t { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const SubAssign for $t { #[inline] #[track_caller] #[rustc_inherit_overflow_checks] fn sub_assign(&mut self, other: $t) { *self -= other } } - forward_ref_op_assign! { impl SubAssign, sub_assign for $t, $t } + forward_ref_op_assign! { impl SubAssign, sub_assign for $t, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } )+) } @@ -871,12 +900,14 @@ sub_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f /// ``` #[lang = "mul_assign"] #[stable(feature = "op_assign_traits", since = "1.8.0")] +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] #[diagnostic::on_unimplemented( message = "cannot multiply-assign `{Self}` by `{Rhs}`", label = "no implementation for `{Self} *= {Rhs}`" )] #[doc(alias = "*")] #[doc(alias = "*=")] +#[const_trait] pub trait MulAssign<Rhs = Self> { /// Performs the `*=` operation. /// @@ -894,14 +925,17 @@ pub trait MulAssign<Rhs = Self> { macro_rules! mul_assign_impl { ($($t:ty)+) => ($( #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl MulAssign for $t { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const MulAssign for $t { #[inline] #[track_caller] #[rustc_inherit_overflow_checks] fn mul_assign(&mut self, other: $t) { *self *= other } } - forward_ref_op_assign! { impl MulAssign, mul_assign for $t, $t } + forward_ref_op_assign! { impl MulAssign, mul_assign for $t, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } )+) } @@ -929,12 +963,14 @@ mul_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f /// ``` #[lang = "div_assign"] #[stable(feature = "op_assign_traits", since = "1.8.0")] +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] #[diagnostic::on_unimplemented( message = "cannot divide-assign `{Self}` by `{Rhs}`", label = "no implementation for `{Self} /= {Rhs}`" )] #[doc(alias = "/")] #[doc(alias = "/=")] +#[const_trait] pub trait DivAssign<Rhs = Self> { /// Performs the `/=` operation. /// @@ -952,13 +988,16 @@ pub trait DivAssign<Rhs = Self> { macro_rules! div_assign_impl { ($($t:ty)+) => ($( #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl DivAssign for $t { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const DivAssign for $t { #[inline] #[track_caller] fn div_assign(&mut self, other: $t) { *self /= other } } - forward_ref_op_assign! { impl DivAssign, div_assign for $t, $t } + forward_ref_op_assign! { impl DivAssign, div_assign for $t, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } )+) } @@ -990,12 +1029,14 @@ div_assign_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f16 f32 f /// ``` #[lang = "rem_assign"] #[stable(feature = "op_assign_traits", since = "1.8.0")] +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] #[diagnostic::on_unimplemented( message = "cannot calculate and assign the remainder of `{Self}` divided by `{Rhs}`", label = "no implementation for `{Self} %= {Rhs}`" )] #[doc(alias = "%")] #[doc(alias = "%=")] +#[const_trait] pub trait RemAssign<Rhs = Self> { /// Performs the `%=` operation. /// @@ -1013,13 +1054,16 @@ pub trait RemAssign<Rhs = Self> { macro_rules! rem_assign_impl { ($($t:ty)+) => ($( #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl RemAssign for $t { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const RemAssign for $t { #[inline] #[track_caller] fn rem_assign(&mut self, other: $t) { *self %= other } } - forward_ref_op_assign! { impl RemAssign, rem_assign for $t, $t } + forward_ref_op_assign! { impl RemAssign, rem_assign for $t, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } )+) } diff --git a/library/core/src/ops/bit.rs b/library/core/src/ops/bit.rs index deb54c8ba34..00196728219 100644 --- a/library/core/src/ops/bit.rs +++ b/library/core/src/ops/bit.rs @@ -30,7 +30,9 @@ /// ``` #[lang = "not"] #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] #[doc(alias = "!")] +#[const_trait] pub trait Not { /// The resulting type after applying the `!` operator. #[stable(feature = "rust1", since = "1.0.0")] @@ -54,21 +56,25 @@ pub trait Not { macro_rules! not_impl { ($($t:ty)*) => ($( #[stable(feature = "rust1", since = "1.0.0")] - impl Not for $t { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const Not for $t { type Output = $t; #[inline] fn not(self) -> $t { !self } } - forward_ref_unop! { impl Not, not for $t } + forward_ref_unop! { impl Not, not for $t, + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } )*) } not_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 } #[stable(feature = "not_never", since = "1.60.0")] -impl Not for ! { +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +impl const Not for ! { type Output = !; #[inline] @@ -137,10 +143,12 @@ impl Not for ! { #[lang = "bitand"] #[doc(alias = "&")] #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] #[diagnostic::on_unimplemented( message = "no implementation for `{Self} & {Rhs}`", label = "no implementation for `{Self} & {Rhs}`" )] +#[const_trait] pub trait BitAnd<Rhs = Self> { /// The resulting type after applying the `&` operator. #[stable(feature = "rust1", since = "1.0.0")] @@ -164,14 +172,17 @@ pub trait BitAnd<Rhs = Self> { macro_rules! bitand_impl { ($($t:ty)*) => ($( #[stable(feature = "rust1", since = "1.0.0")] - impl BitAnd for $t { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const BitAnd for $t { type Output = $t; #[inline] fn bitand(self, rhs: $t) -> $t { self & rhs } } - forward_ref_binop! { impl BitAnd, bitand for $t, $t } + forward_ref_binop! { impl BitAnd, bitand for $t, $t, + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } )*) } @@ -237,10 +248,12 @@ bitand_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 } #[lang = "bitor"] #[doc(alias = "|")] #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] #[diagnostic::on_unimplemented( message = "no implementation for `{Self} | {Rhs}`", label = "no implementation for `{Self} | {Rhs}`" )] +#[const_trait] pub trait BitOr<Rhs = Self> { /// The resulting type after applying the `|` operator. #[stable(feature = "rust1", since = "1.0.0")] @@ -264,14 +277,17 @@ pub trait BitOr<Rhs = Self> { macro_rules! bitor_impl { ($($t:ty)*) => ($( #[stable(feature = "rust1", since = "1.0.0")] - impl BitOr for $t { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const BitOr for $t { type Output = $t; #[inline] fn bitor(self, rhs: $t) -> $t { self | rhs } } - forward_ref_binop! { impl BitOr, bitor for $t, $t } + forward_ref_binop! { impl BitOr, bitor for $t, $t, + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } )*) } @@ -337,10 +353,12 @@ bitor_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 } #[lang = "bitxor"] #[doc(alias = "^")] #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] #[diagnostic::on_unimplemented( message = "no implementation for `{Self} ^ {Rhs}`", label = "no implementation for `{Self} ^ {Rhs}`" )] +#[const_trait] pub trait BitXor<Rhs = Self> { /// The resulting type after applying the `^` operator. #[stable(feature = "rust1", since = "1.0.0")] @@ -364,14 +382,17 @@ pub trait BitXor<Rhs = Self> { macro_rules! bitxor_impl { ($($t:ty)*) => ($( #[stable(feature = "rust1", since = "1.0.0")] - impl BitXor for $t { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const BitXor for $t { type Output = $t; #[inline] fn bitxor(self, other: $t) -> $t { self ^ other } } - forward_ref_binop! { impl BitXor, bitxor for $t, $t } + forward_ref_binop! { impl BitXor, bitxor for $t, $t, + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } )*) } @@ -436,10 +457,12 @@ bitxor_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 } #[lang = "shl"] #[doc(alias = "<<")] #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] #[diagnostic::on_unimplemented( message = "no implementation for `{Self} << {Rhs}`", label = "no implementation for `{Self} << {Rhs}`" )] +#[const_trait] pub trait Shl<Rhs = Self> { /// The resulting type after applying the `<<` operator. #[stable(feature = "rust1", since = "1.0.0")] @@ -461,7 +484,8 @@ pub trait Shl<Rhs = Self> { macro_rules! shl_impl { ($t:ty, $f:ty) => { #[stable(feature = "rust1", since = "1.0.0")] - impl Shl<$f> for $t { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const Shl<$f> for $t { type Output = $t; #[inline] @@ -471,7 +495,9 @@ macro_rules! shl_impl { } } - forward_ref_binop! { impl Shl, shl for $t, $f } + forward_ref_binop! { impl Shl, shl for $t, $f, + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } }; } @@ -554,10 +580,12 @@ shl_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize } #[lang = "shr"] #[doc(alias = ">>")] #[stable(feature = "rust1", since = "1.0.0")] +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] #[diagnostic::on_unimplemented( message = "no implementation for `{Self} >> {Rhs}`", label = "no implementation for `{Self} >> {Rhs}`" )] +#[const_trait] pub trait Shr<Rhs = Self> { /// The resulting type after applying the `>>` operator. #[stable(feature = "rust1", since = "1.0.0")] @@ -579,7 +607,8 @@ pub trait Shr<Rhs = Self> { macro_rules! shr_impl { ($t:ty, $f:ty) => { #[stable(feature = "rust1", since = "1.0.0")] - impl Shr<$f> for $t { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const Shr<$f> for $t { type Output = $t; #[inline] @@ -589,7 +618,9 @@ macro_rules! shr_impl { } } - forward_ref_binop! { impl Shr, shr for $t, $f } + forward_ref_binop! { impl Shr, shr for $t, $f, + #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } }; } @@ -681,10 +712,12 @@ shr_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize } #[lang = "bitand_assign"] #[doc(alias = "&=")] #[stable(feature = "op_assign_traits", since = "1.8.0")] +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] #[diagnostic::on_unimplemented( message = "no implementation for `{Self} &= {Rhs}`", label = "no implementation for `{Self} &= {Rhs}`" )] +#[const_trait] pub trait BitAndAssign<Rhs = Self> { /// Performs the `&=` operation. /// @@ -714,12 +747,15 @@ pub trait BitAndAssign<Rhs = Self> { macro_rules! bitand_assign_impl { ($($t:ty)+) => ($( #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl BitAndAssign for $t { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const BitAndAssign for $t { #[inline] fn bitand_assign(&mut self, other: $t) { *self &= other } } - forward_ref_op_assign! { impl BitAndAssign, bitand_assign for $t, $t } + forward_ref_op_assign! { impl BitAndAssign, bitand_assign for $t, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } )+) } @@ -752,10 +788,12 @@ bitand_assign_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 } #[lang = "bitor_assign"] #[doc(alias = "|=")] #[stable(feature = "op_assign_traits", since = "1.8.0")] +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] #[diagnostic::on_unimplemented( message = "no implementation for `{Self} |= {Rhs}`", label = "no implementation for `{Self} |= {Rhs}`" )] +#[const_trait] pub trait BitOrAssign<Rhs = Self> { /// Performs the `|=` operation. /// @@ -785,12 +823,15 @@ pub trait BitOrAssign<Rhs = Self> { macro_rules! bitor_assign_impl { ($($t:ty)+) => ($( #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl BitOrAssign for $t { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const BitOrAssign for $t { #[inline] fn bitor_assign(&mut self, other: $t) { *self |= other } } - forward_ref_op_assign! { impl BitOrAssign, bitor_assign for $t, $t } + forward_ref_op_assign! { impl BitOrAssign, bitor_assign for $t, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } )+) } @@ -823,10 +864,12 @@ bitor_assign_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 } #[lang = "bitxor_assign"] #[doc(alias = "^=")] #[stable(feature = "op_assign_traits", since = "1.8.0")] +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] #[diagnostic::on_unimplemented( message = "no implementation for `{Self} ^= {Rhs}`", label = "no implementation for `{Self} ^= {Rhs}`" )] +#[const_trait] pub trait BitXorAssign<Rhs = Self> { /// Performs the `^=` operation. /// @@ -856,12 +899,15 @@ pub trait BitXorAssign<Rhs = Self> { macro_rules! bitxor_assign_impl { ($($t:ty)+) => ($( #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl BitXorAssign for $t { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const BitXorAssign for $t { #[inline] fn bitxor_assign(&mut self, other: $t) { *self ^= other } } - forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for $t, $t } + forward_ref_op_assign! { impl BitXorAssign, bitxor_assign for $t, $t, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } )+) } @@ -892,10 +938,12 @@ bitxor_assign_impl! { bool usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 } #[lang = "shl_assign"] #[doc(alias = "<<=")] #[stable(feature = "op_assign_traits", since = "1.8.0")] +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] #[diagnostic::on_unimplemented( message = "no implementation for `{Self} <<= {Rhs}`", label = "no implementation for `{Self} <<= {Rhs}`" )] +#[const_trait] pub trait ShlAssign<Rhs = Self> { /// Performs the `<<=` operation. /// @@ -917,7 +965,8 @@ pub trait ShlAssign<Rhs = Self> { macro_rules! shl_assign_impl { ($t:ty, $f:ty) => { #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl ShlAssign<$f> for $t { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const ShlAssign<$f> for $t { #[inline] #[rustc_inherit_overflow_checks] fn shl_assign(&mut self, other: $f) { @@ -925,7 +974,9 @@ macro_rules! shl_assign_impl { } } - forward_ref_op_assign! { impl ShlAssign, shl_assign for $t, $f } + forward_ref_op_assign! { impl ShlAssign, shl_assign for $t, $f, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } }; } @@ -974,10 +1025,12 @@ shl_assign_impl_all! { u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize } #[lang = "shr_assign"] #[doc(alias = ">>=")] #[stable(feature = "op_assign_traits", since = "1.8.0")] +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] #[diagnostic::on_unimplemented( message = "no implementation for `{Self} >>= {Rhs}`", label = "no implementation for `{Self} >>= {Rhs}`" )] +#[const_trait] pub trait ShrAssign<Rhs = Self> { /// Performs the `>>=` operation. /// @@ -999,7 +1052,8 @@ pub trait ShrAssign<Rhs = Self> { macro_rules! shr_assign_impl { ($t:ty, $f:ty) => { #[stable(feature = "op_assign_traits", since = "1.8.0")] - impl ShrAssign<$f> for $t { + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] + impl const ShrAssign<$f> for $t { #[inline] #[rustc_inherit_overflow_checks] fn shr_assign(&mut self, other: $f) { @@ -1007,7 +1061,9 @@ macro_rules! shr_assign_impl { } } - forward_ref_op_assign! { impl ShrAssign, shr_assign for $t, $f } + forward_ref_op_assign! { impl ShrAssign, shr_assign for $t, $f, + #[stable(feature = "op_assign_builtins_by_ref", since = "1.22.0")] + #[rustc_const_unstable(feature = "const_ops", issue = "143802")] } }; } diff --git a/library/core/src/ops/range.rs b/library/core/src/ops/range.rs index f33a33e6b75..95d1e2069ac 100644 --- a/library/core/src/ops/range.rs +++ b/library/core/src/ops/range.rs @@ -853,7 +853,7 @@ pub trait RangeBounds<T: ?Sized> { /// assert!( RangeBounds::is_empty(&(f32::NAN..5.0))); /// ``` /// - /// But never empty is either side is unbounded: + /// But never empty if either side is unbounded: /// /// ``` /// #![feature(range_bounds_is_empty)] diff --git a/library/core/src/time.rs b/library/core/src/time.rs index 0fb5c0bac75..0cc570f4b73 100644 --- a/library/core/src/time.rs +++ b/library/core/src/time.rs @@ -373,7 +373,6 @@ impl Duration { /// # Examples /// /// ``` - /// #![feature(duration_constructors_lite)] /// use std::time::Duration; /// /// let duration = Duration::from_hours(6); @@ -381,7 +380,8 @@ impl Duration { /// assert_eq!(6 * 60 * 60, duration.as_secs()); /// assert_eq!(0, duration.subsec_nanos()); /// ``` - #[unstable(feature = "duration_constructors_lite", issue = "140881")] + #[stable(feature = "duration_constructors_lite", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "duration_constructors_lite", since = "CURRENT_RUSTC_VERSION")] #[must_use] #[inline] pub const fn from_hours(hours: u64) -> Duration { @@ -401,7 +401,6 @@ impl Duration { /// # Examples /// /// ``` - /// #![feature(duration_constructors_lite)] /// use std::time::Duration; /// /// let duration = Duration::from_mins(10); @@ -409,7 +408,8 @@ impl Duration { /// assert_eq!(10 * 60, duration.as_secs()); /// assert_eq!(0, duration.subsec_nanos()); /// ``` - #[unstable(feature = "duration_constructors_lite", issue = "140881")] + #[stable(feature = "duration_constructors_lite", since = "CURRENT_RUSTC_VERSION")] + #[rustc_const_stable(feature = "duration_constructors_lite", since = "CURRENT_RUSTC_VERSION")] #[must_use] #[inline] pub const fn from_mins(mins: u64) -> Duration { @@ -1100,7 +1100,8 @@ impl Duration { } #[stable(feature = "duration", since = "1.3.0")] -impl Add for Duration { +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +impl const Add for Duration { type Output = Duration; #[inline] @@ -1110,7 +1111,8 @@ impl Add for Duration { } #[stable(feature = "time_augmented_assignment", since = "1.9.0")] -impl AddAssign for Duration { +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +impl const AddAssign for Duration { #[inline] fn add_assign(&mut self, rhs: Duration) { *self = *self + rhs; @@ -1118,7 +1120,8 @@ impl AddAssign for Duration { } #[stable(feature = "duration", since = "1.3.0")] -impl Sub for Duration { +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +impl const Sub for Duration { type Output = Duration; #[inline] @@ -1128,7 +1131,8 @@ impl Sub for Duration { } #[stable(feature = "time_augmented_assignment", since = "1.9.0")] -impl SubAssign for Duration { +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +impl const SubAssign for Duration { #[inline] fn sub_assign(&mut self, rhs: Duration) { *self = *self - rhs; @@ -1136,7 +1140,8 @@ impl SubAssign for Duration { } #[stable(feature = "duration", since = "1.3.0")] -impl Mul<u32> for Duration { +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +impl const Mul<u32> for Duration { type Output = Duration; #[inline] @@ -1146,7 +1151,8 @@ impl Mul<u32> for Duration { } #[stable(feature = "symmetric_u32_duration_mul", since = "1.31.0")] -impl Mul<Duration> for u32 { +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +impl const Mul<Duration> for u32 { type Output = Duration; #[inline] @@ -1156,7 +1162,8 @@ impl Mul<Duration> for u32 { } #[stable(feature = "time_augmented_assignment", since = "1.9.0")] -impl MulAssign<u32> for Duration { +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +impl const MulAssign<u32> for Duration { #[inline] fn mul_assign(&mut self, rhs: u32) { *self = *self * rhs; @@ -1164,7 +1171,8 @@ impl MulAssign<u32> for Duration { } #[stable(feature = "duration", since = "1.3.0")] -impl Div<u32> for Duration { +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +impl const Div<u32> for Duration { type Output = Duration; #[inline] @@ -1175,7 +1183,8 @@ impl Div<u32> for Duration { } #[stable(feature = "time_augmented_assignment", since = "1.9.0")] -impl DivAssign<u32> for Duration { +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +impl const DivAssign<u32> for Duration { #[inline] #[track_caller] fn div_assign(&mut self, rhs: u32) { diff --git a/library/coretests/tests/lib.rs b/library/coretests/tests/lib.rs index 75679bbac91..0c4d49f3c99 100644 --- a/library/coretests/tests/lib.rs +++ b/library/coretests/tests/lib.rs @@ -36,7 +36,6 @@ #![feature(drop_guard)] #![feature(duration_constants)] #![feature(duration_constructors)] -#![feature(duration_constructors_lite)] #![feature(error_generic_member_access)] #![feature(exact_div)] #![feature(exact_size_is_empty)] diff --git a/library/coretests/tests/tuple.rs b/library/coretests/tests/tuple.rs index ea1e281425c..5d680d10472 100644 --- a/library/coretests/tests/tuple.rs +++ b/library/coretests/tests/tuple.rs @@ -37,7 +37,7 @@ fn test_partial_ord() { assert!(!((1.0f64, 2.0f64) <= (f64::NAN, 3.0))); assert!(!((1.0f64, 2.0f64) > (f64::NAN, 3.0))); assert!(!((1.0f64, 2.0f64) >= (f64::NAN, 3.0))); - assert!(((1.0f64, 2.0f64) < (2.0, f64::NAN))); + assert!((1.0f64, 2.0f64) < (2.0, f64::NAN)); assert!(!((2.0f64, 2.0f64) < (2.0, f64::NAN))); } diff --git a/library/std/src/collections/hash/map.rs b/library/std/src/collections/hash/map.rs index edbdd041145..15a7a770d1a 100644 --- a/library/std/src/collections/hash/map.rs +++ b/library/std/src/collections/hash/map.rs @@ -135,6 +135,8 @@ use crate::ops::Index; /// ]); /// ``` /// +/// ## `Entry` API +/// /// `HashMap` implements an [`Entry` API](#method.entry), which allows /// for complex methods of getting, setting, updating and removing keys and /// their values: @@ -167,6 +169,8 @@ use crate::ops::Index; /// player_stats.entry("mana").and_modify(|mana| *mana += 200).or_insert(100); /// ``` /// +/// ## Usage with custom key types +/// /// The easiest way to use `HashMap` with a custom key type is to derive [`Eq`] and [`Hash`]. /// We must also derive [`PartialEq`]. /// diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 0c537530647..25355efd20e 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -281,9 +281,11 @@ #![feature(cfg_target_thread_local)] #![feature(cfi_encoding)] #![feature(char_max_len)] +#![feature(const_trait_impl)] #![feature(core_float_math)] #![feature(decl_macro)] #![feature(deprecated_suggestion)] +#![feature(derive_const)] #![feature(doc_cfg)] #![feature(doc_cfg_hide)] #![feature(doc_masked)] @@ -329,6 +331,10 @@ #![feature(bstr_internals)] #![feature(char_internals)] #![feature(clone_to_uninit)] +#![feature(const_cmp)] +#![feature(const_ops)] +#![feature(const_option_ops)] +#![feature(const_try)] #![feature(core_intrinsics)] #![feature(core_io_borrowed_buf)] #![feature(drop_guard)] diff --git a/library/std/src/path.rs b/library/std/src/path.rs index e7ba6936435..3b52804d6be 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -2678,7 +2678,6 @@ impl Path { /// # Examples /// /// ``` - /// # #![feature(path_file_prefix)] /// use std::path::Path; /// /// assert_eq!("foo", Path::new("foo.rs").file_prefix().unwrap()); @@ -2693,7 +2692,7 @@ impl Path { /// /// [`Path::file_stem`]: Path::file_stem /// - #[unstable(feature = "path_file_prefix", issue = "86319")] + #[stable(feature = "path_file_prefix", since = "CURRENT_RUSTC_VERSION")] #[must_use] pub fn file_prefix(&self) -> Option<&OsStr> { self.file_name().map(split_file_at_dot).and_then(|(before, _after)| Some(before)) diff --git a/library/std/src/sys/fs/windows.rs b/library/std/src/sys/fs/windows.rs index 9b674a25165..09feddd0be9 100644 --- a/library/std/src/sys/fs/windows.rs +++ b/library/std/src/sys/fs/windows.rs @@ -80,7 +80,7 @@ pub struct OpenOptions { attributes: u32, share_mode: u32, security_qos_flags: u32, - security_attributes: *mut c::SECURITY_ATTRIBUTES, + inherit_handle: bool, } #[derive(Clone, PartialEq, Eq, Debug)] @@ -203,7 +203,7 @@ impl OpenOptions { share_mode: c::FILE_SHARE_READ | c::FILE_SHARE_WRITE | c::FILE_SHARE_DELETE, attributes: 0, security_qos_flags: 0, - security_attributes: ptr::null_mut(), + inherit_handle: false, } } @@ -243,8 +243,8 @@ impl OpenOptions { // receive is `SECURITY_ANONYMOUS = 0x0`, which we can't check for later on. self.security_qos_flags = flags | c::SECURITY_SQOS_PRESENT; } - pub fn security_attributes(&mut self, attrs: *mut c::SECURITY_ATTRIBUTES) { - self.security_attributes = attrs; + pub fn inherit_handle(&mut self, inherit: bool) { + self.inherit_handle = inherit; } fn get_access_mode(&self) -> io::Result<u32> { @@ -307,12 +307,17 @@ impl File { fn open_native(path: &WCStr, opts: &OpenOptions) -> io::Result<File> { let creation = opts.get_creation_mode()?; + let sa = c::SECURITY_ATTRIBUTES { + nLength: size_of::<c::SECURITY_ATTRIBUTES>() as u32, + lpSecurityDescriptor: ptr::null_mut(), + bInheritHandle: opts.inherit_handle as c::BOOL, + }; let handle = unsafe { c::CreateFileW( path.as_ptr(), opts.get_access_mode()?, opts.share_mode, - opts.security_attributes, + if opts.inherit_handle { &sa } else { ptr::null() }, creation, opts.get_flags_and_attributes(), ptr::null_mut(), diff --git a/library/std/src/sys/io/io_slice/uefi.rs b/library/std/src/sys/io/io_slice/uefi.rs new file mode 100644 index 00000000000..909cfbea0b7 --- /dev/null +++ b/library/std/src/sys/io/io_slice/uefi.rs @@ -0,0 +1,74 @@ +//! A buffer type used with `Write::write_vectored` for UEFI Networking APIs. Vectored writing to +//! File is not supported as of UEFI Spec 2.11. + +use crate::marker::PhantomData; +use crate::slice; + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct IoSlice<'a> { + len: u32, + data: *const u8, + _p: PhantomData<&'a [u8]>, +} + +impl<'a> IoSlice<'a> { + #[inline] + pub fn new(buf: &'a [u8]) -> IoSlice<'a> { + let len = buf.len().try_into().unwrap(); + Self { len, data: buf.as_ptr(), _p: PhantomData } + } + + #[inline] + pub fn advance(&mut self, n: usize) { + self.len = u32::try_from(n) + .ok() + .and_then(|n| self.len.checked_sub(n)) + .expect("advancing IoSlice beyond its length"); + unsafe { self.data = self.data.add(n) }; + } + + #[inline] + pub const fn as_slice(&self) -> &'a [u8] { + unsafe { slice::from_raw_parts(self.data, self.len as usize) } + } +} + +#[repr(C)] +pub struct IoSliceMut<'a> { + len: u32, + data: *mut u8, + _p: PhantomData<&'a mut [u8]>, +} + +impl<'a> IoSliceMut<'a> { + #[inline] + pub fn new(buf: &'a mut [u8]) -> IoSliceMut<'a> { + let len = buf.len().try_into().unwrap(); + Self { len, data: buf.as_mut_ptr(), _p: PhantomData } + } + + #[inline] + pub fn advance(&mut self, n: usize) { + self.len = u32::try_from(n) + .ok() + .and_then(|n| self.len.checked_sub(n)) + .expect("advancing IoSlice beyond its length"); + unsafe { self.data = self.data.add(n) }; + } + + #[inline] + pub fn as_slice(&self) -> &[u8] { + unsafe { slice::from_raw_parts(self.data, self.len as usize) } + } + + #[inline] + pub const fn into_slice(self) -> &'a mut [u8] { + unsafe { slice::from_raw_parts_mut(self.data, self.len as usize) } + } + + #[inline] + pub fn as_mut_slice(&mut self) -> &mut [u8] { + unsafe { slice::from_raw_parts_mut(self.data, self.len as usize) } + } +} diff --git a/library/std/src/sys/io/mod.rs b/library/std/src/sys/io/mod.rs index 4d0365d42fd..ae75f4d97b4 100644 --- a/library/std/src/sys/io/mod.rs +++ b/library/std/src/sys/io/mod.rs @@ -11,6 +11,9 @@ mod io_slice { } else if #[cfg(target_os = "wasi")] { mod wasi; pub use wasi::*; + } else if #[cfg(target_os = "uefi")] { + mod uefi; + pub use uefi::*; } else { mod unsupported; pub use unsupported::*; diff --git a/library/std/src/sys/pal/hermit/time.rs b/library/std/src/sys/pal/hermit/time.rs index f76a5f96c87..89a427ab88b 100644 --- a/library/std/src/sys/pal/hermit/time.rs +++ b/library/std/src/sys/pal/hermit/time.rs @@ -25,8 +25,15 @@ impl Timespec { Timespec { t: timespec { tv_sec, tv_nsec } } } - fn sub_timespec(&self, other: &Timespec) -> Result<Duration, Duration> { - if self >= other { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + const fn sub_timespec(&self, other: &Timespec) -> Result<Duration, Duration> { + // FIXME: const PartialOrd + let mut cmp = self.t.tv_sec - other.t.tv_sec; + if cmp == 0 { + cmp = self.t.tv_nsec as i64 - other.t.tv_nsec as i64; + } + + if cmp >= 0 { Ok(if self.t.tv_nsec >= other.t.tv_nsec { Duration::new( (self.t.tv_sec - other.t.tv_sec) as u64, @@ -46,20 +53,22 @@ impl Timespec { } } - fn checked_add_duration(&self, other: &Duration) -> Option<Timespec> { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + const fn checked_add_duration(&self, other: &Duration) -> Option<Timespec> { let mut secs = self.t.tv_sec.checked_add_unsigned(other.as_secs())?; // Nano calculations can't overflow because nanos are <1B which fit // in a u32. - let mut nsec = other.subsec_nanos() + u32::try_from(self.t.tv_nsec).unwrap(); - if nsec >= NSEC_PER_SEC.try_into().unwrap() { - nsec -= u32::try_from(NSEC_PER_SEC).unwrap(); + let mut nsec = other.subsec_nanos() + self.t.tv_nsec as u32; + if nsec >= NSEC_PER_SEC as u32 { + nsec -= NSEC_PER_SEC as u32; secs = secs.checked_add(1)?; } Some(Timespec { t: timespec { tv_sec: secs, tv_nsec: nsec as _ } }) } - fn checked_sub_duration(&self, other: &Duration) -> Option<Timespec> { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + const fn checked_sub_duration(&self, other: &Duration) -> Option<Timespec> { let mut secs = self.t.tv_sec.checked_sub_unsigned(other.as_secs())?; // Similar to above, nanos can't overflow. @@ -213,15 +222,18 @@ impl SystemTime { SystemTime(time) } - pub fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> { self.0.sub_timespec(&other.0) } - pub fn checked_add_duration(&self, other: &Duration) -> Option<SystemTime> { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn checked_add_duration(&self, other: &Duration) -> Option<SystemTime> { Some(SystemTime(self.0.checked_add_duration(other)?)) } - pub fn checked_sub_duration(&self, other: &Duration) -> Option<SystemTime> { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn checked_sub_duration(&self, other: &Duration) -> Option<SystemTime> { Some(SystemTime(self.0.checked_sub_duration(other)?)) } } diff --git a/library/std/src/sys/pal/sgx/time.rs b/library/std/src/sys/pal/sgx/time.rs index db4cf2804bf..603dae952ab 100644 --- a/library/std/src/sys/pal/sgx/time.rs +++ b/library/std/src/sys/pal/sgx/time.rs @@ -32,15 +32,22 @@ impl SystemTime { SystemTime(usercalls::insecure_time()) } - pub fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> { - self.0.checked_sub(other.0).ok_or_else(|| other.0 - self.0) + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> { + // FIXME: ok_or_else with const closures + match self.0.checked_sub(other.0) { + Some(duration) => Ok(duration), + None => Err(other.0 - self.0), + } } - pub fn checked_add_duration(&self, other: &Duration) -> Option<SystemTime> { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn checked_add_duration(&self, other: &Duration) -> Option<SystemTime> { Some(SystemTime(self.0.checked_add(*other)?)) } - pub fn checked_sub_duration(&self, other: &Duration) -> Option<SystemTime> { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn checked_sub_duration(&self, other: &Duration) -> Option<SystemTime> { Some(SystemTime(self.0.checked_sub(*other)?)) } } diff --git a/library/std/src/sys/pal/solid/time.rs b/library/std/src/sys/pal/solid/time.rs index c39d715c6a6..e35e60df1a0 100644 --- a/library/std/src/sys/pal/solid/time.rs +++ b/library/std/src/sys/pal/solid/time.rs @@ -39,7 +39,8 @@ impl SystemTime { Self(t) } - pub fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> { if self.0 >= other.0 { Ok(Duration::from_secs((self.0 as u64).wrapping_sub(other.0 as u64))) } else { @@ -47,11 +48,13 @@ impl SystemTime { } } - pub fn checked_add_duration(&self, other: &Duration) -> Option<SystemTime> { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn checked_add_duration(&self, other: &Duration) -> Option<SystemTime> { Some(SystemTime(self.0.checked_add_unsigned(other.as_secs())?)) } - pub fn checked_sub_duration(&self, other: &Duration) -> Option<SystemTime> { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn checked_sub_duration(&self, other: &Duration) -> Option<SystemTime> { Some(SystemTime(self.0.checked_sub_unsigned(other.as_secs())?)) } } diff --git a/library/std/src/sys/pal/uefi/tests.rs b/library/std/src/sys/pal/uefi/tests.rs index 38658cc4e9a..56ca999cc7e 100644 --- a/library/std/src/sys/pal/uefi/tests.rs +++ b/library/std/src/sys/pal/uefi/tests.rs @@ -1,7 +1,13 @@ +//! These tests are not run automatically right now. Please run these tests manually by copying them +//! to a separate project when modifying any related code. + use super::alloc::*; -use super::time::*; +use super::time::system_time_internal::{from_uefi, to_uefi}; +use crate::io::{IoSlice, IoSliceMut}; use crate::time::Duration; +const SECS_IN_MINUTE: u64 = 60; + #[test] fn align() { // UEFI ABI specifies that allocation alignment minimum is always 8. So this can be @@ -23,19 +29,177 @@ fn align() { } #[test] -fn epoch() { - let t = r_efi::system::Time { - year: 1970, +fn systemtime_start() { + let t = r_efi::efi::Time { + year: 1900, month: 1, day: 1, hour: 0, minute: 0, second: 0, nanosecond: 0, - timezone: r_efi::efi::UNSPECIFIED_TIMEZONE, + timezone: -1440, daylight: 0, + pad2: 0, + }; + assert_eq!(from_uefi(&t), Duration::new(0, 0)); + assert_eq!(t, to_uefi(&from_uefi(&t), -1440, 0).unwrap()); + assert!(to_uefi(&from_uefi(&t), 0, 0).is_none()); +} + +#[test] +fn systemtime_utc_start() { + let t = r_efi::efi::Time { + year: 1900, + month: 1, + day: 1, + hour: 0, + minute: 0, + second: 0, pad1: 0, + nanosecond: 0, + timezone: 0, + daylight: 0, pad2: 0, }; - assert_eq!(system_time_internal::uefi_time_to_duration(t), Duration::new(0, 0)); + assert_eq!(from_uefi(&t), Duration::new(1440 * SECS_IN_MINUTE, 0)); + assert_eq!(t, to_uefi(&from_uefi(&t), 0, 0).unwrap()); + assert!(to_uefi(&from_uefi(&t), -1440, 0).is_some()); +} + +#[test] +fn systemtime_end() { + let t = r_efi::efi::Time { + year: 9999, + month: 12, + day: 31, + hour: 23, + minute: 59, + second: 59, + pad1: 0, + nanosecond: 0, + timezone: 1440, + daylight: 0, + pad2: 0, + }; + assert!(to_uefi(&from_uefi(&t), 1440, 0).is_some()); + assert!(to_uefi(&from_uefi(&t), 1439, 0).is_none()); +} + +// UEFI IoSlice and IoSliceMut Tests +// +// Strictly speaking, vectored read/write types for UDP4, UDP6, TCP4, TCP6 are defined +// separately in the UEFI Spec. However, they have the same signature. These tests just ensure +// that `IoSlice` and `IoSliceMut` are compatible with the vectored types for all the +// networking protocols. + +unsafe fn to_slice<T>(val: &T) -> &[u8] { + let len = size_of_val(val); + unsafe { crate::slice::from_raw_parts(crate::ptr::from_ref(val).cast(), len) } +} + +#[test] +fn io_slice_single() { + let mut data = [0, 1, 2, 3, 4]; + + let tcp4_frag = r_efi::protocols::tcp4::FragmentData { + fragment_length: data.len().try_into().unwrap(), + fragment_buffer: data.as_mut_ptr().cast(), + }; + let tcp6_frag = r_efi::protocols::tcp6::FragmentData { + fragment_length: data.len().try_into().unwrap(), + fragment_buffer: data.as_mut_ptr().cast(), + }; + let udp4_frag = r_efi::protocols::udp4::FragmentData { + fragment_length: data.len().try_into().unwrap(), + fragment_buffer: data.as_mut_ptr().cast(), + }; + let udp6_frag = r_efi::protocols::udp6::FragmentData { + fragment_length: data.len().try_into().unwrap(), + fragment_buffer: data.as_mut_ptr().cast(), + }; + let io_slice = IoSlice::new(&data); + + unsafe { + assert_eq!(to_slice(&io_slice), to_slice(&tcp4_frag)); + assert_eq!(to_slice(&io_slice), to_slice(&tcp6_frag)); + assert_eq!(to_slice(&io_slice), to_slice(&udp4_frag)); + assert_eq!(to_slice(&io_slice), to_slice(&udp6_frag)); + } +} + +#[test] +fn io_slice_mut_single() { + let mut data = [0, 1, 2, 3, 4]; + + let tcp4_frag = r_efi::protocols::tcp4::FragmentData { + fragment_length: data.len().try_into().unwrap(), + fragment_buffer: data.as_mut_ptr().cast(), + }; + let tcp6_frag = r_efi::protocols::tcp6::FragmentData { + fragment_length: data.len().try_into().unwrap(), + fragment_buffer: data.as_mut_ptr().cast(), + }; + let udp4_frag = r_efi::protocols::udp4::FragmentData { + fragment_length: data.len().try_into().unwrap(), + fragment_buffer: data.as_mut_ptr().cast(), + }; + let udp6_frag = r_efi::protocols::udp6::FragmentData { + fragment_length: data.len().try_into().unwrap(), + fragment_buffer: data.as_mut_ptr().cast(), + }; + let io_slice_mut = IoSliceMut::new(&mut data); + + unsafe { + assert_eq!(to_slice(&io_slice_mut), to_slice(&tcp4_frag)); + assert_eq!(to_slice(&io_slice_mut), to_slice(&tcp6_frag)); + assert_eq!(to_slice(&io_slice_mut), to_slice(&udp4_frag)); + assert_eq!(to_slice(&io_slice_mut), to_slice(&udp6_frag)); + } +} + +#[test] +fn io_slice_multi() { + let mut data = [0, 1, 2, 3, 4]; + + let tcp4_frag = r_efi::protocols::tcp4::FragmentData { + fragment_length: data.len().try_into().unwrap(), + fragment_buffer: data.as_mut_ptr().cast(), + }; + let rhs = + [tcp4_frag.clone(), tcp4_frag.clone(), tcp4_frag.clone(), tcp4_frag.clone(), tcp4_frag]; + let lhs = [ + IoSlice::new(&data), + IoSlice::new(&data), + IoSlice::new(&data), + IoSlice::new(&data), + IoSlice::new(&data), + ]; + + unsafe { + assert_eq!(to_slice(&lhs), to_slice(&rhs)); + } +} + +#[test] +fn io_slice_basic() { + let data = [0, 1, 2, 3, 4]; + let mut io_slice = IoSlice::new(&data); + + assert_eq!(data, io_slice.as_slice()); + io_slice.advance(2); + assert_eq!(&data[2..], io_slice.as_slice()); +} + +#[test] +fn io_slice_mut_basic() { + let data = [0, 1, 2, 3, 4]; + let mut data_clone = [0, 1, 2, 3, 4]; + let mut io_slice_mut = IoSliceMut::new(&mut data_clone); + + assert_eq!(data, io_slice_mut.as_slice()); + assert_eq!(data, io_slice_mut.as_mut_slice()); + + io_slice_mut.advance(2); + assert_eq!(&data[2..], io_slice_mut.into_slice()); } diff --git a/library/std/src/sys/pal/uefi/time.rs b/library/std/src/sys/pal/uefi/time.rs index eeb2c35ffbb..df5611b2ddd 100644 --- a/library/std/src/sys/pal/uefi/time.rs +++ b/library/std/src/sys/pal/uefi/time.rs @@ -1,16 +1,42 @@ use crate::time::Duration; -const SECS_IN_MINUTE: u64 = 60; -const SECS_IN_HOUR: u64 = SECS_IN_MINUTE * 60; -const SECS_IN_DAY: u64 = SECS_IN_HOUR * 24; - #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] pub struct Instant(Duration); +/// When a Timezone is specified, the stored Duration is in UTC. If timezone is unspecified, then +/// the timezone is assumed to be in UTC. +/// +/// UEFI SystemTime is stored as Duration from 1900-01-01-00:00:00 with timezone -1440 as anchor #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] pub struct SystemTime(Duration); -pub const UNIX_EPOCH: SystemTime = SystemTime(Duration::from_secs(0)); +pub const UNIX_EPOCH: SystemTime = SystemTime::from_uefi(r_efi::efi::Time { + year: 1970, + month: 1, + day: 1, + hour: 0, + minute: 0, + second: 0, + nanosecond: 0, + timezone: 0, + daylight: 0, + pad1: 0, + pad2: 0, +}); + +const MAX_UEFI_TIME: SystemTime = SystemTime::from_uefi(r_efi::efi::Time { + year: 9999, + month: 12, + day: 31, + hour: 23, + minute: 59, + second: 59, + nanosecond: 999_999_999, + timezone: 1440, + daylight: 0, + pad1: 0, + pad2: 0, +}); impl Instant { pub fn now() -> Instant { @@ -40,20 +66,45 @@ impl Instant { } impl SystemTime { + pub(crate) const fn from_uefi(t: r_efi::efi::Time) -> Self { + Self(system_time_internal::from_uefi(&t)) + } + + #[expect(dead_code)] + pub(crate) const fn to_uefi(self, timezone: i16, daylight: u8) -> Option<r_efi::efi::Time> { + system_time_internal::to_uefi(&self.0, timezone, daylight) + } + pub fn now() -> SystemTime { system_time_internal::now() .unwrap_or_else(|| panic!("time not implemented on this platform")) } - pub fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> { - self.0.checked_sub(other.0).ok_or_else(|| other.0 - self.0) + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> { + // FIXME: ok_or_else with const closures + match self.0.checked_sub(other.0) { + Some(duration) => Ok(duration), + None => Err(other.0 - self.0), + } } - pub fn checked_add_duration(&self, other: &Duration) -> Option<SystemTime> { - Some(SystemTime(self.0.checked_add(*other)?)) + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn checked_add_duration(&self, other: &Duration) -> Option<SystemTime> { + let temp = self.0.checked_add(*other)?; + + // Check if can be represented in UEFI + // FIXME: const PartialOrd + let mut cmp = temp.as_secs() - MAX_UEFI_TIME.0.as_secs(); + if cmp == 0 { + cmp = temp.subsec_nanos() as u64 - MAX_UEFI_TIME.0.subsec_nanos() as u64; + } + + if cmp <= 0 { Some(SystemTime(temp)) } else { None } } - pub fn checked_sub_duration(&self, other: &Duration) -> Option<SystemTime> { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn checked_sub_duration(&self, other: &Duration) -> Option<SystemTime> { Some(SystemTime(self.0.checked_sub(*other)?)) } } @@ -66,51 +117,132 @@ pub(crate) mod system_time_internal { use crate::mem::MaybeUninit; use crate::ptr::NonNull; + const SECS_IN_MINUTE: u64 = 60; + const SECS_IN_HOUR: u64 = SECS_IN_MINUTE * 60; + const SECS_IN_DAY: u64 = SECS_IN_HOUR * 24; + const TIMEZONE_DELTA: u64 = 1440 * SECS_IN_MINUTE; + pub fn now() -> Option<SystemTime> { let runtime_services: NonNull<RuntimeServices> = helpers::runtime_services()?; let mut t: MaybeUninit<Time> = MaybeUninit::uninit(); let r = unsafe { ((*runtime_services.as_ptr()).get_time)(t.as_mut_ptr(), crate::ptr::null_mut()) }; - if r.is_error() { return None; } let t = unsafe { t.assume_init() }; - Some(SystemTime(uefi_time_to_duration(t))) + Some(SystemTime::from_uefi(t)) } - // This algorithm is based on the one described in the post - // https://blog.reverberate.org/2020/05/12/optimizing-date-algorithms.html - pub(crate) const fn uefi_time_to_duration(t: r_efi::system::Time) -> Duration { - assert!(t.month <= 12); - assert!(t.month != 0); + /// This algorithm is a modified form of the one described in the post + /// https://blog.reverberate.org/2020/05/12/optimizing-date-algorithms.html + /// + /// The changes are to use 1900-01-01-00:00:00 with timezone -1440 as anchor instead of UNIX + /// epoch used in the original algorithm. + pub(crate) const fn from_uefi(t: &Time) -> Duration { + assert!(t.month <= 12 && t.month != 0); + assert!(t.year >= 1900 && t.year <= 9999); + assert!(t.day <= 31 && t.day != 0); + + assert!(t.second < 60); + assert!(t.minute < 60); + assert!(t.hour < 24); + assert!(t.nanosecond < 1_000_000_000); + + assert!( + (t.timezone <= 1440 && t.timezone >= -1440) + || t.timezone == r_efi::efi::UNSPECIFIED_TIMEZONE + ); const YEAR_BASE: u32 = 4800; /* Before min year, multiple of 400. */ - // Calculate the number of days since 1/1/1970 + // Calculate the number of days since 1/1/1900. This is the earliest supported date in UEFI + // time. // Use 1 March as the start let (m_adj, overflow): (u32, bool) = (t.month as u32).overflowing_sub(3); let (carry, adjust): (u32, u32) = if overflow { (1, 12) } else { (0, 0) }; let y_adj: u32 = (t.year as u32) + YEAR_BASE - carry; let month_days: u32 = (m_adj.wrapping_add(adjust) * 62719 + 769) / 2048; let leap_days: u32 = y_adj / 4 - y_adj / 100 + y_adj / 400; - let days: u32 = y_adj * 365 + leap_days + month_days + (t.day as u32 - 1) - 2472632; + let days: u32 = y_adj * 365 + leap_days + month_days + (t.day as u32 - 1) - 2447065; let localtime_epoch: u64 = (days as u64) * SECS_IN_DAY + (t.second as u64) + (t.minute as u64) * SECS_IN_MINUTE + (t.hour as u64) * SECS_IN_HOUR; - let utc_epoch: u64 = if t.timezone == r_efi::efi::UNSPECIFIED_TIMEZONE { - localtime_epoch + // Calculate the offset from 1/1/1900 at timezone -1440 min + let adjusted_localtime_epoc: u64 = localtime_epoch + TIMEZONE_DELTA; + + let epoch: u64 = if t.timezone == r_efi::efi::UNSPECIFIED_TIMEZONE { + adjusted_localtime_epoc } else { - (localtime_epoch as i64 + (t.timezone as i64) * SECS_IN_MINUTE as i64) as u64 + adjusted_localtime_epoc + .checked_add_signed((t.timezone as i64) * SECS_IN_MINUTE as i64) + .unwrap() }; - Duration::new(utc_epoch, t.nanosecond) + Duration::new(epoch, t.nanosecond) + } + + /// This algorithm is a modifed version of the one described in the post: + /// https://howardhinnant.github.io/date_algorithms.html#clive_from_days + /// + /// The changes are to use 1900-01-01-00:00:00 with timezone -1440 as anchor instead of UNIX + /// epoch used in the original algorithm. + pub(crate) const fn to_uefi(dur: &Duration, timezone: i16, daylight: u8) -> Option<Time> { + // Check timzone validity + assert!(timezone <= 1440 && timezone >= -1440); + + // FIXME(#126043): use checked_sub_signed once stablized + let secs = + dur.as_secs().checked_add_signed((-timezone as i64) * SECS_IN_MINUTE as i64).unwrap(); + + // Convert to seconds since 1900-01-01-00:00:00 in timezone. + let Some(secs) = secs.checked_sub(TIMEZONE_DELTA) else { return None }; + + let days = secs / SECS_IN_DAY; + let remaining_secs = secs % SECS_IN_DAY; + + let z = days + 693901; + let era = z / 146097; + let doe = z - (era * 146097); + let yoe = (doe - doe / 1460 + doe / 36524 - doe / 146096) / 365; + let mut y = yoe + era * 400; + let doy = doe - (365 * yoe + yoe / 4 - yoe / 100); + let mp = (5 * doy + 2) / 153; + let d = doy - (153 * mp + 2) / 5 + 1; + let m = if mp < 10 { mp + 3 } else { mp - 9 }; + + if m <= 2 { + y += 1; + } + + let hour = (remaining_secs / SECS_IN_HOUR) as u8; + let minute = ((remaining_secs % SECS_IN_HOUR) / SECS_IN_MINUTE) as u8; + let second = (remaining_secs % SECS_IN_MINUTE) as u8; + + // Check Bounds + if y >= 1900 && y <= 9999 { + Some(Time { + year: y as u16, + month: m as u8, + day: d as u8, + hour, + minute, + second, + nanosecond: dur.subsec_nanos(), + timezone, + daylight, + pad1: 0, + pad2: 0, + }) + } else { + None + } } } diff --git a/library/std/src/sys/pal/unix/time.rs b/library/std/src/sys/pal/unix/time.rs index bd7f74fea6a..328fe0bc960 100644 --- a/library/std/src/sys/pal/unix/time.rs +++ b/library/std/src/sys/pal/unix/time.rs @@ -38,15 +38,18 @@ impl SystemTime { SystemTime { t: Timespec::now(libc::CLOCK_REALTIME) } } - pub fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> { self.t.sub_timespec(&other.t) } - pub fn checked_add_duration(&self, other: &Duration) -> Option<SystemTime> { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn checked_add_duration(&self, other: &Duration) -> Option<SystemTime> { Some(SystemTime { t: self.t.checked_add_duration(other)? }) } - pub fn checked_sub_duration(&self, other: &Duration) -> Option<SystemTime> { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn checked_sub_duration(&self, other: &Duration) -> Option<SystemTime> { Some(SystemTime { t: self.t.checked_sub_duration(other)? }) } } @@ -133,8 +136,15 @@ impl Timespec { Timespec::new(t.tv_sec as i64, t.tv_nsec as i64).unwrap() } - pub fn sub_timespec(&self, other: &Timespec) -> Result<Duration, Duration> { - if self >= other { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn sub_timespec(&self, other: &Timespec) -> Result<Duration, Duration> { + // FIXME: const PartialOrd + let mut cmp = self.tv_sec - other.tv_sec; + if cmp == 0 { + cmp = self.tv_nsec.as_inner() as i64 - other.tv_nsec.as_inner() as i64; + } + + if cmp >= 0 { // NOTE(eddyb) two aspects of this `if`-`else` are required for LLVM // to optimize it into a branchless form (see also #75545): // @@ -169,7 +179,8 @@ impl Timespec { } } - pub fn checked_add_duration(&self, other: &Duration) -> Option<Timespec> { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn checked_add_duration(&self, other: &Duration) -> Option<Timespec> { let mut secs = self.tv_sec.checked_add_unsigned(other.as_secs())?; // Nano calculations can't overflow because nanos are <1B which fit @@ -179,10 +190,11 @@ impl Timespec { nsec -= NSEC_PER_SEC as u32; secs = secs.checked_add(1)?; } - Some(unsafe { Timespec::new_unchecked(secs, nsec.into()) }) + Some(unsafe { Timespec::new_unchecked(secs, nsec as i64) }) } - pub fn checked_sub_duration(&self, other: &Duration) -> Option<Timespec> { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn checked_sub_duration(&self, other: &Duration) -> Option<Timespec> { let mut secs = self.tv_sec.checked_sub_unsigned(other.as_secs())?; // Similar to above, nanos can't overflow. @@ -191,7 +203,7 @@ impl Timespec { nsec += NSEC_PER_SEC as i32; secs = secs.checked_sub(1)?; } - Some(unsafe { Timespec::new_unchecked(secs, nsec.into()) }) + Some(unsafe { Timespec::new_unchecked(secs, nsec as i64) }) } #[allow(dead_code)] diff --git a/library/std/src/sys/pal/unsupported/time.rs b/library/std/src/sys/pal/unsupported/time.rs index 6d67b538a96..0c387917044 100644 --- a/library/std/src/sys/pal/unsupported/time.rs +++ b/library/std/src/sys/pal/unsupported/time.rs @@ -31,15 +31,22 @@ impl SystemTime { panic!("time not implemented on this platform") } - pub fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> { - self.0.checked_sub(other.0).ok_or_else(|| other.0 - self.0) + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> { + // FIXME: ok_or_else with const closures + match self.0.checked_sub(other.0) { + Some(duration) => Ok(duration), + None => Err(other.0 - self.0), + } } - pub fn checked_add_duration(&self, other: &Duration) -> Option<SystemTime> { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn checked_add_duration(&self, other: &Duration) -> Option<SystemTime> { Some(SystemTime(self.0.checked_add(*other)?)) } - pub fn checked_sub_duration(&self, other: &Duration) -> Option<SystemTime> { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn checked_sub_duration(&self, other: &Duration) -> Option<SystemTime> { Some(SystemTime(self.0.checked_sub(*other)?)) } } diff --git a/library/std/src/sys/pal/wasi/time.rs b/library/std/src/sys/pal/wasi/time.rs index 0d8d0b59ac1..892661b312b 100644 --- a/library/std/src/sys/pal/wasi/time.rs +++ b/library/std/src/sys/pal/wasi/time.rs @@ -43,23 +43,34 @@ impl SystemTime { SystemTime(current_time(wasi::CLOCKID_REALTIME)) } - pub fn from_wasi_timestamp(ts: wasi::Timestamp) -> SystemTime { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn from_wasi_timestamp(ts: wasi::Timestamp) -> SystemTime { SystemTime(Duration::from_nanos(ts)) } - pub fn to_wasi_timestamp(&self) -> Option<wasi::Timestamp> { - self.0.as_nanos().try_into().ok() + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn to_wasi_timestamp(&self) -> Option<wasi::Timestamp> { + // FIXME: const TryInto + let ns = self.0.as_nanos(); + if ns <= u64::MAX as u128 { Some(ns as u64) } else { None } } - pub fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> { - self.0.checked_sub(other.0).ok_or_else(|| other.0 - self.0) + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> { + // FIXME: ok_or_else with const closures + match self.0.checked_sub(other.0) { + Some(duration) => Ok(duration), + None => Err(other.0 - self.0), + } } - pub fn checked_add_duration(&self, other: &Duration) -> Option<SystemTime> { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn checked_add_duration(&self, other: &Duration) -> Option<SystemTime> { Some(SystemTime(self.0.checked_add(*other)?)) } - pub fn checked_sub_duration(&self, other: &Duration) -> Option<SystemTime> { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn checked_sub_duration(&self, other: &Duration) -> Option<SystemTime> { Some(SystemTime(self.0.checked_sub(*other)?)) } } diff --git a/library/std/src/sys/pal/windows/time.rs b/library/std/src/sys/pal/windows/time.rs index 68126bd8d2f..a948c07e0a3 100644 --- a/library/std/src/sys/pal/windows/time.rs +++ b/library/std/src/sys/pal/windows/time.rs @@ -72,7 +72,8 @@ impl SystemTime { } } - fn from_intervals(intervals: i64) -> SystemTime { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + const fn from_intervals(intervals: i64) -> SystemTime { SystemTime { t: c::FILETIME { dwLowDateTime: intervals as u32, @@ -81,11 +82,13 @@ impl SystemTime { } } - fn intervals(&self) -> i64 { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + const fn intervals(&self) -> i64 { (self.t.dwLowDateTime as i64) | ((self.t.dwHighDateTime as i64) << 32) } - pub fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> { let me = self.intervals(); let other = other.intervals(); if me >= other { @@ -95,12 +98,14 @@ impl SystemTime { } } - pub fn checked_add_duration(&self, other: &Duration) -> Option<SystemTime> { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn checked_add_duration(&self, other: &Duration) -> Option<SystemTime> { let intervals = self.intervals().checked_add(checked_dur2intervals(other)?)?; Some(SystemTime::from_intervals(intervals)) } - pub fn checked_sub_duration(&self, other: &Duration) -> Option<SystemTime> { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn checked_sub_duration(&self, other: &Duration) -> Option<SystemTime> { let intervals = self.intervals().checked_sub(checked_dur2intervals(other)?)?; Some(SystemTime::from_intervals(intervals)) } @@ -150,15 +155,18 @@ impl Hash for SystemTime { } } -fn checked_dur2intervals(dur: &Duration) -> Option<i64> { - dur.as_secs() +#[rustc_const_unstable(feature = "const_system_time", issue = "144517")] +const fn checked_dur2intervals(dur: &Duration) -> Option<i64> { + // FIXME: const TryInto + let secs = dur + .as_secs() .checked_mul(INTERVALS_PER_SEC)? - .checked_add(dur.subsec_nanos() as u64 / 100)? - .try_into() - .ok() + .checked_add(dur.subsec_nanos() as u64 / 100)?; + if secs <= i64::MAX as u64 { Some(secs.cast_signed()) } else { None } } -fn intervals2dur(intervals: u64) -> Duration { +#[rustc_const_unstable(feature = "const_system_time", issue = "144517")] +const fn intervals2dur(intervals: u64) -> Duration { Duration::new(intervals / INTERVALS_PER_SEC, ((intervals % INTERVALS_PER_SEC) * 100) as u32) } diff --git a/library/std/src/sys/pal/xous/time.rs b/library/std/src/sys/pal/xous/time.rs index ae8be81c0b7..d737416436e 100644 --- a/library/std/src/sys/pal/xous/time.rs +++ b/library/std/src/sys/pal/xous/time.rs @@ -43,15 +43,22 @@ impl SystemTime { SystemTime { 0: Duration::from_millis((upper as u64) << 32 | lower as u64) } } - pub fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> { - self.0.checked_sub(other.0).ok_or_else(|| other.0 - self.0) + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn sub_time(&self, other: &SystemTime) -> Result<Duration, Duration> { + // FIXME: ok_or_else with const closures + match self.0.checked_sub(other.0) { + Some(duration) => Ok(duration), + None => Err(other.0 - self.0), + } } - pub fn checked_add_duration(&self, other: &Duration) -> Option<SystemTime> { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn checked_add_duration(&self, other: &Duration) -> Option<SystemTime> { Some(SystemTime(self.0.checked_add(*other)?)) } - pub fn checked_sub_duration(&self, other: &Duration) -> Option<SystemTime> { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn checked_sub_duration(&self, other: &Duration) -> Option<SystemTime> { Some(SystemTime(self.0.checked_sub(*other)?)) } } diff --git a/library/std/src/sys/process/windows.rs b/library/std/src/sys/process/windows.rs index 1ee3fbd285f..f9e15b82475 100644 --- a/library/std/src/sys/process/windows.rs +++ b/library/std/src/sys/process/windows.rs @@ -623,16 +623,10 @@ impl Stdio { // permissions as well as the ability to be inherited to child // processes (as this is about to be inherited). Stdio::Null => { - let size = size_of::<c::SECURITY_ATTRIBUTES>(); - let mut sa = c::SECURITY_ATTRIBUTES { - nLength: size as u32, - lpSecurityDescriptor: ptr::null_mut(), - bInheritHandle: 1, - }; let mut opts = OpenOptions::new(); opts.read(stdio_id == c::STD_INPUT_HANDLE); opts.write(stdio_id != c::STD_INPUT_HANDLE); - opts.security_attributes(&mut sa); + opts.inherit_handle(true); File::open(Path::new(r"\\.\NUL"), &opts).map(|file| file.into_inner()) } } diff --git a/library/std/src/time.rs b/library/std/src/time.rs index cd0683f44c9..07bb41f1496 100644 --- a/library/std/src/time.rs +++ b/library/std/src/time.rs @@ -551,8 +551,13 @@ impl SystemTime { /// println!("{difference:?}"); /// ``` #[stable(feature = "time2", since = "1.8.0")] - pub fn duration_since(&self, earlier: SystemTime) -> Result<Duration, SystemTimeError> { - self.0.sub_time(&earlier.0).map_err(SystemTimeError) + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn duration_since(&self, earlier: SystemTime) -> Result<Duration, SystemTimeError> { + // FIXME: map_err in const + match self.0.sub_time(&earlier.0) { + Ok(time) => Ok(time), + Err(err) => Err(SystemTimeError(err)), + } } /// Returns the difference from this system time to the @@ -589,7 +594,8 @@ impl SystemTime { /// `SystemTime` (which means it's inside the bounds of the underlying data structure), `None` /// otherwise. #[stable(feature = "time_checked_add", since = "1.34.0")] - pub fn checked_add(&self, duration: Duration) -> Option<SystemTime> { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn checked_add(&self, duration: Duration) -> Option<SystemTime> { self.0.checked_add_duration(&duration).map(SystemTime) } @@ -597,13 +603,15 @@ impl SystemTime { /// `SystemTime` (which means it's inside the bounds of the underlying data structure), `None` /// otherwise. #[stable(feature = "time_checked_add", since = "1.34.0")] - pub fn checked_sub(&self, duration: Duration) -> Option<SystemTime> { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn checked_sub(&self, duration: Duration) -> Option<SystemTime> { self.0.checked_sub_duration(&duration).map(SystemTime) } } #[stable(feature = "time2", since = "1.8.0")] -impl Add<Duration> for SystemTime { +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +impl const Add<Duration> for SystemTime { type Output = SystemTime; /// # Panics @@ -616,14 +624,16 @@ impl Add<Duration> for SystemTime { } #[stable(feature = "time_augmented_assignment", since = "1.9.0")] -impl AddAssign<Duration> for SystemTime { +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +impl const AddAssign<Duration> for SystemTime { fn add_assign(&mut self, other: Duration) { *self = *self + other; } } #[stable(feature = "time2", since = "1.8.0")] -impl Sub<Duration> for SystemTime { +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +impl const Sub<Duration> for SystemTime { type Output = SystemTime; fn sub(self, dur: Duration) -> SystemTime { @@ -632,7 +642,8 @@ impl Sub<Duration> for SystemTime { } #[stable(feature = "time_augmented_assignment", since = "1.9.0")] -impl SubAssign<Duration> for SystemTime { +#[rustc_const_unstable(feature = "const_ops", issue = "143802")] +impl const SubAssign<Duration> for SystemTime { fn sub_assign(&mut self, other: Duration) { *self = *self - other; } @@ -699,7 +710,8 @@ impl SystemTimeError { /// ``` #[must_use] #[stable(feature = "time2", since = "1.8.0")] - pub fn duration(&self) -> Duration { + #[rustc_const_unstable(feature = "const_system_time", issue = "144517")] + pub const fn duration(&self) -> Duration { self.0 } } diff --git a/library/std/tests/env.rs b/library/std/tests/env.rs index e754cf8263b..b53fd69b707 100644 --- a/library/std/tests/env.rs +++ b/library/std/tests/env.rs @@ -16,7 +16,7 @@ fn test_self_exe_path() { #[test] fn test() { - assert!((!Path::new("test-path").is_absolute())); + assert!(!Path::new("test-path").is_absolute()); #[cfg(not(target_env = "sgx"))] current_dir().unwrap(); diff --git a/library/std/tests/path.rs b/library/std/tests/path.rs index 901d2770f20..e1576a0d423 100644 --- a/library/std/tests/path.rs +++ b/library/std/tests/path.rs @@ -1,10 +1,4 @@ -#![feature( - clone_to_uninit, - path_add_extension, - path_file_prefix, - maybe_uninit_slice, - normalize_lexically -)] +#![feature(clone_to_uninit, path_add_extension, maybe_uninit_slice, normalize_lexically)] use std::clone::CloneToUninit; use std::ffi::OsStr; diff --git a/library/test/src/cli.rs b/library/test/src/cli.rs index 8840714a662..1b3f9e2564c 100644 --- a/library/test/src/cli.rs +++ b/library/test/src/cli.rs @@ -162,18 +162,17 @@ tests whose names contain the filter are run. Multiple filter strings may be passed, which will run all tests matching any of the filters. By default, all tests are run in parallel. This can be altered with the ---test-threads flag or the RUST_TEST_THREADS environment variable when running -tests (set it to 1). +--test-threads flag when running tests (set it to 1). -By default, the tests are run in alphabetical order. Use --shuffle or set -RUST_TEST_SHUFFLE to run the tests in random order. Pass the generated -"shuffle seed" to --shuffle-seed (or set RUST_TEST_SHUFFLE_SEED) to run the -tests in the same order again. Note that --shuffle and --shuffle-seed do not -affect whether the tests are run in parallel. +By default, the tests are run in alphabetical order. Use --shuffle to run +the tests in random order. Pass the generated "shuffle seed" to +--shuffle-seed to run the tests in the same order again. Note that +--shuffle and --shuffle-seed do not affect whether the tests are run in +parallel. All tests have their standard output and standard error captured by default. -This can be overridden with the --no-capture flag or setting RUST_TEST_NOCAPTURE -environment variable to a value other than "0". Logging is not captured by default. +This can be overridden with the --no-capture flag to a value other than "0". +Logging is not captured by default. Test Attributes: diff --git a/src/bootstrap/Cargo.lock b/src/bootstrap/Cargo.lock index e091c94eb53..044d360ac37 100644 --- a/src/bootstrap/Cargo.lock +++ b/src/bootstrap/Cargo.lock @@ -730,9 +730,9 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.36.0" +version = "0.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aab138f5c1bb35231de19049060a87977ad23e04f2303e953bc5c2947ac7dec4" +checksum = "07cec4dc2d2e357ca1e610cfb07de2fa7a10fc3e9fe89f72545f3d244ea87753" dependencies = [ "libc", "memchr", diff --git a/src/bootstrap/Cargo.toml b/src/bootstrap/Cargo.toml index 8dc41d1dec6..60d4976b934 100644 --- a/src/bootstrap/Cargo.toml +++ b/src/bootstrap/Cargo.toml @@ -58,7 +58,7 @@ walkdir = "2.4" xz2 = "0.1" # Dependencies needed by the build-metrics feature -sysinfo = { version = "0.36.0", default-features = false, optional = true, features = ["system"] } +sysinfo = { version = "0.37.0", default-features = false, optional = true, features = ["system"] } # Dependencies needed by the `tracing` feature tracing = { version = "0.1", optional = true, features = ["attributes"] } diff --git a/src/bootstrap/src/bin/rustc.rs b/src/bootstrap/src/bin/rustc.rs index 0364c664ba5..5865df67b66 100644 --- a/src/bootstrap/src/bin/rustc.rs +++ b/src/bootstrap/src/bin/rustc.rs @@ -258,7 +258,7 @@ fn main() { eprintln!("{prefix} libdir: {libdir:?}"); } - maybe_dump(format!("stage{stage}-rustc"), &cmd); + maybe_dump(format!("stage{}-rustc", stage + 1), &cmd); let start = Instant::now(); let (child, status) = { diff --git a/src/bootstrap/src/bin/rustdoc.rs b/src/bootstrap/src/bin/rustdoc.rs index a338b9c8080..efb51bdce1e 100644 --- a/src/bootstrap/src/bin/rustdoc.rs +++ b/src/bootstrap/src/bin/rustdoc.rs @@ -56,11 +56,11 @@ fn main() { // Thus, if we are on stage 0, we explicitly set `--cfg=bootstrap`. // We also declare that the flag is expected, which we need to do to not // get warnings about it being unexpected. - if stage == "0" { + if stage == 0 { cmd.arg("--cfg=bootstrap"); } - maybe_dump(format!("stage{stage}-rustdoc"), &cmd); + maybe_dump(format!("stage{}-rustdoc", stage + 1), &cmd); if verbose > 1 { eprintln!( diff --git a/src/bootstrap/src/core/build_steps/check.rs b/src/bootstrap/src/core/build_steps/check.rs index f931aae3c2e..0cbf8f55e99 100644 --- a/src/bootstrap/src/core/build_steps/check.rs +++ b/src/bootstrap/src/core/build_steps/check.rs @@ -72,7 +72,6 @@ impl Step for Std { fn run(self, builder: &Builder<'_>) { let build_compiler = self.build_compiler; - let stage = build_compiler.stage; let target = self.target; let mut cargo = builder::Cargo::new( @@ -94,10 +93,12 @@ impl Step for Std { cargo.arg("-p").arg(krate); } - let _guard = builder.msg_check( + let _guard = builder.msg( + Kind::Check, format_args!("library artifacts{}", crate_description(&self.crates)), + Mode::Std, + self.build_compiler, target, - Some(stage), ); let stamp = build_stamp::libstd_stamp(builder, build_compiler, target).with_prefix("check"); @@ -136,7 +137,13 @@ impl Step for Std { let stamp = build_stamp::libstd_stamp(builder, build_compiler, target).with_prefix("check-test"); - let _guard = builder.msg_check("library test/bench/example targets", target, Some(stage)); + let _guard = builder.msg( + Kind::Check, + "library test/bench/example targets", + Mode::Std, + self.build_compiler, + target, + ); run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false); } @@ -227,10 +234,12 @@ impl Step for Rustc { cargo.arg("-p").arg(krate); } - let _guard = builder.msg_check( + let _guard = builder.msg( + Kind::Check, format_args!("compiler artifacts{}", crate_description(&self.crates)), + Mode::Rustc, + self.build_compiler, target, - None, ); let stamp = @@ -357,7 +366,13 @@ impl Step for CodegenBackend { .arg(builder.src.join(format!("compiler/{}/Cargo.toml", backend.crate_name()))); rustc_cargo_env(builder, &mut cargo, target); - let _guard = builder.msg_check(backend.crate_name(), target, None); + let _guard = builder.msg( + Kind::Check, + backend.crate_name(), + Mode::Codegen, + self.build_compiler, + target, + ); let stamp = build_stamp::codegen_backend_stamp(builder, build_compiler, target, &backend) .with_prefix("check"); @@ -482,14 +497,7 @@ fn run_tool_check_step( let stamp = BuildStamp::new(&builder.cargo_out(build_compiler, mode, target)) .with_prefix(&format!("{display_name}-check")); - let stage = match mode { - // Mode::ToolRustc is included here because of how msg_sysroot_tool prints stages - Mode::Std | Mode::ToolRustc => build_compiler.stage, - _ => build_compiler.stage + 1, - }; - - let _guard = - builder.msg_tool(builder.kind, mode, display_name, stage, &build_compiler.host, &target); + let _guard = builder.msg(builder.kind, display_name, mode, build_compiler, target); run_cargo(builder, cargo, builder.config.free_args.clone(), &stamp, vec![], true, false); } diff --git a/src/bootstrap/src/core/build_steps/clean.rs b/src/bootstrap/src/core/build_steps/clean.rs index f67569d1486..8712aeb81eb 100644 --- a/src/bootstrap/src/core/build_steps/clean.rs +++ b/src/bootstrap/src/core/build_steps/clean.rs @@ -129,7 +129,7 @@ fn clean_specific_stage(build: &Build, stage: u32) { for entry in entries { let entry = t!(entry); - let stage_prefix = format!("stage{stage}"); + let stage_prefix = format!("stage{}", stage + 1); // if current entry is not related with the target stage, continue if !entry.file_name().to_str().unwrap_or("").contains(&stage_prefix) { diff --git a/src/bootstrap/src/core/build_steps/clippy.rs b/src/bootstrap/src/core/build_steps/clippy.rs index 93c767bdd25..4d734fe5c66 100644 --- a/src/bootstrap/src/core/build_steps/clippy.rs +++ b/src/bootstrap/src/core/build_steps/clippy.rs @@ -143,11 +143,11 @@ impl Step for Std { fn run(self, builder: &Builder<'_>) { let target = self.target; - let compiler = builder.compiler(builder.top_stage, builder.config.host_target); + let build_compiler = builder.compiler(builder.top_stage, builder.config.host_target); let mut cargo = builder::Cargo::new( builder, - compiler, + build_compiler, Mode::Std, SourceType::InTree, target, @@ -160,14 +160,19 @@ impl Step for Std { cargo.arg("-p").arg(krate); } - let _guard = - builder.msg_clippy(format_args!("library{}", crate_description(&self.crates)), target); + let _guard = builder.msg( + Kind::Clippy, + format_args!("library{}", crate_description(&self.crates)), + Mode::Std, + build_compiler, + target, + ); run_cargo( builder, cargo, lint_args(builder, &self.config, IGNORED_RULES_FOR_STD_AND_RUSTC), - &build_stamp::libstd_stamp(builder, compiler, target), + &build_stamp::libstd_stamp(builder, build_compiler, target), vec![], true, false, @@ -203,33 +208,33 @@ impl Step for Rustc { /// This will lint the compiler for a particular stage of the build using /// the `compiler` targeting the `target` architecture. fn run(self, builder: &Builder<'_>) { - let compiler = builder.compiler(builder.top_stage, builder.config.host_target); + let build_compiler = builder.compiler(builder.top_stage, builder.config.host_target); let target = self.target; if !builder.download_rustc() { - if compiler.stage != 0 { + if build_compiler.stage != 0 { // If we're not in stage 0, then we won't have a std from the beta // compiler around. That means we need to make sure there's one in // the sysroot for the compiler to find. Otherwise, we're going to // fail when building crates that need to generate code (e.g., build // scripts and their dependencies). - builder.std(compiler, compiler.host); - builder.std(compiler, target); + builder.std(build_compiler, build_compiler.host); + builder.std(build_compiler, target); } else { - builder.ensure(check::Std::new(compiler, target)); + builder.ensure(check::Std::new(build_compiler, target)); } } let mut cargo = builder::Cargo::new( builder, - compiler, + build_compiler, Mode::Rustc, SourceType::InTree, target, Kind::Clippy, ); - rustc_cargo(builder, &mut cargo, target, &compiler, &self.crates); + rustc_cargo(builder, &mut cargo, target, &build_compiler, &self.crates); // Explicitly pass -p for all compiler crates -- this will force cargo // to also lint the tests/benches/examples for these crates, rather @@ -238,14 +243,19 @@ impl Step for Rustc { cargo.arg("-p").arg(krate); } - let _guard = - builder.msg_clippy(format_args!("compiler{}", crate_description(&self.crates)), target); + let _guard = builder.msg( + Kind::Clippy, + format_args!("compiler{}", crate_description(&self.crates)), + Mode::Rustc, + build_compiler, + target, + ); run_cargo( builder, cargo, lint_args(builder, &self.config, IGNORED_RULES_FOR_STD_AND_RUSTC), - &build_stamp::librustc_stamp(builder, compiler, target), + &build_stamp::librustc_stamp(builder, build_compiler, target), vec![], true, false, @@ -284,16 +294,16 @@ macro_rules! lint_any { } fn run(self, builder: &Builder<'_>) -> Self::Output { - let compiler = builder.compiler(builder.top_stage, builder.config.host_target); + let build_compiler = builder.compiler(builder.top_stage, builder.config.host_target); let target = self.target; if !builder.download_rustc() { - builder.ensure(check::Rustc::new(builder, compiler, target)); + builder.ensure(check::Rustc::new(builder, build_compiler, target)); }; let cargo = prepare_tool_cargo( builder, - compiler, + build_compiler, Mode::ToolRustc, target, Kind::Clippy, @@ -302,17 +312,16 @@ macro_rules! lint_any { &[], ); - let _guard = builder.msg_tool( + let _guard = builder.msg( Kind::Clippy, - Mode::ToolRustc, $readable_name, - compiler.stage, - &compiler.host, - &target, + Mode::ToolRustc, + build_compiler, + target, ); let stringified_name = stringify!($name).to_lowercase(); - let stamp = BuildStamp::new(&builder.cargo_out(compiler, Mode::ToolRustc, target)) + let stamp = BuildStamp::new(&builder.cargo_out(build_compiler, Mode::ToolRustc, target)) .with_prefix(&format!("{}-check", stringified_name)); run_cargo( diff --git a/src/bootstrap/src/core/build_steps/compile.rs b/src/bootstrap/src/core/build_steps/compile.rs index e1ee0773107..c8feba48d84 100644 --- a/src/bootstrap/src/core/build_steps/compile.rs +++ b/src/bootstrap/src/core/build_steps/compile.rs @@ -23,8 +23,7 @@ use crate::core::build_steps::tool::{RustcPrivateCompilers, SourceType, copy_lld use crate::core::build_steps::{dist, llvm}; use crate::core::builder; use crate::core::builder::{ - Builder, Cargo, Kind, PathSet, RunConfig, ShouldRun, Step, StepMetadata, TaskPath, - crate_description, + Builder, Cargo, Kind, RunConfig, ShouldRun, Step, StepMetadata, crate_description, }; use crate::core::config::{DebuginfoLevel, LlvmLibunwind, RustcLto, TargetSelection}; use crate::utils::build_stamp; @@ -160,7 +159,7 @@ impl Step for Std { return; } - let compiler = if builder.download_rustc() && self.force_recompile { + let build_compiler = if builder.download_rustc() && self.force_recompile { // When there are changes in the library tree with CI-rustc, we want to build // the stageN library and that requires using stageN-1 compiler. builder.compiler(self.compiler.stage.saturating_sub(1), builder.config.host_target) @@ -174,7 +173,8 @@ impl Step for Std { && builder.config.is_host_target(target) && !self.force_recompile { - let sysroot = builder.ensure(Sysroot { compiler, force_recompile: false }); + let sysroot = + builder.ensure(Sysroot { compiler: build_compiler, force_recompile: false }); cp_rustc_component_to_ci_sysroot( builder, &sysroot, @@ -183,53 +183,58 @@ impl Step for Std { return; } - if builder.config.keep_stage.contains(&compiler.stage) - || builder.config.keep_stage_std.contains(&compiler.stage) + if builder.config.keep_stage.contains(&build_compiler.stage) + || builder.config.keep_stage_std.contains(&build_compiler.stage) { trace!(keep_stage = ?builder.config.keep_stage); trace!(keep_stage_std = ?builder.config.keep_stage_std); builder.info("WARNING: Using a potentially old libstd. This may not behave well."); - builder.ensure(StartupObjects { compiler, target }); + builder.ensure(StartupObjects { compiler: build_compiler, target }); - self.copy_extra_objects(builder, &compiler, target); + self.copy_extra_objects(builder, &build_compiler, target); - builder.ensure(StdLink::from_std(self, compiler)); + builder.ensure(StdLink::from_std(self, build_compiler)); return; } - let mut target_deps = builder.ensure(StartupObjects { compiler, target }); + let mut target_deps = builder.ensure(StartupObjects { compiler: build_compiler, target }); - let compiler_to_use = builder.compiler_for(compiler.stage, compiler.host, target); + let compiler_to_use = + builder.compiler_for(build_compiler.stage, build_compiler.host, target); trace!(?compiler_to_use); - if compiler_to_use != compiler + if compiler_to_use != build_compiler // Never uplift std unless we have compiled stage 1; if stage 1 is compiled, // uplift it from there. // // FIXME: improve `fn compiler_for` to avoid adding stage condition here. - && compiler.stage > 1 + && build_compiler.stage > 1 { - trace!(?compiler_to_use, ?compiler, "compiler != compiler_to_use, uplifting library"); + trace!( + ?compiler_to_use, + ?build_compiler, + "build_compiler != compiler_to_use, uplifting library" + ); builder.std(compiler_to_use, target); let msg = if compiler_to_use.host == target { format!( "Uplifting library (stage{} -> stage{})", - compiler_to_use.stage, compiler.stage + compiler_to_use.stage, build_compiler.stage ) } else { format!( "Uplifting library (stage{}:{} -> stage{}:{})", - compiler_to_use.stage, compiler_to_use.host, compiler.stage, target + compiler_to_use.stage, compiler_to_use.host, build_compiler.stage, target ) }; builder.info(&msg); // Even if we're not building std this stage, the new sysroot must // still contain the third party objects needed by various targets. - self.copy_extra_objects(builder, &compiler, target); + self.copy_extra_objects(builder, &build_compiler, target); builder.ensure(StdLink::from_std(self, compiler_to_use)); return; @@ -237,11 +242,11 @@ impl Step for Std { trace!( ?compiler_to_use, - ?compiler, + ?build_compiler, "compiler == compiler_to_use, handling not-cross-compile scenario" ); - target_deps.extend(self.copy_extra_objects(builder, &compiler, target)); + target_deps.extend(self.copy_extra_objects(builder, &build_compiler, target)); // We build a sysroot for mir-opt tests using the same trick that Miri does: A check build // with -Zalways-encode-mir. This frees us from the need to have a target linker, and the @@ -250,7 +255,7 @@ impl Step for Std { trace!("building special sysroot for mir-opt tests"); let mut cargo = builder::Cargo::new_for_mir_opt_tests( builder, - compiler, + build_compiler, Mode::Std, SourceType::InTree, target, @@ -263,7 +268,7 @@ impl Step for Std { trace!("building regular sysroot"); let mut cargo = builder::Cargo::new( builder, - compiler, + build_compiler, Mode::Std, SourceType::InTree, target, @@ -286,16 +291,16 @@ impl Step for Std { let _guard = builder.msg( Kind::Build, - compiler.stage, format_args!("library artifacts{}", crate_description(&self.crates)), - compiler.host, + Mode::Std, + build_compiler, target, ); run_cargo( builder, cargo, vec![], - &build_stamp::libstd_stamp(builder, compiler, target), + &build_stamp::libstd_stamp(builder, build_compiler, target), target_deps, self.is_for_mir_opt_tests, // is_check false, @@ -303,7 +308,7 @@ impl Step for Std { builder.ensure(StdLink::from_std( self, - builder.compiler(compiler.stage, builder.config.host_target), + builder.compiler(build_compiler.stage, builder.config.host_target), )); } @@ -1127,11 +1132,11 @@ impl Step for Rustc { cargo.env("RUSTC_BOLT_LINK_FLAGS", "1"); } - let _guard = builder.msg_rustc_tool( + let _guard = builder.msg( Kind::Build, - build_compiler.stage, format_args!("compiler artifacts{}", crate_description(&self.crates)), - build_compiler.host, + Mode::Rustc, + build_compiler, target, ); let stamp = build_stamp::librustc_stamp(builder, build_compiler, target); @@ -1539,99 +1544,126 @@ impl Step for RustcLink { } #[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub struct CodegenBackend { +pub struct GccCodegenBackend { compilers: RustcPrivateCompilers, - backend: CodegenBackendKind, } -fn needs_codegen_config(run: &RunConfig<'_>) -> bool { - let mut needs_codegen_cfg = false; - for path_set in &run.paths { - needs_codegen_cfg = match path_set { - PathSet::Set(set) => set.iter().any(|p| is_codegen_cfg_needed(p, run)), - PathSet::Suite(suite) => is_codegen_cfg_needed(suite, run), - } +impl Step for GccCodegenBackend { + type Output = BuildStamp; + const ONLY_HOSTS: bool = true; + + fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { + run.alias("rustc_codegen_gcc").alias("cg_gcc") } - needs_codegen_cfg -} -pub(crate) const CODEGEN_BACKEND_PREFIX: &str = "rustc_codegen_"; + fn make_run(run: RunConfig<'_>) { + run.builder.ensure(GccCodegenBackend { + compilers: RustcPrivateCompilers::new(run.builder, run.builder.top_stage, run.target), + }); + } -fn is_codegen_cfg_needed(path: &TaskPath, run: &RunConfig<'_>) -> bool { - let path = path.path.to_str().unwrap(); + #[cfg_attr( + feature = "tracing", + instrument( + level = "debug", + name = "GccCodegenBackend::run", + skip_all, + fields( + compilers = ?self.compilers, + ), + ), + )] + fn run(self, builder: &Builder<'_>) -> Self::Output { + let target = self.compilers.target(); + let build_compiler = self.compilers.build_compiler(); - let is_explicitly_called = |p| -> bool { run.builder.paths.contains(p) }; - let should_enforce = run.builder.kind == Kind::Dist || run.builder.kind == Kind::Install; + let stamp = build_stamp::codegen_backend_stamp( + builder, + build_compiler, + target, + &CodegenBackendKind::Gcc, + ); - if path.contains(CODEGEN_BACKEND_PREFIX) { - let mut needs_codegen_backend_config = true; - for backend in run.builder.config.codegen_backends(run.target) { - if path.ends_with(&(CODEGEN_BACKEND_PREFIX.to_owned() + backend.name())) { - needs_codegen_backend_config = false; - } - } - if (is_explicitly_called(&PathBuf::from(path)) || should_enforce) - && needs_codegen_backend_config - { - run.builder.info( - "WARNING: no codegen-backends config matched the requested path to build a codegen backend. \ - HELP: add backend to codegen-backends in bootstrap.toml.", + if builder.config.keep_stage.contains(&build_compiler.stage) { + trace!("`keep-stage` requested"); + builder.info( + "WARNING: Using a potentially old codegen backend. \ + This may not behave well.", ); - return true; + // Codegen backends are linked separately from this step today, so we don't do + // anything here. + return stamp; } + + let mut cargo = builder::Cargo::new( + builder, + build_compiler, + Mode::Codegen, + SourceType::InTree, + target, + Kind::Build, + ); + cargo.arg("--manifest-path").arg(builder.src.join("compiler/rustc_codegen_gcc/Cargo.toml")); + rustc_cargo_env(builder, &mut cargo, target); + + let gcc = builder.ensure(Gcc { target }); + add_cg_gcc_cargo_flags(&mut cargo, &gcc); + + let _guard = + builder.msg(Kind::Build, "codegen backend gcc", Mode::Codegen, build_compiler, target); + let files = run_cargo(builder, cargo, vec![], &stamp, vec![], false, false); + write_codegen_backend_stamp(stamp, files, builder.config.dry_run()) } - false + fn metadata(&self) -> Option<StepMetadata> { + Some( + StepMetadata::build("rustc_codegen_gcc", self.compilers.target()) + .built_by(self.compilers.build_compiler()), + ) + } } -impl Step for CodegenBackend { - type Output = (); +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct CraneliftCodegenBackend { + pub compilers: RustcPrivateCompilers, +} + +impl Step for CraneliftCodegenBackend { + type Output = BuildStamp; const ONLY_HOSTS: bool = true; - /// Only the backends specified in the `codegen-backends` entry of `bootstrap.toml` are built. - const DEFAULT: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.paths(&["compiler/rustc_codegen_cranelift", "compiler/rustc_codegen_gcc"]) + run.alias("rustc_codegen_cranelift").alias("cg_clif") } fn make_run(run: RunConfig<'_>) { - if needs_codegen_config(&run) { - return; - } - - for backend in run.builder.config.codegen_backends(run.target) { - if backend.is_llvm() { - continue; // Already built as part of rustc - } - - run.builder.ensure(CodegenBackend { - compilers: RustcPrivateCompilers::new( - run.builder, - run.builder.top_stage, - run.target, - ), - backend: backend.clone(), - }); - } + run.builder.ensure(CraneliftCodegenBackend { + compilers: RustcPrivateCompilers::new(run.builder, run.builder.top_stage, run.target), + }); } #[cfg_attr( feature = "tracing", instrument( level = "debug", - name = "CodegenBackend::run", + name = "CraneliftCodegenBackend::run", skip_all, fields( compilers = ?self.compilers, - backend = ?self.backend, ), ), )] - fn run(self, builder: &Builder<'_>) { - let backend = self.backend; + fn run(self, builder: &Builder<'_>) -> Self::Output { let target = self.compilers.target(); let build_compiler = self.compilers.build_compiler(); + let stamp = build_stamp::codegen_backend_stamp( + builder, + build_compiler, + target, + &CodegenBackendKind::Cranelift, + ); + if builder.config.keep_stage.contains(&build_compiler.stage) { trace!("`keep-stage` requested"); builder.info( @@ -1640,11 +1672,9 @@ impl Step for CodegenBackend { ); // Codegen backends are linked separately from this step today, so we don't do // anything here. - return; + return stamp; } - let out_dir = builder.cargo_out(build_compiler, Mode::Codegen, target); - let mut cargo = builder::Cargo::new( builder, build_compiler, @@ -1655,71 +1685,67 @@ impl Step for CodegenBackend { ); cargo .arg("--manifest-path") - .arg(builder.src.join(format!("compiler/{}/Cargo.toml", backend.crate_name()))); + .arg(builder.src.join("compiler/rustc_codegen_cranelift/Cargo.toml")); rustc_cargo_env(builder, &mut cargo, target); - // Ideally, we'd have a separate step for the individual codegen backends, - // like we have in tests (test::CodegenGCC) but that would require a lot of restructuring. - // If the logic gets more complicated, it should probably be done. - if backend.is_gcc() { - let gcc = builder.ensure(Gcc { target }); - add_cg_gcc_cargo_flags(&mut cargo, &gcc); - } - - let tmp_stamp = BuildStamp::new(&out_dir).with_prefix("tmp"); - - let _guard = builder.msg_rustc_tool( + let _guard = builder.msg( Kind::Build, - build_compiler.stage, - format_args!("codegen backend {}", backend.name()), - build_compiler.host, + "codegen backend cranelift", + Mode::Codegen, + build_compiler, target, ); - let files = run_cargo(builder, cargo, vec![], &tmp_stamp, vec![], false, false); - if builder.config.dry_run() { - return; - } - let mut files = files.into_iter().filter(|f| { - let filename = f.file_name().unwrap().to_str().unwrap(); - is_dylib(f) && filename.contains("rustc_codegen_") - }); - let codegen_backend = match files.next() { - Some(f) => f, - None => panic!("no dylibs built for codegen backend?"), - }; - if let Some(f) = files.next() { - panic!( - "codegen backend built two dylibs:\n{}\n{}", - codegen_backend.display(), - f.display() - ); - } - let stamp = build_stamp::codegen_backend_stamp(builder, build_compiler, target, &backend); - let codegen_backend = codegen_backend.to_str().unwrap(); - t!(stamp.add_stamp(codegen_backend).write()); + let files = run_cargo(builder, cargo, vec![], &stamp, vec![], false, false); + write_codegen_backend_stamp(stamp, files, builder.config.dry_run()) } fn metadata(&self) -> Option<StepMetadata> { Some( - StepMetadata::build(&self.backend.crate_name(), self.compilers.target()) + StepMetadata::build("rustc_codegen_cranelift", self.compilers.target()) .built_by(self.compilers.build_compiler()), ) } } +/// Write filtered `files` into the passed build stamp and returns it. +fn write_codegen_backend_stamp( + mut stamp: BuildStamp, + files: Vec<PathBuf>, + dry_run: bool, +) -> BuildStamp { + if dry_run { + return stamp; + } + + let mut files = files.into_iter().filter(|f| { + let filename = f.file_name().unwrap().to_str().unwrap(); + is_dylib(f) && filename.contains("rustc_codegen_") + }); + let codegen_backend = match files.next() { + Some(f) => f, + None => panic!("no dylibs built for codegen backend?"), + }; + if let Some(f) = files.next() { + panic!("codegen backend built two dylibs:\n{}\n{}", codegen_backend.display(), f.display()); + } + + let codegen_backend = codegen_backend.to_str().unwrap(); + stamp = stamp.add_stamp(codegen_backend); + t!(stamp.write()); + stamp +} + /// Creates the `codegen-backends` folder for a compiler that's about to be /// assembled as a complete compiler. /// -/// This will take the codegen artifacts produced by `compiler` and link them +/// This will take the codegen artifacts recorded in the given `stamp` and link them /// into an appropriate location for `target_compiler` to be a functional /// compiler. fn copy_codegen_backends_to_sysroot( builder: &Builder<'_>, - compiler: Compiler, + stamp: BuildStamp, target_compiler: Compiler, ) { - let target = target_compiler.host; - // Note that this step is different than all the other `*Link` steps in // that it's not assembling a bunch of libraries but rather is primarily // moving the codegen backend into place. The codegen backend of rustc is @@ -1735,28 +1761,31 @@ fn copy_codegen_backends_to_sysroot( return; } - for backend in builder.config.codegen_backends(target) { - if backend.is_llvm() { - continue; // Already built as part of rustc - } - - let stamp = build_stamp::codegen_backend_stamp(builder, compiler, target, backend); - if stamp.path().exists() { - let dylib = t!(fs::read_to_string(stamp.path())); - let file = Path::new(&dylib); - let filename = file.file_name().unwrap().to_str().unwrap(); - // change `librustc_codegen_cranelift-xxxxxx.so` to - // `librustc_codegen_cranelift-release.so` - let target_filename = { - let dash = filename.find('-').unwrap(); - let dot = filename.find('.').unwrap(); - format!("{}-{}{}", &filename[..dash], builder.rust_release(), &filename[dot..]) - }; - builder.copy_link(file, &dst.join(target_filename), FileType::NativeLibrary); - } + if stamp.path().exists() { + let file = get_codegen_backend_file(&stamp); + builder.copy_link( + &file, + &dst.join(normalize_codegen_backend_name(builder, &file)), + FileType::NativeLibrary, + ); } } +/// Gets the path to a dynamic codegen backend library from its build stamp. +pub fn get_codegen_backend_file(stamp: &BuildStamp) -> PathBuf { + PathBuf::from(t!(fs::read_to_string(stamp.path()))) +} + +/// Normalize the name of a dynamic codegen backend library. +pub fn normalize_codegen_backend_name(builder: &Builder<'_>, path: &Path) -> String { + let filename = path.file_name().unwrap().to_str().unwrap(); + // change e.g. `librustc_codegen_cranelift-xxxxxx.so` to + // `librustc_codegen_cranelift-release.so` + let dash = filename.find('-').unwrap(); + let dot = filename.find('.').unwrap(); + format!("{}-{}{}", &filename[..dash], builder.rust_release(), &filename[dot..]) +} + pub fn compiler_file( builder: &Builder<'_>, compiler: &Path, @@ -2162,44 +2191,52 @@ impl Step for Assemble { ); build_compiler.stage = actual_stage; - #[cfg(feature = "tracing")] - let _codegen_backend_span = - span!(tracing::Level::DEBUG, "building requested codegen backends").entered(); - for backend in builder.config.codegen_backends(target_compiler.host) { - if backend.is_llvm() { - debug!("llvm codegen backend is already built as part of rustc"); - continue; // Already built as part of rustc - } + let mut codegen_backend_stamps = vec![]; + { + #[cfg(feature = "tracing")] + let _codegen_backend_span = + span!(tracing::Level::DEBUG, "building requested codegen backends").entered(); + + for backend in builder.config.enabled_codegen_backends(target_compiler.host) { + // FIXME: this is a horrible hack used to make `x check` work when other codegen + // backends are enabled. + // `x check` will check stage 1 rustc, which copies its rmetas to the stage0 sysroot. + // Then it checks codegen backends, which correctly use these rmetas. + // Then it needs to check std, but for that it needs to build stage 1 rustc. + // This copies the build rmetas into the stage0 sysroot, effectively poisoning it, + // because we then have both check and build rmetas in the same sysroot. + // That would be fine on its own. However, when another codegen backend is enabled, + // then building stage 1 rustc implies also building stage 1 codegen backend (even if + // it isn't used for anything). And since that tries to use the poisoned + // rmetas, it fails to build. + // We don't actually need to build rustc-private codegen backends for checking std, + // so instead we skip that. + // Note: this would be also an issue for other rustc-private tools, but that is "solved" + // by check::Std being last in the list of checked things (see + // `Builder::get_step_descriptions`). + if builder.kind == Kind::Check && builder.top_stage == 1 { + continue; + } - // FIXME: this is a horrible hack used to make `x check` work when other codegen - // backends are enabled. - // `x check` will check stage 1 rustc, which copies its rmetas to the stage0 sysroot. - // Then it checks codegen backends, which correctly use these rmetas. - // Then it needs to check std, but for that it needs to build stage 1 rustc. - // This copies the build rmetas into the stage0 sysroot, effectively poisoning it, - // because we then have both check and build rmetas in the same sysroot. - // That would be fine on its own. However, when another codegen backend is enabled, - // then building stage 1 rustc implies also building stage 1 codegen backend (even if - // it isn't used for anything). And since that tries to use the poisoned - // rmetas, it fails to build. - // We don't actually need to build rustc-private codegen backends for checking std, - // so instead we skip that. - // Note: this would be also an issue for other rustc-private tools, but that is "solved" - // by check::Std being last in the list of checked things (see - // `Builder::get_step_descriptions`). - if builder.kind == Kind::Check && builder.top_stage == 1 { - continue; + let prepare_compilers = || { + RustcPrivateCompilers::from_build_and_target_compiler( + build_compiler, + target_compiler, + ) + }; + + let stamp = match backend { + CodegenBackendKind::Cranelift => { + builder.ensure(CraneliftCodegenBackend { compilers: prepare_compilers() }) + } + CodegenBackendKind::Gcc => { + builder.ensure(GccCodegenBackend { compilers: prepare_compilers() }) + } + CodegenBackendKind::Llvm | CodegenBackendKind::Custom(_) => continue, + }; + codegen_backend_stamps.push(stamp); } - builder.ensure(CodegenBackend { - compilers: RustcPrivateCompilers::from_build_and_target_compiler( - build_compiler, - target_compiler, - ), - backend: backend.clone(), - }); } - #[cfg(feature = "tracing")] - drop(_codegen_backend_span); let stage = target_compiler.stage; let host = target_compiler.host; @@ -2260,7 +2297,9 @@ impl Step for Assemble { } debug!("copying codegen backends to sysroot"); - copy_codegen_backends_to_sysroot(builder, build_compiler, target_compiler); + for stamp in codegen_backend_stamps { + copy_codegen_backends_to_sysroot(builder, stamp, target_compiler); + } if builder.config.lld_enabled { let lld_wrapper = diff --git a/src/bootstrap/src/core/build_steps/dist.rs b/src/bootstrap/src/core/build_steps/dist.rs index cbbfb6b6a11..f9cb300b68e 100644 --- a/src/bootstrap/src/core/build_steps/dist.rs +++ b/src/bootstrap/src/core/build_steps/dist.rs @@ -19,6 +19,7 @@ use object::read::archive::ArchiveFile; #[cfg(feature = "tracing")] use tracing::instrument; +use crate::core::build_steps::compile::{get_codegen_backend_file, normalize_codegen_backend_name}; use crate::core::build_steps::doc::DocumentationFormat; use crate::core::build_steps::tool::{self, RustcPrivateCompilers, Tool}; use crate::core::build_steps::vendor::{VENDOR_DIR, Vendor}; @@ -92,7 +93,8 @@ impl Step for Docs { #[derive(Debug, PartialOrd, Ord, Clone, Hash, PartialEq, Eq)] pub struct JsonDocs { - pub host: TargetSelection, + build_compiler: Compiler, + target: TargetSelection, } impl Step for JsonDocs { @@ -105,24 +107,27 @@ impl Step for JsonDocs { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(JsonDocs { host: run.target }); + run.builder.ensure(JsonDocs { + build_compiler: run.builder.compiler(run.builder.top_stage, run.builder.host_target), + target: run.target, + }); } /// Builds the `rust-docs-json` installer component. fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> { - let host = self.host; - builder.ensure(crate::core::build_steps::doc::Std::new( - builder.top_stage, - host, + let target = self.target; + let directory = builder.ensure(crate::core::build_steps::doc::Std::from_build_compiler( + self.build_compiler, + target, DocumentationFormat::Json, )); let dest = "share/doc/rust/json"; - let mut tarball = Tarball::new(builder, "rust-docs-json", &host.triple); + let mut tarball = Tarball::new(builder, "rust-docs-json", &target.triple); tarball.set_product_name("Rust Documentation In JSON Format"); tarball.is_preview(true); - tarball.add_bulk_dir(builder.json_doc_out(host), dest); + tarball.add_bulk_dir(directory, dest); Some(tarball.generate()) } } @@ -925,6 +930,8 @@ fn copy_src_dirs( "llvm-project\\cmake", "llvm-project/runtimes", "llvm-project\\runtimes", + "llvm-project/third-party", + "llvm-project\\third-party", ]; if spath.contains("llvm-project") && !spath.ends_with("llvm-project") @@ -933,6 +940,18 @@ fn copy_src_dirs( return false; } + // Keep only these third party libraries + const LLVM_THIRD_PARTY: &[&str] = + &["llvm-project/third-party/siphash", "llvm-project\\third-party\\siphash"]; + if (spath.starts_with("llvm-project/third-party") + || spath.starts_with("llvm-project\\third-party")) + && !(spath.ends_with("llvm-project/third-party") + || spath.ends_with("llvm-project\\third-party")) + && !LLVM_THIRD_PARTY.iter().any(|path| spath.contains(path)) + { + return false; + } + const LLVM_TEST: &[&str] = &["llvm-project/llvm/test", "llvm-project\\llvm\\test"]; if LLVM_TEST.iter().any(|path| spath.contains(path)) && (spath.ends_with(".ll") || spath.ends_with(".td") || spath.ends_with(".s")) @@ -1389,38 +1408,39 @@ impl Step for Miri { } #[derive(Debug, Clone, Hash, PartialEq, Eq)] -pub struct CodegenBackend { - pub compiler: Compiler, - pub backend: CodegenBackendKind, +pub struct CraneliftCodegenBackend { + pub build_compiler: Compiler, } -impl Step for CodegenBackend { +impl Step for CraneliftCodegenBackend { type Output = Option<GeneratedTarball>; const DEFAULT: bool = true; const ONLY_HOSTS: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { - run.path("compiler/rustc_codegen_cranelift") + // We only want to build the cranelift backend in `x dist` if the backend was enabled + // in rust.codegen-backends. + // Sadly, we don't have access to the actual target for which we're disting clif here.. + // So we just use the host target. + let clif_enabled_by_default = run + .builder + .config + .enabled_codegen_backends(run.builder.host_target) + .contains(&CodegenBackendKind::Cranelift); + run.alias("rustc_codegen_cranelift").default_condition(clif_enabled_by_default) } fn make_run(run: RunConfig<'_>) { - for backend in run.builder.config.codegen_backends(run.target) { - if backend.is_llvm() { - continue; // Already built as part of rustc - } - - run.builder.ensure(CodegenBackend { - compiler: run.builder.compiler(run.builder.top_stage, run.target), - backend: backend.clone(), - }); - } + run.builder.ensure(CraneliftCodegenBackend { + build_compiler: run.builder.compiler_for( + run.builder.top_stage, + run.builder.config.host_target, + run.target, + ), + }); } fn run(self, builder: &Builder<'_>) -> Option<GeneratedTarball> { - if builder.config.dry_run() { - return None; - } - // This prevents rustc_codegen_cranelift from being built for "dist" // or "install" on the stable/beta channels. It is not yet stable and // should not be included. @@ -1428,58 +1448,52 @@ impl Step for CodegenBackend { return None; } - if !builder.config.codegen_backends(self.compiler.host).contains(&self.backend) { - return None; - } - - if self.backend.is_cranelift() && !target_supports_cranelift_backend(self.compiler.host) { + let target = self.build_compiler.host; + let compilers = + RustcPrivateCompilers::from_build_compiler(builder, self.build_compiler, target); + if !target_supports_cranelift_backend(target) { builder.info("target not supported by rustc_codegen_cranelift. skipping"); return None; } - let compiler = self.compiler; - let backend = self.backend; + let mut tarball = Tarball::new(builder, "rustc-codegen-cranelift", &target.triple); + tarball.set_overlay(OverlayKind::RustcCodegenCranelift); + tarball.is_preview(true); + tarball.add_legal_and_readme_to("share/doc/rustc_codegen_cranelift"); - let mut tarball = Tarball::new( - builder, - &format!("rustc-codegen-{}", backend.name()), - &compiler.host.triple, - ); - if backend.is_cranelift() { - tarball.set_overlay(OverlayKind::RustcCodegenCranelift); - } else { - panic!("Unknown codegen backend {}", backend.name()); + let stamp = builder.ensure(compile::CraneliftCodegenBackend { compilers }); + + if builder.config.dry_run() { + return None; } - tarball.is_preview(true); - tarball.add_legal_and_readme_to(format!("share/doc/{}", backend.crate_name())); - let src = builder.sysroot(compiler); - let backends_src = builder.sysroot_codegen_backends(compiler); - let backends_rel = backends_src - .strip_prefix(src) + // Get the relative path of where the codegen backend should be stored. + let backends_dst = builder.sysroot_codegen_backends(compilers.target_compiler()); + let backends_rel = backends_dst + .strip_prefix(builder.sysroot(compilers.target_compiler())) .unwrap() - .strip_prefix(builder.sysroot_libdir_relative(compiler)) + .strip_prefix(builder.sysroot_libdir_relative(compilers.target_compiler())) .unwrap(); // Don't use custom libdir here because ^lib/ will be resolved again with installer let backends_dst = PathBuf::from("lib").join(backends_rel); - let backend_name = backend.crate_name(); - let mut found_backend = false; - for backend in fs::read_dir(&backends_src).unwrap() { - let file_name = backend.unwrap().file_name(); - if file_name.to_str().unwrap().contains(&backend_name) { - tarball.add_file( - backends_src.join(file_name), - &backends_dst, - FileType::NativeLibrary, - ); - found_backend = true; - } - } - assert!(found_backend); + let codegen_backend_dylib = get_codegen_backend_file(&stamp); + tarball.add_renamed_file( + &codegen_backend_dylib, + &backends_dst, + &normalize_codegen_backend_name(builder, &codegen_backend_dylib), + FileType::NativeLibrary, + ); Some(tarball.generate()) } + + fn metadata(&self) -> Option<StepMetadata> { + Some( + StepMetadata::dist("rustc_codegen_cranelift", self.build_compiler.host) + .built_by(self.build_compiler), + ) + } } #[derive(Debug, Clone, Hash, PartialEq, Eq)] @@ -1570,11 +1584,12 @@ impl Step for Extended { }; } + let target_compiler = builder.compiler(stage, target); // When rust-std package split from rustc, we needed to ensure that during // upgrades rustc was upgraded before rust-std. To avoid rustc clobbering // the std files during uninstall. To do this ensure that rustc comes // before rust-std in the list below. - tarballs.push(builder.ensure(Rustc { compiler: builder.compiler(stage, target) })); + tarballs.push(builder.ensure(Rustc { compiler: target_compiler })); tarballs.push(builder.ensure(Std { compiler, target }).expect("missing std")); if target.is_windows_gnu() { @@ -1582,7 +1597,8 @@ impl Step for Extended { } add_component!("rust-docs" => Docs { host: target }); - add_component!("rust-json-docs" => JsonDocs { host: target }); + // Std stage N is documented with compiler stage N + add_component!("rust-json-docs" => JsonDocs { build_compiler: target_compiler, target }); add_component!("cargo" => Cargo { build_compiler: compiler, target }); add_component!("rustfmt" => Rustfmt { build_compiler: compiler, target }); add_component!("rust-analyzer" => RustAnalyzer { build_compiler: compiler, target }); @@ -1590,9 +1606,8 @@ impl Step for Extended { add_component!("clippy" => Clippy { build_compiler: compiler, target }); add_component!("miri" => Miri { build_compiler: compiler, target }); add_component!("analysis" => Analysis { compiler, target }); - add_component!("rustc-codegen-cranelift" => CodegenBackend { - compiler: builder.compiler(stage, target), - backend: CodegenBackendKind::Cranelift, + add_component!("rustc-codegen-cranelift" => CraneliftCodegenBackend { + build_compiler: compiler, }); add_component!("llvm-bitcode-linker" => LlvmBitcodeLinker { build_compiler: compiler, diff --git a/src/bootstrap/src/core/build_steps/doc.rs b/src/bootstrap/src/core/build_steps/doc.rs index 434e9c0977d..6f0d5203d11 100644 --- a/src/bootstrap/src/core/build_steps/doc.rs +++ b/src/bootstrap/src/core/build_steps/doc.rs @@ -16,8 +16,7 @@ use crate::core::build_steps::tool::{ self, RustcPrivateCompilers, SourceType, Tool, prepare_tool_cargo, }; use crate::core::builder::{ - self, Alias, Builder, Compiler, Kind, RunConfig, ShouldRun, Step, StepMetadata, - crate_description, + self, Builder, Compiler, Kind, RunConfig, ShouldRun, Step, StepMetadata, crate_description, }; use crate::core::config::{Config, TargetSelection}; use crate::helpers::{submodule_path_of, symlink_dir, t, up_to_date}; @@ -26,7 +25,7 @@ use crate::{FileType, Mode}; macro_rules! book { ($($name:ident, $path:expr, $book_name:expr, $lang:expr ;)+) => { $( - #[derive(Debug, Clone, Hash, PartialEq, Eq)] + #[derive(Debug, Clone, Hash, PartialEq, Eq)] pub struct $name { target: TargetSelection, } @@ -57,7 +56,7 @@ macro_rules! book { src: builder.src.join($path), parent: Some(self), languages: $lang.into(), - rustdoc_compiler: None, + build_compiler: None, }) } } @@ -105,7 +104,7 @@ impl Step for UnstableBook { src: builder.md_doc_out(self.target).join("unstable-book"), parent: Some(self), languages: vec![], - rustdoc_compiler: None, + build_compiler: None, }) } } @@ -117,7 +116,8 @@ struct RustbookSrc<P: Step> { src: PathBuf, parent: Option<P>, languages: Vec<&'static str>, - rustdoc_compiler: Option<Compiler>, + /// Compiler whose rustdoc should be used to document things using `mdbook-spec`. + build_compiler: Option<Compiler>, } impl<P: Step> Step for RustbookSrc<P> { @@ -150,7 +150,7 @@ impl<P: Step> Step for RustbookSrc<P> { let mut rustbook_cmd = builder.tool_cmd(Tool::Rustbook); - if let Some(compiler) = self.rustdoc_compiler { + if let Some(compiler) = self.build_compiler { let mut rustdoc = builder.rustdoc_for_compiler(compiler); rustdoc.pop(); let old_path = env::var_os("PATH").unwrap_or_default(); @@ -193,11 +193,21 @@ impl<P: Step> Step for RustbookSrc<P> { builder.maybe_open_in_browser::<P>(index) } } + + fn metadata(&self) -> Option<StepMetadata> { + let mut metadata = StepMetadata::doc(&format!("{} (book)", self.name), self.target); + if let Some(compiler) = self.build_compiler { + metadata = metadata.built_by(compiler); + } + + Some(metadata) + } } #[derive(Debug, Clone, Hash, PartialEq, Eq)] pub struct TheBook { - compiler: Compiler, + /// Compiler whose rustdoc will be used to generated documentation. + build_compiler: Compiler, target: TargetSelection, } @@ -212,7 +222,7 @@ impl Step for TheBook { fn make_run(run: RunConfig<'_>) { run.builder.ensure(TheBook { - compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.host_target), + build_compiler: prepare_doc_compiler(run.builder, run.target, run.builder.top_stage), target: run.target, }); } @@ -229,7 +239,7 @@ impl Step for TheBook { fn run(self, builder: &Builder<'_>) { builder.require_submodule("src/doc/book", None); - let compiler = self.compiler; + let build_compiler = self.build_compiler; let target = self.target; let absolute_path = builder.src.join("src/doc/book"); @@ -242,7 +252,7 @@ impl Step for TheBook { src: absolute_path.clone(), parent: Some(self), languages: vec![], - rustdoc_compiler: None, + build_compiler: None, }); // building older edition redirects @@ -255,7 +265,7 @@ impl Step for TheBook { // treat the other editions as not having a parent. parent: Option::<Self>::None, languages: vec![], - rustdoc_compiler: None, + build_compiler: None, }); } @@ -263,20 +273,20 @@ impl Step for TheBook { let shared_assets = builder.ensure(SharedAssets { target }); // build the redirect pages - let _guard = builder.msg_doc(compiler, "book redirect pages", target); + let _guard = builder.msg(Kind::Doc, "book redirect pages", None, build_compiler, target); for file in t!(fs::read_dir(redirect_path)) { let file = t!(file); let path = file.path(); let path = path.to_str().unwrap(); - invoke_rustdoc(builder, compiler, &shared_assets, target, path); + invoke_rustdoc(builder, build_compiler, &shared_assets, target, path); } } } fn invoke_rustdoc( builder: &Builder<'_>, - compiler: Compiler, + build_compiler: Compiler, shared_assets: &SharedAssetsPaths, target: TargetSelection, markdown: &str, @@ -288,7 +298,7 @@ fn invoke_rustdoc( let header = builder.src.join("src/doc/redirect.inc"); let footer = builder.src.join("src/doc/footer.inc"); - let mut cmd = builder.rustdoc_cmd(compiler); + let mut cmd = builder.rustdoc_cmd(build_compiler); let out = out.join("book"); @@ -317,7 +327,7 @@ fn invoke_rustdoc( #[derive(Debug, Clone, Hash, PartialEq, Eq)] pub struct Standalone { - compiler: Compiler, + build_compiler: Compiler, target: TargetSelection, } @@ -332,7 +342,11 @@ impl Step for Standalone { fn make_run(run: RunConfig<'_>) { run.builder.ensure(Standalone { - compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.host_target), + build_compiler: prepare_doc_compiler( + run.builder, + run.builder.host_target, + run.builder.top_stage, + ), target: run.target, }); } @@ -347,8 +361,8 @@ impl Step for Standalone { /// In the end, this is just a glorified wrapper around rustdoc! fn run(self, builder: &Builder<'_>) { let target = self.target; - let compiler = self.compiler; - let _guard = builder.msg_doc(compiler, "standalone", target); + let build_compiler = self.build_compiler; + let _guard = builder.msg(Kind::Doc, "standalone", None, build_compiler, target); let out = builder.doc_out(target); t!(fs::create_dir_all(&out)); @@ -367,7 +381,7 @@ impl Step for Standalone { } let html = out.join(filename).with_extension("html"); - let rustdoc = builder.rustdoc_for_compiler(compiler); + let rustdoc = builder.rustdoc_for_compiler(build_compiler); if up_to_date(&path, &html) && up_to_date(&footer, &html) && up_to_date(&favicon, &html) @@ -378,7 +392,7 @@ impl Step for Standalone { continue; } - let mut cmd = builder.rustdoc_cmd(compiler); + let mut cmd = builder.rustdoc_cmd(build_compiler); cmd.arg("--html-after-content") .arg(&footer) @@ -415,11 +429,15 @@ impl Step for Standalone { builder.open_in_browser(index); } } + + fn metadata(&self) -> Option<StepMetadata> { + Some(StepMetadata::doc("standalone", self.target).built_by(self.build_compiler)) + } } #[derive(Debug, Clone, Hash, PartialEq, Eq)] pub struct Releases { - compiler: Compiler, + build_compiler: Compiler, target: TargetSelection, } @@ -434,7 +452,11 @@ impl Step for Releases { fn make_run(run: RunConfig<'_>) { run.builder.ensure(Releases { - compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.host_target), + build_compiler: prepare_doc_compiler( + run.builder, + run.builder.host_target, + run.builder.top_stage, + ), target: run.target, }); } @@ -446,15 +468,12 @@ impl Step for Releases { /// the headline added. In the end, the conversion is done by Rustdoc. fn run(self, builder: &Builder<'_>) { let target = self.target; - let compiler = self.compiler; - let _guard = builder.msg_doc(compiler, "releases", target); + let build_compiler = self.build_compiler; + let _guard = builder.msg(Kind::Doc, "releases", None, build_compiler, target); let out = builder.doc_out(target); t!(fs::create_dir_all(&out)); - builder.ensure(Standalone { - compiler: builder.compiler(builder.top_stage, builder.config.host_target), - target, - }); + builder.ensure(Standalone { build_compiler, target }); let version_info = builder.ensure(SharedAssets { target: self.target }).version_info; @@ -465,7 +484,7 @@ impl Step for Releases { let html = out.join("releases.html"); let tmppath = out.join("releases.md"); let inpath = builder.src.join("RELEASES.md"); - let rustdoc = builder.rustdoc_for_compiler(compiler); + let rustdoc = builder.rustdoc_for_compiler(build_compiler); if !up_to_date(&inpath, &html) || !up_to_date(&footer, &html) || !up_to_date(&favicon, &html) @@ -478,7 +497,7 @@ impl Step for Releases { t!(tmpfile.write_all(b"% Rust Release Notes\n\n")); t!(io::copy(&mut t!(fs::File::open(&inpath)), &mut tmpfile)); mem::drop(tmpfile); - let mut cmd = builder.rustdoc_cmd(compiler); + let mut cmd = builder.rustdoc_cmd(build_compiler); cmd.arg("--html-after-content") .arg(&footer) @@ -511,6 +530,10 @@ impl Step for Releases { builder.open_in_browser(&html); } } + + fn metadata(&self) -> Option<StepMetadata> { + Some(StepMetadata::doc("releases", self.target).built_by(self.build_compiler)) + } } #[derive(Debug, Clone)] @@ -556,22 +579,29 @@ impl Step for SharedAssets { } } +/// Document the standard library using `build_compiler`. #[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] pub struct Std { - pub stage: u32, - pub target: TargetSelection, - pub format: DocumentationFormat, + build_compiler: Compiler, + target: TargetSelection, + format: DocumentationFormat, crates: Vec<String>, } impl Std { - pub(crate) fn new(stage: u32, target: TargetSelection, format: DocumentationFormat) -> Self { - Std { stage, target, format, crates: vec![] } + pub(crate) fn from_build_compiler( + build_compiler: Compiler, + target: TargetSelection, + format: DocumentationFormat, + ) -> Self { + Std { build_compiler, target, format, crates: vec![] } } } impl Step for Std { - type Output = (); + /// Path to a directory with the built documentation. + type Output = PathBuf; + const DEFAULT: bool = true; fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { @@ -586,7 +616,7 @@ impl Step for Std { return; } run.builder.ensure(Std { - stage: run.builder.top_stage, + build_compiler: run.builder.compiler(run.builder.top_stage, run.builder.host_target), target: run.target, format: if run.builder.config.cmd.json() { DocumentationFormat::Json @@ -601,8 +631,7 @@ impl Step for Std { /// /// This will generate all documentation for the standard library and its /// dependencies. This is largely just a wrapper around `cargo doc`. - fn run(self, builder: &Builder<'_>) { - let stage = self.stage; + fn run(self, builder: &Builder<'_>) -> Self::Output { let target = self.target; let crates = if self.crates.is_empty() { builder @@ -644,32 +673,32 @@ impl Step for Std { // For `--index-page` and `--output-format=json`. extra_args.push("-Zunstable-options"); - doc_std(builder, self.format, stage, target, &out, &extra_args, &crates); - - // Don't open if the format is json - if let DocumentationFormat::Json = self.format { - return; - } + doc_std(builder, self.format, self.build_compiler, target, &out, &extra_args, &crates); - if builder.paths.iter().any(|path| path.ends_with("library")) { - // For `x.py doc library --open`, open `std` by default. - let index = out.join("std").join("index.html"); - builder.open_in_browser(index); - } else { - for requested_crate in crates { - if STD_PUBLIC_CRATES.iter().any(|&k| k == requested_crate) { - let index = out.join(requested_crate).join("index.html"); - builder.open_in_browser(index); - break; + // Open if the format is HTML + if let DocumentationFormat::Html = self.format { + if builder.paths.iter().any(|path| path.ends_with("library")) { + // For `x.py doc library --open`, open `std` by default. + let index = out.join("std").join("index.html"); + builder.open_in_browser(index); + } else { + for requested_crate in crates { + if STD_PUBLIC_CRATES.iter().any(|&k| k == requested_crate) { + let index = out.join(requested_crate).join("index.html"); + builder.open_in_browser(index); + break; + } } } } + + out } fn metadata(&self) -> Option<StepMetadata> { Some( StepMetadata::doc("std", self.target) - .stage(self.stage) + .built_by(self.build_compiler) .with_metadata(format!("crates=[{}]", self.crates.join(","))), ) } @@ -705,24 +734,29 @@ impl DocumentationFormat { fn doc_std( builder: &Builder<'_>, format: DocumentationFormat, - stage: u32, + build_compiler: Compiler, target: TargetSelection, out: &Path, extra_args: &[&str], requested_crates: &[String], ) { - let compiler = builder.compiler(stage, builder.config.host_target); - let target_doc_dir_name = if format == DocumentationFormat::Json { "json-doc" } else { "doc" }; - let target_dir = builder.stage_out(compiler, Mode::Std).join(target).join(target_doc_dir_name); + let target_dir = + builder.stage_out(build_compiler, Mode::Std).join(target).join(target_doc_dir_name); // This is directory where the compiler will place the output of the command. // We will then copy the files from this directory into the final `out` directory, the specified // as a function parameter. let out_dir = target_dir.join(target).join("doc"); - let mut cargo = - builder::Cargo::new(builder, compiler, Mode::Std, SourceType::InTree, target, Kind::Doc); + let mut cargo = builder::Cargo::new( + builder, + build_compiler, + Mode::Std, + SourceType::InTree, + target, + Kind::Doc, + ); compile::std_cargo(builder, target, &mut cargo); cargo @@ -750,27 +784,46 @@ fn doc_std( let description = format!("library{} in {} format", crate_description(requested_crates), format.as_str()); - let _guard = builder.msg_doc(compiler, description, target); + let _guard = builder.msg(Kind::Doc, description, None, build_compiler, target); cargo.into_cmd().run(builder); builder.cp_link_r(&out_dir, out); } +/// Prepare a compiler that will be able to document something for `target` at `stage`. +fn prepare_doc_compiler(builder: &Builder<'_>, target: TargetSelection, stage: u32) -> Compiler { + assert!(stage > 0, "Cannot document anything in stage 0"); + let build_compiler = builder.compiler(stage - 1, builder.host_target); + builder.std(build_compiler, target); + build_compiler +} + +/// Document the compiler for the given `target` using rustdoc from `build_compiler`. #[derive(Debug, Clone, Hash, PartialEq, Eq)] pub struct Rustc { - pub stage: u32, - pub target: TargetSelection, + build_compiler: Compiler, + target: TargetSelection, crates: Vec<String>, } impl Rustc { - pub(crate) fn new(stage: u32, target: TargetSelection, builder: &Builder<'_>) -> Self { + /// Document `stage` compiler for the given `target`. + pub(crate) fn for_stage(builder: &Builder<'_>, stage: u32, target: TargetSelection) -> Self { + let build_compiler = prepare_doc_compiler(builder, target, stage); + Self::from_build_compiler(builder, build_compiler, target) + } + + fn from_build_compiler( + builder: &Builder<'_>, + build_compiler: Compiler, + target: TargetSelection, + ) -> Self { let crates = builder .in_tree_crates("rustc-main", Some(target)) .into_iter() .map(|krate| krate.name.to_string()) .collect(); - Self { stage, target, crates } + Self { build_compiler, target, crates } } } @@ -787,11 +840,7 @@ impl Step for Rustc { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure(Rustc { - stage: run.builder.top_stage, - target: run.target, - crates: run.make_run_crates(Alias::Compiler), - }); + run.builder.ensure(Rustc::for_stage(run.builder, run.builder.top_stage, run.target)); } /// Generates compiler documentation. @@ -801,7 +850,6 @@ impl Step for Rustc { /// we do not merge it with the other documentation from std, test and /// proc_macros. This is largely just a wrapper around `cargo doc`. fn run(self, builder: &Builder<'_>) { - let stage = self.stage; let target = self.target; // This is the intended out directory for compiler documentation. @@ -810,21 +858,21 @@ impl Step for Rustc { // Build the standard library, so that proc-macros can use it. // (Normally, only the metadata would be necessary, but proc-macros are special since they run at compile-time.) - let compiler = builder.compiler(stage, builder.config.host_target); - builder.std(compiler, builder.config.host_target); + let build_compiler = self.build_compiler; + builder.std(build_compiler, builder.config.host_target); - let _guard = builder.msg_rustc_tool( + let _guard = builder.msg( Kind::Doc, - stage, format!("compiler{}", crate_description(&self.crates)), - compiler.host, + Mode::Rustc, + build_compiler, target, ); // Build cargo command. let mut cargo = builder::Cargo::new( builder, - compiler, + build_compiler, Mode::Rustc, SourceType::InTree, target, @@ -842,7 +890,7 @@ impl Step for Rustc { // If there is any bug, please comment out the next line. cargo.rustdocflag("--generate-link-to-definition"); - compile::rustc_cargo(builder, &mut cargo, target, &compiler, &self.crates); + compile::rustc_cargo(builder, &mut cargo, target, &build_compiler, &self.crates); cargo.arg("-Zskip-rustdoc-fingerprint"); // Only include compiler crates, no dependencies of those, such as `libc`. @@ -857,7 +905,7 @@ impl Step for Rustc { let mut to_open = None; - let out_dir = builder.stage_out(compiler, Mode::Rustc).join(target).join("doc"); + let out_dir = builder.stage_out(build_compiler, Mode::Rustc).join(target).join("doc"); for krate in &*self.crates { // Create all crate output directories first to make sure rustdoc uses // relative links. @@ -879,7 +927,7 @@ impl Step for Rustc { symlink_dir_force(&builder.config, &out, &out_dir); // Cargo puts proc macros in `target/doc` even if you pass `--target` // explicitly (https://github.com/rust-lang/cargo/issues/7677). - let proc_macro_out_dir = builder.stage_out(compiler, Mode::Rustc).join("doc"); + let proc_macro_out_dir = builder.stage_out(build_compiler, Mode::Rustc).join("doc"); symlink_dir_force(&builder.config, &out, &proc_macro_out_dir); cargo.into_cmd().run(builder); @@ -905,7 +953,7 @@ impl Step for Rustc { } fn metadata(&self) -> Option<StepMetadata> { - Some(StepMetadata::doc("rustc", self.target).stage(self.stage)) + Some(StepMetadata::doc("rustc", self.target).built_by(self.build_compiler)) } } @@ -913,12 +961,14 @@ macro_rules! tool_doc { ( $tool: ident, $path: literal, - $(rustc_tool = $rustc_tool:literal, )? + $(rustc_private_tool = $rustc_private_tool:literal, )? $(is_library = $is_library:expr,)? $(crates = $crates:expr)? ) => { #[derive(Debug, Clone, Hash, PartialEq, Eq)] pub struct $tool { + build_compiler: Compiler, + mode: Mode, target: TargetSelection, } @@ -933,15 +983,26 @@ macro_rules! tool_doc { } fn make_run(run: RunConfig<'_>) { - run.builder.ensure($tool { target: run.target }); + let target = run.target; + let (build_compiler, mode) = if true $(&& $rustc_private_tool)? { + // Rustdoc needs the rustc sysroot available to build. + let compilers = RustcPrivateCompilers::new(run.builder, run.builder.top_stage, target); + + // Build rustc docs so that we generate relative links. + run.builder.ensure(Rustc::from_build_compiler(run.builder, compilers.build_compiler(), target)); + + (compilers.build_compiler(), Mode::ToolRustc) + } else { + // bootstrap/host tools have to be documented with the stage 0 compiler + (prepare_doc_compiler(run.builder, target, 1), Mode::ToolBootstrap) + }; + + run.builder.ensure($tool { build_compiler, mode, target }); } - /// Generates compiler documentation. + /// Generates documentation for a tool. /// - /// This will generate all documentation for compiler and dependencies. - /// Compiler documentation is distributed separately, so we make sure - /// we do not merge it with the other documentation from std, test and - /// proc_macros. This is largely just a wrapper around `cargo doc`. + /// This is largely just a wrapper around `cargo doc`. fn run(self, builder: &Builder<'_>) { let mut source_type = SourceType::InTree; @@ -950,31 +1011,17 @@ macro_rules! tool_doc { builder.require_submodule(&submodule_path, None); } - let stage = builder.top_stage; - let target = self.target; + let $tool { build_compiler, mode, target } = self; // This is the intended out directory for compiler documentation. let out = builder.compiler_doc_out(target); t!(fs::create_dir_all(&out)); - let compiler = builder.compiler(stage, builder.config.host_target); - builder.std(compiler, target); - - if true $(&& $rustc_tool)? { - // Build rustc docs so that we generate relative links. - builder.ensure(Rustc::new(stage, target, builder)); - - // Rustdoc needs the rustc sysroot available to build. - // FIXME: is there a way to only ensure `check::Rustc` here? Last time I tried it failed - // with strange errors, but only on a full bors test ... - builder.ensure(compile::Rustc::new(compiler, target)); - } - // Build cargo command. let mut cargo = prepare_tool_cargo( builder, - compiler, - Mode::ToolRustc, + build_compiler, + mode, target, Kind::Doc, $path, @@ -1001,7 +1048,7 @@ macro_rules! tool_doc { cargo.rustdocflag("--show-type-layout"); cargo.rustdocflag("--generate-link-to-definition"); - let out_dir = builder.stage_out(compiler, Mode::ToolRustc).join(target).join("doc"); + let out_dir = builder.stage_out(build_compiler, mode).join(target).join("doc"); $(for krate in $crates { let dir_name = krate.replace("-", "_"); t!(fs::create_dir_all(out_dir.join(&*dir_name))); @@ -1009,10 +1056,10 @@ macro_rules! tool_doc { // Symlink compiler docs to the output directory of rustdoc documentation. symlink_dir_force(&builder.config, &out, &out_dir); - let proc_macro_out_dir = builder.stage_out(compiler, Mode::ToolRustc).join("doc"); + let proc_macro_out_dir = builder.stage_out(build_compiler, mode).join("doc"); symlink_dir_force(&builder.config, &out, &proc_macro_out_dir); - let _guard = builder.msg_doc(compiler, stringify!($tool).to_lowercase(), target); + let _guard = builder.msg(Kind::Doc, stringify!($tool).to_lowercase(), None, build_compiler, target); cargo.into_cmd().run(builder); if !builder.config.dry_run() { @@ -1026,7 +1073,7 @@ macro_rules! tool_doc { } fn metadata(&self) -> Option<StepMetadata> { - Some(StepMetadata::doc(stringify!($tool), self.target)) + Some(StepMetadata::doc(stringify!($tool), self.target).built_by(self.build_compiler)) } } } @@ -1036,7 +1083,7 @@ macro_rules! tool_doc { tool_doc!( BuildHelper, "src/build_helper", - rustc_tool = false, + rustc_private_tool = false, is_library = true, crates = ["build_helper"] ); @@ -1047,7 +1094,7 @@ tool_doc!(Miri, "src/tools/miri", crates = ["miri"]); tool_doc!( Cargo, "src/tools/cargo", - rustc_tool = false, + rustc_private_tool = false, crates = [ "cargo", "cargo-credential", @@ -1061,25 +1108,25 @@ tool_doc!( "rustfix", ] ); -tool_doc!(Tidy, "src/tools/tidy", rustc_tool = false, crates = ["tidy"]); +tool_doc!(Tidy, "src/tools/tidy", rustc_private_tool = false, crates = ["tidy"]); tool_doc!( Bootstrap, "src/bootstrap", - rustc_tool = false, + rustc_private_tool = false, is_library = true, crates = ["bootstrap"] ); tool_doc!( RunMakeSupport, "src/tools/run-make-support", - rustc_tool = false, + rustc_private_tool = false, is_library = true, crates = ["run_make_support"] ); tool_doc!( Compiletest, "src/tools/compiletest", - rustc_tool = false, + rustc_private_tool = false, is_library = true, crates = ["compiletest"] ); @@ -1182,11 +1229,20 @@ fn symlink_dir_force(config: &Config, original: &Path, link: &Path) { ); } +/// Builds the Rust compiler book. #[derive(Ord, PartialOrd, Debug, Clone, Hash, PartialEq, Eq)] pub struct RustcBook { - pub compiler: Compiler, - pub target: TargetSelection, - pub validate: bool, + build_compiler: Compiler, + target: TargetSelection, + /// Test that the examples of lints in the book produce the correct lints in the expected + /// format. + validate: bool, +} + +impl RustcBook { + pub fn validate(build_compiler: Compiler, target: TargetSelection) -> Self { + Self { build_compiler, target, validate: true } + } } impl Step for RustcBook { @@ -1200,8 +1256,17 @@ impl Step for RustcBook { } fn make_run(run: RunConfig<'_>) { + // Bump the stage to 2, because the rustc book requires an in-tree compiler. + // At the same time, since this step is enabled by default, we don't want `x doc` to fail + // in stage 1. + let stage = if run.builder.config.is_explicit_stage() || run.builder.top_stage >= 2 { + run.builder.top_stage + } else { + 2 + }; + run.builder.ensure(RustcBook { - compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.host_target), + build_compiler: prepare_doc_compiler(run.builder, run.target, stage), target: run.target, validate: false, }); @@ -1219,10 +1284,10 @@ impl Step for RustcBook { builder.cp_link_r(&builder.src.join("src/doc/rustc"), &out_base); builder.info(&format!("Generating lint docs ({})", self.target)); - let rustc = builder.rustc(self.compiler); + let rustc = builder.rustc(self.build_compiler); // The tool runs `rustc` for extracting output examples, so it needs a // functional sysroot. - builder.std(self.compiler, self.target); + builder.std(self.build_compiler, self.target); let mut cmd = builder.tool_cmd(Tool::LintDocs); cmd.arg("--src"); cmd.arg(builder.src.join("compiler")); @@ -1248,14 +1313,9 @@ impl Step for RustcBook { // If the lib directories are in an unusual location (changed in // bootstrap.toml), then this needs to explicitly update the dylib search // path. - builder.add_rustc_lib_path(self.compiler, &mut cmd); - let doc_generator_guard = builder.msg( - Kind::Run, - self.compiler.stage, - "lint-docs", - self.compiler.host, - self.target, - ); + builder.add_rustc_lib_path(self.build_compiler, &mut cmd); + let doc_generator_guard = + builder.msg(Kind::Run, "lint-docs", None, self.build_compiler, self.target); cmd.run(builder); drop(doc_generator_guard); @@ -1266,15 +1326,18 @@ impl Step for RustcBook { src: out_base, parent: Some(self), languages: vec![], - rustdoc_compiler: None, + build_compiler: None, }); } } +/// Documents the reference. +/// It has to always be done using a stage 1+ compiler, because it references in-tree +/// compiler/stdlib concepts. #[derive(Ord, PartialOrd, Debug, Clone, Hash, PartialEq, Eq)] pub struct Reference { - pub compiler: Compiler, - pub target: TargetSelection, + build_compiler: Compiler, + target: TargetSelection, } impl Step for Reference { @@ -1287,8 +1350,19 @@ impl Step for Reference { } fn make_run(run: RunConfig<'_>) { + // Bump the stage to 2, because the reference requires an in-tree compiler. + // At the same time, since this step is enabled by default, we don't want `x doc` to fail + // in stage 1. + // FIXME: create a shared method on builder for auto-bumping, and print some warning when + // it happens. + let stage = if run.builder.config.is_explicit_stage() || run.builder.top_stage >= 2 { + run.builder.top_stage + } else { + 2 + }; + run.builder.ensure(Reference { - compiler: run.builder.compiler(run.builder.top_stage, run.builder.config.host_target), + build_compiler: prepare_doc_compiler(run.builder, run.target, stage), target: run.target, }); } @@ -1299,14 +1373,14 @@ impl Step for Reference { // This is needed for generating links to the standard library using // the mdbook-spec plugin. - builder.std(self.compiler, builder.config.host_target); + builder.std(self.build_compiler, builder.config.host_target); // Run rustbook/mdbook to generate the HTML pages. builder.ensure(RustbookSrc { target: self.target, name: "reference".to_owned(), src: builder.src.join("src/doc/reference"), - rustdoc_compiler: Some(self.compiler), + build_compiler: Some(self.build_compiler), parent: Some(self), languages: vec![], }); diff --git a/src/bootstrap/src/core/build_steps/install.rs b/src/bootstrap/src/core/build_steps/install.rs index f628330e9ed..6d09e41e646 100644 --- a/src/bootstrap/src/core/build_steps/install.rs +++ b/src/bootstrap/src/core/build_steps/install.rs @@ -12,7 +12,7 @@ use crate::core::config::{Config, TargetSelection}; use crate::utils::exec::command; use crate::utils::helpers::t; use crate::utils::tarball::GeneratedTarball; -use crate::{CodegenBackendKind, Compiler, Kind}; +use crate::{Compiler, Kind}; #[cfg(target_os = "illumos")] const SHELL: &str = "bash"; @@ -68,7 +68,13 @@ fn install_sh( host: Option<TargetSelection>, tarball: &GeneratedTarball, ) { - let _guard = builder.msg(Kind::Install, stage, package, host, host); + let _guard = builder.msg( + Kind::Install, + package, + None, + (host.unwrap_or(builder.host_target), stage), + host, + ); let prefix = default_path(&builder.config.prefix, "/usr/local"); let sysconfdir = prefix.join(default_path(&builder.config.sysconfdir, "/etc")); @@ -274,9 +280,8 @@ install!((self, builder, _config), install_sh(builder, "rustc", self.compiler.stage, Some(self.target), &tarball); }; RustcCodegenCranelift, alias = "rustc-codegen-cranelift", Self::should_build(_config), only_hosts: true, { - if let Some(tarball) = builder.ensure(dist::CodegenBackend { - compiler: self.compiler, - backend: CodegenBackendKind::Cranelift, + if let Some(tarball) = builder.ensure(dist::CraneliftCodegenBackend { + build_compiler: self.compiler, }) { install_sh(builder, "rustc-codegen-cranelift", self.compiler.stage, Some(self.target), &tarball); } else { diff --git a/src/bootstrap/src/core/build_steps/llvm.rs b/src/bootstrap/src/core/build_steps/llvm.rs index 065a39a4e71..16941a32bb1 100644 --- a/src/bootstrap/src/core/build_steps/llvm.rs +++ b/src/bootstrap/src/core/build_steps/llvm.rs @@ -196,7 +196,10 @@ pub(crate) fn detect_llvm_freshness(config: &Config, is_git: bool) -> PathFreshn /// /// This checks the build triple platform to confirm we're usable at all, and if LLVM /// with/without assertions is available. -pub(crate) fn is_ci_llvm_available_for_target(config: &Config, asserts: bool) -> bool { +pub(crate) fn is_ci_llvm_available_for_target( + host_target: &TargetSelection, + asserts: bool, +) -> bool { // This is currently all tier 1 targets and tier 2 targets with host tools // (since others may not have CI artifacts) // https://doc.rust-lang.org/rustc/platform-support.html#tier-1 @@ -235,8 +238,8 @@ pub(crate) fn is_ci_llvm_available_for_target(config: &Config, asserts: bool) -> ("x86_64-unknown-netbsd", false), ]; - if !supported_platforms.contains(&(&*config.host_target.triple, asserts)) - && (asserts || !supported_platforms.contains(&(&*config.host_target.triple, true))) + if !supported_platforms.contains(&(&*host_target.triple, asserts)) + && (asserts || !supported_platforms.contains(&(&*host_target.triple, true))) { return false; } @@ -421,6 +424,13 @@ impl Step for Llvm { ldflags.shared.push(" -latomic"); } + if target.starts_with("arm64ec") { + // MSVC linker requires the -machine:arm64ec flag to be passed to + // know it's linking as Arm64EC (vs Arm64X). + ldflags.exe.push(" -machine:arm64ec"); + ldflags.shared.push(" -machine:arm64ec"); + } + if target.is_msvc() { cfg.define("CMAKE_MSVC_RUNTIME_LIBRARY", "MultiThreaded"); cfg.static_crt(true); diff --git a/src/bootstrap/src/core/build_steps/test.rs b/src/bootstrap/src/core/build_steps/test.rs index 66332c0b3e8..f1be0af3183 100644 --- a/src/bootstrap/src/core/build_steps/test.rs +++ b/src/bootstrap/src/core/build_steps/test.rs @@ -161,8 +161,7 @@ You can skip linkcheck with --skip src/tools/linkchecker" let linkchecker = builder.tool_cmd(Tool::Linkchecker); // Run the linkchecker. - let _guard = - builder.msg(Kind::Test, compiler.stage, "Linkcheck", bootstrap_host, bootstrap_host); + let _guard = builder.msg(Kind::Test, "Linkcheck", None, compiler, bootstrap_host); let _time = helpers::timeit(builder); linkchecker.delay_failure().arg(builder.out.join(host).join("doc")).run(builder); } @@ -212,10 +211,10 @@ impl Step for HtmlCheck { } // Ensure that a few different kinds of documentation are available. builder.default_doc(&[]); - builder.ensure(crate::core::build_steps::doc::Rustc::new( + builder.ensure(crate::core::build_steps::doc::Rustc::for_stage( + builder, builder.top_stage, self.target, - builder, )); builder @@ -541,8 +540,7 @@ impl Miri { cargo.env("MIRI_SYSROOT", &miri_sysroot); let mut cargo = BootstrapCommand::from(cargo); - let _guard = - builder.msg(Kind::Build, compiler.stage, "miri sysroot", compiler.host, target); + let _guard = builder.msg(Kind::Build, "miri sysroot", Mode::ToolRustc, compiler, target); cargo.run(builder); // # Determine where Miri put its sysroot. @@ -643,7 +641,8 @@ impl Step for Miri { cargo.env("MIRI_TEST_TARGET", target.rustc_target_arg()); { - let _guard = builder.msg_rustc_tool(Kind::Test, stage, "miri", host, target); + let _guard = + builder.msg(Kind::Test, "miri", Mode::ToolRustc, miri.build_compiler, target); let _time = helpers::timeit(builder); cargo.run(builder); } @@ -659,11 +658,11 @@ impl Step for Miri { cargo.args(["tests/pass", "tests/panic"]); { - let _guard = builder.msg_rustc_tool( + let _guard = builder.msg( Kind::Test, - stage, "miri (mir-opt-level 4)", - host, + Mode::ToolRustc, + miri.build_compiler, target, ); let _time = helpers::timeit(builder); @@ -703,7 +702,7 @@ impl Step for CargoMiri { } // This compiler runs on the host, we'll just use it for the target. - let compiler = builder.compiler(stage, host); + let build_compiler = builder.compiler(stage, host); // Run `cargo miri test`. // This is just a smoke test (Miri's own CI invokes this in a bunch of different ways and ensures @@ -711,7 +710,7 @@ impl Step for CargoMiri { // itself executes properly under Miri, and that all the logic in `cargo-miri` does not explode. let mut cargo = tool::prepare_tool_cargo( builder, - compiler, + build_compiler, Mode::ToolStd, // it's unclear what to use here, we're not building anything just doing a smoke test! target, Kind::MiriTest, @@ -736,7 +735,8 @@ impl Step for CargoMiri { // Finally, run everything. let mut cargo = BootstrapCommand::from(cargo); { - let _guard = builder.msg_rustc_tool(Kind::Test, stage, "cargo-miri", host, target); + let _guard = + builder.msg(Kind::Test, "cargo-miri", Mode::ToolRustc, (host, stage), target); let _time = helpers::timeit(builder); cargo.run(builder); } @@ -830,7 +830,7 @@ impl Step for Clippy { /// Runs `cargo test` for clippy. fn run(self, builder: &Builder<'_>) { - let host = self.compilers.target(); + let target = self.compilers.target(); // We need to carefully distinguish the compiler that builds clippy, and the compiler // that is linked into the clippy being tested. `target_compiler` is the latter, @@ -844,7 +844,7 @@ impl Step for Clippy { builder, build_compiler, Mode::ToolRustc, - host, + target, Kind::Test, "src/tools/clippy", SourceType::InTree, @@ -858,7 +858,7 @@ impl Step for Clippy { cargo.env("HOST_LIBS", host_libs); // Build the standard library that the tests can use. - builder.std(target_compiler, host); + builder.std(target_compiler, target); cargo.env("TEST_SYSROOT", builder.sysroot(target_compiler)); cargo.env("TEST_RUSTC", builder.rustc(target_compiler)); cargo.env("TEST_RUSTC_LIB", builder.rustc_libdir(target_compiler)); @@ -881,9 +881,9 @@ impl Step for Clippy { } cargo.add_rustc_lib_path(builder); - let cargo = prepare_cargo_test(cargo, &[], &[], host, builder); + let cargo = prepare_cargo_test(cargo, &[], &[], target, builder); - let _guard = builder.msg_rustc_tool(Kind::Test, build_compiler.stage, "clippy", host, host); + let _guard = builder.msg(Kind::Test, "clippy", Mode::ToolRustc, build_compiler, target); // Clippy reports errors if it blessed the outputs if cargo.allow_failure().run(builder) { @@ -983,16 +983,16 @@ impl Step for RustdocJSStd { command.arg("--test-file").arg(path); } } - builder.ensure(crate::core::build_steps::doc::Std::new( - builder.top_stage, + builder.ensure(crate::core::build_steps::doc::Std::from_build_compiler( + builder.compiler(builder.top_stage, builder.host_target), self.target, DocumentationFormat::Html, )); let _guard = builder.msg( Kind::Test, - builder.top_stage, "rustdoc-js-std", - builder.config.host_target, + None, + (builder.config.host_target, builder.top_stage), self.target, ); command.run(builder); @@ -1141,13 +1141,7 @@ impl Step for RustdocGUI { } let _time = helpers::timeit(builder); - let _guard = builder.msg_rustc_tool( - Kind::Test, - self.compiler.stage, - "rustdoc-gui", - self.compiler.host, - self.target, - ); + let _guard = builder.msg(Kind::Test, "rustdoc-gui", None, self.compiler, self.target); try_run_tests(builder, &mut cmd, true); } } @@ -2237,9 +2231,10 @@ NOTE: if you're sure you want to do this, please open an issue as to why. In the let _group = builder.msg( Kind::Test, - compiler.stage, format!("compiletest suite={suite} mode={mode}"), - compiler.host, + // FIXME: compiletest sometimes behaves as ToolStd, we could expose that difference here + Mode::ToolBootstrap, + compiler, target, ); try_run_tests(builder, &mut cmd, false); @@ -2381,9 +2376,9 @@ impl BookTest { builder.add_rust_test_threads(&mut rustbook_cmd); let _guard = builder.msg( Kind::Test, - compiler.stage, format_args!("mdbook {}", self.path.display()), - compiler.host, + None, + compiler, compiler.host, ); let _time = helpers::timeit(builder); @@ -2402,8 +2397,7 @@ impl BookTest { builder.std(compiler, host); - let _guard = - builder.msg(Kind::Test, compiler.stage, format!("book {}", self.name), host, host); + let _guard = builder.msg(Kind::Test, format!("book {}", self.name), None, compiler, host); // Do a breadth-first traversal of the `src/doc` directory and just run // tests for all files that end in `*.md` @@ -2547,9 +2541,9 @@ impl Step for ErrorIndex { let guard = builder.msg( Kind::Test, - target_compiler.stage, "error-index", - target_compiler.host, + None, + self.compilers.build_compiler(), target_compiler.host, ); let _time = helpers::timeit(builder); @@ -2650,9 +2644,8 @@ fn run_cargo_test<'a>( let compiler = cargo.compiler(); let mut cargo = prepare_cargo_test(cargo, libtest_args, crates, target, builder); let _time = helpers::timeit(builder); - let _group = description.into().and_then(|what| { - builder.msg_rustc_tool(Kind::Test, compiler.stage, what, compiler.host, target) - }); + let _group = + description.into().and_then(|what| builder.msg(Kind::Test, what, None, compiler, target)); #[cfg(feature = "build-metrics")] builder.metrics.begin_test_suite( @@ -3176,8 +3169,9 @@ impl Step for Bootstrap { /// Tests the build system itself. fn run(self, builder: &Builder<'_>) { let host = builder.config.host_target; - let compiler = builder.compiler(0, host); - let _guard = builder.msg(Kind::Test, 0, "bootstrap", host, host); + let build_compiler = builder.compiler(0, host); + let _guard = + builder.msg(Kind::Test, "bootstrap", Mode::ToolBootstrap, build_compiler, host); // Some tests require cargo submodule to be present. builder.build.require_submodule("src/tools/cargo", None); @@ -3196,7 +3190,7 @@ impl Step for Bootstrap { let mut cargo = tool::prepare_tool_cargo( builder, - compiler, + build_compiler, Mode::ToolBootstrap, host, Kind::Test, @@ -3276,9 +3270,9 @@ impl Step for TierCheck { let _guard = builder.msg( Kind::Test, - self.compiler.stage, "platform support check", - self.compiler.host, + None, + self.compiler, self.compiler.host, ); BootstrapCommand::from(cargo).delay_failure().run(builder); @@ -3310,11 +3304,8 @@ impl Step for LintDocs { /// Tests that the lint examples in the rustc book generate the correct /// lints and have the expected format. fn run(self, builder: &Builder<'_>) { - builder.ensure(crate::core::build_steps::doc::RustcBook { - compiler: self.compiler, - target: self.target, - validate: true, - }); + builder + .ensure(crate::core::build_steps::doc::RustcBook::validate(self.compiler, self.target)); } } @@ -3329,10 +3320,10 @@ impl Step for RustInstaller { /// Ensure the version placeholder replacement tool builds fn run(self, builder: &Builder<'_>) { let bootstrap_host = builder.config.host_target; - let compiler = builder.compiler(0, bootstrap_host); + let build_compiler = builder.compiler(0, bootstrap_host); let cargo = tool::prepare_tool_cargo( builder, - compiler, + build_compiler, Mode::ToolBootstrap, bootstrap_host, Kind::Test, @@ -3341,13 +3332,8 @@ impl Step for RustInstaller { &[], ); - let _guard = builder.msg( - Kind::Test, - compiler.stage, - "rust-installer", - bootstrap_host, - bootstrap_host, - ); + let _guard = + builder.msg(Kind::Test, "rust-installer", None, build_compiler, bootstrap_host); run_cargo_test(cargo, &[], &[], None, bootstrap_host, builder); // We currently don't support running the test.sh script outside linux(?) environments. @@ -3358,7 +3344,7 @@ impl Step for RustInstaller { } let mut cmd = command(builder.src.join("src/tools/rust-installer/test.sh")); - let tmpdir = testdir(builder, compiler.host).join("rust-installer"); + let tmpdir = testdir(builder, build_compiler.host).join("rust-installer"); let _ = std::fs::remove_dir_all(&tmpdir); let _ = std::fs::create_dir_all(&tmpdir); cmd.current_dir(&tmpdir); @@ -3478,7 +3464,11 @@ impl Step for CodegenCranelift { return; } - if !builder.config.codegen_backends(run.target).contains(&CodegenBackendKind::Cranelift) { + if !builder + .config + .enabled_codegen_backends(run.target) + .contains(&CodegenBackendKind::Cranelift) + { builder.info("cranelift not in rust.codegen-backends. skipping"); return; } @@ -3605,7 +3595,7 @@ impl Step for CodegenGCC { return; } - if !builder.config.codegen_backends(run.target).contains(&CodegenBackendKind::Gcc) { + if !builder.config.enabled_codegen_backends(run.target).contains(&CodegenBackendKind::Gcc) { builder.info("gcc not in rust.codegen-backends. skipping"); return; } diff --git a/src/bootstrap/src/core/build_steps/tool.rs b/src/bootstrap/src/core/build_steps/tool.rs index aa00cd03c5b..793e6b629c9 100644 --- a/src/bootstrap/src/core/build_steps/tool.rs +++ b/src/bootstrap/src/core/build_steps/tool.rs @@ -26,7 +26,7 @@ use crate::core::builder::{ use crate::core::config::{DebuginfoLevel, RustcLto, TargetSelection}; use crate::utils::exec::{BootstrapCommand, command}; use crate::utils::helpers::{add_dylib_path, exe, t}; -use crate::{Compiler, FileType, Kind, Mode, gha}; +use crate::{Compiler, FileType, Kind, Mode}; #[derive(Debug, Clone, Hash, PartialEq, Eq)] pub enum SourceType { @@ -58,28 +58,6 @@ struct ToolBuild { artifact_kind: ToolArtifactKind, } -impl Builder<'_> { - #[track_caller] - pub(crate) fn msg_tool( - &self, - kind: Kind, - mode: Mode, - tool: &str, - build_stage: u32, - host: &TargetSelection, - target: &TargetSelection, - ) -> Option<gha::Group> { - match mode { - // depends on compiler stage, different to host compiler - Mode::ToolRustc => { - self.msg_rustc_tool(kind, build_stage, format_args!("tool {tool}"), *host, *target) - } - // doesn't depend on compiler, same as host compiler - _ => self.msg(kind, build_stage, format_args!("tool {tool}"), *host, *target), - } - } -} - /// Result of the tool build process. Each `Step` in this module is responsible /// for using this type as `type Output = ToolBuildResult;` #[derive(Clone)] @@ -166,14 +144,8 @@ impl Step for ToolBuild { cargo.args(self.cargo_args); - let _guard = builder.msg_tool( - Kind::Build, - self.mode, - self.tool, - self.build_compiler.stage, - &self.build_compiler.host, - &self.target, - ); + let _guard = + builder.msg(Kind::Build, self.tool, self.mode, self.build_compiler, self.target); // we check this below let build_success = compile::stream_cargo(builder, cargo, vec![], &mut |_| {}); @@ -380,13 +352,13 @@ pub(crate) fn get_tool_target_compiler( /// tools directory. fn copy_link_tool_bin( builder: &Builder<'_>, - compiler: Compiler, + build_compiler: Compiler, target: TargetSelection, mode: Mode, name: &str, ) -> PathBuf { - let cargo_out = builder.cargo_out(compiler, mode, target).join(exe(name, target)); - let bin = builder.tools_dir(compiler).join(exe(name, target)); + let cargo_out = builder.cargo_out(build_compiler, mode, target).join(exe(name, target)); + let bin = builder.tools_dir(build_compiler).join(exe(name, target)); builder.copy_link(&cargo_out, &bin, FileType::Executable); bin } @@ -857,7 +829,9 @@ impl Step for Cargo { fn run(self, builder: &Builder<'_>) -> ToolBuildResult { builder.build.require_submodule("src/tools/cargo", None); + builder.std(self.build_compiler, builder.host_target); builder.std(self.build_compiler, self.target); + builder.ensure(ToolBuild { build_compiler: self.build_compiler, target: self.target, diff --git a/src/bootstrap/src/core/builder/cargo.rs b/src/bootstrap/src/core/builder/cargo.rs index e10af2b55f9..757b9277ec6 100644 --- a/src/bootstrap/src/core/builder/cargo.rs +++ b/src/bootstrap/src/core/builder/cargo.rs @@ -433,6 +433,15 @@ impl Builder<'_> { let out_dir = self.stage_out(compiler, mode); cargo.env("CARGO_TARGET_DIR", &out_dir); + // Bootstrap makes a lot of assumptions about the artifacts produced in the target + // directory. If users override the "build directory" using `build-dir` + // (https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#build-dir), then + // bootstrap couldn't find these artifacts. So we forcefully override that option to our + // target directory here. + // In the future, we could attempt to read the build-dir location from Cargo and actually + // respect it. + cargo.env("CARGO_BUILD_BUILD_DIR", &out_dir); + // Found with `rg "init_env_logger\("`. If anyone uses `init_env_logger` // from out of tree it shouldn't matter, since x.py is only used for // building in-tree. @@ -493,7 +502,9 @@ impl Builder<'_> { if cmd_kind == Kind::Doc { let my_out = match mode { // This is the intended out directory for compiler documentation. - Mode::Rustc | Mode::ToolRustc => self.compiler_doc_out(target), + Mode::Rustc | Mode::ToolRustc | Mode::ToolBootstrap => { + self.compiler_doc_out(target) + } Mode::Std => { if self.config.cmd.json() { out_dir.join(target).join("json-doc") diff --git a/src/bootstrap/src/core/builder/mod.rs b/src/bootstrap/src/core/builder/mod.rs index e15941938f1..de4b941ac90 100644 --- a/src/bootstrap/src/core/builder/mod.rs +++ b/src/bootstrap/src/core/builder/mod.rs @@ -959,7 +959,8 @@ impl<'a> Builder<'a> { compile::Std, compile::Rustc, compile::Assemble, - compile::CodegenBackend, + compile::CraneliftCodegenBackend, + compile::GccCodegenBackend, compile::StartupObjects, tool::BuildManifest, tool::Rustbook, @@ -1150,7 +1151,7 @@ impl<'a> Builder<'a> { dist::JsonDocs, dist::Mingw, dist::Rustc, - dist::CodegenBackend, + dist::CraneliftCodegenBackend, dist::Std, dist::RustcDev, dist::Analysis, @@ -1596,7 +1597,7 @@ You have to build a stage1 compiler for `{}` first, and then use it to build a s cmd.env("CARGO", &self.initial_cargo); // Need to add the `run_compiler` libs. Those are the libs produces *by* `build_compiler` // in `tool::ToolBuild` step, so they match the Miri we just built. However this means they - // are actually living one stage up, i.e. we are running `stage0-tools-bin/miri` with the + // are actually living one stage up, i.e. we are running `stage1-tools-bin/miri` with the // libraries in `stage1/lib`. This is an unfortunate off-by-1 caused (possibly) by the fact // that Miri doesn't have an "assemble" step like rustc does that would cross the stage boundary. // We can't use `add_rustc_lib_path` as that's a NOP on Windows but we do need these libraries diff --git a/src/bootstrap/src/core/builder/tests.rs b/src/bootstrap/src/core/builder/tests.rs index 1914e24fa35..32d191c4265 100644 --- a/src/bootstrap/src/core/builder/tests.rs +++ b/src/bootstrap/src/core/builder/tests.rs @@ -742,6 +742,21 @@ mod snapshot { } #[test] + fn build_compiler_lld_opt_in() { + with_lld_opt_in_targets(vec![host_target()], || { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx.config("build") + .path("compiler") + .render_steps(), @r" + [build] llvm <host> + [build] rustc 0 <host> -> rustc 1 <host> + [build] rustc 0 <host> -> LldWrapper 1 <host> + "); + }); + } + + #[test] fn build_library_no_explicit_stage() { let ctx = TestCtx::new(); insta::assert_snapshot!( @@ -939,7 +954,7 @@ mod snapshot { [build] llvm <host> [build] rustc 0 <host> -> rustc 1 <host> [build] rustdoc 1 <host> - [doc] std 1 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] + [doc] rustc 1 <host> -> std 1 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] "); } @@ -1008,19 +1023,36 @@ mod snapshot { .render_steps(), @r" [build] rustc 0 <host> -> UnstableBookGen 1 <host> [build] rustc 0 <host> -> Rustbook 1 <host> + [doc] unstable-book (book) <host> [build] llvm <host> [build] rustc 0 <host> -> rustc 1 <host> [build] rustc 1 <host> -> std 1 <host> + [doc] book (book) <host> + [doc] book/first-edition (book) <host> + [doc] book/second-edition (book) <host> + [doc] book/2018-edition (book) <host> + [build] rustdoc 1 <host> + [doc] rustc 1 <host> -> standalone 2 <host> [build] rustc 1 <host> -> rustc 2 <host> [build] rustdoc 2 <host> - [doc] std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] + [doc] rustc 2 <host> -> std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] [build] rustc 1 <host> -> error-index 2 <host> [doc] rustc 1 <host> -> error-index 2 <host> - [build] rustc 2 <host> -> std 2 <host> + [doc] nomicon (book) <host> + [doc] rustc 1 <host> -> reference (book) 2 <host> + [doc] rustdoc (book) <host> + [doc] rust-by-example (book) <host> [build] rustc 0 <host> -> LintDocs 1 <host> + [doc] rustc (book) <host> + [doc] cargo (book) <host> + [doc] clippy (book) <host> + [doc] embedded-book (book) <host> + [doc] edition-guide (book) <host> + [doc] style-guide (book) <host> + [doc] rustc 1 <host> -> releases 2 <host> [build] rustc 0 <host> -> RustInstaller 1 <host> [dist] docs <host> - [doc] std 2 <host> crates=[] + [doc] rustc 2 <host> -> std 2 <host> crates=[] [dist] mingw <host> [build] rustc 0 <host> -> GenerateCopyright 1 <host> [dist] rustc <host> @@ -1046,25 +1078,42 @@ mod snapshot { .render_steps(), @r" [build] rustc 0 <host> -> UnstableBookGen 1 <host> [build] rustc 0 <host> -> Rustbook 1 <host> + [doc] unstable-book (book) <host> [build] llvm <host> [build] rustc 0 <host> -> rustc 1 <host> [build] rustc 0 <host> -> LldWrapper 1 <host> [build] rustc 0 <host> -> WasmComponentLd 1 <host> [build] rustc 0 <host> -> LlvmBitcodeLinker 1 <host> [build] rustc 1 <host> -> std 1 <host> + [doc] book (book) <host> + [doc] book/first-edition (book) <host> + [doc] book/second-edition (book) <host> + [doc] book/2018-edition (book) <host> + [build] rustdoc 1 <host> + [doc] rustc 1 <host> -> standalone 2 <host> [build] rustc 1 <host> -> rustc 2 <host> [build] rustc 1 <host> -> LldWrapper 2 <host> [build] rustc 1 <host> -> WasmComponentLd 2 <host> [build] rustc 1 <host> -> LlvmBitcodeLinker 2 <host> [build] rustdoc 2 <host> - [doc] std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] + [doc] rustc 2 <host> -> std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] [build] rustc 1 <host> -> error-index 2 <host> [doc] rustc 1 <host> -> error-index 2 <host> - [build] rustc 2 <host> -> std 2 <host> + [doc] nomicon (book) <host> + [doc] rustc 1 <host> -> reference (book) 2 <host> + [doc] rustdoc (book) <host> + [doc] rust-by-example (book) <host> [build] rustc 0 <host> -> LintDocs 1 <host> + [doc] rustc (book) <host> + [doc] cargo (book) <host> + [doc] clippy (book) <host> + [doc] embedded-book (book) <host> + [doc] edition-guide (book) <host> + [doc] style-guide (book) <host> + [doc] rustc 1 <host> -> releases 2 <host> [build] rustc 0 <host> -> RustInstaller 1 <host> [dist] docs <host> - [doc] std 2 <host> crates=[] + [doc] rustc 2 <host> -> std 2 <host> crates=[] [dist] mingw <host> [build] rustc 1 <host> -> rust-analyzer-proc-macro-srv 2 <host> [build] rustc 0 <host> -> GenerateCopyright 1 <host> @@ -1093,22 +1142,56 @@ mod snapshot { .render_steps(), @r" [build] rustc 0 <host> -> UnstableBookGen 1 <host> [build] rustc 0 <host> -> Rustbook 1 <host> + [doc] unstable-book (book) <host> + [doc] unstable-book (book) <target1> [build] llvm <host> [build] rustc 0 <host> -> rustc 1 <host> [build] rustc 1 <host> -> std 1 <host> + [doc] book (book) <host> + [doc] book/first-edition (book) <host> + [doc] book/second-edition (book) <host> + [doc] book/2018-edition (book) <host> + [build] rustdoc 1 <host> + [build] rustc 1 <host> -> std 1 <target1> + [doc] book (book) <target1> + [doc] book/first-edition (book) <target1> + [doc] book/second-edition (book) <target1> + [doc] book/2018-edition (book) <target1> + [doc] rustc 1 <host> -> standalone 2 <host> + [doc] rustc 1 <host> -> standalone 2 <target1> [build] rustc 1 <host> -> rustc 2 <host> [build] rustdoc 2 <host> - [doc] std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] - [doc] std 2 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] + [doc] rustc 2 <host> -> std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] + [doc] rustc 2 <host> -> std 2 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] [build] rustc 1 <host> -> error-index 2 <host> [doc] rustc 1 <host> -> error-index 2 <host> - [build] rustc 2 <host> -> std 2 <host> + [doc] nomicon (book) <host> + [doc] nomicon (book) <target1> + [doc] rustc 1 <host> -> reference (book) 2 <host> + [doc] rustc 1 <host> -> reference (book) 2 <target1> + [doc] rustdoc (book) <host> + [doc] rustdoc (book) <target1> + [doc] rust-by-example (book) <host> + [doc] rust-by-example (book) <target1> [build] rustc 0 <host> -> LintDocs 1 <host> + [doc] rustc (book) <host> + [doc] cargo (book) <host> + [doc] cargo (book) <target1> + [doc] clippy (book) <host> + [doc] clippy (book) <target1> + [doc] embedded-book (book) <host> + [doc] embedded-book (book) <target1> + [doc] edition-guide (book) <host> + [doc] edition-guide (book) <target1> + [doc] style-guide (book) <host> + [doc] style-guide (book) <target1> + [doc] rustc 1 <host> -> releases 2 <host> + [doc] rustc 1 <host> -> releases 2 <target1> [build] rustc 0 <host> -> RustInstaller 1 <host> [dist] docs <host> [dist] docs <target1> - [doc] std 2 <host> crates=[] - [doc] std 2 <target1> crates=[] + [doc] rustc 2 <host> -> std 2 <host> crates=[] + [doc] rustc 2 <host> -> std 2 <target1> crates=[] [dist] mingw <host> [dist] mingw <target1> [build] rustc 0 <host> -> GenerateCopyright 1 <host> @@ -1132,12 +1215,19 @@ mod snapshot { .render_steps(), @r" [build] rustc 0 <host> -> UnstableBookGen 1 <host> [build] rustc 0 <host> -> Rustbook 1 <host> + [doc] unstable-book (book) <host> [build] llvm <host> [build] rustc 0 <host> -> rustc 1 <host> [build] rustc 1 <host> -> std 1 <host> + [doc] book (book) <host> + [doc] book/first-edition (book) <host> + [doc] book/second-edition (book) <host> + [doc] book/2018-edition (book) <host> + [build] rustdoc 1 <host> + [doc] rustc 1 <host> -> standalone 2 <host> [build] rustc 1 <host> -> rustc 2 <host> [build] rustdoc 2 <host> - [doc] std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] + [doc] rustc 2 <host> -> std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] [build] rustc 1 <host> -> error-index 2 <host> [doc] rustc 1 <host> -> error-index 2 <host> [build] llvm <target1> @@ -1145,12 +1235,22 @@ mod snapshot { [build] rustc 1 <host> -> rustc 2 <target1> [build] rustc 1 <host> -> error-index 2 <target1> [doc] rustc 1 <host> -> error-index 2 <target1> - [build] rustc 2 <host> -> std 2 <host> + [doc] nomicon (book) <host> + [doc] rustc 1 <host> -> reference (book) 2 <host> + [doc] rustdoc (book) <host> + [doc] rust-by-example (book) <host> [build] rustc 0 <host> -> LintDocs 1 <host> - [build] rustc 2 <host> -> std 2 <target1> + [doc] rustc (book) <host> + [doc] rustc (book) <target1> + [doc] cargo (book) <host> + [doc] clippy (book) <host> + [doc] embedded-book (book) <host> + [doc] edition-guide (book) <host> + [doc] style-guide (book) <host> + [doc] rustc 1 <host> -> releases 2 <host> [build] rustc 0 <host> -> RustInstaller 1 <host> [dist] docs <host> - [doc] std 2 <host> crates=[] + [doc] rustc 2 <host> -> std 2 <host> crates=[] [dist] mingw <host> [build] rustc 0 <host> -> GenerateCopyright 1 <host> [dist] rustc <host> @@ -1173,28 +1273,61 @@ mod snapshot { .render_steps(), @r" [build] rustc 0 <host> -> UnstableBookGen 1 <host> [build] rustc 0 <host> -> Rustbook 1 <host> + [doc] unstable-book (book) <host> + [doc] unstable-book (book) <target1> [build] llvm <host> [build] rustc 0 <host> -> rustc 1 <host> [build] rustc 1 <host> -> std 1 <host> + [doc] book (book) <host> + [doc] book/first-edition (book) <host> + [doc] book/second-edition (book) <host> + [doc] book/2018-edition (book) <host> + [build] rustdoc 1 <host> + [build] rustc 1 <host> -> std 1 <target1> + [doc] book (book) <target1> + [doc] book/first-edition (book) <target1> + [doc] book/second-edition (book) <target1> + [doc] book/2018-edition (book) <target1> + [doc] rustc 1 <host> -> standalone 2 <host> + [doc] rustc 1 <host> -> standalone 2 <target1> [build] rustc 1 <host> -> rustc 2 <host> [build] rustdoc 2 <host> - [doc] std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] - [doc] std 2 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] + [doc] rustc 2 <host> -> std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] + [doc] rustc 2 <host> -> std 2 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] [build] rustc 1 <host> -> error-index 2 <host> [doc] rustc 1 <host> -> error-index 2 <host> [build] llvm <target1> - [build] rustc 1 <host> -> std 1 <target1> [build] rustc 1 <host> -> rustc 2 <target1> [build] rustc 1 <host> -> error-index 2 <target1> [doc] rustc 1 <host> -> error-index 2 <target1> - [build] rustc 2 <host> -> std 2 <host> + [doc] nomicon (book) <host> + [doc] nomicon (book) <target1> + [doc] rustc 1 <host> -> reference (book) 2 <host> + [doc] rustc 1 <host> -> reference (book) 2 <target1> + [doc] rustdoc (book) <host> + [doc] rustdoc (book) <target1> + [doc] rust-by-example (book) <host> + [doc] rust-by-example (book) <target1> [build] rustc 0 <host> -> LintDocs 1 <host> - [build] rustc 2 <host> -> std 2 <target1> + [doc] rustc (book) <host> + [doc] rustc (book) <target1> + [doc] cargo (book) <host> + [doc] cargo (book) <target1> + [doc] clippy (book) <host> + [doc] clippy (book) <target1> + [doc] embedded-book (book) <host> + [doc] embedded-book (book) <target1> + [doc] edition-guide (book) <host> + [doc] edition-guide (book) <target1> + [doc] style-guide (book) <host> + [doc] style-guide (book) <target1> + [doc] rustc 1 <host> -> releases 2 <host> + [doc] rustc 1 <host> -> releases 2 <target1> [build] rustc 0 <host> -> RustInstaller 1 <host> [dist] docs <host> [dist] docs <target1> - [doc] std 2 <host> crates=[] - [doc] std 2 <target1> crates=[] + [doc] rustc 2 <host> -> std 2 <host> crates=[] + [doc] rustc 2 <host> -> std 2 <target1> crates=[] [dist] mingw <host> [dist] mingw <target1> [build] rustc 0 <host> -> GenerateCopyright 1 <host> @@ -1219,16 +1352,33 @@ mod snapshot { .render_steps(), @r" [build] rustc 0 <host> -> UnstableBookGen 1 <host> [build] rustc 0 <host> -> Rustbook 1 <host> + [doc] unstable-book (book) <target1> [build] llvm <host> [build] rustc 0 <host> -> rustc 1 <host> + [build] rustc 1 <host> -> std 1 <target1> + [doc] book (book) <target1> + [doc] book/first-edition (book) <target1> + [doc] book/second-edition (book) <target1> + [doc] book/2018-edition (book) <target1> + [build] rustdoc 1 <host> [build] rustc 1 <host> -> std 1 <host> + [doc] rustc 1 <host> -> standalone 2 <target1> [build] rustc 1 <host> -> rustc 2 <host> [build] rustdoc 2 <host> - [doc] std 2 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] - [build] rustc 2 <host> -> std 2 <host> + [doc] rustc 2 <host> -> std 2 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] + [doc] nomicon (book) <target1> + [doc] rustc 1 <host> -> reference (book) 2 <target1> + [doc] rustdoc (book) <target1> + [doc] rust-by-example (book) <target1> + [doc] cargo (book) <target1> + [doc] clippy (book) <target1> + [doc] embedded-book (book) <target1> + [doc] edition-guide (book) <target1> + [doc] style-guide (book) <target1> + [doc] rustc 1 <host> -> releases 2 <target1> [build] rustc 0 <host> -> RustInstaller 1 <host> [dist] docs <target1> - [doc] std 2 <target1> crates=[] + [doc] rustc 2 <host> -> std 2 <target1> crates=[] [dist] mingw <target1> [build] rustc 2 <host> -> std 2 <target1> [dist] rustc 2 <host> -> std 2 <target1> @@ -1249,26 +1399,42 @@ mod snapshot { .render_steps(), @r" [build] rustc 0 <host> -> UnstableBookGen 1 <host> [build] rustc 0 <host> -> Rustbook 1 <host> + [doc] unstable-book (book) <target1> [build] llvm <host> [build] rustc 0 <host> -> rustc 1 <host> [build] rustc 0 <host> -> WasmComponentLd 1 <host> + [build] rustc 1 <host> -> std 1 <target1> + [doc] book (book) <target1> + [doc] book/first-edition (book) <target1> + [doc] book/second-edition (book) <target1> + [doc] book/2018-edition (book) <target1> + [build] rustdoc 1 <host> [build] rustc 1 <host> -> std 1 <host> + [doc] rustc 1 <host> -> standalone 2 <target1> [build] rustc 1 <host> -> rustc 2 <host> [build] rustc 1 <host> -> WasmComponentLd 2 <host> [build] rustdoc 2 <host> - [doc] std 2 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] + [doc] rustc 2 <host> -> std 2 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] [build] llvm <target1> - [build] rustc 1 <host> -> std 1 <target1> [build] rustc 1 <host> -> rustc 2 <target1> [build] rustc 1 <host> -> WasmComponentLd 2 <target1> [build] rustc 1 <host> -> error-index 2 <target1> [doc] rustc 1 <host> -> error-index 2 <target1> - [build] rustc 2 <host> -> std 2 <host> - [build] rustc 2 <host> -> std 2 <target1> + [doc] nomicon (book) <target1> + [doc] rustc 1 <host> -> reference (book) 2 <target1> + [doc] rustdoc (book) <target1> + [doc] rust-by-example (book) <target1> [build] rustc 0 <host> -> LintDocs 1 <host> + [doc] rustc (book) <target1> + [doc] cargo (book) <target1> + [doc] clippy (book) <target1> + [doc] embedded-book (book) <target1> + [doc] edition-guide (book) <target1> + [doc] style-guide (book) <target1> + [doc] rustc 1 <host> -> releases 2 <target1> [build] rustc 0 <host> -> RustInstaller 1 <host> [dist] docs <target1> - [doc] std 2 <target1> crates=[] + [doc] rustc 2 <host> -> std 2 <target1> crates=[] [dist] mingw <target1> [build] rustdoc 2 <target1> [build] rustc 1 <host> -> rust-analyzer-proc-macro-srv 2 <target1> @@ -1285,6 +1451,60 @@ mod snapshot { [build] rustc 1 <host> -> miri 2 <target1> [build] rustc 1 <host> -> cargo-miri 2 <target1> [build] rustc 1 <host> -> LlvmBitcodeLinker 2 <target1> + [doc] rustc 2 <target1> -> std 2 <target1> crates=[] + "); + } + + // Enable dist cranelift tarball by default with `x dist` if cranelift is enabled in + // `rust.codegen-backends`. + #[test] + fn dist_cranelift_by_default() { + let ctx = TestCtx::new(); + insta::assert_snapshot!( + ctx + .config("dist") + .args(&["--set", "rust.codegen-backends=['llvm', 'cranelift']"]) + .render_steps(), @r" + [build] rustc 0 <host> -> UnstableBookGen 1 <host> + [build] rustc 0 <host> -> Rustbook 1 <host> + [doc] unstable-book (book) <host> + [build] llvm <host> + [build] rustc 0 <host> -> rustc 1 <host> + [build] rustc 0 <host> -> rustc_codegen_cranelift 1 <host> + [build] rustc 1 <host> -> std 1 <host> + [doc] book (book) <host> + [doc] book/first-edition (book) <host> + [doc] book/second-edition (book) <host> + [doc] book/2018-edition (book) <host> + [build] rustdoc 1 <host> + [doc] rustc 1 <host> -> standalone 2 <host> + [build] rustc 1 <host> -> rustc 2 <host> + [build] rustc 1 <host> -> rustc_codegen_cranelift 2 <host> + [build] rustdoc 2 <host> + [doc] rustc 2 <host> -> std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] + [build] rustc 1 <host> -> error-index 2 <host> + [doc] rustc 1 <host> -> error-index 2 <host> + [doc] nomicon (book) <host> + [doc] rustc 1 <host> -> reference (book) 2 <host> + [doc] rustdoc (book) <host> + [doc] rust-by-example (book) <host> + [build] rustc 0 <host> -> LintDocs 1 <host> + [doc] rustc (book) <host> + [doc] cargo (book) <host> + [doc] clippy (book) <host> + [doc] embedded-book (book) <host> + [doc] edition-guide (book) <host> + [doc] style-guide (book) <host> + [doc] rustc 1 <host> -> releases 2 <host> + [build] rustc 0 <host> -> RustInstaller 1 <host> + [dist] docs <host> + [doc] rustc 2 <host> -> std 2 <host> crates=[] + [dist] mingw <host> + [build] rustc 0 <host> -> GenerateCopyright 1 <host> + [dist] rustc <host> + [dist] rustc 1 <host> -> rustc_codegen_cranelift 2 <host> + [dist] rustc 1 <host> -> std 1 <host> + [dist] src <> "); } @@ -1657,14 +1877,32 @@ mod snapshot { .render_steps(), @r" [build] rustc 0 <host> -> UnstableBookGen 1 <host> [build] rustc 0 <host> -> Rustbook 1 <host> + [doc] unstable-book (book) <host> + [doc] book (book) <host> + [doc] book/first-edition (book) <host> + [doc] book/second-edition (book) <host> + [doc] book/2018-edition (book) <host> + [build] rustdoc 0 <host> + [doc] rustc 0 <host> -> standalone 1 <host> [build] llvm <host> [build] rustc 0 <host> -> rustc 1 <host> [build] rustdoc 1 <host> - [doc] std 1 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] + [doc] rustc 1 <host> -> std 1 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] [build] rustc 0 <host> -> error-index 1 <host> [doc] rustc 0 <host> -> error-index 1 <host> + [doc] nomicon (book) <host> [build] rustc 1 <host> -> std 1 <host> + [doc] rustc 1 <host> -> reference (book) 2 <host> + [doc] rustdoc (book) <host> + [doc] rust-by-example (book) <host> [build] rustc 0 <host> -> LintDocs 1 <host> + [doc] rustc (book) <host> + [doc] cargo (book) <host> + [doc] clippy (book) <host> + [doc] embedded-book (book) <host> + [doc] edition-guide (book) <host> + [doc] style-guide (book) <host> + [doc] rustc 0 <host> -> releases 1 <host> "); } @@ -1678,7 +1916,7 @@ mod snapshot { [build] llvm <host> [build] rustc 0 <host> -> rustc 1 <host> [build] rustdoc 1 <host> - [doc] std 1 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] + [doc] rustc 1 <host> -> std 1 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind] "); } @@ -1692,7 +1930,7 @@ mod snapshot { [build] llvm <host> [build] rustc 0 <host> -> rustc 1 <host> [build] rustdoc 1 <host> - [doc] std 1 <host> crates=[core] + [doc] rustc 1 <host> -> std 1 <host> crates=[core] "); } @@ -1707,26 +1945,11 @@ mod snapshot { [build] llvm <host> [build] rustc 0 <host> -> rustc 1 <host> [build] rustdoc 1 <host> - [doc] std 1 <host> crates=[core] + [doc] rustc 1 <host> -> std 1 <host> crates=[core] "); } #[test] - fn test_lld_opt_in() { - with_lld_opt_in_targets(vec![host_target()], || { - let ctx = TestCtx::new(); - insta::assert_snapshot!( - ctx.config("build") - .path("compiler") - .render_steps(), @r" - [build] llvm <host> - [build] rustc 0 <host> -> rustc 1 <host> - [build] rustc 0 <host> -> LldWrapper 1 <host> - "); - }); - } - - #[test] fn doc_library_no_std_target() { let ctx = TestCtx::new(); insta::assert_snapshot!( @@ -1737,7 +1960,7 @@ mod snapshot { [build] llvm <host> [build] rustc 0 <host> -> rustc 1 <host> [build] rustdoc 1 <host> - [doc] std 1 <host> crates=[alloc,core] + [doc] rustc 1 <host> -> std 1 <host> crates=[alloc,core] "); } @@ -1753,22 +1976,15 @@ mod snapshot { [build] llvm <host> [build] rustc 0 <host> -> rustc 1 <host> [build] rustdoc 1 <host> - [doc] std 1 <target1> crates=[alloc,core] + [doc] rustc 1 <host> -> std 1 <target1> crates=[alloc,core] "); } #[test] + #[should_panic] fn doc_compiler_stage_0() { let ctx = TestCtx::new(); - insta::assert_snapshot!( - ctx.config("doc") - .path("compiler") - .stage(0) - .render_steps(), @r" - [build] rustdoc 0 <host> - [build] llvm <host> - [doc] rustc 0 <host> - "); + ctx.config("doc").path("compiler").stage(0).run(); } #[test] @@ -1779,11 +1995,9 @@ mod snapshot { .path("compiler") .stage(1) .render_steps(), @r" + [build] rustdoc 0 <host> [build] llvm <host> - [build] rustc 0 <host> -> rustc 1 <host> - [build] rustc 1 <host> -> std 1 <host> - [build] rustdoc 1 <host> - [doc] rustc 1 <host> + [doc] rustc 0 <host> -> rustc 1 <host> "); } @@ -1798,57 +2012,57 @@ mod snapshot { [build] llvm <host> [build] rustc 0 <host> -> rustc 1 <host> [build] rustc 1 <host> -> std 1 <host> - [build] rustc 1 <host> -> rustc 2 <host> - [build] rustc 2 <host> -> std 2 <host> - [build] rustdoc 2 <host> - [doc] rustc 2 <host> + [build] rustdoc 1 <host> + [doc] rustc 1 <host> -> rustc 2 <host> "); } #[test] + #[should_panic] fn doc_compiletest_stage_0() { let ctx = TestCtx::new(); + ctx.config("doc").path("src/tools/compiletest").stage(0).run(); + } + + #[test] + fn doc_compiletest_stage_1() { + let ctx = TestCtx::new(); insta::assert_snapshot!( ctx.config("doc") .path("src/tools/compiletest") - .stage(0) + .stage(1) .render_steps(), @r" [build] rustdoc 0 <host> - [doc] Compiletest <host> + [doc] rustc 0 <host> -> Compiletest 1 <host> "); } #[test] - fn doc_compiletest_stage_1() { + fn doc_compiletest_stage_2() { let ctx = TestCtx::new(); insta::assert_snapshot!( ctx.config("doc") .path("src/tools/compiletest") - .stage(1) + .stage(2) .render_steps(), @r" - [build] llvm <host> - [build] rustc 0 <host> -> rustc 1 <host> - [build] rustc 1 <host> -> std 1 <host> - [build] rustdoc 1 <host> - [doc] Compiletest <host> + [build] rustdoc 0 <host> + [doc] rustc 0 <host> -> Compiletest 1 <host> "); } + // Reference should be auto-bumped to stage 2. #[test] - fn doc_compiletest_stage_2() { + fn doc_reference() { let ctx = TestCtx::new(); insta::assert_snapshot!( ctx.config("doc") - .path("src/tools/compiletest") - .stage(2) + .path("reference") .render_steps(), @r" [build] llvm <host> [build] rustc 0 <host> -> rustc 1 <host> [build] rustc 1 <host> -> std 1 <host> - [build] rustc 1 <host> -> rustc 2 <host> - [build] rustc 2 <host> -> std 2 <host> - [build] rustdoc 2 <host> - [doc] Compiletest <host> + [build] rustc 0 <host> -> Rustbook 1 <host> + [doc] rustc 1 <host> -> reference (book) 2 <host> "); } } diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs index 2c008f957d9..a656927b1f6 100644 --- a/src/bootstrap/src/core/config/config.rs +++ b/src/bootstrap/src/core/config/config.rs @@ -893,21 +893,25 @@ impl Config { let default = config.channel == "dev"; config.omit_git_hash = rust_omit_git_hash.unwrap_or(default); - config.rust_info = config.git_info(config.omit_git_hash, &config.src); + config.rust_info = git_info(&config.exec_ctx, config.omit_git_hash, &config.src); config.cargo_info = - config.git_info(config.omit_git_hash, &config.src.join("src/tools/cargo")); - config.rust_analyzer_info = - config.git_info(config.omit_git_hash, &config.src.join("src/tools/rust-analyzer")); + git_info(&config.exec_ctx, config.omit_git_hash, &config.src.join("src/tools/cargo")); + config.rust_analyzer_info = git_info( + &config.exec_ctx, + config.omit_git_hash, + &config.src.join("src/tools/rust-analyzer"), + ); config.clippy_info = - config.git_info(config.omit_git_hash, &config.src.join("src/tools/clippy")); + git_info(&config.exec_ctx, config.omit_git_hash, &config.src.join("src/tools/clippy")); config.miri_info = - config.git_info(config.omit_git_hash, &config.src.join("src/tools/miri")); + git_info(&config.exec_ctx, config.omit_git_hash, &config.src.join("src/tools/miri")); config.rustfmt_info = - config.git_info(config.omit_git_hash, &config.src.join("src/tools/rustfmt")); + git_info(&config.exec_ctx, config.omit_git_hash, &config.src.join("src/tools/rustfmt")); config.enzyme_info = - config.git_info(config.omit_git_hash, &config.src.join("src/tools/enzyme")); - config.in_tree_llvm_info = config.git_info(false, &config.src.join("src/llvm-project")); - config.in_tree_gcc_info = config.git_info(false, &config.src.join("src/gcc")); + git_info(&config.exec_ctx, config.omit_git_hash, &config.src.join("src/tools/enzyme")); + config.in_tree_llvm_info = + git_info(&config.exec_ctx, false, &config.src.join("src/llvm-project")); + config.in_tree_gcc_info = git_info(&config.exec_ctx, false, &config.src.join("src/gcc")); config.vendor = build_vendor.unwrap_or( config.rust_info.is_from_tarball() @@ -947,11 +951,18 @@ impl Config { ); } - config.download_rustc_commit = config.download_ci_rustc_commit( - rust_download_rustc, - debug_assertions_requested, - config.llvm_assertions, - ); + let dwn_ctx = DownloadContext::from(&config); + config.download_rustc_commit = + download_ci_rustc_commit(dwn_ctx, rust_download_rustc, config.llvm_assertions); + + if debug_assertions_requested && config.download_rustc_commit.is_some() { + eprintln!( + "WARN: `rust.debug-assertions = true` will prevent downloading CI rustc as alt CI \ + rustc is not currently built with debug assertions." + ); + // We need to put this later down_ci_rustc_commit. + config.download_rustc_commit = None; + } if let Some(t) = toml.target { for (triple, cfg) in t { @@ -1157,8 +1168,9 @@ impl Config { "WARNING: `rust.download-rustc` is enabled. The `rust.channel` option will be overridden by the CI rustc's channel." ); + let dwn_ctx = DownloadContext::from(&config); let channel = - config.read_file_by_commit(Path::new("src/ci/channel"), commit).trim().to_owned(); + read_file_by_commit(dwn_ctx, Path::new("src/ci/channel"), commit).trim().to_owned(); config.channel = channel; } @@ -1193,8 +1205,9 @@ impl Config { config.llvm_enable_warnings = llvm_enable_warnings.unwrap_or(false); config.llvm_build_config = llvm_build_config.clone().unwrap_or(Default::default()); + let dwn_ctx = DownloadContext::from(&config); config.llvm_from_ci = - config.parse_download_ci_llvm(llvm_download_ci_llvm, config.llvm_assertions); + parse_download_ci_llvm(dwn_ctx, llvm_download_ci_llvm, config.llvm_assertions); if config.llvm_from_ci { let warn = |option: &str| { @@ -1256,7 +1269,8 @@ impl Config { if config.llvm_from_ci { let triple = &config.host_target.triple; - let ci_llvm_bin = config.ci_llvm_root().join("bin"); + let dwn_ctx = DownloadContext::from(&config); + let ci_llvm_bin = ci_llvm_root(dwn_ctx).join("bin"); let build_target = config .target_config .entry(config.host_target) @@ -1297,7 +1311,8 @@ impl Config { ); } - if config.lld_enabled && config.is_system_llvm(config.host_target) { + let dwn_ctx = DownloadContext::from(&config); + if config.lld_enabled && is_system_llvm(dwn_ctx, config.host_target) { panic!("Cannot enable LLD with `rust.lld = true` when using external llvm-config."); } @@ -1349,11 +1364,15 @@ impl Config { // Now check that the selected stage makes sense, and if not, print a warning and end match (config.stage, &config.cmd) { (0, Subcommand::Build) => { - eprintln!("WARNING: cannot build anything on stage 0. Use at least stage 1."); + eprintln!("ERROR: cannot build anything on stage 0. Use at least stage 1."); exit!(1); } (0, Subcommand::Check { .. }) => { - eprintln!("WARNING: cannot check anything on stage 0. Use at least stage 1."); + eprintln!("ERROR: cannot check anything on stage 0. Use at least stage 1."); + exit!(1); + } + (0, Subcommand::Doc { .. }) => { + eprintln!("ERROR: cannot document anything on stage 0. Use at least stage 1."); exit!(1); } _ => {} @@ -1432,14 +1451,8 @@ impl Config { /// Returns the content of the given file at a specific commit. pub(crate) fn read_file_by_commit(&self, file: &Path, commit: &str) -> String { - assert!( - self.rust_info.is_managed_git_subrepository(), - "`Config::read_file_by_commit` is not supported in non-git sources." - ); - - let mut git = helpers::git(Some(&self.src)); - git.arg("show").arg(format!("{commit}:{}", file.to_str().unwrap())); - git.run_capture_stdout(self).stdout() + let dwn_ctx = DownloadContext::from(self); + read_file_by_commit(dwn_ctx, file, commit) } /// Bootstrap embeds a version number into the name of shared libraries it uploads in CI. @@ -1510,8 +1523,8 @@ impl Config { /// The absolute path to the downloaded LLVM artifacts. pub(crate) fn ci_llvm_root(&self) -> PathBuf { - assert!(self.llvm_from_ci); - self.out.join(self.host_target).join("ci-llvm") + let dwn_ctx = DownloadContext::from(self); + ci_llvm_root(dwn_ctx) } /// Directory where the extracted `rustc-dev` component is stored. @@ -1674,261 +1687,14 @@ impl Config { ), )] pub(crate) fn update_submodule(&self, relative_path: &str) { - if self.rust_info.is_from_tarball() || !self.submodules() { - return; - } - - let absolute_path = self.src.join(relative_path); - - // NOTE: This check is required because `jj git clone` doesn't create directories for - // submodules, they are completely ignored. The code below assumes this directory exists, - // so create it here. - if !absolute_path.exists() { - t!(fs::create_dir_all(&absolute_path)); - } - - // NOTE: The check for the empty directory is here because when running x.py the first time, - // the submodule won't be checked out. Check it out now so we can build it. - if !self.git_info(false, &absolute_path).is_managed_git_subrepository() - && !helpers::dir_is_empty(&absolute_path) - { - return; - } - - // Submodule updating actually happens during in the dry run mode. We need to make sure that - // all the git commands below are actually executed, because some follow-up code - // in bootstrap might depend on the submodules being checked out. Furthermore, not all - // the command executions below work with an empty output (produced during dry run). - // Therefore, all commands below are marked with `run_in_dry_run()`, so that they also run in - // dry run mode. - let submodule_git = || { - let mut cmd = helpers::git(Some(&absolute_path)); - cmd.run_in_dry_run(); - cmd - }; - - // Determine commit checked out in submodule. - let checked_out_hash = - submodule_git().args(["rev-parse", "HEAD"]).run_capture_stdout(self).stdout(); - let checked_out_hash = checked_out_hash.trim_end(); - // Determine commit that the submodule *should* have. - let recorded = helpers::git(Some(&self.src)) - .run_in_dry_run() - .args(["ls-tree", "HEAD"]) - .arg(relative_path) - .run_capture_stdout(self) - .stdout(); - - let actual_hash = recorded - .split_whitespace() - .nth(2) - .unwrap_or_else(|| panic!("unexpected output `{recorded}`")); - - if actual_hash == checked_out_hash { - // already checked out - return; - } - - println!("Updating submodule {relative_path}"); - - helpers::git(Some(&self.src)) - .allow_failure() - .run_in_dry_run() - .args(["submodule", "-q", "sync"]) - .arg(relative_path) - .run(self); - - // Try passing `--progress` to start, then run git again without if that fails. - let update = |progress: bool| { - // Git is buggy and will try to fetch submodules from the tracking branch for *this* repository, - // even though that has no relation to the upstream for the submodule. - let current_branch = helpers::git(Some(&self.src)) - .allow_failure() - .run_in_dry_run() - .args(["symbolic-ref", "--short", "HEAD"]) - .run_capture(self); - - let mut git = helpers::git(Some(&self.src)).allow_failure(); - git.run_in_dry_run(); - if current_branch.is_success() { - // If there is a tag named after the current branch, git will try to disambiguate by prepending `heads/` to the branch name. - // This syntax isn't accepted by `branch.{branch}`. Strip it. - let branch = current_branch.stdout(); - let branch = branch.trim(); - let branch = branch.strip_prefix("heads/").unwrap_or(branch); - git.arg("-c").arg(format!("branch.{branch}.remote=origin")); - } - git.args(["submodule", "update", "--init", "--recursive", "--depth=1"]); - if progress { - git.arg("--progress"); - } - git.arg(relative_path); - git - }; - if !update(true).allow_failure().run(self) { - update(false).allow_failure().run(self); - } - - // Save any local changes, but avoid running `git stash pop` if there are none (since it will exit with an error). - // diff-index reports the modifications through the exit status - let has_local_modifications = - !submodule_git().allow_failure().args(["diff-index", "--quiet", "HEAD"]).run(self); - if has_local_modifications { - submodule_git().allow_failure().args(["stash", "push"]).run(self); - } - - submodule_git().allow_failure().args(["reset", "-q", "--hard"]).run(self); - submodule_git().allow_failure().args(["clean", "-qdfx"]).run(self); - - if has_local_modifications { - submodule_git().allow_failure().args(["stash", "pop"]).run(self); - } - } - - /// Returns the commit to download, or `None` if we shouldn't download CI artifacts. - pub fn download_ci_rustc_commit( - &self, - download_rustc: Option<StringOrBool>, - debug_assertions_requested: bool, - llvm_assertions: bool, - ) -> Option<String> { - if !is_download_ci_available(&self.host_target.triple, llvm_assertions) { - return None; - } - - // If `download-rustc` is not set, default to rebuilding. - let if_unchanged = match download_rustc { - // Globally default `download-rustc` to `false`, because some contributors don't use - // profiles for reasons such as: - // - They need to seamlessly switch between compiler/library work. - // - They don't want to use compiler profile because they need to override too many - // things and it's easier to not use a profile. - None | Some(StringOrBool::Bool(false)) => return None, - Some(StringOrBool::Bool(true)) => false, - Some(StringOrBool::String(s)) if s == "if-unchanged" => { - if !self.rust_info.is_managed_git_subrepository() { - println!( - "ERROR: `download-rustc=if-unchanged` is only compatible with Git managed sources." - ); - crate::exit!(1); - } - - true - } - Some(StringOrBool::String(other)) => { - panic!("unrecognized option for download-rustc: {other}") - } - }; - - let commit = if self.rust_info.is_managed_git_subrepository() { - // Look for a version to compare to based on the current commit. - // Only commits merged by bors will have CI artifacts. - let freshness = self.check_path_modifications(RUSTC_IF_UNCHANGED_ALLOWED_PATHS); - self.verbose(|| { - eprintln!("rustc freshness: {freshness:?}"); - }); - match freshness { - PathFreshness::LastModifiedUpstream { upstream } => upstream, - PathFreshness::HasLocalModifications { upstream } => { - if if_unchanged { - return None; - } - - if self.is_running_on_ci { - eprintln!("CI rustc commit matches with HEAD and we are in CI."); - eprintln!( - "`rustc.download-ci` functionality will be skipped as artifacts are not available." - ); - return None; - } - - upstream - } - PathFreshness::MissingUpstream => { - eprintln!("No upstream commit found"); - return None; - } - } - } else { - channel::read_commit_info_file(&self.src) - .map(|info| info.sha.trim().to_owned()) - .expect("git-commit-info is missing in the project root") - }; - - if debug_assertions_requested { - eprintln!( - "WARN: `rust.debug-assertions = true` will prevent downloading CI rustc as alt CI \ - rustc is not currently built with debug assertions." - ); - return None; - } - - Some(commit) - } - - pub fn parse_download_ci_llvm( - &self, - download_ci_llvm: Option<StringOrBool>, - asserts: bool, - ) -> bool { - // We don't ever want to use `true` on CI, as we should not - // download upstream artifacts if there are any local modifications. - let default = if self.is_running_on_ci { - StringOrBool::String("if-unchanged".to_string()) - } else { - StringOrBool::Bool(true) - }; - let download_ci_llvm = download_ci_llvm.unwrap_or(default); - - let if_unchanged = || { - if self.rust_info.is_from_tarball() { - // Git is needed for running "if-unchanged" logic. - println!("ERROR: 'if-unchanged' is only compatible with Git managed sources."); - crate::exit!(1); - } - - // Fetching the LLVM submodule is unnecessary for self-tests. - #[cfg(not(test))] - self.update_submodule("src/llvm-project"); - - // Check for untracked changes in `src/llvm-project` and other important places. - let has_changes = self.has_changes_from_upstream(LLVM_INVALIDATION_PATHS); - - // Return false if there are untracked changes, otherwise check if CI LLVM is available. - if has_changes { false } else { llvm::is_ci_llvm_available_for_target(self, asserts) } - }; - - match download_ci_llvm { - StringOrBool::Bool(b) => { - if !b && self.download_rustc_commit.is_some() { - panic!( - "`llvm.download-ci-llvm` cannot be set to `false` if `rust.download-rustc` is set to `true` or `if-unchanged`." - ); - } - - if b && self.is_running_on_ci { - // On CI, we must always rebuild LLVM if there were any modifications to it - panic!( - "`llvm.download-ci-llvm` cannot be set to `true` on CI. Use `if-unchanged` instead." - ); - } - - // If download-ci-llvm=true we also want to check that CI llvm is available - b && llvm::is_ci_llvm_available_for_target(self, asserts) - } - StringOrBool::String(s) if s == "if-unchanged" => if_unchanged(), - StringOrBool::String(other) => { - panic!("unrecognized option for download-ci-llvm: {other:?}") - } - } + let dwn_ctx = DownloadContext::from(self); + update_submodule(dwn_ctx, relative_path); } /// Returns true if any of the `paths` have been modified locally. pub fn has_changes_from_upstream(&self, paths: &[&'static str]) -> bool { - match self.check_path_modifications(paths) { - PathFreshness::LastModifiedUpstream { .. } => false, - PathFreshness::HasLocalModifications { .. } | PathFreshness::MissingUpstream => true, - } + let dwn_ctx = DownloadContext::from(self); + has_changes_from_upstream(dwn_ctx, paths) } /// Checks whether any of the given paths have been modified w.r.t. upstream. @@ -1949,10 +1715,6 @@ impl Config { .clone() } - pub fn ci_env(&self) -> CiEnv { - if self.is_running_on_ci { CiEnv::GitHubActions } else { CiEnv::None } - } - pub fn sanitizers_enabled(&self, target: TargetSelection) -> bool { self.target_config.get(&target).and_then(|t| t.sanitizers).unwrap_or(self.sanitizers) } @@ -1977,19 +1739,24 @@ impl Config { .unwrap_or(self.profiler) } - pub fn codegen_backends(&self, target: TargetSelection) -> &[CodegenBackendKind] { + /// Returns codegen backends that should be: + /// - Built and added to the sysroot when we build the compiler. + /// - Distributed when `x dist` is executed (if the codegen backend has a dist step). + pub fn enabled_codegen_backends(&self, target: TargetSelection) -> &[CodegenBackendKind] { self.target_config .get(&target) .and_then(|cfg| cfg.codegen_backends.as_deref()) .unwrap_or(&self.rust_codegen_backends) } - pub fn jemalloc(&self, target: TargetSelection) -> bool { - self.target_config.get(&target).and_then(|cfg| cfg.jemalloc).unwrap_or(self.jemalloc) + /// Returns the codegen backend that should be configured as the *default* codegen backend + /// for a rustc compiled by bootstrap. + pub fn default_codegen_backend(&self, target: TargetSelection) -> Option<CodegenBackendKind> { + self.enabled_codegen_backends(target).first().cloned() } - pub fn default_codegen_backend(&self, target: TargetSelection) -> Option<CodegenBackendKind> { - self.codegen_backends(target).first().cloned() + pub fn jemalloc(&self, target: TargetSelection) -> bool { + self.target_config.get(&target).and_then(|cfg| cfg.jemalloc).unwrap_or(self.jemalloc) } pub fn rpath_enabled(&self, target: TargetSelection) -> bool { @@ -2004,7 +1771,7 @@ impl Config { } pub fn llvm_enabled(&self, target: TargetSelection) -> bool { - self.codegen_backends(target).contains(&CodegenBackendKind::Llvm) + self.enabled_codegen_backends(target).contains(&CodegenBackendKind::Llvm) } pub fn llvm_libunwind(&self, target: TargetSelection) -> LlvmLibunwind { @@ -2036,15 +1803,8 @@ impl Config { /// /// NOTE: this is not the same as `!is_rust_llvm` when `llvm_has_patches` is set. pub fn is_system_llvm(&self, target: TargetSelection) -> bool { - match self.target_config.get(&target) { - Some(Target { llvm_config: Some(_), .. }) => { - let ci_llvm = self.llvm_from_ci && self.is_host_target(target); - !ci_llvm - } - // We're building from the in-tree src/llvm-project sources. - Some(Target { llvm_config: None, .. }) => false, - None => false, - } + let dwn_ctx = DownloadContext::from(self); + is_system_llvm(dwn_ctx, target) } /// Returns `true` if this is our custom, patched, version of LLVM. @@ -2335,3 +2095,365 @@ pub fn check_stage0_version( )); } } + +pub fn download_ci_rustc_commit<'a>( + dwn_ctx: impl AsRef<DownloadContext<'a>>, + download_rustc: Option<StringOrBool>, + llvm_assertions: bool, +) -> Option<String> { + let dwn_ctx = dwn_ctx.as_ref(); + + if !is_download_ci_available(&dwn_ctx.host_target.triple, llvm_assertions) { + return None; + } + + // If `download-rustc` is not set, default to rebuilding. + let if_unchanged = match download_rustc { + // Globally default `download-rustc` to `false`, because some contributors don't use + // profiles for reasons such as: + // - They need to seamlessly switch between compiler/library work. + // - They don't want to use compiler profile because they need to override too many + // things and it's easier to not use a profile. + None | Some(StringOrBool::Bool(false)) => return None, + Some(StringOrBool::Bool(true)) => false, + Some(StringOrBool::String(s)) if s == "if-unchanged" => { + if !dwn_ctx.rust_info.is_managed_git_subrepository() { + println!( + "ERROR: `download-rustc=if-unchanged` is only compatible with Git managed sources." + ); + crate::exit!(1); + } + + true + } + Some(StringOrBool::String(other)) => { + panic!("unrecognized option for download-rustc: {other}") + } + }; + + let commit = if dwn_ctx.rust_info.is_managed_git_subrepository() { + // Look for a version to compare to based on the current commit. + // Only commits merged by bors will have CI artifacts. + let freshness = check_path_modifications_(dwn_ctx, RUSTC_IF_UNCHANGED_ALLOWED_PATHS); + dwn_ctx.exec_ctx.verbose(|| { + eprintln!("rustc freshness: {freshness:?}"); + }); + match freshness { + PathFreshness::LastModifiedUpstream { upstream } => upstream, + PathFreshness::HasLocalModifications { upstream } => { + if if_unchanged { + return None; + } + + if dwn_ctx.is_running_on_ci { + eprintln!("CI rustc commit matches with HEAD and we are in CI."); + eprintln!( + "`rustc.download-ci` functionality will be skipped as artifacts are not available." + ); + return None; + } + + upstream + } + PathFreshness::MissingUpstream => { + eprintln!("No upstream commit found"); + return None; + } + } + } else { + channel::read_commit_info_file(dwn_ctx.src) + .map(|info| info.sha.trim().to_owned()) + .expect("git-commit-info is missing in the project root") + }; + + Some(commit) +} + +pub fn check_path_modifications_<'a>( + dwn_ctx: impl AsRef<DownloadContext<'a>>, + paths: &[&'static str], +) -> PathFreshness { + let dwn_ctx = dwn_ctx.as_ref(); + // Checking path modifications through git can be relatively expensive (>100ms). + // We do not assume that the sources would change during bootstrap's execution, + // so we can cache the results here. + // Note that we do not use a static variable for the cache, because it would cause problems + // in tests that create separate `Config` instsances. + dwn_ctx + .path_modification_cache + .lock() + .unwrap() + .entry(paths.to_vec()) + .or_insert_with(|| { + check_path_modifications( + dwn_ctx.src, + &git_config(dwn_ctx.stage0_metadata), + paths, + CiEnv::current(), + ) + .unwrap() + }) + .clone() +} + +pub fn git_config(stage0_metadata: &build_helper::stage0_parser::Stage0) -> GitConfig<'_> { + GitConfig { + nightly_branch: &stage0_metadata.config.nightly_branch, + git_merge_commit_email: &stage0_metadata.config.git_merge_commit_email, + } +} + +pub fn parse_download_ci_llvm<'a>( + dwn_ctx: impl AsRef<DownloadContext<'a>>, + download_ci_llvm: Option<StringOrBool>, + asserts: bool, +) -> bool { + let dwn_ctx = dwn_ctx.as_ref(); + + // We don't ever want to use `true` on CI, as we should not + // download upstream artifacts if there are any local modifications. + let default = if dwn_ctx.is_running_on_ci { + StringOrBool::String("if-unchanged".to_string()) + } else { + StringOrBool::Bool(true) + }; + let download_ci_llvm = download_ci_llvm.unwrap_or(default); + + let if_unchanged = || { + if dwn_ctx.rust_info.is_from_tarball() { + // Git is needed for running "if-unchanged" logic. + println!("ERROR: 'if-unchanged' is only compatible with Git managed sources."); + crate::exit!(1); + } + + // Fetching the LLVM submodule is unnecessary for self-tests. + #[cfg(not(test))] + update_submodule(dwn_ctx, "src/llvm-project"); + + // Check for untracked changes in `src/llvm-project` and other important places. + let has_changes = has_changes_from_upstream(dwn_ctx, LLVM_INVALIDATION_PATHS); + + // Return false if there are untracked changes, otherwise check if CI LLVM is available. + if has_changes { + false + } else { + llvm::is_ci_llvm_available_for_target(&dwn_ctx.host_target, asserts) + } + }; + + match download_ci_llvm { + StringOrBool::Bool(b) => { + if !b && dwn_ctx.download_rustc_commit.is_some() { + panic!( + "`llvm.download-ci-llvm` cannot be set to `false` if `rust.download-rustc` is set to `true` or `if-unchanged`." + ); + } + + if b && dwn_ctx.is_running_on_ci { + // On CI, we must always rebuild LLVM if there were any modifications to it + panic!( + "`llvm.download-ci-llvm` cannot be set to `true` on CI. Use `if-unchanged` instead." + ); + } + + // If download-ci-llvm=true we also want to check that CI llvm is available + b && llvm::is_ci_llvm_available_for_target(&dwn_ctx.host_target, asserts) + } + StringOrBool::String(s) if s == "if-unchanged" => if_unchanged(), + StringOrBool::String(other) => { + panic!("unrecognized option for download-ci-llvm: {other:?}") + } + } +} + +pub fn has_changes_from_upstream<'a>( + dwn_ctx: impl AsRef<DownloadContext<'a>>, + paths: &[&'static str], +) -> bool { + let dwn_ctx = dwn_ctx.as_ref(); + match check_path_modifications_(dwn_ctx, paths) { + PathFreshness::LastModifiedUpstream { .. } => false, + PathFreshness::HasLocalModifications { .. } | PathFreshness::MissingUpstream => true, + } +} + +#[cfg_attr( + feature = "tracing", + instrument( + level = "trace", + name = "Config::update_submodule", + skip_all, + fields(relative_path = ?relative_path), + ), +)] +pub(crate) fn update_submodule<'a>(dwn_ctx: impl AsRef<DownloadContext<'a>>, relative_path: &str) { + let dwn_ctx = dwn_ctx.as_ref(); + if dwn_ctx.rust_info.is_from_tarball() || !submodules_(dwn_ctx.submodules, dwn_ctx.rust_info) { + return; + } + + let absolute_path = dwn_ctx.src.join(relative_path); + + // NOTE: This check is required because `jj git clone` doesn't create directories for + // submodules, they are completely ignored. The code below assumes this directory exists, + // so create it here. + if !absolute_path.exists() { + t!(fs::create_dir_all(&absolute_path)); + } + + // NOTE: The check for the empty directory is here because when running x.py the first time, + // the submodule won't be checked out. Check it out now so we can build it. + if !git_info(dwn_ctx.exec_ctx, false, &absolute_path).is_managed_git_subrepository() + && !helpers::dir_is_empty(&absolute_path) + { + return; + } + + // Submodule updating actually happens during in the dry run mode. We need to make sure that + // all the git commands below are actually executed, because some follow-up code + // in bootstrap might depend on the submodules being checked out. Furthermore, not all + // the command executions below work with an empty output (produced during dry run). + // Therefore, all commands below are marked with `run_in_dry_run()`, so that they also run in + // dry run mode. + let submodule_git = || { + let mut cmd = helpers::git(Some(&absolute_path)); + cmd.run_in_dry_run(); + cmd + }; + + // Determine commit checked out in submodule. + let checked_out_hash = + submodule_git().args(["rev-parse", "HEAD"]).run_capture_stdout(dwn_ctx.exec_ctx).stdout(); + let checked_out_hash = checked_out_hash.trim_end(); + // Determine commit that the submodule *should* have. + let recorded = helpers::git(Some(dwn_ctx.src)) + .run_in_dry_run() + .args(["ls-tree", "HEAD"]) + .arg(relative_path) + .run_capture_stdout(dwn_ctx.exec_ctx) + .stdout(); + + let actual_hash = recorded + .split_whitespace() + .nth(2) + .unwrap_or_else(|| panic!("unexpected output `{recorded}`")); + + if actual_hash == checked_out_hash { + // already checked out + return; + } + + println!("Updating submodule {relative_path}"); + + helpers::git(Some(dwn_ctx.src)) + .allow_failure() + .run_in_dry_run() + .args(["submodule", "-q", "sync"]) + .arg(relative_path) + .run(dwn_ctx.exec_ctx); + + // Try passing `--progress` to start, then run git again without if that fails. + let update = |progress: bool| { + // Git is buggy and will try to fetch submodules from the tracking branch for *this* repository, + // even though that has no relation to the upstream for the submodule. + let current_branch = helpers::git(Some(dwn_ctx.src)) + .allow_failure() + .run_in_dry_run() + .args(["symbolic-ref", "--short", "HEAD"]) + .run_capture(dwn_ctx.exec_ctx); + + let mut git = helpers::git(Some(dwn_ctx.src)).allow_failure(); + git.run_in_dry_run(); + if current_branch.is_success() { + // If there is a tag named after the current branch, git will try to disambiguate by prepending `heads/` to the branch name. + // This syntax isn't accepted by `branch.{branch}`. Strip it. + let branch = current_branch.stdout(); + let branch = branch.trim(); + let branch = branch.strip_prefix("heads/").unwrap_or(branch); + git.arg("-c").arg(format!("branch.{branch}.remote=origin")); + } + git.args(["submodule", "update", "--init", "--recursive", "--depth=1"]); + if progress { + git.arg("--progress"); + } + git.arg(relative_path); + git + }; + if !update(true).allow_failure().run(dwn_ctx.exec_ctx) { + update(false).allow_failure().run(dwn_ctx.exec_ctx); + } + + // Save any local changes, but avoid running `git stash pop` if there are none (since it will exit with an error). + // diff-index reports the modifications through the exit status + let has_local_modifications = !submodule_git() + .allow_failure() + .args(["diff-index", "--quiet", "HEAD"]) + .run(dwn_ctx.exec_ctx); + if has_local_modifications { + submodule_git().allow_failure().args(["stash", "push"]).run(dwn_ctx.exec_ctx); + } + + submodule_git().allow_failure().args(["reset", "-q", "--hard"]).run(dwn_ctx.exec_ctx); + submodule_git().allow_failure().args(["clean", "-qdfx"]).run(dwn_ctx.exec_ctx); + + if has_local_modifications { + submodule_git().allow_failure().args(["stash", "pop"]).run(dwn_ctx.exec_ctx); + } +} + +pub fn git_info(exec_ctx: &ExecutionContext, omit_git_hash: bool, dir: &Path) -> GitInfo { + GitInfo::new(omit_git_hash, dir, exec_ctx) +} + +pub fn submodules_(submodules: &Option<bool>, rust_info: &channel::GitInfo) -> bool { + // If not specified in config, the default is to only manage + // submodules if we're currently inside a git repository. + submodules.unwrap_or(rust_info.is_managed_git_subrepository()) +} + +/// Returns `true` if this is an external version of LLVM not managed by bootstrap. +/// In particular, we expect llvm sources to be available when this is false. +/// +/// NOTE: this is not the same as `!is_rust_llvm` when `llvm_has_patches` is set. +pub fn is_system_llvm<'a>( + dwn_ctx: impl AsRef<DownloadContext<'a>>, + target: TargetSelection, +) -> bool { + let dwn_ctx = dwn_ctx.as_ref(); + match dwn_ctx.target_config.get(&target) { + Some(Target { llvm_config: Some(_), .. }) => { + let ci_llvm = dwn_ctx.llvm_from_ci && is_host_target(&dwn_ctx.host_target, &target); + !ci_llvm + } + // We're building from the in-tree src/llvm-project sources. + Some(Target { llvm_config: None, .. }) => false, + None => false, + } +} + +pub fn is_host_target(host_target: &TargetSelection, target: &TargetSelection) -> bool { + host_target == target +} + +pub(crate) fn ci_llvm_root<'a>(dwn_ctx: impl AsRef<DownloadContext<'a>>) -> PathBuf { + let dwn_ctx = dwn_ctx.as_ref(); + assert!(dwn_ctx.llvm_from_ci); + dwn_ctx.out.join(dwn_ctx.host_target).join("ci-llvm") +} + +/// Returns the content of the given file at a specific commit. +pub(crate) fn read_file_by_commit<'a>( + dwn_ctx: impl AsRef<DownloadContext<'a>>, + file: &Path, + commit: &str, +) -> String { + let dwn_ctx = dwn_ctx.as_ref(); + assert!( + dwn_ctx.rust_info.is_managed_git_subrepository(), + "`Config::read_file_by_commit` is not supported in non-git sources." + ); + + let mut git = helpers::git(Some(dwn_ctx.src)); + git.arg("show").arg(format!("{commit}:{}", file.to_str().unwrap())); + git.run_capture_stdout(dwn_ctx.exec_ctx).stdout() +} diff --git a/src/bootstrap/src/core/config/toml/rust.rs b/src/bootstrap/src/core/config/toml/rust.rs index b95fb236fa1..3dab8d1d96d 100644 --- a/src/bootstrap/src/core/config/toml/rust.rs +++ b/src/bootstrap/src/core/config/toml/rust.rs @@ -3,7 +3,6 @@ use serde::{Deserialize, Deserializer}; -use crate::core::build_steps::compile::CODEGEN_BACKEND_PREFIX; use crate::core::config::toml::TomlConfig; use crate::core::config::{DebuginfoLevel, Merge, ReplaceOpt, StringOrBool}; use crate::{BTreeSet, CodegenBackendKind, HashSet, PathBuf, TargetSelection, define_config, exit}; @@ -391,6 +390,8 @@ pub(crate) fn parse_codegen_backends( backends: Vec<String>, section: &str, ) -> Vec<CodegenBackendKind> { + const CODEGEN_BACKEND_PREFIX: &str = "rustc_codegen_"; + let mut found_backends = vec![]; for backend in &backends { if let Some(stripped) = backend.strip_prefix(CODEGEN_BACKEND_PREFIX) { diff --git a/src/bootstrap/src/core/download.rs b/src/bootstrap/src/core/download.rs index 7ec6c62a07d..5ded44cef14 100644 --- a/src/bootstrap/src/core/download.rs +++ b/src/bootstrap/src/core/download.rs @@ -1,14 +1,17 @@ +use std::collections::HashMap; use std::env; use std::ffi::OsString; use std::fs::{self, File}; use std::io::{BufRead, BufReader, BufWriter, ErrorKind, Write}; use std::path::{Path, PathBuf}; -use std::sync::OnceLock; +use std::sync::{Arc, Mutex, OnceLock}; +use build_helper::git::PathFreshness; use xz2::bufread::XzDecoder; -use crate::core::config::{BUILDER_CONFIG_FILENAME, TargetSelection}; +use crate::core::config::{BUILDER_CONFIG_FILENAME, Target, TargetSelection}; use crate::utils::build_stamp::BuildStamp; +use crate::utils::channel; use crate::utils::exec::{ExecutionContext, command}; use crate::utils::helpers::{exe, hex_encode, move_file}; use crate::{Config, t}; @@ -398,14 +401,21 @@ impl Config { /// Only should be used for pre config initialization downloads. pub(crate) struct DownloadContext<'a> { - host_target: TargetSelection, - out: &'a Path, - patch_binaries_for_nix: Option<bool>, - exec_ctx: &'a ExecutionContext, - stage0_metadata: &'a build_helper::stage0_parser::Stage0, - llvm_assertions: bool, - bootstrap_cache_path: &'a Option<PathBuf>, - is_running_on_ci: bool, + pub path_modification_cache: Arc<Mutex<HashMap<Vec<&'static str>, PathFreshness>>>, + pub src: &'a Path, + pub rust_info: &'a channel::GitInfo, + pub submodules: &'a Option<bool>, + pub download_rustc_commit: &'a Option<String>, + pub host_target: TargetSelection, + pub llvm_from_ci: bool, + pub target_config: &'a HashMap<TargetSelection, Target>, + pub out: &'a Path, + pub patch_binaries_for_nix: Option<bool>, + pub exec_ctx: &'a ExecutionContext, + pub stage0_metadata: &'a build_helper::stage0_parser::Stage0, + pub llvm_assertions: bool, + pub bootstrap_cache_path: &'a Option<PathBuf>, + pub is_running_on_ci: bool, } impl<'a> AsRef<DownloadContext<'a>> for DownloadContext<'a> { @@ -417,7 +427,14 @@ impl<'a> AsRef<DownloadContext<'a>> for DownloadContext<'a> { impl<'a> From<&'a Config> for DownloadContext<'a> { fn from(value: &'a Config) -> Self { DownloadContext { + path_modification_cache: value.path_modification_cache.clone(), + src: &value.src, host_target: value.host_target, + rust_info: &value.rust_info, + download_rustc_commit: &value.download_rustc_commit, + submodules: &value.submodules, + llvm_from_ci: value.llvm_from_ci, + target_config: &value.target_config, out: &value.out, patch_binaries_for_nix: value.patch_binaries_for_nix, exec_ctx: &value.exec_ctx, diff --git a/src/bootstrap/src/lib.rs b/src/bootstrap/src/lib.rs index 4abf386e5de..0b65ebc0671 100644 --- a/src/bootstrap/src/lib.rs +++ b/src/bootstrap/src/lib.rs @@ -410,6 +410,25 @@ forward! { download_rustc() -> bool, } +/// A mostly temporary helper struct before we can migrate everything in bootstrap to use +/// the concept of a build compiler. +struct HostAndStage { + host: TargetSelection, + stage: u32, +} + +impl From<(TargetSelection, u32)> for HostAndStage { + fn from((host, stage): (TargetSelection, u32)) -> Self { + Self { host, stage } + } +} + +impl From<Compiler> for HostAndStage { + fn from(compiler: Compiler) -> Self { + Self { host: compiler.host, stage: compiler.stage } + } +} + impl Build { /// Creates a new set of build configuration from the `flags` on the command /// line and the filesystem `config`. @@ -859,14 +878,17 @@ impl Build { if self.config.rust_optimize.is_release() { "release" } else { "debug" } } - fn tools_dir(&self, compiler: Compiler) -> PathBuf { - let out = self.out.join(compiler.host).join(format!("stage{}-tools-bin", compiler.stage)); + fn tools_dir(&self, build_compiler: Compiler) -> PathBuf { + let out = self + .out + .join(build_compiler.host) + .join(format!("stage{}-tools-bin", build_compiler.stage + 1)); t!(fs::create_dir_all(&out)); out } /// Returns the root directory for all output generated in a particular - /// stage when running with a particular host compiler. + /// stage when being built with a particular build compiler. /// /// The mode indicates what the root directory is for. fn stage_out(&self, build_compiler: Compiler, mode: Mode) -> PathBuf { @@ -876,15 +898,17 @@ impl Build { (None, "bootstrap-tools") } fn staged_tool(build_compiler: Compiler) -> (Option<u32>, &'static str) { - (Some(build_compiler.stage), "tools") + (Some(build_compiler.stage + 1), "tools") } let (stage, suffix) = match mode { + // Std is special, stage N std is built with stage N rustc Mode::Std => (Some(build_compiler.stage), "std"), - Mode::Rustc => (Some(build_compiler.stage), "rustc"), - Mode::Codegen => (Some(build_compiler.stage), "codegen"), + // The rest of things are built with stage N-1 rustc + Mode::Rustc => (Some(build_compiler.stage + 1), "rustc"), + Mode::Codegen => (Some(build_compiler.stage + 1), "codegen"), Mode::ToolBootstrap => bootstrap_tool(), - Mode::ToolStd | Mode::ToolRustc => (Some(build_compiler.stage), "tools"), + Mode::ToolStd | Mode::ToolRustc => (Some(build_compiler.stage + 1), "tools"), Mode::ToolTarget => { // If we're not cross-compiling (the common case), share the target directory with // bootstrap tools to reuse the build cache. @@ -907,8 +931,8 @@ impl Build { /// Returns the root output directory for all Cargo output in a given stage, /// running a particular compiler, whether or not we're building the /// standard library, and targeting the specified architecture. - fn cargo_out(&self, compiler: Compiler, mode: Mode, target: TargetSelection) -> PathBuf { - self.stage_out(compiler, mode).join(target).join(self.cargo_dir()) + fn cargo_out(&self, build_compiler: Compiler, mode: Mode, target: TargetSelection) -> PathBuf { + self.stage_out(build_compiler, mode).join(target).join(self.cargo_dir()) } /// Root output directory of LLVM for `target` @@ -1067,45 +1091,14 @@ impl Build { } } - #[must_use = "Groups should not be dropped until the Step finishes running"] - #[track_caller] - fn msg_clippy( - &self, - what: impl Display, - target: impl Into<Option<TargetSelection>>, - ) -> Option<gha::Group> { - self.msg(Kind::Clippy, self.config.stage, what, self.config.host_target, target) - } - - #[must_use = "Groups should not be dropped until the Step finishes running"] - #[track_caller] - fn msg_check( - &self, - what: impl Display, - target: impl Into<Option<TargetSelection>>, - custom_stage: Option<u32>, - ) -> Option<gha::Group> { - self.msg( - Kind::Check, - custom_stage.unwrap_or(self.config.stage), - what, - self.config.host_target, - target, - ) - } - - #[must_use = "Groups should not be dropped until the Step finishes running"] - #[track_caller] - fn msg_doc( - &self, - compiler: Compiler, - what: impl Display, - target: impl Into<Option<TargetSelection>> + Copy, - ) -> Option<gha::Group> { - self.msg(Kind::Doc, compiler.stage, what, compiler.host, target.into()) - } - - /// Return a `Group` guard for a [`Step`] that is built for each `--stage`. + /// Return a `Group` guard for a [`Step`] that: + /// - Performs `action` + /// - On `what` + /// - Where `what` possibly corresponds to a `mode` + /// - `action` is performed using the given build compiler (`host_and_stage`). + /// - Since some steps do not use the concept of a build compiler yet, it is also possible + /// to pass the host and stage explicitly. + /// - With a given `target`. /// /// [`Step`]: crate::core::builder::Step #[must_use = "Groups should not be dropped until the Step finishes running"] @@ -1113,19 +1106,36 @@ impl Build { fn msg( &self, action: impl Into<Kind>, - stage: u32, what: impl Display, - host: impl Into<Option<TargetSelection>>, + mode: impl Into<Option<Mode>>, + host_and_stage: impl Into<HostAndStage>, target: impl Into<Option<TargetSelection>>, ) -> Option<gha::Group> { + let host_and_stage = host_and_stage.into(); + let actual_stage = match mode.into() { + // Std has the same stage as the compiler that builds it + Some(Mode::Std) => host_and_stage.stage, + // Other things have stage corresponding to their build compiler + 1 + Some( + Mode::Rustc + | Mode::Codegen + | Mode::ToolBootstrap + | Mode::ToolTarget + | Mode::ToolStd + | Mode::ToolRustc, + ) + | None => host_and_stage.stage + 1, + }; + let action = action.into().description(); - let msg = |fmt| format!("{action} stage{stage} {what}{fmt}"); + let msg = |fmt| format!("{action} stage{actual_stage} {what}{fmt}"); let msg = if let Some(target) = target.into() { - let host = host.into().unwrap(); + let build_stage = host_and_stage.stage; + let host = host_and_stage.host; if host == target { - msg(format_args!(" ({target})")) + msg(format_args!(" (stage{build_stage} -> stage{actual_stage}, {target})")) } else { - msg(format_args!(" ({host} -> {target})")) + msg(format_args!(" (stage{build_stage}:{host} -> stage{actual_stage}:{target})")) } } else { msg(format_args!("")) @@ -1149,27 +1159,6 @@ impl Build { self.group(&msg) } - #[must_use = "Groups should not be dropped until the Step finishes running"] - #[track_caller] - fn msg_rustc_tool( - &self, - action: impl Into<Kind>, - build_stage: u32, - what: impl Display, - host: TargetSelection, - target: TargetSelection, - ) -> Option<gha::Group> { - let action = action.into().description(); - let msg = |fmt| format!("{action} {what} {fmt}"); - - let msg = if host == target { - msg(format_args!("(stage{build_stage} -> stage{}, {target})", build_stage + 1)) - } else { - msg(format_args!("(stage{build_stage}:{host} -> stage{}:{target})", build_stage + 1)) - }; - self.group(&msg) - } - #[track_caller] fn group(&self, msg: &str) -> Option<gha::Group> { match self.config.get_dry_run() { diff --git a/src/bootstrap/src/utils/change_tracker.rs b/src/bootstrap/src/utils/change_tracker.rs index d3331b81587..cd7fba39a84 100644 --- a/src/bootstrap/src/utils/change_tracker.rs +++ b/src/bootstrap/src/utils/change_tracker.rs @@ -491,4 +491,14 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[ severity: ChangeSeverity::Warning, summary: "Added `build.compiletest-allow-stage0` flag instead of `COMPILETEST_FORCE_STAGE0` env var, and reject running `compiletest` self tests against stage 0 rustc unless explicitly allowed.", }, + ChangeInfo { + change_id: 145011, + severity: ChangeSeverity::Warning, + summary: "It is no longer possible to `x doc` with stage 0. All doc commands have to be on stage 1+.", + }, + ChangeInfo { + change_id: 145295, + severity: ChangeSeverity::Warning, + summary: "The names of stageN directories in the build directory have been consolidated with the new (post-stage-0-redesign) staging scheme. Some tools and binaries might be located in a different build directory than before.", + }, ]; diff --git a/src/bootstrap/src/utils/exec.rs b/src/bootstrap/src/utils/exec.rs index 7527dff9cd8..03760faec69 100644 --- a/src/bootstrap/src/utils/exec.rs +++ b/src/bootstrap/src/utils/exec.rs @@ -80,11 +80,21 @@ impl CommandFingerprint { /// Helper method to format both Command and BootstrapCommand as a short execution line, /// without all the other details (e.g. environment variables). pub fn format_short_cmd(&self) -> String { - let program = Path::new(&self.program); - let mut line = vec![program.file_name().unwrap().to_str().unwrap().to_owned()]; - line.extend(self.args.iter().map(|arg| arg.to_string_lossy().into_owned())); - line.extend(self.cwd.iter().map(|p| p.to_string_lossy().into_owned())); - line.join(" ") + use std::fmt::Write; + + let mut cmd = self.program.to_string_lossy().to_string(); + for arg in &self.args { + let arg = arg.to_string_lossy(); + if arg.contains(' ') { + write!(cmd, " '{arg}'").unwrap(); + } else { + write!(cmd, " {arg}").unwrap(); + } + } + if let Some(cwd) = &self.cwd { + write!(cmd, " [workdir={}]", cwd.to_string_lossy()).unwrap(); + } + cmd } } @@ -434,8 +444,8 @@ impl From<Command> for BootstrapCommand { enum CommandStatus { /// The command has started and finished with some status. Finished(ExitStatus), - /// It was not even possible to start the command. - DidNotStart, + /// It was not even possible to start the command or wait for it to finish. + DidNotStartOrFinish, } /// Create a new BootstrapCommand. This is a helper function to make command creation @@ -456,9 +466,9 @@ pub struct CommandOutput { impl CommandOutput { #[must_use] - pub fn did_not_start(stdout: OutputMode, stderr: OutputMode) -> Self { + pub fn not_finished(stdout: OutputMode, stderr: OutputMode) -> Self { Self { - status: CommandStatus::DidNotStart, + status: CommandStatus::DidNotStartOrFinish, stdout: match stdout { OutputMode::Print => None, OutputMode::Capture => Some(vec![]), @@ -489,7 +499,7 @@ impl CommandOutput { pub fn is_success(&self) -> bool { match self.status { CommandStatus::Finished(status) => status.success(), - CommandStatus::DidNotStart => false, + CommandStatus::DidNotStartOrFinish => false, } } @@ -501,7 +511,7 @@ impl CommandOutput { pub fn status(&self) -> Option<ExitStatus> { match self.status { CommandStatus::Finished(status) => Some(status), - CommandStatus::DidNotStart => None, + CommandStatus::DidNotStartOrFinish => None, } } @@ -745,25 +755,11 @@ impl ExecutionContext { self.start(command, stdout, stderr).wait_for_output(self) } - fn fail(&self, message: &str, output: CommandOutput) -> ! { - if self.is_verbose() { - println!("{message}"); - } else { - let (stdout, stderr) = (output.stdout_if_present(), output.stderr_if_present()); - // If the command captures output, the user would not see any indication that - // it has failed. In this case, print a more verbose error, since to provide more - // context. - if stdout.is_some() || stderr.is_some() { - if let Some(stdout) = output.stdout_if_present().take_if(|s| !s.trim().is_empty()) { - println!("STDOUT:\n{stdout}\n"); - } - if let Some(stderr) = output.stderr_if_present().take_if(|s| !s.trim().is_empty()) { - println!("STDERR:\n{stderr}\n"); - } - println!("Command has failed. Rerun with -v to see more details."); - } else { - println!("Command has failed. Rerun with -v to see more details."); - } + fn fail(&self, message: &str) -> ! { + println!("{message}"); + + if !self.is_verbose() { + println!("Command has failed. Rerun with -v to see more details."); } exit!(1); } @@ -856,7 +852,7 @@ impl<'a> DeferredCommand<'a> { && command.should_cache { exec_ctx.command_cache.insert(fingerprint.clone(), output.clone()); - exec_ctx.profiler.record_execution(fingerprint.clone(), start_time); + exec_ctx.profiler.record_execution(fingerprint, start_time); } output @@ -872,6 +868,8 @@ impl<'a> DeferredCommand<'a> { executed_at: &'a std::panic::Location<'a>, exec_ctx: &ExecutionContext, ) -> CommandOutput { + use std::fmt::Write; + command.mark_as_executed(); let process = match process.take() { @@ -881,79 +879,82 @@ impl<'a> DeferredCommand<'a> { let created_at = command.get_created_location(); - let mut message = String::new(); + #[allow(clippy::enum_variant_names)] + enum FailureReason { + FailedAtRuntime(ExitStatus), + FailedToFinish(std::io::Error), + FailedToStart(std::io::Error), + } - let output = match process { + let (output, fail_reason) = match process { Ok(child) => match child.wait_with_output() { - Ok(result) if result.status.success() => { + Ok(output) if output.status.success() => { // Successful execution - CommandOutput::from_output(result, stdout, stderr) + (CommandOutput::from_output(output, stdout, stderr), None) } - Ok(result) => { - // Command ran but failed - use std::fmt::Write; - - writeln!( - message, - r#" -Command {command:?} did not execute successfully. -Expected success, got {} -Created at: {created_at} -Executed at: {executed_at}"#, - result.status, + Ok(output) => { + // Command started, but then it failed + let status = output.status; + ( + CommandOutput::from_output(output, stdout, stderr), + Some(FailureReason::FailedAtRuntime(status)), ) - .unwrap(); - - let output = CommandOutput::from_output(result, stdout, stderr); - - if stdout.captures() { - writeln!(message, "\nSTDOUT ----\n{}", output.stdout().trim()).unwrap(); - } - if stderr.captures() { - writeln!(message, "\nSTDERR ----\n{}", output.stderr().trim()).unwrap(); - } - - output } Err(e) => { // Failed to wait for output - use std::fmt::Write; - - writeln!( - message, - "\n\nCommand {command:?} did not execute successfully.\ - \nIt was not possible to execute the command: {e:?}" + ( + CommandOutput::not_finished(stdout, stderr), + Some(FailureReason::FailedToFinish(e)), ) - .unwrap(); - - CommandOutput::did_not_start(stdout, stderr) } }, Err(e) => { // Failed to spawn the command - use std::fmt::Write; - - writeln!( - message, - "\n\nCommand {command:?} did not execute successfully.\ - \nIt was not possible to execute the command: {e:?}" - ) - .unwrap(); - - CommandOutput::did_not_start(stdout, stderr) + (CommandOutput::not_finished(stdout, stderr), Some(FailureReason::FailedToStart(e))) } }; - if !output.is_success() { + if let Some(fail_reason) = fail_reason { + let mut error_message = String::new(); + let command_str = if exec_ctx.is_verbose() { + format!("{command:?}") + } else { + command.fingerprint().format_short_cmd() + }; + let action = match fail_reason { + FailureReason::FailedAtRuntime(e) => { + format!("failed with exit code {}", e.code().unwrap_or(1)) + } + FailureReason::FailedToFinish(e) => { + format!("failed to finish: {e:?}") + } + FailureReason::FailedToStart(e) => { + format!("failed to start: {e:?}") + } + }; + writeln!( + error_message, + r#"Command `{command_str}` {action} +Created at: {created_at} +Executed at: {executed_at}"#, + ) + .unwrap(); + if stdout.captures() { + writeln!(error_message, "\n--- STDOUT vvv\n{}", output.stdout().trim()).unwrap(); + } + if stderr.captures() { + writeln!(error_message, "\n--- STDERR vvv\n{}", output.stderr().trim()).unwrap(); + } + match command.failure_behavior { BehaviorOnFailure::DelayFail => { if exec_ctx.fail_fast { - exec_ctx.fail(&message, output); + exec_ctx.fail(&error_message); } - exec_ctx.add_to_delay_failure(message); + exec_ctx.add_to_delay_failure(error_message); } BehaviorOnFailure::Exit => { - exec_ctx.fail(&message, output); + exec_ctx.fail(&error_message); } BehaviorOnFailure::Ignore => { // If failures are allowed, either the error has been printed already diff --git a/src/bootstrap/src/utils/shared_helpers.rs b/src/bootstrap/src/utils/shared_helpers.rs index 9428e221f41..d620cc4bbb6 100644 --- a/src/bootstrap/src/utils/shared_helpers.rs +++ b/src/bootstrap/src/utils/shared_helpers.rs @@ -81,10 +81,11 @@ pub fn parse_rustc_verbose() -> usize { } /// Parses the value of the "RUSTC_STAGE" environment variable and returns it as a `String`. +/// This is the stage of the *build compiler*, which we are wrapping using a rustc/rustdoc wrapper. /// /// If "RUSTC_STAGE" was not set, the program will be terminated with 101. -pub fn parse_rustc_stage() -> String { - env::var("RUSTC_STAGE").unwrap_or_else(|_| { +pub fn parse_rustc_stage() -> u32 { + env::var("RUSTC_STAGE").ok().and_then(|v| v.parse().ok()).unwrap_or_else(|| { // Don't panic here; it's reasonable to try and run these shims directly. Give a helpful error instead. eprintln!("rustc shim: FATAL: RUSTC_STAGE was not set"); eprintln!("rustc shim: NOTE: use `x.py build -vvv` to see all environment variables set by bootstrap"); diff --git a/src/ci/docker/host-aarch64/dist-aarch64-linux/Dockerfile b/src/ci/docker/host-aarch64/dist-aarch64-linux/Dockerfile index 2b8a3f829c6..e726329753f 100644 --- a/src/ci/docker/host-aarch64/dist-aarch64-linux/Dockerfile +++ b/src/ci/docker/host-aarch64/dist-aarch64-linux/Dockerfile @@ -96,7 +96,7 @@ ENV RUST_CONFIGURE_ARGS \ --set rust.codegen-units=1 ENV SCRIPT python3 ../x.py build --set rust.debug=true opt-dist && \ - ./build/$HOSTS/stage0-tools-bin/opt-dist linux-ci -- python3 ../x.py dist \ + ./build/$HOSTS/stage1-tools-bin/opt-dist linux-ci -- python3 ../x.py dist \ --host $HOSTS --target $HOSTS --include-default-paths build-manifest bootstrap ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=clang diff --git a/src/ci/docker/host-x86_64/dist-x86_64-linux/dist.sh b/src/ci/docker/host-x86_64/dist-x86_64-linux/dist.sh index 924bdbc7615..4c95d4a401e 100755 --- a/src/ci/docker/host-x86_64/dist-x86_64-linux/dist.sh +++ b/src/ci/docker/host-x86_64/dist-x86_64-linux/dist.sh @@ -4,7 +4,7 @@ set -eux python3 ../x.py build --set rust.debug=true opt-dist -./build/$HOSTS/stage0-tools-bin/opt-dist linux-ci -- python3 ../x.py dist \ +./build/$HOSTS/stage1-tools-bin/opt-dist linux-ci -- python3 ../x.py dist \ --host $HOSTS --target $HOSTS \ --include-default-paths \ build-manifest bootstrap diff --git a/src/ci/docker/host-x86_64/pr-check-2/Dockerfile b/src/ci/docker/host-x86_64/pr-check-2/Dockerfile index f82e19bcbb4..6fea2437276 100644 --- a/src/ci/docker/host-x86_64/pr-check-2/Dockerfile +++ b/src/ci/docker/host-x86_64/pr-check-2/Dockerfile @@ -31,13 +31,13 @@ ENV SCRIPT \ python3 ../x.py clippy ci && \ python3 ../x.py test --stage 1 core alloc std test proc_macro && \ python3 ../x.py test --stage 1 src/tools/compiletest && \ - python3 ../x.py doc --stage 0 bootstrap && \ + python3 ../x.py doc bootstrap && \ # Build both public and internal documentation. - RUSTDOCFLAGS=\"--document-private-items --document-hidden-items\" python3 ../x.py doc --stage 0 compiler && \ - RUSTDOCFLAGS=\"--document-private-items --document-hidden-items\" python3 ../x.py doc --stage 1 library && \ + RUSTDOCFLAGS=\"--document-private-items --document-hidden-items\" python3 ../x.py doc compiler --stage 1 && \ + RUSTDOCFLAGS=\"--document-private-items --document-hidden-items\" python3 ../x.py doc library --stage 1 && \ mkdir -p /checkout/obj/staging/doc && \ cp -r build/x86_64-unknown-linux-gnu/doc /checkout/obj/staging && \ - RUSTDOCFLAGS=\"--document-private-items --document-hidden-items\" python3 ../x.py doc --stage 1 library/test && \ + RUSTDOCFLAGS=\"--document-private-items --document-hidden-items\" python3 ../x.py doc library/test --stage 1 && \ # The BOOTSTRAP_TRACING flag is added to verify whether the # bootstrap process compiles successfully with this flag enabled. BOOTSTRAP_TRACING=1 python3 ../x.py --help diff --git a/src/ci/github-actions/jobs.yml b/src/ci/github-actions/jobs.yml index 48c570bfa11..ae13d14c380 100644 --- a/src/ci/github-actions/jobs.yml +++ b/src/ci/github-actions/jobs.yml @@ -656,7 +656,7 @@ auto: --enable-full-tools --enable-profiler --set rust.codegen-units=1 - SCRIPT: python x.py build --set rust.debug=true opt-dist && PGO_HOST=x86_64-pc-windows-msvc ./build/x86_64-pc-windows-msvc/stage0-tools-bin/opt-dist windows-ci -- python x.py dist bootstrap --include-default-paths + SCRIPT: python x.py build --set rust.debug=true opt-dist && PGO_HOST=x86_64-pc-windows-msvc ./build/x86_64-pc-windows-msvc/stage1-tools-bin/opt-dist windows-ci -- python x.py dist bootstrap --include-default-paths DIST_REQUIRE_ALL_TOOLS: 1 CODEGEN_BACKENDS: llvm,cranelift <<: *job-windows-8c diff --git a/src/ci/run.sh b/src/ci/run.sh index f58a067041d..c9d81f1ff51 100755 --- a/src/ci/run.sh +++ b/src/ci/run.sh @@ -205,6 +205,9 @@ if [ "$ENABLE_GCC_CODEGEN" = "1" ]; then RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-new-symbol-mangling" fi +# If bootstrap fails, we want to see its backtrace +export RUST_BACKTRACE=1 + # Print the date from the local machine and the date from an external source to # check for clock drifts. An HTTP URL is used instead of HTTPS since on Azure # Pipelines it happened that the certificates were marked as expired. diff --git a/src/doc/reference b/src/doc/reference -Subproject 1be151c051a082b542548c62cafbcb055fa8944 +Subproject 59b8af811886313577615c2cf0e045f01faed88 diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example -Subproject bd1279cdc9865bfff605e741fb76a0b2f07314a +Subproject adc1f3b9012ad3255eea2054ca30596a953d053 diff --git a/src/doc/rustc-dev-guide/src/building/optimized-build.md b/src/doc/rustc-dev-guide/src/building/optimized-build.md index 863ed9749fb..46def66d178 100644 --- a/src/doc/rustc-dev-guide/src/building/optimized-build.md +++ b/src/doc/rustc-dev-guide/src/building/optimized-build.md @@ -118,7 +118,7 @@ Here is an example of how can `opt-dist` be used locally (outside of CI): ``` 3. Run the tool with the `local` mode and provide necessary parameters: ```bash - ./build/host/stage0-tools-bin/opt-dist local \ + ./build/host/stage1-tools-bin/opt-dist local \ --target-triple <target> \ # select target, e.g. "x86_64-unknown-linux-gnu" --checkout-dir <path> \ # path to rust checkout, e.g. "." --llvm-dir <path> \ # path to built LLVM toolchain, e.g. "/foo/bar/llvm/install" diff --git a/src/doc/rustc-dev-guide/src/stability.md b/src/doc/rustc-dev-guide/src/stability.md index c26d34273d7..3c4c65fdd5a 100644 --- a/src/doc/rustc-dev-guide/src/stability.md +++ b/src/doc/rustc-dev-guide/src/stability.md @@ -182,6 +182,11 @@ of the standard library raises it to a warning with `#![warn(deprecated_in_future)]`. ## unstable_feature_bound -The `#[unstable_feature_bound(foo)]` attribute can be used together with `#[unstable]` attribute to mark an `impl` of stable type and stable trait as unstable. In std/core, an item annotated with `#[unstable_feature_bound(foo)]` can only be used by another item that is also annotated with `#[unstable_feature_bound(foo)]`. Outside of std/core, using an item with `#[unstable_feature_bound(foo)]` requires the feature to be enabled with `#![feature(foo)]` attribute on the crate. Currently, only `impl`s and free functions can be annotated with `#[unstable_feature_bound]`. +The `#[unstable_feature_bound(foo)]` attribute can be used together with `#[unstable]` attribute to mark an `impl` of stable type and stable trait as unstable. In std/core, an item annotated with `#[unstable_feature_bound(foo)]` can only be used by another item that is also annotated with `#[unstable_feature_bound(foo)]`. Outside of std/core, using an item with `#[unstable_feature_bound(foo)]` requires the feature to be enabled with `#![feature(foo)]` attribute on the crate. + +Currently, the items that can be annotated with `#[unstable_feature_bound]` are: +- `impl` +- free function +- trait [blog]: https://www.ralfj.de/blog/2018/07/19/const.html diff --git a/src/doc/rustc/src/tests/index.md b/src/doc/rustc/src/tests/index.md index 12de69a4c9e..7609ed23351 100644 --- a/src/doc/rustc/src/tests/index.md +++ b/src/doc/rustc/src/tests/index.md @@ -164,7 +164,7 @@ Sets the number of threads to use for running tests in parallel. By default, uses the amount of concurrency available on the hardware as indicated by [`available_parallelism`]. -This can also be specified with the `RUST_TEST_THREADS` environment variable. +Deprecated: this can also be specified with the `RUST_TEST_THREADS` environment variable. #### `--force-run-in-process` @@ -186,7 +186,7 @@ docs](../../unstable-book/compiler-flags/report-time.html) for more information. Runs the tests in random order, as opposed to the default alphabetical order. -This may also be specified by setting the `RUST_TEST_SHUFFLE` environment +Deprecated: this may also be specified by setting the `RUST_TEST_SHUFFLE` environment variable to anything but `0`. The random number generator seed that is output can be passed to @@ -209,7 +209,7 @@ the tests in the same order both times. _SEED_ is any 64-bit unsigned integer, for example, one produced by [`--shuffle`](#--shuffle). -This can also be specified with the `RUST_TEST_SHUFFLE_SEED` environment +Deprecated: this can also be specified with the `RUST_TEST_SHUFFLE_SEED` environment variable. ⚠️ 🚧 This option is [unstable](#unstable-options), and requires the `-Z @@ -231,7 +231,7 @@ Does not capture the stdout and stderr of the test, and allows tests to print to the console. Usually the output is captured, and only displayed if the test fails. -This may also be specified by setting the `RUST_TEST_NOCAPTURE` environment +Deprecated: this may also be specified by setting the `RUST_TEST_NOCAPTURE` environment variable to anything but `0`. `--nocapture` is a deprecated alias for `--no-capture`. diff --git a/src/doc/unstable-book/src/compiler-environment-variables/COLORTERM.md b/src/doc/unstable-book/src/compiler-environment-variables/COLORTERM.md new file mode 100644 index 00000000000..f5be63b796c --- /dev/null +++ b/src/doc/unstable-book/src/compiler-environment-variables/COLORTERM.md @@ -0,0 +1,5 @@ +# `COLORTERM` + +This environment variable is used by [`-Zterminal-urls`] to detect if URLs are supported by the terminal emulator. + +[`-Zterminal-urls`]: ../compiler-flags/terminal-urls.html diff --git a/src/doc/unstable-book/src/compiler-environment-variables/QNX_TARGET.md b/src/doc/unstable-book/src/compiler-environment-variables/QNX_TARGET.md new file mode 100644 index 00000000000..46511598e70 --- /dev/null +++ b/src/doc/unstable-book/src/compiler-environment-variables/QNX_TARGET.md @@ -0,0 +1,11 @@ +# `QNX_TARGET` + +---- + +This environment variable is mandatory when linking on `nto-qnx*_iosock` platforms. It is used to determine an `-L` path to pass to the QNX linker. + +You should [set this variable] by running `source qnxsdp-env.sh`. +See [the QNX docs] for more background information. + +[set this variable]: https://www.qnx.com/developers/docs/qsc/com.qnx.doc.qsc.inst_larg_org/topic/build_server_developer_steps.html +[the QNX docs]: https://www.qnx.com/developers/docs/7.1/#com.qnx.doc.neutrino.io_sock/topic/migrate_app.html. diff --git a/src/doc/unstable-book/src/compiler-environment-variables/SDKROOT.md b/src/doc/unstable-book/src/compiler-environment-variables/SDKROOT.md new file mode 100644 index 00000000000..6d371ae289f --- /dev/null +++ b/src/doc/unstable-book/src/compiler-environment-variables/SDKROOT.md @@ -0,0 +1,6 @@ +# `SDKROOT` + +This environment variable is used on Apple targets. +It is passed through to the linker (currently either directly or via the `-syslibroot` flag). + +Note that this variable is not always respected. When the SDKROOT is clearly wrong (e.g. when the platform of the SDK does not match the `--target` used by rustc), this is ignored and rustc does its own detection. diff --git a/src/doc/unstable-book/src/compiler-environment-variables/TERM.md b/src/doc/unstable-book/src/compiler-environment-variables/TERM.md new file mode 100644 index 00000000000..9208fd378a3 --- /dev/null +++ b/src/doc/unstable-book/src/compiler-environment-variables/TERM.md @@ -0,0 +1,5 @@ +# `TERM` + +This environment variable is used by [`-Zterminal-urls`] to detect if URLs are supported by the terminal emulator. + +[`-Zterminal-urls`]: ../compiler-flags/terminal-urls.html diff --git a/src/doc/unstable-book/src/compiler-flags/terminal-urls.md b/src/doc/unstable-book/src/compiler-flags/terminal-urls.md new file mode 100644 index 00000000000..a5427978f25 --- /dev/null +++ b/src/doc/unstable-book/src/compiler-flags/terminal-urls.md @@ -0,0 +1,13 @@ +# `-Z terminal-urls` + +The tracking feature for this issue is [#125586] + +[#125586]: https://github.com/rust-lang/rust/issues/125586 + +--- + +This flag takes either a boolean or the string "auto". + +When enabled, use the OSC 8 hyperlink terminal specification to print hyperlinks in the compiler output. +Use "auto" to try and autodetect whether the terminal emulator supports hyperlinks. +Currently, "auto" only enables hyperlinks if `COLORTERM=truecolor` and `TERM=xterm-256color`. diff --git a/src/doc/unstable-book/src/language-features/asm-experimental-arch.md b/src/doc/unstable-book/src/language-features/asm-experimental-arch.md index 121f9493435..d9566c9f55c 100644 --- a/src/doc/unstable-book/src/language-features/asm-experimental-arch.md +++ b/src/doc/unstable-book/src/language-features/asm-experimental-arch.md @@ -19,7 +19,6 @@ This feature tracks `asm!` and `global_asm!` support for the following architect - M68k - CSKY - SPARC -- LoongArch32 ## Register classes @@ -54,8 +53,6 @@ This feature tracks `asm!` and `global_asm!` support for the following architect | CSKY | `freg` | `f[0-31]` | `f` | | SPARC | `reg` | `r[2-29]` | `r` | | SPARC | `yreg` | `y` | Only clobbers | -| LoongArch32 | `reg` | `$r1`, `$r[4-20]`, `$r[23,30]` | `r` | -| LoongArch32 | `freg` | `$f[0-31]` | `f` | > **Notes**: > - NVPTX doesn't have a fixed register set, so named registers are not supported. @@ -94,8 +91,6 @@ This feature tracks `asm!` and `global_asm!` support for the following architect | CSKY | `freg` | None | `f32`, | | SPARC | `reg` | None | `i8`, `i16`, `i32`, `i64` (SPARC64 only) | | SPARC | `yreg` | N/A | Only clobbers | -| LoongArch32 | `reg` | None | `i8`, `i16`, `i32`, `f32` | -| LoongArch32 | `freg` | None | `f32`, `f64` | ## Register aliases diff --git a/src/doc/unstable-book/src/library-features/duration-constructors-lite.md b/src/doc/unstable-book/src/library-features/duration-constructors-lite.md deleted file mode 100644 index 5238b84f776..00000000000 --- a/src/doc/unstable-book/src/library-features/duration-constructors-lite.md +++ /dev/null @@ -1,11 +0,0 @@ -# `duration_constructors_lite` - -The tracking issue for this feature is: [#140881] - -[#140881]: https://github.com/rust-lang/rust/issues/140881 - ------------------------- - -Add the methods `from_mins`, `from_hours` to `Duration`. - -For `from_days` and `from_weeks` see [`duration_constructors`](https://github.com/rust-lang/rust/issues/120301). diff --git a/src/doc/unstable-book/src/library-features/duration-constructors.md b/src/doc/unstable-book/src/library-features/duration-constructors.md index 49ad78d1961..2626e0500b5 100644 --- a/src/doc/unstable-book/src/library-features/duration-constructors.md +++ b/src/doc/unstable-book/src/library-features/duration-constructors.md @@ -7,4 +7,3 @@ The tracking issue for this feature is: [#120301] ------------------------ Add the methods `from_days` and `from_weeks` to `Duration`. -For `from_mins` and `from_hours` see [duration-constructors-lite.md](./duration-constructors-lite.md) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 7194c2fcede..890bfaced6c 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2768,7 +2768,7 @@ fn clean_maybe_renamed_item<'tcx>( // These kinds of item either don't need a `name` or accept a `None` one so we handle them // before. match item.kind { - ItemKind::Impl(impl_) => return clean_impl(impl_, item.owner_id.def_id, cx), + ItemKind::Impl(ref impl_) => return clean_impl(impl_, item.owner_id.def_id, cx), ItemKind::Use(path, kind) => { return clean_use_statement( item, @@ -2896,7 +2896,7 @@ fn clean_impl<'tcx>( ) -> Vec<Item> { let tcx = cx.tcx; let mut ret = Vec::new(); - let trait_ = impl_.of_trait.as_ref().map(|t| clean_trait_ref(t, cx)); + let trait_ = impl_.of_trait.map(|t| clean_trait_ref(&t.trait_ref, cx)); let items = impl_ .items .iter() @@ -2922,7 +2922,10 @@ fn clean_impl<'tcx>( }); let mut make_item = |trait_: Option<Path>, for_: Type, items: Vec<Item>| { let kind = ImplItem(Box::new(Impl { - safety: impl_.safety, + safety: match impl_.of_trait { + Some(of_trait) => of_trait.safety, + None => hir::Safety::Safe, + }, generics: clean_generics(impl_.generics, cx), trait_, for_, diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 35ace656638..73ce62cdcde 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -409,9 +409,7 @@ pub(crate) fn run_tests( // We ensure temp dir destructor is called. std::mem::drop(temp_dir); times.display_times(); - // FIXME(GuillaumeGomez): Uncomment the next line once #144297 has been merged. - // std::process::exit(test::ERROR_EXIT_CODE); - std::process::exit(101); + std::process::exit(test::ERROR_EXIT_CODE); } } diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 02ee34aaac6..759f53974f5 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -1656,11 +1656,9 @@ fn display_c_like_variant( } else if should_show_enum_discriminant { let adt_def = cx.tcx().adt_def(enum_def_id); let discr = adt_def.discriminant_for_variant(cx.tcx(), index); - if discr.ty.is_signed() { - write!(w, "{} = {}", name.as_str(), discr.val as i128)?; - } else { - write!(w, "{} = {}", name.as_str(), discr.val)?; - } + // Use `discr`'s `Display` impl to render the value with the correct + // signedness, including proper sign-extension for signed types. + write!(w, "{} = {}", name.as_str(), discr)?; } else { write!(w, "{name}")?; } diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index bcb676cd1f1..40191551e4f 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -997,6 +997,7 @@ fn preprocess_link( } }; + let is_shortcut_style = ori_link.kind == LinkType::ShortcutUnknown; // If there's no backticks, be lenient and revert to the old behavior. // This is to prevent churn by linting on stuff that isn't meant to be a link. // only shortcut links have simple enough syntax that they @@ -1013,11 +1014,22 @@ fn preprocess_link( // | has backtick | never ignore | never ignore | // | no backtick | ignore if url-like | never ignore | // |-------------------------------------------------------| - let ignore_urllike = - can_be_url || (ori_link.kind == LinkType::ShortcutUnknown && !ori_link.link.contains('`')); + let ignore_urllike = can_be_url || (is_shortcut_style && !ori_link.link.contains('`')); if ignore_urllike && should_ignore_link(path_str) { return None; } + // If we have an intra-doc link starting with `!` (which isn't `[!]` because this is the never type), we ignore it + // as it is never valid. + // + // The case is common enough because of cases like `#[doc = include_str!("../README.md")]` which often + // uses GitHub-flavored Markdown (GFM) admonitions, such as `[!NOTE]`. + if is_shortcut_style + && let Some(suffix) = ori_link.link.strip_prefix('!') + && !suffix.is_empty() + && suffix.chars().all(|c| c.is_ascii_alphabetic()) + { + return None; + } // Strip generics from the path. let path_str = match strip_generics_from_path(path_str) { diff --git a/src/tools/clippy/clippy_lints/src/arbitrary_source_item_ordering.rs b/src/tools/clippy/clippy_lints/src/arbitrary_source_item_ordering.rs index d6469d32931..36498adff50 100644 --- a/src/tools/clippy/clippy_lints/src/arbitrary_source_item_ordering.rs +++ b/src/tools/clippy/clippy_lints/src/arbitrary_source_item_ordering.rs @@ -534,6 +534,7 @@ fn get_item_name(item: &Item<'_>) -> Option<String> { if let Some(of_trait) = im.of_trait { let mut trait_segs: Vec<String> = of_trait + .trait_ref .path .segments .iter() diff --git a/src/tools/clippy/clippy_lints/src/bool_assert_comparison.rs b/src/tools/clippy/clippy_lints/src/bool_assert_comparison.rs index 581fe33ea0b..f31b67f470f 100644 --- a/src/tools/clippy/clippy_lints/src/bool_assert_comparison.rs +++ b/src/tools/clippy/clippy_lints/src/bool_assert_comparison.rs @@ -130,18 +130,22 @@ impl<'tcx> LateLintPass<'tcx> for BoolAssertComparison { let mut suggestions = vec![(name_span, non_eq_mac.to_string()), (lit_span, String::new())]; - if bool_value ^ eq_macro { - let Some(sugg) = Sugg::hir_opt(cx, non_lit_expr) else { - return; + if let Some(sugg) = Sugg::hir_opt(cx, non_lit_expr) { + let sugg = if bool_value ^ eq_macro { + !sugg.maybe_paren() + } else if ty::Bool == *non_lit_ty.kind() { + sugg + } else { + !!sugg.maybe_paren() }; - suggestions.push((non_lit_expr.span, (!sugg).to_string())); - } + suggestions.push((non_lit_expr.span, sugg.to_string())); - diag.multipart_suggestion( - format!("replace it with `{non_eq_mac}!(..)`"), - suggestions, - Applicability::MachineApplicable, - ); + diag.multipart_suggestion( + format!("replace it with `{non_eq_mac}!(..)`"), + suggestions, + Applicability::MachineApplicable, + ); + } }, ); } diff --git a/src/tools/clippy/clippy_lints/src/copy_iterator.rs b/src/tools/clippy/clippy_lints/src/copy_iterator.rs index 4ecf3e41611..51aebd8b0cf 100644 --- a/src/tools/clippy/clippy_lints/src/copy_iterator.rs +++ b/src/tools/clippy/clippy_lints/src/copy_iterator.rs @@ -37,12 +37,12 @@ declare_lint_pass!(CopyIterator => [COPY_ITERATOR]); impl<'tcx> LateLintPass<'tcx> for CopyIterator { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if let ItemKind::Impl(Impl { - of_trait: Some(trait_ref), + of_trait: Some(of_trait), .. }) = item.kind && let ty = cx.tcx.type_of(item.owner_id).instantiate_identity() && is_copy(cx, ty) - && let Some(trait_id) = trait_ref.trait_def_id() + && let Some(trait_id) = of_trait.trait_ref.trait_def_id() && cx.tcx.is_diagnostic_item(sym::Iterator, trait_id) { span_lint_and_note( diff --git a/src/tools/clippy/clippy_lints/src/derivable_impls.rs b/src/tools/clippy/clippy_lints/src/derivable_impls.rs index 0a481ddcd12..7580d6cab66 100644 --- a/src/tools/clippy/clippy_lints/src/derivable_impls.rs +++ b/src/tools/clippy/clippy_lints/src/derivable_impls.rs @@ -183,14 +183,14 @@ fn check_enum<'tcx>(cx: &LateContext<'tcx>, item: &'tcx Item<'_>, func_expr: &Ex impl<'tcx> LateLintPass<'tcx> for DerivableImpls { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if let ItemKind::Impl(Impl { - of_trait: Some(trait_ref), + of_trait: Some(of_trait), items: [child], self_ty, .. }) = item.kind && !cx.tcx.is_automatically_derived(item.owner_id.to_def_id()) && !item.span.from_expansion() - && let Some(def_id) = trait_ref.trait_def_id() + && let Some(def_id) = of_trait.trait_ref.trait_def_id() && cx.tcx.is_diagnostic_item(sym::Default, def_id) && let impl_item_hir = child.hir_id() && let Node::ImplItem(impl_item) = cx.tcx.hir_node(impl_item_hir) diff --git a/src/tools/clippy/clippy_lints/src/derive.rs b/src/tools/clippy/clippy_lints/src/derive.rs index 49dd1bb09c6..c53a957f6a8 100644 --- a/src/tools/clippy/clippy_lints/src/derive.rs +++ b/src/tools/clippy/clippy_lints/src/derive.rs @@ -201,10 +201,11 @@ declare_lint_pass!(Derive => [ impl<'tcx> LateLintPass<'tcx> for Derive { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if let ItemKind::Impl(Impl { - of_trait: Some(trait_ref), + of_trait: Some(of_trait), .. }) = item.kind { + let trait_ref = &of_trait.trait_ref; let ty = cx.tcx.type_of(item.owner_id).instantiate_identity(); let is_automatically_derived = cx.tcx.is_automatically_derived(item.owner_id.to_def_id()); diff --git a/src/tools/clippy/clippy_lints/src/empty_drop.rs b/src/tools/clippy/clippy_lints/src/empty_drop.rs index 4e948701da4..2b822188434 100644 --- a/src/tools/clippy/clippy_lints/src/empty_drop.rs +++ b/src/tools/clippy/clippy_lints/src/empty_drop.rs @@ -36,11 +36,11 @@ declare_lint_pass!(EmptyDrop => [EMPTY_DROP]); impl LateLintPass<'_> for EmptyDrop { fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) { if let ItemKind::Impl(Impl { - of_trait: Some(trait_ref), + of_trait: Some(of_trait), items: [child], .. }) = item.kind - && trait_ref.trait_def_id() == cx.tcx.lang_items().drop_trait() + && of_trait.trait_ref.trait_def_id() == cx.tcx.lang_items().drop_trait() && let impl_item_hir = child.hir_id() && let Node::ImplItem(impl_item) = cx.tcx.hir_node(impl_item_hir) && let ImplItemKind::Fn(_, b) = &impl_item.kind diff --git a/src/tools/clippy/clippy_lints/src/error_impl_error.rs b/src/tools/clippy/clippy_lints/src/error_impl_error.rs index 6525648efb1..3018e1f1273 100644 --- a/src/tools/clippy/clippy_lints/src/error_impl_error.rs +++ b/src/tools/clippy/clippy_lints/src/error_impl_error.rs @@ -52,7 +52,7 @@ impl<'tcx> LateLintPass<'tcx> for ErrorImplError { ); }, ItemKind::Impl(imp) - if let Some(trait_def_id) = imp.of_trait.and_then(|t| t.trait_def_id()) + if let Some(trait_def_id) = imp.of_trait.and_then(|t| t.trait_ref.trait_def_id()) && let Some(error_def_id) = cx.tcx.get_diagnostic_item(sym::Error) && error_def_id == trait_def_id && let Some(def_id) = path_res(cx, imp.self_ty).opt_def_id().and_then(DefId::as_local) diff --git a/src/tools/clippy/clippy_lints/src/format_impl.rs b/src/tools/clippy/clippy_lints/src/format_impl.rs index 0535ecf5240..416aea51ea1 100644 --- a/src/tools/clippy/clippy_lints/src/format_impl.rs +++ b/src/tools/clippy/clippy_lints/src/format_impl.rs @@ -254,10 +254,10 @@ fn is_format_trait_impl(cx: &LateContext<'_>, impl_item: &ImplItem<'_>) -> Optio if impl_item.ident.name == sym::fmt && let ImplItemKind::Fn(_, body_id) = impl_item.kind && let Some(Impl { - of_trait: Some(trait_ref), + of_trait: Some(of_trait), .. }) = get_parent_as_impl(cx.tcx, impl_item.hir_id()) - && let Some(did) = trait_ref.trait_def_id() + && let Some(did) = of_trait.trait_ref.trait_def_id() && let Some(name) = cx.tcx.get_diagnostic_name(did) && matches!(name, sym::Debug | sym::Display) { diff --git a/src/tools/clippy/clippy_lints/src/from_over_into.rs b/src/tools/clippy/clippy_lints/src/from_over_into.rs index 1da6952eb64..e3bb5ee10db 100644 --- a/src/tools/clippy/clippy_lints/src/from_over_into.rs +++ b/src/tools/clippy/clippy_lints/src/from_over_into.rs @@ -67,12 +67,12 @@ impl_lint_pass!(FromOverInto => [FROM_OVER_INTO]); impl<'tcx> LateLintPass<'tcx> for FromOverInto { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if let ItemKind::Impl(Impl { - of_trait: Some(hir_trait_ref), + of_trait: Some(of_trait), self_ty, items: [impl_item_ref], .. }) = item.kind - && let Some(into_trait_seg) = hir_trait_ref.path.segments.last() + && let Some(into_trait_seg) = of_trait.trait_ref.path.segments.last() // `impl Into<target_ty> for self_ty` && let Some(GenericArgs { args: [GenericArg::Type(target_ty)], .. }) = into_trait_seg.args && span_is_local(item.span) diff --git a/src/tools/clippy/clippy_lints/src/functions/impl_trait_in_params.rs b/src/tools/clippy/clippy_lints/src/functions/impl_trait_in_params.rs index cb83b1395d2..3105e303ae3 100644 --- a/src/tools/clippy/clippy_lints/src/functions/impl_trait_in_params.rs +++ b/src/tools/clippy/clippy_lints/src/functions/impl_trait_in_params.rs @@ -54,8 +54,7 @@ pub(super) fn check_impl_item(cx: &LateContext<'_>, impl_item: &ImplItem<'_>) { if let ImplItemKind::Fn(_, body_id) = impl_item.kind && let hir::Node::Item(item) = cx.tcx.parent_hir_node(impl_item.hir_id()) && let hir::ItemKind::Impl(impl_) = item.kind - && let hir::Impl { of_trait, .. } = *impl_ - && of_trait.is_none() + && let hir::Impl { of_trait: None, .. } = impl_ && let body = cx.tcx.hir_body(body_id) && cx.tcx.visibility(cx.tcx.hir_body_owner_def_id(body.id())).is_public() && !is_in_test(cx.tcx, impl_item.hir_id()) diff --git a/src/tools/clippy/clippy_lints/src/functions/renamed_function_params.rs b/src/tools/clippy/clippy_lints/src/functions/renamed_function_params.rs index 0d6191f2c97..0a7c6e9d5f8 100644 --- a/src/tools/clippy/clippy_lints/src/functions/renamed_function_params.rs +++ b/src/tools/clippy/clippy_lints/src/functions/renamed_function_params.rs @@ -15,11 +15,11 @@ pub(super) fn check_impl_item(cx: &LateContext<'_>, item: &ImplItem<'_>, ignored && let parent_node = cx.tcx.parent_hir_node(item.hir_id()) && let Node::Item(parent_item) = parent_node && let ItemKind::Impl(Impl { - of_trait: Some(trait_ref), + of_trait: Some(of_trait), .. }) = &parent_item.kind && let Some(did) = trait_item_def_id_of_impl(cx, item.owner_id) - && !is_from_ignored_trait(trait_ref, ignored_traits) + && !is_from_ignored_trait(&of_trait.trait_ref, ignored_traits) { let mut param_idents_iter = cx.tcx.hir_body_param_idents(body_id); let mut default_param_idents_iter = cx.tcx.fn_arg_idents(did).iter().copied(); diff --git a/src/tools/clippy/clippy_lints/src/impl_hash_with_borrow_str_and_bytes.rs b/src/tools/clippy/clippy_lints/src/impl_hash_with_borrow_str_and_bytes.rs index 940adbae428..f73182d3af0 100644 --- a/src/tools/clippy/clippy_lints/src/impl_hash_with_borrow_str_and_bytes.rs +++ b/src/tools/clippy/clippy_lints/src/impl_hash_with_borrow_str_and_bytes.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::ty::implements_trait; use rustc_hir::def::{DefKind, Res}; -use rustc_hir::{Item, ItemKind, Path, TraitRef}; +use rustc_hir::{Item, ItemKind}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::Ty; use rustc_session::declare_lint_pass; @@ -76,10 +76,10 @@ impl LateLintPass<'_> for ImplHashWithBorrowStrBytes { /// three of `Hash`, `Borrow<str>` and `Borrow<[u8]>`. fn check_item(&mut self, cx: &LateContext<'_>, item: &Item<'_>) { if let ItemKind::Impl(imp) = item.kind - && let Some(TraitRef {path: Path {span, res, ..}, ..}) = imp.of_trait + && let Some(of_trait) = imp.of_trait && let ty = cx.tcx.type_of(item.owner_id).instantiate_identity() && let Some(hash_id) = cx.tcx.get_diagnostic_item(sym::Hash) - && Res::Def(DefKind::Trait, hash_id) == *res + && Res::Def(DefKind::Trait, hash_id) == of_trait.trait_ref.path.res && let Some(borrow_id) = cx.tcx.get_diagnostic_item(sym::Borrow) // since we are in the `Hash` impl, we don't need to check for that. // we need only to check for `Borrow<str>` and `Borrow<[u8]>` @@ -89,7 +89,7 @@ impl LateLintPass<'_> for ImplHashWithBorrowStrBytes { span_lint_and_then( cx, IMPL_HASH_BORROW_WITH_STR_AND_BYTES, - *span, + of_trait.trait_ref.path.span, "the semantics of `Borrow<T>` around `Hash` can't be satisfied when both `Borrow<str>` and `Borrow<[u8]>` are implemented", |diag| { diag.note("the `Borrow` semantics require that `Hash` must behave the same for all implementations of Borrow<T>"); diff --git a/src/tools/clippy/clippy_lints/src/infallible_try_from.rs b/src/tools/clippy/clippy_lints/src/infallible_try_from.rs index 589c294a678..36df07a4370 100644 --- a/src/tools/clippy/clippy_lints/src/infallible_try_from.rs +++ b/src/tools/clippy/clippy_lints/src/infallible_try_from.rs @@ -45,8 +45,8 @@ declare_lint_pass!(InfallibleTryFrom => [INFALLIBLE_TRY_FROM]); impl<'tcx> LateLintPass<'tcx> for InfallibleTryFrom { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { let ItemKind::Impl(imp) = item.kind else { return }; - let Some(r#trait) = imp.of_trait else { return }; - let Some(trait_def_id) = r#trait.trait_def_id() else { + let Some(of_trait) = imp.of_trait else { return }; + let Some(trait_def_id) = of_trait.trait_ref.trait_def_id() else { return; }; if !cx.tcx.is_diagnostic_item(sym::TryFrom, trait_def_id) { diff --git a/src/tools/clippy/clippy_lints/src/iter_without_into_iter.rs b/src/tools/clippy/clippy_lints/src/iter_without_into_iter.rs index b89f91f7255..645e0f981f2 100644 --- a/src/tools/clippy/clippy_lints/src/iter_without_into_iter.rs +++ b/src/tools/clippy/clippy_lints/src/iter_without_into_iter.rs @@ -125,8 +125,9 @@ impl LateLintPass<'_> for IterWithoutIntoIter { fn check_item(&mut self, cx: &LateContext<'_>, item: &rustc_hir::Item<'_>) { if let ItemKind::Impl(imp) = item.kind && let TyKind::Ref(_, self_ty_without_ref) = &imp.self_ty.kind - && let Some(trait_ref) = imp.of_trait - && trait_ref + && let Some(of_trait) = imp.of_trait + && of_trait + .trait_ref .trait_def_id() .is_some_and(|did| cx.tcx.is_diagnostic_item(sym::IntoIterator, did)) && !item.span.in_external_macro(cx.sess().source_map()) diff --git a/src/tools/clippy/clippy_lints/src/lifetimes.rs b/src/tools/clippy/clippy_lints/src/lifetimes.rs index 35c9d2fd4eb..149ae5e710c 100644 --- a/src/tools/clippy/clippy_lints/src/lifetimes.rs +++ b/src/tools/clippy/clippy_lints/src/lifetimes.rs @@ -150,7 +150,7 @@ impl<'tcx> LateLintPass<'tcx> for Lifetimes { } = item.kind { check_fn_inner(cx, sig, Some(id), None, generics, item.span, true, self.msrv); - } else if let ItemKind::Impl(impl_) = item.kind + } else if let ItemKind::Impl(impl_) = &item.kind && !item.span.from_expansion() { report_extra_impl_lifetimes(cx, impl_); @@ -712,8 +712,8 @@ fn report_extra_impl_lifetimes<'tcx>(cx: &LateContext<'tcx>, impl_: &'tcx Impl<' let mut checker = LifetimeChecker::<middle_nested_filter::All>::new(cx, impl_.generics); walk_generics(&mut checker, impl_.generics); - if let Some(ref trait_ref) = impl_.of_trait { - walk_trait_ref(&mut checker, trait_ref); + if let Some(of_trait) = impl_.of_trait { + walk_trait_ref(&mut checker, &of_trait.trait_ref); } walk_unambig_ty(&mut checker, impl_.self_ty); for &item in impl_.items { diff --git a/src/tools/clippy/clippy_lints/src/missing_fields_in_debug.rs b/src/tools/clippy/clippy_lints/src/missing_fields_in_debug.rs index 18e2b384a46..8822b32b1c3 100644 --- a/src/tools/clippy/clippy_lints/src/missing_fields_in_debug.rs +++ b/src/tools/clippy/clippy_lints/src/missing_fields_in_debug.rs @@ -198,8 +198,8 @@ fn check_struct<'tcx>( impl<'tcx> LateLintPass<'tcx> for MissingFieldsInDebug { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'tcx>) { // is this an `impl Debug for X` block? - if let ItemKind::Impl(Impl { of_trait: Some(trait_ref), self_ty, .. }) = item.kind - && let Res::Def(DefKind::Trait, trait_def_id) = trait_ref.path.res + if let ItemKind::Impl(Impl { of_trait: Some(of_trait), self_ty, .. }) = item.kind + && let Res::Def(DefKind::Trait, trait_def_id) = of_trait.trait_ref.path.res && let TyKind::Path(QPath::Resolved(_, self_path)) = &self_ty.kind // make sure that the self type is either a struct, an enum or a union // this prevents ICEs such as when self is a type parameter or a primitive type diff --git a/src/tools/clippy/clippy_lints/src/missing_inline.rs b/src/tools/clippy/clippy_lints/src/missing_inline.rs index d02952eb487..b16924babd1 100644 --- a/src/tools/clippy/clippy_lints/src/missing_inline.rs +++ b/src/tools/clippy/clippy_lints/src/missing_inline.rs @@ -190,5 +190,5 @@ impl<'tcx> LateLintPass<'tcx> for MissingInline { /// and a rustc warning would be triggered, see #15301 fn fn_is_externally_exported(cx: &LateContext<'_>, def_id: DefId) -> bool { let attrs = cx.tcx.codegen_fn_attrs(def_id); - attrs.contains_extern_indicator() + attrs.contains_extern_indicator(cx.tcx, def_id) } diff --git a/src/tools/clippy/clippy_lints/src/missing_trait_methods.rs b/src/tools/clippy/clippy_lints/src/missing_trait_methods.rs index 399bf4e1806..9cc93bf0653 100644 --- a/src/tools/clippy/clippy_lints/src/missing_trait_methods.rs +++ b/src/tools/clippy/clippy_lints/src/missing_trait_methods.rs @@ -61,10 +61,10 @@ impl<'tcx> LateLintPass<'tcx> for MissingTraitMethods { if !is_lint_allowed(cx, MISSING_TRAIT_METHODS, item.hir_id()) && span_is_local(item.span) && let ItemKind::Impl(Impl { - of_trait: Some(trait_ref), + of_trait: Some(of_trait), .. }) = item.kind - && let Some(trait_id) = trait_ref.trait_def_id() + && let Some(trait_id) = of_trait.trait_ref.trait_def_id() { let trait_item_ids: DefIdSet = cx .tcx diff --git a/src/tools/clippy/clippy_lints/src/non_copy_const.rs b/src/tools/clippy/clippy_lints/src/non_copy_const.rs index 388c029c9ef..8a5a6f4a4dc 100644 --- a/src/tools/clippy/clippy_lints/src/non_copy_const.rs +++ b/src/tools/clippy/clippy_lints/src/non_copy_const.rs @@ -778,7 +778,7 @@ impl<'tcx> LateLintPass<'tcx> for NonCopyConst<'tcx> { if let Node::Item(parent_item) = cx.tcx.parent_hir_node(item.hir_id()) && let ItemKind::Impl(impl_block) = parent_item.kind && let Some(of_trait) = impl_block.of_trait - && let Some(trait_id) = of_trait.trait_def_id() + && let Some(trait_id) = of_trait.trait_ref.trait_def_id() { // Replace all instances of `<Self as Trait>::AssocType` with the // unit type and check again. If the result is the same then the diff --git a/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs b/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs index 8ff78ec7c58..b810bc01fbd 100644 --- a/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs +++ b/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs @@ -83,10 +83,10 @@ impl<'tcx> LateLintPass<'tcx> for NonSendFieldInSendTy { if !item.span.in_external_macro(cx.tcx.sess.source_map()) && let Some(send_trait) = cx.tcx.get_diagnostic_item(sym::Send) && let ItemKind::Impl(hir_impl) = &item.kind - && let Some(trait_ref) = &hir_impl.of_trait - && let Some(trait_id) = trait_ref.trait_def_id() + && let Some(of_trait) = &hir_impl.of_trait + && let Some(trait_id) = of_trait.trait_ref.trait_def_id() && send_trait == trait_id - && hir_impl.polarity == ImplPolarity::Positive + && of_trait.polarity == ImplPolarity::Positive && let Some(ty_trait_ref) = cx.tcx.impl_trait_ref(item.owner_id) && let self_ty = ty_trait_ref.instantiate_identity().self_ty() && let ty::Adt(adt_def, impl_trait_args) = self_ty.kind() diff --git a/src/tools/clippy/clippy_lints/src/operators/assign_op_pattern.rs b/src/tools/clippy/clippy_lints/src/operators/assign_op_pattern.rs index 9c6141d8222..7317c62df7f 100644 --- a/src/tools/clippy/clippy_lints/src/operators/assign_op_pattern.rs +++ b/src/tools/clippy/clippy_lints/src/operators/assign_op_pattern.rs @@ -1,6 +1,5 @@ use clippy_utils::diagnostics::span_lint_and_then; use clippy_utils::msrvs::Msrv; -use clippy_utils::qualify_min_const_fn::is_stable_const_fn; use clippy_utils::source::SpanRangeExt; use clippy_utils::ty::implements_trait; use clippy_utils::visitors::for_each_expr_without_closures; @@ -21,7 +20,7 @@ pub(super) fn check<'tcx>( expr: &'tcx hir::Expr<'_>, assignee: &'tcx hir::Expr<'_>, e: &'tcx hir::Expr<'_>, - msrv: Msrv, + _msrv: Msrv, ) { if let hir::ExprKind::Binary(op, l, r) = &e.kind { let lint = |assignee: &hir::Expr<'_>, rhs: &hir::Expr<'_>| { @@ -45,10 +44,8 @@ pub(super) fn check<'tcx>( } // Skip if the trait is not stable in const contexts - if is_in_const_context(cx) - && let Some(binop_id) = cx.tcx.associated_item_def_ids(trait_id).first() - && !is_stable_const_fn(cx, *binop_id, msrv) - { + // FIXME: reintroduce a better check after this is merged back into Clippy + if is_in_const_context(cx) { return; } diff --git a/src/tools/clippy/clippy_lints/src/operators/op_ref.rs b/src/tools/clippy/clippy_lints/src/operators/op_ref.rs index 0a1f2625f4c..9c160ff680e 100644 --- a/src/tools/clippy/clippy_lints/src/operators/op_ref.rs +++ b/src/tools/clippy/clippy_lints/src/operators/op_ref.rs @@ -183,7 +183,7 @@ fn in_impl<'tcx>( && let item = cx.tcx.hir_expect_item(impl_def_id.expect_local()) && let ItemKind::Impl(item) = &item.kind && let Some(of_trait) = &item.of_trait - && let Some(seg) = of_trait.path.segments.last() + && let Some(seg) = of_trait.trait_ref.path.segments.last() && let Res::Def(_, trait_id) = seg.res && trait_id == bin_op && let Some(generic_args) = seg.args diff --git a/src/tools/clippy/clippy_lints/src/partialeq_ne_impl.rs b/src/tools/clippy/clippy_lints/src/partialeq_ne_impl.rs index 301b2cd4bf2..77751e75a8e 100644 --- a/src/tools/clippy/clippy_lints/src/partialeq_ne_impl.rs +++ b/src/tools/clippy/clippy_lints/src/partialeq_ne_impl.rs @@ -34,15 +34,15 @@ declare_lint_pass!(PartialEqNeImpl => [PARTIALEQ_NE_IMPL]); impl<'tcx> LateLintPass<'tcx> for PartialEqNeImpl { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if let ItemKind::Impl(Impl { - of_trait: Some(trait_ref), + of_trait: Some(of_trait), items: impl_items, .. }) = item.kind && !cx.tcx.is_automatically_derived(item.owner_id.to_def_id()) && let Some(eq_trait) = cx.tcx.lang_items().eq_trait() - && trait_ref.path.res.def_id() == eq_trait + && of_trait.trait_ref.path.res.def_id() == eq_trait { - for impl_item in *impl_items { + for impl_item in impl_items { if cx.tcx.item_name(impl_item.owner_id) == sym::ne { span_lint_hir( cx, diff --git a/src/tools/clippy/clippy_lints/src/same_name_method.rs b/src/tools/clippy/clippy_lints/src/same_name_method.rs index 67eb71f7d07..b87751f4986 100644 --- a/src/tools/clippy/clippy_lints/src/same_name_method.rs +++ b/src/tools/clippy/clippy_lints/src/same_name_method.rs @@ -68,9 +68,9 @@ impl<'tcx> LateLintPass<'tcx> for SameNameMethod { let existing_name = map.get_mut(res).unwrap(); match of_trait { - Some(trait_ref) => { + Some(of_trait) => { let mut methods_in_trait: BTreeSet<Symbol> = if let Node::TraitRef(TraitRef { path, .. }) = - cx.tcx.hir_node(trait_ref.hir_ref_id) + cx.tcx.hir_node(of_trait.trait_ref.hir_ref_id) && let Res::Def(DefKind::Trait, did) = path.res { // FIXME: if diff --git a/src/tools/clippy/clippy_lints/src/serde_api.rs b/src/tools/clippy/clippy_lints/src/serde_api.rs index 2de22e4b6a3..01c7f394b9a 100644 --- a/src/tools/clippy/clippy_lints/src/serde_api.rs +++ b/src/tools/clippy/clippy_lints/src/serde_api.rs @@ -26,16 +26,16 @@ declare_lint_pass!(SerdeApi => [SERDE_API_MISUSE]); impl<'tcx> LateLintPass<'tcx> for SerdeApi { fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx Item<'_>) { if let ItemKind::Impl(Impl { - of_trait: Some(trait_ref), + of_trait: Some(of_trait), items, .. }) = item.kind { - let did = trait_ref.path.res.def_id(); + let did = of_trait.trait_ref.path.res.def_id(); if paths::SERDE_DE_VISITOR.matches(cx, did) { let mut seen_str = None; let mut seen_string = None; - for item in *items { + for item in items { match cx.tcx.item_name(item.owner_id) { sym::visit_str => seen_str = Some(cx.tcx.def_span(item.owner_id)), sym::visit_string => seen_string = Some(cx.tcx.def_span(item.owner_id)), diff --git a/src/tools/clippy/clippy_lints/src/single_component_path_imports.rs b/src/tools/clippy/clippy_lints/src/single_component_path_imports.rs index 38cf7e3822a..07a8eb5d886 100644 --- a/src/tools/clippy/clippy_lints/src/single_component_path_imports.rs +++ b/src/tools/clippy/clippy_lints/src/single_component_path_imports.rs @@ -1,6 +1,5 @@ use clippy_utils::diagnostics::{span_lint_and_help, span_lint_and_sugg}; use rustc_ast::node_id::{NodeId, NodeMap}; -use rustc_ast::ptr::P; use rustc_ast::visit::{Visitor, walk_expr}; use rustc_ast::{Crate, Expr, ExprKind, Item, ItemKind, MacroDef, ModKind, Ty, TyKind, UseTreeKind}; use rustc_errors::Applicability; @@ -124,7 +123,7 @@ impl Visitor<'_> for ImportUsageVisitor { } impl SingleComponentPathImports { - fn check_mod(&mut self, items: &[P<Item>]) { + fn check_mod(&mut self, items: &[Box<Item>]) { // keep track of imports reused with `self` keyword, such as `self::crypto_hash` in the example // below. Removing the `use crypto_hash;` would make this a compile error // ``` diff --git a/src/tools/clippy/clippy_lints/src/to_string_trait_impl.rs b/src/tools/clippy/clippy_lints/src/to_string_trait_impl.rs index 9596b85664b..303f6028bd5 100644 --- a/src/tools/clippy/clippy_lints/src/to_string_trait_impl.rs +++ b/src/tools/clippy/clippy_lints/src/to_string_trait_impl.rs @@ -48,10 +48,10 @@ declare_lint_pass!(ToStringTraitImpl => [TO_STRING_TRAIT_IMPL]); impl<'tcx> LateLintPass<'tcx> for ToStringTraitImpl { fn check_item(&mut self, cx: &LateContext<'tcx>, it: &'tcx Item<'tcx>) { if let ItemKind::Impl(Impl { - of_trait: Some(trait_ref), + of_trait: Some(of_trait), .. }) = it.kind - && let Some(trait_did) = trait_ref.trait_def_id() + && let Some(trait_did) = of_trait.trait_ref.trait_def_id() && cx.tcx.is_diagnostic_item(sym::ToString, trait_did) { span_lint_and_help( diff --git a/src/tools/clippy/clippy_lints/src/unconditional_recursion.rs b/src/tools/clippy/clippy_lints/src/unconditional_recursion.rs index dcddff557d1..e843e169113 100644 --- a/src/tools/clippy/clippy_lints/src/unconditional_recursion.rs +++ b/src/tools/clippy/clippy_lints/src/unconditional_recursion.rs @@ -137,9 +137,9 @@ fn get_impl_trait_def_id(cx: &LateContext<'_>, method_def_id: LocalDefId) -> Opt // We exclude `impl` blocks generated from rustc's proc macros. && !cx.tcx.is_automatically_derived(owner_id.to_def_id()) // It is a implementation of a trait. - && let Some(trait_) = impl_.of_trait + && let Some(of_trait) = impl_.of_trait { - trait_.trait_def_id() + of_trait.trait_ref.trait_def_id() } else { None } @@ -242,8 +242,8 @@ fn check_to_string(cx: &LateContext<'_>, method_span: Span, method_def_id: Local // We exclude `impl` blocks generated from rustc's proc macros. && !cx.tcx.is_automatically_derived(owner_id.to_def_id()) // It is a implementation of a trait. - && let Some(trait_) = impl_.of_trait - && let Some(trait_def_id) = trait_.trait_def_id() + && let Some(of_trait) = impl_.of_trait + && let Some(trait_def_id) = of_trait.trait_ref.trait_def_id() // The trait is `ToString`. && cx.tcx.is_diagnostic_item(sym::ToString, trait_def_id) { diff --git a/src/tools/clippy/clippy_lints/src/undocumented_unsafe_blocks.rs b/src/tools/clippy/clippy_lints/src/undocumented_unsafe_blocks.rs index cf603c6190b..1c52de52619 100644 --- a/src/tools/clippy/clippy_lints/src/undocumented_unsafe_blocks.rs +++ b/src/tools/clippy/clippy_lints/src/undocumented_unsafe_blocks.rs @@ -8,7 +8,7 @@ use clippy_utils::source::walk_span_to_context; use clippy_utils::visitors::{Descend, for_each_expr}; use hir::HirId; use rustc_hir as hir; -use rustc_hir::{Block, BlockCheckMode, ItemKind, Node, UnsafeSource}; +use rustc_hir::{Block, BlockCheckMode, Impl, ItemKind, Node, UnsafeSource}; use rustc_lexer::{FrontmatterAllowed, TokenKind, tokenize}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::impl_lint_pass; @@ -204,7 +204,7 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks { let item_has_safety_comment = item_has_safety_comment(cx, item); match (&item.kind, item_has_safety_comment) { // lint unsafe impl without safety comment - (ItemKind::Impl(impl_), HasSafetyComment::No) if impl_.safety.is_unsafe() => { + (ItemKind::Impl(Impl { of_trait: Some(of_trait), .. }), HasSafetyComment::No) if of_trait.safety.is_unsafe() => { if !is_lint_allowed(cx, UNDOCUMENTED_UNSAFE_BLOCKS, item.hir_id()) && !is_unsafe_from_proc_macro(cx, item.span) { @@ -228,7 +228,7 @@ impl<'tcx> LateLintPass<'tcx> for UndocumentedUnsafeBlocks { } }, // lint safe impl with unnecessary safety comment - (ItemKind::Impl(impl_), HasSafetyComment::Yes(pos)) if impl_.safety.is_safe() => { + (ItemKind::Impl(Impl { of_trait: Some(of_trait), .. }), HasSafetyComment::Yes(pos)) if of_trait.safety.is_safe() => { if !is_lint_allowed(cx, UNNECESSARY_SAFETY_COMMENT, item.hir_id()) { let (span, help_span) = mk_spans(pos); diff --git a/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs b/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs index bd8420917f5..e9ad578da2f 100644 --- a/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs +++ b/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs @@ -7,13 +7,14 @@ use clippy_utils::msrvs::{self, MsrvStack}; use clippy_utils::over; use rustc_ast::PatKind::*; use rustc_ast::mut_visit::*; -use rustc_ast::ptr::P; use rustc_ast::{self as ast, DUMMY_NODE_ID, Mutability, Pat, PatKind}; use rustc_ast_pretty::pprust; use rustc_errors::Applicability; use rustc_lint::{EarlyContext, EarlyLintPass}; use rustc_session::impl_lint_pass; use rustc_span::DUMMY_SP; +// import needed to shadow `PatKind::Box` glob-imported above +use std::boxed::Box; use std::cell::Cell; use std::mem; use thin_vec::{ThinVec, thin_vec}; @@ -97,7 +98,7 @@ fn lint_unnested_or_patterns(cx: &EarlyContext<'_>, pat: &Pat) { return; } - let mut pat = P(pat.clone()); + let mut pat = Box::new(pat.clone()); // Nix all the paren patterns everywhere so that they aren't in our way. remove_all_parens(&mut pat); @@ -119,7 +120,7 @@ fn lint_unnested_or_patterns(cx: &EarlyContext<'_>, pat: &Pat) { } /// Remove all `(p)` patterns in `pat`. -fn remove_all_parens(pat: &mut P<Pat>) { +fn remove_all_parens(pat: &mut Box<Pat>) { #[derive(Default)] struct Visitor { /// If is not in the outer most pattern. This is needed to avoid removing the outermost @@ -142,7 +143,7 @@ fn remove_all_parens(pat: &mut P<Pat>) { } /// Insert parens where necessary according to Rust's precedence rules for patterns. -fn insert_necessary_parens(pat: &mut P<Pat>) { +fn insert_necessary_parens(pat: &mut Box<Pat>) { struct Visitor; impl MutVisitor for Visitor { fn visit_pat(&mut self, pat: &mut Pat) { @@ -154,7 +155,7 @@ fn insert_necessary_parens(pat: &mut P<Pat>) { Ref(p, Mutability::Not) if matches!(p.kind, Ident(BindingMode::MUT, ..)) => p, // `&(mut x)` _ => return, }; - target.kind = Paren(P(take_pat(target))); + target.kind = Paren(Box::new(take_pat(target))); } } Visitor.visit_pat(pat); @@ -162,7 +163,7 @@ fn insert_necessary_parens(pat: &mut P<Pat>) { /// Unnest or-patterns `p0 | ... | p1` in the pattern `pat`. /// For example, this would transform `Some(0) | FOO | Some(2)` into `Some(0 | 2) | FOO`. -fn unnest_or_patterns(pat: &mut P<Pat>) -> bool { +fn unnest_or_patterns(pat: &mut Box<Pat>) -> bool { struct Visitor { changed: bool, } @@ -222,7 +223,7 @@ macro_rules! always_pat { /// Focus on `focus_idx` in `alternatives`, /// attempting to extend it with elements of the same constructor `C` /// in `alternatives[focus_idx + 1..]`. -fn transform_with_focus_on_idx(alternatives: &mut ThinVec<P<Pat>>, focus_idx: usize) -> bool { +fn transform_with_focus_on_idx(alternatives: &mut ThinVec<Box<Pat>>, focus_idx: usize) -> bool { // Extract the kind; we'll need to make some changes in it. let mut focus_kind = mem::replace(&mut alternatives[focus_idx].kind, Wild); // We'll focus on `alternatives[focus_idx]`, @@ -303,12 +304,12 @@ fn transform_with_focus_on_idx(alternatives: &mut ThinVec<P<Pat>>, focus_idx: us /// So when we fixate on some `ident_k: pat_k`, we try to find `ident_k` in the other pattern /// and check that all `fp_i` where `i ∈ ((0...n) \ k)` between two patterns are equal. fn extend_with_struct_pat( - qself1: Option<&P<ast::QSelf>>, + qself1: Option<&Box<ast::QSelf>>, path1: &ast::Path, fps1: &mut [ast::PatField], rest1: ast::PatFieldsRest, start: usize, - alternatives: &mut ThinVec<P<Pat>>, + alternatives: &mut ThinVec<Box<Pat>>, ) -> bool { (0..fps1.len()).any(|idx| { let pos_in_2 = Cell::new(None); // The element `k`. @@ -346,11 +347,11 @@ fn extend_with_struct_pat( /// while also requiring `ps1[..n] ~ ps2[..n]` (pre) and `ps1[n + 1..] ~ ps2[n + 1..]` (post), /// where `~` denotes semantic equality. fn extend_with_matching_product( - targets: &mut [P<Pat>], + targets: &mut [Box<Pat>], start: usize, - alternatives: &mut ThinVec<P<Pat>>, - predicate: impl Fn(&PatKind, &[P<Pat>], usize) -> bool, - extract: impl Fn(PatKind) -> ThinVec<P<Pat>>, + alternatives: &mut ThinVec<Box<Pat>>, + predicate: impl Fn(&PatKind, &[Box<Pat>], usize) -> bool, + extract: impl Fn(PatKind) -> ThinVec<Box<Pat>>, ) -> bool { (0..targets.len()).any(|idx| { let tail_or = drain_matching( @@ -377,14 +378,14 @@ fn take_pat(from: &mut Pat) -> Pat { /// Extend `target` as an or-pattern with the alternatives /// in `tail_or` if there are any and return if there were. -fn extend_with_tail_or(target: &mut Pat, tail_or: ThinVec<P<Pat>>) -> bool { - fn extend(target: &mut Pat, mut tail_or: ThinVec<P<Pat>>) { +fn extend_with_tail_or(target: &mut Pat, tail_or: ThinVec<Box<Pat>>) -> bool { + fn extend(target: &mut Pat, mut tail_or: ThinVec<Box<Pat>>) { match target { // On an existing or-pattern in the target, append to it. Pat { kind: Or(ps), .. } => ps.append(&mut tail_or), // Otherwise convert the target to an or-pattern. target => { - let mut init_or = thin_vec![P(take_pat(target))]; + let mut init_or = thin_vec![Box::new(take_pat(target))]; init_or.append(&mut tail_or); target.kind = Or(init_or); }, @@ -403,10 +404,10 @@ fn extend_with_tail_or(target: &mut Pat, tail_or: ThinVec<P<Pat>>) -> bool { // Only elements beginning with `start` are considered for extraction. fn drain_matching( start: usize, - alternatives: &mut ThinVec<P<Pat>>, + alternatives: &mut ThinVec<Box<Pat>>, predicate: impl Fn(&PatKind) -> bool, - extract: impl Fn(PatKind) -> P<Pat>, -) -> ThinVec<P<Pat>> { + extract: impl Fn(PatKind) -> Box<Pat>, +) -> ThinVec<Box<Pat>> { let mut tail_or = ThinVec::new(); let mut idx = 0; @@ -438,15 +439,15 @@ fn drain_matching( fn extend_with_matching( target: &mut Pat, start: usize, - alternatives: &mut ThinVec<P<Pat>>, + alternatives: &mut ThinVec<Box<Pat>>, predicate: impl Fn(&PatKind) -> bool, - extract: impl Fn(PatKind) -> P<Pat>, + extract: impl Fn(PatKind) -> Box<Pat>, ) -> bool { extend_with_tail_or(target, drain_matching(start, alternatives, predicate, extract)) } /// Are the patterns in `ps1` and `ps2` equal save for `ps1[idx]` compared to `ps2[idx]`? -fn eq_pre_post(ps1: &[P<Pat>], ps2: &[P<Pat>], idx: usize) -> bool { +fn eq_pre_post(ps1: &[Box<Pat>], ps2: &[Box<Pat>], idx: usize) -> bool { ps1.len() == ps2.len() && ps1[idx].is_rest() == ps2[idx].is_rest() // Avoid `[x, ..] | [x, 0]` => `[x, .. | 0]`. && over(&ps1[..idx], &ps2[..idx], |l, r| eq_pat(l, r)) diff --git a/src/tools/clippy/clippy_lints/src/write.rs b/src/tools/clippy/clippy_lints/src/write.rs index d9a007635ca..a15e4e42e71 100644 --- a/src/tools/clippy/clippy_lints/src/write.rs +++ b/src/tools/clippy/clippy_lints/src/write.rs @@ -347,10 +347,10 @@ impl<'tcx> LateLintPass<'tcx> for Write { fn is_debug_impl(cx: &LateContext<'_>, item: &Item<'_>) -> bool { if let ItemKind::Impl(Impl { - of_trait: Some(trait_ref), + of_trait: Some(of_trait), .. }) = &item.kind - && let Some(trait_id) = trait_ref.trait_def_id() + && let Some(trait_id) = of_trait.trait_ref.trait_def_id() { cx.tcx.is_diagnostic_item(sym::Debug, trait_id) } else { diff --git a/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs b/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs index 96f0273c439..24e017f7cf7 100644 --- a/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs +++ b/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs @@ -5,7 +5,6 @@ #![allow(clippy::wildcard_imports, clippy::enum_glob_use)] use crate::{both, over}; -use rustc_ast::ptr::P; use rustc_ast::{self as ast, *}; use rustc_span::symbol::Ident; use std::mem; @@ -83,11 +82,11 @@ pub fn eq_field_pat(l: &PatField, r: &PatField) -> bool { && over(&l.attrs, &r.attrs, eq_attr) } -pub fn eq_qself(l: &P<QSelf>, r: &P<QSelf>) -> bool { +pub fn eq_qself(l: &Box<QSelf>, r: &Box<QSelf>) -> bool { l.position == r.position && eq_ty(&l.ty, &r.ty) } -pub fn eq_maybe_qself(l: Option<&P<QSelf>>, r: Option<&P<QSelf>>) -> bool { +pub fn eq_maybe_qself(l: Option<&Box<QSelf>>, r: Option<&Box<QSelf>>) -> bool { match (l, r) { (Some(l), Some(r)) => eq_qself(l, r), (None, None) => true, @@ -130,7 +129,7 @@ pub fn eq_generic_arg(l: &GenericArg, r: &GenericArg) -> bool { } } -pub fn eq_expr_opt(l: Option<&P<Expr>>, r: Option<&P<Expr>>) -> bool { +pub fn eq_expr_opt(l: Option<&Box<Expr>>, r: Option<&Box<Expr>>) -> bool { both(l, r, |l, r| eq_expr(l, r)) } @@ -474,33 +473,27 @@ pub fn eq_item_kind(l: &ItemKind, r: &ItemKind) -> bool { eq_id(*li, *ri) && eq_generics(lg, rg) && over(lb, rb, eq_generic_bound) }, ( - Impl(box ast::Impl { - safety: lu, - polarity: lp, - defaultness: ld, - constness: lc, + Impl(ast::Impl { generics: lg, of_trait: lot, self_ty: lst, items: li, }), - Impl(box ast::Impl { - safety: ru, - polarity: rp, - defaultness: rd, - constness: rc, + Impl(ast::Impl { generics: rg, of_trait: rot, self_ty: rst, items: ri, }), ) => { - matches!(lu, Safety::Default) == matches!(ru, Safety::Default) - && matches!(lp, ImplPolarity::Positive) == matches!(rp, ImplPolarity::Positive) - && eq_defaultness(*ld, *rd) - && matches!(lc, ast::Const::No) == matches!(rc, ast::Const::No) - && eq_generics(lg, rg) - && both(lot.as_ref(), rot.as_ref(), |l, r| eq_path(&l.path, &r.path)) + eq_generics(lg, rg) + && both(lot.as_deref(), rot.as_deref(), |l, r| { + matches!(l.safety, Safety::Default) == matches!(r.safety, Safety::Default) + && matches!(l.polarity, ImplPolarity::Positive) == matches!(r.polarity, ImplPolarity::Positive) + && eq_defaultness(l.defaultness, r.defaultness) + && matches!(l.constness, ast::Const::No) == matches!(r.constness, ast::Const::No) + && eq_path(&l.trait_ref.path, &r.trait_ref.path) + }) && eq_ty(lst, rst) && over(li, ri, |l, r| eq_item(l, r, eq_assoc_item_kind)) }, @@ -727,7 +720,7 @@ pub fn eq_fn_header(l: &FnHeader, r: &FnHeader) -> bool { } #[expect(clippy::ref_option, reason = "This is the type how it is stored in the AST")] -pub fn eq_opt_fn_contract(l: &Option<P<FnContract>>, r: &Option<P<FnContract>>) -> bool { +pub fn eq_opt_fn_contract(l: &Option<Box<FnContract>>, r: &Option<Box<FnContract>>) -> bool { match (l, r) { (Some(l), Some(r)) => { eq_expr_opt(l.requires.as_ref(), r.requires.as_ref()) && eq_expr_opt(l.ensures.as_ref(), r.ensures.as_ref()) diff --git a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs index dc31ed08fb7..e0c1b9d445a 100644 --- a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs +++ b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs @@ -19,8 +19,8 @@ use rustc_ast::token::CommentKind; use rustc_hir::intravisit::FnKind; use rustc_hir::{ Block, BlockCheckMode, Body, Closure, Destination, Expr, ExprKind, FieldDef, FnHeader, FnRetTy, HirId, Impl, - ImplItem, ImplItemKind, IsAuto, Item, ItemKind, Lit, LoopSource, MatchSource, MutTy, Node, Path, QPath, Safety, - TraitItem, TraitItemKind, Ty, TyKind, UnOp, UnsafeSource, Variant, VariantData, YieldSource, + ImplItem, ImplItemKind, TraitImplHeader, IsAuto, Item, ItemKind, Lit, LoopSource, MatchSource, MutTy, Node, Path, + QPath, Safety, TraitItem, TraitItemKind, Ty, TyKind, UnOp, UnsafeSource, Variant, VariantData, YieldSource, }; use rustc_lint::{EarlyContext, LateContext, LintContext}; use rustc_middle::ty::TyCtxt; @@ -254,7 +254,7 @@ fn item_search_pat(item: &Item<'_>) -> (Pat, Pat) { ItemKind::Union(..) => (Pat::Str("union"), Pat::Str("}")), ItemKind::Trait(_, _, Safety::Unsafe, ..) | ItemKind::Impl(Impl { - safety: Safety::Unsafe, .. + of_trait: Some(TraitImplHeader { safety: Safety::Unsafe, .. }), .. }) => (Pat::Str("unsafe"), Pat::Str("}")), ItemKind::Trait(_, IsAuto::Yes, ..) => (Pat::Str("auto"), Pat::Str("}")), ItemKind::Trait(..) => (Pat::Str("trait"), Pat::Str("}")), diff --git a/src/tools/clippy/clippy_utils/src/lib.rs b/src/tools/clippy/clippy_utils/src/lib.rs index fc716d86fc6..fcc120656e3 100644 --- a/src/tools/clippy/clippy_utils/src/lib.rs +++ b/src/tools/clippy/clippy_utils/src/lib.rs @@ -528,8 +528,9 @@ pub fn path_def_id<'tcx>(cx: &LateContext<'_>, maybe_path: &impl MaybePath<'tcx> pub fn trait_ref_of_method<'tcx>(cx: &LateContext<'tcx>, owner: OwnerId) -> Option<&'tcx TraitRef<'tcx>> { if let Node::Item(item) = cx.tcx.hir_node(cx.tcx.hir_owner_parent(owner)) && let ItemKind::Impl(impl_) = &item.kind + && let Some(of_trait) = impl_.of_trait { - return impl_.of_trait.as_ref(); + return Some(&of_trait.trait_ref); } None } diff --git a/src/tools/clippy/clippy_utils/src/visitors.rs b/src/tools/clippy/clippy_utils/src/visitors.rs index ba5cbc73836..c9f5401ebe7 100644 --- a/src/tools/clippy/clippy_utils/src/visitors.rs +++ b/src/tools/clippy/clippy_utils/src/visitors.rs @@ -460,7 +460,8 @@ pub fn is_expr_unsafe<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> bool { } fn visit_nested_item(&mut self, id: ItemId) -> Self::Result { if let ItemKind::Impl(i) = &self.cx.tcx.hir_item(id).kind - && i.safety.is_unsafe() + && let Some(of_trait) = i.of_trait + && of_trait.safety.is_unsafe() { ControlFlow::Break(()) } else { diff --git a/src/tools/clippy/tests/missing-test-files.rs b/src/tools/clippy/tests/missing-test-files.rs index 565dcd73f58..63f960c92fa 100644 --- a/src/tools/clippy/tests/missing-test-files.rs +++ b/src/tools/clippy/tests/missing-test-files.rs @@ -1,6 +1,6 @@ #![warn(rust_2018_idioms, unused_lifetimes)] #![allow(clippy::assertions_on_constants)] -#![feature(path_file_prefix)] +#![cfg_attr(bootstrap, feature(path_file_prefix))] use std::cmp::Ordering; use std::ffi::OsStr; diff --git a/src/tools/clippy/tests/ui/bool_assert_comparison.fixed b/src/tools/clippy/tests/ui/bool_assert_comparison.fixed index 721d8b2c2dc..ec76abbef05 100644 --- a/src/tools/clippy/tests/ui/bool_assert_comparison.fixed +++ b/src/tools/clippy/tests/ui/bool_assert_comparison.fixed @@ -1,7 +1,7 @@ #![allow(unused, clippy::assertions_on_constants, clippy::const_is_empty)] #![warn(clippy::bool_assert_comparison)] -use std::ops::Not; +use std::ops::{Add, Not}; macro_rules! a { () => { @@ -62,6 +62,14 @@ impl Not for ImplNotTraitWithBool { } } +impl Add for ImplNotTraitWithBool { + type Output = Self; + + fn add(self, other: Self) -> Self::Output { + self + } +} + #[derive(Debug)] struct NonCopy; @@ -94,7 +102,7 @@ fn main() { assert_eq!(a!(), "".is_empty()); assert_eq!("".is_empty(), b!()); assert_eq!(a, true); - assert!(b); + assert!(!!b); //~^ bool_assert_comparison assert_ne!("a".len(), 1); @@ -122,7 +130,7 @@ fn main() { debug_assert_eq!(a!(), "".is_empty()); debug_assert_eq!("".is_empty(), b!()); debug_assert_eq!(a, true); - debug_assert!(b); + debug_assert!(!!b); //~^ bool_assert_comparison debug_assert_ne!("a".len(), 1); @@ -167,7 +175,7 @@ fn main() { use debug_assert_eq as renamed; renamed!(a, true); - debug_assert!(b); + debug_assert!(!!b); //~^ bool_assert_comparison let non_copy = NonCopy; @@ -199,4 +207,12 @@ fn main() { //~^ bool_assert_comparison debug_assert!(!"requires negation".is_empty()); //~^ bool_assert_comparison + assert!(!b); + //~^ bool_assert_comparison + assert!(!(!b)); + //~^ bool_assert_comparison + assert!(!!(b + b)); + //~^ bool_assert_comparison + assert!(!(b + b)); + //~^ bool_assert_comparison } diff --git a/src/tools/clippy/tests/ui/bool_assert_comparison.rs b/src/tools/clippy/tests/ui/bool_assert_comparison.rs index 5ab4f475b06..40824a23c82 100644 --- a/src/tools/clippy/tests/ui/bool_assert_comparison.rs +++ b/src/tools/clippy/tests/ui/bool_assert_comparison.rs @@ -1,7 +1,7 @@ #![allow(unused, clippy::assertions_on_constants, clippy::const_is_empty)] #![warn(clippy::bool_assert_comparison)] -use std::ops::Not; +use std::ops::{Add, Not}; macro_rules! a { () => { @@ -62,6 +62,14 @@ impl Not for ImplNotTraitWithBool { } } +impl Add for ImplNotTraitWithBool { + type Output = Self; + + fn add(self, other: Self) -> Self::Output { + self + } +} + #[derive(Debug)] struct NonCopy; @@ -199,4 +207,12 @@ fn main() { //~^ bool_assert_comparison debug_assert_eq!("requires negation".is_empty(), false); //~^ bool_assert_comparison + assert_eq!(!b, true); + //~^ bool_assert_comparison + assert_eq!(!b, false); + //~^ bool_assert_comparison + assert_eq!(b + b, true); + //~^ bool_assert_comparison + assert_eq!(b + b, false); + //~^ bool_assert_comparison } diff --git a/src/tools/clippy/tests/ui/bool_assert_comparison.stderr b/src/tools/clippy/tests/ui/bool_assert_comparison.stderr index a1d0af54361..f823f08f31d 100644 --- a/src/tools/clippy/tests/ui/bool_assert_comparison.stderr +++ b/src/tools/clippy/tests/ui/bool_assert_comparison.stderr @@ -1,5 +1,5 @@ error: used `assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:87:5 + --> tests/ui/bool_assert_comparison.rs:95:5 | LL | assert_eq!("a".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -13,7 +13,7 @@ LL + assert!(!"a".is_empty()); | error: used `assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:89:5 + --> tests/ui/bool_assert_comparison.rs:97:5 | LL | assert_eq!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,7 +25,7 @@ LL + assert!("".is_empty()); | error: used `assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:91:5 + --> tests/ui/bool_assert_comparison.rs:99:5 | LL | assert_eq!(true, "".is_empty()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL + assert!("".is_empty()); | error: used `assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:97:5 + --> tests/ui/bool_assert_comparison.rs:105:5 | LL | assert_eq!(b, true); | ^^^^^^^^^^^^^^^^^^^ @@ -45,11 +45,11 @@ LL | assert_eq!(b, true); help: replace it with `assert!(..)` | LL - assert_eq!(b, true); -LL + assert!(b); +LL + assert!(!!b); | error: used `assert_ne!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:101:5 + --> tests/ui/bool_assert_comparison.rs:109:5 | LL | assert_ne!("a".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -61,7 +61,7 @@ LL + assert!("a".is_empty()); | error: used `assert_ne!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:103:5 + --> tests/ui/bool_assert_comparison.rs:111:5 | LL | assert_ne!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -73,7 +73,7 @@ LL + assert!(!"".is_empty()); | error: used `assert_ne!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:105:5 + --> tests/ui/bool_assert_comparison.rs:113:5 | LL | assert_ne!(true, "".is_empty()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -85,7 +85,7 @@ LL + assert!(!"".is_empty()); | error: used `assert_ne!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:111:5 + --> tests/ui/bool_assert_comparison.rs:119:5 | LL | assert_ne!(b, true); | ^^^^^^^^^^^^^^^^^^^ @@ -97,7 +97,7 @@ LL + assert!(!b); | error: used `debug_assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:115:5 + --> tests/ui/bool_assert_comparison.rs:123:5 | LL | debug_assert_eq!("a".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -109,7 +109,7 @@ LL + debug_assert!(!"a".is_empty()); | error: used `debug_assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:117:5 + --> tests/ui/bool_assert_comparison.rs:125:5 | LL | debug_assert_eq!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -121,7 +121,7 @@ LL + debug_assert!("".is_empty()); | error: used `debug_assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:119:5 + --> tests/ui/bool_assert_comparison.rs:127:5 | LL | debug_assert_eq!(true, "".is_empty()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -133,7 +133,7 @@ LL + debug_assert!("".is_empty()); | error: used `debug_assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:125:5 + --> tests/ui/bool_assert_comparison.rs:133:5 | LL | debug_assert_eq!(b, true); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -141,11 +141,11 @@ LL | debug_assert_eq!(b, true); help: replace it with `debug_assert!(..)` | LL - debug_assert_eq!(b, true); -LL + debug_assert!(b); +LL + debug_assert!(!!b); | error: used `debug_assert_ne!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:129:5 + --> tests/ui/bool_assert_comparison.rs:137:5 | LL | debug_assert_ne!("a".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -157,7 +157,7 @@ LL + debug_assert!("a".is_empty()); | error: used `debug_assert_ne!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:131:5 + --> tests/ui/bool_assert_comparison.rs:139:5 | LL | debug_assert_ne!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -169,7 +169,7 @@ LL + debug_assert!(!"".is_empty()); | error: used `debug_assert_ne!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:133:5 + --> tests/ui/bool_assert_comparison.rs:141:5 | LL | debug_assert_ne!(true, "".is_empty()); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -181,7 +181,7 @@ LL + debug_assert!(!"".is_empty()); | error: used `debug_assert_ne!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:139:5 + --> tests/ui/bool_assert_comparison.rs:147:5 | LL | debug_assert_ne!(b, true); | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -193,7 +193,7 @@ LL + debug_assert!(!b); | error: used `assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:145:5 + --> tests/ui/bool_assert_comparison.rs:153:5 | LL | assert_eq!("a".is_empty(), false, "tadam {}", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -205,7 +205,7 @@ LL + assert!(!"a".is_empty(), "tadam {}", 1); | error: used `assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:147:5 + --> tests/ui/bool_assert_comparison.rs:155:5 | LL | assert_eq!("a".is_empty(), false, "tadam {}", true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -217,7 +217,7 @@ LL + assert!(!"a".is_empty(), "tadam {}", true); | error: used `assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:149:5 + --> tests/ui/bool_assert_comparison.rs:157:5 | LL | assert_eq!(false, "a".is_empty(), "tadam {}", true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -229,7 +229,7 @@ LL + assert!(!"a".is_empty(), "tadam {}", true); | error: used `debug_assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:155:5 + --> tests/ui/bool_assert_comparison.rs:163:5 | LL | debug_assert_eq!("a".is_empty(), false, "tadam {}", 1); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -241,7 +241,7 @@ LL + debug_assert!(!"a".is_empty(), "tadam {}", 1); | error: used `debug_assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:157:5 + --> tests/ui/bool_assert_comparison.rs:165:5 | LL | debug_assert_eq!("a".is_empty(), false, "tadam {}", true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -253,7 +253,7 @@ LL + debug_assert!(!"a".is_empty(), "tadam {}", true); | error: used `debug_assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:159:5 + --> tests/ui/bool_assert_comparison.rs:167:5 | LL | debug_assert_eq!(false, "a".is_empty(), "tadam {}", true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -265,31 +265,35 @@ LL + debug_assert!(!"a".is_empty(), "tadam {}", true); | error: used `assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:163:5 + --> tests/ui/bool_assert_comparison.rs:171:5 | LL | assert_eq!(a!(), true); | ^^^^^^^^^^^^^^^^^^^^^^ | help: replace it with `assert!(..)` | -LL - assert_eq!(a!(), true); -LL + assert!(a!()); +LL | true +... +LL | +LL ~ assert!(a!()); | error: used `assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:165:5 + --> tests/ui/bool_assert_comparison.rs:173:5 | LL | assert_eq!(true, b!()); | ^^^^^^^^^^^^^^^^^^^^^^ | help: replace it with `assert!(..)` | -LL - assert_eq!(true, b!()); -LL + assert!(b!()); +LL | true +... +LL | +LL ~ assert!(b!()); | error: used `debug_assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:170:5 + --> tests/ui/bool_assert_comparison.rs:178:5 | LL | renamed!(b, true); | ^^^^^^^^^^^^^^^^^ @@ -297,11 +301,11 @@ LL | renamed!(b, true); help: replace it with `debug_assert!(..)` | LL - renamed!(b, true); -LL + debug_assert!(b); +LL + debug_assert!(!!b); | error: used `assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:185:5 + --> tests/ui/bool_assert_comparison.rs:193:5 | LL | assert_eq!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -313,7 +317,7 @@ LL + assert!("".is_empty()); | error: used `assert_ne!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:187:5 + --> tests/ui/bool_assert_comparison.rs:195:5 | LL | assert_ne!("".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -325,7 +329,7 @@ LL + assert!("".is_empty()); | error: used `assert_ne!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:189:5 + --> tests/ui/bool_assert_comparison.rs:197:5 | LL | assert_ne!("requires negation".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -337,7 +341,7 @@ LL + assert!(!"requires negation".is_empty()); | error: used `assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:191:5 + --> tests/ui/bool_assert_comparison.rs:199:5 | LL | assert_eq!("requires negation".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -349,7 +353,7 @@ LL + assert!(!"requires negation".is_empty()); | error: used `debug_assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:194:5 + --> tests/ui/bool_assert_comparison.rs:202:5 | LL | debug_assert_eq!("".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -361,7 +365,7 @@ LL + debug_assert!("".is_empty()); | error: used `debug_assert_ne!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:196:5 + --> tests/ui/bool_assert_comparison.rs:204:5 | LL | debug_assert_ne!("".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -373,7 +377,7 @@ LL + debug_assert!("".is_empty()); | error: used `debug_assert_ne!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:198:5 + --> tests/ui/bool_assert_comparison.rs:206:5 | LL | debug_assert_ne!("requires negation".is_empty(), true); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -385,7 +389,7 @@ LL + debug_assert!(!"requires negation".is_empty()); | error: used `debug_assert_eq!` with a literal bool - --> tests/ui/bool_assert_comparison.rs:200:5 + --> tests/ui/bool_assert_comparison.rs:208:5 | LL | debug_assert_eq!("requires negation".is_empty(), false); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -396,5 +400,53 @@ LL - debug_assert_eq!("requires negation".is_empty(), false); LL + debug_assert!(!"requires negation".is_empty()); | -error: aborting due to 33 previous errors +error: used `assert_eq!` with a literal bool + --> tests/ui/bool_assert_comparison.rs:210:5 + | +LL | assert_eq!(!b, true); + | ^^^^^^^^^^^^^^^^^^^^ + | +help: replace it with `assert!(..)` + | +LL - assert_eq!(!b, true); +LL + assert!(!b); + | + +error: used `assert_eq!` with a literal bool + --> tests/ui/bool_assert_comparison.rs:212:5 + | +LL | assert_eq!(!b, false); + | ^^^^^^^^^^^^^^^^^^^^^ + | +help: replace it with `assert!(..)` + | +LL - assert_eq!(!b, false); +LL + assert!(!(!b)); + | + +error: used `assert_eq!` with a literal bool + --> tests/ui/bool_assert_comparison.rs:214:5 + | +LL | assert_eq!(b + b, true); + | ^^^^^^^^^^^^^^^^^^^^^^^ + | +help: replace it with `assert!(..)` + | +LL - assert_eq!(b + b, true); +LL + assert!(!!(b + b)); + | + +error: used `assert_eq!` with a literal bool + --> tests/ui/bool_assert_comparison.rs:216:5 + | +LL | assert_eq!(b + b, false); + | ^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: replace it with `assert!(..)` + | +LL - assert_eq!(b + b, false); +LL + assert!(!(b + b)); + | + +error: aborting due to 37 previous errors diff --git a/src/tools/clippy/tests/ui/crashes/ice-96721.stderr b/src/tools/clippy/tests/ui/crashes/ice-96721.stderr index f0778a4b32b..23f7300178e 100644 --- a/src/tools/clippy/tests/ui/crashes/ice-96721.stderr +++ b/src/tools/clippy/tests/ui/crashes/ice-96721.stderr @@ -3,6 +3,8 @@ error: malformed `path` attribute input | LL | #[path = foo!()] | ^^^^^^^^^^^^^^^^ help: must be of the form: `#[path = "file"]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/items/modules.html#the-path-attribute> error: aborting due to 1 previous error diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index f283a625f97..debf67e2741 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -1766,7 +1766,7 @@ impl<'test> TestCx<'test> { match self.config.compare_mode { Some(CompareMode::Polonius) => { - rustc.args(&["-Zpolonius"]); + rustc.args(&["-Zpolonius=next"]); } Some(CompareMode::NextSolver) => { rustc.args(&["-Znext-solver"]); diff --git a/src/tools/miri/src/bin/miri.rs b/src/tools/miri/src/bin/miri.rs index ae1b25f8857..d9e374c414c 100644 --- a/src/tools/miri/src/bin/miri.rs +++ b/src/tools/miri/src/bin/miri.rs @@ -279,7 +279,7 @@ impl rustc_driver::Callbacks for MiriBeRustCompilerCalls { return None; } let codegen_fn_attrs = tcx.codegen_fn_attrs(local_def_id); - if codegen_fn_attrs.contains_extern_indicator() + if codegen_fn_attrs.contains_extern_indicator(tcx, local_def_id.into()) || codegen_fn_attrs .flags .contains(CodegenFnAttrFlags::USED_COMPILER) diff --git a/src/tools/miri/src/borrow_tracker/mod.rs b/src/tools/miri/src/borrow_tracker/mod.rs index ec6c2c60ca9..89bd93edae1 100644 --- a/src/tools/miri/src/borrow_tracker/mod.rs +++ b/src/tools/miri/src/borrow_tracker/mod.rs @@ -260,7 +260,7 @@ impl GlobalStateInner { kind: MemoryKind, machine: &MiriMachine<'_>, ) -> AllocState { - let _span = enter_trace_span!(borrow_tracker::new_allocation, ?id, ?alloc_size, ?kind); + let _trace = enter_trace_span!(borrow_tracker::new_allocation, ?id, ?alloc_size, ?kind); match self.borrow_tracker_method { BorrowTrackerMethod::StackedBorrows => AllocState::StackedBorrows(Box::new(RefCell::new(Stacks::new_allocation( @@ -281,7 +281,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { kind: RetagKind, val: &ImmTy<'tcx>, ) -> InterpResult<'tcx, ImmTy<'tcx>> { - let _span = enter_trace_span!(borrow_tracker::retag_ptr_value, ?kind, ?val.layout); + let _trace = enter_trace_span!(borrow_tracker::retag_ptr_value, ?kind, ?val.layout); let this = self.eval_context_mut(); let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().borrow_tracker_method; match method { @@ -295,7 +295,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { kind: RetagKind, place: &PlaceTy<'tcx>, ) -> InterpResult<'tcx> { - let _span = enter_trace_span!(borrow_tracker::retag_place_contents, ?kind, ?place); + let _trace = enter_trace_span!(borrow_tracker::retag_place_contents, ?kind, ?place); let this = self.eval_context_mut(); let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().borrow_tracker_method; match method { @@ -305,7 +305,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } fn protect_place(&mut self, place: &MPlaceTy<'tcx>) -> InterpResult<'tcx, MPlaceTy<'tcx>> { - let _span = enter_trace_span!(borrow_tracker::protect_place, ?place); + let _trace = enter_trace_span!(borrow_tracker::protect_place, ?place); let this = self.eval_context_mut(); let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().borrow_tracker_method; match method { @@ -315,7 +315,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { } fn expose_tag(&self, alloc_id: AllocId, tag: BorTag) -> InterpResult<'tcx> { - let _span = + let _trace = enter_trace_span!(borrow_tracker::expose_tag, alloc_id = alloc_id.0, tag = tag.0); let this = self.eval_context_ref(); let method = this.machine.borrow_tracker.as_ref().unwrap().borrow().borrow_tracker_method; @@ -360,7 +360,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { &self, frame: &Frame<'tcx, Provenance, FrameExtra<'tcx>>, ) -> InterpResult<'tcx> { - let _span = enter_trace_span!(borrow_tracker::on_stack_pop); + let _trace = enter_trace_span!(borrow_tracker::on_stack_pop); let this = self.eval_context_ref(); let borrow_tracker = this.machine.borrow_tracker.as_ref().unwrap(); // The body of this loop needs `borrow_tracker` immutably @@ -438,7 +438,7 @@ impl AllocState { range: AllocRange, machine: &MiriMachine<'tcx>, ) -> InterpResult<'tcx> { - let _span = enter_trace_span!(borrow_tracker::before_memory_read, alloc_id = alloc_id.0); + let _trace = enter_trace_span!(borrow_tracker::before_memory_read, alloc_id = alloc_id.0); match self { AllocState::StackedBorrows(sb) => sb.borrow_mut().before_memory_read(alloc_id, prov_extra, range, machine), @@ -460,7 +460,7 @@ impl AllocState { range: AllocRange, machine: &MiriMachine<'tcx>, ) -> InterpResult<'tcx> { - let _span = enter_trace_span!(borrow_tracker::before_memory_write, alloc_id = alloc_id.0); + let _trace = enter_trace_span!(borrow_tracker::before_memory_write, alloc_id = alloc_id.0); match self { AllocState::StackedBorrows(sb) => sb.get_mut().before_memory_write(alloc_id, prov_extra, range, machine), @@ -482,7 +482,7 @@ impl AllocState { size: Size, machine: &MiriMachine<'tcx>, ) -> InterpResult<'tcx> { - let _span = + let _trace = enter_trace_span!(borrow_tracker::before_memory_deallocation, alloc_id = alloc_id.0); match self { AllocState::StackedBorrows(sb) => @@ -493,7 +493,7 @@ impl AllocState { } pub fn remove_unreachable_tags(&self, tags: &FxHashSet<BorTag>) { - let _span = enter_trace_span!(borrow_tracker::remove_unreachable_tags); + let _trace = enter_trace_span!(borrow_tracker::remove_unreachable_tags); match self { AllocState::StackedBorrows(sb) => sb.borrow_mut().remove_unreachable_tags(tags), AllocState::TreeBorrows(tb) => tb.borrow_mut().remove_unreachable_tags(tags), @@ -508,7 +508,7 @@ impl AllocState { tag: BorTag, alloc_id: AllocId, // diagnostics ) -> InterpResult<'tcx> { - let _span = enter_trace_span!( + let _trace = enter_trace_span!( borrow_tracker::release_protector, alloc_id = alloc_id.0, tag = tag.0 @@ -523,7 +523,7 @@ impl AllocState { impl VisitProvenance for AllocState { fn visit_provenance(&self, visit: &mut VisitWith<'_>) { - let _span = enter_trace_span!(borrow_tracker::visit_provenance); + let _trace = enter_trace_span!(borrow_tracker::visit_provenance); match self { AllocState::StackedBorrows(sb) => sb.visit_provenance(visit), AllocState::TreeBorrows(tb) => tb.visit_provenance(visit), diff --git a/src/tools/miri/src/helpers.rs b/src/tools/miri/src/helpers.rs index 43cb1c9ae05..a8e2151afe6 100644 --- a/src/tools/miri/src/helpers.rs +++ b/src/tools/miri/src/helpers.rs @@ -132,7 +132,7 @@ pub fn iter_exported_symbols<'tcx>( for def_id in crate_items.definitions() { let exported = tcx.def_kind(def_id).has_codegen_attrs() && { let codegen_attrs = tcx.codegen_fn_attrs(def_id); - codegen_attrs.contains_extern_indicator() + codegen_attrs.contains_extern_indicator(tcx, def_id.into()) || codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL) || codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_COMPILER) || codegen_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER) diff --git a/src/tools/opt-dist/Cargo.toml b/src/tools/opt-dist/Cargo.toml index 2ed3fbac709..f4051ae67d7 100644 --- a/src/tools/opt-dist/Cargo.toml +++ b/src/tools/opt-dist/Cargo.toml @@ -10,7 +10,7 @@ log = "0.4" anyhow = "1" humantime = "2" humansize = "2" -sysinfo = { version = "0.36.0", default-features = false, features = ["disk"] } +sysinfo = { version = "0.37.0", default-features = false, features = ["disk"] } fs_extra = "1" camino = "1" tar = "0.4" diff --git a/src/tools/opt-dist/src/tests.rs b/src/tools/opt-dist/src/tests.rs index d5121b8c786..fa55805bbf2 100644 --- a/src/tools/opt-dist/src/tests.rs +++ b/src/tools/opt-dist/src/tests.rs @@ -36,6 +36,16 @@ pub fn run_tests(env: &Environment) -> anyhow::Result<()> { let cargo_dir = extract_dist_dir(&format!("cargo-{version}-{host_triple}"))?.join("cargo"); let extracted_src_dir = extract_dist_dir(&format!("rust-src-{version}"))?.join("rust-src"); + // If we have a Cranelift archive, copy it to the rustc sysroot + if let Ok(_) = find_file_in_dir(&dist_dir, "rustc-codegen-cranelift-", ".tar.xz") { + let extracted_codegen_dir = + extract_dist_dir(&format!("rustc-codegen-cranelift-{version}-{host_triple}"))? + .join("rustc-codegen-cranelift-preview"); + let rel_path = + Utf8Path::new("lib").join("rustlib").join(host_triple).join("codegen-backends"); + copy_directory(&extracted_codegen_dir.join(&rel_path), &rustc_dir.join(&rel_path))?; + } + // We need to manually copy libstd to the extracted rustc sysroot copy_directory( &libstd_dir.join("lib").join("rustlib").join(host_triple).join("lib"), diff --git a/src/tools/rust-analyzer/crates/syntax-bridge/src/lib.rs b/src/tools/rust-analyzer/crates/syntax-bridge/src/lib.rs index bdff671802c..4e525be3fe3 100644 --- a/src/tools/rust-analyzer/crates/syntax-bridge/src/lib.rs +++ b/src/tools/rust-analyzer/crates/syntax-bridge/src/lib.rs @@ -127,11 +127,11 @@ where // The following items are what `rustc` macro can be parsed into : // link: https://github.com/rust-lang/rust/blob/9ebf47851a357faa4cd97f4b1dc7835f6376e639/src/libsyntax/ext/expand.rs#L141 -// * Expr(P<ast::Expr>) -> token_tree_to_expr -// * Pat(P<ast::Pat>) -> token_tree_to_pat -// * Ty(P<ast::Ty>) -> token_tree_to_ty +// * Expr(Box<ast::Expr>) -> token_tree_to_expr +// * Pat(Box<ast::Pat>) -> token_tree_to_pat +// * Ty(Box<ast::Ty>) -> token_tree_to_ty // * Stmts(SmallVec<[ast::Stmt; 1]>) -> token_tree_to_stmts -// * Items(SmallVec<[P<ast::Item>; 1]>) -> token_tree_to_items +// * Items(SmallVec<[Box<ast::Item>; 1]>) -> token_tree_to_items // // * TraitItems(SmallVec<[ast::TraitItem; 1]>) // * AssocItems(SmallVec<[ast::AssocItem; 1]>) diff --git a/src/tools/rustfmt/src/chains.rs b/src/tools/rustfmt/src/chains.rs index 034ecde068a..2f388197ea1 100644 --- a/src/tools/rustfmt/src/chains.rs +++ b/src/tools/rustfmt/src/chains.rs @@ -58,7 +58,7 @@ use std::borrow::Cow; use std::cmp::min; -use rustc_ast::{ast, ptr}; +use rustc_ast::ast; use rustc_span::{BytePos, Span, symbol}; use tracing::debug; @@ -187,7 +187,7 @@ enum ChainItemKind { MethodCall( ast::PathSegment, Vec<ast::GenericArg>, - ThinVec<ptr::P<ast::Expr>>, + ThinVec<Box<ast::Expr>>, ), StructField(symbol::Ident), TupleField(symbol::Ident, bool), @@ -343,7 +343,7 @@ impl ChainItem { fn rewrite_method_call( method_name: symbol::Ident, types: &[ast::GenericArg], - args: &[ptr::P<ast::Expr>], + args: &[Box<ast::Expr>], span: Span, context: &RewriteContext<'_>, shape: Shape, diff --git a/src/tools/rustfmt/src/closures.rs b/src/tools/rustfmt/src/closures.rs index 61e148cdf18..bb10a7946b8 100644 --- a/src/tools/rustfmt/src/closures.rs +++ b/src/tools/rustfmt/src/closures.rs @@ -1,4 +1,4 @@ -use rustc_ast::{ast, ptr}; +use rustc_ast::ast; use rustc_span::Span; use thin_vec::thin_vec; use tracing::debug; @@ -165,7 +165,7 @@ fn rewrite_closure_with_block( let block = ast::Block { stmts: thin_vec![ast::Stmt { id: ast::NodeId::root(), - kind: ast::StmtKind::Expr(ptr::P(body.clone())), + kind: ast::StmtKind::Expr(Box::new(body.clone())), span: body.span, }], id: ast::NodeId::root(), diff --git a/src/tools/rustfmt/src/expr.rs b/src/tools/rustfmt/src/expr.rs index 08aedff2b20..975f9be44e4 100644 --- a/src/tools/rustfmt/src/expr.rs +++ b/src/tools/rustfmt/src/expr.rs @@ -3,7 +3,7 @@ use std::cmp::min; use itertools::Itertools; use rustc_ast::token::{Delimiter, Lit, LitKind}; -use rustc_ast::{ForLoopKind, MatchKind, ast, ptr, token}; +use rustc_ast::{ForLoopKind, MatchKind, ast, token}; use rustc_span::{BytePos, Span}; use tracing::debug; @@ -1368,7 +1368,7 @@ fn choose_separator_tactic(context: &RewriteContext<'_>, span: Span) -> Option<S pub(crate) fn rewrite_call( context: &RewriteContext<'_>, callee: &str, - args: &[ptr::P<ast::Expr>], + args: &[Box<ast::Expr>], span: Span, shape: Shape, ) -> RewriteResult { @@ -1634,7 +1634,7 @@ fn struct_lit_can_be_aligned(fields: &[ast::ExprField], has_base: bool) -> bool fn rewrite_struct_lit<'a>( context: &RewriteContext<'_>, path: &ast::Path, - qself: &Option<ptr::P<ast::QSelf>>, + qself: &Option<Box<ast::QSelf>>, fields: &'a [ast::ExprField], struct_rest: &ast::StructRest, attrs: &[ast::Attribute], diff --git a/src/tools/rustfmt/src/items.rs b/src/tools/rustfmt/src/items.rs index 7084639aca9..10df6f96702 100644 --- a/src/tools/rustfmt/src/items.rs +++ b/src/tools/rustfmt/src/items.rs @@ -4,8 +4,8 @@ use std::borrow::Cow; use std::cmp::{Ordering, max, min}; use regex::Regex; +use rustc_ast::ast; use rustc_ast::visit; -use rustc_ast::{ast, ptr}; use rustc_span::{BytePos, DUMMY_SP, Ident, Span, symbol}; use tracing::debug; @@ -725,9 +725,9 @@ impl<'a> FmtVisitor<'a> { .ok() } - fn visit_impl_items(&mut self, items: &[ptr::P<ast::AssocItem>]) { + fn visit_impl_items(&mut self, items: &[Box<ast::AssocItem>]) { if self.get_context().config.reorder_impl_items() { - type TyOpt = Option<ptr::P<ast::Ty>>; + type TyOpt = Option<Box<ast::Ty>>; use crate::ast::AssocItemKind::*; let is_type = |ty: &TyOpt| opaque_ty(ty).is_none(); let is_opaque = |ty: &TyOpt| opaque_ty(ty).is_some(); @@ -934,7 +934,7 @@ pub(crate) fn format_impl( fn is_impl_single_line( context: &RewriteContext<'_>, - items: &[ptr::P<ast::AssocItem>], + items: &[Box<ast::AssocItem>], result: &str, where_clause_str: &str, item: &ast::Item, @@ -958,20 +958,19 @@ fn format_impl_ref_and_type( offset: Indent, ) -> Option<String> { let ast::Impl { - safety, - polarity, - defaultness, - constness, - ref generics, - of_trait: ref trait_ref, - ref self_ty, - .. - } = *iimpl; + generics, + of_trait, + self_ty, + items: _, + } = iimpl; let mut result = String::with_capacity(128); result.push_str(&format_visibility(context, &item.vis)); - result.push_str(format_defaultness(defaultness)); - result.push_str(format_safety(safety)); + + if let Some(of_trait) = of_trait.as_deref() { + result.push_str(format_defaultness(of_trait.defaultness)); + result.push_str(format_safety(of_trait.safety)); + } let shape = if context.config.style_edition() >= StyleEdition::Edition2024 { Shape::indented(offset + last_line_width(&result), context.config) @@ -984,28 +983,24 @@ fn format_impl_ref_and_type( }; let generics_str = rewrite_generics(context, "impl", generics, shape).ok()?; result.push_str(&generics_str); - result.push_str(format_constness_right(constness)); - let polarity_str = match polarity { - ast::ImplPolarity::Negative(_) => "!", - ast::ImplPolarity::Positive => "", - }; - - let polarity_overhead; let trait_ref_overhead; - if let Some(ref trait_ref) = *trait_ref { + if let Some(of_trait) = of_trait.as_deref() { + result.push_str(format_constness_right(of_trait.constness)); + let polarity_str = match of_trait.polarity { + ast::ImplPolarity::Negative(_) => "!", + ast::ImplPolarity::Positive => "", + }; let result_len = last_line_width(&result); result.push_str(&rewrite_trait_ref( context, - trait_ref, + &of_trait.trait_ref, offset, polarity_str, result_len, )?); - polarity_overhead = 0; // already written trait_ref_overhead = " for".len(); } else { - polarity_overhead = polarity_str.len(); trait_ref_overhead = 0; } @@ -1020,17 +1015,15 @@ fn format_impl_ref_and_type( } else { 0 }; - let used_space = - last_line_width(&result) + polarity_overhead + trait_ref_overhead + curly_brace_overhead; + let used_space = last_line_width(&result) + trait_ref_overhead + curly_brace_overhead; // 1 = space before the type. let budget = context.budget(used_space + 1); if let Some(self_ty_str) = self_ty.rewrite(context, Shape::legacy(budget, offset)) { if !self_ty_str.contains('\n') { - if trait_ref.is_some() { + if of_trait.is_some() { result.push_str(" for "); } else { result.push(' '); - result.push_str(polarity_str); } result.push_str(&self_ty_str); return Some(result); @@ -1042,12 +1035,10 @@ fn format_impl_ref_and_type( // Add indentation of one additional tab. let new_line_offset = offset.block_indent(context.config); result.push_str(&new_line_offset.to_string(context.config)); - if trait_ref.is_some() { + if of_trait.is_some() { result.push_str("for "); - } else { - result.push_str(polarity_str); } - let budget = context.budget(last_line_width(&result) + polarity_overhead); + let budget = context.budget(last_line_width(&result)); let type_offset = match context.config.indent_style() { IndentStyle::Visual => new_line_offset + trait_ref_overhead, IndentStyle::Block => new_line_offset, @@ -2024,7 +2015,7 @@ pub(crate) struct StaticParts<'a> { generics: Option<&'a ast::Generics>, ty: &'a ast::Ty, mutability: ast::Mutability, - expr_opt: Option<&'a ptr::P<ast::Expr>>, + expr_opt: Option<&'a Box<ast::Expr>>, defaultness: Option<ast::Defaultness>, span: Span, } diff --git a/src/tools/rustfmt/src/macros.rs b/src/tools/rustfmt/src/macros.rs index 0ff0aad7a2d..2e7ac90f596 100644 --- a/src/tools/rustfmt/src/macros.rs +++ b/src/tools/rustfmt/src/macros.rs @@ -12,9 +12,9 @@ use std::collections::HashMap; use std::panic::{AssertUnwindSafe, catch_unwind}; +use rustc_ast::ast; use rustc_ast::token::{Delimiter, Token, TokenKind}; use rustc_ast::tokenstream::{TokenStream, TokenStreamIter, TokenTree}; -use rustc_ast::{ast, ptr}; use rustc_ast_pretty::pprust; use rustc_span::{BytePos, DUMMY_SP, Ident, Span, Symbol}; use tracing::debug; @@ -53,10 +53,10 @@ pub(crate) enum MacroPosition { #[derive(Debug)] pub(crate) enum MacroArg { - Expr(ptr::P<ast::Expr>), - Ty(ptr::P<ast::Ty>), - Pat(ptr::P<ast::Pat>), - Item(ptr::P<ast::Item>), + Expr(Box<ast::Expr>), + Ty(Box<ast::Ty>), + Pat(Box<ast::Pat>), + Item(Box<ast::Item>), Keyword(Ident, Span), } diff --git a/src/tools/rustfmt/src/matches.rs b/src/tools/rustfmt/src/matches.rs index 8f62648e576..209cb2f9287 100644 --- a/src/tools/rustfmt/src/matches.rs +++ b/src/tools/rustfmt/src/matches.rs @@ -2,7 +2,7 @@ use std::iter::repeat; -use rustc_ast::{MatchKind, ast, ptr}; +use rustc_ast::{MatchKind, ast}; use rustc_span::{BytePos, Span}; use tracing::debug; @@ -394,7 +394,7 @@ fn flatten_arm_body<'a>( fn rewrite_match_body( context: &RewriteContext<'_>, - body: &ptr::P<ast::Expr>, + body: &Box<ast::Expr>, pats_str: &str, shape: Shape, has_guard: bool, @@ -569,7 +569,7 @@ fn rewrite_match_body( // The `if ...` guard on a match arm. fn rewrite_guard( context: &RewriteContext<'_>, - guard: &Option<ptr::P<ast::Expr>>, + guard: &Option<Box<ast::Expr>>, shape: Shape, // The amount of space used up on this line for the pattern in // the arm (excludes offset). diff --git a/src/tools/rustfmt/src/modules.rs b/src/tools/rustfmt/src/modules.rs index 44c8123517c..3bc656b64b3 100644 --- a/src/tools/rustfmt/src/modules.rs +++ b/src/tools/rustfmt/src/modules.rs @@ -26,7 +26,7 @@ type FileModMap<'ast> = BTreeMap<FileName, Module<'ast>>; #[derive(Debug, Clone)] pub(crate) struct Module<'a> { ast_mod_kind: Option<Cow<'a, ast::ModKind>>, - pub(crate) items: Cow<'a, ThinVec<rustc_ast::ptr::P<ast::Item>>>, + pub(crate) items: Cow<'a, ThinVec<Box<ast::Item>>>, inner_attr: ast::AttrVec, pub(crate) span: Span, } @@ -35,7 +35,7 @@ impl<'a> Module<'a> { pub(crate) fn new( mod_span: Span, ast_mod_kind: Option<Cow<'a, ast::ModKind>>, - mod_items: Cow<'a, ThinVec<rustc_ast::ptr::P<ast::Item>>>, + mod_items: Cow<'a, ThinVec<Box<ast::Item>>>, mod_attrs: Cow<'a, ast::AttrVec>, ) -> Self { let inner_attr = mod_attrs @@ -170,7 +170,7 @@ impl<'ast, 'psess, 'c> ModResolver<'ast, 'psess> { /// Visit modules defined inside macro calls. fn visit_mod_outside_ast( &mut self, - items: ThinVec<rustc_ast::ptr::P<ast::Item>>, + items: ThinVec<Box<ast::Item>>, ) -> Result<(), ModuleResolutionError> { for item in items { if is_cfg_if(&item) { @@ -197,7 +197,7 @@ impl<'ast, 'psess, 'c> ModResolver<'ast, 'psess> { /// Visit modules from AST. fn visit_mod_from_ast( &mut self, - items: &'ast [rustc_ast::ptr::P<ast::Item>], + items: &'ast [Box<ast::Item>], ) -> Result<(), ModuleResolutionError> { for item in items { if is_cfg_if(item) { diff --git a/src/tools/rustfmt/src/overflow.rs b/src/tools/rustfmt/src/overflow.rs index 728adff2c7d..bb1ebc87f67 100644 --- a/src/tools/rustfmt/src/overflow.rs +++ b/src/tools/rustfmt/src/overflow.rs @@ -3,8 +3,8 @@ use std::cmp::min; use itertools::Itertools; +use rustc_ast::ast; use rustc_ast::token::Delimiter; -use rustc_ast::{ast, ptr}; use rustc_span::Span; use tracing::debug; @@ -219,7 +219,7 @@ pub(crate) trait IntoOverflowableItem<'a>: Rewrite + Spanned { fn into_overflowable_item(&'a self) -> OverflowableItem<'a>; } -impl<'a, T: 'a + IntoOverflowableItem<'a>> IntoOverflowableItem<'a> for ptr::P<T> { +impl<'a, T: 'a + IntoOverflowableItem<'a>> IntoOverflowableItem<'a> for Box<T> { fn into_overflowable_item(&'a self) -> OverflowableItem<'a> { (**self).into_overflowable_item() } diff --git a/src/tools/rustfmt/src/parse/macros/lazy_static.rs b/src/tools/rustfmt/src/parse/macros/lazy_static.rs index cbe81004e22..8611615d123 100644 --- a/src/tools/rustfmt/src/parse/macros/lazy_static.rs +++ b/src/tools/rustfmt/src/parse/macros/lazy_static.rs @@ -1,5 +1,4 @@ use rustc_ast::ast; -use rustc_ast::ptr::P; use rustc_ast::token; use rustc_ast::tokenstream::TokenStream; use rustc_parse::exp; @@ -10,7 +9,7 @@ use crate::rewrite::RewriteContext; pub(crate) fn parse_lazy_static( context: &RewriteContext<'_>, ts: TokenStream, -) -> Option<Vec<(ast::Visibility, symbol::Ident, P<ast::Ty>, P<ast::Expr>)>> { +) -> Option<Vec<(ast::Visibility, symbol::Ident, Box<ast::Ty>, Box<ast::Expr>)>> { let mut result = vec![]; let mut parser = super::build_parser(context, ts); macro_rules! parse_or { diff --git a/src/tools/rustfmt/src/parse/macros/mod.rs b/src/tools/rustfmt/src/parse/macros/mod.rs index d7964484b26..724d7a09e4a 100644 --- a/src/tools/rustfmt/src/parse/macros/mod.rs +++ b/src/tools/rustfmt/src/parse/macros/mod.rs @@ -1,6 +1,6 @@ +use rustc_ast::ast; use rustc_ast::token::{Delimiter, NonterminalKind, NtExprKind::*, NtPatKind::*, TokenKind}; use rustc_ast::tokenstream::TokenStream; -use rustc_ast::{ast, ptr}; use rustc_parse::MACRO_ARGUMENTS; use rustc_parse::parser::{ForceCollect, Parser, Recovery}; use rustc_session::parse::ParseSess; @@ -49,26 +49,26 @@ fn parse_macro_arg<'a, 'b: 'a>(parser: &'a mut Parser<'b>) -> Option<MacroArg> { Expr, NonterminalKind::Expr(Expr), |parser: &mut Parser<'b>| parser.parse_expr(), - |x: ptr::P<ast::Expr>| Some(x) + |x: Box<ast::Expr>| Some(x) ); parse_macro_arg!( Ty, NonterminalKind::Ty, |parser: &mut Parser<'b>| parser.parse_ty(), - |x: ptr::P<ast::Ty>| Some(x) + |x: Box<ast::Ty>| Some(x) ); parse_macro_arg!( Pat, NonterminalKind::Pat(PatParam { inferred: false }), |parser: &mut Parser<'b>| parser.parse_pat_no_top_alt(None, None), - |x: ptr::P<ast::Pat>| Some(x) + |x: Box<ast::Pat>| Some(x) ); - // `parse_item` returns `Option<ptr::P<ast::Item>>`. + // `parse_item` returns `Option<Box<ast::Item>>`. parse_macro_arg!( Item, NonterminalKind::Item, |parser: &mut Parser<'b>| parser.parse_item(ForceCollect::No), - |x: Option<ptr::P<ast::Item>>| x + |x: Option<Box<ast::Item>>| x ); None @@ -164,7 +164,7 @@ pub(crate) fn parse_macro_args( pub(crate) fn parse_expr( context: &RewriteContext<'_>, tokens: TokenStream, -) -> Option<ptr::P<ast::Expr>> { +) -> Option<Box<ast::Expr>> { let mut parser = build_parser(context, tokens); parser.parse_expr().ok() } diff --git a/src/tools/rustfmt/src/parse/parser.rs b/src/tools/rustfmt/src/parse/parser.rs index f357aed66c2..2ec8769c45f 100644 --- a/src/tools/rustfmt/src/parse/parser.rs +++ b/src/tools/rustfmt/src/parse/parser.rs @@ -1,7 +1,7 @@ use std::panic::{AssertUnwindSafe, catch_unwind}; use std::path::{Path, PathBuf}; -use rustc_ast::{ast, attr, ptr}; +use rustc_ast::{ast, attr}; use rustc_errors::Diag; use rustc_parse::parser::Parser as RawParser; use rustc_parse::{exp, new_parser_from_file, new_parser_from_source_str, unwrap_or_emit_fatal}; @@ -102,7 +102,7 @@ impl<'a> Parser<'a> { psess: &'a ParseSess, path: &Path, span: Span, - ) -> Result<(ast::AttrVec, ThinVec<ptr::P<ast::Item>>, Span), ParserError> { + ) -> Result<(ast::AttrVec, ThinVec<Box<ast::Item>>, Span), ParserError> { let result = catch_unwind(AssertUnwindSafe(|| { let mut parser = unwrap_or_emit_fatal(new_parser_from_file(psess.inner(), path, Some(span))); diff --git a/src/tools/rustfmt/src/patterns.rs b/src/tools/rustfmt/src/patterns.rs index cb3879f4be8..d212ecf392a 100644 --- a/src/tools/rustfmt/src/patterns.rs +++ b/src/tools/rustfmt/src/patterns.rs @@ -1,5 +1,4 @@ use rustc_ast::ast::{self, BindingMode, ByRef, Pat, PatField, PatKind, RangeEnd, RangeSyntax}; -use rustc_ast::ptr; use rustc_span::{BytePos, Span}; use crate::comment::{FindUncommented, combine_strs_with_missing_comments}; @@ -77,7 +76,7 @@ fn is_short_pattern_inner(context: &RewriteContext<'_>, pat: &ast::Pat) -> bool } pub(crate) struct RangeOperand<'a, T> { - pub operand: &'a Option<ptr::P<T>>, + pub operand: &'a Option<Box<T>>, pub span: Span, } @@ -329,8 +328,8 @@ impl Rewrite for Pat { pub fn rewrite_range_pat<T: Rewrite>( context: &RewriteContext<'_>, shape: Shape, - lhs: &Option<ptr::P<T>>, - rhs: &Option<ptr::P<T>>, + lhs: &Option<Box<T>>, + rhs: &Option<Box<T>>, end_kind: &rustc_span::source_map::Spanned<RangeEnd>, span: Span, ) -> RewriteResult { @@ -371,7 +370,7 @@ pub fn rewrite_range_pat<T: Rewrite>( } fn rewrite_struct_pat( - qself: &Option<ptr::P<ast::QSelf>>, + qself: &Option<Box<ast::QSelf>>, path: &ast::Path, fields: &[ast::PatField], ellipsis: bool, @@ -505,7 +504,7 @@ impl Rewrite for PatField { #[derive(Debug)] pub(crate) enum TuplePatField<'a> { - Pat(&'a ptr::P<ast::Pat>), + Pat(&'a Box<ast::Pat>), Dotdot(Span), } @@ -562,7 +561,7 @@ pub(crate) fn can_be_overflowed_pat( } fn rewrite_tuple_pat( - pats: &[ptr::P<ast::Pat>], + pats: &[Box<ast::Pat>], path_str: Option<String>, span: Span, context: &RewriteContext<'_>, diff --git a/src/tools/rustfmt/src/rewrite.rs b/src/tools/rustfmt/src/rewrite.rs index 83020709797..f0accd62d1a 100644 --- a/src/tools/rustfmt/src/rewrite.rs +++ b/src/tools/rustfmt/src/rewrite.rs @@ -3,7 +3,6 @@ use std::cell::{Cell, RefCell}; use std::rc::Rc; -use rustc_ast::ptr; use rustc_span::Span; use thiserror::Error; @@ -24,7 +23,7 @@ pub(crate) trait Rewrite { } } -impl<T: Rewrite> Rewrite for ptr::P<T> { +impl<T: Rewrite> Rewrite for Box<T> { fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option<String> { (**self).rewrite(context, shape) } diff --git a/src/tools/rustfmt/src/spanned.rs b/src/tools/rustfmt/src/spanned.rs index ac132999b62..020651e2daa 100644 --- a/src/tools/rustfmt/src/spanned.rs +++ b/src/tools/rustfmt/src/spanned.rs @@ -1,6 +1,6 @@ use std::cmp::max; -use rustc_ast::{ast, ptr}; +use rustc_ast::ast; use rustc_span::{Span, source_map}; use crate::macros::MacroArg; @@ -12,7 +12,7 @@ pub(crate) trait Spanned { fn span(&self) -> Span; } -impl<T: Spanned> Spanned for ptr::P<T> { +impl<T: Spanned> Spanned for Box<T> { fn span(&self) -> Span { (**self).span() } diff --git a/src/tools/rustfmt/src/types.rs b/src/tools/rustfmt/src/types.rs index 9ee10d86270..5dce9a0c8d0 100644 --- a/src/tools/rustfmt/src/types.rs +++ b/src/tools/rustfmt/src/types.rs @@ -1,7 +1,6 @@ use std::ops::Deref; use rustc_ast::ast::{self, FnRetTy, Mutability, Term}; -use rustc_ast::ptr; use rustc_span::{BytePos, Pos, Span, symbol::kw}; use tracing::debug; @@ -39,7 +38,7 @@ pub(crate) enum PathContext { pub(crate) fn rewrite_path( context: &RewriteContext<'_>, path_context: PathContext, - qself: &Option<ptr::P<ast::QSelf>>, + qself: &Option<Box<ast::QSelf>>, path: &ast::Path, shape: Shape, ) -> RewriteResult { @@ -1340,7 +1339,7 @@ fn join_bounds_inner( } } -pub(crate) fn opaque_ty(ty: &Option<ptr::P<ast::Ty>>) -> Option<&ast::GenericBounds> { +pub(crate) fn opaque_ty(ty: &Option<Box<ast::Ty>>) -> Option<&ast::GenericBounds> { ty.as_ref().and_then(|t| match &t.kind { ast::TyKind::ImplTrait(_, bounds) => Some(bounds), _ => None, diff --git a/src/tools/rustfmt/src/utils.rs b/src/tools/rustfmt/src/utils.rs index fcd475b1784..b9950e94d0c 100644 --- a/src/tools/rustfmt/src/utils.rs +++ b/src/tools/rustfmt/src/utils.rs @@ -1,10 +1,10 @@ use std::borrow::Cow; +use rustc_ast::YieldKind; use rustc_ast::ast::{ self, Attribute, MetaItem, MetaItemInner, MetaItemKind, NodeId, Path, Visibility, VisibilityKind, }; -use rustc_ast::{YieldKind, ptr}; use rustc_ast_pretty::pprust; use rustc_span::{BytePos, LocalExpnId, Span, Symbol, SyntaxContext, sym, symbol}; use unicode_width::UnicodeWidthStr; @@ -149,8 +149,8 @@ pub(crate) fn format_extern(ext: ast::Extern, explicit_abi: bool) -> Cow<'static } #[inline] -// Transform `Vec<rustc_ast::ptr::P<T>>` into `Vec<&T>` -pub(crate) fn ptr_vec_to_ref_vec<T>(vec: &[ptr::P<T>]) -> Vec<&T> { +// Transform `Vec<Box<T>>` into `Vec<&T>` +pub(crate) fn ptr_vec_to_ref_vec<T>(vec: &[Box<T>]) -> Vec<&T> { vec.iter().map(|x| &**x).collect::<Vec<_>>() } diff --git a/src/tools/rustfmt/src/visitor.rs b/src/tools/rustfmt/src/visitor.rs index f6a9a3f2cd1..23d07c930d9 100644 --- a/src/tools/rustfmt/src/visitor.rs +++ b/src/tools/rustfmt/src/visitor.rs @@ -874,7 +874,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { !is_skip_attr(segments) } - fn walk_mod_items(&mut self, items: &[rustc_ast::ptr::P<ast::Item>]) { + fn walk_mod_items(&mut self, items: &[Box<ast::Item>]) { self.visit_items_with_reordering(&ptr_vec_to_ref_vec(items)); } diff --git a/src/tools/rustfmt/tests/source/negative-impl.rs b/src/tools/rustfmt/tests/source/negative-impl.rs index da242d4f3dc..e8f9508e656 100644 --- a/src/tools/rustfmt/tests/source/negative-impl.rs +++ b/src/tools/rustfmt/tests/source/negative-impl.rs @@ -1,7 +1,3 @@ impl ! Display for JoinHandle { } -impl ! Box < JoinHandle > { } - impl ! std :: fmt :: Display for JoinHandle < T : std :: future :: Future + std :: marker :: Send + std :: marker :: Sync > { } - -impl ! JoinHandle < T : std :: future :: Future < Output > + std :: marker :: Send + std :: marker :: Sync + 'static > + 'static { } diff --git a/src/tools/rustfmt/tests/target/negative-impl.rs b/src/tools/rustfmt/tests/target/negative-impl.rs index 16ce7e26a99..bb53048dbc6 100644 --- a/src/tools/rustfmt/tests/target/negative-impl.rs +++ b/src/tools/rustfmt/tests/target/negative-impl.rs @@ -1,14 +1,6 @@ impl !Display for JoinHandle {} -impl !Box<JoinHandle> {} - impl !std::fmt::Display for JoinHandle<T: std::future::Future + std::marker::Send + std::marker::Sync> { } - -impl - !JoinHandle<T: std::future::Future<Output> + std::marker::Send + std::marker::Sync + 'static> - + 'static -{ -} diff --git a/src/tools/tidy/src/features.rs b/src/tools/tidy/src/features.rs index fb00b3a943f..6618ba24be6 100644 --- a/src/tools/tidy/src/features.rs +++ b/src/tools/tidy/src/features.rs @@ -9,6 +9,7 @@ //! * All unstable lang features have tests to ensure they are actually unstable. //! * Language features in a group are sorted by feature name. +use std::collections::BTreeSet; use std::collections::hash_map::{Entry, HashMap}; use std::ffi::OsStr; use std::num::NonZeroU32; @@ -21,6 +22,7 @@ use crate::walk::{filter_dirs, filter_not_rust, walk, walk_many}; mod tests; mod version; +use regex::Regex; use version::Version; const FEATURE_GROUP_START_PREFIX: &str = "// feature-group-start"; @@ -623,3 +625,36 @@ fn map_lib_features( }, ); } + +fn should_document(var: &str) -> bool { + if var.starts_with("RUSTC_") || var.starts_with("RUST_") || var.starts_with("UNSTABLE_RUSTDOC_") + { + return true; + } + ["SDKROOT", "QNX_TARGET", "COLORTERM", "TERM"].contains(&var) +} + +pub fn collect_env_vars(compiler: &Path) -> BTreeSet<String> { + let env_var_regex: Regex = Regex::new(r#"env::var(_os)?\("([^"]+)"#).unwrap(); + + let mut vars = BTreeSet::new(); + walk( + compiler, + // skip build scripts, tests, and non-rust files + |path, _is_dir| { + filter_dirs(path) + || filter_not_rust(path) + || path.ends_with("build.rs") + || path.ends_with("tests.rs") + }, + &mut |_entry, contents| { + for env_var in env_var_regex.captures_iter(contents).map(|c| c.get(2).unwrap().as_str()) + { + if should_document(env_var) { + vars.insert(env_var.to_owned()); + } + } + }, + ); + vars +} diff --git a/src/tools/tidy/src/unstable_book.rs b/src/tools/tidy/src/unstable_book.rs index 9dc9d42d466..0ed954d48de 100644 --- a/src/tools/tidy/src/unstable_book.rs +++ b/src/tools/tidy/src/unstable_book.rs @@ -6,6 +6,8 @@ use crate::features::{CollectedFeatures, Features, Status}; pub const PATH_STR: &str = "doc/unstable-book"; +pub const ENV_VARS_DIR: &str = "src/compiler-environment-variables"; + pub const COMPILER_FLAGS_DIR: &str = "src/compiler-flags"; pub const LANG_FEATURES_DIR: &str = "src/language-features"; diff --git a/src/tools/unstable-book-gen/src/main.rs b/src/tools/unstable-book-gen/src/main.rs index 159a1d0fa17..a7c6173d88c 100644 --- a/src/tools/unstable-book-gen/src/main.rs +++ b/src/tools/unstable-book-gen/src/main.rs @@ -5,11 +5,11 @@ use std::env; use std::fs::{self, write}; use std::path::Path; -use tidy::features::{Features, collect_lang_features, collect_lib_features}; +use tidy::features::{Features, collect_env_vars, collect_lang_features, collect_lib_features}; use tidy::t; use tidy::unstable_book::{ - LANG_FEATURES_DIR, LIB_FEATURES_DIR, PATH_STR, collect_unstable_book_section_file_names, - collect_unstable_feature_names, + ENV_VARS_DIR, LANG_FEATURES_DIR, LIB_FEATURES_DIR, PATH_STR, + collect_unstable_book_section_file_names, collect_unstable_feature_names, }; fn generate_stub_issue(path: &Path, name: &str, issue: u32, description: &str) { @@ -27,6 +27,11 @@ fn generate_stub_no_issue(path: &Path, name: &str, description: &str) { t!(write(path, content), path); } +fn generate_stub_env_var(path: &Path, name: &str) { + let content = format!(include_str!("stub-env-var.md"), name = name); + t!(write(path, content), path); +} + fn set_to_summary_str(set: &BTreeSet<String>, dir: &str) -> String { set.iter() .map(|ref n| format!(" - [{}]({}/{}.md)", n.replace('-', "_"), dir, n)) @@ -59,7 +64,7 @@ fn generate_summary(path: &Path, lang_features: &Features, lib_features: &Featur t!(write(&summary_path, content), summary_path); } -fn generate_unstable_book_files(src: &Path, out: &Path, features: &Features) { +fn generate_feature_files(src: &Path, out: &Path, features: &Features) { let unstable_features = collect_unstable_feature_names(features); let unstable_section_file_names = collect_unstable_book_section_file_names(src); t!(fs::create_dir_all(&out)); @@ -83,6 +88,16 @@ fn generate_unstable_book_files(src: &Path, out: &Path, features: &Features) { } } +fn generate_env_files(src: &Path, out: &Path, env_vars: &BTreeSet<String>) { + let env_var_file_names = collect_unstable_book_section_file_names(src); + t!(fs::create_dir_all(&out)); + for env_var in env_vars - &env_var_file_names { + let file_name = format!("{env_var}.md"); + let out_file_path = out.join(&file_name); + generate_stub_env_var(&out_file_path, &env_var); + } +} + fn copy_recursive(from: &Path, to: &Path) { for entry in t!(fs::read_dir(from)) { let e = t!(entry); @@ -112,21 +127,23 @@ fn main() { .into_iter() .filter(|&(ref name, _)| !lang_features.contains_key(name)) .collect(); + let env_vars = collect_env_vars(compiler_path); let doc_src_path = src_path.join(PATH_STR); t!(fs::create_dir_all(&dest_path)); - generate_unstable_book_files( + generate_feature_files( &doc_src_path.join(LANG_FEATURES_DIR), &dest_path.join(LANG_FEATURES_DIR), &lang_features, ); - generate_unstable_book_files( + generate_feature_files( &doc_src_path.join(LIB_FEATURES_DIR), &dest_path.join(LIB_FEATURES_DIR), &lib_features, ); + generate_env_files(&doc_src_path.join(ENV_VARS_DIR), &dest_path.join(ENV_VARS_DIR), &env_vars); copy_recursive(&doc_src_path, &dest_path); diff --git a/src/tools/unstable-book-gen/src/stub-env-var.md b/src/tools/unstable-book-gen/src/stub-env-var.md new file mode 100644 index 00000000000..e8a7ddb855a --- /dev/null +++ b/src/tools/unstable-book-gen/src/stub-env-var.md @@ -0,0 +1,9 @@ +# `{name}` + +Environment variables have no tracking issue. This environment variable has no documentation, and therefore is likely internal to the compiler and not meant for general use. + +See [the code][github search] for more information. + +[github search]: https://github.com/search?q=repo%3Arust-lang%2Frust+%22{name}%22+path%3Acompiler&type=code + +------------------------ diff --git a/tests/assembly-llvm/asm/loongarch-type.rs b/tests/assembly-llvm/asm/loongarch-type.rs index c782be19f1d..95d811a6bd0 100644 --- a/tests/assembly-llvm/asm/loongarch-type.rs +++ b/tests/assembly-llvm/asm/loongarch-type.rs @@ -1,8 +1,15 @@ //@ add-core-stubs +//@ revisions: loongarch32 loongarch64 + //@ assembly-output: emit-asm -//@ compile-flags: --target loongarch64-unknown-linux-gnu + +//@[loongarch32] compile-flags: --target loongarch32-unknown-none +//@[loongarch32] needs-llvm-components: loongarch + +//@[loongarch64] compile-flags: --target loongarch64-unknown-none +//@[loongarch64] needs-llvm-components: loongarch + //@ compile-flags: -Zmerge-functions=disabled -//@ needs-llvm-components: loongarch #![feature(no_core, f16)] #![crate_type = "rlib"] @@ -22,7 +29,7 @@ extern "C" { // CHECK-LABEL: sym_fn: // CHECK: #APP // CHECK: pcalau12i $t0, %got_pc_hi20(extern_func) -// CHECK: ld.d $t0, $t0, %got_pc_lo12(extern_func) +// CHECK: ld.{{[wd]}} $t0, $t0, %got_pc_lo12(extern_func) // CHECK: #NO_APP #[no_mangle] pub unsafe fn sym_fn() { @@ -32,7 +39,7 @@ pub unsafe fn sym_fn() { // CHECK-LABEL: sym_static: // CHECK: #APP // CHECK: pcalau12i $t0, %got_pc_hi20(extern_static) -// CHECK: ld.d $t0, $t0, %got_pc_lo12(extern_static) +// CHECK: ld.{{[wd]}} $t0, $t0, %got_pc_lo12(extern_static) // CHECK: #NO_APP #[no_mangle] pub unsafe fn sym_static() { @@ -87,16 +94,18 @@ check!(reg_i32, i32, reg, "move"); // CHECK: #NO_APP check!(reg_f32, f32, reg, "move"); -// CHECK-LABEL: reg_i64: -// CHECK: #APP -// CHECK: move ${{[a-z0-9]+}}, ${{[a-z0-9]+}} -// CHECK: #NO_APP +// loongarch64-LABEL: reg_i64: +// loongarch64: #APP +// loongarch64: move ${{[a-z0-9]+}}, ${{[a-z0-9]+}} +// loongarch64: #NO_APP +#[cfg(loongarch64)] check!(reg_i64, i64, reg, "move"); -// CHECK-LABEL: reg_f64: -// CHECK: #APP -// CHECK: move ${{[a-z0-9]+}}, ${{[a-z0-9]+}} -// CHECK: #NO_APP +// loongarch64-LABEL: reg_f64: +// loongarch64: #APP +// loongarch64: move ${{[a-z0-9]+}}, ${{[a-z0-9]+}} +// loongarch64: #NO_APP +#[cfg(loongarch64)] check!(reg_f64, f64, reg, "move"); // CHECK-LABEL: reg_ptr: @@ -153,16 +162,18 @@ check_reg!(r4_i32, i32, "$r4", "move"); // CHECK: #NO_APP check_reg!(r4_f32, f32, "$r4", "move"); -// CHECK-LABEL: r4_i64: -// CHECK: #APP -// CHECK: move $a0, $a0 -// CHECK: #NO_APP +// loongarch64-LABEL: r4_i64: +// loongarch64: #APP +// loongarch64: move $a0, $a0 +// loongarch64: #NO_APP +#[cfg(loongarch64)] check_reg!(r4_i64, i64, "$r4", "move"); -// CHECK-LABEL: r4_f64: -// CHECK: #APP -// CHECK: move $a0, $a0 -// CHECK: #NO_APP +// loongarch64-LABEL: r4_f64: +// loongarch64: #APP +// loongarch64: move $a0, $a0 +// loongarch64: #NO_APP +#[cfg(loongarch64)] check_reg!(r4_f64, f64, "$r4", "move"); // CHECK-LABEL: r4_ptr: diff --git a/tests/assembly-llvm/x86_64-bigint-helpers.rs b/tests/assembly-llvm/x86_64-bigint-helpers.rs index 58785932bc2..c5efda58fd6 100644 --- a/tests/assembly-llvm/x86_64-bigint-helpers.rs +++ b/tests/assembly-llvm/x86_64-bigint-helpers.rs @@ -2,9 +2,7 @@ //@ assembly-output: emit-asm //@ compile-flags: --crate-type=lib -Copt-level=3 -C target-cpu=x86-64-v4 //@ compile-flags: -C llvm-args=-x86-asm-syntax=intel -//@ revisions: llvm-pre-20 llvm-20 -//@ [llvm-20] min-llvm-version: 20 -//@ [llvm-pre-20] max-llvm-major-version: 19 +//@ min-llvm-version: 20 #![no_std] #![feature(bigint_helper_methods)] @@ -23,16 +21,15 @@ pub unsafe extern "sysv64" fn bigint_chain_carrying_add( n: usize, mut carry: bool, ) -> bool { - // llvm-pre-20: mov [[TEMP:r..]], qword ptr [rsi + 8*[[IND:r..]] + 8] - // llvm-pre-20: adc [[TEMP]], qword ptr [rdx + 8*[[IND]] + 8] - // llvm-pre-20: mov qword ptr [rdi + 8*[[IND]] + 8], [[TEMP]] - // llvm-pre-20: mov [[TEMP]], qword ptr [rsi + 8*[[IND]] + 16] - // llvm-pre-20: adc [[TEMP]], qword ptr [rdx + 8*[[IND]] + 16] - // llvm-pre-20: mov qword ptr [rdi + 8*[[IND]] + 16], [[TEMP]] - // llvm-20: adc [[TEMP:r..]], qword ptr [rdx + 8*[[IND:r..]]] - // llvm-20: mov qword ptr [rdi + 8*[[IND]]], [[TEMP]] - // llvm-20: mov [[TEMP]], qword ptr [rsi + 8*[[IND]] + 8] - // llvm-20: adc [[TEMP]], qword ptr [rdx + 8*[[IND]] + 8] + // Even if we emit A+B, LLVM will sometimes reorder that to B+A, so this + // test doesn't actually check which register is mov vs which is adc. + + // CHECK: mov [[TEMP1:.+]], qword ptr [{{rdx|rsi}} + 8*[[IND:.+]] + 8] + // CHECK: adc [[TEMP1]], qword ptr [{{rdx|rsi}} + 8*[[IND]] + 8] + // CHECK: mov qword ptr [rdi + 8*[[IND]] + 8], [[TEMP1]] + // CHECK: mov [[TEMP2:.+]], qword ptr [{{rdx|rsi}} + 8*[[IND]] + 16] + // CHECK: adc [[TEMP2]], qword ptr [{{rdx|rsi}} + 8*[[IND]] + 16] + // CHECK: mov qword ptr [rdi + 8*[[IND]] + 16], [[TEMP2]] for i in 0..n { (*dest.add(i), carry) = u64::carrying_add(*src1.add(i), *src2.add(i), carry); } diff --git a/tests/codegen-llvm/bigint-helpers.rs b/tests/codegen-llvm/bigint-helpers.rs index 355cccb8150..ec70a3eabed 100644 --- a/tests/codegen-llvm/bigint-helpers.rs +++ b/tests/codegen-llvm/bigint-helpers.rs @@ -3,11 +3,20 @@ #![crate_type = "lib"] #![feature(bigint_helper_methods)] +// Note that there's also an assembly test for this, which is what checks for +// the `ADC` (Add with Carry) instruction on x86 now that the IR we emit uses +// the preferred instruction phrasing instead of the intrinsic. + // CHECK-LABEL: @u32_carrying_add #[no_mangle] pub fn u32_carrying_add(a: u32, b: u32, c: bool) -> (u32, bool) { - // CHECK: @llvm.uadd.with.overflow.i32 - // CHECK: @llvm.uadd.with.overflow.i32 - // CHECK: or disjoint i1 + // CHECK: %[[AB:.+]] = add i32 {{%a, %b|%b, %a}} + // CHECK: %[[O1:.+]] = icmp ult i32 %[[AB]], %a + // CHECK: %[[CEXT:.+]] = zext i1 %c to i32 + // CHECK: %[[ABC:.+]] = add i32 %[[AB]], %[[CEXT]] + // CHECK: %[[O2:.+]] = icmp ult i32 %[[ABC]], %[[AB]] + // CHECK: %[[O:.+]] = or disjoint i1 %[[O1]], %[[O2]] + // CHECK: insertvalue {{.+}}, i32 %[[ABC]], 0 + // CHECK: insertvalue {{.+}}, i1 %[[O]], 1 u32::carrying_add(a, b, c) } diff --git a/tests/codegen-llvm/issues/saturating-sub-index-139759.rs b/tests/codegen-llvm/issues/saturating-sub-index-139759.rs new file mode 100644 index 00000000000..eac2f4d306b --- /dev/null +++ b/tests/codegen-llvm/issues/saturating-sub-index-139759.rs @@ -0,0 +1,19 @@ +// Test that calculating an index with saturating subtraction from an in-bounds +// index doesn't generate another bounds check. + +//@ compile-flags: -Copt-level=3 +//@ min-llvm-version: 21 + +#![crate_type = "lib"] + +// CHECK-LABEL: @bounds_check_is_elided +#[no_mangle] +pub fn bounds_check_is_elided(s: &[i32], index: usize) -> i32 { + // CHECK-NOT: panic_bounds_check + if index < s.len() { + let lower_bound = index.saturating_sub(1); + s[lower_bound] + } else { + -1 + } +} diff --git a/tests/crashes/135646.rs b/tests/crashes/135646.rs deleted file mode 100644 index 841ea5b81b4..00000000000 --- a/tests/crashes/135646.rs +++ /dev/null @@ -1,7 +0,0 @@ -//@ known-bug: #135646 -//@ compile-flags: -Zpolonius=next -//@ edition: 2024 - -fn main() { - &{ [1, 2, 3][4] }; -} diff --git a/tests/run-make/link-under-xcode/foo.rs b/tests/run-make/link-under-xcode/foo.rs new file mode 100644 index 00000000000..f328e4d9d04 --- /dev/null +++ b/tests/run-make/link-under-xcode/foo.rs @@ -0,0 +1 @@ +fn main() {} diff --git a/tests/run-make/link-under-xcode/rmake.rs b/tests/run-make/link-under-xcode/rmake.rs new file mode 100644 index 00000000000..c9394feb000 --- /dev/null +++ b/tests/run-make/link-under-xcode/rmake.rs @@ -0,0 +1,32 @@ +//! Test that linking works under an environment similar to what Xcode sets up. +//! +//! Regression test for https://github.com/rust-lang/rust/issues/80817. + +//@ only-apple + +use run_make_support::{cmd, rustc, target}; + +fn main() { + // Fetch toolchain `/usr/bin` directory. Usually: + // /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin + let clang_bin = cmd("xcrun").arg("--find").arg("clang").run().stdout_utf8(); + let toolchain_bin = clang_bin.trim().strip_suffix("/clang").unwrap(); + + // Put toolchain directory at the front of PATH. + let path = format!("{}:{}", toolchain_bin, std::env::var("PATH").unwrap()); + + // Check that compiling and linking still works. + // + // Removing `SDKROOT` is necessary for the test to excercise what we want, since bootstrap runs + // under `/usr/bin/python3`, which will set SDKROOT for us. + rustc().target(target()).env_remove("SDKROOT").env("PATH", &path).input("foo.rs").run(); + + // Also check linking directly with the system linker. + rustc() + .target(target()) + .env_remove("SDKROOT") + .env("PATH", &path) + .input("foo.rs") + .arg("-Clinker-flavor=ld") + .run(); +} diff --git a/tests/run-make/raw-dylib-link-ordinal/exporter.def b/tests/run-make/raw-dylib-link-ordinal/exporter.def index 5d87c580a54..0544e9f1803 100644 --- a/tests/run-make/raw-dylib-link-ordinal/exporter.def +++ b/tests/run-make/raw-dylib-link-ordinal/exporter.def @@ -1,5 +1,5 @@ LIBRARY exporter EXPORTS exported_function @13 NONAME - exported_variable @5 NONAME + exported_variable @5 NONAME DATA print_exported_variable @9 NONAME diff --git a/tests/run-make/raw-dylib-link-ordinal/rmake.rs b/tests/run-make/raw-dylib-link-ordinal/rmake.rs index 43274b9765b..b9254b16753 100644 --- a/tests/run-make/raw-dylib-link-ordinal/rmake.rs +++ b/tests/run-make/raw-dylib-link-ordinal/rmake.rs @@ -11,7 +11,7 @@ //@ only-windows -use run_make_support::{cc, diff, is_windows_msvc, run, rustc}; +use run_make_support::{cc, diff, extra_c_flags, is_windows_msvc, run, rustc}; // NOTE: build_native_dynamic lib is not used, as the special `def` files // must be passed to the CC compiler. @@ -24,6 +24,7 @@ fn main() { cc().input("exporter.obj") .arg("exporter.def") .args(&["-link", "-dll", "-noimplib", "-out:exporter.dll"]) + .args(extra_c_flags()) .run(); } else { cc().arg("-v").arg("-c").out_exe("exporter.obj").input("exporter.c").run(); diff --git a/tests/run-make/wasm-panic-small/rmake.rs b/tests/run-make/wasm-panic-small/rmake.rs index e69fbac9635..ea0b6faf037 100644 --- a/tests/run-make/wasm-panic-small/rmake.rs +++ b/tests/run-make/wasm-panic-small/rmake.rs @@ -24,5 +24,5 @@ fn test(cfg: &str) { let bytes = rfs::read("foo.wasm"); println!("{}", bytes.len()); - assert!(bytes.len() < 40_000); + assert!(bytes.len() < 40_000, "bytes len was: {}", bytes.len()); } diff --git a/tests/rustdoc-ui/intra-doc/github-flavored-admonitions.rs b/tests/rustdoc-ui/intra-doc/github-flavored-admonitions.rs new file mode 100644 index 00000000000..d5fa72eb993 --- /dev/null +++ b/tests/rustdoc-ui/intra-doc/github-flavored-admonitions.rs @@ -0,0 +1,6 @@ +// regression test for https://github.com/rust-lang/rust/issues/141866 +//@ check-pass +#![deny(rustdoc::broken_intra_doc_links)] + +//! > [!NOTE] +//! > This should not cause any warnings diff --git a/tests/rustdoc/enum/enum-variant-value.rs b/tests/rustdoc/enum/enum-variant-value.rs index 1670de8a24f..9cc85dfe10d 100644 --- a/tests/rustdoc/enum/enum-variant-value.rs +++ b/tests/rustdoc/enum/enum-variant-value.rs @@ -189,3 +189,25 @@ pub use bar::P; //@ has - '//*[@id="variant.A"]/h3' 'A(u32)' //@ matches - '//*[@id="variant.B"]/h3' '^B$' pub use bar::Q; + +// Ensure signed implicit discriminants are rendered correctly after a negative explicit value. +//@ has 'foo/enum.R.html' +//@ has - '//*[@class="rust item-decl"]/code' 'A = -2,' +//@ has - '//*[@class="rust item-decl"]/code' 'B = -1,' +//@ matches - '//*[@id="variant.A"]/h3' '^A = -2$' +//@ matches - '//*[@id="variant.B"]/h3' '^B = -1$' +pub enum R { + A = -2, + B, +} + +// Also check that incrementing -1 yields 0 for the next implicit variant. +//@ has 'foo/enum.S.html' +//@ has - '//*[@class="rust item-decl"]/code' 'A = -1,' +//@ has - '//*[@class="rust item-decl"]/code' 'B = 0,' +//@ matches - '//*[@id="variant.A"]/h3' '^A = -1$' +//@ matches - '//*[@id="variant.B"]/h3' '^B = 0$' +pub enum S { + A = -1, + B, +} diff --git a/tests/ui-fulldeps/auxiliary/parser.rs b/tests/ui-fulldeps/auxiliary/parser.rs index 8a370512460..6726969350d 100644 --- a/tests/ui-fulldeps/auxiliary/parser.rs +++ b/tests/ui-fulldeps/auxiliary/parser.rs @@ -10,7 +10,6 @@ extern crate rustc_span; use rustc_ast::ast::{AttrKind, Attribute, DUMMY_NODE_ID, Expr}; use rustc_ast::mut_visit::{self, MutVisitor}; use rustc_ast::node_id::NodeId; -use rustc_ast::ptr::P; use rustc_ast::token::{self, Token}; use rustc_ast::tokenstream::{AttrTokenStream, AttrTokenTree, LazyAttrTokenStream}; use rustc_errors::Diag; @@ -19,7 +18,7 @@ use rustc_session::parse::ParseSess; use rustc_span::{AttrId, DUMMY_SP, FileName, Span}; use std::sync::Arc; -pub fn parse_expr(psess: &ParseSess, source_code: &str) -> Option<P<Expr>> { +pub fn parse_expr(psess: &ParseSess, source_code: &str) -> Option<Box<Expr>> { let parser = rustc_parse::unwrap_or_emit_fatal(rustc_parse::new_parser_from_source_str( psess, FileName::anon_source_code(source_code), diff --git a/tests/ui-fulldeps/pprust-expr-roundtrip.rs b/tests/ui-fulldeps/pprust-expr-roundtrip.rs index 8bca20852ad..08ded2aee53 100644 --- a/tests/ui-fulldeps/pprust-expr-roundtrip.rs +++ b/tests/ui-fulldeps/pprust-expr-roundtrip.rs @@ -35,7 +35,6 @@ extern crate rustc_driver; use parser::parse_expr; use rustc_ast::mut_visit::MutVisitor; -use rustc_ast::ptr::P; use rustc_ast::*; use rustc_ast_pretty::pprust; use rustc_session::parse::ParseSess; @@ -45,11 +44,11 @@ use rustc_span::DUMMY_SP; use thin_vec::{thin_vec, ThinVec}; // Helper functions for building exprs -fn expr(kind: ExprKind) -> P<Expr> { - P(Expr { id: DUMMY_NODE_ID, kind, span: DUMMY_SP, attrs: AttrVec::new(), tokens: None }) +fn expr(kind: ExprKind) -> Box<Expr> { + Box::new(Expr { id: DUMMY_NODE_ID, kind, span: DUMMY_SP, attrs: AttrVec::new(), tokens: None }) } -fn make_x() -> P<Expr> { +fn make_x() -> Box<Expr> { let seg = PathSegment::from_ident(Ident::from_str("x")); let path = Path { segments: thin_vec![seg], span: DUMMY_SP, tokens: None }; expr(ExprKind::Path(None, path)) @@ -58,7 +57,7 @@ fn make_x() -> P<Expr> { /// Iterate over exprs of depth up to `depth`. The goal is to explore all "interesting" /// combinations of expression nesting. For example, we explore combinations using `if`, but not /// `while` or `match`, since those should print and parse in much the same way as `if`. -fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) { +fn iter_exprs(depth: usize, f: &mut dyn FnMut(Box<Expr>)) { if depth == 0 { f(make_x()); return; @@ -108,7 +107,7 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) { iter_exprs(depth - 1, &mut |e| g(ExprKind::Unary(UnOp::Deref, e))); } 9 => { - let block = P(Block { + let block = Box::new(Block { stmts: ThinVec::new(), id: DUMMY_NODE_ID, rules: BlockCheckMode::Default, @@ -118,7 +117,10 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) { iter_exprs(depth - 1, &mut |e| g(ExprKind::If(e, block.clone(), None))); } 10 => { - let decl = P(FnDecl { inputs: thin_vec![], output: FnRetTy::Default(DUMMY_SP) }); + let decl = Box::new(FnDecl { + inputs: thin_vec![], + output: FnRetTy::Default(DUMMY_SP), + }); iter_exprs(depth - 1, &mut |e| { g(ExprKind::Closure(Box::new(Closure { binder: ClosureBinder::NotPresent, @@ -159,7 +161,7 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) { } 16 => { let path = Path::from_ident(Ident::from_str("S")); - g(ExprKind::Struct(P(StructExpr { + g(ExprKind::Struct(Box::new(StructExpr { qself: None, path, fields: thin_vec![], @@ -170,8 +172,12 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) { iter_exprs(depth - 1, &mut |e| g(ExprKind::Try(e))); } 18 => { - let pat = - P(Pat { id: DUMMY_NODE_ID, kind: PatKind::Wild, span: DUMMY_SP, tokens: None }); + let pat = Box::new(Pat { + id: DUMMY_NODE_ID, + kind: PatKind::Wild, + span: DUMMY_SP, + tokens: None, + }); iter_exprs(depth - 1, &mut |e| { g(ExprKind::Let(pat.clone(), e, DUMMY_SP, Recovered::No)) }) @@ -204,7 +210,7 @@ impl MutVisitor for AddParens { mut_visit::walk_expr(self, e); let expr = std::mem::replace(e, Expr::dummy()); - e.kind = ExprKind::Paren(P(expr)); + e.kind = ExprKind::Paren(Box::new(expr)); } } diff --git a/tests/ui/argument-suggestions/issue-100478.stderr b/tests/ui/argument-suggestions/issue-100478.stderr index 8889a0ab5df..81dbff2f000 100644 --- a/tests/ui/argument-suggestions/issue-100478.stderr +++ b/tests/ui/argument-suggestions/issue-100478.stderr @@ -75,12 +75,16 @@ LL | fn foo(p1: T1, p2: Arc<T2>, p3: T3, p4: Arc<T4>, p5: T5, p6: T6, p7: T7, p8 | ^^^ ----------- help: provide the argument | -LL - foo( -LL - -LL - p1, //p2, -LL - p3, p4, p5, p6, p7, p8, -LL - ); -LL + foo(p1, /* Arc<T2> */, p3, p4, p5, p6, p7, p8); +LL ~ foo( +LL + p1, +LL + /* Arc<T2> */, +LL + p3, +LL + p4, +LL + p5, +LL + p6, +LL + p7, +LL + p8, +LL ~ ); | error: aborting due to 4 previous errors diff --git a/tests/ui/asm/loongarch/bad-reg.loongarch32_ilp32d.stderr b/tests/ui/asm/loongarch/bad-reg.loongarch32_ilp32d.stderr new file mode 100644 index 00000000000..8742d4bd82c --- /dev/null +++ b/tests/ui/asm/loongarch/bad-reg.loongarch32_ilp32d.stderr @@ -0,0 +1,38 @@ +error: invalid register `$r0`: constant zero cannot be used as an operand for inline asm + --> $DIR/bad-reg.rs:27:18 + | +LL | asm!("", out("$r0") _); + | ^^^^^^^^^^^^ + +error: invalid register `$tp`: reserved for TLS + --> $DIR/bad-reg.rs:29:18 + | +LL | asm!("", out("$tp") _); + | ^^^^^^^^^^^^ + +error: invalid register `$sp`: the stack pointer cannot be used as an operand for inline asm + --> $DIR/bad-reg.rs:31:18 + | +LL | asm!("", out("$sp") _); + | ^^^^^^^^^^^^ + +error: invalid register `$r21`: reserved by the ABI + --> $DIR/bad-reg.rs:33:18 + | +LL | asm!("", out("$r21") _); + | ^^^^^^^^^^^^^ + +error: invalid register `$fp`: the frame pointer cannot be used as an operand for inline asm + --> $DIR/bad-reg.rs:35:18 + | +LL | asm!("", out("$fp") _); + | ^^^^^^^^^^^^ + +error: invalid register `$r31`: $r31 is used internally by LLVM and cannot be used as an operand for inline asm + --> $DIR/bad-reg.rs:37:18 + | +LL | asm!("", out("$r31") _); + | ^^^^^^^^^^^^^ + +error: aborting due to 6 previous errors + diff --git a/tests/ui/asm/loongarch/bad-reg.loongarch32_ilp32s.stderr b/tests/ui/asm/loongarch/bad-reg.loongarch32_ilp32s.stderr new file mode 100644 index 00000000000..e6cb6e40c70 --- /dev/null +++ b/tests/ui/asm/loongarch/bad-reg.loongarch32_ilp32s.stderr @@ -0,0 +1,62 @@ +error: invalid register `$r0`: constant zero cannot be used as an operand for inline asm + --> $DIR/bad-reg.rs:27:18 + | +LL | asm!("", out("$r0") _); + | ^^^^^^^^^^^^ + +error: invalid register `$tp`: reserved for TLS + --> $DIR/bad-reg.rs:29:18 + | +LL | asm!("", out("$tp") _); + | ^^^^^^^^^^^^ + +error: invalid register `$sp`: the stack pointer cannot be used as an operand for inline asm + --> $DIR/bad-reg.rs:31:18 + | +LL | asm!("", out("$sp") _); + | ^^^^^^^^^^^^ + +error: invalid register `$r21`: reserved by the ABI + --> $DIR/bad-reg.rs:33:18 + | +LL | asm!("", out("$r21") _); + | ^^^^^^^^^^^^^ + +error: invalid register `$fp`: the frame pointer cannot be used as an operand for inline asm + --> $DIR/bad-reg.rs:35:18 + | +LL | asm!("", out("$fp") _); + | ^^^^^^^^^^^^ + +error: invalid register `$r31`: $r31 is used internally by LLVM and cannot be used as an operand for inline asm + --> $DIR/bad-reg.rs:37:18 + | +LL | asm!("", out("$r31") _); + | ^^^^^^^^^^^^^ + +error: register class `freg` requires at least one of the following target features: d, f + --> $DIR/bad-reg.rs:41:26 + | +LL | asm!("/* {} */", in(freg) f); + | ^^^^^^^^^^ + +error: register class `freg` requires at least one of the following target features: d, f + --> $DIR/bad-reg.rs:43:26 + | +LL | asm!("/* {} */", out(freg) _); + | ^^^^^^^^^^^ + +error: register class `freg` requires at least one of the following target features: d, f + --> $DIR/bad-reg.rs:45:26 + | +LL | asm!("/* {} */", in(freg) d); + | ^^^^^^^^^^ + +error: register class `freg` requires at least one of the following target features: d, f + --> $DIR/bad-reg.rs:47:26 + | +LL | asm!("/* {} */", out(freg) d); + | ^^^^^^^^^^^ + +error: aborting due to 10 previous errors + diff --git a/tests/ui/asm/loongarch/bad-reg.loongarch64_lp64d.stderr b/tests/ui/asm/loongarch/bad-reg.loongarch64_lp64d.stderr index 0e544119650..8742d4bd82c 100644 --- a/tests/ui/asm/loongarch/bad-reg.loongarch64_lp64d.stderr +++ b/tests/ui/asm/loongarch/bad-reg.loongarch64_lp64d.stderr @@ -1,35 +1,35 @@ error: invalid register `$r0`: constant zero cannot be used as an operand for inline asm - --> $DIR/bad-reg.rs:22:18 + --> $DIR/bad-reg.rs:27:18 | LL | asm!("", out("$r0") _); | ^^^^^^^^^^^^ error: invalid register `$tp`: reserved for TLS - --> $DIR/bad-reg.rs:24:18 + --> $DIR/bad-reg.rs:29:18 | LL | asm!("", out("$tp") _); | ^^^^^^^^^^^^ error: invalid register `$sp`: the stack pointer cannot be used as an operand for inline asm - --> $DIR/bad-reg.rs:26:18 + --> $DIR/bad-reg.rs:31:18 | LL | asm!("", out("$sp") _); | ^^^^^^^^^^^^ error: invalid register `$r21`: reserved by the ABI - --> $DIR/bad-reg.rs:28:18 + --> $DIR/bad-reg.rs:33:18 | LL | asm!("", out("$r21") _); | ^^^^^^^^^^^^^ error: invalid register `$fp`: the frame pointer cannot be used as an operand for inline asm - --> $DIR/bad-reg.rs:30:18 + --> $DIR/bad-reg.rs:35:18 | LL | asm!("", out("$fp") _); | ^^^^^^^^^^^^ error: invalid register `$r31`: $r31 is used internally by LLVM and cannot be used as an operand for inline asm - --> $DIR/bad-reg.rs:32:18 + --> $DIR/bad-reg.rs:37:18 | LL | asm!("", out("$r31") _); | ^^^^^^^^^^^^^ diff --git a/tests/ui/asm/loongarch/bad-reg.loongarch64_lp64s.stderr b/tests/ui/asm/loongarch/bad-reg.loongarch64_lp64s.stderr index 6d0410dc6a1..e6cb6e40c70 100644 --- a/tests/ui/asm/loongarch/bad-reg.loongarch64_lp64s.stderr +++ b/tests/ui/asm/loongarch/bad-reg.loongarch64_lp64s.stderr @@ -1,59 +1,59 @@ error: invalid register `$r0`: constant zero cannot be used as an operand for inline asm - --> $DIR/bad-reg.rs:22:18 + --> $DIR/bad-reg.rs:27:18 | LL | asm!("", out("$r0") _); | ^^^^^^^^^^^^ error: invalid register `$tp`: reserved for TLS - --> $DIR/bad-reg.rs:24:18 + --> $DIR/bad-reg.rs:29:18 | LL | asm!("", out("$tp") _); | ^^^^^^^^^^^^ error: invalid register `$sp`: the stack pointer cannot be used as an operand for inline asm - --> $DIR/bad-reg.rs:26:18 + --> $DIR/bad-reg.rs:31:18 | LL | asm!("", out("$sp") _); | ^^^^^^^^^^^^ error: invalid register `$r21`: reserved by the ABI - --> $DIR/bad-reg.rs:28:18 + --> $DIR/bad-reg.rs:33:18 | LL | asm!("", out("$r21") _); | ^^^^^^^^^^^^^ error: invalid register `$fp`: the frame pointer cannot be used as an operand for inline asm - --> $DIR/bad-reg.rs:30:18 + --> $DIR/bad-reg.rs:35:18 | LL | asm!("", out("$fp") _); | ^^^^^^^^^^^^ error: invalid register `$r31`: $r31 is used internally by LLVM and cannot be used as an operand for inline asm - --> $DIR/bad-reg.rs:32:18 + --> $DIR/bad-reg.rs:37:18 | LL | asm!("", out("$r31") _); | ^^^^^^^^^^^^^ error: register class `freg` requires at least one of the following target features: d, f - --> $DIR/bad-reg.rs:36:26 + --> $DIR/bad-reg.rs:41:26 | LL | asm!("/* {} */", in(freg) f); | ^^^^^^^^^^ error: register class `freg` requires at least one of the following target features: d, f - --> $DIR/bad-reg.rs:38:26 + --> $DIR/bad-reg.rs:43:26 | LL | asm!("/* {} */", out(freg) _); | ^^^^^^^^^^^ error: register class `freg` requires at least one of the following target features: d, f - --> $DIR/bad-reg.rs:40:26 + --> $DIR/bad-reg.rs:45:26 | LL | asm!("/* {} */", in(freg) d); | ^^^^^^^^^^ error: register class `freg` requires at least one of the following target features: d, f - --> $DIR/bad-reg.rs:42:26 + --> $DIR/bad-reg.rs:47:26 | LL | asm!("/* {} */", out(freg) d); | ^^^^^^^^^^^ diff --git a/tests/ui/asm/loongarch/bad-reg.rs b/tests/ui/asm/loongarch/bad-reg.rs index 685b460bc92..0d3eba07f14 100644 --- a/tests/ui/asm/loongarch/bad-reg.rs +++ b/tests/ui/asm/loongarch/bad-reg.rs @@ -1,6 +1,11 @@ //@ add-core-stubs //@ needs-asm-support -//@ revisions: loongarch64_lp64d loongarch64_lp64s +//@ revisions: loongarch32_ilp32d loongarch32_ilp32s loongarch64_lp64d loongarch64_lp64s +//@ min-llvm-version: 20 +//@[loongarch32_ilp32d] compile-flags: --target loongarch32-unknown-none +//@[loongarch32_ilp32d] needs-llvm-components: loongarch +//@[loongarch32_ilp32s] compile-flags: --target loongarch32-unknown-none-softfloat +//@[loongarch32_ilp32s] needs-llvm-components: loongarch //@[loongarch64_lp64d] compile-flags: --target loongarch64-unknown-linux-gnu //@[loongarch64_lp64d] needs-llvm-components: loongarch //@[loongarch64_lp64s] compile-flags: --target loongarch64-unknown-none-softfloat @@ -34,12 +39,12 @@ fn f() { asm!("", out("$f0") _); // ok asm!("/* {} */", in(freg) f); - //[loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f + //[loongarch32_ilp32s,loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f asm!("/* {} */", out(freg) _); - //[loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f + //[loongarch32_ilp32s,loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f asm!("/* {} */", in(freg) d); - //[loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f + //[loongarch32_ilp32s,loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f asm!("/* {} */", out(freg) d); - //[loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f + //[loongarch32_ilp32s,loongarch64_lp64s]~^ ERROR register class `freg` requires at least one of the following target features: d, f } } diff --git a/tests/ui/issues/issue-23442.rs b/tests/ui/associated-types/unioned-keys-with-associated-type-23442.rs index 883c5bb511a..89a2d0177a3 100644 --- a/tests/ui/issues/issue-23442.rs +++ b/tests/ui/associated-types/unioned-keys-with-associated-type-23442.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/23442 //@ check-pass #![allow(dead_code)] use std::marker::PhantomData; diff --git a/tests/ui/async-await/drop-live-upvar-2.may_not_dangle.stderr b/tests/ui/async-await/drop-live-upvar-2.may_not_dangle.stderr new file mode 100644 index 00000000000..34f6ba79246 --- /dev/null +++ b/tests/ui/async-await/drop-live-upvar-2.may_not_dangle.stderr @@ -0,0 +1,18 @@ +error[E0597]: `y` does not live long enough + --> $DIR/drop-live-upvar-2.rs:31:26 + | +LL | let y = (); + | - binding `y` declared here +LL | drop_me = Droppy(&y); + | ^^ borrowed value does not live long enough +... +LL | } + | - `y` dropped here while still borrowed +LL | } + | - borrow might be used here, when `fut` is dropped and runs the destructor for coroutine + | + = note: values in a scope are dropped in the opposite order they are defined + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0597`. diff --git a/tests/ui/async-await/drop-live-upvar-2.rs b/tests/ui/async-await/drop-live-upvar-2.rs new file mode 100644 index 00000000000..605db4c8f76 --- /dev/null +++ b/tests/ui/async-await/drop-live-upvar-2.rs @@ -0,0 +1,37 @@ +//@ revisions: may_dangle may_not_dangle +//@[may_dangle] check-pass +//@ edition: 2018 + +// Ensure that if a coroutine's interior has no drop types then we don't require the upvars to +// be *use-live*, but instead require them to be *drop-live*. In this case, `Droppy<&'?0 ()>` +// does not require that `'?0` is live for drops since the parameter is `#[may_dangle]` in +// the may_dangle revision, but not in the may_not_dangle revision. + +#![feature(dropck_eyepatch)] + +struct Droppy<T>(T); + +#[cfg(may_dangle)] +unsafe impl<#[may_dangle] T> Drop for Droppy<T> { + fn drop(&mut self) { + // This does not use `T` of course. + } +} + +#[cfg(may_not_dangle)] +impl<T> Drop for Droppy<T> { + fn drop(&mut self) {} +} + +fn main() { + let drop_me; + let fut; + { + let y = (); + drop_me = Droppy(&y); + //[may_not_dangle]~^ ERROR `y` does not live long enough + fut = async { + std::mem::drop(drop_me); + }; + } +} diff --git a/tests/ui/async-await/drop-live-upvar.rs b/tests/ui/async-await/drop-live-upvar.rs new file mode 100644 index 00000000000..8e881f729b9 --- /dev/null +++ b/tests/ui/async-await/drop-live-upvar.rs @@ -0,0 +1,23 @@ +//@ edition: 2018 +// Regression test for <https://github.com/rust-lang/rust/issues/144155>. + +struct NeedsDrop<'a>(&'a Vec<i32>); + +async fn await_point() {} + +impl Drop for NeedsDrop<'_> { + fn drop(&mut self) {} +} + +fn foo() { + let v = vec![1, 2, 3]; + let x = NeedsDrop(&v); + let c = async { + std::future::ready(()).await; + drop(x); + }; + drop(v); + //~^ ERROR cannot move out of `v` because it is borrowed +} + +fn main() {} diff --git a/tests/ui/async-await/drop-live-upvar.stderr b/tests/ui/async-await/drop-live-upvar.stderr new file mode 100644 index 00000000000..f804484536b --- /dev/null +++ b/tests/ui/async-await/drop-live-upvar.stderr @@ -0,0 +1,22 @@ +error[E0505]: cannot move out of `v` because it is borrowed + --> $DIR/drop-live-upvar.rs:19:10 + | +LL | let v = vec![1, 2, 3]; + | - binding `v` declared here +LL | let x = NeedsDrop(&v); + | -- borrow of `v` occurs here +... +LL | drop(v); + | ^ move out of `v` occurs here +LL | +LL | } + | - borrow might be used here, when `c` is dropped and runs the destructor for coroutine + | +help: consider cloning the value if the performance cost is acceptable + | +LL | let x = NeedsDrop(&v.clone()); + | ++++++++ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0505`. diff --git a/tests/ui/async-await/recursive-async-auto-trait-overflow.rs b/tests/ui/async-await/recursive-async-auto-trait-overflow.rs new file mode 100644 index 00000000000..716600ce472 --- /dev/null +++ b/tests/ui/async-await/recursive-async-auto-trait-overflow.rs @@ -0,0 +1,14 @@ +// Regression test for <https://github.com/rust-lang/rust/issues/145151>. + +//@ edition: 2024 +//@ check-pass + +async fn process<'a>() { + Box::pin(process()).await; +} + +fn require_send(_: impl Send) {} + +fn main() { + require_send(process()); +} diff --git a/tests/ui/attributes/crate-name-macro-call.stderr b/tests/ui/attributes/crate-name-macro-call.stderr index ab562b41a31..56827aa11a4 100644 --- a/tests/ui/attributes/crate-name-macro-call.stderr +++ b/tests/ui/attributes/crate-name-macro-call.stderr @@ -3,6 +3,8 @@ error: malformed `crate_name` attribute input | LL | #![crate_name = concat!("my", "crate")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#![crate_name = "name"]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/crates-and-source-files.html#the-crate_name-attribute> error: aborting due to 1 previous error diff --git a/tests/ui/attributes/crate-type-delimited.stderr b/tests/ui/attributes/crate-type-delimited.stderr index 0bbbe07b198..7f080f74838 100644 --- a/tests/ui/attributes/crate-type-delimited.stderr +++ b/tests/ui/attributes/crate-type-delimited.stderr @@ -2,7 +2,24 @@ error: malformed `crate_type` attribute input --> $DIR/crate-type-delimited.rs:2:1 | LL | #![crate_type(lib)] - | ^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#![crate_type = "bin|lib|..."]` + | ^^^^^^^^^^^^^^^^^^^ + | + = note: for more information, visit <https://doc.rust-lang.org/reference/linkage.html> +help: the following are the possible correct uses + | +LL - #![crate_type(lib)] +LL + #![crate_type = "bin"] + | +LL - #![crate_type(lib)] +LL + #![crate_type = "cdylib"] + | +LL - #![crate_type(lib)] +LL + #![crate_type = "dylib"] + | +LL - #![crate_type(lib)] +LL + #![crate_type = "lib"] + | + = and 4 other candidates error: aborting due to 1 previous error diff --git a/tests/ui/attributes/crate-type-empty.stderr b/tests/ui/attributes/crate-type-empty.stderr index b9279d961ee..f50bb33d6bb 100644 --- a/tests/ui/attributes/crate-type-empty.stderr +++ b/tests/ui/attributes/crate-type-empty.stderr @@ -2,7 +2,20 @@ error: malformed `crate_type` attribute input --> $DIR/crate-type-empty.rs:2:1 | LL | #![crate_type] - | ^^^^^^^^^^^^^^ help: must be of the form: `#![crate_type = "bin|lib|..."]` + | ^^^^^^^^^^^^^^ + | + = note: for more information, visit <https://doc.rust-lang.org/reference/linkage.html> +help: the following are the possible correct uses + | +LL | #![crate_type = "bin"] + | +++++++ +LL | #![crate_type = "cdylib"] + | ++++++++++ +LL | #![crate_type = "dylib"] + | +++++++++ +LL | #![crate_type = "lib"] + | +++++++ + = and 4 other candidates error: aborting due to 1 previous error diff --git a/tests/ui/attributes/crate-type-macro-call.stderr b/tests/ui/attributes/crate-type-macro-call.stderr index 6ccc3edf885..97938f7af24 100644 --- a/tests/ui/attributes/crate-type-macro-call.stderr +++ b/tests/ui/attributes/crate-type-macro-call.stderr @@ -2,7 +2,24 @@ error: malformed `crate_type` attribute input --> $DIR/crate-type-macro-call.rs:1:1 | LL | #![crate_type = foo!()] - | ^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#![crate_type = "bin|lib|..."]` + | ^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: for more information, visit <https://doc.rust-lang.org/reference/linkage.html> +help: the following are the possible correct uses + | +LL - #![crate_type = foo!()] +LL + #![crate_type = "bin"] + | +LL - #![crate_type = foo!()] +LL + #![crate_type = "cdylib"] + | +LL - #![crate_type = foo!()] +LL + #![crate_type = "dylib"] + | +LL - #![crate_type = foo!()] +LL + #![crate_type = "lib"] + | + = and 4 other candidates error: aborting due to 1 previous error diff --git a/tests/ui/attributes/invalid-macro-use.rs b/tests/ui/attributes/invalid-macro-use.rs index cfb13fd183c..52e4608303f 100644 --- a/tests/ui/attributes/invalid-macro-use.rs +++ b/tests/ui/attributes/invalid-macro-use.rs @@ -8,21 +8,25 @@ extern crate std as s1; #[macro_use(5)] //~^ ERROR malformed `macro_use` attribute input //~| NOTE expected a valid identifier here +//~| NOTE for more information, visit extern crate std as s2; #[macro_use(a = "b")] //~^ ERROR malformed `macro_use` attribute input //~| NOTE didn't expect any arguments here +//~| NOTE for more information, visit extern crate std as s3; #[macro_use(a(b))] //~^ ERROR malformed `macro_use` attribute input //~| NOTE didn't expect any arguments here +//~| NOTE for more information, visit extern crate std as s4; #[macro_use(a::b)] //~^ ERROR malformed `macro_use` attribute input //~| NOTE expected a valid identifier here +//~| NOTE for more information, visit extern crate std as s5; #[macro_use(a)] diff --git a/tests/ui/attributes/invalid-macro-use.stderr b/tests/ui/attributes/invalid-macro-use.stderr index 4f5db5c558a..ff3ed6196d3 100644 --- a/tests/ui/attributes/invalid-macro-use.stderr +++ b/tests/ui/attributes/invalid-macro-use.stderr @@ -1,11 +1,11 @@ error[E0469]: imported macro not found - --> $DIR/invalid-macro-use.rs:47:13 + --> $DIR/invalid-macro-use.rs:51:13 | LL | #[macro_use(a)] | ^ error[E0469]: imported macro not found - --> $DIR/invalid-macro-use.rs:49:13 + --> $DIR/invalid-macro-use.rs:53:13 | LL | #[macro_use(b)] | ^ @@ -24,6 +24,7 @@ LL | #[macro_use(5)] | | | expected a valid identifier here | + = note: for more information, visit <https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute> help: try changing it to one of the following valid forms of the attribute | LL - #[macro_use(5)] @@ -34,13 +35,14 @@ LL + #[macro_use] | error[E0565]: malformed `macro_use` attribute input - --> $DIR/invalid-macro-use.rs:13:1 + --> $DIR/invalid-macro-use.rs:14:1 | LL | #[macro_use(a = "b")] | ^^^^^^^^^^^^^^-----^^ | | | didn't expect any arguments here | + = note: for more information, visit <https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute> help: try changing it to one of the following valid forms of the attribute | LL - #[macro_use(a = "b")] @@ -51,13 +53,14 @@ LL + #[macro_use] | error[E0565]: malformed `macro_use` attribute input - --> $DIR/invalid-macro-use.rs:18:1 + --> $DIR/invalid-macro-use.rs:20:1 | LL | #[macro_use(a(b))] | ^^^^^^^^^^^^^---^^ | | | didn't expect any arguments here | + = note: for more information, visit <https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute> help: try changing it to one of the following valid forms of the attribute | LL - #[macro_use(a(b))] @@ -68,13 +71,14 @@ LL + #[macro_use] | error[E0539]: malformed `macro_use` attribute input - --> $DIR/invalid-macro-use.rs:23:1 + --> $DIR/invalid-macro-use.rs:26:1 | LL | #[macro_use(a::b)] | ^^^^^^^^^^^^----^^ | | | expected a valid identifier here | + = note: for more information, visit <https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute> help: try changing it to one of the following valid forms of the attribute | LL - #[macro_use(a::b)] @@ -85,13 +89,13 @@ LL + #[macro_use] | error: unused attribute - --> $DIR/invalid-macro-use.rs:28:1 + --> $DIR/invalid-macro-use.rs:32:1 | LL | #[macro_use(a)] | ^^^^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/invalid-macro-use.rs:30:1 + --> $DIR/invalid-macro-use.rs:34:1 | LL | #[macro_use] | ^^^^^^^^^^^^ @@ -102,25 +106,25 @@ LL | #![deny(unused_attributes)] | ^^^^^^^^^^^^^^^^^ error: unused attribute - --> $DIR/invalid-macro-use.rs:36:1 + --> $DIR/invalid-macro-use.rs:40:1 | LL | #[macro_use(a)] | ^^^^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/invalid-macro-use.rs:34:1 + --> $DIR/invalid-macro-use.rs:38:1 | LL | #[macro_use] | ^^^^^^^^^^^^ error: unused attribute - --> $DIR/invalid-macro-use.rs:42:1 + --> $DIR/invalid-macro-use.rs:46:1 | LL | #[macro_use] | ^^^^^^^^^^^^ help: remove this attribute | note: attribute also specified here - --> $DIR/invalid-macro-use.rs:40:1 + --> $DIR/invalid-macro-use.rs:44:1 | LL | #[macro_use] | ^^^^^^^^^^^^ diff --git a/tests/ui/attributes/invalid-reprs.stderr b/tests/ui/attributes/invalid-reprs.stderr index 415b969b244..72aaff92bd0 100644 --- a/tests/ui/attributes/invalid-reprs.stderr +++ b/tests/ui/attributes/invalid-reprs.stderr @@ -26,6 +26,7 @@ LL | let y = #[repr(uwu(4))] | ^^^^^^ | = help: valid reprs are `Rust` (default), `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize` + = note: for more information, visit <https://doc.rust-lang.org/reference/type-layout.html?highlight=repr#representations> error: aborting due to 3 previous errors diff --git a/tests/ui/attributes/lint_on_root.rs b/tests/ui/attributes/lint_on_root.rs index 93d47bf0d71..9029da7dc97 100644 --- a/tests/ui/attributes/lint_on_root.rs +++ b/tests/ui/attributes/lint_on_root.rs @@ -1,7 +1,7 @@ // NOTE: this used to panic in debug builds (by a sanity assertion) // and not emit any lint on release builds. See https://github.com/rust-lang/rust/issues/142891. #![inline = ""] -//~^ ERROR valid forms for the attribute are `#[inline(always|never)]` and `#[inline]` +//~^ ERROR: valid forms for the attribute are `#[inline(always)]`, `#[inline(never)]`, and `#[inline]` [ill_formed_attribute_input] //~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! fn main() {} diff --git a/tests/ui/attributes/lint_on_root.stderr b/tests/ui/attributes/lint_on_root.stderr index aaa46e6f54b..91b72730530 100644 --- a/tests/ui/attributes/lint_on_root.stderr +++ b/tests/ui/attributes/lint_on_root.stderr @@ -1,4 +1,4 @@ -error: valid forms for the attribute are `#[inline(always|never)]` and `#[inline]` +error: valid forms for the attribute are `#[inline(always)]`, `#[inline(never)]`, and `#[inline]` --> $DIR/lint_on_root.rs:3:1 | LL | #![inline = ""] @@ -10,3 +10,14 @@ LL | #![inline = ""] error: aborting due to 1 previous error +Future incompatibility report: Future breakage diagnostic: +error: valid forms for the attribute are `#[inline(always)]`, `#[inline(never)]`, and `#[inline]` + --> $DIR/lint_on_root.rs:3:1 + | +LL | #![inline = ""] + | ^^^^^^^^^^^^^^^ + | + = 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 #57571 <https://github.com/rust-lang/rust/issues/57571> + = note: `#[deny(ill_formed_attribute_input)]` on by default + diff --git a/tests/ui/attributes/malformed-attrs.rs b/tests/ui/attributes/malformed-attrs.rs index 0d5bf69d548..3261b29fe7e 100644 --- a/tests/ui/attributes/malformed-attrs.rs +++ b/tests/ui/attributes/malformed-attrs.rs @@ -78,7 +78,7 @@ #[export_stable = 1] //~^ ERROR malformed #[link] -//~^ ERROR attribute must be of the form +//~^ ERROR valid forms for the attribute are //~| WARN this was previously accepted by the compiler #[link_name] //~^ ERROR malformed diff --git a/tests/ui/attributes/malformed-attrs.stderr b/tests/ui/attributes/malformed-attrs.stderr index e8ae4715398..705050e9a7d 100644 --- a/tests/ui/attributes/malformed-attrs.stderr +++ b/tests/ui/attributes/malformed-attrs.stderr @@ -6,6 +6,8 @@ LL | #[cfg] | | | expected this to be a list | help: must be of the form: `#[cfg(predicate)]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute> error: malformed `cfg_attr` attribute input --> $DIR/malformed-attrs.rs:101:1 @@ -29,13 +31,23 @@ error: malformed `windows_subsystem` attribute input --> $DIR/malformed-attrs.rs:26:1 | LL | #![windows_subsystem] - | ^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#![windows_subsystem = "windows|console"]` + | ^^^^^^^^^^^^^^^^^^^^^ + | + = note: for more information, visit <https://doc.rust-lang.org/reference/runtime.html#the-windows_subsystem-attribute> +help: the following are the possible correct uses + | +LL | #![windows_subsystem = "console"] + | +++++++++++ +LL | #![windows_subsystem = "windows"] + | +++++++++++ error: malformed `crate_name` attribute input --> $DIR/malformed-attrs.rs:71:1 | LL | #[crate_name] | ^^^^^^^^^^^^^ help: must be of the form: `#[crate_name = "name"]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/crates-and-source-files.html#the-crate_name-attribute> error: malformed `no_sanitize` attribute input --> $DIR/malformed-attrs.rs:89:1 @@ -48,6 +60,8 @@ error: malformed `instruction_set` attribute input | LL | #[instruction_set] | ^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[instruction_set(set)]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/attributes/codegen.html#the-instruction_set-attribute> error: malformed `patchable_function_entry` attribute input --> $DIR/malformed-attrs.rs:105:1 @@ -80,43 +94,108 @@ error: malformed `linkage` attribute input --> $DIR/malformed-attrs.rs:170:5 | LL | #[linkage] - | ^^^^^^^^^^ help: must be of the form: `#[linkage = "external|internal|..."]` + | ^^^^^^^^^^ + | + = note: for more information, visit <https://doc.rust-lang.org/reference/linkage.html> +help: the following are the possible correct uses + | +LL | #[linkage = "available_externally"] + | ++++++++++++++++++++++++ +LL | #[linkage = "common"] + | ++++++++++ +LL | #[linkage = "extern_weak"] + | +++++++++++++++ +LL | #[linkage = "external"] + | ++++++++++++ + = and 5 other candidates error: malformed `allow` attribute input --> $DIR/malformed-attrs.rs:175:1 | LL | #[allow] - | ^^^^^^^^ help: must be of the form: `#[allow(lint1, lint2, ..., /*opt*/ reason = "...")]` + | ^^^^^^^^ + | + = note: for more information, visit <https://doc.rust-lang.org/reference/attributes/diagnostics.html#lint-check-attributes> +help: the following are the possible correct uses + | +LL | #[allow(lint1)] + | +++++++ +LL | #[allow(lint1, lint2, ...)] + | +++++++++++++++++++ +LL | #[allow(lint1, lint2, lint3, reason = "...")] + | +++++++++++++++++++++++++++++++++++++ error: malformed `expect` attribute input --> $DIR/malformed-attrs.rs:177:1 | LL | #[expect] - | ^^^^^^^^^ help: must be of the form: `#[expect(lint1, lint2, ..., /*opt*/ reason = "...")]` + | ^^^^^^^^^ + | + = note: for more information, visit <https://doc.rust-lang.org/reference/attributes/diagnostics.html#lint-check-attributes> +help: the following are the possible correct uses + | +LL | #[expect(lint1)] + | +++++++ +LL | #[expect(lint1, lint2, ...)] + | +++++++++++++++++++ +LL | #[expect(lint1, lint2, lint3, reason = "...")] + | +++++++++++++++++++++++++++++++++++++ error: malformed `warn` attribute input --> $DIR/malformed-attrs.rs:179:1 | LL | #[warn] - | ^^^^^^^ help: must be of the form: `#[warn(lint1, lint2, ..., /*opt*/ reason = "...")]` + | ^^^^^^^ + | + = note: for more information, visit <https://doc.rust-lang.org/reference/attributes/diagnostics.html#lint-check-attributes> +help: the following are the possible correct uses + | +LL | #[warn(lint1)] + | +++++++ +LL | #[warn(lint1, lint2, ...)] + | +++++++++++++++++++ +LL | #[warn(lint1, lint2, lint3, reason = "...")] + | +++++++++++++++++++++++++++++++++++++ error: malformed `deny` attribute input --> $DIR/malformed-attrs.rs:181:1 | LL | #[deny] - | ^^^^^^^ help: must be of the form: `#[deny(lint1, lint2, ..., /*opt*/ reason = "...")]` + | ^^^^^^^ + | + = note: for more information, visit <https://doc.rust-lang.org/reference/attributes/diagnostics.html#lint-check-attributes> +help: the following are the possible correct uses + | +LL | #[deny(lint1)] + | +++++++ +LL | #[deny(lint1, lint2, ...)] + | +++++++++++++++++++ +LL | #[deny(lint1, lint2, lint3, reason = "...")] + | +++++++++++++++++++++++++++++++++++++ error: malformed `forbid` attribute input --> $DIR/malformed-attrs.rs:183:1 | LL | #[forbid] - | ^^^^^^^^^ help: must be of the form: `#[forbid(lint1, lint2, ..., /*opt*/ reason = "...")]` + | ^^^^^^^^^ + | + = note: for more information, visit <https://doc.rust-lang.org/reference/attributes/diagnostics.html#lint-check-attributes> +help: the following are the possible correct uses + | +LL | #[forbid(lint1)] + | +++++++ +LL | #[forbid(lint1, lint2, ...)] + | +++++++++++++++++++ +LL | #[forbid(lint1, lint2, lint3, reason = "...")] + | +++++++++++++++++++++++++++++++++++++ error: malformed `debugger_visualizer` attribute input --> $DIR/malformed-attrs.rs:185:1 | LL | #[debugger_visualizer] | ^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[debugger_visualizer(natvis_file = "...", gdb_script_file = "...")]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/attributes/debugger.html#the-debugger_visualizer-attribute> error: malformed `thread_local` attribute input --> $DIR/malformed-attrs.rs:200:1 @@ -129,6 +208,8 @@ error: malformed `no_link` attribute input | LL | #[no_link()] | ^^^^^^^^^^^^ help: must be of the form: `#[no_link]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/items/extern-crates.html#the-no_link-attribute> error: malformed `macro_export` attribute input --> $DIR/malformed-attrs.rs:211:1 @@ -136,6 +217,7 @@ error: malformed `macro_export` attribute input LL | #[macro_export = 18] | ^^^^^^^^^^^^^^^^^^^^ | + = note: for more information, visit <https://doc.rust-lang.org/reference/macros-by-example.html#path-based-scope> help: the following are the possible correct uses | LL - #[macro_export = 18] @@ -145,12 +227,6 @@ LL - #[macro_export = 18] LL + #[macro_export] | -error: malformed `allow_internal_unsafe` attribute input - --> $DIR/malformed-attrs.rs:213:1 - | -LL | #[allow_internal_unsafe = 1] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[allow_internal_unsafe]` - error: the `#[proc_macro]` attribute is only usable with crates of the `proc-macro` crate type --> $DIR/malformed-attrs.rs:96:1 | @@ -178,7 +254,7 @@ LL | #[allow_internal_unsafe = 1] = help: add `#![feature(allow_internal_unsafe)]` to the crate attributes to enable = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date -error: valid forms for the attribute are `#[doc(hidden|inline|...)]` and `#[doc = "string"]` +error: valid forms for the attribute are `#[doc(hidden)]`, `#[doc(inline)]`, and `#[doc = "string"]` --> $DIR/malformed-attrs.rs:40:1 | LL | #[doc] @@ -186,9 +262,10 @@ LL | #[doc] | = 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 #57571 <https://github.com/rust-lang/rust/issues/57571> + = note: for more information, visit <https://doc.rust-lang.org/rustdoc/write-documentation/the-doc-attribute.html> = note: `#[deny(ill_formed_attribute_input)]` on by default -error: valid forms for the attribute are `#[doc(hidden|inline|...)]` and `#[doc = "string"]` +error: valid forms for the attribute are `#[doc(hidden)]`, `#[doc(inline)]`, and `#[doc = "string"]` --> $DIR/malformed-attrs.rs:73:1 | LL | #[doc] @@ -196,8 +273,9 @@ LL | #[doc] | = 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 #57571 <https://github.com/rust-lang/rust/issues/57571> + = note: for more information, visit <https://doc.rust-lang.org/rustdoc/write-documentation/the-doc-attribute.html> -error: attribute must be of the form `#[link(name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ wasm_import_module = "...", /*opt*/ import_name_type = "decorated|noprefix|undecorated")]` +error: valid forms for the attribute are `#[link(name = "...")]`, `#[link(name = "...", kind = "dylib|static|...")]`, `#[link(name = "...", wasm_import_module = "...")]`, `#[link(name = "...", import_name_type = "decorated|noprefix|undecorated")]`, and `#[link(name = "...", kind = "dylib|static|...", wasm_import_module = "...", import_name_type = "decorated|noprefix|undecorated")]` --> $DIR/malformed-attrs.rs:80:1 | LL | #[link] @@ -205,6 +283,7 @@ LL | #[link] | = 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 #57571 <https://github.com/rust-lang/rust/issues/57571> + = note: for more information, visit <https://doc.rust-lang.org/reference/items/external-blocks.html#the-link-attribute> error: invalid argument --> $DIR/malformed-attrs.rs:185:1 @@ -257,26 +336,49 @@ LL - #[deprecated = 5] LL + #[deprecated = "reason"] | LL - #[deprecated = 5] -LL + #[deprecated(/*opt*/ since = "version", /*opt*/ note = "reason")] +LL + #[deprecated(note = "reason")] + | +LL - #[deprecated = 5] +LL + #[deprecated(since = "version")] | LL - #[deprecated = 5] -LL + #[deprecated] +LL + #[deprecated(since = "version", note = "reason")] | + = and 1 other candidate error[E0539]: malformed `rustc_macro_transparency` attribute input --> $DIR/malformed-attrs.rs:43:1 | LL | #[rustc_macro_transparency] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_macro_transparency = "transparent|semitransparent|opaque"]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +help: try changing it to one of the following valid forms of the attribute + | +LL | #[rustc_macro_transparency = "opaque"] + | ++++++++++ +LL | #[rustc_macro_transparency = "semitransparent"] + | +++++++++++++++++++ +LL | #[rustc_macro_transparency = "transparent"] + | +++++++++++++++ error[E0539]: malformed `repr` attribute input --> $DIR/malformed-attrs.rs:45:1 | LL | #[repr] - | ^^^^^^^ - | | - | expected this to be a list - | help: must be of the form: `#[repr(C | Rust | align(...) | packed(...) | <integer type> | transparent)]` + | ^^^^^^^ expected this to be a list + | + = note: for more information, visit <https://doc.rust-lang.org/reference/type-layout.html#representations> +help: try changing it to one of the following valid forms of the attribute + | +LL | #[repr(<integer type>)] + | ++++++++++++++++ +LL | #[repr(C)] + | +++ +LL | #[repr(Rust)] + | ++++++ +LL | #[repr(align(...))] + | ++++++++++++ + = and 2 other candidates error[E0565]: malformed `rustc_as_ptr` attribute input --> $DIR/malformed-attrs.rs:48:1 @@ -300,10 +402,16 @@ error[E0539]: malformed `optimize` attribute input --> $DIR/malformed-attrs.rs:55:1 | LL | #[optimize] - | ^^^^^^^^^^^ - | | - | expected this to be a list - | help: must be of the form: `#[optimize(size|speed|none)]` + | ^^^^^^^^^^^ expected this to be a list + | +help: try changing it to one of the following valid forms of the attribute + | +LL | #[optimize(none)] + | ++++++ +LL | #[optimize(size)] + | ++++++ +LL | #[optimize(speed)] + | +++++++ error[E0565]: malformed `cold` attribute input --> $DIR/malformed-attrs.rs:57:1 @@ -363,8 +471,10 @@ LL | #[used()] | help: try changing it to one of the following valid forms of the attribute | -LL | #[used(compiler|linker)] - | +++++++++++++++ +LL | #[used(compiler)] + | ++++++++ +LL | #[used(linker)] + | ++++++ LL - #[used()] LL + #[used] | @@ -392,12 +502,16 @@ error[E0539]: malformed `link_name` attribute input | LL | #[link_name] | ^^^^^^^^^^^^ help: must be of the form: `#[link_name = "name"]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/items/external-blocks.html#the-link_name-attribute> error[E0539]: malformed `link_section` attribute input --> $DIR/malformed-attrs.rs:85:1 | LL | #[link_section] | ^^^^^^^^^^^^^^^ help: must be of the form: `#[link_section = "name"]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/abi.html#the-link_section-attribute> error[E0539]: malformed `coverage` attribute input --> $DIR/malformed-attrs.rs:87:1 @@ -456,6 +570,7 @@ LL | #[must_use = 1] | | | expected a string literal here | + = note: for more information, visit <https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute> help: try changing it to one of the following valid forms of the attribute | LL - #[must_use = 1] @@ -469,10 +584,15 @@ error[E0539]: malformed `proc_macro_derive` attribute input --> $DIR/malformed-attrs.rs:120:1 | LL | #[proc_macro_derive] - | ^^^^^^^^^^^^^^^^^^^^ - | | - | expected this to be a list - | help: must be of the form: `#[proc_macro_derive(TraitName, /*opt*/ attributes(name1, name2, ...))]` + | ^^^^^^^^^^^^^^^^^^^^ expected this to be a list + | + = note: for more information, visit <https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros> +help: try changing it to one of the following valid forms of the attribute + | +LL | #[proc_macro_derive(TraitName)] + | +++++++++++ +LL | #[proc_macro_derive(TraitName, attributes(name1, name2, ...))] + | ++++++++++++++++++++++++++++++++++++++++++ error[E0539]: malformed `rustc_layout_scalar_valid_range_start` attribute input --> $DIR/malformed-attrs.rs:125:1 @@ -527,6 +647,8 @@ LL | #[link_ordinal] | | | expected this to be a list | help: must be of the form: `#[link_ordinal(ordinal)]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/items/external-blocks.html#the-link_ordinal-attribute> error[E0565]: malformed `ffi_const` attribute input --> $DIR/malformed-attrs.rs:168:5 @@ -561,6 +683,15 @@ error: valid forms for the attribute are `#[macro_use(name1, name2, ...)]` and ` LL | #[macro_use = 1] | ^^^^^^^^^^^^^^^^ +error[E0565]: malformed `allow_internal_unsafe` attribute input + --> $DIR/malformed-attrs.rs:213:1 + | +LL | #[allow_internal_unsafe = 1] + | ^^^^^^^^^^^^^^^^^^^^^^^^---^ + | | | + | | didn't expect any arguments here + | help: must be of the form: `#[allow_internal_unsafe]` + error[E0565]: malformed `type_const` attribute input --> $DIR/malformed-attrs.rs:140:5 | @@ -618,7 +749,7 @@ LL | #[diagnostic::on_unimplemented = 1] | = help: only `message`, `note` and `label` are allowed as options -error: valid forms for the attribute are `#[inline(always|never)]` and `#[inline]` +error: valid forms for the attribute are `#[inline(always)]`, `#[inline(never)]`, and `#[inline]` --> $DIR/malformed-attrs.rs:50:1 | LL | #[inline = 5] @@ -660,3 +791,72 @@ error: aborting due to 74 previous errors; 3 warnings emitted Some errors have detailed explanations: E0308, E0463, E0539, E0565, E0658, E0805. For more information about an error, try `rustc --explain E0308`. +Future incompatibility report: Future breakage diagnostic: +error: valid forms for the attribute are `#[doc(hidden)]`, `#[doc(inline)]`, and `#[doc = "string"]` + --> $DIR/malformed-attrs.rs:40:1 + | +LL | #[doc] + | ^^^^^^ + | + = 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 #57571 <https://github.com/rust-lang/rust/issues/57571> + = note: for more information, visit <https://doc.rust-lang.org/rustdoc/write-documentation/the-doc-attribute.html> + = note: `#[deny(ill_formed_attribute_input)]` on by default + +Future breakage diagnostic: +error: valid forms for the attribute are `#[doc(hidden)]`, `#[doc(inline)]`, and `#[doc = "string"]` + --> $DIR/malformed-attrs.rs:73:1 + | +LL | #[doc] + | ^^^^^^ + | + = 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 #57571 <https://github.com/rust-lang/rust/issues/57571> + = note: for more information, visit <https://doc.rust-lang.org/rustdoc/write-documentation/the-doc-attribute.html> + = note: `#[deny(ill_formed_attribute_input)]` on by default + +Future breakage diagnostic: +error: valid forms for the attribute are `#[link(name = "...")]`, `#[link(name = "...", kind = "dylib|static|...")]`, `#[link(name = "...", wasm_import_module = "...")]`, `#[link(name = "...", import_name_type = "decorated|noprefix|undecorated")]`, and `#[link(name = "...", kind = "dylib|static|...", wasm_import_module = "...", import_name_type = "decorated|noprefix|undecorated")]` + --> $DIR/malformed-attrs.rs:80:1 + | +LL | #[link] + | ^^^^^^^ + | + = 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 #57571 <https://github.com/rust-lang/rust/issues/57571> + = note: for more information, visit <https://doc.rust-lang.org/reference/items/external-blocks.html#the-link-attribute> + = note: `#[deny(ill_formed_attribute_input)]` on by default + +Future breakage diagnostic: +error: valid forms for the attribute are `#[inline(always)]`, `#[inline(never)]`, and `#[inline]` + --> $DIR/malformed-attrs.rs:50:1 + | +LL | #[inline = 5] + | ^^^^^^^^^^^^^ + | + = 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 #57571 <https://github.com/rust-lang/rust/issues/57571> + = note: `#[deny(ill_formed_attribute_input)]` on by default + +Future breakage diagnostic: +error: valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]` + --> $DIR/malformed-attrs.rs:91:1 + | +LL | #[ignore()] + | ^^^^^^^^^^^ + | + = 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 #57571 <https://github.com/rust-lang/rust/issues/57571> + = note: `#[deny(ill_formed_attribute_input)]` on by default + +Future breakage diagnostic: +error: valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]` + --> $DIR/malformed-attrs.rs:220:1 + | +LL | #[ignore = 1] + | ^^^^^^^^^^^^^ + | + = 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 #57571 <https://github.com/rust-lang/rust/issues/57571> + = note: `#[deny(ill_formed_attribute_input)]` on by default + diff --git a/tests/ui/attributes/malformed-reprs.stderr b/tests/ui/attributes/malformed-reprs.stderr index c39c98dde31..43085b9c341 100644 --- a/tests/ui/attributes/malformed-reprs.stderr +++ b/tests/ui/attributes/malformed-reprs.stderr @@ -2,10 +2,24 @@ error[E0539]: malformed `repr` attribute input --> $DIR/malformed-reprs.rs:4:1 | LL | #![repr] - | ^^^^^^^^ - | | - | expected this to be a list - | help: must be of the form: `#[repr(C | Rust | align(...) | packed(...) | <integer type> | transparent)]` + | ^^^^^^^^ expected this to be a list + | + = note: for more information, visit <https://doc.rust-lang.org/reference/type-layout.html#representations> +help: try changing it to one of the following valid forms of the attribute + | +LL - #![repr] +LL + #[repr(<integer type>)] + | +LL - #![repr] +LL + #[repr(C)] + | +LL - #![repr] +LL + #[repr(Rust)] + | +LL - #![repr] +LL + #[repr(align(...))] + | + = and 2 other candidates error[E0589]: invalid `repr(align)` attribute: not a power of two --> $DIR/malformed-reprs.rs:9:14 diff --git a/tests/ui/attributes/unsafe/proc-unsafe-attributes.stderr b/tests/ui/attributes/unsafe/proc-unsafe-attributes.stderr index 884e7663c85..107e053ae0c 100644 --- a/tests/ui/attributes/unsafe/proc-unsafe-attributes.stderr +++ b/tests/ui/attributes/unsafe/proc-unsafe-attributes.stderr @@ -119,9 +119,18 @@ error[E0565]: malformed `proc_macro_derive` attribute input | LL | #[proc_macro_derive(unsafe(Foo))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^-----^^ - | | | - | | didn't expect any arguments here - | help: must be of the form: `#[proc_macro_derive(TraitName, /*opt*/ attributes(name1, name2, ...))]` + | | + | didn't expect any arguments here + | + = note: for more information, visit <https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros> +help: try changing it to one of the following valid forms of the attribute + | +LL - #[proc_macro_derive(unsafe(Foo))] +LL + #[proc_macro_derive(TraitName)] + | +LL - #[proc_macro_derive(unsafe(Foo))] +LL + #[proc_macro_derive(TraitName, attributes(name1, name2, ...))] + | error[E0452]: malformed lint attribute input --> $DIR/proc-unsafe-attributes.rs:27:16 diff --git a/tests/ui/attributes/used_with_multi_args.stderr b/tests/ui/attributes/used_with_multi_args.stderr index e48209cf204..308f0519b8c 100644 --- a/tests/ui/attributes/used_with_multi_args.stderr +++ b/tests/ui/attributes/used_with_multi_args.stderr @@ -9,7 +9,10 @@ LL | #[used(compiler, linker)] help: try changing it to one of the following valid forms of the attribute | LL - #[used(compiler, linker)] -LL + #[used(compiler|linker)] +LL + #[used(compiler)] + | +LL - #[used(compiler, linker)] +LL + #[used(linker)] | LL - #[used(compiler, linker)] LL + #[used] diff --git a/tests/ui/issues/issue-91489.rs b/tests/ui/autoref-autoderef/auto-deref-on-cow-regression-91489.rs index 0566302c481..929e98ad719 100644 --- a/tests/ui/issues/issue-91489.rs +++ b/tests/ui/autoref-autoderef/auto-deref-on-cow-regression-91489.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/91489 //@ check-pass // regression test for #91489 diff --git a/tests/ui/issues/issue-9725.rs b/tests/ui/binding/struct-destructuring-repeated-bindings-9725.rs index 360effbd119..6b0b8e37b8c 100644 --- a/tests/ui/issues/issue-9725.rs +++ b/tests/ui/binding/struct-destructuring-repeated-bindings-9725.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/9725 struct A { foo: isize } fn main() { diff --git a/tests/ui/issues/issue-9725.stderr b/tests/ui/binding/struct-destructuring-repeated-bindings-9725.stderr index 687e0cc0f3e..f4d19bed419 100644 --- a/tests/ui/issues/issue-9725.stderr +++ b/tests/ui/binding/struct-destructuring-repeated-bindings-9725.stderr @@ -1,11 +1,11 @@ error[E0416]: identifier `foo` is bound more than once in the same pattern - --> $DIR/issue-9725.rs:4:18 + --> $DIR/struct-destructuring-repeated-bindings-9725.rs:5:18 | LL | let A { foo, foo } = A { foo: 3 }; | ^^^ used in a pattern more than once error[E0025]: field `foo` bound multiple times in the pattern - --> $DIR/issue-9725.rs:4:18 + --> $DIR/struct-destructuring-repeated-bindings-9725.rs:5:18 | LL | let A { foo, foo } = A { foo: 3 }; | --- ^^^ multiple uses of `foo` in pattern diff --git a/tests/ui/issues/issue-15783.rs b/tests/ui/borrowck/array-slice-coercion-mismatch-15783.rs index ef948a1a88c..3322ed71c60 100644 --- a/tests/ui/issues/issue-15783.rs +++ b/tests/ui/borrowck/array-slice-coercion-mismatch-15783.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15783 + //@ dont-require-annotations: NOTE pub fn foo(params: Option<&[&str]>) -> usize { diff --git a/tests/ui/issues/issue-15783.stderr b/tests/ui/borrowck/array-slice-coercion-mismatch-15783.stderr index c9c9a723a86..050eb4baa41 100644 --- a/tests/ui/issues/issue-15783.stderr +++ b/tests/ui/borrowck/array-slice-coercion-mismatch-15783.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/issue-15783.rs:10:19 + --> $DIR/array-slice-coercion-mismatch-15783.rs:12:19 | LL | let msg = foo(x); | --- ^ expected `Option<&[&str]>`, found `Option<&[&str; 1]>` @@ -9,7 +9,7 @@ LL | let msg = foo(x); = note: expected enum `Option<&[&str]>` found enum `Option<&[&str; 1]>` note: function defined here - --> $DIR/issue-15783.rs:3:8 + --> $DIR/array-slice-coercion-mismatch-15783.rs:5:8 | LL | pub fn foo(params: Option<&[&str]>) -> usize { | ^^^ ----------------------- diff --git a/tests/ui/borrowck/borrowck-in-static.stderr b/tests/ui/borrowck/borrowck-in-static.stderr index 9bcf64dd62e..d85f6f5fdd5 100644 --- a/tests/ui/borrowck/borrowck-in-static.stderr +++ b/tests/ui/borrowck/borrowck-in-static.stderr @@ -10,6 +10,7 @@ LL | Box::new(|| x) | | | captured by this `Fn` closure | + = help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once help: consider cloning the value if the performance cost is acceptable | LL | Box::new(|| x.clone()) diff --git a/tests/ui/borrowck/borrowck-move-by-capture.stderr b/tests/ui/borrowck/borrowck-move-by-capture.stderr index 732af1593d6..e9e05440766 100644 --- a/tests/ui/borrowck/borrowck-move-by-capture.stderr +++ b/tests/ui/borrowck/borrowck-move-by-capture.stderr @@ -12,6 +12,11 @@ LL | let _h = to_fn_once(move || -> isize { *bar }); | | | `bar` is moved here | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/borrowck-move-by-capture.rs:3:37 + | +LL | fn to_fn_mut<A:std::marker::Tuple,F:FnMut<A>>(f: F) -> F { f } + | ^^^^^^^^ help: consider cloning the value before moving it into the closure | LL ~ let value = bar.clone(); diff --git a/tests/ui/borrowck/issue-103624.stderr b/tests/ui/borrowck/issue-103624.stderr index af65deb16dc..ef022808886 100644 --- a/tests/ui/borrowck/issue-103624.stderr +++ b/tests/ui/borrowck/issue-103624.stderr @@ -13,6 +13,11 @@ LL | LL | self.b; | ^^^^^^ `self.b` is moved here | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/issue-103624.rs:7:36 + | +LL | async fn spawn_blocking<T>(f: impl (Fn() -> T) + Send + Sync + 'static) -> T { + | ^^^^^^^^^^^ note: if `StructB` implemented `Clone`, you could clone the value --> $DIR/issue-103624.rs:23:1 | diff --git a/tests/ui/borrowck/issue-87456-point-to-closure.stderr b/tests/ui/borrowck/issue-87456-point-to-closure.stderr index a0c7cac2add..043e336cd86 100644 --- a/tests/ui/borrowck/issue-87456-point-to-closure.stderr +++ b/tests/ui/borrowck/issue-87456-point-to-closure.stderr @@ -10,6 +10,11 @@ LL | LL | let _foo: String = val; | ^^^ move occurs because `val` has type `String`, which does not implement the `Copy` trait | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/issue-87456-point-to-closure.rs:3:24 + | +LL | fn take_mut(_val: impl FnMut()) {} + | ^^^^^^^ help: consider borrowing here | LL | let _foo: String = &val; diff --git a/tests/ui/borrowck/unboxed-closures-move-upvar-from-non-once-ref-closure.stderr b/tests/ui/borrowck/unboxed-closures-move-upvar-from-non-once-ref-closure.stderr index 177e9c8d248..d3333041310 100644 --- a/tests/ui/borrowck/unboxed-closures-move-upvar-from-non-once-ref-closure.stderr +++ b/tests/ui/borrowck/unboxed-closures-move-upvar-from-non-once-ref-closure.stderr @@ -10,6 +10,11 @@ LL | y.into_iter(); | | | move occurs because `y` has type `Vec<String>`, which does not implement the `Copy` trait | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/unboxed-closures-move-upvar-from-non-once-ref-closure.rs:5:28 + | +LL | fn call<F>(f: F) where F : Fn() { + | ^^^^ note: `into_iter` takes ownership of the receiver `self`, which moves `y` --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL help: you can `clone` the value and consume it, but this might not be your desired behavior diff --git a/tests/ui/issues/issue-9942.rs b/tests/ui/cast/constant-expression-cast-9942.rs index 6332d9b3e08..d0a6f27b7e3 100644 --- a/tests/ui/issues/issue-9942.rs +++ b/tests/ui/cast/constant-expression-cast-9942.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/9942 //@ run-pass pub fn main() { diff --git a/tests/ui/cfg/cfg-target-compact-errors.stderr b/tests/ui/cfg/cfg-target-compact-errors.stderr index 7df6729e881..cf61f94278a 100644 --- a/tests/ui/cfg/cfg-target-compact-errors.stderr +++ b/tests/ui/cfg/cfg-target-compact-errors.stderr @@ -6,6 +6,8 @@ LL | #[cfg(target(o::o))] | | | | | expected this to be of the form `... = "..."` | help: must be of the form: `#[cfg(predicate)]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute> error[E0539]: malformed `cfg` attribute input --> $DIR/cfg-target-compact-errors.rs:9:1 @@ -15,6 +17,8 @@ LL | #[cfg(target(os = 8))] | | | | | expected a string literal here | help: must be of the form: `#[cfg(predicate)]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute> error[E0539]: malformed `cfg` attribute input --> $DIR/cfg-target-compact-errors.rs:13:1 @@ -24,6 +28,8 @@ LL | #[cfg(target(os = "linux", pointer(width = "64")))] | | | | | expected this to be of the form `... = "..."` | help: must be of the form: `#[cfg(predicate)]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute> error[E0539]: malformed `cfg` attribute input --> $DIR/cfg-target-compact-errors.rs:17:1 @@ -33,6 +39,8 @@ LL | #[cfg(target(true))] | | | | | expected this to be of the form `... = "..."` | help: must be of the form: `#[cfg(predicate)]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute> error: `cfg` predicate key must be an identifier --> $DIR/cfg-target-compact-errors.rs:21:14 diff --git a/tests/ui/issues/issue-9129.rs b/tests/ui/closures/closure-type-inference-in-context-9129.rs index 3856cd133e8..53ee8faab85 100644 --- a/tests/ui/issues/issue-9129.rs +++ b/tests/ui/closures/closure-type-inference-in-context-9129.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/9129 //@ run-pass #![allow(dead_code)] #![allow(non_camel_case_types)] diff --git a/tests/ui/issues/issue-16256.rs b/tests/ui/closures/unused-closure-ice-16256.rs index 1024e4511d6..fd569dd8a0a 100644 --- a/tests/ui/issues/issue-16256.rs +++ b/tests/ui/closures/unused-closure-ice-16256.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/16256 + //@ run-pass fn main() { diff --git a/tests/ui/issues/issue-16256.stderr b/tests/ui/closures/unused-closure-ice-16256.stderr index 75c3ec1bd1c..9df433add5d 100644 --- a/tests/ui/issues/issue-16256.stderr +++ b/tests/ui/closures/unused-closure-ice-16256.stderr @@ -1,5 +1,5 @@ warning: unused closure that must be used - --> $DIR/issue-16256.rs:5:5 + --> $DIR/unused-closure-ice-16256.rs:7:5 | LL | |c: u8| buf.push(c); | ^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/issues/issue-15793.rs b/tests/ui/codegen/nested-enum-match-optimization-15793.rs index af92e9dfa4c..420e3ad82b2 100644 --- a/tests/ui/issues/issue-15793.rs +++ b/tests/ui/codegen/nested-enum-match-optimization-15793.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15793 + //@ run-pass #![allow(dead_code)] diff --git a/tests/ui/issues/issue-9951.rs b/tests/ui/coercion/trait-object-coercion-distribution-9951.rs index 2cd7cd4f430..526d6561510 100644 --- a/tests/ui/issues/issue-9951.rs +++ b/tests/ui/coercion/trait-object-coercion-distribution-9951.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/9951 //@ run-pass #![allow(unused_variables)] diff --git a/tests/ui/issues/issue-9951.stderr b/tests/ui/coercion/trait-object-coercion-distribution-9951.stderr index 62ed9f3e0cc..0c672aa9b33 100644 --- a/tests/ui/issues/issue-9951.stderr +++ b/tests/ui/coercion/trait-object-coercion-distribution-9951.stderr @@ -1,5 +1,5 @@ warning: method `noop` is never used - --> $DIR/issue-9951.rs:6:6 + --> $DIR/trait-object-coercion-distribution-9951.rs:7:6 | LL | trait Bar { | --- method in this trait diff --git a/tests/ui/conditional-compilation/cfg-attr-syntax-validation.rs b/tests/ui/conditional-compilation/cfg-attr-syntax-validation.rs index df87a3d846e..126a534dc6f 100644 --- a/tests/ui/conditional-compilation/cfg-attr-syntax-validation.rs +++ b/tests/ui/conditional-compilation/cfg-attr-syntax-validation.rs @@ -1,21 +1,25 @@ #[cfg] //~^ ERROR malformed `cfg` attribute //~| NOTE expected this to be a list +//~| NOTE for more information, visit struct S1; #[cfg = 10] //~^ ERROR malformed `cfg` attribute //~| NOTE expected this to be a list +//~| NOTE for more information, visit struct S2; #[cfg()] //~^ ERROR malformed `cfg` attribute //~| NOTE expected a single argument here +//~| NOTE for more information, visit struct S3; #[cfg(a, b)] //~^ ERROR malformed `cfg` attribute //~| NOTE expected a single argument here +//~| NOTE for more information, visit struct S4; #[cfg("str")] //~ ERROR `cfg` predicate key must be an identifier @@ -29,6 +33,7 @@ struct S7; #[cfg(a = 10)] //~ ERROR malformed `cfg` attribute input //~^ NOTE expected a string literal here +//~| NOTE for more information, visit struct S8; #[cfg(a = b"hi")] //~ ERROR malformed `cfg` attribute input diff --git a/tests/ui/conditional-compilation/cfg-attr-syntax-validation.stderr b/tests/ui/conditional-compilation/cfg-attr-syntax-validation.stderr index 75e9b9209c0..6acde758ea5 100644 --- a/tests/ui/conditional-compilation/cfg-attr-syntax-validation.stderr +++ b/tests/ui/conditional-compilation/cfg-attr-syntax-validation.stderr @@ -6,63 +6,73 @@ LL | #[cfg] | | | expected this to be a list | help: must be of the form: `#[cfg(predicate)]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute> error[E0539]: malformed `cfg` attribute input - --> $DIR/cfg-attr-syntax-validation.rs:6:1 + --> $DIR/cfg-attr-syntax-validation.rs:7:1 | LL | #[cfg = 10] | ^^^^^^^^^^^ | | | expected this to be a list | help: must be of the form: `#[cfg(predicate)]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute> error[E0805]: malformed `cfg` attribute input - --> $DIR/cfg-attr-syntax-validation.rs:11:1 + --> $DIR/cfg-attr-syntax-validation.rs:13:1 | LL | #[cfg()] | ^^^^^--^ | | | | | expected a single argument here | help: must be of the form: `#[cfg(predicate)]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute> error[E0805]: malformed `cfg` attribute input - --> $DIR/cfg-attr-syntax-validation.rs:16:1 + --> $DIR/cfg-attr-syntax-validation.rs:19:1 | LL | #[cfg(a, b)] | ^^^^^------^ | | | | | expected a single argument here | help: must be of the form: `#[cfg(predicate)]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute> error: `cfg` predicate key must be an identifier - --> $DIR/cfg-attr-syntax-validation.rs:21:7 + --> $DIR/cfg-attr-syntax-validation.rs:25:7 | LL | #[cfg("str")] | ^^^^^ error: `cfg` predicate key must be an identifier - --> $DIR/cfg-attr-syntax-validation.rs:24:7 + --> $DIR/cfg-attr-syntax-validation.rs:28:7 | LL | #[cfg(a::b)] | ^^^^ error[E0537]: invalid predicate `a` - --> $DIR/cfg-attr-syntax-validation.rs:27:7 + --> $DIR/cfg-attr-syntax-validation.rs:31:7 | LL | #[cfg(a())] | ^^^ error[E0539]: malformed `cfg` attribute input - --> $DIR/cfg-attr-syntax-validation.rs:30:1 + --> $DIR/cfg-attr-syntax-validation.rs:34:1 | LL | #[cfg(a = 10)] | ^^^^^^^^^^--^^ | | | | | expected a string literal here | help: must be of the form: `#[cfg(predicate)]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg-attribute> error[E0539]: malformed `cfg` attribute input - --> $DIR/cfg-attr-syntax-validation.rs:34:1 + --> $DIR/cfg-attr-syntax-validation.rs:39:1 | LL | #[cfg(a = b"hi")] | ^^^^^^^^^^-^^^^^^ @@ -72,7 +82,7 @@ LL | #[cfg(a = b"hi")] = note: expected a normal string literal, not a byte string literal error: expected unsuffixed literal, found `expr` metavariable - --> $DIR/cfg-attr-syntax-validation.rs:40:25 + --> $DIR/cfg-attr-syntax-validation.rs:45:25 | LL | #[cfg(feature = $expr)] | ^^^^^ diff --git a/tests/ui/issues/issue-98299.rs b/tests/ui/const-generics/try-from-with-const-genericsrs-98299.rs index ba63d963475..49c88856bc9 100644 --- a/tests/ui/issues/issue-98299.rs +++ b/tests/ui/const-generics/try-from-with-const-genericsrs-98299.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/98299 use std::convert::TryFrom; pub fn test_usage(p: ()) { diff --git a/tests/ui/issues/issue-98299.stderr b/tests/ui/const-generics/try-from-with-const-genericsrs-98299.stderr index b645267e3b9..1557b83b00e 100644 --- a/tests/ui/issues/issue-98299.stderr +++ b/tests/ui/const-generics/try-from-with-const-genericsrs-98299.stderr @@ -1,5 +1,5 @@ error[E0284]: type annotations needed for `SmallCString<_>` - --> $DIR/issue-98299.rs:4:36 + --> $DIR/try-from-with-const-genericsrs-98299.rs:5:36 | LL | SmallCString::try_from(p).map(|cstr| cstr); | ------------ ^^^^ @@ -7,7 +7,7 @@ LL | SmallCString::try_from(p).map(|cstr| cstr); | type must be known at this point | note: required by a const generic parameter in `SmallCString` - --> $DIR/issue-98299.rs:10:25 + --> $DIR/try-from-with-const-genericsrs-98299.rs:11:25 | LL | pub struct SmallCString<const N: usize> {} | ^^^^^^^^^^^^^^ required by this const generic parameter in `SmallCString` @@ -17,7 +17,7 @@ LL | SmallCString::try_from(p).map(|cstr: SmallCString<N>| cstr); | +++++++++++++++++ error[E0284]: type annotations needed for `SmallCString<_>` - --> $DIR/issue-98299.rs:4:36 + --> $DIR/try-from-with-const-genericsrs-98299.rs:5:36 | LL | SmallCString::try_from(p).map(|cstr| cstr); | ------------ ^^^^ @@ -25,7 +25,7 @@ LL | SmallCString::try_from(p).map(|cstr| cstr); | type must be known at this point | note: required for `SmallCString<_>` to implement `TryFrom<()>` - --> $DIR/issue-98299.rs:12:22 + --> $DIR/try-from-with-const-genericsrs-98299.rs:13:22 | LL | impl<const N: usize> TryFrom<()> for SmallCString<N> { | -------------- ^^^^^^^^^^^ ^^^^^^^^^^^^^^^ @@ -37,7 +37,7 @@ LL | SmallCString::try_from(p).map(|cstr: SmallCString<N>| cstr); | +++++++++++++++++ error[E0284]: type annotations needed for `SmallCString<_>` - --> $DIR/issue-98299.rs:4:36 + --> $DIR/try-from-with-const-genericsrs-98299.rs:5:36 | LL | SmallCString::try_from(p).map(|cstr| cstr); | ------------------------- ^^^^ @@ -45,7 +45,7 @@ LL | SmallCString::try_from(p).map(|cstr| cstr); | type must be known at this point | note: required for `SmallCString<_>` to implement `TryFrom<()>` - --> $DIR/issue-98299.rs:12:22 + --> $DIR/try-from-with-const-genericsrs-98299.rs:13:22 | LL | impl<const N: usize> TryFrom<()> for SmallCString<N> { | -------------- ^^^^^^^^^^^ ^^^^^^^^^^^^^^^ diff --git a/tests/ui/issues/auxiliary/issue-9155.rs b/tests/ui/cross-crate/auxiliary/aux-9155.rs index 049a96a655a..049a96a655a 100644 --- a/tests/ui/issues/auxiliary/issue-9155.rs +++ b/tests/ui/cross-crate/auxiliary/aux-9155.rs diff --git a/tests/ui/issues/auxiliary/issue-9906.rs b/tests/ui/cross-crate/auxiliary/aux-9906.rs index 8a3eea790a2..8a3eea790a2 100644 --- a/tests/ui/issues/auxiliary/issue-9906.rs +++ b/tests/ui/cross-crate/auxiliary/aux-9906.rs diff --git a/tests/ui/cross-crate/generic-newtypes-cross-crate-usage-9155.rs b/tests/ui/cross-crate/generic-newtypes-cross-crate-usage-9155.rs new file mode 100644 index 00000000000..35286615980 --- /dev/null +++ b/tests/ui/cross-crate/generic-newtypes-cross-crate-usage-9155.rs @@ -0,0 +1,11 @@ +// https://github.com/rust-lang/rust/issues/9155 +//@ run-pass +//@ aux-build:aux-9155.rs + +extern crate aux_9155; + +struct Baz; + +pub fn main() { + aux_9155::Foo::new(Baz); +} diff --git a/tests/ui/cross-crate/reexported-structs-impls-link-error-9906.rs b/tests/ui/cross-crate/reexported-structs-impls-link-error-9906.rs new file mode 100644 index 00000000000..b49951bd1f9 --- /dev/null +++ b/tests/ui/cross-crate/reexported-structs-impls-link-error-9906.rs @@ -0,0 +1,10 @@ +// https://github.com/rust-lang/rust/issues/9906 +//@ run-pass +//@ aux-build:aux-9906.rs + +extern crate aux_9906 as testmod; + +pub fn main() { + testmod::foo(); + testmod::FooBar::new(1); +} diff --git a/tests/ui/deprecation/deprecation-sanity.stderr b/tests/ui/deprecation/deprecation-sanity.stderr index f1b4697485c..856f51a4b24 100644 --- a/tests/ui/deprecation/deprecation-sanity.stderr +++ b/tests/ui/deprecation/deprecation-sanity.stderr @@ -18,11 +18,15 @@ LL - #[deprecated(since = "a", note)] LL + #[deprecated = "reason"] | LL - #[deprecated(since = "a", note)] -LL + #[deprecated(/*opt*/ since = "version", /*opt*/ note = "reason")] +LL + #[deprecated(note = "reason")] | LL - #[deprecated(since = "a", note)] -LL + #[deprecated] +LL + #[deprecated(since = "version")] | +LL - #[deprecated(since = "a", note)] +LL + #[deprecated(since = "version", note = "reason")] + | + = and 1 other candidate error[E0539]: malformed `deprecated` attribute input --> $DIR/deprecation-sanity.rs:10:5 @@ -38,11 +42,15 @@ LL - #[deprecated(since, note = "a")] LL + #[deprecated = "reason"] | LL - #[deprecated(since, note = "a")] -LL + #[deprecated(/*opt*/ since = "version", /*opt*/ note = "reason")] +LL + #[deprecated(note = "reason")] + | +LL - #[deprecated(since, note = "a")] +LL + #[deprecated(since = "version")] | LL - #[deprecated(since, note = "a")] -LL + #[deprecated] +LL + #[deprecated(since = "version", note = "reason")] | + = and 1 other candidate error[E0539]: malformed `deprecated` attribute input --> $DIR/deprecation-sanity.rs:13:5 @@ -58,11 +66,15 @@ LL - #[deprecated(since = "a", note(b))] LL + #[deprecated = "reason"] | LL - #[deprecated(since = "a", note(b))] -LL + #[deprecated(/*opt*/ since = "version", /*opt*/ note = "reason")] +LL + #[deprecated(note = "reason")] + | +LL - #[deprecated(since = "a", note(b))] +LL + #[deprecated(since = "version")] | LL - #[deprecated(since = "a", note(b))] -LL + #[deprecated] +LL + #[deprecated(since = "version", note = "reason")] | + = and 1 other candidate error[E0539]: malformed `deprecated` attribute input --> $DIR/deprecation-sanity.rs:16:5 @@ -78,11 +90,15 @@ LL - #[deprecated(since(b), note = "a")] LL + #[deprecated = "reason"] | LL - #[deprecated(since(b), note = "a")] -LL + #[deprecated(/*opt*/ since = "version", /*opt*/ note = "reason")] +LL + #[deprecated(note = "reason")] | LL - #[deprecated(since(b), note = "a")] -LL + #[deprecated] +LL + #[deprecated(since = "version")] | +LL - #[deprecated(since(b), note = "a")] +LL + #[deprecated(since = "version", note = "reason")] + | + = and 1 other candidate error[E0539]: malformed `deprecated` attribute input --> $DIR/deprecation-sanity.rs:19:5 @@ -108,11 +124,15 @@ LL - #[deprecated("test")] LL + #[deprecated = "reason"] | LL - #[deprecated("test")] -LL + #[deprecated(/*opt*/ since = "version", /*opt*/ note = "reason")] +LL + #[deprecated(note = "reason")] + | +LL - #[deprecated("test")] +LL + #[deprecated(since = "version")] | LL - #[deprecated("test")] -LL + #[deprecated] +LL + #[deprecated(since = "version", note = "reason")] | + = and 1 other candidate error: multiple `deprecated` attributes --> $DIR/deprecation-sanity.rs:27:1 @@ -140,11 +160,15 @@ LL - #[deprecated(since = "a", since = "b", note = "c")] LL + #[deprecated = "reason"] | LL - #[deprecated(since = "a", since = "b", note = "c")] -LL + #[deprecated(/*opt*/ since = "version", /*opt*/ note = "reason")] +LL + #[deprecated(note = "reason")] + | +LL - #[deprecated(since = "a", since = "b", note = "c")] +LL + #[deprecated(since = "version")] | LL - #[deprecated(since = "a", since = "b", note = "c")] -LL + #[deprecated] +LL + #[deprecated(since = "version", note = "reason")] | + = and 1 other candidate error: this `#[deprecated]` annotation has no effect --> $DIR/deprecation-sanity.rs:35:1 diff --git a/tests/ui/issues/issue-22992.rs b/tests/ui/deref/dereferenceable-type-behavior-22992.rs index 3bc15cc948a..19fc2e7eb0b 100644 --- a/tests/ui/issues/issue-22992.rs +++ b/tests/ui/deref/dereferenceable-type-behavior-22992.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/22992 //@ run-pass struct X { val: i32 } @@ -6,7 +7,6 @@ impl std::ops::Deref for X { fn deref(&self) -> &i32 { &self.val } } - trait M { fn m(self); } impl M for i32 { fn m(self) { println!("i32::m()"); } } impl M for X { fn m(self) { println!("X::m()"); } } diff --git a/tests/ui/issues/issue-15523-big.rs b/tests/ui/derives/derive-partial-ord-discriminant-64bit.rs index 7214a4fb1d5..5b6bf6fbf1f 100644 --- a/tests/ui/issues/issue-15523-big.rs +++ b/tests/ui/derives/derive-partial-ord-discriminant-64bit.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15523 + //@ run-pass // Issue 15523: derive(PartialOrd) should use the provided // discriminant values for the derived ordering. @@ -28,7 +30,6 @@ fn main() { assert!(Eu64::Pos2 < Eu64::PosMax); assert!(Eu64::Pos1 < Eu64::PosMax); - assert!(Ei64::Pos2 > Ei64::Pos1); assert!(Ei64::Pos2 > Ei64::Neg1); assert!(Ei64::Pos1 > Ei64::Neg1); diff --git a/tests/ui/issues/issue-15523.rs b/tests/ui/derives/derive-partial-ord-discriminant.rs index 9fc2e51c6ab..28f325ec966 100644 --- a/tests/ui/issues/issue-15523.rs +++ b/tests/ui/derives/derive-partial-ord-discriminant.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15523 + //@ run-pass // Issue 15523: derive(PartialOrd) should use the provided // discriminant values for the derived ordering. diff --git a/tests/ui/dist/cranelift-x86_64-unknown-linux-gnu-dist.rs b/tests/ui/dist/cranelift-x86_64-unknown-linux-gnu-dist.rs new file mode 100644 index 00000000000..198f8d1bc10 --- /dev/null +++ b/tests/ui/dist/cranelift-x86_64-unknown-linux-gnu-dist.rs @@ -0,0 +1,11 @@ +// Ensure that Cranelift can be used to compile a simple program with `x86_64-unknown-linux-gnu` +// dist artifacts. + +//@ only-dist +//@ only-x86_64-unknown-linux-gnu +//@ compile-flags: -Z codegen-backend=cranelift +//@ run-pass + +fn main() { + println!("Hello world!"); +} diff --git a/tests/ui/drop/dropck-normalize-errors.stderr b/tests/ui/drop/dropck-normalize-errors.nll.stderr index 2bb5909c6b2..b008daa51a3 100644 --- a/tests/ui/drop/dropck-normalize-errors.stderr +++ b/tests/ui/drop/dropck-normalize-errors.nll.stderr @@ -1,44 +1,44 @@ error[E0277]: the trait bound `NonImplementedStruct: NonImplementedTrait` is not satisfied in `ADecoder<'a>` - --> $DIR/dropck-normalize-errors.rs:15:28 + --> $DIR/dropck-normalize-errors.rs:19:28 | LL | fn make_a_decoder<'a>() -> ADecoder<'a> { | ^^^^^^^^^^^^ within `ADecoder<'a>`, the trait `NonImplementedTrait` is not implemented for `NonImplementedStruct` | help: this trait has no implementations, consider adding one - --> $DIR/dropck-normalize-errors.rs:7:1 + --> $DIR/dropck-normalize-errors.rs:11:1 | LL | trait NonImplementedTrait { | ^^^^^^^^^^^^^^^^^^^^^^^^^ note: required because it appears within the type `BDecoder` - --> $DIR/dropck-normalize-errors.rs:26:12 + --> $DIR/dropck-normalize-errors.rs:30:12 | LL | pub struct BDecoder { | ^^^^^^^^ note: required because it appears within the type `ADecoder<'a>` - --> $DIR/dropck-normalize-errors.rs:12:12 + --> $DIR/dropck-normalize-errors.rs:16:12 | LL | pub struct ADecoder<'a> { | ^^^^^^^^ = note: the return type of a function must have a statically known size error[E0277]: the trait bound `NonImplementedStruct: NonImplementedTrait` is not satisfied in `BDecoder` - --> $DIR/dropck-normalize-errors.rs:23:20 + --> $DIR/dropck-normalize-errors.rs:27:20 | LL | type Decoder = BDecoder; | ^^^^^^^^ within `BDecoder`, the trait `NonImplementedTrait` is not implemented for `NonImplementedStruct` | help: this trait has no implementations, consider adding one - --> $DIR/dropck-normalize-errors.rs:7:1 + --> $DIR/dropck-normalize-errors.rs:11:1 | LL | trait NonImplementedTrait { | ^^^^^^^^^^^^^^^^^^^^^^^^^ note: required because it appears within the type `BDecoder` - --> $DIR/dropck-normalize-errors.rs:26:12 + --> $DIR/dropck-normalize-errors.rs:30:12 | LL | pub struct BDecoder { | ^^^^^^^^ note: required by a bound in `Decode::Decoder` - --> $DIR/dropck-normalize-errors.rs:4:5 + --> $DIR/dropck-normalize-errors.rs:8:5 | LL | type Decoder; | ^^^^^^^^^^^^^ required by this bound in `Decode::Decoder` @@ -48,25 +48,25 @@ LL | type Decoder: ?Sized; | ++++++++ error[E0277]: the trait bound `NonImplementedStruct: NonImplementedTrait` is not satisfied - --> $DIR/dropck-normalize-errors.rs:27:22 + --> $DIR/dropck-normalize-errors.rs:31:22 | LL | non_implemented: <NonImplementedStruct as NonImplementedTrait>::Assoc, | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NonImplementedTrait` is not implemented for `NonImplementedStruct` | help: this trait has no implementations, consider adding one - --> $DIR/dropck-normalize-errors.rs:7:1 + --> $DIR/dropck-normalize-errors.rs:11:1 | LL | trait NonImplementedTrait { | ^^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `NonImplementedStruct: NonImplementedTrait` is not satisfied - --> $DIR/dropck-normalize-errors.rs:15:28 + --> $DIR/dropck-normalize-errors.rs:19:28 | LL | fn make_a_decoder<'a>() -> ADecoder<'a> { | ^^^^^^^^^^^^ the trait `NonImplementedTrait` is not implemented for `NonImplementedStruct` | help: this trait has no implementations, consider adding one - --> $DIR/dropck-normalize-errors.rs:7:1 + --> $DIR/dropck-normalize-errors.rs:11:1 | LL | trait NonImplementedTrait { | ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/drop/dropck-normalize-errors.polonius.stderr b/tests/ui/drop/dropck-normalize-errors.polonius.stderr new file mode 100644 index 00000000000..f8674b8e34a --- /dev/null +++ b/tests/ui/drop/dropck-normalize-errors.polonius.stderr @@ -0,0 +1,64 @@ +error[E0277]: the trait bound `NonImplementedStruct: NonImplementedTrait` is not satisfied in `ADecoder<'a>` + --> $DIR/dropck-normalize-errors.rs:19:28 + | +LL | fn make_a_decoder<'a>() -> ADecoder<'a> { + | ^^^^^^^^^^^^ within `ADecoder<'a>`, the trait `NonImplementedTrait` is not implemented for `NonImplementedStruct` + | +help: this trait has no implementations, consider adding one + --> $DIR/dropck-normalize-errors.rs:11:1 + | +LL | trait NonImplementedTrait { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +note: required because it appears within the type `BDecoder` + --> $DIR/dropck-normalize-errors.rs:30:12 + | +LL | pub struct BDecoder { + | ^^^^^^^^ +note: required because it appears within the type `ADecoder<'a>` + --> $DIR/dropck-normalize-errors.rs:16:12 + | +LL | pub struct ADecoder<'a> { + | ^^^^^^^^ + = note: the return type of a function must have a statically known size + +error[E0277]: the trait bound `NonImplementedStruct: NonImplementedTrait` is not satisfied in `BDecoder` + --> $DIR/dropck-normalize-errors.rs:27:20 + | +LL | type Decoder = BDecoder; + | ^^^^^^^^ within `BDecoder`, the trait `NonImplementedTrait` is not implemented for `NonImplementedStruct` + | +help: this trait has no implementations, consider adding one + --> $DIR/dropck-normalize-errors.rs:11:1 + | +LL | trait NonImplementedTrait { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +note: required because it appears within the type `BDecoder` + --> $DIR/dropck-normalize-errors.rs:30:12 + | +LL | pub struct BDecoder { + | ^^^^^^^^ +note: required by a bound in `Decode::Decoder` + --> $DIR/dropck-normalize-errors.rs:8:5 + | +LL | type Decoder; + | ^^^^^^^^^^^^^ required by this bound in `Decode::Decoder` +help: consider relaxing the implicit `Sized` restriction + | +LL | type Decoder: ?Sized; + | ++++++++ + +error[E0277]: the trait bound `NonImplementedStruct: NonImplementedTrait` is not satisfied + --> $DIR/dropck-normalize-errors.rs:31:22 + | +LL | non_implemented: <NonImplementedStruct as NonImplementedTrait>::Assoc, + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `NonImplementedTrait` is not implemented for `NonImplementedStruct` + | +help: this trait has no implementations, consider adding one + --> $DIR/dropck-normalize-errors.rs:11:1 + | +LL | trait NonImplementedTrait { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/drop/dropck-normalize-errors.rs b/tests/ui/drop/dropck-normalize-errors.rs index 793122bd33d..2ade63f27c5 100644 --- a/tests/ui/drop/dropck-normalize-errors.rs +++ b/tests/ui/drop/dropck-normalize-errors.rs @@ -1,5 +1,9 @@ // Test that we don't ICE when computing the drop types for +//@ ignore-compare-mode-polonius (explicit revisions) +//@ revisions: nll polonius +//@ [polonius] compile-flags: -Zpolonius=next + trait Decode<'a> { type Decoder; } @@ -14,7 +18,7 @@ pub struct ADecoder<'a> { } fn make_a_decoder<'a>() -> ADecoder<'a> { //~^ ERROR the trait bound - //~| ERROR the trait bound + //[nll]~| ERROR the trait bound panic!() } diff --git a/tests/ui/issues/issue-15063.rs b/tests/ui/drop/enum-drop-impl-15063.rs index 969dbe5fad2..a8198abafa0 100644 --- a/tests/ui/issues/issue-15063.rs +++ b/tests/ui/drop/enum-drop-impl-15063.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15063 + //@ run-pass #![allow(dead_code)] #![allow(unused_variables)] diff --git a/tests/ui/issues/issue-15858.rs b/tests/ui/drop/generic-drop-trait-bound-15858.rs index 27887d49e3e..682604d17d8 100644 --- a/tests/ui/issues/issue-15858.rs +++ b/tests/ui/drop/generic-drop-trait-bound-15858.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15858 + //@ run-pass // FIXME(static_mut_refs): this could use an atomic #![allow(static_mut_refs)] diff --git a/tests/ui/issues/issue-15858.stderr b/tests/ui/drop/generic-drop-trait-bound-15858.stderr index 0c082cc0862..86cd6cb6026 100644 --- a/tests/ui/issues/issue-15858.stderr +++ b/tests/ui/drop/generic-drop-trait-bound-15858.stderr @@ -1,5 +1,5 @@ warning: method `do_something` is never used - --> $DIR/issue-15858.rs:7:8 + --> $DIR/generic-drop-trait-bound-15858.rs:9:8 | LL | trait Bar { | --- method in this trait diff --git a/tests/ui/issues/issue-25549-multiple-drop.rs b/tests/ui/drop/multiple-drop-safe-code-25549.rs index 1eec15a4aa2..dcf7a3fc79c 100644 --- a/tests/ui/issues/issue-25549-multiple-drop.rs +++ b/tests/ui/drop/multiple-drop-safe-code-25549.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/25549 //@ run-pass #![allow(unused_variables)] struct Foo<'r>(&'r mut i32); diff --git a/tests/ui/issues/issue-15763.rs b/tests/ui/drop/nested-return-drop-order.rs index 0ebadd80541..67ab52e6250 100644 --- a/tests/ui/issues/issue-15763.rs +++ b/tests/ui/drop/nested-return-drop-order.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15763 + //@ run-pass #![allow(unreachable_code)] diff --git a/tests/ui/drop/same-alloca-reassigned-match-binding-16151.rs b/tests/ui/drop/same-alloca-reassigned-match-binding-16151.rs new file mode 100644 index 00000000000..ecc862ec7be --- /dev/null +++ b/tests/ui/drop/same-alloca-reassigned-match-binding-16151.rs @@ -0,0 +1,34 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/16151 + +//@ run-pass + +// FIXME(static_mut_refs): Do not allow `static_mut_refs` lint +#![allow(static_mut_refs)] + +use std::mem; + +static mut DROP_COUNT: usize = 0; + +struct Fragment; + +impl Drop for Fragment { + fn drop(&mut self) { + unsafe { + DROP_COUNT += 1; + } + } +} + +fn main() { + { + let mut fragments = vec![Fragment, Fragment, Fragment]; + let _new_fragments: Vec<Fragment> = mem::replace(&mut fragments, vec![]) + .into_iter() + .skip_while(|_fragment| { + true + }).collect(); + } + unsafe { + assert_eq!(DROP_COUNT, 3); + } +} diff --git a/tests/ui/issues/issue-9243.rs b/tests/ui/drop/static-variable-with-drop-trait-9243.rs index 34ae944d1d8..0ae32c983e9 100644 --- a/tests/ui/issues/issue-9243.rs +++ b/tests/ui/drop/static-variable-with-drop-trait-9243.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/9243 //@ build-pass #![allow(dead_code)] // Regression test for issue 9243 diff --git a/tests/ui/issues/issue-16492.rs b/tests/ui/drop/struct-field-drop-order.rs index cfdba5fda35..80e3ea616a5 100644 --- a/tests/ui/issues/issue-16492.rs +++ b/tests/ui/drop/struct-field-drop-order.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/16492 + //@ run-pass #![allow(non_snake_case)] diff --git a/tests/ui/issues/issue-53333.rs b/tests/ui/editions/edition-specific-identifier-shadowing-53333.rs index 468b7d8075f..dd973bb8439 100644 --- a/tests/ui/issues/issue-53333.rs +++ b/tests/ui/editions/edition-specific-identifier-shadowing-53333.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/53333 //@ run-pass #![allow(unused_imports)] //@ edition:2018 diff --git a/tests/ui/issues/issue-9837.rs b/tests/ui/enum-discriminant/enum-discriminant-const-eval-truncation-9837.rs index 33152a5d077..8768d81b93f 100644 --- a/tests/ui/issues/issue-9837.rs +++ b/tests/ui/enum-discriminant/enum-discriminant-const-eval-truncation-9837.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/9837 //@ run-pass const C1: i32 = 0x12345678; const C2: isize = C1 as i16 as isize; diff --git a/tests/ui/issues/issue-9814.rs b/tests/ui/enum/single-variant-enum-deref-error-9814.rs index a87478e221b..f10d665299c 100644 --- a/tests/ui/issues/issue-9814.rs +++ b/tests/ui/enum/single-variant-enum-deref-error-9814.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/9814 // Verify that single-variant enums can't be de-referenced // Regression test for issue #9814 diff --git a/tests/ui/issues/issue-9814.stderr b/tests/ui/enum/single-variant-enum-deref-error-9814.stderr index fa23fb7c176..5e069f4c21d 100644 --- a/tests/ui/issues/issue-9814.stderr +++ b/tests/ui/enum/single-variant-enum-deref-error-9814.stderr @@ -1,5 +1,5 @@ error[E0614]: type `Foo` cannot be dereferenced - --> $DIR/issue-9814.rs:7:13 + --> $DIR/single-variant-enum-deref-error-9814.rs:8:13 | LL | let _ = *Foo::Bar(2); | ^^^^^^^^^^^^ can't be dereferenced diff --git a/tests/ui/issues/issue-3037.rs b/tests/ui/enum/zero-variant-enum-pattern-matching-3037.rs index 933b450ac8e..7a7abb1c67c 100644 --- a/tests/ui/issues/issue-3037.rs +++ b/tests/ui/enum/zero-variant-enum-pattern-matching-3037.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/3037 //@ run-pass #![allow(dead_code)] #![allow(non_camel_case_types)] diff --git a/tests/ui/error-codes/E0197.stderr b/tests/ui/error-codes/E0197.stderr index c06777396e8..04c6174b9f1 100644 --- a/tests/ui/error-codes/E0197.stderr +++ b/tests/ui/error-codes/E0197.stderr @@ -5,6 +5,8 @@ LL | unsafe impl Foo { } | ------ ^^^ inherent impl for this type | | | unsafe because of this + | + = note: only trait implementations may be annotated with `unsafe` error: aborting due to 1 previous error diff --git a/tests/ui/error-codes/E0540.stderr b/tests/ui/error-codes/E0540.stderr index 3e5f408feb5..ae23dce5c50 100644 --- a/tests/ui/error-codes/E0540.stderr +++ b/tests/ui/error-codes/E0540.stderr @@ -6,10 +6,13 @@ LL | #[inline()] | | | expected a single argument here | + = note: for more information, visit <https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute> help: try changing it to one of the following valid forms of the attribute | -LL | #[inline(always|never)] - | ++++++++++++ +LL | #[inline(always)] + | ++++++ +LL | #[inline(never)] + | +++++ LL - #[inline()] LL + #[inline] | diff --git a/tests/ui/error-codes/E0565-1.stderr b/tests/ui/error-codes/E0565-1.stderr index 6277e6400d7..52daf2a62fc 100644 --- a/tests/ui/error-codes/E0565-1.stderr +++ b/tests/ui/error-codes/E0565-1.stderr @@ -12,11 +12,15 @@ LL - #[deprecated("since")] LL + #[deprecated = "reason"] | LL - #[deprecated("since")] -LL + #[deprecated(/*opt*/ since = "version", /*opt*/ note = "reason")] +LL + #[deprecated(note = "reason")] | LL - #[deprecated("since")] -LL + #[deprecated] +LL + #[deprecated(since = "version")] | +LL - #[deprecated("since")] +LL + #[deprecated(since = "version", note = "reason")] + | + = and 1 other candidate error: aborting due to 1 previous error diff --git a/tests/ui/issues/issue-16441.rs b/tests/ui/extern/empty-struct-extern-fn-16441.rs index 58cfb389297..82f2eee611d 100644 --- a/tests/ui/issues/issue-16441.rs +++ b/tests/ui/extern/empty-struct-extern-fn-16441.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/16441 + //@ run-pass #![allow(dead_code)] diff --git a/tests/ui/extern/issue-47725.rs b/tests/ui/extern/issue-47725.rs index 60d0cd62347..8ac866dc7d9 100644 --- a/tests/ui/extern/issue-47725.rs +++ b/tests/ui/extern/issue-47725.rs @@ -17,6 +17,7 @@ extern "C" { #[link_name] //~^ ERROR malformed `link_name` attribute input //~| HELP must be of the form +//~| NOTE for more information, visit extern "C" { fn bar() -> u32; } diff --git a/tests/ui/extern/issue-47725.stderr b/tests/ui/extern/issue-47725.stderr index 4fd02a1778b..c5af54b8029 100644 --- a/tests/ui/extern/issue-47725.stderr +++ b/tests/ui/extern/issue-47725.stderr @@ -3,6 +3,8 @@ error[E0539]: malformed `link_name` attribute input | LL | #[link_name] | ^^^^^^^^^^^^ help: must be of the form: `#[link_name = "name"]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/items/external-blocks.html#the-link_name-attribute> warning: attribute should be applied to a foreign function or static --> $DIR/issue-47725.rs:3:1 diff --git a/tests/ui/feature-gates/feature-gate-optimize_attribute.stderr b/tests/ui/feature-gates/feature-gate-optimize_attribute.stderr index e7e62b4f989..646abf8e4a1 100644 --- a/tests/ui/feature-gates/feature-gate-optimize_attribute.stderr +++ b/tests/ui/feature-gates/feature-gate-optimize_attribute.stderr @@ -43,9 +43,20 @@ error[E0539]: malformed `optimize` attribute input | LL | #[optimize(banana)] | ^^^^^^^^^^^------^^ - | | | - | | valid arguments are `size`, `speed` or `none` - | help: must be of the form: `#[optimize(size|speed|none)]` + | | + | valid arguments are `size`, `speed` or `none` + | +help: try changing it to one of the following valid forms of the attribute + | +LL - #[optimize(banana)] +LL + #[optimize(none)] + | +LL - #[optimize(banana)] +LL + #[optimize(size)] + | +LL - #[optimize(banana)] +LL + #[optimize(speed)] + | error: aborting due to 5 previous errors diff --git a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr index 4cba54bf67c..7550e26f4a7 100644 --- a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr +++ b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr @@ -304,7 +304,7 @@ error[E0517]: attribute should be applied to a struct, enum, or union LL | #[repr(Rust)] impl S { } | ^^^^ ---------- not a struct, enum, or union -error: valid forms for the attribute are `#[inline(always|never)]` and `#[inline]` +error: valid forms for the attribute are `#[inline(always)]`, `#[inline(never)]`, and `#[inline]` --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:46:5 | LL | #[inline = "2100"] fn f() { } @@ -318,3 +318,14 @@ error: aborting due to 38 previous errors Some errors have detailed explanations: E0517, E0518, E0658. For more information about an error, try `rustc --explain E0517`. +Future incompatibility report: Future breakage diagnostic: +error: valid forms for the attribute are `#[inline(always)]`, `#[inline(never)]`, and `#[inline]` + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:46:5 + | +LL | #[inline = "2100"] fn f() { } + | ^^^^^^^^^^^^^^^^^^ + | + = 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 #57571 <https://github.com/rust-lang/rust/issues/57571> + = note: `#[deny(ill_formed_attribute_input)]` on by default + diff --git a/tests/ui/fn/fn-arg-count-mismatch-diagnostics.rs b/tests/ui/fn/fn-arg-count-mismatch-diagnostics.rs index b2f80ba1bf6..3b12ea1a736 100644 --- a/tests/ui/fn/fn-arg-count-mismatch-diagnostics.rs +++ b/tests/ui/fn/fn-arg-count-mismatch-diagnostics.rs @@ -46,9 +46,21 @@ impl Bar { } } +fn function_with_lots_of_arguments(a: i32, b: char, c: i32, d: i32, e: i32, f: i32) {} + fn main() { foo(1, 2, 3); //~^ ERROR function takes 4 arguments but 3 bar(1, 2, 3); //~^ ERROR function takes 6 arguments but 3 + + let variable_name = 42; + function_with_lots_of_arguments( + variable_name, + variable_name, + variable_name, + variable_name, + variable_name, + ); + //~^^^^^^^ ERROR this function takes 6 arguments but 5 arguments were supplied [E0061] } diff --git a/tests/ui/fn/fn-arg-count-mismatch-diagnostics.stderr b/tests/ui/fn/fn-arg-count-mismatch-diagnostics.stderr index 6af7671af03..dda9b398a83 100644 --- a/tests/ui/fn/fn-arg-count-mismatch-diagnostics.stderr +++ b/tests/ui/fn/fn-arg-count-mismatch-diagnostics.stderr @@ -52,7 +52,7 @@ LL | <$from>::$method(8, /* u8 */) | ++++++++++ error[E0061]: this function takes 4 arguments but 3 arguments were supplied - --> $DIR/fn-arg-count-mismatch-diagnostics.rs:50:5 + --> $DIR/fn-arg-count-mismatch-diagnostics.rs:52:5 | LL | foo(1, 2, 3); | ^^^--------- argument #4 of type `isize` is missing @@ -68,7 +68,7 @@ LL | foo(1, 2, 3, /* isize */); | +++++++++++++ error[E0061]: this function takes 6 arguments but 3 arguments were supplied - --> $DIR/fn-arg-count-mismatch-diagnostics.rs:52:5 + --> $DIR/fn-arg-count-mismatch-diagnostics.rs:54:5 | LL | bar(1, 2, 3); | ^^^--------- three arguments of type `i32`, `i32`, and `i32` are missing @@ -83,6 +83,28 @@ help: provide the arguments LL | bar(1, 2, 3, /* i32 */, /* i32 */, /* i32 */); | +++++++++++++++++++++++++++++++++ -error: aborting due to 5 previous errors +error[E0061]: this function takes 6 arguments but 5 arguments were supplied + --> $DIR/fn-arg-count-mismatch-diagnostics.rs:58:5 + | +LL | function_with_lots_of_arguments( + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | variable_name, +LL | variable_name, + | ------------- argument #2 of type `char` is missing + | +note: function defined here + --> $DIR/fn-arg-count-mismatch-diagnostics.rs:49:4 + | +LL | fn function_with_lots_of_arguments(a: i32, b: char, c: i32, d: i32, e: i32, f: i32) {} + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ------- +help: provide the argument + | +LL | function_with_lots_of_arguments( +LL | variable_name, +LL ~ /* char */, +LL ~ variable_name, + | + +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0061`. diff --git a/tests/ui/issues/issue-15094.rs b/tests/ui/fn/fn-traits-call-once-signature-15094.rs index 408ab82eb8c..f550bafe43d 100644 --- a/tests/ui/issues/issue-15094.rs +++ b/tests/ui/fn/fn-traits-call-once-signature-15094.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15094 + #![feature(fn_traits, unboxed_closures)] use std::{fmt, ops}; diff --git a/tests/ui/issues/issue-15094.stderr b/tests/ui/fn/fn-traits-call-once-signature-15094.stderr index 8e0fc8f1770..bb1d336e848 100644 --- a/tests/ui/issues/issue-15094.stderr +++ b/tests/ui/fn/fn-traits-call-once-signature-15094.stderr @@ -1,5 +1,5 @@ error[E0053]: method `call_once` has an incompatible type for trait - --> $DIR/issue-15094.rs:11:5 + --> $DIR/fn-traits-call-once-signature-15094.rs:13:5 | LL | fn call_once(self, _args: ()) { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected "rust-call" fn, found "Rust" fn diff --git a/tests/ui/issues/auxiliary/issue-9968.rs b/tests/ui/imports/auxiliary/aux-9968.rs index 8d795b59ea8..8d795b59ea8 100644 --- a/tests/ui/issues/auxiliary/issue-9968.rs +++ b/tests/ui/imports/auxiliary/aux-9968.rs diff --git a/tests/ui/issues/issue-15774.rs b/tests/ui/imports/enum-variant-import-path-15774.rs index dadd59cc077..583fe4da179 100644 --- a/tests/ui/issues/issue-15774.rs +++ b/tests/ui/imports/enum-variant-import-path-15774.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15774 + //@ edition: 2015 //@ run-pass diff --git a/tests/ui/imports/pub-use-link-errors-9968.rs b/tests/ui/imports/pub-use-link-errors-9968.rs new file mode 100644 index 00000000000..517a0049ce0 --- /dev/null +++ b/tests/ui/imports/pub-use-link-errors-9968.rs @@ -0,0 +1,12 @@ +// https://github.com/rust-lang/rust/issues/9968 +//@ run-pass +//@ aux-build:aux-9968.rs + +extern crate aux_9968 as lib; + +use lib::{Trait, Struct}; + +pub fn main() +{ + Struct::init().test(); +} diff --git a/tests/ui/inference/iterator-sum-array-15673.rs b/tests/ui/inference/iterator-sum-array-15673.rs new file mode 100644 index 00000000000..c3d94415aff --- /dev/null +++ b/tests/ui/inference/iterator-sum-array-15673.rs @@ -0,0 +1,11 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15673 + +//@ run-pass +#![allow(stable_features)] + +#![feature(iter_arith)] + +fn main() { + let x: [u64; 3] = [1, 2, 3]; + assert_eq!(6, (0..3).map(|i| x[i]).sum::<u64>()); +} diff --git a/tests/ui/issues/issue-15965.rs b/tests/ui/inference/return-block-type-inference-15965.rs index eef4900d432..50753e309e8 100644 --- a/tests/ui/issues/issue-15965.rs +++ b/tests/ui/inference/return-block-type-inference-15965.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15965 + fn main() { return { return () } diff --git a/tests/ui/issues/issue-15965.stderr b/tests/ui/inference/return-block-type-inference-15965.stderr index 14727e74334..fc4f2defe7f 100644 --- a/tests/ui/issues/issue-15965.stderr +++ b/tests/ui/inference/return-block-type-inference-15965.stderr @@ -1,5 +1,5 @@ error[E0282]: type annotations needed - --> $DIR/issue-15965.rs:3:9 + --> $DIR/return-block-type-inference-15965.rs:5:9 | LL | / { return () } LL | | diff --git a/tests/ui/infinite/issue-41731-infinite-macro-print.rs b/tests/ui/infinite/issue-41731-infinite-macro-print.rs index 7cd3ff3d629..aa5555b117a 100644 --- a/tests/ui/infinite/issue-41731-infinite-macro-print.rs +++ b/tests/ui/infinite/issue-41731-infinite-macro-print.rs @@ -5,7 +5,7 @@ fn main() { macro_rules! stack { ($overflow:expr) => { - print!(stack!($overflow)); + print!(stack!($overflow)) //~^ ERROR recursion limit reached while expanding //~| ERROR format argument must be a string literal }; diff --git a/tests/ui/infinite/issue-41731-infinite-macro-print.stderr b/tests/ui/infinite/issue-41731-infinite-macro-print.stderr index 71510816d0b..84436de9aa3 100644 --- a/tests/ui/infinite/issue-41731-infinite-macro-print.stderr +++ b/tests/ui/infinite/issue-41731-infinite-macro-print.stderr @@ -14,11 +14,11 @@ LL | stack!("overflow"); | ^^^^^^^^^^^^^^^^^^ | = note: expanding `stack! { "overflow" }` - = note: to `print! (stack! ("overflow"));` + = note: to `print! (stack! ("overflow"))` = note: expanding `print! { stack! ("overflow") }` = note: to `{ $crate :: io :: _print($crate :: format_args! (stack! ("overflow"))); }` = note: expanding `stack! { "overflow" }` - = note: to `print! (stack! ("overflow"));` + = note: to `print! (stack! ("overflow"))` = note: expanding `print! { stack! ("overflow") }` = note: to `{ $crate :: io :: _print($crate :: format_args! (stack! ("overflow"))); }` @@ -31,7 +31,7 @@ LL | stack!("overflow"); = note: this error originates in the macro `print` which comes from the expansion of the macro `stack` (in Nightly builds, run with -Z macro-backtrace for more info) help: you might be missing a string literal to format with | -LL | print!("{}", stack!($overflow)); +LL | print!("{}", stack!($overflow)) | +++++ error: aborting due to 2 previous errors diff --git a/tests/ui/infinite/issue-41731-infinite-macro-println.rs b/tests/ui/infinite/issue-41731-infinite-macro-println.rs index 491f18dc4c6..cf59afb0194 100644 --- a/tests/ui/infinite/issue-41731-infinite-macro-println.rs +++ b/tests/ui/infinite/issue-41731-infinite-macro-println.rs @@ -5,7 +5,7 @@ fn main() { macro_rules! stack { ($overflow:expr) => { - println!(stack!($overflow)); + println!(stack!($overflow)) //~^ ERROR recursion limit reached while expanding //~| ERROR format argument must be a string literal }; diff --git a/tests/ui/infinite/issue-41731-infinite-macro-println.stderr b/tests/ui/infinite/issue-41731-infinite-macro-println.stderr index 645176d45cb..6d0432abe4c 100644 --- a/tests/ui/infinite/issue-41731-infinite-macro-println.stderr +++ b/tests/ui/infinite/issue-41731-infinite-macro-println.stderr @@ -14,11 +14,11 @@ LL | stack!("overflow"); | ^^^^^^^^^^^^^^^^^^ | = note: expanding `stack! { "overflow" }` - = note: to `println! (stack! ("overflow"));` + = note: to `println! (stack! ("overflow"))` = note: expanding `println! { stack! ("overflow") }` = note: to `{ $crate :: io :: _print($crate :: format_args_nl! (stack! ("overflow"))); }` = note: expanding `stack! { "overflow" }` - = note: to `println! (stack! ("overflow"));` + = note: to `println! (stack! ("overflow"))` = note: expanding `println! { stack! ("overflow") }` = note: to `{ $crate :: io :: _print($crate :: format_args_nl! (stack! ("overflow"))); }` @@ -31,7 +31,7 @@ LL | stack!("overflow"); = note: this error originates in the macro `println` which comes from the expansion of the macro `stack` (in Nightly builds, run with -Z macro-backtrace for more info) help: you might be missing a string literal to format with | -LL | println!("{}", stack!($overflow)); +LL | println!("{}", stack!($overflow)) | +++++ error: aborting due to 2 previous errors diff --git a/tests/ui/invalid-compile-flags/print-crate-name-request-malformed-crate-name.stderr b/tests/ui/invalid-compile-flags/print-crate-name-request-malformed-crate-name.stderr index 6bf09a2b131..b773f7c97aa 100644 --- a/tests/ui/invalid-compile-flags/print-crate-name-request-malformed-crate-name.stderr +++ b/tests/ui/invalid-compile-flags/print-crate-name-request-malformed-crate-name.stderr @@ -3,6 +3,8 @@ error: malformed `crate_name` attribute input | LL | #![crate_name = concat!("wrapped")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#![crate_name = "name"]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/crates-and-source-files.html#the-crate_name-attribute> error: aborting due to 1 previous error diff --git a/tests/ui/invalid-compile-flags/print-file-names-request-malformed-crate-name-1.stderr b/tests/ui/invalid-compile-flags/print-file-names-request-malformed-crate-name-1.stderr index de62aed79fc..64e38ed8533 100644 --- a/tests/ui/invalid-compile-flags/print-file-names-request-malformed-crate-name-1.stderr +++ b/tests/ui/invalid-compile-flags/print-file-names-request-malformed-crate-name-1.stderr @@ -3,6 +3,8 @@ error: malformed `crate_name` attribute input | LL | #![crate_name] | ^^^^^^^^^^^^^^ help: must be of the form: `#![crate_name = "name"]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/crates-and-source-files.html#the-crate_name-attribute> error: aborting due to 1 previous error diff --git a/tests/ui/invalid-compile-flags/print-file-names-request-malformed-crate-name-2.stderr b/tests/ui/invalid-compile-flags/print-file-names-request-malformed-crate-name-2.stderr index 42c33de1221..e9a5b58e4f9 100644 --- a/tests/ui/invalid-compile-flags/print-file-names-request-malformed-crate-name-2.stderr +++ b/tests/ui/invalid-compile-flags/print-file-names-request-malformed-crate-name-2.stderr @@ -3,6 +3,8 @@ error: malformed `crate_name` attribute input | LL | #![crate_name = concat!("this_one_is_not")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#![crate_name = "name"]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/crates-and-source-files.html#the-crate_name-attribute> error: aborting due to 1 previous error diff --git a/tests/ui/invalid-compile-flags/print-file-names-request-malformed-crate-name.stderr b/tests/ui/invalid-compile-flags/print-file-names-request-malformed-crate-name.stderr index cb5ffaab9ca..e63525c6a5d 100644 --- a/tests/ui/invalid-compile-flags/print-file-names-request-malformed-crate-name.stderr +++ b/tests/ui/invalid-compile-flags/print-file-names-request-malformed-crate-name.stderr @@ -3,6 +3,8 @@ error: malformed `crate_name` attribute input | LL | #![crate_name = concat!("wrapped")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#![crate_name = "name"]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/crates-and-source-files.html#the-crate_name-attribute> error: aborting due to 1 previous error diff --git a/tests/ui/invalid/invalid-inline.stderr b/tests/ui/invalid/invalid-inline.stderr index 54e6b2b5408..78ffe3270a7 100644 --- a/tests/ui/invalid/invalid-inline.stderr +++ b/tests/ui/invalid/invalid-inline.stderr @@ -6,10 +6,14 @@ LL | #[inline(please,no)] | | | expected a single argument here | + = note: for more information, visit <https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute> help: try changing it to one of the following valid forms of the attribute | LL - #[inline(please,no)] -LL + #[inline(always|never)] +LL + #[inline(always)] + | +LL - #[inline(please,no)] +LL + #[inline(never)] | LL - #[inline(please,no)] LL + #[inline] @@ -23,10 +27,13 @@ LL | #[inline()] | | | expected a single argument here | + = note: for more information, visit <https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute> help: try changing it to one of the following valid forms of the attribute | -LL | #[inline(always|never)] - | ++++++++++++ +LL | #[inline(always)] + | ++++++ +LL | #[inline(never)] + | +++++ LL - #[inline()] LL + #[inline] | diff --git a/tests/ui/issues/issue-4335.stderr b/tests/ui/issues/issue-4335.stderr index 42ac6322564..b6d8f086163 100644 --- a/tests/ui/issues/issue-4335.stderr +++ b/tests/ui/issues/issue-4335.stderr @@ -10,6 +10,7 @@ LL | id(Box::new(|| *v)) | | | captured by this `FnMut` closure | + = help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once help: if `T` implemented `Clone`, you could clone the value --> $DIR/issue-4335.rs:5:10 | diff --git a/tests/ui/issues/issue-43988.stderr b/tests/ui/issues/issue-43988.stderr index fe61e136a51..b50d691e685 100644 --- a/tests/ui/issues/issue-43988.stderr +++ b/tests/ui/issues/issue-43988.stderr @@ -6,10 +6,14 @@ LL | #[inline(XYZ)] | | | valid arguments are `always` or `never` | + = note: for more information, visit <https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute> help: try changing it to one of the following valid forms of the attribute | LL - #[inline(XYZ)] -LL + #[inline(always|never)] +LL + #[inline(always)] + | +LL - #[inline(XYZ)] +LL + #[inline(never)] | LL - #[inline(XYZ)] LL + #[inline] @@ -22,6 +26,7 @@ LL | #[repr(nothing)] | ^^^^^^^ | = help: valid reprs are `Rust` (default), `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize` + = note: for more information, visit <https://doc.rust-lang.org/reference/type-layout.html?highlight=repr#representations> error[E0552]: unrecognized representation hint --> $DIR/issue-43988.rs:18:12 @@ -30,15 +35,26 @@ LL | #[repr(something_not_real)] | ^^^^^^^^^^^^^^^^^^ | = help: valid reprs are `Rust` (default), `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize` + = note: for more information, visit <https://doc.rust-lang.org/reference/type-layout.html?highlight=repr#representations> error[E0539]: malformed `repr` attribute input --> $DIR/issue-43988.rs:24:5 | LL | #[repr] - | ^^^^^^^ - | | - | expected this to be a list - | help: must be of the form: `#[repr(C | Rust | align(...) | packed(...) | <integer type> | transparent)]` + | ^^^^^^^ expected this to be a list + | + = note: for more information, visit <https://doc.rust-lang.org/reference/type-layout.html#representations> +help: try changing it to one of the following valid forms of the attribute + | +LL | #[repr(<integer type>)] + | ++++++++++++++++ +LL | #[repr(C)] + | +++ +LL | #[repr(Rust)] + | ++++++ +LL | #[repr(align(...))] + | ++++++++++++ + = and 2 other candidates error[E0539]: malformed `inline` attribute input --> $DIR/issue-43988.rs:30:5 @@ -48,10 +64,14 @@ LL | #[inline(ABC)] | | | valid arguments are `always` or `never` | + = note: for more information, visit <https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute> help: try changing it to one of the following valid forms of the attribute | LL - #[inline(ABC)] -LL + #[inline(always|never)] +LL + #[inline(always)] + | +LL - #[inline(ABC)] +LL + #[inline(never)] | LL - #[inline(ABC)] LL + #[inline] @@ -61,10 +81,20 @@ error[E0539]: malformed `repr` attribute input --> $DIR/issue-43988.rs:34:14 | LL | let _z = #[repr] 1; - | ^^^^^^^ - | | - | expected this to be a list - | help: must be of the form: `#[repr(C | Rust | align(...) | packed(...) | <integer type> | transparent)]` + | ^^^^^^^ expected this to be a list + | + = note: for more information, visit <https://doc.rust-lang.org/reference/type-layout.html#representations> +help: try changing it to one of the following valid forms of the attribute + | +LL | let _z = #[repr(<integer type>)] 1; + | ++++++++++++++++ +LL | let _z = #[repr(C)] 1; + | +++ +LL | let _z = #[repr(Rust)] 1; + | ++++++ +LL | let _z = #[repr(align(...))] 1; + | ++++++++++++ + = and 2 other candidates error[E0518]: attribute should be applied to function or closure --> $DIR/issue-43988.rs:5:5 diff --git a/tests/ui/issues/issue-9155.rs b/tests/ui/issues/issue-9155.rs deleted file mode 100644 index dfd9dea2009..00000000000 --- a/tests/ui/issues/issue-9155.rs +++ /dev/null @@ -1,11 +0,0 @@ -//@ run-pass -//@ aux-build:issue-9155.rs - - -extern crate issue_9155; - -struct Baz; - -pub fn main() { - issue_9155::Foo::new(Baz); -} diff --git a/tests/ui/issues/issue-9906.rs b/tests/ui/issues/issue-9906.rs deleted file mode 100644 index 50417d3e456..00000000000 --- a/tests/ui/issues/issue-9906.rs +++ /dev/null @@ -1,10 +0,0 @@ -//@ run-pass -//@ aux-build:issue-9906.rs - - -extern crate issue_9906 as testmod; - -pub fn main() { - testmod::foo(); - testmod::FooBar::new(1); -} diff --git a/tests/ui/issues/issue-9968.rs b/tests/ui/issues/issue-9968.rs deleted file mode 100644 index 89e60ba5ac7..00000000000 --- a/tests/ui/issues/issue-9968.rs +++ /dev/null @@ -1,12 +0,0 @@ -//@ run-pass -//@ aux-build:issue-9968.rs - - -extern crate issue_9968 as lib; - -use lib::{Trait, Struct}; - -pub fn main() -{ - Struct::init().test(); -} diff --git a/tests/ui/issues/issue-15756.rs b/tests/ui/iterators/explicit-deref-non-deref-type-15756.rs index e0861dee61e..6d4a3bffcf7 100644 --- a/tests/ui/issues/issue-15756.rs +++ b/tests/ui/iterators/explicit-deref-non-deref-type-15756.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15756 + use std::slice::Chunks; use std::slice::ChunksMut; diff --git a/tests/ui/issues/issue-15756.stderr b/tests/ui/iterators/explicit-deref-non-deref-type-15756.stderr index a487d360bef..b4f9aab8496 100644 --- a/tests/ui/issues/issue-15756.stderr +++ b/tests/ui/iterators/explicit-deref-non-deref-type-15756.stderr @@ -1,5 +1,5 @@ error[E0277]: the size for values of type `[T]` cannot be known at compilation time - --> $DIR/issue-15756.rs:7:10 + --> $DIR/explicit-deref-non-deref-type-15756.rs:9:10 | LL | &mut something | ^^^^^^^^^ doesn't have a size known at compile-time diff --git a/tests/ui/issues/issue-21655.rs b/tests/ui/iterators/for-loop-over-mut-iterator-21655.rs index 1068b28b338..b5c9826bd45 100644 --- a/tests/ui/issues/issue-21655.rs +++ b/tests/ui/iterators/for-loop-over-mut-iterator-21655.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/21655 //@ run-pass fn test(it: &mut dyn Iterator<Item=i32>) { diff --git a/tests/ui/issues/issue-15034.rs b/tests/ui/lifetimes/nondeterministic-lifetime-errors-15034.rs index 9ea6ed89ca2..e7f9a94231f 100644 --- a/tests/ui/issues/issue-15034.rs +++ b/tests/ui/lifetimes/nondeterministic-lifetime-errors-15034.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15034 + pub struct Lexer<'a> { input: &'a str, } diff --git a/tests/ui/issues/issue-15034.stderr b/tests/ui/lifetimes/nondeterministic-lifetime-errors-15034.stderr index 7db8ade2e48..0762714d259 100644 --- a/tests/ui/issues/issue-15034.stderr +++ b/tests/ui/lifetimes/nondeterministic-lifetime-errors-15034.stderr @@ -1,5 +1,5 @@ error[E0621]: explicit lifetime required in the type of `lexer` - --> $DIR/issue-15034.rs:17:9 + --> $DIR/nondeterministic-lifetime-errors-15034.rs:19:9 | LL | Parser { lexer: lexer } | ^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'a` required diff --git a/tests/ui/lifetimes/struct-lifetime-inference-15735.rs b/tests/ui/lifetimes/struct-lifetime-inference-15735.rs new file mode 100644 index 00000000000..39e619648eb --- /dev/null +++ b/tests/ui/lifetimes/struct-lifetime-inference-15735.rs @@ -0,0 +1,19 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15735 + +//@ check-pass +#![allow(dead_code)] +struct A<'a> { + a: &'a i32, + b: &'a i32, +} + +impl <'a> A<'a> { + fn foo<'b>(&'b self) { + A { + a: self.a, + b: self.b, + }; + } +} + +fn main() { } diff --git a/tests/ui/issues/issue-9259.rs b/tests/ui/lifetimes/struct-with-lifetime-parameters-9259.rs index c45288f7d65..7e39fdc3f10 100644 --- a/tests/ui/issues/issue-9259.rs +++ b/tests/ui/lifetimes/struct-with-lifetime-parameters-9259.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/9259 //@ run-pass #![allow(dead_code)] diff --git a/tests/ui/link-native-libs/link-attr-validation-early.rs b/tests/ui/link-native-libs/link-attr-validation-early.rs index b9a835fb5e9..a7dd80f8920 100644 --- a/tests/ui/link-native-libs/link-attr-validation-early.rs +++ b/tests/ui/link-native-libs/link-attr-validation-early.rs @@ -1,7 +1,7 @@ // Top-level ill-formed -#[link] //~ ERROR attribute must be of the form +#[link] //~ ERROR valid forms for the attribute are //~| WARN this was previously accepted -#[link = "foo"] //~ ERROR attribute must be of the form +#[link = "foo"] //~ ERROR valid forms for the attribute are //~| WARN this was previously accepted extern "C" {} diff --git a/tests/ui/link-native-libs/link-attr-validation-early.stderr b/tests/ui/link-native-libs/link-attr-validation-early.stderr index 24ad9d825f8..36cca6f27ef 100644 --- a/tests/ui/link-native-libs/link-attr-validation-early.stderr +++ b/tests/ui/link-native-libs/link-attr-validation-early.stderr @@ -1,4 +1,4 @@ -error: attribute must be of the form `#[link(name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ wasm_import_module = "...", /*opt*/ import_name_type = "decorated|noprefix|undecorated")]` +error: valid forms for the attribute are `#[link(name = "...")]`, `#[link(name = "...", kind = "dylib|static|...")]`, `#[link(name = "...", wasm_import_module = "...")]`, `#[link(name = "...", import_name_type = "decorated|noprefix|undecorated")]`, and `#[link(name = "...", kind = "dylib|static|...", wasm_import_module = "...", import_name_type = "decorated|noprefix|undecorated")]` --> $DIR/link-attr-validation-early.rs:2:1 | LL | #[link] @@ -6,9 +6,10 @@ LL | #[link] | = 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 #57571 <https://github.com/rust-lang/rust/issues/57571> + = note: for more information, visit <https://doc.rust-lang.org/reference/items/external-blocks.html#the-link-attribute> = note: `#[deny(ill_formed_attribute_input)]` on by default -error: attribute must be of the form `#[link(name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ wasm_import_module = "...", /*opt*/ import_name_type = "decorated|noprefix|undecorated")]` +error: valid forms for the attribute are `#[link(name = "...")]`, `#[link(name = "...", kind = "dylib|static|...")]`, `#[link(name = "...", wasm_import_module = "...")]`, `#[link(name = "...", import_name_type = "decorated|noprefix|undecorated")]`, and `#[link(name = "...", kind = "dylib|static|...", wasm_import_module = "...", import_name_type = "decorated|noprefix|undecorated")]` --> $DIR/link-attr-validation-early.rs:4:1 | LL | #[link = "foo"] @@ -16,6 +17,31 @@ LL | #[link = "foo"] | = 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 #57571 <https://github.com/rust-lang/rust/issues/57571> + = note: for more information, visit <https://doc.rust-lang.org/reference/items/external-blocks.html#the-link-attribute> error: aborting due to 2 previous errors +Future incompatibility report: Future breakage diagnostic: +error: valid forms for the attribute are `#[link(name = "...")]`, `#[link(name = "...", kind = "dylib|static|...")]`, `#[link(name = "...", wasm_import_module = "...")]`, `#[link(name = "...", import_name_type = "decorated|noprefix|undecorated")]`, and `#[link(name = "...", kind = "dylib|static|...", wasm_import_module = "...", import_name_type = "decorated|noprefix|undecorated")]` + --> $DIR/link-attr-validation-early.rs:2:1 + | +LL | #[link] + | ^^^^^^^ + | + = 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 #57571 <https://github.com/rust-lang/rust/issues/57571> + = note: for more information, visit <https://doc.rust-lang.org/reference/items/external-blocks.html#the-link-attribute> + = note: `#[deny(ill_formed_attribute_input)]` on by default + +Future breakage diagnostic: +error: valid forms for the attribute are `#[link(name = "...")]`, `#[link(name = "...", kind = "dylib|static|...")]`, `#[link(name = "...", wasm_import_module = "...")]`, `#[link(name = "...", import_name_type = "decorated|noprefix|undecorated")]`, and `#[link(name = "...", kind = "dylib|static|...", wasm_import_module = "...", import_name_type = "decorated|noprefix|undecorated")]` + --> $DIR/link-attr-validation-early.rs:4:1 + | +LL | #[link = "foo"] + | ^^^^^^^^^^^^^^^ + | + = 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 #57571 <https://github.com/rust-lang/rust/issues/57571> + = note: for more information, visit <https://doc.rust-lang.org/reference/items/external-blocks.html#the-link-attribute> + = note: `#[deny(ill_formed_attribute_input)]` on by default + diff --git a/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-invalid-format.stderr b/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-invalid-format.stderr index ffae30aabcc..6bf1eab311a 100644 --- a/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-invalid-format.stderr +++ b/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-invalid-format.stderr @@ -6,6 +6,8 @@ LL | #[link_ordinal("JustMonika")] | | | | | expected an integer literal here | help: must be of the form: `#[link_ordinal(ordinal)]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/items/external-blocks.html#the-link_ordinal-attribute> error[E0539]: malformed `link_ordinal` attribute input --> $DIR/link-ordinal-invalid-format.rs:6:5 @@ -15,6 +17,8 @@ LL | #[link_ordinal("JustMonika")] | | | | | expected an integer literal here | help: must be of the form: `#[link_ordinal(ordinal)]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/items/external-blocks.html#the-link_ordinal-attribute> error: aborting due to 2 previous errors diff --git a/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-missing-argument.rs b/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-missing-argument.rs index 2a8b9ebacf7..58f19085540 100644 --- a/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-missing-argument.rs +++ b/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-missing-argument.rs @@ -3,10 +3,12 @@ extern "C" { #[link_ordinal()] //~^ ERROR malformed `link_ordinal` attribute input //~| NOTE expected a single argument + //~| NOTE for more information, visit fn foo(); #[link_ordinal()] //~^ ERROR malformed `link_ordinal` attribute input //~| NOTE expected a single argument + //~| NOTE for more information, visit static mut imported_variable: i32; } diff --git a/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-missing-argument.stderr b/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-missing-argument.stderr index c6b8a18d03a..d575b0961af 100644 --- a/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-missing-argument.stderr +++ b/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-missing-argument.stderr @@ -6,15 +6,19 @@ LL | #[link_ordinal()] | | | | | expected a single argument here | help: must be of the form: `#[link_ordinal(ordinal)]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/items/external-blocks.html#the-link_ordinal-attribute> error[E0805]: malformed `link_ordinal` attribute input - --> $DIR/link-ordinal-missing-argument.rs:7:5 + --> $DIR/link-ordinal-missing-argument.rs:8:5 | LL | #[link_ordinal()] | ^^^^^^^^^^^^^^--^ | | | | | expected a single argument here | help: must be of the form: `#[link_ordinal(ordinal)]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/items/external-blocks.html#the-link_ordinal-attribute> error: aborting due to 2 previous errors diff --git a/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-too-many-arguments.rs b/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-too-many-arguments.rs index ddf9583352f..55b18ae0d96 100644 --- a/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-too-many-arguments.rs +++ b/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-too-many-arguments.rs @@ -3,10 +3,12 @@ extern "C" { #[link_ordinal(3, 4)] //~^ ERROR malformed `link_ordinal` attribute input //~| NOTE expected a single argument + //~| NOTE for more information, visit fn foo(); #[link_ordinal(3, 4)] //~^ ERROR malformed `link_ordinal` attribute input //~| NOTE expected a single argument + //~| NOTE for more information, visit static mut imported_variable: i32; } diff --git a/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-too-many-arguments.stderr b/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-too-many-arguments.stderr index 7d63304f598..a84fef9f9e4 100644 --- a/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-too-many-arguments.stderr +++ b/tests/ui/linkage-attr/raw-dylib/windows/link-ordinal-too-many-arguments.stderr @@ -6,15 +6,19 @@ LL | #[link_ordinal(3, 4)] | | | | | expected a single argument here | help: must be of the form: `#[link_ordinal(ordinal)]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/items/external-blocks.html#the-link_ordinal-attribute> error[E0805]: malformed `link_ordinal` attribute input - --> $DIR/link-ordinal-too-many-arguments.rs:7:5 + --> $DIR/link-ordinal-too-many-arguments.rs:8:5 | LL | #[link_ordinal(3, 4)] | ^^^^^^^^^^^^^^------^ | | | | | expected a single argument here | help: must be of the form: `#[link_ordinal(ordinal)]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/items/external-blocks.html#the-link_ordinal-attribute> error: aborting due to 2 previous errors diff --git a/tests/ui/lint/dead-code/self-assign.rs b/tests/ui/lint/dead-code/self-assign.rs index 357846baf22..ce91f53cbf1 100644 --- a/tests/ui/lint/dead-code/self-assign.rs +++ b/tests/ui/lint/dead-code/self-assign.rs @@ -7,23 +7,20 @@ //! - `dead_code` lint expansion for self-assignments was implemented in #87129. //! - Unfortunately implementation components of #87129 had to be disabled as part of reverts //! #86212, #83171 (to revert #81473) to address regressions #81626 and #81658. -//! - Consequently, none of the following warnings are emitted. +//! - Re-enabled in current version to properly detect self-assignments. //@ check-pass -// Implementation of self-assignment `dead_code` lint expansions disabled due to reverts. -//@ known-bug: #75356 - #![allow(unused_assignments)] #![warn(dead_code)] fn main() { let mut x = 0; x = x; - // FIXME ~^ WARNING: useless assignment of variable of type `i32` to itself + //~^ WARNING: useless assignment of variable of type `i32` to itself x = (x); - // FIXME ~^ WARNING: useless assignment of variable of type `i32` to itself + //~^ WARNING: useless assignment of variable of type `i32` to itself x = {x}; // block expressions don't count as self-assignments @@ -32,10 +29,10 @@ fn main() { struct S<'a> { f: &'a str } let mut s = S { f: "abc" }; s = s; - // FIXME ~^ WARNING: useless assignment of variable of type `S` to itself + //~^ WARNING: useless assignment of variable of type `S<'_>` to itself s.f = s.f; - // FIXME ~^ WARNING: useless assignment of field of type `&str` to itself + //~^ WARNING: useless assignment of field of type `&str` to itself struct N0 { x: Box<i32> } @@ -44,11 +41,11 @@ fn main() { struct N3 { n: N2 }; let mut n3 = N3 { n: N2(N1 { n: N0 { x: Box::new(42) } }) }; n3.n.0.n.x = n3.n.0.n.x; - // FIXME ~^ WARNING: useless assignment of field of type `Box<i32>` to itself + //~^ WARNING: useless assignment of field of type `Box<i32>` to itself let mut t = (1, ((2, 3, (4, 5)),)); t.1.0.2.1 = t.1.0.2.1; - // FIXME ~^ WARNING: useless assignment of field of type `i32` to itself + //~^ WARNING: useless assignment of field of type `i32` to itself let mut y = 0; diff --git a/tests/ui/lint/dead-code/self-assign.stderr b/tests/ui/lint/dead-code/self-assign.stderr new file mode 100644 index 00000000000..408ebdb658b --- /dev/null +++ b/tests/ui/lint/dead-code/self-assign.stderr @@ -0,0 +1,44 @@ +warning: useless assignment of variable of type `i32` to itself + --> $DIR/self-assign.rs:19:5 + | +LL | x = x; + | ^^^^^ + | +note: the lint level is defined here + --> $DIR/self-assign.rs:15:9 + | +LL | #![warn(dead_code)] + | ^^^^^^^^^ + +warning: useless assignment of variable of type `i32` to itself + --> $DIR/self-assign.rs:22:5 + | +LL | x = (x); + | ^^^^^^^ + +warning: useless assignment of variable of type `S<'_>` to itself + --> $DIR/self-assign.rs:31:5 + | +LL | s = s; + | ^^^^^ + +warning: useless assignment of field of type `&str` to itself + --> $DIR/self-assign.rs:34:5 + | +LL | s.f = s.f; + | ^^^^^^^^^ + +warning: useless assignment of field of type `Box<i32>` to itself + --> $DIR/self-assign.rs:43:5 + | +LL | n3.n.0.n.x = n3.n.0.n.x; + | ^^^^^^^^^^^^^^^^^^^^^^^ + +warning: useless assignment of field of type `i32` to itself + --> $DIR/self-assign.rs:47:5 + | +LL | t.1.0.2.1 = t.1.0.2.1; + | ^^^^^^^^^^^^^^^^^^^^^ + +warning: 6 warnings emitted + diff --git a/tests/ui/lint/lint-malformed.stderr b/tests/ui/lint/lint-malformed.stderr index 0bdcc293b65..25a4298bd75 100644 --- a/tests/ui/lint/lint-malformed.stderr +++ b/tests/ui/lint/lint-malformed.stderr @@ -16,7 +16,20 @@ error: malformed `deny` attribute input --> $DIR/lint-malformed.rs:1:1 | LL | #![deny = "foo"] - | ^^^^^^^^^^^^^^^^ help: must be of the form: `#![deny(lint1, lint2, ..., /*opt*/ reason = "...")]` + | ^^^^^^^^^^^^^^^^ + | + = note: for more information, visit <https://doc.rust-lang.org/reference/attributes/diagnostics.html#lint-check-attributes> +help: the following are the possible correct uses + | +LL - #![deny = "foo"] +LL + #![deny(lint1)] + | +LL - #![deny = "foo"] +LL + #![deny(lint1, lint2, ...)] + | +LL - #![deny = "foo"] +LL + #![deny(lint1, lint2, lint3, reason = "...")] + | error[E0452]: malformed lint attribute input --> $DIR/lint-malformed.rs:2:10 diff --git a/tests/ui/issues/issue-29710.rs b/tests/ui/lint/unused-results-lint-triggered-by-derive-debug-29710.rs index 906ffe9e77b..51702f69c20 100644 --- a/tests/ui/issues/issue-29710.rs +++ b/tests/ui/lint/unused-results-lint-triggered-by-derive-debug-29710.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/29710 //@ check-pass #![deny(unused_results)] #![allow(dead_code)] diff --git a/tests/ui/issues/issue-9047.rs b/tests/ui/loops/loop-with-label-9047.rs index 97733588d51..29e6dba0b9e 100644 --- a/tests/ui/issues/issue-9047.rs +++ b/tests/ui/loops/loop-with-label-9047.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/9047 //@ run-pass #![allow(unused_mut)] #![allow(unused_variables)] diff --git a/tests/ui/issues/issue-15189.rs b/tests/ui/macros/for-loop-macro-rules-hygiene.rs index 4dbe2179dd9..fcebda1b9da 100644 --- a/tests/ui/issues/issue-15189.rs +++ b/tests/ui/macros/for-loop-macro-rules-hygiene.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15189 + //@ run-pass macro_rules! third { ($e:expr) => ({let x = 2; $e[x]}) diff --git a/tests/ui/macros/issue-111749.stderr b/tests/ui/macros/issue-111749.stderr index 7db2b8e6ad1..884537ef531 100644 --- a/tests/ui/macros/issue-111749.stderr +++ b/tests/ui/macros/issue-111749.stderr @@ -16,3 +16,14 @@ LL | cbor_map! { #[test(test)] 4}; error: aborting due to 2 previous errors +Future incompatibility report: Future breakage diagnostic: +error: attribute must be of the form `#[test]` + --> $DIR/issue-111749.rs:8:17 + | +LL | cbor_map! { #[test(test)] 4}; + | ^^^^^^^^^^^^^ + | + = 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 #57571 <https://github.com/rust-lang/rust/issues/57571> + = note: `#[deny(ill_formed_attribute_input)]` on by default + diff --git a/tests/ui/issues/issue-9110.rs b/tests/ui/macros/macro-expansion-module-structure-9110.rs index 47533dc43b5..b6241a7c18e 100644 --- a/tests/ui/issues/issue-9110.rs +++ b/tests/ui/macros/macro-expansion-module-structure-9110.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/9110 //@ check-pass #![allow(dead_code)] #![allow(non_snake_case)] diff --git a/tests/ui/issues/issue-15167.rs b/tests/ui/macros/macro-hygiene-scope-15167.rs index a2653c10ea4..6578f898a5f 100644 --- a/tests/ui/issues/issue-15167.rs +++ b/tests/ui/macros/macro-hygiene-scope-15167.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15167 + // macro f should not be able to inject a reference to 'n'. macro_rules! f { () => (n) } diff --git a/tests/ui/issues/issue-15167.stderr b/tests/ui/macros/macro-hygiene-scope-15167.stderr index 53082ea0ec6..58112c52df1 100644 --- a/tests/ui/issues/issue-15167.stderr +++ b/tests/ui/macros/macro-hygiene-scope-15167.stderr @@ -1,5 +1,5 @@ error[E0425]: cannot find value `n` in this scope - --> $DIR/issue-15167.rs:3:25 + --> $DIR/macro-hygiene-scope-15167.rs:5:25 | LL | macro_rules! f { () => (n) } | ^ not found in this scope @@ -10,7 +10,7 @@ LL | println!("{}", f!()); = note: this error originates in the macro `f` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0425]: cannot find value `n` in this scope - --> $DIR/issue-15167.rs:3:25 + --> $DIR/macro-hygiene-scope-15167.rs:5:25 | LL | macro_rules! f { () => (n) } | ^ not found in this scope @@ -21,7 +21,7 @@ LL | println!("{}", f!()); = note: this error originates in the macro `f` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0425]: cannot find value `n` in this scope - --> $DIR/issue-15167.rs:3:25 + --> $DIR/macro-hygiene-scope-15167.rs:5:25 | LL | macro_rules! f { () => (n) } | ^ not found in this scope @@ -32,7 +32,7 @@ LL | println!("{}", f!()); = note: this error originates in the macro `f` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0425]: cannot find value `n` in this scope - --> $DIR/issue-15167.rs:3:25 + --> $DIR/macro-hygiene-scope-15167.rs:5:25 | LL | macro_rules! f { () => (n) } | ^ not found in this scope diff --git a/tests/ui/issues/issue-9737.rs b/tests/ui/macros/macro-invocation-with-variable-in-scope-9737.rs index a8a17e58dd6..957c2e3f103 100644 --- a/tests/ui/issues/issue-9737.rs +++ b/tests/ui/macros/macro-invocation-with-variable-in-scope-9737.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/9737 //@ run-pass #![allow(unused_variables)] macro_rules! f { diff --git a/tests/ui/macros/macro-use-bad-args-1.stderr b/tests/ui/macros/macro-use-bad-args-1.stderr index 2f43d0997df..542b4ae2b7a 100644 --- a/tests/ui/macros/macro-use-bad-args-1.stderr +++ b/tests/ui/macros/macro-use-bad-args-1.stderr @@ -6,6 +6,7 @@ LL | #[macro_use(foo(bar))] | | | didn't expect any arguments here | + = note: for more information, visit <https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute> help: try changing it to one of the following valid forms of the attribute | LL - #[macro_use(foo(bar))] diff --git a/tests/ui/macros/macro-use-bad-args-2.stderr b/tests/ui/macros/macro-use-bad-args-2.stderr index d7b03c93588..2db9ffe50b0 100644 --- a/tests/ui/macros/macro-use-bad-args-2.stderr +++ b/tests/ui/macros/macro-use-bad-args-2.stderr @@ -6,6 +6,7 @@ LL | #[macro_use(foo="bar")] | | | didn't expect any arguments here | + = note: for more information, visit <https://doc.rust-lang.org/reference/macros-by-example.html#the-macro_use-attribute> help: try changing it to one of the following valid forms of the attribute | LL - #[macro_use(foo="bar")] diff --git a/tests/ui/issues/issue-25386.rs b/tests/ui/macros/private-struct-member-macro-access-25386.rs index b26cc77680d..88e5a22a699 100644 --- a/tests/ui/issues/issue-25386.rs +++ b/tests/ui/macros/private-struct-member-macro-access-25386.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/25386 mod stuff { pub struct Item { c_object: Box<CObj>, diff --git a/tests/ui/issues/issue-25386.stderr b/tests/ui/macros/private-struct-member-macro-access-25386.stderr index 720b77866a5..d02a41848f4 100644 --- a/tests/ui/issues/issue-25386.stderr +++ b/tests/ui/macros/private-struct-member-macro-access-25386.stderr @@ -1,5 +1,5 @@ error[E0616]: field `c_object` of struct `Item` is private - --> $DIR/issue-25386.rs:19:16 + --> $DIR/private-struct-member-macro-access-25386.rs:20:16 | LL | (*$var.c_object).$member.is_some() | ^^^^^^^^ private field diff --git a/tests/ui/malformed/malformed-regressions.rs b/tests/ui/malformed/malformed-regressions.rs index f0a7aac59c1..99f0fc904a9 100644 --- a/tests/ui/malformed/malformed-regressions.rs +++ b/tests/ui/malformed/malformed-regressions.rs @@ -4,9 +4,9 @@ //~^ WARN this was previously accepted #[inline = ""] //~ ERROR valid forms for the attribute are //~^ WARN this was previously accepted -#[link] //~ ERROR attribute must be of the form +#[link] //~ ERROR valid forms for the attribute are //~^ WARN this was previously accepted -#[link = ""] //~ ERROR attribute must be of the form +#[link = ""] //~ ERROR valid forms for the attribute are //~^ WARN this was previously accepted fn main() {} diff --git a/tests/ui/malformed/malformed-regressions.stderr b/tests/ui/malformed/malformed-regressions.stderr index 8c22919a1c2..4a00c9b4a7d 100644 --- a/tests/ui/malformed/malformed-regressions.stderr +++ b/tests/ui/malformed/malformed-regressions.stderr @@ -1,4 +1,4 @@ -error: valid forms for the attribute are `#[doc(hidden|inline|...)]` and `#[doc = "string"]` +error: valid forms for the attribute are `#[doc(hidden)]`, `#[doc(inline)]`, and `#[doc = "string"]` --> $DIR/malformed-regressions.rs:1:1 | LL | #[doc] @@ -6,9 +6,10 @@ LL | #[doc] | = 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 #57571 <https://github.com/rust-lang/rust/issues/57571> + = note: for more information, visit <https://doc.rust-lang.org/rustdoc/write-documentation/the-doc-attribute.html> = note: `#[deny(ill_formed_attribute_input)]` on by default -error: attribute must be of the form `#[link(name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ wasm_import_module = "...", /*opt*/ import_name_type = "decorated|noprefix|undecorated")]` +error: valid forms for the attribute are `#[link(name = "...")]`, `#[link(name = "...", kind = "dylib|static|...")]`, `#[link(name = "...", wasm_import_module = "...")]`, `#[link(name = "...", import_name_type = "decorated|noprefix|undecorated")]`, and `#[link(name = "...", kind = "dylib|static|...", wasm_import_module = "...", import_name_type = "decorated|noprefix|undecorated")]` --> $DIR/malformed-regressions.rs:7:1 | LL | #[link] @@ -16,8 +17,9 @@ LL | #[link] | = 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 #57571 <https://github.com/rust-lang/rust/issues/57571> + = note: for more information, visit <https://doc.rust-lang.org/reference/items/external-blocks.html#the-link-attribute> -error: attribute must be of the form `#[link(name = "...", /*opt*/ kind = "dylib|static|...", /*opt*/ wasm_import_module = "...", /*opt*/ import_name_type = "decorated|noprefix|undecorated")]` +error: valid forms for the attribute are `#[link(name = "...")]`, `#[link(name = "...", kind = "dylib|static|...")]`, `#[link(name = "...", wasm_import_module = "...")]`, `#[link(name = "...", import_name_type = "decorated|noprefix|undecorated")]`, and `#[link(name = "...", kind = "dylib|static|...", wasm_import_module = "...", import_name_type = "decorated|noprefix|undecorated")]` --> $DIR/malformed-regressions.rs:9:1 | LL | #[link = ""] @@ -25,6 +27,7 @@ LL | #[link = ""] | = 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 #57571 <https://github.com/rust-lang/rust/issues/57571> + = note: for more information, visit <https://doc.rust-lang.org/reference/items/external-blocks.html#the-link-attribute> error: valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]` --> $DIR/malformed-regressions.rs:3:1 @@ -35,7 +38,7 @@ LL | #[ignore()] = 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 #57571 <https://github.com/rust-lang/rust/issues/57571> -error: valid forms for the attribute are `#[inline(always|never)]` and `#[inline]` +error: valid forms for the attribute are `#[inline(always)]`, `#[inline(never)]`, and `#[inline]` --> $DIR/malformed-regressions.rs:5:1 | LL | #[inline = ""] @@ -46,3 +49,61 @@ LL | #[inline = ""] error: aborting due to 5 previous errors +Future incompatibility report: Future breakage diagnostic: +error: valid forms for the attribute are `#[doc(hidden)]`, `#[doc(inline)]`, and `#[doc = "string"]` + --> $DIR/malformed-regressions.rs:1:1 + | +LL | #[doc] + | ^^^^^^ + | + = 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 #57571 <https://github.com/rust-lang/rust/issues/57571> + = note: for more information, visit <https://doc.rust-lang.org/rustdoc/write-documentation/the-doc-attribute.html> + = note: `#[deny(ill_formed_attribute_input)]` on by default + +Future breakage diagnostic: +error: valid forms for the attribute are `#[link(name = "...")]`, `#[link(name = "...", kind = "dylib|static|...")]`, `#[link(name = "...", wasm_import_module = "...")]`, `#[link(name = "...", import_name_type = "decorated|noprefix|undecorated")]`, and `#[link(name = "...", kind = "dylib|static|...", wasm_import_module = "...", import_name_type = "decorated|noprefix|undecorated")]` + --> $DIR/malformed-regressions.rs:7:1 + | +LL | #[link] + | ^^^^^^^ + | + = 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 #57571 <https://github.com/rust-lang/rust/issues/57571> + = note: for more information, visit <https://doc.rust-lang.org/reference/items/external-blocks.html#the-link-attribute> + = note: `#[deny(ill_formed_attribute_input)]` on by default + +Future breakage diagnostic: +error: valid forms for the attribute are `#[link(name = "...")]`, `#[link(name = "...", kind = "dylib|static|...")]`, `#[link(name = "...", wasm_import_module = "...")]`, `#[link(name = "...", import_name_type = "decorated|noprefix|undecorated")]`, and `#[link(name = "...", kind = "dylib|static|...", wasm_import_module = "...", import_name_type = "decorated|noprefix|undecorated")]` + --> $DIR/malformed-regressions.rs:9:1 + | +LL | #[link = ""] + | ^^^^^^^^^^^^ + | + = 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 #57571 <https://github.com/rust-lang/rust/issues/57571> + = note: for more information, visit <https://doc.rust-lang.org/reference/items/external-blocks.html#the-link-attribute> + = note: `#[deny(ill_formed_attribute_input)]` on by default + +Future breakage diagnostic: +error: valid forms for the attribute are `#[ignore = "reason"]` and `#[ignore]` + --> $DIR/malformed-regressions.rs:3:1 + | +LL | #[ignore()] + | ^^^^^^^^^^^ + | + = 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 #57571 <https://github.com/rust-lang/rust/issues/57571> + = note: `#[deny(ill_formed_attribute_input)]` on by default + +Future breakage diagnostic: +error: valid forms for the attribute are `#[inline(always)]`, `#[inline(never)]`, and `#[inline]` + --> $DIR/malformed-regressions.rs:5:1 + | +LL | #[inline = ""] + | ^^^^^^^^^^^^^^ + | + = 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 #57571 <https://github.com/rust-lang/rust/issues/57571> + = note: `#[deny(ill_formed_attribute_input)]` on by default + diff --git a/tests/ui/issues/issue-92741.fixed b/tests/ui/mismatched_types/newlines-in-diagnostic-fix-suggestions-92741.fixed index cb37d25273f..c165779e402 100644 --- a/tests/ui/issues/issue-92741.fixed +++ b/tests/ui/mismatched_types/newlines-in-diagnostic-fix-suggestions-92741.fixed @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/92741 //@ run-rustfix fn main() {} fn _foo() -> bool { diff --git a/tests/ui/issues/issue-92741.rs b/tests/ui/mismatched_types/newlines-in-diagnostic-fix-suggestions-92741.rs index 1c5d5810a57..b3fa5f77308 100644 --- a/tests/ui/issues/issue-92741.rs +++ b/tests/ui/mismatched_types/newlines-in-diagnostic-fix-suggestions-92741.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/92741 //@ run-rustfix fn main() {} fn _foo() -> bool { diff --git a/tests/ui/issues/issue-92741.stderr b/tests/ui/mismatched_types/newlines-in-diagnostic-fix-suggestions-92741.stderr index 49315e7a8bf..60917d9a63e 100644 --- a/tests/ui/issues/issue-92741.stderr +++ b/tests/ui/mismatched_types/newlines-in-diagnostic-fix-suggestions-92741.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/issue-92741.rs:4:5 + --> $DIR/newlines-in-diagnostic-fix-suggestions-92741.rs:5:5 | LL | fn _foo() -> bool { | ---- expected `bool` because of return type @@ -15,7 +15,7 @@ LL - mut | error[E0308]: mismatched types - --> $DIR/issue-92741.rs:10:5 + --> $DIR/newlines-in-diagnostic-fix-suggestions-92741.rs:11:5 | LL | fn _bar() -> bool { | ---- expected `bool` because of return type @@ -31,7 +31,7 @@ LL + if true { true } else { false } | error[E0308]: mismatched types - --> $DIR/issue-92741.rs:15:5 + --> $DIR/newlines-in-diagnostic-fix-suggestions-92741.rs:16:5 | LL | fn _baz() -> bool { | ---- expected `bool` because of return type diff --git a/tests/ui/modules/path-invalid-form.stderr b/tests/ui/modules/path-invalid-form.stderr index e8ded1343f7..4e9a62fa7a9 100644 --- a/tests/ui/modules/path-invalid-form.stderr +++ b/tests/ui/modules/path-invalid-form.stderr @@ -3,6 +3,8 @@ error: malformed `path` attribute input | LL | #[path = 123] | ^^^^^^^^^^^^^ help: must be of the form: `#[path = "file"]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/items/modules.html#the-path-attribute> error: aborting due to 1 previous error diff --git a/tests/ui/modules/path-macro.stderr b/tests/ui/modules/path-macro.stderr index eb02c721edd..fd93871f3a6 100644 --- a/tests/ui/modules/path-macro.stderr +++ b/tests/ui/modules/path-macro.stderr @@ -3,6 +3,8 @@ error: malformed `path` attribute input | LL | #[path = foo!()] | ^^^^^^^^^^^^^^^^ help: must be of the form: `#[path = "file"]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/items/modules.html#the-path-attribute> error: aborting due to 1 previous error diff --git a/tests/ui/issues/issue-15571.rs b/tests/ui/moves/match-move-same-binding-15571.rs index cf17113a282..f6d79c6d76c 100644 --- a/tests/ui/issues/issue-15571.rs +++ b/tests/ui/moves/match-move-same-binding-15571.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15571 + //@ run-pass fn match_on_local() { diff --git a/tests/ui/moves/moves-based-on-type-move-out-of-closure-env-issue-1965.stderr b/tests/ui/moves/moves-based-on-type-move-out-of-closure-env-issue-1965.stderr index 51d0f85c031..dfc983bf487 100644 --- a/tests/ui/moves/moves-based-on-type-move-out-of-closure-env-issue-1965.stderr +++ b/tests/ui/moves/moves-based-on-type-move-out-of-closure-env-issue-1965.stderr @@ -10,6 +10,11 @@ LL | let _f = to_fn(|| test(i)); | | | captured by this `Fn` closure | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/moves-based-on-type-move-out-of-closure-env-issue-1965.rs:3:33 + | +LL | fn to_fn<A:std::marker::Tuple,F:Fn<A>>(f: F) -> F { f } + | ^^^^^ help: consider cloning the value if the performance cost is acceptable | LL | let _f = to_fn(|| test(i.clone())); diff --git a/tests/ui/moves/use-correct-generic-args-in-borrow-suggest.rs b/tests/ui/moves/use-correct-generic-args-in-borrow-suggest.rs new file mode 100644 index 00000000000..0fb0cee2013 --- /dev/null +++ b/tests/ui/moves/use-correct-generic-args-in-borrow-suggest.rs @@ -0,0 +1,13 @@ +//! Regression test for #145164: For normal calls, make sure the suggestion to borrow generic inputs +//! uses the generic args from the callee's type rather than those attached to the callee's HIR +//! node. In cases where the callee isn't an identifier expression, its HIR node won't have its +//! generic arguments attached, which could lead to ICE when it had other generic args. In this +//! case, the callee expression is `run.clone()`, to which `clone`'s generic arguments are attached. + +fn main() { + let value = String::new(); + run.clone()(value, ()); + run(value, ()); + //~^ ERROR use of moved value: `value` +} +fn run<F, T: Clone>(value: T, f: F) {} diff --git a/tests/ui/moves/use-correct-generic-args-in-borrow-suggest.stderr b/tests/ui/moves/use-correct-generic-args-in-borrow-suggest.stderr new file mode 100644 index 00000000000..8c29bfbd290 --- /dev/null +++ b/tests/ui/moves/use-correct-generic-args-in-borrow-suggest.stderr @@ -0,0 +1,18 @@ +error[E0382]: use of moved value: `value` + --> $DIR/use-correct-generic-args-in-borrow-suggest.rs:10:9 + | +LL | let value = String::new(); + | ----- move occurs because `value` has type `String`, which does not implement the `Copy` trait +LL | run.clone()(value, ()); + | ----- value moved here +LL | run(value, ()); + | ^^^^^ value used here after move + | +help: consider borrowing `value` + | +LL | run.clone()(&value, ()); + | + + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0382`. diff --git a/tests/ui/issues/issue-15207.rs b/tests/ui/never/never-type-method-call-15207.rs index 356e55ac912..69cdeeabb7c 100644 --- a/tests/ui/issues/issue-15207.rs +++ b/tests/ui/never/never-type-method-call-15207.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15207 + fn main() { loop { break.push(1) //~ ERROR no method named `push` found for type `!` diff --git a/tests/ui/issues/issue-15207.stderr b/tests/ui/never/never-type-method-call-15207.stderr index a1047e27ba2..265e7c8611d 100644 --- a/tests/ui/issues/issue-15207.stderr +++ b/tests/ui/never/never-type-method-call-15207.stderr @@ -1,5 +1,5 @@ error[E0599]: no method named `push` found for type `!` in the current scope - --> $DIR/issue-15207.rs:3:15 + --> $DIR/never-type-method-call-15207.rs:5:15 | LL | break.push(1) | ^^^^ method not found in `!` diff --git a/tests/ui/nll/issue-46589.nll.stderr b/tests/ui/nll/issue-46589.nll.stderr index dc80c1d08de..f2d08d1f4c8 100644 --- a/tests/ui/nll/issue-46589.nll.stderr +++ b/tests/ui/nll/issue-46589.nll.stderr @@ -1,5 +1,5 @@ error[E0499]: cannot borrow `**other` as mutable more than once at a time - --> $DIR/issue-46589.rs:24:21 + --> $DIR/issue-46589.rs:25:21 | LL | *other = match (*other).get_self() { | -------- first mutable borrow occurs here diff --git a/tests/ui/nll/issue-46589.polonius.stderr b/tests/ui/nll/issue-46589.polonius.stderr new file mode 100644 index 00000000000..f2d08d1f4c8 --- /dev/null +++ b/tests/ui/nll/issue-46589.polonius.stderr @@ -0,0 +1,15 @@ +error[E0499]: cannot borrow `**other` as mutable more than once at a time + --> $DIR/issue-46589.rs:25:21 + | +LL | *other = match (*other).get_self() { + | -------- first mutable borrow occurs here +LL | Some(s) => s, +LL | None => (*other).new_self() + | ^^^^^^^^ + | | + | second mutable borrow occurs here + | first borrow later used here + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0499`. diff --git a/tests/ui/nll/issue-46589.rs b/tests/ui/nll/issue-46589.rs index 10aff0d7b4e..9a23f61b8cb 100644 --- a/tests/ui/nll/issue-46589.rs +++ b/tests/ui/nll/issue-46589.rs @@ -1,9 +1,10 @@ //@ ignore-compare-mode-polonius (explicit revisions) -//@ revisions: nll polonius_next polonius -//@ [polonius_next] check-pass -//@ [polonius_next] compile-flags: -Zpolonius=next -//@ [polonius] check-pass -//@ [polonius] compile-flags: -Zpolonius +//@ revisions: nll polonius legacy +//@ [nll] known-bug: #46589 +//@ [polonius] known-bug: #46589 +//@ [polonius] compile-flags: -Zpolonius=next +//@ [legacy] check-pass +//@ [legacy] compile-flags: -Zpolonius=legacy struct Foo; @@ -22,7 +23,6 @@ impl Foo { *other = match (*other).get_self() { Some(s) => s, None => (*other).new_self() - //[nll]~^ ERROR cannot borrow `**other` as mutable more than once at a time [E0499] }; let c = other; diff --git a/tests/ui/nll/issue-52663-span-decl-captured-variable.stderr b/tests/ui/nll/issue-52663-span-decl-captured-variable.stderr index 57546037006..7f9a8e50dae 100644 --- a/tests/ui/nll/issue-52663-span-decl-captured-variable.stderr +++ b/tests/ui/nll/issue-52663-span-decl-captured-variable.stderr @@ -10,6 +10,11 @@ LL | expect_fn(|| drop(x.0)); | | | captured by this `Fn` closure | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/issue-52663-span-decl-captured-variable.rs:1:33 + | +LL | fn expect_fn<F>(f: F) where F : Fn() { + | ^^^^ help: consider cloning the value if the performance cost is acceptable | LL | expect_fn(|| drop(x.0.clone())); diff --git a/tests/ui/nll/polonius/array-literal-index-oob-2024.rs b/tests/ui/nll/polonius/array-literal-index-oob-2024.rs new file mode 100644 index 00000000000..2054a32e535 --- /dev/null +++ b/tests/ui/nll/polonius/array-literal-index-oob-2024.rs @@ -0,0 +1,12 @@ +// This test used to ICE under `-Zpolonius=next` when computing loan liveness +// and taking kills into account during reachability traversal of the localized +// constraint graph. Originally from another test but on edition 2024, as +// seen in issue #135646. + +//@ compile-flags: -Zpolonius=next +//@ edition: 2024 +//@ check-pass + +fn main() { + &{ [1, 2, 3][4] }; +} diff --git a/tests/ui/nll/polonius/flow-sensitive-invariance.nll.stderr b/tests/ui/nll/polonius/flow-sensitive-invariance.nll.stderr new file mode 100644 index 00000000000..5756148f4eb --- /dev/null +++ b/tests/ui/nll/polonius/flow-sensitive-invariance.nll.stderr @@ -0,0 +1,36 @@ +error: lifetime may not live long enough + --> $DIR/flow-sensitive-invariance.rs:20:17 + | +LL | fn use_it<'a, 'b>(choice: bool) -> Result<Invariant<'a>, Invariant<'b>> { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | let returned_value = create_invariant(); +LL | if choice { Ok(returned_value) } else { Err(returned_value) } + | ^^^^^^^^^^^^^^^^^^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b` + | + = help: consider adding the following bound: `'b: 'a` + = note: requirement occurs because of the type `Invariant<'_>`, which makes the generic argument `'_` invariant + = note: the struct `Invariant<'l>` is invariant over the parameter `'l` + = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance + +error: lifetime may not live long enough + --> $DIR/flow-sensitive-invariance.rs:20:45 + | +LL | fn use_it<'a, 'b>(choice: bool) -> Result<Invariant<'a>, Invariant<'b>> { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | let returned_value = create_invariant(); +LL | if choice { Ok(returned_value) } else { Err(returned_value) } + | ^^^^^^^^^^^^^^^^^^^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a` + | + = help: consider adding the following bound: `'a: 'b` + = note: requirement occurs because of the type `Invariant<'_>`, which makes the generic argument `'_` invariant + = note: the struct `Invariant<'l>` is invariant over the parameter `'l` + = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance + +help: `'a` and `'b` must be the same: replace one with the other + +error: aborting due to 2 previous errors + diff --git a/tests/ui/nll/polonius/flow-sensitive-invariance.polonius.stderr b/tests/ui/nll/polonius/flow-sensitive-invariance.polonius.stderr new file mode 100644 index 00000000000..5756148f4eb --- /dev/null +++ b/tests/ui/nll/polonius/flow-sensitive-invariance.polonius.stderr @@ -0,0 +1,36 @@ +error: lifetime may not live long enough + --> $DIR/flow-sensitive-invariance.rs:20:17 + | +LL | fn use_it<'a, 'b>(choice: bool) -> Result<Invariant<'a>, Invariant<'b>> { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | let returned_value = create_invariant(); +LL | if choice { Ok(returned_value) } else { Err(returned_value) } + | ^^^^^^^^^^^^^^^^^^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b` + | + = help: consider adding the following bound: `'b: 'a` + = note: requirement occurs because of the type `Invariant<'_>`, which makes the generic argument `'_` invariant + = note: the struct `Invariant<'l>` is invariant over the parameter `'l` + = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance + +error: lifetime may not live long enough + --> $DIR/flow-sensitive-invariance.rs:20:45 + | +LL | fn use_it<'a, 'b>(choice: bool) -> Result<Invariant<'a>, Invariant<'b>> { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | let returned_value = create_invariant(); +LL | if choice { Ok(returned_value) } else { Err(returned_value) } + | ^^^^^^^^^^^^^^^^^^^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a` + | + = help: consider adding the following bound: `'a: 'b` + = note: requirement occurs because of the type `Invariant<'_>`, which makes the generic argument `'_` invariant + = note: the struct `Invariant<'l>` is invariant over the parameter `'l` + = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance + +help: `'a` and `'b` must be the same: replace one with the other + +error: aborting due to 2 previous errors + diff --git a/tests/ui/nll/polonius/flow-sensitive-invariance.rs b/tests/ui/nll/polonius/flow-sensitive-invariance.rs new file mode 100644 index 00000000000..c5571f131da --- /dev/null +++ b/tests/ui/nll/polonius/flow-sensitive-invariance.rs @@ -0,0 +1,34 @@ +// An example (from @steffahn) of reachability as an approximation of liveness where the polonius +// alpha analysis shows the same imprecision as NLLs, unlike the datalog implementation. + +//@ ignore-compare-mode-polonius (explicit revisions) +//@ revisions: nll polonius legacy +//@ [polonius] compile-flags: -Z polonius=next +//@ [legacy] check-pass +//@ [legacy] compile-flags: -Z polonius=legacy + +use std::cell::Cell; + +struct Invariant<'l>(Cell<&'l ()>); + +fn create_invariant<'l>() -> Invariant<'l> { + Invariant(Cell::new(&())) +} + +fn use_it<'a, 'b>(choice: bool) -> Result<Invariant<'a>, Invariant<'b>> { + let returned_value = create_invariant(); + if choice { Ok(returned_value) } else { Err(returned_value) } + //[nll]~^ ERROR lifetime may not live long enough + //[nll]~| ERROR lifetime may not live long enough + //[polonius]~^^^ ERROR lifetime may not live long enough + //[polonius]~| ERROR lifetime may not live long enough +} + +fn use_it_but_its_the_same_region<'a: 'b, 'b: 'a>( + choice: bool, +) -> Result<Invariant<'a>, Invariant<'b>> { + let returned_value = create_invariant(); + if choice { Ok(returned_value) } else { Err(returned_value) } +} + +fn main() {} diff --git a/tests/ui/nll/polonius/iterating-updating-cursor-issue-108704.nll.stderr b/tests/ui/nll/polonius/iterating-updating-cursor-issue-108704.nll.stderr index 7ac4e5de283..b768f60590c 100644 --- a/tests/ui/nll/polonius/iterating-updating-cursor-issue-108704.nll.stderr +++ b/tests/ui/nll/polonius/iterating-updating-cursor-issue-108704.nll.stderr @@ -1,5 +1,5 @@ error[E0499]: cannot borrow `*elements` as mutable more than once at a time - --> $DIR/iterating-updating-cursor-issue-108704.rs:40:26 + --> $DIR/iterating-updating-cursor-issue-108704.rs:41:26 | LL | for (idx, el) in elements.iter_mut().enumerate() { | ^^^^^^^^ diff --git a/tests/ui/nll/polonius/iterating-updating-cursor-issue-108704.polonius.stderr b/tests/ui/nll/polonius/iterating-updating-cursor-issue-108704.polonius.stderr new file mode 100644 index 00000000000..b768f60590c --- /dev/null +++ b/tests/ui/nll/polonius/iterating-updating-cursor-issue-108704.polonius.stderr @@ -0,0 +1,12 @@ +error[E0499]: cannot borrow `*elements` as mutable more than once at a time + --> $DIR/iterating-updating-cursor-issue-108704.rs:41:26 + | +LL | for (idx, el) in elements.iter_mut().enumerate() { + | ^^^^^^^^ + | | + | `*elements` was mutably borrowed here in the previous iteration of the loop + | first borrow used here, in later iteration of loop + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0499`. diff --git a/tests/ui/nll/polonius/iterating-updating-cursor-issue-108704.rs b/tests/ui/nll/polonius/iterating-updating-cursor-issue-108704.rs index 420cb73bed2..673efa8f225 100644 --- a/tests/ui/nll/polonius/iterating-updating-cursor-issue-108704.rs +++ b/tests/ui/nll/polonius/iterating-updating-cursor-issue-108704.rs @@ -1,11 +1,12 @@ #![crate_type = "lib"] -// An example from #108704 of the linked-list cursor-like pattern of #46859/#48001. +// An example from #108704 of the linked-list cursor-like pattern of #46859/#48001, where the +// polonius alpha analysis shows the same imprecision as NLLs, unlike the datalog implementation. //@ ignore-compare-mode-polonius (explicit revisions) //@ revisions: nll polonius legacy //@ [nll] known-bug: #108704 -//@ [polonius] check-pass +//@ [polonius] known-bug: #108704 //@ [polonius] compile-flags: -Z polonius=next //@ [legacy] check-pass //@ [legacy] compile-flags: -Z polonius=legacy @@ -32,7 +33,7 @@ fn merge_tree_ok(root: &mut Root, path: Vec<String>) { } } -// NLLs fail here +// NLLs and polonius alpha fail here fn merge_tree_ko(root: &mut Root, path: Vec<String>) { let mut elements = &mut root.children; diff --git a/tests/ui/nll/polonius/iterating-updating-cursor-issue-57165.nll.stderr b/tests/ui/nll/polonius/iterating-updating-cursor-issue-57165.nll.stderr index 14e1726e158..34b04e707db 100644 --- a/tests/ui/nll/polonius/iterating-updating-cursor-issue-57165.nll.stderr +++ b/tests/ui/nll/polonius/iterating-updating-cursor-issue-57165.nll.stderr @@ -1,5 +1,5 @@ error[E0499]: cannot borrow `p.0` as mutable more than once at a time - --> $DIR/iterating-updating-cursor-issue-57165.rs:29:20 + --> $DIR/iterating-updating-cursor-issue-57165.rs:30:20 | LL | while let Some(now) = p { | ^^^ - first borrow used here, in later iteration of loop @@ -7,7 +7,7 @@ LL | while let Some(now) = p { | `p.0` was mutably borrowed here in the previous iteration of the loop error[E0503]: cannot use `*p` because it was mutably borrowed - --> $DIR/iterating-updating-cursor-issue-57165.rs:29:27 + --> $DIR/iterating-updating-cursor-issue-57165.rs:30:27 | LL | while let Some(now) = p { | --- ^ diff --git a/tests/ui/nll/polonius/iterating-updating-cursor-issue-57165.polonius.stderr b/tests/ui/nll/polonius/iterating-updating-cursor-issue-57165.polonius.stderr new file mode 100644 index 00000000000..34b04e707db --- /dev/null +++ b/tests/ui/nll/polonius/iterating-updating-cursor-issue-57165.polonius.stderr @@ -0,0 +1,22 @@ +error[E0499]: cannot borrow `p.0` as mutable more than once at a time + --> $DIR/iterating-updating-cursor-issue-57165.rs:30:20 + | +LL | while let Some(now) = p { + | ^^^ - first borrow used here, in later iteration of loop + | | + | `p.0` was mutably borrowed here in the previous iteration of the loop + +error[E0503]: cannot use `*p` because it was mutably borrowed + --> $DIR/iterating-updating-cursor-issue-57165.rs:30:27 + | +LL | while let Some(now) = p { + | --- ^ + | | | + | | use of borrowed `p.0` + | | borrow later used here + | `p.0` is borrowed here + +error: aborting due to 2 previous errors + +Some errors have detailed explanations: E0499, E0503. +For more information about an error, try `rustc --explain E0499`. diff --git a/tests/ui/nll/polonius/iterating-updating-cursor-issue-57165.rs b/tests/ui/nll/polonius/iterating-updating-cursor-issue-57165.rs index 63ec89146d4..9670fc77e6f 100644 --- a/tests/ui/nll/polonius/iterating-updating-cursor-issue-57165.rs +++ b/tests/ui/nll/polonius/iterating-updating-cursor-issue-57165.rs @@ -1,11 +1,12 @@ #![crate_type = "lib"] -// An example from #57165 of the linked-list cursor-like pattern of #46859/#48001. +// An example from #57165 of the linked-list cursor-like pattern of #46859/#48001, where the +// polonius alpha analysis shows the same imprecision as NLLs, unlike the datalog implementation. //@ ignore-compare-mode-polonius (explicit revisions) //@ revisions: nll polonius legacy //@ [nll] known-bug: #57165 -//@ [polonius] check-pass +//@ [polonius] known-bug: #57165 //@ [polonius] compile-flags: -Z polonius=next //@ [legacy] check-pass //@ [legacy] compile-flags: -Z polonius=legacy @@ -22,7 +23,7 @@ fn no_control_flow() { } } -// NLLs fail here +// NLLs and polonius alpha fail here fn conditional() { let mut b = Some(Box::new(X { next: None })); let mut p = &mut b; diff --git a/tests/ui/nll/polonius/iterating-updating-cursor-issue-63908.nll.stderr b/tests/ui/nll/polonius/iterating-updating-cursor-issue-63908.nll.stderr index bf38da566c6..b76e4ff6398 100644 --- a/tests/ui/nll/polonius/iterating-updating-cursor-issue-63908.nll.stderr +++ b/tests/ui/nll/polonius/iterating-updating-cursor-issue-63908.nll.stderr @@ -1,5 +1,5 @@ error[E0506]: cannot assign to `*node_ref` because it is borrowed - --> $DIR/iterating-updating-cursor-issue-63908.rs:42:5 + --> $DIR/iterating-updating-cursor-issue-63908.rs:43:5 | LL | fn remove_last_node_iterative<T>(mut node_ref: &mut List<T>) { | - let's call the lifetime of this reference `'1` diff --git a/tests/ui/nll/polonius/iterating-updating-cursor-issue-63908.polonius.stderr b/tests/ui/nll/polonius/iterating-updating-cursor-issue-63908.polonius.stderr new file mode 100644 index 00000000000..b76e4ff6398 --- /dev/null +++ b/tests/ui/nll/polonius/iterating-updating-cursor-issue-63908.polonius.stderr @@ -0,0 +1,18 @@ +error[E0506]: cannot assign to `*node_ref` because it is borrowed + --> $DIR/iterating-updating-cursor-issue-63908.rs:43:5 + | +LL | fn remove_last_node_iterative<T>(mut node_ref: &mut List<T>) { + | - let's call the lifetime of this reference `'1` +LL | loop { +LL | let next_ref = &mut node_ref.as_mut().unwrap().next; + | -------- `*node_ref` is borrowed here +... +LL | node_ref = next_ref; + | ------------------- assignment requires that `*node_ref` is borrowed for `'1` +... +LL | *node_ref = None; + | ^^^^^^^^^ `*node_ref` is assigned to here but it was already borrowed + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0506`. diff --git a/tests/ui/nll/polonius/iterating-updating-cursor-issue-63908.rs b/tests/ui/nll/polonius/iterating-updating-cursor-issue-63908.rs index 00e48b65fed..6682926c523 100644 --- a/tests/ui/nll/polonius/iterating-updating-cursor-issue-63908.rs +++ b/tests/ui/nll/polonius/iterating-updating-cursor-issue-63908.rs @@ -1,11 +1,12 @@ #![crate_type = "lib"] -// An example from #63908 of the linked-list cursor-like pattern of #46859/#48001. +// An example from #63908 of the linked-list cursor-like pattern of #46859/#48001, where the +// polonius alpha analysis shows the same imprecision as NLLs, unlike the datalog implementation. //@ ignore-compare-mode-polonius (explicit revisions) //@ revisions: nll polonius legacy //@ [nll] known-bug: #63908 -//@ [polonius] check-pass +//@ [polonius] known-bug: #63908 //@ [polonius] compile-flags: -Z polonius=next //@ [legacy] check-pass //@ [legacy] compile-flags: -Z polonius=legacy @@ -27,7 +28,7 @@ fn remove_last_node_recursive<T>(node_ref: &mut List<T>) { } } -// NLLs fail here +// NLLs and polonius alpha fail here fn remove_last_node_iterative<T>(mut node_ref: &mut List<T>) { loop { let next_ref = &mut node_ref.as_mut().unwrap().next; diff --git a/tests/ui/nll/polonius/iterating-updating-mutref.nll.stderr b/tests/ui/nll/polonius/iterating-updating-mutref.nll.stderr new file mode 100644 index 00000000000..941c736d8d2 --- /dev/null +++ b/tests/ui/nll/polonius/iterating-updating-mutref.nll.stderr @@ -0,0 +1,15 @@ +error[E0499]: cannot borrow `self.buf_read` as mutable more than once at a time + --> $DIR/iterating-updating-mutref.rs:61:23 + | +LL | pub fn next<'a>(&'a mut self) -> &'a str { + | -- lifetime `'a` defined here +LL | loop { +LL | let buf = self.buf_read.fill_buf(); + | ^^^^^^^^^^^^^ `self.buf_read` was mutably borrowed here in the previous iteration of the loop +LL | if let Some(s) = decode(buf) { +LL | return s; + | - returning this value requires that `self.buf_read` is borrowed for `'a` + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0499`. diff --git a/tests/ui/nll/polonius/iterating-updating-mutref.rs b/tests/ui/nll/polonius/iterating-updating-mutref.rs new file mode 100644 index 00000000000..a315bf66279 --- /dev/null +++ b/tests/ui/nll/polonius/iterating-updating-mutref.rs @@ -0,0 +1,87 @@ +// These are some examples of iterating through and updating a mutable ref, similar in spirit to the +// linked-list-like pattern of #46859/#48001 where the polonius alpha analysis shows imprecision, +// unlike the datalog implementation. +// +// They differ in that after the loans prior to the loop are either not live after the loop, or with +// control flow and outlives relationships that are simple enough for the reachability +// approximation. They're thus accepted by the alpha analysis, like NLLs did for the simplest cases +// of flow-sensitivity. + +//@ ignore-compare-mode-polonius (explicit revisions) +//@ revisions: nll polonius legacy +//@ [nll] known-bug: #46859 +//@ [polonius] check-pass +//@ [polonius] compile-flags: -Z polonius=next +//@ [legacy] check-pass +//@ [legacy] compile-flags: -Z polonius=legacy + +// The #46859 OP +struct List<T> { + value: T, + next: Option<Box<List<T>>>, +} + +fn to_refs<T>(mut list: &mut List<T>) -> Vec<&mut T> { + let mut result = vec![]; + loop { + result.push(&mut list.value); + if let Some(n) = list.next.as_mut() { + list = n; + } else { + return result; + } + } +} + +// A similar construction, where paths in the constraint graph are also clearly terminating, so it's +// fine even for NLLs. +fn to_refs2<T>(mut list: &mut List<T>) -> Vec<&mut T> { + let mut result = vec![]; + loop { + result.push(&mut list.value); + if let Some(n) = list.next.as_mut() { + list = n; + } else { + break; + } + } + + result +} + +// Another MCVE from the same issue, but was rejected by NLLs. +pub struct Decoder { + buf_read: BufRead, +} + +impl Decoder { + // NLLs fail here + pub fn next<'a>(&'a mut self) -> &'a str { + loop { + let buf = self.buf_read.fill_buf(); + if let Some(s) = decode(buf) { + return s; + } + // loop to get more input data + + // At this point `buf` is not used anymore. + // With NLL I would expect the borrow to end here, + // such that `self.buf_read` is not borrowed anymore + // by the time we start the next loop iteration. + } + } +} + +struct BufRead; + +impl BufRead { + fn fill_buf(&mut self) -> &[u8] { + unimplemented!() + } +} + +fn decode(_: &[u8]) -> Option<&str> { + unimplemented!() +} + +fn main() {} diff --git a/tests/ui/nll/polonius/lending-iterator-sanity-checks.legacy.stderr b/tests/ui/nll/polonius/lending-iterator-sanity-checks.legacy.stderr new file mode 100644 index 00000000000..fa201b89048 --- /dev/null +++ b/tests/ui/nll/polonius/lending-iterator-sanity-checks.legacy.stderr @@ -0,0 +1,28 @@ +error[E0499]: cannot borrow `*t` as mutable more than once at a time + --> $DIR/lending-iterator-sanity-checks.rs:19:19 + | +LL | fn use_live<T: LendingIterator>(t: &mut T) -> Option<(T::Item<'_>, T::Item<'_>)> { + | - let's call the lifetime of this reference `'1` +LL | let Some(i) = t.next() else { return None }; + | - first mutable borrow occurs here +LL | let Some(j) = t.next() else { return None }; + | ^ second mutable borrow occurs here +... +LL | Some((i, j)) + | ------------ returning this value requires that `*t` is borrowed for `'1` + +error[E0499]: cannot borrow `*t` as mutable more than once at a time + --> $DIR/lending-iterator-sanity-checks.rs:31:13 + | +LL | let i = t.next(); + | - first mutable borrow occurs here +... +LL | let j = t.next(); + | ^ second mutable borrow occurs here +LL | +LL | } + | - first borrow might be used here, when `i` is dropped and runs the destructor for type `Option<<T as LendingIterator>::Item<'_>>` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0499`. diff --git a/tests/ui/nll/polonius/lending-iterator-sanity-checks.nll.stderr b/tests/ui/nll/polonius/lending-iterator-sanity-checks.nll.stderr new file mode 100644 index 00000000000..fa201b89048 --- /dev/null +++ b/tests/ui/nll/polonius/lending-iterator-sanity-checks.nll.stderr @@ -0,0 +1,28 @@ +error[E0499]: cannot borrow `*t` as mutable more than once at a time + --> $DIR/lending-iterator-sanity-checks.rs:19:19 + | +LL | fn use_live<T: LendingIterator>(t: &mut T) -> Option<(T::Item<'_>, T::Item<'_>)> { + | - let's call the lifetime of this reference `'1` +LL | let Some(i) = t.next() else { return None }; + | - first mutable borrow occurs here +LL | let Some(j) = t.next() else { return None }; + | ^ second mutable borrow occurs here +... +LL | Some((i, j)) + | ------------ returning this value requires that `*t` is borrowed for `'1` + +error[E0499]: cannot borrow `*t` as mutable more than once at a time + --> $DIR/lending-iterator-sanity-checks.rs:31:13 + | +LL | let i = t.next(); + | - first mutable borrow occurs here +... +LL | let j = t.next(); + | ^ second mutable borrow occurs here +LL | +LL | } + | - first borrow might be used here, when `i` is dropped and runs the destructor for type `Option<<T as LendingIterator>::Item<'_>>` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0499`. diff --git a/tests/ui/nll/polonius/lending-iterator-sanity-checks.polonius.stderr b/tests/ui/nll/polonius/lending-iterator-sanity-checks.polonius.stderr new file mode 100644 index 00000000000..bf8546b63bf --- /dev/null +++ b/tests/ui/nll/polonius/lending-iterator-sanity-checks.polonius.stderr @@ -0,0 +1,26 @@ +error[E0499]: cannot borrow `*t` as mutable more than once at a time + --> $DIR/lending-iterator-sanity-checks.rs:19:19 + | +LL | let Some(i) = t.next() else { return None }; + | - first mutable borrow occurs here +LL | let Some(j) = t.next() else { return None }; + | ^ second mutable borrow occurs here +... +LL | } + | - first borrow might be used here, when `i` is dropped and runs the destructor for type `<T as LendingIterator>::Item<'_>` + +error[E0499]: cannot borrow `*t` as mutable more than once at a time + --> $DIR/lending-iterator-sanity-checks.rs:31:13 + | +LL | let i = t.next(); + | - first mutable borrow occurs here +... +LL | let j = t.next(); + | ^ second mutable borrow occurs here +LL | +LL | } + | - first borrow might be used here, when `i` is dropped and runs the destructor for type `Option<<T as LendingIterator>::Item<'_>>` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0499`. diff --git a/tests/ui/nll/polonius/lending-iterator-sanity-checks.rs b/tests/ui/nll/polonius/lending-iterator-sanity-checks.rs new file mode 100644 index 00000000000..ae8cc78957f --- /dev/null +++ b/tests/ui/nll/polonius/lending-iterator-sanity-checks.rs @@ -0,0 +1,71 @@ +// Some sanity checks for lending iterators with GATs. This is just some non-regression tests +// ensuring the polonius alpha analysis, the datalog implementation, and NLLs agree in these common +// cases of overlapping yielded items. + +//@ ignore-compare-mode-polonius (explicit revisions) +//@ revisions: nll polonius legacy +//@ [polonius] compile-flags: -Z polonius=next +//@ [legacy] compile-flags: -Z polonius=legacy + +trait LendingIterator { + type Item<'a> + where + Self: 'a; + fn next(&mut self) -> Option<Self::Item<'_>>; +} + +fn use_live<T: LendingIterator>(t: &mut T) -> Option<(T::Item<'_>, T::Item<'_>)> { + let Some(i) = t.next() else { return None }; + let Some(j) = t.next() else { return None }; + //~^ ERROR cannot borrow `*t` as mutable more than once at a time + + // `i` is obviously still (use-)live here, but we called `next` again to get `j`. + Some((i, j)) +} + +fn drop_live<T: LendingIterator>(t: &mut T) { + let i = t.next(); + + // Now `i` is use-dead here, but we don't know if the iterator items have a `Drop` impl, so it's + // still drop-live. + let j = t.next(); + //~^ ERROR cannot borrow `*t` as mutable more than once at a time +} + +// But we can still manually serialize the lifetimes with scopes (or preventing the destructor from +// being called), so they're not overlapping. +fn manually_non_overlapping<T: LendingIterator>(t: &mut T) { + { + let i = t.next(); + } + + let j = t.next(); // i is dead + + drop(j); + let k = t.next(); // j is dead + + let k = std::mem::ManuallyDrop::new(k); + let l = t.next(); // we told the compiler that k is not drop-live +} + +// The cfg below is because there's a diagnostic ICE trying to explain the source of the error when +// using the datalog implementation. We're not fixing *that*, outside of removing the implementation +// in the future. +#[cfg(not(legacy))] // FIXME: remove this cfg when removing the datalog implementation +fn items_have_no_borrows<T: LendingIterator>(t: &mut T) +where + for<'a> T::Item<'a>: 'static, +{ + let i = t.next(); + let j = t.next(); +} + +fn items_are_copy<T: LendingIterator>(t: &mut T) +where + for<'a> T::Item<'a>: Copy, +{ + let i = t.next(); + let j = t.next(); +} + +fn main() {} diff --git a/tests/ui/issues/issue-99838.rs b/tests/ui/packed/misaligned-reference-drop-field-99838.rs index 687b47fbe71..58e168162cb 100644 --- a/tests/ui/issues/issue-99838.rs +++ b/tests/ui/packed/misaligned-reference-drop-field-99838.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/99838 //@ run-pass use std::hint; diff --git a/tests/ui/parser/bad-lit-suffixes.stderr b/tests/ui/parser/bad-lit-suffixes.stderr index 7876d75c5a4..9a51cf70960 100644 --- a/tests/ui/parser/bad-lit-suffixes.stderr +++ b/tests/ui/parser/bad-lit-suffixes.stderr @@ -158,6 +158,7 @@ LL | #[must_use = "string"suffix] | | | expected a string literal here | + = note: for more information, visit <https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute> help: try changing it to one of the following valid forms of the attribute | LL - #[must_use = "string"suffix] diff --git a/tests/ui/parser/default-on-wrong-item-kind.rs b/tests/ui/parser/default-on-wrong-item-kind.rs index da990a4b421..9de85640565 100644 --- a/tests/ui/parser/default-on-wrong-item-kind.rs +++ b/tests/ui/parser/default-on-wrong-item-kind.rs @@ -19,7 +19,7 @@ mod free_items { default union foo {} //~ ERROR a union cannot be `default` default trait foo {} //~ ERROR a trait cannot be `default` default trait foo = Ord; //~ ERROR a trait alias cannot be `default` - default impl foo {} + default impl foo {} //~ ERROR inherent impls cannot be default default!(); default::foo::bar!(); default default!(); //~ ERROR an item macro invocation cannot be `default` @@ -53,7 +53,7 @@ extern "C" { //~^ ERROR trait is not supported in `extern` blocks default trait foo = Ord; //~ ERROR a trait alias cannot be `default` //~^ ERROR trait alias is not supported in `extern` blocks - default impl foo {} + default impl foo {} //~ ERROR inherent impls cannot be default //~^ ERROR implementation is not supported in `extern` blocks default!(); default::foo::bar!(); @@ -90,7 +90,7 @@ impl S { //~^ ERROR trait is not supported in `trait`s or `impl`s default trait foo = Ord; //~ ERROR a trait alias cannot be `default` //~^ ERROR trait alias is not supported in `trait`s or `impl`s - default impl foo {} + default impl foo {} //~ ERROR inherent impls cannot be default //~^ ERROR implementation is not supported in `trait`s or `impl`s default!(); default::foo::bar!(); @@ -127,7 +127,7 @@ trait T { //~^ ERROR trait is not supported in `trait`s or `impl`s default trait foo = Ord; //~ ERROR a trait alias cannot be `default` //~^ ERROR trait alias is not supported in `trait`s or `impl`s - default impl foo {} + default impl foo {} //~ ERROR inherent impls cannot be default //~^ ERROR implementation is not supported in `trait`s or `impl`s default!(); default::foo::bar!(); diff --git a/tests/ui/parser/default-on-wrong-item-kind.stderr b/tests/ui/parser/default-on-wrong-item-kind.stderr index 56641565b16..0380fcdf775 100644 --- a/tests/ui/parser/default-on-wrong-item-kind.stderr +++ b/tests/ui/parser/default-on-wrong-item-kind.stderr @@ -78,6 +78,16 @@ LL | default trait foo = Ord; | = note: only associated `fn`, `const`, and `type` items can be `default` +error: inherent impls cannot be default + --> $DIR/default-on-wrong-item-kind.rs:22:18 + | +LL | default impl foo {} + | ------- ^^^ inherent impl for this type + | | + | default because of this + | + = note: only trait implementations may be annotated with `default` + error: an item macro invocation cannot be `default` --> $DIR/default-on-wrong-item-kind.rs:25:5 | @@ -275,6 +285,16 @@ LL | default trait foo = Ord; | = help: consider moving the trait alias out to a nearby module scope +error: inherent impls cannot be default + --> $DIR/default-on-wrong-item-kind.rs:56:18 + | +LL | default impl foo {} + | ------- ^^^ inherent impl for this type + | | + | default because of this + | + = note: only trait implementations may be annotated with `default` + error: implementation is not supported in `extern` blocks --> $DIR/default-on-wrong-item-kind.rs:56:5 | @@ -489,6 +509,16 @@ LL | default trait foo = Ord; | = help: consider moving the trait alias out to a nearby module scope +error: inherent impls cannot be default + --> $DIR/default-on-wrong-item-kind.rs:93:18 + | +LL | default impl foo {} + | ------- ^^^ inherent impl for this type + | | + | default because of this + | + = note: only trait implementations may be annotated with `default` + error: implementation is not supported in `trait`s or `impl`s --> $DIR/default-on-wrong-item-kind.rs:93:5 | @@ -703,6 +733,16 @@ LL | default trait foo = Ord; | = help: consider moving the trait alias out to a nearby module scope +error: inherent impls cannot be default + --> $DIR/default-on-wrong-item-kind.rs:130:18 + | +LL | default impl foo {} + | ------- ^^^ inherent impl for this type + | | + | default because of this + | + = note: only trait implementations may be annotated with `default` + error: implementation is not supported in `trait`s or `impl`s --> $DIR/default-on-wrong-item-kind.rs:130:5 | @@ -759,5 +799,5 @@ LL | default macro_rules! foo {} | = help: consider moving the macro definition out to a nearby module scope -error: aborting due to 95 previous errors +error: aborting due to 99 previous errors diff --git a/tests/ui/issues/issue-15043.rs b/tests/ui/parser/generics-rangle-eq-15043.rs index a9bb46b649b..1afc334dfd8 100644 --- a/tests/ui/issues/issue-15043.rs +++ b/tests/ui/parser/generics-rangle-eq-15043.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15043 + //@ run-pass #![allow(warnings)] diff --git a/tests/ui/issues/issue-15896.rs b/tests/ui/pattern/enum-struct-pattern-mismatch-15896.rs index d3153b516e6..9f7c5084c0e 100644 --- a/tests/ui/issues/issue-15896.rs +++ b/tests/ui/pattern/enum-struct-pattern-mismatch-15896.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15896 + // Regression test for #15896. It used to ICE rustc. fn main() { diff --git a/tests/ui/issues/issue-15896.stderr b/tests/ui/pattern/enum-struct-pattern-mismatch-15896.stderr index 381f6dc2276..8dee4c37e2f 100644 --- a/tests/ui/issues/issue-15896.stderr +++ b/tests/ui/pattern/enum-struct-pattern-mismatch-15896.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/issue-15896.rs:11:11 + --> $DIR/enum-struct-pattern-mismatch-15896.rs:13:11 | LL | let u = match e { | - this expression has type `E` diff --git a/tests/ui/issues/issue-15381.rs b/tests/ui/pattern/refutable-pattern-for-loop-15381.rs index bd5f62ddc67..3c19612c9cc 100644 --- a/tests/ui/issues/issue-15381.rs +++ b/tests/ui/pattern/refutable-pattern-for-loop-15381.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15381 + fn main() { let values: Vec<u8> = vec![1,2,3,4,5,6,7,8]; diff --git a/tests/ui/issues/issue-15381.stderr b/tests/ui/pattern/refutable-pattern-for-loop-15381.stderr index 03a0100f1bd..3c1d5fb454c 100644 --- a/tests/ui/issues/issue-15381.stderr +++ b/tests/ui/pattern/refutable-pattern-for-loop-15381.stderr @@ -1,5 +1,5 @@ error[E0005]: refutable pattern in `for` loop binding - --> $DIR/issue-15381.rs:4:9 + --> $DIR/refutable-pattern-for-loop-15381.rs:6:9 | LL | for &[x,y,z] in values.chunks(3).filter(|&xs| xs.len() == 3) { | ^^^^^^^^ patterns `&[]`, `&[_]`, `&[_, _]` and 1 more not covered diff --git a/tests/ui/issues/issue-15104.rs b/tests/ui/pattern/slice-pattern-recursion-15104.rs index e68c94c370e..24e3fe78de0 100644 --- a/tests/ui/issues/issue-15104.rs +++ b/tests/ui/pattern/slice-pattern-recursion-15104.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15104 + //@ run-pass fn main() { diff --git a/tests/ui/issues/issue-16149.rs b/tests/ui/pattern/static-binding-shadow-16149.rs index 51b60725c5a..a46f78214c7 100644 --- a/tests/ui/issues/issue-16149.rs +++ b/tests/ui/pattern/static-binding-shadow-16149.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/16149 + extern "C" { static externalValue: isize; } diff --git a/tests/ui/issues/issue-16149.stderr b/tests/ui/pattern/static-binding-shadow-16149.stderr index 9ffd0e7e645..6d8c7634acd 100644 --- a/tests/ui/issues/issue-16149.stderr +++ b/tests/ui/pattern/static-binding-shadow-16149.stderr @@ -1,5 +1,5 @@ error[E0530]: match bindings cannot shadow statics - --> $DIR/issue-16149.rs:7:9 + --> $DIR/static-binding-shadow-16149.rs:9:9 | LL | static externalValue: isize; | ---------------------------- the static `externalValue` is defined here diff --git a/tests/ui/issues/issue-15260.rs b/tests/ui/pattern/struct-field-duplicate-binding-15260.rs index 64fc3df3d23..a3617798cdf 100644 --- a/tests/ui/issues/issue-15260.rs +++ b/tests/ui/pattern/struct-field-duplicate-binding-15260.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15260 + struct Foo { a: usize, } diff --git a/tests/ui/issues/issue-15260.stderr b/tests/ui/pattern/struct-field-duplicate-binding-15260.stderr index 4a3041122b2..536904fbcb3 100644 --- a/tests/ui/issues/issue-15260.stderr +++ b/tests/ui/pattern/struct-field-duplicate-binding-15260.stderr @@ -1,5 +1,5 @@ error[E0025]: field `a` bound multiple times in the pattern - --> $DIR/issue-15260.rs:8:9 + --> $DIR/struct-field-duplicate-binding-15260.rs:10:9 | LL | a: _, | ---- first use of `a` @@ -7,7 +7,7 @@ LL | a: _ | ^^^^ multiple uses of `a` in pattern error[E0025]: field `a` bound multiple times in the pattern - --> $DIR/issue-15260.rs:14:9 + --> $DIR/struct-field-duplicate-binding-15260.rs:16:9 | LL | a, | - first use of `a` @@ -15,7 +15,7 @@ LL | a: _ | ^^^^ multiple uses of `a` in pattern error[E0025]: field `a` bound multiple times in the pattern - --> $DIR/issue-15260.rs:20:9 + --> $DIR/struct-field-duplicate-binding-15260.rs:22:9 | LL | a, | - first use of `a` @@ -23,7 +23,7 @@ LL | a: _, | ^^^^ multiple uses of `a` in pattern error[E0025]: field `a` bound multiple times in the pattern - --> $DIR/issue-15260.rs:22:9 + --> $DIR/struct-field-duplicate-binding-15260.rs:24:9 | LL | a, | - first use of `a` diff --git a/tests/ui/issues/issue-15129-rpass.rs b/tests/ui/pattern/tuple-enum-match-15129.rs index e2ddb989072..1d6192c4cb3 100644 --- a/tests/ui/issues/issue-15129-rpass.rs +++ b/tests/ui/pattern/tuple-enum-match-15129.rs @@ -1,24 +1,25 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15129 + //@ run-pass pub enum T { T1(()), - T2(()) + T2(()), } pub enum V { V1(isize), - V2(bool) + V2(bool), } fn foo(x: (T, V)) -> String { match x { - (T::T1(()), V::V1(i)) => format!("T1(()), V1({})", i), - (T::T2(()), V::V2(b)) => format!("T2(()), V2({})", b), - _ => String::new() + (T::T1(()), V::V1(i)) => format!("T1(()), V1({})", i), + (T::T2(()), V::V2(b)) => format!("T2(()), V2({})", b), + _ => String::new(), } } - fn main() { assert_eq!(foo((T::T1(()), V::V1(99))), "T1(()), V1(99)".to_string()); assert_eq!(foo((T::T2(()), V::V2(true))), "T2(()), V2(true)".to_string()); diff --git a/tests/ui/issues/issue-16401.rs b/tests/ui/pattern/unit-type-struct-pattern-mismatch-16401.rs index 0985a6806d2..2eba33e177e 100644 --- a/tests/ui/issues/issue-16401.rs +++ b/tests/ui/pattern/unit-type-struct-pattern-mismatch-16401.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/16401 + struct Slice<T> { data: *const T, len: usize, diff --git a/tests/ui/issues/issue-16401.stderr b/tests/ui/pattern/unit-type-struct-pattern-mismatch-16401.stderr index 6af920ca439..22c04e439c4 100644 --- a/tests/ui/issues/issue-16401.stderr +++ b/tests/ui/pattern/unit-type-struct-pattern-mismatch-16401.stderr @@ -1,5 +1,5 @@ error[E0308]: mismatched types - --> $DIR/issue-16401.rs:8:9 + --> $DIR/unit-type-struct-pattern-mismatch-16401.rs:10:9 | LL | match () { | -- this expression has type `()` diff --git a/tests/ui/issues/issue-pr29383.rs b/tests/ui/pattern/unit-variant-pattern-matching-29383.rs index 2bcc0aa2782..e339dc01f46 100644 --- a/tests/ui/issues/issue-pr29383.rs +++ b/tests/ui/pattern/unit-variant-pattern-matching-29383.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/29383 enum E { A, B, diff --git a/tests/ui/issues/issue-pr29383.stderr b/tests/ui/pattern/unit-variant-pattern-matching-29383.stderr index 57783d75ba1..e30837568a5 100644 --- a/tests/ui/issues/issue-pr29383.stderr +++ b/tests/ui/pattern/unit-variant-pattern-matching-29383.stderr @@ -1,5 +1,5 @@ error[E0532]: expected tuple struct or tuple variant, found unit variant `E::A` - --> $DIR/issue-pr29383.rs:9:14 + --> $DIR/unit-variant-pattern-matching-29383.rs:10:14 | LL | A, | - `E::A` defined here @@ -8,7 +8,7 @@ LL | Some(E::A(..)) => {} | ^^^^^^^^ help: use this syntax instead: `E::A` error[E0532]: expected tuple struct or tuple variant, found unit variant `E::B` - --> $DIR/issue-pr29383.rs:11:14 + --> $DIR/unit-variant-pattern-matching-29383.rs:12:14 | LL | B, | - `E::B` defined here diff --git a/tests/ui/proc-macro/attribute.rs b/tests/ui/proc-macro/attribute.rs index 988cdcd0403..dfb26738377 100644 --- a/tests/ui/proc-macro/attribute.rs +++ b/tests/ui/proc-macro/attribute.rs @@ -9,46 +9,55 @@ use proc_macro::*; #[proc_macro_derive] //~^ ERROR malformed `proc_macro_derive` attribute //~| NOTE expected this to be a list +//~| NOTE for more information, visit pub fn foo1(input: TokenStream) -> TokenStream { input } #[proc_macro_derive = ""] //~^ ERROR malformed `proc_macro_derive` attribute //~| NOTE expected this to be a list +//~| NOTE for more information, visit pub fn foo2(input: TokenStream) -> TokenStream { input } #[proc_macro_derive(d3, a, b)] //~^ ERROR malformed `proc_macro_derive` attribute //~| NOTE the only valid argument here is `attributes` +//~| NOTE for more information, visit pub fn foo3(input: TokenStream) -> TokenStream { input } #[proc_macro_derive(d4, attributes(a), b)] //~^ ERROR malformed `proc_macro_derive` attribute //~| NOTE didn't expect any arguments here +//~| NOTE for more information, visit pub fn foo4(input: TokenStream) -> TokenStream { input } #[proc_macro_derive("a")] //~^ ERROR malformed `proc_macro_derive` attribute //~| NOTE didn't expect a literal here +//~| NOTE for more information, visit pub fn foo5(input: TokenStream) -> TokenStream { input } #[proc_macro_derive(d6 = "")] //~^ ERROR malformed `proc_macro_derive` attribute //~| NOTE didn't expect any arguments here +//~| NOTE for more information, visit pub fn foo6(input: TokenStream) -> TokenStream { input } #[proc_macro_derive(m::d7)] //~^ ERROR malformed `proc_macro_derive` attribute //~| NOTE expected a valid identifier here +//~| NOTE for more information, visit pub fn foo7(input: TokenStream) -> TokenStream { input } #[proc_macro_derive(d8(a))] //~^ ERROR malformed `proc_macro_derive` attribute //~| NOTE didn't expect any arguments here +//~| NOTE for more information, visit pub fn foo8(input: TokenStream) -> TokenStream { input } #[proc_macro_derive(self)] //~^ ERROR malformed `proc_macro_derive` attribute //~| NOTE expected a valid identifier here +//~| NOTE for more information, visit pub fn foo9(input: TokenStream) -> TokenStream { input } #[proc_macro_derive(PartialEq)] // OK @@ -57,34 +66,41 @@ pub fn foo10(input: TokenStream) -> TokenStream { input } #[proc_macro_derive(d11, a)] //~^ ERROR malformed `proc_macro_derive` attribute //~| NOTE the only valid argument here is `attributes` +//~| NOTE for more information, visit pub fn foo11(input: TokenStream) -> TokenStream { input } #[proc_macro_derive(d12, attributes)] //~^ ERROR malformed `proc_macro_derive` attribute //~| NOTE expected this to be a list +//~| NOTE for more information, visit pub fn foo12(input: TokenStream) -> TokenStream { input } #[proc_macro_derive(d13, attributes("a"))] //~^ ERROR malformed `proc_macro_derive` attribute //~| NOTE expected a valid identifier here +//~| NOTE for more information, visit pub fn foo13(input: TokenStream) -> TokenStream { input } #[proc_macro_derive(d14, attributes(a = ""))] //~^ ERROR malformed `proc_macro_derive` attribute //~| NOTE didn't expect any arguments here +//~| NOTE for more information, visit pub fn foo14(input: TokenStream) -> TokenStream { input } #[proc_macro_derive(d15, attributes(m::a))] //~^ ERROR malformed `proc_macro_derive` attribute //~| NOTE expected a valid identifier here +//~| NOTE for more information, visit pub fn foo15(input: TokenStream) -> TokenStream { input } #[proc_macro_derive(d16, attributes(a(b)))] //~^ ERROR malformed `proc_macro_derive` attribute //~| NOTE didn't expect any arguments here +//~| NOTE for more information, visit pub fn foo16(input: TokenStream) -> TokenStream { input } #[proc_macro_derive(d17, attributes(self))] //~^ ERROR malformed `proc_macro_derive` attribute //~| NOTE expected a valid identifier here +//~| NOTE for more information, visit pub fn foo17(input: TokenStream) -> TokenStream { input } diff --git a/tests/ui/proc-macro/attribute.stderr b/tests/ui/proc-macro/attribute.stderr index db59a1fdfb3..e7127c8ef1d 100644 --- a/tests/ui/proc-macro/attribute.stderr +++ b/tests/ui/proc-macro/attribute.stderr @@ -2,145 +2,283 @@ error[E0539]: malformed `proc_macro_derive` attribute input --> $DIR/attribute.rs:9:1 | LL | #[proc_macro_derive] - | ^^^^^^^^^^^^^^^^^^^^ - | | - | expected this to be a list - | help: must be of the form: `#[proc_macro_derive(TraitName, /*opt*/ attributes(name1, name2, ...))]` + | ^^^^^^^^^^^^^^^^^^^^ expected this to be a list + | + = note: for more information, visit <https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros> +help: try changing it to one of the following valid forms of the attribute + | +LL | #[proc_macro_derive(TraitName)] + | +++++++++++ +LL | #[proc_macro_derive(TraitName, attributes(name1, name2, ...))] + | ++++++++++++++++++++++++++++++++++++++++++ error[E0539]: malformed `proc_macro_derive` attribute input - --> $DIR/attribute.rs:14:1 + --> $DIR/attribute.rs:15:1 | LL | #[proc_macro_derive = ""] - | ^^^^^^^^^^^^^^^^^^^^^^^^^ - | | - | expected this to be a list - | help: must be of the form: `#[proc_macro_derive(TraitName, /*opt*/ attributes(name1, name2, ...))]` + | ^^^^^^^^^^^^^^^^^^^^^^^^^ expected this to be a list + | + = note: for more information, visit <https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros> +help: try changing it to one of the following valid forms of the attribute + | +LL - #[proc_macro_derive = ""] +LL + #[proc_macro_derive(TraitName)] + | +LL - #[proc_macro_derive = ""] +LL + #[proc_macro_derive(TraitName, attributes(name1, name2, ...))] + | error[E0539]: malformed `proc_macro_derive` attribute input - --> $DIR/attribute.rs:19:1 + --> $DIR/attribute.rs:21:1 | LL | #[proc_macro_derive(d3, a, b)] | ^^^^^^^^^^^^^^^^^^^^^^^^-^^^^^ - | | | - | | the only valid argument here is `attributes` - | help: must be of the form: `#[proc_macro_derive(TraitName, /*opt*/ attributes(name1, name2, ...))]` + | | + | the only valid argument here is `attributes` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros> +help: try changing it to one of the following valid forms of the attribute + | +LL - #[proc_macro_derive(d3, a, b)] +LL + #[proc_macro_derive(TraitName)] + | +LL - #[proc_macro_derive(d3, a, b)] +LL + #[proc_macro_derive(TraitName, attributes(name1, name2, ...))] + | error[E0565]: malformed `proc_macro_derive` attribute input - --> $DIR/attribute.rs:24:1 + --> $DIR/attribute.rs:27:1 | LL | #[proc_macro_derive(d4, attributes(a), b)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-^^ - | | | - | | didn't expect any arguments here - | help: must be of the form: `#[proc_macro_derive(TraitName, /*opt*/ attributes(name1, name2, ...))]` + | | + | didn't expect any arguments here + | + = note: for more information, visit <https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros> +help: try changing it to one of the following valid forms of the attribute + | +LL - #[proc_macro_derive(d4, attributes(a), b)] +LL + #[proc_macro_derive(TraitName)] + | +LL - #[proc_macro_derive(d4, attributes(a), b)] +LL + #[proc_macro_derive(TraitName, attributes(name1, name2, ...))] + | error[E0565]: malformed `proc_macro_derive` attribute input - --> $DIR/attribute.rs:29:1 + --> $DIR/attribute.rs:33:1 | LL | #[proc_macro_derive("a")] | ^^^^^^^^^^^^^^^^^^^^---^^ - | | | - | | didn't expect a literal here - | help: must be of the form: `#[proc_macro_derive(TraitName, /*opt*/ attributes(name1, name2, ...))]` + | | + | didn't expect a literal here + | + = note: for more information, visit <https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros> +help: try changing it to one of the following valid forms of the attribute + | +LL - #[proc_macro_derive("a")] +LL + #[proc_macro_derive(TraitName)] + | +LL - #[proc_macro_derive("a")] +LL + #[proc_macro_derive(TraitName, attributes(name1, name2, ...))] + | error[E0565]: malformed `proc_macro_derive` attribute input - --> $DIR/attribute.rs:34:1 + --> $DIR/attribute.rs:39:1 | LL | #[proc_macro_derive(d6 = "")] | ^^^^^^^^^^^^^^^^^^^^^^^----^^ - | | | - | | didn't expect any arguments here - | help: must be of the form: `#[proc_macro_derive(TraitName, /*opt*/ attributes(name1, name2, ...))]` + | | + | didn't expect any arguments here + | + = note: for more information, visit <https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros> +help: try changing it to one of the following valid forms of the attribute + | +LL - #[proc_macro_derive(d6 = "")] +LL + #[proc_macro_derive(TraitName)] + | +LL - #[proc_macro_derive(d6 = "")] +LL + #[proc_macro_derive(TraitName, attributes(name1, name2, ...))] + | error[E0539]: malformed `proc_macro_derive` attribute input - --> $DIR/attribute.rs:39:1 + --> $DIR/attribute.rs:45:1 | LL | #[proc_macro_derive(m::d7)] | ^^^^^^^^^^^^^^^^^^^^-----^^ - | | | - | | expected a valid identifier here - | help: must be of the form: `#[proc_macro_derive(TraitName, /*opt*/ attributes(name1, name2, ...))]` + | | + | expected a valid identifier here + | + = note: for more information, visit <https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros> +help: try changing it to one of the following valid forms of the attribute + | +LL - #[proc_macro_derive(m::d7)] +LL + #[proc_macro_derive(TraitName)] + | +LL - #[proc_macro_derive(m::d7)] +LL + #[proc_macro_derive(TraitName, attributes(name1, name2, ...))] + | error[E0565]: malformed `proc_macro_derive` attribute input - --> $DIR/attribute.rs:44:1 + --> $DIR/attribute.rs:51:1 | LL | #[proc_macro_derive(d8(a))] | ^^^^^^^^^^^^^^^^^^^^^^---^^ - | | | - | | didn't expect any arguments here - | help: must be of the form: `#[proc_macro_derive(TraitName, /*opt*/ attributes(name1, name2, ...))]` + | | + | didn't expect any arguments here + | + = note: for more information, visit <https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros> +help: try changing it to one of the following valid forms of the attribute + | +LL - #[proc_macro_derive(d8(a))] +LL + #[proc_macro_derive(TraitName)] + | +LL - #[proc_macro_derive(d8(a))] +LL + #[proc_macro_derive(TraitName, attributes(name1, name2, ...))] + | error[E0539]: malformed `proc_macro_derive` attribute input - --> $DIR/attribute.rs:49:1 + --> $DIR/attribute.rs:57:1 | LL | #[proc_macro_derive(self)] | ^^^^^^^^^^^^^^^^^^^^----^^ - | | | - | | expected a valid identifier here - | help: must be of the form: `#[proc_macro_derive(TraitName, /*opt*/ attributes(name1, name2, ...))]` + | | + | expected a valid identifier here + | + = note: for more information, visit <https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros> +help: try changing it to one of the following valid forms of the attribute + | +LL - #[proc_macro_derive(self)] +LL + #[proc_macro_derive(TraitName)] + | +LL - #[proc_macro_derive(self)] +LL + #[proc_macro_derive(TraitName, attributes(name1, name2, ...))] + | error[E0539]: malformed `proc_macro_derive` attribute input - --> $DIR/attribute.rs:57:1 + --> $DIR/attribute.rs:66:1 | LL | #[proc_macro_derive(d11, a)] | ^^^^^^^^^^^^^^^^^^^^^^^^^-^^ - | | | - | | the only valid argument here is `attributes` - | help: must be of the form: `#[proc_macro_derive(TraitName, /*opt*/ attributes(name1, name2, ...))]` + | | + | the only valid argument here is `attributes` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros> +help: try changing it to one of the following valid forms of the attribute + | +LL - #[proc_macro_derive(d11, a)] +LL + #[proc_macro_derive(TraitName)] + | +LL - #[proc_macro_derive(d11, a)] +LL + #[proc_macro_derive(TraitName, attributes(name1, name2, ...))] + | error[E0539]: malformed `proc_macro_derive` attribute input - --> $DIR/attribute.rs:62:1 + --> $DIR/attribute.rs:72:1 | LL | #[proc_macro_derive(d12, attributes)] | ^^^^^^^^^^^^^^^^^^^^^^^^^----------^^ - | | | - | | expected this to be a list - | help: must be of the form: `#[proc_macro_derive(TraitName, /*opt*/ attributes(name1, name2, ...))]` + | | + | expected this to be a list + | + = note: for more information, visit <https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros> +help: try changing it to one of the following valid forms of the attribute + | +LL - #[proc_macro_derive(d12, attributes)] +LL + #[proc_macro_derive(TraitName)] + | +LL - #[proc_macro_derive(d12, attributes)] +LL + #[proc_macro_derive(TraitName, attributes(name1, name2, ...))] + | error[E0539]: malformed `proc_macro_derive` attribute input - --> $DIR/attribute.rs:67:1 + --> $DIR/attribute.rs:78:1 | LL | #[proc_macro_derive(d13, attributes("a"))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---^^^ - | | | - | | expected a valid identifier here - | help: must be of the form: `#[proc_macro_derive(TraitName, /*opt*/ attributes(name1, name2, ...))]` + | | + | expected a valid identifier here + | + = note: for more information, visit <https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros> +help: try changing it to one of the following valid forms of the attribute + | +LL - #[proc_macro_derive(d13, attributes("a"))] +LL + #[proc_macro_derive(TraitName)] + | +LL - #[proc_macro_derive(d13, attributes("a"))] +LL + #[proc_macro_derive(TraitName, attributes(name1, name2, ...))] + | error[E0565]: malformed `proc_macro_derive` attribute input - --> $DIR/attribute.rs:72:1 + --> $DIR/attribute.rs:84:1 | LL | #[proc_macro_derive(d14, attributes(a = ""))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^----^^^ - | | | - | | didn't expect any arguments here - | help: must be of the form: `#[proc_macro_derive(TraitName, /*opt*/ attributes(name1, name2, ...))]` + | | + | didn't expect any arguments here + | + = note: for more information, visit <https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros> +help: try changing it to one of the following valid forms of the attribute + | +LL - #[proc_macro_derive(d14, attributes(a = ""))] +LL + #[proc_macro_derive(TraitName)] + | +LL - #[proc_macro_derive(d14, attributes(a = ""))] +LL + #[proc_macro_derive(TraitName, attributes(name1, name2, ...))] + | error[E0539]: malformed `proc_macro_derive` attribute input - --> $DIR/attribute.rs:77:1 + --> $DIR/attribute.rs:90:1 | LL | #[proc_macro_derive(d15, attributes(m::a))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^----^^^ - | | | - | | expected a valid identifier here - | help: must be of the form: `#[proc_macro_derive(TraitName, /*opt*/ attributes(name1, name2, ...))]` + | | + | expected a valid identifier here + | + = note: for more information, visit <https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros> +help: try changing it to one of the following valid forms of the attribute + | +LL - #[proc_macro_derive(d15, attributes(m::a))] +LL + #[proc_macro_derive(TraitName)] + | +LL - #[proc_macro_derive(d15, attributes(m::a))] +LL + #[proc_macro_derive(TraitName, attributes(name1, name2, ...))] + | error[E0565]: malformed `proc_macro_derive` attribute input - --> $DIR/attribute.rs:82:1 + --> $DIR/attribute.rs:96:1 | LL | #[proc_macro_derive(d16, attributes(a(b)))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---^^^ - | | | - | | didn't expect any arguments here - | help: must be of the form: `#[proc_macro_derive(TraitName, /*opt*/ attributes(name1, name2, ...))]` + | | + | didn't expect any arguments here + | + = note: for more information, visit <https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros> +help: try changing it to one of the following valid forms of the attribute + | +LL - #[proc_macro_derive(d16, attributes(a(b)))] +LL + #[proc_macro_derive(TraitName)] + | +LL - #[proc_macro_derive(d16, attributes(a(b)))] +LL + #[proc_macro_derive(TraitName, attributes(name1, name2, ...))] + | error[E0539]: malformed `proc_macro_derive` attribute input - --> $DIR/attribute.rs:87:1 + --> $DIR/attribute.rs:102:1 | LL | #[proc_macro_derive(d17, attributes(self))] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^----^^^ - | | | - | | expected a valid identifier here - | help: must be of the form: `#[proc_macro_derive(TraitName, /*opt*/ attributes(name1, name2, ...))]` + | | + | expected a valid identifier here + | + = note: for more information, visit <https://doc.rust-lang.org/reference/procedural-macros.html#derive-macros> +help: try changing it to one of the following valid forms of the attribute + | +LL - #[proc_macro_derive(d17, attributes(self))] +LL + #[proc_macro_derive(TraitName)] + | +LL - #[proc_macro_derive(d17, attributes(self))] +LL + #[proc_macro_derive(TraitName, attributes(name1, name2, ...))] + | error: aborting due to 16 previous errors diff --git a/tests/ui/proc-macro/auxiliary/match-expander.rs b/tests/ui/proc-macro/auxiliary/match-expander.rs new file mode 100644 index 00000000000..bf78df2addf --- /dev/null +++ b/tests/ui/proc-macro/auxiliary/match-expander.rs @@ -0,0 +1,15 @@ +extern crate proc_macro; + +use proc_macro::TokenStream; + +#[proc_macro] +pub fn matcher(input: TokenStream) -> TokenStream { +" +struct S(()); +let s = S(()); +match s { + true => {} + _ => {} +} +".parse().unwrap() +} diff --git a/tests/ui/proc-macro/match-expander.rs b/tests/ui/proc-macro/match-expander.rs new file mode 100644 index 00000000000..23e5746c540 --- /dev/null +++ b/tests/ui/proc-macro/match-expander.rs @@ -0,0 +1,12 @@ +//@ proc-macro: match-expander.rs +// Ensure that we don't point at macro invocation when providing inference contexts. + +#[macro_use] +extern crate match_expander; + +fn main() { + match_expander::matcher!(); + //~^ ERROR: mismatched types + //~| NOTE: expected `S`, found `bool` + //~| NOTE: in this expansion of match_expander::matcher! +} diff --git a/tests/ui/proc-macro/match-expander.stderr b/tests/ui/proc-macro/match-expander.stderr new file mode 100644 index 00000000000..b77468ec60a --- /dev/null +++ b/tests/ui/proc-macro/match-expander.stderr @@ -0,0 +1,11 @@ +error[E0308]: mismatched types + --> $DIR/match-expander.rs:8:5 + | +LL | match_expander::matcher!(); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `S`, found `bool` + | + = note: this error originates in the macro `match_expander::matcher` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/proc-macro/quote/does-not-have-iter-interpolated-dup.stderr b/tests/ui/proc-macro/quote/does-not-have-iter-interpolated-dup.stderr index ecb12c1df3b..0bcea9b85f4 100644 --- a/tests/ui/proc-macro/quote/does-not-have-iter-interpolated-dup.stderr +++ b/tests/ui/proc-macro/quote/does-not-have-iter-interpolated-dup.stderr @@ -5,7 +5,6 @@ LL | quote!($($nonrep $nonrep)*); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | | | expected `HasIterator`, found `ThereIsNoIteratorInRepetition` - | expected due to this | here the type of `has_iter` is inferred to be `ThereIsNoIteratorInRepetition` error: aborting due to 1 previous error diff --git a/tests/ui/proc-macro/quote/does-not-have-iter-interpolated.stderr b/tests/ui/proc-macro/quote/does-not-have-iter-interpolated.stderr index 093e2ebc098..d945ab41a12 100644 --- a/tests/ui/proc-macro/quote/does-not-have-iter-interpolated.stderr +++ b/tests/ui/proc-macro/quote/does-not-have-iter-interpolated.stderr @@ -5,7 +5,6 @@ LL | quote!($($nonrep)*); | ^^^^^^^^^^^^^^^^^^^ | | | expected `HasIterator`, found `ThereIsNoIteratorInRepetition` - | expected due to this | here the type of `has_iter` is inferred to be `ThereIsNoIteratorInRepetition` error: aborting due to 1 previous error diff --git a/tests/ui/proc-macro/quote/does-not-have-iter-separated.stderr b/tests/ui/proc-macro/quote/does-not-have-iter-separated.stderr index 937209e675e..2d715f293d4 100644 --- a/tests/ui/proc-macro/quote/does-not-have-iter-separated.stderr +++ b/tests/ui/proc-macro/quote/does-not-have-iter-separated.stderr @@ -2,10 +2,7 @@ error[E0308]: mismatched types --> $DIR/does-not-have-iter-separated.rs:8:5 | LL | quote!($(a b),*); - | ^^^^^^^^^^^^^^^^ - | | - | expected `HasIterator`, found `ThereIsNoIteratorInRepetition` - | expected due to this + | ^^^^^^^^^^^^^^^^ expected `HasIterator`, found `ThereIsNoIteratorInRepetition` error: aborting due to 1 previous error diff --git a/tests/ui/proc-macro/quote/does-not-have-iter.stderr b/tests/ui/proc-macro/quote/does-not-have-iter.stderr index e74ea334899..ac8e725038a 100644 --- a/tests/ui/proc-macro/quote/does-not-have-iter.stderr +++ b/tests/ui/proc-macro/quote/does-not-have-iter.stderr @@ -2,10 +2,7 @@ error[E0308]: mismatched types --> $DIR/does-not-have-iter.rs:8:5 | LL | quote!($(a b)*); - | ^^^^^^^^^^^^^^^ - | | - | expected `HasIterator`, found `ThereIsNoIteratorInRepetition` - | expected due to this + | ^^^^^^^^^^^^^^^ expected `HasIterator`, found `ThereIsNoIteratorInRepetition` error: aborting due to 1 previous error diff --git a/tests/ui/recursion_limit/invalid_digit_type.stderr b/tests/ui/recursion_limit/invalid_digit_type.stderr index 94442b5747f..a122262f1df 100644 --- a/tests/ui/recursion_limit/invalid_digit_type.stderr +++ b/tests/ui/recursion_limit/invalid_digit_type.stderr @@ -3,6 +3,8 @@ error: malformed `recursion_limit` attribute input | LL | #![recursion_limit = 123] | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#![recursion_limit = "N"]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/attributes/limits.html#the-recursion_limit-attribute> error: aborting due to 1 previous error diff --git a/tests/ui/recursion_limit/invalid_macro.stderr b/tests/ui/recursion_limit/invalid_macro.stderr index aa4894ec4d8..b4dbc9fcb13 100644 --- a/tests/ui/recursion_limit/invalid_macro.stderr +++ b/tests/ui/recursion_limit/invalid_macro.stderr @@ -3,6 +3,8 @@ error: malformed `recursion_limit` attribute input | LL | #![recursion_limit = foo!()] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#![recursion_limit = "N"]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/attributes/limits.html#the-recursion_limit-attribute> error: aborting due to 1 previous error diff --git a/tests/ui/recursion_limit/no-value.stderr b/tests/ui/recursion_limit/no-value.stderr index b2e8c46c372..4a0ad04f271 100644 --- a/tests/ui/recursion_limit/no-value.stderr +++ b/tests/ui/recursion_limit/no-value.stderr @@ -3,6 +3,8 @@ error: malformed `recursion_limit` attribute input | LL | #![recursion_limit] | ^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#![recursion_limit = "N"]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/attributes/limits.html#the-recursion_limit-attribute> error: aborting due to 1 previous error diff --git a/tests/ui/repr/invalid_repr_list_help.stderr b/tests/ui/repr/invalid_repr_list_help.stderr index 763ad9c2795..f9d1593275e 100644 --- a/tests/ui/repr/invalid_repr_list_help.stderr +++ b/tests/ui/repr/invalid_repr_list_help.stderr @@ -5,6 +5,7 @@ LL | #[repr(uwu)] | ^^^ | = help: valid reprs are `Rust` (default), `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize` + = note: for more information, visit <https://doc.rust-lang.org/reference/type-layout.html?highlight=repr#representations> error[E0552]: unrecognized representation hint --> $DIR/invalid_repr_list_help.rs:6:8 @@ -13,6 +14,7 @@ LL | #[repr(uwu = "a")] | ^^^^^^^^^ | = help: valid reprs are `Rust` (default), `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize` + = note: for more information, visit <https://doc.rust-lang.org/reference/type-layout.html?highlight=repr#representations> error[E0552]: unrecognized representation hint --> $DIR/invalid_repr_list_help.rs:9:8 @@ -21,6 +23,7 @@ LL | #[repr(uwu(4))] | ^^^^^^ | = help: valid reprs are `Rust` (default), `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize` + = note: for more information, visit <https://doc.rust-lang.org/reference/type-layout.html?highlight=repr#representations> error[E0552]: unrecognized representation hint --> $DIR/invalid_repr_list_help.rs:14:8 @@ -29,6 +32,7 @@ LL | #[repr(uwu, u8)] | ^^^ | = help: valid reprs are `Rust` (default), `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize` + = note: for more information, visit <https://doc.rust-lang.org/reference/type-layout.html?highlight=repr#representations> error[E0552]: unrecognized representation hint --> $DIR/invalid_repr_list_help.rs:19:8 @@ -37,6 +41,7 @@ LL | #[repr(uwu)] | ^^^ | = help: valid reprs are `Rust` (default), `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize` + = note: for more information, visit <https://doc.rust-lang.org/reference/type-layout.html?highlight=repr#representations> error: unknown `doc` attribute `owo` --> $DIR/invalid_repr_list_help.rs:20:7 diff --git a/tests/ui/repr/repr.stderr b/tests/ui/repr/repr.stderr index 9e581332278..d4faea12517 100644 --- a/tests/ui/repr/repr.stderr +++ b/tests/ui/repr/repr.stderr @@ -2,28 +2,66 @@ error[E0539]: malformed `repr` attribute input --> $DIR/repr.rs:1:1 | LL | #[repr] - | ^^^^^^^ - | | - | expected this to be a list - | help: must be of the form: `#[repr(C | Rust | align(...) | packed(...) | <integer type> | transparent)]` + | ^^^^^^^ expected this to be a list + | + = note: for more information, visit <https://doc.rust-lang.org/reference/type-layout.html#representations> +help: try changing it to one of the following valid forms of the attribute + | +LL | #[repr(<integer type>)] + | ++++++++++++++++ +LL | #[repr(C)] + | +++ +LL | #[repr(Rust)] + | ++++++ +LL | #[repr(align(...))] + | ++++++++++++ + = and 2 other candidates error[E0539]: malformed `repr` attribute input --> $DIR/repr.rs:4:1 | LL | #[repr = "B"] - | ^^^^^^^^^^^^^ - | | - | expected this to be a list - | help: must be of the form: `#[repr(C | Rust | align(...) | packed(...) | <integer type> | transparent)]` + | ^^^^^^^^^^^^^ expected this to be a list + | + = note: for more information, visit <https://doc.rust-lang.org/reference/type-layout.html#representations> +help: try changing it to one of the following valid forms of the attribute + | +LL - #[repr = "B"] +LL + #[repr(<integer type>)] + | +LL - #[repr = "B"] +LL + #[repr(C)] + | +LL - #[repr = "B"] +LL + #[repr(Rust)] + | +LL - #[repr = "B"] +LL + #[repr(align(...))] + | + = and 2 other candidates error[E0539]: malformed `repr` attribute input --> $DIR/repr.rs:7:1 | LL | #[repr = "C"] - | ^^^^^^^^^^^^^ - | | - | expected this to be a list - | help: must be of the form: `#[repr(C | Rust | align(...) | packed(...) | <integer type> | transparent)]` + | ^^^^^^^^^^^^^ expected this to be a list + | + = note: for more information, visit <https://doc.rust-lang.org/reference/type-layout.html#representations> +help: try changing it to one of the following valid forms of the attribute + | +LL - #[repr = "C"] +LL + #[repr(<integer type>)] + | +LL - #[repr = "C"] +LL + #[repr(C)] + | +LL - #[repr = "C"] +LL + #[repr(Rust)] + | +LL - #[repr = "C"] +LL + #[repr(align(...))] + | + = and 2 other candidates error: aborting due to 3 previous errors diff --git a/tests/ui/resolve/path-attr-in-const-block.stderr b/tests/ui/resolve/path-attr-in-const-block.stderr index 0b5942a287d..f3ae5b60c4f 100644 --- a/tests/ui/resolve/path-attr-in-const-block.stderr +++ b/tests/ui/resolve/path-attr-in-const-block.stderr @@ -12,6 +12,8 @@ LL | #![path = foo!()] | | | | | expected a string literal here | help: must be of the form: `#[path = "file"]` + | + = note: for more information, visit <https://doc.rust-lang.org/reference/items/modules.html#the-path-attribute> error: aborting due to 2 previous errors diff --git a/tests/ui/span/E0539.stderr b/tests/ui/span/E0539.stderr index 01f091a2676..34d81b73cb5 100644 --- a/tests/ui/span/E0539.stderr +++ b/tests/ui/span/E0539.stderr @@ -6,10 +6,14 @@ LL | #[inline(unknown)] | | | valid arguments are `always` or `never` | + = note: for more information, visit <https://doc.rust-lang.org/reference/attributes/codegen.html#the-inline-attribute> help: try changing it to one of the following valid forms of the attribute | LL - #[inline(unknown)] -LL + #[inline(always|never)] +LL + #[inline(always)] + | +LL - #[inline(unknown)] +LL + #[inline(never)] | LL - #[inline(unknown)] LL + #[inline] diff --git a/tests/ui/span/borrowck-call-is-borrow-issue-12224.stderr b/tests/ui/span/borrowck-call-is-borrow-issue-12224.stderr index f37dc320fa3..8081f7b3a8b 100644 --- a/tests/ui/span/borrowck-call-is-borrow-issue-12224.stderr +++ b/tests/ui/span/borrowck-call-is-borrow-issue-12224.stderr @@ -44,6 +44,7 @@ LL | LL | foo(f); | ^ move occurs because `f` has type `{closure@$DIR/borrowck-call-is-borrow-issue-12224.rs:52:17: 52:58}`, which does not implement the `Copy` trait | + = help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once help: consider cloning the value if the performance cost is acceptable | LL | foo(f.clone()); diff --git a/tests/ui/specialization/defaultimpl/validation.rs b/tests/ui/specialization/defaultimpl/validation.rs index 14771be8982..78f6099c3dd 100644 --- a/tests/ui/specialization/defaultimpl/validation.rs +++ b/tests/ui/specialization/defaultimpl/validation.rs @@ -4,7 +4,7 @@ struct S; struct Z; -default impl S {} //~ ERROR inherent impls cannot be `default` +default impl S {} //~ ERROR inherent impls cannot be default default unsafe impl Send for S {} //~^ ERROR impls of auto traits cannot be default diff --git a/tests/ui/specialization/defaultimpl/validation.stderr b/tests/ui/specialization/defaultimpl/validation.stderr index 82a33bf9cdc..a8dfef2dcfb 100644 --- a/tests/ui/specialization/defaultimpl/validation.stderr +++ b/tests/ui/specialization/defaultimpl/validation.stderr @@ -1,10 +1,10 @@ -error: inherent impls cannot be `default` +error: inherent impls cannot be default --> $DIR/validation.rs:7:14 | LL | default impl S {} | ------- ^ inherent impl for this type | | - | `default` because of this + | default because of this | = note: only trait implementations may be annotated with `default` diff --git a/tests/ui/issues/issue-9249.rs b/tests/ui/static/static-string-slice-9249.rs index b98ba050521..da099117bd4 100644 --- a/tests/ui/issues/issue-9249.rs +++ b/tests/ui/static/static-string-slice-9249.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/9249 //@ check-pass #![allow(dead_code)] diff --git a/tests/ui/issues/issue-16452.rs b/tests/ui/statics/conditional-static-declaration-16010.rs index 4ab74f09059..0bc5b0ee86f 100644 --- a/tests/ui/issues/issue-16452.rs +++ b/tests/ui/statics/conditional-static-declaration-16010.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/16010 + //@ run-pass #![allow(dead_code)] diff --git a/tests/ui/structs/default-field-values/auxiliary/struct_field_default.rs b/tests/ui/structs/default-field-values/auxiliary/struct_field_default.rs index b315df5dba2..a1c9645a1ae 100644 --- a/tests/ui/structs/default-field-values/auxiliary/struct_field_default.rs +++ b/tests/ui/structs/default-field-values/auxiliary/struct_field_default.rs @@ -3,3 +3,13 @@ pub struct A { pub a: isize = 42, } + +struct Priv; + +pub struct B { + pub a: Priv = Priv, +} + +pub struct C { + pub a: Priv, +} diff --git a/tests/ui/structs/default-field-values/non-exhaustive-ctor-2.rs b/tests/ui/structs/default-field-values/non-exhaustive-ctor-2.rs new file mode 100644 index 00000000000..047505c3f1c --- /dev/null +++ b/tests/ui/structs/default-field-values/non-exhaustive-ctor-2.rs @@ -0,0 +1,29 @@ +//@ aux-build:struct_field_default.rs +#![feature(default_field_values)] + +extern crate struct_field_default as xc; + +use m::S; + +mod m { + pub struct S { + pub field: () = (), + pub field1: Priv1 = Priv1 {}, + pub field2: Priv2 = Priv2, + } + struct Priv1 {} + struct Priv2; +} + +fn main() { + let _ = S { field: (), field1: m::Priv1 {} }; + //~^ ERROR missing field `field2` + //~| ERROR struct `Priv1` is private + let _ = S { field: (), field1: m::Priv1 {}, field2: m::Priv2 }; + //~^ ERROR struct `Priv1` is private + //~| ERROR unit struct `Priv2` is private + let _ = xc::B { a: xc::Priv }; + //~^ ERROR unit struct `Priv` is private + let _ = xc::C { a: xc::Priv }; + //~^ ERROR unit struct `Priv` is private +} diff --git a/tests/ui/structs/default-field-values/non-exhaustive-ctor-2.stderr b/tests/ui/structs/default-field-values/non-exhaustive-ctor-2.stderr new file mode 100644 index 00000000000..66de73561db --- /dev/null +++ b/tests/ui/structs/default-field-values/non-exhaustive-ctor-2.stderr @@ -0,0 +1,105 @@ +error[E0603]: struct `Priv1` is private + --> $DIR/non-exhaustive-ctor-2.rs:19:39 + | +LL | let _ = S { field: (), field1: m::Priv1 {} }; + | ------ ^^^^^ private struct + | | + | while setting this field + | +note: the struct `Priv1` is defined here + --> $DIR/non-exhaustive-ctor-2.rs:14:4 + | +LL | struct Priv1 {} + | ^^^^^^^^^^^^ +help: the type `Priv1` of field `field1` is private, but you can construct the default value defined for it in `S` using `..` in the struct initializer expression + | +LL - let _ = S { field: (), field1: m::Priv1 {} }; +LL + let _ = S { field: (), .. }; + | + +error[E0603]: struct `Priv1` is private + --> $DIR/non-exhaustive-ctor-2.rs:22:39 + | +LL | let _ = S { field: (), field1: m::Priv1 {}, field2: m::Priv2 }; + | ------ ^^^^^ private struct + | | + | while setting this field + | +note: the struct `Priv1` is defined here + --> $DIR/non-exhaustive-ctor-2.rs:14:4 + | +LL | struct Priv1 {} + | ^^^^^^^^^^^^ +help: the type `Priv1` of field `field1` is private, but you can construct the default value defined for it in `S` using `..` in the struct initializer expression + | +LL - let _ = S { field: (), field1: m::Priv1 {}, field2: m::Priv2 }; +LL + let _ = S { field: (), field2: m::Priv2, .. }; + | + +error[E0603]: unit struct `Priv2` is private + --> $DIR/non-exhaustive-ctor-2.rs:22:60 + | +LL | let _ = S { field: (), field1: m::Priv1 {}, field2: m::Priv2 }; + | ------ ^^^^^ private unit struct + | | + | while setting this field + | +note: the unit struct `Priv2` is defined here + --> $DIR/non-exhaustive-ctor-2.rs:15:4 + | +LL | struct Priv2; + | ^^^^^^^^^^^^^ +help: the type `Priv2` of field `field2` is private, but you can construct the default value defined for it in `S` using `..` in the struct initializer expression + | +LL - let _ = S { field: (), field1: m::Priv1 {}, field2: m::Priv2 }; +LL + let _ = S { field: (), field1: m::Priv1 {}, .. }; + | + +error[E0603]: unit struct `Priv` is private + --> $DIR/non-exhaustive-ctor-2.rs:25:28 + | +LL | let _ = xc::B { a: xc::Priv }; + | - ^^^^ private unit struct + | | + | while setting this field + | +note: the unit struct `Priv` is defined here + --> $DIR/auxiliary/struct_field_default.rs:7:1 + | +LL | struct Priv; + | ^^^^^^^^^^^ +help: the type `Priv` of field `a` is private, but you can construct the default value defined for it in `B` using `..` in the struct initializer expression + | +LL - let _ = xc::B { a: xc::Priv }; +LL + let _ = xc::B { .. }; + | + +error[E0603]: unit struct `Priv` is private + --> $DIR/non-exhaustive-ctor-2.rs:27:28 + | +LL | let _ = xc::C { a: xc::Priv }; + | - ^^^^ private unit struct + | | + | while setting this field + | +note: the unit struct `Priv` is defined here + --> $DIR/auxiliary/struct_field_default.rs:7:1 + | +LL | struct Priv; + | ^^^^^^^^^^^ + +error[E0063]: missing field `field2` in initializer of `S` + --> $DIR/non-exhaustive-ctor-2.rs:19:13 + | +LL | let _ = S { field: (), field1: m::Priv1 {} }; + | ^ missing `field2` + | +help: all remaining fields have default values, you can use those values with `..` + | +LL | let _ = S { field: (), field1: m::Priv1 {}, .. }; + | ++++ + +error: aborting due to 6 previous errors + +Some errors have detailed explanations: E0063, E0603. +For more information about an error, try `rustc --explain E0063`. diff --git a/tests/ui/issues/issue-24365.rs b/tests/ui/structs/struct-field-access-errors-24365.rs index da195116047..13a95cd1cca 100644 --- a/tests/ui/issues/issue-24365.rs +++ b/tests/ui/structs/struct-field-access-errors-24365.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/24365 pub enum Attribute { Code {attr_name_idx: u16}, } diff --git a/tests/ui/issues/issue-24365.stderr b/tests/ui/structs/struct-field-access-errors-24365.stderr index 3f6ed0231d8..65275af4701 100644 --- a/tests/ui/issues/issue-24365.stderr +++ b/tests/ui/structs/struct-field-access-errors-24365.stderr @@ -1,17 +1,17 @@ error[E0609]: no field `b` on type `Foo` - --> $DIR/issue-24365.rs:10:22 + --> $DIR/struct-field-access-errors-24365.rs:11:22 | LL | println!("{}", a.b); | ^ unknown field error[E0609]: no field `attr_name_idx` on type `&Attribute` - --> $DIR/issue-24365.rs:17:18 + --> $DIR/struct-field-access-errors-24365.rs:18:18 | LL | let z = (&x).attr_name_idx; | ^^^^^^^^^^^^^ unknown field error[E0609]: no field `attr_name_idx` on type `Attribute` - --> $DIR/issue-24365.rs:18:15 + --> $DIR/struct-field-access-errors-24365.rs:19:15 | LL | let y = x.attr_name_idx; | ^^^^^^^^^^^^^ unknown field diff --git a/tests/ui/suggestions/dont-suggest-ref/move-into-closure.rs b/tests/ui/suggestions/dont-suggest-ref/move-into-closure.rs index 44eac3691a3..34088f219b2 100644 --- a/tests/ui/suggestions/dont-suggest-ref/move-into-closure.rs +++ b/tests/ui/suggestions/dont-suggest-ref/move-into-closure.rs @@ -11,8 +11,55 @@ struct X(Y); struct Y; fn consume_fn<F: Fn()>(_f: F) { } +//~^ HELP `Fn` and `FnMut` closures +//~| HELP `Fn` and `FnMut` closures +//~| HELP `Fn` and `FnMut` closures +//~| HELP `Fn` and `FnMut` closures +//~| HELP `Fn` and `FnMut` closures +//~| HELP `Fn` and `FnMut` closures +//~| HELP `Fn` and `FnMut` closures +//~| HELP `Fn` and `FnMut` closures +//~| HELP `Fn` and `FnMut` closures +//~| HELP `Fn` and `FnMut` closures fn consume_fnmut<F: FnMut()>(_f: F) { } +//~^ HELP `Fn` and `FnMut` closures +//~| HELP `Fn` and `FnMut` closures +//~| HELP `Fn` and `FnMut` closures +//~| HELP `Fn` and `FnMut` closures +//~| HELP `Fn` and `FnMut` closures +//~| HELP `Fn` and `FnMut` closures +//~| HELP `Fn` and `FnMut` closures +//~| HELP `Fn` and `FnMut` closures +//~| HELP `Fn` and `FnMut` closures +//~| HELP `Fn` and `FnMut` closures +//~| HELP `Fn` and `FnMut` closures + +trait T { + fn consume_fn<F: Fn()>(_f: F) { } + //~^ HELP `Fn` and `FnMut` closures + //~| HELP `Fn` and `FnMut` closures + //~| HELP `Fn` and `FnMut` closures + //~| HELP `Fn` and `FnMut` closures + //~| HELP `Fn` and `FnMut` closures + //~| HELP `Fn` and `FnMut` closures + //~| HELP `Fn` and `FnMut` closures + //~| HELP `Fn` and `FnMut` closures + //~| HELP `Fn` and `FnMut` closures + //~| HELP `Fn` and `FnMut` closures + fn method_consume_fn<F: Fn()>(&self, _f: F) { } + //~^ HELP `Fn` and `FnMut` closures + //~| HELP `Fn` and `FnMut` closures + //~| HELP `Fn` and `FnMut` closures + //~| HELP `Fn` and `FnMut` closures + //~| HELP `Fn` and `FnMut` closures + //~| HELP `Fn` and `FnMut` closures + //~| HELP `Fn` and `FnMut` closures + //~| HELP `Fn` and `FnMut` closures + //~| HELP `Fn` and `FnMut` closures + //~| HELP `Fn` and `FnMut` closures +} +impl T for () {} pub fn main() { } @@ -73,6 +120,120 @@ fn move_into_fn() { }); } +fn move_into_assoc_fn() { + let e = Either::One(X(Y)); + let mut em = Either::One(X(Y)); + + let x = X(Y); + + // move into Fn + + <() as T>::consume_fn(|| { + let X(_t) = x; + //~^ ERROR cannot move + //~| HELP consider borrowing here + if let Either::One(_t) = e { } + //~^ ERROR cannot move + //~| HELP consider borrowing here + while let Either::One(_t) = e { } + //~^ ERROR cannot move + //~| HELP consider borrowing here + match e { + //~^ ERROR cannot move + //~| HELP consider borrowing here + Either::One(_t) + | Either::Two(_t) => (), + } + match e { + //~^ ERROR cannot move + //~| HELP consider borrowing here + Either::One(_t) => (), + Either::Two(ref _t) => (), + // FIXME: should suggest removing `ref` too + } + + let X(mut _t) = x; + //~^ ERROR cannot move + //~| HELP consider borrowing here + if let Either::One(mut _t) = em { } + //~^ ERROR cannot move + //~| HELP consider borrowing here + while let Either::One(mut _t) = em { } + //~^ ERROR cannot move + //~| HELP consider borrowing here + match em { + //~^ ERROR cannot move + //~| HELP consider borrowing here + Either::One(mut _t) + | Either::Two(mut _t) => (), + } + match em { + //~^ ERROR cannot move + //~| HELP consider borrowing here + Either::One(mut _t) => (), + Either::Two(ref _t) => (), + // FIXME: should suggest removing `ref` too + } + }); +} + +fn move_into_method() { + let e = Either::One(X(Y)); + let mut em = Either::One(X(Y)); + + let x = X(Y); + + // move into Fn + + ().method_consume_fn(|| { + let X(_t) = x; + //~^ ERROR cannot move + //~| HELP consider borrowing here + if let Either::One(_t) = e { } + //~^ ERROR cannot move + //~| HELP consider borrowing here + while let Either::One(_t) = e { } + //~^ ERROR cannot move + //~| HELP consider borrowing here + match e { + //~^ ERROR cannot move + //~| HELP consider borrowing here + Either::One(_t) + | Either::Two(_t) => (), + } + match e { + //~^ ERROR cannot move + //~| HELP consider borrowing here + Either::One(_t) => (), + Either::Two(ref _t) => (), + // FIXME: should suggest removing `ref` too + } + + let X(mut _t) = x; + //~^ ERROR cannot move + //~| HELP consider borrowing here + if let Either::One(mut _t) = em { } + //~^ ERROR cannot move + //~| HELP consider borrowing here + while let Either::One(mut _t) = em { } + //~^ ERROR cannot move + //~| HELP consider borrowing here + match em { + //~^ ERROR cannot move + //~| HELP consider borrowing here + Either::One(mut _t) + | Either::Two(mut _t) => (), + } + match em { + //~^ ERROR cannot move + //~| HELP consider borrowing here + Either::One(mut _t) => (), + Either::Two(ref _t) => (), + // FIXME: should suggest removing `ref` too + } + }); +} + fn move_into_fnmut() { let e = Either::One(X(Y)); let mut em = Either::One(X(Y)); diff --git a/tests/ui/suggestions/dont-suggest-ref/move-into-closure.stderr b/tests/ui/suggestions/dont-suggest-ref/move-into-closure.stderr index edda2cbc735..132a31c8f7c 100644 --- a/tests/ui/suggestions/dont-suggest-ref/move-into-closure.stderr +++ b/tests/ui/suggestions/dont-suggest-ref/move-into-closure.stderr @@ -1,5 +1,5 @@ error[E0507]: cannot move out of `x.0`, as `x` is a captured variable in an `Fn` closure - --> $DIR/move-into-closure.rs:28:21 + --> $DIR/move-into-closure.rs:75:21 | LL | let x = X(Y); | - captured outer variable @@ -12,13 +12,18 @@ LL | let X(_t) = x; | data moved here | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:13:18 + | +LL | fn consume_fn<F: Fn()>(_f: F) { } + | ^^^^ help: consider borrowing here | LL | let X(_t) = &x; | + error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure - --> $DIR/move-into-closure.rs:31:34 + --> $DIR/move-into-closure.rs:78:34 | LL | let e = Either::One(X(Y)); | - captured outer variable @@ -32,13 +37,18 @@ LL | if let Either::One(_t) = e { } | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:13:18 + | +LL | fn consume_fn<F: Fn()>(_f: F) { } + | ^^^^ help: consider borrowing here | LL | if let Either::One(_t) = &e { } | + error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure - --> $DIR/move-into-closure.rs:34:37 + --> $DIR/move-into-closure.rs:81:37 | LL | let e = Either::One(X(Y)); | - captured outer variable @@ -52,13 +62,18 @@ LL | while let Either::One(_t) = e { } | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:13:18 + | +LL | fn consume_fn<F: Fn()>(_f: F) { } + | ^^^^ help: consider borrowing here | LL | while let Either::One(_t) = &e { } | + error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure - --> $DIR/move-into-closure.rs:37:15 + --> $DIR/move-into-closure.rs:84:15 | LL | let e = Either::One(X(Y)); | - captured outer variable @@ -75,13 +90,18 @@ LL | Either::One(_t) | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:13:18 + | +LL | fn consume_fn<F: Fn()>(_f: F) { } + | ^^^^ help: consider borrowing here | LL | match &e { | + error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure - --> $DIR/move-into-closure.rs:43:15 + --> $DIR/move-into-closure.rs:90:15 | LL | let e = Either::One(X(Y)); | - captured outer variable @@ -98,13 +118,18 @@ LL | Either::One(_t) => (), | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:13:18 + | +LL | fn consume_fn<F: Fn()>(_f: F) { } + | ^^^^ help: consider borrowing here | LL | match &e { | + error[E0507]: cannot move out of `x.0`, as `x` is a captured variable in an `Fn` closure - --> $DIR/move-into-closure.rs:51:25 + --> $DIR/move-into-closure.rs:98:25 | LL | let x = X(Y); | - captured outer variable @@ -118,13 +143,18 @@ LL | let X(mut _t) = x; | data moved here | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:13:18 + | +LL | fn consume_fn<F: Fn()>(_f: F) { } + | ^^^^ help: consider borrowing here | LL | let X(mut _t) = &x; | + error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure - --> $DIR/move-into-closure.rs:54:38 + --> $DIR/move-into-closure.rs:101:38 | LL | let mut em = Either::One(X(Y)); | ------ captured outer variable @@ -138,13 +168,18 @@ LL | if let Either::One(mut _t) = em { } | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:13:18 + | +LL | fn consume_fn<F: Fn()>(_f: F) { } + | ^^^^ help: consider borrowing here | LL | if let Either::One(mut _t) = &em { } | + error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure - --> $DIR/move-into-closure.rs:57:41 + --> $DIR/move-into-closure.rs:104:41 | LL | let mut em = Either::One(X(Y)); | ------ captured outer variable @@ -158,13 +193,18 @@ LL | while let Either::One(mut _t) = em { } | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:13:18 + | +LL | fn consume_fn<F: Fn()>(_f: F) { } + | ^^^^ help: consider borrowing here | LL | while let Either::One(mut _t) = &em { } | + error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure - --> $DIR/move-into-closure.rs:60:15 + --> $DIR/move-into-closure.rs:107:15 | LL | let mut em = Either::One(X(Y)); | ------ captured outer variable @@ -181,13 +221,18 @@ LL | Either::One(mut _t) | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:13:18 + | +LL | fn consume_fn<F: Fn()>(_f: F) { } + | ^^^^ help: consider borrowing here | LL | match &em { | + error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure - --> $DIR/move-into-closure.rs:66:15 + --> $DIR/move-into-closure.rs:113:15 | LL | let mut em = Either::One(X(Y)); | ------ captured outer variable @@ -204,13 +249,540 @@ LL | Either::One(mut _t) => (), | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:13:18 + | +LL | fn consume_fn<F: Fn()>(_f: F) { } + | ^^^^ +help: consider borrowing here + | +LL | match &em { + | + + +error[E0507]: cannot move out of `x.0`, as `x` is a captured variable in an `Fn` closure + --> $DIR/move-into-closure.rs:132:21 + | +LL | let x = X(Y); + | - captured outer variable +... +LL | <() as T>::consume_fn(|| { + | -- captured by this `Fn` closure +LL | let X(_t) = x; + | -- ^ + | | + | data moved here + | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:39:22 + | +LL | fn consume_fn<F: Fn()>(_f: F) { } + | ^^^^ +help: consider borrowing here + | +LL | let X(_t) = &x; + | + + +error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure + --> $DIR/move-into-closure.rs:135:34 + | +LL | let e = Either::One(X(Y)); + | - captured outer variable +... +LL | <() as T>::consume_fn(|| { + | -- captured by this `Fn` closure +... +LL | if let Either::One(_t) = e { } + | -- ^ + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:39:22 + | +LL | fn consume_fn<F: Fn()>(_f: F) { } + | ^^^^ +help: consider borrowing here + | +LL | if let Either::One(_t) = &e { } + | + + +error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure + --> $DIR/move-into-closure.rs:138:37 + | +LL | let e = Either::One(X(Y)); + | - captured outer variable +... +LL | <() as T>::consume_fn(|| { + | -- captured by this `Fn` closure +... +LL | while let Either::One(_t) = e { } + | -- ^ + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:39:22 + | +LL | fn consume_fn<F: Fn()>(_f: F) { } + | ^^^^ +help: consider borrowing here + | +LL | while let Either::One(_t) = &e { } + | + + +error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure + --> $DIR/move-into-closure.rs:141:15 + | +LL | let e = Either::One(X(Y)); + | - captured outer variable +... +LL | <() as T>::consume_fn(|| { + | -- captured by this `Fn` closure +... +LL | match e { + | ^ +... +LL | Either::One(_t) + | -- + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:39:22 + | +LL | fn consume_fn<F: Fn()>(_f: F) { } + | ^^^^ +help: consider borrowing here + | +LL | match &e { + | + + +error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure + --> $DIR/move-into-closure.rs:147:15 + | +LL | let e = Either::One(X(Y)); + | - captured outer variable +... +LL | <() as T>::consume_fn(|| { + | -- captured by this `Fn` closure +... +LL | match e { + | ^ +... +LL | Either::One(_t) => (), + | -- + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:39:22 + | +LL | fn consume_fn<F: Fn()>(_f: F) { } + | ^^^^ +help: consider borrowing here + | +LL | match &e { + | + + +error[E0507]: cannot move out of `x.0`, as `x` is a captured variable in an `Fn` closure + --> $DIR/move-into-closure.rs:155:25 + | +LL | let x = X(Y); + | - captured outer variable +... +LL | <() as T>::consume_fn(|| { + | -- captured by this `Fn` closure +... +LL | let X(mut _t) = x; + | ------ ^ + | | + | data moved here + | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:39:22 + | +LL | fn consume_fn<F: Fn()>(_f: F) { } + | ^^^^ +help: consider borrowing here + | +LL | let X(mut _t) = &x; + | + + +error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure + --> $DIR/move-into-closure.rs:158:38 + | +LL | let mut em = Either::One(X(Y)); + | ------ captured outer variable +... +LL | <() as T>::consume_fn(|| { + | -- captured by this `Fn` closure +... +LL | if let Either::One(mut _t) = em { } + | ------ ^^ + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:39:22 + | +LL | fn consume_fn<F: Fn()>(_f: F) { } + | ^^^^ +help: consider borrowing here + | +LL | if let Either::One(mut _t) = &em { } + | + + +error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure + --> $DIR/move-into-closure.rs:161:41 + | +LL | let mut em = Either::One(X(Y)); + | ------ captured outer variable +... +LL | <() as T>::consume_fn(|| { + | -- captured by this `Fn` closure +... +LL | while let Either::One(mut _t) = em { } + | ------ ^^ + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:39:22 + | +LL | fn consume_fn<F: Fn()>(_f: F) { } + | ^^^^ +help: consider borrowing here + | +LL | while let Either::One(mut _t) = &em { } + | + + +error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure + --> $DIR/move-into-closure.rs:164:15 + | +LL | let mut em = Either::One(X(Y)); + | ------ captured outer variable +... +LL | <() as T>::consume_fn(|| { + | -- captured by this `Fn` closure +... +LL | match em { + | ^^ +... +LL | Either::One(mut _t) + | ------ + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:39:22 + | +LL | fn consume_fn<F: Fn()>(_f: F) { } + | ^^^^ +help: consider borrowing here + | +LL | match &em { + | + + +error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure + --> $DIR/move-into-closure.rs:170:15 + | +LL | let mut em = Either::One(X(Y)); + | ------ captured outer variable +... +LL | <() as T>::consume_fn(|| { + | -- captured by this `Fn` closure +... +LL | match em { + | ^^ +... +LL | Either::One(mut _t) => (), + | ------ + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:39:22 + | +LL | fn consume_fn<F: Fn()>(_f: F) { } + | ^^^^ +help: consider borrowing here + | +LL | match &em { + | + + +error[E0507]: cannot move out of `x.0`, as `x` is a captured variable in an `Fn` closure + --> $DIR/move-into-closure.rs:189:21 + | +LL | let x = X(Y); + | - captured outer variable +... +LL | ().method_consume_fn(|| { + | -- captured by this `Fn` closure +LL | let X(_t) = x; + | -- ^ + | | + | data moved here + | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:50:29 + | +LL | fn method_consume_fn<F: Fn()>(&self, _f: F) { } + | ^^^^ +help: consider borrowing here + | +LL | let X(_t) = &x; + | + + +error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure + --> $DIR/move-into-closure.rs:192:34 + | +LL | let e = Either::One(X(Y)); + | - captured outer variable +... +LL | ().method_consume_fn(|| { + | -- captured by this `Fn` closure +... +LL | if let Either::One(_t) = e { } + | -- ^ + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:50:29 + | +LL | fn method_consume_fn<F: Fn()>(&self, _f: F) { } + | ^^^^ +help: consider borrowing here + | +LL | if let Either::One(_t) = &e { } + | + + +error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure + --> $DIR/move-into-closure.rs:195:37 + | +LL | let e = Either::One(X(Y)); + | - captured outer variable +... +LL | ().method_consume_fn(|| { + | -- captured by this `Fn` closure +... +LL | while let Either::One(_t) = e { } + | -- ^ + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:50:29 + | +LL | fn method_consume_fn<F: Fn()>(&self, _f: F) { } + | ^^^^ +help: consider borrowing here + | +LL | while let Either::One(_t) = &e { } + | + + +error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure + --> $DIR/move-into-closure.rs:198:15 + | +LL | let e = Either::One(X(Y)); + | - captured outer variable +... +LL | ().method_consume_fn(|| { + | -- captured by this `Fn` closure +... +LL | match e { + | ^ +... +LL | Either::One(_t) + | -- + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:50:29 + | +LL | fn method_consume_fn<F: Fn()>(&self, _f: F) { } + | ^^^^ +help: consider borrowing here + | +LL | match &e { + | + + +error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `Fn` closure + --> $DIR/move-into-closure.rs:204:15 + | +LL | let e = Either::One(X(Y)); + | - captured outer variable +... +LL | ().method_consume_fn(|| { + | -- captured by this `Fn` closure +... +LL | match e { + | ^ +... +LL | Either::One(_t) => (), + | -- + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:50:29 + | +LL | fn method_consume_fn<F: Fn()>(&self, _f: F) { } + | ^^^^ +help: consider borrowing here + | +LL | match &e { + | + + +error[E0507]: cannot move out of `x.0`, as `x` is a captured variable in an `Fn` closure + --> $DIR/move-into-closure.rs:212:25 + | +LL | let x = X(Y); + | - captured outer variable +... +LL | ().method_consume_fn(|| { + | -- captured by this `Fn` closure +... +LL | let X(mut _t) = x; + | ------ ^ + | | + | data moved here + | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait + | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:50:29 + | +LL | fn method_consume_fn<F: Fn()>(&self, _f: F) { } + | ^^^^ +help: consider borrowing here + | +LL | let X(mut _t) = &x; + | + + +error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure + --> $DIR/move-into-closure.rs:215:38 + | +LL | let mut em = Either::One(X(Y)); + | ------ captured outer variable +... +LL | ().method_consume_fn(|| { + | -- captured by this `Fn` closure +... +LL | if let Either::One(mut _t) = em { } + | ------ ^^ + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:50:29 + | +LL | fn method_consume_fn<F: Fn()>(&self, _f: F) { } + | ^^^^ +help: consider borrowing here + | +LL | if let Either::One(mut _t) = &em { } + | + + +error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure + --> $DIR/move-into-closure.rs:218:41 + | +LL | let mut em = Either::One(X(Y)); + | ------ captured outer variable +... +LL | ().method_consume_fn(|| { + | -- captured by this `Fn` closure +... +LL | while let Either::One(mut _t) = em { } + | ------ ^^ + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:50:29 + | +LL | fn method_consume_fn<F: Fn()>(&self, _f: F) { } + | ^^^^ +help: consider borrowing here + | +LL | while let Either::One(mut _t) = &em { } + | + + +error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure + --> $DIR/move-into-closure.rs:221:15 + | +LL | let mut em = Either::One(X(Y)); + | ------ captured outer variable +... +LL | ().method_consume_fn(|| { + | -- captured by this `Fn` closure +... +LL | match em { + | ^^ +... +LL | Either::One(mut _t) + | ------ + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:50:29 + | +LL | fn method_consume_fn<F: Fn()>(&self, _f: F) { } + | ^^^^ +help: consider borrowing here + | +LL | match &em { + | + + +error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `Fn` closure + --> $DIR/move-into-closure.rs:227:15 + | +LL | let mut em = Either::One(X(Y)); + | ------ captured outer variable +... +LL | ().method_consume_fn(|| { + | -- captured by this `Fn` closure +... +LL | match em { + | ^^ +... +LL | Either::One(mut _t) => (), + | ------ + | | + | data moved here + | move occurs because `_t` has type `X`, which does not implement the `Copy` trait + | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:50:29 + | +LL | fn method_consume_fn<F: Fn()>(&self, _f: F) { } + | ^^^^ help: consider borrowing here | LL | match &em { | + error[E0507]: cannot move out of `x.0`, as `x` is a captured variable in an `FnMut` closure - --> $DIR/move-into-closure.rs:85:21 + --> $DIR/move-into-closure.rs:246:21 | LL | let x = X(Y); | - captured outer variable @@ -223,13 +795,18 @@ LL | let X(_t) = x; | data moved here | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:25:21 + | +LL | fn consume_fnmut<F: FnMut()>(_f: F) { } + | ^^^^^^^ help: consider borrowing here | LL | let X(_t) = &x; | + error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `FnMut` closure - --> $DIR/move-into-closure.rs:88:34 + --> $DIR/move-into-closure.rs:249:34 | LL | let e = Either::One(X(Y)); | - captured outer variable @@ -243,13 +820,18 @@ LL | if let Either::One(_t) = e { } | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:25:21 + | +LL | fn consume_fnmut<F: FnMut()>(_f: F) { } + | ^^^^^^^ help: consider borrowing here | LL | if let Either::One(_t) = &e { } | + error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `FnMut` closure - --> $DIR/move-into-closure.rs:91:37 + --> $DIR/move-into-closure.rs:252:37 | LL | let e = Either::One(X(Y)); | - captured outer variable @@ -263,13 +845,18 @@ LL | while let Either::One(_t) = e { } | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:25:21 + | +LL | fn consume_fnmut<F: FnMut()>(_f: F) { } + | ^^^^^^^ help: consider borrowing here | LL | while let Either::One(_t) = &e { } | + error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `FnMut` closure - --> $DIR/move-into-closure.rs:94:15 + --> $DIR/move-into-closure.rs:255:15 | LL | let e = Either::One(X(Y)); | - captured outer variable @@ -286,13 +873,18 @@ LL | Either::One(_t) | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:25:21 + | +LL | fn consume_fnmut<F: FnMut()>(_f: F) { } + | ^^^^^^^ help: consider borrowing here | LL | match &e { | + error[E0507]: cannot move out of `e.0`, as `e` is a captured variable in an `FnMut` closure - --> $DIR/move-into-closure.rs:100:15 + --> $DIR/move-into-closure.rs:261:15 | LL | let e = Either::One(X(Y)); | - captured outer variable @@ -309,13 +901,18 @@ LL | Either::One(_t) => (), | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:25:21 + | +LL | fn consume_fnmut<F: FnMut()>(_f: F) { } + | ^^^^^^^ help: consider borrowing here | LL | match &e { | + error[E0507]: cannot move out of `x.0`, as `x` is a captured variable in an `FnMut` closure - --> $DIR/move-into-closure.rs:108:25 + --> $DIR/move-into-closure.rs:269:25 | LL | let x = X(Y); | - captured outer variable @@ -329,13 +926,18 @@ LL | let X(mut _t) = x; | data moved here | move occurs because `_t` has type `Y`, which does not implement the `Copy` trait | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:25:21 + | +LL | fn consume_fnmut<F: FnMut()>(_f: F) { } + | ^^^^^^^ help: consider borrowing here | LL | let X(mut _t) = &x; | + error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `FnMut` closure - --> $DIR/move-into-closure.rs:111:38 + --> $DIR/move-into-closure.rs:272:38 | LL | let mut em = Either::One(X(Y)); | ------ captured outer variable @@ -349,13 +951,18 @@ LL | if let Either::One(mut _t) = em { } | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:25:21 + | +LL | fn consume_fnmut<F: FnMut()>(_f: F) { } + | ^^^^^^^ help: consider borrowing here | LL | if let Either::One(mut _t) = &em { } | + error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `FnMut` closure - --> $DIR/move-into-closure.rs:114:41 + --> $DIR/move-into-closure.rs:275:41 | LL | let mut em = Either::One(X(Y)); | ------ captured outer variable @@ -369,13 +976,18 @@ LL | while let Either::One(mut _t) = em { } | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:25:21 + | +LL | fn consume_fnmut<F: FnMut()>(_f: F) { } + | ^^^^^^^ help: consider borrowing here | LL | while let Either::One(mut _t) = &em { } | + error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `FnMut` closure - --> $DIR/move-into-closure.rs:117:15 + --> $DIR/move-into-closure.rs:278:15 | LL | let mut em = Either::One(X(Y)); | ------ captured outer variable @@ -392,13 +1004,18 @@ LL | Either::One(mut _t) | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:25:21 + | +LL | fn consume_fnmut<F: FnMut()>(_f: F) { } + | ^^^^^^^ help: consider borrowing here | LL | match &em { | + error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `FnMut` closure - --> $DIR/move-into-closure.rs:123:15 + --> $DIR/move-into-closure.rs:284:15 | LL | let mut em = Either::One(X(Y)); | ------ captured outer variable @@ -415,13 +1032,18 @@ LL | Either::One(mut _t) => (), | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:25:21 + | +LL | fn consume_fnmut<F: FnMut()>(_f: F) { } + | ^^^^^^^ help: consider borrowing here | LL | match &em { | + error[E0507]: cannot move out of `em.0`, as `em` is a captured variable in an `FnMut` closure - --> $DIR/move-into-closure.rs:130:15 + --> $DIR/move-into-closure.rs:291:15 | LL | let mut em = Either::One(X(Y)); | ------ captured outer variable @@ -438,11 +1060,16 @@ LL | Either::One(mut _t) => (), | data moved here | move occurs because `_t` has type `X`, which does not implement the `Copy` trait | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/move-into-closure.rs:25:21 + | +LL | fn consume_fnmut<F: FnMut()>(_f: F) { } + | ^^^^^^^ help: consider borrowing here | LL | match &em { | + -error: aborting due to 21 previous errors +error: aborting due to 41 previous errors For more information about this error, try `rustc --explain E0507`. diff --git a/tests/ui/suggestions/option-content-move2.stderr b/tests/ui/suggestions/option-content-move2.stderr index c73e874b403..c8aa6667b58 100644 --- a/tests/ui/suggestions/option-content-move2.stderr +++ b/tests/ui/suggestions/option-content-move2.stderr @@ -14,6 +14,11 @@ LL | LL | var = Some(NotCopyable); | --- variable moved due to use in closure | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/option-content-move2.rs:5:12 + | +LL | fn func<F: FnMut() -> H, H: FnMut()>(_: F) {} + | ^^^^^^^^^^^^ note: if `NotCopyable` implemented `Clone`, you could clone the value --> $DIR/option-content-move2.rs:1:1 | @@ -38,6 +43,12 @@ LL | move || { LL | LL | var = Some(NotCopyableButCloneable); | --- variable moved due to use in closure + | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/option-content-move2.rs:5:12 + | +LL | fn func<F: FnMut() -> H, H: FnMut()>(_: F) {} + | ^^^^^^^^^^^^ error: aborting due to 2 previous errors diff --git a/tests/ui/suggestions/option-content-move3.stderr b/tests/ui/suggestions/option-content-move3.stderr index 68c52352a65..2c9a86c036b 100644 --- a/tests/ui/suggestions/option-content-move3.stderr +++ b/tests/ui/suggestions/option-content-move3.stderr @@ -9,6 +9,7 @@ LL | move || { LL | let x = var; | ^^^ move occurs because `var` has type `NotCopyable`, which does not implement the `Copy` trait | + = help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once note: if `NotCopyable` implemented `Clone`, you could clone the value --> $DIR/option-content-move3.rs:2:1 | @@ -37,6 +38,11 @@ LL | move || { LL | let x = var; | --- variable moved due to use in closure | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/option-content-move3.rs:6:12 + | +LL | fn func<F: FnMut() -> H, H: FnMut()>(_: F) {} + | ^^^^^^^^^^^^ note: if `NotCopyable` implemented `Clone`, you could clone the value --> $DIR/option-content-move3.rs:2:1 | @@ -57,6 +63,7 @@ LL | move || { LL | let x = var; | ^^^ move occurs because `var` has type `NotCopyableButCloneable`, which does not implement the `Copy` trait | + = help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once help: consider borrowing here | LL | let x = &var; @@ -77,6 +84,11 @@ LL | move || { LL | let x = var; | --- variable moved due to use in closure | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/option-content-move3.rs:6:12 + | +LL | fn func<F: FnMut() -> H, H: FnMut()>(_: F) {} + | ^^^^^^^^^^^^ help: consider cloning the value before moving it into the closure | LL ~ { diff --git a/tests/ui/test-attrs/test-should-panic-attr.rs b/tests/ui/test-attrs/test-should-panic-attr.rs index af54689551c..e6de07d0094 100644 --- a/tests/ui/test-attrs/test-should-panic-attr.rs +++ b/tests/ui/test-attrs/test-should-panic-attr.rs @@ -10,6 +10,7 @@ fn test1() { #[should_panic(expected)] //~^ ERROR malformed `should_panic` attribute input //~| NOTE expected this to be of the form `expected = "..."` +//~| NOTE for more information, visit fn test2() { panic!(); } @@ -18,6 +19,7 @@ fn test2() { #[should_panic(expect)] //~^ ERROR malformed `should_panic` attribute input //~| NOTE the only valid argument here is "expected" +//~| NOTE for more information, visit fn test3() { panic!(); } @@ -26,6 +28,7 @@ fn test3() { #[should_panic(expected(foo, bar))] //~^ ERROR malformed `should_panic` attribute input //~| NOTE expected this to be of the form `expected = "..."` +//~| NOTE for more information, visit fn test4() { panic!(); } @@ -34,6 +37,7 @@ fn test4() { #[should_panic(expected = "foo", bar)] //~^ ERROR malformed `should_panic` attribute input //~| NOTE expected a single argument here +//~| NOTE for more information, visit fn test5() { panic!(); } diff --git a/tests/ui/test-attrs/test-should-panic-attr.stderr b/tests/ui/test-attrs/test-should-panic-attr.stderr index 5dfc8e503e8..475a55ad0cb 100644 --- a/tests/ui/test-attrs/test-should-panic-attr.stderr +++ b/tests/ui/test-attrs/test-should-panic-attr.stderr @@ -6,6 +6,7 @@ LL | #[should_panic(expected)] | | | expected this to be of the form `expected = "..."` | + = note: for more information, visit <https://doc.rust-lang.org/reference/attributes/testing.html#the-should_panic-attribute> help: try changing it to one of the following valid forms of the attribute | LL - #[should_panic(expected)] @@ -18,13 +19,14 @@ LL + #[should_panic] | error[E0539]: malformed `should_panic` attribute input - --> $DIR/test-should-panic-attr.rs:18:1 + --> $DIR/test-should-panic-attr.rs:19:1 | LL | #[should_panic(expect)] | ^^^^^^^^^^^^^^--------^ | | | the only valid argument here is "expected" | + = note: for more information, visit <https://doc.rust-lang.org/reference/attributes/testing.html#the-should_panic-attribute> help: try changing it to one of the following valid forms of the attribute | LL - #[should_panic(expect)] @@ -37,13 +39,14 @@ LL + #[should_panic] | error[E0539]: malformed `should_panic` attribute input - --> $DIR/test-should-panic-attr.rs:26:1 + --> $DIR/test-should-panic-attr.rs:28:1 | LL | #[should_panic(expected(foo, bar))] | ^^^^^^^^^^^^^^^------------------^^ | | | expected this to be of the form `expected = "..."` | + = note: for more information, visit <https://doc.rust-lang.org/reference/attributes/testing.html#the-should_panic-attribute> help: try changing it to one of the following valid forms of the attribute | LL - #[should_panic(expected(foo, bar))] @@ -57,13 +60,14 @@ LL + #[should_panic] | error[E0805]: malformed `should_panic` attribute input - --> $DIR/test-should-panic-attr.rs:34:1 + --> $DIR/test-should-panic-attr.rs:37:1 | LL | #[should_panic(expected = "foo", bar)] | ^^^^^^^^^^^^^^-----------------------^ | | | expected a single argument here | + = note: for more information, visit <https://doc.rust-lang.org/reference/attributes/testing.html#the-should_panic-attribute> help: try changing it to one of the following valid forms of the attribute | LL - #[should_panic(expected = "foo", bar)] diff --git a/tests/ui/issues/issue-30756.rs b/tests/ui/thread-local/thread-local-with-attributes-30756.rs index d103776406c..fcf7bb813c8 100644 --- a/tests/ui/issues/issue-30756.rs +++ b/tests/ui/thread-local/thread-local-with-attributes-30756.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/30756 //@ run-pass #![forbid(unsafe_code)] diff --git a/tests/ui/trait-bounds/more_maybe_bounds.rs b/tests/ui/trait-bounds/more_maybe_bounds.rs index 47348b0a0dd..d367dd5b299 100644 --- a/tests/ui/trait-bounds/more_maybe_bounds.rs +++ b/tests/ui/trait-bounds/more_maybe_bounds.rs @@ -1,7 +1,7 @@ // FIXME(more_maybe_bounds): Even under `more_maybe_bounds` / `-Zexperimental-default-bounds`, // trying to relax non-default bounds should still be an error in all contexts! As you can see -// there are places like supertrait bounds and trait object types where we currently don't perform -// this check. +// there are places like supertrait bounds, trait object types or associated type bounds (ATB) +// where we currently don't perform this check. #![feature(auto_traits, more_maybe_bounds, negative_impls)] trait Trait1 {} @@ -13,11 +13,15 @@ trait Trait4 where Self: Trait1 {} // FIXME: `?Trait2` should be rejected, `Trait2` isn't marked `#[lang = "default_traitN"]`. fn foo(_: Box<(dyn Trait3 + ?Trait2)>) {} + fn bar<T: ?Sized + ?Trait2 + ?Trait1 + ?Trait4>(_: &T) {} //~^ ERROR bound modifier `?` can only be applied to default traits like `Sized` //~| ERROR bound modifier `?` can only be applied to default traits like `Sized` //~| ERROR bound modifier `?` can only be applied to default traits like `Sized` +// FIXME: `?Trait1` should be rejected, `Trait1` isn't marked `#[lang = "default_traitN"]`. +fn baz<T>() where T: Iterator<Item: ?Trait1> {} + struct S; impl !Trait2 for S {} impl Trait1 for S {} diff --git a/tests/ui/trait-bounds/more_maybe_bounds.stderr b/tests/ui/trait-bounds/more_maybe_bounds.stderr index 09c9fc31165..8dd83fc7728 100644 --- a/tests/ui/trait-bounds/more_maybe_bounds.stderr +++ b/tests/ui/trait-bounds/more_maybe_bounds.stderr @@ -1,17 +1,17 @@ error: bound modifier `?` can only be applied to default traits like `Sized` - --> $DIR/more_maybe_bounds.rs:16:20 + --> $DIR/more_maybe_bounds.rs:17:20 | LL | fn bar<T: ?Sized + ?Trait2 + ?Trait1 + ?Trait4>(_: &T) {} | ^^^^^^^ error: bound modifier `?` can only be applied to default traits like `Sized` - --> $DIR/more_maybe_bounds.rs:16:30 + --> $DIR/more_maybe_bounds.rs:17:30 | LL | fn bar<T: ?Sized + ?Trait2 + ?Trait1 + ?Trait4>(_: &T) {} | ^^^^^^^ error: bound modifier `?` can only be applied to default traits like `Sized` - --> $DIR/more_maybe_bounds.rs:16:40 + --> $DIR/more_maybe_bounds.rs:17:40 | LL | fn bar<T: ?Sized + ?Trait2 + ?Trait1 + ?Trait4>(_: &T) {} | ^^^^^^^ diff --git a/tests/ui/traits/const-traits/inherent-impl.rs b/tests/ui/traits/const-traits/inherent-impl.rs index 07b23adf9e1..5ca4c5d7863 100644 --- a/tests/ui/traits/const-traits/inherent-impl.rs +++ b/tests/ui/traits/const-traits/inherent-impl.rs @@ -5,9 +5,9 @@ struct S; trait T {} impl const S {} -//~^ ERROR inherent impls cannot be `const` +//~^ ERROR inherent impls cannot be const impl const dyn T {} -//~^ ERROR inherent impls cannot be `const` +//~^ ERROR inherent impls cannot be const fn main() {} diff --git a/tests/ui/traits/const-traits/inherent-impl.stderr b/tests/ui/traits/const-traits/inherent-impl.stderr index e4ec1e807b0..d828ecb6349 100644 --- a/tests/ui/traits/const-traits/inherent-impl.stderr +++ b/tests/ui/traits/const-traits/inherent-impl.stderr @@ -1,20 +1,20 @@ -error: inherent impls cannot be `const` +error: inherent impls cannot be const --> $DIR/inherent-impl.rs:7:12 | LL | impl const S {} | ----- ^ inherent impl for this type | | - | `const` because of this + | const because of this | = note: only trait implementations may be annotated with `const` -error: inherent impls cannot be `const` +error: inherent impls cannot be const --> $DIR/inherent-impl.rs:10:12 | LL | impl const dyn T {} | ----- ^^^^^ inherent impl for this type | | - | `const` because of this + | const because of this | = note: only trait implementations may be annotated with `const` diff --git a/tests/ui/traits/const-traits/macro-const-trait-bound-theoretical-regression.stderr b/tests/ui/traits/const-traits/macro-const-trait-bound-theoretical-regression.stderr index af160a45f3e..9fad260f0be 100644 --- a/tests/ui/traits/const-traits/macro-const-trait-bound-theoretical-regression.stderr +++ b/tests/ui/traits/const-traits/macro-const-trait-bound-theoretical-regression.stderr @@ -1,15 +1,4 @@ -error: macro expansion ignores keyword `dyn` and any tokens following - --> $DIR/macro-const-trait-bound-theoretical-regression.rs:14:31 - | -LL | (dyn $c:ident Trait) => { dyn $c Trait {} }; - | ^^^ -... -LL | demo! { dyn const Trait } - | ------------------------- caused by the macro expansion here - | - = note: the usage of `demo!` is likely invalid in item context - -error: inherent impls cannot be `const` +error: inherent impls cannot be const --> $DIR/macro-const-trait-bound-theoretical-regression.rs:10:40 | LL | (impl $c:ident Trait) => { impl $c Trait {} }; @@ -18,12 +7,23 @@ LL | (impl $c:ident Trait) => { impl $c Trait {} }; LL | demo! { impl const Trait } | -------------------------- | | | - | | `const` because of this + | | const because of this | in this macro invocation | = note: only trait implementations may be annotated with `const` = note: this error originates in the macro `demo` (in Nightly builds, run with -Z macro-backtrace for more info) +error: macro expansion ignores keyword `dyn` and any tokens following + --> $DIR/macro-const-trait-bound-theoretical-regression.rs:14:31 + | +LL | (dyn $c:ident Trait) => { dyn $c Trait {} }; + | ^^^ +... +LL | demo! { dyn const Trait } + | ------------------------- caused by the macro expansion here + | + = note: the usage of `demo!` is likely invalid in item context + error[E0658]: const trait impls are experimental --> $DIR/macro-const-trait-bound-theoretical-regression.rs:17:14 | diff --git a/tests/ui/traits/const-traits/span-bug-issue-121418.rs b/tests/ui/traits/const-traits/span-bug-issue-121418.rs index 50a7e12f2a7..593180ac094 100644 --- a/tests/ui/traits/const-traits/span-bug-issue-121418.rs +++ b/tests/ui/traits/const-traits/span-bug-issue-121418.rs @@ -4,7 +4,7 @@ struct S; trait T {} impl const dyn T { - //~^ ERROR inherent impls cannot be `const` + //~^ ERROR inherent impls cannot be const pub const fn new() -> std::sync::Mutex<dyn T> {} //~^ ERROR mismatched types //~| ERROR cannot be known at compilation time diff --git a/tests/ui/traits/const-traits/span-bug-issue-121418.stderr b/tests/ui/traits/const-traits/span-bug-issue-121418.stderr index f31129d9cb7..0c8ca918a3e 100644 --- a/tests/ui/traits/const-traits/span-bug-issue-121418.stderr +++ b/tests/ui/traits/const-traits/span-bug-issue-121418.stderr @@ -1,10 +1,10 @@ -error: inherent impls cannot be `const` +error: inherent impls cannot be const --> $DIR/span-bug-issue-121418.rs:6:12 | LL | impl const dyn T { | ----- ^^^^^ inherent impl for this type | | - | `const` because of this + | const because of this | = note: only trait implementations may be annotated with `const` diff --git a/tests/ui/issues/issue-15444.rs b/tests/ui/traits/fn-type-trait-impl-15444.rs index 14708c7733c..ab91e88b9cd 100644 --- a/tests/ui/issues/issue-15444.rs +++ b/tests/ui/traits/fn-type-trait-impl-15444.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15444 + //@ run-pass trait MyTrait { diff --git a/tests/ui/issues/issue-15734.rs b/tests/ui/traits/index-trait-multiple-impls-15734.rs index 26fb7061664..a2d5d7c87fc 100644 --- a/tests/ui/issues/issue-15734.rs +++ b/tests/ui/traits/index-trait-multiple-impls-15734.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/15734 + //@ run-pass //@ revisions: current next //@ ignore-compare-mode-next-solver (explicit revisions) diff --git a/tests/ui/issues/issue-16048.rs b/tests/ui/traits/lifetime-mismatch-trait-impl-16048.rs index eaf6acff26b..9c36b231403 100644 --- a/tests/ui/issues/issue-16048.rs +++ b/tests/ui/traits/lifetime-mismatch-trait-impl-16048.rs @@ -1,3 +1,5 @@ +//! Regression test for https://github.com/rust-lang/rust/issues/16048 + trait NoLifetime { fn get<'p, T : Test<'p>>(&self) -> T; //~^ NOTE lifetimes in impl do not match this method in trait diff --git a/tests/ui/issues/issue-16048.stderr b/tests/ui/traits/lifetime-mismatch-trait-impl-16048.stderr index f97f13152bc..08b69184b7f 100644 --- a/tests/ui/issues/issue-16048.stderr +++ b/tests/ui/traits/lifetime-mismatch-trait-impl-16048.stderr @@ -1,5 +1,5 @@ error[E0195]: lifetime parameters or bounds on method `get` do not match the trait declaration - --> $DIR/issue-16048.rs:21:11 + --> $DIR/lifetime-mismatch-trait-impl-16048.rs:23:11 | LL | fn get<'p, T : Test<'p>>(&self) -> T; | ------------------ lifetimes in impl do not match this method in trait @@ -8,7 +8,7 @@ LL | fn get<'p, T: Test<'a> + From<Foo<'a>>>(&self) -> T { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetimes do not match method in trait error[E0605]: non-primitive cast: `Foo<'a>` as `T` - --> $DIR/issue-16048.rs:24:16 + --> $DIR/lifetime-mismatch-trait-impl-16048.rs:26:16 | LL | return *self as T; | ^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object diff --git a/tests/ui/traits/safety-inherent-impl.stderr b/tests/ui/traits/safety-inherent-impl.stderr index 2513fef909e..45cdbe2b523 100644 --- a/tests/ui/traits/safety-inherent-impl.stderr +++ b/tests/ui/traits/safety-inherent-impl.stderr @@ -5,6 +5,8 @@ LL | unsafe impl SomeStruct { | ------ ^^^^^^^^^^ inherent impl for this type | | | unsafe because of this + | + = note: only trait implementations may be annotated with `unsafe` error: aborting due to 1 previous error diff --git a/tests/ui/traits/syntax-trait-polarity.stderr b/tests/ui/traits/syntax-trait-polarity.stderr index 1fd40fb6657..8ffcdc7d8b5 100644 --- a/tests/ui/traits/syntax-trait-polarity.stderr +++ b/tests/ui/traits/syntax-trait-polarity.stderr @@ -5,15 +5,8 @@ LL | impl !TestType {} | -^^^^^^^^ inherent impl for this type | | | negative because of this - -error[E0198]: negative impls cannot be unsafe - --> $DIR/syntax-trait-polarity.rs:12:13 | -LL | unsafe impl !Send for TestType {} - | ------ -^^^^ - | | | - | | negative because of this - | unsafe because of this + = note: only trait implementations may be annotated with `!` error: inherent impls cannot be negative --> $DIR/syntax-trait-polarity.rs:18:10 @@ -22,6 +15,17 @@ LL | impl<T> !TestType2<T> {} | -^^^^^^^^^^^^ inherent impl for this type | | | negative because of this + | + = note: only trait implementations may be annotated with `!` + +error[E0198]: negative impls cannot be unsafe + --> $DIR/syntax-trait-polarity.rs:12:13 + | +LL | unsafe impl !Send for TestType {} + | ------ -^^^^ + | | | + | | negative because of this + | unsafe because of this error[E0198]: negative impls cannot be unsafe --> $DIR/syntax-trait-polarity.rs:21:16 diff --git a/tests/ui/issues/issue-30236.rs b/tests/ui/typeck/unused-type-parameter-span-30236.rs index 08d08a54402..bcdc922a71b 100644 --- a/tests/ui/issues/issue-30236.rs +++ b/tests/ui/typeck/unused-type-parameter-span-30236.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/30236 type Foo< Unused //~ ERROR type parameter `Unused` is never used > = u8; diff --git a/tests/ui/issues/issue-30236.stderr b/tests/ui/typeck/unused-type-parameter-span-30236.stderr index bfe374a653f..038bd1ebd28 100644 --- a/tests/ui/issues/issue-30236.stderr +++ b/tests/ui/typeck/unused-type-parameter-span-30236.stderr @@ -1,5 +1,5 @@ error[E0091]: type parameter `Unused` is never used - --> $DIR/issue-30236.rs:2:5 + --> $DIR/unused-type-parameter-span-30236.rs:3:5 | LL | Unused | ^^^^^^ unused type parameter diff --git a/tests/ui/unboxed-closures/unboxed-closure-illegal-move.stderr b/tests/ui/unboxed-closures/unboxed-closure-illegal-move.stderr index 8d9a61cb681..9d87402a15b 100644 --- a/tests/ui/unboxed-closures/unboxed-closure-illegal-move.stderr +++ b/tests/ui/unboxed-closures/unboxed-closure-illegal-move.stderr @@ -10,6 +10,11 @@ LL | let f = to_fn(|| drop(x)); | | | captured by this `Fn` closure | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/unboxed-closure-illegal-move.rs:7:33 + | +LL | fn to_fn<A:std::marker::Tuple,F:Fn<A>>(f: F) -> F { f } + | ^^^^^ help: consider cloning the value if the performance cost is acceptable | LL | let f = to_fn(|| drop(x.clone())); @@ -27,6 +32,11 @@ LL | let f = to_fn_mut(|| drop(x)); | | | captured by this `FnMut` closure | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/unboxed-closure-illegal-move.rs:8:37 + | +LL | fn to_fn_mut<A:std::marker::Tuple,F:FnMut<A>>(f: F) -> F { f } + | ^^^^^^^^ help: consider cloning the value if the performance cost is acceptable | LL | let f = to_fn_mut(|| drop(x.clone())); @@ -43,6 +53,12 @@ LL | let f = to_fn(move || drop(x)); | ------- ^ `x` is moved here | | | captured by this `Fn` closure + | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/unboxed-closure-illegal-move.rs:7:33 + | +LL | fn to_fn<A:std::marker::Tuple,F:Fn<A>>(f: F) -> F { f } + | ^^^^^ error[E0507]: cannot move out of `x`, a captured variable in an `FnMut` closure --> $DIR/unboxed-closure-illegal-move.rs:32:40 @@ -55,6 +71,12 @@ LL | let f = to_fn_mut(move || drop(x)); | ------- ^ `x` is moved here | | | captured by this `FnMut` closure + | +help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but an `FnOnce` consume them only once + --> $DIR/unboxed-closure-illegal-move.rs:8:37 + | +LL | fn to_fn_mut<A:std::marker::Tuple,F:FnMut<A>>(f: F) -> F { f } + | ^^^^^^^^ error: aborting due to 4 previous errors diff --git a/tests/ui/issues/issue-88150.rs b/tests/ui/uninhabited/uninhabited-type-layout-computation-88150.rs index 1dadba307c0..1387c5b6c10 100644 --- a/tests/ui/issues/issue-88150.rs +++ b/tests/ui/uninhabited/uninhabited-type-layout-computation-88150.rs @@ -1,3 +1,4 @@ +// https://github.com/rust-lang/rust/issues/88150 //@ run-pass //@ compile-flags:-C debuginfo=2 //@ edition:2018 diff --git a/tests/ui/unpretty/exhaustive.hir.stdout b/tests/ui/unpretty/exhaustive.hir.stdout index 9cfa65f5801..e9823c9575b 100644 --- a/tests/ui/unpretty/exhaustive.hir.stdout +++ b/tests/ui/unpretty/exhaustive.hir.stdout @@ -509,7 +509,7 @@ mod items { impl () { } impl <T> () { } impl Default for () { } - impl const <T> Default for () { } + impl <T> const Default for () { } } /// ItemKind::MacCall mod item_mac_call { } diff --git a/tests/ui/unsized/relaxed-bounds-invalid-places.rs b/tests/ui/unsized/relaxed-bounds-invalid-places.rs index b8eda1e7786..4c1f242a01c 100644 --- a/tests/ui/unsized/relaxed-bounds-invalid-places.rs +++ b/tests/ui/unsized/relaxed-bounds-invalid-places.rs @@ -22,6 +22,10 @@ impl<T> S1<T> { fn f() where T: ?Sized {} //~ ERROR this relaxed bound is not permitted here } +// Test associated type bounds (ATB). +// issue: <https://github.com/rust-lang/rust/issues/135229> +struct S6<T>(T) where T: Iterator<Item: ?Sized>; //~ ERROR this relaxed bound is not permitted here + trait Tr: ?Sized {} //~ ERROR relaxed bounds are not permitted in supertrait bounds // Test that relaxed `Sized` bounds are rejected in trait object types: diff --git a/tests/ui/unsized/relaxed-bounds-invalid-places.stderr b/tests/ui/unsized/relaxed-bounds-invalid-places.stderr index 30285d62693..d3f0535e2f0 100644 --- a/tests/ui/unsized/relaxed-bounds-invalid-places.stderr +++ b/tests/ui/unsized/relaxed-bounds-invalid-places.stderr @@ -38,8 +38,16 @@ LL | fn f() where T: ?Sized {} | = note: in this context, relaxed bounds are only allowed on type parameters defined by the closest item +error: this relaxed bound is not permitted here + --> $DIR/relaxed-bounds-invalid-places.rs:27:41 + | +LL | struct S6<T>(T) where T: Iterator<Item: ?Sized>; + | ^^^^^^ + | + = note: in this context, relaxed bounds are only allowed on type parameters defined by the closest item + error: relaxed bounds are not permitted in supertrait bounds - --> $DIR/relaxed-bounds-invalid-places.rs:25:11 + --> $DIR/relaxed-bounds-invalid-places.rs:29:11 | LL | trait Tr: ?Sized {} | ^^^^^^ @@ -47,19 +55,19 @@ LL | trait Tr: ?Sized {} = note: traits are `?Sized` by default error: relaxed bounds are not permitted in trait object types - --> $DIR/relaxed-bounds-invalid-places.rs:29:20 + --> $DIR/relaxed-bounds-invalid-places.rs:33:20 | LL | type O1 = dyn Tr + ?Sized; | ^^^^^^ error: relaxed bounds are not permitted in trait object types - --> $DIR/relaxed-bounds-invalid-places.rs:30:15 + --> $DIR/relaxed-bounds-invalid-places.rs:34:15 | LL | type O2 = dyn ?Sized + ?Sized + Tr; | ^^^^^^ error: relaxed bounds are not permitted in trait object types - --> $DIR/relaxed-bounds-invalid-places.rs:30:24 + --> $DIR/relaxed-bounds-invalid-places.rs:34:24 | LL | type O2 = dyn ?Sized + ?Sized + Tr; | ^^^^^^ @@ -76,5 +84,5 @@ error: bound modifier `?` can only be applied to `Sized` LL | struct S5<T>(*const T) where T: ?Trait<'static> + ?Sized; | ^^^^^^^^^^^^^^^ -error: aborting due to 11 previous errors +error: aborting due to 12 previous errors diff --git a/tests/ui/unstable-feature-bound/unstable_feature_bound_on_trait.fail.stderr b/tests/ui/unstable-feature-bound/unstable_feature_bound_on_trait.fail.stderr new file mode 100644 index 00000000000..69be101a40d --- /dev/null +++ b/tests/ui/unstable-feature-bound/unstable_feature_bound_on_trait.fail.stderr @@ -0,0 +1,18 @@ +error: unstable feature `foo` is used without being enabled. + --> $DIR/unstable_feature_bound_on_trait.rs:28:5 + | +LL | Foo::bar(); + | ^^^^^^^^^^ + | + = help: The feature can be enabled by marking the current item with `#[unstable_feature_bound(foo)]` +note: required by a bound in `Bar::bar` + --> $DIR/unstable_feature_bound_on_trait.rs:16:1 + | +LL | #[unstable_feature_bound(foo)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `Bar::bar` +... +LL | fn bar() {} + | --- required by a bound in this associated function + +error: aborting due to 1 previous error + diff --git a/tests/ui/unstable-feature-bound/unstable_feature_bound_on_trait.rs b/tests/ui/unstable-feature-bound/unstable_feature_bound_on_trait.rs new file mode 100644 index 00000000000..0ee00d5e7fb --- /dev/null +++ b/tests/ui/unstable-feature-bound/unstable_feature_bound_on_trait.rs @@ -0,0 +1,33 @@ +//@ revisions: pass fail +//@[pass] check-pass + +#![allow(internal_features)] +#![feature(staged_api)] +#![stable(feature = "a", since = "1.1.1" )] + +/// Test the behaviour of marking a trait with #[unstable_feature_bound]. +/// In this testcase, even though the trait method `bar` and the `struct Foo` are +/// both stable, #[unstable_feature_bound] is still needed at the call site of Foo::bar(). + +#[stable(feature = "a", since = "1.1.1" )] +struct Foo; + +#[unstable(feature = "foo", issue = "none" )] +#[unstable_feature_bound(foo)] +trait Bar { + #[stable(feature = "a", since = "1.1.1" )] + fn bar() {} +} + +#[unstable_feature_bound(foo)] +impl Bar for Foo { +} + +#[cfg_attr(pass, unstable_feature_bound(foo))] +fn moo() { + Foo::bar(); + //[fail]~^ ERROR: unstable feature `foo` is used without being enabled. +} + + +fn main() {} diff --git a/tests/ui/unstable-feature-bound/unstable_inherent_method.rs b/tests/ui/unstable-feature-bound/unstable_inherent_method.rs index 5f3095430a8..0d6e4ebb408 100644 --- a/tests/ui/unstable-feature-bound/unstable_inherent_method.rs +++ b/tests/ui/unstable-feature-bound/unstable_inherent_method.rs @@ -9,14 +9,14 @@ pub trait Trait { #[unstable(feature = "feat", issue = "none" )] #[unstable_feature_bound(foo)] - //~^ ERROR: attribute should be applied to `impl` or free function outside of any `impl` or trait + //~^ ERROR: attribute should be applied to `impl`, trait or free function fn foo(); } #[stable(feature = "a", since = "1.1.1" )] impl Trait for u8 { #[unstable_feature_bound(foo)] - //~^ ERROR: attribute should be applied to `impl` or free function outside of any `impl` or trait + //~^ ERROR: attribute should be applied to `impl`, trait or free function fn foo() {} } diff --git a/tests/ui/unstable-feature-bound/unstable_inherent_method.stderr b/tests/ui/unstable-feature-bound/unstable_inherent_method.stderr index fa1c39db259..90cbb32df7c 100644 --- a/tests/ui/unstable-feature-bound/unstable_inherent_method.stderr +++ b/tests/ui/unstable-feature-bound/unstable_inherent_method.stderr @@ -1,20 +1,20 @@ -error: attribute should be applied to `impl` or free function outside of any `impl` or trait +error: attribute should be applied to `impl`, trait or free function --> $DIR/unstable_inherent_method.rs:11:5 | LL | #[unstable_feature_bound(foo)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LL | LL | fn foo(); - | --------- not an `impl` or free function + | --------- not an `impl`, trait or free function -error: attribute should be applied to `impl` or free function outside of any `impl` or trait +error: attribute should be applied to `impl`, trait or free function --> $DIR/unstable_inherent_method.rs:18:5 | LL | #[unstable_feature_bound(foo)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ LL | LL | fn foo() {} - | ----------- not an `impl` or free function + | ----------- not an `impl`, trait or free function error: aborting due to 2 previous errors diff --git a/tests/ui/wf/hir-wf-check-erase-regions.stderr b/tests/ui/wf/hir-wf-check-erase-regions.nll.stderr index 07304cd448e..dcade3aa367 100644 --- a/tests/ui/wf/hir-wf-check-erase-regions.stderr +++ b/tests/ui/wf/hir-wf-check-erase-regions.nll.stderr @@ -1,5 +1,5 @@ error[E0277]: `&'a T` is not an iterator - --> $DIR/hir-wf-check-erase-regions.rs:7:21 + --> $DIR/hir-wf-check-erase-regions.rs:11:21 | LL | type IntoIter = std::iter::Flatten<std::slice::Iter<'a, T>>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `&'a T` is not an iterator @@ -11,7 +11,7 @@ note: required by a bound in `std::iter::IntoIterator::IntoIter` --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL error[E0277]: `&'a T` is not an iterator - --> $DIR/hir-wf-check-erase-regions.rs:7:5 + --> $DIR/hir-wf-check-erase-regions.rs:11:5 | LL | type IntoIter = std::iter::Flatten<std::slice::Iter<'a, T>>; | ^^^^^^^^^^^^^ `&'a T` is not an iterator @@ -23,7 +23,7 @@ note: required by a bound in `Flatten` --> $SRC_DIR/core/src/iter/adapters/flatten.rs:LL:COL error[E0277]: `&'a T` is not an iterator - --> $DIR/hir-wf-check-erase-regions.rs:11:27 + --> $DIR/hir-wf-check-erase-regions.rs:15:27 | LL | fn into_iter(self) -> Self::IntoIter { | ^^^^^^^^^^^^^^ `&'a T` is not an iterator @@ -35,7 +35,7 @@ note: required by a bound in `Flatten` --> $SRC_DIR/core/src/iter/adapters/flatten.rs:LL:COL error[E0277]: `&T` is not an iterator - --> $DIR/hir-wf-check-erase-regions.rs:11:27 + --> $DIR/hir-wf-check-erase-regions.rs:15:27 | LL | fn into_iter(self) -> Self::IntoIter { | ^^^^^^^^^^^^^^ `&T` is not an iterator diff --git a/tests/ui/wf/hir-wf-check-erase-regions.polonius.stderr b/tests/ui/wf/hir-wf-check-erase-regions.polonius.stderr new file mode 100644 index 00000000000..55728aa642b --- /dev/null +++ b/tests/ui/wf/hir-wf-check-erase-regions.polonius.stderr @@ -0,0 +1,39 @@ +error[E0277]: `&'a T` is not an iterator + --> $DIR/hir-wf-check-erase-regions.rs:11:21 + | +LL | type IntoIter = std::iter::Flatten<std::slice::Iter<'a, T>>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `&'a T` is not an iterator + | + = help: the trait `Iterator` is not implemented for `&'a T` + = help: the trait `Iterator` is implemented for `&mut I` + = note: required for `Flatten<std::slice::Iter<'a, T>>` to implement `Iterator` +note: required by a bound in `std::iter::IntoIterator::IntoIter` + --> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL + +error[E0277]: `&'a T` is not an iterator + --> $DIR/hir-wf-check-erase-regions.rs:11:5 + | +LL | type IntoIter = std::iter::Flatten<std::slice::Iter<'a, T>>; + | ^^^^^^^^^^^^^ `&'a T` is not an iterator + | + = help: the trait `Iterator` is not implemented for `&'a T` + = help: the trait `Iterator` is implemented for `&mut I` + = note: required for `&'a T` to implement `IntoIterator` +note: required by a bound in `Flatten` + --> $SRC_DIR/core/src/iter/adapters/flatten.rs:LL:COL + +error[E0277]: `&'a T` is not an iterator + --> $DIR/hir-wf-check-erase-regions.rs:15:27 + | +LL | fn into_iter(self) -> Self::IntoIter { + | ^^^^^^^^^^^^^^ `&'a T` is not an iterator + | + = help: the trait `Iterator` is not implemented for `&'a T` + = help: the trait `Iterator` is implemented for `&mut I` + = note: required for `&'a T` to implement `IntoIterator` +note: required by a bound in `Flatten` + --> $SRC_DIR/core/src/iter/adapters/flatten.rs:LL:COL + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/wf/hir-wf-check-erase-regions.rs b/tests/ui/wf/hir-wf-check-erase-regions.rs index 20cc1cfe730..ef9132697ef 100644 --- a/tests/ui/wf/hir-wf-check-erase-regions.rs +++ b/tests/ui/wf/hir-wf-check-erase-regions.rs @@ -1,6 +1,10 @@ // Regression test for #87549. //@ incremental +//@ ignore-compare-mode-polonius (explicit revisions) +//@ revisions: nll polonius +//@ [polonius] compile-flags: -Zpolonius=next + pub struct Table<T, const N: usize>([Option<T>; N]); impl<'a, T, const N: usize> IntoIterator for &'a Table<T, N> { @@ -10,7 +14,7 @@ impl<'a, T, const N: usize> IntoIterator for &'a Table<T, N> { fn into_iter(self) -> Self::IntoIter { //~^ ERROR `&'a T` is not an iterator - //~| ERROR `&T` is not an iterator + //[nll]~| ERROR `&T` is not an iterator unimplemented!() } } diff --git a/triagebot.toml b/triagebot.toml index 7b1325899f3..6f6e95c5b50 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -207,6 +207,7 @@ trigger_labels = [ "regression-from-stable-to-beta", "regression-from-stable-to-nightly", "I-unsound", + "I-miscompile", ] exclude_labels = [ "P-*", @@ -1573,7 +1574,7 @@ changelog-branch = "master" [note] [behind-upstream] -days-threshold = 14 +days-threshold = 28 # Canonicalize issue numbers to avoid closing the wrong issue # when commits are included in subtrees, as well as warning links in commits. |
