Skip to content

Commit 5bdd72b

Browse files
authored
Rollup merge of #142687 - cjgillot:less-hir_crate, r=oli-obk
Reduce uses of `hir_crate`. I tried rebasing my old incremental-HIR branch. This is a by-product, which is required if we want to get rid of `hir_crate` entirely. The second commit is a drive-by cleanup. It can be pulled into its own PR. r? ```@oli-obk```
2 parents 29ed9bd + ede4891 commit 5bdd72b

File tree

16 files changed

+48
-102
lines changed

16 files changed

+48
-102
lines changed

compiler/rustc_const_eval/src/check_consts/check.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -463,12 +463,6 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
463463
);
464464
}
465465

466-
fn crate_inject_span(&self) -> Option<Span> {
467-
self.tcx.hir_crate_items(()).definitions().next().and_then(|id| {
468-
self.tcx.crate_level_attribute_injection_span(self.tcx.local_def_id_to_hir_id(id))
469-
})
470-
}
471-
472466
/// Check the const stability of the given item (fn or trait).
473467
fn check_callee_stability(&mut self, def_id: DefId) {
474468
match self.tcx.lookup_const_stability(def_id) {
@@ -543,7 +537,6 @@ impl<'mir, 'tcx> Checker<'mir, 'tcx> {
543537
feature,
544538
feature_enabled,
545539
safe_to_expose_on_stable: callee_safe_to_expose_on_stable,
546-
suggestion_span: self.crate_inject_span(),
547540
is_function_call: self.tcx.def_kind(def_id) != DefKind::Trait,
548541
});
549542
}
@@ -919,7 +912,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
919912
name: intrinsic.name,
920913
feature,
921914
const_stable_indirect: is_const_stable,
922-
suggestion: self.crate_inject_span(),
923915
});
924916
}
925917
Some(attrs::ConstStability {

compiler/rustc_const_eval/src/check_consts/ops.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Concrete error types for all operations which may be invalid in a certain const context.
22
33
use hir::{ConstContext, LangItem};
4+
use rustc_errors::Diag;
45
use rustc_errors::codes::*;
5-
use rustc_errors::{Applicability, Diag};
66
use rustc_hir as hir;
77
use rustc_hir::def_id::DefId;
88
use rustc_infer::infer::TyCtxtInferExt;
@@ -384,7 +384,6 @@ pub(crate) struct CallUnstable {
384384
/// expose on stable.
385385
pub feature_enabled: bool,
386386
pub safe_to_expose_on_stable: bool,
387-
pub suggestion_span: Option<Span>,
388387
/// true if `def_id` is the function we are calling, false if `def_id` is an unstable trait.
389388
pub is_function_call: bool,
390389
}
@@ -412,20 +411,7 @@ impl<'tcx> NonConstOp<'tcx> for CallUnstable {
412411
def_path: ccx.tcx.def_path_str(self.def_id),
413412
})
414413
};
415-
// FIXME: make this translatable
416-
let msg = format!("add `#![feature({})]` to the crate attributes to enable", self.feature);
417-
#[allow(rustc::untranslatable_diagnostic)]
418-
if let Some(span) = self.suggestion_span {
419-
err.span_suggestion_verbose(
420-
span,
421-
msg,
422-
format!("#![feature({})]\n", self.feature),
423-
Applicability::MachineApplicable,
424-
);
425-
} else {
426-
err.help(msg);
427-
}
428-
414+
ccx.tcx.disabled_nightly_features(&mut err, [(String::new(), self.feature)]);
429415
err
430416
}
431417
}
@@ -452,7 +438,6 @@ pub(crate) struct IntrinsicUnstable {
452438
pub name: Symbol,
453439
pub feature: Symbol,
454440
pub const_stable_indirect: bool,
455-
pub suggestion: Option<Span>,
456441
}
457442

458443
impl<'tcx> NonConstOp<'tcx> for IntrinsicUnstable {
@@ -472,8 +457,7 @@ impl<'tcx> NonConstOp<'tcx> for IntrinsicUnstable {
472457
span,
473458
name: self.name,
474459
feature: self.feature,
475-
suggestion: self.suggestion,
476-
help: self.suggestion.is_none(),
460+
suggestion: ccx.tcx.crate_level_attribute_injection_span(),
477461
})
478462
}
479463
}

compiler/rustc_const_eval/src/errors.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@ pub(crate) struct UnstableIntrinsic {
136136
code = "#![feature({feature})]\n",
137137
applicability = "machine-applicable"
138138
)]
139-
pub suggestion: Option<Span>,
140-
#[help(const_eval_unstable_intrinsic_suggestion)]
141-
pub help: bool,
139+
pub suggestion: Span,
142140
}
143141

144142
#[derive(Diagnostic)]

compiler/rustc_driver_impl/src/pretty.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,11 @@ pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
292292
}
293293
HirTree => {
294294
debug!("pretty printing HIR tree");
295-
format!("{:#?}", ex.tcx().hir_crate(()))
295+
ex.tcx()
296+
.hir_crate_items(())
297+
.owners()
298+
.map(|owner| format!("{:#?} => {:#?}\n", owner, ex.tcx().hir_owner_nodes(owner)))
299+
.collect()
296300
}
297301
Mir => {
298302
let mut out = Vec::new();

compiler/rustc_hir_analysis/src/check/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,7 @@ fn default_body_is_unstable(
311311
reason: reason_str,
312312
});
313313

