authorbors <bors@rust-lang.org> 2025-04-02 14:17:11 UTC
committerbors <bors@rust-lang.org> 2025-04-02 14:17:11 UTC
log4f0de4c81d80121ac7b576bc68d8016064f4d261
tree42b49e29b715aee68185f5fd028d62632e0d1b8d
parentae9173d7dd4a31806c950c90dcc331f1508b4d17
parentabcfc3e39055ffa03ee03dd2ab7b0887656f8292

Auto merge of #139257 - TaKO8Ki:rollup-vjzdas7, r=TaKO8Ki

Rollup of 5 pull requests Successful merges: - #139178 (Remove cjgillot from automated review assignment) - #139184 (Add unstable `--print=crate-root-lint-levels`) - #139215 (Add `opt-level = "s"` for more std symbolication crates) - #139232 (Move methods from `Map` to `TyCtxt`, part 5.) - #139239 (Remove `aux_build` run-make rustc helpers) r? `@ghost` `@rustbot` modify labels: rollup

96 files changed, 397 insertions(+), 238 deletions(-)

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs+1-1
......@@ -1364,7 +1364,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
13641364 }
13651365 // Try to find predicates on *generic params* that would allow copying `ty`
13661366 let mut suggestion =
1367 if let Some(symbol) = tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) {
1367 if let Some(symbol) = tcx.hir_maybe_get_struct_pattern_shorthand_field(expr) {
13681368 format!(": {symbol}.clone()")
13691369 } else {
13701370 ".clone()".to_owned()
compiler/rustc_borrowck/src/diagnostics/move_errors.rs+1-1
......@@ -502,7 +502,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
502502 let upvar = &self.upvars[upvar_field.unwrap().index()];
503503 let upvar_hir_id = upvar.get_root_variable();
504504 let upvar_name = upvar.to_string(tcx);
505 let upvar_span = tcx.hir().span(upvar_hir_id);
505 let upvar_span = tcx.hir_span(upvar_hir_id);
506506
507507 let place_name = self.describe_any_place(move_place.as_ref());
508508
compiler/rustc_borrowck/src/diagnostics/region_errors.rs+1-1
......@@ -628,7 +628,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
628628
629629 if let Some(def_hir) = defined_hir {
630630 let upvars_map = self.infcx.tcx.upvars_mentioned(def_id).unwrap();
631 let upvar_def_span = self.infcx.tcx.hir().span(def_hir);
631 let upvar_def_span = self.infcx.tcx.hir_span(def_hir);
632632 let upvar_span = upvars_map.get(&def_hir).unwrap().span;
633633 diag.subdiagnostic(VarHereDenote::Defined { span: upvar_def_span });
634634 diag.subdiagnostic(VarHereDenote::Captured { span: upvar_span });
compiler/rustc_borrowck/src/diagnostics/region_name.rs+2-2
......@@ -291,7 +291,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
291291 match *error_region {
292292 ty::ReEarlyParam(ebr) => ebr.has_name().then(|| {
293293 let def_id = tcx.generics_of(self.mir_def_id()).region_param(ebr, tcx).def_id;
294 let span = tcx.hir().span_if_local(def_id).unwrap_or(DUMMY_SP);
294 let span = tcx.hir_span_if_local(def_id).unwrap_or(DUMMY_SP);
295295 RegionName { name: ebr.name, source: RegionNameSource::NamedEarlyParamRegion(span) }
296296 }),
297297
......@@ -302,7 +302,7 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
302302 ty::ReLateParam(late_param) => match late_param.kind {
303303 ty::LateParamRegionKind::Named(region_def_id, name) => {
304304 // Get the span to point to, even if we don't use the name.
305 let span = tcx.hir().span_if_local(region_def_id).unwrap_or(DUMMY_SP);
305 let span = tcx.hir_span_if_local(region_def_id).unwrap_or(DUMMY_SP);
306306 debug!(
307307 "bound region named: {:?}, is_named: {:?}",
308308 name,
compiler/rustc_borrowck/src/diagnostics/var_name.rs+1-1
......@@ -70,7 +70,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
7070 debug!("get_upvar_name_and_span_for_region: upvar_hir_id={upvar_hir_id:?}");
7171
7272 let upvar_name = tcx.hir_name(upvar_hir_id);
73 let upvar_span = tcx.hir().span(upvar_hir_id);
73 let upvar_span = tcx.hir_span(upvar_hir_id);
7474 debug!(
7575 "get_upvar_name_and_span_for_region: upvar_name={upvar_name:?} upvar_span={upvar_span:?}",
7676 );
compiler/rustc_const_eval/src/const_eval/valtrees.rs+1-1
......@@ -256,7 +256,7 @@ pub(crate) fn eval_to_valtree<'tcx>(
256256 Err(err) => {
257257 let did = cid.instance.def_id();
258258 let global_const_id = cid.display(tcx);
259 let span = tcx.hir().span_if_local(did);
259 let span = tcx.hir_span_if_local(did);
260260 match err {
261261 ValTreeCreationError::NodesOverflow => {
262262 let handled =
compiler/rustc_driver_impl/src/lib.rs+28
......@@ -691,6 +691,34 @@ fn print_crate_info(
691691 };
692692 println_info!("{}", passes::get_crate_name(sess, attrs));
693693 }
694 CrateRootLintLevels => {
695 let Some(attrs) = attrs.as_ref() else {
696 // no crate attributes, print out an error and exit
697 return Compilation::Continue;
698 };
699 let crate_name = passes::get_crate_name(sess, attrs);
700 let lint_store = crate::unerased_lint_store(sess);
701 let registered_tools = rustc_resolve::registered_tools_ast(sess.dcx(), attrs);
702 let features = rustc_expand::config::features(sess, attrs, crate_name);
703 let lint_levels = rustc_lint::LintLevelsBuilder::crate_root(
704 sess,
705 &features,
706 true,
707 lint_store,
708 &registered_tools,
709 attrs,
710 );
711 for lint in lint_store.get_lints() {
712 if let Some(feature_symbol) = lint.feature_gate
713 && !features.enabled(feature_symbol)
714 {
715 // lint is unstable and feature gate isn't active, don't print
716 continue;
717 }
718 let level = lint_levels.lint_level(lint).0;
719 println_info!("{}={}", lint.name_lower(), level.as_str());
720 }
721 }
694722 Cfg => {
695723 let mut cfgs = sess
696724 .psess
compiler/rustc_hir/src/hir.rs+1-1
......@@ -2123,7 +2123,7 @@ pub type Lit = Spanned<LitKind>;
21232123/// explicit discriminant values for enum variants.
21242124///
21252125/// You can check if this anon const is a default in a const param
2126/// `const N: usize = { ... }` with `tcx.hir().opt_const_param_default_param_def_id(..)`
2126/// `const N: usize = { ... }` with `tcx.hir_opt_const_param_default_param_def_id(..)`
21272127#[derive(Copy, Clone, Debug, HashStable_Generic)]
21282128pub struct AnonConst {
21292129 #[stable_hasher(ignore)]
compiler/rustc_hir_analysis/src/check/check.rs+5-7
......@@ -578,10 +578,8 @@ fn check_opaque_precise_captures<'tcx>(tcx: TyCtxt<'tcx>, opaque_def_id: LocalDe
578578 }
579579 }
580580 _ => {
581 tcx.dcx().span_delayed_bug(
582 tcx.hir().span(hir_id),
583 "parameter should have been resolved",
584 );
581 tcx.dcx()
582 .span_delayed_bug(tcx.hir_span(hir_id), "parameter should have been resolved");
585583 }
586584 }
587585 }
......@@ -1049,7 +1047,7 @@ fn check_impl_items_against_trait<'tcx>(
10491047 leaf_def.as_ref().is_some_and(|node_item| !node_item.defining_node.is_from_trait());
10501048
10511049 if !is_implemented_here {
1052 let full_impl_span = tcx.hir().span_with_body(tcx.local_def_id_to_hir_id(impl_id));
1050 let full_impl_span = tcx.hir_span_with_body(tcx.local_def_id_to_hir_id(impl_id));
10531051 match tcx.eval_default_body_stability(trait_item_id, full_impl_span) {
10541052 EvalResult::Deny { feature, reason, issue, .. } => default_body_is_unstable(
10551053 tcx,
......@@ -1105,7 +1103,7 @@ fn check_impl_items_against_trait<'tcx>(
11051103 }
11061104
11071105 if !missing_items.is_empty() {
1108 let full_impl_span = tcx.hir().span_with_body(tcx.local_def_id_to_hir_id(impl_id));
1106 let full_impl_span = tcx.hir_span_with_body(tcx.local_def_id_to_hir_id(impl_id));
11091107 missing_items_err(tcx, impl_id, &missing_items, full_impl_span);
11101108 }
11111109
......@@ -1321,7 +1319,7 @@ pub(super) fn check_transparent<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>)
13211319 let typing_env = ty::TypingEnv::non_body_analysis(tcx, field.did);
13221320 let layout = tcx.layout_of(typing_env.as_query_input(ty));
13231321 // We are currently checking the type this field came from, so it must be local
1324 let span = tcx.hir().span_if_local(field.did).unwrap();
1322 let span = tcx.hir_span_if_local(field.did).unwrap();
13251323 let trivial = layout.is_ok_and(|layout| layout.is_1zst());
13261324 if !trivial {
13271325 return (span, trivial, None);
compiler/rustc_hir_analysis/src/check/compare_impl_item.rs+6-6
......@@ -1208,7 +1208,7 @@ fn extract_spans_for_error_reporting<'tcx>(
12081208 TypeError::ArgumentMutability(i) | TypeError::ArgumentSorts(ExpectedFound { .. }, i) => {
12091209 (impl_args.nth(i).unwrap(), trait_args.and_then(|mut args| args.nth(i)))
12101210 }
1211 _ => (cause.span, tcx.hir().span_if_local(trait_m.def_id)),
1211 _ => (cause.span, tcx.hir_span_if_local(trait_m.def_id)),
12121212 }
12131213}
12141214
......@@ -1261,7 +1261,7 @@ fn compare_self_type<'tcx>(
12611261 self_descr
12621262 );
12631263 err.span_label(impl_m_span, format!("`{self_descr}` used in impl"));
1264 if let Some(span) = tcx.hir().span_if_local(trait_m.def_id) {
1264 if let Some(span) = tcx.hir_span_if_local(trait_m.def_id) {
12651265 err.span_label(span, format!("trait method declared without `{self_descr}`"));
12661266 } else {
12671267 err.note_trait_signature(trait_m.name, trait_m.signature(tcx));
......@@ -1281,7 +1281,7 @@ fn compare_self_type<'tcx>(
12811281 self_descr
12821282 );
12831283 err.span_label(impl_m_span, format!("expected `{self_descr}` in impl"));
1284 if let Some(span) = tcx.hir().span_if_local(trait_m.def_id) {
1284 if let Some(span) = tcx.hir_span_if_local(trait_m.def_id) {
12851285 err.span_label(span, format!("`{self_descr}` used in trait"));
12861286 } else {
12871287 err.note_trait_signature(trait_m.name, trait_m.signature(tcx));
......@@ -1389,7 +1389,7 @@ fn compare_number_of_generics<'tcx>(
13891389 .collect();
13901390 (Some(arg_spans), impl_trait_spans)
13911391 } else {
1392 let trait_span = tcx.hir().span_if_local(trait_.def_id);
1392 let trait_span = tcx.hir_span_if_local(trait_.def_id);
13931393 (trait_span.map(|s| vec![s]), vec![])
13941394 };
13951395
......@@ -1481,7 +1481,7 @@ fn compare_number_of_method_arguments<'tcx>(
14811481 }
14821482 })
14831483 })
1484 .or_else(|| tcx.hir().span_if_local(trait_m.def_id));
1484 .or_else(|| tcx.hir_span_if_local(trait_m.def_id));
14851485
14861486 let (impl_m_sig, _) = &tcx.hir_expect_impl_item(impl_m.def_id.expect_local()).expect_fn();
14871487 let pos = impl_number_args.saturating_sub(1);
......@@ -2366,7 +2366,7 @@ fn try_report_async_mismatch<'tcx>(
23662366 return Err(tcx.sess.dcx().emit_err(MethodShouldReturnFuture {
23672367 span: tcx.def_span(impl_m.def_id),
23682368 method_name: tcx.item_ident(impl_m.def_id),
2369 trait_item_span: tcx.hir().span_if_local(trait_m.def_id),
2369 trait_item_span: tcx.hir_span_if_local(trait_m.def_id),
23702370 }));
23712371 }
23722372 }
compiler/rustc_hir_analysis/src/check/mod.rs+2-2
......@@ -243,7 +243,7 @@ fn missing_items_err(
243243 tcx.impl_trait_ref(impl_def_id).unwrap().instantiate_identity(),
244244 ));
245245 let code = format!("{padding}{snippet}\n{padding}");
246 if let Some(span) = tcx.hir().span_if_local(trait_item.def_id) {
246 if let Some(span) = tcx.hir_span_if_local(trait_item.def_id) {
247247 missing_trait_item_label
248248 .push(errors::MissingTraitItemLabel { span, item: trait_item.name });
249249 missing_trait_item.push(errors::MissingTraitItemSuggestion {
......@@ -534,7 +534,7 @@ fn bad_variant_count<'tcx>(tcx: TyCtxt<'tcx>, adt: ty::AdtDef<'tcx>, sp: Span, d
534534 let variant_spans: Vec<_> = adt
535535 .variants()
536536 .iter()
537 .map(|variant| tcx.hir().span_if_local(variant.def_id).unwrap())
537 .map(|variant| tcx.hir_span_if_local(variant.def_id).unwrap())
538538 .collect();
539539 let (mut spans, mut many) = (Vec::new(), None);
540540 if let [start @ .., end] = &*variant_spans {
compiler/rustc_hir_analysis/src/collect/generics_of.rs+1-2
......@@ -116,8 +116,7 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
116116 {
117117 // enum variant discriminants are not allowed to use any kind of generics
118118 None
119 } else if let Some(param_id) =
120 tcx.hir().opt_const_param_default_param_def_id(hir_id)
119 } else if let Some(param_id) = tcx.hir_opt_const_param_default_param_def_id(hir_id)
121120 {
122121 // If the def_id we are calling generics_of on is an anon ct default i.e:
123122 //
compiler/rustc_hir_analysis/src/collect/predicates_of.rs+1-1
......@@ -508,7 +508,7 @@ pub(super) fn explicit_predicates_of<'tcx>(
508508 if matches!(def_kind, DefKind::AnonConst)
509509 && tcx.features().generic_const_exprs()
510510 && let Some(defaulted_param_def_id) =
511 tcx.hir().opt_const_param_default_param_def_id(tcx.local_def_id_to_hir_id(def_id))
511 tcx.hir_opt_const_param_default_param_def_id(tcx.local_def_id_to_hir_id(def_id))
512512 {
513513 // In `generics_of` we set the generics' parent to be our parent's parent which means that
514514 // we lose out on the predicates of our actual parent if we dont return those predicates here.
compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs+4-4
......@@ -1529,7 +1529,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
15291529 if let ResolvedArg::LateBound(..) = def
15301530 && let Some(what) = crossed_late_boundary
15311531 {
1532 let use_span = self.tcx.hir().span(hir_id);
1532 let use_span = self.tcx.hir_span(hir_id);
15331533 let def_span = self.tcx.def_span(param_def_id);
15341534 let guar = match self.tcx.def_kind(param_def_id) {
15351535 DefKind::ConstParam => {
......@@ -1576,11 +1576,11 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
15761576 } => {
15771577 let guar = self.tcx.dcx().emit_err(match self.tcx.def_kind(param_def_id) {
15781578 DefKind::TyParam => errors::LateBoundInApit::Type {
1579 span: self.tcx.hir().span(hir_id),
1579 span: self.tcx.hir_span(hir_id),
15801580 param_span: self.tcx.def_span(param_def_id),
15811581 },
15821582 DefKind::ConstParam => errors::LateBoundInApit::Const {
1583 span: self.tcx.hir().span(hir_id),
1583 span: self.tcx.hir_span(hir_id),
15841584 param_span: self.tcx.def_span(param_def_id),
15851585 },
15861586 kind => {
......@@ -1605,7 +1605,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> {
16051605
16061606 self.tcx
16071607 .dcx()
1608 .span_bug(self.tcx.hir().span(hir_id), format!("could not resolve {param_def_id:?}"));
1608 .span_bug(self.tcx.hir_span(hir_id), format!("could not resolve {param_def_id:?}"));
16091609 }
16101610
16111611 #[instrument(level = "debug", skip(self))]
compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs+1-1
......@@ -684,7 +684,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
684684 return Err(self.dcx().emit_err(crate::errors::ReturnTypeNotationOnNonRpitit {
685685 span: path_span,
686686 ty: tcx.liberate_late_bound_regions(item_def_id, output),
687 fn_span: tcx.hir().span_if_local(item_def_id),
687 fn_span: tcx.hir_span_if_local(item_def_id),
688688 note: (),
689689 }));
690690 };
compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs+1-1
......@@ -32,7 +32,7 @@ pub(crate) fn validate_cmse_abi<'tcx>(
3232 span,
3333 ..
3434 }) => *span,
35 _ => tcx.hir().span(hir_id),
35 _ => tcx.hir_span(hir_id),
3636 };
3737 struct_span_code_err!(
3838 tcx.dcx(),
compiler/rustc_hir_analysis/src/hir_ty_lowering/errors.rs+2-2
......@@ -882,7 +882,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
882882
883883 let rename_message = if is_shadowed { ", consider renaming it" } else { "" };
884884
885 if let Some(sp) = tcx.hir().span_if_local(item.def_id) {
885 if let Some(sp) = tcx.hir_span_if_local(item.def_id) {
886886 err.span_label(
887887 sp,
888888 format!("`{}{}` defined here{}", prefix, item.name, rename_message),
......@@ -1381,7 +1381,7 @@ pub(crate) fn fn_trait_to_string(
13811381 .find_map(|c| {
13821382 if c.ident.name == sym::Output
13831383 && let Some(ty) = c.ty()
1384 && ty.span != tcx.hir().span(trait_segment.hir_id)
1384 && ty.span != tcx.hir_span(trait_segment.hir_id)
13851385 {
13861386 tcx.sess.source_map().span_to_snippet(ty.span).ok()
13871387 } else {
compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs+1-1
......@@ -92,7 +92,7 @@ fn generic_arg_mismatch_err(
9292 GenericArg::Type(hir::Ty { kind: hir::TyKind::Array(_, len), .. }),
9393 GenericParamDefKind::Const { .. },
9494 ) if tcx.type_of(param.def_id).skip_binder() == tcx.types.usize => {
95 let snippet = sess.source_map().span_to_snippet(tcx.hir().span(len.hir_id));
95 let snippet = sess.source_map().span_to_snippet(tcx.hir_span(len.hir_id));
9696 if let Ok(snippet) = snippet {
9797 err.span_suggestion(
9898 arg.span(),
compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs+2-2
......@@ -1066,7 +1066,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
10661066 let bound_span = tcx
10671067 .associated_items(bound_id)
10681068 .find_by_name_and_kind(tcx, assoc_name, assoc_kind, bound_id)
1069 .and_then(|item| tcx.hir().span_if_local(item.def_id));
1069 .and_then(|item| tcx.hir_span_if_local(item.def_id));
10701070
10711071 if let Some(bound_span) = bound_span {
10721072 err.span_label(
......@@ -1400,7 +1400,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
14001400 );
14011401 }
14021402
1403 if let Some(sp) = tcx.hir().span_if_local(adt_def.did()) {
1403 if let Some(sp) = tcx.hir_span_if_local(adt_def.did()) {
14041404 err.span_label(sp, format!("variant `{assoc_ident}` not found here"));
14051405 }
14061406
compiler/rustc_hir_analysis/src/hir_wf_check.rs+1-1
......@@ -170,7 +170,7 @@ fn diagnostic_hir_wf_check<'tcx>(
170170 ..
171171 }) => vec![*ty],
172172 hir::Node::AnonConst(_) => {
173 if let Some(const_param_id) = tcx.hir().opt_const_param_default_param_def_id(hir_id)
173 if let Some(const_param_id) = tcx.hir_opt_const_param_default_param_def_id(hir_id)
174174 && let hir::Node::GenericParam(hir::GenericParam {
175175 kind: hir::GenericParamKind::Const { ty, .. },
176176 ..
compiler/rustc_hir_analysis/src/outlives/mod.rs+1-1
......@@ -25,7 +25,7 @@ fn inferred_outlives_of(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[(ty::Clau
2525 }
2626 DefKind::AnonConst if tcx.features().generic_const_exprs() => {
2727 let id = tcx.local_def_id_to_hir_id(item_def_id);
28 if tcx.hir().opt_const_param_default_param_def_id(id).is_some() {
28 if tcx.hir_opt_const_param_default_param_def_id(id).is_some() {
2929 // In `generics_of` we set the generics' parent to be our parent's parent which means that
3030 // we lose out on the predicates of our actual parent if we dont return those predicates here.
3131 // (See comment in `generics_of` for more information on why the parent shenanigans is necessary)
compiler/rustc_hir_typeck/src/callee.rs+2-2
......@@ -771,7 +771,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
771771 format!("this {descr} returns an unsized value `{output_ty}`, so it cannot be called")
772772 );
773773 if let DefIdOrName::DefId(def_id) = maybe_def
774 && let Some(def_span) = self.tcx.hir().span_if_local(def_id)
774 && let Some(def_span) = self.tcx.hir_span_if_local(def_id)
775775 {
776776 err.span_label(def_span, "the callable type is defined here");
777777 }
......@@ -780,7 +780,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
780780 }
781781 }
782782
783 if let Some(span) = self.tcx.hir().res_span(def) {
783 if let Some(span) = self.tcx.hir_res_span(def) {
784784 let callee_ty = callee_ty.to_string();
785785 let label = match (unit_variant, inner_callee_path) {
786786 (Some((_, kind, path)), _) => {
compiler/rustc_hir_typeck/src/closure.rs+1-1
......@@ -970,7 +970,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
970970 self.typeck_results.borrow_mut().user_provided_sigs.insert(expr_def_id, c_result);
971971
972972 // Normalize only after registering in `user_provided_sigs`.
973 self.normalize(self.tcx.hir().span(hir_id), result)
973 self.normalize(self.tcx.hir_span(hir_id), result)
974974 }
975975
976976 /// Invoked when we are translating the coroutine that results
compiler/rustc_hir_typeck/src/demand.rs+2-4
......@@ -999,10 +999,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
999999 let container = with_no_trimmed_paths!(self.tcx.def_path_str(container_id));
10001000 for def_id in pick.import_ids {
10011001 let hir_id = self.tcx.local_def_id_to_hir_id(def_id);
1002 path_span.push_span_label(
1003 self.tcx.hir().span(hir_id),
1004 format!("`{container}` imported here"),
1005 );
1002 path_span
1003 .push_span_label(self.tcx.hir_span(hir_id), format!("`{container}` imported here"));
10061004 }
10071005 let tail = with_no_trimmed_paths!(match &other_methods_in_scope[..] {
10081006 [] => return,
compiler/rustc_hir_typeck/src/expr.rs+1-1
......@@ -3239,7 +3239,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
32393239 Some(x) => self.tcx.local_def_id_to_hir_id(x),
32403240 None => return,
32413241 };
3242 let param_span = self.tcx.hir().span(param_hir_id);
3242 let param_span = self.tcx.hir_span(param_hir_id);
32433243 let param_name = self.tcx.hir_ty_param_name(param_def_id.expect_local());
32443244
32453245 err.span_label(param_span, format!("type parameter '{param_name}' declared here"));
compiler/rustc_hir_typeck/src/expr_use_visitor.rs+4-12
......@@ -1182,9 +1182,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
11821182 self.cx.error_reported_in_ty(ty)?;
11831183 if ty.is_ty_var() {
11841184 debug!("resolve_type_vars_or_bug: infer var from {:?}", ty);
1185 Err(self
1186 .cx
1187 .report_bug(self.cx.tcx().hir().span(id), "encountered type variable"))
1185 Err(self.cx.report_bug(self.cx.tcx().hir_span(id), "encountered type variable"))
11881186 } else {
11891187 Ok(ty)
11901188 }
......@@ -1509,10 +1507,7 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
15091507 if node_ty != place_ty
15101508 && self
15111509 .cx
1512 .try_structurally_resolve_type(
1513 self.cx.tcx().hir().span(base_place.hir_id),
1514 place_ty,
1515 )
1510 .try_structurally_resolve_type(self.cx.tcx().hir_span(base_place.hir_id), place_ty)
15161511 .is_impl_trait()
15171512 {
15181513 projections.push(Projection { kind: ProjectionKind::OpaqueCast, ty: node_ty });
......@@ -1551,17 +1546,14 @@ impl<'tcx, Cx: TypeInformationCtxt<'tcx>, D: Delegate<'tcx>> ExprUseVisitor<'tcx
15511546 let base_curr_ty = base_place.place.ty();
15521547 let deref_ty = match self
15531548 .cx
1554 .try_structurally_resolve_type(
1555 self.cx.tcx().hir().span(base_place.hir_id),
1556 base_curr_ty,
1557 )
1549 .try_structurally_resolve_type(self.cx.tcx().hir_span(base_place.hir_id), base_curr_ty)
15581550 .builtin_deref(true)
15591551 {
15601552 Some(ty) => ty,
15611553 None => {
15621554 debug!("explicit deref of non-derefable type: {:?}", base_curr_ty);
15631555 return Err(self.cx.report_bug(
1564 self.cx.tcx().hir().span(node),
1556 self.cx.tcx().hir_span(node),
15651557 "explicit deref of non-derefable type",
15661558 ));
15671559 }
compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs+2-2
......@@ -157,7 +157,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
157157 // Lots of that diagnostics code relies on subtle effects of re-lowering, so we'll
158158 // let it keep doing that and just ensure that compilation won't succeed.
159159 self.dcx().span_delayed_bug(
160 self.tcx.hir().span(id),
160 self.tcx.hir_span(id),
161161 format!("`{prev}` overridden by `{ty}` for {id:?} in {:?}", self.body_id),
162162 );
163163 }
......@@ -532,7 +532,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
532532 let ct = self.lowerer().lower_const_arg(const_arg, feed);
533533 self.register_wf_obligation(
534534 ct.into(),
535 self.tcx.hir().span(const_arg.hir_id),
535 self.tcx.hir_span(const_arg.hir_id),
536536 ObligationCauseCode::WellFormed(None),
537537 );
538538 ct
compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs+13-14
......@@ -351,7 +351,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
351351
352352 if self.suggest_fn_call(err, expr, found, |output| self.may_coerce(output, expected))
353353 && let ty::FnDef(def_id, ..) = *found.kind()
354 && let Some(sp) = self.tcx.hir().span_if_local(def_id)
354 && let Some(sp) = self.tcx.hir_span_if_local(def_id)
355355 {
356356 let name = self.tcx.item_name(def_id);
357357 let kind = self.tcx.def_kind(def_id);
......@@ -407,7 +407,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
407407 vec![(expr.span.shrink_to_hi(), format!(".{}()", conversion_method.name))]
408408 };
409409 let struct_pat_shorthand_field =
410 self.tcx.hir().maybe_get_struct_pattern_shorthand_field(expr);
410 self.tcx.hir_maybe_get_struct_pattern_shorthand_field(expr);
411411 if let Some(name) = struct_pat_shorthand_field {
412412 sugg.insert(0, (expr.span.shrink_to_lo(), format!("{name}: ")));
413413 }
......@@ -449,7 +449,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
449449 });
450450
451451 let prefix_wrap = |sugg: &str| {
452 if let Some(name) = self.tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) {
452 if let Some(name) = self.tcx.hir_maybe_get_struct_pattern_shorthand_field(expr) {
453453 format!(": {}{}", name, sugg)
454454 } else {
455455 sugg.to_string()
......@@ -671,7 +671,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
671671 }
672672 _ => {
673673 let prefix = if let Some(name) =
674 self.tcx.hir().maybe_get_struct_pattern_shorthand_field(expr)
674 self.tcx.hir_maybe_get_struct_pattern_shorthand_field(expr)
675675 {
676676 format!("{}: ", name)
677677 } else {
......@@ -1153,7 +1153,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
11531153 };
11541154 if can_return
11551155 && let Some(span) = expr.span.find_ancestor_inside(
1156 self.tcx.hir().span_with_body(self.tcx.local_def_id_to_hir_id(fn_id)),
1156 self.tcx.hir_span_with_body(self.tcx.local_def_id_to_hir_id(fn_id)),
11571157 )
11581158 {
11591159 // When the expr is in a match arm's body, we shouldn't add semicolon ';' at the end.
......@@ -1275,7 +1275,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12751275 )
12761276 .must_apply_modulo_regions()
12771277 {
1278 let suggestion = match self.tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) {
1278 let suggestion = match self.tcx.hir_maybe_get_struct_pattern_shorthand_field(expr) {
12791279 Some(ident) => format!(": {ident}.clone()"),
12801280 None => ".clone()".to_string(),
12811281 };
......@@ -1381,7 +1381,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13811381 (span.shrink_to_hi(), ").into()".to_owned()),
13821382 ]
13831383 };
1384 if let Some(name) = self.tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) {
1384 if let Some(name) = self.tcx.hir_maybe_get_struct_pattern_shorthand_field(expr) {
13851385 sugg.insert(0, (expr.span.shrink_to_lo(), format!("{}: ", name)));
13861386 }
13871387 diag.multipart_suggestion(
......@@ -1436,7 +1436,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14361436 return false;
14371437 }
14381438
1439 let suggestion = match self.tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) {
1439 let suggestion = match self.tcx.hir_maybe_get_struct_pattern_shorthand_field(expr) {
14401440 Some(ident) => format!(": {ident}.is_some()"),
14411441 None => ".is_some()".to_string(),
14421442 };
......@@ -2032,7 +2032,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20322032 )
20332033 };
20342034
2035 let sugg = match self.tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) {
2035 let sugg = match self.tcx.hir_maybe_get_struct_pattern_shorthand_field(expr) {
20362036 Some(ident) => format!(": {ident}{sugg}"),
20372037 None => sugg.to_string(),
20382038 };
......@@ -2289,7 +2289,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22892289 // Unroll desugaring, to make sure this works for `for` loops etc.
22902290 loop {
22912291 parent = self.tcx.parent_hir_id(id);
2292 let parent_span = self.tcx.hir().span(parent);
2292 let parent_span = self.tcx.hir_span(parent);
22932293 if parent_span.find_ancestor_inside(expr.span).is_some() {
22942294 // The parent node is part of the same span, so is the result of the
22952295 // same expansion/desugaring and not the 'real' parent node.
......@@ -2378,7 +2378,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23782378 .collect();
23792379
23802380 let suggestions_for = |variant: &_, ctor_kind, field_name| {
2381 let prefix = match self.tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) {
2381 let prefix = match self.tcx.hir_maybe_get_struct_pattern_shorthand_field(expr) {
23822382 Some(ident) => format!("{ident}: "),
23832383 None => String::new(),
23842384 };
......@@ -2700,8 +2700,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
27002700 ));
27012701 }
27022702
2703 let prefix = match self.tcx.hir().maybe_get_struct_pattern_shorthand_field(expr)
2704 {
2703 let prefix = match self.tcx.hir_maybe_get_struct_pattern_shorthand_field(expr) {
27052704 Some(ident) => format!("{ident}: "),
27062705 None => String::new(),
27072706 };
......@@ -2911,7 +2910,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
29112910 };
29122911
29132912 let prefix =
2914 match self.tcx.hir().maybe_get_struct_pattern_shorthand_field(expr) {
2913 match self.tcx.hir_maybe_get_struct_pattern_shorthand_field(expr) {
29152914 Some(ident) => format!("{ident}: "),
29162915 None => String::new(),
29172916 };
compiler/rustc_hir_typeck/src/intrinsicck.rs+1-1
......@@ -45,7 +45,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
4545 pub(crate) fn check_transmute(&self, from: Ty<'tcx>, to: Ty<'tcx>, hir_id: HirId) {
4646 let tcx = self.tcx;
4747 let dl = &tcx.data_layout;
48 let span = tcx.hir().span(hir_id);
48 let span = tcx.hir_span(hir_id);
4949 let normalize = |ty| {
5050 let ty = self.resolve_vars_if_possible(ty);
5151 if let Ok(ty) =
compiler/rustc_hir_typeck/src/lib.rs+1-1
......@@ -117,7 +117,7 @@ fn typeck_with_inspect<'tcx>(
117117
118118 let id = tcx.local_def_id_to_hir_id(def_id);
119119 let node = tcx.hir_node(id);
120 let span = tcx.hir().span(id);
120 let span = tcx.hir_span(id);
121121
122122 // Figure out what primary body this item has.
123123 let body_id = node.body_id().unwrap_or_else(|| {
compiler/rustc_hir_typeck/src/method/suggest.rs+4-7
......@@ -254,11 +254,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
254254 item_name
255255 );
256256 err.span_label(item_name.span, format!("private {kind}"));
257 let sp = self
258 .tcx
259 .hir()
260 .span_if_local(def_id)
261 .unwrap_or_else(|| self.tcx.def_span(def_id));
257 let sp =
258 self.tcx.hir_span_if_local(def_id).unwrap_or_else(|| self.tcx.def_span(def_id));
262259 err.span_label(sp, format!("private {kind} defined here"));
263260 if let Some(within_macro_span) = within_macro_span {
264261 err.span_label(within_macro_span, "due to this macro variable");
......@@ -566,7 +563,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
566563 span.push_span_label(sugg_let.span,
567564 format!("`{rcvr_name}` of type `{self_ty}` that has method `{method_name}` defined earlier here"));
568565 span.push_span_label(
569 self.tcx.hir().span(recv_id),
566 self.tcx.hir_span(recv_id),
570567 format!(
571568 "earlier `{rcvr_name}` shadowed here with type `{ty_str_reported}`"
572569 ),
......@@ -2561,7 +2558,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
25612558 ExprKind::Path(QPath::Resolved(_, path)) => {
25622559 // local binding
25632560 if let hir::def::Res::Local(hir_id) = path.res {
2564 let span = tcx.hir().span(hir_id);
2561 let span = tcx.hir_span(hir_id);
25652562 let filename = tcx.sess.source_map().span_to_filename(span);
25662563
25672564 let parent_node = self.tcx.parent_hir_node(hir_id);
compiler/rustc_hir_typeck/src/pat.rs+3-4
......@@ -944,10 +944,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
944944 ) {
945945 let var_ty = self.local_ty(span, var_id);
946946 if let Err(mut err) = self.demand_eqtype_pat_diag(span, var_ty, ty, ti) {
947 let hir = self.tcx.hir();
948947 let var_ty = self.resolve_vars_if_possible(var_ty);
949948 let msg = format!("first introduced with type `{var_ty}` here");
950 err.span_label(hir.span(var_id), msg);
949 err.span_label(self.tcx.hir_span(var_id), msg);
951950 let in_match = self.tcx.hir_parent_iter(var_id).any(|(_, n)| {
952951 matches!(
953952 n,
......@@ -1255,7 +1254,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12551254 })) => match self.tcx.hir_node(body_id.hir_id) {
12561255 hir::Node::Expr(expr) => {
12571256 if hir::is_range_literal(expr) {
1258 let span = self.tcx.hir().span(body_id.hir_id);
1257 let span = self.tcx.hir_span(body_id.hir_id);
12591258 if let Ok(snip) = self.tcx.sess.source_map().span_to_snippet(span) {
12601259 e.span_suggestion_verbose(
12611260 ident.span,
......@@ -1286,7 +1285,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12861285 pat_ty: Ty<'tcx>,
12871286 segments: &'tcx [hir::PathSegment<'tcx>],
12881287 ) {
1289 if let Some(span) = self.tcx.hir().res_span(pat_res) {
1288 if let Some(span) = self.tcx.hir_res_span(pat_res) {
12901289 e.span_label(span, format!("{} defined here", res.descr()));
12911290 if let [hir::PathSegment { ident, .. }] = &*segments {
12921291 e.span_label(
compiler/rustc_hir_typeck/src/upvar.rs+14-16
......@@ -635,7 +635,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
635635 let (place, capture_kind) = truncate_capture_for_optimization(place, capture_kind);
636636
637637 let usage_span = if let Some(usage_expr) = capture_info.path_expr_id {
638 self.tcx.hir().span(usage_expr)
638 self.tcx.hir_span(usage_expr)
639639 } else {
640640 unreachable!()
641641 };
......@@ -986,7 +986,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
986986 for lint_note in diagnostics_info.iter() {
987987 match &lint_note.captures_info {
988988 UpvarMigrationInfo::CapturingPrecise { source_expr: Some(capture_expr_id), var_name: captured_name } => {
989 let cause_span = self.tcx.hir().span(*capture_expr_id);
989 let cause_span = self.tcx.hir_span(*capture_expr_id);
990990 lint.span_label(cause_span, format!("in Rust 2018, this closure captures all of `{}`, but in Rust 2021, it will only capture `{}`",
991991 self.tcx.hir_name(*var_hir_id),
992992 captured_name,
......@@ -1047,13 +1047,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10471047 "add a dummy let to cause {migrated_variables_concat} to be fully captured"
10481048 );
10491049
1050 let closure_span = self.tcx.hir().span_with_body(closure_hir_id);
1050 let closure_span = self.tcx.hir_span_with_body(closure_hir_id);
10511051 let mut closure_body_span = {
10521052 // If the body was entirely expanded from a macro
10531053 // invocation, i.e. the body is not contained inside the
10541054 // closure span, then we walk up the expansion until we
10551055 // find the span before the expansion.
1056 let s = self.tcx.hir().span_with_body(body_id.hir_id);
1056 let s = self.tcx.hir_span_with_body(body_id.hir_id);
10571057 s.find_ancestor_inside(closure_span).unwrap_or(s)
10581058 };
10591059
......@@ -1752,8 +1752,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17521752 let capture_str = construct_capture_info_string(self.tcx, place, capture_info);
17531753 let output_str = format!("Capturing {capture_str}");
17541754
1755 let span =
1756 capture_info.path_expr_id.map_or(closure_span, |e| self.tcx.hir().span(e));
1755 let span = capture_info.path_expr_id.map_or(closure_span, |e| self.tcx.hir_span(e));
17571756 diag.span_note(span, output_str);
17581757 }
17591758 diag.emit();
......@@ -1780,10 +1779,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17801779 if capture.info.path_expr_id != capture.info.capture_kind_expr_id {
17811780 let path_span = capture_info
17821781 .path_expr_id
1783 .map_or(closure_span, |e| self.tcx.hir().span(e));
1782 .map_or(closure_span, |e| self.tcx.hir_span(e));
17841783 let capture_kind_span = capture_info
17851784 .capture_kind_expr_id
1786 .map_or(closure_span, |e| self.tcx.hir().span(e));
1785 .map_or(closure_span, |e| self.tcx.hir_span(e));
17871786
17881787 let mut multi_span: MultiSpan =
17891788 MultiSpan::from_spans(vec![path_span, capture_kind_span]);
......@@ -1799,7 +1798,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17991798 } else {
18001799 let span = capture_info
18011800 .path_expr_id
1802 .map_or(closure_span, |e| self.tcx.hir().span(e));
1801 .map_or(closure_span, |e| self.tcx.hir_span(e));
18031802
18041803 diag.span_note(span, output_str);
18051804 };
......@@ -1828,8 +1827,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18281827 let mut is_mutbl = bm.1;
18291828
18301829 for pointer_ty in place.deref_tys() {
1831 match self.structurally_resolve_type(self.tcx.hir().span(var_hir_id), pointer_ty).kind()
1832 {
1830 match self.structurally_resolve_type(self.tcx.hir_span(var_hir_id), pointer_ty).kind() {
18331831 // We don't capture derefs of raw ptrs
18341832 ty::RawPtr(_, _) => unreachable!(),
18351833
......@@ -1844,7 +1842,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18441842 ty::Adt(def, ..) if def.is_box() => {}
18451843
18461844 unexpected_ty => span_bug!(
1847 self.tcx.hir().span(var_hir_id),
1845 self.tcx.hir_span(var_hir_id),
18481846 "deref of unexpected pointer type {:?}",
18491847 unexpected_ty
18501848 ),
......@@ -1975,14 +1973,14 @@ fn drop_location_span(tcx: TyCtxt<'_>, hir_id: HirId) -> Span {
19751973 let owner_node = tcx.hir_node(owner_id);
19761974 let owner_span = match owner_node {
19771975 hir::Node::Item(item) => match item.kind {
1978 hir::ItemKind::Fn { body: owner_id, .. } => tcx.hir().span(owner_id.hir_id),
1976 hir::ItemKind::Fn { body: owner_id, .. } => tcx.hir_span(owner_id.hir_id),
19791977 _ => {
19801978 bug!("Drop location span error: need to handle more ItemKind '{:?}'", item.kind);
19811979 }
19821980 },
1983 hir::Node::Block(block) => tcx.hir().span(block.hir_id),
1984 hir::Node::TraitItem(item) => tcx.hir().span(item.hir_id()),
1985 hir::Node::ImplItem(item) => tcx.hir().span(item.hir_id()),
1981 hir::Node::Block(block) => tcx.hir_span(block.hir_id),
1982 hir::Node::TraitItem(item) => tcx.hir_span(item.hir_id()),
1983 hir::Node::ImplItem(item) => tcx.hir_span(item.hir_id()),
19861984 _ => {
19871985 bug!("Drop location span error: need to handle more Node '{:?}'", owner_node);
19881986 }
compiler/rustc_hir_typeck/src/writeback.rs+2-2
......@@ -491,7 +491,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
491491
492492 if let ty::UserTypeKind::TypeOf(_, user_args) = c_ty.value.kind {
493493 // This is a unit-testing mechanism.
494 let span = self.tcx().hir().span(hir_id);
494 let span = self.tcx().hir_span(hir_id);
495495 // We need to buffer the errors in order to guarantee a consistent
496496 // order when emitting them.
497497 let err =
......@@ -775,7 +775,7 @@ impl Locatable for Span {
775775
776776impl Locatable for HirId {
777777 fn to_span(&self, tcx: TyCtxt<'_>) -> Span {
778 tcx.hir().span(*self)
778 tcx.hir_span(*self)
779779 }
780780}
781781
compiler/rustc_lint/src/impl_trait_overcaptures.rs+1-1
......@@ -392,7 +392,7 @@ where
392392 }
393393 _ => {
394394 self.tcx.dcx().span_delayed_bug(
395 self.tcx.hir().span(arg.hir_id()),
395 self.tcx.hir_span(arg.hir_id()),
396396 "no valid for captured arg",
397397 );
398398 }
compiler/rustc_lint/src/levels.rs+13
......@@ -450,6 +450,19 @@ impl<'s> LintLevelsBuilder<'s, TopDown> {
450450 builder
451451 }
452452
453 pub fn crate_root(
454 sess: &'s Session,
455 features: &'s Features,
456 lint_added_lints: bool,
457 store: &'s LintStore,
458 registered_tools: &'s RegisteredTools,
459 crate_attrs: &[ast::Attribute],
460 ) -> Self {
461 let mut builder = Self::new(sess, features, lint_added_lints, store, registered_tools);
462 builder.add(crate_attrs, true, None);
463 builder
464 }
465
453466 fn process_command_line(&mut self) {
454467 self.provider.cur = self
455468 .provider
compiler/rustc_lint/src/lib.rs+1
......@@ -130,6 +130,7 @@ pub use context::{
130130};
131131pub use early::{EarlyCheckNode, check_ast_node};
132132pub use late::{check_crate, late_lint_mod, unerased_lint_store};
133pub use levels::LintLevelsBuilder;
133134pub use passes::{EarlyLintPass, LateLintPass};
134135pub use rustc_session::lint::Level::{self, *};
135136pub use rustc_session::lint::{
compiler/rustc_lint/src/types.rs+1-1
......@@ -1403,7 +1403,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
14031403 CItemKind::Definition => "fn",
14041404 };
14051405 let span_note = if let ty::Adt(def, _) = ty.kind()
1406 && let Some(sp) = self.cx.tcx.hir().span_if_local(def.did())
1406 && let Some(sp) = self.cx.tcx.hir_span_if_local(def.did())
14071407 {
14081408 Some(sp)
14091409 } else {
compiler/rustc_metadata/src/rmeta/encoder.rs+1-3
......@@ -1890,8 +1890,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
18901890 let is_proc_macro = self.tcx.crate_types().contains(&CrateType::ProcMacro);
18911891 if is_proc_macro {
18921892 let tcx = self.tcx;
1893 let hir = tcx.hir();
1894
18951893 let proc_macro_decls_static = tcx.proc_macro_decls_static(()).unwrap().local_def_index;
18961894 let stability = tcx.lookup_stability(CRATE_DEF_ID);
18971895 let macros =
......@@ -1924,7 +1922,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
19241922 let id = proc_macro;
19251923 let proc_macro = tcx.local_def_id_to_hir_id(proc_macro);
19261924 let mut name = tcx.hir_name(proc_macro);
1927 let span = hir.span(proc_macro);
1925 let span = tcx.hir_span(proc_macro);
19281926 // Proc-macros may have attributes like `#[allow_internal_unstable]`,
19291927 // so downstream crates need access to them.
19301928 let attrs = tcx.hir_attrs(proc_macro);
compiler/rustc_middle/src/hir/map.rs+24-26
......@@ -22,6 +22,7 @@ use crate::ty::TyCtxt;
2222// only serves as "namespace" for HIR-related methods, and can be
2323// removed if all the methods are reasonably renamed and moved to tcx
2424// (https://github.com/rust-lang/rust/pull/118256#issuecomment-1826442834).
25#[allow(unused)] // FIXME: temporary
2526#[derive(Copy, Clone)]
2627pub struct Map<'hir> {
2728 pub(super) tcx: TyCtxt<'hir>,
......@@ -273,7 +274,7 @@ impl<'tcx> TyCtxt<'tcx> {
273274 self.hir_maybe_body_owned_by(id).unwrap_or_else(|| {
274275 let hir_id = self.local_def_id_to_hir_id(id);
275276 span_bug!(
276 self.hir().span(hir_id),
277 self.hir_span(hir_id),
277278 "body_owned_by: {} has no associated body",
278279 self.hir_id_to_string(hir_id)
279280 );
......@@ -677,9 +678,8 @@ impl<'tcx> TyCtxt<'tcx> {
677678 pub fn hir_id_to_string(self, id: HirId) -> String {
678679 let path_str = |def_id: LocalDefId| self.def_path_str(def_id);
679680
680 let span_str = || {
681 self.sess.source_map().span_to_snippet(Map { tcx: self }.span(id)).unwrap_or_default()
682 };
681 let span_str =
682 || self.sess.source_map().span_to_snippet(self.hir_span(id)).unwrap_or_default();
683683 let node_str = |prefix| format!("{id} ({prefix} `{}`)", span_str());
684684
685685 match self.hir_node(id) {
......@@ -875,12 +875,10 @@ impl<'tcx> TyCtxt<'tcx> {
875875 pub fn hir_attrs(self, id: HirId) -> &'tcx [Attribute] {
876876 self.hir_attr_map(id.owner).get(id.local_id)
877877 }
878}
879878
880impl<'hir> Map<'hir> {
881879 /// Gets the span of the definition of the specified HIR node.
882880 /// This is used by `tcx.def_span`.
883 pub fn span(self, hir_id: HirId) -> Span {
881 pub fn hir_span(self, hir_id: HirId) -> Span {
884882 fn until_within(outer: Span, end: Span) -> Span {
885883 if let Some(end) = end.find_ancestor_inside(outer) {
886884 outer.with_hi(end.hi())
......@@ -900,7 +898,7 @@ impl<'hir> Map<'hir> {
900898 span
901899 }
902900
903 let span = match self.tcx.hir_node(hir_id) {
901 let span = match self.hir_node(hir_id) {
904902 // Function-like.
905903 Node::Item(Item { kind: ItemKind::Fn { sig, .. }, span: outer_span, .. })
906904 | Node::TraitItem(TraitItem {
......@@ -980,7 +978,7 @@ impl<'hir> Map<'hir> {
980978 Node::Variant(variant) => named_span(variant.span, variant.ident, None),
981979 Node::ImplItem(item) => named_span(item.span, item.ident, Some(item.generics)),
982980 Node::ForeignItem(item) => named_span(item.span, item.ident, None),
983 Node::Ctor(_) => return self.span(self.tcx.parent_hir_id(hir_id)),
981 Node::Ctor(_) => return self.hir_span(self.parent_hir_id(hir_id)),
984982 Node::Expr(Expr {
985983 kind: ExprKind::Closure(Closure { fn_decl_span, .. }),
986984 span,
......@@ -989,16 +987,16 @@ impl<'hir> Map<'hir> {
989987 // Ensure that the returned span has the item's SyntaxContext.
990988 fn_decl_span.find_ancestor_inside(*span).unwrap_or(*span)
991989 }
992 _ => self.span_with_body(hir_id),
990 _ => self.hir_span_with_body(hir_id),
993991 };
994 debug_assert_eq!(span.ctxt(), self.span_with_body(hir_id).ctxt());
992 debug_assert_eq!(span.ctxt(), self.hir_span_with_body(hir_id).ctxt());
995993 span
996994 }
997995
998 /// Like `hir.span()`, but includes the body of items
996 /// Like `hir_span()`, but includes the body of items
999997 /// (instead of just the item header)
1000 pub fn span_with_body(self, hir_id: HirId) -> Span {
1001 match self.tcx.hir_node(hir_id) {
998 pub fn hir_span_with_body(self, hir_id: HirId) -> Span {
999 match self.hir_node(hir_id) {
10021000 Node::Param(param) => param.span,
10031001 Node::Item(item) => item.span,
10041002 Node::ForeignItem(foreign_item) => foreign_item.span,
......@@ -1007,7 +1005,7 @@ impl<'hir> Map<'hir> {
10071005 Node::Variant(variant) => variant.span,
10081006 Node::Field(field) => field.span,
10091007 Node::AnonConst(constant) => constant.span,
1010 Node::ConstBlock(constant) => self.tcx.hir_body(constant.body).value.span,
1008 Node::ConstBlock(constant) => self.hir_body(constant.body).value.span,
10111009 Node::ConstArg(const_arg) => const_arg.span(),
10121010 Node::Expr(expr) => expr.span,
10131011 Node::ExprField(field) => field.span,
......@@ -1027,7 +1025,7 @@ impl<'hir> Map<'hir> {
10271025 Node::PatExpr(lit) => lit.span,
10281026 Node::Arm(arm) => arm.span,
10291027 Node::Block(block) => block.span,
1030 Node::Ctor(..) => self.span_with_body(self.tcx.parent_hir_id(hir_id)),
1028 Node::Ctor(..) => self.hir_span_with_body(self.parent_hir_id(hir_id)),
10311029 Node::Lifetime(lifetime) => lifetime.ident.span,
10321030 Node::GenericParam(param) => param.span,
10331031 Node::Infer(i) => i.span,
......@@ -1040,23 +1038,23 @@ impl<'hir> Map<'hir> {
10401038 }
10411039 }
10421040
1043 pub fn span_if_local(self, id: DefId) -> Option<Span> {
1044 id.is_local().then(|| self.tcx.def_span(id))
1041 pub fn hir_span_if_local(self, id: DefId) -> Option<Span> {
1042 id.is_local().then(|| self.def_span(id))
10451043 }
10461044
1047 pub fn res_span(self, res: Res) -> Option<Span> {
1045 pub fn hir_res_span(self, res: Res) -> Option<Span> {
10481046 match res {
10491047 Res::Err => None,
1050 Res::Local(id) => Some(self.span(id)),
1051 res => self.span_if_local(res.opt_def_id()?),
1048 Res::Local(id) => Some(self.hir_span(id)),
1049 res => self.hir_span_if_local(res.opt_def_id()?),
10521050 }
10531051 }
10541052
10551053 /// Returns the HirId of `N` in `struct Foo<const N: usize = { ... }>` when
10561054 /// called with the HirId for the `{ ... }` anon const
1057 pub fn opt_const_param_default_param_def_id(self, anon_const: HirId) -> Option<LocalDefId> {
1058 let const_arg = self.tcx.parent_hir_id(anon_const);
1059 match self.tcx.parent_hir_node(const_arg) {
1055 pub fn hir_opt_const_param_default_param_def_id(self, anon_const: HirId) -> Option<LocalDefId> {
1056 let const_arg = self.parent_hir_id(anon_const);
1057 match self.parent_hir_node(const_arg) {
10601058 Node::GenericParam(GenericParam {
10611059 def_id: param_id,
10621060 kind: GenericParamKind::Const { .. },
......@@ -1066,7 +1064,7 @@ impl<'hir> Map<'hir> {
10661064 }
10671065 }
10681066
1069 pub fn maybe_get_struct_pattern_shorthand_field(&self, expr: &Expr<'_>) -> Option<Symbol> {
1067 pub fn hir_maybe_get_struct_pattern_shorthand_field(self, expr: &Expr<'_>) -> Option<Symbol> {
10701068 let local = match expr {
10711069 Expr {
10721070 kind:
......@@ -1081,7 +1079,7 @@ impl<'hir> Map<'hir> {
10811079 _ => None,
10821080 }?;
10831081
1084 match self.tcx.parent_hir_node(expr.hir_id) {
1082 match self.parent_hir_node(expr.hir_id) {
10851083 Node::ExprField(field) => {
10861084 if field.ident.name == local.name && field.is_shorthand {
10871085 return Some(local.name);
compiler/rustc_middle/src/hir/mod.rs+2-3
......@@ -210,13 +210,12 @@ pub fn provide(providers: &mut Providers) {
210210 providers.hir_attr_map = |tcx, id| {
211211 tcx.hir_crate(()).owners[id.def_id].as_owner().map_or(AttributeMap::EMPTY, |o| &o.attrs)
212212 };
213 providers.def_span = |tcx, def_id| tcx.hir().span(tcx.local_def_id_to_hir_id(def_id));
213 providers.def_span = |tcx, def_id| tcx.hir_span(tcx.local_def_id_to_hir_id(def_id));
214214 providers.def_ident_span = |tcx, def_id| {
215215 let hir_id = tcx.local_def_id_to_hir_id(def_id);
216216 tcx.hir_opt_ident_span(hir_id)
217217 };
218218 providers.fn_arg_names = |tcx, def_id| {
219 let hir = tcx.hir();
220219 if let Some(body_id) = tcx.hir_node_by_def_id(def_id).body_id() {
221220 tcx.arena.alloc_from_iter(tcx.hir_body_param_names(body_id))
222221 } else if let Node::TraitItem(&TraitItem {
......@@ -231,7 +230,7 @@ pub fn provide(providers: &mut Providers) {
231230 idents
232231 } else {
233232 span_bug!(
234 hir.span(tcx.local_def_id_to_hir_id(def_id)),
233 tcx.hir_span(tcx.local_def_id_to_hir_id(def_id)),
235234 "fn_arg_names: unexpected item {:?}",
236235 def_id
237236 );
compiler/rustc_middle/src/middle/region.rs+1-1
......@@ -175,7 +175,7 @@ impl Scope {
175175 let Some(hir_id) = self.hir_id(scope_tree) else {
176176 return DUMMY_SP;
177177 };
178 let span = tcx.hir().span(hir_id);
178 let span = tcx.hir_span(hir_id);
179179 if let ScopeData::Remainder(first_statement_index) = self.data {
180180 if let Node::Block(blk) = tcx.hir_node(hir_id) {
181181 // Want span for scope starting after the
compiler/rustc_middle/src/query/keys.rs+2-2
......@@ -586,7 +586,7 @@ impl Key for HirId {
586586 type Cache<V> = DefaultCache<Self, V>;
587587
588588 fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
589 tcx.hir().span(*self)
589 tcx.hir_span(*self)
590590 }
591591
592592 #[inline(always)]
......@@ -599,7 +599,7 @@ impl Key for (LocalDefId, HirId) {
599599 type Cache<V> = DefaultCache<Self, V>;
600600
601601 fn default_span(&self, tcx: TyCtxt<'_>) -> Span {
602 tcx.hir().span(self.1)
602 tcx.hir_span(self.1)
603603 }
604604
605605 #[inline(always)]
compiler/rustc_middle/src/ty/closure.rs+4-4
......@@ -150,9 +150,9 @@ impl<'tcx> CapturedPlace<'tcx> {
150150 /// Return span pointing to use that resulted in selecting the captured path
151151 pub fn get_path_span(&self, tcx: TyCtxt<'tcx>) -> Span {
152152 if let Some(path_expr_id) = self.info.path_expr_id {
153 tcx.hir().span(path_expr_id)
153 tcx.hir_span(path_expr_id)
154154 } else if let Some(capture_kind_expr_id) = self.info.capture_kind_expr_id {
155 tcx.hir().span(capture_kind_expr_id)
155 tcx.hir_span(capture_kind_expr_id)
156156 } else {
157157 // Fallback on upvars mentioned if neither path or capture expr id is captured
158158
......@@ -166,9 +166,9 @@ impl<'tcx> CapturedPlace<'tcx> {
166166 /// Return span pointing to use that resulted in selecting the current capture kind
167167 pub fn get_capture_kind_span(&self, tcx: TyCtxt<'tcx>) -> Span {
168168 if let Some(capture_kind_expr_id) = self.info.capture_kind_expr_id {
169 tcx.hir().span(capture_kind_expr_id)
169 tcx.hir_span(capture_kind_expr_id)
170170 } else if let Some(path_expr_id) = self.info.path_expr_id {
171 tcx.hir().span(path_expr_id)
171 tcx.hir_span(path_expr_id)
172172 } else {
173173 // Fallback on upvars mentioned if neither path or capture expr id is captured
174174
compiler/rustc_middle/src/ty/instance.rs+2-2
......@@ -720,7 +720,7 @@ impl<'tcx> Instance<'tcx> {
720720 ty::TypingEnv::fully_monomorphized(),
721721 def_id,
722722 args,
723 ty.ty_adt_def().and_then(|adt| tcx.hir().span_if_local(adt.did())).unwrap_or(DUMMY_SP),
723 ty.ty_adt_def().and_then(|adt| tcx.hir_span_if_local(adt.did())).unwrap_or(DUMMY_SP),
724724 )
725725 }
726726
......@@ -732,7 +732,7 @@ impl<'tcx> Instance<'tcx> {
732732 ty::TypingEnv::fully_monomorphized(),
733733 def_id,
734734 args,
735 ty.ty_adt_def().and_then(|adt| tcx.hir().span_if_local(adt.did())).unwrap_or(DUMMY_SP),
735 ty.ty_adt_def().and_then(|adt| tcx.hir_span_if_local(adt.did())).unwrap_or(DUMMY_SP),
736736 )
737737 }
738738
compiler/rustc_mir_build/src/builder/expr/as_place.rs+1-1
......@@ -258,7 +258,7 @@ impl<'tcx> PlaceBuilder<'tcx> {
258258 self.projection
259259 ),
260260 PlaceBase::Upvar { var_hir_id, closure_def_id: _ } => span_bug!(
261 cx.tcx.hir().span(var_hir_id.0),
261 cx.tcx.hir_span(var_hir_id.0),
262262 "could not resolve upvar: {var_hir_id:?} + {:?}",
263263 self.projection
264264 ),
compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs+1-1
......@@ -416,7 +416,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
416416 if let Some(mir_place) = place_builder.try_to_place(this) {
417417 this.cfg.push_fake_read(
418418 block,
419 this.source_info(this.tcx.hir().span(*hir_id)),
419 this.source_info(this.tcx.hir_span(*hir_id)),
420420 *cause,
421421 mir_place,
422422 );
compiler/rustc_mir_build/src/builder/mod.rs+1-1
......@@ -457,7 +457,7 @@ fn construct_fn<'tcx>(
457457
458458 // Figure out what primary body this item has.
459459 let body = tcx.hir_body_owned_by(fn_def);
460 let span_with_body = tcx.hir().span_with_body(fn_id);
460 let span_with_body = tcx.hir_span_with_body(fn_id);
461461 let return_ty_span = tcx
462462 .hir_fn_decl_by_hir_id(fn_id)
463463 .unwrap_or_else(|| span_bug!(span, "can't build MIR for {:?}", fn_def))
compiler/rustc_mir_build/src/check_unsafety.rs+1-1
......@@ -943,7 +943,7 @@ impl UnsafeOpKind {
943943 }
944944 });
945945 let unsafe_not_inherited_note = if let Some((id, _)) = note_non_inherited {
946 let span = tcx.hir().span(id);
946 let span = tcx.hir_span(id);
947947 let span = tcx.sess.source_map().guess_head_span(span);
948948 Some(UnsafeNotInheritedNote { span })
949949 } else {
compiler/rustc_mir_build/src/thir/pattern/check_match.rs+1-1
......@@ -1174,7 +1174,7 @@ fn report_arm_reachability<'p, 'tcx>(
11741174 for (arm, is_useful) in report.arm_usefulness.iter() {
11751175 if let Usefulness::Redundant(explanation) = is_useful {
11761176 let hir_id = arm.arm_data;
1177 let arm_span = cx.tcx.hir().span(hir_id);
1177 let arm_span = cx.tcx.hir_span(hir_id);
11781178 let whole_arm_span = if is_match_arm {
11791179 // If the arm is followed by a comma, extend the span to include it.
11801180 let with_whitespace = sm.span_extend_while_whitespace(arm_span);
compiler/rustc_passes/src/check_attr.rs+3-3
......@@ -1157,7 +1157,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
11571157 errors::DocInlineOnlyUse {
11581158 attr_span: meta.span(),
11591159 item_span: (attr.style() == AttrStyle::Outer)
1160 .then(|| self.tcx.hir().span(hir_id)),
1160 .then(|| self.tcx.hir_span(hir_id)),
11611161 },
11621162 );
11631163 }
......@@ -1179,7 +1179,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
11791179 errors::DocMaskedOnlyExternCrate {
11801180 attr_span: meta.span(),
11811181 item_span: (attr.style() == AttrStyle::Outer)
1182 .then(|| self.tcx.hir().span(hir_id)),
1182 .then(|| self.tcx.hir_span(hir_id)),
11831183 },
11841184 );
11851185 return;
......@@ -1193,7 +1193,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
11931193 errors::DocMaskedNotExternCrateSelf {
11941194 attr_span: meta.span(),
11951195 item_span: (attr.style() == AttrStyle::Outer)
1196 .then(|| self.tcx.hir().span(hir_id)),
1196 .then(|| self.tcx.hir_span(hir_id)),
11971197 },
11981198 );
11991199 }
compiler/rustc_passes/src/diagnostic_items.rs+2-2
......@@ -41,8 +41,8 @@ fn report_duplicate_item(
4141 original_def_id: DefId,
4242 item_def_id: DefId,
4343) {
44 let orig_span = tcx.hir().span_if_local(original_def_id);
45 let duplicate_span = tcx.hir().span_if_local(item_def_id);
44 let orig_span = tcx.hir_span_if_local(original_def_id);
45 let duplicate_span = tcx.hir_span_if_local(item_def_id);
4646 tcx.dcx().emit_err(DuplicateDiagnosticItemInCrate {
4747 duplicate_span,
4848 orig_span,
compiler/rustc_passes/src/stability.rs+2-2
......@@ -726,7 +726,7 @@ fn stability_index(tcx: TyCtxt<'_>, (): ()) -> Index {
726726
727727 annotator.annotate(
728728 CRATE_DEF_ID,
729 tcx.hir().span(CRATE_HIR_ID),
729 tcx.hir_span(CRATE_HIR_ID),
730730 None,
731731 AnnotationKind::Required,
732732 InheritDeprecation::Yes,
......@@ -1099,7 +1099,7 @@ pub fn check_unused_or_stable_features(tcx: TyCtxt<'_>) {
10991099 if is_staged_api {
11001100 let effective_visibilities = &tcx.effective_visibilities(());
11011101 let mut missing = MissingStabilityAnnotations { tcx, effective_visibilities };
1102 missing.check_missing_stability(CRATE_DEF_ID, tcx.hir().span(CRATE_HIR_ID));
1102 missing.check_missing_stability(CRATE_DEF_ID, tcx.hir_span(CRATE_HIR_ID));
11031103 tcx.hir_walk_toplevel_module(&mut missing);
11041104 tcx.hir_visit_all_item_likes_in_crate(&mut missing);
11051105 }
compiler/rustc_resolve/src/lib.rs+2
......@@ -88,6 +88,8 @@ mod late;
8888mod macros;
8989pub mod rustdoc;
9090
91pub use macros::registered_tools_ast;
92
9193rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
9294
9395#[derive(Debug)]
compiler/rustc_resolve/src/macros.rs+11-4
......@@ -10,7 +10,7 @@ use rustc_ast::{self as ast, Crate, NodeId, attr};
1010use rustc_ast_pretty::pprust;
1111use rustc_attr_parsing::{AttributeKind, StabilityLevel, find_attr};
1212use rustc_data_structures::intern::Interned;
13use rustc_errors::{Applicability, StashKey};
13use rustc_errors::{Applicability, DiagCtxtHandle, StashKey};
1414use rustc_expand::base::{
1515 DeriveResolution, Indeterminate, ResolverExpand, SyntaxExtension, SyntaxExtensionKind,
1616};
......@@ -124,14 +124,21 @@ fn fast_print_path(path: &ast::Path) -> Symbol {
124124}
125125
126126pub(crate) fn registered_tools(tcx: TyCtxt<'_>, (): ()) -> RegisteredTools {
127 let mut registered_tools = RegisteredTools::default();
128127 let (_, pre_configured_attrs) = &*tcx.crate_for_resolver(()).borrow();
128 registered_tools_ast(tcx.dcx(), pre_configured_attrs)
129}
130
131pub fn registered_tools_ast(
132 dcx: DiagCtxtHandle<'_>,
133 pre_configured_attrs: &[ast::Attribute],
134) -> RegisteredTools {
135 let mut registered_tools = RegisteredTools::default();
129136 for attr in attr::filter_by_name(pre_configured_attrs, sym::register_tool) {
130137 for meta_item_inner in attr.meta_item_list().unwrap_or_default() {
131138 match meta_item_inner.ident() {
132139 Some(ident) => {
133140 if let Some(old_ident) = registered_tools.replace(ident) {
134 tcx.dcx().emit_err(errors::ToolWasAlreadyRegistered {
141 dcx.emit_err(errors::ToolWasAlreadyRegistered {
135142 span: ident.span,
136143 tool: ident,
137144 old_ident_span: old_ident.span,
......@@ -139,7 +146,7 @@ pub(crate) fn registered_tools(tcx: TyCtxt<'_>, (): ()) -> RegisteredTools {
139146 }
140147 }
141148 None => {
142 tcx.dcx().emit_err(errors::ToolOnlyAcceptsIdentifiers {
149 dcx.emit_err(errors::ToolOnlyAcceptsIdentifiers {
143150 span: meta_item_inner.span(),
144151 tool: sym::register_tool,
145152 });
compiler/rustc_session/src/config.rs+3
......@@ -50,6 +50,7 @@ pub const PRINT_KINDS: &[(&str, PrintKind)] = &[
5050 ("check-cfg", PrintKind::CheckCfg),
5151 ("code-models", PrintKind::CodeModels),
5252 ("crate-name", PrintKind::CrateName),
53 ("crate-root-lint-levels", PrintKind::CrateRootLintLevels),
5354 ("deployment-target", PrintKind::DeploymentTarget),
5455 ("file-names", PrintKind::FileNames),
5556 ("host-tuple", PrintKind::HostTuple),
......@@ -881,6 +882,7 @@ pub enum PrintKind {
881882 CheckCfg,
882883 CodeModels,
883884 CrateName,
885 CrateRootLintLevels,
884886 DeploymentTarget,
885887 FileNames,
886888 HostTuple,
......@@ -2067,6 +2069,7 @@ fn check_print_request_stability(
20672069 match print_kind {
20682070 PrintKind::AllTargetSpecsJson
20692071 | PrintKind::CheckCfg
2072 | PrintKind::CrateRootLintLevels
20702073 | PrintKind::SupportedCrateTypes
20712074 | PrintKind::TargetSpecJson
20722075 if !unstable_opts.unstable_options =>
compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs+3-3
......@@ -1051,7 +1051,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
10511051 None?
10521052 }
10531053 let args = self.node_args_opt(expr.hir_id)?;
1054 let span = tcx.hir().span(segment.hir_id);
1054 let span = tcx.hir_span(segment.hir_id);
10551055 let insert_span = segment.ident.span.shrink_to_hi().with_hi(span.hi());
10561056 InsertableGenericArgs {
10571057 insert_span,
......@@ -1110,7 +1110,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
11101110 if generics.has_impl_trait() {
11111111 return None;
11121112 }
1113 let span = tcx.hir().span(segment.hir_id);
1113 let span = tcx.hir_span(segment.hir_id);
11141114 let insert_span = segment.ident.span.shrink_to_hi().with_hi(span.hi());
11151115 Some(InsertableGenericArgs {
11161116 insert_span,
......@@ -1144,7 +1144,7 @@ impl<'a, 'tcx> FindInferSourceVisitor<'a, 'tcx> {
11441144 if !segment.infer_args || generics.has_impl_trait() {
11451145 do yeet ();
11461146 }
1147 let span = tcx.hir().span(segment.hir_id);
1147 let span = tcx.hir_span(segment.hir_id);
11481148 let insert_span = segment.ident.span.shrink_to_hi().with_hi(span.hi());
11491149 InsertableGenericArgs {
11501150 insert_span,
compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/util.rs+1-2
......@@ -51,7 +51,6 @@ pub fn find_param_with_region<'tcx>(
5151 _ => return None, // not a free region
5252 };
5353
54 let hir = &tcx.hir();
5554 let def_id = id.as_local()?;
5655
5756 // FIXME: use def_kind
......@@ -93,7 +92,7 @@ pub fn find_param_with_region<'tcx>(
9392 });
9493 found_anon_region.then(|| {
9594 let ty_hir_id = fn_decl.inputs[index].hir_id;
96 let param_ty_span = hir.span(ty_hir_id);
95 let param_ty_span = tcx.hir_span(ty_hir_id);
9796 let is_first = index == 0;
9897 AnonymousParamInfo { param, param_ty: new_param_ty, param_ty_span, kind, is_first }
9998 })
compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs+3-4
......@@ -1236,7 +1236,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
12361236 );
12371237 // Only suggest derive if this isn't a derived obligation,
12381238 // and the struct is local.
1239 if let Some(span) = self.tcx.hir().span_if_local(def.did())
1239 if let Some(span) = self.tcx.hir_span_if_local(def.did())
12401240 && obligation.cause.code().parent().is_none()
12411241 {
12421242 if ty.is_structural_eq_shallow(self.tcx) {
......@@ -2943,7 +2943,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
29432943 };
29442944
29452945 let found_node = found_did.and_then(|did| self.tcx.hir_get_if_local(did));
2946 let found_span = found_did.and_then(|did| self.tcx.hir().span_if_local(did));
2946 let found_span = found_did.and_then(|did| self.tcx.hir_span_if_local(did));
29472947
29482948 if !self.reported_signature_mismatch.borrow_mut().insert((span, found_span)) {
29492949 // We check closures twice, with obligations flowing in different directions,
......@@ -3030,7 +3030,6 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
30303030 node: Node<'_>,
30313031 ) -> Option<(Span, Option<Span>, Vec<ArgKind>)> {
30323032 let sm = self.tcx.sess.source_map();
3033 let hir = self.tcx.hir();
30343033 Some(match node {
30353034 Node::Expr(&hir::Expr {
30363035 kind: hir::ExprKind::Closure(&hir::Closure { body, fn_decl_span, fn_arg_span, .. }),
......@@ -3086,7 +3085,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
30863085 .collect::<Vec<ArgKind>>(),
30873086 ),
30883087 Node::Ctor(variant_data) => {
3089 let span = variant_data.ctor_hir_id().map_or(DUMMY_SP, |id| hir.span(id));
3088 let span = variant_data.ctor_hir_id().map_or(DUMMY_SP, |id| self.tcx.hir_span(id));
30903089 (span, None, vec![ArgKind::empty(); variant_data.fields().len()])
30913090 }
30923091 _ => panic!("non-FnLike node found: {node:?}"),
compiler/rustc_trait_selection/src/error_reporting/traits/mod.rs+1-1
......@@ -398,7 +398,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
398398 );
399399
400400 if !self.tcx.is_impl_trait_in_trait(trait_item_def_id) {
401 if let Some(span) = self.tcx.hir().span_if_local(trait_item_def_id) {
401 if let Some(span) = self.tcx.hir_span_if_local(trait_item_def_id) {
402402 let item_name = self.tcx.item_name(impl_item_def_id.to_def_id());
403403 err.span_label(span, format!("definition of `{item_name}` from trait"));
404404 }
compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs+5-5
......@@ -1193,7 +1193,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
11931193 // FIXME(compiler-errors): This is kind of a mess, but required for obligations
11941194 // that come from a path expr to affect the *call* expr.
11951195 c @ ObligationCauseCode::WhereClauseInExpr(_, _, hir_id, _)
1196 if self.tcx.hir().span(*hir_id).lo() == span.lo() =>
1196 if self.tcx.hir_span(*hir_id).lo() == span.lo() =>
11971197 {
11981198 c
11991199 }
......@@ -4481,7 +4481,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
44814481 Obligation::new(self.tcx, obligation.cause.clone(), obligation.param_env, trait_ref);
44824482
44834483 if self.predicate_must_hold_modulo_regions(&obligation) {
4484 let arg_span = self.tcx.hir().span(*arg_hir_id);
4484 let arg_span = self.tcx.hir_span(*arg_hir_id);
44854485 err.multipart_suggestion_verbose(
44864486 format!("use a unary tuple instead"),
44874487 vec![(arg_span.shrink_to_lo(), "(".into()), (arg_span.shrink_to_hi(), ",)".into())],
......@@ -4521,7 +4521,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
45214521 parent_code: _,
45224522 } = cause.code()
45234523 {
4524 let arg_span = self.tcx.hir().span(*arg_hir_id);
4524 let arg_span = self.tcx.hir_span(*arg_hir_id);
45254525 let mut sp: MultiSpan = arg_span.into();
45264526
45274527 sp.push_span_label(
......@@ -4530,7 +4530,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
45304530 generic types that should be inferred from this argument",
45314531 );
45324532 sp.push_span_label(
4533 self.tcx.hir().span(*call_hir_id),
4533 self.tcx.hir_span(*call_hir_id),
45344534 "add turbofish arguments to this call to \
45354535 specify the types manually, even if it's redundant",
45364536 );
......@@ -4939,7 +4939,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
49394939 .type_implements_trait(pred.def_id(), [rhs_ty, lhs_ty], param_env)
49404940 .must_apply_modulo_regions()
49414941 {
4942 let lhs_span = tcx.hir().span(lhs_hir_id);
4942 let lhs_span = tcx.hir_span(lhs_hir_id);
49434943 let sm = tcx.sess.source_map();
49444944 if let Ok(rhs_snippet) = sm.span_to_snippet(rhs_span)
49454945 && let Ok(lhs_snippet) = sm.span_to_snippet(lhs_span)
library/Cargo.toml+3
......@@ -38,8 +38,11 @@ adler2.debug = 0
3838gimli.debug = 0
3939gimli.opt-level = "s"
4040miniz_oxide.debug = 0
41miniz_oxide.opt-level = "s"
42# `opt-level = "s"` for `object` led to a size regression when tried previously
4143object.debug = 0
4244rustc-demangle.debug = 0
45rustc-demangle.opt-level = "s"
4346
4447[patch.crates-io]
4548# See comments in `library/rustc-std-workspace-core/README.md` for what's going on
src/doc/unstable-book/src/compiler-flags/print-crate-root-lint-levels.md created+23
......@@ -0,0 +1,23 @@
1# `print=crate-root-lint-levels`
2
3The tracking issue for this feature is: [#139180](https://github.com/rust-lang/rust/issues/139180).
4
5------------------------
6
7This option of the `--print` flag print the list of lints with print out all the lints and their associated levels (`allow`, `warn`, `deny`, `forbid`) based on the regular Rust rules at crate root, that is *(roughly)*:
8 - command line args (`-W`, `-A`, `--force-warn`, `--cap-lints`, ...)
9 - crate root attributes (`#![allow]`, `#![warn]`, `#[expect]`, ...)
10 - *the special `warnings` lint group*
11 - the default lint level
12
13The output format is `LINT_NAME=LINT_LEVEL`, e.g.:
14```text
15unknown_lint=warn
16arithmetic_overflow=deny
17```
18
19To be used like this:
20
21```bash
22rustc --print=crate-root-lint-levels -Zunstable-options lib.rs
23```
src/librustdoc/clean/types.rs+1-4
......@@ -367,10 +367,7 @@ impl fmt::Debug for Item {
367367pub(crate) fn rustc_span(def_id: DefId, tcx: TyCtxt<'_>) -> Span {
368368 Span::new(def_id.as_local().map_or_else(
369369 || tcx.def_span(def_id),
370 |local| {
371 let hir = tcx.hir();
372 hir.span_with_body(tcx.local_def_id_to_hir_id(local))
373 },
370 |local| tcx.hir_span_with_body(tcx.local_def_id_to_hir_id(local)),
374371 ))
375372}
376373
src/librustdoc/doctest/rust.rs+1-1
......@@ -80,7 +80,7 @@ impl<'tcx> HirCollector<'tcx> {
8080
8181 pub fn collect_crate(mut self) -> Vec<ScrapedDocTest> {
8282 let tcx = self.tcx;
83 self.visit_testable(None, CRATE_DEF_ID, tcx.hir().span(CRATE_HIR_ID), |this| {
83 self.visit_testable(None, CRATE_DEF_ID, tcx.hir_span(CRATE_HIR_ID), |this| {
8484 tcx.hir_walk_toplevel_module(this)
8585 });
8686 self.collector.tests
src/librustdoc/html/render/span_map.rs+1-1
......@@ -95,7 +95,7 @@ impl SpanMapVisitor<'_> {
9595 .unwrap_or(path.span);
9696 self.matches.insert(span, link);
9797 }
98 Res::Local(_) if let Some(span) = self.tcx.hir().res_span(path.res) => {
98 Res::Local(_) if let Some(span) = self.tcx.hir_res_span(path.res) => {
9999 self.matches.insert(path.span, LinkFromSrc::Local(clean::Span::new(span)));
100100 }
101101 Res::PrimTy(p) => {
src/librustdoc/scrape_examples.rs+1-2
......@@ -176,8 +176,7 @@ where
176176
177177 // If the enclosing item has a span coming from a proc macro, then we also don't want to
178178 // include the example.
179 let enclosing_item_span =
180 tcx.hir().span_with_body(tcx.hir_get_parent_item(ex.hir_id).into());
179 let enclosing_item_span = tcx.hir_span_with_body(tcx.hir_get_parent_item(ex.hir_id).into());
181180 if enclosing_item_span.from_expansion() {
182181 trace!("Rejecting expr ({call_span:?}) from macro item: {enclosing_item_span:?}");
183182 return;
src/tools/clippy/clippy_lints/src/casts/unnecessary_cast.rs+1-1
......@@ -143,7 +143,7 @@ pub(super) fn check<'tcx>(
143143
144144 if cast_from.kind() == cast_to.kind() && !expr.span.in_external_macro(cx.sess().source_map()) {
145145 if let Some(id) = path_to_local(cast_expr)
146 && !cx.tcx.hir().span(id).eq_ctxt(cast_expr.span)
146 && !cx.tcx.hir_span(id).eq_ctxt(cast_expr.span)
147147 {
148148 // Binding context is different than the identifiers context.
149149 // Weird macro wizardry could be involved here.
src/tools/clippy/clippy_lints/src/derive.rs+2-2
......@@ -254,7 +254,7 @@ fn check_hash_peq<'tcx>(
254254 |diag| {
255255 if let Some(local_def_id) = impl_id.as_local() {
256256 let hir_id = cx.tcx.local_def_id_to_hir_id(local_def_id);
257 diag.span_note(cx.tcx.hir().span(hir_id), "`PartialEq` implemented here");
257 diag.span_note(cx.tcx.hir_span(hir_id), "`PartialEq` implemented here");
258258 }
259259 },
260260 );
......@@ -298,7 +298,7 @@ fn check_ord_partial_ord<'tcx>(
298298 span_lint_and_then(cx, DERIVE_ORD_XOR_PARTIAL_ORD, span, mess, |diag| {
299299 if let Some(local_def_id) = impl_id.as_local() {
300300 let hir_id = cx.tcx.local_def_id_to_hir_id(local_def_id);
301 diag.span_note(cx.tcx.hir().span(hir_id), "`PartialOrd` implemented here");
301 diag.span_note(cx.tcx.hir_span(hir_id), "`PartialOrd` implemented here");
302302 }
303303 });
304304 }
src/tools/clippy/clippy_lints/src/escape.rs+1-1
......@@ -120,7 +120,7 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
120120 cx,
121121 BOXED_LOCAL,
122122 node,
123 cx.tcx.hir().span(node),
123 cx.tcx.hir_span(node),
124124 "local variable doesn't need to be boxed here",
125125 );
126126 }
src/tools/clippy/clippy_lints/src/index_refutable_slice.rs+1-1
......@@ -248,7 +248,7 @@ impl<'tcx> Visitor<'tcx> for SliceIndexLintingVisitor<'_, 'tcx> {
248248 {
249249 use_info
250250 .index_use
251 .push((index_value, cx.tcx.hir().span(parent_expr.hir_id)));
251 .push((index_value, cx.tcx.hir_span(parent_expr.hir_id)));
252252 return;
253253 }
254254
src/tools/clippy/clippy_lints/src/loops/mut_range_bound.rs+4-4
......@@ -85,10 +85,10 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> {
8585 if bk == ty::BorrowKind::Mutable {
8686 if let PlaceBase::Local(id) = cmt.place.base {
8787 if Some(id) == self.hir_id_low && !BreakAfterExprVisitor::is_found(self.cx, diag_expr_id) {
88 self.span_low = Some(self.cx.tcx.hir().span(diag_expr_id));
88 self.span_low = Some(self.cx.tcx.hir_span(diag_expr_id));
8989 }
9090 if Some(id) == self.hir_id_high && !BreakAfterExprVisitor::is_found(self.cx, diag_expr_id) {
91 self.span_high = Some(self.cx.tcx.hir().span(diag_expr_id));
91 self.span_high = Some(self.cx.tcx.hir_span(diag_expr_id));
9292 }
9393 }
9494 }
......@@ -97,10 +97,10 @@ impl<'tcx> Delegate<'tcx> for MutatePairDelegate<'_, 'tcx> {
9797 fn mutate(&mut self, cmt: &PlaceWithHirId<'tcx>, diag_expr_id: HirId) {
9898 if let PlaceBase::Local(id) = cmt.place.base {
9999 if Some(id) == self.hir_id_low && !BreakAfterExprVisitor::is_found(self.cx, diag_expr_id) {
100 self.span_low = Some(self.cx.tcx.hir().span(diag_expr_id));
100 self.span_low = Some(self.cx.tcx.hir_span(diag_expr_id));
101101 }
102102 if Some(id) == self.hir_id_high && !BreakAfterExprVisitor::is_found(self.cx, diag_expr_id) {
103 self.span_high = Some(self.cx.tcx.hir().span(diag_expr_id));
103 self.span_high = Some(self.cx.tcx.hir_span(diag_expr_id));
104104 }
105105 }
106106 }
src/tools/clippy/clippy_lints/src/macro_metavars_in_unsafe.rs+1-1
......@@ -253,7 +253,7 @@ impl<'tcx> LateLintPass<'tcx> for ExprMetavarsInUnsafe {
253253 // Remove the syntax context to hide "in this macro invocation" in the diagnostic.
254254 // The invocation doesn't matter. Also we want to dedupe by the unsafe block and not by anything
255255 // related to the callsite.
256 let span = cx.tcx.hir().span(id);
256 let span = cx.tcx.hir_span(id);
257257
258258 (id, Span::new(span.lo(), span.hi(), SyntaxContext::root(), None))
259259 })
src/tools/clippy/clippy_lints/src/misc.rs+1-1
......@@ -329,7 +329,7 @@ fn used_underscore_binding<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
329329 let name = ident.name.as_str();
330330 if name.starts_with('_')
331331 && !name.starts_with("__")
332 && let definition_span = cx.tcx.hir().span(definition_hir_id)
332 && let definition_span = cx.tcx.hir_span(definition_hir_id)
333333 && !definition_span.from_expansion()
334334 && !fulfill_or_allowed(cx, USED_UNDERSCORE_BINDING, [expr.hir_id, definition_hir_id])
335335 {
src/tools/clippy/clippy_lints/src/needless_pass_by_ref_mut.rs+1-1
......@@ -280,7 +280,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByRefMut<'tcx> {
280280 diag.span_suggestion(
281281 sp,
282282 "consider changing to".to_string(),
283 format!("&{}", snippet(cx, cx.tcx.hir().span(inner_ty.ty.hir_id), "_"),),
283 format!("&{}", snippet(cx, cx.tcx.hir_span(inner_ty.ty.hir_id), "_"),),
284284 Applicability::Unspecified,
285285 );
286286 if cx.effective_visibilities.is_exported(*fn_def_id) {
src/tools/clippy/clippy_lints/src/needless_pass_by_value.rs+1-1
......@@ -198,7 +198,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
198198 // Dereference suggestion
199199 let sugg = |diag: &mut Diag<'_, ()>| {
200200 if let ty::Adt(def, ..) = ty.kind() {
201 if let Some(span) = cx.tcx.hir().span_if_local(def.did()) {
201 if let Some(span) = cx.tcx.hir_span_if_local(def.did()) {
202202 if type_allowed_to_implement_copy(
203203 cx.tcx,
204204 cx.param_env,
src/tools/clippy/clippy_lints/src/operators/arithmetic_side_effects.rs+2-2
......@@ -354,7 +354,7 @@ impl<'tcx> LateLintPass<'tcx> for ArithmeticSideEffects {
354354
355355 let body_owner_kind = cx.tcx.hir_body_owner_kind(body_owner_def_id);
356356 if let hir::BodyOwnerKind::Const { .. } | hir::BodyOwnerKind::Static(_) = body_owner_kind {
357 let body_span = cx.tcx.hir().span_with_body(body_owner);
357 let body_span = cx.tcx.hir_span_with_body(body_owner);
358358 if let Some(span) = self.const_span
359359 && span.contains(body_span)
360360 {
......@@ -366,7 +366,7 @@ impl<'tcx> LateLintPass<'tcx> for ArithmeticSideEffects {
366366
367367 fn check_body_post(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) {
368368 let body_owner = cx.tcx.hir_body_owner(body.id());
369 let body_span = cx.tcx.hir().span(body_owner);
369 let body_span = cx.tcx.hir_span(body_owner);
370370 if let Some(span) = self.const_span
371371 && span.contains(body_span)
372372 {
src/tools/clippy/clippy_lints/src/operators/numeric_arithmetic.rs+2-2
......@@ -73,7 +73,7 @@ impl Context {
7373
7474 match cx.tcx.hir_body_owner_kind(body_owner_def_id) {
7575 hir::BodyOwnerKind::Static(_) | hir::BodyOwnerKind::Const { .. } => {
76 let body_span = cx.tcx.hir().span_with_body(body_owner);
76 let body_span = cx.tcx.hir_span_with_body(body_owner);
7777
7878 if let Some(span) = self.const_span {
7979 if span.contains(body_span) {
......@@ -88,7 +88,7 @@ impl Context {
8888
8989 pub fn body_post(&mut self, cx: &LateContext<'_>, body: &hir::Body<'_>) {
9090 let body_owner = cx.tcx.hir_body_owner(body.id());
91 let body_span = cx.tcx.hir().span_with_body(body_owner);
91 let body_span = cx.tcx.hir_span_with_body(body_owner);
9292
9393 if let Some(span) = self.const_span {
9494 if span.contains(body_span) {
src/tools/clippy/clippy_lints/src/shadow.rs+1-1
......@@ -218,7 +218,7 @@ fn lint_shadow(cx: &LateContext<'_>, pat: &Pat<'_>, shadowed: HirId, span: Span)
218218 },
219219 };
220220 span_lint_and_then(cx, lint, span, msg, |diag| {
221 diag.span_note(cx.tcx.hir().span(shadowed), "previous binding is here");
221 diag.span_note(cx.tcx.hir_span(shadowed), "previous binding is here");
222222 });
223223}
224224
src/tools/clippy/clippy_lints/src/single_call_fn.rs+1-1
......@@ -137,7 +137,7 @@ impl<'tcx> LateLintPass<'tcx> for SingleCallFn {
137137 for (&def_id, usage) in &self.def_id_to_usage {
138138 if let CallState::Once { call_site } = *usage
139139 && let fn_hir_id = cx.tcx.local_def_id_to_hir_id(def_id)
140 && let fn_span = cx.tcx.hir().span_with_body(fn_hir_id)
140 && let fn_span = cx.tcx.hir_span_with_body(fn_hir_id)
141141 && !self.is_function_allowed(cx, def_id, fn_hir_id, fn_span)
142142 {
143143 span_lint_hir_and_then(
src/tools/clippy/clippy_utils/src/lib.rs+1-1
......@@ -2990,7 +2990,7 @@ pub fn expr_use_ctxt<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'tcx>) -> ExprU
29902990 {
29912991 adjustments = cx.typeck_results().expr_adjustments(e);
29922992 }
2993 same_ctxt &= cx.tcx.hir().span(parent_id).ctxt() == ctxt;
2993 same_ctxt &= cx.tcx.hir_span(parent_id).ctxt() == ctxt;
29942994 if let Node::Expr(e) = parent {
29952995 match e.kind {
29962996 ExprKind::If(e, _, _) | ExprKind::Match(e, _, _) if e.hir_id != child_id => {
src/tools/clippy/clippy_utils/src/macros.rs+1-2
......@@ -178,7 +178,6 @@ pub fn first_node_in_macro(cx: &LateContext<'_>, node: &impl HirNode) -> Option<
178178
179179 // get the parent node, possibly skipping over a statement
180180 // if the parent is not found, it is sensible to return `Some(root)`
181 let hir = cx.tcx.hir();
182181 let mut parent_iter = cx.tcx.hir_parent_iter(node.hir_id());
183182 let (parent_id, _) = match parent_iter.next() {
184183 None => return Some(ExpnId::root()),
......@@ -190,7 +189,7 @@ pub fn first_node_in_macro(cx: &LateContext<'_>, node: &impl HirNode) -> Option<
190189 };
191190
192191 // get the macro expansion of the parent node
193 let parent_span = hir.span(parent_id);
192 let parent_span = cx.tcx.hir_span(parent_id);
194193 let Some(parent_macro_call) = macro_backtrace(parent_span).next() else {
195194 // the parent node is not in a macro
196195 return Some(ExpnId::root());
src/tools/clippy/clippy_utils/src/sugg.rs+1-2
......@@ -839,8 +839,7 @@ impl<'tcx> Delegate<'tcx> for DerefDelegate<'_, 'tcx> {
839839
840840 fn borrow(&mut self, cmt: &PlaceWithHirId<'tcx>, _: HirId, _: ty::BorrowKind) {
841841 if let PlaceBase::Local(id) = cmt.place.base {
842 let map = self.cx.tcx.hir();
843 let span = map.span(cmt.hir_id);
842 let span = self.cx.tcx.hir_span(cmt.hir_id);
844843 let start_span = Span::new(self.next_pos, span.lo(), span.ctxt(), None);
845844 let mut start_snip = snippet_with_applicability(self.cx, start_span, "..", &mut self.applicability);
846845
src/tools/run-make-support/src/external_deps/rustc.rs-14
......@@ -22,12 +22,6 @@ pub fn bare_rustc() -> Rustc {
2222 Rustc::bare()
2323}
2424
25/// Construct a new `rustc` aux-build invocation.
26#[track_caller]
27pub fn aux_build() -> Rustc {
28 Rustc::new_aux_build()
29}
30
3125/// A `rustc` invocation builder.
3226#[derive(Debug)]
3327#[must_use]
......@@ -67,14 +61,6 @@ impl Rustc {
6761 Self { cmd }
6862 }
6963
70 /// Construct a new `rustc` invocation with `aux_build` preset (setting `--crate-type=lib`).
71 #[track_caller]
72 pub fn new_aux_build() -> Self {
73 let mut cmd = setup_common();
74 cmd.arg("--crate-type=lib");
75 Self { cmd }
76 }
77
7864 // Argument provider methods
7965
8066 /// Configure the compilation environment.
src/tools/run-make-support/src/lib.rs+1-1
......@@ -68,7 +68,7 @@ pub use llvm::{
6868 LlvmFilecheck, LlvmNm, LlvmObjcopy, LlvmObjdump, LlvmProfdata, LlvmReadobj,
6969};
7070pub use python::python_command;
71pub use rustc::{aux_build, bare_rustc, rustc, rustc_path, Rustc};
71pub use rustc::{bare_rustc, rustc, rustc_path, Rustc};
7272pub use rustdoc::{rustdoc, Rustdoc};
7373
7474/// [`diff`][mod@diff] is implemented in terms of the [similar] library.
tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs+2-2
......@@ -3,10 +3,10 @@
33// Check that the `CURRENT_RUSTC_VERSION` placeholder is correctly replaced by the current
44// `rustc` version and the `since` property in feature stability gating is properly respected.
55
6use run_make_support::{aux_build, rfs, rustc, source_root};
6use run_make_support::{rfs, rustc, source_root};
77
88fn main() {
9 aux_build().input("stable.rs").emit("metadata").run();
9 rustc().crate_type("lib").input("stable.rs").emit("metadata").run();
1010
1111 let output =
1212 rustc().input("main.rs").emit("metadata").extern_("stable", "libstable.rmeta").run();
tests/run-make/issue-107495-archive-permissions/rmake.rs+2-2
......@@ -4,7 +4,7 @@ use std::path::Path;
44
55#[cfg(unix)]
66use run_make_support::libc;
7use run_make_support::{aux_build, rfs};
7use run_make_support::{rfs, rustc};
88
99fn main() {
1010 #[cfg(unix)]
......@@ -12,7 +12,7 @@ fn main() {
1212 libc::umask(0o002);
1313 }
1414
15 aux_build().arg("foo.rs").run();
15 rustc().crate_type("lib").arg("foo.rs").run();
1616 verify(Path::new("libfoo.rlib"));
1717}
1818
tests/run-make/print-crate-root-lint-levels/lib.rs created+5
......@@ -0,0 +1,5 @@
1#![allow(unexpected_cfgs)]
2#![expect(unused_mut)]
3
4#[deny(unknown_lints)]
5mod my_mod {}
tests/run-make/print-crate-root-lint-levels/rmake.rs created+118
......@@ -0,0 +1,118 @@
1//! This checks the output of `--print=crate-root-lint-levels`
2
3extern crate run_make_support;
4
5use std::collections::HashSet;
6use std::iter::FromIterator;
7
8use run_make_support::rustc;
9
10struct CrateRootLintLevels {
11 args: &'static [&'static str],
12 contains: Contains,
13}
14
15struct Contains {
16 contains: &'static [&'static str],
17 doesnt_contain: &'static [&'static str],
18}
19
20fn main() {
21 check(CrateRootLintLevels {
22 args: &[],
23 contains: Contains {
24 contains: &[
25 "unexpected_cfgs=allow",
26 "unused_mut=expect",
27 "warnings=warn",
28 "stable_features=warn",
29 "unknown_lints=warn",
30 ],
31 doesnt_contain: &["unexpected_cfgs=warn", "unused_mut=warn"],
32 },
33 });
34 check(CrateRootLintLevels {
35 args: &["-Wunexpected_cfgs"],
36 contains: Contains {
37 contains: &["unexpected_cfgs=allow", "warnings=warn"],
38 doesnt_contain: &["unexpected_cfgs=warn"],
39 },
40 });
41 check(CrateRootLintLevels {
42 args: &["-Dwarnings"],
43 contains: Contains {
44 contains: &[
45 "unexpected_cfgs=allow",
46 "warnings=deny",
47 "stable_features=deny",
48 "unknown_lints=deny",
49 ],
50 doesnt_contain: &["warnings=warn"],
51 },
52 });
53 check(CrateRootLintLevels {
54 args: &["-Dstable_features"],
55 contains: Contains {
56 contains: &["warnings=warn", "stable_features=deny", "unexpected_cfgs=allow"],
57 doesnt_contain: &["warnings=deny"],
58 },
59 });
60 check(CrateRootLintLevels {
61 args: &["-Dwarnings", "--force-warn=stable_features"],
62 contains: Contains {
63 contains: &["warnings=deny", "stable_features=force-warn", "unknown_lints=deny"],
64 doesnt_contain: &["warnings=warn"],
65 },
66 });
67 check(CrateRootLintLevels {
68 args: &["-Dwarnings", "--cap-lints=warn"],
69 contains: Contains {
70 contains: &[
71 "unexpected_cfgs=allow",
72 "warnings=warn",
73 "stable_features=warn",
74 "unknown_lints=warn",
75 ],
76 doesnt_contain: &["warnings=deny"],
77 },
78 });
79}
80
81#[track_caller]
82fn check(CrateRootLintLevels { args, contains }: CrateRootLintLevels) {
83 let output = rustc()
84 .input("lib.rs")
85 .arg("-Zunstable-options")
86 .print("crate-root-lint-levels")
87 .args(args)
88 .run();
89
90 let stdout = output.stdout_utf8();
91
92 let mut found = HashSet::<String>::new();
93
94 for l in stdout.lines() {
95 assert!(l == l.trim());
96 if let Some((left, right)) = l.split_once('=') {
97 assert!(!left.contains("\""));
98 assert!(!right.contains("\""));
99 } else {
100 assert!(l.contains('='));
101 }
102 assert!(found.insert(l.to_string()), "{}", &l);
103 }
104
105 let Contains { contains, doesnt_contain } = contains;
106
107 {
108 let should_found = HashSet::<String>::from_iter(contains.iter().map(|s| s.to_string()));
109 let diff: Vec<_> = should_found.difference(&found).collect();
110 assert!(diff.is_empty(), "should found: {:?}, didn't found {:?}", &should_found, &diff);
111 }
112 {
113 let should_not_find =
114 HashSet::<String>::from_iter(doesnt_contain.iter().map(|s| s.to_string()));
115 let diff: Vec<_> = should_not_find.intersection(&found).collect();
116 assert!(diff.is_empty(), "should not find {:?}, did found {:?}", &should_not_find, &diff);
117 }
118}
tests/run-make/rustc-help/help-v.stdout+1-1
......@@ -29,7 +29,7 @@ Options:
2929 --emit [asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]
3030 Comma separated list of types of output for the
3131 compiler to emit
32 --print [all-target-specs-json|calling-conventions|cfg|check-cfg|code-models|crate-name|deployment-target|file-names|host-tuple|link-args|native-static-libs|relocation-models|split-debuginfo|stack-protector-strategies|supported-crate-types|sysroot|target-cpus|target-features|target-libdir|target-list|target-spec-json|tls-models]
32 --print [all-target-specs-json|calling-conventions|cfg|check-cfg|code-models|crate-name|crate-root-lint-levels|deployment-target|file-names|host-tuple|link-args|native-static-libs|relocation-models|split-debuginfo|stack-protector-strategies|supported-crate-types|sysroot|target-cpus|target-features|target-libdir|target-list|target-spec-json|tls-models]
3333 Compiler information to print on stdout
3434 -g Equivalent to -C debuginfo=2
3535 -O Equivalent to -C opt-level=3
tests/run-make/rustc-help/help.stdout+1-1
......@@ -29,7 +29,7 @@ Options:
2929 --emit [asm|llvm-bc|llvm-ir|obj|metadata|link|dep-info|mir]
3030 Comma separated list of types of output for the
3131 compiler to emit
32 --print [all-target-specs-json|calling-conventions|cfg|check-cfg|code-models|crate-name|deployment-target|file-names|host-tuple|link-args|native-static-libs|relocation-models|split-debuginfo|stack-protector-strategies|supported-crate-types|sysroot|target-cpus|target-features|target-libdir|target-list|target-spec-json|tls-models]
32 --print [all-target-specs-json|calling-conventions|cfg|check-cfg|code-models|crate-name|crate-root-lint-levels|deployment-target|file-names|host-tuple|link-args|native-static-libs|relocation-models|split-debuginfo|stack-protector-strategies|supported-crate-types|sysroot|target-cpus|target-features|target-libdir|target-list|target-spec-json|tls-models]
3333 Compiler information to print on stdout
3434 -g Equivalent to -C debuginfo=2
3535 -O Equivalent to -C opt-level=3
tests/ui/invalid-compile-flags/print-without-arg.stderr+1-1
......@@ -1,5 +1,5 @@
11error: Argument to option 'print' missing
22 Usage:
3 --print [all-target-specs-json|calling-conventions|cfg|check-cfg|code-models|crate-name|deployment-target|file-names|host-tuple|link-args|native-static-libs|relocation-models|split-debuginfo|stack-protector-strategies|supported-crate-types|sysroot|target-cpus|target-features|target-libdir|target-list|target-spec-json|tls-models]
3 --print [all-target-specs-json|calling-conventions|cfg|check-cfg|code-models|crate-name|crate-root-lint-levels|deployment-target|file-names|host-tuple|link-args|native-static-libs|relocation-models|split-debuginfo|stack-protector-strategies|supported-crate-types|sysroot|target-cpus|target-features|target-libdir|target-list|target-spec-json|tls-models]
44 Compiler information to print on stdout
55
tests/ui/invalid-compile-flags/print.stderr+1-1
......@@ -1,5 +1,5 @@
11error: unknown print request: `yyyy`
22 |
3 = help: valid print requests are: `all-target-specs-json`, `calling-conventions`, `cfg`, `check-cfg`, `code-models`, `crate-name`, `deployment-target`, `file-names`, `host-tuple`, `link-args`, `native-static-libs`, `relocation-models`, `split-debuginfo`, `stack-protector-strategies`, `supported-crate-types`, `sysroot`, `target-cpus`, `target-features`, `target-libdir`, `target-list`, `target-spec-json`, `tls-models`
3 = help: valid print requests are: `all-target-specs-json`, `calling-conventions`, `cfg`, `check-cfg`, `code-models`, `crate-name`, `crate-root-lint-levels`, `deployment-target`, `file-names`, `host-tuple`, `link-args`, `native-static-libs`, `relocation-models`, `split-debuginfo`, `stack-protector-strategies`, `supported-crate-types`, `sysroot`, `target-cpus`, `target-features`, `target-libdir`, `target-list`, `target-spec-json`, `tls-models`
44 = help: for more information, see the rustc book: https://doc.rust-lang.org/rustc/command-line-arguments.html#--print-print-compiler-information
55
tests/ui/print-request/print-lints-help.stderr+1-1
......@@ -1,6 +1,6 @@
11error: unknown print request: `lints`
22 |
3 = help: valid print requests are: `all-target-specs-json`, `calling-conventions`, `cfg`, `check-cfg`, `code-models`, `crate-name`, `deployment-target`, `file-names`, `host-tuple`, `link-args`, `native-static-libs`, `relocation-models`, `split-debuginfo`, `stack-protector-strategies`, `supported-crate-types`, `sysroot`, `target-cpus`, `target-features`, `target-libdir`, `target-list`, `target-spec-json`, `tls-models`
3 = help: valid print requests are: `all-target-specs-json`, `calling-conventions`, `cfg`, `check-cfg`, `code-models`, `crate-name`, `crate-root-lint-levels`, `deployment-target`, `file-names`, `host-tuple`, `link-args`, `native-static-libs`, `relocation-models`, `split-debuginfo`, `stack-protector-strategies`, `supported-crate-types`, `sysroot`, `target-cpus`, `target-features`, `target-libdir`, `target-list`, `target-spec-json`, `tls-models`
44 = help: use `-Whelp` to print a list of lints
55 = help: for more information, see the rustc book: https://doc.rust-lang.org/rustc/command-line-arguments.html#--print-print-compiler-information
66
tests/ui/print-request/stability.rs+4
......@@ -18,6 +18,10 @@
1818//@[all_target_specs_json] compile-flags: --print=all-target-specs-json
1919//@[all_target_specs_json] error-pattern: the `-Z unstable-options` flag must also be passed
2020
21//@ revisions: crate_root_lint_levels
22//@[crate_root_lint_levels] compile-flags: --print=crate-root-lint-levels
23//@[crate_root_lint_levels] error-pattern: the `-Z unstable-options` flag must also be passed
24
2125//@ revisions: check_cfg
2226//@[check_cfg] compile-flags: --print=check-cfg
2327//@[check_cfg] error-pattern: the `-Z unstable-options` flag must also be passed
triagebot.toml+1-2
......@@ -1142,7 +1142,6 @@ compiler_leads = [
11421142]
11431143compiler = [
11441144 "@BoxyUwU",
1145 "@cjgillot",
11461145 "@compiler-errors",
11471146 "@davidtwco",
11481147 "@estebank",
......@@ -1197,7 +1196,7 @@ codegen = [
11971196 "@workingjubilee",
11981197]
11991198query-system = [
1200 "@cjgillot",
1199 "@oli-obk",
12011200]
12021201incremental = [
12031202 "@wesleywiser",