From b8e0e797e701f60bd975b3f8a295e1cb1a1de58c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 1 Sep 2023 17:04:44 +0200 Subject: bootstrap/format: remove unnecessary paths.push --- src/bootstrap/format.rs | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src') diff --git a/src/bootstrap/format.rs b/src/bootstrap/format.rs index d658be0b8eb..11f2762f766 100644 --- a/src/bootstrap/format.rs +++ b/src/bootstrap/format.rs @@ -127,8 +127,6 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) { Err(_) => false, }; - let mut paths = paths.to_vec(); - if git_available { let in_working_tree = match build .config @@ -201,8 +199,6 @@ pub fn format(build: &Builder<'_>, check: bool, paths: &[PathBuf]) { "WARN: Something went wrong when running git commands:\n{err}\n\ Falling back to formatting all files." ); - // Something went wrong when getting the version. Just format all the files. - paths.push(".".into()); } } } -- cgit 1.4.1-3-g733a5 From ce3b0442983e3689464f512b93b0c6bf020e7c36 Mon Sep 17 00:00:00 2001 From: Alex Macleod Date: Sun, 10 Sep 2023 18:17:47 +0000 Subject: Call `LateLintPass::check_attribute` from `with_lint_attrs` --- compiler/rustc_lint/src/late.rs | 25 +++++++++++----------- src/tools/clippy/tests/ui/allow_attributes.fixed | 7 ++++++ src/tools/clippy/tests/ui/allow_attributes.rs | 7 ++++++ .../ui/blanket_clippy_restriction_lints.stderr | 14 ++++++------ 4 files changed, 33 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/compiler/rustc_lint/src/late.rs b/compiler/rustc_lint/src/late.rs index 73af51d9e90..b24186ae1aa 100644 --- a/compiler/rustc_lint/src/late.rs +++ b/compiler/rustc_lint/src/late.rs @@ -21,7 +21,6 @@ use rustc_data_structures::sync::join; use rustc_hir as hir; use rustc_hir::def_id::{LocalDefId, LocalModDefId}; use rustc_hir::intravisit as hir_visit; -use rustc_hir::intravisit::Visitor; use rustc_middle::hir::nested_filter; use rustc_middle::ty::{self, TyCtxt}; use rustc_session::lint::LintPass; @@ -61,6 +60,9 @@ impl<'tcx, T: LateLintPass<'tcx>> LateContextAndPass<'tcx, T> { self.context.last_node_with_lint_attrs = id; debug!("late context: enter_attrs({:?})", attrs); lint_callback!(self, enter_lint_attrs, attrs); + for attr in attrs { + lint_callback!(self, check_attribute, attr); + } f(self); debug!("late context: exit_attrs({:?})", attrs); lint_callback!(self, exit_lint_attrs, attrs); @@ -377,20 +379,18 @@ fn late_lint_mod_inner<'tcx, T: LateLintPass<'tcx>>( let (module, _span, hir_id) = tcx.hir().get_module(module_def_id); - // There is no module lint that will have the crate itself as an item, so check it here. - if hir_id == hir::CRATE_HIR_ID { - lint_callback!(cx, check_crate,); - } + cx.with_lint_attrs(hir_id, |cx| { + // There is no module lint that will have the crate itself as an item, so check it here. + if hir_id == hir::CRATE_HIR_ID { + lint_callback!(cx, check_crate,); + } - cx.process_mod(module, hir_id); + cx.process_mod(module, hir_id); - // Visit the crate attributes - if hir_id == hir::CRATE_HIR_ID { - for attr in tcx.hir().attrs(hir::CRATE_HIR_ID).iter() { - cx.visit_attribute(attr) + if hir_id == hir::CRATE_HIR_ID { + lint_callback!(cx, check_crate_post,); } - lint_callback!(cx, check_crate_post,); - } + }); } fn late_lint_crate<'tcx>(tcx: TyCtxt<'tcx>) { @@ -431,7 +431,6 @@ fn late_lint_crate_inner<'tcx, T: LateLintPass<'tcx>>( // item), warn for it here. lint_callback!(cx, check_crate,); tcx.hir().walk_toplevel_module(cx); - tcx.hir().walk_attributes(cx); lint_callback!(cx, check_crate_post,); }) } diff --git a/src/tools/clippy/tests/ui/allow_attributes.fixed b/src/tools/clippy/tests/ui/allow_attributes.fixed index 945ba83611c..b506a9890f5 100644 --- a/src/tools/clippy/tests/ui/allow_attributes.fixed +++ b/src/tools/clippy/tests/ui/allow_attributes.fixed @@ -22,6 +22,13 @@ struct T4; #[cfg_attr(panic = "unwind", expect(dead_code))] struct CfgT; +#[allow(clippy::allow_attributes, unused)] +struct Allowed; + +#[expect(clippy::allow_attributes)] +#[allow(unused)] +struct Expected; + fn ignore_external() { external! { #[allow(clippy::needless_borrow)] // Should not lint diff --git a/src/tools/clippy/tests/ui/allow_attributes.rs b/src/tools/clippy/tests/ui/allow_attributes.rs index 8afa61c7002..c7daa7abd9d 100644 --- a/src/tools/clippy/tests/ui/allow_attributes.rs +++ b/src/tools/clippy/tests/ui/allow_attributes.rs @@ -22,6 +22,13 @@ struct T4; #[cfg_attr(panic = "unwind", allow(dead_code))] struct CfgT; +#[allow(clippy::allow_attributes, unused)] +struct Allowed; + +#[expect(clippy::allow_attributes)] +#[allow(unused)] +struct Expected; + fn ignore_external() { external! { #[allow(clippy::needless_borrow)] // Should not lint diff --git a/src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.stderr b/src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.stderr index d04ea7151c2..afb634f34b4 100644 --- a/src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.stderr +++ b/src/tools/clippy/tests/ui/blanket_clippy_restriction_lints.stderr @@ -1,10 +1,3 @@ -error: `clippy::restriction` is not meant to be enabled as a group - | - = note: because of the command line `--warn clippy::restriction` - = help: enable the restriction lints you need individually - = note: `-D clippy::blanket-clippy-restriction-lints` implied by `-D warnings` - = help: to override `-D warnings` add `#[allow(clippy::blanket_clippy_restriction_lints)]` - error: `clippy::restriction` is not meant to be enabled as a group --> $DIR/blanket_clippy_restriction_lints.rs:6:9 | @@ -12,6 +5,8 @@ LL | #![warn(clippy::restriction)] | ^^^^^^^^^^^^^^^^^^^ | = help: enable the restriction lints you need individually + = note: `-D clippy::blanket-clippy-restriction-lints` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(clippy::blanket_clippy_restriction_lints)]` error: `clippy::restriction` is not meant to be enabled as a group --> $DIR/blanket_clippy_restriction_lints.rs:8:9 @@ -29,5 +24,10 @@ LL | #![forbid(clippy::restriction)] | = help: enable the restriction lints you need individually +error: `clippy::restriction` is not meant to be enabled as a group + | + = note: because of the command line `--warn clippy::restriction` + = help: enable the restriction lints you need individually + error: aborting due to 4 previous errors -- cgit 1.4.1-3-g733a5 From 7468af8d66f6f6bb774b70d34536c86a7372a541 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 11 Sep 2023 14:17:20 +0200 Subject: Add missing "Aliased type" title in the sidebar --- src/librustdoc/html/render/sidebar.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/librustdoc/html/render/sidebar.rs b/src/librustdoc/html/render/sidebar.rs index 6466ae825d7..76f63c6f63e 100644 --- a/src/librustdoc/html/render/sidebar.rs +++ b/src/librustdoc/html/render/sidebar.rs @@ -237,6 +237,7 @@ fn sidebar_type_alias<'a>( ) -> Vec> { let mut items = vec![]; if let Some(inner_type) = &t.inner_type { + items.push(LinkBlock::forced(Link::new("aliased-type", "Aliased type"))); match inner_type { clean::TypeAliasInnerType::Enum { variants, is_non_exhaustive: _ } => { let mut variants = variants -- cgit 1.4.1-3-g733a5 From c523701c2dca7668a7023da02e056c9541754a4a Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 11 Sep 2023 14:20:15 +0200 Subject: Add missing ID into the ID map --- src/librustdoc/html/markdown.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index a8d85fb6fb4..b28019e3f91 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -1609,6 +1609,7 @@ fn init_id_map() -> FxHashMap, usize> { map.insert("blanket-implementations-list".into(), 1); map.insert("deref-methods".into(), 1); map.insert("layout".into(), 1); + map.insert("aliased-type".into(), 1); map } -- cgit 1.4.1-3-g733a5 From 9654d5ceaf3c0e916bcc99c2865d374595becc54 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Mon, 11 Sep 2023 13:18:36 +0000 Subject: add `is_host_effect` to `GenericParamDefKind::Const` and address review --- compiler/rustc_hir_analysis/src/astconv/mod.rs | 2 +- compiler/rustc_hir_analysis/src/check/wfcheck.rs | 2 +- compiler/rustc_hir_analysis/src/collect/generics_of.rs | 5 ++++- compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs | 11 +++++++---- compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs | 11 +++++++---- compiler/rustc_infer/src/infer/combine.rs | 8 ++++---- compiler/rustc_infer/src/infer/mod.rs | 7 +++---- compiler/rustc_metadata/src/rmeta/encoder.rs | 4 ++-- compiler/rustc_middle/src/infer/canonical.rs | 1 - compiler/rustc_middle/src/ty/generics.rs | 6 +++--- compiler/rustc_privacy/src/lib.rs | 2 +- compiler/rustc_smir/src/rustc_smir/mod.rs | 2 +- src/librustdoc/clean/mod.rs | 2 +- 13 files changed, 35 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 90f64e18632..acfd8dcb112 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -523,7 +523,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { Ty::new_misc_error(tcx).into() } } - GenericParamDefKind::Const { has_default } => { + GenericParamDefKind::Const { has_default, .. } => { let ty = tcx .at(self.span) .type_of(param.def_id) diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index f5beefc47f3..b97e0a80fe6 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1255,7 +1255,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id let is_our_default = |def: &ty::GenericParamDef| match def.kind { GenericParamDefKind::Type { has_default, .. } - | GenericParamDefKind::Const { has_default } => { + | GenericParamDefKind::Const { has_default, .. } => { has_default && def.index >= generics.parent_count as u32 } GenericParamDefKind::Lifetime => unreachable!(), diff --git a/compiler/rustc_hir_analysis/src/collect/generics_of.rs b/compiler/rustc_hir_analysis/src/collect/generics_of.rs index 4842008279a..3d60c57b9d5 100644 --- a/compiler/rustc_hir_analysis/src/collect/generics_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/generics_of.rs @@ -328,7 +328,10 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics { name: param.name.ident().name, def_id: param.def_id.to_def_id(), pure_wrt_drop: param.pure_wrt_drop, - kind: ty::GenericParamDefKind::Const { has_default: default.is_some() }, + kind: ty::GenericParamDefKind::Const { + has_default: default.is_some(), + is_host_effect: is_host_param, + }, }) } })); diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 694f3f67bab..c94cfde0670 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -1295,10 +1295,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { (GenericParamDefKind::Type { .. }, GenericArg::Infer(inf)) => { self.fcx.ty_infer(Some(param), inf.span).into() } - (&GenericParamDefKind::Const { has_default }, GenericArg::Infer(inf)) => { + ( + &GenericParamDefKind::Const { has_default, is_host_effect }, + GenericArg::Infer(inf), + ) => { let tcx = self.fcx.tcx(); - if has_default && tcx.has_attr(param.def_id, sym::rustc_host) { + if has_default && is_host_effect { self.fcx.var_for_effect(param) } else { self.fcx @@ -1341,7 +1344,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.fcx.var_for_def(self.span, param) } } - GenericParamDefKind::Const { has_default } => { + GenericParamDefKind::Const { has_default, is_host_effect } => { if has_default { // N.B. this is a bit of a hack. `infer_args` is passed depending on // whether the user has provided generic args. E.g. for `Vec::new` @@ -1352,7 +1355,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // it before falling back to default, such that a `const fn` such as // `needs_drop::<()>` can still be called in const contexts. (if we defaulted // instead of inferred, typeck would error) - if tcx.has_attr(param.def_id, sym::rustc_host) { + if is_host_effect { return self.fcx.var_for_effect(param); } else if !infer_args { return tcx diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs index 6f0d8ca774f..4237b4488ca 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs @@ -20,7 +20,7 @@ use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKin use rustc_middle::ty::{self, Const, Ty, TyCtxt, TypeVisitableExt}; use rustc_session::Session; use rustc_span::symbol::Ident; -use rustc_span::{self, sym, Span, DUMMY_SP}; +use rustc_span::{self, Span, DUMMY_SP}; use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode, ObligationCtxt}; use std::cell::{Cell, RefCell}; @@ -268,9 +268,12 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> { ) -> Const<'tcx> { // FIXME ideally this shouldn't use unwrap match param { - Some(param) if self.tcx.has_attr(param.def_id, sym::rustc_host) => { - self.var_for_effect(param).as_const().unwrap() - } + Some( + param @ ty::GenericParamDef { + kind: ty::GenericParamDefKind::Const { is_host_effect: true, .. }, + .. + }, + ) => self.var_for_effect(param).as_const().unwrap(), Some(param) => self.var_for_def(span, param).as_const().unwrap(), None => self.next_const_var( ty, diff --git a/compiler/rustc_infer/src/infer/combine.rs b/compiler/rustc_infer/src/infer/combine.rs index 377c414456d..ee13eb0271e 100644 --- a/compiler/rustc_infer/src/infer/combine.rs +++ b/compiler/rustc_infer/src/infer/combine.rs @@ -546,9 +546,9 @@ fn float_unification_error<'tcx>( } fn effect_unification_error<'tcx>( - tcx: TyCtxt<'tcx>, - a_is_expected: bool, - (a, b): (EffectVarValue<'tcx>, EffectVarValue<'tcx>), + _tcx: TyCtxt<'tcx>, + _a_is_expected: bool, + (_a, _b): (EffectVarValue<'tcx>, EffectVarValue<'tcx>), ) -> TypeError<'tcx> { - TypeError::ConstMismatch(ExpectedFound::new(a_is_expected, a.as_const(tcx), b.as_const(tcx))) + bug!("unexpected effect unification error") } diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs index b31046c2d32..f637d509400 100644 --- a/compiler/rustc_infer/src/infer/mod.rs +++ b/compiler/rustc_infer/src/infer/mod.rs @@ -36,7 +36,7 @@ use rustc_middle::ty::{self, GenericParamDefKind, InferConst, InferTy, Ty, TyCtx use rustc_middle::ty::{ConstVid, EffectVid, FloatVid, IntVid, TyVid}; use rustc_middle::ty::{GenericArg, GenericArgKind, GenericArgs, GenericArgsRef}; use rustc_span::symbol::Symbol; -use rustc_span::{sym, Span}; +use rustc_span::Span; use std::cell::{Cell, RefCell}; use std::fmt; @@ -1181,9 +1181,8 @@ impl<'tcx> InferCtxt<'tcx> { Ty::new_var(self.tcx, ty_var_id).into() } - GenericParamDefKind::Const { .. } => { - // todo what about using effect var here - if self.tcx.has_attr(param.def_id, sym::rustc_host) { + GenericParamDefKind::Const { is_host_effect, .. } => { + if is_host_effect { return self.var_for_effect(param); } let origin = ConstVariableOrigin { diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 7eae164ad3d..4f4351633a2 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -873,14 +873,14 @@ fn should_encode_attrs(def_kind: DefKind) -> bool { | DefKind::AssocConst | DefKind::Macro(_) | DefKind::Field - | DefKind::Impl { .. } - | DefKind::ConstParam => true, + | DefKind::Impl { .. } => true, // Tools may want to be able to detect their tool lints on // closures from upstream crates, too. This is used by // https://github.com/model-checking/kani and is not a performance // or maintenance issue for us. DefKind::Closure => true, DefKind::TyParam + | DefKind::ConstParam | DefKind::Ctor(..) | DefKind::ExternCrate | DefKind::Use diff --git a/compiler/rustc_middle/src/infer/canonical.rs b/compiler/rustc_middle/src/infer/canonical.rs index af9ca6b60c7..e1db8f810a7 100644 --- a/compiler/rustc_middle/src/infer/canonical.rs +++ b/compiler/rustc_middle/src/infer/canonical.rs @@ -448,7 +448,6 @@ impl<'tcx> CanonicalVarValues<'tcx> { }; ty::Region::new_late_bound(tcx, ty::INNERMOST, br).into() } - // todo eh? CanonicalVarKind::Effect => ty::Const::new_bound( tcx, ty::INNERMOST, diff --git a/compiler/rustc_middle/src/ty/generics.rs b/compiler/rustc_middle/src/ty/generics.rs index 70a35f137d8..ceac21cf6ea 100644 --- a/compiler/rustc_middle/src/ty/generics.rs +++ b/compiler/rustc_middle/src/ty/generics.rs @@ -12,7 +12,7 @@ use super::{Clause, EarlyBoundRegion, InstantiatedPredicates, ParamConst, ParamT pub enum GenericParamDefKind { Lifetime, Type { has_default: bool, synthetic: bool }, - Const { has_default: bool }, + Const { has_default: bool, is_host_effect: bool }, } impl GenericParamDefKind { @@ -87,7 +87,7 @@ impl GenericParamDef { GenericParamDefKind::Type { has_default, .. } if has_default => { Some(tcx.type_of(self.def_id).map_bound(|t| t.into())) } - GenericParamDefKind::Const { has_default } if has_default => { + GenericParamDefKind::Const { has_default, .. } if has_default => { Some(tcx.const_param_default(self.def_id).map_bound(|c| c.into())) } _ => None, @@ -187,7 +187,7 @@ impl<'tcx> Generics { GenericParamDefKind::Type { has_default, .. } => { own_defaults.types += has_default as usize; } - GenericParamDefKind::Const { has_default } => { + GenericParamDefKind::Const { has_default, .. } => { own_defaults.consts += has_default as usize; } } diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 906a36cdb25..8f9b6f7fe03 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -836,7 +836,7 @@ impl ReachEverythingInTheInterfaceVisitor<'_, '_> { self.visit(self.ev.tcx.type_of(param.def_id).instantiate_identity()); } } - GenericParamDefKind::Const { has_default } => { + GenericParamDefKind::Const { has_default, .. } => { self.visit(self.ev.tcx.type_of(param.def_id).instantiate_identity()); if has_default { self.visit( diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index 822a6e48658..65d108f7633 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -1242,7 +1242,7 @@ impl<'tcx> Stable<'tcx> for rustc_middle::ty::GenericParamDefKind { ty::GenericParamDefKind::Type { has_default, synthetic } => { GenericParamDefKind::Type { has_default: *has_default, synthetic: *synthetic } } - ty::GenericParamDefKind::Const { has_default } => { + ty::GenericParamDefKind::Const { has_default, is_host_effect: _ } => { GenericParamDefKind::Const { has_default: *has_default } } } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index b584c32a4c7..cbcb8fd99d8 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -541,7 +541,7 @@ fn clean_generic_param_def<'tcx>( }, ) } - ty::GenericParamDefKind::Const { has_default } => ( + ty::GenericParamDefKind::Const { has_default, .. } => ( def.name, GenericParamDefKind::Const { ty: Box::new(clean_middle_ty( -- cgit 1.4.1-3-g733a5