Skip to content

Commit 0dd7e10

Browse files
committed
Auto merge of rust-lang#96877 - matthiaskrgr:rollup-evlh6ot, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#95483 (Improve floating point documentation) - rust-lang#96008 (Warn on unused `#[doc(hidden)]` attributes on trait impl items) - rust-lang#96841 (Revert "Implement [OsStr]::join", which was merged without FCP.) - rust-lang#96844 (Actually fix ICE from rust-lang#96583) - rust-lang#96854 (Some subst cleanup) - rust-lang#96858 (Remove unused param from search.js::checkPath) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0e345b7 + 5972222 commit 0dd7e10

File tree

37 files changed

+472
-215
lines changed

37 files changed

+472
-215
lines changed

compiler/rustc_middle/src/ty/subst.rs

+10-38
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_data_structures::intern::{Interned, WithStableHash};
1010
use rustc_hir::def_id::DefId;
1111
use rustc_macros::HashStable;
1212
use rustc_serialize::{self, Decodable, Encodable};
13-
use rustc_span::{Span, DUMMY_SP};
13+
use rustc_span::DUMMY_SP;
1414
use smallvec::SmallVec;
1515

1616
use core::intrinsics;
@@ -498,34 +498,14 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<Ty<'tcx>> {
498498
}
499499
}
500500

501-
///////////////////////////////////////////////////////////////////////////
502-
// Public trait `Subst`
503-
//
504-
// Just call `foo.subst(tcx, substs)` to perform a substitution across
505-
// `foo`. Or use `foo.subst_spanned(tcx, substs, Some(span))` when
506-
// there is more information available (for better errors).
507-
501+
// Just call `foo.subst(tcx, substs)` to perform a substitution across `foo`.
508502
pub trait Subst<'tcx>: Sized {
509-
fn subst(self, tcx: TyCtxt<'tcx>, substs: &[GenericArg<'tcx>]) -> Self {
510-
self.subst_spanned(tcx, substs, None)
511-
}
512-
513-
fn subst_spanned(
514-
self,
515-
tcx: TyCtxt<'tcx>,
516-
substs: &[GenericArg<'tcx>],
517-
span: Option<Span>,
518-
) -> Self;
503+
fn subst(self, tcx: TyCtxt<'tcx>, substs: &[GenericArg<'tcx>]) -> Self;
519504
}
520505

521506
impl<'tcx, T: TypeFoldable<'tcx>> Subst<'tcx> for T {
522-
fn subst_spanned(
523-
self,
524-
tcx: TyCtxt<'tcx>,
525-
substs: &[GenericArg<'tcx>],
526-
span: Option<Span>,
527-
) -> T {
528-
let mut folder = SubstFolder { tcx, substs, span, binders_passed: 0 };
507+
fn subst(self, tcx: TyCtxt<'tcx>, substs: &[GenericArg<'tcx>]) -> T {
508+
let mut folder = SubstFolder { tcx, substs, binders_passed: 0 };
529509
self.fold_with(&mut folder)
530510
}
531511
}
@@ -537,9 +517,6 @@ struct SubstFolder<'a, 'tcx> {
537517
tcx: TyCtxt<'tcx>,
538518
substs: &'a [GenericArg<'tcx>],
539519

540-
/// The location for which the substitution is performed, if available.
541-
span: Option<Span>,
542-
543520
/// Number of region binders we have passed through while doing the substitution
544521
binders_passed: u32,
545522
}
@@ -571,13 +548,12 @@ impl<'a, 'tcx> TypeFolder<'tcx> for SubstFolder<'a, 'tcx> {
571548
match rk {
572549
Some(GenericArgKind::Lifetime(lt)) => self.shift_region_through_binders(lt),
573550
_ => {
574-
let span = self.span.unwrap_or(DUMMY_SP);
575551
let msg = format!(
576552
"Region parameter out of range \
577553
when substituting in region {} (index={})",
578554
data.name, data.index
579555
);
580-
span_bug!(span, "{}", msg);
556+
span_bug!(DUMMY_SP, "{}", msg);
581557
}
582558
}
583559
}
@@ -617,9 +593,8 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
617593
let ty = match opt_ty {
618594
Some(GenericArgKind::Type(ty)) => ty,
619595
Some(kind) => {
620-
let span = self.span.unwrap_or(DUMMY_SP);
621596
span_bug!(
622-
span,
597+
DUMMY_SP,
623598
"expected type for `{:?}` ({:?}/{}) but found {:?} \
624599
when substituting, substs={:?}",
625600
p,
@@ -630,9 +605,8 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
630605
);
631606
}
632607
None => {
633-
let span = self.span.unwrap_or(DUMMY_SP);
634608
span_bug!(
635-
span,
609+
DUMMY_SP,
636610
"type parameter `{:?}` ({:?}/{}) out of range \
637611
when substituting, substs={:?}",
638612
p,
@@ -652,9 +626,8 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
652626
let ct = match opt_ct {
653627
Some(GenericArgKind::Const(ct)) => ct,
654628
Some(kind) => {
655-
let span = self.span.unwrap_or(DUMMY_SP);
656629
span_bug!(
657-
span,
630+
DUMMY_SP,
658631
"expected const for `{:?}` ({:?}/{}) but found {:?} \
659632
when substituting substs={:?}",
660633
p,
@@ -665,9 +638,8 @@ impl<'a, 'tcx> SubstFolder<'a, 'tcx> {
665638
);
666639
}
667640
None => {
668-
let span = self.span.unwrap_or(DUMMY_SP);
669641
span_bug!(
670-
span,
642+
DUMMY_SP,
671643
"const parameter `{:?}` ({:?}/{}) out of range \
672644
when substituting substs={:?}",
673645
p,

compiler/rustc_passes/src/check_attr.rs

+74-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
//! conflicts between multiple such attributes attached to the same
55
//! item.
66
7-
use rustc_ast::{ast, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
7+
use rustc_ast::tokenstream::DelimSpan;
8+
use rustc_ast::{ast, AttrStyle, Attribute, Lit, LitKind, MacArgs, MetaItemKind, NestedMetaItem};
89
use rustc_data_structures::fx::FxHashMap;
910
use rustc_errors::{pluralize, struct_span_err, Applicability, MultiSpan};
1011
use rustc_feature::{AttributeDuplicates, AttributeType, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP};
@@ -810,6 +811,68 @@ impl CheckAttrVisitor<'_> {
810811
}
811812
}
812813

814+
/// Checks `#[doc(hidden)]` attributes. Returns `true` if valid.
815+
fn check_doc_hidden(
816+
&self,
817+
attr: &Attribute,
818+
meta_index: usize,
819+
meta: &NestedMetaItem,
820+
hir_id: HirId,
821+
target: Target,
822+
) -> bool {
823+
if let Target::AssocConst
824+
| Target::AssocTy
825+
| Target::Method(MethodKind::Trait { body: true }) = target
826+
{
827+
let parent_hir_id = self.tcx.hir().get_parent_item(hir_id);
828+
let containing_item = self.tcx.hir().expect_item(parent_hir_id);
829+
830+
if Target::from_item(containing_item) == Target::Impl {
831+
let meta_items = attr.meta_item_list().unwrap();
832+
833+
let (span, replacement_span) = if meta_items.len() == 1 {
834+
(attr.span, attr.span)
835+
} else {
836+
let meta_span = meta.span();
837+
(
838+
meta_span,
839+
meta_span.until(match meta_items.get(meta_index + 1) {
840+
Some(next_item) => next_item.span(),
841+
None => match attr.get_normal_item().args {
842+
MacArgs::Delimited(DelimSpan { close, .. }, ..) => close,
843+
_ => unreachable!(),
844+
},
845+
}),
846+
)
847+
};
848+
849+
// FIXME: #[doc(hidden)] was previously erroneously allowed on trait impl items,
850+
// so for backward compatibility only emit a warning and do not mark it as invalid.
851+
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, span, |lint| {
852+
lint.build("`#[doc(hidden)]` is ignored on trait impl items")
853+
.warn(
854+
"this was previously accepted by the compiler but is \
855+
being phased out; it will become a hard error in \
856+
a future release!",
857+
)
858+
.note(
859+
"whether the impl item is `doc(hidden)` or not \
860+
entirely depends on the corresponding trait item",
861+
)
862+
.span_suggestion(
863+
replacement_span,
864+
"remove this attribute",
865+
String::new(),
866+
Applicability::MachineApplicable,
867+
)
868+
.emit();
869+
});
870+
}
871+
}
872+
873+
true
874+
}
875+
813876
/// Checks that an attribute is *not* used at the crate level. Returns `true` if valid.
814877
fn check_attr_not_crate_level(
815878
&self,
@@ -928,7 +991,7 @@ impl CheckAttrVisitor<'_> {
928991
let mut is_valid = true;
929992

930993
if let Some(mi) = attr.meta() && let Some(list) = mi.meta_item_list() {
931-
for meta in list {
994+
for (meta_index, meta) in list.into_iter().enumerate() {
932995
if let Some(i_meta) = meta.meta_item() {
933996
match i_meta.name_or_empty() {
934997
sym::alias
@@ -969,6 +1032,15 @@ impl CheckAttrVisitor<'_> {
9691032
is_valid = false;
9701033
}
9711034

1035+
sym::hidden if !self.check_doc_hidden(attr,
1036+
meta_index,
1037+
meta,
1038+
hir_id,
1039+
target,
1040+
) => {
1041+
is_valid = false;
1042+
}
1043+
9721044
// no_default_passes: deprecated
9731045
// passes: deprecated
9741046
// plugins: removed, but rustdoc warns about it itself

compiler/rustc_typeck/src/astconv/mod.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -523,11 +523,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
523523
self.astconv
524524
.normalize_ty(
525525
self.span,
526-
tcx.at(self.span).type_of(param.def_id).subst_spanned(
527-
tcx,
528-
substs,
529-
Some(self.span),
530-
),
526+
tcx.at(self.span).type_of(param.def_id).subst(tcx, substs),
531527
)
532528
.into()
533529
}
@@ -547,9 +543,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
547543
GenericParamDefKind::Const { has_default } => {
548544
let ty = tcx.at(self.span).type_of(param.def_id);
549545
if !infer_args && has_default {
550-
tcx.const_param_default(param.def_id)
551-
.subst_spanned(tcx, substs.unwrap(), Some(self.span))
552-
.into()
546+
tcx.const_param_default(param.def_id).subst(tcx, substs.unwrap()).into()
553547
} else {
554548
if infer_args {
555549
self.astconv.ct_infer(ty, Some(param), self.span).into()

compiler/rustc_typeck/src/check/expr.rs

+20-11
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ use rustc_middle::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase};
4444
use rustc_middle::ty::error::ExpectedFound;
4545
use rustc_middle::ty::error::TypeError::{FieldMisMatch, Sorts};
4646
use rustc_middle::ty::subst::SubstsRef;
47-
use rustc_middle::ty::{self, AdtKind, Ty, TypeFoldable};
47+
use rustc_middle::ty::{self, AdtKind, DefIdTree, Ty, TypeFoldable};
4848
use rustc_session::parse::feature_err;
4949
use rustc_span::hygiene::DesugaringKind;
5050
use rustc_span::lev_distance::find_best_match_for_name;
@@ -2034,17 +2034,26 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20342034
base: &'tcx hir::Expr<'tcx>,
20352035
def_id: DefId,
20362036
) {
2037-
let local_id = def_id.expect_local();
2038-
let hir_id = self.tcx.hir().local_def_id_to_hir_id(local_id);
2039-
let node = self.tcx.hir().get(hir_id);
2040-
2041-
if let Some(fields) = node.tuple_fields() {
2042-
let kind = match self.tcx.opt_def_kind(local_id) {
2043-
Some(DefKind::Ctor(of, _)) => of,
2044-
_ => return,
2045-
};
2037+
if let Some(local_id) = def_id.as_local() {
2038+
let hir_id = self.tcx.hir().local_def_id_to_hir_id(local_id);
2039+
let node = self.tcx.hir().get(hir_id);
2040+
2041+
if let Some(fields) = node.tuple_fields() {
2042+
let kind = match self.tcx.opt_def_kind(local_id) {
2043+
Some(DefKind::Ctor(of, _)) => of,
2044+
_ => return,
2045+
};
20462046

2047-
suggest_call_constructor(base.span, kind, fields.len(), err);
2047+
suggest_call_constructor(base.span, kind, fields.len(), err);
2048+
}
2049+
} else {
2050+
// The logic here isn't smart but `associated_item_def_ids`
2051+
// doesn't work nicely on local.
2052+
if let DefKind::Ctor(of, _) = self.tcx.def_kind(def_id) {
2053+
let parent_def_id = self.tcx.parent(def_id);
2054+
let fields = self.tcx.associated_item_def_ids(parent_def_id);
2055+
suggest_call_constructor(base.span, of, fields.len(), err);
2056+
}
20482057
}
20492058
}
20502059

compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -1403,10 +1403,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14031403
// is missing.
14041404
let default = tcx.type_of(param.def_id);
14051405
self.fcx
1406-
.normalize_ty(
1407-
self.span,
1408-
default.subst_spanned(tcx, substs.unwrap(), Some(self.span)),
1409-
)
1406+
.normalize_ty(self.span, default.subst(tcx, substs.unwrap()))
14101407
.into()
14111408
} else {
14121409
// If no type arguments were provided, we have to infer them.
@@ -1418,9 +1415,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14181415
}
14191416
GenericParamDefKind::Const { has_default } => {
14201417
if !infer_args && has_default {
1421-
tcx.const_param_default(param.def_id)
1422-
.subst_spanned(tcx, substs.unwrap(), Some(self.span))
1423-
.into()
1418+
tcx.const_param_default(param.def_id).subst(tcx, substs.unwrap()).into()
14241419
} else {
14251420
self.fcx.var_for_def(self.span, param)
14261421
}

compiler/rustc_typeck/src/check/method/confirm.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -462,19 +462,13 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
462462

463463
let sig = self.tcx.fn_sig(def_id);
464464

465-
// Instantiate late-bound regions and substitute the trait
466-
// parameters into the method type to get the actual method type.
467-
//
468-
// N.B., instantiate late-bound regions first so that
469-
// `instantiate_type_scheme` can normalize associated types that
470-
// may reference those regions.
471-
let method_sig = self.replace_bound_vars_with_fresh_vars(sig);
472-
debug!("late-bound lifetimes from method instantiated, method_sig={:?}", method_sig);
465+
let sig = sig.subst(self.tcx, all_substs);
466+
debug!("type scheme substituted, sig={:?}", sig);
473467

474-
let method_sig = method_sig.subst(self.tcx, all_substs);
475-
debug!("type scheme substituted, method_sig={:?}", method_sig);
468+
let sig = self.replace_bound_vars_with_fresh_vars(sig);
469+
debug!("late-bound lifetimes from method instantiated, sig={:?}", sig);
476470

477-
(method_sig, method_predicates)
471+
(sig, method_predicates)
478472
}
479473

480474
fn add_obligations(

compiler/rustc_typeck/src/check/method/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
461461
// `instantiate_type_scheme` can normalize associated types that
462462
// may reference those regions.
463463
let fn_sig = tcx.fn_sig(def_id);
464-
let fn_sig = self.replace_bound_vars_with_fresh_vars(span, infer::FnCall, fn_sig).0;
465464
let fn_sig = fn_sig.subst(self.tcx, substs);
465+
let fn_sig = self.replace_bound_vars_with_fresh_vars(span, infer::FnCall, fn_sig).0;
466466

467467
let InferOk { value, obligations: o } = if is_op {
468468
self.normalize_op_associated_types_in_as_infer_ok(span, fn_sig, opt_input_expr)

compiler/rustc_typeck/src/check/method/probe.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1784,12 +1784,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
17841784
let generics = self.tcx.generics_of(method);
17851785
assert_eq!(substs.len(), generics.parent_count as usize);
17861786

1787-
// Erase any late-bound regions from the method and substitute
1788-
// in the values from the substitution.
1789-
let xform_fn_sig = self.erase_late_bound_regions(fn_sig);
1790-
1791-
if generics.params.is_empty() {
1792-
xform_fn_sig.subst(self.tcx, substs)
1787+
let xform_fn_sig = if generics.params.is_empty() {
1788+
fn_sig.subst(self.tcx, substs)
17931789
} else {
17941790
let substs = InternalSubsts::for_item(self.tcx, method, |param, _| {
17951791
let i = param.index as usize;
@@ -1807,8 +1803,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
18071803
}
18081804
}
18091805
});
1810-
xform_fn_sig.subst(self.tcx, substs)
1811-
}
1806+
fn_sig.subst(self.tcx, substs)
1807+
};
1808+
1809+
self.erase_late_bound_regions(xform_fn_sig)
18121810
}
18131811

18141812
/// Gets the type of an impl and generate substitutions with placeholders.

library/alloc/src/collections/vec_deque/iter.rs

-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ impl<'a, T> Iterator for Iter<'a, T> {
122122
}
123123

124124
#[inline]
125-
#[doc(hidden)]
126125
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item {
127126
// Safety: The TrustedRandomAccess contract requires that callers only pass an index
128127
// that is in bounds.

library/alloc/src/collections/vec_deque/iter_mut.rs

-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ impl<'a, T> Iterator for IterMut<'a, T> {
100100
}
101101

102102
#[inline]
103-
#[doc(hidden)]
104103
unsafe fn __iterator_get_unchecked(&mut self, idx: usize) -> Self::Item {
105104
// Safety: The TrustedRandomAccess contract requires that callers only pass an index
106105
// that is in bounds.

0 commit comments

Comments
 (0)