diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 8986430141be4..cf1b1a33795d6 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -3009,7 +3009,7 @@ impl BoundPolarity { } } -/// The constness of a trait bound. +/// The constness of a trait bound or function. #[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, Hash)] #[derive(HashStable_Generic)] pub enum BoundConstness { @@ -3461,7 +3461,7 @@ pub struct FnHeader { /// Whether this is `async`, `gen`, or nothing. pub coroutine_kind: Option, /// The `const` keyword, if any - pub constness: Const, + pub constness: BoundConstness, /// The `extern` keyword and corresponding ABI string, if any. pub ext: Extern, } @@ -3472,7 +3472,7 @@ impl FnHeader { let Self { safety, coroutine_kind, constness, ext } = self; matches!(safety, Safety::Unsafe(_)) || coroutine_kind.is_some() - || matches!(constness, Const::Yes(_)) + || !matches!(constness, BoundConstness::Never) || !matches!(ext, Extern::None) } } @@ -3482,7 +3482,7 @@ impl Default for FnHeader { FnHeader { safety: Safety::Default, coroutine_kind: None, - constness: Const::No, + constness: BoundConstness::Never, ext: Extern::None, } } diff --git a/compiler/rustc_ast/src/mut_visit.rs b/compiler/rustc_ast/src/mut_visit.rs index 6aae2e481a59f..1d996855e35a0 100644 --- a/compiler/rustc_ast/src/mut_visit.rs +++ b/compiler/rustc_ast/src/mut_visit.rs @@ -902,6 +902,14 @@ fn visit_constness(vis: &mut T, constness: &mut Const) { } } +// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`. +fn walk_bound_constness(vis: &mut T, constness: &mut BoundConstness) { + match constness { + BoundConstness::Never => {} + BoundConstness::Always(span) | BoundConstness::Maybe(span) => vis.visit_span(span), + } +} + fn walk_closure_binder(vis: &mut T, binder: &mut ClosureBinder) { match binder { ClosureBinder::NotPresent => {} @@ -1131,10 +1139,7 @@ fn walk_poly_trait_ref(vis: &mut T, p: &mut PolyTraitRef) { fn walk_modifiers(vis: &mut V, m: &mut TraitBoundModifiers) { let TraitBoundModifiers { constness, asyncness, polarity } = m; - match constness { - BoundConstness::Never => {} - BoundConstness::Always(span) | BoundConstness::Maybe(span) => vis.visit_span(span), - } + walk_bound_constness(vis, constness); match asyncness { BoundAsyncness::Normal => {} BoundAsyncness::Async(span) => vis.visit_span(span), @@ -1443,7 +1448,7 @@ fn walk_const_item(vis: &mut T, item: &mut ConstItem) { fn walk_fn_header(vis: &mut T, header: &mut FnHeader) { let FnHeader { safety, coroutine_kind, constness, ext: _ } = header; - visit_constness(vis, constness); + walk_bound_constness(vis, constness); coroutine_kind.as_mut().map(|coroutine_kind| vis.visit_coroutine_kind(coroutine_kind)); visit_safety(vis, safety); } diff --git a/compiler/rustc_ast_lowering/src/item.rs b/compiler/rustc_ast_lowering/src/item.rs index c009abd729da9..6cd183d095027 100644 --- a/compiler/rustc_ast_lowering/src/item.rs +++ b/compiler/rustc_ast_lowering/src/item.rs @@ -1600,7 +1600,7 @@ impl<'hir> LoweringContext<'_, 'hir> { hir::FnHeader { safety, asyncness, - constness: self.lower_constness(h.constness), + constness: self.lower_fn_header_constness(h.constness), abi: self.lower_extern(h.ext), } } diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 1e14b4d6723f4..24dca6c031a93 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -198,6 +198,15 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { pub(crate) fn dcx(&self) -> DiagCtxtHandle<'hir> { self.tcx.dcx() } + + fn lower_fn_header_constness(&self, constness: BoundConstness) -> hir::Constness { + match constness { + BoundConstness::Never => hir::Constness::NotConst, + BoundConstness::Always(_) => hir::Constness::Const, + // FIXME(const_trait_impls): support non-const fn and `(const)` fns within the same trait + BoundConstness::Maybe(_) => hir::Constness::NotConst, + } + } } #[extension(trait ResolverAstLoweringExt)] diff --git a/compiler/rustc_ast_passes/messages.ftl b/compiler/rustc_ast_passes/messages.ftl index 80754a8f65a69..e66a2b3b4e9a0 100644 --- a/compiler/rustc_ast_passes/messages.ftl +++ b/compiler/rustc_ast_passes/messages.ftl @@ -47,6 +47,8 @@ ast_passes_const_and_coroutine = functions cannot be both `const` and `{$corouti ast_passes_const_bound_trait_object = const trait bounds are not allowed in trait object types +ast_passes_const_in_trait = `const fn` in traits is unstable + ast_passes_const_without_body = free constant item without body .suggestion = provide a definition for the constant diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index 1feb3e9bf9b40..90d0440ff538f 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -253,12 +253,55 @@ impl<'a> AstValidator<'a> { } } - fn check_trait_fn_not_const(&self, constness: Const, parent: &TraitOrTraitImpl) { - let Const::Yes(span) = constness else { - return; + fn check_trait_fn_not_const( + &self, + constness: BoundConstness, + sig_span: Span, + parent: &TraitOrTraitImpl, + ) { + let const_trait_impl = self.features.const_trait_impl(); + + let span = match (constness, parent) { + (BoundConstness::Never, toti) => { + // only `(const)` or `const` fn are allowed in traits or impls respectively. + // But for bootstrap purposes we allow the stage1 std and the stage0 std to be the same. + if toti.constness().is_some() && !self.features.staged_api() { + // FIXME(const_trait_impls): allow non-const fns + self.dcx() + .struct_span_err( + sig_span.shrink_to_lo(), + "non-const fn in const traits are not supported yet", + ) + .with_span_suggestion( + sig_span.shrink_to_lo(), + "mark the function as const", + match toti { + TraitOrTraitImpl::Trait { .. } => "(const) ", + TraitOrTraitImpl::TraitImpl { .. } => "const ", + }, + rustc_errors::Applicability::MachineApplicable, + ) + .emit(); + } + return; + } + // `(const) fn` in `const Trait` or `impl const Trait` is ok + (BoundConstness::Always(span), _) => span, + ( + BoundConstness::Maybe(span), + TraitOrTraitImpl::Trait { constness_span: Some(_), .. } + | TraitOrTraitImpl::TraitImpl { constness: Const::Yes(_), .. }, + ) => { + if !const_trait_impl { + self.sess + .create_feature_err(errors::ConstInTrait { span }, sym::const_trait_impl) + .emit(); + } + return; + } + (BoundConstness::Maybe(span), _) => span, }; - let const_trait_impl = self.features.const_trait_impl(); let make_impl_const_sugg = if const_trait_impl && let TraitOrTraitImpl::TraitImpl { constness: Const::No, @@ -500,8 +543,9 @@ impl<'a> AstValidator<'a> { None => (), } match constness { - Const::Yes(span) => report_err(span, "const"), - Const::No => (), + BoundConstness::Always(span) => report_err(span, "const"), + BoundConstness::Maybe(span) => report_err(span, "~const"), + BoundConstness::Never => (), } match ext { Extern::None => (), @@ -538,7 +582,9 @@ impl<'a> AstValidator<'a> { } if let Some(header) = fk.header() { - if let Const::Yes(const_span) = header.constness { + if let BoundConstness::Always(const_span) | BoundConstness::Maybe(const_span) = + header.constness + { let mut spans = variadic_spans.clone(); spans.push(const_span); self.dcx().emit_err(errors::ConstAndCVariadic { @@ -1348,7 +1394,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { // Functions cannot both be `const async` or `const gen` if let Some(&FnHeader { - constness: Const::Yes(const_span), + constness: BoundConstness::Always(const_span) | BoundConstness::Maybe(const_span), coroutine_kind: Some(coroutine_kind), .. }) = fk.header() @@ -1399,14 +1445,14 @@ impl<'a> Visitor<'a> for AstValidator<'a> { }); } - let tilde_const_allowed = - matches!(fk.header(), Some(FnHeader { constness: ast::Const::Yes(_), .. })) - || matches!(fk.ctxt(), Some(FnCtxt::Assoc(_))) - && self - .outer_trait_or_trait_impl - .as_ref() - .and_then(TraitOrTraitImpl::constness) - .is_some(); + let tilde_const_allowed = matches!(fk.header(), Some(FnHeader { constness: ast::BoundConstness::Always(_) | ast::BoundConstness::Maybe(_), .. })) + // FIXME(const_trait_impls): remove this, we don't want to allow `~const` trait bounds in non-const methods + || matches!(fk.ctxt(), Some(FnCtxt::Assoc(_))) + && self + .outer_trait_or_trait_impl + .as_ref() + .and_then(TraitOrTraitImpl::constness) + .is_some(); let disallowed = (!tilde_const_allowed).then(|| match fk { FnKind::Fn(_, _, f) => TildeConstReason::Function { ident: f.ident.span }, @@ -1475,7 +1521,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { if let Some(parent) = &self.outer_trait_or_trait_impl { self.visibility_not_permitted(&item.vis, errors::VisibilityNotPermittedNote::TraitImpl); if let AssocItemKind::Fn(box Fn { sig, .. }) = &item.kind { - self.check_trait_fn_not_const(sig.header.constness, parent); + self.check_trait_fn_not_const(sig.header.constness, sig.span, parent); } } @@ -1490,7 +1536,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> { AssocItemKind::Fn(func) if parent_is_const || ctxt == AssocCtxt::Trait - || matches!(func.sig.header.constness, Const::Yes(_)) => + || !matches!(func.sig.header.constness, ast::BoundConstness::Never) => { self.visit_attrs_vis_ident(&item.attrs, &item.vis, &func.ident); let kind = FnKind::Fn(FnCtxt::Assoc(ctxt), &item.vis, &*func); diff --git a/compiler/rustc_ast_passes/src/errors.rs b/compiler/rustc_ast_passes/src/errors.rs index 6f9737e08314e..4269ce02e01af 100644 --- a/compiler/rustc_ast_passes/src/errors.rs +++ b/compiler/rustc_ast_passes/src/errors.rs @@ -565,6 +565,13 @@ pub(crate) struct NestedLifetimes { pub span: Span, } +#[derive(Diagnostic)] +#[diag(ast_passes_const_in_trait)] +pub(crate) struct ConstInTrait { + #[primary_span] + pub span: Span, +} + #[derive(Diagnostic)] #[diag(ast_passes_optional_trait_supertrait)] #[note] diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index 985359e1234e8..8881c5f81eebe 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -1981,7 +1981,7 @@ impl<'a> State<'a> { } fn print_fn_header_info(&mut self, header: ast::FnHeader) { - self.print_constness(header.constness); + self.print_bound_constness(header.constness); header.coroutine_kind.map(|coroutine_kind| self.print_coroutine_kind(coroutine_kind)); self.print_safety(header.safety); @@ -2015,6 +2015,14 @@ impl<'a> State<'a> { } } + fn print_bound_constness(&mut self, s: ast::BoundConstness) { + match s { + ast::BoundConstness::Never => {} + ast::BoundConstness::Always(_) => self.word_nbsp("const"), + ast::BoundConstness::Maybe(_) => self.word_nbsp("~const"), + } + } + fn print_is_auto(&mut self, s: ast::IsAuto) { match s { ast::IsAuto::Yes => self.word_nbsp("auto"), diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index d9aac54ee73c7..60b4423c26c48 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -1018,7 +1018,18 @@ impl<'a> MethodDef<'a> { let trait_lo_sp = span.shrink_to_lo(); - let sig = ast::FnSig { header: ast::FnHeader::default(), decl: fn_decl, span }; + let sig = ast::FnSig { + header: ast::FnHeader { + constness: if trait_.is_const { + ast::BoundConstness::Maybe(span) + } else { + ast::BoundConstness::Never + }, + ..Default::default() + }, + decl: fn_decl, + span, + }; let defaultness = ast::Defaultness::Final; // Create the method. diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index 4be8a90368d29..dc19ead96d6af 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -857,13 +857,20 @@ impl<'a> Parser<'a> { false } + fn is_paren_const(&self, i: usize) -> bool { + self.look_ahead(i, |t| *t == token::OpenParen) + && self.look_ahead(1 + i, |t| t.is_keyword(kw::Const)) + && self.look_ahead(2 + i, |t| *t == token::CloseParen) + } + /// Parses defaultness (i.e., `default` or nothing). fn parse_defaultness(&mut self) -> Defaultness { // We are interested in `default` followed by another identifier. // However, we must avoid keywords that occur as binary operators. // Currently, the only applicable keyword is `as` (`default as Ty`). if self.check_keyword(exp!(Default)) - && self.look_ahead(1, |t| t.is_non_raw_ident_where(|i| i.name != kw::As)) + && (self.look_ahead(1, |t| t.is_non_raw_ident_where(|i| i.name != kw::As)) + || self.is_paren_const(1)) { self.bump(); // `default` Defaultness::Default(self.prev_token_uninterpolated_span()) @@ -2613,6 +2620,8 @@ impl<'a> Parser<'a> { // Rule out `async gen {` and `async gen move {` && !self.is_async_gen_block()) }) + // `(const)` + || self.is_paren_const(0) // `extern ABI fn` || self.check_keyword_case(exp!(Extern), case) // Use `tree_look_ahead` because `ABI` might be a metavariable, @@ -2647,12 +2656,31 @@ impl<'a> Parser<'a> { ) } + pub fn parse_fn_constness(&mut self, case: Case) -> PResult<'a, BoundConstness> { + Ok(if self.eat_keyword_case(exp!(Const), case) { + BoundConstness::Always(self.prev_token.span) + } else if self.check(exp!(OpenParen)) + && self.look_ahead(1, |t| t.is_keyword(kw::Const)) + && self.look_ahead(2, |t| *t == token::CloseParen) + { + let start = self.token.span; + self.bump(); + self.expect_keyword(exp!(Const)).unwrap(); + self.bump(); + let span = start.to(self.prev_token.span); + self.psess.gated_spans.gate(sym::const_trait_impl, span); + BoundConstness::Maybe(span) + } else { + BoundConstness::Never + }) + } + /// Parses all the "front matter" (or "qualifiers") for a `fn` declaration, /// up to and including the `fn` keyword. The formal grammar is: /// /// ```text /// Extern = "extern" StringLit? ; - /// FnQual = "const"? "async"? "unsafe"? Extern? ; + /// FnQual = "(const)"? "const"? "async"? "unsafe"? Extern? ; /// FnFrontMatter = FnQual "fn" ; /// ``` /// @@ -2664,7 +2692,7 @@ impl<'a> Parser<'a> { case: Case, ) -> PResult<'a, FnHeader> { let sp_start = self.token.span; - let constness = self.parse_constness(case); + let constness = self.parse_fn_constness(case)?; let async_start_sp = self.token.span; let coroutine_kind = self.parse_coroutine_kind(case); @@ -2713,9 +2741,11 @@ impl<'a> Parser<'a> { // that the keyword is already present and the second instance should be removed. let wrong_kw = if self.check_keyword(exp!(Const)) { match constness { - Const::Yes(sp) => Some(WrongKw::Duplicated(sp)), - Const::No => { - recover_constness = Const::Yes(self.token.span); + BoundConstness::Always(sp) | BoundConstness::Maybe(sp) => { + Some(WrongKw::Duplicated(sp)) + } + BoundConstness::Never => { + recover_constness = BoundConstness::Always(self.token.span); Some(WrongKw::Misplaced(async_start_sp)) } } diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 17481731b1107..7590a7e8516ab 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -682,7 +682,9 @@ impl<'a> Parser<'a> { // | | safety_sp.lo // | coroutine_sp.lo // const_sp.lo - if let ast::Const::Yes(const_span) = constness { + if let ast::BoundConstness::Always(const_span) | ast::BoundConstness::Maybe(const_span) = + constness + { let next_token_lo = if let Some( ast::CoroutineKind::Async { span, .. } | ast::CoroutineKind::Gen { span, .. } @@ -1036,18 +1038,7 @@ impl<'a> Parser<'a> { /// See `parse_generic_ty_bound` for the complete grammar of trait bound modifiers. fn parse_trait_bound_modifiers(&mut self) -> PResult<'a, TraitBoundModifiers> { let modifier_lo = self.token.span; - let constness = if self.eat(exp!(Tilde)) { - let tilde = self.prev_token.span; - self.expect_keyword(exp!(Const))?; - let span = tilde.to(self.prev_token.span); - self.psess.gated_spans.gate(sym::const_trait_impl, span); - BoundConstness::Maybe(span) - } else if self.eat_keyword(exp!(Const)) { - self.psess.gated_spans.gate(sym::const_trait_impl, self.prev_token.span); - BoundConstness::Always(self.prev_token.span) - } else { - BoundConstness::Never - }; + let constness = self.parse_bound_constness()?; let asyncness = if self.token_uninterpolated_span().at_least_rust_2018() && self.eat_keyword(exp!(Async)) @@ -1109,6 +1100,32 @@ impl<'a> Parser<'a> { Ok(TraitBoundModifiers { constness, asyncness, polarity }) } + pub fn parse_bound_constness(&mut self) -> PResult<'a, BoundConstness> { + Ok(if self.eat(exp!(Tilde)) { + let tilde = self.prev_token.span; + self.expect_keyword(exp!(Const))?; + let span = tilde.to(self.prev_token.span); + self.psess.gated_spans.gate(sym::const_trait_impl, span); + BoundConstness::Maybe(span) + } else if self.eat_keyword(exp!(Const)) { + self.psess.gated_spans.gate(sym::const_trait_impl, self.prev_token.span); + BoundConstness::Always(self.prev_token.span) + } else if self.check(exp!(OpenParen)) + && self.look_ahead(1, |t| t.is_keyword(kw::Const)) + && self.look_ahead(2, |t| *t == token::CloseParen) + { + let start = self.prev_token.span; + self.bump(); + self.expect_keyword(exp!(Const)).unwrap(); + self.bump(); + let span = start.to(self.prev_token.span); + self.psess.gated_spans.gate(sym::const_trait_impl, span); + BoundConstness::Maybe(span) + } else { + BoundConstness::Never + }) + } + /// Parses a type bound according to: /// ```ebnf /// TY_BOUND = TY_BOUND_NOPAREN | (TY_BOUND_NOPAREN) 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 8996b694ed8f7..33e4ce27e4397 100644 --- a/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs +++ b/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs @@ -719,7 +719,7 @@ fn eq_opt_coroutine_kind(l: Option, r: Option) -> pub fn eq_fn_header(l: &FnHeader, r: &FnHeader) -> bool { matches!(l.safety, Safety::Default) == matches!(r.safety, Safety::Default) && eq_opt_coroutine_kind(l.coroutine_kind, r.coroutine_kind) - && matches!(l.constness, Const::No) == matches!(r.constness, Const::No) + && l.constness == r.constness && eq_ext(&l.ext, &r.ext) } diff --git a/src/tools/rustfmt/src/items.rs b/src/tools/rustfmt/src/items.rs index 5c3be769f9e0d..c951e04495ac9 100644 --- a/src/tools/rustfmt/src/items.rs +++ b/src/tools/rustfmt/src/items.rs @@ -303,7 +303,7 @@ pub(crate) struct FnSig<'a> { generics: &'a ast::Generics, ext: ast::Extern, coroutine_kind: Cow<'a, Option>, - constness: ast::Const, + constness: ast::BoundConstness, defaultness: ast::Defaultness, safety: ast::Safety, visibility: &'a ast::Visibility, diff --git a/src/tools/rustfmt/src/utils.rs b/src/tools/rustfmt/src/utils.rs index fcd475b1784f5..065dbf09c6c48 100644 --- a/src/tools/rustfmt/src/utils.rs +++ b/src/tools/rustfmt/src/utils.rs @@ -84,10 +84,11 @@ pub(crate) fn format_coro(coroutine_kind: &ast::CoroutineKind) -> &'static str { } #[inline] -pub(crate) fn format_constness(constness: ast::Const) -> &'static str { +pub(crate) fn format_constness(constness: ast::BoundConstness) -> &'static str { match constness { - ast::Const::Yes(..) => "const ", - ast::Const::No => "", + ast::BoundConstness::Always(..) => "const ", + ast::BoundConstness::Never => "", + ast::BoundConstness::Maybe(..) => "(const) ", } } diff --git a/tests/crashes/117629.rs b/tests/crashes/117629.rs deleted file mode 100644 index d8b5f328545da..0000000000000 --- a/tests/crashes/117629.rs +++ /dev/null @@ -1,11 +0,0 @@ -//@ known-bug: #117629 -//@ edition:2021 - -#![feature(const_trait_impl)] - -#[const_trait] -trait Tr { - async fn ft1() {} -} - -fn main() {} diff --git a/tests/rustdoc/const-effect-param.rs b/tests/rustdoc/const-effect-param.rs index cceb0adac3096..c4b2caccd4c96 100644 --- a/tests/rustdoc/const-effect-param.rs +++ b/tests/rustdoc/const-effect-param.rs @@ -5,7 +5,7 @@ #[const_trait] pub trait Tr { - fn f(); + (const) fn f(); } //@ has foo/fn.g.html diff --git a/tests/rustdoc/rfc-2632-const-trait-impl.rs b/tests/rustdoc/rfc-2632-const-trait-impl.rs index 8a86e3e5e9782..6320fee769793 100644 --- a/tests/rustdoc/rfc-2632-const-trait-impl.rs +++ b/tests/rustdoc/rfc-2632-const-trait-impl.rs @@ -25,7 +25,7 @@ pub trait Tr { //@ has - '//section[@id="method.a"]/h4[@class="code-header"]/a[@class="trait"]' 'Fn' //@ !has - '//section[@id="method.a"]/h4[@class="code-header"]/span[@class="where"]' '~const' //@ has - '//section[@id="method.a"]/h4[@class="code-header"]/div[@class="where"]' ': Fn' - fn a() + (const) fn a() where Option: /* ~const */ Fn() /* + ~const Destruct */, { @@ -41,7 +41,7 @@ impl const Tr for T where Option: /* ~const */ Fn() /* + ~const Destruct */, { - fn a() + (const) fn a() where Option: /* ~const */ Fn() /* + ~const Destruct */, { diff --git a/tests/ui/const-generics/const_trait_fn-issue-88433.rs b/tests/ui/const-generics/const_trait_fn-issue-88433.rs index bc91fc1700eaf..045b4ba378230 100644 --- a/tests/ui/const-generics/const_trait_fn-issue-88433.rs +++ b/tests/ui/const-generics/const_trait_fn-issue-88433.rs @@ -7,7 +7,7 @@ trait Func { type Output; - fn call_once(self, arg: T) -> Self::Output; + (const) fn call_once(self, arg: T) -> Self::Output; } @@ -16,7 +16,7 @@ struct Closure; impl const Func<&usize> for Closure { type Output = usize; - fn call_once(self, arg: &usize) -> Self::Output { + (const) fn call_once(self, arg: &usize) -> Self::Output { *arg } } diff --git a/tests/ui/consts/const-try.rs b/tests/ui/consts/const-try.rs index 26aa9230a3983..07b0b103b5615 100644 --- a/tests/ui/consts/const-try.rs +++ b/tests/ui/consts/const-try.rs @@ -14,7 +14,7 @@ struct Error; impl const FromResidual for TryMe { //~^ ERROR const `impl` for trait `FromResidual` which is not marked with `#[const_trait]` - fn from_residual(residual: Error) -> Self { + (const) fn from_residual(residual: Error) -> Self { TryMe } } @@ -23,10 +23,10 @@ impl const Try for TryMe { //~^ ERROR const `impl` for trait `Try` which is not marked with `#[const_trait]` type Output = (); type Residual = Error; - fn from_output(output: Self::Output) -> Self { + (const) fn from_output(output: Self::Output) -> Self { TryMe } - fn branch(self) -> ControlFlow { + (const) fn branch(self) -> ControlFlow { ControlFlow::Break(Error) } } diff --git a/tests/ui/consts/constifconst-call-in-const-position.stderr b/tests/ui/consts/constifconst-call-in-const-position.stderr index c778299560fab..c49c013ca7b02 100644 --- a/tests/ui/consts/constifconst-call-in-const-position.stderr +++ b/tests/ui/consts/constifconst-call-in-const-position.stderr @@ -1,3 +1,9 @@ +error: non-const fn in const traits are not supported yet + --> $DIR/constifconst-call-in-const-position.rs:8:5 + | +LL | fn a() -> usize; + | ^ help: mark the function as const: `(const)` + error[E0277]: the trait bound `T: const Tr` is not satisfied --> $DIR/constifconst-call-in-const-position.rs:17:38 | @@ -10,6 +16,6 @@ error[E0277]: the trait bound `T: const Tr` is not satisfied LL | [0; T::a()] | ^ -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/consts/promoted-const-drop.rs b/tests/ui/consts/promoted-const-drop.rs index 1d1897e15d443..39e3fc961e304 100644 --- a/tests/ui/consts/promoted-const-drop.rs +++ b/tests/ui/consts/promoted-const-drop.rs @@ -3,7 +3,7 @@ struct A(); impl const Drop for A { - fn drop(&mut self) {} + (const) fn drop(&mut self) {} } const C: A = A(); diff --git a/tests/ui/consts/promoted_const_call.rs b/tests/ui/consts/promoted_const_call.rs index 79cb2ea2a02a0..18d3e08659fa9 100644 --- a/tests/ui/consts/promoted_const_call.rs +++ b/tests/ui/consts/promoted_const_call.rs @@ -1,7 +1,7 @@ #![feature(const_trait_impl, const_destruct)] struct Panic; -impl const Drop for Panic { fn drop(&mut self) { panic!(); } } +impl const Drop for Panic { (const) fn drop(&mut self) { panic!(); } } pub const fn id(x: T) -> T { x } pub const C: () = { diff --git a/tests/ui/coroutine/gen_fn.none.stderr b/tests/ui/coroutine/gen_fn.none.stderr index 590210641aed4..f3c770bb65865 100644 --- a/tests/ui/coroutine/gen_fn.none.stderr +++ b/tests/ui/coroutine/gen_fn.none.stderr @@ -1,8 +1,8 @@ -error: expected one of `#`, `async`, `const`, `default`, `extern`, `fn`, `pub`, `safe`, `unsafe`, or `use`, found `gen` +error: expected one of `#`, `(`, `async`, `const`, `default`, `extern`, `fn`, `pub`, `safe`, `unsafe`, or `use`, found `gen` --> $DIR/gen_fn.rs:4:1 | LL | gen fn foo() {} - | ^^^ expected one of 10 possible tokens + | ^^^ expected one of 11 possible tokens error: aborting due to 1 previous error diff --git a/tests/ui/coroutine/gen_fn.rs b/tests/ui/coroutine/gen_fn.rs index 2f50d5db9acf6..61881eedadaa5 100644 --- a/tests/ui/coroutine/gen_fn.rs +++ b/tests/ui/coroutine/gen_fn.rs @@ -2,7 +2,7 @@ //@[e2024] edition: 2024 gen fn foo() {} -//[none]~^ ERROR: expected one of `#`, `async`, `const`, `default`, `extern`, `fn`, `pub`, `safe`, `unsafe`, or `use`, found `gen` +//[none]~^ ERROR: expected one of `#`, `(`, `async`, `const`, `default`, `extern`, `fn`, `pub`, `safe`, `unsafe`, or `use`, found `gen` //[e2024]~^^ ERROR: gen blocks are experimental fn main() {} diff --git a/tests/ui/delegation/unsupported.rs b/tests/ui/delegation/unsupported.rs index af1c20976d7ad..1a6ddf07af050 100644 --- a/tests/ui/delegation/unsupported.rs +++ b/tests/ui/delegation/unsupported.rs @@ -42,7 +42,7 @@ mod recursive { mod effects { #[const_trait] trait Trait { - fn foo(); + (const) fn foo(); } reuse Trait::foo; diff --git a/tests/ui/generic-const-items/const-trait-impl.rs b/tests/ui/generic-const-items/const-trait-impl.rs index e11d346b712d8..8639291a97a81 100644 --- a/tests/ui/generic-const-items/const-trait-impl.rs +++ b/tests/ui/generic-const-items/const-trait-impl.rs @@ -13,11 +13,11 @@ pub const K1: i32 = CREATE; // arg inferred #[const_trait] trait Create { - fn create() -> Self; + (const) fn create() -> Self; } impl const Create for i32 { - fn create() -> i32 { + (const) fn create() -> i32 { 4096 } } diff --git a/tests/ui/parser/impls-nested-within-fns-semantic-1.rs b/tests/ui/parser/impls-nested-within-fns-semantic-1.rs index f06d19d7f5ec6..225027fa0d70a 100644 --- a/tests/ui/parser/impls-nested-within-fns-semantic-1.rs +++ b/tests/ui/parser/impls-nested-within-fns-semantic-1.rs @@ -6,11 +6,11 @@ #[const_trait] trait Trait { - fn required(); + (const) fn required(); } impl const Trait for () { - fn required() { + (const) fn required() { pub struct Type; impl Type { diff --git a/tests/ui/parser/misspelled-keywords/pub-fn.stderr b/tests/ui/parser/misspelled-keywords/pub-fn.stderr index 1123c652c0ee7..5f88d2868dc69 100644 --- a/tests/ui/parser/misspelled-keywords/pub-fn.stderr +++ b/tests/ui/parser/misspelled-keywords/pub-fn.stderr @@ -1,8 +1,8 @@ -error: expected one of `#`, `async`, `auto`, `const`, `default`, `enum`, `extern`, `fn`, `gen`, `impl`, `macro_rules`, `macro`, `mod`, `pub`, `safe`, `static`, `struct`, `trait`, `type`, `unsafe`, or `use`, found `puB` +error: expected one of `#`, `(`, `async`, `auto`, `const`, `default`, `enum`, `extern`, `fn`, `gen`, `impl`, `macro_rules`, `macro`, `mod`, `pub`, `safe`, `static`, `struct`, `trait`, `type`, `unsafe`, or `use`, found `puB` --> $DIR/pub-fn.rs:1:1 | LL | puB fn code() {} - | ^^^ expected one of 21 possible tokens + | ^^^ expected one of 22 possible tokens | help: write keyword `pub` in lowercase | diff --git a/tests/ui/specialization/const_trait_impl.stderr b/tests/ui/specialization/const_trait_impl.stderr index 3e1260ff09c92..6540e8beaeb37 100644 --- a/tests/ui/specialization/const_trait_impl.stderr +++ b/tests/ui/specialization/const_trait_impl.stderr @@ -1,3 +1,45 @@ +error: non-const fn in const traits are not supported yet + --> $DIR/const_trait_impl.rs:8:5 + | +LL | fn foo() -> u32; + | ^ help: mark the function as const: `(const)` + +error: non-const fn in const traits are not supported yet + --> $DIR/const_trait_impl.rs:16:5 + | +LL | default fn foo() -> u32 { + | ^ help: mark the function as const: `const` + +error: non-const fn in const traits are not supported yet + --> $DIR/const_trait_impl.rs:22:5 + | +LL | fn foo() -> u32 { + | ^ help: mark the function as const: `const` + +error: non-const fn in const traits are not supported yet + --> $DIR/const_trait_impl.rs:31:5 + | +LL | fn a() -> u32; + | ^ help: mark the function as const: `(const)` + +error: non-const fn in const traits are not supported yet + --> $DIR/const_trait_impl.rs:35:5 + | +LL | default fn a() -> u32 { + | ^ help: mark the function as const: `const` + +error: non-const fn in const traits are not supported yet + --> $DIR/const_trait_impl.rs:41:5 + | +LL | default fn a() -> u32 { + | ^ help: mark the function as const: `const` + +error: non-const fn in const traits are not supported yet + --> $DIR/const_trait_impl.rs:47:5 + | +LL | fn a() -> u32 { + | ^ help: mark the function as const: `const` + error: `~const` can only be applied to `#[const_trait]` traits --> $DIR/const_trait_impl.rs:34:9 | @@ -55,5 +97,5 @@ note: `Default` can't be used with `~const` because it isn't annotated with `#[c --> $SRC_DIR/core/src/default.rs:LL:COL = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` -error: aborting due to 6 previous errors +error: aborting due to 13 previous errors diff --git a/tests/ui/structs/default-field-values/support.rs b/tests/ui/structs/default-field-values/support.rs index 8209d6dd4a093..f178c582b0c3e 100644 --- a/tests/ui/structs/default-field-values/support.rs +++ b/tests/ui/structs/default-field-values/support.rs @@ -28,11 +28,11 @@ pub enum Bar { } #[const_trait] pub trait ConstDefault { - fn value() -> Self; + (const) fn value() -> Self; } impl const ConstDefault for i32 { - fn value() -> i32 { + (const) fn value() -> i32 { 101 } } diff --git a/tests/ui/traits/const-traits/assoc-type-const-bound-usage-0.rs b/tests/ui/traits/const-traits/assoc-type-const-bound-usage-0.rs index 9141d327aee87..c129262475e2e 100644 --- a/tests/ui/traits/const-traits/assoc-type-const-bound-usage-0.rs +++ b/tests/ui/traits/const-traits/assoc-type-const-bound-usage-0.rs @@ -7,7 +7,7 @@ #[const_trait] trait Trait { type Assoc: ~const Trait; - fn func() -> i32; + (const) fn func() -> i32; } const fn unqualified() -> i32 { diff --git a/tests/ui/traits/const-traits/assoc-type-const-bound-usage-1.rs b/tests/ui/traits/const-traits/assoc-type-const-bound-usage-1.rs index 19e86b50d3321..9339cc76bb7d4 100644 --- a/tests/ui/traits/const-traits/assoc-type-const-bound-usage-1.rs +++ b/tests/ui/traits/const-traits/assoc-type-const-bound-usage-1.rs @@ -6,7 +6,7 @@ #[const_trait] trait Trait { type Assoc: ~const Trait; - fn func() -> i32; + (const) fn func() -> i32; } struct Type; diff --git a/tests/ui/traits/const-traits/assoc-type-const-bound-usage-fail-2.rs b/tests/ui/traits/const-traits/assoc-type-const-bound-usage-fail-2.rs index e1c30b5361124..6fe8249c8f030 100644 --- a/tests/ui/traits/const-traits/assoc-type-const-bound-usage-fail-2.rs +++ b/tests/ui/traits/const-traits/assoc-type-const-bound-usage-fail-2.rs @@ -14,7 +14,7 @@ trait Trait { where U: ~const Other; - fn func(); + (const) fn func(); } #[const_trait] diff --git a/tests/ui/traits/const-traits/assoc-type-const-bound-usage-fail.rs b/tests/ui/traits/const-traits/assoc-type-const-bound-usage-fail.rs index 3761fea19684d..afa4d890d13b5 100644 --- a/tests/ui/traits/const-traits/assoc-type-const-bound-usage-fail.rs +++ b/tests/ui/traits/const-traits/assoc-type-const-bound-usage-fail.rs @@ -10,7 +10,7 @@ #[const_trait] trait Trait { type Assoc: ~const Trait; - fn func(); + (const) fn func(); } const fn unqualified() { diff --git a/tests/ui/traits/const-traits/assoc-type.rs b/tests/ui/traits/const-traits/assoc-type.rs index a169b61994cbf..32b1f9f93626d 100644 --- a/tests/ui/traits/const-traits/assoc-type.rs +++ b/tests/ui/traits/const-traits/assoc-type.rs @@ -7,13 +7,13 @@ trait Add { type Output; - fn add(self, other: Rhs) -> Self::Output; + (const) fn add(self, other: Rhs) -> Self::Output; } impl const Add for i32 { type Output = Self; - fn add(self, other: Self) -> Self::Output { + (const) fn add(self, other: Self) -> Self::Output { self + other } } diff --git a/tests/ui/traits/const-traits/async-const-trait-methods.rs b/tests/ui/traits/const-traits/async-const-trait-methods.rs new file mode 100644 index 0000000000000..a1dba5fd68541 --- /dev/null +++ b/tests/ui/traits/const-traits/async-const-trait-methods.rs @@ -0,0 +1,23 @@ +//This test used to ICE: #117629 +//@ edition:2021 + +#![feature(const_trait_impl)] + +#[const_trait] +trait Tr { + (const) async fn ft1() {} + //~^ ERROR: functions cannot be both `const` and `async` + async fn ft2() {} + //~^ ERROR: non-const fn in const traits are not supported yet + const async fn ft3() {} + //~^ ERROR: functions in traits cannot be declared const + //~| ERROR: functions cannot be both `const` and `async` + async const fn ft4() {} + //~^ ERROR: expected one of `extern`, `fn`, `safe`, or `unsafe`, found keyword `const` + //~| ERROR: functions in traits cannot be declared const + //~| ERROR: functions cannot be both `const` and `async` + async (const) fn ft5() {} + //~^ ERROR: non-item in item list +} + +fn main() {} diff --git a/tests/ui/traits/const-traits/async-const-trait-methods.stderr b/tests/ui/traits/const-traits/async-const-trait-methods.stderr new file mode 100644 index 0000000000000..b7bd7246524c8 --- /dev/null +++ b/tests/ui/traits/const-traits/async-const-trait-methods.stderr @@ -0,0 +1,83 @@ +error: expected one of `extern`, `fn`, `safe`, or `unsafe`, found keyword `const` + --> $DIR/async-const-trait-methods.rs:15:11 + | +LL | async const fn ft4() {} + | ------^^^^^ + | | | + | | expected one of `extern`, `fn`, `safe`, or `unsafe` + | help: `const` must come before `async`: `const async` + | + = note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern` + +error: non-item in item list + --> $DIR/async-const-trait-methods.rs:19:5 + | +LL | trait Tr { + | - item list starts here +... +LL | async (const) fn ft5() {} + | ^^^^^ non-item starts here +LL | +LL | } + | - item list ends here + +error: functions cannot be both `const` and `async` + --> $DIR/async-const-trait-methods.rs:8:5 + | +LL | (const) async fn ft1() {} + | ^^^^^^^-^^^^^------------ + | | | + | | `async` because of this + | `const` because of this + +error: non-const fn in const traits are not supported yet + --> $DIR/async-const-trait-methods.rs:10:5 + | +LL | async fn ft2() {} + | ^ help: mark the function as const: `(const)` + +error[E0379]: functions in traits cannot be declared const + --> $DIR/async-const-trait-methods.rs:12:5 + | +LL | #[const_trait] + | -------------- this declares all associated functions implicitly const +... +LL | const async fn ft3() {} + | ^^^^^- + | | + | functions in traits cannot be const + | help: remove the `const` + +error: functions cannot be both `const` and `async` + --> $DIR/async-const-trait-methods.rs:12:5 + | +LL | const async fn ft3() {} + | ^^^^^-^^^^^------------ + | | | + | | `async` because of this + | `const` because of this + +error[E0379]: functions in traits cannot be declared const + --> $DIR/async-const-trait-methods.rs:15:11 + | +LL | #[const_trait] + | -------------- this declares all associated functions implicitly const +... +LL | async const fn ft4() {} + | ^^^^^- + | | + | functions in traits cannot be const + | help: remove the `const` + +error: functions cannot be both `const` and `async` + --> $DIR/async-const-trait-methods.rs:15:5 + | +LL | async const fn ft4() {} + | ^^^^^-^^^^^------------ + | | | + | | `const` because of this + | `async` because of this + +error: aborting due to 8 previous errors + +For more information about this error, try `rustc --explain E0379`. diff --git a/tests/ui/traits/const-traits/attr-misuse.rs b/tests/ui/traits/const-traits/attr-misuse.rs index 01ac74feff74d..e7b7bda89b08e 100644 --- a/tests/ui/traits/const-traits/attr-misuse.rs +++ b/tests/ui/traits/const-traits/attr-misuse.rs @@ -3,7 +3,7 @@ #[const_trait] trait A { #[const_trait] //~ ERROR attribute should be applied - fn foo(self); + (const) fn foo(self); } #[const_trait] //~ ERROR attribute should be applied diff --git a/tests/ui/traits/const-traits/attr-misuse.stderr b/tests/ui/traits/const-traits/attr-misuse.stderr index 998958cedf748..e8b8413f1c4ea 100644 --- a/tests/ui/traits/const-traits/attr-misuse.stderr +++ b/tests/ui/traits/const-traits/attr-misuse.stderr @@ -11,8 +11,8 @@ error: attribute should be applied to a trait | LL | #[const_trait] | ^^^^^^^^^^^^^^ -LL | fn foo(self); - | ------------- not a trait +LL | (const) fn foo(self); + | --------------------- not a trait error: aborting due to 2 previous errors diff --git a/tests/ui/traits/const-traits/auxiliary/cross-crate.rs b/tests/ui/traits/const-traits/auxiliary/cross-crate.rs index 01921c140cbcf..de4dd7fa5e2ad 100644 --- a/tests/ui/traits/const-traits/auxiliary/cross-crate.rs +++ b/tests/ui/traits/const-traits/auxiliary/cross-crate.rs @@ -3,8 +3,8 @@ #[const_trait] pub trait MyTrait { - fn defaulted_func(&self) {} - fn func(self); + (const) fn defaulted_func(&self) {} + (const) fn func(self); } pub struct NonConst; @@ -18,7 +18,7 @@ impl MyTrait for NonConst { pub struct Const; impl const MyTrait for Const { - fn func(self) { + (const) fn func(self) { } } diff --git a/tests/ui/traits/const-traits/auxiliary/minicore.rs b/tests/ui/traits/const-traits/auxiliary/minicore.rs index 08d7817548d7c..78edef720c483 100644 --- a/tests/ui/traits/const-traits/auxiliary/minicore.rs +++ b/tests/ui/traits/const-traits/auxiliary/minicore.rs @@ -32,12 +32,12 @@ impl Copy for &T {} pub trait Add { type Output; - fn add(self, rhs: Rhs) -> Self::Output; + (const) fn add(self, rhs: Rhs) -> Self::Output; } impl const Add for i32 { type Output = i32; - fn add(self, rhs: i32) -> i32 { + (const) fn add(self, rhs: i32) -> i32 { loop {} } } @@ -57,16 +57,16 @@ pub trait Try: FromResidual { type Residual; #[lang = "from_output"] - fn from_output(output: Self::Output) -> Self; + (const) fn from_output(output: Self::Output) -> Self; #[lang = "branch"] - fn branch(self) -> ControlFlow; + (const) fn branch(self) -> ControlFlow; } #[const_trait] pub trait FromResidual::Residual> { #[lang = "from_residual"] - fn from_residual(residual: R) -> Self; + (const) fn from_residual(residual: R) -> Self; } enum ControlFlow { @@ -80,14 +80,14 @@ enum ControlFlow { #[lang = "fn"] #[rustc_paren_sugar] pub trait Fn: ~const FnMut { - extern "rust-call" fn call(&self, args: Args) -> Self::Output; + (const) extern "rust-call" fn call(&self, args: Args) -> Self::Output; } #[const_trait] #[lang = "fn_mut"] #[rustc_paren_sugar] pub trait FnMut: ~const FnOnce { - extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output; + (const) extern "rust-call" fn call_mut(&mut self, args: Args) -> Self::Output; } #[const_trait] @@ -97,7 +97,7 @@ pub trait FnOnce { #[lang = "fn_once_output"] type Output; - extern "rust-call" fn call_once(self, args: Args) -> Self::Output; + (const) extern "rust-call" fn call_once(self, args: Args) -> Self::Output; } #[lang = "tuple_trait"] @@ -130,7 +130,7 @@ pub unsafe auto trait Freeze {} #[lang = "drop"] #[const_trait] pub trait Drop { - fn drop(&mut self); + (const) fn drop(&mut self); } #[const_trait] @@ -165,13 +165,13 @@ fn panic_fmt() {} pub trait Index { type Output: ?Sized; - fn index(&self, index: Idx) -> &Self::Output; + (const) fn index(&self, index: Idx) -> &Self::Output; } #[const_trait] pub unsafe trait SliceIndex { type Output: ?Sized; - fn index(self, slice: &T) -> &Self::Output; + (const) fn index(self, slice: &T) -> &Self::Output; } impl const Index for [T] @@ -181,7 +181,7 @@ where type Output = I::Output; #[inline] - fn index(&self, index: I) -> &I::Output { + (const) fn index(&self, index: I) -> &I::Output { index.index(self) } } @@ -193,7 +193,7 @@ where type Output = <[T] as Index>::Output; #[inline] - fn index(&self, index: I) -> &<[T] as Index>::Output { + (const) fn index(&self, index: I) -> &<[T] as Index>::Output { Index::index(self as &[T], index) } } @@ -212,13 +212,13 @@ pub trait Deref { #[lang = "deref_target"] type Target: ?Sized; - fn deref(&self) -> &Self::Target; + (const) fn deref(&self) -> &Self::Target; } impl const Deref for &T { type Target = T; - fn deref(&self) -> &T { + (const) fn deref(&self) -> &T { *self } } @@ -226,7 +226,7 @@ impl const Deref for &T { impl const Deref for &mut T { type Target = T; - fn deref(&self) -> &T { + (const) fn deref(&self) -> &T { *self } } @@ -268,25 +268,25 @@ where #[const_trait] pub trait Into: Sized { - fn into(self) -> T; + (const) fn into(self) -> T; } #[const_trait] pub trait From: Sized { - fn from(value: T) -> Self; + (const) fn from(value: T) -> Self; } impl const Into for T where U: ~const From, { - fn into(self) -> U { + (const) fn into(self) -> U { U::from(self) } } impl const From for T { - fn from(t: T) -> T { + (const) fn from(t: T) -> T { t } } @@ -308,8 +308,8 @@ fn from_str(s: &str) -> Result { #[lang = "eq"] #[const_trait] pub trait PartialEq { - fn eq(&self, other: &Rhs) -> bool; - fn ne(&self, other: &Rhs) -> bool { + (const) fn eq(&self, other: &Rhs) -> bool; + (const) fn ne(&self, other: &Rhs) -> bool { !self.eq(other) } } @@ -318,7 +318,7 @@ impl const PartialEq<&B> for &A where A: ~const PartialEq, { - fn eq(&self, other: &&B) -> bool { + (const) fn eq(&self, other: &&B) -> bool { PartialEq::eq(*self, *other) } } @@ -333,12 +333,12 @@ impl PartialEq for str { #[const_trait] pub trait Not { type Output; - fn not(self) -> Self::Output; + (const) fn not(self) -> Self::Output; } impl const Not for bool { type Output = bool; - fn not(self) -> bool { + (const) fn not(self) -> bool { !self } } @@ -398,14 +398,14 @@ impl Option { impl const Deref for Pin