314-
let inject_span = item_did
315-
.as_local()
316-
.and_then(|id| tcx.crate_level_attribute_injection_span(tcx.local_def_id_to_hir_id(id)));
314+
let inject_span = item_did.is_local().then(|| tcx.crate_level_attribute_injection_span());
317315
rustc_session::parse::add_feature_diagnostics_for_issue(
318316
&mut err,
319317
&tcx.sess,

compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(),
10641064
Ok(..) => Some(vec![(adt_const_params_feature_string, sym::adt_const_params)]),
10651065
};
10661066
if let Some(features) = may_suggest_feature {
1067-
tcx.disabled_nightly_features(&mut diag, Some(param.hir_id), features);
1067+
tcx.disabled_nightly_features(&mut diag, features);
10681068
}
10691069

10701070
Err(diag.emit())

compiler/rustc_hir_typeck/src/errors.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ pub(crate) struct BaseExpressionDoubleDot {
3131
)]
3232
pub default_field_values_suggestion: Option<Span>,
3333
#[subdiagnostic]
34-
pub default_field_values_help: Option<BaseExpressionDoubleDotEnableDefaultFieldValues>,
35-
#[subdiagnostic]
3634
pub add_expr: Option<BaseExpressionDoubleDotAddExpr>,
3735
#[subdiagnostic]
3836
pub remove_dots: Option<BaseExpressionDoubleDotRemove>,
@@ -62,10 +60,6 @@ pub(crate) struct BaseExpressionDoubleDotAddExpr {
6260
pub span: Span,
6361
}
6462

65-
#[derive(Subdiagnostic)]
66-
#[help(hir_typeck_base_expression_double_dot_enable_default_field_values)]
67-
pub(crate) struct BaseExpressionDoubleDotEnableDefaultFieldValues;
68-
6963
#[derive(Diagnostic)]
7064
#[diag(hir_typeck_field_multiply_specified_in_initializer, code = E0062)]
7165
pub(crate) struct FieldMultiplySpecifiedInInitializer {

compiler/rustc_hir_typeck/src/expr.rs

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,9 @@ use crate::Expectation::{self, ExpectCastableToType, ExpectHasType, NoExpectatio
4343
use crate::coercion::{CoerceMany, DynamicCoerceMany};
4444
use crate::errors::{
4545
AddressOfTemporaryTaken, BaseExpressionDoubleDot, BaseExpressionDoubleDotAddExpr,
46-
BaseExpressionDoubleDotEnableDefaultFieldValues, BaseExpressionDoubleDotRemove,
47-
CantDereference, FieldMultiplySpecifiedInInitializer, FunctionalRecordUpdateOnNonStruct,
48-
HelpUseLatestEdition, NakedAsmOutsideNakedFn, NoFieldOnType, NoFieldOnVariant,
49-
ReturnLikeStatementKind, ReturnStmtOutsideOfFnBody, StructExprNonExhaustive,
46+
BaseExpressionDoubleDotRemove, CantDereference, FieldMultiplySpecifiedInInitializer,
47+
FunctionalRecordUpdateOnNonStruct, HelpUseLatestEdition, NakedAsmOutsideNakedFn, NoFieldOnType,
48+
NoFieldOnVariant, ReturnLikeStatementKind, ReturnStmtOutsideOfFnBody, StructExprNonExhaustive,
5049
TypeMismatchFruTypo, YieldExprOutsideOfCoroutine,
5150
};
5251
use crate::{
@@ -2152,26 +2151,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21522151
}
21532152
}
21542153
if !self.tcx.features().default_field_values() {
2155-
let sugg = self.tcx.crate_level_attribute_injection_span(expr.hir_id);
2154+
let sugg = self.tcx.crate_level_attribute_injection_span();
21562155
self.dcx().emit_err(BaseExpressionDoubleDot {
21572156
span: span.shrink_to_hi(),
21582157
// We only mention enabling the feature if this is a nightly rustc *and* the
21592158
// expression would make sense with the feature enabled.
21602159
default_field_values_suggestion: if self.tcx.sess.is_nightly_build()
21612160
&& missing_mandatory_fields.is_empty()
21622161
&& !missing_optional_fields.is_empty()
2163-
&& sugg.is_some()
21642162
{
2165-
sugg
2166-
} else {
2167-
None
2168-
},
2169-
default_field_values_help: if self.tcx.sess.is_nightly_build()
2170-
&& missing_mandatory_fields.is_empty()
2171-
&& !missing_optional_fields.is_empty()
2172-
&& sugg.is_none()
2173-
{
2174-
Some(BaseExpressionDoubleDotEnableDefaultFieldValues)
2163+
Some(sugg)
21752164
} else {
21762165
None
21772166
},

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1727,7 +1727,6 @@ impl<'tcx> Pick<'tcx> {
17271727
}
17281728
tcx.disabled_nightly_features(
17291729
lint,
1730-
Some(scope_expr_id),
17311730
self.unstable_candidates.iter().map(|(candidate, feature)| {
17321731
(format!(" `{}`", tcx.def_path_str(candidate.item.def_id)), *feature)
17331732
}),

compiler/rustc_interface/src/passes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,8 +1011,8 @@ fn run_required_analyses(tcx: TyCtxt<'_>) {
10111011

10121012
// Prefetch this to prevent multiple threads from blocking on it later.
10131013
// This is needed since the `hir_id_validator::check_crate` call above is not guaranteed
1014-
// to use `hir_crate`.
1015-
tcx.ensure_done().hir_crate(());
1014+
// to use `hir_crate_items`.
1015+
tcx.ensure_done().hir_crate_items(());
10161016

10171017
let sess = tcx.sess;
10181018
sess.time("misc_checking_1", || {

0 commit comments

Comments
 (0)