Skip to content

Commit 3c8f740

Browse files
committed
Don't check generic parameter's parent deprecation
1 parent 6233993 commit 3c8f740

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

src/librustc/middle/stability.rs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,21 @@ impl<'tcx> TyCtxt<'tcx> {
281281
/// If `id` is `Some(_)`, this function will also check if the item at `def_id` has been
282282
/// deprecated. If the item is indeed deprecated, we will emit a deprecation lint attached to
283283
/// `id`.
284-
pub fn eval_stability(self, def_id: DefId, id: Option<HirId>, span: Span) -> EvalResult {
284+
pub fn eval_stability(
285+
self,
286+
def_id: DefId,
287+
id: Option<HirId>,
288+
span: Span,
289+
inherit_dep: bool,
290+
) -> EvalResult {
285291
// Deprecated attributes apply in-crate and cross-crate.
286292
if let Some(id) = id {
287293
if let Some(depr_entry) = self.lookup_deprecation_entry(def_id) {
288294
let parent_def_id = self.hir().local_def_id(self.hir().get_parent_item(id));
289-
let skip = self
290-
.lookup_deprecation_entry(parent_def_id)
291-
.map_or(false, |parent_depr| parent_depr.same_origin(&depr_entry));
295+
let skip = !inherit_dep
296+
|| self
297+
.lookup_deprecation_entry(parent_def_id)
298+
.map_or(false, |parent_depr| parent_depr.same_origin(&depr_entry));
292299

293300
if !skip {
294301
let (message, lint) =
@@ -386,9 +393,26 @@ impl<'tcx> TyCtxt<'tcx> {
386393
/// Additionally, this function will also check if the item is deprecated. If so, and `id` is
387394
/// not `None`, a deprecated lint attached to `id` will be emitted.
388395
pub fn check_stability(self, def_id: DefId, id: Option<HirId>, span: Span) {
396+
self.check_stability_internal(def_id, id, span, true)
397+
}
398+
399+
/// Checks if an item is stable or error out.
400+
///
401+
/// If the item defined by `def_id` is unstable and the corresponding `#![feature]` does not
402+
/// exist, emits an error.
403+
///
404+
/// Additionally when `inherit_dep` is `true`, this function will also check if the item is deprecated. If so, and `id` is
405+
/// not `None`, a deprecated lint attached to `id` will be emitted.
406+
pub fn check_stability_internal(
407+
self,
408+
def_id: DefId,
409+
id: Option<HirId>,
410+
span: Span,
411+
inherit_dep: bool,
412+
) {
389413
let soft_handler =
390414
|lint, span, msg: &_| self.lint_hir(lint, id.unwrap_or(hir::CRATE_HIR_ID), span, msg);
391-
match self.eval_stability(def_id, id, span) {
415+
match self.eval_stability(def_id, id, span, inherit_dep) {
392416
EvalResult::Allow => {}
393417
EvalResult::Deny { feature, reason, issue, is_soft } => {
394418
report_unstable(self.sess, feature, reason, issue, is_soft, span, soft_handler)

src/librustc_typeck/astconv.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
699699
}
700700
(GenericParamDefKind::Type { has_default, .. }, GenericArg::Type(ty)) => {
701701
if *has_default {
702-
tcx.check_stability(param.def_id, Some(arg.id()), arg.span());
702+
tcx.check_stability_internal(
703+
param.def_id,
704+
Some(arg.id()),
705+
arg.span(),
706+
false,
707+
);
703708
}
704709

705710
self.ast_ty_to_ty(&ty).into()

src/librustc_typeck/check/method/probe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1252,7 +1252,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
12521252
if let Some(uc) = unstable_candidates {
12531253
applicable_candidates.retain(|&(p, _)| {
12541254
if let stability::EvalResult::Deny { feature, .. } =
1255-
self.tcx.eval_stability(p.item.def_id, None, self.span)
1255+
self.tcx.eval_stability(p.item.def_id, None, self.span, false)
12561256
{
12571257
uc.push((p, feature));
12581258
return false;

0 commit comments

Comments
 (0)