{ type Target = P::Target; - fn deref(&self) -> &P::Target { + (const) fn deref(&self) -> &P::Target { Pin::get_ref(Pin::as_ref(self)) } } impl const Deref for Option { type Target = T; - fn deref(&self) -> &T { + (const) fn deref(&self) -> &T { loop {} } } @@ -457,8 +457,8 @@ impl Deref for Ref<'_, T> { #[rustc_trivial_field_reads] #[const_trait] pub trait Clone: Sized { - fn clone(&self) -> Self; - fn clone_from(&mut self, source: &Self) + (const) fn clone(&self) -> Self; + (const) fn clone_from(&mut self, source: &Self) where Self: ~const Destruct, { diff --git a/tests/ui/traits/const-traits/call-const-closure.rs b/tests/ui/traits/const-traits/call-const-closure.rs index 21f4374b8d530..ffc99641c73b0 100644 --- a/tests/ui/traits/const-traits/call-const-closure.rs +++ b/tests/ui/traits/const-traits/call-const-closure.rs @@ -6,7 +6,7 @@ #[const_trait] trait Bar { - fn foo(&self); + (const) fn foo(&self); } impl Bar for () { diff --git a/tests/ui/traits/const-traits/call-const-in-tilde-const.rs b/tests/ui/traits/const-traits/call-const-in-tilde-const.rs index b6d1517499d6e..b3f27ad14a8b6 100644 --- a/tests/ui/traits/const-traits/call-const-in-tilde-const.rs +++ b/tests/ui/traits/const-traits/call-const-in-tilde-const.rs @@ -2,7 +2,7 @@ #![feature(const_trait_impl)] #[const_trait] trait Foo { - fn foo(); + (const) fn foo(); } const fn foo() { diff --git a/tests/ui/traits/const-traits/call-const-trait-method-fail.rs b/tests/ui/traits/const-traits/call-const-trait-method-fail.rs index e06d04db80409..3053d5a5f0ae4 100644 --- a/tests/ui/traits/const-traits/call-const-trait-method-fail.rs +++ b/tests/ui/traits/const-traits/call-const-trait-method-fail.rs @@ -3,11 +3,11 @@ #[const_trait] pub trait Plus { - fn plus(self, rhs: Self) -> Self; + (const) fn plus(self, rhs: Self) -> Self; } impl const Plus for i32 { - fn plus(self, rhs: Self) -> Self { + (const) fn plus(self, rhs: Self) -> Self { self + rhs } } diff --git a/tests/ui/traits/const-traits/call-const-trait-method-pass.stderr b/tests/ui/traits/const-traits/call-const-trait-method-pass.stderr index 7746f103ac368..7490f1fe64d62 100644 --- a/tests/ui/traits/const-traits/call-const-trait-method-pass.stderr +++ b/tests/ui/traits/const-traits/call-const-trait-method-pass.stderr @@ -1,3 +1,33 @@ +error: non-const fn in const traits are not supported yet + --> $DIR/call-const-trait-method-pass.rs:10:5 + | +LL | fn add(self, rhs: Self) -> Self { + | ^ help: mark the function as const: `const` + +error: non-const fn in const traits are not supported yet + --> $DIR/call-const-trait-method-pass.rs:16:5 + | +LL | fn eq(&self, rhs: &Self) -> bool { + | ^ help: mark the function as const: `const` + +error: non-const fn in const traits are not supported yet + --> $DIR/call-const-trait-method-pass.rs:19:5 + | +LL | fn ne(&self, other: &Self) -> bool { + | ^ help: mark the function as const: `const` + +error: non-const fn in const traits are not supported yet + --> $DIR/call-const-trait-method-pass.rs:26:5 + | +LL | fn plus(self, rhs: Self) -> Self; + | ^ help: mark the function as const: `(const)` + +error: non-const fn in const traits are not supported yet + --> $DIR/call-const-trait-method-pass.rs:30:5 + | +LL | fn plus(self, rhs: Self) -> Self { + | ^ help: mark the function as const: `const` + error: const `impl` for trait `PartialEq` which is not marked with `#[const_trait]` --> $DIR/call-const-trait-method-pass.rs:15:12 | @@ -15,6 +45,6 @@ LL | !self.eq(other) | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants -error: aborting due to 2 previous errors +error: aborting due to 7 previous errors For more information about this error, try `rustc --explain E0015`. diff --git a/tests/ui/traits/const-traits/call-generic-in-impl.stderr b/tests/ui/traits/const-traits/call-generic-in-impl.stderr index a45dfd95b4a46..13dc00c44c156 100644 --- a/tests/ui/traits/const-traits/call-generic-in-impl.stderr +++ b/tests/ui/traits/const-traits/call-generic-in-impl.stderr @@ -1,3 +1,15 @@ +error: non-const fn in const traits are not supported yet + --> $DIR/call-generic-in-impl.rs:7:5 + | +LL | fn eq(&self, other: &Self) -> bool; + | ^ help: mark the function as const: `(const)` + +error: non-const fn in const traits are not supported yet + --> $DIR/call-generic-in-impl.rs:11:5 + | +LL | fn eq(&self, other: &Self) -> bool { + | ^ help: mark the function as const: `const` + error: `~const` can only be applied to `#[const_trait]` traits --> $DIR/call-generic-in-impl.rs:10:9 | @@ -25,6 +37,6 @@ LL | PartialEq::eq(self, other) | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants -error: aborting due to 3 previous errors +error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0015`. diff --git a/tests/ui/traits/const-traits/call-generic-method-chain.stderr b/tests/ui/traits/const-traits/call-generic-method-chain.stderr index 40b4f14733f0c..85db14833408f 100644 --- a/tests/ui/traits/const-traits/call-generic-method-chain.stderr +++ b/tests/ui/traits/const-traits/call-generic-method-chain.stderr @@ -1,3 +1,15 @@ +error: non-const fn in const traits are not supported yet + --> $DIR/call-generic-method-chain.rs:12:5 + | +LL | fn eq(&self, _: &S) -> bool { + | ^ help: mark the function as const: `const` + +error: non-const fn in const traits are not supported yet + --> $DIR/call-generic-method-chain.rs:15:5 + | +LL | fn ne(&self, other: &S) -> bool { + | ^ help: mark the function as const: `const` + error: const `impl` for trait `PartialEq` which is not marked with `#[const_trait]` --> $DIR/call-generic-method-chain.rs:11:12 | @@ -61,6 +73,6 @@ LL | !self.eq(other) | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants -error: aborting due to 7 previous errors +error: aborting due to 9 previous errors For more information about this error, try `rustc --explain E0015`. diff --git a/tests/ui/traits/const-traits/call-generic-method-dup-bound.stderr b/tests/ui/traits/const-traits/call-generic-method-dup-bound.stderr index c74f5cf786c1e..cf6a9f86f4d25 100644 --- a/tests/ui/traits/const-traits/call-generic-method-dup-bound.stderr +++ b/tests/ui/traits/const-traits/call-generic-method-dup-bound.stderr @@ -1,3 +1,15 @@ +error: non-const fn in const traits are not supported yet + --> $DIR/call-generic-method-dup-bound.rs:10:5 + | +LL | fn eq(&self, _: &S) -> bool { + | ^ help: mark the function as const: `const` + +error: non-const fn in const traits are not supported yet + --> $DIR/call-generic-method-dup-bound.rs:13:5 + | +LL | fn ne(&self, other: &S) -> bool { + | ^ help: mark the function as const: `const` + error: const `impl` for trait `PartialEq` which is not marked with `#[const_trait]` --> $DIR/call-generic-method-dup-bound.rs:9:12 | @@ -69,6 +81,6 @@ LL | *t == *t | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants -error: aborting due to 8 previous errors +error: aborting due to 10 previous errors For more information about this error, try `rustc --explain E0015`. diff --git a/tests/ui/traits/const-traits/call-generic-method-nonconst.rs b/tests/ui/traits/const-traits/call-generic-method-nonconst.rs index 446a74eb7b7d4..fccf135125dcf 100644 --- a/tests/ui/traits/const-traits/call-generic-method-nonconst.rs +++ b/tests/ui/traits/const-traits/call-generic-method-nonconst.rs @@ -5,7 +5,7 @@ struct S; #[const_trait] trait Foo { - fn eq(&self, _: &Self) -> bool; + (const) fn eq(&self, _: &Self) -> bool; } impl Foo for S { diff --git a/tests/ui/traits/const-traits/call-generic-method-pass.stderr b/tests/ui/traits/const-traits/call-generic-method-pass.stderr index 1a33ff5ab450f..d34b359e5801a 100644 --- a/tests/ui/traits/const-traits/call-generic-method-pass.stderr +++ b/tests/ui/traits/const-traits/call-generic-method-pass.stderr @@ -1,3 +1,15 @@ +error: non-const fn in const traits are not supported yet + --> $DIR/call-generic-method-pass.rs:12:5 + | +LL | fn eq(&self, _: &S) -> bool { + | ^ help: mark the function as const: `const` + +error: non-const fn in const traits are not supported yet + --> $DIR/call-generic-method-pass.rs:15:5 + | +LL | fn ne(&self, other: &S) -> bool { + | ^ help: mark the function as const: `const` + error: const `impl` for trait `PartialEq` which is not marked with `#[const_trait]` --> $DIR/call-generic-method-pass.rs:11:12 | @@ -42,6 +54,6 @@ LL | !self.eq(other) | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants -error: aborting due to 5 previous errors +error: aborting due to 7 previous errors For more information about this error, try `rustc --explain E0015`. diff --git a/tests/ui/traits/const-traits/const-and-non-const-impl.stderr b/tests/ui/traits/const-traits/const-and-non-const-impl.stderr index 4eb1517734700..706f172a725ef 100644 --- a/tests/ui/traits/const-traits/const-and-non-const-impl.stderr +++ b/tests/ui/traits/const-traits/const-and-non-const-impl.stderr @@ -1,3 +1,15 @@ +error: non-const fn in const traits are not supported yet + --> $DIR/const-and-non-const-impl.rs:10:5 + | +LL | fn add(self, rhs: Self) -> Self { + | ^ help: mark the function as const: `const` + +error: non-const fn in const traits are not supported yet + --> $DIR/const-and-non-const-impl.rs:26:5 + | +LL | fn add(self, rhs: Self) -> Self { + | ^ help: mark the function as const: `const` + error[E0119]: conflicting implementations of trait `Add` for type `Int` --> $DIR/const-and-non-const-impl.rs:23:1 | @@ -20,7 +32,7 @@ LL | impl const std::ops::Add for i32 { = note: for more information see https://doc.rust-lang.org/reference/items/implementations.html#orphan-rules = note: define and implement a trait or new type instead -error: aborting due to 2 previous errors +error: aborting due to 4 previous errors Some errors have detailed explanations: E0117, E0119. For more information about an error, try `rustc --explain E0117`. diff --git a/tests/ui/traits/const-traits/const-bound-in-host.rs b/tests/ui/traits/const-traits/const-bound-in-host.rs index b4c4f5a6de1d0..32cb540ebd372 100644 --- a/tests/ui/traits/const-traits/const-bound-in-host.rs +++ b/tests/ui/traits/const-traits/const-bound-in-host.rs @@ -4,7 +4,7 @@ #![feature(const_trait_impl)] #[const_trait] trait Foo { - fn foo(); + (const) fn foo(); } fn foo() { diff --git a/tests/ui/traits/const-traits/const-bound-on-not-const-associated-fn.rs b/tests/ui/traits/const-traits/const-bound-on-not-const-associated-fn.rs index c735f855bcea7..84feef158528b 100644 --- a/tests/ui/traits/const-traits/const-bound-on-not-const-associated-fn.rs +++ b/tests/ui/traits/const-traits/const-bound-on-not-const-associated-fn.rs @@ -4,7 +4,7 @@ #[const_trait] trait MyTrait { - fn do_something(&self); + (const) fn do_something(&self); } trait OtherTrait { @@ -15,7 +15,7 @@ trait OtherTrait { struct MyStruct(T); impl const MyTrait for u32 { - fn do_something(&self) {} + (const) fn do_something(&self) {} } impl MyStruct { diff --git a/tests/ui/traits/const-traits/const-check-fns-in-const-impl.rs b/tests/ui/traits/const-traits/const-check-fns-in-const-impl.rs index f7686ea6139b5..b35d2ec34d4e9 100644 --- a/tests/ui/traits/const-traits/const-check-fns-in-const-impl.rs +++ b/tests/ui/traits/const-traits/const-check-fns-in-const-impl.rs @@ -5,13 +5,13 @@ struct S; #[const_trait] trait T { - fn foo(); + (const) fn foo(); } fn non_const() {} impl const T for S { - fn foo() { non_const() } + (const) fn foo() { non_const() } //~^ ERROR cannot call non-const function } diff --git a/tests/ui/traits/const-traits/const-check-fns-in-const-impl.stderr b/tests/ui/traits/const-traits/const-check-fns-in-const-impl.stderr index 599a5503b0f33..f8301386d0727 100644 --- a/tests/ui/traits/const-traits/const-check-fns-in-const-impl.stderr +++ b/tests/ui/traits/const-traits/const-check-fns-in-const-impl.stderr @@ -1,8 +1,8 @@ error[E0015]: cannot call non-const function `non_const` in constant functions - --> $DIR/const-check-fns-in-const-impl.rs:14:16 + --> $DIR/const-check-fns-in-const-impl.rs:14:24 | -LL | fn foo() { non_const() } - | ^^^^^^^^^^^ +LL | (const) fn foo() { non_const() } + | ^^^^^^^^^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants diff --git a/tests/ui/traits/const-traits/const-closure-trait-method-fail.stderr b/tests/ui/traits/const-traits/const-closure-trait-method-fail.stderr index 2a97846ccb448..c65647911742e 100644 --- a/tests/ui/traits/const-traits/const-closure-trait-method-fail.stderr +++ b/tests/ui/traits/const-traits/const-closure-trait-method-fail.stderr @@ -1,3 +1,9 @@ +error: non-const fn in const traits are not supported yet + --> $DIR/const-closure-trait-method-fail.rs:7:5 + | +LL | fn a(self) -> i32; + | ^ help: mark the function as const: `(const)` + error: `~const` can only be applied to `#[const_trait]` traits --> $DIR/const-closure-trait-method-fail.rs:14:32 | @@ -25,6 +31,6 @@ LL | x(()) | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0015`. diff --git a/tests/ui/traits/const-traits/const-closure-trait-method.stderr b/tests/ui/traits/const-traits/const-closure-trait-method.stderr index 9c63b7e63a65d..01332ba99f1f2 100644 --- a/tests/ui/traits/const-traits/const-closure-trait-method.stderr +++ b/tests/ui/traits/const-traits/const-closure-trait-method.stderr @@ -1,3 +1,15 @@ +error: non-const fn in const traits are not supported yet + --> $DIR/const-closure-trait-method.rs:7:5 + | +LL | fn a(self) -> i32; + | ^ help: mark the function as const: `(const)` + +error: non-const fn in const traits are not supported yet + --> $DIR/const-closure-trait-method.rs:11:5 + | +LL | fn a(self) -> i32 { 42 } + | ^ help: mark the function as const: `const` + error: `~const` can only be applied to `#[const_trait]` traits --> $DIR/const-closure-trait-method.rs:14:32 | @@ -25,6 +37,6 @@ LL | x(()) | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants -error: aborting due to 3 previous errors +error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0015`. diff --git a/tests/ui/traits/const-traits/const-cond-for-rpitit.rs b/tests/ui/traits/const-traits/const-cond-for-rpitit.rs index 50bf93f9a0328..9364d1ab0d698 100644 --- a/tests/ui/traits/const-traits/const-cond-for-rpitit.rs +++ b/tests/ui/traits/const-traits/const-cond-for-rpitit.rs @@ -6,7 +6,7 @@ #[const_trait] pub trait Foo { - fn method(self) -> impl ~const Bar; + (const) fn method(self) -> impl ~const Bar; } #[const_trait] @@ -14,7 +14,7 @@ pub trait Bar {} struct A(T); impl const Foo for A where A: ~const Bar { - fn method(self) -> impl ~const Bar { + (const) fn method(self) -> impl ~const Bar { self } } diff --git a/tests/ui/traits/const-traits/const-default-method-bodies.rs b/tests/ui/traits/const-traits/const-default-method-bodies.rs index 0ef11a7f0c933..73b24840d5423 100644 --- a/tests/ui/traits/const-traits/const-default-method-bodies.rs +++ b/tests/ui/traits/const-traits/const-default-method-bodies.rs @@ -3,9 +3,9 @@ #[const_trait] trait ConstDefaultFn: Sized { - fn b(self); + (const) fn b(self); - fn a(self) { + (const) fn a(self) { self.b(); } } @@ -18,7 +18,7 @@ impl ConstDefaultFn for NonConstImpl { } impl const ConstDefaultFn for ConstImpl { - fn b(self) {} + (const) fn b(self) {} } const fn test() { diff --git a/tests/ui/traits/const-traits/const-drop-fail-2.rs b/tests/ui/traits/const-traits/const-drop-fail-2.rs index 1bcc87e907037..c502265cb6546 100644 --- a/tests/ui/traits/const-traits/const-drop-fail-2.rs +++ b/tests/ui/traits/const-traits/const-drop-fail-2.rs @@ -14,7 +14,7 @@ impl Drop for NonTrivialDrop { } #[const_trait] -trait A { fn a() { } } +trait A { (const) fn a() { } } impl A for NonTrivialDrop {} @@ -23,7 +23,7 @@ const fn check(_: T) {} struct ConstDropImplWithBounds(PhantomData); impl const Drop for ConstDropImplWithBounds { - fn drop(&mut self) { + (const) fn drop(&mut self) { T::a(); } } @@ -36,7 +36,7 @@ const _: () = check::>( struct ConstDropImplWithNonConstBounds(PhantomData); impl const Drop for ConstDropImplWithNonConstBounds { - fn drop(&mut self) { + (const) fn drop(&mut self) { T::a(); } } diff --git a/tests/ui/traits/const-traits/const-drop-fail.rs b/tests/ui/traits/const-traits/const-drop-fail.rs index a7f3d5654de93..f832865c733f0 100644 --- a/tests/ui/traits/const-traits/const-drop-fail.rs +++ b/tests/ui/traits/const-traits/const-drop-fail.rs @@ -18,7 +18,7 @@ impl Drop for NonTrivialDrop { struct ConstImplWithDropGlue(NonTrivialDrop); impl const Drop for ConstImplWithDropGlue { - fn drop(&mut self) {} + (const) fn drop(&mut self) {} } const fn check(_: T) {} diff --git a/tests/ui/traits/const-traits/const-drop.rs b/tests/ui/traits/const-traits/const-drop.rs index e2d87aeff47fb..d0fc7f067be20 100644 --- a/tests/ui/traits/const-traits/const-drop.rs +++ b/tests/ui/traits/const-traits/const-drop.rs @@ -11,7 +11,7 @@ use std::marker::Destruct; struct S<'a>(&'a mut u8); impl<'a> const Drop for S<'a> { - fn drop(&mut self) { + (const) fn drop(&mut self) { *self.0 += 1; } } @@ -45,7 +45,7 @@ mod t { pub struct ConstDrop; impl const Drop for ConstDrop { - fn drop(&mut self) {} + (const) fn drop(&mut self) {} } pub struct HasConstDrop(pub ConstDrop); @@ -53,10 +53,10 @@ mod t { #[const_trait] pub trait SomeTrait { - fn foo(); + (const) fn foo(); } impl const SomeTrait for () { - fn foo() {} + (const) fn foo() {} } // non-const impl impl SomeTrait for i32 { @@ -66,7 +66,7 @@ mod t { pub struct ConstDropWithBound(pub core::marker::PhantomData); impl const Drop for ConstDropWithBound { - fn drop(&mut self) { + (const) fn drop(&mut self) { T::foo(); } } @@ -74,7 +74,7 @@ mod t { pub struct ConstDropWithNonconstBound(pub core::marker::PhantomData); impl const Drop for ConstDropWithNonconstBound { - fn drop(&mut self) { + (const) fn drop(&mut self) { // Note: we DON'T use the `T: SomeTrait` bound } } diff --git a/tests/ui/traits/const-traits/const-impl-trait.stderr b/tests/ui/traits/const-traits/const-impl-trait.stderr index 27d7957c00148..730de6534d2c0 100644 --- a/tests/ui/traits/const-traits/const-impl-trait.stderr +++ b/tests/ui/traits/const-traits/const-impl-trait.stderr @@ -1,3 +1,15 @@ +error: non-const fn in const traits are not supported yet + --> $DIR/const-impl-trait.rs:23:5 + | +LL | fn huh() -> impl ~const PartialEq + ~const Destruct + Copy; + | ^ help: mark the function as const: `(const)` + +error: non-const fn in const traits are not supported yet + --> $DIR/const-impl-trait.rs:27:5 + | +LL | fn huh() -> impl ~const PartialEq + ~const Destruct + Copy { + | ^ help: mark the function as const: `const` + error[E0635]: unknown feature `const_cmp` --> $DIR/const-impl-trait.rs:7:30 | @@ -191,7 +203,7 @@ LL | a == a | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants -error: aborting due to 21 previous errors +error: aborting due to 23 previous errors Some errors have detailed explanations: E0015, E0635. For more information about an error, try `rustc --explain E0015`. diff --git a/tests/ui/traits/const-traits/const-in-closure.rs b/tests/ui/traits/const-traits/const-in-closure.rs index ebc17a50c8660..65d6201000344 100644 --- a/tests/ui/traits/const-traits/const-in-closure.rs +++ b/tests/ui/traits/const-traits/const-in-closure.rs @@ -4,7 +4,7 @@ #![feature(const_trait_impl)] #[const_trait] trait Trait { - fn method(); + (const) fn method(); } const fn foo() { diff --git a/tests/ui/traits/const-traits/const-opaque.rs b/tests/ui/traits/const-traits/const-opaque.rs index 96cdd7d9f2619..482671e921b55 100644 --- a/tests/ui/traits/const-traits/const-opaque.rs +++ b/tests/ui/traits/const-traits/const-opaque.rs @@ -6,16 +6,16 @@ #[const_trait] trait Foo { - fn method(&self); + (const) fn method(&self); } impl const Foo for (T,) { - fn method(&self) {} + (const) fn method(&self) {} } #[cfg(yes)] impl const Foo for () { - fn method(&self) {} + (const) fn method(&self) {} } #[cfg(no)] diff --git a/tests/ui/traits/const-traits/const_derives/derive-const-gate.rs b/tests/ui/traits/const-traits/const_derives/derive-const-gate.rs index a772d69c9e2e2..d9e5731e2b494 100644 --- a/tests/ui/traits/const-traits/const_derives/derive-const-gate.rs +++ b/tests/ui/traits/const-traits/const_derives/derive-const-gate.rs @@ -1,5 +1,6 @@ #[derive_const(Default)] //~ ERROR use of unstable library feature //~^ ERROR const `impl` for trait `Default` which is not marked with `#[const_trait]` +//~| ERROR `const fn` in traits is unstable pub struct S; fn main() {} diff --git a/tests/ui/traits/const-traits/const_derives/derive-const-gate.stderr b/tests/ui/traits/const-traits/const_derives/derive-const-gate.stderr index 202210a2e659a..15f2ac029ebbe 100644 --- a/tests/ui/traits/const-traits/const_derives/derive-const-gate.stderr +++ b/tests/ui/traits/const-traits/const_derives/derive-const-gate.stderr @@ -7,6 +7,16 @@ LL | #[derive_const(Default)] = help: add `#![feature(derive_const)]` 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[E0658]: `const fn` in traits is unstable + --> $DIR/derive-const-gate.rs:1:16 + | +LL | #[derive_const(Default)] + | ^^^^^^^ + | + = note: see issue #67792 for more information + = help: add `#![feature(const_trait_impl)]` 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: const `impl` for trait `Default` which is not marked with `#[const_trait]` --> $DIR/derive-const-gate.rs:1:16 | @@ -16,6 +26,6 @@ LL | #[derive_const(Default)] = note: marking a trait with `#[const_trait]` ensures all default method bodies are `const` = note: adding a non-const method body in the future would be a breaking change -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/traits/const-traits/const_derives/derive-const-non-const-type.stderr b/tests/ui/traits/const-traits/const_derives/derive-const-non-const-type.stderr index 27f4bcf46ef82..f39f59d8a4ce9 100644 --- a/tests/ui/traits/const-traits/const_derives/derive-const-non-const-type.stderr +++ b/tests/ui/traits/const-traits/const_derives/derive-const-non-const-type.stderr @@ -1,3 +1,13 @@ +error[E0658]: `const fn` in traits is unstable + --> $DIR/derive-const-non-const-type.rs:10:16 + | +LL | #[derive_const(Default)] + | ^^^^^^^ + | + = note: see issue #67792 for more information + = help: add `#![feature(const_trait_impl)]` 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: const `impl` for trait `Default` which is not marked with `#[const_trait]` --> $DIR/derive-const-non-const-type.rs:10:16 | @@ -17,6 +27,7 @@ LL | pub struct S(A); | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants -error: aborting due to 2 previous errors +error: aborting due to 3 previous errors -For more information about this error, try `rustc --explain E0015`. +Some errors have detailed explanations: E0015, E0658. +For more information about an error, try `rustc --explain E0015`. diff --git a/tests/ui/traits/const-traits/const_derives/derive-const-use.stderr b/tests/ui/traits/const-traits/const_derives/derive-const-use.stderr index 8297911a3f3c7..64b1c58017c72 100644 --- a/tests/ui/traits/const-traits/const_derives/derive-const-use.stderr +++ b/tests/ui/traits/const-traits/const_derives/derive-const-use.stderr @@ -1,3 +1,15 @@ +error: non-const fn in const traits are not supported yet + --> $DIR/derive-const-use.rs:8:5 + | +LL | fn default() -> A { A } + | ^ help: mark the function as const: `const` + +error: non-const fn in const traits are not supported yet + --> $DIR/derive-const-use.rs:12:5 + | +LL | fn eq(&self, _: &A) -> bool { true } + | ^ help: mark the function as const: `const` + error[E0635]: unknown feature `const_cmp` --> $DIR/derive-const-use.rs:3:30 | @@ -102,7 +114,7 @@ LL | pub struct S((), A); | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants -error: aborting due to 12 previous errors +error: aborting due to 14 previous errors Some errors have detailed explanations: E0015, E0635. For more information about an error, try `rustc --explain E0015`. diff --git a/tests/ui/traits/const-traits/default-method-body-is-const-body-checking.rs b/tests/ui/traits/const-traits/default-method-body-is-const-body-checking.rs index 96acdc300e0dd..a2640e05d29de 100644 --- a/tests/ui/traits/const-traits/default-method-body-is-const-body-checking.rs +++ b/tests/ui/traits/const-traits/default-method-body-is-const-body-checking.rs @@ -8,7 +8,7 @@ const fn foo() where T: ~const Tr {} #[const_trait] pub trait Foo { - fn foo() { + (const) fn foo() { foo::<()>(); //~^ ERROR the trait bound `(): ~const Tr` is not satisfied } diff --git a/tests/ui/traits/const-traits/default-method-body-is-const-same-trait-ck.rs b/tests/ui/traits/const-traits/default-method-body-is-const-same-trait-ck.rs index b3beba08237c1..681350b0630f9 100644 --- a/tests/ui/traits/const-traits/default-method-body-is-const-same-trait-ck.rs +++ b/tests/ui/traits/const-traits/default-method-body-is-const-same-trait-ck.rs @@ -3,9 +3,9 @@ #[const_trait] pub trait Tr { - fn a(&self) {} + (const) fn a(&self) {} - fn b(&self) { + (const) fn b(&self) { ().a() //~^ ERROR the trait bound `(): ~const Tr` is not satisfied } diff --git a/tests/ui/traits/const-traits/do-not-const-check-override.rs b/tests/ui/traits/const-traits/do-not-const-check-override.rs index 2b8e1d38ac99f..309521eaf78c5 100644 --- a/tests/ui/traits/const-traits/do-not-const-check-override.rs +++ b/tests/ui/traits/const-traits/do-not-const-check-override.rs @@ -6,12 +6,12 @@ #[const_trait] trait Foo { #[rustc_do_not_const_check] - fn into_iter(&self) { println!("FEAR ME!") } + (const) fn into_iter(&self) { println!("FEAR ME!") } } impl const Foo for () { - fn into_iter(&self) { + (const) fn into_iter(&self) { // ^_^ } } diff --git a/tests/ui/traits/const-traits/do-not-const-check.rs b/tests/ui/traits/const-traits/do-not-const-check.rs index 443b638573576..645ea03664511 100644 --- a/tests/ui/traits/const-traits/do-not-const-check.rs +++ b/tests/ui/traits/const-traits/do-not-const-check.rs @@ -3,13 +3,13 @@ #[const_trait] trait IntoIter { - fn into_iter(self); + (const) fn into_iter(self); } #[const_trait] trait Hmm: Sized { #[rustc_do_not_const_check] - fn chain(self, other: U) where U: IntoIter, + (const) fn chain(self, other: U) where U: IntoIter, { other.into_iter() } diff --git a/tests/ui/traits/const-traits/dont-observe-host.rs b/tests/ui/traits/const-traits/dont-observe-host.rs index 06050385f9168..71c513876e72d 100644 --- a/tests/ui/traits/const-traits/dont-observe-host.rs +++ b/tests/ui/traits/const-traits/dont-observe-host.rs @@ -5,7 +5,7 @@ #[const_trait] trait Trait { - fn method() {} + (const) fn method() {} } impl const Trait for () {} diff --git a/tests/ui/traits/const-traits/enforce-deref-on-adjust.rs b/tests/ui/traits/const-traits/enforce-deref-on-adjust.rs index d5240b7e18ddb..14f96c32be253 100644 --- a/tests/ui/traits/const-traits/enforce-deref-on-adjust.rs +++ b/tests/ui/traits/const-traits/enforce-deref-on-adjust.rs @@ -15,7 +15,7 @@ impl Foo { impl const Deref for Wrap { type Target = T; - fn deref(&self) -> &Self::Target { + (const) fn deref(&self) -> &Self::Target { &self.0 } } diff --git a/tests/ui/traits/const-traits/eval-bad-signature.rs b/tests/ui/traits/const-traits/eval-bad-signature.rs index 97c573ea6528d..63494cf14dfe8 100644 --- a/tests/ui/traits/const-traits/eval-bad-signature.rs +++ b/tests/ui/traits/const-traits/eval-bad-signature.rs @@ -4,7 +4,7 @@ #[const_trait] trait Value { - fn value() -> u32; + (const) fn value() -> u32; } const fn get_value() -> u32 { @@ -14,7 +14,7 @@ const fn get_value() -> u32 { struct FortyTwo; impl const Value for FortyTwo { - fn value() -> i64 { + (const) fn value() -> i64 { //~^ ERROR method `value` has an incompatible type for trait 42 } diff --git a/tests/ui/traits/const-traits/eval-bad-signature.stderr b/tests/ui/traits/const-traits/eval-bad-signature.stderr index 52de5283f7fdf..a020e01ec1eda 100644 --- a/tests/ui/traits/const-traits/eval-bad-signature.stderr +++ b/tests/ui/traits/const-traits/eval-bad-signature.stderr @@ -1,20 +1,20 @@ error[E0053]: method `value` has an incompatible type for trait - --> $DIR/eval-bad-signature.rs:17:19 + --> $DIR/eval-bad-signature.rs:17:27 | -LL | fn value() -> i64 { - | ^^^ expected `u32`, found `i64` +LL | (const) fn value() -> i64 { + | ^^^ expected `u32`, found `i64` | note: type in trait - --> $DIR/eval-bad-signature.rs:7:19 + --> $DIR/eval-bad-signature.rs:7:27 | -LL | fn value() -> u32; - | ^^^ +LL | (const) fn value() -> u32; + | ^^^ = note: expected signature `fn() -> u32` found signature `fn() -> i64` help: change the output type to match the trait | -LL - fn value() -> i64 { -LL + fn value() -> u32 { +LL - (const) fn value() -> i64 { +LL + (const) fn value() -> u32 { | error: aborting due to 1 previous error diff --git a/tests/ui/traits/const-traits/generic-bound.rs b/tests/ui/traits/const-traits/generic-bound.rs index 99de21471b20c..a8df93709d22c 100644 --- a/tests/ui/traits/const-traits/generic-bound.rs +++ b/tests/ui/traits/const-traits/generic-bound.rs @@ -16,7 +16,7 @@ impl Clone for S { impl const std::ops::Add for S { type Output = Self; - fn add(self, _: Self) -> Self { + (const) fn add(self, _: Self) -> Self { S(std::marker::PhantomData) } } diff --git a/tests/ui/traits/const-traits/hir-const-check.rs b/tests/ui/traits/const-traits/hir-const-check.rs index c485fb121841b..c6cecba2fdebf 100644 --- a/tests/ui/traits/const-traits/hir-const-check.rs +++ b/tests/ui/traits/const-traits/hir-const-check.rs @@ -6,11 +6,11 @@ #[const_trait] pub trait MyTrait { - fn method(&self) -> Option<()>; + (const) fn method(&self) -> Option<()>; } impl const MyTrait for () { - fn method(&self) -> Option<()> { + (const) fn method(&self) -> Option<()> { Some(())?; //~^ ERROR `?` is not allowed on //~| ERROR `?` is not allowed on diff --git a/tests/ui/traits/const-traits/ice-119717-constant-lifetime.rs b/tests/ui/traits/const-traits/ice-119717-constant-lifetime.rs index e53b87274d3a7..8f421525f2bac 100644 --- a/tests/ui/traits/const-traits/ice-119717-constant-lifetime.rs +++ b/tests/ui/traits/const-traits/ice-119717-constant-lifetime.rs @@ -6,7 +6,7 @@ use std::ops::FromResidual; impl const FromResidual for T { //~^ ERROR const `impl` for trait `FromResidual` which is not marked with `#[const_trait]` //~| ERROR type parameter `T` must be used as the type parameter for some local type - fn from_residual(t: T) -> _ { + (const) fn from_residual(t: T) -> _ { //~^ ERROR the placeholder `_` is not allowed t } diff --git a/tests/ui/traits/const-traits/ice-119717-constant-lifetime.stderr b/tests/ui/traits/const-traits/ice-119717-constant-lifetime.stderr index c6e0c699520b5..88323b2b2e37a 100644 --- a/tests/ui/traits/const-traits/ice-119717-constant-lifetime.stderr +++ b/tests/ui/traits/const-traits/ice-119717-constant-lifetime.stderr @@ -17,15 +17,15 @@ LL | impl const FromResidual for T { = note: only traits defined in the current crate can be implemented for a type parameter error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions - --> $DIR/ice-119717-constant-lifetime.rs:9:31 + --> $DIR/ice-119717-constant-lifetime.rs:9:39 | -LL | fn from_residual(t: T) -> _ { - | ^ not allowed in type signatures +LL | (const) fn from_residual(t: T) -> _ { + | ^ not allowed in type signatures | help: try replacing `_` with the type in the corresponding trait method signature | -LL - fn from_residual(t: T) -> _ { -LL + fn from_residual(t: T) -> T { +LL - (const) fn from_residual(t: T) -> _ { +LL + (const) fn from_residual(t: T) -> T { | error: aborting due to 3 previous errors diff --git a/tests/ui/traits/const-traits/ice-121536-const-method.rs b/tests/ui/traits/const-traits/ice-121536-const-method.rs index b89786bfd933f..853ae23e52106 100644 --- a/tests/ui/traits/const-traits/ice-121536-const-method.rs +++ b/tests/ui/traits/const-traits/ice-121536-const-method.rs @@ -4,7 +4,7 @@ pub struct Vec3; #[const_trait] pub trait Add { - fn add(self) -> Vec3; + (const) fn add(self) -> Vec3; } impl Add for Vec3 { diff --git a/tests/ui/traits/const-traits/impl-with-default-fn-fail.rs b/tests/ui/traits/const-traits/impl-with-default-fn-fail.rs index 6df9696f2cbd7..09d10cd6ec5ba 100644 --- a/tests/ui/traits/const-traits/impl-with-default-fn-fail.rs +++ b/tests/ui/traits/const-traits/impl-with-default-fn-fail.rs @@ -2,15 +2,15 @@ #[const_trait] trait Tr { - fn req(&self); + (const) fn req(&self); - fn default() {} + (const) fn default() {} } struct S; impl const Tr for u16 { - fn default() {} + (const) fn default() {} } //~^^ ERROR not all trait items implemented diff --git a/tests/ui/traits/const-traits/impl-with-default-fn-fail.stderr b/tests/ui/traits/const-traits/impl-with-default-fn-fail.stderr index 36c8163f1c567..e0c9f2e9b82a7 100644 --- a/tests/ui/traits/const-traits/impl-with-default-fn-fail.stderr +++ b/tests/ui/traits/const-traits/impl-with-default-fn-fail.stderr @@ -1,8 +1,8 @@ error[E0046]: not all trait items implemented, missing: `req` --> $DIR/impl-with-default-fn-fail.rs:12:1 | -LL | fn req(&self); - | -------------- `req` from trait +LL | (const) fn req(&self); + | ---------------------- `req` from trait ... LL | impl const Tr for u16 { | ^^^^^^^^^^^^^^^^^^^^^ missing `req` in implementation diff --git a/tests/ui/traits/const-traits/impl-with-default-fn-pass.rs b/tests/ui/traits/const-traits/impl-with-default-fn-pass.rs index c776a29716ff7..ec3ac2821d266 100644 --- a/tests/ui/traits/const-traits/impl-with-default-fn-pass.rs +++ b/tests/ui/traits/const-traits/impl-with-default-fn-pass.rs @@ -4,19 +4,19 @@ #[const_trait] trait Tr { - fn req(&self); + (const) fn req(&self); - fn default() {} + (const) fn default() {} } impl const Tr for u8 { - fn req(&self) {} + (const) fn req(&self) {} } macro_rules! impl_tr { ($ty: ty) => { impl const Tr for $ty { - fn req(&self) {} + (const) fn req(&self) {} } } } diff --git a/tests/ui/traits/const-traits/issue-100222.rs b/tests/ui/traits/const-traits/issue-100222.rs index 55722d35075a2..ff98d853c1778 100644 --- a/tests/ui/traits/const-traits/issue-100222.rs +++ b/tests/ui/traits/const-traits/issue-100222.rs @@ -14,6 +14,9 @@ pub trait Index { pub trait IndexMut where Self: Index { const C: ::Output; type Assoc = ::Output; + #[cfg(any(ny, yy))] + (const) fn foo(&mut self, x: ::Output) -> ::Output; + #[cfg(not(any(ny, yy)))] fn foo(&mut self, x: ::Output) -> ::Output; } @@ -23,7 +26,7 @@ impl Index for () { type Output = (); } impl const IndexMut for <() as Index>::Output { const C: ::Output = (); type Assoc = ::Output; - fn foo(&mut self, x: ::Output) -> ::Output + (const) fn foo(&mut self, x: ::Output) -> ::Output where ::Output:, {} } diff --git a/tests/ui/traits/const-traits/issue-79450.rs b/tests/ui/traits/const-traits/issue-79450.rs index 5ba5036ce277a..2ebb0a45a890e 100644 --- a/tests/ui/traits/const-traits/issue-79450.rs +++ b/tests/ui/traits/const-traits/issue-79450.rs @@ -3,9 +3,9 @@ #[const_trait] trait Tr { - fn req(&self); + (const) fn req(&self); - fn prov(&self) { + (const) fn prov(&self) { println!("lul"); //~ ERROR: cannot call non-const function `_print` in constant functions self.req(); } @@ -14,7 +14,7 @@ trait Tr { struct S; impl const Tr for S { - fn req(&self) {} + (const) fn req(&self) {} } fn main() {} diff --git a/tests/ui/traits/const-traits/minicore-drop-fail.rs b/tests/ui/traits/const-traits/minicore-drop-fail.rs index 274e5db21c4f6..342c7ad93d6f0 100644 --- a/tests/ui/traits/const-traits/minicore-drop-fail.rs +++ b/tests/ui/traits/const-traits/minicore-drop-fail.rs @@ -20,7 +20,7 @@ impl Foo for () {} struct Conditional(T); impl const Drop for Conditional where T: ~const Foo { - fn drop(&mut self) {} + (const) fn drop(&mut self) {} } const fn test() { diff --git a/tests/ui/traits/const-traits/minicore-drop-without-feature-gate.rs b/tests/ui/traits/const-traits/minicore-drop-without-feature-gate.rs index e75bf3db007f0..1855e07954c27 100644 --- a/tests/ui/traits/const-traits/minicore-drop-without-feature-gate.rs +++ b/tests/ui/traits/const-traits/minicore-drop-without-feature-gate.rs @@ -14,7 +14,7 @@ use minicore::*; struct ConstDrop; impl const Drop for ConstDrop { - fn drop(&mut self) {} + (const) fn drop(&mut self) {} } // Make sure that `ConstDrop` can only be dropped when the `const_drop` diff --git a/tests/ui/traits/const-traits/minicore-works.rs b/tests/ui/traits/const-traits/minicore-works.rs index c79b4fc07dfd6..4e340f901605c 100644 --- a/tests/ui/traits/const-traits/minicore-works.rs +++ b/tests/ui/traits/const-traits/minicore-works.rs @@ -13,7 +13,7 @@ use minicore::*; struct Custom; impl const Add for Custom { type Output = (); - fn add(self, _other: Self) {} + (const) fn add(self, _other: Self) {} } const fn test_op() { @@ -21,7 +21,9 @@ const fn test_op() { let _y = Custom + Custom; } -const fn call_indirect(t: &T) { t() } +const fn call_indirect(t: &T) { + t() +} const fn call() { call_indirect(&call); diff --git a/tests/ui/traits/const-traits/no-explicit-const-params.rs b/tests/ui/traits/const-traits/no-explicit-const-params.rs index 76663292223b2..7d6491efe1657 100644 --- a/tests/ui/traits/const-traits/no-explicit-const-params.rs +++ b/tests/ui/traits/const-traits/no-explicit-const-params.rs @@ -4,7 +4,7 @@ const fn foo() {} #[const_trait] trait Bar { - fn bar(); + (const) fn bar(); } impl Bar for () { diff --git a/tests/ui/traits/const-traits/non-const-op-in-closure-in-const.stderr b/tests/ui/traits/const-traits/non-const-op-in-closure-in-const.stderr index 190af5e7c2dd1..dbabb280d4dfc 100644 --- a/tests/ui/traits/const-traits/non-const-op-in-closure-in-const.stderr +++ b/tests/ui/traits/const-traits/non-const-op-in-closure-in-const.stderr @@ -1,3 +1,15 @@ +error: non-const fn in const traits are not supported yet + --> $DIR/non-const-op-in-closure-in-const.rs:7:5 + | +LL | fn to(self) -> T; + | ^ help: mark the function as const: `(const)` + +error: non-const fn in const traits are not supported yet + --> $DIR/non-const-op-in-closure-in-const.rs:11:5 + | +LL | fn to(self) -> B { + | ^ help: mark the function as const: `const` + error: `~const` can only be applied to `#[const_trait]` traits --> $DIR/non-const-op-in-closure-in-const.rs:10:44 | @@ -25,6 +37,6 @@ LL | B::from(self) | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants -error: aborting due to 3 previous errors +error: aborting due to 5 previous errors For more information about this error, try `rustc --explain E0015`. diff --git a/tests/ui/traits/const-traits/overlap-const-with-nonconst.rs b/tests/ui/traits/const-traits/overlap-const-with-nonconst.rs index eb66d03faa638..6fff7a6643120 100644 --- a/tests/ui/traits/const-traits/overlap-const-with-nonconst.rs +++ b/tests/ui/traits/const-traits/overlap-const-with-nonconst.rs @@ -11,13 +11,13 @@ impl const Bar for T {} #[const_trait] trait Foo { - fn method(&self); + (const) fn method(&self); } impl const Foo for T where T: ~const Bar, { - default fn method(&self) {} + default (const) fn method(&self) {} } // specializing impl: impl Foo for (T,) { diff --git a/tests/ui/traits/const-traits/predicate-entailment-fails.rs b/tests/ui/traits/const-traits/predicate-entailment-fails.rs index 266a49f9e386d..d9269bb21dd30 100644 --- a/tests/ui/traits/const-traits/predicate-entailment-fails.rs +++ b/tests/ui/traits/const-traits/predicate-entailment-fails.rs @@ -8,7 +8,7 @@ impl const Bar for () {} #[const_trait] trait TildeConst { type Bar where T: ~const Bar; - fn foo() where T: ~const Bar; + (const) fn foo() where T: ~const Bar; } impl TildeConst for () { type Bar = () where T: const Bar; @@ -22,7 +22,7 @@ impl TildeConst for () { #[const_trait] trait NeverConst { type Bar where T: Bar; - fn foo() where T: Bar; + (const) fn foo() where T: Bar; } impl NeverConst for i32 { type Bar = () where T: const Bar; @@ -35,7 +35,7 @@ impl const NeverConst for u32 { type Bar = () where T: ~const Bar; //~^ ERROR impl has stricter requirements than trait - fn foo() where T: ~const Bar {} + (const) fn foo() where T: ~const Bar {} //~^ ERROR impl has stricter requirements than trait } diff --git a/tests/ui/traits/const-traits/predicate-entailment-fails.stderr b/tests/ui/traits/const-traits/predicate-entailment-fails.stderr index dfdc4d232508f..8860d86c1474c 100644 --- a/tests/ui/traits/const-traits/predicate-entailment-fails.stderr +++ b/tests/ui/traits/const-traits/predicate-entailment-fails.stderr @@ -10,8 +10,8 @@ LL | type Bar = () where T: const Bar; error[E0276]: impl has stricter requirements than trait --> $DIR/predicate-entailment-fails.rs:17:26 | -LL | fn foo() where T: ~const Bar; - | -------------------------------- definition of `foo` from trait +LL | (const) fn foo() where T: ~const Bar; + | ---------------------------------------- definition of `foo` from trait ... LL | fn foo() where T: const Bar {} | ^^^^^^^^^ impl has extra requirement `T: const Bar` @@ -28,8 +28,8 @@ LL | type Bar = () where T: const Bar; error[E0276]: impl has stricter requirements than trait --> $DIR/predicate-entailment-fails.rs:31:26 | -LL | fn foo() where T: Bar; - | ------------------------- definition of `foo` from trait +LL | (const) fn foo() where T: Bar; + | --------------------------------- definition of `foo` from trait ... LL | fn foo() where T: const Bar {} | ^^^^^^^^^ impl has extra requirement `T: const Bar` @@ -44,13 +44,13 @@ LL | type Bar = () where T: ~const Bar; | ^^^^^^^^^^ impl has extra requirement `T: ~const Bar` error[E0276]: impl has stricter requirements than trait - --> $DIR/predicate-entailment-fails.rs:38:26 + --> $DIR/predicate-entailment-fails.rs:38:34 | -LL | fn foo() where T: Bar; - | ------------------------- definition of `foo` from trait +LL | (const) fn foo() where T: Bar; + | --------------------------------- definition of `foo` from trait ... -LL | fn foo() where T: ~const Bar {} - | ^^^^^^^^^^ impl has extra requirement `T: ~const Bar` +LL | (const) fn foo() where T: ~const Bar {} + | ^^^^^^^^^^ impl has extra requirement `T: ~const Bar` error: aborting due to 6 previous errors diff --git a/tests/ui/traits/const-traits/predicate-entailment-passes.rs b/tests/ui/traits/const-traits/predicate-entailment-passes.rs index 28ae21891f386..b924054d446b2 100644 --- a/tests/ui/traits/const-traits/predicate-entailment-passes.rs +++ b/tests/ui/traits/const-traits/predicate-entailment-passes.rs @@ -7,7 +7,7 @@ impl const Bar for () {} #[const_trait] trait TildeConst { - fn foo() where T: ~const Bar; + (const) fn foo() where T: ~const Bar; } impl TildeConst for () { fn foo() where T: Bar {} @@ -15,13 +15,13 @@ impl TildeConst for () { #[const_trait] trait AlwaysConst { - fn foo() where T: const Bar; + (const) fn foo() where T: const Bar; } impl AlwaysConst for i32 { fn foo() where T: Bar {} } impl const AlwaysConst for u32 { - fn foo() where T: ~const Bar {} + (const) fn foo() where T: ~const Bar {} } fn main() {} diff --git a/tests/ui/traits/const-traits/specialization/const-default-bound-non-const-specialized-bound.stderr b/tests/ui/traits/const-traits/specialization/const-default-bound-non-const-specialized-bound.stderr index 9166b8ca5d22b..3c07d138f9b6e 100644 --- a/tests/ui/traits/const-traits/specialization/const-default-bound-non-const-specialized-bound.stderr +++ b/tests/ui/traits/const-traits/specialization/const-default-bound-non-const-specialized-bound.stderr @@ -1,3 +1,33 @@ +error: non-const fn in const traits are not supported yet + --> $DIR/const-default-bound-non-const-specialized-bound.rs:18:5 + | +LL | fn bar(); + | ^ help: mark the function as const: `(const)` + +error: non-const fn in const traits are not supported yet + --> $DIR/const-default-bound-non-const-specialized-bound.rs:25:5 + | +LL | default fn bar() {} + | ^ help: mark the function as const: `const` + +error: non-const fn in const traits are not supported yet + --> $DIR/const-default-bound-non-const-specialized-bound.rs:38:5 + | +LL | fn baz(); + | ^ help: mark the function as const: `(const)` + +error: non-const fn in const traits are not supported yet + --> $DIR/const-default-bound-non-const-specialized-bound.rs:45:5 + | +LL | default fn baz() {} + | ^ help: mark the function as const: `const` + +error: non-const fn in const traits are not supported yet + --> $DIR/const-default-bound-non-const-specialized-bound.rs:53:5 + | +LL | fn baz() {} + | ^ help: mark the function as const: `const` + error[E0119]: conflicting implementations of trait `Bar` --> $DIR/const-default-bound-non-const-specialized-bound.rs:28:1 | @@ -26,6 +56,6 @@ LL | | T: Foo, LL | | T: Specialize, | |__________________^ conflicting implementation -error: aborting due to 2 previous errors +error: aborting due to 7 previous errors For more information about this error, try `rustc --explain E0119`. diff --git a/tests/ui/traits/const-traits/specialization/const-default-const-specialized.rs b/tests/ui/traits/const-traits/specialization/const-default-const-specialized.rs index 89ad61c3c31c4..71aea8ce1e6ba 100644 --- a/tests/ui/traits/const-traits/specialization/const-default-const-specialized.rs +++ b/tests/ui/traits/const-traits/specialization/const-default-const-specialized.rs @@ -8,7 +8,7 @@ #[const_trait] trait Value { - fn value() -> u32; + (const) fn value() -> u32; } const fn get_value() -> u32 { @@ -16,7 +16,7 @@ const fn get_value() -> u32 { } impl const Value for T { - default fn value() -> u32 { + default (const) fn value() -> u32 { 0 } } @@ -24,7 +24,7 @@ impl const Value for T { struct FortyTwo; impl const Value for FortyTwo { - fn value() -> u32 { + (const) fn value() -> u32 { 42 } } diff --git a/tests/ui/traits/const-traits/specialization/const-default-impl-non-const-specialized-impl.rs b/tests/ui/traits/const-traits/specialization/const-default-impl-non-const-specialized-impl.rs index acf0a967a884d..2734b294a5f2d 100644 --- a/tests/ui/traits/const-traits/specialization/const-default-impl-non-const-specialized-impl.rs +++ b/tests/ui/traits/const-traits/specialization/const-default-impl-non-const-specialized-impl.rs @@ -8,11 +8,11 @@ #[const_trait] trait Value { - fn value() -> u32; + (const) fn value() -> u32; } impl const Value for T { - default fn value() -> u32 { + default (const) fn value() -> u32 { 0 } } diff --git a/tests/ui/traits/const-traits/specialization/default-keyword.rs b/tests/ui/traits/const-traits/specialization/default-keyword.rs index bc45a70777ca5..0f776e59b36df 100644 --- a/tests/ui/traits/const-traits/specialization/default-keyword.rs +++ b/tests/ui/traits/const-traits/specialization/default-keyword.rs @@ -5,11 +5,11 @@ #[const_trait] trait Foo { - fn foo(); + (const) fn foo(); } impl const Foo for u32 { - default fn foo() {} + default (const) fn foo() {} } fn main() {} diff --git a/tests/ui/traits/const-traits/specialization/issue-95186-specialize-on-tilde-const.rs b/tests/ui/traits/const-traits/specialization/issue-95186-specialize-on-tilde-const.rs index d80370aee8209..c19abb5b5ffe7 100644 --- a/tests/ui/traits/const-traits/specialization/issue-95186-specialize-on-tilde-const.rs +++ b/tests/ui/traits/const-traits/specialization/issue-95186-specialize-on-tilde-const.rs @@ -12,30 +12,30 @@ trait Specialize {} #[const_trait] trait Foo { - fn foo(); + (const) fn foo(); } impl const Foo for T { - default fn foo() {} + default (const) fn foo() {} } impl const Foo for T where T: ~const Specialize, { - fn foo() {} + (const) fn foo() {} } #[const_trait] trait Bar { - fn bar() {} + (const) fn bar() {} } impl const Bar for T where T: ~const Foo, { - default fn bar() {} + default (const) fn bar() {} } impl const Bar for T @@ -43,7 +43,7 @@ where T: ~const Foo, T: ~const Specialize, { - fn bar() {} + (const) fn bar() {} } fn main() {} diff --git a/tests/ui/traits/const-traits/specialization/issue-95187-same-trait-bound-different-constness.rs b/tests/ui/traits/const-traits/specialization/issue-95187-same-trait-bound-different-constness.rs index d97469edaf97f..d8bf7827c5097 100644 --- a/tests/ui/traits/const-traits/specialization/issue-95187-same-trait-bound-different-constness.rs +++ b/tests/ui/traits/const-traits/specialization/issue-95187-same-trait-bound-different-constness.rs @@ -16,7 +16,7 @@ trait Foo {} #[const_trait] trait Bar { - fn bar(); + (const) fn bar(); } impl Bar for T @@ -31,19 +31,19 @@ where T: ~const Foo, T: Specialize, { - fn bar() {} + (const) fn bar() {} } #[const_trait] trait Baz { - fn baz(); + (const) fn baz(); } impl const Baz for T where T: Foo, { - default fn baz() {} + default (const) fn baz() {} } impl const Baz for T @@ -51,7 +51,7 @@ where T: ~const Foo, T: Specialize, { - fn baz() {} + (const) fn baz() {} } fn main() {} diff --git a/tests/ui/traits/const-traits/specialization/non-const-default-const-specialized.rs b/tests/ui/traits/const-traits/specialization/non-const-default-const-specialized.rs index e9b494bc2c0d9..eb500068650b0 100644 --- a/tests/ui/traits/const-traits/specialization/non-const-default-const-specialized.rs +++ b/tests/ui/traits/const-traits/specialization/non-const-default-const-specialized.rs @@ -8,7 +8,7 @@ #[const_trait] trait Value { - fn value() -> u32; + (const) fn value() -> u32; } const fn get_value() -> u32 { @@ -25,7 +25,7 @@ impl Value for T { struct FortyTwo; impl const Value for FortyTwo { - fn value() -> u32 { + (const) fn value() -> u32 { 42 } } diff --git a/tests/ui/traits/const-traits/specializing-constness-2.stderr b/tests/ui/traits/const-traits/specializing-constness-2.stderr index edba836aac354..586939ab3c6fc 100644 --- a/tests/ui/traits/const-traits/specializing-constness-2.stderr +++ b/tests/ui/traits/const-traits/specializing-constness-2.stderr @@ -1,9 +1,21 @@ +error: non-const fn in const traits are not supported yet + --> $DIR/specializing-constness-2.rs:11:5 + | +LL | fn a() -> u32; + | ^ help: mark the function as const: `(const)` + +error: non-const fn in const traits are not supported yet + --> $DIR/specializing-constness-2.rs:21:5 + | +LL | fn a() -> u32 { + | ^ help: mark the function as const: `const` + error[E0277]: the trait bound `T: ~const A` is not satisfied --> $DIR/specializing-constness-2.rs:27:6 | LL | ::a(); | ^ -error: aborting due to 1 previous error +error: aborting due to 3 previous errors For more information about this error, try `rustc --explain E0277`. diff --git a/tests/ui/traits/const-traits/specializing-constness.rs b/tests/ui/traits/const-traits/specializing-constness.rs index 94b6da7124d29..6da679078c637 100644 --- a/tests/ui/traits/const-traits/specializing-constness.rs +++ b/tests/ui/traits/const-traits/specializing-constness.rs @@ -8,14 +8,14 @@ impl const Sup for () {} #[const_trait] pub trait A { - fn a() -> u32; + (const) fn a() -> u32; } #[const_trait] pub trait Spec {} impl const A for T { - default fn a() -> u32 { + default (const) fn a() -> u32 { 2 } } diff --git a/tests/ui/traits/const-traits/super-traits-fail-2.nn.stderr b/tests/ui/traits/const-traits/super-traits-fail-2.nn.stderr index 8f88e3aa8bc6d..0c35e291e98f9 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-2.nn.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-2.nn.stderr @@ -1,17 +1,17 @@ error: `~const` is not allowed here - --> $DIR/super-traits-fail-2.rs:11:12 + --> $DIR/super-traits-fail-2.rs:14:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ | note: this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds - --> $DIR/super-traits-fail-2.rs:11:1 + --> $DIR/super-traits-fail-2.rs:14:1 | LL | trait Bar: ~const Foo {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-2.rs:11:12 + --> $DIR/super-traits-fail-2.rs:14:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` @@ -22,7 +22,7 @@ LL | #[const_trait] trait Foo { | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-2.rs:11:12 + --> $DIR/super-traits-fail-2.rs:14:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` @@ -34,7 +34,7 @@ LL | #[const_trait] trait Foo { | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-2.rs:11:12 + --> $DIR/super-traits-fail-2.rs:14:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` @@ -46,7 +46,7 @@ LL | #[const_trait] trait Foo { | ++++++++++++++ error[E0015]: cannot call non-const method `::a` in constant functions - --> $DIR/super-traits-fail-2.rs:20:7 + --> $DIR/super-traits-fail-2.rs:23:7 | LL | x.a(); | ^^^ diff --git a/tests/ui/traits/const-traits/super-traits-fail-2.ny.stderr b/tests/ui/traits/const-traits/super-traits-fail-2.ny.stderr index 087e80de788e0..407ae19fc18a5 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-2.ny.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-2.ny.stderr @@ -1,5 +1,5 @@ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-2.rs:11:12 + --> $DIR/super-traits-fail-2.rs:14:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` @@ -10,7 +10,7 @@ LL | #[const_trait] trait Foo { | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-2.rs:11:12 + --> $DIR/super-traits-fail-2.rs:14:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` @@ -22,7 +22,7 @@ LL | #[const_trait] trait Foo { | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-2.rs:11:12 + --> $DIR/super-traits-fail-2.rs:14:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` @@ -34,7 +34,7 @@ LL | #[const_trait] trait Foo { | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-2.rs:11:12 + --> $DIR/super-traits-fail-2.rs:14:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` @@ -46,7 +46,7 @@ LL | #[const_trait] trait Foo { | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-2.rs:11:12 + --> $DIR/super-traits-fail-2.rs:14:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` @@ -58,7 +58,7 @@ LL | #[const_trait] trait Foo { | ++++++++++++++ error[E0015]: cannot call non-const method `::a` in constant functions - --> $DIR/super-traits-fail-2.rs:20:7 + --> $DIR/super-traits-fail-2.rs:23:7 | LL | x.a(); | ^^^ diff --git a/tests/ui/traits/const-traits/super-traits-fail-2.rs b/tests/ui/traits/const-traits/super-traits-fail-2.rs index 6cc9d7394767a..0024e3d048bdf 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-2.rs +++ b/tests/ui/traits/const-traits/super-traits-fail-2.rs @@ -4,6 +4,9 @@ #[cfg_attr(any(yy, yn), const_trait)] trait Foo { + #[cfg(any(yy, yn))] + (const) fn a(&self); + #[cfg(any(ny, nn))] fn a(&self); } diff --git a/tests/ui/traits/const-traits/super-traits-fail-2.yn.stderr b/tests/ui/traits/const-traits/super-traits-fail-2.yn.stderr index ee49810bacec4..32fb0e005199f 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-2.yn.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-2.yn.stderr @@ -1,17 +1,17 @@ error: `~const` is not allowed here - --> $DIR/super-traits-fail-2.rs:11:12 + --> $DIR/super-traits-fail-2.rs:14:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ | note: this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds - --> $DIR/super-traits-fail-2.rs:11:1 + --> $DIR/super-traits-fail-2.rs:14:1 | LL | trait Bar: ~const Foo {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error[E0277]: the trait bound `T: ~const Foo` is not satisfied - --> $DIR/super-traits-fail-2.rs:20:7 + --> $DIR/super-traits-fail-2.rs:23:7 | LL | x.a(); | ^ diff --git a/tests/ui/traits/const-traits/super-traits-fail-2.yy.stderr b/tests/ui/traits/const-traits/super-traits-fail-2.yy.stderr index a213273c1c78d..5cca4fd9de663 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-2.yy.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-2.yy.stderr @@ -1,5 +1,5 @@ error[E0277]: the trait bound `T: ~const Foo` is not satisfied - --> $DIR/super-traits-fail-2.rs:20:7 + --> $DIR/super-traits-fail-2.rs:23:7 | LL | x.a(); | ^ diff --git a/tests/ui/traits/const-traits/super-traits-fail-3.nnn.stderr b/tests/ui/traits/const-traits/super-traits-fail-3.nnn.stderr index a5ef716a62a5d..f9e917e330603 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-3.nnn.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-3.nnn.stderr @@ -1,17 +1,27 @@ error: `~const` is not allowed here - --> $DIR/super-traits-fail-3.rs:23:12 + --> $DIR/super-traits-fail-3.rs:27:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ | note: this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds - --> $DIR/super-traits-fail-3.rs:23:1 + --> $DIR/super-traits-fail-3.rs:27:1 | LL | trait Bar: ~const Foo {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error[E0658]: const trait impls are experimental - --> $DIR/super-traits-fail-3.rs:23:12 + --> $DIR/super-traits-fail-3.rs:19:5 + | +LL | (const) fn a(&self); + | ^^^^^^^ + | + = note: see issue #67792 for more information + = help: add `#![feature(const_trait_impl)]` 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[E0658]: const trait impls are experimental + --> $DIR/super-traits-fail-3.rs:27:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ @@ -21,7 +31,7 @@ LL | trait Bar: ~const Foo {} = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: const trait impls are experimental - --> $DIR/super-traits-fail-3.rs:32:17 + --> $DIR/super-traits-fail-3.rs:36:17 | LL | const fn foo(x: &T) { | ^^^^^^ @@ -31,7 +41,7 @@ LL | const fn foo(x: &T) { = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:23:12 + --> $DIR/super-traits-fail-3.rs:27:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` @@ -42,7 +52,7 @@ LL | #[const_trait] trait Foo { | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:23:12 + --> $DIR/super-traits-fail-3.rs:27:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` @@ -54,7 +64,7 @@ LL | #[const_trait] trait Foo { | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:23:12 + --> $DIR/super-traits-fail-3.rs:27:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` @@ -66,7 +76,7 @@ LL | #[const_trait] trait Foo { | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:32:17 + --> $DIR/super-traits-fail-3.rs:36:17 | LL | const fn foo(x: &T) { | ^^^^^^ can't be applied to `Bar` @@ -77,7 +87,7 @@ LL | #[const_trait] trait Bar: ~const Foo {} | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:32:17 + --> $DIR/super-traits-fail-3.rs:36:17 | LL | const fn foo(x: &T) { | ^^^^^^ can't be applied to `Bar` @@ -89,14 +99,14 @@ LL | #[const_trait] trait Bar: ~const Foo {} | ++++++++++++++ error[E0015]: cannot call non-const method `::a` in constant functions - --> $DIR/super-traits-fail-3.rs:36:7 + --> $DIR/super-traits-fail-3.rs:40:7 | LL | x.a(); | ^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants -error: aborting due to 9 previous errors +error: aborting due to 10 previous errors Some errors have detailed explanations: E0015, E0658. For more information about an error, try `rustc --explain E0015`. diff --git a/tests/ui/traits/const-traits/super-traits-fail-3.nny.stderr b/tests/ui/traits/const-traits/super-traits-fail-3.nny.stderr index a5ef716a62a5d..f9e917e330603 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-3.nny.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-3.nny.stderr @@ -1,17 +1,27 @@ error: `~const` is not allowed here - --> $DIR/super-traits-fail-3.rs:23:12 + --> $DIR/super-traits-fail-3.rs:27:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ | note: this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds - --> $DIR/super-traits-fail-3.rs:23:1 + --> $DIR/super-traits-fail-3.rs:27:1 | LL | trait Bar: ~const Foo {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error[E0658]: const trait impls are experimental - --> $DIR/super-traits-fail-3.rs:23:12 + --> $DIR/super-traits-fail-3.rs:19:5 + | +LL | (const) fn a(&self); + | ^^^^^^^ + | + = note: see issue #67792 for more information + = help: add `#![feature(const_trait_impl)]` 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[E0658]: const trait impls are experimental + --> $DIR/super-traits-fail-3.rs:27:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ @@ -21,7 +31,7 @@ LL | trait Bar: ~const Foo {} = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: const trait impls are experimental - --> $DIR/super-traits-fail-3.rs:32:17 + --> $DIR/super-traits-fail-3.rs:36:17 | LL | const fn foo(x: &T) { | ^^^^^^ @@ -31,7 +41,7 @@ LL | const fn foo(x: &T) { = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:23:12 + --> $DIR/super-traits-fail-3.rs:27:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` @@ -42,7 +52,7 @@ LL | #[const_trait] trait Foo { | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:23:12 + --> $DIR/super-traits-fail-3.rs:27:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` @@ -54,7 +64,7 @@ LL | #[const_trait] trait Foo { | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:23:12 + --> $DIR/super-traits-fail-3.rs:27:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` @@ -66,7 +76,7 @@ LL | #[const_trait] trait Foo { | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:32:17 + --> $DIR/super-traits-fail-3.rs:36:17 | LL | const fn foo(x: &T) { | ^^^^^^ can't be applied to `Bar` @@ -77,7 +87,7 @@ LL | #[const_trait] trait Bar: ~const Foo {} | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:32:17 + --> $DIR/super-traits-fail-3.rs:36:17 | LL | const fn foo(x: &T) { | ^^^^^^ can't be applied to `Bar` @@ -89,14 +99,14 @@ LL | #[const_trait] trait Bar: ~const Foo {} | ++++++++++++++ error[E0015]: cannot call non-const method `::a` in constant functions - --> $DIR/super-traits-fail-3.rs:36:7 + --> $DIR/super-traits-fail-3.rs:40:7 | LL | x.a(); | ^^^ | = note: calls in constant functions are limited to constant functions, tuple structs and tuple variants -error: aborting due to 9 previous errors +error: aborting due to 10 previous errors Some errors have detailed explanations: E0015, E0658. For more information about an error, try `rustc --explain E0015`. diff --git a/tests/ui/traits/const-traits/super-traits-fail-3.nyn.stderr b/tests/ui/traits/const-traits/super-traits-fail-3.nyn.stderr index 024db4b6d68d0..b5639335c1807 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-3.nyn.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-3.nyn.stderr @@ -1,5 +1,25 @@ +error[E0658]: `const fn` in traits is unstable + --> $DIR/super-traits-fail-3.rs:19:5 + | +LL | (const) fn a(&self); + | ^^^^^^^ + | + = note: see issue #67792 for more information + = help: add `#![feature(const_trait_impl)]` 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[E0658]: const trait impls are experimental + --> $DIR/super-traits-fail-3.rs:19:5 + | +LL | (const) fn a(&self); + | ^^^^^^^ + | + = note: see issue #67792 for more information + = help: add `#![feature(const_trait_impl)]` 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[E0658]: const trait impls are experimental - --> $DIR/super-traits-fail-3.rs:23:12 + --> $DIR/super-traits-fail-3.rs:27:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ @@ -9,7 +29,7 @@ LL | trait Bar: ~const Foo {} = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: const trait impls are experimental - --> $DIR/super-traits-fail-3.rs:32:17 + --> $DIR/super-traits-fail-3.rs:36:17 | LL | const fn foo(x: &T) { | ^^^^^^ @@ -29,7 +49,7 @@ LL | #[cfg_attr(any(yyy, yyn, nyy, nyn), const_trait)] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: `const_trait` is a temporary placeholder for marking a trait that is suitable for `const` `impls` and all default bodies as `const`, which may be removed or renamed in the future. - --> $DIR/super-traits-fail-3.rs:21:37 + --> $DIR/super-traits-fail-3.rs:25:37 | LL | #[cfg_attr(any(yyy, yny, nyy, nyn), const_trait)] | ^^^^^^^^^^^ @@ -39,7 +59,7 @@ LL | #[cfg_attr(any(yyy, yny, nyy, nyn), const_trait)] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: cannot call conditionally-const method `::a` in constant functions - --> $DIR/super-traits-fail-3.rs:36:7 + --> $DIR/super-traits-fail-3.rs:40:7 | LL | x.a(); | ^^^ @@ -49,6 +69,6 @@ LL | x.a(); = help: add `#![feature(const_trait_impl)]` 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: aborting due to 5 previous errors +error: aborting due to 7 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/traits/const-traits/super-traits-fail-3.nyy.stderr b/tests/ui/traits/const-traits/super-traits-fail-3.nyy.stderr index 024db4b6d68d0..b5639335c1807 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-3.nyy.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-3.nyy.stderr @@ -1,5 +1,25 @@ +error[E0658]: `const fn` in traits is unstable + --> $DIR/super-traits-fail-3.rs:19:5 + | +LL | (const) fn a(&self); + | ^^^^^^^ + | + = note: see issue #67792 for more information + = help: add `#![feature(const_trait_impl)]` 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[E0658]: const trait impls are experimental + --> $DIR/super-traits-fail-3.rs:19:5 + | +LL | (const) fn a(&self); + | ^^^^^^^ + | + = note: see issue #67792 for more information + = help: add `#![feature(const_trait_impl)]` 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[E0658]: const trait impls are experimental - --> $DIR/super-traits-fail-3.rs:23:12 + --> $DIR/super-traits-fail-3.rs:27:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ @@ -9,7 +29,7 @@ LL | trait Bar: ~const Foo {} = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: const trait impls are experimental - --> $DIR/super-traits-fail-3.rs:32:17 + --> $DIR/super-traits-fail-3.rs:36:17 | LL | const fn foo(x: &T) { | ^^^^^^ @@ -29,7 +49,7 @@ LL | #[cfg_attr(any(yyy, yyn, nyy, nyn), const_trait)] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: `const_trait` is a temporary placeholder for marking a trait that is suitable for `const` `impls` and all default bodies as `const`, which may be removed or renamed in the future. - --> $DIR/super-traits-fail-3.rs:21:37 + --> $DIR/super-traits-fail-3.rs:25:37 | LL | #[cfg_attr(any(yyy, yny, nyy, nyn), const_trait)] | ^^^^^^^^^^^ @@ -39,7 +59,7 @@ LL | #[cfg_attr(any(yyy, yny, nyy, nyn), const_trait)] = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date error[E0658]: cannot call conditionally-const method `::a` in constant functions - --> $DIR/super-traits-fail-3.rs:36:7 + --> $DIR/super-traits-fail-3.rs:40:7 | LL | x.a(); | ^^^ @@ -49,6 +69,6 @@ LL | x.a(); = help: add `#![feature(const_trait_impl)]` 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: aborting due to 5 previous errors +error: aborting due to 7 previous errors For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/traits/const-traits/super-traits-fail-3.rs b/tests/ui/traits/const-traits/super-traits-fail-3.rs index d7e0cdc26edd0..5e1a003ff89e7 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-3.rs +++ b/tests/ui/traits/const-traits/super-traits-fail-3.rs @@ -15,6 +15,10 @@ #[cfg_attr(any(yyy, yyn, nyy, nyn), const_trait)] //[nyy,nyn]~^ ERROR: `const_trait` is a temporary placeholder for marking a trait that is suitable for `const` `impls` and all default bodies as `const`, which may be removed or renamed in the future trait Foo { + #[cfg(any(yyy, yyn, nyy, nyn))] + (const) fn a(&self); //[nyy,nyn]~ ERROR: `const fn` in traits is unstable + //[nyy,nyn,nny,nnn]~^ ERROR: const trait impls are experimental + #[cfg(not(any(yyy, yyn, nyy, nyn)))] fn a(&self); } diff --git a/tests/ui/traits/const-traits/super-traits-fail-3.ynn.stderr b/tests/ui/traits/const-traits/super-traits-fail-3.ynn.stderr index f22bdd472e538..53ce085c54b08 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-3.ynn.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-3.ynn.stderr @@ -1,17 +1,17 @@ error: `~const` is not allowed here - --> $DIR/super-traits-fail-3.rs:23:12 + --> $DIR/super-traits-fail-3.rs:27:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ | note: this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds - --> $DIR/super-traits-fail-3.rs:23:1 + --> $DIR/super-traits-fail-3.rs:27:1 | LL | trait Bar: ~const Foo {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:23:12 + --> $DIR/super-traits-fail-3.rs:27:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` @@ -22,7 +22,7 @@ LL | #[const_trait] trait Foo { | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:23:12 + --> $DIR/super-traits-fail-3.rs:27:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` @@ -34,7 +34,7 @@ LL | #[const_trait] trait Foo { | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:23:12 + --> $DIR/super-traits-fail-3.rs:27:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` @@ -46,7 +46,7 @@ LL | #[const_trait] trait Foo { | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:32:17 + --> $DIR/super-traits-fail-3.rs:36:17 | LL | const fn foo(x: &T) { | ^^^^^^ can't be applied to `Bar` @@ -57,7 +57,7 @@ LL | #[const_trait] trait Bar: ~const Foo {} | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:32:17 + --> $DIR/super-traits-fail-3.rs:36:17 | LL | const fn foo(x: &T) { | ^^^^^^ can't be applied to `Bar` @@ -69,7 +69,7 @@ LL | #[const_trait] trait Bar: ~const Foo {} | ++++++++++++++ error[E0015]: cannot call non-const method `::a` in constant functions - --> $DIR/super-traits-fail-3.rs:36:7 + --> $DIR/super-traits-fail-3.rs:40:7 | LL | x.a(); | ^^^ diff --git a/tests/ui/traits/const-traits/super-traits-fail-3.yny.stderr b/tests/ui/traits/const-traits/super-traits-fail-3.yny.stderr index 14b50815b8e9c..d756221716829 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-3.yny.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-3.yny.stderr @@ -1,5 +1,5 @@ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:23:12 + --> $DIR/super-traits-fail-3.rs:27:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` @@ -10,7 +10,7 @@ LL | #[const_trait] trait Foo { | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:23:12 + --> $DIR/super-traits-fail-3.rs:27:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` @@ -22,7 +22,7 @@ LL | #[const_trait] trait Foo { | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:23:12 + --> $DIR/super-traits-fail-3.rs:27:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` @@ -34,7 +34,7 @@ LL | #[const_trait] trait Foo { | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:23:12 + --> $DIR/super-traits-fail-3.rs:27:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` @@ -46,7 +46,7 @@ LL | #[const_trait] trait Foo { | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:23:12 + --> $DIR/super-traits-fail-3.rs:27:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ can't be applied to `Foo` @@ -58,7 +58,7 @@ LL | #[const_trait] trait Foo { | ++++++++++++++ error[E0015]: cannot call non-const method `::a` in constant functions - --> $DIR/super-traits-fail-3.rs:36:7 + --> $DIR/super-traits-fail-3.rs:40:7 | LL | x.a(); | ^^^ diff --git a/tests/ui/traits/const-traits/super-traits-fail-3.yyn.stderr b/tests/ui/traits/const-traits/super-traits-fail-3.yyn.stderr index 3270611dace2e..d7ff115c03dfa 100644 --- a/tests/ui/traits/const-traits/super-traits-fail-3.yyn.stderr +++ b/tests/ui/traits/const-traits/super-traits-fail-3.yyn.stderr @@ -1,17 +1,17 @@ error: `~const` is not allowed here - --> $DIR/super-traits-fail-3.rs:23:12 + --> $DIR/super-traits-fail-3.rs:27:12 | LL | trait Bar: ~const Foo {} | ^^^^^^ | note: this trait is not a `#[const_trait]`, so it cannot have `~const` trait bounds - --> $DIR/super-traits-fail-3.rs:23:1 + --> $DIR/super-traits-fail-3.rs:27:1 | LL | trait Bar: ~const Foo {} | ^^^^^^^^^^^^^^^^^^^^^^^^ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:32:17 + --> $DIR/super-traits-fail-3.rs:36:17 | LL | const fn foo(x: &T) { | ^^^^^^ can't be applied to `Bar` @@ -22,7 +22,7 @@ LL | #[const_trait] trait Bar: ~const Foo {} | ++++++++++++++ error: `~const` can only be applied to `#[const_trait]` traits - --> $DIR/super-traits-fail-3.rs:32:17 + --> $DIR/super-traits-fail-3.rs:36:17 | LL | const fn foo(x: &T) { | ^^^^^^ can't be applied to `Bar` @@ -34,7 +34,7 @@ LL | #[const_trait] trait Bar: ~const Foo {} | ++++++++++++++ error[E0277]: the trait bound `T: ~const Foo` is not satisfied - --> $DIR/super-traits-fail-3.rs:36:7 + --> $DIR/super-traits-fail-3.rs:40:7 | LL | x.a(); | ^ diff --git a/tests/ui/traits/const-traits/super-traits-fail.rs b/tests/ui/traits/const-traits/super-traits-fail.rs index 9fd6263118bdc..6dd6bcf056e10 100644 --- a/tests/ui/traits/const-traits/super-traits-fail.rs +++ b/tests/ui/traits/const-traits/super-traits-fail.rs @@ -4,7 +4,7 @@ #[const_trait] trait Foo { - fn a(&self); + (const) fn a(&self); } #[const_trait] trait Bar: ~const Foo {} diff --git a/tests/ui/traits/const-traits/super-traits.rs b/tests/ui/traits/const-traits/super-traits.rs index 73ddc037cd795..a381c4accdfa5 100644 --- a/tests/ui/traits/const-traits/super-traits.rs +++ b/tests/ui/traits/const-traits/super-traits.rs @@ -4,7 +4,7 @@ #[const_trait] trait Foo { - fn a(&self); + (const) fn a(&self); } #[const_trait] @@ -12,7 +12,7 @@ trait Bar: ~const Foo {} struct S; impl const Foo for S { - fn a(&self) {} + (const) fn a(&self) {} } impl const Bar for S {} diff --git a/tests/ui/traits/const-traits/syntactical-unstable.rs b/tests/ui/traits/const-traits/syntactical-unstable.rs index e192e80fabd9e..ca1180502faad 100644 --- a/tests/ui/traits/const-traits/syntactical-unstable.rs +++ b/tests/ui/traits/const-traits/syntactical-unstable.rs @@ -28,7 +28,7 @@ const fn rpit() -> impl ~const MyTrait { Local } struct Local; impl const MyTrait for Local { //~^ ERROR use of unstable const library feature `unstable` - fn func() {} + (const) fn func() {} } fn main() {} diff --git a/tests/ui/traits/const-traits/tilde-const-and-const-params.rs b/tests/ui/traits/const-traits/tilde-const-and-const-params.rs index 706c77b6200a8..63ae0e96d7f6e 100644 --- a/tests/ui/traits/const-traits/tilde-const-and-const-params.rs +++ b/tests/ui/traits/const-traits/tilde-const-and-const-params.rs @@ -15,11 +15,11 @@ impl Foo { #[const_trait] trait Add42 { - fn add(a: usize) -> usize; + (const) fn add(a: usize) -> usize; } impl const Add42 for () { - fn add(a: usize) -> usize { + (const) fn add(a: usize) -> usize { a + 42 } } diff --git a/tests/ui/traits/const-traits/tilde-const-assoc-fn-in-trait-impl.rs b/tests/ui/traits/const-traits/tilde-const-assoc-fn-in-trait-impl.rs index 73b2bdc4e3f86..8068d01a2f05e 100644 --- a/tests/ui/traits/const-traits/tilde-const-assoc-fn-in-trait-impl.rs +++ b/tests/ui/traits/const-traits/tilde-const-assoc-fn-in-trait-impl.rs @@ -5,22 +5,22 @@ #[const_trait] trait Main { - fn compute() -> u32; + (const) fn compute() -> u32; } impl const Main for () { - fn compute() -> u32 { + (const) fn compute() -> u32 { T::generate() } } #[const_trait] trait Aux { - fn generate() -> u32; + (const) fn generate() -> u32; } impl const Aux for () { - fn generate() -> u32 { 1024 } + (const) fn generate() -> u32 { 1024 } } fn main() { diff --git a/tests/ui/traits/const-traits/tilde-const-inherent-assoc-const-fn.rs b/tests/ui/traits/const-traits/tilde-const-inherent-assoc-const-fn.rs index 0e010695587f4..d132ccfbc2b48 100644 --- a/tests/ui/traits/const-traits/tilde-const-inherent-assoc-const-fn.rs +++ b/tests/ui/traits/const-traits/tilde-const-inherent-assoc-const-fn.rs @@ -4,7 +4,7 @@ #[const_trait] trait Foo { - fn foo(&self) {} + (const) fn foo(&self) {} } struct Bar(T); diff --git a/tests/ui/traits/const-traits/trait-where-clause-const.rs b/tests/ui/traits/const-traits/trait-where-clause-const.rs index 6f281ca571805..79357290e52ab 100644 --- a/tests/ui/traits/const-traits/trait-where-clause-const.rs +++ b/tests/ui/traits/const-traits/trait-where-clause-const.rs @@ -11,9 +11,9 @@ trait Bar {} #[const_trait] trait Foo { - fn a(); - fn b() where Self: ~const Bar; - fn c(); + (const) fn a(); + (const) fn b() where Self: ~const Bar; + (const) fn c(); } const fn test1() { diff --git a/tests/ui/traits/const-traits/trait-where-clause-const.stderr b/tests/ui/traits/const-traits/trait-where-clause-const.stderr index 4ebd7b9757fe7..655565ac405ac 100644 --- a/tests/ui/traits/const-traits/trait-where-clause-const.stderr +++ b/tests/ui/traits/const-traits/trait-where-clause-const.stderr @@ -5,10 +5,10 @@ LL | T::b(); | ^ | note: required by a bound in `Foo::b` - --> $DIR/trait-where-clause-const.rs:15:24 + --> $DIR/trait-where-clause-const.rs:15:32 | -LL | fn b() where Self: ~const Bar; - | ^^^^^^^^^^ required by this bound in `Foo::b` +LL | (const) fn b() where Self: ~const Bar; + | ^^^^^^^^^^ required by this bound in `Foo::b` error[E0277]: the trait bound `T: ~const Bar` is not satisfied --> $DIR/trait-where-clause-const.rs:23:12 @@ -17,10 +17,10 @@ LL | T::c::(); | ^ | note: required by a bound in `Foo::c` - --> $DIR/trait-where-clause-const.rs:16:13 + --> $DIR/trait-where-clause-const.rs:16:21 | -LL | fn c(); - | ^^^^^^^^^^ required by this bound in `Foo::c` +LL | (const) fn c(); + | ^^^^^^^^^^ required by this bound in `Foo::c` error: aborting due to 2 previous errors diff --git a/tests/ui/traits/const-traits/trait-where-clause-run.rs b/tests/ui/traits/const-traits/trait-where-clause-run.rs index 2582a69acab20..60ee74d0ccb49 100644 --- a/tests/ui/traits/const-traits/trait-where-clause-run.rs +++ b/tests/ui/traits/const-traits/trait-where-clause-run.rs @@ -5,12 +5,12 @@ #[const_trait] trait Bar { - fn bar() -> u8; + (const) fn bar() -> u8; } #[const_trait] trait Foo { - fn foo() -> u8 where Self: ~const Bar { + (const) fn foo() -> u8 where Self: ~const Bar { ::bar() * 6 } } @@ -27,7 +27,7 @@ impl Bar for NonConst { impl Foo for NonConst {} impl const Bar for Const { - fn bar() -> u8 { + (const) fn bar() -> u8 { 4 } } diff --git a/tests/ui/traits/const-traits/trait-where-clause-self-referential.rs b/tests/ui/traits/const-traits/trait-where-clause-self-referential.rs index b6ac574a4fcd8..64ab4da1e1900 100644 --- a/tests/ui/traits/const-traits/trait-where-clause-self-referential.rs +++ b/tests/ui/traits/const-traits/trait-where-clause-self-referential.rs @@ -4,7 +4,7 @@ #[const_trait] trait Foo { - fn bar() where Self: ~const Foo; + (const) fn bar() where Self: ~const Foo; } struct S; diff --git a/tests/ui/traits/const-traits/unsatisfied-const-trait-bound.stderr b/tests/ui/traits/const-traits/unsatisfied-const-trait-bound.stderr index 03e26615d7edc..3f5c925a88456 100644 --- a/tests/ui/traits/const-traits/unsatisfied-const-trait-bound.stderr +++ b/tests/ui/traits/const-traits/unsatisfied-const-trait-bound.stderr @@ -1,3 +1,9 @@ +error: non-const fn in const traits are not supported yet + --> $DIR/unsatisfied-const-trait-bound.rs:12:5 + | +LL | fn make() -> u32; + | ^ help: mark the function as const: `(const)` + error: `-Znext-solver=globally` and `generic_const_exprs` are incompatible, using them at the same time is not allowed --> $DIR/unsatisfied-const-trait-bound.rs:5:30 | @@ -134,6 +140,6 @@ LL | const fn accept1(_: Container<{ T::make() }>) {} | ^^^^^^^^^^^^^ = note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0391`. diff --git a/tests/ui/traits/next-solver/canonical/effect-var.rs b/tests/ui/traits/next-solver/canonical/effect-var.rs index 82dbde0413c49..49e17c71b6bf3 100644 --- a/tests/ui/traits/next-solver/canonical/effect-var.rs +++ b/tests/ui/traits/next-solver/canonical/effect-var.rs @@ -5,17 +5,17 @@ #[const_trait] trait Foo { - fn foo(); + (const) fn foo(); } trait Bar {} impl const Foo for i32 { - fn foo() {} + (const) fn foo() {} } impl const Foo for T where T: Bar { - fn foo() {} + (const) fn foo() {} } fn main() {}