diff --git a/compiler/rustc_error_messages/locales/en-US/passes.ftl b/compiler/rustc_error_messages/locales/en-US/passes.ftl index 0c7e02912d4ef..789a7cef4ae71 100644 --- a/compiler/rustc_error_messages/locales/en-US/passes.ftl +++ b/compiler/rustc_error_messages/locales/en-US/passes.ftl @@ -745,3 +745,7 @@ passes_proc_macro_invalid_abi = proc macro functions may not be `extern "{$abi}" passes_proc_macro_unsafe = proc macro functions may not be `unsafe` passes_skipping_const_checks = skipping const checks + +passes_invalid_macro_export_arguments = `{$name}` isn't a valid `#[macro_export]` argument + +passes_invalid_macro_export_arguments_too_many_items = `#[macro_export]` can only take 1 or 0 arguments diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 69a7235802bb3..6a33826ea281c 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -932,25 +932,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { labels .push((provided_span, format!("unexpected argument{}", provided_ty_name))); let mut span = provided_span; - if arg_idx.index() > 0 + if span.can_be_used_for_suggestions() { + if arg_idx.index() > 0 && let Some((_, prev)) = provided_arg_tys .get(ProvidedIdx::from_usize(arg_idx.index() - 1) ) { // Include previous comma - span = span.with_lo(prev.hi()); - } else if let Some((_, next)) = provided_arg_tys.get( - ProvidedIdx::from_usize(arg_idx.index() + 1), - ) { - // Include next comma - span = span.until(*next); + span = prev.shrink_to_hi().to(span); } - suggestions.push((span, String::new())); + suggestions.push((span, String::new())); - suggestion_text = match suggestion_text { - SuggestionText::None => SuggestionText::Remove(false), - SuggestionText::Remove(_) => SuggestionText::Remove(true), - _ => SuggestionText::DidYouMean, - }; + suggestion_text = match suggestion_text { + SuggestionText::None => SuggestionText::Remove(false), + SuggestionText::Remove(_) => SuggestionText::Remove(true), + _ => SuggestionText::DidYouMean, + }; + } } Error::Missing(expected_idx) => { // If there are multiple missing arguments adjacent to each other, diff --git a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs index ac203c4eb0b24..e6b7602f334cb 100644 --- a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs +++ b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs @@ -1046,7 +1046,7 @@ impl<'tcx> LexicalRegionResolutions<'tcx> { ty::ReVar(rid) => match self.values[rid] { VarValue::Empty(_) => r, VarValue::Value(r) => r, - VarValue::ErrorValue => tcx.mk_re_error_misc(), + VarValue::ErrorValue => tcx.lifetimes.re_static, }, _ => r, }; diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 9d8ad9d9ed9f6..46ec1a2dca1f7 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -4103,3 +4103,33 @@ declare_lint! { }; report_in_external_macro } + +declare_lint! { + /// The `invalid_macro_export_arguments` lint detects cases where `#[macro_export]` is being used with invalid arguments. + /// + /// ### Example + /// + /// ```rust,compile_fail + /// #![deny(invalid_macro_export_arguments)] + /// + /// #[macro_export(invalid_parameter)] + /// macro_rules! myMacro { + /// () => { + /// // [...] + /// } + /// } + /// + /// #[macro_export(too, many, items)] + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// The only valid argument is `#[macro_export(local_inner_macros)]` or no argument (`#[macro_export]`). + /// You can't have multiple arguments in a `#[macro_export(..)]`, or mention arguments other than `local_inner_macros`. + /// + pub INVALID_MACRO_EXPORT_ARGUMENTS, + Warn, + "\"invalid_parameter\" isn't a valid argument for `#[macro_export]`", +} diff --git a/compiler/rustc_middle/src/values.rs b/compiler/rustc_middle/src/values.rs index 34e8a559784e6..21f3ef9267ff3 100644 --- a/compiler/rustc_middle/src/values.rs +++ b/compiler/rustc_middle/src/values.rs @@ -2,7 +2,7 @@ use crate::dep_graph::DepKind; use rustc_data_structures::fx::FxHashSet; use rustc_errors::{pluralize, struct_span_err, Applicability, MultiSpan}; use rustc_hir as hir; -use rustc_hir::def::DefKind; +use rustc_hir::def::{DefKind, Res}; use rustc_middle::ty::Representability; use rustc_middle::ty::{self, DefIdTree, Ty, TyCtxt}; use rustc_query_system::query::QueryInfo; @@ -199,7 +199,8 @@ fn find_item_ty_spans( ) { match ty.kind { hir::TyKind::Path(hir::QPath::Resolved(_, path)) => { - if let Some(def_id) = path.res.opt_def_id() { + if let Res::Def(kind, def_id) = path.res + && kind != DefKind::TyAlias { let check_params = def_id.as_local().map_or(true, |def_id| { if def_id == needle { spans.push(ty.span); diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 8ad4a5ef95813..1f796267e4988 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -23,7 +23,8 @@ use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams}; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{ParamEnv, TyCtxt}; use rustc_session::lint::builtin::{ - CONFLICTING_REPR_HINTS, INVALID_DOC_ATTRIBUTES, UNUSED_ATTRIBUTES, + CONFLICTING_REPR_HINTS, INVALID_DOC_ATTRIBUTES, INVALID_MACRO_EXPORT_ARGUMENTS, + UNUSED_ATTRIBUTES, }; use rustc_session::parse::feature_err; use rustc_span::symbol::{kw, sym, Symbol}; @@ -2102,7 +2103,33 @@ impl CheckAttrVisitor<'_> { fn check_macro_export(&self, hir_id: HirId, attr: &Attribute, target: Target) { if target != Target::MacroDef { - self.tcx.emit_spanned_lint(UNUSED_ATTRIBUTES, hir_id, attr.span, errors::MacroExport); + self.tcx.emit_spanned_lint( + UNUSED_ATTRIBUTES, + hir_id, + attr.span, + errors::MacroExport::Normal, + ); + } else if let Some(meta_item_list) = attr.meta_item_list() && + !meta_item_list.is_empty() { + if meta_item_list.len() > 1 { + self.tcx.emit_spanned_lint( + INVALID_MACRO_EXPORT_ARGUMENTS, + hir_id, + attr.span, + errors::MacroExport::TooManyItems, + ); + } else { + if meta_item_list[0].name_or_empty() != sym::local_inner_macros { + self.tcx.emit_spanned_lint( + INVALID_MACRO_EXPORT_ARGUMENTS, + hir_id, + meta_item_list[0].span(), + errors::MacroExport::UnknownItem { + name: meta_item_list[0].name_or_empty(), + }, + ); + } + } } } diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 68b098e3457b7..d651d7d9fdba2 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -640,8 +640,16 @@ pub struct MacroUse { } #[derive(LintDiagnostic)] -#[diag(passes_macro_export)] -pub struct MacroExport; +pub enum MacroExport { + #[diag(passes_macro_export)] + Normal, + + #[diag(passes_invalid_macro_export_arguments)] + UnknownItem { name: Symbol }, + + #[diag(passes_invalid_macro_export_arguments_too_many_items)] + TooManyItems, +} #[derive(LintDiagnostic)] #[diag(passes_plugin_registrar)] diff --git a/compiler/rustc_trait_selection/src/solve/assembly.rs b/compiler/rustc_trait_selection/src/solve/assembly.rs index 841169ac78d7d..d55aebf1a2696 100644 --- a/compiler/rustc_trait_selection/src/solve/assembly.rs +++ b/compiler/rustc_trait_selection/src/solve/assembly.rs @@ -1,6 +1,5 @@ //! Code shared by trait and projection goals for candidate assembly. -use super::infcx_ext::InferCtxtExt; #[cfg(doc)] use super::trait_goals::structural_traits::*; use super::{CanonicalResponse, Certainty, EvalCtxt, Goal, MaybeCause, QueryResult}; @@ -206,7 +205,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { &mut self, goal: Goal<'tcx, G>, ) -> Vec> { - debug_assert_eq!(goal, self.infcx.resolve_vars_if_possible(goal)); + debug_assert_eq!(goal, self.resolve_vars_if_possible(goal)); // HACK: `_: Trait` is ambiguous, because it may be satisfied via a builtin rule, // object bound, alias bound, etc. We are unable to determine this until we can at @@ -250,8 +249,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { let &ty::Alias(ty::Projection, projection_ty) = goal.predicate.self_ty().kind() else { return }; - self.infcx.probe(|_| { - let normalized_ty = self.infcx.next_ty_infer(); + self.probe(|this| { + let normalized_ty = this.next_ty_infer(); let normalizes_to_goal = goal.with( tcx, ty::Binder::dummy(ty::ProjectionPredicate { @@ -259,16 +258,16 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { term: normalized_ty.into(), }), ); - let normalization_certainty = match self.evaluate_goal(normalizes_to_goal) { + let normalization_certainty = match this.evaluate_goal(normalizes_to_goal) { Ok((_, certainty)) => certainty, Err(NoSolution) => return, }; - let normalized_ty = self.infcx.resolve_vars_if_possible(normalized_ty); + let normalized_ty = this.resolve_vars_if_possible(normalized_ty); // NOTE: Alternatively we could call `evaluate_goal` here and only have a `Normalized` candidate. // This doesn't work as long as we use `CandidateSource` in winnowing. let goal = goal.with(tcx, goal.predicate.with_self_ty(tcx, normalized_ty)); - let normalized_candidates = self.assemble_and_evaluate_candidates(goal); + let normalized_candidates = this.assemble_and_evaluate_candidates(goal); for mut normalized_candidate in normalized_candidates { normalized_candidate.result = normalized_candidate.result.unchecked_map(|mut response| { diff --git a/compiler/rustc_trait_selection/src/solve/eval_ctxt.rs b/compiler/rustc_trait_selection/src/solve/eval_ctxt.rs new file mode 100644 index 0000000000000..67addd732d0ad --- /dev/null +++ b/compiler/rustc_trait_selection/src/solve/eval_ctxt.rs @@ -0,0 +1,172 @@ +use rustc_hir::def_id::DefId; +use rustc_infer::infer::at::ToTrace; +use rustc_infer::infer::canonical::CanonicalVarValues; +use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; +use rustc_infer::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime}; +use rustc_infer::traits::query::NoSolution; +use rustc_infer::traits::ObligationCause; +use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind}; +use rustc_middle::ty::{self, ir::TypeVisitor, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable}; +use rustc_span::DUMMY_SP; +use std::ops::ControlFlow; + +use super::search_graph::SearchGraph; +use super::Goal; + +pub struct EvalCtxt<'a, 'tcx> { + // FIXME: should be private. + pub(super) infcx: &'a InferCtxt<'tcx>, + + pub(super) var_values: CanonicalVarValues<'tcx>, + + pub(super) search_graph: &'a mut SearchGraph<'tcx>, + + /// This field is used by a debug assertion in [`EvalCtxt::evaluate_goal`], + /// see the comment in that method for more details. + pub in_projection_eq_hack: bool, +} + +impl<'tcx> EvalCtxt<'_, 'tcx> { + pub(super) fn probe(&mut self, f: impl FnOnce(&mut EvalCtxt<'_, 'tcx>) -> T) -> T { + self.infcx.probe(|_| f(self)) + } + + pub(super) fn tcx(&self) -> TyCtxt<'tcx> { + self.infcx.tcx + } + + pub(super) fn next_ty_infer(&self) -> Ty<'tcx> { + self.infcx.next_ty_var(TypeVariableOrigin { + kind: TypeVariableOriginKind::MiscVariable, + span: DUMMY_SP, + }) + } + + pub(super) fn next_const_infer(&self, ty: Ty<'tcx>) -> ty::Const<'tcx> { + self.infcx.next_const_var( + ty, + ConstVariableOrigin { kind: ConstVariableOriginKind::MiscVariable, span: DUMMY_SP }, + ) + } + + /// Is the projection predicate is of the form `exists ::Assoc = T`. + /// + /// This is the case if the `term` is an inference variable in the innermost universe + /// and does not occur in any other part of the predicate. + pub(super) fn term_is_fully_unconstrained( + &self, + goal: Goal<'tcx, ty::ProjectionPredicate<'tcx>>, + ) -> bool { + let term_is_infer = match goal.predicate.term.unpack() { + ty::TermKind::Ty(ty) => { + if let &ty::Infer(ty::TyVar(vid)) = ty.kind() { + match self.infcx.probe_ty_var(vid) { + Ok(value) => bug!("resolved var in query: {goal:?} {value:?}"), + Err(universe) => universe == self.universe(), + } + } else { + false + } + } + ty::TermKind::Const(ct) => { + if let ty::ConstKind::Infer(ty::InferConst::Var(vid)) = ct.kind() { + match self.infcx.probe_const_var(vid) { + Ok(value) => bug!("resolved var in query: {goal:?} {value:?}"), + Err(universe) => universe == self.universe(), + } + } else { + false + } + } + }; + + // Guard against `>::Assoc = ?0>`. + struct ContainsTerm<'tcx> { + term: ty::Term<'tcx>, + } + impl<'tcx> TypeVisitor> for ContainsTerm<'tcx> { + type BreakTy = (); + fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { + if t.needs_infer() { + if ty::Term::from(t) == self.term { + ControlFlow::Break(()) + } else { + t.super_visit_with(self) + } + } else { + ControlFlow::Continue(()) + } + } + + fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow { + if c.needs_infer() { + if ty::Term::from(c) == self.term { + ControlFlow::Break(()) + } else { + c.super_visit_with(self) + } + } else { + ControlFlow::Continue(()) + } + } + } + + let mut visitor = ContainsTerm { term: goal.predicate.term }; + + term_is_infer + && goal.predicate.projection_ty.visit_with(&mut visitor).is_continue() + && goal.param_env.visit_with(&mut visitor).is_continue() + } + + #[instrument(level = "debug", skip(self, param_env), ret)] + pub(super) fn eq>( + &self, + param_env: ty::ParamEnv<'tcx>, + lhs: T, + rhs: T, + ) -> Result>>, NoSolution> { + self.infcx + .at(&ObligationCause::dummy(), param_env) + .eq(lhs, rhs) + .map(|InferOk { value: (), obligations }| { + obligations.into_iter().map(|o| o.into()).collect() + }) + .map_err(|e| { + debug!(?e, "failed to equate"); + NoSolution + }) + } + + pub(super) fn instantiate_binder_with_infer + Copy>( + &self, + value: ty::Binder<'tcx, T>, + ) -> T { + self.infcx.instantiate_binder_with_fresh_vars( + DUMMY_SP, + LateBoundRegionConversionTime::HigherRankedType, + value, + ) + } + + pub(super) fn instantiate_binder_with_placeholders + Copy>( + &self, + value: ty::Binder<'tcx, T>, + ) -> T { + self.infcx.instantiate_binder_with_placeholders(value) + } + + pub(super) fn resolve_vars_if_possible(&self, value: T) -> T + where + T: TypeFoldable<'tcx>, + { + self.infcx.resolve_vars_if_possible(value) + } + + pub(super) fn fresh_substs_for_item(&self, def_id: DefId) -> ty::SubstsRef<'tcx> { + self.infcx.fresh_substs_for_item(DUMMY_SP, def_id) + } + + pub(super) fn universe(&self) -> ty::UniverseIndex { + self.infcx.universe() + } +} diff --git a/compiler/rustc_trait_selection/src/solve/infcx_ext.rs b/compiler/rustc_trait_selection/src/solve/infcx_ext.rs deleted file mode 100644 index 06570e1f4b41c..0000000000000 --- a/compiler/rustc_trait_selection/src/solve/infcx_ext.rs +++ /dev/null @@ -1,77 +0,0 @@ -use rustc_infer::infer::at::ToTrace; -use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; -use rustc_infer::infer::{InferCtxt, InferOk, LateBoundRegionConversionTime}; -use rustc_infer::traits::query::NoSolution; -use rustc_infer::traits::ObligationCause; -use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind}; -use rustc_middle::ty::{self, Ty, TypeFoldable}; -use rustc_span::DUMMY_SP; - -use super::Goal; - -/// Methods used inside of the canonical queries of the solver. -/// -/// Most notably these do not care about diagnostics information. -/// If you find this while looking for methods to use outside of the -/// solver, you may look at the implementation of these method for -/// help. -pub(super) trait InferCtxtExt<'tcx> { - fn next_ty_infer(&self) -> Ty<'tcx>; - fn next_const_infer(&self, ty: Ty<'tcx>) -> ty::Const<'tcx>; - - fn eq>( - &self, - param_env: ty::ParamEnv<'tcx>, - lhs: T, - rhs: T, - ) -> Result>>, NoSolution>; - - fn instantiate_binder_with_infer + Copy>( - &self, - value: ty::Binder<'tcx, T>, - ) -> T; -} - -impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> { - fn next_ty_infer(&self) -> Ty<'tcx> { - self.next_ty_var(TypeVariableOrigin { - kind: TypeVariableOriginKind::MiscVariable, - span: DUMMY_SP, - }) - } - fn next_const_infer(&self, ty: Ty<'tcx>) -> ty::Const<'tcx> { - self.next_const_var( - ty, - ConstVariableOrigin { kind: ConstVariableOriginKind::MiscVariable, span: DUMMY_SP }, - ) - } - - #[instrument(level = "debug", skip(self, param_env), ret)] - fn eq>( - &self, - param_env: ty::ParamEnv<'tcx>, - lhs: T, - rhs: T, - ) -> Result>>, NoSolution> { - self.at(&ObligationCause::dummy(), param_env) - .eq(lhs, rhs) - .map(|InferOk { value: (), obligations }| { - obligations.into_iter().map(|o| o.into()).collect() - }) - .map_err(|e| { - debug!(?e, "failed to equate"); - NoSolution - }) - } - - fn instantiate_binder_with_infer + Copy>( - &self, - value: ty::Binder<'tcx, T>, - ) -> T { - self.instantiate_binder_with_fresh_vars( - DUMMY_SP, - LateBoundRegionConversionTime::HigherRankedType, - value, - ) - } -} diff --git a/compiler/rustc_trait_selection/src/solve/mod.rs b/compiler/rustc_trait_selection/src/solve/mod.rs index 6890811fd046e..c080f7e59fa22 100644 --- a/compiler/rustc_trait_selection/src/solve/mod.rs +++ b/compiler/rustc_trait_selection/src/solve/mod.rs @@ -35,16 +35,15 @@ use crate::solve::search_graph::OverflowHandler; use crate::traits::ObligationCause; mod assembly; +mod eval_ctxt; mod fulfill; -mod infcx_ext; mod project_goals; mod search_graph; mod trait_goals; +pub use eval_ctxt::EvalCtxt; pub use fulfill::FulfillmentCtxt; -use self::infcx_ext::InferCtxtExt; - /// A goal is a statement, i.e. `predicate`, we want to prove /// given some assumptions, i.e. `param_env`. /// @@ -180,22 +179,7 @@ impl<'tcx> InferCtxtEvalExt<'tcx> for InferCtxt<'tcx> { } } -struct EvalCtxt<'a, 'tcx> { - infcx: &'a InferCtxt<'tcx>, - var_values: CanonicalVarValues<'tcx>, - - search_graph: &'a mut search_graph::SearchGraph<'tcx>, - - /// This field is used by a debug assertion in [`EvalCtxt::evaluate_goal`], - /// see the comment in that method for more details. - in_projection_eq_hack: bool, -} - impl<'a, 'tcx> EvalCtxt<'a, 'tcx> { - fn tcx(&self) -> TyCtxt<'tcx> { - self.infcx.tcx - } - /// The entry point of the solver. /// /// This function deals with (coinductive) cycles, overflow, and caching @@ -427,7 +411,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> { let evaluate_normalizes_to = |ecx: &mut EvalCtxt<'_, 'tcx>, alias, other| { debug!("evaluate_normalizes_to(alias={:?}, other={:?})", alias, other); - let r = ecx.infcx.probe(|_| { + let r = ecx.probe(|ecx| { let (_, certainty) = ecx.evaluate_goal(goal.with( tcx, ty::Binder::dummy(ty::ProjectionPredicate { @@ -462,10 +446,10 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> { // Evaluate all 3 potential candidates for the alias' being equal candidates.push(evaluate_normalizes_to(self, alias_lhs, goal.predicate.1)); candidates.push(evaluate_normalizes_to(self, alias_rhs, goal.predicate.0)); - candidates.push(self.infcx.probe(|_| { + candidates.push(self.probe(|this| { debug!("compute_alias_eq_goal: alias defids are equal, equating substs"); - let nested_goals = self.infcx.eq(goal.param_env, alias_lhs, alias_rhs)?; - self.evaluate_all_and_make_canonical_response(nested_goals) + let nested_goals = this.eq(goal.param_env, alias_lhs, alias_rhs)?; + this.evaluate_all_and_make_canonical_response(nested_goals) })); debug!(?candidates); @@ -481,7 +465,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> { goal: Goal<'tcx, (ty::Const<'tcx>, Ty<'tcx>)>, ) -> QueryResult<'tcx> { let (ct, ty) = goal.predicate; - let nested_goals = self.infcx.eq(goal.param_env, ct.ty(), ty)?; + let nested_goals = self.eq(goal.param_env, ct.ty(), ty)?; self.evaluate_all_and_make_canonical_response(nested_goals) } } diff --git a/compiler/rustc_trait_selection/src/solve/project_goals.rs b/compiler/rustc_trait_selection/src/solve/project_goals.rs index 48153b465b7ec..9f83bfa1ccb9b 100644 --- a/compiler/rustc_trait_selection/src/solve/project_goals.rs +++ b/compiler/rustc_trait_selection/src/solve/project_goals.rs @@ -1,7 +1,6 @@ use crate::traits::{specialization_graph, translate_substs}; use super::assembly; -use super::infcx_ext::InferCtxtExt; use super::trait_goals::structural_traits; use super::{Certainty, EvalCtxt, Goal, QueryResult}; use rustc_errors::ErrorGuaranteed; @@ -13,12 +12,11 @@ use rustc_infer::traits::query::NoSolution; use rustc_infer::traits::specialization_graph::LeafDef; use rustc_infer::traits::Reveal; use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams}; +use rustc_middle::ty::ProjectionPredicate; use rustc_middle::ty::{self, Ty, TyCtxt}; -use rustc_middle::ty::{ir::TypeVisitor, ProjectionPredicate, TypeSuperVisitable}; use rustc_middle::ty::{ToPredicate, TypeVisitable}; use rustc_span::{sym, DUMMY_SP}; use std::iter; -use std::ops::ControlFlow; impl<'tcx> EvalCtxt<'_, 'tcx> { pub(super) fn compute_projection_goal( @@ -38,8 +36,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { } else { let predicate = goal.predicate; let unconstrained_rhs = match predicate.term.unpack() { - ty::TermKind::Ty(_) => self.infcx.next_ty_infer().into(), - ty::TermKind::Const(ct) => self.infcx.next_const_infer(ct.ty()).into(), + ty::TermKind::Ty(_) => self.next_ty_infer().into(), + ty::TermKind::Const(ct) => self.next_const_infer(ct.ty()).into(), }; let unconstrained_predicate = ty::Clause::Projection(ProjectionPredicate { projection_ty: goal.predicate.projection_ty, @@ -49,8 +47,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { this.evaluate_goal(goal.with(this.tcx(), unconstrained_predicate)) })?; - let nested_eq_goals = - self.infcx.eq(goal.param_env, unconstrained_rhs, predicate.term)?; + let nested_eq_goals = self.eq(goal.param_env, unconstrained_rhs, predicate.term)?; let eval_certainty = self.evaluate_all(nested_eq_goals)?; self.make_canonical_response(normalize_certainty.unify_and(eval_certainty)) } @@ -65,73 +62,6 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { result } - /// Is the projection predicate is of the form `exists ::Assoc = T`. - /// - /// This is the case if the `term` is an inference variable in the innermost universe - /// and does not occur in any other part of the predicate. - fn term_is_fully_unconstrained(&self, goal: Goal<'tcx, ProjectionPredicate<'tcx>>) -> bool { - let infcx = self.infcx; - let term_is_infer = match goal.predicate.term.unpack() { - ty::TermKind::Ty(ty) => { - if let &ty::Infer(ty::TyVar(vid)) = ty.kind() { - match infcx.probe_ty_var(vid) { - Ok(value) => bug!("resolved var in query: {goal:?} {value:?}"), - Err(universe) => universe == infcx.universe(), - } - } else { - false - } - } - ty::TermKind::Const(ct) => { - if let ty::ConstKind::Infer(ty::InferConst::Var(vid)) = ct.kind() { - match self.infcx.probe_const_var(vid) { - Ok(value) => bug!("resolved var in query: {goal:?} {value:?}"), - Err(universe) => universe == infcx.universe(), - } - } else { - false - } - } - }; - - // Guard against `>::Assoc = ?0>`. - struct ContainsTerm<'tcx> { - term: ty::Term<'tcx>, - } - impl<'tcx> TypeVisitor> for ContainsTerm<'tcx> { - type BreakTy = (); - fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { - if t.needs_infer() { - if ty::Term::from(t) == self.term { - ControlFlow::Break(()) - } else { - t.super_visit_with(self) - } - } else { - ControlFlow::Continue(()) - } - } - - fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow { - if c.needs_infer() { - if ty::Term::from(c) == self.term { - ControlFlow::Break(()) - } else { - c.super_visit_with(self) - } - } else { - ControlFlow::Continue(()) - } - } - } - - let mut visitor = ContainsTerm { term: goal.predicate.term }; - - term_is_infer - && goal.predicate.projection_ty.visit_with(&mut visitor).is_continue() - && goal.param_env.visit_with(&mut visitor).is_continue() - } - /// After normalizing the projection to `normalized_alias` with the given /// `normalization_certainty`, constrain the inference variable `term` to it /// and return a query response. @@ -145,7 +75,6 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { // // It can however be ambiguous when the `normalized_alias` contains a projection. let nested_goals = self - .infcx .eq(goal.param_env, goal.predicate.term, normalized_alias.into()) .expect("failed to unify with unconstrained term"); let rhs_certainty = @@ -177,10 +106,10 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> { if let Some(poly_projection_pred) = assumption.to_opt_poly_projection_pred() && poly_projection_pred.projection_def_id() == goal.predicate.def_id() { - ecx.infcx.probe(|_| { + ecx.probe(|ecx| { let assumption_projection_pred = - ecx.infcx.instantiate_binder_with_infer(poly_projection_pred); - let mut nested_goals = ecx.infcx.eq( + ecx.instantiate_binder_with_infer(poly_projection_pred); + let mut nested_goals = ecx.eq( goal.param_env, goal.predicate.projection_ty, assumption_projection_pred.projection_ty, @@ -215,11 +144,11 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> { return Err(NoSolution); } - ecx.infcx.probe(|_| { - let impl_substs = ecx.infcx.fresh_substs_for_item(DUMMY_SP, impl_def_id); + ecx.probe(|ecx| { + let impl_substs = ecx.fresh_substs_for_item(impl_def_id); let impl_trait_ref = impl_trait_ref.subst(tcx, impl_substs); - let mut nested_goals = ecx.infcx.eq(goal.param_env, goal_trait_ref, impl_trait_ref)?; + let mut nested_goals = ecx.eq(goal.param_env, goal_trait_ref, impl_trait_ref)?; let where_clause_bounds = tcx .predicates_of(impl_def_id) .instantiate(tcx, impl_substs) @@ -367,7 +296,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> { goal: Goal<'tcx, Self>, ) -> QueryResult<'tcx> { let tcx = ecx.tcx(); - ecx.infcx.probe(|_| { + ecx.probe(|ecx| { let metadata_ty = match goal.predicate.self_ty().kind() { ty::Bool | ty::Char @@ -546,8 +475,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> { goal: Goal<'tcx, Self>, ) -> QueryResult<'tcx> { let discriminant = goal.predicate.self_ty().discriminant_ty(ecx.tcx()); - ecx.infcx - .probe(|_| ecx.eq_term_and_make_canonical_response(goal, Certainty::Yes, discriminant)) + ecx.probe(|ecx| ecx.eq_term_and_make_canonical_response(goal, Certainty::Yes, discriminant)) } } diff --git a/compiler/rustc_trait_selection/src/solve/trait_goals.rs b/compiler/rustc_trait_selection/src/solve/trait_goals.rs index f2f25ef850a9a..6d1381bbf0c9f 100644 --- a/compiler/rustc_trait_selection/src/solve/trait_goals.rs +++ b/compiler/rustc_trait_selection/src/solve/trait_goals.rs @@ -3,11 +3,9 @@ use std::iter; use super::assembly; -use super::infcx_ext::InferCtxtExt; use super::{CanonicalResponse, Certainty, EvalCtxt, Goal, QueryResult}; use rustc_hir::def_id::DefId; use rustc_hir::LangItem; -use rustc_infer::infer::InferCtxt; use rustc_infer::traits::query::NoSolution; use rustc_infer::traits::util::supertraits; use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams}; @@ -45,12 +43,12 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { return Err(NoSolution); } - ecx.infcx.probe(|_| { - let impl_substs = ecx.infcx.fresh_substs_for_item(DUMMY_SP, impl_def_id); + ecx.probe(|ecx| { + let impl_substs = ecx.fresh_substs_for_item(impl_def_id); let impl_trait_ref = impl_trait_ref.subst(tcx, impl_substs); let mut nested_goals = - ecx.infcx.eq(goal.param_env, goal.predicate.trait_ref, impl_trait_ref)?; + ecx.eq(goal.param_env, goal.predicate.trait_ref, impl_trait_ref)?; let where_clause_bounds = tcx .predicates_of(impl_def_id) .instantiate(tcx, impl_substs) @@ -72,10 +70,10 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { && poly_trait_pred.def_id() == goal.predicate.def_id() { // FIXME: Constness and polarity - ecx.infcx.probe(|_| { + ecx.probe(|ecx| { let assumption_trait_pred = - ecx.infcx.instantiate_binder_with_infer(poly_trait_pred); - let mut nested_goals = ecx.infcx.eq( + ecx.instantiate_binder_with_infer(poly_trait_pred); + let mut nested_goals = ecx.eq( goal.param_env, goal.predicate.trait_ref, assumption_trait_pred.trait_ref, @@ -118,7 +116,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { ) -> QueryResult<'tcx> { let tcx = ecx.tcx(); - ecx.infcx.probe(|_| { + ecx.probe(|ecx| { let nested_obligations = tcx .predicates_of(goal.predicate.def_id()) .instantiate(tcx, goal.predicate.trait_ref.substs); @@ -275,7 +273,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { if b_ty.is_ty_var() { return ecx.make_canonical_response(Certainty::AMBIGUOUS); } - ecx.infcx.probe(|_| { + ecx.probe(|ecx| { match (a_ty.kind(), b_ty.kind()) { // Trait upcasting, or `dyn Trait + Auto + 'a` -> `dyn Trait + 'b` (&ty::Dynamic(_, _, ty::Dyn), &ty::Dynamic(_, _, ty::Dyn)) => { @@ -318,7 +316,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { // `[T; n]` -> `[T]` unsizing (&ty::Array(a_elem_ty, ..), &ty::Slice(b_elem_ty)) => { // We just require that the element type stays the same - let nested_goals = ecx.infcx.eq(goal.param_env, a_elem_ty, b_elem_ty)?; + let nested_goals = ecx.eq(goal.param_env, a_elem_ty, b_elem_ty)?; ecx.evaluate_all_and_make_canonical_response(nested_goals) } // Struct unsizing `Struct` -> `Struct` where `T: Unsize` @@ -352,7 +350,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { // Finally, we require that `TailA: Unsize` for the tail field // types. - let mut nested_goals = ecx.infcx.eq(goal.param_env, unsized_a_ty, b_ty)?; + let mut nested_goals = ecx.eq(goal.param_env, unsized_a_ty, b_ty)?; nested_goals.push(goal.with( tcx, ty::Binder::dummy( @@ -371,7 +369,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { // Substitute just the tail field of B., and require that they're equal. let unsized_a_ty = tcx.mk_tup(a_rest_tys.iter().chain([b_last_ty]).copied()); - let mut nested_goals = ecx.infcx.eq(goal.param_env, unsized_a_ty, b_ty)?; + let mut nested_goals = ecx.eq(goal.param_env, unsized_a_ty, b_ty)?; // Similar to ADTs, require that the rest of the fields are equal. nested_goals.push(goal.with( @@ -411,7 +409,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { } let mut unsize_dyn_to_principal = |principal: Option>| { - ecx.infcx.probe(|_| -> Result<_, NoSolution> { + ecx.probe(|ecx| -> Result<_, NoSolution> { // Require that all of the trait predicates from A match B, except for // the auto traits. We do this by constructing a new A type with B's // auto traits, and equating these types. @@ -431,7 +429,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { let new_a_ty = tcx.mk_dynamic(new_a_data, b_region, ty::Dyn); // We also require that A's lifetime outlives B's lifetime. - let mut nested_obligations = ecx.infcx.eq(goal.param_env, new_a_ty, b_ty)?; + let mut nested_obligations = ecx.eq(goal.param_env, new_a_ty, b_ty)?; nested_obligations.push( goal.with(tcx, ty::Binder::dummy(ty::OutlivesPredicate(a_region, b_region))), ); @@ -482,16 +480,16 @@ impl<'tcx> EvalCtxt<'_, 'tcx> { fn probe_and_evaluate_goal_for_constituent_tys( &mut self, goal: Goal<'tcx, TraitPredicate<'tcx>>, - constituent_tys: impl Fn(&InferCtxt<'tcx>, Ty<'tcx>) -> Result>, NoSolution>, + constituent_tys: impl Fn(&EvalCtxt<'_, 'tcx>, Ty<'tcx>) -> Result>, NoSolution>, ) -> QueryResult<'tcx> { - self.infcx.probe(|_| { - self.evaluate_all_and_make_canonical_response( - constituent_tys(self.infcx, goal.predicate.self_ty())? + self.probe(|this| { + this.evaluate_all_and_make_canonical_response( + constituent_tys(this, goal.predicate.self_ty())? .into_iter() .map(|ty| { goal.with( - self.tcx(), - ty::Binder::dummy(goal.predicate.with_self_ty(self.tcx(), ty)), + this.tcx(), + ty::Binder::dummy(goal.predicate.with_self_ty(this.tcx(), ty)), ) }) .collect(), diff --git a/compiler/rustc_trait_selection/src/solve/trait_goals/structural_traits.rs b/compiler/rustc_trait_selection/src/solve/trait_goals/structural_traits.rs index 3662463178f85..2c13465d347c4 100644 --- a/compiler/rustc_trait_selection/src/solve/trait_goals/structural_traits.rs +++ b/compiler/rustc_trait_selection/src/solve/trait_goals/structural_traits.rs @@ -1,16 +1,18 @@ use rustc_hir::{Movability, Mutability}; -use rustc_infer::{infer::InferCtxt, traits::query::NoSolution}; +use rustc_infer::traits::query::NoSolution; use rustc_middle::ty::{self, Ty, TyCtxt}; +use crate::solve::EvalCtxt; + // Calculates the constituent types of a type for `auto trait` purposes. // // For types with an "existential" binder, i.e. generator witnesses, we also // instantiate the binder with placeholders eagerly. pub(super) fn instantiate_constituent_tys_for_auto_trait<'tcx>( - infcx: &InferCtxt<'tcx>, + ecx: &EvalCtxt<'_, 'tcx>, ty: Ty<'tcx>, ) -> Result>, NoSolution> { - let tcx = infcx.tcx; + let tcx = ecx.tcx(); match *ty.kind() { ty::Uint(_) | ty::Int(_) @@ -53,9 +55,7 @@ pub(super) fn instantiate_constituent_tys_for_auto_trait<'tcx>( Ok(vec![generator_substs.tupled_upvars_ty(), generator_substs.witness()]) } - ty::GeneratorWitness(types) => { - Ok(infcx.instantiate_binder_with_placeholders(types).to_vec()) - } + ty::GeneratorWitness(types) => Ok(ecx.instantiate_binder_with_placeholders(types).to_vec()), ty::GeneratorWitnessMIR(..) => todo!(), @@ -74,7 +74,7 @@ pub(super) fn instantiate_constituent_tys_for_auto_trait<'tcx>( } pub(super) fn instantiate_constituent_tys_for_sized_trait<'tcx>( - infcx: &InferCtxt<'tcx>, + ecx: &EvalCtxt<'_, 'tcx>, ty: Ty<'tcx>, ) -> Result>, NoSolution> { match *ty.kind() { @@ -113,18 +113,18 @@ pub(super) fn instantiate_constituent_tys_for_sized_trait<'tcx>( ty::Tuple(tys) => Ok(tys.to_vec()), ty::Adt(def, substs) => { - let sized_crit = def.sized_constraint(infcx.tcx); + let sized_crit = def.sized_constraint(ecx.tcx()); Ok(sized_crit .0 .iter() - .map(|ty| sized_crit.rebind(*ty).subst(infcx.tcx, substs)) + .map(|ty| sized_crit.rebind(*ty).subst(ecx.tcx(), substs)) .collect()) } } } pub(super) fn instantiate_constituent_tys_for_copy_clone_trait<'tcx>( - infcx: &InferCtxt<'tcx>, + ecx: &EvalCtxt<'_, 'tcx>, ty: Ty<'tcx>, ) -> Result>, NoSolution> { match *ty.kind() { @@ -165,7 +165,7 @@ pub(super) fn instantiate_constituent_tys_for_copy_clone_trait<'tcx>( ty::Closure(_, substs) => Ok(vec![substs.as_closure().tupled_upvars_ty()]), ty::Generator(_, substs, Movability::Movable) => { - if infcx.tcx.features().generator_clone { + if ecx.tcx().features().generator_clone { let generator = substs.as_generator(); Ok(vec![generator.tupled_upvars_ty(), generator.witness()]) } else { @@ -173,9 +173,7 @@ pub(super) fn instantiate_constituent_tys_for_copy_clone_trait<'tcx>( } } - ty::GeneratorWitness(types) => { - Ok(infcx.instantiate_binder_with_placeholders(types).to_vec()) - } + ty::GeneratorWitness(types) => Ok(ecx.instantiate_binder_with_placeholders(types).to_vec()), ty::GeneratorWitnessMIR(..) => todo!(), } diff --git a/library/std/src/sys/unix/fd.rs b/library/std/src/sys/unix/fd.rs index ab57fba6c9f27..66c33d58d6ca3 100644 --- a/library/std/src/sys/unix/fd.rs +++ b/library/std/src/sys/unix/fd.rs @@ -197,11 +197,6 @@ impl FileDesc { } } - #[cfg(target_os = "linux")] - pub fn get_cloexec(&self) -> io::Result { - unsafe { Ok((cvt(libc::fcntl(self.as_raw_fd(), libc::F_GETFD))? & libc::FD_CLOEXEC) != 0) } - } - #[cfg(not(any( target_env = "newlib", target_os = "solaris", diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 0c70d31ed607e..5541136ef490d 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2114,17 +2114,29 @@ fn get_all_import_attributes<'hir>( attributes: &mut Vec, is_inline: bool, ) { + let mut first = true; let hir_map = tcx.hir(); let mut visitor = OneLevelVisitor::new(hir_map, target_def_id); let mut visited = FxHashSet::default(); + // If the item is an import and has at least a path with two parts, we go into it. while let hir::ItemKind::Use(path, _) = item.kind && visited.insert(item.hir_id()) { - // We add the attributes from this import into the list. - add_without_unwanted_attributes(attributes, hir_map.attrs(item.hir_id()), is_inline); + if first { + // This is the "original" reexport so we get all its attributes without filtering them. + attributes.extend_from_slice(hir_map.attrs(item.hir_id())); + first = false; + } else { + add_without_unwanted_attributes(attributes, hir_map.attrs(item.hir_id()), is_inline); + } - let def_id = if path.segments.len() > 1 { - match path.segments[path.segments.len() - 2].res { + let def_id = if let [.., parent_segment, _] = &path.segments { + match parent_segment.res { hir::def::Res::Def(_, def_id) => def_id, + _ if parent_segment.ident.name == kw::Crate => { + // In case the "parent" is the crate, it'll give `Res::Err` so we need to + // circumvent it this way. + tcx.parent(item.owner_id.def_id.to_def_id()) + } _ => break, } } else { @@ -2341,9 +2353,7 @@ fn clean_maybe_renamed_item<'tcx>( if let Some(import_id) = import_id && let Some(hir::Node::Item(use_node)) = cx.tcx.hir().find_by_def_id(import_id) { - // First, we add the attributes from the current import. - extra_attrs.extend_from_slice(inline::load_attrs(cx, import_id.to_def_id())); - let is_inline = extra_attrs.lists(sym::doc).get_word_attr(sym::inline).is_some(); + let is_inline = inline::load_attrs(cx, import_id.to_def_id()).lists(sym::doc).get_word_attr(sym::inline).is_some(); // Then we get all the various imports' attributes. get_all_import_attributes(use_node, cx.tcx, item.owner_id.def_id, &mut extra_attrs, is_inline); add_without_unwanted_attributes(&mut extra_attrs, inline::load_attrs(cx, def_id), is_inline); diff --git a/tests/rustdoc/issue-108281.rs b/tests/rustdoc/issue-108281.rs new file mode 100644 index 0000000000000..8e1b6ba88a692 --- /dev/null +++ b/tests/rustdoc/issue-108281.rs @@ -0,0 +1,25 @@ +// Regression test for . +// It ensures that the attributes on the first reexport are not duplicated. + +#![crate_name = "foo"] + +// @has 'foo/index.html' + +#[doc(hidden)] +pub fn bar() {} +mod sub { + pub fn public() {} +} + +// @matches - '//*[@class="desc docblock-short"]' '^Displayed$' +/// Displayed +#[doc(inline)] +pub use crate::bar as Bar; +// @matches - '//*[@class="desc docblock-short"]' '^Hello\sDisplayed$' +#[doc(inline)] +/// Hello +pub use crate::Bar as Bar2; + +// @matches - '//*[@class="desc docblock-short"]' '^Public$' +/// Public +pub use crate::sub::public as Public; diff --git a/tests/ui/alloc-error/alloc-error-handler-bad-signature-3.stderr b/tests/ui/alloc-error/alloc-error-handler-bad-signature-3.stderr index d1b9d7a40b47b..eb739b149a103 100644 --- a/tests/ui/alloc-error/alloc-error-handler-bad-signature-3.stderr +++ b/tests/ui/alloc-error/alloc-error-handler-bad-signature-3.stderr @@ -7,10 +7,7 @@ LL | fn oom() -> ! { | _-^^^^^^^^^^^^ LL | | loop {} LL | | } - | | - - | | | - | |_unexpected argument of type `core::alloc::Layout` - | help: remove the extra argument + | |_- unexpected argument of type `core::alloc::Layout` | note: function defined here --> $DIR/alloc-error-handler-bad-signature-3.rs:10:4 diff --git a/tests/ui/argument-suggestions/extra_arguments.rs b/tests/ui/argument-suggestions/extra_arguments.rs index 3f83de95e2d54..1442062326d19 100644 --- a/tests/ui/argument-suggestions/extra_arguments.rs +++ b/tests/ui/argument-suggestions/extra_arguments.rs @@ -3,8 +3,15 @@ fn one_arg(_a: i32) {} fn two_arg_same(_a: i32, _b: i32) {} fn two_arg_diff(_a: i32, _b: &str) {} +macro_rules! foo { + ($x:expr) => { + empty($x, 1); //~ ERROR function takes + } +} + fn main() { empty(""); //~ ERROR function takes + empty(1, 1); //~ ERROR function takes one_arg(1, 1); //~ ERROR function takes one_arg(1, ""); //~ ERROR function takes @@ -32,4 +39,5 @@ fn main() { 1, "" ); + foo!(1); } diff --git a/tests/ui/argument-suggestions/extra_arguments.stderr b/tests/ui/argument-suggestions/extra_arguments.stderr index 0911685b4280a..11c7109974355 100644 --- a/tests/ui/argument-suggestions/extra_arguments.stderr +++ b/tests/ui/argument-suggestions/extra_arguments.stderr @@ -1,5 +1,5 @@ error[E0061]: this function takes 0 arguments but 1 argument was supplied - --> $DIR/extra_arguments.rs:7:3 + --> $DIR/extra_arguments.rs:13:3 | LL | empty(""); | ^^^^^ -- @@ -13,8 +13,27 @@ note: function defined here LL | fn empty() {} | ^^^^^ +error[E0061]: this function takes 0 arguments but 2 arguments were supplied + --> $DIR/extra_arguments.rs:14:3 + | +LL | empty(1, 1); + | ^^^^^ - - unexpected argument of type `{integer}` + | | + | unexpected argument of type `{integer}` + | +note: function defined here + --> $DIR/extra_arguments.rs:1:4 + | +LL | fn empty() {} + | ^^^^^ +help: remove the extra arguments + | +LL - empty(1, 1); +LL + empty(); + | + error[E0061]: this function takes 1 argument but 2 arguments were supplied - --> $DIR/extra_arguments.rs:9:3 + --> $DIR/extra_arguments.rs:16:3 | LL | one_arg(1, 1); | ^^^^^^^ --- @@ -29,7 +48,7 @@ LL | fn one_arg(_a: i32) {} | ^^^^^^^ ------- error[E0061]: this function takes 1 argument but 2 arguments were supplied - --> $DIR/extra_arguments.rs:10:3 + --> $DIR/extra_arguments.rs:17:3 | LL | one_arg(1, ""); | ^^^^^^^ ---- @@ -44,7 +63,7 @@ LL | fn one_arg(_a: i32) {} | ^^^^^^^ ------- error[E0061]: this function takes 1 argument but 3 arguments were supplied - --> $DIR/extra_arguments.rs:11:3 + --> $DIR/extra_arguments.rs:18:3 | LL | one_arg(1, "", 1.0); | ^^^^^^^ -- --- unexpected argument of type `{float}` @@ -63,7 +82,7 @@ LL + one_arg(1); | error[E0061]: this function takes 2 arguments but 3 arguments were supplied - --> $DIR/extra_arguments.rs:13:3 + --> $DIR/extra_arguments.rs:20:3 | LL | two_arg_same(1, 1, 1); | ^^^^^^^^^^^^ --- @@ -78,7 +97,7 @@ LL | fn two_arg_same(_a: i32, _b: i32) {} | ^^^^^^^^^^^^ ------- ------- error[E0061]: this function takes 2 arguments but 3 arguments were supplied - --> $DIR/extra_arguments.rs:14:3 + --> $DIR/extra_arguments.rs:21:3 | LL | two_arg_same(1, 1, 1.0); | ^^^^^^^^^^^^ ----- @@ -93,7 +112,7 @@ LL | fn two_arg_same(_a: i32, _b: i32) {} | ^^^^^^^^^^^^ ------- ------- error[E0061]: this function takes 2 arguments but 3 arguments were supplied - --> $DIR/extra_arguments.rs:16:3 + --> $DIR/extra_arguments.rs:23:3 | LL | two_arg_diff(1, 1, ""); | ^^^^^^^^^^^^ --- @@ -108,7 +127,7 @@ LL | fn two_arg_diff(_a: i32, _b: &str) {} | ^^^^^^^^^^^^ ------- -------- error[E0061]: this function takes 2 arguments but 3 arguments were supplied - --> $DIR/extra_arguments.rs:17:3 + --> $DIR/extra_arguments.rs:24:3 | LL | two_arg_diff(1, "", ""); | ^^^^^^^^^^^^ ---- @@ -123,7 +142,7 @@ LL | fn two_arg_diff(_a: i32, _b: &str) {} | ^^^^^^^^^^^^ ------- -------- error[E0061]: this function takes 2 arguments but 4 arguments were supplied - --> $DIR/extra_arguments.rs:18:3 + --> $DIR/extra_arguments.rs:25:3 | LL | two_arg_diff(1, 1, "", ""); | ^^^^^^^^^^^^ - -- unexpected argument of type `&'static str` @@ -142,7 +161,7 @@ LL + two_arg_diff(1, ""); | error[E0061]: this function takes 2 arguments but 4 arguments were supplied - --> $DIR/extra_arguments.rs:19:3 + --> $DIR/extra_arguments.rs:26:3 | LL | two_arg_diff(1, "", 1, ""); | ^^^^^^^^^^^^ - -- unexpected argument of type `&'static str` @@ -161,7 +180,7 @@ LL + two_arg_diff(1, ""); | error[E0061]: this function takes 2 arguments but 3 arguments were supplied - --> $DIR/extra_arguments.rs:22:3 + --> $DIR/extra_arguments.rs:29:3 | LL | two_arg_same(1, 1, ""); | ^^^^^^^^^^^^ -------- @@ -176,7 +195,7 @@ LL | fn two_arg_same(_a: i32, _b: i32) {} | ^^^^^^^^^^^^ ------- ------- error[E0061]: this function takes 2 arguments but 3 arguments were supplied - --> $DIR/extra_arguments.rs:23:3 + --> $DIR/extra_arguments.rs:30:3 | LL | two_arg_diff(1, 1, ""); | ^^^^^^^^^^^^ --- @@ -191,7 +210,7 @@ LL | fn two_arg_diff(_a: i32, _b: &str) {} | ^^^^^^^^^^^^ ------- -------- error[E0061]: this function takes 2 arguments but 3 arguments were supplied - --> $DIR/extra_arguments.rs:24:3 + --> $DIR/extra_arguments.rs:31:3 | LL | two_arg_same( | ^^^^^^^^^^^^ @@ -211,7 +230,7 @@ LL | fn two_arg_same(_a: i32, _b: i32) {} | ^^^^^^^^^^^^ ------- ------- error[E0061]: this function takes 2 arguments but 3 arguments were supplied - --> $DIR/extra_arguments.rs:30:3 + --> $DIR/extra_arguments.rs:37:3 | LL | two_arg_diff( | ^^^^^^^^^^^^ @@ -229,6 +248,26 @@ note: function defined here LL | fn two_arg_diff(_a: i32, _b: &str) {} | ^^^^^^^^^^^^ ------- -------- -error: aborting due to 14 previous errors +error[E0061]: this function takes 0 arguments but 2 arguments were supplied + --> $DIR/extra_arguments.rs:8:9 + | +LL | empty($x, 1); + | ^^^^^ - unexpected argument of type `{integer}` +... +LL | foo!(1); + | ------- + | | | + | | unexpected argument of type `{integer}` + | | help: remove the extra argument + | in this macro invocation + | +note: function defined here + --> $DIR/extra_arguments.rs:1:4 + | +LL | fn empty() {} + | ^^^^^ + = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to 16 previous errors For more information about this error, try `rustc --explain E0061`. diff --git a/tests/ui/attributes/invalid_macro_export_argument.rs b/tests/ui/attributes/invalid_macro_export_argument.rs new file mode 100644 index 0000000000000..85d009f11a6f3 --- /dev/null +++ b/tests/ui/attributes/invalid_macro_export_argument.rs @@ -0,0 +1,26 @@ +// check-pass +#[macro_export(hello, world)] //~ WARN `#[macro_export]` can only take 1 or 0 arguments +macro_rules! a { + () => () +} + +#[macro_export(not_local_inner_macros)] //~ WARN `not_local_inner_macros` isn't a valid `#[macro_export]` argument +macro_rules! b { + () => () +} + +#[macro_export] +macro_rules! c { + () => () +} +#[macro_export(local_inner_macros)] +macro_rules! d { + () => () +} + +#[macro_export()] +macro_rules! e { + () => () +} + +fn main() {} diff --git a/tests/ui/attributes/invalid_macro_export_argument.stderr b/tests/ui/attributes/invalid_macro_export_argument.stderr new file mode 100644 index 0000000000000..a4e17642c2aac --- /dev/null +++ b/tests/ui/attributes/invalid_macro_export_argument.stderr @@ -0,0 +1,16 @@ +warning: `#[macro_export]` can only take 1 or 0 arguments + --> $DIR/invalid_macro_export_argument.rs:2:1 + | +LL | #[macro_export(hello, world)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = note: `#[warn(invalid_macro_export_arguments)]` on by default + +warning: `not_local_inner_macros` isn't a valid `#[macro_export]` argument + --> $DIR/invalid_macro_export_argument.rs:7:16 + | +LL | #[macro_export(not_local_inner_macros)] + | ^^^^^^^^^^^^^^^^^^^^^^ + +warning: 2 warnings emitted + diff --git a/tests/ui/infinite/auxiliary/alias.rs b/tests/ui/infinite/auxiliary/alias.rs new file mode 100644 index 0000000000000..59add7eb18bdb --- /dev/null +++ b/tests/ui/infinite/auxiliary/alias.rs @@ -0,0 +1,2 @@ +pub struct W(T); +pub type Wrapper = W; diff --git a/tests/ui/infinite/infinite-alias.rs b/tests/ui/infinite/infinite-alias.rs new file mode 100644 index 0000000000000..45356f359cede --- /dev/null +++ b/tests/ui/infinite/infinite-alias.rs @@ -0,0 +1,9 @@ +// aux-build: alias.rs +// regression test for 108160 + +extern crate alias; + +use alias::Wrapper; +struct Rec(Wrapper); //~ ERROR recursive type `Rec` has infinite + +fn main() {} diff --git a/tests/ui/infinite/infinite-alias.stderr b/tests/ui/infinite/infinite-alias.stderr new file mode 100644 index 0000000000000..9d9265f8c367c --- /dev/null +++ b/tests/ui/infinite/infinite-alias.stderr @@ -0,0 +1,14 @@ +error[E0072]: recursive type `Rec` has infinite size + --> $DIR/infinite-alias.rs:7:1 + | +LL | struct Rec(Wrapper); + | ^^^^^^^^^^ ------------ recursive without indirection + | +help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle + | +LL | struct Rec(Box>); + | ++++ + + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0072`. diff --git a/tests/ui/issues/issue-26094.rs b/tests/ui/issues/issue-26094.rs index abf3543ddb9f8..2742529edd3b3 100644 --- a/tests/ui/issues/issue-26094.rs +++ b/tests/ui/issues/issue-26094.rs @@ -1,7 +1,7 @@ macro_rules! some_macro { - ($other: expr) => ({ + ($other: expr) => {{ $other(None) //~ NOTE unexpected argument of type `Option<_>` - }) + }}; } fn some_function() {} //~ NOTE defined here @@ -9,5 +9,4 @@ fn some_function() {} //~ NOTE defined here fn main() { some_macro!(some_function); //~^ ERROR function takes 0 arguments but 1 argument was supplied - //~| NOTE in this expansion of some_macro! } diff --git a/tests/ui/issues/issue-26094.stderr b/tests/ui/issues/issue-26094.stderr index 608d2c7aff93f..ecdf48470f730 100644 --- a/tests/ui/issues/issue-26094.stderr +++ b/tests/ui/issues/issue-26094.stderr @@ -2,10 +2,7 @@ error[E0061]: this function takes 0 arguments but 1 argument was supplied --> $DIR/issue-26094.rs:10:17 | LL | $other(None) - | ---- - | | - | unexpected argument of type `Option<_>` - | help: remove the extra argument + | ---- unexpected argument of type `Option<_>` ... LL | some_macro!(some_function); | ^^^^^^^^^^^^^ diff --git a/tests/ui/regions/resolve-re-error-ice.rs b/tests/ui/regions/resolve-re-error-ice.rs new file mode 100644 index 0000000000000..f37b27a82b363 --- /dev/null +++ b/tests/ui/regions/resolve-re-error-ice.rs @@ -0,0 +1,22 @@ +// check-pass + +// Allow this for now, can remove this UI test when this becomes a hard error. +#![allow(implied_bounds_entailment)] + +use std::collections::hash_map::{Keys, HashMap}; +use std::marker::PhantomData; + +trait MapAssertion<'a, K, V, R> { + fn key_set(&self) -> Subject, (), R>; +} + +struct Subject<'a, T, V, R>(PhantomData<(&'a T, V, R)>); + +impl<'a, K, V, R> MapAssertion<'a, K, V, R> for Subject<'a, HashMap, (), R> +{ + fn key_set(&self) -> Subject<'a, Keys, (), R> { + todo!() + } +} + +fn main() {} diff --git a/tests/ui/regions/resolve-re-error-ice.stderr b/tests/ui/regions/resolve-re-error-ice.stderr new file mode 100644 index 0000000000000..e7003e1c32f64 --- /dev/null +++ b/tests/ui/regions/resolve-re-error-ice.stderr @@ -0,0 +1,15 @@ +Future incompatibility report: Future breakage diagnostic: +warning: impl method assumes more implied bounds than the corresponding trait method + --> $DIR/resolve-re-error-ice.rs:17:16 + | +LL | fn key_set(&self) -> Subject<'a, Keys, (), R> { + | ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace this type to make the impl signature compatible: `Subject<'_, std::collections::hash_map::Keys<'_, K, V>, (), R>` + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #105572 +note: the lint level is defined here + --> $DIR/resolve-re-error-ice.rs:4:10 + | +LL | #![allow(implied_bounds_entailment)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ +