From 9835e2ae736235810b4ea1c162ca5e65c547e770 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 18 May 2024 04:49:50 +0200 Subject: Merging upstream version 1.71.1+dfsg1. Signed-off-by: Daniel Baumann --- compiler/rustc_ast_passes/src/ast_validation.rs | 24 +++++++++++++++++++----- compiler/rustc_ast_passes/src/errors.rs | 17 ++++++++++++++++- compiler/rustc_ast_passes/src/feature_gate.rs | 15 +++++++++++---- compiler/rustc_ast_passes/src/lib.rs | 2 +- 4 files changed, 47 insertions(+), 11 deletions(-) (limited to 'compiler/rustc_ast_passes/src') diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index c79626ccd..04ed27678 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -348,7 +348,7 @@ impl<'a> AstValidator<'a> { let source_map = self.session.source_map(); let end = source_map.end_point(sp); - if source_map.span_to_snippet(end).map(|s| s == ";").unwrap_or(false) { + if source_map.span_to_snippet(end).is_ok_and(|s| s == ";") { end } else { sp.shrink_to_hi() @@ -736,11 +736,10 @@ impl<'a> Visitor<'a> for AstValidator<'a> { this.visit_expr(&arm.body); this.visit_pat(&arm.pat); walk_list!(this, visit_attribute, &arm.attrs); - if let Some(guard) = &arm.guard && let ExprKind::Let(_, guard_expr, _) = &guard.kind { + if let Some(guard) = &arm.guard { this.with_let_management(None, |this, _| { - this.visit_expr(guard_expr) + this.visit_expr(guard) }); - return; } } } @@ -1168,12 +1167,27 @@ impl<'a> Visitor<'a> for AstValidator<'a> { }); } (_, TraitBoundModifier::MaybeConstMaybe) => { - self.err_handler().emit_err(errors::OptionalConstExclusive {span: bound.span()}); + self.err_handler().emit_err(errors::OptionalConstExclusive {span: bound.span(), modifier: "?" }); + } + (_, TraitBoundModifier::MaybeConstNegative) => { + self.err_handler().emit_err(errors::OptionalConstExclusive {span: bound.span(), modifier: "!" }); } _ => {} } } + // Negative trait bounds are not allowed to have associated constraints + if let GenericBound::Trait(trait_ref, TraitBoundModifier::Negative) = bound + && let Some(segment) = trait_ref.trait_ref.path.segments.last() + && let Some(ast::GenericArgs::AngleBracketed(args)) = segment.args.as_deref() + { + for arg in &args.args { + if let ast::AngleBracketedArg::Constraint(constraint) = arg { + self.err_handler().emit_err(errors::ConstraintOnNegativeBound { span: constraint.span }); + } + } + } + visit::walk_param_bound(self, bound) } diff --git a/compiler/rustc_ast_passes/src/errors.rs b/compiler/rustc_ast_passes/src/errors.rs index 27bbd2379..82fe2a21d 100644 --- a/compiler/rustc_ast_passes/src/errors.rs +++ b/compiler/rustc_ast_passes/src/errors.rs @@ -567,6 +567,7 @@ pub enum TildeConstReason { pub struct OptionalConstExclusive { #[primary_span] pub span: Span, + pub modifier: &'static str, } #[derive(Diagnostic)] @@ -677,7 +678,7 @@ impl AddToDiagnostic for StableFeature { } #[derive(Diagnostic)] -#[diag(ast_passes_incompatbile_features)] +#[diag(ast_passes_incompatible_features)] #[help] pub struct IncompatibleFeatures { #[primary_span] @@ -693,3 +694,17 @@ pub struct ShowSpan { pub span: Span, pub msg: &'static str, } + +#[derive(Diagnostic)] +#[diag(ast_passes_negative_bound_not_supported)] +pub struct NegativeBoundUnsupported { + #[primary_span] + pub span: Span, +} + +#[derive(Diagnostic)] +#[diag(ast_passes_constraint_on_negative_bound)] +pub struct ConstraintOnNegativeBound { + #[primary_span] + pub span: Span, +} diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index 17bcd24ee..274f931e4 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -83,7 +83,7 @@ impl<'a> PostExpansionVisitor<'a> { &self, const_extern_fn, span, - &format!("`{}` as a `const fn` ABI is unstable", abi) + format!("`{}` as a `const fn` ABI is unstable", abi) ), } } @@ -104,7 +104,7 @@ impl<'a> PostExpansionVisitor<'a> { if self.sess.opts.pretty.map_or(true, |ppm| ppm.needs_hir()) { self.sess.parse_sess.span_diagnostic.delay_span_bug( span, - &format!( + format!( "unrecognized ABI not caught in lowering: {}", symbol_unescaped.as_str() ), @@ -317,8 +317,7 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { match i.kind { ast::ForeignItemKind::Fn(..) | ast::ForeignItemKind::Static(..) => { let link_name = attr::first_attr_value_str_by_name(&i.attrs, sym::link_name); - let links_to_llvm = - link_name.map_or(false, |val| val.as_str().starts_with("llvm.")); + let links_to_llvm = link_name.is_some_and(|val| val.as_str().starts_with("llvm.")); if links_to_llvm { gate_feature_post!( &self, @@ -572,6 +571,7 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) { } }; } + gate_all!(c_str_literals, "`c\"..\"` literals are experimental"); gate_all!( if_let_guard, "`if let` guards are experimental", @@ -602,6 +602,13 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) { gate_all!(yeet_expr, "`do yeet` expression is experimental"); gate_all!(dyn_star, "`dyn*` trait objects are experimental"); gate_all!(const_closures, "const closures are experimental"); + gate_all!(builtin_syntax, "`builtin #` syntax is unstable"); + + if !visitor.features.negative_bounds { + for &span in spans.get(&sym::negative_bounds).iter().copied().flatten() { + sess.emit_err(errors::NegativeBoundUnsupported { span }); + } + } // All uses of `gate_all!` below this point were added in #65742, // and subsequently disabled (with the non-early gating readded). diff --git a/compiler/rustc_ast_passes/src/lib.rs b/compiler/rustc_ast_passes/src/lib.rs index e2c666604..7db413c5b 100644 --- a/compiler/rustc_ast_passes/src/lib.rs +++ b/compiler/rustc_ast_passes/src/lib.rs @@ -13,7 +13,7 @@ #![deny(rustc::diagnostic_outside_of_impl)] use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; -use rustc_macros::fluent_messages; +use rustc_fluent_macro::fluent_messages; pub mod ast_validation; mod errors; -- cgit v1.2.3